Skip to content

Commit c441891

Browse files
thaystglambdageek
andauthored
[mono][hotreload] Generate seq_points if we don't have pdb information 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) <akliger@gmail.com> * Addressing @lambdageek comments --------- Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
1 parent 4dcad85 commit c441891

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/mono/mono/metadata/debug-internals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,6 @@ mono_debug_lookup_source_location_by_il (MonoMethod *method, guint32 il_offset,
112112
MONO_COMPONENT_API char*
113113
mono_debug_image_get_sourcelink (MonoImage *image);
114114

115+
mono_bool
116+
mono_debug_generate_enc_seq_points_without_debug_info (MonoDebugMethodInfo *minfo);
115117
#endif /* __DEBUG_INTERNALS_H__ */

src/mono/mono/metadata/mono-debug.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,21 @@ mono_debug_enabled (void)
11271127
return mono_debug_format != MONO_DEBUG_FORMAT_NONE;
11281128
}
11291129

1130+
1131+
//Returns true if the method has updates but doesn't have ppdb information then we should generate the seq points using the coreclr rules
1132+
mono_bool
1133+
mono_debug_generate_enc_seq_points_without_debug_info (MonoDebugMethodInfo *minfo)
1134+
{
1135+
MonoImage* img = m_class_get_image (minfo->method->klass);
1136+
if (G_UNLIKELY (img->has_updates)) {
1137+
guint32 idx = mono_metadata_token_index (minfo->method->token);
1138+
MonoDebugInformationEnc *mdie = (MonoDebugInformationEnc *) mono_metadata_update_get_updated_method_ppdb (img, idx);
1139+
if (mdie == NULL)
1140+
return TRUE;
1141+
}
1142+
return FALSE;
1143+
}
1144+
11301145
void
11311146
mono_debug_get_seq_points (MonoDebugMethodInfo *minfo, char **source_file, GPtrArray **source_file_list, int **source_files, MonoSymSeqPoint **seq_points, int *n_seq_points)
11321147
{

src/mono/mono/mini/interp/transform.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4782,6 +4782,19 @@ is_ip_protected (MonoMethodHeader *header, int offset)
47824782
return FALSE;
47834783
}
47844784

4785+
static gboolean
4786+
should_insert_seq_point (TransformData *td)
4787+
{
4788+
//following the CoreCLR's algorithm for adding the sequence points
4789+
if ((*td->ip == CEE_NOP) ||
4790+
(*td->ip == CEE_CALLVIRT) ||
4791+
(*td->ip == CEE_CALLI) ||
4792+
(*td->ip == CEE_CALL) ||
4793+
(GPTRDIFF_TO_INT (td->sp - td->stack) == 0))
4794+
return TRUE;
4795+
return FALSE;
4796+
}
4797+
47854798
static gboolean
47864799
generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, MonoGenericContext *generic_context, MonoError *error)
47874800
{
@@ -4813,6 +4826,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
48134826
gboolean save_last_error = FALSE;
48144827
gboolean link_bblocks = TRUE;
48154828
gboolean inlining = td->method != method;
4829+
gboolean generate_enc_seq_points_without_debug_info = FALSE;
48164830
InterpBasicBlock *exit_bb = NULL;
48174831

48184832
original_bb = bb = mono_basic_block_split (method, error, header);
@@ -4859,6 +4873,8 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
48594873
int n_il_offsets;
48604874

48614875
mono_debug_get_seq_points (minfo, NULL, NULL, NULL, &sps, &n_il_offsets);
4876+
if (n_il_offsets == 0)
4877+
generate_enc_seq_points_without_debug_info = mono_debug_generate_enc_seq_points_without_debug_info (minfo);
48624878
// FIXME: Free
48634879
seq_point_locs = mono_bitset_mem_new (mono_mempool_alloc0 (td->mempool, mono_bitset_alloc_size (header->code_size, 0)), header->code_size, 0);
48644880
sym_seq_points = TRUE;
@@ -5084,6 +5100,9 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
50845100
WRITE64_INS (td->last_ins, 0, &counter);
50855101
}
50865102

5103+
if (G_UNLIKELY (generate_enc_seq_points_without_debug_info) && should_insert_seq_point (td))
5104+
last_seq_point = interp_add_ins (td, MINT_SDB_SEQ_POINT);
5105+
50875106
switch (*td->ip) {
50885107
case CEE_NOP:
50895108
/* lose it */
@@ -5353,7 +5372,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
53535372
if (!interp_transform_call (td, method, NULL, generic_context, constrained_class, readonly, error, TRUE, save_last_error, tailcall))
53545373
goto exit;
53555374

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

0 commit comments

Comments
 (0)