From c65f2cf4361e9fd9fdcb8e85ed0a7ac7ab683a08 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Wed, 5 Sep 2018 15:07:46 -0300 Subject: [PATCH] dwarves: Rename variable->location to ->scope We'll use location in the DWARF sense, i.e. location lists, etc, i.e. where is this variable? In a register? The stack? etc. Signed-off-by: Arnaldo Carvalho de Melo --- ctf_encoder.c | 2 +- ctf_loader.c | 2 +- dwarf_loader.c | 27 ++++++++++++++++----------- dwarves.h | 16 +++++++++------- dwarves_fprintf.c | 12 ++++++------ 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/ctf_encoder.c b/ctf_encoder.c index ab70254..6787eb6 100644 --- a/ctf_encoder.c +++ b/ctf_encoder.c @@ -319,7 +319,7 @@ int cu__encode_ctf(struct cu *cu, int verbose) struct variable *var; cu__for_each_variable(cu, id, pos) { var = tag__variable(pos); - if (var->location != LOCATION_GLOBAL) + if (variable__scope(var) != VSCOPE_GLOBAL) continue; struct hlist_head *head = &hash_addr[hashaddr__fn(var->ip.addr)]; hlist_add_head(&var->tool_hnode, head); diff --git a/ctf_loader.c b/ctf_loader.c index f73fd1e..d6542a9 100644 --- a/ctf_loader.c +++ b/ctf_loader.c @@ -551,7 +551,7 @@ static struct variable *variable__new(uint16_t type, GElf_Sym *sym, struct variable *var = tag__alloc(sizeof(*var)); if (var != NULL) { - var->location = LOCATION_GLOBAL; + var->scope = VSCOPE_GLOBAL; var->ip.addr = elf_sym__value(sym); var->name = sym->st_name; var->external = elf_sym__bind(sym) == STB_GLOBAL; diff --git a/dwarf_loader.c b/dwarf_loader.c index 1ae0d26..e7ea79d 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -543,28 +543,33 @@ static struct enumerator *enumerator__new(Dwarf_Die *die, struct cu *cu) return enumerator; } -static enum vlocation dwarf__location(Dwarf_Die *die, uint64_t *addr) +static enum vscope dwarf__location(Dwarf_Die *die, uint64_t *addr) { Dwarf_Op *expr; size_t exprlen; - enum vlocation location = LOCATION_UNKNOWN; + enum vscope scope = VSCOPE_UNKNOWN; if (attr_location(die, &expr, &exprlen) != 0) - location = LOCATION_OPTIMIZED; + scope = VSCOPE_OPTIMIZED; else if (exprlen != 0) switch (expr->atom) { case DW_OP_addr: - location = LOCATION_GLOBAL; + scope = VSCOPE_GLOBAL; *addr = expr[0].number; break; case DW_OP_reg1 ... DW_OP_reg31: case DW_OP_breg0 ... DW_OP_breg31: - location = LOCATION_REGISTER; break; + scope = VSCOPE_REGISTER; break; case DW_OP_fbreg: - location = LOCATION_LOCAL; break; + scope = VSCOPE_LOCAL; break; } - return location; + return scope; +} + +enum vscope variable__scope(const struct variable *var) +{ + return var->scope; } static struct variable *variable__new(Dwarf_Die *die, struct cu *cu) @@ -578,10 +583,10 @@ static struct variable *variable__new(Dwarf_Die *die, struct cu *cu) var->external = dwarf_hasattr(die, DW_AT_external); /* non-defining declaration of an object */ var->declaration = dwarf_hasattr(die, DW_AT_declaration); - var->location = LOCATION_UNKNOWN; + var->scope = VSCOPE_UNKNOWN; var->ip.addr = 0; if (!var->declaration && cu->has_addr_info) - var->location = dwarf__location(die, &var->ip.addr); + var->scope = dwarf__location(die, &var->ip.addr); } return var; @@ -1501,7 +1506,7 @@ static int die__process_function(Dwarf_Die *die, struct ftype *ftype, continue; case DW_TAG_dwarf_procedure: /* - * Ignore it, just location expressions, that we have no use for (so far). + * Ignore it, just scope expressions, that we have no use for (so far). */ continue; #ifdef STB_GNU_UNIQUE @@ -1631,7 +1636,7 @@ static struct tag *__die__process_tag(Dwarf_Die *die, struct cu *cu, /* fall thru */ case DW_TAG_dwarf_procedure: /* - * Ignore it, just location expressions, that we have no use for (so far). + * Ignore it, just scope expressions, that we have no use for (so far). */ tag = &unsupported_tag; break; diff --git a/dwarves.h b/dwarves.h index 52a68db..5d36521 100644 --- a/dwarves.h +++ b/dwarves.h @@ -571,12 +571,12 @@ static inline const char *label__name(const struct label *label, return cu__string(cu, label->name); } -enum vlocation { - LOCATION_UNKNOWN, - LOCATION_LOCAL, - LOCATION_GLOBAL, - LOCATION_REGISTER, - LOCATION_OPTIMIZED +enum vscope { + VSCOPE_UNKNOWN, + VSCOPE_LOCAL, + VSCOPE_GLOBAL, + VSCOPE_REGISTER, + VSCOPE_OPTIMIZED } __attribute__((packed)); struct variable { @@ -584,7 +584,7 @@ struct variable { strings_t name; uint8_t external:1; uint8_t declaration:1; - enum vlocation location; + enum vscope scope; struct hlist_node tool_hnode; }; @@ -593,6 +593,8 @@ static inline struct variable *tag__variable(const struct tag *tag) return (struct variable *)tag; } +enum vscope variable__scope(const struct variable *var); + const char *variable__name(const struct variable *var, const struct cu *cu); const char *variable__type_name(const struct variable *var, diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c index 2164c9e..fa306d8 100644 --- a/dwarves_fprintf.c +++ b/dwarves_fprintf.c @@ -522,19 +522,19 @@ const char *tag__name(const struct tag *tag, const struct cu *cu, static const char *variable__prefix(const struct variable *var) { - switch (var->location) { - case LOCATION_REGISTER: + switch (variable__scope(var)) { + case VSCOPE_REGISTER: return "register "; - case LOCATION_UNKNOWN: + case VSCOPE_UNKNOWN: if (var->external && var->declaration) return "extern "; break; - case LOCATION_GLOBAL: + case VSCOPE_GLOBAL: if (!var->external) return "static "; break; - case LOCATION_LOCAL: - case LOCATION_OPTIMIZED: + case VSCOPE_LOCAL: + case VSCOPE_OPTIMIZED: break; } return NULL;