|
1 | | -// Copyright (c) Microsoft. All rights reserved. |
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
2 | 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
3 | 3 |
|
| 4 | +using MICore; |
4 | 5 | using System; |
5 | 6 | using System.Collections.Generic; |
| 7 | +using System.Diagnostics; |
| 8 | +using System.Globalization; |
6 | 9 | using System.Linq; |
7 | | -using System.Text; |
8 | 10 | using System.Threading; |
9 | 11 | using System.Threading.Tasks; |
10 | | -using System.Diagnostics; |
11 | | -using MICore; |
12 | | -using System.Globalization; |
13 | 12 |
|
14 | 13 | namespace Microsoft.MIDebugEngine |
15 | 14 | { |
@@ -181,9 +180,22 @@ public async Task<ulong> SeekBack(ulong address, int nInstructions) |
181 | 180 | } |
182 | 181 | ulong endAddress; |
183 | 182 | ulong startAddress; |
184 | | - var range = await _process.FindValidMemoryRange(address, (uint)(_process.MaxInstructionSize * (nInstructions+1)), (int)(_process.MaxInstructionSize * -nInstructions)); |
185 | | - startAddress = range.Item1; |
186 | | - endAddress = range.Item2; |
| 183 | + |
| 184 | + // LLDB does not work well with '-data-read-memory-bytes' as it cannot resolve the data. |
| 185 | + // Querying the data returns following error: "LLDB unable to read entire memory block of n bytes at address 0x0...." |
| 186 | + // Since lldb doesn't need to query the memory we can use the address and its offset as start and end addresses. |
| 187 | + if (_process.LaunchOptions.DebuggerMIMode == MIMode.Lldb) |
| 188 | + { |
| 189 | + startAddress = (ulong)((long)address + (_process.MaxInstructionSize * -nInstructions)); |
| 190 | + endAddress = startAddress + (ulong)(_process.MaxInstructionSize * (nInstructions + 1)); |
| 191 | + } |
| 192 | + else |
| 193 | + { |
| 194 | + var range = await _process.FindValidMemoryRange(address, (uint)(_process.MaxInstructionSize * (nInstructions + 1)), (int)(_process.MaxInstructionSize * -nInstructions)); |
| 195 | + startAddress = range.Item1; |
| 196 | + endAddress = range.Item2; |
| 197 | + } |
| 198 | + |
187 | 199 | if (endAddress - startAddress == 0 || address < startAddress) // bad address range, no instructions |
188 | 200 | { |
189 | 201 | return defaultAddr; |
@@ -244,9 +256,22 @@ public async Task<ICollection<DisasmInstruction>> FetchInstructions(ulong addres |
244 | 256 |
|
245 | 257 | ulong endAddress; |
246 | 258 | ulong startAddress; |
247 | | - var range = await _process.FindValidMemoryRange(address, (uint)(_process.MaxInstructionSize * nInstructions), 0); |
248 | | - startAddress = range.Item1; |
249 | | - endAddress = range.Item2; |
| 259 | + |
| 260 | + // LLDB does not work well with '-data-read-memory-bytes' as it cannot resolve the data. |
| 261 | + // Querying the data returns following error: "LLDB unable to read entire memory block of n bytes at address 0x0...." |
| 262 | + // Since lldb doesn't need to query the memory we can use the address and its offset as start and end addresses. |
| 263 | + if (_process.LaunchOptions.DebuggerMIMode == MIMode.Lldb) |
| 264 | + { |
| 265 | + startAddress = address; |
| 266 | + endAddress = address + (ulong)(_process.MaxInstructionSize * nInstructions); |
| 267 | + } |
| 268 | + else |
| 269 | + { |
| 270 | + var range = await _process.FindValidMemoryRange(address, (uint)(_process.MaxInstructionSize * nInstructions), 0); |
| 271 | + startAddress = range.Item1; |
| 272 | + endAddress = range.Item2; |
| 273 | + } |
| 274 | + |
250 | 275 | int gap = (int)(startAddress - address); // num of bytes before instructions begin |
251 | 276 | if (endAddress > startAddress && nInstructions > gap) |
252 | 277 | { |
|
0 commit comments