2 SPDX-License-Identifier: GPL-2.0-only
4 Copyright (C) 2007-2016 Arnaldo Carvalho de Melo <acme@kernel.org>
15 static struct conf_fprintf conf
= {
19 static void emit_tag(struct tag
*tag
, uint32_t tag_id
, struct cu
*cu
)
21 printf("/* %d */\n", tag_id
);
23 if (tag__is_struct(tag
))
24 class__find_holes(tag__class(tag
));
26 if (tag
->tag
== DW_TAG_base_type
) {
28 const char *name
= base_type__name(tag__base_type(tag
), bf
, sizeof(bf
));
31 printf("anonymous base_type\n");
34 } else if (tag__is_pointer(tag
))
35 printf(" /* pointer to %lld */\n", (unsigned long long)tag
->type
);
37 tag__fprintf(tag
, cu
, &conf
, stdout
);
39 printf(" /* size: %zd */\n\n", tag__size(tag
, cu
));
42 static int cu__emit_tags(struct cu
*cu
)
47 puts("/* Types: */\n");
48 cu__for_each_type(cu
, i
, tag
)
51 puts("/* Functions: */\n");
52 conf
.no_semicolon
= true;
53 struct function
*function
;
54 cu__for_each_function(cu
, i
, function
) {
55 tag__fprintf(function__tag(function
), cu
, &conf
, stdout
);
57 lexblock__fprintf(&function
->lexblock
, cu
, function
, 0,
59 printf(" /* size: %zd */\n\n",
60 tag__size(function__tag(function
), cu
));
62 conf
.no_semicolon
= false;
64 puts("\n\n/* Variables: */\n");
65 cu__for_each_variable(cu
, i
, tag
) {
66 tag__fprintf(tag
, cu
, NULL
, stdout
);
67 printf(" /* size: %zd */\n\n", tag__size(tag
, cu
));
70 puts("\n\n/* Constants: */\n");
71 cu__for_each_constant(cu
, i
, tag
) {
72 tag__fprintf(tag
, cu
, NULL
, stdout
);
73 printf(" /* size: %zd */\n\n", tag__size(tag
, cu
));
79 static enum load_steal_kind
pdwtags_stealer(struct cu
*cu
,
80 struct conf_load
*conf_load __maybe_unused
,
81 void *thr_data __maybe_unused
)
87 static struct conf_load pdwtags_conf_load
= {
88 .steal
= pdwtags_stealer
,
89 .conf_fprintf
= &conf
,
92 /* Name and version of program. */
93 ARGP_PROGRAM_VERSION_HOOK_DEF
= dwarves_print_version
;
95 static const struct argp_option pdwtags__options
[] = {
97 .name
= "format_path",
100 .doc
= "List of debugging formats to try"
105 .doc
= "show details",
112 static error_t
pdwtags__options_parser(int key
, char *arg __maybe_unused
,
113 struct argp_state
*state
)
117 if (state
->child_inputs
!= NULL
)
118 state
->child_inputs
[0] = state
->input
;
120 case 'F': pdwtags_conf_load
.format_path
= arg
; break;
121 case 'V': conf
.show_decl_info
= 1; break;
122 default: return ARGP_ERR_UNKNOWN
;
127 static const char pdwtags__args_doc
[] = "FILE";
129 static struct argp pdwtags__argp
= {
130 .options
= pdwtags__options
,
131 .parser
= pdwtags__options_parser
,
132 .args_doc
= pdwtags__args_doc
,
135 int main(int argc
, char *argv
[])
137 int remaining
, rc
= EXIT_FAILURE
, err
;
138 struct cus
*cus
= cus__new();
140 if (dwarves__init() || cus
== NULL
) {
141 fputs("pwdtags: insufficient memory\n", stderr
);
145 dwarves__resolve_cacheline_size(&pdwtags_conf_load
, 0);
147 if (argp_parse(&pdwtags__argp
, argc
, argv
, 0, &remaining
, NULL
) ||
149 argp_help(&pdwtags__argp
, stderr
, ARGP_HELP_SEE
, argv
[0]);
153 err
= cus__load_files(cus
, &pdwtags_conf_load
, argv
+ remaining
);
159 cus__fprintf_load_files_err(cus
, "pdwtags", argv
+ remaining
, err
, stderr
);