From 5e8208c0c3012c3f2b0215385c2b02422c2e4769 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 9 Jun 2009 08:54:59 -0700 Subject: Fix uninitialized shdr in probe_table (redo commit 3d022fa9c6bdbca383dfc639d08d65287c708f56) * tapsets.cxx (dwarf_builder::probe_table::probe_table): gcc 4.4 complains that shdr may be used uninitialized. I added returns to ensure that it's ok, but gcc still complains. Set the thing to NULL as well to silence the beast. --- tapsets.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index b684adc2..4b8d9a13 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -689,7 +689,7 @@ dwarf_builder::probe_table::probe_table(string& mark_name, systemtap_session & s { Elf* elf; GElf_Shdr shdr_mem; - GElf_Shdr *shdr; + GElf_Shdr *shdr = NULL; Dwarf_Addr bias; size_t shstrndx; @@ -713,6 +713,9 @@ dwarf_builder::probe_table::probe_table(string& mark_name, systemtap_session & s break; } } + + if (!have_probes) + return; // Older versions put .probes section in the debuginfo dwarf file, // so check if it actually exists, if not take the main elf file @@ -721,6 +724,7 @@ dwarf_builder::probe_table::probe_table(string& mark_name, systemtap_session & s elf = dwfl_module_getelf (dw->module, &bias); dwfl_assert ("getshstrndx", elf_getshstrndx (elf, &shstrndx)); probe_scn = NULL; + have_probes = false; while ((probe_scn = elf_nextscn (elf, probe_scn))) { shdr = gelf_getshdr (probe_scn, &shdr_mem); @@ -731,6 +735,9 @@ dwarf_builder::probe_table::probe_table(string& mark_name, systemtap_session & s } } + if (!have_probes) + return; + pdata = elf_getdata_rawchunk (elf, shdr->sh_offset, shdr->sh_size, ELF_T_BYTE); probe_scn_offset = 0; probe_scn_addr = shdr->sh_addr; -- cgit From 56e33af59ec3003a1559a052fb1936647c01580c Mon Sep 17 00:00:00 2001 From: Stan Cox Date: Tue, 9 Jun 2009 17:05:53 -0400 Subject: * tapsets.cxx (sdt_var_expanding_visitor::process_name): New. (sdt_var_expanding_visitor::visit_target_symbol): Have @cast use types from a dtrace built object instead of a dtrace supplied header. (dwarf_builder::build): Use it. --- tapsets.cxx | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index 4b8d9a13..4aae1aa6 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -3195,12 +3195,13 @@ dwarf_derived_probe_group::emit_module_exit (systemtap_session& s) struct sdt_var_expanding_visitor: public var_expanding_visitor { - sdt_var_expanding_visitor(dwflpp& dw, string& probe_name, + sdt_var_expanding_visitor(dwflpp& dw, string & process_name, string & probe_name, int arg_count, bool have_reg_args): - dw (dw), probe_name (probe_name), have_reg_args (have_reg_args), - arg_count (arg_count) {} - dwflpp& dw; - string probe_name; + dw (dw), process_name (process_name), probe_name (probe_name), + have_reg_args (have_reg_args), arg_count (arg_count) {} + dwflpp & dw; + string & process_name; + string & probe_name; bool have_reg_args; int arg_count; @@ -3272,11 +3273,7 @@ sdt_var_expanding_visitor::visit_target_symbol (target_symbol *e) cast->operand = fc; cast->components = e->components; cast->type = probe_name + "_arg" + lex_cast(argno); - string sdt_include_path = ""; - for (unsigned int i = 0; i < dw.sess.args.size(); i++) - if (dw.sess.args[i].find("isdt=") == 0) - sdt_include_path = dw.sess.args[i].substr(5); - cast->module = "<" + sdt_include_path + ">"; + cast->module = process_name; dwarf_builder *db = new dwarf_builder(); dwarf_cast_expanding_visitor *v = new dwarf_cast_expanding_visitor(this->dw.sess, *db); v->visit_cast_op(cast); @@ -3320,6 +3317,8 @@ dwarf_builder::build(systemtap_session & sess, { string mark_name; assert (get_param(parameters, TOK_MARK, mark_name)); + string process_name; + assert (get_param(parameters, TOK_PROCESS, process_name)); probe_table probe_table(mark_name, sess, dw, location); if (! probe_table.get_next_probe()) return; @@ -3351,7 +3350,7 @@ dwarf_builder::build(systemtap_session & sess, << hex << probe_table.probe_arg << dec << endl; // Now expand the local variables in the probe body - sdt_var_expanding_visitor svv (*dw, probe_table.mark_name, + sdt_var_expanding_visitor svv (*dw, process_name, probe_table.mark_name, probe_table.probe_arg, false); new_base->body = svv.require (new_base->body); @@ -3408,7 +3407,7 @@ dwarf_builder::build(systemtap_session & sess, b->statements.insert(b->statements.begin(),(statement*) is); // Now expand the local variables in the probe body - sdt_var_expanding_visitor svv (*dw, probe_table.mark_name, + sdt_var_expanding_visitor svv (*dw, process_name, probe_table.mark_name, probe_table.probe_arg, true); new_base->body = svv.require (new_base->body); new_location->components[0]->functor = "kernel"; @@ -3483,7 +3482,7 @@ dwarf_builder::build(systemtap_session & sess, b->statements.insert(b->statements.begin(),(statement*) is); // Now expand the local variables in the probe body - sdt_var_expanding_visitor svv (*dw, probe_table.mark_name, + sdt_var_expanding_visitor svv (*dw, process_name, probe_table.mark_name, probe_table.probe_arg, true); new_base->body = svv.require (new_base->body); -- cgit From 3e1e31fbbbd19b9175b2fd0ed74e5e0dc7ba2673 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 9 Jun 2009 16:34:38 -0700 Subject: Simplify process.mark parameter parsing This just makes it so the parameters only need to be checked and pulled out once. --- tapsets.cxx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index 4aae1aa6..9ded301d 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -3313,12 +3313,9 @@ dwarf_builder::build(systemtap_session & sess, if (sess.verbose > 3) clog << "dwarf_builder::build for " << module_name << endl; - if (((probe_point::component*)(location->components[1]))->functor == TOK_MARK) + string mark_name; + if (get_param(parameters, TOK_MARK, mark_name)) { - string mark_name; - assert (get_param(parameters, TOK_MARK, mark_name)); - string process_name; - assert (get_param(parameters, TOK_PROCESS, process_name)); probe_table probe_table(mark_name, sess, dw, location); if (! probe_table.get_next_probe()) return; @@ -3350,7 +3347,7 @@ dwarf_builder::build(systemtap_session & sess, << hex << probe_table.probe_arg << dec << endl; // Now expand the local variables in the probe body - sdt_var_expanding_visitor svv (*dw, process_name, probe_table.mark_name, + sdt_var_expanding_visitor svv (*dw, module_name, probe_table.mark_name, probe_table.probe_arg, false); new_base->body = svv.require (new_base->body); @@ -3407,7 +3404,7 @@ dwarf_builder::build(systemtap_session & sess, b->statements.insert(b->statements.begin(),(statement*) is); // Now expand the local variables in the probe body - sdt_var_expanding_visitor svv (*dw, process_name, probe_table.mark_name, + sdt_var_expanding_visitor svv (*dw, module_name, probe_table.mark_name, probe_table.probe_arg, true); new_base->body = svv.require (new_base->body); new_location->components[0]->functor = "kernel"; @@ -3482,7 +3479,7 @@ dwarf_builder::build(systemtap_session & sess, b->statements.insert(b->statements.begin(),(statement*) is); // Now expand the local variables in the probe body - sdt_var_expanding_visitor svv (*dw, process_name, probe_table.mark_name, + sdt_var_expanding_visitor svv (*dw, module_name, probe_table.mark_name, probe_table.probe_arg, true); new_base->body = svv.require (new_base->body); -- cgit From 18247b09c99a85b7600abfca48a21818a78a9e97 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 9 Jun 2009 16:37:14 -0700 Subject: Remove the spurious sdt @cast expansion The result of sdt's private @cast expansion was not being used, and it's not really needed anyway. The global cast visitor is registered to run as a post-processing step on ALL functions and probes, and so it will pick up and expand sdt's casts too. --- tapsets.cxx | 3 --- 1 file changed, 3 deletions(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index 9ded301d..71456ab6 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -3274,9 +3274,6 @@ sdt_var_expanding_visitor::visit_target_symbol (target_symbol *e) cast->components = e->components; cast->type = probe_name + "_arg" + lex_cast(argno); cast->module = process_name; - dwarf_builder *db = new dwarf_builder(); - dwarf_cast_expanding_visitor *v = new dwarf_cast_expanding_visitor(this->dw.sess, *db); - v->visit_cast_op(cast); provide(cast); } -- cgit From 9f02b156fd0b57a57f8d4985cdd2902a6ee920cb Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 9 Jun 2009 16:41:30 -0700 Subject: Remove sdt_var_expanding_visitor's now-unused dw --- tapsets.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index 71456ab6..61962b3d 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -3195,11 +3195,10 @@ dwarf_derived_probe_group::emit_module_exit (systemtap_session& s) struct sdt_var_expanding_visitor: public var_expanding_visitor { - sdt_var_expanding_visitor(dwflpp& dw, string & process_name, string & probe_name, + sdt_var_expanding_visitor(string & process_name, string & probe_name, int arg_count, bool have_reg_args): - dw (dw), process_name (process_name), probe_name (probe_name), + process_name (process_name), probe_name (probe_name), have_reg_args (have_reg_args), arg_count (arg_count) {} - dwflpp & dw; string & process_name; string & probe_name; bool have_reg_args; @@ -3344,7 +3343,7 @@ dwarf_builder::build(systemtap_session & sess, << hex << probe_table.probe_arg << dec << endl; // Now expand the local variables in the probe body - sdt_var_expanding_visitor svv (*dw, module_name, probe_table.mark_name, + sdt_var_expanding_visitor svv (module_name, probe_table.mark_name, probe_table.probe_arg, false); new_base->body = svv.require (new_base->body); @@ -3401,7 +3400,7 @@ dwarf_builder::build(systemtap_session & sess, b->statements.insert(b->statements.begin(),(statement*) is); // Now expand the local variables in the probe body - sdt_var_expanding_visitor svv (*dw, module_name, probe_table.mark_name, + sdt_var_expanding_visitor svv (module_name, probe_table.mark_name, probe_table.probe_arg, true); new_base->body = svv.require (new_base->body); new_location->components[0]->functor = "kernel"; @@ -3476,7 +3475,7 @@ dwarf_builder::build(systemtap_session & sess, b->statements.insert(b->statements.begin(),(statement*) is); // Now expand the local variables in the probe body - sdt_var_expanding_visitor svv (*dw, module_name, probe_table.mark_name, + sdt_var_expanding_visitor svv (module_name, probe_table.mark_name, probe_table.probe_arg, true); new_base->body = svv.require (new_base->body); -- cgit From 59d00eb0920ca89f67704e0f0bf0aa3074abb328 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 9 Jun 2009 16:47:17 -0700 Subject: Remove probe_table's unused location member --- tapsets.cxx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index 61962b3d..64657454 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -670,22 +670,21 @@ struct dwarf_builder: public derived_probe_builder __uint64_t probe_arg; string & mark_name; string probe_name; - probe_table(string & mark_name, systemtap_session & sess, dwflpp * dw, probe_point * location); + probe_table(string & mark_name, systemtap_session & sess, dwflpp * dw); bool get_next_probe(); private: bool have_probes; systemtap_session & sess; dwflpp* dw; - probe_point* location; Elf_Data *pdata; size_t probe_scn_offset; size_t probe_scn_addr; }; }; -dwarf_builder::probe_table::probe_table(string& mark_name, systemtap_session & sess, dwflpp* dw, probe_point* location): - mark_name(mark_name), sess(sess), dw(dw), location(location) +dwarf_builder::probe_table::probe_table(string& mark_name, systemtap_session & sess, dwflpp* dw): + mark_name(mark_name), sess(sess), dw(dw) { Elf* elf; GElf_Shdr shdr_mem; @@ -3312,7 +3311,7 @@ dwarf_builder::build(systemtap_session & sess, string mark_name; if (get_param(parameters, TOK_MARK, mark_name)) { - probe_table probe_table(mark_name, sess, dw, location); + probe_table probe_table(mark_name, sess, dw); if (! probe_table.get_next_probe()) return; -- cgit From a8ec77194e89a8e685c7f44260be75a632254eaa Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 9 Jun 2009 17:04:40 -0700 Subject: Add bounds-checking to sdt $argN --- tapsets.cxx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tapsets.cxx') diff --git a/tapsets.cxx b/tapsets.cxx index 64657454..3ecf2250 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -3197,7 +3197,10 @@ struct sdt_var_expanding_visitor: public var_expanding_visitor sdt_var_expanding_visitor(string & process_name, string & probe_name, int arg_count, bool have_reg_args): process_name (process_name), probe_name (probe_name), - have_reg_args (have_reg_args), arg_count (arg_count) {} + have_reg_args (have_reg_args), arg_count (arg_count) + { + assert(!have_reg_args || (arg_count >= 0 && arg_count <= 10)); + } string & process_name; string & probe_name; bool have_reg_args; @@ -3221,13 +3224,14 @@ sdt_var_expanding_visitor::visit_target_symbol (target_symbol *e) provide(e); return; } - + + int argno = lex_cast(e->base_name.substr(4)); + if (argno < 1 || argno > arg_count) + throw semantic_error ("invalid argument number", e->tok); + bool lvalue = is_active_lvalue(e); - string argname = e->base_name.substr(1); functioncall *fc = new functioncall; - int argno = lex_cast(argname.substr(3)); - if (arg_count < 6) { fc->function = "ulong_arg"; -- cgit