From: Philippe Waroquiers Date: Sat, 12 Nov 2016 22:55:35 +0000 (+0000) Subject: Fix sym name cache: handles the difference between text and data, + match in symbol X-Git-Tag: svn/VALGRIND_3_13_0~285 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7646bee8ede19ec5b9bedbb3e2cdf94e1db3b2f2;p=thirdparty%2Fvalgrind.git Fix sym name cache: handles the difference between text and data, + match in symbol * sym name cache to cache the 'isText' characteristic of the cached sym_name * implement the match anywhere also in the cache Not handling matchAnywhere has bad performance effect on callgrind, as almost many IPs were considered as a fn entry, while they were not. * use the same convention to name the findText argument git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16136 --- diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index 557f015fae..0a1cddee08 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -1646,7 +1646,6 @@ void VG_(delete_IIPC)(InlIPCursor *iipc) */ static void search_all_symtabs ( Addr ptr, /*OUT*/DebugInfo** pdi, /*OUT*/Word* symno, - Bool match_anywhere_in_sym, Bool findText ) { Word sno; @@ -1690,8 +1689,7 @@ static void search_all_symtabs ( Addr ptr, /*OUT*/DebugInfo** pdi, if (!inRange) continue; - sno = ML_(search_one_symtab) ( - di, ptr, match_anywhere_in_sym, findText ); + sno = ML_(search_one_symtab) ( di, ptr, findText ); if (sno == -1) goto not_found; *symno = sno; *pdi = di; @@ -1733,7 +1731,12 @@ static void search_all_loctabs ( Addr ptr, /*OUT*/DebugInfo** pdi, #define N_SYM_NAME_CACHE 509 typedef - struct { Addr sym_avma; const HChar* sym_name; PtrdiffT offset; } + struct { + Addr sym_avma; + const HChar* sym_name; + PtrdiffT offset : (sizeof(PtrdiffT)*8)-1; + Bool isText : 1; + } Sym_Name_CacheEnt; /* Sym_Name_CacheEnt associates a queried address to the sym name found. By nature, if a sym name was found, it means the searched address @@ -1783,12 +1786,13 @@ Bool get_sym_name ( Bool do_cxx_demangling, Bool do_z_demangling, UWord hash = a % N_SYM_NAME_CACHE; Sym_Name_CacheEnt* se = &sym_name_cache[hash]; - if (UNLIKELY(se->sym_avma != a)) { + if (UNLIKELY(se->sym_avma != a || se->isText != findText)) { DebugInfo* di; Word sno; - search_all_symtabs ( a, &di, &sno, match_anywhere_in_sym, findText ); + search_all_symtabs ( a, &di, &sno, findText ); se->sym_avma = a; + se->isText = findText; if (di == NULL || a == 0) se->sym_name = no_sym_name; else { @@ -1798,7 +1802,8 @@ Bool get_sym_name ( Bool do_cxx_demangling, Bool do_z_demangling, } } - if (se->sym_name == no_sym_name) { + if (se->sym_name == no_sym_name + || (!match_anywhere_in_sym && se->offset != 0)) { *buf = ""; return False; } @@ -1834,7 +1839,7 @@ Bool get_sym_name ( Bool do_cxx_demangling, Bool do_z_demangling, VG_(strcpy)(bufwo, *buf); VG_(sprintf)(bufwo + len, "%c%ld", se->offset < 0 ? '-' : '+', - se->offset < 0 ? -se->offset : se->offset); + (PtrdiffT) (se->offset < 0 ? -se->offset : se->offset)); *buf = bufwo; } @@ -1851,7 +1856,6 @@ Addr VG_(get_tocptr) ( Addr guest_code_addr ) Word sno; search_all_symtabs ( guest_code_addr, &si, &sno, - True/*match_anywhere_in_fun*/, True/*consider text symbols only*/ ); if (si == NULL) return 0; @@ -1873,7 +1877,7 @@ Bool VG_(get_fnname) ( Addr a, const HChar** buf ) a, buf, /*match_anywhere_in_fun*/True, /*show offset?*/False, - /*text syms only*/True, + /*text sym*/True, /*offsetP*/NULL ); } @@ -1888,7 +1892,7 @@ Bool VG_(get_fnname_w_offset) ( Addr a, const HChar** buf ) a, buf, /*match_anywhere_in_fun*/True, /*show offset?*/True, - /*text syms only*/True, + /*text sym*/True, /*offsetP*/NULL ); } @@ -1907,7 +1911,7 @@ Bool VG_(get_fnname_if_entry) ( Addr a, const HChar** buf ) a, &tmp, /*match_anywhere_in_fun*/False, /*show offset?*/False, - /*text syms only*/True, + /*text sym*/True, /*offsetP*/NULL ); if (res) *buf = tmp; @@ -1926,7 +1930,7 @@ Bool VG_(get_fnname_raw) ( Addr a, const HChar** buf ) a, buf, /*match_anywhere_in_fun*/True, /*show offset?*/False, - /*text syms only*/True, + /*text sym*/True, /*offsetP*/NULL ); } @@ -1945,7 +1949,7 @@ Bool VG_(get_fnname_no_cxx_demangle) ( Addr a, const HChar** buf, a, buf, /*match_anywhere_in_fun*/True, /*show offset?*/False, - /*text syms only*/True, + /*text sym*/True, /*offsetP*/NULL ); } else { const DiInlLoc *next_inl = iipc && iipc->next_inltab >= 0 @@ -1970,7 +1974,7 @@ Bool VG_(get_inst_offset_in_function)( Addr a, a, &fnname, /*match_anywhere_in_sym*/True, /*show offset?*/False, - /*text syms only*/True, + /*text sym*/True, offset ); } @@ -2027,7 +2031,7 @@ Bool VG_(get_datasym_and_offset)( Addr data_addr, data_addr, dname, /*match_anywhere_in_sym*/True, /*show offset?*/False, - /*data syms only please*/False, + /*text sym*/False, offset ); } diff --git a/coregrind/m_debuginfo/priv_storage.h b/coregrind/m_debuginfo/priv_storage.h index a43720ae12..25fa91928f 100644 --- a/coregrind/m_debuginfo/priv_storage.h +++ b/coregrind/m_debuginfo/priv_storage.h @@ -1108,7 +1108,6 @@ extern void ML_(finish_CFSI_arrays) ( struct _DebugInfo* di ); /* Find a symbol-table index containing the specified pointer, or -1 if not found. Binary search. */ extern Word ML_(search_one_symtab) ( const DebugInfo* di, Addr ptr, - Bool match_anywhere_in_sym, Bool findText ); /* Find a location-table index containing the specified pointer, or -1 diff --git a/coregrind/m_debuginfo/storage.c b/coregrind/m_debuginfo/storage.c index c46f4bd848..12b4c914b3 100644 --- a/coregrind/m_debuginfo/storage.c +++ b/coregrind/m_debuginfo/storage.c @@ -2360,11 +2360,10 @@ void ML_(canonicaliseTables) ( struct _DebugInfo* di ) if not found. Binary search. */ Word ML_(search_one_symtab) ( const DebugInfo* di, Addr ptr, - Bool match_anywhere_in_sym, Bool findText ) { Addr a_mid_lo, a_mid_hi; - Word mid, size, + Word mid, lo = 0, hi = di->symtab_used-1; while (True) { @@ -2372,10 +2371,7 @@ Word ML_(search_one_symtab) ( const DebugInfo* di, Addr ptr, if (lo > hi) return -1; /* not found */ mid = (lo + hi) / 2; a_mid_lo = di->symtab[mid].avmas.main; - size = ( match_anywhere_in_sym - ? di->symtab[mid].size - : 1); - a_mid_hi = ((Addr)di->symtab[mid].avmas.main) + size - 1; + a_mid_hi = ((Addr)di->symtab[mid].avmas.main) + di->symtab[mid].size - 1; if (ptr < a_mid_lo) { hi = mid-1; continue; } if (ptr > a_mid_hi) { lo = mid+1; continue; }