Skip to content

Commit

Permalink
gdbsupport: Let construct_inferior_arguments take gdb::array_view param
Browse files Browse the repository at this point in the history
Adapt the construct_inferior_arguments function to
take a gdb::array_view<char * const> parameter instead
of a char * array and an int indicating the length
and adapt the only call site.

This will allow calling it more simply in a follow-up
patch introducing more uses of the function.

gdbsupport/ChangeLog:

	* common-inferior.cc, common-inferior.h (construct_inferior_arguments):
	Adapt to take a gdb::array_view<char * const> parameter.
	Adapt call site.

Change-Id: I1c6496c8c0b0eb3ef3fda96e9e3bd64c5e6cac3c
  • Loading branch information
michaelweghorn authored and simark committed May 25, 2020
1 parent c699004 commit 8c4b5f3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
5 changes: 3 additions & 2 deletions gdb/infcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ get_inferior_args (void)
{
if (current_inferior ()->argc != 0)
{
std::string n = construct_inferior_arguments (current_inferior ()->argc,
current_inferior ()->argv);
gdb::array_view<char * const> args (current_inferior ()->argv,
current_inferior ()->argc);
std::string n = construct_inferior_arguments (args);
set_inferior_args (n.c_str ());
}

Expand Down
6 changes: 6 additions & 0 deletions gdbsupport/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2020-05-25 Michael Weghorn <[email protected]>

* common-inferior.cc, common-inferior.h (construct_inferior_arguments):
Adapt to take a gdb::array_view<char * const> parameter.
Adapt call site.

2020-05-25 Michael Weghorn <[email protected]>

* common-inferior.cc, common-inferior.h (construct_inferior_arguments):
Expand Down
16 changes: 7 additions & 9 deletions gdbsupport/common-inferior.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ bool startup_with_shell = true;
/* See common-inferior.h. */

std::string
construct_inferior_arguments (int argc, char * const *argv)
construct_inferior_arguments (gdb::array_view<char * const> argv)
{
gdb_assert (argc >= 0);

std::string result;

if (startup_with_shell)
Expand All @@ -48,7 +46,7 @@ construct_inferior_arguments (int argc, char * const *argv)
static const char special[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
static const char quote = '\'';
#endif
for (int i = 0; i < argc; ++i)
for (int i = 0; i < argv.size (); ++i)
{
if (i > 0)
result += ' ';
Expand Down Expand Up @@ -103,19 +101,19 @@ construct_inferior_arguments (int argc, char * const *argv)
{
/* In this case we can't handle arguments that contain spaces,
tabs, or newlines -- see breakup_args(). */
for (int i = 0; i < argc; ++i)
for (char *arg : argv)
{
char *cp = strchr (argv[i], ' ');
char *cp = strchr (arg, ' ');
if (cp == NULL)
cp = strchr (argv[i], '\t');
cp = strchr (arg, '\t');
if (cp == NULL)
cp = strchr (argv[i], '\n');
cp = strchr (arg, '\n');
if (cp != NULL)
error (_("can't handle command-line "
"argument containing whitespace"));
}

for (int i = 0; i < argc; ++i)
for (int i = 0; i < argv.size (); ++i)
{
if (i > 0)
result += " ";
Expand Down
5 changes: 4 additions & 1 deletion gdbsupport/common-inferior.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef COMMON_COMMON_INFERIOR_H
#define COMMON_COMMON_INFERIOR_H

#include "gdbsupport/array-view.h"

/* Return the exec wrapper to be used when starting the inferior, or NULL
otherwise. */
extern const char *get_exec_wrapper ();
Expand Down Expand Up @@ -60,6 +62,7 @@ extern bool startup_with_shell;

/* Compute command-line string given argument vector. This does the
same shell processing as fork_inferior. */
extern std::string construct_inferior_arguments (int, char * const *);
extern std::string
construct_inferior_arguments (gdb::array_view<char * const>);

#endif /* COMMON_COMMON_INFERIOR_H */

0 comments on commit 8c4b5f3

Please sign in to comment.