瀏覽代碼

reset profile marking of stack data after dump

Nicolas Cannasse 5 年之前
父節點
當前提交
2279e9c2f5
共有 2 個文件被更改,包括 26 次插入2 次删除
  1. 3 1
      src/module.c
  2. 23 1
      src/profile.c

+ 3 - 1
src/module.c

@@ -80,7 +80,6 @@ static bool module_resolve_pos( hl_module *m, void *addr, int *fidx, int *fpos )
 uchar *hl_module_resolve_symbol_full( void *addr, uchar *out, int *outSize, int **r_debug_addr ) {
 	int *debug_addr;
 	int file, line;
-	int size = *outSize;
 	int pos = 0;
 	int fidx, fpos;
 	hl_function *fdebug;
@@ -103,6 +102,9 @@ uchar *hl_module_resolve_symbol_full( void *addr, uchar *out, int *outSize, int
 		*r_debug_addr = debug_addr;
 		if( file < 0 ) return NULL; // already cached
 	}
+	if( !out )
+		return NULL;
+	int size = *outSize;
 	if( fdebug->obj )
 		pos += usprintf(out,size - pos,USTR("%s.%s("),fdebug->obj->name,fdebug->field.name);
 	else if( fdebug->field.ref )

+ 23 - 1
src/profile.c

@@ -219,7 +219,7 @@ static bool read_profile_data( profile_reader *r, void *ptr, int size ) {
 		if( r->r == NULL ) return false;
 		int bytes = r->r->currentPos - r->pos;
 		if( bytes > size ) bytes = size;
-		memcpy(ptr, r->r->data + r->pos, bytes);
+		if( ptr ) memcpy(ptr, r->r->data + r->pos, bytes);
 		size -= bytes;
 		r->pos += bytes;
 		if( r->pos == r->r->currentPos ) {
@@ -288,6 +288,28 @@ static void profile_dump() {
 			}
 		}
 	}
+	// reset debug_addr flags (allow further dumps)
+	r.r = data.first_record;
+	r.pos = 0;
+	while( true ) {
+		int i, eventId;
+		if( !read_profile_data(&r,NULL, sizeof(double) + sizeof(int)) ) break;
+		read_profile_data(&r,&eventId,sizeof(int));
+		if( eventId < 0 ) {
+			int count = eventId & 0x7FFFFFFF;
+			read_profile_data(&r,data.stackOut,sizeof(void*)*count);
+			for(i=0;i<count;i++) {
+				int *debug_addr = NULL;
+				hl_module_resolve_symbol_full(data.stackOut[i],NULL,NULL,&debug_addr);
+				if( debug_addr )
+					debug_addr[0] &= 0x7FFFFFFF;
+			}
+		} else {
+			int size;
+			read_profile_data(&r,&size,sizeof(int));
+			read_profile_data(&r,NULL,size);
+		}
+	}
 	fclose(f);
 	printf("%d profile samples saved\n", samples);
 	data.profiling_pause--;