27
27
28
28
namespace OpenDebugAD7
29
29
{
30
- internal class AD7DebugSession : DebugAdapterBase , IDebugPortNotify2 , IDebugEventCallback2
30
+ internal sealed class AD7DebugSession : DebugAdapterBase , IDebugPortNotify2 , IDebugEventCallback2
31
31
{
32
32
// This is a general purpose lock. Don't hold it across long operations.
33
33
private readonly object m_lock = new object ( ) ;
@@ -42,6 +42,8 @@ internal class AD7DebugSession : DebugAdapterBase, IDebugPortNotify2, IDebugEven
42
42
43
43
private readonly DebugEventLogger m_logger ;
44
44
private readonly Dictionary < string , Dictionary < int , IDebugPendingBreakpoint2 > > m_breakpoints ;
45
+ private readonly List < IDebugCodeContext2 > m_gotoCodeContexts = new List < IDebugCodeContext2 > ( ) ;
46
+
45
47
private Dictionary < string , IDebugPendingBreakpoint2 > m_functionBreakpoints ;
46
48
private readonly Dictionary < int , ThreadFrameEnumInfo > m_threadFrameEnumInfos = new Dictionary < int , ThreadFrameEnumInfo > ( ) ;
47
49
private readonly HandleCollection < IDebugStackFrame2 > m_frameHandles ;
@@ -277,6 +279,7 @@ public void BeforeContinue()
277
279
m_variableManager . Reset ( ) ;
278
280
m_frameHandles . Reset ( ) ;
279
281
m_threadFrameEnumInfos . Clear ( ) ;
282
+ m_gotoCodeContexts . Clear ( ) ;
280
283
}
281
284
}
282
285
@@ -620,7 +623,8 @@ protected override void HandleInitializeRequestAsync(IRequestResponder<Initializ
620
623
ExceptionBreakpointFilters = m_engineConfiguration . ExceptionSettings . ExceptionBreakpointFilters . Select ( item => new ExceptionBreakpointsFilter ( ) { Default = item . @default , Filter = item . filter , Label = item . label } ) . ToList ( ) ,
621
624
SupportsClipboardContext = m_engineConfiguration . ClipboardContext ,
622
625
SupportsLogPoints = true ,
623
- SupportsReadMemoryRequest = true
626
+ SupportsReadMemoryRequest = true ,
627
+ SupportsGotoTargetsRequest = true ,
624
628
} ;
625
629
626
630
responder . SetResponse ( initializeResponse ) ;
@@ -1193,6 +1197,87 @@ protected override void HandlePauseRequestAsync(IRequestResponder<PauseArguments
1193
1197
m_program . CauseBreak ( ) ;
1194
1198
responder . SetResponse ( new PauseResponse ( ) ) ;
1195
1199
}
1200
+
1201
+ protected override void HandleGotoRequestAsync ( IRequestResponder < GotoArguments > responder )
1202
+ {
1203
+ var response = new GotoResponse ( ) ;
1204
+ if ( ! m_isStopped )
1205
+ {
1206
+ responder . SetResponse ( response ) ;
1207
+ return ;
1208
+ }
1209
+
1210
+ var gotoTarget = m_gotoCodeContexts [ responder . Arguments . TargetId ] ;
1211
+ IDebugThread2 thread = null ;
1212
+ lock ( m_threads )
1213
+ {
1214
+ if ( ! m_threads . TryGetValue ( responder . Arguments . ThreadId , out thread ) )
1215
+ throw new AD7Exception ( "Could not find thread!" ) ;
1216
+ }
1217
+ BeforeContinue ( ) ;
1218
+ var builder = new ErrorBuilder ( ( ) => AD7Resources . Error_UnableToSetNextStatement ) ;
1219
+ try
1220
+ {
1221
+ builder . CheckHR ( thread . SetNextStatement ( null , gotoTarget ) ) ;
1222
+ }
1223
+ catch ( AD7Exception e )
1224
+ {
1225
+ m_isStopped = true ;
1226
+ responder . SetError ( new ProtocolException ( e . Message ) ) ;
1227
+ }
1228
+
1229
+ responder . SetResponse ( response ) ;
1230
+ }
1231
+
1232
+ protected override void HandleGotoTargetsRequestAsync ( IRequestResponder < GotoTargetsArguments , GotoTargetsResponse > responder )
1233
+ {
1234
+ var response = new GotoTargetsResponse ( ) ;
1235
+
1236
+ var source = responder . Arguments . Source ;
1237
+ // TODO: handle this for disassembly debugging
1238
+ if ( source . Path == null )
1239
+ {
1240
+ responder . SetResponse ( response ) ;
1241
+ return ;
1242
+ }
1243
+
1244
+ try
1245
+ {
1246
+ string convertedPath = m_pathConverter . ConvertClientPathToDebugger ( source . Path ) ;
1247
+ int line = m_pathConverter . ConvertClientLineToDebugger ( responder . Arguments . Line ) ;
1248
+ var docPos = new AD7DocumentPosition ( m_sessionConfig , convertedPath , line ) ;
1249
+
1250
+ var targets = new List < GotoTarget > ( ) ;
1251
+
1252
+ IEnumDebugCodeContexts2 codeContextsEnum ;
1253
+ if ( m_program . EnumCodeContexts ( docPos , out codeContextsEnum ) == HRConstants . S_OK )
1254
+ {
1255
+ var codeContexts = new IDebugCodeContext2 [ 1 ] ;
1256
+ uint nProps = 0 ;
1257
+ while ( codeContextsEnum . Next ( 1 , codeContexts , ref nProps ) == HRConstants . S_OK )
1258
+ {
1259
+ var codeContext = codeContexts [ 0 ] ;
1260
+ string contextName ;
1261
+ codeContext . GetName ( out contextName ) ;
1262
+ m_gotoCodeContexts . Add ( codeContext ) ;
1263
+ targets . Add ( new GotoTarget ( m_gotoCodeContexts . Count - 1 , contextName , responder . Arguments . Line ) ) ; // TODO: get the real line
1264
+ }
1265
+ }
1266
+
1267
+ response . Targets = targets ;
1268
+ }
1269
+ catch ( Exception e )
1270
+ {
1271
+ e = Utilities . GetInnerMost ( e ) ;
1272
+ if ( Utilities . IsCorruptingException ( e ) )
1273
+ Utilities . ReportException ( e ) ;
1274
+
1275
+ responder . SetError ( new ProtocolException ( e . Message ) ) ;
1276
+ return ;
1277
+ }
1278
+
1279
+ responder . SetResponse ( response ) ;
1280
+ }
1196
1281
1197
1282
protected override void HandleStackTraceRequestAsync ( IRequestResponder < StackTraceArguments , StackTraceResponse > responder )
1198
1283
{
0 commit comments