This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: WIP fix for PR 12997
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
Tom> How about the appended?
Or not, cough cough, that one was really broken.
How about this one instead? It includes a test case. The test case
fails with an unmodified stap, and passes with the rest of the patch
applied.
Tom
diff --git a/dwflpp.cxx b/dwflpp.cxx
index 7a659c4..17f3bf8 100644
--- a/dwflpp.cxx
+++ b/dwflpp.cxx
@@ -1,5 +1,5 @@
// C++ interface to dwfl
-// Copyright (C) 2005-2011 Red Hat Inc.
+// Copyright (C) 2005-2012 Red Hat Inc.
// Copyright (C) 2005-2007 Intel Corporation.
// Copyright (C) 2008 James.Bottomley@HansenPartnership.com
//
@@ -76,7 +76,8 @@ static string TOK_KERNEL("kernel");
dwflpp::dwflpp(systemtap_session & session, const string& name, bool kernel_p):
sess(session), module(NULL), module_bias(0), mod_info(NULL),
module_start(0), module_end(0), cu(NULL),
- module_dwarf(NULL), function(NULL), blacklist_func(), blacklist_func_ret(),
+ module_dwarf(NULL), function(NULL), loaded_type_units(false),
+ blacklist_func(), blacklist_func_ret(),
blacklist_file(), blacklist_enabled(false)
{
if (kernel_p)
@@ -93,7 +94,8 @@ dwflpp::dwflpp(systemtap_session & session, const vector<string>& names,
bool kernel_p):
sess(session), module(NULL), module_bias(0), mod_info(NULL),
module_start(0), module_end(0), cu(NULL),
- module_dwarf(NULL), function(NULL), blacklist_enabled(false)
+ module_dwarf(NULL), function(NULL), loaded_type_units(false),
+ blacklist_enabled(false)
{
if (kernel_p)
setup_kernel(names);
@@ -405,7 +407,7 @@ dwflpp::iterate_over_modules(int (* callback)(Dwfl_Module *, void **,
void
dwflpp::iterate_over_cus (int (*callback)(Dwarf_Die * die, void * arg),
- void * data)
+ void * data, bool want_types)
{
get_module_dwarf(false);
Dwarf *dw = module_dwarf;
@@ -431,6 +433,26 @@ dwflpp::iterate_over_cus (int (*callback)(Dwarf_Die * die, void * arg),
}
}
+ if (want_types && !this->loaded_type_units)
+ {
+ // Process type units.
+ Dwarf_Off off = 0;
+ size_t cuhl;
+ Dwarf_Off noff;
+ uint64_t type_signature;
+ while (dwarf_next_unit (dw, off, &noff, &cuhl, NULL, NULL, NULL, NULL,
+ &type_signature, NULL) == 0)
+ {
+ if (pending_interrupts) return;
+ Dwarf_Die die_mem;
+ Dwarf_Die *die;
+ die = dwarf_offdie_types (dw, off + cuhl, &die_mem);
+ v->push_back (*die); /* copy */
+ off = noff;
+ }
+ this->loaded_type_units = true;
+ }
+
for (vector<Dwarf_Die>::iterator i = v->begin(); i != v->end(); ++i)
{
int rc = (*callback)(&*i, data);
@@ -816,7 +838,7 @@ dwflpp::global_alias_caching_callback_cus(Dwarf_Die *die, void *arg)
Dwarf_Die *
dwflpp::declaration_resolve_other_cus(const string& name)
{
- iterate_over_cus(global_alias_caching_callback_cus, this);
+ iterate_over_cus(global_alias_caching_callback_cus, this, true);
for (mod_cu_type_cache_t::iterator i = global_alias_cache.begin();
i != global_alias_cache.end(); ++i)
{
@@ -986,7 +1008,7 @@ dwflpp::iterate_single_function (int (* callback)(Dwarf_Die * func, base_query *
{
v = new cu_function_cache_t;
mod_function_cache[module_dwarf] = v;
- iterate_over_cus (mod_function_caching_callback, v);
+ iterate_over_cus (mod_function_caching_callback, v, false);
if (sess.verbose > 4)
clog << _F("module function cache %s size %zu", module_name.c_str(),
v->size()) << endl;
@@ -1031,7 +1053,8 @@ dwflpp::iterate_over_globals (Dwarf_Die *cu_die,
void * data)
{
assert (cu_die);
- assert (dwarf_tag(cu_die) == DW_TAG_compile_unit);
+ assert (dwarf_tag(cu_die) == DW_TAG_compile_unit
+ || dwarf_tag(cu_die) == DW_TAG_type_unit);
// If this is C++, recurse for any inner types
bool has_inner_types = dwarf_srclang(cu_die) == DW_LANG_C_plus_plus;
diff --git a/dwflpp.h b/dwflpp.h
index adbc5a6..2f693eb 100644
--- a/dwflpp.h
+++ b/dwflpp.h
@@ -1,5 +1,5 @@
// C++ interface to dwfl
-// Copyright (C) 2005-2011 Red Hat Inc.
+// Copyright (C) 2005-2012 Red Hat Inc.
// Copyright (C) 2005-2007 Intel Corporation.
// Copyright (C) 2008 James.Bottomley@HansenPartnership.com
//
@@ -201,7 +201,7 @@ struct dwflpp
void *data);
void iterate_over_cus (int (*callback)(Dwarf_Die * die, void * arg),
- void * data);
+ void * data, bool want_types);
bool func_is_inline();
@@ -333,6 +333,7 @@ private:
module_cu_cache_t module_cu_cache;
mod_cu_function_cache_t cu_function_cache;
mod_function_cache_t mod_function_cache;
+ bool loaded_type_units;
std::set<void*> cu_inl_function_cache_done; // CUs that are already cached
cu_inl_function_cache_t cu_inl_function_cache;
diff --git a/tapsets.cxx b/tapsets.cxx
index 74d604f..d1a0576 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -892,7 +892,7 @@ dwarf_query::query_module_dwarf()
!startswith(function, "_Z"))
query_module_functions();
else
- dw.iterate_over_cus(&query_cu, this);
+ dw.iterate_over_cus(&query_cu, this, false);
}
}
@@ -9489,7 +9489,7 @@ void
tracepoint_query::handle_query_module()
{
// look for the tracepoints in each CU
- dw.iterate_over_cus(tracepoint_query_cu, this);
+ dw.iterate_over_cus(tracepoint_query_cu, this, false);
}
diff --git a/testsuite/systemtap.pass1-4/debugtypes.cxx b/testsuite/systemtap.pass1-4/debugtypes.cxx
new file mode 100644
index 0000000..faaebab
--- /dev/null
+++ b/testsuite/systemtap.pass1-4/debugtypes.cxx
@@ -0,0 +1,21 @@
+struct s1
+{
+ char c;
+ short s;
+ int i;
+ long l;
+ float f;
+ double d;
+};
+
+s1 S1;
+
+int func (s1 *p)
+{
+ return p->i;
+}
+
+int main()
+{
+ return func (&S1);
+}
diff --git a/testsuite/systemtap.pass1-4/debugtypes.exp b/testsuite/systemtap.pass1-4/debugtypes.exp
new file mode 100644
index 0000000..37cacf9
--- /dev/null
+++ b/testsuite/systemtap.pass1-4/debugtypes.exp
@@ -0,0 +1,16 @@
+set test debugtypes
+
+if {[target_compile $srcdir/$subdir/$test.cxx $test.exe executable \
+ {debug {additional_flags=-gdwarf-4 -fdebug-types-section}}] != ""} {
+ fail "compiling $test.cxx"
+ return
+}
+pass "compiling $test.cxx"
+
+verbose "path = $env(PATH)" 0
+
+if {[stap_run_batch $srcdir/$subdir/$test.stp] == 0} {
+ pass "compiling $test.stp"
+} else {
+ fail "compiling $test.stp"
+}
diff --git a/testsuite/systemtap.pass1-4/debugtypes.stp b/testsuite/systemtap.pass1-4/debugtypes.stp
new file mode 100755
index 0000000..4a96d1d
--- /dev/null
+++ b/testsuite/systemtap.pass1-4/debugtypes.stp
@@ -0,0 +1,5 @@
+#! stap -p2
+
+probe process("debugtypes.exe").function("func") {
+ println(@cast($p, "struct s1")->l)
+}