2
0
Эх сурвалжийг харах

fixed debug info for hot reload

Nicolas Cannasse 3 жил өмнө
parent
commit
ef918cf0ee
2 өөрчлөгдсөн 35 нэмэгдсэн , 13 устгасан
  1. 3 1
      src/jit.c
  2. 32 12
      src/module.c

+ 3 - 1
src/jit.c

@@ -2659,8 +2659,10 @@ static int jit_build( jit_ctx *ctx, void (*fbuild)( jit_ctx *) ) {
 static void hl_jit_init_module( jit_ctx *ctx, hl_module *m ) {
 	int i;
 	ctx->m = m;
-	if( m->code->hasdebug )
+	if( m->code->hasdebug ) {
 		ctx->debug = (hl_debug_infos*)malloc(sizeof(hl_debug_infos) * m->code->nfunctions);
+		memset(ctx->debug, -1, sizeof(hl_debug_infos) * m->code->nfunctions);
+	}
 	for(i=0;i<m->code->nfloats;i++) {
 		jit_buf(ctx);
 		*ctx->buf.d++ = m->code->floats[i];

+ 32 - 12
src/module.c

@@ -58,9 +58,12 @@ static bool module_resolve_pos( hl_module *m, void *addr, int *fidx, int *fpos )
 	}
 	if( min == 0 )
 		return false; // hl_callback
-	*fidx = (min - 1);
-	dbg = m->jit_debug + (min - 1);
-	fdebug = m->code->functions + (min - 1);
+	do {
+		min--;
+		*fidx = min;
+		dbg = m->jit_debug + min;
+		fdebug = m->code->functions + min;
+	} while( !dbg->offsets );
 	// lookup inside function
 	min = 0;
 	max = fdebug->nops;
@@ -549,6 +552,16 @@ static void hl_module_init_constant( hl_module *m, hl_constant *c ) {
 	hl_remove_root(global);
 }
 
+static void hl_module_add( hl_module *m ) {
+	hl_module **old_modules = cur_modules;
+	hl_module **new_modules = (hl_module**)malloc(sizeof(void*)*(modules_count + 1));
+	memcpy(new_modules, old_modules, sizeof(void*)*modules_count);
+	new_modules[modules_count] = m;
+	cur_modules = new_modules;
+	modules_count++;
+	free(old_modules);
+}
+
 int hl_module_init( hl_module *m, h_bool hot_reload ) {
 	int i;
 	jit_ctx *ctx;
@@ -601,15 +614,7 @@ int hl_module_init( hl_module *m, h_bool hot_reload ) {
 		hl_module_init_constant(m, c);
 	}
 
-	// DONE
-	hl_module **old_modules = cur_modules;
-	hl_module **new_modules = (hl_module**)malloc(sizeof(void*)*(modules_count + 1));
-	memcpy(new_modules, old_modules, sizeof(void*)*modules_count);
-	new_modules[modules_count] = m;
-	cur_modules = new_modules;
-	modules_count++;
-	free(old_modules);
-
+	hl_module_add(m);
 	hl_setup_exception(module_resolve_symbol, module_capture_stack);
 	hl_gc_set_dump_types(hl_module_types_dump);
 	hl_jit_free(ctx, hot_reload);
@@ -744,6 +749,20 @@ h_bool hl_module_patch( hl_module *m1, hl_code *c ) {
 	}
 
 	m2->jit_code = hl_jit_code(ctx, m2, &m2->codesize, &m2->jit_debug, m1);
+
+	// patch missing debug info
+	int start = -1;
+	if( m2->jit_debug ) {
+		for(i=0;i<c->nfunctions;i++) {
+			if( m2->jit_debug[i].start < 0 ) {
+				m2->jit_debug[i].start = start;
+				m2->jit_debug[i].offsets = NULL;
+			} else {
+				start = m2->jit_debug[i].start;
+			}
+		}
+	}
+
 	hl_jit_free(ctx,true);
 
 	if( m2->jit_code == NULL ) {
@@ -773,6 +792,7 @@ h_bool hl_module_patch( hl_module *m1, hl_code *c ) {
 		printf("[HotReload] %d changes\n", changes_count);
 		fflush(stdout);
 	}
+	hl_module_add(m2);
 
 	return true;
 }