aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectMemory.cpp
diff options
context:
space:
mode:
authorGeorgeHuyubo <113479859+GeorgeHuyubo@users.noreply.github.com>2024-05-14 14:36:17 -0700
committerGitHub <noreply@github.com>2024-05-14 14:36:17 -0700
commit5bf653ca42dceb8266a0ff70634292ccd2ad4c43 (patch)
tree985dd7c61d9d65f44195ecbcf7775c029f7eabf7 /lldb/source/Commands/CommandObjectMemory.cpp
parent536abf827b481f78a0879b02202fb9a3ffe3a908 (diff)
downloadllvm-5bf653ca42dceb8266a0ff70634292ccd2ad4c43.zip
llvm-5bf653ca42dceb8266a0ff70634292ccd2ad4c43.tar.gz
llvm-5bf653ca42dceb8266a0ff70634292ccd2ad4c43.tar.bz2
Revert "Read and store gnu build id from loaded core file" (#92181)
Reverts llvm/llvm-project#92078
Diffstat (limited to 'lldb/source/Commands/CommandObjectMemory.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectMemory.cpp61
1 files changed, 59 insertions, 2 deletions
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index 1c13484..b78a049 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -977,6 +977,35 @@ 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
@@ -1077,8 +1106,8 @@ protected:
found_location = low_addr;
bool ever_found = false;
while (count) {
- found_location = process->FindInMemory(
- found_location, high_addr, buffer.GetBytes(), buffer.GetByteSize());
+ found_location = FastSearch(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");
@@ -1115,6 +1144,34 @@ 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;