Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 94 additions & 3 deletions src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <mono/metadata/threads.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/debug-internals.h>
#include <mono/metadata/domain-internals.h>
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/mono-config.h>
Expand Down Expand Up @@ -2015,7 +2016,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
Expand All @@ -2031,7 +2032,8 @@ enum {
#elif HOST_RISCV
ELF_MACHINE = EM_RISCV,
#endif
JIT_CODE_LOAD = 0
JIT_CODE_LOAD = 0,
JIT_DEBUG_INFO = 2
};
typedef struct
{
Expand Down Expand Up @@ -2062,7 +2064,22 @@ typedef struct
// Null terminated function name
// Native code
} JitCodeLoadRecord;
typedef struct
{
guint64 code_addr;
guint32 line;
guint32 discrim;
char name[];
}DebugEntry;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}DebugEntry;
} DebugEntry;

typedef struct
{
RecordHeader header;
guint64 code_addr;
guint64 nr_entry;
DebugEntry debug_entry[];
}JitCodeDebug;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}JitCodeDebug;
} JitCodeDebug;


static void add_basic_JitCodeDebug_info(JitCodeDebug *record);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void add_basic_JitCodeDebug_info(JitCodeDebug *record);
static void add_basic_JitCodeDebug_info (JitCodeDebug *record);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In mono code base, we add a space between the function name and the "(". Please follow this function call style for all the code change in this PR.

static void add_file_header_info (FileHeader *header);
static void add_basic_JitCodeLoadRecord_info (JitCodeLoadRecord *record);

Expand Down Expand Up @@ -2128,7 +2145,75 @@ mono_emit_jit_dump (MonoJitInfo *jinfo, gpointer code)

record.code_index = ++code_index;

// TODO: write debugInfo and unwindInfo immediately before the JitCodeLoadRecord (while lock is held).
DebugEntry ent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should follow the mono coding conventions, see the rest of the file for examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. let me know if there is anything else

JitCodeDebug rec;
MonoDebugMethodInfo *minfo;
MonoDebugMethodJitInfo *dmji;
MonoDebugSourceLocation *loc;
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);

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)
{
//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);
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);
}


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 unwindInfo immediately before the JitCodeLoadRecord (while lock is held).

record.header.timestamp = mono_clock_get_time_ns (clock_id);

Expand All @@ -2139,7 +2224,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)
{
Expand Down