Skip to content

Commit 03850bf

Browse files
authored
Support debug on android after hot reload. (#344)
1 parent 08268b7 commit 03850bf

File tree

7 files changed

+90
-3
lines changed

7 files changed

+90
-3
lines changed

Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,9 @@ enum EventKind {
483483
KEEPALIVE = 14,
484484
USER_BREAK = 15,
485485
USER_LOG = 16,
486-
CRASH = 17
486+
CRASH = 17,
487+
ENC_UPDATE = 18,
488+
METHOD_UPDATE = 19,
487489
}
488490

489491
enum ModifierKind {
@@ -1620,6 +1622,9 @@ bool ReceivePacket () {
16201622
//EventHandler.Exception (req_id, thread_id, id, loc);
16211623
} else if (kind == EventKind.KEEPALIVE) {
16221624
events [i] = new EventInfo (etype, req_id) { };
1625+
} else if (kind == EventKind.METHOD_UPDATE) {
1626+
long id = r.ReadId ();
1627+
events[i] = new EventInfo (etype, req_id) { ThreadId = thread_id, Id = id };
16231628
} else {
16241629
throw new NotImplementedException ("Unknown event kind: " + kind);
16251630
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
namespace Mono.Debugger.Soft
3+
{
4+
public class MethodUpdateEvent : Event
5+
{
6+
long id;
7+
MethodMirror method;
8+
internal MethodUpdateEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.MethodUpdate, vm, req_id, thread_id)
9+
{
10+
this.id = id;
11+
method = vm.GetMethod (id);
12+
method.ClearCachedLocalsDebugInfo ();
13+
}
14+
15+
public MethodMirror GetMethod()
16+
{
17+
return method;
18+
}
19+
}
20+
}

Mono.Debugger.Soft/Mono.Debugger.Soft/EventRequest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,18 @@ protected void CheckMirror (VirtualMachine vm, Mirror m) {
138138
if (vm != m.VirtualMachine)
139139
throw new VMMismatchException ();
140140
}
141+
142+
//Used by EnC
143+
public void UpdateReqId (int id)
144+
{
145+
this.id = id;
146+
enabled = true;
147+
}
148+
149+
public int GetId ()
150+
{
151+
return id;
152+
}
153+
141154
}
142155
}

Mono.Debugger.Soft/Mono.Debugger.Soft/EventType.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public enum EventType {
2727
//
2828
UserLog = 16,
2929
// Fatal error handling
30-
Crash = 17,
31-
// Not part of the wire protocol
30+
Crash = 17,
31+
EnCUpdate = 18,
32+
MethodUpdate = 19,
33+
// Not part of the wire protocol
3234
VMDisconnect = 99
3335
}
3436
}

Mono.Debugger.Soft/Mono.Debugger.Soft/MethodMirror.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public class MethodMirror : Mirror
3333
internal MethodMirror (VirtualMachine vm, long id) : base (vm, id) {
3434
}
3535

36+
public long GetId() {
37+
return id;
38+
}
39+
3640
public string Name {
3741
get {
3842
if (name == null)
@@ -248,6 +252,13 @@ public ParameterInfoMirror ReturnParameter {
248252
}
249253
}
250254

255+
public void ClearCachedLocalsDebugInfo ()
256+
{
257+
locals = null;
258+
debug_info = null;
259+
locations = null;
260+
}
261+
251262
public LocalScope [] GetScopes () {
252263
vm.CheckProtocolVersion (2, 43);
253264
GetLocals ();

Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,9 @@ public void Events (SuspendPolicy suspend_policy, EventInfo[] events) {
874874
case EventType.Crash:
875875
l.Add (new CrashEvent (vm, req_id, thread_id, ei.Dump, ei.Hash));
876876
break;
877+
case EventType.MethodUpdate:
878+
l.Add (new MethodUpdateEvent (vm, req_id, thread_id, id));
879+
break;
877880
}
878881
}
879882

Mono.Debugging.Soft/SoftDebuggerSession.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ void ConnectionStarted (VirtualMachine machine)
602602
machine.EnableEvents (EventType.TypeLoad);
603603
}
604604

605+
606+
machine.EnableEvents (EventType.MethodUpdate);
607+
605608
started = true;
606609

607610
/* Wait for the VMStart event */
@@ -1347,6 +1350,17 @@ void InsertBreakpoint (Breakpoint bp, BreakInfo bi)
13471350
InsertBreakpoint (bp, bi, bi.Location.Method, bi.Location.ILOffset);
13481351
}
13491352

1353+
void UpdateBreakpoint (Breakpoint bp, BreakInfo bi)
1354+
{
1355+
foreach (var req in bi.Requests)
1356+
{
1357+
req.Key.Disable ();
1358+
var request = vm.SetBreakpoint (bi.Location.Method, bi.Location.ILOffset);
1359+
req.Key.UpdateReqId (request.GetId());
1360+
req.Key.Enabled = bp.Enabled;
1361+
}
1362+
}
1363+
13501364
void InsertBreakpoint (Breakpoint bp, BreakInfo bi, MethodMirror method, int ilOffset)
13511365
{
13521366
EventRequest request;
@@ -1858,6 +1872,9 @@ void HandleEventSet (EventSet es)
18581872
case EventType.UserLog:
18591873
HandleUserLogEvents (Array.ConvertAll (es.Events, item => (UserLogEvent)item));
18601874
break;
1875+
case EventType.MethodUpdate:
1876+
HandleMethodUpdateEvents (Array.ConvertAll (es.Events, item => (MethodUpdateEvent)item));
1877+
break;
18611878
default:
18621879
DebuggerLoggingService.LogMessage ("Ignoring unknown debugger event type {0}", type);
18631880
break;
@@ -2391,6 +2408,22 @@ void HandleUserLogEvents (UserLogEvent[] events)
23912408
OnTargetDebug (ul.Level, ul.Category, ul.Message);
23922409
}
23932410

2411+
void HandleMethodUpdateEvents(MethodUpdateEvent[] methods)
2412+
{
2413+
foreach (var method in methods)
2414+
{
2415+
foreach (var bp in breakpoints) {
2416+
if (bp.Value.Location.Method.GetId() == method.GetMethod().GetId())
2417+
{
2418+
bool dummy = false;
2419+
var l = FindLocationByMethod (bp.Value.Location.Method, bp.Value.Location.SourceFile, bp.Value.Location.LineNumber, bp.Value.Location.ColumnNumber, ref dummy);
2420+
bp.Value.Location = l;
2421+
UpdateBreakpoint ((Breakpoint)bp.Value.BreakEvent, bp.Value);
2422+
}
2423+
}
2424+
}
2425+
}
2426+
23942427
public ObjectMirror GetExceptionObject (ThreadMirror thread)
23952428
{
23962429
ObjectMirror obj;

0 commit comments

Comments
 (0)