diff options
author | Josh Stone <jistone@redhat.com> | 2009-08-03 14:45:21 -0700 |
---|---|---|
committer | Josh Stone <jistone@redhat.com> | 2009-08-03 15:14:21 -0700 |
commit | 6fda2dff51c667a8c73545dd397b844108715310 (patch) | |
tree | b0a6be2e84f7a9ce8b0f72a3e9b4f2c329ac9ba2 /tapsets.cxx | |
parent | dc5a09fc9a61c8b33078164b6855dea54a33627c (diff) | |
download | systemtap-steved-6fda2dff51c667a8c73545dd397b844108715310.tar.gz systemtap-steved-6fda2dff51c667a8c73545dd397b844108715310.tar.xz systemtap-steved-6fda2dff51c667a8c73545dd397b844108715310.zip |
PR2049: support arbitrary $target-array indexing
Rather than just numeric literals, we can now support arbitrary
expressions for the index value. Note that loc2c won't allow this for
noncontiguous arrays, as the access methods need to be statically
computed, but for contiguous arrays and pointers-as-arrays it works
just fine.
* staptree.h (target_symbol::component): Add expression_array_index.
* staptree.cxx (target_symbol::visit_components): New helper.
(target_symbol::assert_no_components): Recognize new array type.
(target_symbol::component::print): Print subexpressions.
(traversing_visitor::visit_target_symbol, visit_cast_op): Visit the
indexing components too.
(varuse_collecting_visitor::visit_target_symbol): Ditto.
(update_visitor::visit_target_symbol, visit_cast_op): Ditto.
* elaborate.cxx (void_statement_reducer::visit_target_symbol): New.
(void_statement_reducer::visit_cast_op): Save indexes too.
* parse.cxx (parser::parse_target_symbol_components): Parse expressions.
* tapsets.cxx (dwarf_var_expanding_visitor::visit_target_symbol): Pass
expression-indexes as parameters (indexN) to the dwarf function.
(dwarf_cast_expanding_visitor::visit_cast_op): Ditto.
(tracepoint_var_expanding_visitor::visit_target_symbol_arg): Ditto.
(sdt_var_expanding_visitor::visit_target_symbol): Visit the new @cast.
* dwflpp.cxx (dwflpp::translate_components): Use THIS->indexN.
* translate.cxx (c_unparser::visit_target_symbol): Correct error msg.
* testsuite/systemtap.base/pointer_array.stp: Use a simple index.
Diffstat (limited to 'tapsets.cxx')
-rw-r--r-- | tapsets.cxx | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/tapsets.cxx b/tapsets.cxx index 537c33e7..ba344c51 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -2268,6 +2268,18 @@ dwarf_var_expanding_visitor::visit_target_symbol (target_symbol *e) fdecl->name = fname; fdecl->body = ec; + + // Any non-literal indexes need to be passed in too. + for (unsigned i = 0; i < e->components.size(); ++i) + if (e->components[i].type == target_symbol::comp_expression_array_index) + { + vardecl *v = new vardecl; + v->type = pe_long; + v->name = "index" + lex_cast<string>(i); + v->tok = e->tok; + fdecl->formal_args.push_back(v); + } + if (lvalue) { // Modify the fdecl so it carries a single pe_long formal @@ -2292,6 +2304,11 @@ dwarf_var_expanding_visitor::visit_target_symbol (target_symbol *e) n->function = fname; n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session + // Any non-literal indexes need to be passed in too. + for (unsigned i = 0; i < e->components.size(); ++i) + if (e->components[i].type == target_symbol::comp_expression_array_index) + n->args.push_back(require(e->components[i].expr_index)); + if (lvalue) { // Provide the functioncall to our parent, so that it can be @@ -2521,6 +2538,17 @@ void dwarf_cast_expanding_visitor::visit_cast_op (cast_op* e) v1->tok = e->tok; fdecl->formal_args.push_back(v1); + // Any non-literal indexes need to be passed in too. + for (unsigned i = 0; i < e->components.size(); ++i) + if (e->components[i].type == target_symbol::comp_expression_array_index) + { + vardecl *v = new vardecl; + v->type = pe_long; + v->name = "index" + lex_cast<string>(i); + v->tok = e->tok; + fdecl->formal_args.push_back(v); + } + if (lvalue) { // Modify the fdecl so it carries a second pe_long formal @@ -2549,6 +2577,11 @@ void dwarf_cast_expanding_visitor::visit_cast_op (cast_op* e) n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session n->args.push_back(e->operand); + // Any non-literal indexes need to be passed in too. + for (unsigned i = 0; i < e->components.size(); ++i) + if (e->components[i].type == target_symbol::comp_expression_array_index) + n->args.push_back(require(e->components[i].expr_index)); + if (lvalue) { // Provide the functioncall to our parent, so that it can be @@ -3277,7 +3310,7 @@ sdt_var_expanding_visitor::visit_target_symbol (target_symbol *e) cast->type = probe_name + "_arg" + lex_cast<string>(argno); cast->module = process_name; - provide(cast); + cast->visit(this); } @@ -5327,6 +5360,17 @@ tracepoint_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e) v1->tok = e->tok; fdecl->formal_args.push_back(v1); + // Any non-literal indexes need to be passed in too. + for (unsigned i = 0; i < e->components.size(); ++i) + if (e->components[i].type == target_symbol::comp_expression_array_index) + { + vardecl *v = new vardecl; + v->type = pe_long; + v->name = "index" + lex_cast<string>(i); + v->tok = e->tok; + fdecl->formal_args.push_back(v); + } + if (lvalue) { // Modify the fdecl so it carries a pe_long formal @@ -5354,10 +5398,16 @@ tracepoint_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e) n->function = fname; n->referent = 0; // NB: must not resolve yet, to ensure inclusion in session - // make the original a bare target symbol for the tracepoint value, - // which will be passed into the dwarf dereferencing code - e->components.clear(); - n->args.push_back(require(e)); + // make a copy of the original as a bare target symbol for the tracepoint + // value, which will be passed into the dwarf dereferencing code + target_symbol* e2 = deep_copy_visitor::deep_copy(e); + e2->components.clear(); + n->args.push_back(require(e2)); + + // Any non-literal indexes need to be passed in too. + for (unsigned i = 0; i < e->components.size(); ++i) + if (e->components[i].type == target_symbol::comp_expression_array_index) + n->args.push_back(require(e->components[i].expr_index)); if (lvalue) { |