-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[LLDB] Process minidump is in memory check command #149401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jlalond
wants to merge
4
commits into
llvm:main
Choose a base branch
from
Jlalond:process-minidump-is-in-memory-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4e692b2
Add check-memory command to see if an address is in a Minidump
Jlalond ff66c23
Fix rangemap for entry or prior and add test
Jlalond 9c9866d
Formatting
Jlalond cc41f5f
Add a check for the iterator being equal to end before checking contains
Jlalond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -601,9 +601,41 @@ bool ProcessMinidump::GetProcessInfo(ProcessInstanceInfo &info) { | |
return true; | ||
} | ||
|
||
std::optional<lldb_private::MemoryRegionInfo> | ||
ProcessMinidump::TryGetMemoryRegionInCore( | ||
lldb::addr_t addr, | ||
std::optional<lldb_private::MemoryRegionInfo> &closest_prior_region, | ||
std::optional<lldb_private::MemoryRegionInfo> &closest_following_region) { | ||
// Ensure memory regions are built! | ||
BuildMemoryRegions(); | ||
|
||
// First try to find the region that contains the address (if any | ||
std::optional<minidump::Range> addr_region_maybe = | ||
m_minidump_parser->FindMemoryRange(addr); | ||
if (addr_region_maybe) { | ||
MemoryRegionInfo region = MinidumpParser::GetMemoryRegionInfo( | ||
*m_memory_regions, addr_region_maybe->start); | ||
return region; | ||
} | ||
|
||
// If we didn't find a region, try to find the closest prior and following | ||
std::optional<minidump::Range> closest_prior_range_maybe = | ||
m_minidump_parser->GetClosestPriorRegion(addr); | ||
if (closest_prior_range_maybe) | ||
closest_prior_region = MinidumpParser::GetMemoryRegionInfo( | ||
*m_memory_regions, closest_prior_range_maybe->start); | ||
|
||
std::optional<minidump::Range> closest_following_range_maybe = | ||
m_minidump_parser->GetClosestFollowingRegion(addr); | ||
if (closest_following_range_maybe) | ||
closest_following_region = MinidumpParser::GetMemoryRegionInfo( | ||
*m_memory_regions, closest_following_range_maybe->start); | ||
|
||
return std::nullopt; | ||
} | ||
|
||
// For minidumps there's no runtime generated code so we don't need JITLoader(s) | ||
// Avoiding them will also speed up minidump loading since JITLoaders normally | ||
// try to set up symbolic breakpoints, which in turn may force loading more | ||
// debug information than needed. | ||
JITLoaderList &ProcessMinidump::GetJITLoaders() { | ||
if (!m_jit_loaders_up) { | ||
|
@@ -961,6 +993,73 @@ class CommandObjectProcessMinidumpDump : public CommandObjectParsed { | |
} | ||
}; | ||
|
||
class CommandObjectProcessMinidumpCheckMemory : public CommandObjectParsed { | ||
public: | ||
CommandObjectProcessMinidumpCheckMemory(CommandInterpreter &interpreter) | ||
: CommandObjectParsed(interpreter, "process plugin check-memory", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bulbazord Hey Alex, do you have any idea on a better name than |
||
"Check if a memory address is stored in the " | ||
"Minidump, or the closest ranges.", | ||
nullptr) { | ||
CommandArgumentEntry arg1; | ||
CommandArgumentData addr_arg; | ||
addr_arg.arg_type = eArgTypeAddressOrExpression; | ||
|
||
arg1.push_back(addr_arg); | ||
m_arguments.push_back(arg1); | ||
} | ||
|
||
void DoExecute(Args &command, CommandReturnObject &result) override { | ||
const size_t argc = command.GetArgumentCount(); | ||
if (argc == 0) { | ||
result.AppendErrorWithFormat("'%s' Requires a memory address", | ||
m_cmd_name.c_str()); | ||
return; | ||
} | ||
|
||
Status error; | ||
lldb::addr_t address = OptionArgParser::ToAddress( | ||
&m_exe_ctx, command[0].ref(), LLDB_INVALID_ADDRESS, &error); | ||
|
||
if (error.Fail() || address == LLDB_INVALID_ADDRESS) { | ||
result.AppendErrorWithFormat("'%s' Is an invalid address.", | ||
command[0].c_str()); | ||
return; | ||
} | ||
|
||
ProcessMinidump *process = static_cast<ProcessMinidump *>( | ||
m_interpreter.GetExecutionContext().GetProcessPtr()); | ||
|
||
result.SetStatus(eReturnStatusSuccessFinishResult); | ||
std::optional<lldb_private::MemoryRegionInfo> closest_prior_region; | ||
std::optional<lldb_private::MemoryRegionInfo> closest_following_region; | ||
std::optional<lldb_private::MemoryRegionInfo> memory_region_maybe = | ||
process->TryGetMemoryRegionInCore(address, closest_prior_region, | ||
closest_following_region); | ||
|
||
if (memory_region_maybe) { | ||
result.AppendMessageWithFormat( | ||
"Address found in Minidump. Address located in range: %s", | ||
memory_region_maybe->Dump().c_str()); | ||
return; | ||
} | ||
|
||
lldb_private::StreamString result_stream; | ||
result_stream << "Address not found in Minidump" << "\n"; | ||
if (closest_prior_region) | ||
result_stream << "Closest prior range: " | ||
<< closest_prior_region->Dump().c_str() << "\n"; | ||
else | ||
result_stream << "No prior range found" << "\n"; | ||
if (closest_following_region) | ||
result_stream << "Closest following range: " | ||
<< closest_following_region->Dump().c_str() << "\n"; | ||
else | ||
result_stream << "No following range found" << "\n"; | ||
|
||
result.AppendMessage(result_stream.GetString()); | ||
} | ||
}; | ||
|
||
class CommandObjectMultiwordProcessMinidump : public CommandObjectMultiword { | ||
public: | ||
CommandObjectMultiwordProcessMinidump(CommandInterpreter &interpreter) | ||
|
@@ -969,6 +1068,9 @@ class CommandObjectMultiwordProcessMinidump : public CommandObjectMultiword { | |
"process plugin <subcommand> [<subcommand-options>]") { | ||
LoadSubCommand("dump", | ||
CommandObjectSP(new CommandObjectProcessMinidumpDump(interpreter))); | ||
LoadSubCommand("check-memory", | ||
CommandObjectSP(new CommandObjectProcessMinidumpCheckMemory( | ||
interpreter))); | ||
} | ||
|
||
~CommandObjectMultiwordProcessMinidump() override = default; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Check that looking up a memory region not present in the Minidump fails | ||
# even if it's in the /proc/<pid>/maps file. | ||
|
||
# RUN: yaml2obj %s -o %t | ||
# RUN: %lldb -c %t -o "process plugin check-memory 0x1000" \ | ||
# RUN: -o "process plugin check-memory 0x800" \ | ||
# RUN: -o "process plugin check-memory 0x1500" \ | ||
# RUN: -o "process plugin check-memory 0x2400" | FileCheck %s | ||
|
||
# CHECK-LABEL: (lldb) process plugin check-memory 0x1000 | ||
# CHECK-NEXT: Address found in Minidump. Address located in range: [0000000000001000-0000000000001100) r?? | ||
# CHECK-LABEL: (lldb) process plugin check-memory 0x800 | ||
# CHECK-NEXT: Address not found in Minidump | ||
# CHECK-NEXT: No prior range found | ||
# CHECK-NEXT: Closest following range: [0000000000001000-0000000000001100) r?? | ||
# CHECK-LABEL: (lldb) process plugin check-memory 0x1500 | ||
# CHECK-NEXT: Address not found in Minidump | ||
# CHECK-NEXT: Closest prior range: [0000000000001000-0000000000001100) r?? | ||
# CHECK-NEXT: Closest following range: [0000000000002000-0000000000002200) r?? | ||
# CHECK-LABEL: (lldb) process plugin check-memory 0x2400 | ||
# CHECK-NEXT: Address not found in Minidump | ||
# CHECK-NEXT: Closest prior range: [0000000000002000-0000000000002200) r?? | ||
# CHECK-NEXT: No following range found | ||
|
||
--- !minidump | ||
Streams: | ||
- Type: SystemInfo | ||
Processor Arch: AMD64 | ||
Processor Level: 6 | ||
Processor Revision: 15876 | ||
Number of Processors: 40 | ||
Platform ID: Linux | ||
CSD Version: 'Linux 3.13.0-91-generic #138-Ubuntu SMP Fri Jun 24 17:00:34 UTC 2016 x86_64' | ||
CPU: | ||
Vendor ID: GenuineIntel | ||
Version Info: 0x00000000 | ||
Feature Info: 0x00000000 | ||
- Type: LinuxProcStatus | ||
Text: | | ||
Name: test-yaml | ||
Umask: 0002 | ||
State: t (tracing stop) | ||
Pid: 8567 | ||
- Type: Memory64List | ||
Memory Ranges: | ||
- Start of Memory Range: 0x1000 | ||
Data Size: 0x100 | ||
Content : '' | ||
- Start of Memory Range: 0x2000 | ||
Data Size: 0x200 | ||
Content : '' | ||
... |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @JDevlieghere is there a better way to print MemoryRegionInfo? I must be reinventing the wheel but there isn't an existing method on MemoryRegion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, stream this into an ostream: