diff options
| author | Mark Wielaard <[email protected]> | 2013-09-20 09:50:42 -0400 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2013-09-24 10:28:14 +0200 |
| commit | 1b734df17fca9f89a887b85ffe74616a87388f51 (patch) | |
| tree | 2dc0ba75b4c517261ad60a17f96b6f766722f9b5 /tests/allfcts.c | |
| parent | 21fc33fe191603b71e9e14d2d1a79a8aa48ad6e6 (diff) | |
libdw: Make dwarf_getfuncs find all (defining) DW_TAG_subprogram DIEs.
dwarf_getfuncs used to return only the DW_TAG_subprogram DIEs that were
direct children of the given CU. This is normally how GCC outputs the
subprogram DIEs. But not always. For nested functions the subprogram DIE
is placed under the code construct DIE where it is nested. Other compilers
might output the defining subprogram DIE of a C++ class function under
the DW_TAG_namespace DIE where it was defined. Both such constructs seem
allowed by the DWARF specification. So just searching the CU DIE children
was wrong.
To find all (defining) subprogram DIEs in a CU dwarf_getfuncs should
use __libdw_visit_scopes to walk the tree for all DIEs that can contain
subprograms as children. The only tricky part is making sure the offset
returned and used when the callback returns DWARF_CB_ABORT is correct
and the search continues at the right spot in the CU DIE tree. This
operation now needs to rewalk the whole tree.
Two new testcases were added that fail without this patch. And the
allfcts test was tweaked so that it always returns DWARF_CB_ABORT
from its callback to make sure the offset handling is correct.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'tests/allfcts.c')
| -rw-r--r-- | tests/allfcts.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tests/allfcts.c b/tests/allfcts.c index f14b4935..7803722f 100644 --- a/tests/allfcts.c +++ b/tests/allfcts.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 Red Hat, Inc. +/* Copyright (C) 2005, 2013 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -34,7 +34,7 @@ cb (Dwarf_Die *func, void *arg __attribute__ ((unused))) printf ("%s:%d:%s\n", file, line, fct); - return DWARF_CB_OK; + return DWARF_CB_ABORT; } @@ -57,7 +57,13 @@ main (int argc, char *argv[]) Dwarf_Die die_mem; Dwarf_Die *die = dwarf_offdie (dbg, off + cuhl, &die_mem); - (void) dwarf_getfuncs (die, cb, NULL, 0); + /* Explicitly stop in the callback and then resume each time. */ + ptrdiff_t doff = 0; + do + { + doff = dwarf_getfuncs (die, cb, NULL, doff); + } + while (doff > 0); off = noff; } |
