Skip to content

Commit 165f4b0

Browse files
thaystgmonojenkins
andauthored
[2020-02][debugger] Fix NOT_IMPLEMENTED while debugging. (#19450)
* Backporting this, and after this I will backport the bump protocol for this PR. * Bump API snapshot submodule Co-authored-by: monojenkins <jo.shields+jenkins@xamarin.com>
1 parent b04dc7e commit 165f4b0

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

external/api-snapshot

Submodule api-snapshot updated 1 file

mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ public class ErrorHandlerEventArgs : EventArgs {
409409
public ErrorCode ErrorCode {
410410
get; set;
411411
}
412+
public string ErrorMessage {
413+
get; set;
414+
}
412415
}
413416

414417
/*
@@ -792,10 +795,12 @@ public PacketReader (Connection connection, byte[] packet) {
792795

793796
// For reply packets
794797
offset = 0;
795-
ReadInt (); // length
798+
var len = ReadInt (); // length
796799
ReadInt (); // id
797800
ReadByte (); // flags
798801
ErrorCode = ReadShort ();
802+
if (ErrorCode == (int)Mono.Debugger.Soft.ErrorCode.INVALID_ARGUMENT && len > offset)
803+
ErrorMsg = ReadString ();
799804
}
800805

801806
public CommandSet CommandSet {
@@ -810,6 +815,10 @@ public int ErrorCode {
810815
get; set;
811816
}
812817

818+
public string ErrorMsg {
819+
get; internal set;
820+
}
821+
813822
public int Offset {
814823
get {
815824
return offset;
@@ -1792,7 +1801,7 @@ PacketReader SendReceive (CommandSet command_set, int command, PacketWriter pack
17921801
LogPacket (packetId, encoded_packet, reply, command_set, command, watch);
17931802
if (r.ErrorCode != 0) {
17941803
if (ErrorHandler != null)
1795-
ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
1804+
ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode, ErrorMessage = r.ErrorMsg});
17961805
throw new NotImplementedException ("No error handler set.");
17971806
} else {
17981807
return r;

mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ internal void ErrorHandler (object sender, ErrorHandlerEventArgs args) {
371371
case ErrorCode.NO_SEQ_POINT_AT_IL_OFFSET:
372372
throw new ArgumentException ("Cannot set breakpoint on the specified IL offset.");
373373
default:
374-
throw new CommandException (args.ErrorCode);
374+
throw new CommandException (args.ErrorCode, args.ErrorMessage);
375375
}
376376
}
377377

@@ -887,13 +887,18 @@ public void VMDisconnect (int req_id, long thread_id, string vm_uri) {
887887

888888
public class CommandException : Exception {
889889

890-
internal CommandException (ErrorCode error_code) : base ("Debuggee returned error code " + error_code + ".") {
890+
internal CommandException (ErrorCode error_code, string error_message) : base ("Debuggee returned error code " + error_code + (error_message == null || error_message.Length == 0 ? "." : " - " + error_message + ".")) {
891891
ErrorCode = error_code;
892+
ErrorMessage = error_message;
892893
}
893894

894895
public ErrorCode ErrorCode {
895896
get; set;
896897
}
898+
899+
public string ErrorMessage {
900+
get; internal set;
901+
}
897902
}
898903

899904
public class VMNotSuspendedException : InvalidOperationException

mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ public static int Main (String[] args) {
617617
ss_multi_thread ();
618618
return 0;
619619
}
620+
test_invalid_argument_assembly_get_type ();
620621
return 3;
621622
}
622623

@@ -645,6 +646,10 @@ public static void local_reflect () {
645646
LocalReflectClass.RunMe ();
646647
}
647648

649+
public static void test_invalid_argument_assembly_get_type () {
650+
651+
}
652+
648653
public static void breakpoints () {
649654
/* Call these early so it is JITted by the time a breakpoint is placed on it */
650655
bp3 ();

mcs/class/Mono.Debugger.Soft/Test/dtest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5201,6 +5201,18 @@ public void InvalidPointer_GetValue () {
52015201
}
52025202
}
52035203

5204+
[Test]
5205+
public void InvalidArgumentAssemblyGetType () {
5206+
Event e = run_until ("test_invalid_argument_assembly_get_type");
5207+
var assembly = entry_point.DeclaringType.Assembly;
5208+
try {
5209+
var type = assembly.GetType ("System.Collections.Generic.Dictionary<double, float>.Main");
5210+
}
5211+
catch (CommandException ex) {
5212+
Assert.AreEqual(ex.ErrorMessage, "Unexpected assembly-qualified type \"System.Collections.Generic.Dictionary<double, float>.Main\" was provided");
5213+
}
5214+
}
5215+
52045216
[Test]
52055217
public void CheckSuspendPolicySentWhenLaunchSuspendYes () {
52065218
vm.Exit (0);

mono/mini/debugger-agent.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7269,6 +7269,7 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
72697269
ignore_case = decode_byte (p, &p, end);
72707270

72717271
if (!mono_reflection_parse_type_checked (name, &info, error)) {
7272+
buffer_add_string (buf, mono_error_get_message (error));
72727273
mono_error_cleanup (error);
72737274
g_free (name);
72747275
mono_reflection_free_type_info (&info);
@@ -7757,6 +7758,8 @@ assembly_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
77577758
case CMD_ASSEMBLY_GET_TYPE: {
77587759
ERROR_DECL (error);
77597760
char *s = decode_string (p, &p, end);
7761+
char* original_s = g_strdup_printf ("\"%s\"", s);
7762+
77607763
gboolean ignorecase = decode_byte (p, &p, end);
77617764
MonoTypeNameParse info;
77627765
MonoType *t;
@@ -7772,20 +7775,33 @@ assembly_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
77727775
mono_error_cleanup (error);
77737776
t = NULL;
77747777
} else {
7775-
if (info.assembly.name)
7776-
NOT_IMPLEMENTED;
7778+
if (info.assembly.name) {
7779+
mono_reflection_free_type_info (&info);
7780+
g_free (s);
7781+
mono_domain_set_fast (d, TRUE);
7782+
char* error_msg = g_strdup_printf ("Unexpected assembly-qualified type %s was provided", original_s);
7783+
buffer_add_string (buf, error_msg);
7784+
g_free (error_msg);
7785+
g_free (original_s);
7786+
return ERR_INVALID_ARGUMENT;
7787+
}
77777788
t = mono_reflection_get_type_checked (alc, ass->image, ass->image, &info, ignorecase, TRUE, &type_resolve, error);
77787789
if (!is_ok (error)) {
77797790
mono_error_cleanup (error); /* FIXME don't swallow the error */
77807791
mono_reflection_free_type_info (&info);
77817792
g_free (s);
7793+
mono_domain_set_fast (d, TRUE);
7794+
char* error_msg = g_strdup_printf ("Invalid type name %s", original_s);
7795+
buffer_add_string (buf, error_msg);
7796+
g_free (error_msg);
7797+
g_free (original_s);
77827798
return ERR_INVALID_ARGUMENT;
77837799
}
77847800
}
77857801
buffer_add_typeid (buf, domain, t ? mono_class_from_mono_type_internal (t) : NULL);
77867802
mono_reflection_free_type_info (&info);
77877803
g_free (s);
7788-
7804+
g_free (original_s);
77897805
mono_domain_set_fast (d, TRUE);
77907806

77917807
break;
@@ -7842,6 +7858,7 @@ assembly_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
78427858
error_init (error);
78437859
MonoClass* mono_class = mono_class_get_checked (ass->image, token, error);
78447860
if (!is_ok (error)) {
7861+
buffer_add_string (buf, mono_error_get_message (error));
78457862
mono_error_cleanup (error);
78467863
return ERR_INVALID_ARGUMENT;
78477864
}
@@ -7858,6 +7875,7 @@ assembly_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
78587875
error_init (error);
78597876
MonoMethod* mono_method = mono_get_method_checked (ass->image, token, NULL, NULL, error);
78607877
if (!is_ok (error)) {
7878+
buffer_add_string (buf, mono_error_get_message (error));
78617879
mono_error_cleanup (error);
78627880
return ERR_INVALID_ARGUMENT;
78637881
}
@@ -8710,6 +8728,7 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
87108728

87118729
header = mono_method_get_header_checked (method, error);
87128730
if (!header) {
8731+
buffer_add_string (buf, mono_error_get_message (error));
87138732
mono_error_cleanup (error); /* FIXME don't swallow the error */
87148733
return ERR_INVALID_ARGUMENT;
87158734
}
@@ -9541,7 +9560,7 @@ string_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
95419560
if (!is_ok (error)) {
95429561
if (s)
95439562
g_free (s);
9544-
9563+
buffer_add_string (buf, mono_error_get_message (error));
95459564
return ERR_INVALID_ARGUMENT;
95469565
}
95479566
buffer_add_string (buf, s);

0 commit comments

Comments
 (0)