aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/search.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gdbsupport/search.cc')
-rw-r--r--gdbsupport/search.cc78
1 files changed, 38 insertions, 40 deletions
diff --git a/gdbsupport/search.cc b/gdbsupport/search.cc
index ace02d7..99c6e01 100644
--- a/gdbsupport/search.cc
+++ b/gdbsupport/search.cc
@@ -27,11 +27,10 @@
target side with, for example, gdbserver). */
int
-simple_search_memory
- (gdb::function_view<target_read_memory_ftype> read_memory,
- CORE_ADDR start_addr, ULONGEST search_space_len,
- const gdb_byte *pattern, ULONGEST pattern_len,
- CORE_ADDR *found_addrp)
+simple_search_memory (gdb::function_view<target_read_memory_ftype> read_memory,
+ CORE_ADDR start_addr, ULONGEST search_space_len,
+ const gdb_byte *pattern, ULONGEST pattern_len,
+ CORE_ADDR *found_addrp)
{
const unsigned chunk_size = SEARCH_CHUNK_SIZE;
/* Buffer to hold memory contents for searching. */
@@ -49,9 +48,9 @@ simple_search_memory
if (!read_memory (start_addr, search_buf.data (), search_buf_size))
{
- warning (_("Unable to access %s bytes of target "
- "memory at %s, halting search."),
- pulongest (search_buf_size), hex_string (start_addr));
+ warning (_ ("Unable to access %s bytes of target "
+ "memory at %s, halting search."),
+ pulongest (search_buf_size), hex_string (start_addr));
return -1;
}
@@ -65,53 +64,52 @@ simple_search_memory
{
gdb_byte *found_ptr;
unsigned nr_search_bytes
- = std::min (search_space_len, (ULONGEST) search_buf_size);
+ = std::min (search_space_len, (ULONGEST) search_buf_size);
found_ptr = (gdb_byte *) memmem (search_buf.data (), nr_search_bytes,
- pattern, pattern_len);
+ pattern, pattern_len);
if (found_ptr != NULL)
- {
- CORE_ADDR found_addr = start_addr + (found_ptr - search_buf.data ());
+ {
+ CORE_ADDR found_addr = start_addr + (found_ptr - search_buf.data ());
- *found_addrp = found_addr;
- return 1;
- }
+ *found_addrp = found_addr;
+ return 1;
+ }
/* Not found in this chunk, skip to next chunk. */
/* Don't let search_space_len wrap here, it's unsigned. */
if (search_space_len >= chunk_size)
- search_space_len -= chunk_size;
+ search_space_len -= chunk_size;
else
- search_space_len = 0;
+ search_space_len = 0;
if (search_space_len >= pattern_len)
- {
- unsigned keep_len = search_buf_size - chunk_size;
- CORE_ADDR read_addr = start_addr + chunk_size + keep_len;
- int nr_to_read;
+ {
+ unsigned keep_len = search_buf_size - chunk_size;
+ CORE_ADDR read_addr = start_addr + chunk_size + keep_len;
+ int nr_to_read;
- /* Copy the trailing part of the previous iteration to the front
+ /* Copy the trailing part of the previous iteration to the front
of the buffer for the next iteration. */
- gdb_assert (keep_len == pattern_len - 1);
- if (keep_len > 0)
- memcpy (&search_buf[0], &search_buf[chunk_size], keep_len);
-
- nr_to_read = std::min (search_space_len - keep_len,
- (ULONGEST) chunk_size);
-
- if (!read_memory (read_addr, &search_buf[keep_len], nr_to_read))
- {
- warning (_("Unable to access %s bytes of target "
- "memory at %s, halting search."),
- plongest (nr_to_read),
- hex_string (read_addr));
- return -1;
- }
-
- start_addr += chunk_size;
- }
+ gdb_assert (keep_len == pattern_len - 1);
+ if (keep_len > 0)
+ memcpy (&search_buf[0], &search_buf[chunk_size], keep_len);
+
+ nr_to_read
+ = std::min (search_space_len - keep_len, (ULONGEST) chunk_size);
+
+ if (!read_memory (read_addr, &search_buf[keep_len], nr_to_read))
+ {
+ warning (_ ("Unable to access %s bytes of target "
+ "memory at %s, halting search."),
+ plongest (nr_to_read), hex_string (read_addr));
+ return -1;
+ }
+
+ start_addr += chunk_size;
+ }
}
/* Not found. */