Skip to content

Commit 04635cb

Browse files
authored
bypass -data-read-memory-bytes when using lldb
1 parent 8b684ad commit 04635cb

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

src/MIDebugEngine/Engine.Impl/Disassembly.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using MICore;
45
using System;
56
using System.Collections.Generic;
7+
using System.Diagnostics;
8+
using System.Globalization;
69
using System.Linq;
7-
using System.Text;
810
using System.Threading;
911
using System.Threading.Tasks;
10-
using System.Diagnostics;
11-
using MICore;
12-
using System.Globalization;
1312

1413
namespace Microsoft.MIDebugEngine
1514
{
@@ -181,9 +180,22 @@ public async Task<ulong> SeekBack(ulong address, int nInstructions)
181180
}
182181
ulong endAddress;
183182
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+
187199
if (endAddress - startAddress == 0 || address < startAddress) // bad address range, no instructions
188200
{
189201
return defaultAddr;
@@ -244,9 +256,22 @@ public async Task<ICollection<DisasmInstruction>> FetchInstructions(ulong addres
244256

245257
ulong endAddress;
246258
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+
250275
int gap = (int)(startAddress - address); // num of bytes before instructions begin
251276
if (endAddress > startAddress && nInstructions > gap)
252277
{

0 commit comments

Comments
 (0)