diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4e429f4fa371..eb855819e7c8 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2019-02-19 Simon Marchi + + * top.h (source_file_name): Change to std::string. + * top.c (source_file_name): Likewise. + (command_line_input): Adjust. + * cli/cli-script.c (script_from_file): Adjust. + 2019-02-19 Tom Tromey * ravenscar-thread.c diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index aaead00a101c..85f00c75b3ff 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -1537,8 +1537,9 @@ script_from_file (FILE *stream, const char *file) scoped_restore restore_line_number = make_scoped_restore (&source_line_number, 0); - scoped_restore resotre_file - = make_scoped_restore (&source_file_name, file); + scoped_restore restore_file + = make_scoped_restore (&source_file_name, + file); scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); @@ -1552,7 +1553,7 @@ script_from_file (FILE *stream, const char *file) prepended. */ throw_error (e.error, _("%s:%d: Error in sourced command file:\n%s"), - source_file_name, source_line_number, e.message); + source_file_name.c_str (), source_line_number, e.message); } END_CATCH } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index f50f1e3aca49..cd2a654ca588 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2019-02-19 Simon Marchi + + * gdb.base/source.exp: Move "error in sourced script" code to + the end. + * gdb.base/source-error.gdb: Move contents to + source-error-1.gdb. Add new code to source source-error-1.gdb. + * gdb.base/source-error-1.gdb: New file, from previous + source-error.gdb. + 2019-02-17 Tom Tromey * gdb.base/style.exp: Use -g3 to compile when possible. Add test diff --git a/gdb/testsuite/gdb.base/source-error-1.gdb b/gdb/testsuite/gdb.base/source-error-1.gdb new file mode 100644 index 000000000000..c879fd2af6f0 --- /dev/null +++ b/gdb/testsuite/gdb.base/source-error-1.gdb @@ -0,0 +1,22 @@ +# This testcase is part of GDB, the GNU debugger. + +# Copyright 2005-2019 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 . + +# Test GDB's "source" command - reads in a GDB script. + +echo working line\n +x 0 +echo should not reach this line\n diff --git a/gdb/testsuite/gdb.base/source-error.gdb b/gdb/testsuite/gdb.base/source-error.gdb index c879fd2af6f0..85e0d9f8cf11 100644 --- a/gdb/testsuite/gdb.base/source-error.gdb +++ b/gdb/testsuite/gdb.base/source-error.gdb @@ -1,6 +1,6 @@ # This testcase is part of GDB, the GNU debugger. -# Copyright 2005-2019 Free Software Foundation, Inc. +# Copyright 2019 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 @@ -17,6 +17,4 @@ # Test GDB's "source" command - reads in a GDB script. -echo working line\n -x 0 -echo should not reach this line\n +source source-error-1.gdb diff --git a/gdb/testsuite/gdb.base/source.exp b/gdb/testsuite/gdb.base/source.exp index c6ff65783da0..a8fef098f100 100644 --- a/gdb/testsuite/gdb.base/source.exp +++ b/gdb/testsuite/gdb.base/source.exp @@ -23,10 +23,6 @@ standard_testfile structs.c gdb_start -gdb_test "source ${srcdir}/${subdir}/source-error.gdb" \ - "source-error.gdb:21: Error in sourced command file:\[\r\n\]*Cannot access memory at address 0x0.*" \ - "script contains error" - gdb_test "source -v ${srcdir}/${subdir}/source-test.gdb" \ "echo test source options.*" \ "source -v" @@ -66,4 +62,14 @@ gdb_test "source for-sure-nonexistant-file" \ gdb_test "source source-nofile.gdb" \ "warning: for-sure-nonexistant-file: No such file or directory\.\[\r\n\]*source error not fatal" -gdb_exit + +# Test commands that error out in sourced files, including in nested sourced +# files. +# +# This needs to come after the "dir" command tested above for source-error.gdb +# to find source-error-1.gdb. +gdb_test "source ${srcdir}/${subdir}/source-error.gdb" \ + [multi_line ".*source-error.gdb:20: Error in sourced command file:" \ + "source-error-1.gdb:21: Error in sourced command file:" \ + "Cannot access memory at address 0x0" ] \ + "script contains error" diff --git a/gdb/top.c b/gdb/top.c index c756a6978e8d..22e6f7e29ab9 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -400,7 +400,7 @@ quit_cover (void) /* NOTE 1999-04-29: This variable will be static again, once we modify gdb to use the event loop as the default command loop and we merge event-top.c into this file, top.c. */ -/* static */ const char *source_file_name; +/* static */ std::string source_file_name; /* Read commands from STREAM. */ void @@ -1221,7 +1221,7 @@ command_line_input (const char *prompt_arg, const char *annotation_suffix) gdb_flush (gdb_stdout); gdb_flush (gdb_stderr); - if (source_file_name != NULL) + if (!source_file_name.empty ()) ++source_line_number; if (from_tty && annotation_level > 1) diff --git a/gdb/top.h b/gdb/top.h index 1d860188c6da..025d9389d601 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -281,7 +281,7 @@ extern void gdb_init (char *); /* For use by event-top.c. */ /* Variables from top.c. */ extern int source_line_number; -extern const char *source_file_name; +extern std::string source_file_name; extern int history_expansion_p; extern int server_command; extern char *lim_at_start;