Skip to content

Commit cb94504

Browse files
committed
gendwarfksyms: Expand subroutine_type
Add support for expanding DW_TAG_subroutine_type and the parameters in DW_TAG_formal_parameter. Use this to also expand subprograms. Example output with --debug: subprogram( formal_parameter base_type usize byte_size(8), formal_parameter base_type usize byte_size(8), ) -> base_type void; Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
1 parent de397f1 commit cb94504

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

scripts/gendwarfksyms/dwarf.c

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ DEFINE_PROCESS_UDATA_ATTRIBUTE(alignment)
210210
DEFINE_PROCESS_UDATA_ATTRIBUTE(byte_size)
211211
DEFINE_PROCESS_UDATA_ATTRIBUTE(encoding)
212212

213+
/* Match functions -- die_match_callback_t */
214+
#define DEFINE_MATCH(type) \
215+
static bool match_##type##_type(Dwarf_Die *die) \
216+
{ \
217+
return dwarf_tag(die) == DW_TAG_##type##_type; \
218+
}
219+
220+
DEFINE_MATCH(formal_parameter)
221+
213222
bool match_all(Dwarf_Die *die)
214223
{
215224
return true;
@@ -247,6 +256,25 @@ static int process_type_attr(struct state *state, struct die *cache,
247256
return check(process(state, cache, "base_type void"));
248257
}
249258

259+
/* Comma-separated with DW_AT_type */
260+
static int __process_list_type(struct state *state, struct die *cache,
261+
Dwarf_Die *die, const char *type)
262+
{
263+
check(process(state, cache, type));
264+
check(process_type_attr(state, cache, die));
265+
check(process(state, cache, ","));
266+
return check(process_linebreak(cache, 0));
267+
}
268+
269+
#define DEFINE_PROCESS_LIST_TYPE(type) \
270+
static int process_##type##_type(struct state *state, \
271+
struct die *cache, Dwarf_Die *die) \
272+
{ \
273+
return __process_list_type(state, cache, die, #type " "); \
274+
}
275+
276+
DEFINE_PROCESS_LIST_TYPE(formal_parameter)
277+
250278
/* Container types with DW_AT_type */
251279
static int __process_type(struct state *state, struct die *cache,
252280
Dwarf_Die *die, const char *type)
@@ -281,6 +309,29 @@ DEFINE_PROCESS_TYPE(shared)
281309
DEFINE_PROCESS_TYPE(volatile)
282310
DEFINE_PROCESS_TYPE(typedef)
283311

312+
static int __process_subroutine_type(struct state *state, struct die *cache,
313+
Dwarf_Die *die, const char *type)
314+
{
315+
check(process(state, cache, type));
316+
check(process(state, cache, "("));
317+
check(process_linebreak(cache, 1));
318+
/* Parameters */
319+
check(process_die_container(state, cache, die, process_type,
320+
match_formal_parameter_type));
321+
check(process_linebreak(cache, -1));
322+
check(process(state, cache, ")"));
323+
process_linebreak(cache, 0);
324+
/* Return type */
325+
check(process(state, cache, "-> "));
326+
return check(process_type_attr(state, cache, die));
327+
}
328+
329+
static int process_subroutine_type(struct state *state, struct die *cache,
330+
Dwarf_Die *die)
331+
{
332+
return check(__process_subroutine_type(state, cache, die,
333+
"subroutine_type"));
334+
}
284335
static int process_base_type(struct state *state, struct die *cache,
285336
Dwarf_Die *die)
286337
{
@@ -358,8 +409,11 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
358409
PROCESS_TYPE(rvalue_reference)
359410
PROCESS_TYPE(shared)
360411
PROCESS_TYPE(volatile)
412+
/* Subtypes */
413+
PROCESS_TYPE(formal_parameter)
361414
/* Other types */
362415
PROCESS_TYPE(base)
416+
PROCESS_TYPE(subroutine)
363417
PROCESS_TYPE(typedef)
364418
default:
365419
debug("unimplemented type: %x", tag);
@@ -379,7 +433,8 @@ static int process_type(struct state *state, struct die *parent, Dwarf_Die *die)
379433
*/
380434
static int process_subprogram(struct state *state, Dwarf_Die *die)
381435
{
382-
return check(process(state, NULL, "subprogram;\n"));
436+
check(__process_subroutine_type(state, NULL, die, "subprogram"));
437+
return check(process(state, NULL, ";\n"));
383438
}
384439

385440
static int process_variable(struct state *state, Dwarf_Die *die)

scripts/gendwarfksyms/gendwarfksyms.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extern bool debug;
5959
#define checkp(expr) __check(expr, __res < 0, __res)
6060

6161
/* Consistent aliases (DW_TAG_<type>_type) for DWARF tags */
62+
#define DW_TAG_formal_parameter_type DW_TAG_formal_parameter
6263
#define DW_TAG_typedef_type DW_TAG_typedef
6364

6465
/*

0 commit comments

Comments
 (0)