|
From: <sv...@va...> - 2009-02-11 06:06:16
|
Author: njn
Date: 2009-02-11 06:06:10 +0000 (Wed, 11 Feb 2009)
New Revision: 9138
Log:
Cleaned up the demangling mess:
- Now more clearly distinguishing between C++-demangling, Z-demangling, and
below-main renaming, particularly in 'get_sym_name'.
- --demangle=no no longer prevents Z-demangling, which makes more sense,
although it's unlikely to affect anyone.
- Broke the circular dependency between m_demangle and m_debuginfo by moving
below-main renaming into m_debuginfo.
- Renamed some get_fnname_* functions to make their effect clearer, and
improved their comments.
Modified:
trunk/coregrind/m_debuginfo/debuginfo.c
trunk/coregrind/m_demangle/demangle.c
trunk/coregrind/m_errormgr.c
trunk/coregrind/m_stacktrace.c
trunk/coregrind/pub_core_debuginfo.h
trunk/coregrind/pub_core_demangle.h
Modified: trunk/coregrind/m_debuginfo/debuginfo.c
===================================================================
--- trunk/coregrind/m_debuginfo/debuginfo.c 2009-02-11 01:10:43 UTC (rev 9137)
+++ trunk/coregrind/m_debuginfo/debuginfo.c 2009-02-11 06:06:10 UTC (rev 9138)
@@ -1091,13 +1091,15 @@
/* The whole point of this whole big deal: map a code address to a
plausible symbol name. Returns False if no idea; otherwise True.
- Caller supplies buf and nbuf. If demangle is False, don't do
- demangling, regardless of VG_(clo_demangle) -- probably because the
- call has come from VG_(get_fnname_nodemangle)(). findText
+ Caller supplies buf and nbuf. If do_cxx_demangling is False, don't do
+ C++ demangling, regardless of VG_(clo_demangle) -- probably because the
+ call has come from VG_(get_fnname_raw)(). findText
indicates whether we're looking for a text symbol or a data symbol
-- caller must choose one kind or the other. */
static
-Bool get_sym_name ( Bool demangle, Addr a, Char* buf, Int nbuf,
+Bool get_sym_name ( Bool do_cxx_demangling, Bool do_z_demangling,
+ Bool do_below_main_renaming,
+ Addr a, Char* buf, Int nbuf,
Bool match_anywhere_in_sym, Bool show_offset,
Bool findText, /*OUT*/PtrdiffT* offsetP )
{
@@ -1108,14 +1110,20 @@
search_all_symtabs ( a, &di, &sno, match_anywhere_in_sym, findText );
if (di == NULL)
return False;
- if (demangle) {
- VG_(demangle) ( True/*do C++ demangle*/,
- di->symtab[sno].name, buf, nbuf );
- } else {
- VG_(strncpy_safely) ( buf, di->symtab[sno].name, nbuf );
+ VG_(demangle) ( do_cxx_demangling, do_z_demangling,
+ di->symtab[sno].name, buf, nbuf );
+
+ /* Do the below-main hack */
+ // To reduce the endless nuisance of multiple different names
+ // for "the frame below main()" screwing up the testsuite, change all
+ // known incarnations of said into a single name, "(below main)", if
+ // --show-below-main=yes.
+ if ( do_below_main_renaming && ! VG_(clo_show_below_main) &&
+ Vg_FnNameBelowMain == VG_(get_fnname_kind)(buf) )
+ {
+ VG_(strncpy_safely)(buf, "(below main)", nbuf);
}
-
offset = a - di->symtab[sno].addr;
if (offsetP) *offsetP = offset;
@@ -1136,6 +1144,8 @@
}
}
+ buf[nbuf-1] = 0; /* paranoia */
+
return True;
}
@@ -1160,7 +1170,9 @@
match anywhere in function, but don't show offsets. */
Bool VG_(get_fnname) ( Addr a, Char* buf, Int nbuf )
{
- return get_sym_name ( /*demangle*/True, a, buf, nbuf,
+ return get_sym_name ( /*C++-demangle*/True, /*Z-demangle*/True,
+ /*below-main-renaming*/True,
+ a, buf, nbuf,
/*match_anywhere_in_fun*/True,
/*show offset?*/False,
/*text syms only*/True,
@@ -1171,7 +1183,9 @@
match anywhere in function, and show offset if nonzero. */
Bool VG_(get_fnname_w_offset) ( Addr a, Char* buf, Int nbuf )
{
- return get_sym_name ( /*demangle*/True, a, buf, nbuf,
+ return get_sym_name ( /*C++-demangle*/True, /*Z-demangle*/True,
+ /*below-main-renaming*/True,
+ a, buf, nbuf,
/*match_anywhere_in_fun*/True,
/*show offset?*/True,
/*text syms only*/True,
@@ -1183,18 +1197,23 @@
and don't show offsets. */
Bool VG_(get_fnname_if_entry) ( Addr a, Char* buf, Int nbuf )
{
- return get_sym_name ( /*demangle*/True, a, buf, nbuf,
+ return get_sym_name ( /*C++-demangle*/True, /*Z-demangle*/True,
+ /*below-main-renaming*/True,
+ a, buf, nbuf,
/*match_anywhere_in_fun*/False,
/*show offset?*/False,
/*text syms only*/True,
/*offsetP*/NULL );
}
-/* This is only available to core... don't demangle C++ names,
- match anywhere in function, and don't show offsets. */
-Bool VG_(get_fnname_nodemangle) ( Addr a, Char* buf, Int nbuf )
+/* This is only available to core... don't C++-demangle, don't Z-demangle,
+ don't rename below-main, match anywhere in function, and don't show
+ offsets. */
+Bool VG_(get_fnname_raw) ( Addr a, Char* buf, Int nbuf )
{
- return get_sym_name ( /*demangle*/False, a, buf, nbuf,
+ return get_sym_name ( /*C++-demangle*/False, /*Z-demangle*/False,
+ /*below-main-renaming*/False,
+ a, buf, nbuf,
/*match_anywhere_in_fun*/True,
/*show offset?*/False,
/*text syms only*/True,
@@ -1202,29 +1221,17 @@
}
/* This is only available to core... don't demangle C++ names, but do
- do Z-demangling, match anywhere in function, and don't show
- offsets. */
-Bool VG_(get_fnname_Z_demangle_only) ( Addr a, Char* buf, Int nbuf )
+ do Z-demangling and below-main-renaming, match anywhere in function, and
+ don't show offsets. */
+Bool VG_(get_fnname_no_cxx_demangle) ( Addr a, Char* buf, Int nbuf )
{
-# define N_TMPBUF 4096 /* arbitrary, 4096 == ERRTXT_LEN */
- Char tmpbuf[N_TMPBUF];
- Bool ok;
- vg_assert(nbuf > 0);
- ok = get_sym_name ( /*demangle*/False, a, tmpbuf, N_TMPBUF,
- /*match_anywhere_in_fun*/True,
- /*show offset?*/False,
- /*text syms only*/True,
- /*offsetP*/NULL );
- tmpbuf[N_TMPBUF-1] = 0; /* paranoia */
- if (!ok)
- return False;
-
- /* We have something, at least. Try to Z-demangle it. */
- VG_(demangle)( False/*don't do C++ demangling*/, tmpbuf, buf, nbuf);
-
- buf[nbuf-1] = 0; /* paranoia */
- return True;
-# undef N_TMPBUF
+ return get_sym_name ( /*C++-demangle*/False, /*Z-demangle*/True,
+ /*below-main-renaming*/True,
+ a, buf, nbuf,
+ /*match_anywhere_in_fun*/True,
+ /*show offset?*/False,
+ /*text syms only*/True,
+ /*offsetP*/NULL );
}
Vg_FnNameKind VG_(get_fnname_kind) ( Char* name )
@@ -1257,7 +1264,7 @@
// We don't demangle, because it's faster not to, and the special names
// we're looking for won't be demangled.
- if (VG_(get_fnname_nodemangle) ( ip, buf, BUFLEN )) {
+ if (VG_(get_fnname_raw) ( ip, buf, BUFLEN )) {
buf[BUFLEN-1] = '\0'; // paranoia
return VG_(get_fnname_kind)(buf);
} else {
@@ -1275,7 +1282,9 @@
{
Bool ok;
vg_assert(n_dname > 1);
- ok = get_sym_name ( /*demangle*/False, data_addr, dname, n_dname,
+ ok = get_sym_name ( /*C++-demangle*/False, /*Z-demangle*/False,
+ /*below-main-renaming*/False,
+ data_addr, dname, n_dname,
/*match_anywhere_in_sym*/True,
/*show offset?*/False,
/*data syms only please*/False,
Modified: trunk/coregrind/m_demangle/demangle.c
===================================================================
--- trunk/coregrind/m_demangle/demangle.c 2009-02-11 01:10:43 UTC (rev 9137)
+++ trunk/coregrind/m_demangle/demangle.c 2009-02-11 06:06:10 UTC (rev 9138)
@@ -29,7 +29,6 @@
*/
#include "pub_core_basics.h"
-#include "pub_core_debuginfo.h" // XXX: circular dependency
#include "pub_core_demangle.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcbase.h"
@@ -87,34 +86,31 @@
/* This is the main, standard demangler entry point. */
-void VG_(demangle) ( Bool do_cxx_demangle,
+void VG_(demangle) ( Bool do_cxx_demangling, Bool do_z_demangling,
Char* orig, Char* result, Int result_size )
{
# define N_ZBUF 4096
HChar* demangled = NULL;
HChar z_demangled[N_ZBUF];
- if (!VG_(clo_demangle)) {
- VG_(strncpy_safely)(result, orig, result_size);
- return;
- }
-
- /* Undo (2) */
- /* Demangling was requested. First see if it's a Z-mangled
- intercept specification. The fastest way is just to attempt a
- Z-demangling (with NULL soname buffer, since we're not
+ /* Possibly undo (2) */
+ /* Z-Demangling was requested.
+ The fastest way to see if it's a Z-mangled name is just to attempt
+ to Z-demangle it (with NULL for the soname buffer, since we're not
interested in that). */
- if (VG_(maybe_Z_demangle)( orig, NULL,0,/*soname*/
- z_demangled, N_ZBUF, NULL)) {
- orig = z_demangled;
+ if (do_z_demangling) {
+ if (VG_(maybe_Z_demangle)( orig, NULL,0,/*soname*/
+ z_demangled, N_ZBUF, NULL)) {
+ orig = z_demangled;
+ }
}
/* Possibly undo (1) */
- if (do_cxx_demangle)
+ if (do_cxx_demangling && VG_(clo_demangle)) {
demangled = ML_(cplus_demangle) ( orig, DMGL_ANSI | DMGL_PARAMS );
- else
+ } else {
demangled = NULL;
-
+ }
if (demangled) {
VG_(strncpy_safely)(result, demangled, result_size);
VG_(arena_free) (VG_AR_DEMANGLE, demangled);
@@ -127,19 +123,6 @@
// very rarely (ie. I've heard of it twice in 3 years), the demangler
// does leak. But, we can't do much about it, and it's not a disaster,
// so we just let it slide without aborting or telling the user.
-
- /* Do the below-main hack */
- // Finally, to reduce the endless nuisance of multiple different names
- // for "the frame below main()" screwing up the testsuite, change all
- // known incarnations of said into a single name, "(below main)", if
- // --show-below-main=yes.
- // XXX: this makes a circular dependency between m_demangle and
- // m_debuginfo.
- if ( ! VG_(clo_show_below_main) &&
- Vg_FnNameBelowMain == VG_(get_fnname_kind)(result))
- {
- VG_(strncpy_safely)(result, "(below main)", result_size);
- }
# undef N_ZBUF
}
Modified: trunk/coregrind/m_errormgr.c
===================================================================
--- trunk/coregrind/m_errormgr.c 2009-02-11 01:10:43 UTC (rev 9137)
+++ trunk/coregrind/m_errormgr.c 2009-02-11 06:06:10 UTC (rev 9138)
@@ -404,7 +404,7 @@
{
static UChar buf[ERRTXT_LEN];
- if ( VG_(get_fnname_Z_demangle_only) (ip, buf, ERRTXT_LEN) ) {
+ if ( VG_(get_fnname_no_cxx_demangle) (ip, buf, ERRTXT_LEN) ) {
VG_(printf)(" fun:%s\n", buf);
} else if ( VG_(get_objname)(ip, buf, ERRTXT_LEN) ) {
VG_(printf)(" obj:%s\n", buf);
@@ -1210,12 +1210,12 @@
case FunName:
/* Get the function name into 'caller_name', or "???"
if unknown. */
- // Nb: mangled names used in suppressions. Do, though,
+ // Nb: C++-mangled names are used in suppressions. Do, though,
// Z-demangle them, since otherwise it's possible to wind
// up comparing "malloc" in the suppression against
// "_vgrZU_libcZdsoZa_malloc" in the backtrace, and the
// two of them need to be made to match.
- if (!VG_(get_fnname_Z_demangle_only)(ip, caller_name, ERRTXT_LEN))
+ if (!VG_(get_fnname_no_cxx_demangle)(ip, caller_name, ERRTXT_LEN))
VG_(strcpy)(caller_name, "???");
break;
default:
Modified: trunk/coregrind/m_stacktrace.c
===================================================================
--- trunk/coregrind/m_stacktrace.c 2009-02-11 01:10:43 UTC (rev 9137)
+++ trunk/coregrind/m_stacktrace.c 2009-02-11 06:06:10 UTC (rev 9138)
@@ -337,8 +337,8 @@
UChar buf_lr[M_VG_ERRTXT], buf_ip[M_VG_ERRTXT];
/* The following conditional looks grossly inefficient and
surely could be majorly improved, with not much effort. */
- if (VG_(get_fnname_nodemangle) (lr, buf_lr, M_VG_ERRTXT))
- if (VG_(get_fnname_nodemangle) (ip, buf_ip, M_VG_ERRTXT))
+ if (VG_(get_fnname_raw) (lr, buf_lr, M_VG_ERRTXT))
+ if (VG_(get_fnname_raw) (ip, buf_ip, M_VG_ERRTXT))
if (VG_(strncmp)(buf_lr, buf_ip, M_VG_ERRTXT))
lr_is_first_RA = True;
# undef M_VG_ERRTXT
Modified: trunk/coregrind/pub_core_debuginfo.h
===================================================================
--- trunk/coregrind/pub_core_debuginfo.h 2009-02-11 01:10:43 UTC (rev 9137)
+++ trunk/coregrind/pub_core_debuginfo.h 2009-02-11 06:06:10 UTC (rev 9138)
@@ -87,9 +87,19 @@
extern void VG_(di_discard_ALL_debuginfo)( void );
-extern Bool VG_(get_fnname_nodemangle)( Addr a,
- Char* fnname, Int n_fnname );
+/* Like VG_(get_fnname), but it does not do C++ demangling nor Z-demangling
+ * nor below-main renaming.
+ * It should not be used for any names that will be shown to users.
+ * It should only be used in cases where the names of interest will have
+ * particular (ie. non-mangled) forms, or the mangled form is acceptable. */
+extern
+Bool VG_(get_fnname_raw) ( Addr a, Char* buf, Int nbuf );
+/* Like VG_(get_fnname), but without C++ demangling. (But it does
+ * Z-demangling and below-main renaming.) */
+extern
+Bool VG_(get_fnname_no_cxx_demangle) ( Addr a, Char* buf, Int nbuf );
+
/* Use DWARF2/3 CFA information to do one step of stack unwinding. */
extern Bool VG_(use_CF_info) ( /*MOD*/Addr* ipP,
/*MOD*/Addr* spP,
@@ -102,12 +112,6 @@
guest_code_addr. Returns 0 if not known. */
extern Addr VG_(get_tocptr) ( Addr guest_code_addr );
-/* This is only available to core... don't demangle C++ names, but do
- do Z-demangling, match anywhere in function, and don't show
- offsets. */
-extern
-Bool VG_(get_fnname_Z_demangle_only) ( Addr a, Char* buf, Int nbuf );
-
/* Map a function name to its entry point and toc pointer. Is done by
sequential search of all symbol tables, so is very slow. To
mitigate the worst performance effects, you may specify a soname
Modified: trunk/coregrind/pub_core_demangle.h
===================================================================
--- trunk/coregrind/pub_core_demangle.h 2009-02-11 01:10:43 UTC (rev 9137)
+++ trunk/coregrind/pub_core_demangle.h 2009-02-11 06:06:10 UTC (rev 9138)
@@ -36,15 +36,11 @@
// Z-encoded names.
//--------------------------------------------------------------------
-/* This is the main, standard demangler entry point. It does three things:
- * (1) undoes Z-encoding;
- * (2) undoes C++ demangling, if 'do_cxx_demangle' is True
- * (3) converts "below main" names (eg. '__libc_start_main') to "(below
- * main)", if --show-below-main=no.
- */
-
+/* This is the main, standard demangler entry point. It does two things:
+ * (1) undoes Z-encoding, if "do_z_demangle" is True;
+ * (2) undoes C++ demangling, if 'do_cxx_demangle' is True. */
extern
-void VG_(demangle) ( Bool do_cxx_demangle,
+void VG_(demangle) ( Bool do_cxx_demangling, Bool do_z_demangling,
Char* orig, Char* result, Int result_size );
/* Demangle a Z-encoded name as described in pub_tool_redir.h.
|
|
From: Florian K. <br...@ac...> - 2009-02-11 12:47:05
|
On Wednesday 11 February 2009 01:06:12 sv...@va... wrote:
> + /* Do the below-main hack */
> + // To reduce the endless nuisance of multiple different names
> + // for "the frame below main()" screwing up the testsuite, change all
> + // known incarnations of said into a single name, "(below main)", if
> + // --show-below-main=yes.
I think you meant: --show-below-main=no
> + if ( do_below_main_renaming && ! VG_(clo_show_below_main) &&
> + Vg_FnNameBelowMain == VG_(get_fnname_kind)(buf) )
> + {
Florian
|