diff options
author | rmathew <rmathew@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-06-29 14:57:39 +0000 |
---|---|---|
committer | rmathew <rmathew@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-06-29 14:57:39 +0000 |
commit | 795a5d4021e6db957b3f2e18e1468bd7064fda28 (patch) | |
tree | c184ad263e2312d7a38fbced2682933d1ad843bc /libjava/win32.cc | |
parent | a589f7967ccc42f329a1627c541db03478c59eeb (diff) | |
download | gcc-795a5d4021e6db957b3f2e18e1468bd7064fda28.tar.gz |
* gcj/javaprims.h (_Jv_uintptr_t): New typedef similar to uintptr_t in
C99.
* include/java-stack.h: Include stdlib.h.
(_Jv_AddrInfo): New structure to hold address information.
* include/posix.h (_Jv_platform_dladdr): Declare.
* include/win32.h (_Jv_platform_dladdr): Declare.
(backtrace): Remove declaration.
* posix.cc: Include dlfcn.h if available. Include java-stack.h.
(_Jv_platform_dladdr): Define.
* win32.cc: Include string.h. Include java-stack.h.
(backtrace): Remove.
(_Jv_platform_dladdr): Define.
* sysdep/i386/backtrace.h (fallback_backtrace): Check that a potential
frame pointer value is 32-bit word-aligned. Use operand of the CALL
instruction calling the current function to find its starting address.
* stacktrace.cc: Do not include dlfcn.h. Include platform.h.
(_Jv_StackTrace::getLineNumberForFrame): Use _Jv_platform_dladdr()
instead of dladdr().
(_Jv_StackTrace::GetStackTraceElements): Use nCodeMap even for Windows.
(_Jv_StackTrace::GetClassContext): Use fallback_backtrace() for
targets with SJLJ exceptions instead of using _Unwind_Backtrace().
(_Jv_StackTrace::GetFirstNonSystemClassLoader): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@115069 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/win32.cc')
-rw-r--r-- | libjava/win32.cc | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/libjava/win32.cc b/libjava/win32.cc index a0ae0f0f9cb..a78f814c687 100644 --- a/libjava/win32.cc +++ b/libjava/win32.cc @@ -12,8 +12,11 @@ details. */ #include <platform.h> #include <sys/timeb.h> #include <stdlib.h> +#include <string.h> #include <fcntl.h> +#include <java-stack.h> + #include <java/lang/ArithmeticException.h> #include <java/lang/UnsupportedOperationException.h> #include <java/io/IOException.h> @@ -442,28 +445,6 @@ _Jv_platform_initProperties (java::util::Properties* newprops) } } -/* Store up to SIZE return address of the current program state in - ARRAY and return the exact number of values stored. */ -int -backtrace (void **__array, int __size) -{ - register void *_ebp __asm__ ("ebp"); - register void *_esp __asm__ ("esp"); - unsigned int *rfp; - - int i=0; - for (rfp = *(unsigned int**)_ebp; - rfp && i < __size; - rfp = *(unsigned int **)rfp) - { - int diff = *rfp - (unsigned int)rfp; - if ((void*)rfp < _esp || diff > 4 * 1024 || diff < 0) break; - - __array[i++] = (void*)(rfp[1]-4); - } - return i; -} - int _Jv_pipe (int filedes[2]) { @@ -477,3 +458,42 @@ _Jv_platform_close_on_exec (HANDLE h) // no effect under Win9X. SetHandleInformation (h, HANDLE_FLAG_INHERIT, 0); } + +// Given an address, find the object that defines it and the nearest +// defined symbol to that address. Returns 0 if no object defines this +// address. +int +_Jv_platform_dladdr (const void *addr, _Jv_AddrInfo *info) +{ + // Since we do not have dladdr() on Windows, we use a trick involving + // VirtualQuery() to find the module (EXE or DLL) that contains a given + // address. This was taken from Matt Pietrek's "Under the Hood" column + // for the April 1997 issue of Microsoft Systems Journal. + + MEMORY_BASIC_INFORMATION mbi; + if (!VirtualQuery (addr, &mbi, sizeof (mbi))) + { + return 0; + } + + HMODULE hMod = (HMODULE) mbi.AllocationBase; + + char moduleName[MAX_PATH]; + + // FIXME: We explicitly use the ANSI variant of the function here. + if (!GetModuleFileNameA (hMod, moduleName, sizeof (moduleName))) + { + return 0; + } + + char *file_name = (char *)(malloc (strlen (moduleName) + 1)); + strcpy (file_name, moduleName); + info->file_name = file_name; + + // FIXME. + info->base = NULL; + info->sym_name = NULL; + info->sym_addr = NULL; + + return 1; +} |