Bug 89707

Summary: alloc-fn appears not to work for C++ class member functions
Product: [Developer tools] valgrind Reporter: martijn versteegh <m.versteegh>
Component: massifAssignee: Nicholas Nethercote <njn>
Status: RESOLVED INTENTIONAL    
Severity: wishlist CC: pjfloyd
Priority: NOR    
Version First Reported In: 2.2.0   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description martijn versteegh 2004-09-17 16:48:16 UTC
It would be very nice if the --alloc-fn cmdline option could take
MyClass::MemberFunction type functionnames.

btw kudos for the great tool

--
martijn
Comment 1 Jeremy Fitzhardinge 2004-11-24 21:00:17 UTC
The trouble is that different C++ compilers have different name-mangling algorithms, so Valgrind would also need to know exactly which compiler/ABI you're using.
Comment 2 Paul Floyd 2021-10-19 16:42:13 UTC
I'm closing this as intentional.

There are ways to demangle decorated name (we could 'popen c++filt' or use abi::__cxa_demangle [but that is a C++ interface]) but that is the wrong direction. I'm not aware of tools that preform mangling, other than the compiler.

I don't think that it's a good idea for us to maintain a copy of the C++ or Rust or whatever mangler in Valgrind.

There is another small disadvantage to using undecorated names. Some of the characters (like ~ in destructor names) are not shell-friendly and may need quoting/escaping. Not that this is too likely, with the main need being for replacement malloc/free//new/delete.

In summary, I think the best solution is to simply use 'nm' on your executable.

In case the name of the function you are looking for is not obvious you can run 'nm -C', note the hexd offset, then run 'nm' without -C and look for the same hex offset.