Bug 17669 - edit command wrong source line
Summary: edit command wrong source line
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: cli (show other bugs)
Version: 7.8
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 23337 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-12-02 15:26 UTC by Jason Kraftcheck
Modified: 2019-01-10 09:30 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Kraftcheck 2014-12-02 15:26:19 UTC
The source line passed to the editor for the 'edit' command appears to consistently be off by five.  The script below will produce this output:

  Breakpoint 1, main () at test.c:3
  3	  int i = 5;
  edit +8 /tmp/test.c
  
Note that source line is 3.  Line number passed to editor is 8.


#!/bin/sh

GDB=${HOME}/opt/gdb-7.8.1/bin/gdb

cat >test.c <<end_of_source
int main()
{
  int i = 5;
  int j = 6;
  int k = 1;
  return i - j + k;
}
end_of_source

gcc test.c -g -o test

cat <<end_of_gdb | EDITOR=echo $GDB test
b 2
r
edit
q
end_of_gdb
Comment 1 Jason Kraftcheck 2014-12-02 15:28:30 UTC
Script and output don't quite match up.  Corrected script (cosmetic change).

#!/bin/sh

GDB=${HOME}/opt/gdb-7.8.1/bin/gdb

cat >test.c <<end_of_source
int main()
{
  int i = 5;
  int j = 6;
  int k = 1;
  return i - j + k;
}
end_of_source

gcc test.c -g -o test

cat <<end_of_gdb | EDITOR="echo edit" $GDB test
b 2
r
edit
q
end_of_gdb
Comment 2 dje 2014-12-02 20:17:47 UTC
I wonder if this is related to the list window size.

Yeah, simple experiments suggest it is.

E.g., do "set listsize 1", and I get the cursor on the right line.
Comment 3 Tom Tromey 2018-11-15 16:26:35 UTC
*** Bug 23337 has been marked as a duplicate of this bug. ***
Comment 4 Lluís Batlle 2019-01-10 09:30:44 UTC
The bug is in edit_command since 2002 very annoying also to me, where it adds listsize/2 to the src line.

Can someone maintainer quickly remove this line?

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/cli/cli-cmds.c;h=4694553b7ddf8e37dc1834e9bbcd6f7a14549bbd;hb=15146ff7370d5abad01dbecfacb0bf0e66a93cd6#l787

Line to be deleted:
sal.line += get_lines_to_list () / 2;