Phil Muldoon
2011-01-07 12:41:35 UTC
These changes never made it into an FSF merge, they were folded and
re-factored into the Python inferior search memory APIs. These changes
have long been orphaned. This patch restores findcmd.c and target.h
back to the upstream equivalent.
Cheers
Phil
--
diff --git a/gdb/findcmd.c b/gdb/findcmd.c
index 4ff9177..c21c028 100644
--- a/gdb/findcmd.c
+++ b/gdb/findcmd.c
@@ -45,41 +45,6 @@ put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
}
}
-/* Allocates a buffer in *PATTERN_BUF, with a hard-coded initial size which
- will be returned in *PATTERN_BUF_SIZE. *PATTERN_BUF_END points to the same
- place as *PATTERN_BUF, indicating that the buffer is initially empty. */
-
-void
-allocate_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
- ULONGEST *pattern_buf_size)
-{
-#define INITIAL_PATTERN_BUF_SIZE 100
- *pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
- *pattern_buf = xmalloc (*pattern_buf_size);
- *pattern_buf_end = *pattern_buf;
-}
-
-/* Grows *PATTERN_BUF by a factor of two if it's not large enough to hold
- VAL_BYTES more bytes or a 64-bit value, whichever is larger.
- *PATTERN_BUF_END is updated as necessary. */
-
-void
-increase_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
- ULONGEST *pattern_buf_size, int val_bytes)
-{
- /* Keep it simple and assume size == 'g' when watching for when we
- need to grow the pattern buf. */
- if ((*pattern_buf_end - *pattern_buf + max (val_bytes, sizeof (int64_t)))
- > *pattern_buf_size)
- {
- size_t current_offset = *pattern_buf_end - *pattern_buf;
-
- *pattern_buf_size *= 2;
- *pattern_buf = xrealloc (*pattern_buf, *pattern_buf_size);
- *pattern_buf_end = *pattern_buf + current_offset;
- }
-}
-
/* Subroutine of find_command to simplify it.
Parse the arguments of the "find" command. */
@@ -96,7 +61,8 @@ parse_find_args (char *args, ULONGEST *max_countp,
char *pattern_buf;
/* Current size of search pattern buffer.
We realloc space as needed. */
- ULONGEST pattern_buf_size;
+#define INITIAL_PATTERN_BUF_SIZE 100
+ ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
/* Pointer to one past the last in-use part of pattern_buf. */
char *pattern_buf_end;
ULONGEST pattern_len;
@@ -109,7 +75,8 @@ parse_find_args (char *args, ULONGEST *max_countp,
if (args == NULL)
error (_("Missing search parameters."));
- allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
+ pattern_buf = xmalloc (pattern_buf_size);
+ pattern_buf_end = pattern_buf;
old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
/* Get search granularity and/or max count if specified.
@@ -209,9 +176,17 @@ parse_find_args (char *args, ULONGEST *max_countp,
v = parse_to_comma_and_eval (&s);
val_bytes = TYPE_LENGTH (value_type (v));
- increase_pattern_buffer (&pattern_buf, &pattern_buf_end,
- &pattern_buf_size, val_bytes);
+ /* Keep it simple and assume size == 'g' when watching for when we
+ need to grow the pattern buf. */
+ if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
+ > pattern_buf_size)
+ {
+ size_t current_offset = pattern_buf_end - pattern_buf;
+ pattern_buf_size *= 2;
+ pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
+ pattern_buf_end = pattern_buf + current_offset;
+ }
if (size != '\0')
{
@@ -266,45 +241,6 @@ parse_find_args (char *args, ULONGEST *max_countp,
discard_cleanups (old_cleanups);
}
-/* Drives target_search_memory to sweep through the specified search space,
- possibly in several iterations (with one call to this function for each
- iteration). *START_ADDR is the address where the search starts, and is
- updated to the next starting address to continue the search.
- *SEARCH_SPACE_LEN is the amount of bytes which will be searched, and is
- updated for the next iteration. PATTERN_BUF holds the pattern to be searched
- for, PATTERN_LEN is the size of the pattern in bytes. If a match is found,
- it's address is put in *FOUND_ADDR.
-
- Returns 1 if found, 0 if not found, and -1 if there was an error requiring
- halting of the search (e.g. memory read error). */
-
-int
-search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
- const char *pattern_buf, ULONGEST pattern_len,
- CORE_ADDR *found_addr)
-{
- /* Offset from start of this iteration to the next iteration. */
- ULONGEST next_iter_incr;
- int found;
-
- found = target_search_memory (*start_addr, *search_space_len,
- pattern_buf, pattern_len, found_addr);
- if (found <= 0)
- return found;
-
- /* Begin next iteration at one byte past this match. */
- next_iter_incr = (*found_addr - *start_addr) + 1;
-
- /* For robustness, we don't let search_space_len go -ve here. */
- if (*search_space_len >= next_iter_incr)
- *search_space_len -= next_iter_incr;
- else
- *search_space_len = 0;
- *start_addr += next_iter_incr;
-
- return found;
-}
-
static void
find_command (char *args, int from_tty)
{
@@ -335,11 +271,12 @@ find_command (char *args, int from_tty)
while (search_space_len >= pattern_len
&& found_count < max_count)
{
+ /* Offset from start of this iteration to the next iteration. */
+ ULONGEST next_iter_incr;
CORE_ADDR found_addr;
- int found;
+ int found = target_search_memory (start_addr, search_space_len,
+ pattern_buf, pattern_len, &found_addr);
- found = search_memory (&start_addr, &search_space_len, pattern_buf,
- pattern_len, &found_addr);
if (found <= 0)
break;
@@ -347,6 +284,16 @@ find_command (char *args, int from_tty)
printf_filtered ("\n");
++found_count;
last_found_addr = found_addr;
+
+ /* Begin next iteration at one byte past this match. */
+ next_iter_incr = (found_addr - start_addr) + 1;
+
+ /* For robustness, we don't let search_space_len go -ve here. */
+ if (search_space_len >= next_iter_incr)
+ search_space_len -= next_iter_incr;
+ else
+ search_space_len = 0;
+ start_addr += next_iter_incr;
}
/* Record and print the results. */
diff --git a/gdb/target.h b/gdb/target.h
index d4fcbfc..c34625c 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1372,18 +1372,6 @@ extern int target_search_memory (CORE_ADDR start_addr,
ULONGEST pattern_len,
CORE_ADDR *found_addrp);
-/* Utility functions which can be used by search_memory implementations. */
-
-void allocate_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
- ULONGEST *pattern_buf_size);
-
-void increase_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
- ULONGEST *pattern_buf_size, int val_bytes);
-
-int search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
- const char *pattern_buf, ULONGEST pattern_len,
- CORE_ADDR *found_addr);
-
/* Tracepoint-related operations. */
#define target_trace_init() \
re-factored into the Python inferior search memory APIs. These changes
have long been orphaned. This patch restores findcmd.c and target.h
back to the upstream equivalent.
Cheers
Phil
--
diff --git a/gdb/findcmd.c b/gdb/findcmd.c
index 4ff9177..c21c028 100644
--- a/gdb/findcmd.c
+++ b/gdb/findcmd.c
@@ -45,41 +45,6 @@ put_bits (bfd_uint64_t data, char *buf, int bits, bfd_boolean big_p)
}
}
-/* Allocates a buffer in *PATTERN_BUF, with a hard-coded initial size which
- will be returned in *PATTERN_BUF_SIZE. *PATTERN_BUF_END points to the same
- place as *PATTERN_BUF, indicating that the buffer is initially empty. */
-
-void
-allocate_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
- ULONGEST *pattern_buf_size)
-{
-#define INITIAL_PATTERN_BUF_SIZE 100
- *pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
- *pattern_buf = xmalloc (*pattern_buf_size);
- *pattern_buf_end = *pattern_buf;
-}
-
-/* Grows *PATTERN_BUF by a factor of two if it's not large enough to hold
- VAL_BYTES more bytes or a 64-bit value, whichever is larger.
- *PATTERN_BUF_END is updated as necessary. */
-
-void
-increase_pattern_buffer (char **pattern_buf, char **pattern_buf_end,
- ULONGEST *pattern_buf_size, int val_bytes)
-{
- /* Keep it simple and assume size == 'g' when watching for when we
- need to grow the pattern buf. */
- if ((*pattern_buf_end - *pattern_buf + max (val_bytes, sizeof (int64_t)))
- > *pattern_buf_size)
- {
- size_t current_offset = *pattern_buf_end - *pattern_buf;
-
- *pattern_buf_size *= 2;
- *pattern_buf = xrealloc (*pattern_buf, *pattern_buf_size);
- *pattern_buf_end = *pattern_buf + current_offset;
- }
-}
-
/* Subroutine of find_command to simplify it.
Parse the arguments of the "find" command. */
@@ -96,7 +61,8 @@ parse_find_args (char *args, ULONGEST *max_countp,
char *pattern_buf;
/* Current size of search pattern buffer.
We realloc space as needed. */
- ULONGEST pattern_buf_size;
+#define INITIAL_PATTERN_BUF_SIZE 100
+ ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
/* Pointer to one past the last in-use part of pattern_buf. */
char *pattern_buf_end;
ULONGEST pattern_len;
@@ -109,7 +75,8 @@ parse_find_args (char *args, ULONGEST *max_countp,
if (args == NULL)
error (_("Missing search parameters."));
- allocate_pattern_buffer (&pattern_buf, &pattern_buf_end, &pattern_buf_size);
+ pattern_buf = xmalloc (pattern_buf_size);
+ pattern_buf_end = pattern_buf;
old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
/* Get search granularity and/or max count if specified.
@@ -209,9 +176,17 @@ parse_find_args (char *args, ULONGEST *max_countp,
v = parse_to_comma_and_eval (&s);
val_bytes = TYPE_LENGTH (value_type (v));
- increase_pattern_buffer (&pattern_buf, &pattern_buf_end,
- &pattern_buf_size, val_bytes);
+ /* Keep it simple and assume size == 'g' when watching for when we
+ need to grow the pattern buf. */
+ if ((pattern_buf_end - pattern_buf + max (val_bytes, sizeof (int64_t)))
+ > pattern_buf_size)
+ {
+ size_t current_offset = pattern_buf_end - pattern_buf;
+ pattern_buf_size *= 2;
+ pattern_buf = xrealloc (pattern_buf, pattern_buf_size);
+ pattern_buf_end = pattern_buf + current_offset;
+ }
if (size != '\0')
{
@@ -266,45 +241,6 @@ parse_find_args (char *args, ULONGEST *max_countp,
discard_cleanups (old_cleanups);
}
-/* Drives target_search_memory to sweep through the specified search space,
- possibly in several iterations (with one call to this function for each
- iteration). *START_ADDR is the address where the search starts, and is
- updated to the next starting address to continue the search.
- *SEARCH_SPACE_LEN is the amount of bytes which will be searched, and is
- updated for the next iteration. PATTERN_BUF holds the pattern to be searched
- for, PATTERN_LEN is the size of the pattern in bytes. If a match is found,
- it's address is put in *FOUND_ADDR.
-
- Returns 1 if found, 0 if not found, and -1 if there was an error requiring
- halting of the search (e.g. memory read error). */
-
-int
-search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
- const char *pattern_buf, ULONGEST pattern_len,
- CORE_ADDR *found_addr)
-{
- /* Offset from start of this iteration to the next iteration. */
- ULONGEST next_iter_incr;
- int found;
-
- found = target_search_memory (*start_addr, *search_space_len,
- pattern_buf, pattern_len, found_addr);
- if (found <= 0)
- return found;
-
- /* Begin next iteration at one byte past this match. */
- next_iter_incr = (*found_addr - *start_addr) + 1;
-
- /* For robustness, we don't let search_space_len go -ve here. */
- if (*search_space_len >= next_iter_incr)
- *search_space_len -= next_iter_incr;
- else
- *search_space_len = 0;
- *start_addr += next_iter_incr;
-
- return found;
-}
-
static void
find_command (char *args, int from_tty)
{
@@ -335,11 +271,12 @@ find_command (char *args, int from_tty)
while (search_space_len >= pattern_len
&& found_count < max_count)
{
+ /* Offset from start of this iteration to the next iteration. */
+ ULONGEST next_iter_incr;
CORE_ADDR found_addr;
- int found;
+ int found = target_search_memory (start_addr, search_space_len,
+ pattern_buf, pattern_len, &found_addr);
- found = search_memory (&start_addr, &search_space_len, pattern_buf,
- pattern_len, &found_addr);
if (found <= 0)
break;
@@ -347,6 +284,16 @@ find_command (char *args, int from_tty)
printf_filtered ("\n");
++found_count;
last_found_addr = found_addr;
+
+ /* Begin next iteration at one byte past this match. */
+ next_iter_incr = (found_addr - start_addr) + 1;
+
+ /* For robustness, we don't let search_space_len go -ve here. */
+ if (search_space_len >= next_iter_incr)
+ search_space_len -= next_iter_incr;
+ else
+ search_space_len = 0;
+ start_addr += next_iter_incr;
}
/* Record and print the results. */
diff --git a/gdb/target.h b/gdb/target.h
index d4fcbfc..c34625c 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1372,18 +1372,6 @@ extern int target_search_memory (CORE_ADDR start_addr,
ULONGEST pattern_len,
CORE_ADDR *found_addrp);
-/* Utility functions which can be used by search_memory implementations. */
-
-void allocate_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
- ULONGEST *pattern_buf_size);
-
-void increase_pattern_buffer (char **pattern_bufp, char **pattern_buf_end,
- ULONGEST *pattern_buf_size, int val_bytes);
-
-int search_memory (CORE_ADDR *start_addr, ULONGEST *search_space_len,
- const char *pattern_buf, ULONGEST pattern_len,
- CORE_ADDR *found_addr);
-
/* Tracepoint-related operations. */
#define target_trace_init() \