You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gs...@apache.org on 2008/01/30 19:44:08 UTC

svn commit: r616840 - in /harmony/enhanced/drlvm/trunk/vm: include/open/ port/include/ port/src/misc/linux/ port/src/misc/win/ vmcore/include/ vmcore/src/class_support/ vmcore/src/init/ vmcore/src/stack/ vmcore/src/util/ vmcore/src/util/em64t/base/ vmc...

Author: gshimansky
Date: Wed Jan 30 10:44:06 2008
New Revision: 616840

URL: http://svn.apache.org/viewvc?rev=616840&view=rev
Log:
Applied patch from HARMONY-5297
[drlvm][signals] It would be very helpful if crash handler printed VM memory map, command line arguments and OS environment


Added:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/em64t/base/signals_arch.cpp   (with props)
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/signals_arch.cpp   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/vm/include/open/types.h
    harmony/enhanced/drlvm/trunk/vm/port/include/port_sysinfo.h
    harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysinfo.c
    harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/dso.c
    harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysinfo.c
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_stack.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/stack_dump.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/method_lookup.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_properties.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/crash_handler.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/crash_handler.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/exception_filter.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/signals_common.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_em64t.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ia32.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/stack_dump_platf.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_stack.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/em64t/nt_exception_filter.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/include/exception_filter.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/stack_dump_platf.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/include/open/types.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/include/open/types.h?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/include/open/types.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/include/open/types.h Wed Jan 30 10:44:06 2008
@@ -140,12 +140,12 @@
 #else 
 #define PI_FMT "ll"
 #endif
-#define W_PI_FMT "016"PI_FMT
+#define W_PI_FMT "016"PI_FMT"x"
 #else
 #define POINTER_SIZE_INT uint32
 #define POINTER_SIZE_SINT int32
 #define PI_FMT ""
-#define W_PI_FMT "08"PI_FMT
+#define W_PI_FMT "08"PI_FMT"x"
 #endif // POINTER64
 
 /**

Modified: harmony/enhanced/drlvm/trunk/vm/port/include/port_sysinfo.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/include/port_sysinfo.h?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/include/port_sysinfo.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/include/port_sysinfo.h Wed Jan 30 10:44:06 2008
@@ -44,11 +44,10 @@
 /**
  * Determines the absolute path of the executing process.
  * @param[out] self_name - the pointer to the requested path string
- * @param pool           - a pool to allocate return buffer
  * @return <code>APR_SUCCESS</code> if OK; otherwise, an error code.
+ * @note The value returned can be freed by <code>STD_FREE</code> macro.
  */
-APR_DECLARE(apr_status_t) port_executable_name(char** self_name,
-                                   apr_pool_t* pool);
+APR_DECLARE(apr_status_t) port_executable_name(char** self_name);
 
 /**
 * Returns the number of processors in the system.

Modified: harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysinfo.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysinfo.c?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysinfo.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/misc/linux/sysinfo.c Wed Jan 30 10:44:06 2008
@@ -24,33 +24,53 @@
 #include <sys/utsname.h>
 #include <limits.h>
 #include <errno.h>
+#include "port_malloc.h"
 #include "port_sysinfo.h"
 #include <apr_strings.h>
 #if defined(FREEBSD)
+#define _GNU_SOURCE
 #include <dlfcn.h>
 extern int main (int argc, char **argv, char **envp);
 #endif
 
-APR_DECLARE(apr_status_t) port_executable_name(char** self_name,
-								   apr_pool_t* pool) {
+APR_DECLARE(apr_status_t) port_executable_name(char** self_name) {
+
+    char* buf;
 
 #if defined(FREEBSD)
-        Dl_info info;
-        if (dladdr( (const void*)&main, &info) == 0) {
-                return APR_ENOENT;
-        }
-        char* buf = apr_pstrdup(pool, info.dli_fname);
+    Dl_info info;
+
+    if (dladdr( (const void*)&main, &info) == 0) {
+        return APR_ENOENT;
+    }
+
+    buf = (char*)STD_MALLOC(strlen(info.dli_fname) + 1);
+
+    if (!buf)
+        return APR_ENOMEM;
+
+    strcpy(buf, info.dli_fname);
 #else
-	char* buf = apr_palloc(pool, PATH_MAX + 1); 
-	int n = readlink("/proc/self/exe", buf, PATH_MAX);
-	if (n == -1) {
-		return apr_get_os_error();
-	}
-	buf[n] = '\0';
+    char tmpbuf[PATH_MAX + 1];
+
+    int n = readlink("/proc/self/exe", tmpbuf, PATH_MAX);
+
+    if (n == -1) {
+        return apr_get_os_error();
+    }
+
+    tmpbuf[n] = '\0';
+
+    buf = (char*)STD_MALLOC(n + 1);
+
+    if (!buf)
+        return APR_ENOMEM;
+
+    strcpy(buf, tmpbuf);
 #endif
-	*self_name = buf;
 
-	return APR_SUCCESS;
+    *self_name = buf;
+    return APR_SUCCESS;
 }
 
 APR_DECLARE(int) port_CPUs_number(void) {

Modified: harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/dso.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/dso.c?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/dso.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/dso.c Wed Jan 30 10:44:06 2008
@@ -26,8 +26,9 @@
 #include <apr_strings.h>
 #include <apr_env.h>
 
-#include "port_dso.h"
+#include "port_malloc.h"
 #include "port_sysinfo.h"
+#include "port_dso.h"
 
 struct apr_dso_handle_t {
 	apr_pool_t *pool;
@@ -36,48 +37,53 @@
 };
 
 APR_DECLARE(apr_status_t) port_dso_load_ex(apr_dso_handle_t** handle,
-									  const char* path,
-									  uint32 mode,
-									  apr_pool_t* pool){
-	/*
-	* FIXME Windows does not support lazy dll resolution a la Linux's RTLD_LAZY.
-	* Proper support for it requires hacking of APR DSO functions. 
-	* Just ignore the <code>mode<code> param for now.
-	*/
+                                           const char* path,
+                                           uint32 mode,
+                                           apr_pool_t* pool){
+    /*
+    * FIXME Windows does not support lazy dll resolution a la Linux's RTLD_LAZY.
+    * Proper support for it requires hacking of APR DSO functions. 
+    * Just ignore the <code>mode<code> param for now.
+    */
 
     /*if (mode == PORT_DSO_DEFAULT || !path) {*/
-    	char *self_path;
-		if (!path) {
-			port_executable_name(&self_path, pool);
-			return apr_dso_load(handle, (const char*)self_path, pool);
-		}
-
-		return apr_dso_load(handle, path, pool);
-	/*} else {
-		HINSTANCE native_handle = NULL;
-		DWORD flag = (mode & PORT_DSO_BIND_DEFER) ? 
-			(DONT_RESOLVE_DLL_REFERENCES) : (0);
-		char *cp = apr_pstrdup(pool, path);
-		char *p = cp;
-		while ((p = strchr(p, '/')) != NULL) {
-			*p = '\\';
-		}
-
-		native_handle = LoadLibraryEx(cp, NULL, flag);
-		*handle = apr_palloc(pool, sizeof(apr_dso_handle_t));
-		if (native_handle == 0) {
-			native_handle = LoadLibraryEx(cp, NULL, flag | LOAD_WITH_ALTERED_SEARCH_PATH);
-			if (native_handle == 0) {
-				DWORD sys_err = apr_get_os_error();
-				(*handle)->error = sys_err;
-				return sys_err;
-			}
-		}
-		(*handle)->handle = native_handle;
-		(*handle)->pool = pool;
-		(*handle)->error = APR_SUCCESS;
-		return APR_SUCCESS;
-	}*/
+        char *self_path;
+        apr_status_t res;
+
+        if (!path) {
+            port_executable_name(&self_path);
+            res = apr_dso_load(handle, (const char*)self_path, pool);
+            STD_FREE(self_path);
+            return res;
+        }
+
+        return apr_dso_load(handle, path, pool);
+
+    /*} else {
+        HINSTANCE native_handle = NULL;
+        DWORD flag = (mode & PORT_DSO_BIND_DEFER) ? 
+            (DONT_RESOLVE_DLL_REFERENCES) : (0);
+        char *cp = apr_pstrdup(pool, path);
+        char *p = cp;
+        while ((p = strchr(p, '/')) != NULL) {
+            *p = '\\';
+        }
+
+        native_handle = LoadLibraryEx(cp, NULL, flag);
+        *handle = apr_palloc(pool, sizeof(apr_dso_handle_t));
+        if (native_handle == 0) {
+            native_handle = LoadLibraryEx(cp, NULL, flag | LOAD_WITH_ALTERED_SEARCH_PATH);
+            if (native_handle == 0) {
+                DWORD sys_err = apr_get_os_error();
+                (*handle)->error = sys_err;
+                return sys_err;
+            }
+        }
+        (*handle)->handle = native_handle;
+        (*handle)->pool = pool;
+        (*handle)->error = APR_SUCCESS;
+        return APR_SUCCESS;
+    }*/
 }
  
 APR_DECLARE(apr_status_t) port_dso_search_path(char** path,

Modified: harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysinfo.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysinfo.c?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysinfo.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/port/src/misc/win/sysinfo.c Wed Jan 30 10:44:06 2008
@@ -16,7 +16,9 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <windows.h>
+#include "port_malloc.h"
 #include "port_sysinfo.h"
 
 APR_DECLARE(int) port_CPUs_number() {
@@ -93,17 +95,19 @@
 	return APR_SUCCESS;
 }
 
-APR_DECLARE(apr_status_t) port_executable_name(char** self_name,
-								   apr_pool_t* pool){
+APR_DECLARE(apr_status_t) port_executable_name(char** self_name){
 
-	char* buf = apr_palloc(pool, _MAX_PATH*2); /*XXX result in TCHARs */
-	int len = GetModuleFileName(0, buf, _MAX_PATH);
-	if (0 == len) {
-		return apr_get_os_error();
-	}
-	
-	*self_name = buf;
-	return APR_SUCCESS;
+    char buf[_MAX_PATH*2]; /*XXX result in TCHARs */
+    int len = GetModuleFileName(0, buf, _MAX_PATH);
+    if (0 == len) {
+        return apr_get_os_error();
+    }
+
+    *self_name = STD_MALLOC(strlen(buf) + 1);
+    if (*self_name)
+        strcpy(*self_name, buf);
+
+    return APR_SUCCESS;
 }
 
 APR_DECLARE(const char *) port_CPU_architecture(void){

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_stack.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_stack.h?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_stack.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_stack.h Wed Jan 30 10:44:06 2008
@@ -57,6 +57,7 @@
 void native_unwind_interrupted_frame(jvmti_thread_t thread, void** p_ip, void** p_bp, void** p_sp);
 bool native_is_ip_in_modules(native_module_t* modules, void* ip);
 bool native_is_ip_stub(void* ip);
+char* native_get_stub_name(void* ip, char* buf, size_t buflen);
 
 
 #ifdef __cplusplus

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/stack_dump.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/stack_dump.h?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/stack_dump.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/stack_dump.h Wed Jan 30 10:44:06 2008
@@ -59,7 +59,6 @@
 };
 
 
-
 /**
  * Prints a stack trace using given register context for current thread
  */
@@ -77,6 +76,8 @@
 void sd_parse_module_info(native_module_t* module, void* ip);
 void sd_get_c_method_info(MethodInfo* info, native_module_t* module, void* ip);
 int sd_get_cur_tid();
+void sd_init_crash_handler();
+void sd_print_cwdcmdenv();
 
 // general functions to call from platform-dependent code
 const char* sd_get_module_type(const char* short_name);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/method_lookup.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/method_lookup.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/method_lookup.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/method_lookup.cpp Wed Jan 30 10:44:06 2008
@@ -460,6 +460,19 @@
 
 
 
+CodeChunkInfo* vm_find_method(void *addr)
+{
+    Global_Env *env = VM_Global_State::loader_env;
+
+    if (NULL == env || NULL == env->vm_methods)
+        return NULL;
+
+    return env->vm_methods->find(addr);
+
+} //vm_identify_eip
+
+
+
 VM_Code_Type vm_identify_eip(void *addr)
 {
     Global_Env *env = VM_Global_State::loader_env;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_properties.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_properties.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_properties.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_properties.cpp Wed Jan 30 10:44:06 2008
@@ -156,9 +156,10 @@
     // java.home initialization, try to find absolute location of the executable and set
     // java.home to the parent directory.
     char *launcher_dir;
-    if (port_executable_name(&launcher_dir, prop_pool) != APR_SUCCESS) {
+    if (port_executable_name(&launcher_dir) != APR_SUCCESS) {
         LDIE(13, "Failed to find executable location");
     }
+    STD_FREE(launcher_dir);
 
     properties.set_new("java.vm.specification.version", "1.0");
     properties.set_new("java.vm.specification.vendor", "Sun Microsystems Inc.");

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/stack/stack_dump.cpp Wed Jan 30 10:44:06 2008
@@ -33,6 +33,7 @@
 #include "native_stack.h"
 #include "native_modules.h"
 #include "natives_support.h"
+#include "exception_filter.h"
 
 #include "stack_dump.h"
 
@@ -43,7 +44,7 @@
 static void sd_fill_modules()
 {
     if (g_modules)
-        clear_native_modules(&g_modules);
+        return;
 
     int count;
     bool res = get_all_native_modules(&g_modules, &count);
@@ -61,7 +62,14 @@
         return;
 
     hymutex_lock(sd_lock);
-    sd_fill_modules();
+
+    if (g_modules)
+        clear_native_modules(&g_modules);
+
+    int count;
+    res = get_all_native_modules(&g_modules, &count);
+    assert(res && g_modules && count);
+
     hymutex_unlock(sd_lock);
 }
 #endif // SD_UPDATE_MODULES
@@ -178,20 +186,26 @@
     while ((si && !si_is_past_end(si)) || frame_num < num_frames)
     {
         MethodInfo m;
+        void* cur_ip = frames[frame_num].ip;
 
         if (frame_num < num_frames && frames[frame_num].java_depth < 0)
         {
-            if (native_is_ip_stub(frames[frame_num].ip)) // Generated stub
+            if (native_is_ip_stub(cur_ip)) // Generated stub
             {
-                fprintf(stderr, "%3d: 0x%"W_PI_FMT"X  <Generated stub>\n",
-                    count++, (POINTER_SIZE_INT)frames[frame_num].ip);
+                char buf[81];
+                char* stub_name =
+                    native_get_stub_name(cur_ip, buf, sizeof(buf));
+
+                fprintf(stderr, "%3d: 0x%"W_PI_FMT": stub '%s'\n",
+                    count++, (POINTER_SIZE_INT)cur_ip,
+                    stub_name ? stub_name : "??");
                 ++frame_num;
                 continue;
             }
 
             // pure native frame
-            native_module_t* module = find_native_module(g_modules, frames[frame_num].ip);
-            sd_get_c_method_info(&m, module, frames[frame_num].ip);
+            native_module_t* module = find_native_module(g_modules, cur_ip);
+            sd_get_c_method_info(&m, module, cur_ip);
             sd_print_line(count++, &m);
             ++frame_num;
             continue;
@@ -207,8 +221,8 @@
         if (si_is_native(si) && frame_num < num_frames)
         {
             // Print information from native stack trace for JNI frames
-            native_module_t* module = find_native_module(g_modules, frames[frame_num].ip);
-            sd_get_c_method_info(&m, module, frames[frame_num].ip);
+            native_module_t* module = find_native_module(g_modules, cur_ip);
+            sd_get_c_method_info(&m, module, cur_ip);
             sd_print_line(count, &m);
         }
         else if (si_is_native(si) && frame_num >= num_frames)
@@ -350,15 +364,18 @@
 }
 
 
-static void sd_print_modules_info(Registers* regs)
+static void sd_print_module_info(Registers* regs)
 {
-#ifndef SD_UPDATE_MODULES
+#ifdef SD_UPDATE_MODULES
     sd_fill_modules(); // Fill modules table if needed
 #endif
 
     native_module_t* module = find_native_module(g_modules, (void*)regs->get_ip());
     sd_parse_module_info(module, (void*)regs->get_ip());
+}
 
+static void sd_print_modules()
+{
     fprintf(stderr, "\nLoaded modules:\n\n");
     dump_native_modules(g_modules, stderr);
 }
@@ -423,11 +440,20 @@
 
     hymutex_lock(sd_lock);
 
+    // Print register info
+    print_reg_state(regs);
+
+    // Print crashed modile info
+    sd_print_module_info(regs);
+
+    // Print program environment info
+    sd_print_cwdcmdenv();
+
+    // Print the whole list of modules
+    sd_print_modules();
+
     VM_thread* thread = get_thread_ptr(); // Can be NULL for pure native thread
     native_frame_t* frames = NULL;
-
-    // Print crashed modile info and whole list of modules
-    sd_print_modules_info(regs);
 
     // Print threads info
     sd_print_threads_info(thread);

Added: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/em64t/base/signals_arch.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/em64t/base/signals_arch.cpp?rev=616840&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/em64t/base/signals_arch.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/em64t/base/signals_arch.cpp Wed Jan 30 10:44:06 2008
@@ -0,0 +1,41 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <stdio.h>
+#include "vm_core_types.h"
+
+void print_reg_state(Registers* regs)
+{
+    fprintf(stderr, "Registers:\n");
+    fprintf(stderr, "    RAX: 0x%"W_PI_FMT", RBX: 0x%"W_PI_FMT"\n",
+        regs->rax, regs->rbx);
+    fprintf(stderr, "    RCX: 0x%"W_PI_FMT", RDX: 0x%"W_PI_FMT"\n",
+        regs->rcx, regs->rdx);
+    fprintf(stderr, "    RSI: 0x%"W_PI_FMT", RDI: 0x%"W_PI_FMT"\n",
+        regs->rsi, regs->rdi);
+    fprintf(stderr, "    RSP: 0x%"W_PI_FMT", RBP: 0x%"W_PI_FMT"\n",
+        regs->rsp, regs->rbp);
+    fprintf(stderr, "    R8 : 0x%"W_PI_FMT", R9 : 0x%"W_PI_FMT"\n",
+        regs->r8,  regs->r9);
+    fprintf(stderr, "    R10: 0x%"W_PI_FMT", R11: 0x%"W_PI_FMT"\n",
+        regs->r10, regs->r11);
+    fprintf(stderr, "    R12: 0x%"W_PI_FMT", R13: 0x%"W_PI_FMT"\n",
+        regs->r12, regs->r13);
+    fprintf(stderr, "    R14: 0x%"W_PI_FMT", R15: 0x%"W_PI_FMT"\n",
+        regs->r14, regs->r15);
+    fprintf(stderr, "    RIP: 0x%"W_PI_FMT"\n", regs->rip);
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/em64t/base/signals_arch.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/signals_arch.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/signals_arch.cpp?rev=616840&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/signals_arch.cpp (added)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/signals_arch.cpp Wed Jan 30 10:44:06 2008
@@ -0,0 +1,29 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <stdio.h>
+#include "vm_core_types.h"
+
+void print_reg_state(Registers* regs)
+{
+    fprintf(stderr, "Registers:\n");
+    fprintf(stderr, "    EAX: 0x%"W_PI_FMT", EBX: 0x%"W_PI_FMT", ECX: 0x%"W_PI_FMT", EDX: 0x%"W_PI_FMT"\n",
+        regs->eax, regs->ebx, regs->ecx, regs->edx);
+    fprintf(stderr, "    ESI: 0x%"W_PI_FMT", EDI: 0x%"W_PI_FMT", ESP: 0x%"W_PI_FMT", EBP: 0x%"W_PI_FMT"\n",
+        regs->esi, regs->edi, regs->esp, regs->ebp);
+    fprintf(stderr, "    EIP: 0x%"W_PI_FMT"\n", regs->eip);
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/ia32/base/signals_arch.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/crash_handler.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/crash_handler.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/crash_handler.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/crash_handler.cpp Wed Jan 30 10:44:06 2008
@@ -24,16 +24,15 @@
 #include <stdio.h>
 #include <semaphore.h>
 
+#include "vm_core_types.h"
 #include "environment.h"
+#include "port_sysinfo.h"
 #include "platform_lowlevel.h"
+#include "exception_filter.h"
 
 #include "crash_handler.h"
-#if defined(FREEBSD)
-#include <dlfcn.h>
-extern int main (int argc, char **argv, char **envp);
-#endif
 
-static char g_executable[1024]; // Executable file name
+static char* g_executable = NULL;// Executable file name
 static sem_t g_sem_started;     // Prevent forking debugger more than once
 static bool g_prepared = false; // Flag is set if gdb crash handler is prepared
 static bool g_enabled = false;  // vm.crash_handler value is stored here
@@ -47,21 +46,19 @@
 
 bool is_gdb_crash_handler_enabled()
 {
-    if (!g_prepared)
-        return false;
-
-    if (VM_Global_State::loader_env == NULL)
-        return g_enabled;
-
-    return get_boolean_property("vm.crash_handler", FALSE, VM_PROPERTIES);
+    return (g_prepared && g_enabled);
 }
 
-bool gdb_crash_handler()
+bool gdb_crash_handler(Registers* regs)
 {
-    if (!g_prepared ||
+    if (!g_prepared || !g_enabled ||
+        !g_executable ||
         0 != sem_trywait(&g_sem_started)) // gdb was already started
         return false;
 
+    // Print register info
+    print_reg_state(regs);
+
     static const int tid_len = 10;
     char tid[tid_len];
     snprintf(tid, tid_len, "%d", gettid());
@@ -87,35 +84,28 @@
 #pragma warning ( pop )
 #endif
 
-int get_executable_name(char executable[], int len) {
-#if defined(FREEBSD)
-    Dl_info info;
-    if (dladdr( (const void*)&main, &info) == 0) {
-        return -1;
-    }
-    strncpy(executable, info.dli_fname, len);
-    executable[len] = '\0';
-    return 0;
-#else
-    int n = readlink("/proc/self/exe", executable, len);
-    if (n == -1) {
-        perror("Can't determine executable name");
+static int get_executable_name()
+{
+    if (port_executable_name(&g_executable) != 0)
         return -1;
-    }
-    executable[n] = '\0';
-    return 0;
-#endif
+
+    return g_executable ? 0 : -1;
 }
 
 
-int init_gdb_crash_handler()
+void init_gdb_crash_handler()
 {
     if (sem_init(&g_sem_started, 0, 1) != 0 ||
-        get_executable_name(g_executable, sizeof(g_executable)) != 0)
-        return -1;
+        get_executable_name() != 0)
+    {
+        g_prepared = false;
+        return;
+    }
 
-    g_prepared = true;
+    if (!VM_Global_State::loader_env)
+        g_enabled = true;
+    else
+        g_enabled = get_boolean_property("vm.crash_handler", FALSE, VM_PROPERTIES);
 
-    assert(VM_Global_State::loader_env);
-    g_enabled = get_boolean_property("vm.crash_handler", FALSE, VM_PROPERTIES);
+    g_prepared = true;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/ia32_em64t/signals_common.cpp Wed Jan 30 10:44:06 2008
@@ -74,7 +74,7 @@
 
 
 extern "C" {
-static void __attribute__ ((used, cdecl)) c_exception_handler(Class* exn_class, bool java_code) {
+static void DECL_CHANDLER c_exception_handler(Class* exn_class, bool java_code) {
     // this exception handler is executed *after* NT exception handler returned
     DebugUtilsTI* ti = VM_Global_State::loader_env->TI;
     // Create local copy for registers because registers in TLS can be changed
@@ -494,8 +494,6 @@
 
 static void process_crash(Registers* regs)
 {
-    // Print register info
-    print_state(regs);
     // print stack trace
     sd_print_stack(regs);
 }
@@ -508,7 +506,7 @@
     fprintf(stderr, "Signal is reported: %s\n", message);
 
     if (!is_gdb_crash_handler_enabled() ||
-        !gdb_crash_handler())
+        !gdb_crash_handler(regs))
     {
         process_crash(regs);
     }
@@ -622,6 +620,9 @@
 
     // Prepare gdb crash handler
     init_gdb_crash_handler();
+
+    // Prepare general crash handler
+    sd_init_crash_handler();
 
 } //initialize_signals
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/crash_handler.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/crash_handler.h?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/crash_handler.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/crash_handler.h Wed Jan 30 10:44:06 2008
@@ -22,6 +22,8 @@
 #ifndef _CRASH_HANDLER_H
 #define _CRASH_HANDLER_H
 
+#include "vm_core_types.h"
+
 /**
  * \file
  * Provides definition needed to install gdb crash handler.
@@ -39,13 +41,13 @@
  *
  * @return 0 on success or negative value on failure
  */
-int init_gdb_crash_handler();
+void init_gdb_crash_handler();
 
 /**
  * Invokes gdb.
  *
  * @return true on success or false on failure
  */
-bool gdb_crash_handler();
+bool gdb_crash_handler(Registers* regs);
 
 #endif // _CRASH_HANDLER_H

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/exception_filter.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/exception_filter.h?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/exception_filter.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/exception_filter.h Wed Jan 30 10:44:06 2008
@@ -19,7 +19,9 @@
  * @version $Revision: 1.1.2.1.4.3 $
  */  
 
-//
-// Place holder
-//
+#include "vm_core_types.h"
 
+/**
+ * For using in crash handlers
+ */
+void print_reg_state(Registers* regs);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/signals_common.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/signals_common.h?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/signals_common.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/include/signals_common.h Wed Jan 30 10:44:06 2008
@@ -52,6 +52,8 @@
     return get_mem_protect_stack_size() + 0x0400;
 }
 
+#define DECL_CHANDLER __attribute__ ((used))
+
 // ^^^^^^^^ EM64T ^^^^^^^^
 #else // #ifdef _EM64T_
 // vvvvvvvv IA-32 vvvvvvvv
@@ -83,6 +85,8 @@
     return get_mem_protect_stack_size() + 0x0100;
 }
 
+#define DECL_CHANDLER __attribute__ ((used, cdecl))
+
 // ^^^^^^^^ IA-32 ^^^^^^^^
 #endif // #ifdef _EM64T_
 
@@ -101,6 +105,5 @@
 void ucontext_to_regs(Registers* regs, ucontext_t *uc);
 void regs_to_ucontext(ucontext_t *uc, Registers* regs);
 
-void print_state(Registers* regs);
 
 #endif // _SIGNALS_COMMON_H_

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_em64t.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_em64t.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_em64t.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_em64t.cpp Wed Jan 30 10:44:06 2008
@@ -91,25 +91,3 @@
         return;
     }
 }
-
-void print_state(Registers* regs)
-{
-    fprintf(stderr, "Registers:\n");
-    fprintf(stderr, "    RAX: 0x%016llx, RBX: 0x%016llx\n",
-        regs->rax, regs->rbx);
-    fprintf(stderr, "    RCX: 0x%016llx, RDX: 0x%016llx\n",
-        regs->rcx, regs->rdx);
-    fprintf(stderr, "    RSI: 0x%016llx, RDI: 0x%016llx\n",
-        regs->rsi, regs->rdi);
-    fprintf(stderr, "    RSP: 0x%016llx, RBP: 0x%016llx\n",
-        regs->rsp, regs->rbp);
-    fprintf(stderr, "    R8 : 0x%016llx, R9 : 0x%016llx\n",
-        regs->r8,  regs->r9);
-    fprintf(stderr, "    R10: 0x%016llx, R11: 0x%016llx\n",
-        regs->r10, regs->r11);
-    fprintf(stderr, "    R12: 0x%016llx, R13: 0x%016llx\n",
-        regs->r12, regs->r13);
-    fprintf(stderr, "    R14: 0x%016llx, R15: 0x%016llx\n",
-        regs->r14, regs->r15);
-    fprintf(stderr, "    RIP: 0x%016llx\n", regs->rip);
-}

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ia32.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ia32.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ia32.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ia32.cpp Wed Jan 30 10:44:06 2008
@@ -83,14 +83,3 @@
 #else
 #error need to add correct mcontext_t lookup for registers
 #endif
-
-void print_state(Registers* regs)
-{
-    fprintf(stderr, "Registers:\n");
-    fprintf(stderr, "    EAX: 0x%08x, EBX: 0x%08x, ECX: 0x%08x, EDX: 0x%08x\n",
-        regs->eax, regs->ebx, regs->ecx, regs->edx);
-    fprintf(stderr, "    ESI: 0x%08x, EDI: 0x%08x, ESP: 0x%08x, EBP: 0x%08x\n",
-        regs->esi, regs->edi, regs->esp, regs->ebp);
-    fprintf(stderr, "    EIP: 0x%08x\n", regs->eip);
-}
-

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/signals_ipf.cpp Wed Jan 30 10:44:06 2008
@@ -135,7 +135,7 @@
     signal(signum, SIG_DFL);
 
     if (!is_gdb_crash_handler_enabled() ||
-        !gdb_crash_handler())
+        !gdb_crash_handler(&regs))
     {
         // print stack trace
         sd_print_stack(&regs);
@@ -175,7 +175,7 @@
     signal(signum, SIG_DFL);
 
     if (!is_gdb_crash_handler_enabled() ||
-        !gdb_crash_handler())
+        !gdb_crash_handler(&regs))
     {
         // print stack trace
         sd_print_stack(&regs);
@@ -459,7 +459,7 @@
     signal(signum, SIG_DFL);
 
     if (!is_gdb_crash_handler_enabled() ||
-        !gdb_crash_handler())
+        !gdb_crash_handler(&regs))
     {
         // print stack trace
         sd_print_stack(&regs);
@@ -491,6 +491,9 @@
 
     // Prepare gdb crash handler
     init_gdb_crash_handler();
+
+    // Prepare general crash handler
+    sd_init_crash_handler();
 
 } //initialize_signals
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/stack_dump_platf.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/stack_dump_platf.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/stack_dump_platf.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/linux/stack_dump_platf.cpp Wed Jan 30 10:44:06 2008
@@ -15,12 +15,13 @@
  *  limitations under the License.
  */
 
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <sys/types.h>
-#include <sys/wait.h>
 
 #include "open/hythread_ext.h"
 #include "native_stack.h"
@@ -30,6 +31,8 @@
 
 
 static hymutex_t g_lock;
+static const char* g_curdir = NULL;
+static const char* g_cmdline = NULL;
 
 
 bool sd_initialize(hymutex_t** p_lock)
@@ -83,7 +86,7 @@
 
     if (!module)
     { // Unknown address
-        fprintf(stderr, "Unknown address 0x%"W_PI_FMT"X\n",
+        fprintf(stderr, "Unknown address 0x%"W_PI_FMT"\n",
                 (POINTER_SIZE_INT)ip);
         return;
     }
@@ -92,7 +95,7 @@
 
     if (!module->filename)
     {
-        fprintf(stderr, "Unknown memory region 0x%"W_PI_FMT"X:0x%"W_PI_FMT"X%s\n",
+        fprintf(stderr, "Unknown memory region 0x%"W_PI_FMT":0x%"W_PI_FMT"%s\n",
                 (size_t)segment->base, (size_t)segment->base + segment->size,
                 (segment->type == SEGMENT_TYPE_CODE) ? "" : " without execution rights");
         return;
@@ -100,7 +103,7 @@
 
     if (sd_is_predefined_name(module->filename))
     { // Special memory region
-        fprintf(stderr, "%s memory region 0x%"W_PI_FMT"X:0x%"W_PI_FMT"X%s\n",
+        fprintf(stderr, "%s memory region 0x%"W_PI_FMT":0x%"W_PI_FMT"%s\n",
                 module->filename,
                 (size_t)segment->base, (size_t)segment->base + segment->size,
                 (segment->type == SEGMENT_TYPE_CODE) ? "" : " without execution rights");
@@ -201,4 +204,62 @@
 int sd_get_cur_tid()
 {
     return gettid();
+}
+
+void sd_init_crash_handler()
+{
+    // Get current directory
+    char buf[PATH_MAX + 1];
+    char* cwd = getcwd(buf, sizeof(buf));
+
+    if (cwd)
+    {
+        cwd = (char*)STD_MALLOC(strlen(cwd) + 1);
+        g_curdir = cwd;
+        if (cwd)
+            strcpy(cwd, buf);
+    }
+
+    // Get command line
+    sprintf(buf, "/proc/%d/cmdline", getpid());
+    int file = open(buf, O_RDONLY);
+
+    if (file > 0)
+    {
+        size_t size = 0;
+        char rdbuf[256];
+        ssize_t rd;
+        do
+        {
+            rd = read(file, rdbuf, sizeof(rdbuf));
+            size += (rd > 0) ? rd : 0;
+        } while (rd == sizeof(rdbuf));
+
+        if (size)
+        {
+            char* cmd = (char*)STD_MALLOC(size + 1);
+            g_cmdline = cmd;
+            if (cmd)
+            {
+                cmd[size + 1] = '\0';
+                lseek(file, 0, SEEK_SET);
+                read(file, cmd, size);
+            }
+        }
+        close(file);
+    }
+}
+
+void sd_print_cwdcmdenv()
+{
+    fprintf(stderr, "\nWorking directory:\n%s\n", g_curdir ? g_curdir : "'null'");
+
+    fprintf(stderr, "\nCommand line:\n");
+    for (const char* ptr = g_cmdline; *ptr; ptr += strlen(ptr) + 1)
+        fprintf(stderr, "%s ", ptr);
+    fprintf(stderr, "\n");
+
+    fprintf(stderr, "\nEnvironment variables:\n");
+    for (char** env = environ; *env; ++env)
+        fprintf(stderr, "%s\n", *env);
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_modules_common.cpp Wed Jan 30 10:44:06 2008
@@ -49,7 +49,7 @@
         {
             size_t base = (size_t)module->segments[i].base;
 
-            fprintf(out, "\t0x%"W_PI_FMT"x:0x%"W_PI_FMT"x\n",
+            fprintf(out, "\t0x%"W_PI_FMT":0x%"W_PI_FMT"\n",
                     base, base + module->segments[i].size);
         }
     }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_stack.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_stack.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_stack.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/native_stack.cpp Wed Jan 30 10:44:06 2008
@@ -19,6 +19,7 @@
  * @version $Revision: 1.1.2.1 $
  */
 
+#include <string.h>
 #include "lock_manager.h"
 #include "method_lookup.h"
 #include "m2n.h"
@@ -78,20 +79,44 @@
     return false;
 }
 
-bool native_is_ip_stub(void* ip)
+static DynamicCode* native_find_stub(void* ip)
 {
-    // Synchronizing access to dynamic code list
-    LMAutoUnlock dcll(VM_Global_State::loader_env->p_dclist_lock);
-
     for (DynamicCode *dcList = compile_get_dynamic_code_list();
          NULL != dcList; dcList = dcList->next)
     {
         if (ip >= dcList->address &&
             ip < (void*)((POINTER_SIZE_INT)dcList->address + dcList->length))
-            return true;
+            return dcList;
     }
 
-    return false;
+    return NULL;
+}
+
+char* native_get_stub_name(void* ip, char* buf, size_t buflen)
+{
+    // Synchronizing access to dynamic code list
+    LMAutoUnlock dcll(VM_Global_State::loader_env->p_dclist_lock);
+
+    if (!buf || buflen == 0)
+        return NULL;
+
+    DynamicCode* code = native_find_stub(ip);
+
+    if (!code || !code->name)
+        return NULL;
+
+    strncpy(buf, code->name, buflen);
+    buf[buflen - 1] = '\0';
+
+    return buf;
+}
+
+bool native_is_ip_stub(void* ip)
+{
+    // Synchronizing access to dynamic code list
+    LMAutoUnlock dcll(VM_Global_State::loader_env->p_dclist_lock);
+
+    return (native_find_stub(ip) != NULL);
 }
 
 static bool native_is_ip_in_breakpoint_handler(void* ip)

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/em64t/nt_exception_filter.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/em64t/nt_exception_filter.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/em64t/nt_exception_filter.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/em64t/nt_exception_filter.cpp Wed Jan 30 10:44:06 2008
@@ -70,33 +70,6 @@
     pcontext->EFlags = regs->eflags;
 }
 
-void print_state(LPEXCEPTION_POINTERS nt_exception, const char *msg)
-{
-    if (msg != 0)
-        fprintf(stderr, "Windows reported exception: %s\n", msg);
-    else
-        fprintf(stderr, "Windows reported exception: 0x%x\n", nt_exception->ExceptionRecord->ExceptionCode);
-
-    fprintf(stderr, "Registers:\n");
-    fprintf(stderr, "    RAX: 0x%016I64x, RBX: 0x%016I64x\n",
-        nt_exception->ContextRecord->Rax, nt_exception->ContextRecord->Rbx);
-    fprintf(stderr, "    RCX: 0x%016I64x, RDX: 0x%016I64x\n",
-        nt_exception->ContextRecord->Rcx, nt_exception->ContextRecord->Rdx);
-    fprintf(stderr, "    RSI: 0x%016I64x, RDI: 0x%016I64x\n",
-        nt_exception->ContextRecord->Rsi, nt_exception->ContextRecord->Rdi);
-    fprintf(stderr, "    RSP: 0x%016I64x, RBP: 0x%016I64x\n",
-        nt_exception->ContextRecord->Rsp, nt_exception->ContextRecord->Rbp);
-    fprintf(stderr, "    R8 : 0x%016I64x, R9 : 0x%016I64x\n",
-        nt_exception->ContextRecord->R8, nt_exception->ContextRecord->R9);
-    fprintf(stderr, "    R10: 0x%016I64x, R11: 0x%016I64x\n",
-        nt_exception->ContextRecord->R10, nt_exception->ContextRecord->R11);
-    fprintf(stderr, "    R12: 0x%016I64x, R13: 0x%016I64x\n",
-        nt_exception->ContextRecord->R12, nt_exception->ContextRecord->R13);
-    fprintf(stderr, "    R14: 0x%016I64x, R15: 0x%016I64x\n",
-        nt_exception->ContextRecord->R14, nt_exception->ContextRecord->R15);
-    fprintf(stderr, "    RIP: 0x%016I64x\n", nt_exception->ContextRecord->Rip);
-}
-
 void* regs_get_sp(Registers* pregs)
 {
     return (void*)pregs->rsp;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32/nt_exception_filter.cpp Wed Jan 30 10:44:06 2008
@@ -50,23 +50,6 @@
     context->EFlags = regs->eflags;
 }
 
-void print_state(LPEXCEPTION_POINTERS nt_exception, const char *msg)
-{
-    if (msg != 0)
-        fprintf(stderr, "Windows reported exception: %s\n", msg);
-    else
-        fprintf(stderr, "Windows reported exception: 0x%x\n", nt_exception->ExceptionRecord->ExceptionCode);
-
-    fprintf(stderr, "Registers:\n");
-    fprintf(stderr, "    EAX: 0x%08x, EBX: 0x%08x, ECX: 0x%08x, EDX: 0x%08x\n",
-        nt_exception->ContextRecord->Eax, nt_exception->ContextRecord->Ebx,
-        nt_exception->ContextRecord->Ecx, nt_exception->ContextRecord->Edx);
-    fprintf(stderr, "    ESI: 0x%08x, EDI: 0x%08x, ESP: 0x%08x, EBP: 0x%08x\n",
-        nt_exception->ContextRecord->Esi, nt_exception->ContextRecord->Edi,
-        nt_exception->ContextRecord->Esp, nt_exception->ContextRecord->Ebp);
-    fprintf(stderr, "    EIP: 0x%08x\n", nt_exception->ContextRecord->Eip);
-}
-
 LONG __declspec(naked) NTAPI vectored_exception_handler(LPEXCEPTION_POINTERS nt_exception)
 {
     __asm {

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/ia32_em64t/nt_exception_filter_common.cpp Wed Jan 30 10:44:06 2008
@@ -43,29 +43,19 @@
 #error Unknown value of INSTRUMENTATION_BYTE
 #endif
 
-static void print_callstack(LPEXCEPTION_POINTERS nt_exception) {
-    PCONTEXT context = nt_exception->ContextRecord;
-    Registers regs;
-    nt_to_vm_context(context, &regs);
-    sd_print_stack(&regs);
-}
 
-
-static LONG process_crash(LPEXCEPTION_POINTERS nt_exception, const char* msg = NULL)
+static LONG process_crash(Registers* regs, DWORD ExceptionCode)
 {
 static DWORD saved_eip_index = TlsAlloc();
 static BOOL UNREF tmp_init = TlsSetValue(saved_eip_index, (LPVOID)0);
 
-    Registers regs;
-    nt_to_vm_context(nt_exception->ContextRecord, &regs);
-
     // Check crash location to prevent infinite recursion
-    if (regs.get_ip() == (void*)TlsGetValue(saved_eip_index))
+    if (regs->get_ip() == (void*)TlsGetValue(saved_eip_index))
         return EXCEPTION_CONTINUE_SEARCH;
     // Store registers to compare IP in future
-    TlsSetValue(saved_eip_index, (LPVOID)regs.get_ip());
+    TlsSetValue(saved_eip_index, (LPVOID)regs->get_ip());
 
-    switch (nt_exception->ExceptionRecord->ExceptionCode)
+    switch (ExceptionCode)
     {
     case EXCEPTION_DATATYPE_MISALIGNMENT:
     case EXCEPTION_ILLEGAL_INSTRUCTION:
@@ -88,8 +78,10 @@
         get_boolean_property("vm.assert_dialog", TRUE, VM_PROPERTIES))
         return EXCEPTION_CONTINUE_SEARCH;
 
-    print_state(nt_exception, msg);
-    print_callstack(nt_exception);
+    // Report crash
+    fprintf(stderr, "Windows reported exception: 0x%x\n", ExceptionCode);
+
+    sd_print_stack(regs);
     LOGGER_EXIT(-1);
     return EXCEPTION_CONTINUE_EXECUTION;
 }
@@ -338,7 +330,7 @@
         (!in_java && code != STATUS_STACK_OVERFLOW)) &&
         code != JVMTI_EXCEPTION_STATUS)
     {
-        LONG result = process_crash(nt_exception);
+        LONG result = process_crash(&regs, code);
         regs.set_ip((void*)saved_eip);
         vm_to_nt_context(&regs, context);
         return result;
@@ -420,7 +412,7 @@
         }
     default:
         // unexpected hardware exception occured in java code
-        LONG result = process_crash(nt_exception);
+        LONG result = process_crash(&regs, code);
         regs.set_ip((void*)saved_eip);
         vm_to_nt_context(&regs, context);
         return result;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/include/exception_filter.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/include/exception_filter.h?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/include/exception_filter.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/include/exception_filter.h Wed Jan 30 10:44:06 2008
@@ -54,7 +54,7 @@
 
 
 // Prints register state
-void print_state(LPEXCEPTION_POINTERS nt_exception, const char *msg);
+void print_reg_state(Registers* regs);
 
 // Conversion from NT context to VM Registers structure and visa versa
 void nt_to_vm_context(PCONTEXT context, Registers* regs);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/nt_platform_utils.cpp Wed Jan 30 10:44:06 2008
@@ -33,6 +33,7 @@
 #include "init.h"
 #include "platform_utils.h"
 #include "open/vm_util.h"
+#include "stack_dump.h"
 #include "exception_filter.h"
 
 BOOL ctrl_handler(DWORD ctrlType) 
@@ -63,6 +64,9 @@
     TRACE2("signals", "Adding vectored exception handler...");
     veh = AddVectoredExceptionHandler(0, vectored_exception_handler);
     assert(veh);
+
+    // Prepare general crash handler
+    sd_init_crash_handler();
 }
 
 void shutdown_signals() {

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/stack_dump_platf.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/stack_dump_platf.cpp?rev=616840&r1=616839&r2=616840&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/stack_dump_platf.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/util/win/stack_dump_platf.cpp Wed Jan 30 10:44:06 2008
@@ -27,6 +27,9 @@
 
 
 static hymutex_t g_lock;
+static const char* g_curdir = NULL;
+static const char* g_cmdline = NULL;
+static const char* g_environ = NULL;
 
 #ifndef NO_DBGHELP
 typedef BOOL (WINAPI *SymFromAddr_type)
@@ -119,7 +122,7 @@
 
         if (!module->filename)
         { // We should not reach this code
-            fprintf(stderr, "Unknown memory region 0x%"W_PI_FMT"X:0x%"W_PI_FMT"X%s\n",
+            fprintf(stderr, "Unknown memory region 0x%"W_PI_FMT":0x%"W_PI_FMT"%s\n",
                     (size_t)segment->base, (size_t)segment->base + segment->size,
                     (segment->type == SEGMENT_TYPE_CODE) ? "" : " without execution rights");
             return;
@@ -141,7 +144,7 @@
     region_size = (size_t)mem_info.RegionSize;
     end_addr = start_addr + region_size;
 
-    fprintf(stderr, "Memory region 0x%"W_PI_FMT"X:0x%"W_PI_FMT"X %s\n",
+    fprintf(stderr, "Memory region 0x%"W_PI_FMT":0x%"W_PI_FMT" %s\n",
                 start_addr, end_addr, sd_get_region_access_info(&mem_info));
 }
 
@@ -202,4 +205,64 @@
 int sd_get_cur_tid()
 {
     return GetCurrentThreadId();
+}
+
+void sd_init_crash_handler()
+{
+    // Get current directory
+    DWORD required = GetCurrentDirectory(0, NULL);
+    char* ptr = (char*)STD_MALLOC(required);
+
+    if (ptr)
+    {
+        GetCurrentDirectory(required, ptr);
+        g_curdir = ptr;
+    }
+
+    // Get command line
+    LPTSTR cmdline = GetCommandLine();
+    ptr = (char*)STD_MALLOC(strlen(cmdline) + 1);
+    strcpy(ptr, cmdline);
+    g_cmdline = ptr;
+
+    // Get environment
+    LPVOID env_block = GetEnvironmentStrings();
+
+    if (!env_block)
+        return;
+
+    size_t total_len = 1;
+    ptr = (char*)env_block;
+
+    while (*ptr)
+    {
+        total_len += strlen(ptr) + 1;
+        ptr += strlen(ptr) + 1;
+    }
+
+    ptr = (char*)STD_MALLOC(total_len);
+
+    if (ptr)
+    {
+        memcpy(ptr, env_block, total_len);
+        g_environ = ptr;
+    }
+
+    FreeEnvironmentStrings((char*)env_block);
+}
+
+void sd_print_cwdcmdenv()
+{
+    fprintf(stderr, "\nWorking directory:\n%s\n", g_curdir ? g_curdir : "'null'");
+    fprintf(stderr, "\nCommand line:\n%s\n", g_cmdline);
+
+    fprintf(stderr, "\nEnvironment variables:\n");
+
+    const char* penv = (char*)g_environ;
+
+    while (*penv)
+    {
+        fprintf(stderr, "%s\n", penv);
+        penv += strlen(penv) + 1;
+    }
 }