Переглянути джерело

debugger: backtrace working

Nicolas Cannasse 8 роки тому
батько
коміт
c39b8c4787
4 змінених файлів з 14 додано та 3 видалено
  1. 4 0
      src/debugger.c
  2. 2 2
      src/jit.c
  3. 0 1
      src/std/debug.c
  4. 8 0
      src/std/thread.c

+ 4 - 0
src/debugger.c

@@ -33,10 +33,12 @@ HL_API hl_socket *hl_socket_accept( hl_socket *s );
 HL_API int hl_socket_send( hl_socket *s, vbyte *buf, int pos, int len );
 HL_API int hl_socket_recv( hl_socket *s, vbyte *buf, int pos, int len );
 HL_API void hl_sys_sleep( double t );
+HL_API int hl_thread_id();
 
 static hl_socket *debug_socket = NULL;
 static hl_socket *client_socket = NULL;
 static bool debugger_connected = false;
+static int main_thread_id = 0;
 
 #define send hl_send_data
 static void send( void *ptr, int size ) {
@@ -57,6 +59,7 @@ static void hl_debug_loop( hl_module *m ) {
 		client_socket = s;
 		send("HLD0",4);
 		send(&flags,4);
+		send(&main_thread_id,4);
 		send(&stack_top,sizeof(void*));
 		send(&m->jit_code,sizeof(void*));
 		send(&m->codesize,4);
@@ -96,6 +99,7 @@ bool hl_module_debug( hl_module *m, int port, bool wait ) {
 	}
 	hl_add_root(&debug_socket);
 	hl_add_root(&client_socket);
+	main_thread_id = hl_thread_id();
 	debug_socket = s;
 	if( !hl_thread_start(hl_debug_loop, m, false) ) {
 		hl_socket_close(s);

+ 2 - 2
src/jit.c

@@ -2191,11 +2191,11 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 	ctx->totalRegsSize = size;
 	jit_buf(ctx);
 	ctx->functionPos = BUF_POS();
+	op_enter(ctx);
 	if( ctx->m->code->hasdebug ) {
 		debug16 = (unsigned short*)malloc(sizeof(unsigned short) * (f->nops + 1));
-		debug16[0] = 0;
+		debug16[0] = (unsigned short)(BUF_POS() - codePos);
 	}
-	op_enter(ctx);
 	ctx->opsPos[0] = BUF_POS();
 
 	for(opCount=0;opCount<f->nops;opCount++) {

+ 0 - 1
src/std/debug.c

@@ -157,7 +157,6 @@ REGDATA *GetContextReg( CONTEXT *c, int reg ) {
 HL_API void *hl_debug_read_register( int pit, int thread, int reg ) {
 #	ifdef HL_WIN
 	CONTEXT c;
-	memset(&c,0xFF,sizeof(c));
 	c.ContextFlags = CONTEXT_FULL;
 	if( !GetThreadContext(OpenTID(thread),&c) )
 		return NULL;

+ 8 - 0
src/std/thread.c

@@ -33,6 +33,14 @@ HL_PRIM hl_thread *hl_thread_current() {
 #	endif
 }
 
+HL_PRIM int hl_thread_id() {
+#	ifdef HL_WIN
+	return (int)GetCurrentThreadId();
+#	else
+	return (int)gettid();
+#	endif
+}
+
 HL_PRIM hl_thread *hl_thread_start( void *callback, void *param, bool withGC ) {
 	if( withGC ) hl_error("Threads with garbage collector are currently not supported");
 #	ifdef HL_WIN