addr2line and the name of the executable
Mohan Embar
gnustuff@thisiscool.com
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 configure.in
case $host in
*-linux*)
AC_DEFINE(HAVE_PROC_SELF_EXE)
;;
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
*mingw*)
# Has a platform-specific mechanism for
# for retrieving the name of the executable.
AC_DEFINE(HAVE_PLATFORM_GETEXENAME)
;;
esac
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
I also added the corresponding line to acconfig.h:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/* Define if you have a platform-specific _Jv_GetPlatformExecutableName */
#undef HAVE_PLATFORM_GETEXENAME
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
I reran autoconf and autoheader.
In prims.cc, we have:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#ifdef HAVE_PLATFORM_GETEXENAME
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.)
#endif
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Later in prims.cc, we add one more test in _Jv_RunMain:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#if defined(DISABLE_MAIN_ARGS)
_Jv_ThisExecutable ("[Embedded App]");
#elif defined(HAVE_PLATFORM_GETEXENAME)
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);
#else
_Jv_ThisExecutable (argv[0]);
#endif /* DISABLE_MAIN_ARGS, HAVE_PLATFORM_GETEXENAME, HAVE_PROC_SELF_EXE */
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Finally, we provide our platform-specific implementation
in win32.cc:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
extern "C" void _Jv_GetPlatformExecutableName(char* buf, int size)
{
GetModuleFileName(NULL, buf, size);
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
In essence, prims.cc declares a common interface for a platform-specific
mechanism of obtaining the name of the current process.
-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/
More information about the Java
mailing list