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. doc/ * gdb.texinfo (Source Path): Document "set directories". testsuite/ * gdb.base/help.exp: Update expected output. * gdb.python/py-param.exp: Delete, contents moved to ... * gdb.python/py-parameter.exp: ... here. New file. Add test for gdb.parameter ("directories"). Index: NEWS =================================================================== RCS file: /cvs/src/src/gdb/NEWS,v retrieving revision 1.410 diff -u -p -r1.410 NEWS --- NEWS 5 Nov 2010 14:31:25 -0000 1.410 +++ NEWS 5 Nov 2010 16:52:52 -0000 @@ -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 Index: source.c =================================================================== RCS file: /cvs/src/src/gdb/source.c,v retrieving revision 1.114 diff -u -p -r1.114 source.c --- source.c 9 Jul 2010 02:39:58 -0000 1.114 +++ source.c 5 Nov 2010 16:52:52 -0000 @@ -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 fr 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 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."), Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.772 diff -u -p -r1.772 gdb.texinfo --- doc/gdb.texinfo 5 Nov 2010 14:31:28 -0000 1.772 +++ doc/gdb.texinfo 5 Nov 2010 16:52:53 -0000 @@ -6623,6 +6623,11 @@ Reset the source path to its default val @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. Index: testsuite/gdb.base/help.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/help.exp,v retrieving revision 1.46 diff -u -p -r1.46 help.exp --- testsuite/gdb.base/help.exp 16 Aug 2010 19:19:22 -0000 1.46 +++ testsuite/gdb.base/help.exp 5 Nov 2010 16:52:53 -0000 @@ -507,7 +507,7 @@ gdb_test "help show confirm" "Show wheth # 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 Index: py-param.exp =================================================================== RCS file: py-param.exp diff -N py-param.exp --- py-param.exp 1 Oct 2010 17:03:50 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,113 +0,0 @@ -# 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 the mechanism -# exposing convenience functions to Python. - -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 } - -# Test a simple boolean parameter. -gdb_py_test_multiple "Simple gdb booleanparameter" \ - "python" "" \ - "class TestParam (gdb.Parameter):" "" \ - " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \ - " show_doc = \"Show whether the state of the Test Parameter does something useful\"" ""\ - " set_doc = \"Set whether the state of the Test Parameter does something useful\"" "" \ - " def __init__ (self, name):" "" \ - " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ - " self.value = True" "" \ - "test_param = TestParam ('print test-param')" ""\ - "end" - -gdb_test "python print test_param.value" "True" "Test parameter value" -gdb_test "show print test-param" "Whether the state of the Test Parameter does something useful is on.*" "Show parameter on" -gdb_py_test_silent_cmd "set print test-param off" "Turn off parameter" 1 -gdb_test "show print test-param" "Whether the state of the Test Parameter does something useful is off.*" "Show parameter off" -gdb_test "python print test_param.value" "False" "Test parameter value" -gdb_test "help show print test-param" "Show whether the state of the Test Parameter does something useful.*" "Test show help" -gdb_test "help set print test-param" "Set whether the state of the Test Parameter does something useful.*" "Test set help" -gdb_test "help set print" "set print test-param -- Set whether the state of the Test Parameter.*" "Test general help" - -# Test an enum parameter. -gdb_py_test_multiple "enum gdb parameter" \ - "python" "" \ - "class TestEnumParam (gdb.Parameter):" "" \ - " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ - " show_doc = \"Show the state of the enum\"" ""\ - " set_doc = \"Set the state of the enum\"" "" \ - " def __init__ (self, name):" "" \ - " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \ - " self.value = \"one\"" "" \ - "test_enum_param = TestEnumParam ('print test-enum-param')" ""\ - "end" - -gdb_test "python print test_enum_param.value" "one" "Test enum parameter value" -gdb_test "show print test-enum-param" "The state of the enum is \"one\".*" "Show parameter is initial value" -gdb_py_test_silent_cmd "set print test-enum-param two" "Set parameter to enum value" 1 -gdb_test "show print test-enum-param" "The state of the enum is \"two\".*" "Show parameter is new value" -gdb_test "python print test_enum_param.value" "two" "Test enum parameter value" -gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter" - -# Test a file parameter. -gdb_py_test_multiple "file gdb parameter" \ - "python" "" \ - "class TestFileParam (gdb.Parameter):" "" \ - " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ - " show_doc = \"Show the name of the file\"" ""\ - " set_doc = \"Set the name of the file\"" "" \ - " def __init__ (self, name):" "" \ - " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \ - " self.value = \"foo.txt\"" "" \ - "test_file_param = TestFileParam ('test-file-param')" ""\ - "end" - -gdb_test "python print test_file_param.value" "foo.txt" "Test file parameter value" -gdb_test "show test-file-param" "The name of the file is \"foo.txt\".*" "Show initial file value" -gdb_py_test_silent_cmd "set test-file-param bar.txt" "Set new file parameter" 1 -gdb_test "show test-file-param" "The name of the file is \"bar.txt\".*" "Show new file value" -gdb_test "python print test_file_param.value" "bar.txt" "Test new file parameter value" -gdb_test "set test-file-param" "Argument required.*" - -# Test a file parameter. -gdb_py_test_multiple "file gdb parameter" \ - "python" "" \ - "class TestFileParam (gdb.Parameter):" "" \ - " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ - " show_doc = \"Show the name of the file\"" ""\ - " set_doc = \"Set the name of the file\"" "" \ - " def __init__ (self, name):" "" \ - " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \ - " self.value = \"foo.txt\"" "" \ - "test_file_param = TestFileParam ('test-file-param')" ""\ - "end" - -gdb_test "python print test_file_param.value" "foo.txt" "Test parameter value" -gdb_test "show test-file-param" "The name of the file is \"foo.txt\".*" "Show parameter on" -gdb_py_test_silent_cmd "set test-file-param bar.txt" "Turn off parameter" 1 -gdb_test "show test-file-param" "The name of the file is \"bar.txt\".*" "Show parameter on" -gdb_test "python print test_file_param.value" "bar.txt" "Test parameter value" -gdb_test "set test-file-param" "Argument required.*" Index: testsuite/gdb.python/py-parameter.exp =================================================================== RCS file: testsuite/gdb.python/py-parameter.exp diff -N testsuite/gdb.python/py-parameter.exp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ testsuite/gdb.python/py-parameter.exp 5 Nov 2010 16:52:53 -0000 @@ -0,0 +1,116 @@ +# 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 and 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" + +# Test a simple boolean parameter. +gdb_py_test_multiple "Simple gdb booleanparameter" \ + "python" "" \ + "class TestParam (gdb.Parameter):" "" \ + " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \ + " show_doc = \"Show whether the state of the Test Parameter does something useful\"" ""\ + " set_doc = \"Set whether the state of the Test Parameter does something useful\"" "" \ + " def __init__ (self, name):" "" \ + " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ + " self.value = True" "" \ + "test_param = TestParam ('print test-param')" ""\ + "end" + +gdb_test "python print test_param.value" "True" "Test parameter value" +gdb_test "show print test-param" "Whether the state of the Test Parameter does something useful is on.*" "Show parameter on" +gdb_py_test_silent_cmd "set print test-param off" "Turn off parameter" 1 +gdb_test "show print test-param" "Whether the state of the Test Parameter does something useful is off.*" "Show parameter off" +gdb_test "python print test_param.value" "False" "Test parameter value" +gdb_test "help show print test-param" "Show whether the state of the Test Parameter does something useful.*" "Test show help" +gdb_test "help set print test-param" "Set whether the state of the Test Parameter does something useful.*" "Test set help" +gdb_test "help set print" "set print test-param -- Set whether the state of the Test Parameter.*" "Test general help" + +# Test an enum parameter. +gdb_py_test_multiple "enum gdb parameter" \ + "python" "" \ + "class TestEnumParam (gdb.Parameter):" "" \ + " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ + " show_doc = \"Show the state of the enum\"" ""\ + " set_doc = \"Set the state of the enum\"" "" \ + " def __init__ (self, name):" "" \ + " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \ + " self.value = \"one\"" "" \ + "test_enum_param = TestEnumParam ('print test-enum-param')" ""\ + "end" + +gdb_test "python print test_enum_param.value" "one" "Test enum parameter value" +gdb_test "show print test-enum-param" "The state of the enum is \"one\".*" "Show parameter is initial value" +gdb_py_test_silent_cmd "set print test-enum-param two" "Set parameter to enum value" 1 +gdb_test "show print test-enum-param" "The state of the enum is \"two\".*" "Show parameter is new value" +gdb_test "python print test_enum_param.value" "two" "Test enum parameter value" +gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter" + +# Test a file parameter. +gdb_py_test_multiple "file gdb parameter" \ + "python" "" \ + "class TestFileParam (gdb.Parameter):" "" \ + " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ + " show_doc = \"Show the name of the file\"" ""\ + " set_doc = \"Set the name of the file\"" "" \ + " def __init__ (self, name):" "" \ + " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \ + " self.value = \"foo.txt\"" "" \ + "test_file_param = TestFileParam ('test-file-param')" ""\ + "end" + +gdb_test "python print test_file_param.value" "foo.txt" "Test file parameter value" +gdb_test "show test-file-param" "The name of the file is \"foo.txt\".*" "Show initial file value" +gdb_py_test_silent_cmd "set test-file-param bar.txt" "Set new file parameter" 1 +gdb_test "show test-file-param" "The name of the file is \"bar.txt\".*" "Show new file value" +gdb_test "python print test_file_param.value" "bar.txt" "Test new file parameter value" +gdb_test "set test-file-param" "Argument required.*" + +# Test a file parameter. +gdb_py_test_multiple "file gdb parameter" \ + "python" "" \ + "class TestFileParam (gdb.Parameter):" "" \ + " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ + " show_doc = \"Show the name of the file\"" ""\ + " set_doc = \"Set the name of the file\"" "" \ + " def __init__ (self, name):" "" \ + " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \ + " self.value = \"foo.txt\"" "" \ + "test_file_param = TestFileParam ('test-file-param')" ""\ + "end" + +gdb_test "python print test_file_param.value" "foo.txt" "Test parameter value" +gdb_test "show test-file-param" "The name of the file is \"foo.txt\".*" "Show parameter on" +gdb_py_test_silent_cmd "set test-file-param bar.txt" "Turn off parameter" 1 +gdb_test "show test-file-param" "The name of the file is \"bar.txt\".*" "Show parameter on" +gdb_test "python print test_file_param.value" "bar.txt" "Test parameter value" +gdb_test "set test-file-param" "Argument required.*"