Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.163.
Browse files Browse the repository at this point in the history
Make wakeHighestPriority filter-out zombie processes; fixes Newspeak/Glue crash.
Add -blockonerror flag to Unix & Mac VMs to allow attaching gdb on error/segv.
Make the sigsegv handler catch SIGILL and SIGBUS on Unix and Mac.
Move ioExit[WithErrorCode] from sqWin32Window.c to sqWin32Intel.c.


git-svn-id: http://squeakvm.org/svn/squeak/branches/Cog@2559 fa1542d4-bde8-0310-ad64-8ed1123d492a
  • Loading branch information
eliot committed Jun 21, 2012
1 parent 9a2de4b commit 7161d2b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 38 deletions.
43 changes: 36 additions & 7 deletions platforms/Mac OS/vm/sqMacMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,27 @@ reportStackState(char *msg, char *date, int printAll, ucontext_t *uap)
fflush(stdout);
}

int blockOnError = 0; /* to allow attaching gdb on fatal error */

static void
block()
{ struct timespec while_away_the_hours;

printf("blocking e.g. to allow attaching debugger\n");
while (1) {
while_away_the_hours.tv_sec = 3600;
nanosleep(&while_away_the_hours, 0);
}
}

/* Print an error message, possibly a stack trace, and exit. */
/* Disable Intel compiler inlining of error which is used for breakpoints */
#pragma auto_inline off
void
error(char *msg)
{
reportStackState(msg,0,0,0);
if (blockOnError) block();
abort();
}
#pragma auto_inline on
Expand Down Expand Up @@ -286,19 +300,32 @@ sigusr1(int sig, siginfo_t *info, void *uap)
errno = saved_errno;
}

static int inFault = 0;

static void
sigsegv(int sig, siginfo_t *info, void *uap)
{
time_t now = time(NULL);
char ctimebuf[32];
char crashdump[IMAGE_NAME_SIZE+1];

getCrashDumpFilenameInto(crashdump);
ctime_r(&now,ctimebuf);
pushOutputFile(crashdump);
reportStackState("Segmentation fault", ctimebuf, 0, uap);
popOutputFile();
reportStackState("Segmentation fault", ctimebuf, 0, uap);
char *fault = sig == SIGSEGV
? "Segmentation fault"
: (sig == SIGBUS
? "Bus error"
: (sig == SIGILL
? "Illegal instruction"
: "Unknown signal"));

if (!inFault) {
inFault = 1;
getCrashDumpFilenameInto(crashdump);
ctime_r(&now,ctimebuf);
pushOutputFile(crashdump);
reportStackState(fault, ctimebuf, 0, uap);
popOutputFile();
reportStackState(fault, ctimebuf, 0, uap);
}
if (blockOnError) block();
abort();
}

Expand Down Expand Up @@ -369,6 +396,8 @@ main(int argc, char **argv, char **envp)
sigsegv_handler_action.sa_sigaction = sigsegv;
sigsegv_handler_action.sa_flags = SA_NODEFER | SA_SIGINFO;
sigemptyset(&sigsegv_handler_action.sa_mask);
(void)sigaction(SIGBUS, &sigsegv_handler_action, 0);
(void)sigaction(SIGILL, &sigsegv_handler_action, 0);
(void)sigaction(SIGSEGV, &sigsegv_handler_action, 0);

sigusr1_handler_action.sa_sigaction = sigusr1;
Expand Down
21 changes: 18 additions & 3 deletions platforms/Mac OS/vm/sqMacUnixCommandLineInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ static int parseArgument(int argc, char **argv)
else if (!strncmp(argv[0], "-psn_", 5)) { return 1; }
else if (!strcmp(argv[0], "-headless")) { gSqueakHeadless = true; return 1; }
else if (!strcmp(argv[0], "-headfull")) { gSqueakHeadless = false; return 1; }
else if (!strcmp(argv[0], "-blockonerror")) {
extern int blockOnError;
blockOnError = true;
return 1; }
#if (STACKVM || NewspeakVM) && !COGVM
else if (!strcmp(argv[0], "-sendtrace")) { extern sqInt sendTrace; sendTrace = 1; return 1; }
#endif
Expand Down Expand Up @@ -275,17 +279,28 @@ static void printUsage(void)
printf(" -eden <size>[mk] set eden memory to bytes\n");
printf(" -leakcheck num check for leaks in the heap\n");
printf(" -stackpages num use n stack pages\n");
printf(" -sendtrace[=num] enable send tracing (optionally to a specific value)\n");
printf(" -numextsems num make the external semaphore table num in size\n");
printf(" -noheartbeat disable the heartbeat for VM debugging. disables input\n");
printf(" -pollpip output . on each poll for input\n");
#endif
#if COGVM
printf(" -codesize <size>[mk] set machine code memory to bytes\n");
printf(" -sendtrace[=num] enable send tracing (optionally to a specific value)\n");
printf(" -tracestores enable store tracing (assert check stores)\n");
printf(" -cogmaxlits <n> set max number of literals for methods compiled to machine code\n");
printf(" -cogmaxlits <n> set max number of literals for methods to be compiled to machine code\n");
printf(" -cogminjumps <n> set min number of backward jumps for interpreted methods to be considered for compilation to machine code\n");
#endif
printf(" -pathenc <enc> set encoding for pathnames (default: macintosh)\n");
#if STACKVM || NewspeakVM
printf(" -breaksel selector call warning when sending or jitting selector\n");
#endif
printf(" -pathenc <enc> set encoding for pathnames (default: %s)\n",
getEncodingType(gCurrentVMEncoding));

printf(" -headless run in headless (no window) mode (default: false)\n");
printf(" -headfull run in headful (window) mode (default: true)\n");
printf(" -version print version information, then exit\n");

printf(" -blockonerror on error or segv block, not exit. useful for attaching gdb\n");
}

static void printUsageNotes(void)
Expand Down
45 changes: 38 additions & 7 deletions platforms/unix/vm/sqUnixMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,13 +852,27 @@ reportStackState(char *msg, char *date, int printAll, ucontext_t *uap)
fflush(stdout);
}

int blockOnError = 0; /* to allow attaching gdb on fatal error */

static void
block()
{ struct timespec while_away_the_hours;

printf("blocking e.g. to allow attaching debugger\n");
while (1) {
while_away_the_hours.tv_sec = 3600;
nanosleep(&while_away_the_hours, 0);
}
}

/* Print an error message, possibly a stack trace, and exit. */
/* Disable Intel compiler inlining of error which is used for breakpoints */
#pragma auto_inline off
void
error(char *msg)
{
reportStackState(msg,0,0,0);
if (blockOnError) block();
abort();
}
#pragma auto_inline on
Expand Down Expand Up @@ -896,19 +910,31 @@ sigusr1(int sig, siginfo_t *info, void *uap)
errno = saved_errno;
}

static int inFault = 0;

static void
sigsegv(int sig, siginfo_t *info, void *uap)
{
time_t now = time(NULL);
char ctimebuf[32];
char crashdump[IMAGE_NAME_SIZE+1];

getCrashDumpFilenameInto(crashdump);
ctime_r(&now,ctimebuf);
pushOutputFile(crashdump);
reportStackState("Segmentation fault", ctimebuf, 0, uap);
popOutputFile();
reportStackState("Segmentation fault", ctimebuf, 0, uap);
char *fault = sig == SIGSEGV
? "Segmentation fault"
: (sig == SIGBUS
? "Bus error"
: (sig == SIGILL
? "Illegal instruction"
: "Unknown signal"));

if (!inFault) {
getCrashDumpFilenameInto(crashdump);
ctime_r(&now,ctimebuf);
pushOutputFile(crashdump);
reportStackState(fault, ctimebuf, 0, uap);
popOutputFile();
reportStackState(fault, ctimebuf, 0, uap);
}
if (blockOnError) block();
abort();
}

Expand Down Expand Up @@ -1277,6 +1303,7 @@ static int vm_parseArgument(int argc, char **argv)
else if (!strcmp(argv[0], "-nomixer")) { noSoundMixer = 1; return 1; }
else if (!strcmp(argv[0], "-notimer")) { useItimer = 0; return 1; }
else if (!strcmp(argv[0], "-nohandlers")) { installHandlers= 0; return 1; }
else if (!strcmp(argv[0], "-blockonerror")) { blockOnError = 1; return 1; }
#if !STACKVM && !COGVM
else if (!strncmp(argv[0],"-jit", 4)) { useJit = jitArgs(argv[0]+4); return 1; }
else if (!strcmp(argv[0], "-nojit")) { useJit = 0; return 1; }
Expand Down Expand Up @@ -1400,6 +1427,7 @@ static void vm_printUsage(void)
#endif
printf(" -noevents disable event-driven input support\n");
printf(" -nohandlers disable sigsegv & sigusr1 handlers\n");
printf(" -pollpip output . on each poll for input\n");
printf(" -pathenc <enc> set encoding for pathnames (default: UTF-8)\n");
printf(" -plugins <path> specify alternative plugin location (see manpage)\n");
printf(" -textenc <enc> set encoding for external text (default: UTF-8)\n");
Expand All @@ -1412,6 +1440,7 @@ static void vm_printUsage(void)
printf(" -cogmaxlits <n> set max number of literals for methods compiled to machine code\n");
printf(" -cogminjumps <n> set min number of backward jumps for interpreted methods to be considered for compilation to machine code\n");
#endif
printf(" -blockonerror on error or segv block, not exit. useful for attaching gdb\n");
#if 1
printf("Deprecated:\n");
# if !STACKVM
Expand Down Expand Up @@ -1781,6 +1810,8 @@ main(int argc, char **argv, char **envp)
sigsegv_handler_action.sa_flags = SA_NODEFER | SA_SIGINFO;
sigemptyset(&sigsegv_handler_action.sa_mask);
(void)sigaction(SIGSEGV, &sigsegv_handler_action, 0);
(void)sigaction(SIGBUS, &sigsegv_handler_action, 0);
(void)sigaction(SIGILL, &sigsegv_handler_action, 0);

sigusr1_handler_action.sa_sigaction = sigusr1;
sigusr1_handler_action.sa_flags = SA_NODEFER | SA_SIGINFO;
Expand Down
22 changes: 19 additions & 3 deletions platforms/win32/vm/sqWin32Intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,11 @@ getVersionInfo(int verbose)
return info;
}

/* Calling exit(ec) apparently does NOT provide the correct exit code for the
* terminating process (MinGW bug?). So instead call the shutdown sequence via
* _cexit() and then terminate explicitly.
*/
#define exit(ec) do { _cexit(ec); ExitProcess(ec); } while (0)

static void
versionInfo(void)
Expand Down Expand Up @@ -1003,6 +1008,19 @@ error(char *msg) {
/* dumpStackIfInMainThread(0); */
exit(-1);
}

static int inCleanExit = 0; /* to suppress stack trace in Cleanup */

int ioExit(void) { return ioExitWithErrorCode(0); }

sqInt
ioExitWithErrorCode(int ec)
{
inCleanExit = 1;
exit(ec);
return ec;
}

#pragma auto_inline on

static void
Expand Down Expand Up @@ -1126,9 +1144,7 @@ printCrashDebugInformation(LPEXCEPTION_POINTERS exp)
void __cdecl Cleanup(void)
{ /* not all of these are essential, but they're polite... */

extern int inCleanExit; /* from platforms/win32/vm/sqWin32Window.c */

if(!inCleanExit) {
if (!inCleanExit) {
dumpStackIfInMainThread(0);
}
ioShutdownAllModules();
Expand Down
18 changes: 0 additions & 18 deletions platforms/win32/vm/sqWin32Window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,24 +1506,6 @@ int ioMousePoint(void)
/****************************************************************************/
/* Misc support primitves */
/****************************************************************************/
int inCleanExit = 0;

int ioExit(void) { return ioExitWithErrorCode(0); }

sqInt
ioExitWithErrorCode(int ec)
{
inCleanExit = 1;
/* Calling exit(ec) apparently does NOT provide the correct
exit code for the terminating process. So instead call
the shutdown sequence via _cexit() and then terminate
explicitly. */
_cexit(ec);
ExitProcess(ec);
/* avoid the warnings here */
return ec;
}

int ioBeep(void)
{
MessageBeep(0);
Expand Down

0 comments on commit 7161d2b

Please sign in to comment.