From 45582cbc9e54546d119e82dd4734c56d166ea642 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 16 Apr 2014 10:51:24 -0400 Subject: [PATCH] gut out dwflpp::iterate_over_srcfile_lines() To prepare for the new code, we empty out iterate_over_srcfile_lines() and remove associated functions. This is also where we break the link between dwflpp and dwarf_query (the original issue mentioned in PR16615). --- dwflpp.cxx | 231 +--------------------------------------------------- dwflpp.h | 8 -- tapsets.cxx | 21 +---- 3 files changed, 4 insertions(+), 256 deletions(-) diff --git a/dwflpp.cxx b/dwflpp.cxx index 27d8613d6..d8c71c532 100644 --- a/dwflpp.cxx +++ b/dwflpp.cxx @@ -1481,74 +1481,6 @@ dwflpp::iterate_over_plt(void *object, void (*callback)(void*, } -// This little test routine represents an unfortunate breakdown in -// abstraction between dwflpp (putatively, a layer right on top of -// elfutils), and dwarf_query (interpreting a systemtap probe point). -// It arises because we sometimes try to fix up slightly-off -// .statement() probes (something we find out in fairly low-level). -// -// An alternative would be to put some more intelligence into query_cu(), -// and have it print additional suggestions after finding that -// q->dw.iterate_over_srcfile_lines resulted in no new finished_results. - -bool -dwflpp::has_single_line_record (dwarf_query * q, char const * srcfile, int lineno) -{ - if (lineno < 0) - return false; - - Dwarf_Line **srcsp = NULL; - size_t nsrcs = 0; - - dwarf_assert ("dwarf_getsrc_file", - dwarf_getsrc_file (module_dwarf, - srcfile, lineno, 0, - &srcsp, &nsrcs)); - - if (nsrcs != 1) - { - if (sess.verbose>4) - clog << _F("alternative line %d rejected: nsrcs=%zu", lineno, nsrcs) << endl; - return false; - } - - // We also try to filter out lines that leave the selected - // functions (if any). - - dwarf_line_t line(srcsp[0]); - Dwarf_Addr addr = line.addr(); - - func_info_map_t *filtered_functions = get_filtered_functions(q); - for (func_info_map_t::iterator i = filtered_functions->begin(); - i != filtered_functions->end(); ++i) - { - if (die_has_pc (i->die, addr)) - { - if (sess.verbose>4) - clog << _F("alternative line %d accepted: fn=%s", lineno, i->name.c_str()) << endl; - return true; - } - } - - inline_instance_map_t *filtered_inlines = get_filtered_inlines(q); - for (inline_instance_map_t::iterator i = filtered_inlines->begin(); - i != filtered_inlines->end(); ++i) - { - if (die_has_pc (i->die, addr)) - { - if (sess.verbose>4) - clog << _F("alternative line %d accepted: ifn=%s", lineno, i->name.c_str()) << endl; - return true; - } - } - - if (sess.verbose>4) - //TRANSLATORS: given line number leaves (is beyond) given function. - clog << _F("alternative line %d rejected: leaves selected fns", lineno) << endl; - return false; -} - - template<> void dwflpp::iterate_over_srcfile_lines(char const * srcfile, int linenos[2], @@ -1559,168 +1491,7 @@ dwflpp::iterate_over_srcfile_lines(char const * srcfile, const std::string& func_pattern, void *data) { - Dwarf_Line **srcsp = NULL; - size_t nsrcs = 0; - // XXX: MUST GET RID OF THIS (see also comment block before - // has_single_line_record()) - dwarf_query * q = static_cast(data); - int lineno = linenos[0]; - auto_free_ref free_srcsp(srcsp); - - get_module_dwarf(); - if (!this->function) - return; - - if (lineno_type == RELATIVE) - { - Dwarf_Addr addr; - Dwarf_Line *line; - int line_number; - - if (!die_entrypc(this->function, &addr)) - return; - - if (addr != 0) - { - line = dwarf_getsrc_die (this->cu, addr); - dwarf_assert ("dwarf_getsrc_die", line == NULL); - dwarf_assert ("dwarf_lineno", dwarf_lineno (line, &line_number)); - } - else if (dwarf_decl_line (this->function, &line_number) != 0) - { - // use DW_AT_decl_line as a fallback method - Dwarf_Attribute type_attr; - Dwarf_Word constant; - if (dwarf_attr_integrate (this->function, DW_AT_decl_line, &type_attr)) - { - dwarf_formudata (&type_attr, &constant); - line_number = constant; - } - else - return; - } - lineno += line_number; - } - else if (lineno_type == WILDCARD) { - if (name_has_wildcard(func_pattern)) /* PR14774: look at whole file if function name is wildcard */ - lineno = 0; - else - function_line (&lineno); - } - else if (lineno_type == RANGE) { /* correct lineno */ - int start_lineno; - - if (name_has_wildcard(func_pattern)) /* PR10294: wider range like statement("*@foo.c") */ - start_lineno = lineno; - else - function_line (&start_lineno); - lineno = lineno < start_lineno ? start_lineno : lineno; - if (lineno > linenos[1]) { /* invalid line range */ - stringstream advice; - advice << _("Invalid line range (") << linenos[0] << "-" << linenos[1] << ")"; - if (start_lineno > linenos[1]) - advice << _(", the end line number ") << linenos[1] << " < " << start_lineno; - throw SEMANTIC_ERROR (advice.str()); - } - } - - - for (int l = lineno; ; l = l + 1) - { - set lines_probed; - pair::iterator,bool> line_probed; - int ret = 0; - - assert_no_interrupts(); - - nsrcs = 0; - ret = dwarf_getsrc_file (module_dwarf, srcfile, l, 0, - &srcsp, &nsrcs); - if (ret != 0) /* tolerate invalid line number */ - break; - - if (lineno_type == WILDCARD || lineno_type == RANGE) - { - Dwarf_Addr line_addr; - - dwarf_lineno (srcsp [0], &lineno); - /* Maybe lineno will exceed the input end */ - if (lineno_type == RANGE && lineno > linenos[1]) - break; - line_probed = lines_probed.insert(lineno); - if (lineno != l || line_probed.second == false || nsrcs > 1) - continue; - dwarf_lineaddr (srcsp [0], &line_addr); - if (!function_name_matches(func_pattern) && dwarf_haspc (function, line_addr) != 1) - break; - } - - // NB: Formerly, we used to filter, because: - - // dwarf_getsrc_file gets one *near hits* for line numbers, not - // exact matches. For example, an existing file but a nonexistent - // line number will be rounded up to the next definition in that - // file. This may be similar to the GDB breakpoint algorithm, but - // we don't want to be so fuzzy in systemtap land. So we filter. - - // But we now see the error of our ways, and skip this filtering. - - // XXX: the code also fails to match e.g. inline function - // definitions when the srcfile is a header file rather than the - // CU name. - - size_t remaining_nsrcs = nsrcs; - - if (need_single_match && remaining_nsrcs > 1) - { - // We wanted a single line record (a unique address for the - // line) and we got a bunch of line records. We're going to - // skip this probe (throw an exception) but before we throw - // we're going to look around a bit to see if there's a low or - // high line number nearby which *doesn't* have this problem, - // so we can give the user some advice. - - int lo_try = -1; - int hi_try = -1; - for (size_t i = 1; i < 6; ++i) - { - if (lo_try == -1 && has_single_line_record(q, srcfile, lineno - i)) - lo_try = lineno - i; - - if (hi_try == -1 && has_single_line_record(q, srcfile, lineno + i)) - hi_try = lineno + i; - } - - stringstream advice; - advice << _F("multiple addresses for %s:%d [man error::dwarf]", srcfile, lineno); - if (lo_try > 0 || hi_try > 0) - { - //TRANSLATORS: Here we are trying to advise what source file - //TRANSLATORS: to attempt. - advice << _(" (try "); - if (lo_try > 0) - advice << srcfile << ":" << lo_try; - if (lo_try > 0 && hi_try > 0) - advice << _(" or "); - if (hi_try > 0) - advice << srcfile << ":" << hi_try; - advice << ")"; - } - throw SEMANTIC_ERROR (advice.str()); - } - - for (size_t i = 0; i < nsrcs; ++i) - { - assert_no_interrupts(); - if (srcsp [i]) // skip over mismatched lines - callback (dwarf_line_t(srcsp[i]), data); - } - - if (lineno_type == ABSOLUTE || lineno_type == RELATIVE) - break; - else if (lineno_type == RANGE && l == linenos[1]) - break; - } + throw SEMANTIC_ERROR("under construction"); } diff --git a/dwflpp.h b/dwflpp.h index d78896e6c..2707b80e1 100644 --- a/dwflpp.h +++ b/dwflpp.h @@ -35,7 +35,6 @@ struct func_info; struct inline_instance_info; struct symbol_table; struct base_query; -struct dwarf_query; struct external_function_query; enum lineno_t { ABSOLUTE, RELATIVE, RANGE, WILDCARD }; @@ -79,11 +78,6 @@ typedef std::vector func_info_map_t; typedef std::vector inline_instance_map_t; -/* XXX FIXME functions that dwflpp needs from tapsets.cxx */ -func_info_map_t *get_filtered_functions(dwarf_query *q); -inline_instance_map_t *get_filtered_inlines(dwarf_query *q); - - struct module_info { @@ -521,8 +515,6 @@ private: static int external_function_cu_callback (Dwarf_Die* cu, external_function_query *efq); static int external_function_func_callback (Dwarf_Die* func, external_function_query *efq); - bool has_single_line_record (dwarf_query * q, char const * srcfile, int lineno); - static void loc2c_error (void *, const char *fmt, ...) __attribute__ ((noreturn)); // This function generates code used for addressing computations of diff --git a/tapsets.cxx b/tapsets.cxx index eb1b75577..182489651 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -405,10 +405,6 @@ static const string TOK_CLASS("class");; static const string TOK_CALLEE("callee");; static const string TOK_CALLEES("callees");; -static int query_cu (Dwarf_Die * cudie, dwarf_query *q); -static void query_addr(Dwarf_Addr addr, dwarf_query *q); -static void query_plt_statement(dwarf_query *q); - // Can we handle this query with just symbol-table info? enum dbinfo_reqt { @@ -424,6 +420,9 @@ struct dwarf_query; struct dwflpp; struct symbol_table; +static int query_cu (Dwarf_Die * cudie, dwarf_query *q); +static void query_addr(Dwarf_Addr addr, dwarf_query *q); +static void query_plt_statement(dwarf_query *q); struct symbol_table @@ -963,20 +962,6 @@ dwarf_query::dwarf_query(probe * base_probe, } -func_info_map_t * -get_filtered_functions(dwarf_query *q) -{ - return &q->filtered_functions; -} - - -inline_instance_map_t * -get_filtered_inlines(dwarf_query *q) -{ - return &q->filtered_inlines; -} - - void dwarf_query::query_module_dwarf() { -- 2.43.5