This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
/
SingleSteppingEngine.cs
3808 lines (3152 loc) · 101 KB
/
SingleSteppingEngine.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Configuration;
using System.Globalization;
using System.Reflection;
using System.Diagnostics;
using System.Collections;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Remoting.Messaging;
using Mono.Debugger.Languages;
using Mono.Debugger.Languages.Mono;
using Mono.Debugger.Architectures;
namespace Mono.Debugger.Backend
{
// <summary>
// The single stepping engine is responsible for doing all the stepping
// operations.
//
// sse - short for single stepping engine.
//
// stepping operation - an operation which has been invoked by the user such
// as StepLine(), NextLine() etc.
//
// atomic operation - an operation which the sse invokes on the target
// such as stepping one machine instruction or resuming
// the target until a breakpoint is hit.
//
// step frame - an address range; the sse invokes atomic operations
// until the target hit a breakpoint, received a signal
// or stopped at an address outside this range.
//
// temporary breakpoint - a breakpoint which is automatically removed the next
// time the target stopped; it is used to step over
// method calls.
//
// source stepping op - stepping operation based on the program's source code,
// such as StepLine() or NextLine().
//
// native stepping op - stepping operation based on the machine code such as
// StepInstruction() or NextInstruction().
//
// The SingleSteppingEngine supports both synchronous and asynchronous
// operations; in synchronous mode, the engine waits until the child has stopped
// before returning. In either case, the step commands return true on success
// and false an error.
//
// Since the SingleSteppingEngine can be used from multiple threads at the same
// time, you can no longer safely use the `State' property to find out whether
// the target is stopped or not. It is safe to call all the step commands from
// multiple threads, but for obvious reasons only one command can run at a
// time. So if you attempt to issue a step command while the engine is still
// busy, the step command will return false to signal this error.
// </summary>
// <summary>
// The ThreadManager creates one SingleSteppingEngine instance for each thread
// in the target.
//
// The `SingleSteppingEngine' class is basically just responsible for whatever happens
// in the background thread: processing commands and events. Their methods
// are just meant to be called from the SingleSteppingEngine (since it's a
// protected nested class they can't actually be called from anywhere else).
//
// See the `Thread' class for the "user interface".
// </summary>
internal class SingleSteppingEngine : ThreadServant
{
// <summary>
// This is invoked after compiling a trampoline - it returns whether or
// not we should enter that trampoline.
// </summary>
internal delegate bool TrampolineHandler (Method method);
internal delegate bool CheckBreakpointHandler ();
protected SingleSteppingEngine (ThreadManager manager, ProcessServant process,
ProcessStart start)
: base (manager, process)
{
this.start = start;
Report.Debug (DebugFlags.Threads, "New SSE ({0}): {1}",
DebuggerWaitHandle.CurrentThread, this);
exception_handlers = new Hashtable ();
}
public SingleSteppingEngine (ThreadManager manager, ProcessServant process,
ProcessStart start, out CommandResult result)
: this (manager, process, start)
{
inferior = Inferior.CreateInferior (manager, process, start);
inferior.TargetOutput += new TargetOutputHandler (inferior_output_handler);
is_main = true;
if (start.PID != 0) {
this.pid = start.PID;
inferior.Attach (pid);
} else {
pid = inferior.Run (true);
}
result = new ThreadCommandResult (thread);
current_operation = new OperationStart (this, result);
}
public SingleSteppingEngine (ThreadManager manager, ProcessServant process,
Inferior inferior, int pid)
: this (manager, process, inferior.ProcessStart)
{
this.inferior = inferior;
this.pid = pid;
}
public CommandResult StartThread (bool do_attach)
{
if (do_attach)
inferior.Attach (pid);
else
inferior.InitializeThread (pid);
CommandResult result = new ThreadCommandResult (thread);
if (do_attach)
current_operation = new OperationInitialize (this, result);
else
current_operation = new OperationRun (this, result);
return result;
}
#region child event processing
// <summary>
// This is called from the SingleSteppingEngine's main event loop to give
// us the next event - `status' has no meaning to us, it's just meant to
// be passed to inferior.ProcessEvent() to get the actual event.
// </summary>
// <remarks>
// Actually, `status' is the waitpid() status code. In Linux 2.6.x, you
// can call waitpid() from any thread in the debugger, but we need to get
// the target's registers to find out whether it's a breakpoint etc.
// That's done in inferior.ProcessEvent() - which must always be called
// from the engine's thread.
// </remarks>
public void ProcessEvent (int status)
{
if (inferior == null)
return;
ProcessEvent (inferior.ProcessEvent (status));
}
public void ProcessEvent (Inferior.ChildEvent cevent)
{
Report.Debug (DebugFlags.EventLoop, "{0} received event {1} {2}",
this, cevent, stop_requested ? " - stop requested" : "");
if (killed && (cevent.Type != Inferior.ChildEventType.CHILD_EXITED)) {
Report.Debug (DebugFlags.EventLoop,
"{0} received event {1} when already killed",
this, cevent);
return;
}
if (has_thread_lock) {
Report.Debug (DebugFlags.EventLoop,
"{0} received event {1} while being thread-locked ({2})",
this, cevent, stop_event);
if (stop_event != null)
throw new InternalError ();
stop_event = cevent;
stopped = true;
return;
}
if (cevent.Type == Inferior.ChildEventType.CHILD_NOTIFICATION)
Report.Debug (DebugFlags.Notification,
"{0} received event {1} {2}",
this, cevent, (NotificationType) cevent.Argument);
else if ((cevent.Type != Inferior.ChildEventType.CHILD_EXITED) &&
(cevent.Type != Inferior.ChildEventType.CHILD_SIGNALED))
Report.Debug (DebugFlags.EventLoop,
"{0} received event {1} at {2} while running {3}",
this, cevent, inferior.CurrentFrame,
current_operation);
else
Report.Debug (DebugFlags.EventLoop,
"{0} received event {1} while running {2}",
this, cevent, current_operation);
if ((cevent.Type == Inferior.ChildEventType.CHILD_EXITED) ||
(cevent.Type == Inferior.ChildEventType.CHILD_SIGNALED)) {
Report.Debug (DebugFlags.SSE, "{0} is now dead!", this);
dead = true;
}
if (cevent.Type == Inferior.ChildEventType.CHILD_INTERRUPTED) {
stop_requested = false;
frame_changed (inferior.CurrentFrame, null);
OperationCompleted (new TargetEventArgs (TargetEventType.TargetInterrupted, 0, current_frame));
return;
}
bool resume_target;
if (manager.HandleChildEvent (this, inferior, ref cevent, out resume_target)) {
Report.Debug (DebugFlags.EventLoop,
"{0} done handling event: {1} {2} {3} {4}",
this, cevent, resume_target, stop_requested,
has_thread_lock);
if (!resume_target)
return;
if (stop_requested) {
stop_requested = false;
frame_changed (inferior.CurrentFrame, null);
OperationCompleted (new TargetEventArgs (TargetEventType.TargetStopped, 0, current_frame));
return;
}
inferior.Continue ();
return;
}
ProcessChildEvent (cevent);
}
// <summary>
// Process one event from the target. The return value specifies whether
// we started another atomic operation or whether the target is still
// stopped.
//
// This method is called each time an atomic operation is completed - or
// something unexpected happened, for instance we hit a breakpoint, received
// a signal or just died.
//
// Now, our first task is figuring out whether the atomic operation actually
// completed, ie. the target stopped normally.
// </summary>
protected void ProcessChildEvent (Inferior.ChildEvent cevent)
{
Inferior.ChildEventType message = cevent.Type;
int arg = (int) cevent.Argument;
TargetEventArgs result = null;
if ((message == Inferior.ChildEventType.THROW_EXCEPTION) ||
(message == Inferior.ChildEventType.HANDLE_EXCEPTION)) {
TargetAddress info = new TargetAddress (
inferior.AddressDomain, cevent.Data1);
TargetAddress ip = new TargetAddress (
manager.AddressDomain, cevent.Data2);
Report.Debug (DebugFlags.EventLoop,
"{0} received exception: {1} {2} {3}",
this, message, info, ip);
TargetAddress stack = inferior.ReadAddress (info);
TargetAddress exc = inferior.ReadAddress (info + inferior.TargetAddressSize);
bool stop_on_exc;
if (message == Inferior.ChildEventType.THROW_EXCEPTION)
stop_on_exc = throw_exception (stack, exc, ip);
else
stop_on_exc = handle_exception (stack, exc, ip);
Report.Debug (DebugFlags.SSE,
"{0} {1}stopping at exception ({2}:{3}:{4}) - {5} - {6}",
this, stop_on_exc ? "" : "not ", stack, exc, ip,
current_operation, temp_breakpoint_id);
if (stop_on_exc) {
inferior.WriteInteger (info + 2 * inferior.TargetAddressSize, 1);
PushOperation (new OperationException (this, ip, exc, false));
return;
}
do_continue ();
return;
}
// To step over a method call, the sse inserts a temporary
// breakpoint immediately after the call instruction and then
// resumes the target.
//
// If the target stops and we have such a temporary breakpoint, we
// need to distinguish a few cases:
//
// a) we may have received a signal
// b) we may have hit another breakpoint
// c) we actually hit the temporary breakpoint
//
// In either case, we need to remove the temporary breakpoint if
// the target is to remain stopped. Note that this piece of code
// here only deals with the temporary breakpoint, the handling of
// a signal or another breakpoint is done later.
if (temp_breakpoint_id != 0) {
if ((message == Inferior.ChildEventType.CHILD_EXITED) ||
(message == Inferior.ChildEventType.CHILD_SIGNALED))
// we can't remove the breakpoint anymore after
// the target exited, but we need to clear this id.
temp_breakpoint_id = 0;
else if ((message == Inferior.ChildEventType.CHILD_HIT_BREAKPOINT) &&
(arg == temp_breakpoint_id)) {
// we hit the temporary breakpoint; this'll always
// happen in the `correct' thread since the
// `temp_breakpoint_id' is only set in this
// SingleSteppingEngine and not in any other thread's.
inferior.RemoveBreakpoint (temp_breakpoint_id);
temp_breakpoint_id = 0;
Breakpoint bpt = lookup_breakpoint (arg);
Report.Debug (DebugFlags.SSE,
"{0} hit temporary breakpoint {1} at {2} {3}",
this, arg, inferior.CurrentFrame, bpt);
if ((bpt == null) || !bpt.Breaks (thread.ID)) {
message = Inferior.ChildEventType.CHILD_STOPPED;
arg = 0;
cevent = new Inferior.ChildEvent (
Inferior.ChildEventType.CHILD_STOPPED, 0, 0, 0);
} else {
ProcessChildEvent (cevent, result);
return;
}
}
}
if (message == Inferior.ChildEventType.CHILD_HIT_BREAKPOINT) {
// Ok, the next thing we need to check is whether this is actually "our"
// breakpoint or whether it belongs to another thread. In this case,
// `step_over_breakpoint' does everything for us and we can just continue
// execution.
bool remain_stopped = child_breakpoint (cevent, arg);
if (stop_requested) {
stop_requested = false;
frame_changed (inferior.CurrentFrame, null);
if (remain_stopped)
result = new TargetEventArgs (TargetEventType.TargetHitBreakpoint, arg, current_frame);
else
result = new TargetEventArgs (TargetEventType.TargetStopped, 0, current_frame);
} else if (!remain_stopped) {
do_continue ();
return;
}
}
switch (message) {
case Inferior.ChildEventType.CHILD_STOPPED:
if (stop_requested || (arg != 0)) {
stop_requested = false;
frame_changed (inferior.CurrentFrame, null);
result = new TargetEventArgs (
TargetEventType.TargetStopped, arg,
current_frame);
}
break;
case Inferior.ChildEventType.UNHANDLED_EXCEPTION: {
TargetAddress exc = new TargetAddress (
manager.AddressDomain, cevent.Data1);
TargetAddress ip = new TargetAddress (
manager.AddressDomain, cevent.Data2);
PushOperation (new OperationException (this, ip, exc, true));
return;
}
case Inferior.ChildEventType.CHILD_HIT_BREAKPOINT:
break;
case Inferior.ChildEventType.CHILD_SIGNALED:
if (killed)
result = new TargetEventArgs (TargetEventType.TargetExited, 0);
else
result = new TargetEventArgs (TargetEventType.TargetSignaled, arg);
break;
case Inferior.ChildEventType.CHILD_EXITED:
result = new TargetEventArgs (TargetEventType.TargetExited, arg);
break;
case Inferior.ChildEventType.CHILD_CALLBACK_COMPLETED:
frame_changed (inferior.CurrentFrame, null);
result = new TargetEventArgs (
TargetEventType.TargetStopped, 0,
current_frame);
break;
}
ProcessChildEvent (cevent, result);
}
protected void ProcessChildEvent (Inferior.ChildEvent cevent, TargetEventArgs result)
{
Inferior.ChildEventType message = cevent.Type;
int arg = (int) cevent.Argument;
send_result:
// If `result' is not null, then the target stopped abnormally.
if (result != null) {
if (is_main && !reached_main &&
(cevent.Type != Inferior.ChildEventType.CHILD_EXITED) &&
(cevent.Type != Inferior.ChildEventType.CHILD_SIGNALED)) {
reached_main = true;
if (!process.IsManaged)
inferior.InitializeModules ();
}
// Ok, inform the user that we stopped.
OperationCompleted (result);
return;
}
//
// Sometimes, we need to do just one atomic operation - in all
// other cases, `current_operation' is the current stepping
// operation.
//
// ProcessEvent() will either start another atomic operation
// (and return false) or tell us the stepping operation is
// completed by returning true.
//
if (current_operation != null) {
bool send_result;
if (!current_operation.ProcessEvent (cevent, out result, out send_result))
return;
if (result != null)
goto send_result;
if (!send_result) {
OperationCompleted (null);
return;
}
}
//
// Ok, the target stopped normally. Now we need to compute the
// new stack frame and then send the result to our caller.
//
TargetAddress frame = inferior.CurrentFrame;
//
// We're done with our stepping operation, but first we need to
// compute the new StackFrame. While doing this, `frame_changed'
// may discover that we need to do another stepping operation
// before telling the user that we're finished. This is to avoid
// that we stop in things like a method's prologue or epilogue
// code. If that happens, we just continue stepping until we reach
// the first actual source line in the method.
//
Operation new_operation = frame_changed (frame, current_operation);
if (new_operation != null) {
Report.Debug (DebugFlags.SSE,
"{0} frame changed at {1} => new operation {2}",
this, frame, new_operation, message);
if (message == Inferior.ChildEventType.CHILD_HIT_BREAKPOINT)
new_operation.PendingBreakpoint = arg;
ProcessOperation (new_operation);
return;
}
//
// Now we're really finished.
//
int pending_bpt = -1;
if (message == Inferior.ChildEventType.CHILD_HIT_BREAKPOINT)
pending_bpt = arg;
else if (current_operation != null)
pending_bpt = current_operation.PendingBreakpoint;
if (pending_bpt >= 0) {
Breakpoint bpt = lookup_breakpoint (pending_bpt);
if ((bpt != null) && bpt.Breaks (thread.ID) && !bpt.HideFromUser) {
result = new TargetEventArgs (
TargetEventType.TargetHitBreakpoint, bpt.Index,
current_frame);
goto send_result;
}
}
result = new TargetEventArgs (TargetEventType.TargetStopped, 0, current_frame);
goto send_result;
}
#endregion
void OperationCompleted (TargetEventArgs result)
{
lock (this) {
remove_temporary_breakpoint ();
engine_stopped = true;
last_target_event = result;
Report.Debug (DebugFlags.EventLoop, "{0} completed operation {1}: {2}",
this, current_operation, result);
if (result != null)
manager.Debugger.SendTargetEvent (this, result);
if (current_operation != null) {
Report.Debug (DebugFlags.EventLoop, "{0} setting completed: {1}",
this, current_operation.Result);
current_operation.Result.Completed ();
current_operation = null;
}
}
}
internal void OnManagedThreadCreated (TargetAddress end_stack_address)
{
this.end_stack_address = end_stack_address;
}
internal void SetTID (long tid)
{
this.tid = tid;
}
internal void SetManagedThreadData (TargetAddress lmf_address,
TargetAddress extended_notifications_addr)
{
this.lmf_address = lmf_address;
this.extended_notifications_addr = extended_notifications_addr;
}
internal void OnManagedThreadExited ()
{
this.end_stack_address = TargetAddress.Null;
}
internal void OnThreadExited (Inferior.ChildEvent cevent)
{
TargetEventArgs result;
int arg = (int) cevent.Argument;
if (killed)
result = new TargetEventArgs (TargetEventType.TargetExited, 0);
else if (cevent.Type == Inferior.ChildEventType.CHILD_SIGNALED)
result = new TargetEventArgs (TargetEventType.TargetSignaled, arg);
else
result = new TargetEventArgs (TargetEventType.TargetExited, arg);
temp_breakpoint_id = 0;
OperationCompleted (result);
process.OnThreadExitedEvent (this);
Dispose ();
}
Breakpoint lookup_breakpoint (int index)
{
BreakpointHandle handle = process.BreakpointManager.LookupBreakpoint (index);
if (handle == null)
return null;
return handle.Breakpoint;
}
void set_registers (Registers registers)
{
if (!registers.FromCurrentFrame)
throw new InvalidOperationException ();
this.registers = registers;
inferior.SetRegisters (registers);
}
// <summary>
// Start a new stepping operation.
//
// All stepping operations are done asynchronously.
//
// The inferior basically just knows two kinds of stepping operations:
// there is do_continue() to continue execution (until a breakpoint is
// hit or the target receives a signal or exits) and there is do_step_native()
// to single-step one machine instruction. There's also a version of
// do_continue() which takes an address - it inserts a temporary breakpoint
// on that address and calls do_continue().
//
// Let's call these "atomic operations" while a "stepping operation" is
// something like stepping until the next source line. We normally need to
// do several atomic operations for each stepping operation.
//
// We start a new stepping operation here, but what we actually do is
// starting an atomic operation on the target. Note that we just start it,
// but don't wait until is completed. Once the target is running, we go
// back to the main event loop and wait for it (or another thread) to stop
// (or to get another command from the user).
// </summary>
void StartOperation ()
{
lock (this) {
if (!engine_stopped || (has_thread_lock && (pending_operation != null))) {
Report.Debug (DebugFlags.Wait,
"{0} not stopped", this);
throw new TargetException (TargetError.NotStopped);
}
engine_stopped = false;
last_target_event = null;
}
}
object SendCommand (TargetAccessDelegate target)
{
if (inferior == null)
throw new TargetException (TargetError.NoTarget);
if (ThreadManager.InBackgroundThread)
return target (thread, null);
else
return manager.SendCommand (this, target, null);
}
CommandResult StartOperation (Operation operation)
{
StartOperation ();
return (CommandResult) SendCommand (delegate {
return ProcessOperation (operation);
});
}
CommandResult ProcessOperation (Operation operation)
{
stop_requested = false;
if (has_thread_lock) {
Report.Debug (DebugFlags.SSE,
"{0} starting {1} while being thread-locked",
this, operation);
pending_operation = operation;
return operation.Result;
} else
Report.Debug (DebugFlags.SSE,
"{0} starting {1}", this, operation);
current_operation = operation;
ExecuteOperation (operation);
return operation.Result;
}
void PushOperation (Operation operation)
{
current_operation.PushOperation (operation);
ExecuteOperation (operation);
}
void ExecuteOperation (Operation operation)
{
try {
check_inferior ();
operation.Execute ();
} catch (Exception ex) {
Report.Debug (DebugFlags.SSE, "{0} caught exception while " +
"processing operation {1}: {2}", this, operation, ex);
operation.Result.Result = ex;
OperationCompleted (null);
}
}
public override TargetEventArgs LastTargetEvent {
get { return last_target_event; }
}
public override Method Lookup (TargetAddress address)
{
process.UpdateSymbolTable (inferior);
Method method = process.SymbolTableManager.Lookup (address);
Report.Debug (DebugFlags.JitSymtab, "{0} lookup {1}: {2}",
this, address, method);
return method;
}
public override Symbol SimpleLookup (TargetAddress address, bool exact_match)
{
return process.SymbolTableManager.SimpleLookup (address, exact_match);
}
#region public properties
internal Inferior Inferior {
get { return inferior; }
}
internal override Architecture Architecture {
get { return inferior.Architecture; }
}
public Thread Thread {
get { return thread; }
}
public override int PID {
get { return pid; }
}
public override long TID {
get { return tid; }
}
public override bool IsAlive {
get { return !dead && !killed && (inferior != null); }
}
public override TargetAddress LMFAddress {
get { return lmf_address; }
}
public override bool CanRun {
get { return true; }
}
public override bool CanStep {
get { return true; }
}
public override bool IsStopped {
get { return engine_stopped; }
}
internal override ProcessServant ProcessServant {
get { return process; }
}
internal override ThreadManager ThreadManager {
get { return manager; }
}
public override Backtrace CurrentBacktrace {
get { return current_backtrace; }
}
public override StackFrame CurrentFrame {
get { return current_frame; }
}
public override Method CurrentMethod {
get { return current_method; }
}
public override TargetAddress CurrentFrameAddress {
get { return inferior.CurrentFrame; }
}
protected MonoDebuggerInfo MonoDebuggerInfo {
get { return process.MonoManager.MonoDebuggerInfo; }
}
public override TargetState State {
get {
if (inferior == null)
return TargetState.NoTarget;
else
return inferior.State;
}
}
#endregion
protected TargetAddress EndStackAddress {
get { return end_stack_address; }
}
public override TargetMemoryInfo TargetMemoryInfo {
get {
check_inferior ();
return inferior.TargetMemoryInfo;
}
}
public override TargetMemoryArea[] GetMemoryMaps ()
{
check_inferior ();
return inferior.GetMemoryMaps ();
}
public override void Kill ()
{
killed = true;
SendCommand (delegate {
inferior.Kill ();
return null;
});
}
internal override object DoTargetAccess (TargetAccessHandler func)
{
return SendCommand (delegate {
return func (inferior);
});
}
public override void Detach ()
{
SendCommand (delegate {
if (!engine_stopped) {
Report.Debug (DebugFlags.Wait,
"{0} not stopped", this);
throw new TargetException (TargetError.NotStopped);
}
process.AcquireGlobalThreadLock (this);
process.BreakpointManager.RemoveAllBreakpoints (inferior);
if (process.MonoManager != null)
StartOperation (new OperationDetach (this));
else
DoDetach ();
return null;
});
}
protected void DoDetach ()
{
foreach (ThreadServant servant in process.ThreadServants)
servant.DetachThread ();
}
internal override void DetachThread ()
{
if (inferior != null) {
inferior.Detach ();
inferior.Dispose ();
inferior = null;
}
OperationCompleted (new TargetEventArgs (TargetEventType.TargetExited, 0));
process.OnThreadExitedEvent (this);
Dispose ();
}
public override void Stop ()
{
lock (this) {
Report.Debug (DebugFlags.EventLoop, "{0} interrupt: {1} {2}",
this, engine_stopped, current_operation);
if (engine_stopped || stop_requested)
return;
stop_requested = true;
bool stopped = inferior.Stop ();
Report.Debug (DebugFlags.EventLoop, "{0} interrupt #1: {1}",
this, stopped);
if (current_operation is OperationStepOverBreakpoint) {
int index = ((OperationStepOverBreakpoint) current_operation).Index;
Report.Debug (DebugFlags.SSE,
"{0} stepped over breakpoint {1}: {2}",
this, index, inferior.CurrentFrame);
inferior.EnableBreakpoint (index);
process.ReleaseGlobalThreadLock (this);
}
if (!stopped) {
// We're already stopped, so just consider the
// current operation as finished.
engine_stopped = true;
stop_requested = false;
frame_changed (inferior.CurrentFrame, null);
TargetEventArgs args = new TargetEventArgs (
TargetEventType.FrameChanged, current_frame);
OperationCompleted (args);
}
}
}
protected void check_inferior ()
{
if (inferior == null)
throw new TargetException (TargetError.NoTarget);
}
// <summary>
// A breakpoint has been hit; now the sse needs to find out what do do:
// either ignore the breakpoint and continue or keep the target stopped
// and send out the notification.
//
// If @index is zero, we hit an "unknown" breakpoint - ie. a
// breakpoint which we did not create. Normally, this means that there
// is a breakpoint instruction (such as G_BREAKPOINT ()) in the code.
// Such unknown breakpoints are handled by the Debugger; one of
// the language backends may recognize the breakpoint's address, for
// instance if this is the JIT's breakpoint trampoline.
//
// Returns true if the target should remain stopped and false to
// continue stepping.
//
// If we can't find a handler for the breakpoint, the default is to stop
// the target and let the user decide what to do.
// </summary>
bool child_breakpoint (Inferior.ChildEvent cevent, int index)
{
// The inferior knows about breakpoints from all threads, so if this is
// zero, then no other thread has set this breakpoint.
if (index == 0)
return true;
Breakpoint bpt = lookup_breakpoint (index);
if ((bpt == null) || !bpt.Breaks (thread.ID))
return false;
if (!process.BreakpointManager.IsBreakpointEnabled (index))
return false;
bool remain_stopped;
if (bpt.BreakpointHandler (inferior, out remain_stopped))
return remain_stopped;
TargetAddress address = inferior.CurrentFrame;
return bpt.CheckBreakpointHit (thread, address);
}
bool step_over_breakpoint (bool singlestep, TargetAddress until)
{
int index;
bool is_enabled;
process.BreakpointManager.LookupBreakpoint (
inferior.CurrentFrame, out index, out is_enabled);
if ((index == 0) || !is_enabled)
return false;
Report.Debug (DebugFlags.SSE,
"{0} stepping over breakpoint {1} at {2} until {3}",
this, index, inferior.CurrentFrame, until);
Instruction instruction = inferior.Architecture.ReadInstruction (
inferior, inferior.CurrentFrame);
if ((instruction == null) || !instruction.HasInstructionSize ||
!process.CanExecuteCode) {
PushOperation (new OperationStepOverBreakpoint (this, index, until));
return true;
}
if (instruction.InterpretInstruction (inferior)) {
if (!singlestep)
return false;
byte[] nop_insn = Architecture.Opcodes.GenerateNopInstruction ();
inferior.ExecuteInstruction (nop_insn, false);
return true;
}
if (instruction.IsIpRelative) {
PushOperation (new OperationStepOverBreakpoint (this, index, until));
return true;
}
PushOperation (new OperationExecuteInstruction (this, instruction));
return true;
}
void enable_extended_notification (NotificationType type)
{
long notifications = inferior.ReadLongInteger (extended_notifications_addr);
notifications |= (long) type;
inferior.WriteLongInteger (extended_notifications_addr, notifications);
}
void disable_extended_notification (NotificationType type)
{
long notifications = inferior.ReadLongInteger (extended_notifications_addr);
notifications &= ~(long) type;
inferior.WriteLongInteger (extended_notifications_addr, notifications);
}
bool throw_exception (TargetAddress stack, TargetAddress exc, TargetAddress ip)
{
Report.Debug (DebugFlags.SSE,
"{0} throwing exception {1} at {2} while running {3}", this, exc, ip,
current_operation);
if ((current_operation != null) && !current_operation.StartFrame.IsNull &&
current_operation.StartFrame == ip)
return false;
if (current_operation is OperationRuntimeInvoke)
return false;
foreach (ExceptionCatchPoint handle in exception_handlers.Values) {
Report.Debug (DebugFlags.SSE,
"{0} invoking exception handler {1} for {0}",
this, handle.Name, exc);
if (!handle.CheckException (thread, exc))
continue;
Report.Debug (DebugFlags.SSE,
"{0} stopped on exception {1} at {2}", this, exc, ip);
return true;
}
return false;
}
bool handle_exception (TargetAddress stack, TargetAddress exc, TargetAddress ip)
{