From 808480f667e41e2fdb66bfdc9d5e047f1aa34a68 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 13 Apr 2017 11:46:07 +0100 Subject: fork-child.c: Avoid unnecessary heap-allocation / string copying The previous change to fork-child.c converted the argv building from an alloca-allocated array of non-owning arg pointers, to a std::vector of owning pointers, which results in N string dups, with N being the number of arguments in the vector, and then requires manually releasing the pointers owned by the vector. This patch makes the vector hold non-owning pointers, and avoids the string dups, by doing one single string copy of the arguments upfront, and replacing separators with NULL terminators in place, like we used to. All the logic to do that is encapsulated in a new class. With this, there's no need to remember to manually release the argv elements with free_vector_argv either. gdb/ChangeLog: 2017-04-13 Pedro Alves * fork-child.c (execv_argv): New class. (breakup_args): Refactored as ... (execv_argv::init_for_no_shell): .. this method of execv_argv. Copy arguments to storage and replace separators with NULL terminators in place. (escape_bang_in_quoted_argument): Adjust to return bool. (execv_argv::execv_argv): New ctor. (execv_argv::init_for_shell): New method, factored out from fork_inferior. Don't strdup strings into the vector. (fork_inferior): Eliminate "shell" local and use execv_argv. Use Remove free_vector_argv call. --- gdb/ChangeLog | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gdb/ChangeLog') diff --git a/gdb/ChangeLog b/gdb/ChangeLog index ed71880..90ed21c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2017-04-13 Pedro Alves + + * fork-child.c (execv_argv): New class. + (breakup_args): Refactored as ... + (execv_argv::init_for_no_shell): .. this method of execv_argv. + Copy arguments to storage and replace separators with NULL + terminators in place. + (escape_bang_in_quoted_argument): Adjust to return bool. + (execv_argv::execv_argv): New ctor. + (execv_argv::init_for_shell): New method, factored out from + fork_inferior. Don't strdup strings into the vector. + (fork_inferior): Eliminate "shell" local and use execv_argv. Use + Remove free_vector_argv call. + 2017-04-13 Yao Qi * rx-tdep.c (rx_fpsw_type): Check tdep->rx_fpsw_type instead of -- cgit v1.1