diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 50ce2b44927..65268a6ee6c 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -974,7 +974,7 @@ linux_ptrace_fun () int linux_process_target::create_inferior (const char *program, - const std::vector &program_args) + const std::string &program_args) { client_state &cs = get_client_state (); struct lwp_info *new_lwp; @@ -984,10 +984,9 @@ linux_process_target::create_inferior (const char *program, { maybe_disable_address_space_randomization restore_personality (cs.disable_randomization); - std::string str_program_args = construct_inferior_arguments (program_args); pid = fork_inferior (program, - str_program_args.c_str (), + program_args.c_str (), get_environ ()->envp (), linux_ptrace_fun, NULL, NULL, NULL, NULL); } diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h index 5be00b8c98c..75af38d898f 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -141,7 +141,7 @@ class linux_process_target : public process_stratum_target public: int create_inferior (const char *program, - const std::vector &program_args) override; + const std::string &program_args) override; void post_create_inferior () override; diff --git a/gdbserver/netbsd-low.cc b/gdbserver/netbsd-low.cc index 04e103563e7..9e7314b02a9 100644 --- a/gdbserver/netbsd-low.cc +++ b/gdbserver/netbsd-low.cc @@ -78,11 +78,9 @@ netbsd_ptrace_fun () int netbsd_process_target::create_inferior (const char *program, - const std::vector &program_args) + const std::string &program_args) { - std::string str_program_args = construct_inferior_arguments (program_args); - - pid_t pid = fork_inferior (program, str_program_args.c_str (), + pid_t pid = fork_inferior (program, program_args.c_str (), get_environ ()->envp (), netbsd_ptrace_fun, nullptr, nullptr, nullptr, nullptr); diff --git a/gdbserver/netbsd-low.h b/gdbserver/netbsd-low.h index 53200ddffc4..aef1ce40cb9 100644 --- a/gdbserver/netbsd-low.h +++ b/gdbserver/netbsd-low.h @@ -42,7 +42,7 @@ class netbsd_process_target : public process_stratum_target public: int create_inferior (const char *program, - const std::vector &program_args) override; + const std::string &program_args) override; void post_create_inferior () override; diff --git a/gdbserver/server.cc b/gdbserver/server.cc index bc591599b02..c1b18cc947e 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -121,7 +121,11 @@ private: /* The program name, adjusted if needed. */ std::string m_path; } program_path; -static std::vector program_args; + +/* All program arguments are merged into a single string. */ + +static std::string program_args; + static std::string wrapper_argv; /* The PID of the originally created or attached inferior. Used to @@ -3458,9 +3462,8 @@ handle_v_run (char *own_buf) else program_path.set (new_program_name.get ()); - /* Free the old argv and install the new one. */ - free_vector_argv (program_args); - program_args = new_argv; + program_args = construct_inferior_arguments (new_argv); + free_vector_argv (new_argv); try { @@ -4346,12 +4349,11 @@ captured_main (int argc, char *argv[]) if (pid == 0 && *next_arg != NULL) { - int i, n; - - n = argc - (next_arg - argv); program_path.set (next_arg[0]); - for (i = 1; i < n; i++) - program_args.push_back (xstrdup (next_arg[i])); + + int n = argc - (next_arg - argv); + program_args + = construct_inferior_arguments ({&next_arg[1], &next_arg[n]}); /* Wait till we are at first instruction in program. */ target_create_inferior (program_path.get (), program_args); diff --git a/gdbserver/target.h b/gdbserver/target.h index 3643b9110da..1a013bb83db 100644 --- a/gdbserver/target.h +++ b/gdbserver/target.h @@ -77,13 +77,13 @@ public: /* Start a new process. PROGRAM is a path to the program to execute. - PROGRAM_ARGS is a standard NULL-terminated array of arguments, - to be passed to the inferior as ``argv'' (along with PROGRAM). + PROGRAM_ARGS is a string containing all of the arguments that will be + used to start the inferior. Returns the new PID on success, -1 on failure. Registers the new process with the process list. */ virtual int create_inferior (const char *program, - const std::vector &program_args) = 0; + const std::string &program_args) = 0; /* Do additional setup after a new process is created, including exec-wrapper completion. */ diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index da858b65e6f..3cfae74d61a 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -490,14 +490,11 @@ create_process (const char *program, char *args, return ret; } -/* Start a new process. - PROGRAM is the program name. - PROGRAM_ARGS is the vector containing the inferior's args. - Returns the new PID on success, -1 on failure. Registers the new - process with the process list. */ +/* See target.h. */ + int win32_process_target::create_inferior (const char *program, - const std::vector &program_args) + const std::string &program_args) { client_state &cs = get_client_state (); #ifndef USE_WIN32API @@ -508,8 +505,7 @@ win32_process_target::create_inferior (const char *program, DWORD flags; PROCESS_INFORMATION pi; DWORD err; - std::string str_program_args = construct_inferior_arguments (program_args); - char *args = (char *) str_program_args.c_str (); + char *args = (char *) program_args.c_str (); /* win32_wait needs to know we're not attaching. */ windows_process.attaching = 0; diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h index daed16a6ae6..e9dd6adc5a8 100644 --- a/gdbserver/win32-low.h +++ b/gdbserver/win32-low.h @@ -101,7 +101,7 @@ class win32_process_target : public process_stratum_target public: int create_inferior (const char *program, - const std::vector &program_args) override; + const std::string &program_args) override; int attach (unsigned long pid) override;