diff options
author | Josh Stone <jistone@redhat.com> | 2009-04-13 19:50:23 -0700 |
---|---|---|
committer | Josh Stone <jistone@redhat.com> | 2009-04-13 19:50:23 -0700 |
commit | b9c2e81cc7a62336ec1daf374cb3411add772ab4 (patch) | |
tree | a4bd05ef043f77e6cfe8c78b6f24879f68689910 | |
parent | 675e4d2a0635f822e8258c3f219c6dda685c67cf (diff) | |
download | systemtap-steved-b9c2e81cc7a62336ec1daf374cb3411add772ab4.tar.gz systemtap-steved-b9c2e81cc7a62336ec1daf374cb3411add772ab4.tar.xz systemtap-steved-b9c2e81cc7a62336ec1daf374cb3411add772ab4.zip |
PR10067: fix bitfield access
* tapsets.cxx (dwflpp::translate_components): Eliminate the extra
die-dereference at the end of the loop (a regression from @casts).
* runtime/loc2c-runtime.h (store_bitfield): Use the target as the
representative type, since the base is always int64_t. Also be a
bit more aggressive with masking and parentheses.
* testsuite/systemtap.base/bitfield.*: New test for R/W bitfields.
-rw-r--r-- | runtime/loc2c-runtime.h | 11 | ||||
-rw-r--r-- | tapsets.cxx | 7 | ||||
-rw-r--r-- | testsuite/systemtap.base/bitfield.exp | 3 | ||||
-rw-r--r-- | testsuite/systemtap.base/bitfield.stp | 46 |
4 files changed, 60 insertions, 7 deletions
diff --git a/runtime/loc2c-runtime.h b/runtime/loc2c-runtime.h index eaf47cad..620e1615 100644 --- a/runtime/loc2c-runtime.h +++ b/runtime/loc2c-runtime.h @@ -29,11 +29,12 @@ & (((__typeof (base)) 1 << (nbits)) - 1)) #define store_bitfield(target, base, higherbits, nbits) \ - target = (target \ - &~ ((((__typeof (base)) 1 << (nbits)) - 1) \ - << (sizeof (base) * 8 - (higherbits) - (nbits))) \ - | ((__typeof (base)) (base) \ - << (sizeof (base) * 8 - (higherbits) - (nbits)))) + target = ((target \ + &~ ((((__typeof (target)) 1 << (nbits)) - 1) \ + << (sizeof (target) * 8 - (higherbits) - (nbits)))) \ + | ((((__typeof (target)) (base)) \ + & (((__typeof (target)) 1 << (nbits)) - 1)) \ + << (sizeof (target) * 8 - (higherbits) - (nbits)))) /* Given a DWARF register number, fetch its intptr_t (long) value from the diff --git a/tapsets.cxx b/tapsets.cxx index 094ae358..c63151e1 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -2006,7 +2006,7 @@ struct dwflpp Dwarf_Die *die_mem, Dwarf_Attribute *attr_mem) { - Dwarf_Die *die = die_mem; + Dwarf_Die *die = NULL; Dwarf_Die struct_die; Dwarf_Attribute temp_attr; @@ -2015,6 +2015,9 @@ struct dwflpp if (vardie) *die_mem = *vardie; + if (e->components.empty()) + return die_mem; + static unsigned int func_call_level ; static unsigned int dwarf_error_flag ; // indicates current error is dwarf error static unsigned int dwarf_error_count ; // keeps track of no of dwarf errors @@ -2031,6 +2034,7 @@ struct dwflpp obstack_printf (pool, "c->last_stmt = %s;", lex_cast_qstring(piece).c_str()); #endif + die = die ? dwarf_formref_die (attr_mem, die_mem) : die_mem; const int typetag = dwarf_tag (die); switch (typetag) { @@ -2188,7 +2192,6 @@ struct dwflpp /* Now iterate on the type in DIE's attribute. */ if (dwarf_attr_integrate (die, DW_AT_type, attr_mem) == NULL) throw semantic_error ("cannot get type of field: " + string(dwarf_errmsg (-1)), e->tok); - die = dwarf_formref_die (attr_mem, die_mem); } return die; } diff --git a/testsuite/systemtap.base/bitfield.exp b/testsuite/systemtap.base/bitfield.exp new file mode 100644 index 00000000..16451369 --- /dev/null +++ b/testsuite/systemtap.base/bitfield.exp @@ -0,0 +1,3 @@ +# test that bitfield r/w works correctly +set test "bitfield" +stap_run $srcdir/$subdir/$test.stp no_load $all_pass_string -g diff --git a/testsuite/systemtap.base/bitfield.stp b/testsuite/systemtap.base/bitfield.stp new file mode 100644 index 00000000..c2ff4929 --- /dev/null +++ b/testsuite/systemtap.base/bitfield.stp @@ -0,0 +1,46 @@ +%{ +#include <linux/tcp.h> +static struct tcphdr foo = {0}; +%} + +function get_ptr:long() %{ THIS->__retvalue = (long)&foo; /* pure */ %} +function get_ack:long() %{ THIS->__retvalue = foo.ack; /* pure */ %} +function get_urg:long() %{ THIS->__retvalue = foo.urg; /* pure */ %} + +function check:long(ack:long, urg:long) { + ptr = get_ptr() + + /* set the bits with cast */ + @cast(ptr, "tcphdr")->ack = ack + @cast(ptr, "tcphdr")->urg = urg + + /* check that reading with embedded-C is ok */ + real_ack = get_ack() + real_urg = get_urg() + errors = (ack != real_ack) + (urg != real_urg) + + /* check that reading with a cast is ok */ + cast_ack = @cast(ptr, "tcphdr")->ack + cast_urg = @cast(ptr, "tcphdr")->urg + errors += (ack != cast_ack) + (urg != cast_urg) + + if (errors) + printf("bitfield had %d errors; expect(%d%d), real(%d%d), cast(%d%d)\n", + errors, ack, urg, real_ack, real_urg, cast_ack, cast_urg) + + return errors +} + +probe begin { + println("systemtap starting probe") + + errors = check(0, 0) + errors += check(0, 1) + errors += check(1, 0) + errors += check(1, 1) + + println("systemtap ending probe") + if (errors == 0) + println("systemtap test success") + exit() +} |