This is the mail archive of the gdb-patches@sources.redhat.com 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]

Re: [PATCH] specify arguments to debugee from commandline


David,

First of all, do you have a valid assignment with the FSF?
Maybe your patch is small enough so that we are able to use it without
an assignment, I will defer this decision to Andrew.

I am not the maintainer of these files (although I keep meddling with
them) but I have two objections (easy to fix) with regards to the patch
below.

1) I don't like the changes to infcmd.c.  The initialization should not
be conditional and the use of inferior_args both as a flag causes it to
be "initialized" twice -- first time with zero and second time with a
pointer to an empty string.

You can avoid this by storing your arguments in a temporary place in
main.c until you can process it (it should be done around where the
files are loaded).

2) The external definition for set_inferior_args() and possibly for
get_inferior_args() should go into a header file.  If people decide to
incorporate your patch one of us can create a infcmd.h for you.
There was a discussion about this header file issue recently and it was
decided (AFAICT) that we would keep declarations in header files
associated with the one where things are defined.


Anyway, beofore concerning yourself with these details, we must know
what people think of the syntax.  Alexandre Oliva has made a comment
with regards to that and so did Pierre Muller.  I believe that should be
addressed first.


But your patch is a good initiative.  Thanks for bringing this command
line issue back to discussion.

Regards,
Fernando



David Deephanphongs wrote:
> 
> This patch will add the option --args=<args> to gdb.
> It assumes that <args> is one argument (i.e., is in quotes, or has the
> spaces escaped).
> --args acts just like calling 'set args <args>' does from the gdb prompt:
> gdb --args '--color=never -l gdb' /bin/ls
> is equivalent to:
> gdb /bin/ls
> gdb> set args --color=never -l gdb
> 
> It also adds a description of --args when 'gdb -h' is run,
> and adds a description of --args to the manpage.
> 
> The patch is against the 20010327 snapshot.
> 
> ======= Changelog =========
> 2001-03-30  David Deephanphongs  <david@llamedos.org>
> 
>         * main.c:
>         (set_inferior_args): Added extern prototype of set_inferior_args.
>         (captured_main): Add --args option to gdb.
>         * infcmd.c:
>         (inferior_args): initialize to zero.
>         (_initialize_infcmd): only call set_inferior_args (xtrdup (""))
>         if inferior_args is set to zero.
>         * gdb.1, main.c (print_gdb_help):
>         Document --args option
> 
> ====== Patch =======
> diff -c3p gdb-orig/gdb.1 gdb/gdb.1
> *** gdb-orig/gdb.1      Tue Mar  6 03:21:07 2001
> --- gdb/gdb.1   Fri Mar 30 00:22:00 2001
> *************** gdb \- The GNU Debugger
> *** 38,43 ****
> --- 38,46 ----
>   .RB "[\|" "\-d "\c
>   .I dir\c
>   \&\|]
> + .RB "[\|" "\-args "\c
> + .I args\c
> + \&\|]
>   .RB "[\|" \c
>   .I prog\c
>   .RB "[\|" \c
> *************** Execute GDB commands from file \c
> *** 264,269 ****
> --- 267,280 ----
>   Add \c
>   .I directory\c
>   \& to the path to search for source files.
> +
> +
> + .TP
> + .BI "\-args=" "args"\c
> + \&
> + Set \c
> + .I args\c
> + \& as the default arguments for the program to be debugged.
>   .PP
> 
>   .TP
> diff -c3p gdb-orig/infcmd.c gdb/infcmd.c
> *** gdb-orig/infcmd.c   Wed Mar 21 11:42:38 2001
> --- gdb/infcmd.c        Thu Mar 29 23:27:07 2001
> *************** static void breakpoint_auto_delete_conte
> *** 121,127 ****
>   /* String containing arguments to give to the program, separated by spaces.
>      Empty string (pointer to '\0') means no args.  */
> 
> ! static char *inferior_args;
> 
>   /* File name for default use for standard in/out in the inferior.  */
> 
> --- 121,127 ----
>   /* String containing arguments to give to the program, separated by spaces.
>      Empty string (pointer to '\0') means no args.  */
> 
> ! static char *inferior_args = 0;
> 
>   /* File name for default use for standard in/out in the inferior.  */
> 
> *************** Register name as argument means describe
> *** 1967,1973 ****
>     add_info ("float", float_info,
>             "Print the status of the floating point unit\n");
> 
> !   set_inferior_args (xstrdup (""));   /* Initially no args */
>     inferior_environ = make_environ ();
>     init_environ (inferior_environ);
>   }
> --- 1967,1974 ----
>     add_info ("float", float_info,
>             "Print the status of the floating point unit\n");
> 
> !   if (inferior_args == 0)
> !       set_inferior_args (xstrdup (""));       /* Initially no args */
>     inferior_environ = make_environ ();
>     init_environ (inferior_environ);
>   }
> diff -c3p gdb-orig/main.c gdb/main.c
> *** gdb-orig/main.c     Tue Mar  6 03:21:10 2001
> --- gdb/main.c  Fri Mar 30 00:14:39 2001
> *************** static void print_gdb_help (struct ui_fi
> *** 89,94 ****
> --- 89,98 ----
>   extern int enable_external_editor;
>   extern char *external_editor_command;
> 
> + /* Used to set the arguments to the inferior program (i.e., the program that
> +    is being debugged.) */
> + extern char *set_inferior_args (char *newargs);
> +
>   #ifdef __CYGWIN__
>   #include <windows.h>          /* for MAX_PATH */
>   #include <sys/cygwin.h>               /* for cygwin32_conv_to_posix_path */
> *************** captured_main (void *data)
> *** 284,289 ****
> --- 288,294 ----
>         {"windows", no_argument, &use_windows, 1},
>         {"statistics", no_argument, 0, 13},
>         {"write", no_argument, &write_files, 1},
> +         {"args", required_argument, 0, 14},
>   /* Allow machine descriptions to add more options... */
>   #ifdef ADDITIONAL_OPTIONS
>         ADDITIONAL_OPTIONS
> *************** captured_main (void *data)
> *** 325,330 ****
> --- 330,339 ----
>             display_time = 1;
>             display_space = 1;
>             break;
> +         case 14:
> +           /* Set the arguments for the inferior program. */
> +           set_inferior_args ( xstrdup (optarg) );
> +           break;
>           case 'f':
>             annotation_level = 1;
>   /* We have probably been invoked from emacs.  Disable window interface.  */
> *************** Options:\n\n\
> *** 824,829 ****
> --- 833,841 ----
>     -w                 Use a window interface.\n\
>     --write            Set writing into executable and core files.\n\
>     --xdb              XDB compatibility mode.\n\
> + ", stream);
> +   fputs_unfiltered ("\
> +   --args=args        Set arguments to give debugged program when it is run.\n\
>   ", stream);
>   #ifdef ADDITIONAL_OPTION_HELP
>     fputs_unfiltered (ADDITIONAL_OPTION_HELP, stream);

-- 
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]