aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectMemory.cpp
diff options
context:
space:
mode:
authorGeorgeHuyubo <113479859+GeorgeHuyubo@users.noreply.github.com>2024-05-14 14:35:35 -0700
committerGitHub <noreply@github.com>2024-05-14 14:35:35 -0700
commit536abf827b481f78a0879b02202fb9a3ffe3a908 (patch)
tree3c72d07e93c0b7d15e8a2a6aa7b5a3a9bc729c4d /lldb/source/Commands/CommandObjectMemory.cpp
parent67beebfcb9a267cc1e443aa4d3788adbfcf02639 (diff)
downloadllvm-536abf827b481f78a0879b02202fb9a3ffe3a908.zip
llvm-536abf827b481f78a0879b02202fb9a3ffe3a908.tar.gz
llvm-536abf827b481f78a0879b02202fb9a3ffe3a908.tar.bz2
Read and store gnu build id from loaded core file (#92078)
As we have debuginfod as symbol locator available in lldb now, we want to make full use of it. In case of post mortem debugging, we don't always have the main executable available. However, the .note.gnu.build-id of the main executable(some other modules too), should be available in the core file, as those binaries are loaded in memory and dumped in the core file. We try to iterate through the NT_FILE entries, read and store the gnu build id if possible. This will be very useful as this id is the unique key which is needed for querying the debuginfod server. Test: Build and run lldb. Breakpoint set to https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/SymbolLocator/Debuginfod/SymbolLocatorDebuginfod.cpp#L147 Verified after this commit, module_uuid is the correct gnu build id of the main executable which caused the crash(first in the NT_FILE entry)
Diffstat (limited to 'lldb/source/Commands/CommandObjectMemory.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectMemory.cpp61
1 files changed, 2 insertions, 59 deletions
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index b78a049..1c13484 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -977,35 +977,6 @@ public:
Options *GetOptions() override { return &m_option_group; }
protected:
- class ProcessMemoryIterator {
- public:
- ProcessMemoryIterator(ProcessSP process_sp, lldb::addr_t base)
- : m_process_sp(process_sp), m_base_addr(base) {
- lldbassert(process_sp.get() != nullptr);
- }
-
- bool IsValid() { return m_is_valid; }
-
- uint8_t operator[](lldb::addr_t offset) {
- if (!IsValid())
- return 0;
-
- uint8_t retval = 0;
- Status error;
- if (0 ==
- m_process_sp->ReadMemory(m_base_addr + offset, &retval, 1, error)) {
- m_is_valid = false;
- return 0;
- }
-
- return retval;
- }
-
- private:
- ProcessSP m_process_sp;
- lldb::addr_t m_base_addr;
- bool m_is_valid = true;
- };
void DoExecute(Args &command, CommandReturnObject &result) override {
// No need to check "process" for validity as eCommandRequiresProcess
// ensures it is valid
@@ -1106,8 +1077,8 @@ protected:
found_location = low_addr;
bool ever_found = false;
while (count) {
- found_location = FastSearch(found_location, high_addr, buffer.GetBytes(),
- buffer.GetByteSize());
+ found_location = process->FindInMemory(
+ found_location, high_addr, buffer.GetBytes(), buffer.GetByteSize());
if (found_location == LLDB_INVALID_ADDRESS) {
if (!ever_found) {
result.AppendMessage("data not found within the range.\n");
@@ -1144,34 +1115,6 @@ protected:
result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
}
- lldb::addr_t FastSearch(lldb::addr_t low, lldb::addr_t high, uint8_t *buffer,
- size_t buffer_size) {
- const size_t region_size = high - low;
-
- if (region_size < buffer_size)
- return LLDB_INVALID_ADDRESS;
-
- std::vector<size_t> bad_char_heuristic(256, buffer_size);
- ProcessSP process_sp = m_exe_ctx.GetProcessSP();
- ProcessMemoryIterator iterator(process_sp, low);
-
- for (size_t idx = 0; idx < buffer_size - 1; idx++) {
- decltype(bad_char_heuristic)::size_type bcu_idx = buffer[idx];
- bad_char_heuristic[bcu_idx] = buffer_size - idx - 1;
- }
- for (size_t s = 0; s <= (region_size - buffer_size);) {
- int64_t j = buffer_size - 1;
- while (j >= 0 && buffer[j] == iterator[s + j])
- j--;
- if (j < 0)
- return low + s;
- else
- s += bad_char_heuristic[iterator[s + buffer_size - 1]];
- }
-
- return LLDB_INVALID_ADDRESS;
- }
-
OptionGroupOptions m_option_group;
OptionGroupFindMemory m_memory_options;
OptionGroupMemoryTag m_memory_tag_options;