aboutsummaryrefslogtreecommitdiff
path: root/gdb/symfile.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-02-22 16:31:15 -0700
committerTom Tromey <tom@tromey.com>2018-03-13 17:41:12 -0600
commitb577b6af8e7f4cc53e73ee01188d1700fb8d3b82 (patch)
treee0c9db0a28e74b5b6e1f8153345e43b451a68928 /gdb/symfile.c
parente45ad1239d7d8591d5e80d8cbba7d404c6c3640f (diff)
downloadgdb-b577b6af8e7f4cc53e73ee01188d1700fb8d3b82.zip
gdb-b577b6af8e7f4cc53e73ee01188d1700fb8d3b82.tar.gz
gdb-b577b6af8e7f4cc53e73ee01188d1700fb8d3b82.tar.bz2
Remove two cleanups using std::string
This patches removes cleanups from a couple of spots by using std::string rather than manual memory management. Regression tested by the buildbot, though note that I don't believe the buildbot actually exercises the machoread code. gdb/ChangeLog 2018-03-13 Tom Tromey <tom@tromey.com> * machoread.c (macho_check_dsym): Change filenamep to a std::string*. (macho_symfile_read): Update. * symfile.c (load_command): Use std::string.
Diffstat (limited to 'gdb/symfile.c')
-rw-r--r--gdb/symfile.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 58747d5..f714845 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1789,8 +1789,6 @@ find_sym_fns (bfd *abfd)
static void
load_command (const char *arg, int from_tty)
{
- struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
-
dont_repeat ();
/* The user might be reloading because the binary has changed. Take
@@ -1798,40 +1796,28 @@ load_command (const char *arg, int from_tty)
reopen_exec_file ();
reread_symbols ();
+ std::string temp;
if (arg == NULL)
{
- const char *parg;
- int count = 0;
+ const char *parg, *prev;
- parg = arg = get_exec_file (1);
+ arg = get_exec_file (1);
- /* Count how many \ " ' tab space there are in the name. */
+ /* We may need to quote this string so buildargv can pull it
+ apart. */
+ prev = parg = arg;
while ((parg = strpbrk (parg, "\\\"'\t ")))
{
- parg++;
- count++;
+ temp.append (prev, parg - prev);
+ prev = parg++;
+ temp.push_back ('\\');
}
-
- if (count)
+ /* If we have not copied anything yet, then we didn't see a
+ character to quote, and we can just leave ARG unchanged. */
+ if (!temp.empty ())
{
- /* We need to quote this string so buildargv can pull it apart. */
- char *temp = (char *) xmalloc (strlen (arg) + count + 1 );
- char *ptemp = temp;
- const char *prev;
-
- make_cleanup (xfree, temp);
-
- prev = parg = arg;
- while ((parg = strpbrk (parg, "\\\"'\t ")))
- {
- strncpy (ptemp, prev, parg - prev);
- ptemp += parg - prev;
- prev = parg++;
- *ptemp++ = '\\';
- }
- strcpy (ptemp, prev);
-
- arg = temp;
+ temp.append (prev);
+ arg = temp.c_str ();
}
}
@@ -1840,8 +1826,6 @@ load_command (const char *arg, int from_tty)
/* After re-loading the executable, we don't really know which
overlays are mapped any more. */
overlay_cache_invalid = 1;
-
- do_cleanups (cleanup);
}
/* This version of "load" should be usable for any target. Currently