From 99e7ae30ed872f3f81762504c930634c47055b7c Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Fri, 5 Nov 2010 16:55:40 +0000 Subject: [PATCH] Make gdb.parameter("directories") work. New command "set directories". * NEWS: Document them. * source.c (set_directories_command): New function. (show_directories_1): Renamed from show_directories. All callers updated. (show_directories_command): New function. (_initialize_source): Install "directories" as a set/show variable instead of just a show command. doc/ * gdb.texinfo (Source Path): Document "set directories". testsuite/ * gdb.base/help.exp: Update expected output. * gdb.python/py-parameter.exp: New file. --- gdb/ChangeLog | 12 ++++++ gdb/NEWS | 6 +++ gdb/doc/ChangeLog | 4 ++ gdb/doc/gdb.texinfo | 5 +++ gdb/source.c | 62 ++++++++++++++++++++++++++----- gdb/testsuite/ChangeLog | 5 +++ gdb/testsuite/gdb.base/help.exp | 2 +- gdb/testsuite/gdb.python/py-parameter.exp | 33 ++++++++++++++++ 8 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 gdb/testsuite/gdb.python/py-parameter.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 793c062..e3ab178 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2010-11-05 Doug Evans + + Make gdb.parameter("directories") work. + New command "set directories". + * NEWS: Document them. + * source.c (set_directories_command): New function. + (show_directories_1): Renamed from show_directories. + All callers updated. + (show_directories_command): New function. + (_initialize_source): Install "directories" as a set/show + variable instead of just a show command. + 2010-11-05 Ken Werner * NEWS: Mention OpenCL C language support. diff --git a/gdb/NEWS b/gdb/NEWS index e883a8b..38478c4 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,6 +3,10 @@ *** Changes since GDB 7.2 +* GDB has a new command: "set directories". + It is like the "dir" command except that it replaces the + source path list instead of augmenting it. + * OpenCL C Initial support for the OpenCL C language (http://www.khronos.org/opencl) has been integrated into GDB. @@ -29,6 +33,8 @@ ** New commands "info pretty-printers", "enable pretty-printer" and "disable pretty-printer" have been added. + ** gdb.parameter("directories") is now available. + * C++ Improvements: ** GDB now puts template parameters in scope when debugging in an diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 63f97ec..7e006ce 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2010-11-05 Doug Evans + + * gdb.texinfo (Source Path): Document "set directories". + 2010-11-05 Ken Werner * gdb.texinfo: (Summary) Add mention about OpenCL C language support. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 993b0fb..257ff19 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -6623,6 +6623,11 @@ Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). @c RET-repeat for @code{directory} is explicitly disabled, but since @c repeating it would be a no-op we do not say that. (thanks to RMS) +@item set directories @var{path-list} +@kindex set directories +Set the source path to @var{path-list}. +@samp{$cdir:$cwd} are added if missing. + @item show directories @kindex show directories Print the source path: show which directories it contains. diff --git a/gdb/source.c b/gdb/source.c index 3e89672..bae2fd0 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -68,8 +68,6 @@ static void line_info (char *, int); static void source_info (char *, int); -static void show_directories (char *, int); - /* Path of directories to search for source files. Same format as the PATH environment variable's value. */ @@ -293,14 +291,49 @@ select_source_symtab (struct symtab *s) error (_("Can't find a default source file")); } +/* Handler for "set directories path-list" command. + "set dir mumble" doesn't prepend paths, it resets the entire + path list. The theory is that set(show(dir)) should be a no-op. */ + +static void +set_directories_command (char *args, int from_tty, struct cmd_list_element *c) +{ + /* This is the value that was set. + It needs to be processed to maintain $cdir:$cwd and remove dups. */ + char *set_path = source_path; + + /* We preserve the invariant that $cdir:$cwd begins life at the end of + the list by calling init_source_path. If they appear earlier in + SET_PATH then mod_path will move them appropriately. + mod_path will also remove duplicates. */ + init_source_path (); + if (*set_path != '\0') + mod_path (set_path, &source_path); + + xfree (set_path); +} + +/* Print the list of source directories. + This is used by the "ld" command, so it has the signature of a command + function. */ + static void -show_directories (char *ignore, int from_tty) +show_directories_1 (char *ignore, int from_tty) { puts_filtered ("Source directories searched: "); puts_filtered (source_path); puts_filtered ("\n"); } +/* Handler for "show directories" command. */ + +static void +show_directories_command (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + show_directories_1 (NULL, from_tty); +} + /* Forget what we learned about line positions in source files, and which directories contain them; must check again now since files may be found in a different directory now. */ @@ -367,7 +400,7 @@ directory_command (char *dirname, int from_tty) forget_cached_source_info (); } if (from_tty) - show_directories ((char *) 0, from_tty); + show_directories_1 ((char *) 0, from_tty); } /* Add a path given with the -d command line switch. @@ -1938,16 +1971,27 @@ With no argument, reset the search path to $cdir:$cwd, the default."), set_cmd_completer (c, filename_completer); - add_cmd ("directories", no_class, show_directories, _("\ -Current search path for finding source files.\n\ + add_setshow_optional_filename_cmd ("directories", + class_files, + &source_path, + _("\ +Set the search path for finding source files."), + _("\ +Show the search path for finding source files."), + _("\ $cwd in the path means the current working directory.\n\ -$cdir in the path means the compilation directory of the source file."), - &showlist); +$cdir in the path means the compilation directory of the source file.\n\ +GDB ensures the search path always ends with $cdir:$cwd by\n\ +appending these directories if necessary.\n\ +Setting the value to an empty string sets it to $cdir:$cwd, the default."), + set_directories_command, + show_directories_command, + &setlist, &showlist); if (xdb_commands) { add_com_alias ("D", "directory", class_files, 0); - add_cmd ("ld", no_class, show_directories, _("\ + add_cmd ("ld", no_class, show_directories_1, _("\ Current search path for finding source files.\n\ $cwd in the path means the current working directory.\n\ $cdir in the path means the compilation directory of the source file."), diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 1a2dde5..cb81219 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-11-05 Doug Evans + + * gdb.base/help.exp: Update expected output. + * gdb.python/py-parameter.exp: New file. + 2010-11-05 Ken Werner * Makefile.in (ALL_SUBDIRS): Add gdb.opencl. diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp index 6e70b9d..805cc86 100644 --- a/gdb/testsuite/gdb.base/help.exp +++ b/gdb/testsuite/gdb.base/help.exp @@ -507,7 +507,7 @@ gdb_test "help show confirm" "Show whether to confirm potentially dangerous oper # test help show convenience gdb_test "help show convenience" "Debugger convenience \\(\"\\\$foo\"\\) variables\.\[\r\n\]+These variables are created when you assign them values;\[\r\n\]+thus, \"print \\\$foo=1\" gives \"\\\$foo\" the value 1\. Values may be any type\.\[\r\n\]+A few convenience variables are given values automatically:\[\r\n\]+\"\\\$_\"holds the last address examined with \"x\" or \"info lines\",\[\r\n\]+\"\\\$__\" holds the contents of the last address examined with \"x\"\." "help show convenience" # test help show directories -gdb_test "help show directories" "Current search path for finding source files\.\[\r\n\]+\\\$cwd in the path means the current working directory\.\[\r\n\]+\\\$cdir in the path means the compilation directory of the source file\." "help show directories" +gdb_test "help show directories" "Show the search path for finding source files\.\[\r\n\]+\\\$cwd in the path means the current working directory\.\[\r\n\]+\\\$cdir in the path means the compilation directory of the source file\..*" "help show directories" # test help show editing gdb_test "help show editing" "Show editing of command lines as they are typed\.\[\r\n\]+Use \"on\" to enable the editing, and \"off\" to disable it\.\[\r\n\]+Without an argument, command line editing is enabled\. To edit, use\[\r\n\]+EMACS-like or VI-like commands like control-P or ESC\." "help show editing" # test help show environment diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp new file mode 100644 index 0000000..2332fa4 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-parameter.exp @@ -0,0 +1,33 @@ +# Copyright (C) 2010 Free Software Foundation, Inc. + +# 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 3 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, see . + +# This file is part of the GDB testsuite. It tests gdb.parameter. + +if $tracelevel then { + strace $tracelevel +} + +load_lib gdb-python.exp + +# Start with a fresh gdb. +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +# We use "." here instead of ":" so that this works on win32 too. +gdb_test "python print gdb.parameter ('directories')" "$srcdir/$subdir.\\\$cdir.\\\$cwd" -- 2.7.4