@@ -4589,7 +4589,16 @@ get_object_id_for_debugger_method (MonoClass* async_builder_class)
45894589 ERROR_DECL (error );
45904590 GPtrArray * array = mono_class_get_methods_by_name (async_builder_class , "get_ObjectIdForDebugger" , 0x24 , 1 , FALSE, error );
45914591 mono_error_assert_ok (error );
4592- g_assert (array -> len == 1 );
4592+ if (array -> len != 1 ) {
4593+ g_ptr_array_free (array , TRUE);
4594+ //if we don't find method get_ObjectIdForDebugger we try to find the property Task to continue async debug.
4595+ MonoProperty * prop = mono_class_get_property_from_name_internal (async_builder_class , "Task" );
4596+ if (!prop ) {
4597+ DEBUG_PRINTF (1 , "Impossible to debug async methods.\n" );
4598+ return NULL ;
4599+ }
4600+ return prop -> get ;
4601+ }
45934602 MonoMethod * method = (MonoMethod * )g_ptr_array_index (array , 0 );
45944603 g_ptr_array_free (array , TRUE);
45954604 return method ;
@@ -4607,7 +4616,9 @@ get_class_to_get_builder_field(DbgEngineStackFrame *frame)
46074616 MonoGenericContext context ;
46084617 MonoType * inflated_type ;
46094618
4610- g_assert (this_obj );
4619+ if (!this_obj )
4620+ return NULL ;
4621+
46114622 context = mono_get_generic_context_from_stack_frame (frame -> ji , this_obj -> vtable );
46124623 inflated_type = mono_class_inflate_generic_type_checked (m_class_get_byval_arg (original_class ), & context , error );
46134624 mono_error_assert_ok (error ); /* FIXME don't swallow the error */
@@ -4632,7 +4643,8 @@ get_async_method_builder (DbgEngineStackFrame *frame)
46324643
46334644 klass = get_class_to_get_builder_field (frame );
46344645 builder_field = mono_class_get_field_from_name_full (klass , "<>t__builder" , NULL );
4635- g_assert (builder_field );
4646+ if (!builder_field )
4647+ return NULL ;
46364648
46374649 this_addr = get_this_addr (frame );
46384650 if (!this_addr )
@@ -4671,7 +4683,8 @@ get_this_async_id (DbgEngineStackFrame *frame)
46714683 return 0 ;
46724684
46734685 builder_field = mono_class_get_field_from_name_full (get_class_to_get_builder_field (frame ), "<>t__builder" , NULL );
4674- g_assert (builder_field );
4686+ if (!builder_field )
4687+ return 0 ;
46754688
46764689 tls = (DebuggerTlsData * )mono_native_tls_get_value (debugger_tls_id );
46774690 if (tls ) {
@@ -4680,6 +4693,11 @@ get_this_async_id (DbgEngineStackFrame *frame)
46804693 }
46814694
46824695 method = get_object_id_for_debugger_method (mono_class_from_mono_type_internal (builder_field -> type ));
4696+ if (!method ) {
4697+ if (tls )
4698+ tls -> disable_breakpoints = old_disable_breakpoints ;
4699+ return 0 ;
4700+ }
46834701 obj = mono_runtime_try_invoke (method , builder , NULL , & ex , error );
46844702 mono_error_assert_ok (error );
46854703
@@ -4695,9 +4713,11 @@ static gboolean
46954713set_set_notification_for_wait_completion_flag (DbgEngineStackFrame * frame )
46964714{
46974715 MonoClassField * builder_field = mono_class_get_field_from_name_full (get_class_to_get_builder_field (frame ), "<>t__builder" , NULL );
4698- g_assert (builder_field );
4716+ if (!builder_field )
4717+ return FALSE;
46994718 gpointer builder = get_async_method_builder (frame );
4700- g_assert (builder );
4719+ if (!builder )
4720+ return FALSE;
47014721
47024722 MonoMethod * method = get_set_notification_method (mono_class_from_mono_type_internal (builder_field -> type ));
47034723 if (method == NULL )
@@ -5071,7 +5091,10 @@ ss_create_init_args (SingleStepReq *ss_req, SingleStepArgs *args)
50715091 * We are stopped at a throw site. Stepping should go to the catch site.
50725092 */
50735093 frame = tls -> catch_frame ;
5074- g_assert (frame .type == FRAME_TYPE_MANAGED || frame .type == FRAME_TYPE_INTERP );
5094+ if (frame .type != FRAME_TYPE_MANAGED && frame .type != FRAME_TYPE_INTERP ) {
5095+ DEBUG_PRINTF (1 , "Current frame is not managed nor interpreter.\n" );
5096+ return ERR_INVALID_ARGUMENT ;
5097+ }
50755098
50765099 /*
50775100 * Find the seq point corresponding to the landing site ip, which is the first seq
@@ -5080,7 +5103,10 @@ ss_create_init_args (SingleStepReq *ss_req, SingleStepArgs *args)
50805103 found_sp = mono_find_next_seq_point_for_native_offset (frame .domain , frame .method , frame .native_offset , & info , & args -> sp );
50815104 if (!found_sp )
50825105 no_seq_points_found (frame .method , frame .native_offset );
5083- g_assert (found_sp );
5106+ if (!found_sp ) {
5107+ DEBUG_PRINTF (1 , "Could not find next sequence point.\n" );
5108+ return ERR_INVALID_ARGUMENT ;
5109+ }
50845110
50855111 method = frame .method ;
50865112
@@ -5125,7 +5151,10 @@ ss_create_init_args (SingleStepReq *ss_req, SingleStepArgs *args)
51255151 found_sp = mono_find_prev_seq_point_for_native_offset (frame -> de .domain , frame -> de .method , frame -> de .native_offset , & info , & args -> sp );
51265152 if (!found_sp )
51275153 no_seq_points_found (frame -> de .method , frame -> de .native_offset );
5128- g_assert (found_sp );
5154+ if (!found_sp ) {
5155+ DEBUG_PRINTF (1 , "Could not find next sequence point.\n" );
5156+ return ERR_INVALID_ARGUMENT ;
5157+ }
51295158 method = frame -> de .method ;
51305159 }
51315160 }
@@ -8861,7 +8890,11 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
88618890 if (mono_class_get_context (klass )) {
88628891 ERROR_DECL (error );
88638892 result = mono_class_inflate_generic_method_full_checked (result , klass , mono_class_get_context (klass ), error );
8864- g_assert (is_ok (error )); /* FIXME don't swallow the error */
8893+ if (!is_ok (error )) {
8894+ add_error_string (buf , mono_error_get_message (error ));
8895+ mono_error_cleanup (error );
8896+ return ERR_INVALID_ARGUMENT ;
8897+ }
88658898 }
88668899 }
88678900 }
@@ -8999,7 +9032,12 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
89999032 char * s ;
90009033
90019034 s = mono_string_to_utf8_checked_internal ((MonoString * )val , error );
9002- mono_error_assert_ok (error );
9035+ if (!is_ok (error )) {
9036+ add_error_string (buf , mono_error_get_message (error ));
9037+ mono_error_cleanup (error );
9038+ g_free (s );
9039+ return ERR_INVALID_ARGUMENT ;
9040+ }
90039041 buffer_add_byte (buf , TOKEN_TYPE_STRING );
90049042 buffer_add_string (buf , s );
90059043 g_free (s );
@@ -9062,7 +9100,11 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
90629100 tmp_context .method_inst = ginst ;
90639101
90649102 inflated = mono_class_inflate_generic_method_checked (method , & tmp_context , error );
9065- g_assert (is_ok (error )); /* FIXME don't swallow the error */
9103+ if (!is_ok (error )) {
9104+ add_error_string (buf , mono_error_get_message (error ));
9105+ mono_error_cleanup (error );
9106+ return ERR_INVALID_ARGUMENT ;
9107+ }
90669108 if (!mono_verifier_is_method_valid_generic_instantiation (inflated ))
90679109 return ERR_INVALID_ARGUMENT ;
90689110 buffer_add_methodid (buf , domain , inflated );
@@ -9489,7 +9531,10 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
94899531 set_interp_var (m_class_get_this_arg (frame -> actual_method -> klass ), addr , val_buf );
94909532 } else {
94919533 var = jit -> this_var ;
9492- g_assert (var );
9534+ if (!var ) {
9535+ add_error_string (buf , "Invalid this object" );
9536+ return ERR_INVALID_ARGUMENT ;
9537+ }
94939538
94949539 set_var (m_class_get_this_arg (frame -> actual_method -> klass ), var , & frame -> ctx , frame -> de .domain , val_buf , frame -> reg_locations , & tls -> restore_state .ctx );
94959540 }
@@ -9532,9 +9577,11 @@ array_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
95329577 index = decode_int (p , & p , end );
95339578 len = decode_int (p , & p , end );
95349579
9535- g_assert (index >= 0 && len >= 0 );
9580+ if (index < 0 || len < 0 )
9581+ return ERR_INVALID_ARGUMENT ;
95369582 // Reordered to avoid integer overflow
9537- g_assert (!(index > arr -> max_length - len ));
9583+ if (index > arr -> max_length - len )
9584+ return ERR_INVALID_ARGUMENT ;
95389585
95399586 esize = mono_array_element_size (arr -> obj .vtable -> klass );
95409587 for (i = index ; i < index + len ; ++ i ) {
@@ -9546,9 +9593,11 @@ array_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
95469593 index = decode_int (p , & p , end );
95479594 len = decode_int (p , & p , end );
95489595
9549- g_assert (index >= 0 && len >= 0 );
9596+ if (index < 0 || len < 0 )
9597+ return ERR_INVALID_ARGUMENT ;
95509598 // Reordered to avoid integer overflow
9551- g_assert (!(index > arr -> max_length - len ));
9599+ if (index > arr -> max_length - len )
9600+ return ERR_INVALID_ARGUMENT ;
95529601
95539602 esize = mono_array_element_size (arr -> obj .vtable -> klass );
95549603 for (i = index ; i < index + len ; ++ i ) {
0 commit comments