2727
2828namespace OpenDebugAD7
2929{
30- internal class AD7DebugSession : DebugAdapterBase , IDebugPortNotify2 , IDebugEventCallback2
30+ internal sealed class AD7DebugSession : DebugAdapterBase , IDebugPortNotify2 , IDebugEventCallback2
3131 {
3232 // This is a general purpose lock. Don't hold it across long operations.
3333 private readonly object m_lock = new object ( ) ;
@@ -42,6 +42,8 @@ internal class AD7DebugSession : DebugAdapterBase, IDebugPortNotify2, IDebugEven
4242
4343 private readonly DebugEventLogger m_logger ;
4444 private readonly Dictionary < string , Dictionary < int , IDebugPendingBreakpoint2 > > m_breakpoints ;
45+ private readonly List < IDebugCodeContext2 > m_gotoCodeContexts = new List < IDebugCodeContext2 > ( ) ;
46+
4547 private Dictionary < string , IDebugPendingBreakpoint2 > m_functionBreakpoints ;
4648 private readonly Dictionary < int , ThreadFrameEnumInfo > m_threadFrameEnumInfos = new Dictionary < int , ThreadFrameEnumInfo > ( ) ;
4749 private readonly HandleCollection < IDebugStackFrame2 > m_frameHandles ;
@@ -277,6 +279,7 @@ public void BeforeContinue()
277279 m_variableManager . Reset ( ) ;
278280 m_frameHandles . Reset ( ) ;
279281 m_threadFrameEnumInfos . Clear ( ) ;
282+ m_gotoCodeContexts . Clear ( ) ;
280283 }
281284 }
282285
@@ -620,7 +623,8 @@ protected override void HandleInitializeRequestAsync(IRequestResponder<Initializ
620623 ExceptionBreakpointFilters = m_engineConfiguration . ExceptionSettings . ExceptionBreakpointFilters . Select ( item => new ExceptionBreakpointsFilter ( ) { Default = item . @default , Filter = item . filter , Label = item . label } ) . ToList ( ) ,
621624 SupportsClipboardContext = m_engineConfiguration . ClipboardContext ,
622625 SupportsLogPoints = true ,
623- SupportsReadMemoryRequest = true
626+ SupportsReadMemoryRequest = true ,
627+ SupportsGotoTargetsRequest = true ,
624628 } ;
625629
626630 responder . SetResponse ( initializeResponse ) ;
@@ -1193,6 +1197,87 @@ protected override void HandlePauseRequestAsync(IRequestResponder<PauseArguments
11931197 m_program . CauseBreak ( ) ;
11941198 responder . SetResponse ( new PauseResponse ( ) ) ;
11951199 }
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+ }
11961281
11971282 protected override void HandleStackTraceRequestAsync ( IRequestResponder < StackTraceArguments , StackTraceResponse > responder )
11981283 {
0 commit comments