Patch: addr2line and the name of the executable
Mohan Embar
gnustuff@thisiscool.com
Wed Feb 26 05:01:00 GMT 2003
Hi People,
This patch, using GetModuleFilename() on Win32 to retrieve the
name of the executable, addresses a need identified by Ranjit.
EXECUTIVE SUMMARY
- The patch is needed because, as Ranjit pointed out,
stack traces are broken on Win32 because addr2line
needs an ".exe" extension, which isn't always present
in argv[0]. Using GetModuleFilename() remedies this.
- The patch introduces an interface whereby other
platforms can also opt to provide implementation-specific
name for _Jv_ThisExecutable() other than argv[0].
- The patch only changes behavior on mingw32. All
other platforms are unaffected. I've tested this
by building gcc/gcj on i686 Linux and Win32 and
everything looks okay.
BORING DETAILS
Here is Ranjit's original post, which identifies
this need:
http://gcc.gnu.org/ml/java/2003-02/msg00284.html
My approach is outlined here:
http://gcc.gnu.org/ml/java/2003-02/msg00306.html
There was a thread among Ranjit, Andrew and me concerning
this which started here:
http://gcc.gnu.org/ml/java/2003-02/msg00284.html
In the end, I opted to have gnu.gcj.progname always
return _Jv_ThisExecutable() based on this reasoning:
http://gcc.gnu.org/ml/java/2003-02/msg00491.html
THE PATCH
What follows is my patch. I've also sent it as an
attachment because the diff for prims.cc picked
up an embedded page break. (Why are we putting
embedded control characters in our source files?!)
-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/
ChangeLog
2003-02-25 Mohan Embar <gnustuff@thisiscool.com>
* configure.in: added AC_DEFINE(HAVE_PLATFORM_GETEXENAME)
for mingw
* acconfig.h: new HAVE_PLATFORM_GETEXENAME: undefine
* configure: rebuilt
* include/config.h.in: rebuilt (using autoheader)
* prims.cc: if HAVE_PLATFORM_GETEXENAME is defined, declare an
external _Jv_platform_exename for retrieving our process' executable
name. This mechanism overrides any other means of deterimining the
executable name except DISABLE_MAIN_ARGS
* win32.cc: _Jv_platform_exename implementation using Win32
GetModuleFileName
Index: acconfig.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/acconfig.h,v
retrieving revision 1.26
diff -u -2 -r1.26 acconfig.h
--- acconfig.h 29 Aug 2002 18:05:14 -0000 1.26
+++ acconfig.h 25 Feb 2003 13:42:48 -0000
@@ -138,4 +138,7 @@
#undef HAVE_PROC_SELF_EXE
+/* Define if you have a platform-specific _Jv_platform_exename */
+#undef HAVE_PLATFORM_GETEXENAME
+
/* Define if you have dladdr() */
#undef HAVE_DLADDR
Index: configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/configure.in,v
retrieving revision 1.142.4.6
diff -u -2 -r1.142.4.6 configure.in
--- configure.in 20 Feb 2003 09:12:24 -0000 1.142.4.6
+++ configure.in 25 Feb 2003 13:42:50 -0000
@@ -542,4 +542,9 @@
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
fi
Index: prims.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.76
diff -u -2 -r1.76 prims.cc
--- prims.cc 5 Dec 2002 00:49:29 -0000 1.76
+++ prims.cc 25 Feb 2003 13:42:52 -0000
@@ -100,8 +100,14 @@
void (*_Jv_JVMPI_Notify_THREAD_END) (JVMPI_Event *event);
#endif
-
extern "C" void _Jv_ThrowSignal (jthrowable) __attribute ((noreturn));
+#ifdef HAVE_PLATFORM_GETEXENAME
+extern "C" void _Jv_platform_exename(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
+
// Just like _Jv_Throw, but fill in the stack trace first. Although
// this is declared extern in order that its name not be mangled, it
@@ -962,8 +968,11 @@
-#ifdef DISABLE_MAIN_ARGS
+#if defined(DISABLE_MAIN_ARGS)
_Jv_ThisExecutable ("[Embedded App]");
-#else
-#ifdef HAVE_PROC_SELF_EXE
+#elif defined(HAVE_PLATFORM_GETEXENAME)
+ char exec_name[300];
+ _Jv_platform_exename(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 ());
@@ -971,6 +980,5 @@
#else
_Jv_ThisExecutable (argv[0]);
-#endif /* HAVE_PROC_SELF_EXE */
-#endif /* DISABLE_MAIN_ARGS */
+#endif /* DISABLE_MAIN_ARGS, HAVE_PLATFORM_GETEXENAME, HAVE_PROC_SELF_EXE */
try
Index: win32.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/win32.cc,v
retrieving revision 1.12.22.2
diff -u -2 -r1.12.22.2 win32.cc
--- win32.cc 19 Feb 2003 16:27:22 -0000 1.12.22.2
+++ win32.cc 25 Feb 2003 13:42:52 -0000
@@ -197,4 +197,9 @@
}
+extern "C" void _Jv_platform_exename(char* buf, int size)
+{
+ GetModuleFileName(NULL, buf, size);
+}
+
/* Store up to SIZE return address of the current program state in
ARRAY and return the exact number of values stored. */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ntvexe.diff
Type: application/octet-stream
Size: 3631 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20030226/8224146a/attachment.obj>
More information about the Java-patches
mailing list