Bug 372182

Summary: Support more languages/demangling styles than just C++ (and Rust)
Product: [Developer tools] valgrind Reporter: Mark Wielaard <mark>
Component: generalAssignee: Julian Seward <jseward>
Status: REPORTED ---    
Severity: normal CC: jseward, mark, philippe.waroquiers
Priority: NOR    
Version First Reported In: 3.12 SVN   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Bug Depends on: 372120    
Bug Blocks:    

Description Mark Wielaard 2016-11-07 14:27:35 UTC
+++ This bug was initially created as a clone of Bug #372120 +++

For the below code, the demanglers demangle a non c++ symbol as if it
would be a mangled c++ name.
This was detected on an Ada program (as gnat mangles Ada names by
replacing . by __) but that equally happens on c symbols having 2 underscores.
To reproduce:
gcc -g -o demang demang.c
./vg-in-place --leak-check=full ./demang
==30660== 90 bytes in 9 blocks are definitely lost in loss record 2 of 2
==30660==    at 0x4C27BB5: malloc (vg_replace_malloc.c:299)
==30660==    by 0x400515: main__calling__some(...)(long long,...)(char) (demang.c:7)
==30660==    by 0x40052C: main (demang.c:12)


#include <stdlib.h>
char *v;
void main__calling__some__exec(void)
{  
   int i;
   for (i = 0; i < 10; i++)
      v = malloc(10);
}

main ()
{
   main__calling__some__exec();
}
Comment 1 Mark Wielaard 2016-11-07 14:31:39 UTC
Currently we only support demangling (modern) C++ style symbol demangling (which includes Rust demangling, which is based on C++/gnu_v3 style demangling).

This is because not all demangling styles can be auto-detected (we only handle symbols starting with "_Z" at the moment).

We could detect the language if we have debuginfo from the CU DW_AT_language covering the symbol address. In that case we could set the language style first before calling ML_(cplus_demangle). See demangle.h for the language styles supported.