Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Print address of pointer as well as value #3446

Closed
whereswaldon opened this issue Jul 19, 2023 · 3 comments · Fixed by #3448
Closed

Feature Request: Print address of pointer as well as value #3446

whereswaldon opened this issue Jul 19, 2023 · 3 comments · Fixed by #3448

Comments

@whereswaldon
Copy link

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)?
$ dlv version
Delve Debugger
Version: 1.20.2
Build: $Id: e0c278ad8e0126a312b553b8e171e81bcbd37f60 $
  1. What version of Go are you using? (go version)?
$ go version
go version go1.20.4 linux/amd64
  1. What operating system and processor architecture are you using?

Linux amd64

  1. What did you do?

During a debug session, I printed a pointer to a struct and got this:

(dlv) p w.EditorStyle.Editor
*gioui.org/widget.Editor {
        text: gioui.org/widget.textView {
                Alignment: Start (0),
                SingleLine: false,
                MaxLines: 0,
                Truncator: "",
                WrapPolicy: WrapHeuristically (0),
                Mask: 0,
                params: (*"gioui.org/text.Parameters")(0xc001fe3880),
                shaper: *gioui.org/text.Shaper nil,
                seekCursor: 0,
                rr: gioui.org/widget.textSource nil,
                maskReader: (*"gioui.org/widget.maskReader")(0xc001fe3918),
                graphemes: []int len: 0, cap: 0, nil,
                paragraphReader: (*"gioui.org/widget.graphemeReader")(0xc001fe3978),
                lastMask: 0,
                viewSize: (*image.Point)(0xc001fe3a08),
                valid: false,
                regions: []gioui.org/widget.Region len: 0, cap: 0, nil,
                dims: (*"gioui.org/layout.Dimensions")(0xc001fe3a38),
                offIndex: []gioui.org/widget.offEntry len: 0, cap: 0, nil,
                index: (*"gioui.org/widget.glyphIndex")(0xc001fe3a68),
                caret: (*"struct { gioui.org/widget.xoff golang.org/x/image/math/fixed.Int26_6; gioui.org/widget.start int; gioui.org/widget.end int }")(0xc001fe3b10),
                scrollOff: (*image.Point)(0xc001fe3b28),},
        Alignment: Start (0),
        SingleLine: true,
        ReadOnly: false,
        Submit: true,
        Mask: 0,
        InputHint: HintAny (0),
        MaxLen: 0,
        Filter: "",
        WrapPolicy: WrapHeuristically (0),
        buffer: *gioui.org/widget.editBuffer nil,
        scratch: []uint8 len: 0, cap: 0, nil,
        eventKey: 0,
        blinkStart: time.Time(0001-01-01T00:00:00Z){
                wall: 0,
                ext: 0,
                loc: *time.Location nil,},
        focused: false,
        requestFocus: true,
        ime: struct { gioui.org/widget.imeState; gioui.org/widget.scratch []uint8 } {
                imeState: (*"gioui.org/widget.imeState")(0xc001fe3bb0),
                scratch: []uint8 len: 0, cap: 0, nil,},
        dragging: false,
        dragger: gioui.org/gesture.Drag {
                dragging: false,
                pressed: false,
                pid: 0,
                start: (*"gioui.org/f32.Point")(0xc001fe3c20),
                grab: false,},
        scroller: gioui.org/gesture.Scroll {
                dragging: false,
                axis: Horizontal (0),
                estimator: (*"gioui.org/internal/fling.Extrapolation")(0xc001fe3c38),
                flinger: (*"gioui.org/internal/fling.Animation")(0xc001fe3e40),
                pid: 0,
                grab: false,
                last: 0,
                scroll: 0,},
        scrollCaret: false,
        showCaret: false,
        clicker: gioui.org/gesture.Click {clickedAt: 0, clicks: 0, pressed: false, hovered: false, entered: false, pid: 0},
        events: []gioui.org/widget.EditorEvent len: 0, cap: 0, nil,
        prevEvents: 0,
        history: []gioui.org/widget.modification len: 0, cap: 0, nil,
        nextHistoryIdx: 0,}
  1. What did you expect to see?

I expected to see the address of the value pointed at somewhere in the output.

  1. What did you see instead?

I have to type the following to see the address:

(dlv) p &(*w.EditorStyle.Editor)
("*gioui.org/widget.Editor")(0xc001fe3858)

This is just an ergonomics issue. There are many instances of this struct within my program, and I want to know the address easily so that I can make sure I'm looking at the right one during a debug session. It seems like it should be relatively easy to include the address at the beginning or end of the struct output.

Thanks for all the hard work on delve!

@aarzilli
Copy link
Member

You can also do: p uintptr(w.EditorStyle.Editor).

What should it look like in your opinion? Also should it only happen if the argument is a pointer or on every pointer?

@whereswaldon
Copy link
Author

Could the output read:

(dlv) p w.EditorStyle.Editor
("*gioui.org/widget.Editor")(0xc001fe3858) {
       text: gioui.org/widget.textView {
...

Basically could the format for printing "pointer to a struct" be the same as the format used when delve doesn't recurse into a field (example (*"gioui.org/text.Parameters")(0xc001fe3880), above)?

I would think it would be simplest to implement and most consistent to use if this was how every pointer was printed, but there are probably design constraints that I'm not aware of.

aarzilli added a commit to aarzilli/delve that referenced this issue Jul 22, 2023
When printing a pointer variable first print the address that it points
to before printing its dereferenced value.

Fixes go-delve#3446
derekparker pushed a commit that referenced this issue Jul 25, 2023
When printing a pointer variable first print the address that it points
to before printing its dereferenced value.

Fixes #3446
@whereswaldon
Copy link
Author

Thank you very much @aarzilli!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants