2009-10-05 Doug Evans Make "directories" a variable so gdb.parameter ("directories") works from python. * source.c (source_path_1): New static global. (set_directories_command): New function. (show_directories_1): Renamed from show_directories, all callers updated. (show_directories_command): New function. (_initialize_source): Remove "directories" add_cmd, replace with add_setshow_optional_filename_cmd. * testsuite/gdb.base/help.exp (show directories): Update expected output. Index: source.c =================================================================== RCS file: /cvs/src/src/gdb/source.c,v retrieving revision 1.104 diff -u -p -r1.104 source.c --- source.c 22 Sep 2009 22:34:17 -0000 1.104 +++ source.c 6 Oct 2009 18:06:54 -0000 @@ -66,7 +66,10 @@ static void line_info (char *, int); static void source_info (char *, int); -static void show_directories (char *, int); +/* "set directories foo" stores the value here, + which is later copied to SOURCE_PATH by set_directories. */ + +static char *source_path_1; /* Path of directories to search for source files. Same format as the PATH environment variable's value. */ @@ -303,13 +306,36 @@ select_source_symtab (struct symtab *s) } static void -show_directories (char *ignore, int from_tty) +set_directories_command (char *args, int from_tty, struct cmd_list_element *c) +{ + /* "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. */ + + /* 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 + SOURCE_PATH_1 then mod_path will move them appropriately. + mod_path will also remove duplicates. */ + xfree (source_path); + init_source_path (); + if (*source_path_1 != '\0') + mod_path (source_path_1, &source_path); +} + +static void +show_directories_1 (char *ignore, int from_tty) { puts_filtered ("Source directories searched: "); puts_filtered (source_path); puts_filtered ("\n"); } +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. */ @@ -381,7 +407,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. @@ -1926,6 +1952,7 @@ void _initialize_source (void) { struct cmd_list_element *c; + current_source_symtab = 0; init_source_path (); @@ -1948,16 +1975,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_1, + _("\ +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 paths 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: testsuite/gdb.base/help.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/help.exp,v retrieving revision 1.35 diff -u -p -r1.35 help.exp --- testsuite/gdb.base/help.exp 13 Aug 2009 14:58:27 -0000 1.35 +++ testsuite/gdb.base/help.exp 6 Oct 2009 18:06:54 -0000 @@ -513,7 +513,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