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

add GoDebug #1390

Merged
merged 70 commits into from
Feb 27, 2018
Merged

add GoDebug #1390

merged 70 commits into from
Feb 27, 2018

Conversation

mattn
Copy link
Contributor

@mattn mattn commented Jul 27, 2017

Hi, I added debugger. Do you have interesting this?

godebug

@mattn
Copy link
Contributor Author

mattn commented Jul 27, 2017

Maybe, there are not enough commands, features, behaviors.

@arp242
Copy link
Contributor

arp242 commented Jul 27, 2017

A previous PR: #1198

@mattn
Copy link
Contributor Author

mattn commented Jul 28, 2017

status update
terminal

@fatih
Copy link
Owner

fatih commented Aug 2, 2017

@mattn so happy that you working on this. I'm on road to NYC, but hopefully gonna take a look more in detail.

I think this is possible now that vim-8 has term support. Do you know which patch version should be cap it? I think we should add something like this:

  " we use XXXtermXXX() which was introduce with 8.0.XXXXX, be sure we have
  " it: http://ftp.vim.org/vim/patches/8.0/8.0.XXX
  if !exists("*XXXtermXXX")
    call go#util#EchoError("GoDebugStart requires 'XXXtermXXX'. Update your Vim/Neovim version.")
    return
  endif

or better if you have the patch version that would be better. I think people should use an updated Vim version otherwise we have to deal with problems that are already fixed on HEAD in vim-dev.

@mattn
Copy link
Contributor Author

mattn commented Aug 2, 2017

Ultimately, I did not use vim8 terminal feature for this debugger. Just used job_xxx. So this should work on current vim8. And one more point is possible to port to neovim easily.

@arp242
Copy link
Contributor

arp242 commented Sep 7, 2017

I haven't had time to look at this before, but I just tested it and this is great stuff! It already works very well.

I made a PR on your fork with a bunch of minor changes: mattn#1; that was easier than adding comments :-) See the commit messages for details on that. I also did some work on improving and expanding the documentation a bit but didn't commit that yet; I'll finish that up later.


Some further comments (Vim 8.0.1066, Go 1.9):

  • The string v := "hello" is displayed as v: [5], and expanding it gives me
    the byte values:

      v[0]: 104
      v[1]: 101
      v[2]: 108
      v[3]: 108
      v[4]: 111
    

    Is this intentional?

  • Small thing, but you can't close expanded variables. I would expect a second
    <CR> to close it. I tried adding this in s:expand_var() but had some
    trouble grokking that function at a glance.

  • Both the the struct:

      s := struct {
      	a, b string
      	u    int64
      }{"aasd", "zxc", 42}
    

    and:

      type named struct {
      	a, b string
      	u    int64
      }
      n := named{"zxc", "qwe", 42}
    

    Give an error on expanding:

      expression "s" (struct { main.a string; main.b string; main.u int64 }) does not support indexing
      expression "n" (main.named) does not support indexing
    

    Expanding slices seems to work fine.

@arp242
Copy link
Contributor

arp242 commented Sep 10, 2017

Did some more testing, and found a few more small problems:

  • String types now show up as v: "" with this example (breaking on the fmt line):

    v := "hello"
    fmt.Println("one", v)
    
  • Using vim dbg/debug.go gives the error:

    2017/09/10 04:49:57 debugger.go:97: launching process with args: [/home/martin/go/src/a/debug ]
    Can not debug non-main package
    

    I have to use :cd dbg and then :GoDebugStart works.

  • :GoDebugRestart doesn't seem to work. I added a breakpoint and the program is paused. I changed a variable declaration line (e.g. from i := 42 to i := 43), and use :GoDebugRestart. I would expect the debugger to restart the program with the new source, but i still shows us as 42 instead of the expected 43. I need to use :GoDebugStop and :GoDebugStart to get the new version.

    Also, the debugger doesn't restart with the new source if I restart the program with F5 after it has finished. I'm not sure if it should though!

  • Pressing F5 after the program has exited messes up the window layout:
    2017-09-10-045658_906x532_scrot

    :messages has:

    API server listening at: 127.0.0.1:8181
    Process 19284 has exited with status 0
    Process 19284 has exited with status 0
    Process 19284 has exited with status 0
    
  • The current directory now has a debug binary in it, presumably from the debug.go filename. This is because it's currently using dlv debug .... Maybe it would be better to :GoInstall the binary and then use dlv exec? Or run it from a temp directory (like go run)?
    It's not a huge deal, but personally I'm not a huge fan of commands that produce unexpected side-effects like this on the filesystem.

  • Come to think of it, maybe we want to have a way for the user to add flags to dlv? Especially --build-flags would be useful for some people I think. We can also do this later maybe, if someone asks for it ("YAGNI")

@@ -381,6 +381,7 @@ function! go#debug#Start(...) abort
try
echohl SpecialKey | echomsg 'Starting GoDebug...' | echohl None
let s:state['message'] = []
exe 'lcd' fnamemodify(bufname(''), ':p:h')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this cause the current working directory to change? :pwd gives me /home/martin/go/src/a when starting vim dbg/debug.go, but it's /home/martin/go/src/a/debug after running :GoDebugStart.

Also, I get an error using :GoDebugStart with the latest changes?

can't load package: package ['--']: cannot find package "['--']" in any of:
        /usr/lib/go/src/['--'] (from $GOROOT)
        /home/martin/go/src/['--'] (from $GOPATH)
        /home/martin/work/src/['--']
exit status 1

Maybe it's worth adding some tests for this? I never really looked in to testing Vimscript stuff so I don't know how hard that is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed for ["--"].

lcd change current directory for current window.

@arp242
Copy link
Contributor

arp242 commented Sep 11, 2017

What are your plans for supporting Neovim btw @mattn? It currently errors out with Vim(let):E117: Unknown function: job_start.

@mattn
Copy link
Contributor Author

mattn commented Sep 11, 2017

Go debugger uses JSON-RPC to communicate with dlv debugger. neovim support TCP connection?

@arp242
Copy link
Contributor

arp242 commented Sep 11, 2017

I don't know; never looked in to Neovim's implementation in detail.

Personally I'm fine with not adding support for that in this PR if it's hard, but then we should add a clear error message for that similar to the Vim 7.4 error (if has('nvim') [...]).

@fatih
Copy link
Owner

fatih commented Sep 11, 2017

We should not add NeoVim now. First, let finish making the UX and usability right. And then fix bugs and co. once it's in master. Neovim can wait as Vim-go aims to be a Vim first class plugin rather than supporting both nvim and vim.

@arp242 arp242 added the wip label Sep 21, 2017
mattn pushed a commit to mattn/vim-go that referenced this pull request Sep 23, 2017
As it's not yet supported; otherwise it will give a confusing error.

fatih#1390 (comment)
arp242 added a commit to mattn/vim-go that referenced this pull request Nov 23, 2017
As it's not yet supported; otherwise it will give a confusing error.

fatih#1390 (comment)
@arp242
Copy link
Contributor

arp242 commented Nov 28, 2017

This PR currently depends on this delve PR, but after that's merged this PR should be ready to be merged @mattn @fatih @bhcleek. Testing and/or feedback appreciated!

There are some areas that might need some further improving – there always are – but overall it works well and I don't expect any further major changes to the :GoDebug commands.

It's currently a bit slow for larger packages because dlv builds the binary with -a, skipping the cache. This is so that it can add the -gcflags "-N -l" compile flags (the cached packages may not have that). Luckily this will be fixed for us in Go 1.10 which has the ability to keep different caches for different build flags.

Aside from the :GoDebug* commands this also adds a g:go_debug setting to debug vim-go itself. See this commit. Other than this, all changes are limited to :GoDebug* commands.

See :help go-debug for documentation.

@arp242 arp242 removed the wip label Nov 28, 2017
@fatih
Copy link
Owner

fatih commented Jan 4, 2018

I want to test it before we merge it. Please don't merge it until then. I appreciate all the hard work btw, I think this is going to be one of the biggest addition in 2018 :)

I think this command makes more sense, as it "prints the result from an
expression". It's also the command that the dlv commandline uses (`p` or
`print`).
I'm not sure when this is useful? Remove for now.
- Delve needs `stepOut`, not `stepout`. This took me an insane amount of
  time to track down :-/
- Add `debugger-commands` to `g:go_debug`; useful to track down the
  above.
- Remove stepin, as Delve doesn't seem to support that. The current
  implementation doesn't do anything, and it's not listed as one of the
  constants in `service/api/types.go` (around like 265).
Much better UX, I think. Especially since starting dlv can take a
bit; this will reduce the time people will need spend fiddling their
thumbs.
Need to remove the BufWipe events, as that would cause problems with
them stopping the newly created async job.
Not sure if that was a good idea in the first place to be honest, why
shouldn't I be allowed to remove one of the windows from the layout?
Otherwise hovering over a string and lots of other stuff will show
errors.
@@ -28,7 +29,6 @@ This plugin adds Go language support for Vim, with the following main features:
errors, or make sure errors are checked with `:GoErrCheck`.
* Advanced source analysis tools utilizing `guru`, such as `:GoImplements`,
`:GoCallees`, and `:GoReferrers`.
* Precise type-safe renaming of identifiers with `:GoRename`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this removed accidentally?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, at some point it was decided to keep the top 10 or 15 points from the help file here instead of all. So I removed the bottom one after I added the debug feature.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the automatic gopath detection line and keep this? I think the GOPATH one can change as it's less relevant nowadays.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sounds good

doc/vim-go.txt Outdated
DEBUGGER COMMANDS~

Only |:GoDebugStart| and |:GoDebugBreakpoint| are available by default; the
rest of the commands become available after starting debug mode.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commands and mappings... Worth noting that we also create default mappings

doc/vim-go.txt Outdated
in with |:GoDebugStep| (<F11>).

Struct values are displayed as `{...}`, array/slices as `[4]`. Use <CR> on the
variable name to expand the values.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, but I didn't know I had to go to the GODEBUG_VARIABLES window. Worth adding this little piece. Actually we should document more each window. We just mentioned them briefly above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I rephrased it a bit and added some more info.

doc/vim-go.txt Outdated
variable name to expand the values.

When you're done use |:GoDebugStop| to close the debugging windows and halt
the `dlv` process, or |:GoDebugRestart| to recompile the code.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I clear previously set breakpoints? Even though I've stopped or restarted the server, the breakpoints are still intact. Is this something we can provide to the user? Seems like there is no way to remove all breakpoints right now and you have to manually remove them one by one.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it seems like restarting Vim does remove all breakpoints

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a :GoDebugReset command maybe?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap definitely, I think this is much needed otherwise one has to close and restart Vim (which is not something we want to do). Also another thing that I've just seen is, when you change or remove the lines, the breakpoint lines will be invalid. Not %100 related to this, but worth adding as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you change or remove the lines, the breakpoint lines will be invalid. Not %100 related to this, but worth adding as well.

How do other debuggers handle this? Move the breakpoint, or just clear it?

Copy link
Owner

@fatih fatih Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In VSCode it moves when you add newlines. So it's dynamic to the content of the line. But not sure if it's worth adding that kind of complexity. But one thing I appreciate is the way to disable/enable breakpoints. This allows to temporary run the whole stack without getting blocked. And they also have something to reset all the breakpoints. So I think we need the following commands:

:GoDebugToggleBreakpoint (current :GoDebugBreakpoint, we can keep this)
:GoDebugDisableBreakpoints
:GoDebugEnableBreakpoints
:GoDebugRemoveBreakpoints

Also I think :GoDebugReset would be confusing with :GoDebugRestart. So don't let us use :GoDebugReset (Instead let's use :GoDebugRemoveBreakpoints), instead let's have the above dedicated commands. We can add :GoDisableBreakpoints and :GoEnableBreakpoints later if it's to much work. Wdyt?

(Here is the Debug menu from VSCode)

screen shot 2018-02-27 at 6 08 20 pm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure of adding four new commands, I find it more annoying to use as e.g. :GoDebug<Tab> now has many more commands that are pretty much the same.

I think a better way is to use e.g.:

:GoDebugBreakpoint 42         " Toggle breakpoint for a line (add/remove)
:GoDebugBreakpoint toggle     " Toggle all
:GoDebugBreakpoint disable    " Disable all
:GoDebugBreakpoint enable     " Enable all 
:GoDebugBreakpoint remove     " Remove all

That being said, I think we should make an issue for this after merging this. It definitely should be done one way or the other, but I don't think it's a critical feature to add right now.

Same applies to the other issue with the wrong line. It's definitely something that needs to be improved, but not necessarily in this PR. It's already a large PR, and tracking all comments on GitHub is kind of hard.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with that. Let's talk about the UI changes later (command and co).

@fatih
Copy link
Owner

fatih commented Feb 26, 2018

Thanks a lot for the hard work. There are couple of things that I think needs clarification, otherwise it looks good.

@codecov-io
Copy link

codecov-io commented Feb 26, 2018

Codecov Report

Merging #1390 into master will decrease coverage by 2.5%.
The diff coverage is 0.18%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1390      +/-   ##
=========================================
- Coverage    22.2%   19.7%   -2.51%     
=========================================
  Files          53      57       +4     
  Lines        4197    4735     +538     
=========================================
+ Hits          932     933       +1     
- Misses       3265    3802     +537
Flag Coverage Δ
#nvim 15.1% <0.18%> (-1.92%) ⬇️
#vim74 17.31% <0.18%> (-2.2%) ⬇️
#vim80 18.62% <0.18%> (-2.37%) ⬇️
Impacted Files Coverage Δ
plugin/go.vim 29.26% <ø> (ø) ⬆️
autoload/go/debug.vim 0% <0%> (ø)
syntax/godebugvariables.vim 0% <0%> (ø)
syntax/godebugstacktrace.vim 0% <0%> (ø)
syntax/godebugoutput.vim 0% <0%> (ø)
ftplugin/go/commands.vim 0% <0%> (ø) ⬆️
autoload/go/util.vim 60.91% <33.33%> (-0.12%) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39beabe...9290447. Read the comment docs.

@fatih
Copy link
Owner

fatih commented Feb 27, 2018

@mattn @Carpetsmoker lgtm. This is ready to be merged. let's merge this and then open new PR's upon feedback and things we see later (such as the breakpoint improvements). Thanks again for all the hard work, much appreciated.

@mattn
Copy link
Contributor Author

mattn commented Feb 28, 2018

Great. Thank you!

mattn added a commit to mattn/blog that referenced this pull request Mar 27, 2019
See fatih/vim-go#1390

Change-Id: I5d79ce162d466351ca54e435183e4e2e3151ad2c
GitHub-Last-Rev: 4ec9a16
GitHub-Pull-Request: golang#21
gopherbot pushed a commit to golang/blog that referenced this pull request Mar 27, 2019
See fatih/vim-go#1390

Change-Id: I59a45a207b68d08c53d4f16ff4240a28d145c1a1
Reviewed-on: https://go-review.googlesource.com/c/blog/+/169537
Reviewed-by: Austin Clements <austin@google.com>
gopherbot pushed a commit to golang/website that referenced this pull request May 26, 2021
See fatih/vim-go#1390

Change-Id: I59a45a207b68d08c53d4f16ff4240a28d145c1a1
Reviewed-on: https://go-review.googlesource.com/c/blog/+/169537
Reviewed-by: Austin Clements <austin@google.com>
X-Blog-Commit: 6bedf551f6d7d21cf7f656a0748ca65bf387b884
passionSeven added a commit to passionSeven/website that referenced this pull request Oct 18, 2022
See fatih/vim-go#1390

Change-Id: I59a45a207b68d08c53d4f16ff4240a28d145c1a1
Reviewed-on: https://go-review.googlesource.com/c/blog/+/169537
Reviewed-by: Austin Clements <austin@google.com>
X-Blog-Commit: 6bedf551f6d7d21cf7f656a0748ca65bf387b884
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants