forked from Imagelibrary/binutils-gdb
This commit was inspired by this mailing list post: https://inbox.sourceware.org/gdb-patches/osmtfvf5xe3yx4n7oirukidym4cik7lehhy4re5mxpset2qgwt@6qlboxhqiwgm When reviewing that patch, the first thing I wanted to do was add some tests for the 'edit' command because, as far as I can tell, there are no real tests right now. The approach I've taken for testing is to override the EDITOR environment variable, setting this to just 'echo'. Now when the 'edit' command is run, instead of entering an interactive editor, the shell instead echos back the arguments that GDB is trying to pass to the editor. The output might look like this: (gdb) edit +22 /tmp/gdb/testsuite/gdb.base/edit-cmd.c (gdb) We can then test this like any other normal command. I then wrote some basic tests covering a few situations like, using 'edit' before the inferior is started. Using 'edit' without any arguments, and using 'edit' with a line number argument. There are plenty of cases that are still not tested, for example, the test program only has a single source file for example. But we can always add more tests later. I then used these tests to validate the fix proposed in the above patch. The patch above does indeed fix some cases, specifically, when GDB stops at a location (e.g. a breakpoint location) and then the 'edit' command without any arguments is fixed. But using the 'list' command to show some other location, and then 'edit' to edit the just listed location broken before and after the above patch. I am instead proposing this alternative patch which I think fixes more cases. When GDB stops at a location then 'edit' with no arguments should correctly edit the current line. And using 'list XX' to list a specific location, followed by 'edit' should also now edit the just listed location. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=17669 Co-Authored-By: Lluís Batlle i Rossell <viric@viric.name> Approved-By: Tom Tromey <tom@tromey.com>
56 lines
1.2 KiB
C
56 lines
1.2 KiB
C
/* This testcase is part of GDB, the GNU debugger.
|
|
|
|
Copyright 2024 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 <http://www.gnu.org/licenses/>. */
|
|
|
|
/* Used so we have some work to do. */
|
|
volatile int global_var = 0;
|
|
|
|
int
|
|
main (void)
|
|
{ /* prologue location */
|
|
++global_var; /* first location */
|
|
|
|
/*
|
|
*
|
|
*
|
|
* This comment is here as filler.
|
|
*
|
|
*
|
|
*/
|
|
|
|
++global_var; /* second location */
|
|
|
|
/*
|
|
*
|
|
*
|
|
* This comment is also here as filler.
|
|
*
|
|
*
|
|
*/
|
|
|
|
++global_var; /* third location */
|
|
|
|
/*
|
|
*
|
|
*
|
|
* This is yet another filler comment.
|
|
*
|
|
*
|
|
*/
|
|
|
|
return 0; /* fourth location */
|
|
}
|