@@ -5442,12 +5442,47 @@ get_object_id_for_debugger_method (MonoClass* async_builder_class)
5442
5442
MonoError error ;
5443
5443
GPtrArray * array = mono_class_get_methods_by_name (async_builder_class , "get_ObjectIdForDebugger" , 0x24 , FALSE, FALSE, & error );
5444
5444
mono_error_assert_ok (& error );
5445
- g_assert (array -> len == 1 );
5445
+ if (array -> len != 1 ) {
5446
+ g_ptr_array_free (array , TRUE);
5447
+ //if we don't find method get_ObjectIdForDebugger we try to find the property Task to continue async debug.
5448
+ MonoProperty * prop = mono_class_get_property_from_name (async_builder_class , "Task" );
5449
+ if (!prop ) {
5450
+ DEBUG_PRINTF (1 , "Impossible to debug async methods.\n" );
5451
+ return NULL ;
5452
+ }
5453
+ return prop -> get ;
5454
+ }
5446
5455
MonoMethod * method = (MonoMethod * )g_ptr_array_index (array , 0 );
5447
5456
g_ptr_array_free (array , TRUE);
5448
5457
return method ;
5449
5458
}
5450
5459
5460
+ static MonoClass *
5461
+ get_class_to_get_builder_field (StackFrame * frame )
5462
+ {
5463
+ MonoError error ;
5464
+ gpointer this_addr = get_this_addr (frame );
5465
+ MonoClass * original_class = frame -> method -> klass ;
5466
+ MonoClass * ret ;
5467
+ if (!mono_class_is_valuetype (original_class ) && mono_class_is_open_constructed_type (& original_class -> byval_arg )) {
5468
+ MonoObject * this_obj = * (MonoObject * * )this_addr ;
5469
+ MonoGenericContext context ;
5470
+ MonoType * inflated_type ;
5471
+
5472
+ if (!this_obj )
5473
+ return NULL ;
5474
+
5475
+ context = mono_get_generic_context_from_stack_frame (frame -> ji , this_obj -> vtable );
5476
+ inflated_type = mono_class_inflate_generic_type_checked (& original_class -> byval_arg , & context , & error );
5477
+ mono_error_assert_ok (& error ); /* FIXME don't swallow the error */
5478
+
5479
+ ret = mono_class_from_mono_type (inflated_type );
5480
+ mono_metadata_free_type (inflated_type );
5481
+ return ret ;
5482
+ }
5483
+ return original_class ;
5484
+ }
5485
+
5451
5486
/* Return the address of the AsyncMethodBuilder struct belonging to the state machine method pointed to by FRAME */
5452
5487
static gpointer
5453
5488
get_async_method_builder (StackFrame * frame )
@@ -5456,15 +5491,18 @@ get_async_method_builder (StackFrame *frame)
5456
5491
MonoClassField * builder_field ;
5457
5492
gpointer builder ;
5458
5493
guint8 * this_addr ;
5494
+ MonoClass * klass = frame -> method -> klass ;
5459
5495
5460
- builder_field = mono_class_get_field_from_name (frame -> method -> klass , "<>t__builder" );
5461
- g_assert (builder_field );
5496
+ klass = get_class_to_get_builder_field (frame );
5497
+ builder_field = mono_class_get_field_from_name_full (klass , "<>t__builder" , NULL );
5498
+ if (!builder_field )
5499
+ return NULL ;
5462
5500
5463
5501
this_addr = get_this_addr (frame );
5464
5502
if (!this_addr )
5465
5503
return NULL ;
5466
5504
5467
- if (mono_class_is_valuetype (frame -> method -> klass )) {
5505
+ if (mono_class_is_valuetype (klass )) {
5468
5506
guint8 * vtaddr = * (guint8 * * )this_addr ;
5469
5507
builder = (char * )vtaddr + mono_field_get_offset (builder_field ) - sizeof (MonoObject );
5470
5508
} else {
@@ -5497,8 +5535,9 @@ get_this_async_id (StackFrame *frame)
5497
5535
if (!builder )
5498
5536
return 0 ;
5499
5537
5500
- builder_field = mono_class_get_field_from_name (frame -> method -> klass , "<>t__builder" );
5501
- g_assert (builder_field );
5538
+ builder_field = mono_class_get_field_from_name (get_class_to_get_builder_field (frame ), "<>t__builder" );
5539
+ if (!builder_field )
5540
+ return 0 ;
5502
5541
5503
5542
tls = (DebuggerTlsData * )mono_native_tls_get_value (debugger_tls_id );
5504
5543
if (tls ) {
@@ -5507,6 +5546,11 @@ get_this_async_id (StackFrame *frame)
5507
5546
}
5508
5547
5509
5548
method = get_object_id_for_debugger_method (mono_class_from_mono_type (mono_field_get_type (builder_field )));
5549
+ if (!method ) {
5550
+ if (tls )
5551
+ tls -> disable_breakpoints = old_disable_breakpoints ;
5552
+ return 0 ;
5553
+ }
5510
5554
obj = mono_runtime_try_invoke (method , builder , NULL , & ex , & error );
5511
5555
mono_error_assert_ok (& error );
5512
5556
@@ -5521,10 +5565,12 @@ get_this_async_id (StackFrame *frame)
5521
5565
static gboolean
5522
5566
set_set_notification_for_wait_completion_flag (StackFrame * frame )
5523
5567
{
5524
- MonoClassField * builder_field = mono_class_get_field_from_name (frame -> method -> klass , "<>t__builder" );
5525
- g_assert (builder_field );
5568
+ MonoClassField * builder_field = mono_class_get_field_from_name (get_class_to_get_builder_field (frame ), "<>t__builder" );
5569
+ if (!builder_field )
5570
+ return FALSE;
5526
5571
gpointer builder = get_async_method_builder (frame );
5527
- g_assert (builder );
5572
+ if (!builder )
5573
+ return FALSE;
5528
5574
5529
5575
void * args [1 ];
5530
5576
gboolean arg = TRUE;
@@ -6016,7 +6062,6 @@ process_single_step_inner (DebuggerTlsData *tls, gboolean from_signal)
6016
6062
return ;
6017
6063
}
6018
6064
6019
-
6020
6065
/*
6021
6066
* The ip points to the instruction causing the single step event, which is before
6022
6067
* the offset recorded in the seq point map, so find the next seq point after ip.
@@ -6788,7 +6833,10 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilte
6788
6833
* We are stopped at a throw site. Stepping should go to the catch site.
6789
6834
*/
6790
6835
frame = tls -> catch_frame ;
6791
- g_assert (frame .type == FRAME_TYPE_MANAGED || frame .type == FRAME_TYPE_INTERP );
6836
+ if (frame .type != FRAME_TYPE_MANAGED && frame .type != FRAME_TYPE_INTERP ) {
6837
+ DEBUG_PRINTF (1 , "Current frame is not managed nor interpreter.\n" );
6838
+ return ERR_INVALID_ARGUMENT ;
6839
+ }
6792
6840
6793
6841
/*
6794
6842
* Find the seq point corresponding to the landing site ip, which is the first seq
@@ -6798,7 +6846,11 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilte
6798
6846
sp = (found_sp )? & local_sp : NULL ;
6799
6847
if (!sp )
6800
6848
no_seq_points_found (frame .method , frame .native_offset );
6801
- g_assert (sp );
6849
+
6850
+ if (!sp ) {
6851
+ DEBUG_PRINTF (1 , "Could not find next sequence point.\n" );
6852
+ return ERR_INVALID_ARGUMENT ;
6853
+ }
6802
6854
6803
6855
method = frame .method ;
6804
6856
@@ -6844,7 +6896,10 @@ ss_create (MonoInternalThread *thread, StepSize size, StepDepth depth, StepFilte
6844
6896
sp = (found_sp )? & local_sp : NULL ;
6845
6897
if (!sp )
6846
6898
no_seq_points_found (frame -> method , frame -> native_offset );
6847
- g_assert (sp );
6899
+ if (!sp ) {
6900
+ DEBUG_PRINTF (1 , "Could not find next sequence point.\n" );
6901
+ return ERR_INVALID_ARGUMENT ;
6902
+ }
6848
6903
method = frame -> method ;
6849
6904
}
6850
6905
}
@@ -10812,7 +10867,11 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
10812
10867
if (mono_class_get_context (klass )) {
10813
10868
MonoError error ;
10814
10869
result = mono_class_inflate_generic_method_full_checked (result , klass , mono_class_get_context (klass ), & error );
10815
- g_assert (mono_error_ok (& error )); /* FIXME don't swallow the error */
10870
+ if (!mono_error_ok (& error )) {
10871
+ buffer_add_string (buf , mono_error_get_message (& error ));
10872
+ mono_error_cleanup (& error );
10873
+ return ERR_INVALID_ARGUMENT ;
10874
+ }
10816
10875
}
10817
10876
}
10818
10877
}
@@ -10955,7 +11014,12 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
10955
11014
char * s ;
10956
11015
10957
11016
s = mono_string_to_utf8_checked ((MonoString * )val , & error );
10958
- mono_error_assert_ok (& error );
11017
+ if (!mono_error_ok (& error )) {
11018
+ buffer_add_string (buf , mono_error_get_message (& error ));
11019
+ mono_error_cleanup (& error );
11020
+ g_free (s );
11021
+ return ERR_INVALID_ARGUMENT ;
11022
+ }
10959
11023
buffer_add_byte (buf , TOKEN_TYPE_STRING );
10960
11024
buffer_add_string (buf , s );
10961
11025
g_free (s );
@@ -11023,7 +11087,11 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
11023
11087
tmp_context .method_inst = ginst ;
11024
11088
11025
11089
inflated = mono_class_inflate_generic_method_checked (method , & tmp_context , & error );
11026
- g_assert (mono_error_ok (& error )); /* FIXME don't swallow the error */
11090
+ if (!mono_error_ok (& error )) {
11091
+ buffer_add_string (buf , mono_error_get_message (& error ));
11092
+ mono_error_cleanup (& error );
11093
+ return ERR_INVALID_ARGUMENT ;
11094
+ }
11027
11095
if (!mono_verifier_is_method_valid_generic_instantiation (inflated ))
11028
11096
return ERR_INVALID_ARGUMENT ;
11029
11097
buffer_add_methodid (buf , domain , inflated );
@@ -11492,7 +11560,10 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
11492
11560
set_interp_var (& frame -> actual_method -> klass -> this_arg , addr , val_buf );
11493
11561
} else {
11494
11562
var = jit -> this_var ;
11495
- g_assert (var );
11563
+ if (!var ) {
11564
+ buffer_add_string (buf , "Invalid this object" );
11565
+ return ERR_INVALID_ARGUMENT ;
11566
+ }
11496
11567
11497
11568
set_var (& frame -> actual_method -> klass -> this_arg , var , & frame -> ctx , frame -> domain , val_buf , frame -> reg_locations , & tls -> restore_state .ctx );
11498
11569
}
@@ -11535,9 +11606,11 @@ array_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
11535
11606
index = decode_int (p , & p , end );
11536
11607
len = decode_int (p , & p , end );
11537
11608
11538
- g_assert (index >= 0 && len >= 0 );
11609
+ if (index < 0 || len < 0 )
11610
+ return ERR_INVALID_ARGUMENT ;
11539
11611
// Reordered to avoid integer overflow
11540
- g_assert (!(index > arr -> max_length - len ));
11612
+ if (index > arr -> max_length - len )
11613
+ return ERR_INVALID_ARGUMENT ;
11541
11614
11542
11615
esize = mono_array_element_size (mono_object_get_class (& arr -> obj ));
11543
11616
for (i = index ; i < index + len ; ++ i ) {
@@ -11549,9 +11622,11 @@ array_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
11549
11622
index = decode_int (p , & p , end );
11550
11623
len = decode_int (p , & p , end );
11551
11624
11552
- g_assert (index >= 0 && len >= 0 );
11625
+ if (index < 0 || len < 0 )
11626
+ return ERR_INVALID_ARGUMENT ;
11553
11627
// Reordered to avoid integer overflow
11554
- g_assert (!(index > arr -> max_length - len ));
11628
+ if (index > arr -> max_length - len )
11629
+ return ERR_INVALID_ARGUMENT ;
11555
11630
11556
11631
esize = mono_array_element_size (mono_object_get_class (& arr -> obj ));
11557
11632
for (i = index ; i < index + len ; ++ i ) {
0 commit comments