This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Stack Traces in GCJ/MinGW
- From: Ranjit Mathew <rmathew at hotmail dot com>
- To: java at gcc dot gnu dot org
- Date: Fri, 24 Jan 2003 23:40:35 +0530
- Subject: Stack Traces in GCJ/MinGW
Hi,
Inspired by Erik's comment on this topic, I tried my hand
today at getting stack traces working with MinGW/GCJ. In short,
I was able to get very crude, albeit still useful, results as
explained in more detail below.
After a bit of digging around the sources, I found that
HAVE_BACKTRACE was not being defined for
"gnu/gcj/runtime/natStackTrace.cc" even though "win32.h"
defines it and "win32.cc" provides an implementation for
backtrace( ) (thanks Adam!) - the solution was to either
include "platform.h" in natStackTrace.cc or to define
something like the following for this file:
#ifdef WIN32
#define HAVE_BACKTRACE 1
extern int backtrace( void **, int);
#endif
Depending on what is preferred, I will submit a patch for
this. I took the latter approach for my experiments.
With this out of the way, I could actually get a stacktrace
but only with numerical addresses in hex on each line
accompanied by "(Unknown Source)". :-(
It turns out that "gnu/gcj/runtime/NameFinder.java" tries to
spawn "c++filt" as well as "addr2line" to decipher symbols and
filenames respectively corresponding to these addresses and
the GCJ/Win32 process spawning support being what it is
(i.e. absent), this does not work.
In any case, I wrote a crude shell script like this to convert
the dump from a given executable to a meaningful form:
----------------------------------- 8< -----------------------------------
#!/bin/sh
$1 2>&1 \
|grep "^ at " \
|cut -b9-17 \
|addr2line -f -s -e $1 \
|grep "java\|_ZN" \
|c++filt --format java -s java
----------------------------------- 8< -----------------------------------
When I run it with my program (where main( ) calls foo( ), calls bar( ),
calls snafu( ), calls wombat( ), which throws an exception), I get
the following output:
----------------------------------- 8< -----------------------------------
MyEx.wombat()
MyEx.java:31
MyEx.snafu()
MyEx.java:26
MyEx.bar()
MyEx.java:20
MyEx.foo()
MyEx.java:14
MyEx.main(java.lang.String[])
MyEx.java:8
----------------------------------- 8< -----------------------------------
Not that bad, eh?
;-)
(NOTE: the addr2name.awk script included with GCJ did not work for
me.)
Sincerely Yours,
Ranjit.
--
Ranjit Mathew Email: rmathew AT hotmail DOT com
Bangalore,
INDIA. Web: http://ranjitmathew.tripod.com/