From 465110ec99d334c193ae9a06bb1becab798d206b Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Wed, 5 Sep 2018 15:35:05 -0300 Subject: [PATCH] dwarves: Add the DWARF location to struct variable This is DWARF specific, we don't have in CTF, AFAIK, info about where a variable is put, i.e. in a register? in the stack? etc. Signed-off-by: Arnaldo Carvalho de Melo --- dwarf_loader.c | 12 ++++++------ dwarves.h | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index e7ea79d..7b8029d 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -543,15 +543,14 @@ static struct enumerator *enumerator__new(Dwarf_Die *die, struct cu *cu) return enumerator; } -static enum vscope dwarf__location(Dwarf_Die *die, uint64_t *addr) +static enum vscope dwarf__location(Dwarf_Die *die, uint64_t *addr, struct location *location) { - Dwarf_Op *expr; - size_t exprlen; enum vscope scope = VSCOPE_UNKNOWN; - if (attr_location(die, &expr, &exprlen) != 0) + if (attr_location(die, &location->expr, &location->exprlen) != 0) scope = VSCOPE_OPTIMIZED; - else if (exprlen != 0) + else if (location->exprlen != 0) { + Dwarf_Op *expr = location->expr; switch (expr->atom) { case DW_OP_addr: scope = VSCOPE_GLOBAL; @@ -563,6 +562,7 @@ static enum vscope dwarf__location(Dwarf_Die *die, uint64_t *addr) case DW_OP_fbreg: scope = VSCOPE_LOCAL; break; } + } return scope; } @@ -586,7 +586,7 @@ static struct variable *variable__new(Dwarf_Die *die, struct cu *cu) var->scope = VSCOPE_UNKNOWN; var->ip.addr = 0; if (!var->declaration && cu->has_addr_info) - var->scope = dwarf__location(die, &var->ip.addr); + var->scope = dwarf__location(die, &var->ip.addr, &var->location); } return var; diff --git a/dwarves.h b/dwarves.h index 5d36521..17c9bc7 100644 --- a/dwarves.h +++ b/dwarves.h @@ -579,12 +579,18 @@ enum vscope { VSCOPE_OPTIMIZED } __attribute__((packed)); +struct location { + Dwarf_Op *expr; + size_t exprlen; +}; + struct variable { struct ip_tag ip; strings_t name; uint8_t external:1; uint8_t declaration:1; enum vscope scope; + struct location location; struct hlist_node tool_hnode; };