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
));
76 bool first_namespace
= true;
78 cu__for_each_namespace(cu
, i
, tag
) {
82 if (first_namespace
) {
83 puts("\n\n/* Namespaces: */\n");
84 first_namespace
= false;
86 tag__fprintf(tag
, cu
, NULL
, stdout
);
93 static enum load_steal_kind
pdwtags_stealer(struct cu
*cu
,
94 struct conf_load
*conf_load __maybe_unused
)
100 static struct conf_load pdwtags_conf_load
= {
101 .steal
= pdwtags_stealer
,
102 .conf_fprintf
= &conf
,
105 /* Name and version of program. */
106 ARGP_PROGRAM_VERSION_HOOK_DEF
= dwarves_print_version
;
108 static const struct argp_option pdwtags__options
[] = {
110 .name
= "format_path",
112 .arg
= "FORMAT_LIST",
113 .doc
= "List of debugging formats to try"
118 .doc
= "show details",
125 static error_t
pdwtags__options_parser(int key
, char *arg __maybe_unused
,
126 struct argp_state
*state
)
130 if (state
->child_inputs
!= NULL
)
131 state
->child_inputs
[0] = state
->input
;
133 case 'F': pdwtags_conf_load
.format_path
= arg
; break;
134 case 'V': conf
.show_decl_info
= 1; break;
135 default: return ARGP_ERR_UNKNOWN
;
140 static const char pdwtags__args_doc
[] = "FILE";
142 static struct argp pdwtags__argp
= {
143 .options
= pdwtags__options
,
144 .parser
= pdwtags__options_parser
,
145 .args_doc
= pdwtags__args_doc
,
148 int main(int argc
, char *argv
[])
150 int remaining
, rc
= EXIT_FAILURE
, err
;
151 struct cus
*cus
= cus__new();
153 if (dwarves__init() || cus
== NULL
) {
154 fputs("pwdtags: insufficient memory\n", stderr
);
158 dwarves__resolve_cacheline_size(&pdwtags_conf_load
, 0);
160 if (argp_parse(&pdwtags__argp
, argc
, argv
, 0, &remaining
, NULL
) ||
162 argp_help(&pdwtags__argp
, stderr
, ARGP_HELP_SEE
, argv
[0]);
166 err
= cus__load_files(cus
, &pdwtags_conf_load
, argv
+ remaining
);
172 cus__fprintf_load_files_err(cus
, "pdwtags", argv
+ remaining
, err
, stderr
);