• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修訂d6b9b80f9483b6c1a3a018c0fcaf813ca098d8af (tree)
時間2017-09-12 07:15:10
作者Tom Tromey <tom@trom...>
CommiterTom Tromey

Log Message

Remove cleanups from findcmd.c

This removes cleanups from findcmd.c, replacing manual buffer
management with a gdb::byte_vector.

ChangeLog
2017-09-11 Tom Tromey <tom@tromey.com>

* findcmd.c (put_bits): Take a gdb::byte_vector.
(parse_find_args): Return gdb::byte_vector. "args" now const.
Remove "pattern_bufp" and "pattern_lenp" parameters. Remove
cleanups.
(find_command): Update.

Change Summary

差異

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
11 2017-09-11 Tom Tromey <tom@tromey.com>
22
3+ * findcmd.c (put_bits): Take a gdb::byte_vector.
4+ (parse_find_args): Return gdb::byte_vector. "args" now const.
5+ Remove "pattern_bufp" and "pattern_lenp" parameters. Remove
6+ cleanups.
7+ (find_command): Update.
8+
9+2017-09-11 Tom Tromey <tom@tromey.com>
10+
311 * cli/cli-script.c (class scoped_restore_hook_in): New.
412 (clear_hook_in_cleanup): Remove.
513 (execute_cmd_pre_hook, execute_cmd_post_hook): Use
--- a/gdb/findcmd.c
+++ b/gdb/findcmd.c
@@ -25,11 +25,12 @@
2525 #include "target.h"
2626 #include "cli/cli-utils.h"
2727 #include <algorithm>
28+#include "common/byte-vector.h"
2829
2930 /* Copied from bfd_put_bits. */
3031
3132 static void
32-put_bits (bfd_uint64_t data, gdb_byte *buf, int bits, bfd_boolean big_p)
33+put_bits (bfd_uint64_t data, gdb::byte_vector &buf, int bits, bfd_boolean big_p)
3334 {
3435 int i;
3536 int bytes;
@@ -37,11 +38,13 @@ put_bits (bfd_uint64_t data, gdb_byte *buf, int bits, bfd_boolean big_p)
3738 gdb_assert (bits % 8 == 0);
3839
3940 bytes = bits / 8;
41+ size_t last = buf.size ();
42+ buf.resize (last + bytes);
4043 for (i = 0; i < bytes; i++)
4144 {
4245 int index = big_p ? bytes - i - 1 : i;
4346
44- buf[index] = data & 0xff;
47+ buf[last + index] = data & 0xff;
4548 data >>= 8;
4649 }
4750 }
@@ -49,9 +52,8 @@ put_bits (bfd_uint64_t data, gdb_byte *buf, int bits, bfd_boolean big_p)
4952 /* Subroutine of find_command to simplify it.
5053 Parse the arguments of the "find" command. */
5154
52-static void
53-parse_find_args (char *args, ULONGEST *max_countp,
54- gdb_byte **pattern_bufp, ULONGEST *pattern_lenp,
55+static gdb::byte_vector
56+parse_find_args (const char *args, ULONGEST *max_countp,
5557 CORE_ADDR *start_addrp, ULONGEST *search_space_lenp,
5658 bfd_boolean big_p)
5759 {
@@ -59,27 +61,15 @@ parse_find_args (char *args, ULONGEST *max_countp,
5961 char size = '\0';
6062 ULONGEST max_count = ~(ULONGEST) 0;
6163 /* Buffer to hold the search pattern. */
62- gdb_byte *pattern_buf;
63- /* Current size of search pattern buffer.
64- We realloc space as needed. */
65-#define INITIAL_PATTERN_BUF_SIZE 100
66- ULONGEST pattern_buf_size = INITIAL_PATTERN_BUF_SIZE;
67- /* Pointer to one past the last in-use part of pattern_buf. */
68- gdb_byte *pattern_buf_end;
69- ULONGEST pattern_len;
64+ gdb::byte_vector pattern_buf;
7065 CORE_ADDR start_addr;
7166 ULONGEST search_space_len;
7267 const char *s = args;
73- struct cleanup *old_cleanups;
7468 struct value *v;
7569
7670 if (args == NULL)
7771 error (_("Missing search parameters."));
7872
79- pattern_buf = (gdb_byte *) xmalloc (pattern_buf_size);
80- pattern_buf_end = pattern_buf;
81- old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
82-
8373 /* Get search granularity and/or max count if specified.
8474 They may be specified in either order, together or separately. */
8575
@@ -131,9 +121,8 @@ parse_find_args (char *args, ULONGEST *max_countp,
131121 len = value_as_long (v);
132122 if (len == 0)
133123 {
134- do_cleanups (old_cleanups);
135124 printf_filtered (_("Empty search range.\n"));
136- return;
125+ return pattern_buf;
137126 }
138127 if (len < 0)
139128 error (_("Invalid length."));
@@ -169,53 +158,36 @@ parse_find_args (char *args, ULONGEST *max_countp,
169158 {
170159 LONGEST x;
171160 struct type *t;
172- ULONGEST pattern_buf_size_need;
173161
174162 s = skip_spaces (s);
175163
176164 v = parse_to_comma_and_eval (&s);
177165 t = value_type (v);
178166
179- /* Keep it simple and assume size == 'g' when watching for when we
180- need to grow the pattern buf. */
181- pattern_buf_size_need = (pattern_buf_end - pattern_buf
182- + std::max (TYPE_LENGTH (t),
183- (unsigned) sizeof (int64_t)));
184- if (pattern_buf_size_need > pattern_buf_size)
185- {
186- size_t current_offset = pattern_buf_end - pattern_buf;
187-
188- pattern_buf_size = pattern_buf_size_need * 2;
189- pattern_buf = (gdb_byte *) xrealloc (pattern_buf, pattern_buf_size);
190- pattern_buf_end = pattern_buf + current_offset;
191- }
192-
193167 if (size != '\0')
194168 {
195169 x = value_as_long (v);
196170 switch (size)
197171 {
198172 case 'b':
199- *pattern_buf_end++ = x;
173+ pattern_buf.push_back (x);
200174 break;
201175 case 'h':
202- put_bits (x, pattern_buf_end, 16, big_p);
203- pattern_buf_end += sizeof (int16_t);
176+ put_bits (x, pattern_buf, 16, big_p);
204177 break;
205178 case 'w':
206- put_bits (x, pattern_buf_end, 32, big_p);
207- pattern_buf_end += sizeof (int32_t);
179+ put_bits (x, pattern_buf, 32, big_p);
208180 break;
209181 case 'g':
210- put_bits (x, pattern_buf_end, 64, big_p);
211- pattern_buf_end += sizeof (int64_t);
182+ put_bits (x, pattern_buf, 64, big_p);
212183 break;
213184 }
214185 }
215186 else
216187 {
217- memcpy (pattern_buf_end, value_contents (v), TYPE_LENGTH (t));
218- pattern_buf_end += TYPE_LENGTH (t);
188+ const gdb_byte *contents = value_contents (v);
189+ pattern_buf.insert (pattern_buf.end (), contents,
190+ contents + TYPE_LENGTH (t));
219191 }
220192
221193 if (*s == ',')
@@ -223,23 +195,17 @@ parse_find_args (char *args, ULONGEST *max_countp,
223195 s = skip_spaces (s);
224196 }
225197
226- if (pattern_buf_end == pattern_buf)
198+ if (pattern_buf.empty ())
227199 error (_("Missing search pattern."));
228200
229- pattern_len = pattern_buf_end - pattern_buf;
230-
231- if (search_space_len < pattern_len)
201+ if (search_space_len < pattern_buf.size ())
232202 error (_("Search space too small to contain pattern."));
233203
234204 *max_countp = max_count;
235- *pattern_bufp = pattern_buf;
236- *pattern_lenp = pattern_len;
237205 *start_addrp = start_addr;
238206 *search_space_lenp = search_space_len;
239207
240- /* We successfully parsed the arguments, leave the freeing of PATTERN_BUF
241- to the caller now. */
242- discard_cleanups (old_cleanups);
208+ return pattern_buf;
243209 }
244210
245211 static void
@@ -250,33 +216,32 @@ find_command (char *args, int from_tty)
250216 /* Command line parameters.
251217 These are initialized to avoid uninitialized warnings from -Wall. */
252218 ULONGEST max_count = 0;
253- gdb_byte *pattern_buf = 0;
254- ULONGEST pattern_len = 0;
255219 CORE_ADDR start_addr = 0;
256220 ULONGEST search_space_len = 0;
257221 /* End of command line parameters. */
258222 unsigned int found_count;
259223 CORE_ADDR last_found_addr;
260- struct cleanup *old_cleanups;
261224
262- parse_find_args (args, &max_count, &pattern_buf, &pattern_len,
263- &start_addr, &search_space_len, big_p);
264-
265- old_cleanups = make_cleanup (free_current_contents, &pattern_buf);
225+ gdb::byte_vector pattern_buf = parse_find_args (args, &max_count,
226+ &start_addr,
227+ &search_space_len,
228+ big_p);
266229
267230 /* Perform the search. */
268231
269232 found_count = 0;
270233 last_found_addr = 0;
271234
272- while (search_space_len >= pattern_len
235+ while (search_space_len >= pattern_buf.size ()
273236 && found_count < max_count)
274237 {
275238 /* Offset from start of this iteration to the next iteration. */
276239 ULONGEST next_iter_incr;
277240 CORE_ADDR found_addr;
278241 int found = target_search_memory (start_addr, search_space_len,
279- pattern_buf, pattern_len, &found_addr);
242+ pattern_buf.data (),
243+ pattern_buf.size (),
244+ &found_addr);
280245
281246 if (found <= 0)
282247 break;
@@ -313,8 +278,6 @@ find_command (char *args, int from_tty)
313278 else
314279 printf_filtered ("%d pattern%s found.\n", found_count,
315280 found_count > 1 ? "s" : "");
316-
317- do_cleanups (old_cleanups);
318281 }
319282
320283 void