addr2line and the name of the executable

Mohan Embar
Wed Feb 19 08:41:00 GMT 2003

>Would you be willing to let me get my feet wet by trying to code
>this up according to Andrew's and your specifications?

Hi People,
Here's what I came up with: I don't know if I'm on to something
or delusional (probably the latter). This isn't in diff
format because my build environment is kind of messed up right
now and I primarily want to get feedback on this approach. Please
indulge a bit of verbosity here because I'm new at this.

The motivation: allow for a a generic, yet platform-specific means
of determining the executable name of the current process. This might
also allow certain embedded targets to specify something other than
[Embedded App].

I've coded this and it works, but I'm worried that I might be way
off the mark here. Also addr2line doesn't seem to care for the absolute
path with backslashes on Win32 and stack traces don't work - haven't had
time to look into this.

First, I added this AC_DEFINE to

     case $host in
       # Has a platform-specific mechanism for
       # for retrieving the name of the executable.

I also added the corresponding line to acconfig.h:

/* Define if you have a platform-specific _Jv_GetPlatformExecutableName */

I reran autoconf and autoheader.

In, we have:

extern "C" void _Jv_GetPlatformExecutableName(char* buf, int size);
  // this platform has a specific way of retrieving our executable
  // name which overrides other mechanisms (such as assuming
  // argv[0], etc.)

Later in, we add one more test in _Jv_RunMain:

#if defined(DISABLE_MAIN_ARGS)
  _Jv_ThisExecutable ("[Embedded App]");
  char exec_name[300];
  _Jv_GetPlatformExecutableName(exec_name, sizeof(exec_name));
  _Jv_ThisExecutable (exec_name);
#elif defined(HAVE_PROC_SELF_EXE)
  char exec_name[20];
  sprintf (exec_name, "/proc/%d/exe", getpid ());
  _Jv_ThisExecutable (exec_name);
  _Jv_ThisExecutable (argv[0]);

Finally, we provide our platform-specific implementation

extern "C" void _Jv_GetPlatformExecutableName(char* buf, int size)
  GetModuleFileName(NULL, buf, size);

In essence, declares a common interface for a platform-specific
mechanism of obtaining the name of the current process.

-- Mohan

More information about the Java mailing list