|
From: <sv...@va...> - 2005-12-06 15:22:36
|
Author: sewardj
Date: 2005-12-06 15:22:33 +0000 (Tue, 06 Dec 2005)
New Revision: 5293
Log:
Fix up demangling, so that Z-encoded names are decoded by the standard
demangle function, VG_(demangle). Also move VG_(maybe_Z_demangle) to
m_demangle. This gets rid of the longstanding kludge in which the
Z-demangler modified the symbol tables in place, causing problems of
its own.
Modified:
branches/FNWRAP/coregrind/m_demangle/demangle.c
branches/FNWRAP/coregrind/m_redir.c
branches/FNWRAP/coregrind/pub_core_demangle.h
branches/FNWRAP/coregrind/pub_core_redir.h
branches/FNWRAP/include/pub_tool_redir.h
Modified: branches/FNWRAP/coregrind/m_demangle/demangle.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/FNWRAP/coregrind/m_demangle/demangle.c 2005-12-06 15:19:57 U=
TC (rev 5292)
+++ branches/FNWRAP/coregrind/m_demangle/demangle.c 2005-12-06 15:22:33 U=
TC (rev 5293)
@@ -34,17 +34,35 @@
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
#include "pub_core_profile.h"
+#include "pub_core_libcassert.h"
#include "demangle.h"
+#include "pub_core_libcprint.h"
=20
+
+/* This is the main, standard demangler entry point. */
+
void VG_(demangle) ( Char* orig, Char* result, Int result_size )
{
- Char* demangled =3D NULL;
+# define N_ZBUF 4096
+ HChar* demangled =3D NULL;
+ HChar z_demangled[N_ZBUF];
=20
- VGP_PUSHCC(VgpDemangle);
+ if (!VG_(clo_demangle)) {
+ VG_(strncpy_safely)(result, orig, result_size);
+ return;
+ }
=20
- if (VG_(clo_demangle))
- demangled =3D VG_(cplus_demangle) ( orig, DMGL_ANSI | DMGL_PARAMS =
);
+ /* 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
+ interested in that). */
+ if (VG_(maybe_Z_demangle)( orig, NULL,0,/*soname*/
+ z_demangled, N_ZBUF)) {
+ orig =3D z_demangled;
+ }
=20
+ demangled =3D VG_(cplus_demangle) ( orig, DMGL_ANSI | DMGL_PARAMS );
+
if (demangled) {
VG_(strncpy_safely)(result, demangled, result_size);
VG_(arena_free) (VG_AR_DEMANGLE, demangled);
@@ -58,9 +76,172 @@
// does leak. But, we can't do much about it, and it's not a disaste=
r,
// so we just let it slide without aborting or telling the user.
=20
- VGP_POPCC(VgpDemangle);
+# undef N_ZBUF
}
=20
+
+/*------------------------------------------------------------*/
+/*--- DEMANGLE Z-ENCODED NAMES ---*/
+/*------------------------------------------------------------*/
+
+/* Demangle a Z-encoded name as described in pub_tool_redir.h.=20
+ Z-encoded names are used by Valgrind for doing function=20
+ interception/wrapping.
+
+ Demangle 'sym' into its soname and fnname parts, putting them in
+ the specified buffers. Returns a Bool indicating whether the
+ demangled failed or not. A failure can occur because the prefix
+ isn't recognised, the internal Z-escaping is wrong, or because one
+ or the other (or both) of the output buffers becomes full. Passing
+ 'so' as NULL is acceptable if the caller is only interested in the
+ function name part. */
+
+Bool VG_(maybe_Z_demangle) ( const HChar* sym,=20
+ /*OUT*/HChar* so, Int soLen,
+ /*OUT*/HChar* fn, Int fnLen )
+{
+# define EMITSO(ch) \
+ do { \
+ if (so) { \
+ if (soi >=3D soLen) { \
+ so[soLen-1] =3D 0; oflow =3D True; \
+ } else { \
+ so[soi++] =3D ch; so[soi] =3D 0; \
+ } \
+ } \
+ } while (0)
+# define EMITFN(ch) \
+ do { \
+ if (fni >=3D fnLen) { \
+ fn[fnLen-1] =3D 0; oflow =3D True; \
+ } else { \
+ fn[fni++] =3D ch; fn[fni] =3D 0; \
+ } \
+ } while (0)
+
+ Bool error, oflow, valid, fn_is_encoded;
+ Int soi, fni, i;
+
+ vg_assert(soLen > 0 || (soLen =3D=3D 0 && so =3D=3D NULL));
+ vg_assert(fnLen > 0);
+ error =3D False;
+ oflow =3D False;
+ soi =3D 0;
+ fni =3D 0;
+
+ valid =3D sym[0] =3D=3D '_'
+ && sym[1] =3D=3D 'v'
+ && sym[2] =3D=3D 'g'
+ && (sym[3] =3D=3D 'r' || sym[3] =3D=3D 'n')
+ && sym[4] =3D=3D 'Z'
+ && (sym[5] =3D=3D 'Z' || sym[5] =3D=3D 'U')
+ && sym[6] =3D=3D '_';
+ if (!valid)
+ return False;
+
+ fn_is_encoded =3D sym[5] =3D=3D 'Z';
+
+ /* Now scan the Z-encoded soname. */
+ i =3D 7;
+ while (True) {
+
+ if (sym[i] =3D=3D '_')
+ /* Found the delimiter. Move on to the fnname loop. */
+ break;
+
+ if (sym[i] =3D=3D 0) {
+ error =3D True;
+ goto out;
+ }
+
+ if (sym[i] !=3D 'Z') {
+ EMITSO(sym[i]);
+ i++;
+ continue;
+ }
+
+ /* We've got a Z-escape. */
+ i++;
+ switch (sym[i]) {
+ case 'a': EMITSO('*'); break;
+ case 'p': EMITSO('+'); break;
+ case 'c': EMITSO(':'); break;
+ case 'd': EMITSO('.'); break;
+ case 'u': EMITSO('_'); break;
+ case 'h': EMITSO('-'); break;
+ case 's': EMITSO(' '); break;
+ case 'Z': EMITSO('Z'); break;
+ case 'A': EMITSO('@'); break;
+ default: error =3D True; goto out;
+ }
+ i++;
+ }
+
+ vg_assert(sym[i] =3D=3D '_');
+ i++;
+
+ /* Now deal with the function name part. */
+ if (!fn_is_encoded) {
+
+ /* simple; just copy. */
+ while (True) {
+ if (sym[i] =3D=3D 0)
+ break;
+ EMITFN(sym[i]);
+ i++;
+ }
+ goto out;
+
+ }
+
+ /* else use a Z-decoding loop like with soname */
+ while (True) {
+
+ if (sym[i] =3D=3D 0)
+ break;
+
+ if (sym[i] !=3D 'Z') {
+ EMITFN(sym[i]);
+ i++;
+ continue;
+ }
+
+ /* We've got a Z-escape. */
+ i++;
+ switch (sym[i]) {
+ case 'a': EMITFN('*'); break;
+ case 'p': EMITFN('+'); break;
+ case 'c': EMITFN(':'); break;
+ case 'd': EMITFN('.'); break;
+ case 'u': EMITFN('_'); break;
+ case 'h': EMITFN('-'); break;
+ case 's': EMITFN(' '); break;
+ case 'Z': EMITFN('Z'); break;
+ case 'A': EMITFN('@'); break;
+ default: error =3D True; goto out;
+ }
+ i++;
+ }
+
+ out:
+ EMITSO(0);
+ EMITFN(0);
+
+ if (error) {
+ /* Something's wrong. Give up. */
+ VG_(message)(Vg_UserMsg, "m_redir: error demangling: %s", sym);
+ return False;
+ }
+ if (oflow) {
+ /* It didn't fit. Give up. */
+ VG_(message)(Vg_UserMsg, "m_debuginfo: oflow demangling: %s", sym)=
;
+ return False;
+ }
+
+ return True;
+}
+
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: branches/FNWRAP/coregrind/m_redir.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/FNWRAP/coregrind/m_redir.c 2005-12-06 15:19:57 UTC (rev 5292=
)
+++ branches/FNWRAP/coregrind/m_redir.c 2005-12-06 15:22:33 UTC (rev 5293=
)
@@ -45,6 +45,7 @@
#include "pub_core_tooliface.h" // VG_(needs).malloc_replacement
#include "pub_core_aspacemgr.h" // VG_(am_find_nsegment)
#include "pub_core_clientstate.h" // VG_(client___libc_freeres_wrapper)
+#include "pub_core_demangle.h" // VG_(maybe_Z_demangle)
=20
=20
/*------------------------------------------------------------*/
@@ -463,8 +464,10 @@
=20
bad:
vg_assert(what);
- VG_(message)(Vg_UserMsg, "WARNING: %s", what);
- show_active(" ", &act);
+ if (VG_(clo_verbosity) > 1) {
+ VG_(message)(Vg_UserMsg, "WARNING: %s", what);
+ show_active( " new: ", &act);
+ }
}
=20
=20
@@ -761,160 +764,6 @@
=20
=20
/*------------------------------------------------------------*/
-/*--- THE DEMANGLER ---*/
-/*------------------------------------------------------------*/
-
-/* Demangle 'sym' into its soname and fnname parts, putting them in
- the specified buffers. Returns a Bool indicating whether the
- demangled failed or not. A failure can occur because the prefix
- isn't recognised, the internal Z-escaping is wrong, or because one
- or the other (or both) of the output buffers becomes full. */
-
-Bool VG_(maybe_Z_demangle) ( const HChar* sym,=20
- /*OUT*/HChar* so, Int soLen,
- /*OUT*/HChar* fn, Int fnLen )
-{
-# define EMITSO(ch) \
- do { \
- if (soi >=3D soLen) { \
- so[soLen-1] =3D 0; oflow =3D True; \
- } else { \
- so[soi++] =3D ch; so[soi] =3D 0; \
- } \
- } while (0)
-# define EMITFN(ch) \
- do { \
- if (fni >=3D fnLen) { \
- fn[fnLen-1] =3D 0; oflow =3D True; \
- } else { \
- fn[fni++] =3D ch; fn[fni] =3D 0; \
- } \
- } while (0)
-
- Bool error, oflow, valid, fn_is_encoded;
- Int soi, fni, i;
-
- vg_assert(soLen > 0);
- vg_assert(fnLen > 0);
- error =3D False;
- oflow =3D False;
- soi =3D 0;
- fni =3D 0;
-
- valid =3D sym[0] =3D=3D '_'
- && sym[1] =3D=3D 'v'
- && sym[2] =3D=3D 'g'
- && (sym[3] =3D=3D 'r' || sym[3] =3D=3D 'n')
- && sym[4] =3D=3D 'Z'
- && (sym[5] =3D=3D 'Z' || sym[5] =3D=3D 'U')
- && sym[6] =3D=3D '_';
- if (!valid)
- return False;
-
- fn_is_encoded =3D sym[5] =3D=3D 'Z';
-
- /* Now scan the Z-encoded soname. */
- i =3D 7;
- while (True) {
-
- if (sym[i] =3D=3D '_')
- /* Found the delimiter. Move on to the fnname loop. */
- break;
-
- if (sym[i] =3D=3D 0) {
- error =3D True;
- goto out;
- }
-
- if (sym[i] !=3D 'Z') {
- EMITSO(sym[i]);
- i++;
- continue;
- }
-
- /* We've got a Z-escape. */
- i++;
- switch (sym[i]) {
- case 'a': EMITSO('*'); break;
- case 'p': EMITSO('+'); break;
- case 'c': EMITSO(':'); break;
- case 'd': EMITSO('.'); break;
- case 'u': EMITSO('_'); break;
- case 'h': EMITSO('-'); break;
- case 's': EMITSO(' '); break;
- case 'Z': EMITSO('Z'); break;
- case 'A': EMITSO('@'); break;
- default: error =3D True; goto out;
- }
- i++;
- }
-
- vg_assert(sym[i] =3D=3D '_');
- i++;
-
- /* Now deal with the function name part. */
- if (!fn_is_encoded) {
-
- /* simple; just copy. */
- while (True) {
- if (sym[i] =3D=3D 0)
- break;
- EMITFN(sym[i]);
- i++;
- }
- goto out;
-
- }
-
- /* else use a Z-decoding loop like with soname */
- while (True) {
-
- if (sym[i] =3D=3D 0)
- break;
-
- if (sym[i] !=3D 'Z') {
- EMITFN(sym[i]);
- i++;
- continue;
- }
-
- /* We've got a Z-escape. */
- i++;
- switch (sym[i]) {
- case 'a': EMITFN('*'); break;
- case 'p': EMITFN('+'); break;
- case 'c': EMITFN(':'); break;
- case 'd': EMITFN('.'); break;
- case 'u': EMITFN('_'); break;
- case 'h': EMITFN('-'); break;
- case 's': EMITFN(' '); break;
- case 'Z': EMITFN('Z'); break;
- case 'A': EMITFN('@'); break;
- default: error =3D True; goto out;
- }
- i++;
- }
-
- out:
- EMITSO(0);
- EMITFN(0);
-
- if (error) {
- /* Something's wrong. Give up. */
- VG_(message)(Vg_UserMsg, "m_redir: error demangling: %s", sym);
- return False;
- }
- if (oflow) {
- /* It didn't fit. Give up. */
- VG_(message)(Vg_UserMsg, "m_debuginfo: oflow demangling: %s", sym)=
;
- return False;
- }
-
- return True;
-}
-
-
-/*------------------------------------------------------------*/
/*--- SANITY/DEBUG ---*/
/*------------------------------------------------------------*/
=20
Modified: branches/FNWRAP/coregrind/pub_core_demangle.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/FNWRAP/coregrind/pub_core_demangle.h 2005-12-06 15:19:57 UTC=
(rev 5292)
+++ branches/FNWRAP/coregrind/pub_core_demangle.h 2005-12-06 15:22:33 UTC=
(rev 5293)
@@ -32,12 +32,33 @@
#define __PUB_CORE_DEMANGLE_H
=20
//--------------------------------------------------------------------
-// PURPOSE: This module exports a single function for demangling C++
-// names.
+// PURPOSE: This module exports functions for demangling C++ and=20
+// Z-encoded names.
//--------------------------------------------------------------------
=20
-extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
+/* This is the main, standard demangler entry point. */
=20
+extern=20
+void VG_(demangle) ( Char* orig, Char* result, Int result_size );
+
+/* Demangle a Z-encoded name as described in pub_tool_redir.h.=20
+ Z-encoded names are used by Valgrind for doing function=20
+ interception/wrapping.
+
+ Demangle 'sym' into its soname and fnname parts, putting them in
+ the specified buffers. Returns a Bool indicating whether the
+ demangled failed or not. A failure can occur because the prefix
+ isn't recognised, the internal Z-escaping is wrong, or because one
+ or the other (or both) of the output buffers becomes full. Passing
+ 'so' as NULL is acceptable if the caller is only interested in the
+ function name part. */
+
+extern=20
+Bool VG_(maybe_Z_demangle) ( const HChar* sym,=20
+ /*OUT*/HChar* so, Int soLen,
+ /*OUT*/HChar* fn, Int fnLen );
+
+
#endif // __PUB_CORE_DEMANGLE_H
=20
/*--------------------------------------------------------------------*/
Modified: branches/FNWRAP/coregrind/pub_core_redir.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/FNWRAP/coregrind/pub_core_redir.h 2005-12-06 15:19:57 UTC (r=
ev 5292)
+++ branches/FNWRAP/coregrind/pub_core_redir.h 2005-12-06 15:22:33 UTC (r=
ev 5293)
@@ -88,21 +88,6 @@
=20
=20
//--------------------------------------------------------------------
-// Demangling of Z-encoded names
-//--------------------------------------------------------------------
-
-/* Demangle 'sym' into its soname and fnname parts, putting them in
- the specified buffers. Returns a Bool indicating whether the
- demangled failed or not. A failure can occur because the prefix
- isn't recognised, the internal Z-escaping is wrong, or because one
- or the other (or both) of the output buffers becomes full. */
-
-Bool VG_(maybe_Z_demangle) ( const HChar* sym,=20
- /*OUT*/HChar* so, Int soLen,
- /*OUT*/HChar* fn, Int fnLen );
-
-
-//--------------------------------------------------------------------
// Function wrapping
//--------------------------------------------------------------------
=20
Modified: branches/FNWRAP/include/pub_tool_redir.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/FNWRAP/include/pub_tool_redir.h 2005-12-06 15:19:57 UTC (rev=
5292)
+++ branches/FNWRAP/include/pub_tool_redir.h 2005-12-06 15:22:33 UTC (rev=
5293)
@@ -110,6 +110,8 @@
Everything else is left unchanged.
*/
=20
+/* If you change these, the code in VG_(maybe_Z_demangle) needs to
+ be changed accordingly. */
#define VG_REDIRECT_FUNCTION_ZU(soname,fnname) _vgrZU_##soname##_##fnnam=
e
#define VG_REDIRECT_FUNCTION_ZZ(soname,fnname) _vgrZZ_##soname##_##fnnam=
e
=20
|