Skip to content

Commit

Permalink
Merge pull request #1274 from Unity-Technologies/unity-master-fix-119…
Browse files Browse the repository at this point in the history
…7204

[debugger] Fix NOT_IMPLEMENTED while debugging. (mono#19248)
  • Loading branch information
joncham committed Mar 24, 2020
2 parents 625a6bd + 32e3d73 commit 73c75f0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
13 changes: 11 additions & 2 deletions mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ public class ErrorHandlerEventArgs : EventArgs {
public ErrorCode ErrorCode {
get; set;
}
public string ErrorMessage {
get; set;
}
}

/*
Expand Down Expand Up @@ -751,10 +754,12 @@ public PacketReader (Connection connection, byte[] packet) {

// For reply packets
offset = 0;
ReadInt (); // length
var len = ReadInt (); // length
ReadInt (); // id
ReadByte (); // flags
ErrorCode = ReadShort ();
if (ErrorCode == (int)Mono.Debugger.Soft.ErrorCode.INVALID_ARGUMENT && len > offset)
ErrorMsg = ReadString ();
}

public CommandSet CommandSet {
Expand All @@ -769,6 +774,10 @@ public int ErrorCode {
get; set;
}

public string ErrorMsg {
get; internal set;
}

public int Offset {
get {
return offset;
Expand Down Expand Up @@ -1570,7 +1579,7 @@ PacketReader SendReceive (CommandSet command_set, int command, PacketWriter pack
LogPacket (packetId, encoded_packet, reply, command_set, command, watch);
if (r.ErrorCode != 0) {
if (ErrorHandler != null)
ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode, ErrorMessage = r.ErrorMsg});
throw new NotImplementedException ("No error handler set.");
} else {
return r;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ internal void ErrorHandler (object sender, ErrorHandlerEventArgs args) {
case ErrorCode.NO_SEQ_POINT_AT_IL_OFFSET:
throw new ArgumentException ("Cannot set breakpoint on the specified IL offset.");
default:
throw new CommandException (args.ErrorCode);
throw new CommandException (args.ErrorCode, args.ErrorMessage);
}
}

Expand Down Expand Up @@ -792,13 +792,18 @@ public void VMDisconnect (int req_id, long thread_id, string vm_uri) {

public class CommandException : Exception {

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

public ErrorCode ErrorCode {
get; set;
}

public string ErrorMessage {
get; internal set;
}
}

public class VMNotSuspendedException : InvalidOperationException
Expand Down
7 changes: 7 additions & 0 deletions mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ public static int Main (String[] args) {
if (args.Length > 0 && args [0] == "invoke-abort")
new Tests ().invoke_abort ();
new Tests ().evaluate_method ();

test_invalid_argument_assembly_get_type ();

return 3;
}

Expand All @@ -373,6 +376,10 @@ public static void local_reflect () {
LocalReflectClass.RunMe ();
}

public static void test_invalid_argument_assembly_get_type () {

}

public static void breakpoints () {
/* Call these early so it is JITted by the time a breakpoint is placed on it */
bp3 ();
Expand Down
13 changes: 13 additions & 0 deletions mcs/class/Mono.Debugger.Soft/Test/dtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4431,5 +4431,18 @@ public void InvokeRefReturnMethod () {
AssertValue (1, mirror["i"]);
AssertValue (2.0, mirror["d"]);
}

[Test]
public void InvalidArgumentAssemblyGetType () {
Event e = run_until ("test_invalid_argument_assembly_get_type");
var assembly = entry_point.DeclaringType.Assembly;
try {
var type = assembly.GetType ("System.Collections.Generic.Dictionary<double, float>.Main");
}
catch (CommandException ex) {
Assert.AreEqual(ex.ErrorMessage, "Unexpected assembly-qualified type \"System.Collections.Generic.Dictionary<double, float>.Main\" was provided");
}
}

} // class DebuggerTests
} // namespace
25 changes: 21 additions & 4 deletions mono/mini/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -9183,6 +9183,7 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
ignore_case = decode_byte (p, &p, end);

if (!mono_reflection_parse_type_checked (name, &info, &error)) {
buffer_add_string (buf, mono_error_get_message (&error));
mono_error_cleanup (&error);
g_free (name);
mono_reflection_free_type_info (&info);
Expand Down Expand Up @@ -9700,6 +9701,8 @@ assembly_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
case CMD_ASSEMBLY_GET_TYPE: {
MonoError error;
char *s = decode_string (p, &p, end);
char* original_s = g_strdup_printf ("\"%s\"", s);

gboolean ignorecase = decode_byte (p, &p, end);
MonoTypeNameParse info;
MonoType *t;
Expand All @@ -9714,20 +9717,33 @@ assembly_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
mono_error_cleanup (&error);
t = NULL;
} else {
if (info.assembly.name)
NOT_IMPLEMENTED;
if (info.assembly.name) {
mono_reflection_free_type_info (&info);
g_free (s);
mono_domain_set (d, TRUE);
char* error_msg = g_strdup_printf ("Unexpected assembly-qualified type %s was provided", original_s);
buffer_add_string (buf, error_msg);
g_free (error_msg);
g_free (original_s);
return ERR_INVALID_ARGUMENT;
}
t = mono_reflection_get_type_checked (ass->image, ass->image, &info, ignorecase, &type_resolve, &error);
if (!is_ok (&error)) {
mono_error_cleanup (&error); /* FIXME don't swallow the error */
mono_reflection_free_type_info (&info);
g_free (s);
mono_domain_set (d, TRUE);
char* error_msg = g_strdup_printf ("Invalid type name %s", original_s);
buffer_add_string (buf, error_msg);
g_free (error_msg);
g_free (original_s);
return ERR_INVALID_ARGUMENT;
}
}
buffer_add_typeid (buf, domain, t ? mono_class_from_mono_type (t) : NULL);
mono_reflection_free_type_info (&info);
g_free (s);

g_free (original_s);
mono_domain_set (d, TRUE);

break;
Expand Down Expand Up @@ -10693,6 +10709,7 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g

header = mono_method_get_header_checked (method, &error);
if (!header) {
buffer_add_string (buf, mono_error_get_message (&error));
mono_error_cleanup (&error); /* FIXME don't swallow the error */
return ERR_INVALID_ARGUMENT;
}
Expand Down Expand Up @@ -11580,7 +11597,7 @@ string_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
if (!mono_error_ok (&error)) {
if (s)
g_free (s);

buffer_add_string (buf, mono_error_get_message (&error));
return ERR_INVALID_ARGUMENT;
}

Expand Down

0 comments on commit 73c75f0

Please sign in to comment.