diff -ruN kozos09/Makefile kozos10/Makefile --- kozos09/Makefile Wed Nov 7 21:55:48 2007 +++ kozos10/Makefile Wed Nov 7 21:55:48 2007 @@ -1,4 +1,5 @@ OBJS += thread.o syscall.o outlog.o extintr.o idle.o +OBJS += stubd.o stublib.o i386-stub.o OBJS += main.o clock.o telnetd.o httpd.o TARGET ?= koz CC ?= gcc diff -ruN kozos09/kozos.h kozos10/kozos.h --- kozos09/kozos.h Wed Nov 7 21:55:48 2007 +++ kozos10/kozos.h Wed Nov 7 21:55:48 2007 @@ -18,19 +18,23 @@ int kz_timer(int msec); int kz_pending(); int kz_setsig(int signo); +int kz_debug(int sockt); void *kz_memalloc(int size); int kz_memfree(void *p); /* library */ void kz_start(kz_func func, char *name, int pri, int argc, char *argv[]); +void kz_break(); /* general thread */ extern int outlog_id; extern int extintr_id; extern int idle_id; +extern int stubd_id; int outlog_main(int argc, char *argv[]); int extintr_main(int argc, char *argv[]); int idle_main(int argc, char *argv[]); +int stubd_main(int argc, char *argv[]); /* user thread */ extern int clock_id; diff -ruN kozos09/main.c kozos10/main.c --- kozos09/main.c Wed Nov 7 21:55:48 2007 +++ kozos10/main.c Wed Nov 7 21:55:48 2007 @@ -6,7 +6,8 @@ int mainfunc(int argc, char *argv[]) { extintr_id = kz_run(extintr_main, "extintr", 1, 0, NULL); - outlog_id = kz_run(outlog_main, "outlog", 2, 0, NULL); + stubd_id = kz_run(stubd_main, "stubd", 2, 0, NULL); + outlog_id = kz_run(outlog_main, "outlog", 3, 0, NULL); idle_id = kz_run(idle_main, "idle", 31, 0, NULL); clock_id = kz_run(clock_main, "clock", 7, 0, NULL); telnetd_id = kz_run(telnetd_main, "telnetd", 8, 0, NULL); diff -ruN kozos09/syscall.c kozos10/syscall.c --- kozos09/syscall.c Wed Nov 7 21:55:48 2007 +++ kozos10/syscall.c Wed Nov 7 21:55:48 2007 @@ -112,6 +112,14 @@ return param.un.setsig.ret; } +int kz_debug(int sockt) +{ + kz_syscall_param_t param; + param.un.debug.sockt = sockt; + kz_syscall(KZ_SYSCALL_TYPE_DEBUG, ¶m); + return param.un.debug.ret; +} + void *kz_memalloc(int size) { kz_syscall_param_t param; diff -ruN kozos09/syscall.h kozos10/syscall.h --- kozos09/syscall.h Wed Nov 7 21:55:48 2007 +++ kozos10/syscall.h Wed Nov 7 21:55:48 2007 @@ -16,6 +16,7 @@ KZ_SYSCALL_TYPE_TIMER, KZ_SYSCALL_TYPE_PENDING, KZ_SYSCALL_TYPE_SETSIG, + KZ_SYSCALL_TYPE_DEBUG, KZ_SYSCALL_TYPE_MEMALLOC, KZ_SYSCALL_TYPE_MEMFREE, } kz_syscall_type_t; @@ -72,6 +73,10 @@ int signo; int ret; } setsig; + struct { + int sockt; + int ret; + } debug; struct { int size; void *ret; diff -ruN kozos09/telnetd.c kozos10/telnetd.c --- kozos09/telnetd.c Wed Nov 7 21:55:48 2007 +++ kozos10/telnetd.c Wed Nov 7 21:55:48 2007 @@ -42,9 +42,11 @@ if (!strncmp(buffer, "echo", 4)) { write(s, buffer + 4, strlen(buffer + 4)); - } else if (!strncmp(buffer, "break", 5)) { + } else if (!strncmp(buffer, "down", 4)) { int *nullp = NULL; *nullp = 1; + } else if (!strncmp(buffer, "break", 5)) { + kz_break(); } else if (!strncmp(buffer, "date", 4)) { time_t t; t = time(NULL); diff -ruN kozos09/thread.c kozos10/thread.c --- kozos09/thread.c Wed Nov 7 21:55:48 2007 +++ kozos10/thread.c Wed Nov 7 21:55:48 2007 @@ -9,6 +9,7 @@ #include "kozos.h" #include "syscall.h" #include "thread.h" +#include "stublib.h" #define SIG_NUM 32 #define STACK_SIZE 0x8000 @@ -24,6 +25,7 @@ static jmp_buf intr_env; static kz_timebuf *timers; static kz_thread *sigcalls[SIG_NUM]; +static int debug_sockt = 0; kz_thread *current; @@ -298,6 +300,14 @@ sendmsg(sigcalls[signo], 0, 0, NULL); } +static int thread_debug(int sockt) +{ + debug_sockt = sockt; + stub_init(sockt); + putcurrent(); + return 0; +} + static void *thread_memalloc(int size) { putcurrent(); @@ -357,6 +367,9 @@ case KZ_SYSCALL_TYPE_SETSIG: p->un.setsig.ret = thread_setsig(p->un.setsig.signo); break; + case KZ_SYSCALL_TYPE_DEBUG: + p->un.debug.ret = thread_debug(p->un.debug.sockt); + break; case KZ_SYSCALL_TYPE_MEMALLOC: p->un.memalloc.ret = thread_memalloc(p->un.memalloc.size); break; @@ -397,7 +410,9 @@ case SIGSEGV: case SIGTRAP: case SIGILL: - { + if (debug_sockt) { + stub_proc(current, signo); + } else { fprintf(stderr, "error thread \"%s\"\n", current->name); /* ダウン要因発生により継続不可能なので,スリープ状態にする*/ getcurrent(); @@ -468,4 +483,13 @@ /* ここには返ってこない */ abort(); +} + +void kz_break() +{ + /* + * スタブ付属の breakpoint() でうまくブレークできないので, + * トラップシグナルを上げてブレークする. + */ + kill(getpid(), SIGTRAP); }