ソースを参照

Refactored for new debug source registration.

Brucey 5 年 前
コミット
4398cb9bf0
3 ファイル変更91 行追加3 行削除
  1. 2 1
      appstub.mod/debugger.stdio.glue.c
  2. 77 0
      blitz.mod/blitz_debug.c
  3. 12 2
      blitz.mod/blitz_debug.h

+ 2 - 1
appstub.mod/debugger.stdio.glue.c

@@ -134,7 +134,8 @@ BBString * bmx_debugger_DebugEnumDeclValue(struct BBDebugDecl * decl, void * val
 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 BBString * bmx_debugger_DebugStmFile(struct BBDebugStm * stmt) {
-	return bbStringFromCString(stmt->source_file);
+	BBSource * src = bbSourceForId(stmt->id);
+	return bbStringFromCString(src->file);
 }
 
 int bmx_debugger_DebugStmLine(struct BBDebugStm * stmt) {

+ 77 - 0
blitz.mod/blitz_debug.c

@@ -23,3 +23,80 @@ void (*bbOnDebugPopExState)()=debugNop;
 
 void (*bbOnDebugUnhandledEx)( BBObject *ex )=debugUnhandledEx;
 
+static unsigned int bpCount = 0;
+static unsigned int bpSize = 0;
+static BBSource * sources = 0;
+
+static void swap(BBSource* a, BBSource* b) {
+	BBSource s = *a;
+	*a = *b;
+	*b = s;
+}
+
+static int partition (BBSource arr[], int low, int high) {
+	BBULONG pivot = arr[high].id;
+	int i = (low - 1);
+	for (int j = low; j <= high- 1; j++) {
+		if (arr[j].id < pivot) {
+			i++;
+			swap(&arr[i], &arr[j]);
+		}
+	}
+	swap(&arr[i + 1], &arr[high]);
+	return (i + 1);
+}
+
+static void sort(BBSource arr[], int low, int high) {
+	if (low < high) {
+		int part = partition(arr, low, high);
+		sort(arr, low, part - 1);
+		sort(arr, part + 1, high);
+	}
+}
+
+void bbRegisterSource(BBULONG sourceId, const char * source) {
+	if (sources == 0) {
+		bpSize = 32;
+		sources = calloc(bpSize, sizeof(BBSource));
+	} else {
+		if (bpCount == bpSize) {
+			BBSource * bp = calloc(bpSize * 2, sizeof(BBSource));
+			memcpy(bp, sources, bpSize * sizeof(BBSource));
+			BBSource * old = sources;
+			sources = bp;
+			free(old);
+			bpSize *= 2;
+		}
+	}
+	
+	sources[bpCount].id = sourceId;
+	sources[bpCount].file = source;
+	
+	bpCount++;
+	
+	if (bpCount > 1) {
+		sort(sources, 0, bpCount - 1);
+	}
+}
+
+BBSource * bbSourceForId(BBULONG id) {
+	unsigned first = 0;
+	unsigned last = bpCount - 1;
+	unsigned index = 0;
+	
+	while (first <= last) {
+		index = (first + last) / 2;
+		if (sources[index].id == id) {
+			return &sources[index];
+		} else {
+			if (sources[index].id < id) {
+				first = index + 1;
+			} else {
+				last = index - 1;
+			}
+		}
+	}
+
+	return "<Error:Unmapped source>";
+}
+

+ 12 - 2
blitz.mod/blitz_debug.h

@@ -56,10 +56,17 @@ struct BBDebugScope{
 };
 
 struct BBDebugStm{
-	const char		*source_file;
-	int				line_num,char_num;
+	BBULONG      id;
+	int          line_num,char_num;
 };
 
+typedef struct BBSource {
+	BBULONG id;
+	char * file;
+	unsigned int count;
+	unsigned int lines[32];
+} BBSource;
+
 extern void bbCAssertEx();
 
 extern void (*bbOnDebugStop)();
@@ -71,6 +78,9 @@ extern void (*bbOnDebugPushExState)();
 extern void (*bbOnDebugPopExState)();
 extern void (*bbOnDebugUnhandledEx)( BBObject *ex );
 
+void bbRegisterSource(BBULONG sourceId, const char * source);
+BBSource * bbSourceForId(BBULONG id);
+
 #ifdef __cplusplus
 }
 #endif