From: Josh Stone Date: Thu, 17 Sep 2009 23:37:36 +0000 (-0700) Subject: Map std semaphores from probe->addr X-Git-Tag: release-1.0~26 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=4ddb6dd03ee4364bdb36bc32888846faad48a080;p=systemtap.git Map std semaphores from probe->addr Each probe needs to know the associated semaphore address, rather than the other way around. * session.h (sdt_semaphore_addr): Reverse the key-value types. * tapsets.cxx (record_semaphore): Take an index to only record the semaphore for newly added results. (sdt_query::handle_query_module): Adjust accordingly. (uprobe_derived_probe_group::emit_module_decls): Now it's a simple map lookup for sdt_sem_address. * tapset-utrace.cxx (utrace_derived_probe_group::emit_probe_decl): Ditto. --- diff --git a/session.h b/session.h index 4f5097143..760b610ab 100644 --- a/session.h +++ b/session.h @@ -223,7 +223,7 @@ struct systemtap_session // Location of semaphores to activate sdt probes - std::map sdt_semaphore_addr; + std::map sdt_semaphore_addr; // NB: It is very important for all of the above (and below) fields // to be cleared in the systemtap_session ctor (elaborate.cxx) diff --git a/tapset-utrace.cxx b/tapset-utrace.cxx index 639f0c209..9e5ce939b 100644 --- a/tapset-utrace.cxx +++ b/tapset-utrace.cxx @@ -716,20 +716,14 @@ utrace_derived_probe_group::emit_probe_decl (systemtap_session& s, break; } s.op->line() << " .engine_attached=0,"; - map::iterator its; - if (s.sdt_semaphore_addr.empty()) + + map::iterator its = s.sdt_semaphore_addr.find(p); + if (its == s.sdt_semaphore_addr.end()) s.op->line() << " .sdt_sem_address=(unsigned long)0x0,"; else - for (its = s.sdt_semaphore_addr.begin(); - its != s.sdt_semaphore_addr.end(); - its++) - { - if (p == ((struct utrace_derived_probe*)(its->second))) - { - s.op->line() << " .sdt_sem_address=(unsigned long)0x" << hex << its->first << dec << "ULL,"; - break; - } - } + s.op->line() << " .sdt_sem_address=(unsigned long)0x" + << hex << its->second << dec << "ULL,"; + s.op->line() << " .tsk=0,"; s.op->line() << " },"; } diff --git a/tapsets.cxx b/tapsets.cxx index 53f8ace59..4bede3c9b 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -3509,7 +3509,7 @@ private: bool get_next_probe(); void convert_probe(probe *base); - void record_semaphore(vector & results); + void record_semaphore(vector & results, unsigned start); void convert_location(probe *base, probe_point *location); }; @@ -3560,11 +3560,8 @@ sdt_query::handle_query_module() unsigned i = results.size(); if (probe_type == kprobe_type || probe_type == utrace_type) - { - derive_probes(sess, new_base, results); - record_semaphore(results); - } - + derive_probes(sess, new_base, results); + else { literal_map_t params; @@ -3577,9 +3574,10 @@ sdt_query::handle_query_module() dwarf_query q(new_base, new_location, dw, params, results); q.has_mark = true; // enables mid-statement probing dw.iterate_over_modules(&query_module, &q); - record_semaphore(results); } + record_semaphore(results, i); + if (sess.listing_mode) { // restore the locations to print a nicer probe name @@ -3709,7 +3707,7 @@ sdt_query::get_next_probe() void -sdt_query::record_semaphore (vector & results) +sdt_query::record_semaphore (vector & results, unsigned start) { int sym_count = dwfl_module_getsymtab(dw.module); assert (sym_count >= 0); @@ -3722,8 +3720,8 @@ sdt_query::record_semaphore (vector & results) { string process_name; derived_probe_builder::get_param(params, TOK_PROCESS, process_name); - for (unsigned int i = 0; i < results.size(); ++i) - sess.sdt_semaphore_addr.insert(make_pair(sym.st_value, results[i])); + for (unsigned i = start; i < results.size(); ++i) + sess.sdt_semaphore_addr.insert(make_pair(results[i], sym.st_value)); break; } } @@ -4471,22 +4469,16 @@ uprobe_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->line() << " .address=(unsigned long)0x" << hex << p->addr << dec << "ULL,"; s.op->line() << " .pp=" << lex_cast_qstring (*p->sole_location()) << ","; s.op->line() << " .ph=&" << p->name << ","; - map::iterator its; - if (s.sdt_semaphore_addr.empty()) + + map::iterator its = s.sdt_semaphore_addr.find(p); + if (its == s.sdt_semaphore_addr.end()) s.op->line() << " .sdt_sem_address=(unsigned long)0x0,"; else - for (its = s.sdt_semaphore_addr.begin(); - its != s.sdt_semaphore_addr.end(); - its++) - { - if (p->module == ((struct uprobe_derived_probe*)(its->second))->module - && p->addr == ((struct uprobe_derived_probe*)(its->second))->addr) - { - s.op->line() << " .sdt_sem_address=(unsigned long)0x" << hex << its->first << dec << "ULL,"; - break; - } - } - if (p->has_return) s.op->line() << " .return_p=1,"; + s.op->line() << " .sdt_sem_address=(unsigned long)0x" + << hex << its->second << dec << "ULL,"; + + if (p->has_return) + s.op->line() << " .return_p=1,"; s.op->line() << " },"; } s.op->newline(-1) << "};";