Skip to content

Commit d9517b1

Browse files
committed
[WIP] memory find speedup+bugfix
1 parent 20b2c9f commit d9517b1

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

lldb/source/Target/Process.cpp

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,6 @@ class ProcessOptionValueProperties
114114
}
115115
};
116116

117-
class ProcessMemoryIterator {
118-
public:
119-
ProcessMemoryIterator(Process &process, lldb::addr_t base)
120-
: m_process(process), m_base_addr(base) {}
121-
122-
bool IsValid() { return m_is_valid; }
123-
124-
uint8_t operator[](lldb::addr_t offset) {
125-
if (!IsValid())
126-
return 0;
127-
128-
uint8_t retval = 0;
129-
Status error;
130-
if (0 == m_process.ReadMemory(m_base_addr + offset, &retval, 1, error)) {
131-
m_is_valid = false;
132-
return 0;
133-
}
134-
135-
return retval;
136-
}
137-
138-
private:
139-
Process &m_process;
140-
const lldb::addr_t m_base_addr;
141-
bool m_is_valid = true;
142-
};
143-
144117
static constexpr OptionEnumValueElement g_follow_fork_mode_values[] = {
145118
{
146119
eFollowParent,
@@ -3368,20 +3341,37 @@ lldb::addr_t Process::FindInMemory(lldb::addr_t low, lldb::addr_t high,
33683341
return LLDB_INVALID_ADDRESS;
33693342

33703343
std::vector<size_t> bad_char_heuristic(256, size);
3371-
ProcessMemoryIterator iterator(*this, low);
3372-
33733344
for (size_t idx = 0; idx < size - 1; idx++) {
33743345
decltype(bad_char_heuristic)::size_type bcu_idx = buf[idx];
33753346
bad_char_heuristic[bcu_idx] = size - idx - 1;
33763347
}
3377-
for (size_t s = 0; s <= (region_size - size);) {
3348+
3349+
llvm::SmallVector<uint8_t, 0> mem;
3350+
addr_t mem_pos = low;
3351+
const size_t read_size = std::max<size_t>(size, 0x10000);
3352+
3353+
for (addr_t s = low; s <= (high - size);) {
3354+
if (s + size >= mem.size() + mem_pos) {
3355+
mem.resize_for_overwrite(read_size);
3356+
Status error;
3357+
mem.resize(
3358+
ReadMemory(s, mem.data(), std::min(mem.size(), high - s), error));
3359+
mem_pos = s;
3360+
if (error.Fail()) {
3361+
MemoryRegionInfo info;
3362+
error = GetMemoryRegionInfo(s, info);
3363+
if (error.Fail())
3364+
return LLDB_INVALID_ADDRESS;
3365+
s = info.GetRange().GetRangeEnd();
3366+
continue;
3367+
}
3368+
}
33783369
int64_t j = size - 1;
3379-
while (j >= 0 && buf[j] == iterator[s + j])
3370+
while (j >= 0 && buf[j] == mem[s + j - mem_pos])
33803371
j--;
33813372
if (j < 0)
3382-
return low + s;
3383-
else
3384-
s += bad_char_heuristic[iterator[s + size - 1]];
3373+
return s;
3374+
s += bad_char_heuristic[mem[s + size - 1 - mem_pos]];
33853375
}
33863376

33873377
return LLDB_INVALID_ADDRESS;

0 commit comments

Comments
 (0)