|
2 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
3 | 3 |
|
4 | 4 | using System; |
| 5 | +using System.Collections.Concurrent; |
5 | 6 | using System.Collections.Generic; |
6 | 7 | using System.Diagnostics; |
7 | 8 | using System.Globalization; |
@@ -42,7 +43,9 @@ internal sealed class AD7DebugSession : DebugAdapterBase, IDebugPortNotify2, IDe |
42 | 43 |
|
43 | 44 | private readonly DebugEventLogger m_logger; |
44 | 45 | private readonly Dictionary<string, Dictionary<int, IDebugPendingBreakpoint2>> m_breakpoints; |
45 | | - private readonly List<IDebugCodeContext2> m_gotoCodeContexts = new List<IDebugCodeContext2>(); |
| 46 | + |
| 47 | + private readonly ConcurrentDictionary<int, IDebugCodeContext2> m_gotoCodeContexts = new ConcurrentDictionary<int, IDebugCodeContext2>(); |
| 48 | + private int m_nextContextId = 1; |
46 | 49 |
|
47 | 50 | private Dictionary<string, IDebugPendingBreakpoint2> m_functionBreakpoints; |
48 | 51 | private readonly Dictionary<int, ThreadFrameEnumInfo> m_threadFrameEnumInfos = new Dictionary<int, ThreadFrameEnumInfo>(); |
@@ -1268,15 +1271,17 @@ protected override void HandleGotoRequestAsync(IRequestResponder<GotoArguments> |
1268 | 1271 | var builder = new ErrorBuilder(() => AD7Resources.Error_UnableToSetNextStatement); |
1269 | 1272 | try |
1270 | 1273 | { |
1271 | | - var gotoTarget = m_gotoCodeContexts[responder.Arguments.TargetId]; |
1272 | | - IDebugThread2 thread = null; |
1273 | | - lock (m_threads) |
| 1274 | + if (m_gotoCodeContexts.TryGetValue(responder.Arguments.TargetId, out IDebugCodeContext2 gotoTarget)) |
1274 | 1275 | { |
1275 | | - if (!m_threads.TryGetValue(responder.Arguments.ThreadId, out thread)) |
1276 | | - throw new AD7Exception("Unknown thread id: " + responder.Arguments.ThreadId.ToString(CultureInfo.InvariantCulture)); |
| 1276 | + IDebugThread2 thread = null; |
| 1277 | + lock (m_threads) |
| 1278 | + { |
| 1279 | + if (!m_threads.TryGetValue(responder.Arguments.ThreadId, out thread)) |
| 1280 | + throw new AD7Exception("Unknown thread id: " + responder.Arguments.ThreadId.ToString(CultureInfo.InvariantCulture)); |
| 1281 | + } |
| 1282 | + BeforeContinue(); |
| 1283 | + builder.CheckHR(thread.SetNextStatement(null, gotoTarget)); |
1277 | 1284 | } |
1278 | | - BeforeContinue(); |
1279 | | - builder.CheckHR(thread.SetNextStatement(null, gotoTarget)); |
1280 | 1285 | } |
1281 | 1286 | catch (AD7Exception e) |
1282 | 1287 | { |
@@ -1321,11 +1326,16 @@ protected override void HandleGotoTargetsRequestAsync(IRequestResponder<GotoTarg |
1321 | 1326 | IDebugDocumentContext2 documentContext; |
1322 | 1327 | if (codeContext.GetDocumentContext(out documentContext) == HRConstants.S_OK) |
1323 | 1328 | { |
1324 | | - var pos = new TEXT_POSITION[1]; |
1325 | | - if (documentContext.GetStatementRange(pos, null) == HRConstants.S_OK) |
1326 | | - line = m_pathConverter.ConvertDebuggerLineToClient((int)pos[0].dwLine); |
| 1329 | + var startPos = new TEXT_POSITION[1]; |
| 1330 | + var endPos = new TEXT_POSITION[1]; |
| 1331 | + if (documentContext.GetStatementRange(startPos, endPos) == HRConstants.S_OK) |
| 1332 | + line = m_pathConverter.ConvertDebuggerLineToClient((int)startPos[0].dwLine); |
1327 | 1333 | } |
1328 | | - targets.Add(new GotoTarget(m_gotoCodeContexts.Create(codeContext), contextName, line)); |
| 1334 | + |
| 1335 | + int codeContextId = m_nextContextId++; |
| 1336 | + m_gotoCodeContexts.TryAdd(codeContextId, codeContext); |
| 1337 | + |
| 1338 | + targets.Add(new GotoTarget(codeContextId, contextName, line)); |
1329 | 1339 | } |
1330 | 1340 | } |
1331 | 1341 |
|
|
0 commit comments