inlinecall

Print call sites of an inline function
git clone git://git.margiolis.net/inlinecall.git
Log | Files | Refs | README | LICENSE

commit 4deaa9f56ebe87a10a6df8c5afce1a11b4d1a16a
parent 9c99dbdee8a1543ec0376eac65e478a293e129f1
Author: Christos Margiolis <christos@margiolis.net>
Date:   Mon, 13 Feb 2023 02:41:53 +0200

add more comments and remove unused variables

Diffstat:
Minlinecall.c | 35++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/inlinecall.c b/inlinecall.c @@ -36,6 +36,7 @@ emalloc(size_t nb) if ((p = malloc(nb)) == NULL) err(1, "malloc"); + return (p); } @@ -45,23 +46,21 @@ parse_die(Dwarf_Debug dbg, Dwarf_Die die, void *data, int level, int flag) static Dwarf_Die die_root; Dwarf_Die die_next; Dwarf_Ranges *ranges, *rp; - Dwarf_Attribute attp, *attr_list; + Dwarf_Attribute attp; + Dwarf_Addr *addr_lo, *addr_hi, v_addr; Dwarf_Off dieoff, cuoff, culen, v_off; - Dwarf_Addr v_addr; - Dwarf_Addr *addr_lo, *addr_hi; - Dwarf_Unsigned v_udata, line, nbytes; - Dwarf_Signed nattr, v_sdata, nranges; - Dwarf_Half tag, attr, form; + Dwarf_Unsigned line, nbytes, v_udata; + Dwarf_Signed nranges; + Dwarf_Half attr, tag; Dwarf_Bool v_flag; Dwarf_Error error; struct die_info *di; const char *str; - char *file = NULL; char *v_str; + char *file = NULL; int naddrs; int res, i, found = 0; - /* Save the root DIE so that we can re-parse it. */ if (level == 0) die_root = die; @@ -99,6 +98,10 @@ parse_die(Dwarf_Debug dbg, Dwarf_Die die, void *data, int level, int flag) } if (strcmp(v_str, (char *)data) != 0) goto cont; + /* + * The function name we're searching for has an inline + * definition. + */ found = 1; } else if (flag == F_INLINE_COPY) { /* @@ -117,8 +120,10 @@ parse_die(Dwarf_Debug dbg, Dwarf_Die die, void *data, int level, int flag) goto cont; } v_off += cuoff; + /* Doesn't point to the definition's DIE offset. */ if (v_off != (Dwarf_Off)data) goto cont; + if (dwarf_hasattr(die, DW_AT_ranges, &v_flag, &error) != DW_DLV_OK) { warnx("%s", dwarf_errmsg(error)); @@ -189,8 +194,8 @@ parse_die(Dwarf_Debug dbg, Dwarf_Die die, void *data, int level, int flag) naddrs = 1; addr_lo = emalloc(sizeof(Dwarf_Off)); addr_hi = emalloc(sizeof(Dwarf_Off)); - addr_lo[0] = v_addr; - addr_hi[0] = v_addr + v_udata; + addr_lo[0] = v_addr; /* lowpc */ + addr_hi[0] = v_addr + v_udata; /* lowpc + highpc */ } } else goto cont; @@ -253,8 +258,13 @@ cont: */ if (found) { die = die_root; - data = (void *)dieoff; level = 0; + /* + * We'll be checking against the DIE offset of the definition + * to determine if the inline copy's DW_AT_abstract_origin + * points to it. + */ + data = (void *)dieoff; flag = F_INLINE_COPY; } @@ -317,8 +327,7 @@ main(int argc, char *argv[]) Dwarf_Signed nfiles; Dwarf_Error error; char *func, *file; - int fd; - int res = DW_DLV_OK; + int fd, res = DW_DLV_OK; if (argc < 3) { fprintf(stderr, "usage: %s function debug_file\n", *argv);