This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
On Friday, May 27, 2011 13:46:59 Tom Tromey wrote: > Offhand it seems like it would be better if this code directly built > sim_argv rather than building a string and converting it, but I don't > know if any odd issue is lurking. i slapped this together. what do you think (ignoring missing docs) ? -mike --- libiberty/argv.c 13 Aug 2010 11:36:10 -0000 1.22 +++ libiberty/argv.c 1 Jun 2011 16:17:06 -0000 @@ -301,6 +301,56 @@ char **buildargv (const char *input) return (argv); } +char **appendargv (char **argv, const char *arg, ...) +{ + va_list ap; + int argc; + + for (argc = 0; argv[argc]; ++argc) + continue; + + va_start (ap, arg); + while (arg) + { + argv = (char **) realloc (argv, sizeof (*argv) * (argc + 2)); + argv[argc] = strdup (arg); + ++argc; + arg = va_arg (ap, const char *); + } + va_end (ap); + + if (argv) + argv[argc] = NULL; + + return argv; +} + +char **mergeargv (char **iargv, ...) +{ + va_list ap; + char **argv = NULL; + int i, argc = 0; + + va_start (ap, iargv); + while (iargv) + { + for (i = 0; iargv[i]; ++i) + { + argv = (char **) realloc (argv, sizeof (*argv) * (argc + 2)); + argv[argc] = strdup (iargv[i]); + ++argc; + } + + iargv = va_arg (ap, char **); + } + va_end (ap); + + if (argv) + argv[argc] = NULL; + + return argv; +} + /* @deftypefn Extension int writeargv (const char **@var{argv}, FILE *@var{file}) --- include/libiberty.h 3 Jan 2011 21:05:50 -0000 1.63 +++ include/libiberty.h 1 Jun 2011 16:17:06 -0000 @@ -74,6 +74,9 @@ extern FILE *freopen_unlocked (const cha extern char **buildargv (const char *) ATTRIBUTE_MALLOC; +extern char **appendargv (char **, const char *, ...) ATTRIBUTE_MALLOC; +extern char **mergeargv (char **iargv, ...) ATTRIBUTE_MALLOC; + /* Free a vector returned by buildargv. */ extern void freeargv (char **); --- gdb/remote-sim.c 1 Jun 2011 15:29:07 -0000 1.103 +++ gdb/remote-sim.c 1 Jun 2011 16:17:06 -0000 @@ -664,7 +664,7 @@ static void gdbsim_open (char *args, int from_tty) { int len; - char *arg_buf; + char **argv; struct sim_inferior_data *sim_data; SIM_DESC gdbsim_desc; @@ -681,44 +681,43 @@ gdbsim_open (char *args, int from_tty) if (gdbsim_is_open) unpush_target (&gdbsim_ops); - len = (7 + 1 /* gdbsim */ - + strlen (" -E little") - + strlen (" --architecture=xxxxxxxxxx") - + strlen (" --sysroot=") + strlen (gdb_sysroot) + - + (args ? strlen (args) : 0) - + 50) /* slack */ ; - arg_buf = (char *) alloca (len); - strcpy (arg_buf, "gdbsim"); /* 7 */ + argv = buildargv ("gdbsim"); + /* Specify the byte order for the target when it is explicitly specified by the user (not auto detected). */ switch (selected_byte_order ()) { case BFD_ENDIAN_BIG: - strcat (arg_buf, " -E big"); + argv = appendargv (argv, "-E", "big", NULL); break; case BFD_ENDIAN_LITTLE: - strcat (arg_buf, " -E little"); + argv = appendargv (argv, "-E", "little", NULL); break; case BFD_ENDIAN_UNKNOWN: break; } + /* Specify the architecture of the target when it has been explicitly specified */ if (selected_architecture_name () != NULL) - { - strcat (arg_buf, " --architecture="); - strcat (arg_buf, selected_architecture_name ()); - } + argv = appendargv (argv, "--architecture", + selected_architecture_name (), NULL); + /* Pass along gdb's concept of the sysroot. */ - strcat (arg_buf, " --sysroot="); - strcat (arg_buf, gdb_sysroot); + argv = appendargv (argv, "--sysroot", gdb_sysroot, NULL); + /* finally, any explicit args */ if (args) { - strcat (arg_buf, " "); /* 1 */ - strcat (arg_buf, args); + char **uargv; + + uargv = gdb_buildargv (args); + sim_argv = mergeargv (argv, uargv, NULL); + freeargv (argv); + freeargv (uargv); } - sim_argv = gdb_buildargv (arg_buf); + else + sim_argv = argv; init_callbacks (); gdbsim_desc = sim_open (SIM_OPEN_DEBUG, &gdb_callback, exec_bfd, sim_argv);
Attachment:
signature.asc
Description: This is a digitally signed message part.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |