[Vm-dev] [commit][2785] If possible, print the register state when printing the stack on

commits at squeakvm.org commits at squeakvm.org
Wed Sep 25 18:56:00 UTC 2013


Revision: 2785
Author:   eliot
Date:     2013-09-25 11:55:57 -0700 (Wed, 25 Sep 2013)
Log Message:
-----------
If possible, print the register state when printing the stack on
exceptions, SIGUSR1 etc.

Eliminate a compiler warning on Mac OS.

Modified Paths:
--------------
    branches/Cog/platforms/Mac OS/vm/sqMacMain.c
    branches/Cog/platforms/unix/vm/sqUnixMain.c

Modified: branches/Cog/platforms/Mac OS/vm/sqMacMain.c
===================================================================
--- branches/Cog/platforms/Mac OS/vm/sqMacMain.c	2013-09-19 01:07:31 UTC (rev 2784)
+++ branches/Cog/platforms/Mac OS/vm/sqMacMain.c	2013-09-25 18:55:57 UTC (rev 2785)
@@ -161,6 +161,8 @@
 /* Print an error message, possibly a stack trace, do /not/ exit.
  * Allows e.g. writing to a log file and stderr.
  */
+static void printRegisterState(ucontext_t *uap);
+
 static void
 reportStackState(char *msg, char *date, int printAll, ucontext_t *uap)
 {
@@ -175,6 +177,7 @@
 	printf("%s\n\n", getVersionInfo(1));
 
 #if !defined(NOEXECINFO)
+	printRegisterState(uap);
 	printf("C stack backtrace:\n");
 	fflush(stdout); /* backtrace_symbols_fd uses unbuffered i/o */
 	depth = backtrace(addrs, BACKTRACE_DEPTH);
@@ -246,6 +249,27 @@
 	fflush(stdout);
 }
 
+/* Attempt to dump the registers to stdout.  Only do so if we know how. */
+static void
+printRegisterState(ucontext_t *uap)
+{
+#if __DARWIN_UNIX03 && __APPLE__ && __MACH__ && __i386__
+	_STRUCT_X86_THREAD_STATE32 *regs = &uap->uc_mcontext->__ss;
+	printf(	"eax 0x%8x ebx 0x%8x ecx 0x%8x edx 0x%8x\n"
+			"edi 0x%8x esi 0x%8x ebp 0x%8x esp 0x%8x\n",
+			regs->__eax, regs->__ebx, regs->__ecx, regs->__edx,
+			regs->__edi, regs->__edi, regs->__ebp, regs->__esp);
+#elif __APPLE__ && __MACH__ && __i386__
+	_STRUCT_X86_THREAD_STATE32 *regs = &uap->uc_mcontext->ss;
+	printf(	"eax 0x%8x ebx 0x%8x ecx 0x%8x edx 0x%8x\n"
+			"edi 0x%8x esi 0x%8x ebp 0x%8x esp 0x%8x\n",
+			regs->eax, regs->ebx, regs->ecx, regs->edx,
+			regs->edi, regs->edi, regs->ebp, regs->esp);
+#else
+	printf("don't know how to derive register state from a ucontext_t on this platform\n");
+#endif
+}
+
 int blockOnError = 0; /* to allow attaching gdb on fatal error */
 
 static void
@@ -276,8 +300,10 @@
 static void
 getCrashDumpFilenameInto(char *buf)
 {
-	strcpy(buf,vmLogDirA);
-	vmLogDirA[0] && strcat(buf, "/");
+	if (vmLogDirA[0]) {
+		strcpy(buf,vmLogDirA);
+		strcat(buf, "/");
+	}
 	strcat(buf, "crash.dmp");
 }
 

Modified: branches/Cog/platforms/unix/vm/sqUnixMain.c
===================================================================
--- branches/Cog/platforms/unix/vm/sqUnixMain.c	2013-09-19 01:07:31 UTC (rev 2784)
+++ branches/Cog/platforms/unix/vm/sqUnixMain.c	2013-09-25 18:55:57 UTC (rev 2785)
@@ -786,6 +786,8 @@
 /* Print an error message, possibly a stack trace, do /not/ exit.
  * Allows e.g. writing to a log file and stderr.
  */
+static void printRegisterState(ucontext_t *uap);
+
 static void
 reportStackState(char *msg, char *date, int printAll, ucontext_t *uap)
 {
@@ -800,6 +802,7 @@
 	printf("%s\n\n", getVersionInfo(1));
 
 #if !defined(NOEXECINFO)
+	printRegisterState(uap);
 	printf("C stack backtrace:\n");
 	fflush(stdout); /* backtrace_symbols_fd uses unbuffered i/o */
 	depth = backtrace(addrs, BACKTRACE_DEPTH);
@@ -866,6 +869,27 @@
 	fflush(stdout);
 }
 
+/* Attempt to dump the registers to stdout.  Only do so if we know how. */
+static void
+printRegisterState(ucontext_t *uap)
+{
+#if __linux__ && __i386__
+	gregset_t *regs = &uap->uc_mcontext.gregs;
+	printf(	"eax 0x%8x ebx 0x%8x ecx 0x%8x edx 0x%8x\n"
+			"edi 0x%8x esi 0x%8x ebp 0x%8x esp 0x%8x\n",
+			regs[REG_EAX], regs[REG_EBX], regs[REG_ECX], regs[REG_EDX],
+			regs[REG_EDI], regs[REG_EDI], regs[REG_EBP], regs[REG_ESP]);
+#elif __FreeBSD__ && __i386__
+	struct mcontext *regs = &uap->uc_mcontext;
+	printf(	"eax 0x%8x ebx 0x%8x ecx 0x%8x edx 0x%8x\n"
+			"edi 0x%8x esi 0x%8x ebp 0x%8x esp 0x%8x\n",
+			regs->mc_eax, regs->mc_ebx, regs->mc_ecx, regs->mc_edx,
+			regs->mc_edi, regs->mc_edi, regs->mc_ebp, regs->mc_esp);
+#else
+	printf("don't know how to derive register state from a ucontext_t on this platform\n");
+#endif
+}
+
 int blockOnError = 0; /* to allow attaching gdb on fatal error */
 
 static void



More information about the Vm-dev mailing list