From fbeb8da9bb125cd200434f941fdf9c13da9983f6 Mon Sep 17 00:00:00 2001 From: Sanjam Panda Date: Thu, 20 Apr 2023 15:48:49 +0200 Subject: [PATCH 1/8] added support for JITDEBUG_INFO --- src/mono/mono/mini/mini-runtime.c | 92 ++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 0a4ef9fefbb61..b329daeeb63bb 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2023,7 +2023,7 @@ static clockid_t clock_id = CLOCK_MONOTONIC; enum { JIT_DUMP_MAGIC = 0x4A695444, - JIT_DUMP_VERSION = 2, + JIT_DUMP_VERSION = 1, #if HOST_X86 ELF_MACHINE = EM_386, #elif HOST_AMD64 @@ -2039,7 +2039,8 @@ enum { #elif HOST_RISCV ELF_MACHINE = EM_RISCV, #endif - JIT_CODE_LOAD = 0 + JIT_CODE_LOAD = 0, + JIT_DEBUG_INFO = 2 }; typedef struct { @@ -2070,7 +2071,22 @@ typedef struct // Null terminated function name // Native code } JitCodeLoadRecord; +typedef struct +{ + guint64 code_addr; + guint32 line; + guint32 discrim; + char name[]; +}DebugEntry; +typedef struct +{ + RecordHeader header; + guint64 code_addr; + guint64 nr_entry; + DebugEntry debug_entry[]; +}JitCodeDebug; +static void add_basic_JitCodeDebug_info(JitCodeDebug *record); static void add_file_header_info (FileHeader *header); static void add_basic_JitCodeLoadRecord_info (JitCodeLoadRecord *record); @@ -2136,6 +2152,72 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) record.code_index = ++code_index; + DebugEntry ent; + JitCodeDebug rec; + MonoDebugMethodInfo *minfo; + MonoDebugMethodJitInfo *dmji; + MonoDebugSourceLocation *loc; + int i; + + memset(&rec, 0, sizeof(rec)); + + minfo = mono_debug_lookup_method(jinfo->d.method); + dmji = mono_debug_find_method( jinfo->d.method, NULL); + + add_basic_JitCodeDebug_info(&rec); + rec.code_addr = (guint64)dmji->code_start; + rec.header.total_size = sizeof(rec) + sizeof(ent) + 1; + rec.nr_entry=1; + for(i=0;i < dmji->num_line_numbers;++i) + { + loc = mono_debug_lookup_source_location_by_il(jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); + + if(!(loc)) + { + continue; + } + if(!(loc->source_file)) + { + mono_debug_free_source_location(loc); + continue; + } + + rec.header.total_size += sizeof(ent) + strlen(loc->source_file) + 1; + rec.nr_entry++; + } + + fwrite(&rec,sizeof(rec), 1 ,perf_dump_file); + + + for( i = 0; i < dmji->num_line_numbers;++i) + { + loc = mono_debug_lookup_source_location_by_il(jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); + + if(!loc) + continue; + if(!(loc->source_file)) + { + mono_debug_free_source_location(loc); + continue; + } + + ent.code_addr = (guint64)dmji->code_start + dmji->line_numbers[i].native_offset; + ent.discrim = 0; + ent.line = (guint32)loc->row; + + + + fwrite(&ent, sizeof(ent),1,perf_dump_file); + fwrite(loc->source_file,strlen(loc->source_file)+1,1,perf_dump_file); + } + + // TODO: write unwindInfo immediately before the JitCodeLoadRecord (while lock is held). + ent.code_addr = (guint64)jinfo->code_start + jinfo->code_size; + ent.discrim = 0; + ent.line = 0; + fwrite(&ent,sizeof(ent),1,perf_dump_file); + fwrite("",1,1,perf_dump_file); + // TODO: write debugInfo and unwindInfo immediately before the JitCodeLoadRecord (while lock is held). record.header.timestamp = mono_clock_get_time_ns (clock_id); @@ -2147,7 +2229,13 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) mono_os_mutex_unlock (&perf_dump_mutex); } } +static void +add_basic_JitCodeDebug_info(JitCodeDebug *record) +{ + record->header.id = JIT_DEBUG_INFO; + record->header.timestamp = mono_clock_get_time_ns (clock_id); +} static void add_basic_JitCodeLoadRecord_info (JitCodeLoadRecord *record) { From f196e765bb30c334835e7b6132d400b94046248c Mon Sep 17 00:00:00 2001 From: Sanjam Panda <36253777+saitama951@users.noreply.github.com> Date: Thu, 20 Apr 2023 19:37:57 +0530 Subject: [PATCH 2/8] added comments --- src/mono/mono/mini/mini-runtime.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index b329daeeb63bb..a291a3ae093b7 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2160,7 +2160,8 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) int i; memset(&rec, 0, sizeof(rec)); - + + //populating info relating debug methods minfo = mono_debug_lookup_method(jinfo->d.method); dmji = mono_debug_find_method( jinfo->d.method, NULL); @@ -2191,6 +2192,7 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) for( i = 0; i < dmji->num_line_numbers;++i) { + //get the line number using il offset loc = mono_debug_lookup_source_location_by_il(jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); if(!loc) @@ -2211,14 +2213,14 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) fwrite(loc->source_file,strlen(loc->source_file)+1,1,perf_dump_file); } - // TODO: write unwindInfo immediately before the JitCodeLoadRecord (while lock is held). + ent.code_addr = (guint64)jinfo->code_start + jinfo->code_size; ent.discrim = 0; ent.line = 0; fwrite(&ent,sizeof(ent),1,perf_dump_file); fwrite("",1,1,perf_dump_file); - // TODO: write debugInfo and unwindInfo immediately before the JitCodeLoadRecord (while lock is held). + // TODO: write unwindInfo immediately before the JitCodeLoadRecord (while lock is held). record.header.timestamp = mono_clock_get_time_ns (clock_id); From c48a6dcb8c9e0ae97a800832bb4264ebccd4c647 Mon Sep 17 00:00:00 2001 From: Sanjam Panda <36253777+saitama951@users.noreply.github.com> Date: Thu, 20 Apr 2023 20:10:01 +0530 Subject: [PATCH 3/8] Update mini-runtime.c --- src/mono/mono/mini/mini-runtime.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index a291a3ae093b7..17aa8d81204e4 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include From f1b010c1786937d05604b1db1d48d8d845db5401 Mon Sep 17 00:00:00 2001 From: Sanjam Panda <36253777+saitama951@users.noreply.github.com> Date: Fri, 21 Apr 2023 10:17:54 +0530 Subject: [PATCH 4/8] made changes to coding conventions --- src/mono/mono/mini/mini-runtime.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 17aa8d81204e4..c2ade3d0c0bd3 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2170,16 +2170,14 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) rec.code_addr = (guint64)dmji->code_start; rec.header.total_size = sizeof(rec) + sizeof(ent) + 1; rec.nr_entry=1; - for(i=0;i < dmji->num_line_numbers;++i) - { - loc = mono_debug_lookup_source_location_by_il(jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); + for(i=0;i < dmji->num_line_numbers;++i){ + + loc = mono_debug_lookup_source_location_by_il(jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); - if(!(loc)) - { + if(!(loc) continue; - } - if(!(loc->source_file)) - { + + if(!(loc->source_file)){ mono_debug_free_source_location(loc); continue; } @@ -2191,16 +2189,17 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) fwrite(&rec,sizeof(rec), 1 ,perf_dump_file); - for( i = 0; i < dmji->num_line_numbers;++i) - { + for( i = 0; i < dmji->num_line_numbers;++i){ + //get the line number using il offset loc = mono_debug_lookup_source_location_by_il(jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); if(!loc) continue; - if(!(loc->source_file)) - { - mono_debug_free_source_location(loc); + + if(!(loc->source_file)){ + + mono_debug_free_source_location(loc); continue; } @@ -2208,8 +2207,6 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) ent.discrim = 0; ent.line = (guint32)loc->row; - - fwrite(&ent, sizeof(ent),1,perf_dump_file); fwrite(loc->source_file,strlen(loc->source_file)+1,1,perf_dump_file); } From 78579e30362ed95a4b7fd575e9ec59797faa0958 Mon Sep 17 00:00:00 2001 From: Sanjam Panda <36253777+saitama951@users.noreply.github.com> Date: Mon, 24 Apr 2023 09:43:12 +0530 Subject: [PATCH 5/8] Update mini-runtime.c --- src/mono/mono/mini/mini-runtime.c | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index c2ade3d0c0bd3..212fbc15e5748 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2160,46 +2160,46 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) MonoDebugSourceLocation *loc; int i; - memset(&rec, 0, sizeof(rec)); + memset (&rec, 0, sizeof(rec)); //populating info relating debug methods - minfo = mono_debug_lookup_method(jinfo->d.method); - dmji = mono_debug_find_method( jinfo->d.method, NULL); + minfo = mono_debug_lookup_method (jinfo->d.method); + dmji = mono_debug_find_method (jinfo->d.method, NULL); - add_basic_JitCodeDebug_info(&rec); + add_basic_JitCodeDebug_info (&rec); rec.code_addr = (guint64)dmji->code_start; - rec.header.total_size = sizeof(rec) + sizeof(ent) + 1; - rec.nr_entry=1; - for(i=0;i < dmji->num_line_numbers;++i){ + rec.header.total_size = sizeof (rec) + sizeof (ent) + 1; + rec.nr_entry = 1; + for (i = 0; i < dmji->num_line_numbers; ++i){ - loc = mono_debug_lookup_source_location_by_il(jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); + loc = mono_debug_lookup_source_location_by_il (jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); - if(!(loc) + if(!loc) continue; - if(!(loc->source_file)){ - mono_debug_free_source_location(loc); + if(!loc->source_file){ + mono_debug_free_source_location (loc); continue; } - rec.header.total_size += sizeof(ent) + strlen(loc->source_file) + 1; + rec.header.total_size += sizeof (ent) + strlen (loc->source_file) + 1; rec.nr_entry++; } - fwrite(&rec,sizeof(rec), 1 ,perf_dump_file); + fwrite (&rec, sizeof (rec), 1 , perf_dump_file); - for( i = 0; i < dmji->num_line_numbers;++i){ + for( i = 0; i < dmji->num_line_numbers; ++i){ //get the line number using il offset - loc = mono_debug_lookup_source_location_by_il(jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); + loc = mono_debug_lookup_source_location_by_il (jinfo->d.method, dmji->line_numbers[i].il_offset, NULL); if(!loc) continue; - if(!(loc->source_file)){ + if(!loc->source_file){ - mono_debug_free_source_location(loc); + mono_debug_free_source_location (loc); continue; } @@ -2207,16 +2207,16 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) ent.discrim = 0; ent.line = (guint32)loc->row; - fwrite(&ent, sizeof(ent),1,perf_dump_file); - fwrite(loc->source_file,strlen(loc->source_file)+1,1,perf_dump_file); + fwrite (&ent, sizeof(ent), 1, perf_dump_file); + fwrite (loc->source_file, strlen (loc->source_file) + 1, 1, perf_dump_file); } ent.code_addr = (guint64)jinfo->code_start + jinfo->code_size; ent.discrim = 0; ent.line = 0; - fwrite(&ent,sizeof(ent),1,perf_dump_file); - fwrite("",1,1,perf_dump_file); + fwrite (&ent, sizeof (ent), 1, perf_dump_file); + fwrite ("", 1, 1, perf_dump_file); // TODO: write unwindInfo immediately before the JitCodeLoadRecord (while lock is held). @@ -2230,7 +2230,7 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) } } static void -add_basic_JitCodeDebug_info(JitCodeDebug *record) +add_basic_JitCodeDebug_info (JitCodeDebug *record) { record->header.id = JIT_DEBUG_INFO; record->header.timestamp = mono_clock_get_time_ns (clock_id); From 42813e9109c09f207080d1bf421a668b9ba09fed Mon Sep 17 00:00:00 2001 From: Sanjam Panda <36253777+saitama951@users.noreply.github.com> Date: Mon, 24 Apr 2023 09:44:26 +0530 Subject: [PATCH 6/8] Update mini-runtime.c --- src/mono/mono/mini/mini-runtime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 212fbc15e5748..8bf27c1f0f17a 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2078,16 +2078,16 @@ typedef struct guint32 line; guint32 discrim; char name[]; -}DebugEntry; +} DebugEntry; typedef struct { RecordHeader header; guint64 code_addr; guint64 nr_entry; DebugEntry debug_entry[]; -}JitCodeDebug; +} JitCodeDebug; -static void add_basic_JitCodeDebug_info(JitCodeDebug *record); +static void add_basic_JitCodeDebug_info (JitCodeDebug *record); static void add_file_header_info (FileHeader *header); static void add_basic_JitCodeLoadRecord_info (JitCodeLoadRecord *record); From 2c03cc21b5acf01fbf43fde1157b15495ce31add Mon Sep 17 00:00:00 2001 From: Sanjam Panda <36253777+saitama951@users.noreply.github.com> Date: Mon, 24 Apr 2023 09:50:57 +0530 Subject: [PATCH 7/8] Update mini-runtime.c --- src/mono/mono/mini/mini-runtime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 8bf27c1f0f17a..e9745a12387d6 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2172,7 +2172,7 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) rec.nr_entry = 1; for (i = 0; i < dmji->num_line_numbers; ++i){ - loc = mono_debug_lookup_source_location_by_il (jinfo->d.method,dmji->line_numbers[i].il_offset,NULL); + loc = mono_debug_lookup_source_location_by_il (jinfo->d.method, dmji->line_numbers[i].il_offset, NULL); if(!loc) continue; @@ -2186,7 +2186,7 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) rec.nr_entry++; } - fwrite (&rec, sizeof (rec), 1 , perf_dump_file); + fwrite (&rec, sizeof (rec), 1, perf_dump_file); for( i = 0; i < dmji->num_line_numbers; ++i){ From 2117a4816b98c192cb151a5fdfb5ce68306bea75 Mon Sep 17 00:00:00 2001 From: Sanjam Panda <36253777+saitama951@users.noreply.github.com> Date: Mon, 24 Apr 2023 09:51:47 +0530 Subject: [PATCH 8/8] Update mini-runtime.c --- src/mono/mono/mini/mini-runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index e9745a12387d6..f0163ce233835 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2160,7 +2160,7 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code) MonoDebugSourceLocation *loc; int i; - memset (&rec, 0, sizeof(rec)); + memset (&rec, 0, sizeof (rec)); //populating info relating debug methods minfo = mono_debug_lookup_method (jinfo->d.method);