From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29350 invoked by alias); 6 Dec 2002 15:25:18 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 29150 invoked from network); 6 Dec 2002 15:23:31 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sources.redhat.com with SMTP; 6 Dec 2002 15:23:31 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.11.6/8.11.6) with ESMTP id gB6EwHP11903 for ; Fri, 6 Dec 2002 09:58:17 -0500 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id gB6FNUD31444; Fri, 6 Dec 2002 10:23:30 -0500 Received: from localhost.redhat.com (romulus-int.sfbay.redhat.com [172.16.27.46]) by pobox.corp.redhat.com (8.11.6/8.11.6) with ESMTP id gB6FNS921864; Fri, 6 Dec 2002 10:23:28 -0500 Received: by localhost.redhat.com (Postfix, from userid 469) id 18FF0FF79; Fri, 6 Dec 2002 10:19:08 -0500 (EST) From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15856.49132.808513.946745@localhost.redhat.com> Date: Fri, 06 Dec 2002 07:34:00 -0000 To: "J. Johnston" Cc: Elena Zannoni , gdb-patches@sources.redhat.com, eliz@is.elta.co.il Subject: Re: Proposed patch for gdb/mi 741 In-Reply-To: <3DD01DED.8D485C56@redhat.com> References: <3DA4886F.194D484D@redhat.com> <15797.30559.329315.574728@localhost.redhat.com> <3DCAE4E2.D05B3DD8@redhat.com> <15818.64935.170977.501640@localhost.redhat.com> <3DCC4E80.D1688178@redhat.com> <3DD01DED.8D485C56@redhat.com> X-SW-Source: 2002-12/txt/msg00224.txt.bz2 J. Johnston writes: > Ok I noticed a few more things in mi-cmd-env.c, the rest is ok. Sorry, another iteration.... See below. > gdb/ChangeLog: > > 2002-11-11 Jeff Johnston > > * defs.h (init_last_source_visited): New prototype. > (add_path): Ditto. > * source.c (add_path): New function that adds to a specified path. > (mod_path): Change to call add_path. > (init_last_source_visited): New function to allow interfaces to > initialize static variable: last_source_visited. Part of fix > for PR gdb/741. > * Makefile.in: Add support for mi/mi-cmd-env.c. > > gdb/mi/ChangeLog: > > 2002-11-11 Jeff Johnston > > * mi-cmds.c (-environment-directory) Change to use mi_cmd_env_dir, > (-environment-cd): Change to use mi_cmd_env_cd,. > (-environment-pwd): Change to use mi_cmd_env_pwd. > (-environment-path): Change to use mi_cmd_env_path. > * mi-cmds.h (mi_cmd_env_cd, mi_cmd_env_dir): New prototypes. > (mi_cmd_env_path, mi_cmd_env_pwd): Ditto. > * mi-cmd-env.c: New file. Part of fix for PR gdb/741. > * gdbmi.texinfo (environment-cd): Update output and example. > (environment-pwd): Ditto. > (environment-dir): Update output, description, and examples. > (environment-path): Ditto. > > gdb/testsuite/gdb.mi/ChangeLog: > > 2002-11-11 Jeff Johnston > > * mi-basics.exp: Change tests for -environment-directory. Also add > tests for -environment-cd and -environment-pwd. Part of fix for > PR gdb/741.Index: defs.h > =================================================================== > RCS file: /cvs/src/src/gdb/defs.h,v > retrieving revision 1.102 > diff -u -r1.102 defs.h > --- defs.h 15 Oct 2002 02:16:51 -0000 1.102 > +++ defs.h 9 Nov 2002 00:33:14 -0000 > @@ -572,9 +572,15 @@ > > extern void mod_path (char *, char **); > > +extern void add_path (char *, char **, int); > + > extern void directory_command (char *, int); > > +extern char *source_path; > + > extern void init_source_path (void); > + > +extern void init_last_source_visited (void); > > extern char *symtab_to_filename (struct symtab *); > > Index: source.c > =================================================================== > RCS file: /cvs/src/src/gdb/source.c,v > retrieving revision 1.36 > diff -u -r1.36 source.c > --- source.c 24 Oct 2002 21:02:53 -0000 1.36 > +++ source.c 9 Nov 2002 00:33:14 -0000 > @@ -357,6 +357,12 @@ > forget_cached_source_info (); > } > > +void > +init_last_source_visited (void) > +{ > + last_source_visited = NULL; > +} > + > /* Add zero or more directories to the front of the source path. */ > > void > @@ -387,6 +393,18 @@ > void > mod_path (char *dirname, char **which_path) > { > + add_path (dirname, which_path, 1); > +} > + > +/* Workhorse of mod_path. Takes an extra argument to determine > + if dirname should be parsed for separators that indicate multiple > + directories. This allows for interfaces that pre-parse the dirname > + and allow specification of traditional separator characters such > + as space or tab. */ > + > +void > +add_path (char *dirname, char **which_path, int parse_separators) > +{ > char *old = *which_path; > int prefix = 0; > > @@ -403,9 +421,16 @@ > struct stat st; > > { > - char *separator = strchr (name, DIRNAME_SEPARATOR); > - char *space = strchr (name, ' '); > - char *tab = strchr (name, '\t'); > + char *separator = NULL; > + char *space = NULL; > + char *tab = NULL; > + > + if (parse_separators) > + { > + separator = strchr (name, DIRNAME_SEPARATOR); > + space = strchr (name, ' '); > + tab = strchr (name, '\t'); > + } > > if (separator == 0 && space == 0 && tab == 0) > p = dirname = name + strlen (name); > @@ -536,7 +561,8 @@ > tinybuf[0] = DIRNAME_SEPARATOR; > tinybuf[1] = '\0'; > > - /* If we have already tacked on a name(s) in this command, be sure they stay on the front as we tack on some more. */ > + /* If we have already tacked on a name(s) in this command, be sure they stay > + on the front as we tack on some more. */ > if (prefix) > { > char *temp, c; > Index: Makefile.in > =================================================================== > RCS file: /cvs/src/src/gdb/Makefile.in,v > retrieving revision 1.278 > diff -u -r1.278 Makefile.in > --- Makefile.in 8 Nov 2002 20:48:54 -0000 1.278 > +++ Makefile.in 9 Nov 2002 00:33:14 -0000 > @@ -166,12 +166,12 @@ > # > SUBDIR_MI_OBS = \ > mi-out.o mi-console.o \ > - mi-cmds.o mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \ > + mi-cmds.o mi-cmd-env.o mi-cmd-var.o mi-cmd-break.o mi-cmd-stack.o \ > mi-cmd-disas.o \ > mi-main.o mi-parse.o mi-getopt.o > SUBDIR_MI_SRCS = \ > mi/mi-out.c mi/mi-console.c \ > - mi/mi-cmds.c \ > + mi/mi-cmds.c mi/mi-cmd-env.c \ > mi/mi-cmd-var.c mi/mi-cmd-break.c mi/mi-cmd-stack.c \ > mi/mi-cmd-disas.c \ > mi/mi-main.c mi/mi-parse.c mi/mi-getopt.c > @@ -2487,6 +2487,10 @@ > mi-cmd-disas.o: $(srcdir)/mi/mi-cmd-disas.c $(defs_h) $(target_h) $(value_h) \ > $(mi_cmds_h) $(mi_getopt_h) $(ui_out_h) $(gdb_string_h) $(disasm_h) > $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-cmd-disas.c > +mi-cmd-env.o: $(srcdir)/mi/mi-cmd-env.c $(defs_h) $(mi_cmds_h) $(ui_out_h) \ > + $(mi_out_h) $(varobj_h) $(value_h) $(gdb_string_h) $(inferior.h) \ > + $(mi_getopt_h) > + $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-cmd-env.c > mi-cmd-stack.o: $(srcdir)/mi/mi-cmd-stack.c $(defs_h) $(target_h) $(frame_h) \ > $(value_h) $(mi_cmds_h) $(ui_out_h) $(symtab_h) > $(CC) -c $(INTERNAL_CFLAGS) $(srcdir)/mi/mi-cmd-stack.c > Index: mi/mi-cmd-env.c > =================================================================== > RCS file: mi/mi-cmd-env.c > diff -N mi/mi-cmd-env.c > --- mi/mi-cmd-env.c 1 Jan 1970 00:00:00 -0000 > +++ mi/mi-cmd-env.c 9 Nov 2002 00:33:14 -0000 > @@ -0,0 +1,202 @@ > +/* MI Command Set - environment commands. > + Copyright 2002 Free Software Foundation, Inc. > + Contributed by Red Hat Inc. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 2 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program; if not, write to the Free Software > + Foundation, Inc., 59 Temple Place - Suite 330, > + Boston, MA 02111-1307, USA. */ > + > +#include > +#include > + > +#include "defs.h" > +#include "target.h" > +#include "frame.h" > +#include "value.h" > +#include "mi-cmds.h" > +#include "mi-out.h" > +#include "mi-getopt.h" > +#include "ui-out.h" > +#include "symtab.h" > +#include "filenames.h" > +#include "environ.h" > +#include "command.h" > +#include "top.h" > +#include "inferior.h" > + Are all these includes needed? they are not listed in the Makefile dependencies. > +static void env_cli_command (const char *cli, char *args); > +static void env_mod_path (char *dirname, char **which_path); > + > +static const char path_var_name[] = "PATH"; > + > +/* The following is copied from mi-main.c so for m1 and below we > + can perform old behavior and use cli commands. */ > +static void > +env_execute_cli_command (const char *cli, char *args) > +{ > + if (cli != 0) > + { > + struct cleanup *old_cleanups; > + char *run; > + xasprintf (&run, cli, args); > + old_cleanups = make_cleanup (xfree, run); > + execute_command ( /*ui */ run, 0 /*from_tty */ ); > + do_cleanups (old_cleanups); > + return; > + } > +} > + > + > +/* Print working directory. */ > +enum mi_cmd_result > +mi_cmd_env_pwd (char *command, char **argv, int argc) > +{ > + if (argc > 0) > + error ("mi_cmd_env_pwd: No arguments required"); > + > + if (mi_version (uiout) < 2) > + { > + env_execute_cli_command ("pwd", NULL); > + return MI_CMD_DONE; > + } > + > + /* Otherwise the mi level is 2 or higher. */ > + > + getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); > + ui_out_field_string (uiout, "cwd", gdb_dirbuf); > + > + return MI_CMD_DONE; > +} > + > +/* Change working directory. */ > +enum mi_cmd_result > +mi_cmd_env_cd (char *command, char **argv, int argc) > +{ > + if (argc == 0 || argc > 1) > + error ("mi_cmd_env_cd: Usage DIRECTORY"); > + > + env_execute_cli_command ("cd %s", argv[0]); > + > + return MI_CMD_DONE; > +} > + > +static void > +env_mod_path (char *dirname, char **which_path) > +{ > + if (dirname == 0 || dirname[0] == '\0') > + return; > + > + /* Call add_path with last arg 0 to indicate not to parse for > + separator characters. */ > + add_path (dirname, which_path, 0); > +} > + > +/* Add one or more directories to start of executable search path. */ > +enum mi_cmd_result > +mi_cmd_env_path (char *command, char **argv, int argc) > +{ > + char *exec_path; > + char *env; > + int i; > + > + if (mi_version (uiout) < 2) > + { > + for (i = argc - 1; i >= 0; --i) > + env_execute_cli_command ("path %s", argv[i]); > + return MI_CMD_DONE; > + } > + > + /* Otherwise the mi level is 2 or higher. */ > + dont_repeat (); > + env = get_in_environ (inferior_environ, path_var_name); > + > + /* Can be null if path is not set. */ > + if (!env) > + env = ""; > + exec_path = xstrdup (env); > + > + for (i = argc - 1; i >= 0; --i) > + env_mod_path (argv[i], &exec_path); > + Could you add a -reset option here too? We might as well have some symmetry. > + set_in_environ (inferior_environ, path_var_name, exec_path); > + xfree (exec_path); > + env = get_in_environ (inferior_environ, path_var_name); > + ui_out_field_string (uiout, "path", env); > + > + return MI_CMD_DONE; > +} > + > +/* Add zero or more directories to the front of the source path. */ > +enum mi_cmd_result > +mi_cmd_env_dir (char *command, char **argv, int argc) > +{ > + int i; > + int optind = 0; > + int reset = 0; > + char *optarg; > + enum opt > + { > + RESET_OPT > + }; > + static struct mi_opt opts[] = > + { > + {"r", RESET_OPT, 0}, > + 0 > + }; > + > + dont_repeat (); > + > + if (mi_version (uiout) < 2) > + { > + for (i = argc - 1; i >= 0; --i) > + env_execute_cli_command ("dir %s", argv[i]); > + return MI_CMD_DONE; > + } > + > + /* Otherwise mi level is 2 or higher. */ > + while (1) > + { > + int opt = mi_getopt ("mi_cmd_data_read_memory", argc, argv, opts, ^^^^^^^^^^^^^^^^^^^^^^^ > + &optind, &optarg); > + if (opt < 0) > + break; > + switch ((enum opt) opt) > + { > + case RESET_OPT: > + reset = 1; > + break; > + } > + } > + argv += optind; > + argc -= optind; > + > + if (reset) > + { > + /* No args implies reset to default path. */ > + xfree (source_path); > + init_source_path (); > + } > + > + for (i = argc - 1; i >= 0; --i) > + env_mod_path (argv[i], &source_path); > + init_last_source_visited (); > + > + ui_out_field_string (uiout, "source-path", source_path); > + forget_cached_source_info (); > + > + return MI_CMD_DONE; > +} > + > Index: mi/mi-cmds.h > =================================================================== > RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v > retrieving revision 1.5 > diff -u -r1.5 mi-cmds.h > --- mi/mi-cmds.h 6 Mar 2001 08:21:45 -0000 1.5 > +++ mi/mi-cmds.h 9 Nov 2002 00:33:14 -0000 > @@ -64,6 +64,10 @@ > extern mi_cmd_argv_ftype mi_cmd_data_read_memory; > extern mi_cmd_argv_ftype mi_cmd_data_write_memory; > extern mi_cmd_argv_ftype mi_cmd_data_write_register_values; > +extern mi_cmd_argv_ftype mi_cmd_env_cd; > +extern mi_cmd_argv_ftype mi_cmd_env_dir; > +extern mi_cmd_argv_ftype mi_cmd_env_path; > +extern mi_cmd_argv_ftype mi_cmd_env_pwd; > extern mi_cmd_args_ftype mi_cmd_exec_continue; > extern mi_cmd_args_ftype mi_cmd_exec_finish; > extern mi_cmd_args_ftype mi_cmd_exec_next; > Index: mi/mi-cmds.c > =================================================================== > RCS file: /cvs/src/src/gdb/mi/mi-cmds.c,v > retrieving revision 1.8 > diff -u -r1.8 mi-cmds.c > --- mi/mi-cmds.c 6 Mar 2001 08:21:45 -0000 1.8 > +++ mi/mi-cmds.c 9 Nov 2002 00:33:14 -0000 > @@ -56,10 +56,10 @@ > {"display-enable", 0, 0}, > {"display-insert", 0, 0}, > {"display-list", 0, 0}, > - {"environment-cd", "cd %s", 0}, > - {"environment-directory", "dir %s", 0}, > - {"environment-path", "path %s", 0}, > - {"environment-pwd", "pwd", 0}, > + {"environment-cd", 0, 0, mi_cmd_env_cd}, > + {"environment-directory", 0, 0, mi_cmd_env_dir}, > + {"environment-path", 0, 0, mi_cmd_env_path}, > + {"environment-pwd", 0, 0, mi_cmd_env_pwd}, > {"exec-abort", 0, 0}, > {"exec-arguments", "set args %s", 0}, > {"exec-continue", 0, mi_cmd_exec_continue}, > Index: gdbmi.texinfo > =================================================================== > RCS file: /cvs/src/src/gdb/mi/gdbmi.texinfo,v > retrieving revision 1.29 > diff -u -r1.29 gdbmi.texinfo > --- gdbmi.texinfo 3 Oct 2002 22:31:31 -0000 1.29 > +++ gdbmi.texinfo 9 Nov 2002 00:30:50 -0000 > @@ -1665,10 +1665,18 @@ > @subsubheading Synopsis > > @example > - -environment-directory @var{pathdir} > + -environment-directory [ -r ] [ @var{pathdir} ]+ > @end example > > -Add directory @var{pathdir} to beginning of search path for source files. > +Add directories @var{pathdir} to beginning of search path for source files. > +If the @samp{-r} option is used, the search path is reset to the default > +search path. If directories @var{pathdir} are supplied in addition to the > +@samp{-r} option, the search path is first reset and then addition > +occurs as normal. > +Specifying multiple directories in a single command > +results in the directories added to the beginning of the > +search path in the same order they were presented in the command. > +If no directories are specified, the current search path is displayed. > > @subsubheading @value{GDBN} Command > > @@ -1679,7 +1687,16 @@ > @smallexample > (@value{GDBP}) > -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb > -^done > +^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd" > +(@value{GDBP}) > +-environment-directory "" > +^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd" > +(@value{GDBP}) > +-environment-directory -r /home/jjohnstn/src/gdb > +^done,source-path="/home/jjohnstn/src/gdb:$cdir:$cwd" > +(@value{GDBP}) > +-environment-directory -r > +^done,source-path="$cdir:$cwd" > (@value{GDBP}) > @end smallexample > > @@ -1690,10 +1707,12 @@ > @subsubheading Synopsis > > @example > - -environment-path ( @var{pathdir} )+ > + -environment-path [ @var{pathdir} ]+ > @end example > > Add directories @var{pathdir} to beginning of search path for object files. > +If no paths or an empty path is specified, the current object search path > +is displayed with no modification. > > @subsubheading @value{GDBN} Command > > @@ -1704,7 +1723,10 @@ > @smallexample > (@value{GDBP}) > -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb > -^done > +^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/usr/bin" > +(@value{GDBP}) > +-environment-path > +^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/usr/bin" > (@value{GDBP}) > @end smallexample > > @@ -1729,8 +1751,7 @@ > @smallexample > (@value{GDBP}) > -environment-pwd > -~Working directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb. > -^done > +^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb" > (@value{GDBP}) > @end smallexample > > Index: mi-basics.exp > =================================================================== > RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-basics.exp,v > retrieving revision 1.6 > diff -u -r1.6 mi-basics.exp > --- mi-basics.exp 27 Jun 2001 17:27:07 -0000 1.6 > +++ mi-basics.exp 11 Nov 2002 21:11:07 -0000 > @@ -148,26 +148,52 @@ > global srcdir > global subdir > > - # Clear the search directories, then specify one to be searched > + # Add to the search directories, display, then reset back to default > # Tests: > - # -environment-directory > # -environment-directory arg > + # -environment-directory > + # -environment-directory -r > > #exp_internal 1 > - mi_gdb_test "202-environment-directory" \ > - "\\\^done" \ > + mi_gdb_test "202-environment-directory ${srcdir}/${subdir}" \ > + "\\\^done,source-path=\"${srcdir}/${subdir}:\\\$cdir:\\\$cwd\"" \ > + "environment-directory arg operation" > + > + mi_gdb_test "203-environment-directory" \ > + "\\\^done,source-path=\"${srcdir}/${subdir}:\\\$cdir:\\\$cwd\"" \ > + "environment-directory empty-string operation" > + > + mi_gdb_test "204-environment-directory -r" \ > + "\\\^done,source-path=\"\\\$cdir:\\\$cwd\"" \ > "environment-directory operation" > > - mi_gdb_test "203-environment-directory ${srcdir}/${subdir}" \ > - "\\\^done" \ > - "environment-directory arg operation" > #exp_internal 0 > } > > +proc test_cwd_specification {} { > + global mi_gdb_prompt > + global objdir > + global subdir > + > + # Change the working directory, then print the current working directory > + # Tests: > + # -environment-cd ${objdir} > + # -environment-pwd > + > + mi_gdb_test "205-environment-cd ${objdir}" \ > + "\\\^done" \ > + "environment-cd arg operation" > + > + mi_gdb_test "206-environment-pwd" \ > + "\\\^done,cwd=\"${objdir}\"" \ > + "environment-pwd operation" > +} > + > if [test_mi_interpreter_selection] { > test_exec_and_symbol_mi_operatons > test_breakpoints_deletion > test_dir_specification > + test_cwd_specification > } > > mi_gdb_exit