delve icon indicating copy to clipboard operation
delve copied to clipboard

Make `list` display the next set of lines when the empty command is sent

Open dmlary opened this issue 4 years ago • 7 comments

Note: This is a feature request.

Please answer the following before submitting your issue:

Note: Please include any substantial examples (debug session output, stacktraces, etc) as linked gists.

  1. What version of Delve are you using (dlv version)?
Delve Debugger
Version: 1.4.0
Build: $Id: 67422e6f7148fa1efa0eac1423ab5594b223d93b $
  1. What version of Go are you using? (go version)? go version go1.14.2 linux/amd64

  2. What operating system and processor architecture are you using? x86_64 GNU/Linux

  3. What did you do?

  • list <func> # output 10 lines of code
  • <pressed enter> # output same 10 lines of code
  1. What did you expect to see?

Next 10 lines of code, similar to gdb & lldb. Makes displaying source while debugging more convenient.

  1. What did you see instead?

The same 10 lines of code

Example:

(dlv) list snode.attr
Showing /go/pkg/mod/bazil.org/[email protected]/fs/serve.go:492 (PC: 0x56d9d3)
 487:		//     - hold Server.meta while calling wg.Add, then unlock
 488:		//     - do NOT try to reacquire Server.meta
 489:		wg sync.WaitGroup
 490:	}
 491:
 492:	func (sn *serveNode) attr(ctx context.Context, attr *fuse.Attr) error {
 493:		err := nodeAttr(ctx, sn.node, attr)
 494:		if attr.Inode == 0 {
 495:			attr.Inode = sn.inode
 496:		}
 497:		return err
(dlv)
Showing /go/pkg/mod/bazil.org/[email protected]/fs/serve.go:492 (PC: 0x56d9d3)
 487:		//     - hold Server.meta while calling wg.Add, then unlock
 488:		//     - do NOT try to reacquire Server.meta
 489:		wg sync.WaitGroup
 490:	}
 491:
 492:	func (sn *serveNode) attr(ctx context.Context, attr *fuse.Attr) error {
 493:		err := nodeAttr(ctx, sn.node, attr)
 494:		if attr.Inode == 0 {
 495:			attr.Inode = sn.inode
 496:		}
 497:		return err

dmlary avatar Apr 25 '20 18:04 dmlary

There's an edit command that can open the source code at the current line. You can even set it up to open the source in a different window easily. I've always thought the behavior of list in gdb was archaic, designed for physical teletypes from the '70s.

aarzilli avatar Apr 26 '20 15:04 aarzilli

It is archaic, but occasionally you're working in an environment like that. For example, writing a user-space filesystem with bazil.org/fuse on a mac, which doesn't support mac, I'm forced to run all tests & debugging within a docker image.

dmlary avatar Apr 26 '20 16:04 dmlary

+1 Also, there should be a way to see the previous lines and to set the number of lines printed when issuing list.

jginsburgn avatar Jul 22 '22 08:07 jginsburgn

Not to derail OP's original issue, but I would like to add my +1 to @jginsburgn's suggestion:

set the number of lines printed when issuing list.

It would be useful to be able to print more than the 5 lines either side of the current line, similar to grep's A, B and C flags.

jcass8695 avatar Oct 17 '22 13:10 jcass8695

That can already be done:

(dlv) config source-list-line-count 10

aarzilli avatar Oct 17 '22 13:10 aarzilli

I think it might be more intuitive and user-friendly to have something like list -A 15 -B 12 or list -C 17. If you know roughly where in the codebase I could get started, I might have time over the next few weekends to take a look.

jcass8695 avatar Oct 17 '22 13:10 jcass8695

List takes a location expression as an argument, which can be anything. It's difficult to change it to also take other arguments in an unambiguous way. Also I still think there's little need for this when there's edit.

aarzilli avatar Oct 17 '22 13:10 aarzilli

Fair enough 👍🏻

jcass8695 avatar Oct 18 '22 09:10 jcass8695