Bug 3586 - investigate elf symbol demangler for backtrace
Summary: investigate elf symbol demangler for backtrace
Alias: None
Product: frysk
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Nurdin Premji
Depends on:
Blocks: 2244 frysk-elfutils 3076
  Show dependency treegraph
Reported: 2006-11-24 15:55 UTC by Andrew Cagney
Modified: 2006-12-11 19:21 UTC (History)
1 user (show)

See Also:
Last reconfirmed:

Mangled output of an fstack of eclipse java process (1.90 KB, text/x-log)
2006-12-11 19:18 UTC, Nurdin Premji
Demangled output of same eclipse java process (1.62 KB, text/x-log)
2006-12-11 19:19 UTC, Nurdin Premji

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Cagney 2006-11-24 15:55:50 UTC
The backtrace's elf symbols are not demangled, a demangler needs to be found and
made available to frysk so that that can be done.

Stan, I know you investigated this, can the info be summarized here so that,
with a new bug, a decision can be made (and this bug closed) and a bug for the
work created.
Comment 1 Stan Cox 2006-11-30 02:22:04 UTC
proposed demangle plan is to let libiberty do all the work:
call cplus_demangle (libiberty::cplus-dem.c)
which calls one of:
     cplus_demangle_v3 (libiberty::cp-demangle.c)
     java_demangle_v3 (libiberty::cp-demangle.c)
Comment 2 Nurdin Premji 2006-12-07 16:59:46 UTC
cplus_demangle and setting the demangler require header file demangle.h, which
is not (yet) provided by binutils-devel.

Other possibilities include 


The c++ demangler
__cxa_demangle(const char* __mangled_name, char* __output_buffer,
                 size_t* __length, int* __status);
Comment 3 Nurdin Premji 2006-12-08 20:26:26 UTC
Actually, seems like as long as demangle.h is included in frysk-imports and
-liberty is added to GEN_GCJ_LDADD it's building.

Currently it seems like -liberty needs to be added to each directory
frysk-imports, frysk-sys, frysk-core, frysk-gtk and frysk-gui. I wonder if there
is a way around this, Not doing so gives the error: (when not included in frysk-gtk)

gcj-dbtool -a frysk-gtk.db.tmp frysk-gtk.jar libfrysk-gtk.so
../frysk-imports//libfrysk-imports.so: undefined reference to `cplus_demangle'
collect2: ld returned 1 exit status
make[3]: *** [fryski] Error 1
Comment 4 Andrew Cagney 2006-12-08 20:45:37 UTC
The problem with just adding a random demangle.h, is that there is no guarentee
that it matches the installed libiberty.a library.
Comment 5 Nurdin Premji 2006-12-08 21:33:24 UTC
Managed to get cxa_demangle to work, the problem was that I wasn't including
libstdc++ during load, (thanks to Kyle Galloway) so my little test program
builds and outputs proper stuff, now to get the build system to accept it.
Comment 6 Nurdin Premji 2006-12-08 22:01:14 UTC
This code:

#include <cxxabi.h>
#include <stdio.h>
#include <libiberty.h>
 * This is an ugly hack. In /usr/lib/ansidecl.h (included by libiberty.h) we have
 *       #define VOLATILE        volatile
 * This conflicts with /usr/include/c++/4.1.0/java/lang/reflect/Modifier.h:
 * 		 static const jint VOLATILE = 64L;
 * And makes cni cry

#include <gcj/cni.h>

#include "lib/iberty/Demangler.h"

lib::iberty::Demangler::demangler (const jstring mangled_string)
	const char * mangled_name = (const char *) JvGetStringChars(mangled_string);
	int status = -1;
    char *dem = __cxa_demangle(mangled_name, 0, 0, &status);
    if(status == 0)
        return JvNewStringUTF(dem);
        return mangled_string;

with this compile:

 g++ -DPACKAGE_NAME=\"frysk\" -DPACKAGE_TARNAME=\"frysk\"
-DVERSION=\"\"  -I.
-I/home/yyz/npremji/otherworkspace/frysk/frysk-imports/../frysk-imports -I.
-I./../frysk-imports/libunwind/include -Werror -Wall -fPIC 
-I/home/yyz/npremji/otherworkspace/frysk/frysk-imports/include -g -O -c -o

Produces this error:
In member function ‘java::lang::String*
error: ‘__cxa_demangle’ was not declared in this scope
make[3]: *** [lib/iberty/cni/Demangler.o] Error 1

I've also added lstdc++ to the GEN_GCJ_LDADD

although I don't see it in the g++ command. I must admit I know almost nothing
about linking
Comment 7 Nurdin Premji 2006-12-11 16:25:02 UTC
Fixed, took out the libiberty stuff, I don't know why I still had that, but the
problem was I didn't have the line:
using namespace abi. (Thanks to Andrew Cagney and Tom Tromey.)

December 9, 2006
        * TestDemangler.java: Added.
        * Demangler.java: Added.
        * cni/Demangler.cxx: Added.
        * bootstrap.sh (FILE_LIST): Added lib/stdcpp.
        * Makefile.am (EXTRA_DIST): added lib/stdcpp/ChangeLog.
        (GEN_GCJ_LDADD): Added -lstdc++
        frysk-core/CL frysk-gui/CL frysk-gtk/CL
        Makefile.am (GEN_GCJ_LDADD): Added -lstdc++
Comment 8 Nurdin Premji 2006-12-11 19:18:39 UTC
Created attachment 1455 [details]
Mangled output of an fstack of eclipse java process
Comment 9 Nurdin Premji 2006-12-11 19:19:14 UTC
Created attachment 1456 [details]
Demangled output of same eclipse java process
Comment 10 Nurdin Premji 2006-12-11 19:21:21 UTC
Finished, StackFrame now demangles method names so anything using this (i.e.
fstack and sourcewindow) will have demangled names.

December 11, 2006
	* StackFrame.java (toPrint): Demangle method names.