Skip to content
Permalink
Browse files

Merge b67fe81 into a1ee2eb

  • Loading branch information...
zecke committed May 4, 2019
2 parents a1ee2eb + b67fe81 commit f0c8b3eafdfb047fe387f92dfe3bb1392d2b9d31
@@ -60,7 +60,7 @@ OSXSRC=$(wildcard $(OSXDIR)/*.c) $(wildcard $(OSXDIR)/*.m) \
$(wildcard $(OSXCLASSESDIR)/*.c) $(wildcard $(OSXCLASSESDIR)/*.m)
OSXSRC:=$(filter-out $(XEX),$(OSXSRC))
UNIXSRC:=$(addprefix $(UNIXVMDIR)/,aio.c sqUnixHeartbeat.c sqUnixSpurMemory.c \
sqUnixThreads.c sqUnixVMProfile.c)
sqUnixThreads.c sqUnixVMProfile.c debug.c)
VMSRC:= $(MAKERSRC) $(CROSSSRC) $(OSXSRC) $(UNIXSRC)
VMOBJ:= $(notdir $(VMSRC))
VMOBJ:= $(VMOBJ:.c=.o)
@@ -60,7 +60,7 @@ OSXSRC=$(wildcard $(OSXDIR)/*.c) $(wildcard $(OSXDIR)/*.m) \
$(wildcard $(OSXCLASSESDIR)/*.c) $(wildcard $(OSXCLASSESDIR)/*.m)
OSXSRC:=$(filter-out $(XEX),$(OSXSRC))
UNIXSRC:=$(addprefix $(UNIXVMDIR)/,aio.c sqUnixHeartbeat.c sqUnixSpurMemory.c \
sqUnixThreads.c sqUnixVMProfile.c)
sqUnixThreads.c sqUnixVMProfile.c debug.c)
VMSRC:= $(MAKERSRC) $(CROSSSRC) $(OSXSRC) $(UNIXSRC)
VMOBJ:= $(notdir $(VMSRC))
VMOBJ:= $(VMOBJ:.c=.o)
@@ -651,4 +651,11 @@ sqInt ioFreeModule(void *moduleHandle);
/* The Squeak version from which this interpreter was generated. */
extern const char *interpreterVersion;

/* Debug helper - don't print to the user console directly */

/*
* FILE pointing to the error output of the VM.
*/
extern FILE *VM_ERR(void);

#endif /* _SQ_H */
@@ -298,6 +298,10 @@ - (int) parseArgument: (NSString *) argData peek: (char *) peek
return 1;
}
#endif
if ([argData isEqualToString: VMOPTIONOBJ("quiet")]) {
sqSetVmErrFile(fopen("/dev/null", "w"));
return 1;
}

/* Options with arguments */
if (!peek)
@@ -495,6 +499,7 @@ - (void) usage {

- (void) printUsage {
printf("\nCommon <option>s:\n");
printf(" "VMOPTION("quiet")" don't print debugging messages from the VM\n");
printf(" "VMOPTION("help")" print this help message, then exit\n");
printf(" "VMOPTION("memory")" <size>[mk] use fixed heap size (added to image size)\n");
printf(" "VMOPTION("nohandlers")" disable sigsegv & sigusr1 handlers\n");
@@ -275,17 +275,17 @@ yieldToHighPriorityTickerThread()

if ((err = pthread_mutex_lock(&yield_mutex))) {
if (err != EDEADLK)
fprintf(stderr,"pthread_mutex_lock yield_mutex %s\n", strerror(err));
fprintf(VM_ERR(),"pthread_mutex_lock yield_mutex %s\n", strerror(err));
}
/* If lock fails then unblockVMThreadAfterYieldToHighPriorityTickerThread
* has locked and we should not block.
*/
if ((err = pthread_mutex_lock(&yield_sync))) {
if (err != EDEADLK)
fprintf(stderr,"pthread_mutex_lock yield_sync %s\n", strerror(err));
fprintf(VM_ERR(),"pthread_mutex_lock yield_sync %s\n", strerror(err));
}
else if ((err = pthread_cond_wait(&yield_cond, &yield_mutex)))
fprintf(stderr,"pthread_cond_wait %s\n", strerror(err));
fprintf(VM_ERR(),"pthread_cond_wait %s\n", strerror(err));
}

/* Private to sqTicker.c checkHighPriorityTickees */
@@ -79,7 +79,7 @@ printAndQuit()
void
lockedup(int arg)
{
fprintf(stderr,"system locked %s, time not advancing (yield method %s)\n",
fprintf(VM_ERR(),"system locked %s, time not advancing (yield method %s)\n",
arg == SIGINT ? "" : (char *)arg, method);
printf("vm %10lld hp %9lld hp+vm %10lld yields %d (%d,%d,%d) clk hz %ld\n",
vmcount, hpcount, vmcount + hpcount,
@@ -143,23 +143,23 @@ maybeYield()
case yield_via_wait_signal: { int err;
if ((err = pthread_mutex_lock(&yield_mutex))) {
if (err != EDEADLK)
fprintf(stderr,"pthread_mutex_lock yield_mutex %s\n", strerror(err));
fprintf(VM_ERR(),"pthread_mutex_lock yield_mutex %s\n", strerror(err));
}
else if ((err = pthread_mutex_lock(&yield_sync))) {
if (err != EDEADLK)
fprintf(stderr,"pthread_mutex_lock yield_sync %s\n", strerror(err));
fprintf(VM_ERR(),"pthread_mutex_lock yield_sync %s\n", strerror(err));
}
else {
sqLowLevelMFence();
if (yield
&& (err = pthread_cond_wait(&yield_cond, &yield_mutex)))
fprintf(stderr,"pthread_cond_wait %s\n", strerror(err));
fprintf(VM_ERR(),"pthread_cond_wait %s\n", strerror(err));
}
break;
}

default:
fprintf(stderr,"unrecognized yield method\n");
fprintf(VM_ERR(),"unrecognized yield method\n");
exit(5);
}
}
@@ -236,7 +236,7 @@ main(int argc, char *argv[])
else if (!strcmp(argv[1],"wait_signal"))
yieldMethod = yield_via_wait_signal;
else {
fprintf(stderr,
fprintf(VM_ERR(),
"usage: %s [none] [sched_yield] [nanosleep] [cond_timedwait] [wait_signal] [yield usecs]\n",
argv[0]);
return 3;
@@ -281,4 +281,4 @@ ioNumProcessors(void)
}

void
warning(char *msg) { fprintf(stderr,"%s\n", msg); }
warning(char *msg) { fprintf(VM_ERR(),"%s\n", msg); }
@@ -31,6 +31,7 @@
*/

#include "sqaio.h"
#include "sq.h"

#ifdef HAVE_CONFIG_H

@@ -126,7 +127,7 @@ static fd_set xdMask; /* external descriptor */
static void
undefinedHandler(int fd, void *clientData, int flags)
{
fprintf(stderr, "undefined handler called (fd %d, flags %x)\n", fd, flags);
fprintf(VM_ERR(), "undefined handler called (fd %d, flags %x)\n", fd, flags);
}

#ifdef AIO_DEBUG
@@ -221,7 +222,7 @@ static int tickCount = 0;
#define TICKS_PER_CHAR 10
#define DO_TICK(bool) \
do if ((bool) && !(++tickCount % TICKS_PER_CHAR)) { \
fprintf(stderr, "\r%c\r", *ticker); \
fprintf(VM_ERR(), "\r%c\r", *ticker); \
if (!*ticker++) ticker= ticks; \
} while (0)

@@ -232,7 +233,7 @@ aioPoll(long microSeconds)
fd_set rd, wr, ex;
unsigned long long us;

FPRINTF((stderr, "aioPoll(%ld)\n", microSeconds));
FPRINTF((VM_ERR(), "aioPoll(%ld)\n", microSeconds));
DO_TICK(SHOULD_TICK());

/*
@@ -269,7 +270,7 @@ aioPoll(long microSeconds)
return 0;
}
if (errno && (EINTR != errno)) {
fprintf(stderr, "errno %d\n", errno);
fprintf(VM_ERR(), "errno %d\n", errno);
perror("select");
return 0;
}
@@ -332,13 +333,13 @@ aioSleepForUsecs(long microSeconds)
void
aioEnable(int fd, void *data, int flags)
{
FPRINTF((stderr, "aioEnable(%d)\n", fd));
FPRINTF((VM_ERR(), "aioEnable(%d)\n", fd));
if (fd < 0) {
FPRINTF((stderr, "aioEnable(%d): IGNORED\n", fd));
FPRINTF((VM_ERR(), "aioEnable(%d): IGNORED\n", fd));
return;
}
if (FD_ISSET(fd, &fdMask)) {
fprintf(stderr, "aioEnable: descriptor %d already enabled\n", fd);
fprintf(VM_ERR(), "aioEnable: descriptor %d already enabled\n", fd);
return;
}
clientData[fd] = data;
@@ -395,9 +396,9 @@ aioEnable(int fd, void *data, int flags)
void
aioHandle(int fd, aioHandler handlerFn, int mask)
{
FPRINTF((stderr, "aioHandle(%d, %s, %d)\n", fd, handlerName(handlerFn), mask));
FPRINTF((VM_ERR(), "aioHandle(%d, %s, %d)\n", fd, handlerName(handlerFn), mask));
if (fd < 0) {
FPRINTF((stderr, "aioHandle(%d): IGNORED\n", fd));
FPRINTF((VM_ERR(), "aioHandle(%d): IGNORED\n", fd));
return;
}
#undef _DO
@@ -416,10 +417,10 @@ void
aioSuspend(int fd, int mask)
{
if (fd < 0) {
FPRINTF((stderr, "aioSuspend(%d): IGNORED\n", fd));
FPRINTF((VM_ERR(), "aioSuspend(%d): IGNORED\n", fd));
return;
}
FPRINTF((stderr, "aioSuspend(%d)\n", fd));
FPRINTF((VM_ERR(), "aioSuspend(%d)\n", fd));
#undef _DO
#define _DO(FLAG, TYPE) \
if (mask & FLAG) { \
@@ -436,10 +437,10 @@ void
aioDisable(int fd)
{
if (fd < 0) {
FPRINTF((stderr, "aioDisable(%d): IGNORED\n", fd));
FPRINTF((VM_ERR(), "aioDisable(%d): IGNORED\n", fd));
return;
}
FPRINTF((stderr, "aioDisable(%d)\n", fd));
FPRINTF((VM_ERR(), "aioDisable(%d)\n", fd));
aioSuspend(fd, AIO_RWX);
FD_CLR(fd, &xdMask);
FD_CLR(fd, &fdMask);
@@ -1,4 +1,5 @@
#include "debug.h"
#include "sq.h"

#include <stdio.h>
#include <stdarg.h>
@@ -32,13 +33,28 @@ void __sq_eprintf(const char *fmt, ...)
char *file= strrchr(__sq_errfile, '/');
file= file ? file + 1 : __sq_errfile;
va_start(ap, fmt);
fprintf(stderr, "%s(%d): %s:\n", file, __sq_errline, __sq_errfunc);
fprintf(stderr, "%s(%d): ", file, __sq_errline);
vfprintf(stderr, fmt, ap);
fprintf(VM_ERR(), "%s(%d): %s:\n", file, __sq_errline, __sq_errfunc);
fprintf(VM_ERR(), "%s(%d): ", file, __sq_errline);
vfprintf(VM_ERR(), fmt, ap);
va_end(ap);
}


void sqDebugAnchor(void)
{
}

static FILE *VM_ERR_FILE = NULL;

FILE *VM_ERR(void)
{
if (!VM_ERR_FILE) {
VM_ERR_FILE = stderr;
}
return VM_ERR_FILE;
}

void sqSetVmErrFile(FILE *file)
{
VM_ERR_FILE = file;
}
@@ -1,6 +1,7 @@
#ifndef __sq_debug_h
#define __sq_debug_h

#include <stdio.h>

#ifndef DEBUG
# define DEBUG 0
@@ -44,4 +45,6 @@ extern void __sq_eprintf(const char *fmt, ...);

extern void sqDebugAnchor(void);

extern void sqSetVmErrFile(FILE* file);

#endif /* __sq_debug_h */
@@ -63,12 +63,12 @@ static const char *dlerror(void)

static void dlUndefined(const char *symbol)
{
fprintf(stderr, "dyld: undefined symbol: %s\n", symbol);
fprintf(VM_ERR(), "dyld: undefined symbol: %s\n", symbol);
}

static NSModule dlMultiple(NSSymbol s, NSModule oldModule, NSModule newModule)
{
DPRINTF((stderr, "dyld: %s: %s previously defined in %s, new definition in %s\n",
DPRINTF((VM_ERR(), "dyld: %s: %s previously defined in %s, new definition in %s\n",
NSNameOfSymbol(s), NSNameOfModule(oldModule), NSNameOfModule(newModule)));
return newModule;
}
@@ -77,7 +77,7 @@ static void dlLinkEdit(NSLinkEditErrors errorClass, int errorNumber,
const char *fileName, const char *errorString)

{
fprintf(stderr, "dyld: %s: %s\n", fileName, errorString);
fprintf(VM_ERR(), "dyld: %s: %s\n", fileName, errorString);
}

static NSLinkEditErrorHandlers errorHandlers=
@@ -126,7 +126,7 @@ static void *dlopen(const char *path, int mode)
if (!handle)
dlSetError("could not load shared object: %s", path);

DPRINTF((stderr, "dlopen: %s => %d\n", path, (int)handle));
DPRINTF((VM_ERR(), "dlopen: %s => %d\n", path, (int)handle));

return handle;
}
@@ -139,17 +139,17 @@ static void *dlsym(void *handle, const char *symbol)

snprintf(_symbol, sizeof(_symbol), "_%s", symbol);

DPRINTF((stderr, "dlsym: looking for %s (%s) in %d\n", symbol, _symbol, (int)handle));
DPRINTF((VM_ERR(), "dlsym: looking for %s (%s) in %d\n", symbol, _symbol, (int)handle));

if (!handle)
{
DPRINTF((stderr, "dlsym: setting app context for this handle\n"));
DPRINTF((VM_ERR(), "dlsym: setting app context for this handle\n"));
handle= DL_APP_CONTEXT;
}

if (DL_APP_CONTEXT == handle)
{
DPRINTF((stderr, "dlsym: looking in app context\n"));
DPRINTF((VM_ERR(), "dlsym: looking in app context\n"));
if (NSIsSymbolNameDefined(_symbol))
nsSymbol= NSLookupAndBindSymbol(_symbol);
}
@@ -165,15 +165,15 @@ static void *dlsym(void *handle, const char *symbol)
_symbol,
NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
/*| NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR*/);
DPRINTF((stderr, "dlsym: bundle (image) lookup returned %p\n", nsSymbol));
DPRINTF((VM_ERR(), "dlsym: bundle (image) lookup returned %p\n", nsSymbol));
}
else
DPRINTF((stderr, "dlsym: bundle (image) symbol not defined\n"));
DPRINTF((VM_ERR(), "dlsym: bundle (image) symbol not defined\n"));
}
else
{
nsSymbol= NSLookupSymbolInModule(handle, _symbol);
DPRINTF((stderr, "dlsym: dylib (module) lookup returned %p\n", nsSymbol));
DPRINTF((VM_ERR(), "dlsym: dylib (module) lookup returned %p\n", nsSymbol));
}
}

@@ -33,6 +33,7 @@
# include "sqMemoryAccess.h"
#endif
#include "sqUnixCharConv.h"
#include "sq.h"

#include <stdio.h>
#include <stdlib.h>
@@ -115,7 +116,7 @@ void setEncoding(void **encoding, char *rawName)
}
else
++ap;
fprintf(stderr, "setEncoding: could not set encoding '%s'\n", name);
fprintf(VM_ERR(), "setEncoding: could not set encoding '%s'\n", name);
done:
free(name);
}

0 comments on commit f0c8b3e

Please sign in to comment.
You can’t perform that action at this time.