Merge r14202 from the BUF_REMOVAL branch to trunk.
This patch changes the interface and behaviour of VG_(demangle) and
VG_(maybe_Z_demangle). Instead of copying the demangled name into a
fixed sized buffer that is passed in from the caller (HChar *buf, Int n_buf),
the demangling functions will now return a pointer to the full-length
demangled name (HChar **result). It is the caller's responsiblilty to
make a copy if needed.
This change in function parameters ripples upward
- first: to get_sym_name
- then to the convenience wrappers
- VG_(get_fnname)
- VG_(get_fnname_w_offset)
- VG_(get_fnname_if_entry)
- VG_(get_fnname_raw)
- VG_(get_fnname_no_cxx_demangle)
- VG_(get_datasym_and_offset)
The changes in foComplete then forces the arguments of
- VG_(get_objname) to be changed as well
There are some issues regarding the ownership and persistence of
character strings to consider.
In general, the returned character string is owned by "somebody else"
which means the caller must not free it. Also, the caller must not
modify the returned string as it possibly points to read only memory.
Additionally, the returned string is not necessarily persistent. Here are
the scenarios:
- the returned string is a demangled function name in which case the
memory holding the string will be freed when the demangler is called again.
- the returned string hangs off of a DebugInfo structure in which case
it will be freed when the DebugInfo is discarded
- the returned string hangs off of a segment in the address space manager
in which case it may be overwritten when the segment is merged with
another segment
So the rule of thunb here is: if in doubt strdup the string.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14664 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/massif/ms_main.c b/massif/ms_main.c
index da58bb6..cdd73b4 100644
--- a/massif/ms_main.c
+++ b/massif/ms_main.c
@@ -355,7 +355,7 @@
}
// Determines if the named function is a member of the XArray.
-static Bool is_member_fn(XArray* fns, const HChar* fnname)
+static Bool is_member_fn(const XArray* fns, const HChar* fnname)
{
HChar** fn_ptr;
Int i;
@@ -817,9 +817,9 @@
// Determine if the given IP belongs to a function that should be ignored.
static Bool fn_should_be_ignored(Addr ip)
{
- static HChar buf[BUF_LEN];
+ const HChar *buf;
return
- ( VG_(get_fnname)(ip, buf, BUF_LEN) && is_member_fn(ignore_fns, buf)
+ ( VG_(get_fnname)(ip, &buf) && is_member_fn(ignore_fns, buf)
? True : False );
}
@@ -832,7 +832,6 @@
static
Int get_IPs( ThreadId tid, Bool exclude_first_entry, Addr ips[])
{
- static HChar buf[BUF_LEN];
Int n_ips, i, n_alloc_fns_removed;
Int overestimate;
Bool redo;
@@ -871,7 +870,8 @@
// because VG_(get_fnname) is expensive.
n_alloc_fns_removed = ( exclude_first_entry ? 1 : 0 );
for (i = n_alloc_fns_removed; i < n_ips; i++) {
- if (VG_(get_fnname)(ips[i], buf, BUF_LEN)) {
+ const HChar *buf;
+ if (VG_(get_fnname)(ips[i], &buf)) {
if (is_member_fn(alloc_fns, buf)) {
n_alloc_fns_removed++;
} else {