addr2line and the name of the executable

Andrew Haley
Tue Feb 18 20:30:00 GMT 2003

Ranjit Mathew writes:
 > Hi,
 >     While playing with Mohan's GCJ 3.3 build, I noticed 
 > that I get a proper stack trace with mangled symbols 
 > only if I explicitly invoke my program like "foo.exe" 
 > instead of the usual "foo".
 > It turns out that this is because addr2line expects the 
 > actual file name of the executable with the "-e" flag and 
 > not argv[0] which is what is effectively being passed 
 > to it.

You'll also need to prefix the real path to the executable, I'd

 > I had not noticed it before with my builds simply because
 > the mingw-local patches change argv[0] to the fully 
 > qualified name of the executable. (Which itself is 
 > suspect behaviour since "By convention, argv[0] is the 
 > name by which the program was invoked..." - K&R, 
 > 2nd Ed., Section 5.10.)
 > It manifests in Mohan's build because he uses stock GCC
 > sources instead of mingw-local patched sources.
 > To resolve this, is it OK if I have a "#ifdef WIN32"-ed
 > code in gnu::gcj::runtime::NameFinder::getExecutable( )
 > that just calls the Win32 GetModuleFileName( ) function
 > to retrieve the executable file for the current process?

Sounds good, altho' personally I'd put that function in a Win32 file.
I'd like to get rid of OS specific ifdefs.

 > If yes, I'll submit a patch for this.
 > AFAICT, on Linux, _Jv_ThisExecutable( ) would return
 > "/proc/nn/exe", where "nn" is the PID of the current
 > process and this path is just a symbolic link to the
 > real executable.

It's a link to the executable, yes.

 > So the property "gnu.gcj.progname" would not really be "the name by
 > which the program was invoked" - isn't that (sort of) wrong?

The comment only says "similar to".  It depends on what you want the
information for.  If you really want the file, that's just what you


More information about the Java mailing list