diff options
author | Sergio Durigan Junior <sergiodj@redhat.com> | 2017-03-22 21:54:49 -0400 |
---|---|---|
committer | Sergio Durigan Junior <sergiodj@redhat.com> | 2017-04-12 01:02:03 -0400 |
commit | 7c5ded6a00c4817d56cdf04fbc1969bc33b2a930 (patch) | |
tree | 97d62dfd88f9b04b1b8bf4bad95f03f061c63ea0 /gdb/remote.c | |
parent | ef6a5ae7bd1dd7b528f5cf368d98056603003c35 (diff) | |
download | gdb-7c5ded6a00c4817d56cdf04fbc1969bc33b2a930.zip gdb-7c5ded6a00c4817d56cdf04fbc1969bc33b2a930.tar.gz gdb-7c5ded6a00c4817d56cdf04fbc1969bc33b2a930.tar.bz2 |
C++-fy and prepare for sharing fork_inferior
As a preparation for the next patch, which will move fork_inferior
from GDB to common/ (and therefore share it with gdbserver), it is
interesting to convert a few functions to C++.
This patch touches functions related to parsing command-line arguments
to the inferior (see gdb/fork-child.c:breakup_args), the way the
arguments are stored on fork_inferior (using std::vector instead of
char **), and the code responsible for dealing with argv also on
gdbserver.
I've taken this opportunity and decided to constify a few arguments to
fork_inferior/create_inferior as well, in order to make the code
cleaner. And now, on gdbserver, we're using xstrdup everywhere and
aren't checking for memory allocation failures anymore, as requested
by Pedro:
<https://sourceware.org/ml/gdb-patches/2017-03/msg00191.html>
Message-Id: <025ebdb9-90d9-d54a-c055-57ed2406b812@redhat.com>
Pedro Alves wrote:
> On the "== NULL" check: IIUC, the old NULL check was there to
> handle strdup returning NULL due to out-of-memory.
> See NULL checks and comments further above in this function.
> Now that you're using a std::vector, that doesn't work or make
> sense any longer, since if push_back fails to allocate space for
> its internal buffer (with operator new), our operator new replacement
> (common/new-op.c) calls malloc_failure, which aborts gdbserver.
>
> Not sure it makes sense to handle out-of-memory specially in
> the gdb/rsp-facing functions nowadays (maybe git blame/log/patch
> submission for that code shows some guidelines). Maybe (or, probably)
> it's OK to stop caring about it, but then we should consistently remove
> left over code, by using xstrdup instead and remove the NULL checks.
IMO this refactoring was very good to increase the readability of the
code as well, because some parts of the argument handling were
unnecessarily confusing before.
gdb/ChangeLog:
2017-04-12 Sergio Durigan Junior <sergiodj@redhat.com>
* common/common-utils.c (free_vector_argv): New function.
* common/common-utils.h: Include <vector>.
(free_vector_argv): New prototype.
* darwin-nat.c (darwin_create_inferior): Rewrite function
prototype in order to constify "exec_file" and accept a
"std::string" for "allargs".
* fork-child.c: Include <vector>.
(breakup_args): Rewrite function, using C++.
(fork_inferior): Rewrite function header, constify "exec_file_arg"
and accept "std::string" for "allargs". Update the code to
calculate "argv" based on "allargs". Update calls to "exec_fun"
and "execvp".
* gnu-nat.c (gnu_create_inferior): Rewrite function prototype in
order to constify "exec_file" and accept a "std::string" for
"allargs".
* go32-nat.c (go32_create_inferior): Likewise.
* inf-ptrace.c (inf_ptrace_create_inferior): Likewise.
* infcmd.c (run_command_1): Constify "exec_file". Use
"std::string" for inferior arguments.
* inferior.h (fork_inferior): Update prototype.
* linux-nat.c (linux_nat_create_inferior): Rewrite function
prototype in order to constify "exec_file" and accept a
"std::string" for "allargs".
* nto-procfs.c (procfs_create_inferior): Likewise.
* procfs.c (procfs_create_inferior): Likewise.
* remote-sim.c (gdbsim_create_inferior): Likewise.
* remote.c (extended_remote_run): Update code to accept
"std::string" as argument.
(extended_remote_create_inferior): Rewrite function prototype in
order to constify "exec_file" and accept a "std::string" for
"allargs".
* rs6000-nat.c (super_create_inferior): Likewise.
(rs6000_create_inferior): Likewise.
* target.h (struct target_ops) <to_create_inferior>: Likewise.
* windows-nat.c (windows_create_inferior): Likewise.
gdb/gdbserver/ChangeLog:
2017-04-12 Sergio Durigan Junior <sergiodj@redhat.com>
* server.c: Include <vector>.
<program_argv, wrapper_argv>: Convert to std::vector.
(start_inferior): Rewrite function to use C++.
(handle_v_run): Likewise. Update code that calculates the argv
based on the vRun packet; use C++.
(captured_main): Likewise.
Diffstat (limited to 'gdb/remote.c')
-rw-r--r-- | gdb/remote.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/gdb/remote.c b/gdb/remote.c index a61469c..7c5fe87 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -9526,7 +9526,7 @@ extended_remote_disable_randomization (int val) } static int -extended_remote_run (char *args) +extended_remote_run (const std::string &args) { struct remote_state *rs = get_remote_state (); int len; @@ -9545,14 +9545,13 @@ extended_remote_run (char *args) len += 2 * bin2hex ((gdb_byte *) remote_exec_file, rs->buf + len, strlen (remote_exec_file)); - gdb_assert (args != NULL); - if (*args) + if (!args.empty ()) { struct cleanup *back_to; int i; char **argv; - argv = gdb_buildargv (args); + argv = gdb_buildargv (args.c_str ()); back_to = make_cleanup_freeargv (argv); for (i = 0; argv[i] != NULL; i++) { @@ -9597,7 +9596,8 @@ extended_remote_run (char *args) static void extended_remote_create_inferior (struct target_ops *ops, - char *exec_file, char *args, + const char *exec_file, + const std::string &args, char **env, int from_tty) { int run_worked; @@ -9622,7 +9622,7 @@ extended_remote_create_inferior (struct target_ops *ops, user requested. */ if (remote_exec_file[0]) error (_("Remote target does not support \"set remote exec-file\"")); - if (args[0]) + if (!args.empty ()) error (_("Remote target does not support \"set args\" or run <ARGS>")); /* Fall back to "R". */ |