From: Stephen Brennan <stephen.s.brennan@oracle.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org,
linux-debuggers@vger.kernel.org,
Stephen Brennan <stephen.s.brennan@oracle.com>,
Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH dwarves v2 2/4] dwarf_loader: add "artificial" and "top_level" variable flags
Date: Fri, 20 Sep 2024 01:18:59 -0700 [thread overview]
Message-ID: <20240920081903.13473-3-stephen.s.brennan@oracle.com> (raw)
In-Reply-To: <20240920081903.13473-1-stephen.s.brennan@oracle.com>
The "artificial" flag corresponds directly to DW_AT_artificial, which
indicates a compiler-generated variable (e.g. __func__) which shouldn't
be included in the output.
The "top_level" flag is intended to be a better proxy for global scoped
variables. It indicates that a variable was a direct child of a
compilation unit, rather than a child of a subroutine or lexical block.
Currently, the DWARF loader examines the DWARF location expression, and
if the location is found to be at a constant memory address (not stack,
register, etc), then the variable is assumed to be globally scoped.
However, this includes a variety of variables that aren't truly globally
scoped: most commonly, static local variables of functions. Their
locations may be static, but they're not globally accessible in any
useful way.
These flags will be used by the BTF encoder to select global variables.
Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
---
dwarf_loader.c | 12 +++++++-----
dwarves.h | 2 ++
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/dwarf_loader.c b/dwarf_loader.c
index 065ed4d..d162214 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -730,7 +730,7 @@ const char *variable__scope_str(const struct variable *var)
return "unknown";
}
-static struct variable *variable__new(Dwarf_Die *die, struct cu *cu, struct conf_load *conf)
+static struct variable *variable__new(Dwarf_Die *die, struct cu *cu, struct conf_load *conf, int top_level)
{
bool has_specification = dwarf_hasattr(die, DW_AT_specification);
struct variable *var = tag__alloc(cu, sizeof(*var));
@@ -743,6 +743,8 @@ static struct variable *variable__new(Dwarf_Die *die, struct cu *cu, struct conf
/* non-defining declaration of an object */
var->declaration = dwarf_hasattr(die, DW_AT_declaration);
var->has_specification = has_specification;
+ var->artificial = dwarf_hasattr(die, DW_AT_artificial);
+ var->top_level = top_level;
var->scope = VSCOPE_UNKNOWN;
INIT_LIST_HEAD(&var->annots);
var->ip.addr = 0;
@@ -1767,9 +1769,9 @@ static struct tag *die__create_new_label(Dwarf_Die *die,
return &label->ip.tag;
}
-static struct tag *die__create_new_variable(Dwarf_Die *die, struct cu *cu, struct conf_load *conf)
+static struct tag *die__create_new_variable(Dwarf_Die *die, struct cu *cu, struct conf_load *conf, int top_level)
{
- struct variable *var = variable__new(die, cu, conf);
+ struct variable *var = variable__new(die, cu, conf, top_level);
if (var == NULL || add_child_llvm_annotations(die, -1, conf, &var->annots))
return NULL;
@@ -2243,7 +2245,7 @@ static int die__process_function(Dwarf_Die *die, struct ftype *ftype,
tag = die__create_new_parameter(die, ftype, lexblock, cu, conf, param_idx++);
break;
case DW_TAG_variable:
- tag = die__create_new_variable(die, cu, conf);
+ tag = die__create_new_variable(die, cu, conf, 0);
if (tag == NULL)
goto out_enomem;
lexblock__add_variable(lexblock, tag__variable(tag));
@@ -2367,7 +2369,7 @@ static struct tag *__die__process_tag(Dwarf_Die *die, struct cu *cu,
case DW_TAG_union_type:
tag = die__create_new_union(die, cu, conf); break;
case DW_TAG_variable:
- tag = die__create_new_variable(die, cu, conf); break;
+ tag = die__create_new_variable(die, cu, conf, top_level); break;
case DW_TAG_constant: // First seen in a Go CU
tag = die__create_new_constant(die, cu, conf); break;
default:
diff --git a/dwarves.h b/dwarves.h
index f2d3988..0fede91 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -848,6 +848,8 @@ struct variable {
uint8_t external:1;
uint8_t declaration:1;
uint8_t has_specification:1;
+ uint8_t artificial:1;
+ uint8_t top_level:1;
enum vscope scope;
struct location location;
struct hlist_node tool_hnode;
--
2.43.5
next prev parent reply other threads:[~2024-09-20 8:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-20 8:18 [PATCH dwarves v2 0/4] Emit global variables in BTF Stephen Brennan
2024-09-20 8:18 ` [PATCH dwarves v2 1/4] dutil: return ELF section name when looked up by index Stephen Brennan
2024-09-20 8:18 ` Stephen Brennan [this message]
2024-09-20 8:19 ` [PATCH dwarves v2 3/4] btf_encoder: cache all ELF section info Stephen Brennan
2024-09-20 8:19 ` [PATCH dwarves v2 4/4] btf_encoder: add global_var feature to encode globals Stephen Brennan
2024-10-01 15:07 ` Arnaldo Carvalho de Melo
2024-10-01 17:13 ` Andrii Nakryiko
2024-10-01 18:52 ` Arnaldo Carvalho de Melo
2024-10-01 22:35 ` Stephen Brennan
2024-10-02 14:14 ` Jiri Olsa
2024-10-02 15:11 ` Alan Maguire
2024-10-03 13:10 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240920081903.13473-3-stephen.s.brennan@oracle.com \
--to=stephen.s.brennan@oracle.com \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=linux-debuggers@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox