Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[mono][hotreload] Generate seq_points if we don't have pdb informatio…
…n from HotReload (#93039)

* Generating seq_points if we don't have pdb information from HotReload

* Apply suggestions from code review

Co-authored-by: Aleksey Kliger (λgeek) <[email protected]>

* Addressing @lambdageek comments

---------

Co-authored-by: Aleksey Kliger (λgeek) <[email protected]>
  • Loading branch information
thaystg and lambdageek committed Jan 18, 2024
commit 725e0f8acd96e1c9b409591c9ad8bb2ec20655b4
2 changes: 2 additions & 0 deletions src/mono/mono/metadata/debug-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@ mono_debug_lookup_source_location_by_il (MonoMethod *method, guint32 il_offset,
MONO_COMPONENT_API char*
mono_debug_image_get_sourcelink (MonoImage *image);

mono_bool
mono_debug_generate_enc_seq_points_without_debug_info (MonoDebugMethodInfo *minfo);
#endif /* __DEBUG_INTERNALS_H__ */
15 changes: 15 additions & 0 deletions src/mono/mono/metadata/mono-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,21 @@ mono_debug_enabled (void)
return mono_debug_format != MONO_DEBUG_FORMAT_NONE;
}


//Returns true if the method has updates but doesn't have ppdb information then we should generate the seq points using the coreclr rules
mono_bool
mono_debug_generate_enc_seq_points_without_debug_info (MonoDebugMethodInfo *minfo)
{
MonoImage* img = m_class_get_image (minfo->method->klass);
if (G_UNLIKELY (img->has_updates)) {
guint32 idx = mono_metadata_token_index (minfo->method->token);
MonoDebugInformationEnc *mdie = (MonoDebugInformationEnc *) mono_metadata_update_get_updated_method_ppdb (img, idx);
if (mdie == NULL)
return TRUE;
}
return FALSE;
}

void
mono_debug_get_seq_points (MonoDebugMethodInfo *minfo, char **source_file, GPtrArray **source_file_list, int **source_files, MonoSymSeqPoint **seq_points, int *n_seq_points)
{
Expand Down
21 changes: 20 additions & 1 deletion src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -4786,6 +4786,19 @@ is_ip_protected (MonoMethodHeader *header, int offset)
return FALSE;
}

static gboolean
should_insert_seq_point (TransformData *td)
{
//following the CoreCLR's algorithm for adding the sequence points
if ((*td->ip == CEE_NOP) ||
(*td->ip == CEE_CALLVIRT) ||
(*td->ip == CEE_CALLI) ||
(*td->ip == CEE_CALL) ||
(GPTRDIFF_TO_INT (td->sp - td->stack) == 0))
return TRUE;
return FALSE;
}

static gboolean
generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, MonoGenericContext *generic_context, MonoError *error)
{
Expand Down Expand Up @@ -4817,6 +4830,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
gboolean save_last_error = FALSE;
gboolean link_bblocks = TRUE;
gboolean inlining = td->method != method;
gboolean generate_enc_seq_points_without_debug_info = FALSE;
InterpBasicBlock *exit_bb = NULL;

original_bb = bb = mono_basic_block_split (method, error, header);
Expand Down Expand Up @@ -4863,6 +4877,8 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
int n_il_offsets;

mono_debug_get_seq_points (minfo, NULL, NULL, NULL, &sps, &n_il_offsets);
if (n_il_offsets == 0)
generate_enc_seq_points_without_debug_info = mono_debug_generate_enc_seq_points_without_debug_info (minfo);
// FIXME: Free
seq_point_locs = mono_bitset_mem_new (mono_mempool_alloc0 (td->mempool, mono_bitset_alloc_size (header->code_size, 0)), header->code_size, 0);
sym_seq_points = TRUE;
Expand Down Expand Up @@ -5092,6 +5108,9 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
WRITE64_INS (td->last_ins, 0, &counter);
}

if (G_UNLIKELY (generate_enc_seq_points_without_debug_info) && should_insert_seq_point (td))
last_seq_point = interp_add_ins (td, MINT_SDB_SEQ_POINT);

switch (*td->ip) {
case CEE_NOP:
/* lose it */
Expand Down Expand Up @@ -5361,7 +5380,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
if (!interp_transform_call (td, method, NULL, generic_context, constrained_class, readonly, error, TRUE, save_last_error, tailcall))
goto exit;

if (need_seq_point) {
if (need_seq_point && !generate_enc_seq_points_without_debug_info) {
// check if it is a nested call and remove the MONO_INST_NONEMPTY_STACK of the last breakpoint, only for non native methods
if (!(method->flags & METHOD_IMPL_ATTRIBUTE_NATIVE)) {
if (emitted_funccall_seq_point) {
Expand Down