提交 e37b444e 编写于 作者: T Thays Grazia 提交者: ramanbs-rythmos

[debugger] Fix NOT_IMPLEMENTED while debugging. (#19248)

- Changed the behavior on debugger-agent, if we can't parse the new behavior is to return invalid_argument and not assert and stop debugging
- Changed the mono_domain_set_fast before return from assembly_commands.
- Add error message when return INVALID_ARGUMENT

Fixes #19146
上级 496a812e
......@@ -393,6 +393,9 @@ namespace Mono.Debugger.Soft
public ErrorCode ErrorCode {
get; set;
}
public string ErrorMessage {
get; set;
}
}
/*
......@@ -751,10 +754,12 @@ namespace Mono.Debugger.Soft
// 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 {
......@@ -769,6 +774,10 @@ namespace Mono.Debugger.Soft
get; set;
}
public string ErrorMsg {
get; internal set;
}
public int Offset {
get {
return offset;
......@@ -1570,7 +1579,7 @@ namespace Mono.Debugger.Soft
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;
......
......@@ -347,7 +347,7 @@ namespace Mono.Debugger.Soft
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);
}
}
......@@ -792,13 +792,18 @@ namespace Mono.Debugger.Soft
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
......
......@@ -365,6 +365,9 @@ public class Tests : TestsBase, ITest2
if (args.Length > 0 && args [0] == "invoke-abort")
new Tests ().invoke_abort ();
new Tests ().evaluate_method ();
test_invalid_argument_assembly_get_type ();
return 3;
}
......@@ -373,6 +376,10 @@ public class Tests : TestsBase, ITest2
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 ();
......
......@@ -4431,5 +4431,18 @@ public class DebuggerTests
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
......@@ -9179,6 +9179,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);
......@@ -9696,6 +9697,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;
......@@ -9710,20 +9713,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;
......@@ -10689,6 +10705,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;
}
......@@ -11576,7 +11593,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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册