This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[RFC 07/13] loc2c: Add Dwarf pointer to location_context
- From: Crestez Dan Leonard <cdleonard at gmail dot com>
- To: systemtap at sourceware dot org
- Date: Thu, 31 Jul 2014 23:21:12 +0300
- Subject: [RFC 07/13] loc2c: Add Dwarf pointer to location_context
- Authentication-results: sourceware.org; auth=none
- References: <cover dot 1406837921 dot git dot cdleonard at gmail dot com>
- References: <cover dot 1406837921 dot git dot cdleonard at gmail dot com>
Signed-off-by: Crestez Dan Leonard <cdleonard@gmail.com>
---
dwflpp.cxx | 10 +++++-----
loc2c-test.c | 27 +++++++++++++++++----------
loc2c.c | 20 +++++++++++++-------
loc2c.h | 9 ++++++---
4 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/dwflpp.cxx b/dwflpp.cxx
index dea81b9..10f4abb 100644
--- a/dwflpp.cxx
+++ b/dwflpp.cxx
@@ -3095,7 +3095,7 @@ dwflpp::translate_location(struct obstack *pool,
if (dwarf_whatattr (attr) == DW_AT_const_value)
{
*tail = c_translate_constant (pool, &loc2c_error, this,
- &loc2c_emit_address, 0, pc, attr);
+ &loc2c_emit_address, 0, pc, attr, module_dwarf);
return *tail;
}
@@ -3173,7 +3173,7 @@ dwflpp::translate_location(struct obstack *pool,
return c_translate_location (pool, &loc2c_error, this,
&loc2c_emit_address,
1, 0 /* PR9768 */,
- pc, attr, expr, len, tail, fb_attr, cfa_ops);
+ pc, attr, expr, len, tail, fb_attr, cfa_ops, module_dwarf);
}
@@ -3767,7 +3767,7 @@ dwflpp::literal_stmt_for_local (vector<Dwarf_Die>& scopes,
head = c_translate_location (&pool, &loc2c_error, this,
&loc2c_emit_address,
1, 0, pc,
- NULL, &addr_loc, 1, &tail, NULL, NULL);
+ NULL, &addr_loc, 1, &tail, NULL, NULL, module_dwarf);
}
else
{
@@ -3869,7 +3869,7 @@ dwflpp::literal_stmt_for_return (Dwarf_Die *scope_die,
&loc2c_emit_address,
1, 0 /* PR9768 */,
pc, NULL, locops, nlocops,
- &tail, NULL, NULL);
+ &tail, NULL, NULL, module_dwarf);
/* Translate the ->bar->baz[NN] parts. */
@@ -3929,7 +3929,7 @@ dwflpp::literal_stmt_for_pointer (Dwarf_Die *start_typedie,
obstack_init (&pool);
struct location *head = c_translate_argument (&pool, &loc2c_error, this,
&loc2c_emit_address,
- 1, "STAP_ARG_pointer");
+ 1, "STAP_ARG_pointer", module_dwarf);
struct location *tail = head;
/* Translate the ->bar->baz[NN] parts. */
diff --git a/loc2c-test.c b/loc2c-test.c
index 282047e..370a40f 100644
--- a/loc2c-test.c
+++ b/loc2c-test.c
@@ -89,7 +89,8 @@ static void
handle_fields (struct obstack *pool,
struct location *head, struct location *tail,
Dwarf_Addr cubias, Dwarf_Die *vardie, Dwarf_Addr pc,
- char **fields)
+ char **fields,
+ Dwarf *dwarf)
{
Dwarf_Attribute attr_mem;
@@ -192,7 +193,7 @@ handle_fields (struct obstack *pool,
c_translate_location (pool, NULL, NULL, NULL,
1, cubias, pc, &attr_mem,
locexpr, locexpr_len,
- &tail, NULL, NULL);
+ &tail, NULL, NULL, dwarf);
}
++fields;
break;
@@ -294,7 +295,8 @@ handle_fields (struct obstack *pool,
static void
handle_variable (Dwarf_Die *lscopes, int lnscopes, int out,
Dwarf_Addr cubias, Dwarf_Die *vardie, Dwarf_Addr pc,
- Dwarf_Op *cfa_ops, char **fields)
+ Dwarf_Op *cfa_ops, char **fields,
+ Dwarf *dwarf)
{
struct obstack pool;
obstack_init (&pool);
@@ -345,7 +347,7 @@ handle_variable (Dwarf_Die *lscopes, int lnscopes, int out,
if (dwarf_attr_integrate (vardie, DW_AT_const_value, &attr_mem) != NULL)
/* There is no location expression, but a constant value instead. */
head = tail = c_translate_constant (&pool, &fail, NULL, NULL,
- 1, cubias, &attr_mem);
+ 1, cubias, &attr_mem, dwarf);
else
{
if (dwarf_attr_integrate (vardie, DW_AT_location, &attr_mem) == NULL)
@@ -359,10 +361,10 @@ handle_variable (Dwarf_Die *lscopes, int lnscopes, int out,
head = c_translate_location (&pool, &fail, NULL, NULL,
1, cubias, pc, &attr_mem,
locexpr, locexpr_len,
- &tail, fb_attr, cfa_ops);
+ &tail, fb_attr, cfa_ops, dwarf);
}
- handle_fields (&pool, head, tail, cubias, vardie, pc, fields);
+ handle_fields (&pool, head, tail, cubias, vardie, pc, fields, dwarf);
}
static void
@@ -656,8 +658,11 @@ In the fifth form, the access is a store rather than a fetch."
if (dwarf_tag (&scopes[i]) == DW_TAG_subprogram)
{
const Dwarf_Op *locexpr;
+ Dwfl_Module *mod = dwfl_addrmodule (dwfl, pc);
+ Dwarf_Addr bias;
+ Dwarf *dwarf = dwfl_module_getdwarf (mod, &bias);
int locexpr_len = dwfl_module_return_value_location
- (dwfl_addrmodule (dwfl, pc), &scopes[i], &locexpr);
+ (mod, &scopes[i], &locexpr);
if (locexpr_len < 0)
error (EXIT_FAILURE, 0,
"dwfl_module_return_value_location: %s",
@@ -668,9 +673,9 @@ In the fifth form, the access is a store rather than a fetch."
head = c_translate_location (&pool, &fail, NULL, NULL,
1, cubias, pc, NULL,
locexpr, locexpr_len,
- &tail, NULL, NULL);
+ &tail, NULL, NULL, dwarf);
handle_fields (&pool, head, tail, cubias, &scopes[i], pc,
- &argv[argi]);
+ &argv[argi], dwarf);
free (scopes);
dwfl_end (dwfl);
return 0;
@@ -709,6 +714,7 @@ In the fifth form, the access is a store rather than a fetch."
size_t cfa_nops;
Dwarf_Addr bias;
Dwfl_Module *module = dwfl_addrmodule (dwfl, pc);
+ Dwarf *dwarf = NULL;
if (module != NULL)
{
// Try debug_frame first, then fall back on eh_frame.
@@ -729,10 +735,11 @@ In the fifth form, the access is a store rather than a fetch."
dwarf_frame_cfa (frame, &cfa_ops, &cfa_nops);
}
}
+ dwarf = dwfl_module_getdwarf (module, &bias);
}
handle_variable (scopes, n, out, cubias, &vardie, pc, cfa_ops,
- &argv[argi]);
+ &argv[argi], dwarf);
}
}
diff --git a/loc2c.c b/loc2c.c
index aef999c..64f34e6 100644
--- a/loc2c.c
+++ b/loc2c.c
@@ -56,6 +56,7 @@ struct location_context
Dwarf_Addr pc;
Dwarf_Attribute *fb_attr;
const Dwarf_Op *cfa_ops;
+ Dwarf *dwarf;
};
struct location
@@ -140,7 +141,8 @@ new_context (struct obstack *pool,
struct obstack *, Dwarf_Addr),
Dwarf_Addr dwbias, Dwarf_Addr pc_address,
Dwarf_Attribute *attr, Dwarf_Attribute *fb_attr,
- const Dwarf_Op *cfa_ops)
+ const Dwarf_Op *cfa_ops,
+ Dwarf *dwarf)
{
struct location_context *ctx = obstack_alloc (pool, sizeof *ctx);
ctx->pool = pool;
@@ -152,6 +154,7 @@ new_context (struct obstack *pool,
ctx->pc = pc_address;
ctx->fb_attr = fb_attr;
ctx->cfa_ops = cfa_ops;
+ ctx->dwarf = dwarf;
return ctx;
}
@@ -257,10 +260,11 @@ c_translate_constant (struct obstack *pool,
void (*emit_address) (void *fail_arg,
struct obstack *,
Dwarf_Addr),
- int indent, Dwarf_Addr dwbias, Dwarf_Attribute *attr)
+ int indent, Dwarf_Addr dwbias, Dwarf_Attribute *attr,
+ Dwarf *dwarf)
{
return translate_constant (new_context (pool, fail, fail_arg, emit_address,
- dwbias, 0, attr, NULL, NULL),
+ dwbias, 0, attr, NULL, NULL, dwarf),
indent, attr);
}
@@ -1428,14 +1432,15 @@ c_translate_location (struct obstack *pool,
Dwarf_Attribute *attr,
const Dwarf_Op *expr, size_t len,
struct location **input, Dwarf_Attribute *fb_attr,
- const Dwarf_Op *cfa_ops)
+ const Dwarf_Op *cfa_ops,
+ Dwarf *dwarf)
{
indent += 2;
struct location_context *ctx;
if (*input == NULL)
ctx = new_context (pool, fail, fail_arg, emit_address, dwbias, pc_address,
- attr, fb_attr, cfa_ops);
+ attr, fb_attr, cfa_ops, dwarf);
else
{
ctx = (*input)->context;
@@ -1486,7 +1491,8 @@ c_translate_argument (struct obstack *pool,
void *fail_arg,
void (*emit_address) (void *fail_arg,
struct obstack *, Dwarf_Addr),
- int indent, const char *value)
+ int indent, const char *value,
+ Dwarf *dwarf)
{
indent += 2;
@@ -1496,7 +1502,7 @@ c_translate_argument (struct obstack *pool,
struct location *loc = obstack_alloc (pool, sizeof *loc);
loc->context = new_context (pool, fail, fail_arg, emit_address, 0,
- 0, NULL, NULL, NULL);
+ 0, NULL, NULL, NULL, dwarf);
loc->next = NULL;
loc->ops = NULL;
loc->nops = 0;
diff --git a/loc2c.h b/loc2c.h
index 25d2839..92121ae 100644
--- a/loc2c.h
+++ b/loc2c.h
@@ -39,7 +39,8 @@ struct location *c_translate_location (struct obstack *,
size_t locexprlen,
struct location **input,
Dwarf_Attribute *fb_attr,
- const Dwarf_Op *cfa_ops);
+ const Dwarf_Op *cfa_ops,
+ Dwarf *dwarf);
/* Translate a fragment for a compile-time constant from DW_AT_const_value.
*/
@@ -53,7 +54,8 @@ struct location *c_translate_constant (struct obstack *,
struct obstack *,
Dwarf_Addr),
int indent, Dwarf_Addr dwbias,
- Dwarf_Attribute *attr);
+ Dwarf_Attribute *attr,
+ Dwarf *dwarf);
/* Translate a fragment to dereference the given DW_TAG_pointer_type DIE,
where *INPUT is the location of the pointer with that type. */
@@ -122,7 +124,8 @@ struct location *c_translate_argument (struct obstack *,
void (*emit_address) (void *fail_arg,
struct obstack *,
Dwarf_Addr),
- int indent, const char *value);
+ int indent, const char *value,
+ Dwarf *dwarf);