Coder Social home page Coder Social logo

neogdb.vim's Introduction

Project deprecated in favor of my another re-implement plugin vimgdb (neovim+tmux):

neogdb.vim

Vim GDB front-end for neovim: https://github.com/huawenyu/neogdb.vim
The code reference: https://github.com/neovim/neovim/blob/master/contrib/gdb/neovim_gdb.vim

feature

  • gdb commands maps: next, step, finish, continue, etc.
  • breakpoints:
    • auto save/load,
    • populate to local list: lopen
    • side color sign
    • triple state: enable -> disable -> delete
    • toggle current line/toggle-all-breakpoints
    • support condition set
  • backtrace:
    • populate to quickfix: copen

layout

+-------------------------+--------------------------+
|                         |                          |
|                         |                          |
|                         |                          |
|                         |    terminal>             |
|     Code c/c++          |    (gdb)                 |
|                         |                          |
|                         |                          |
|                         |                          |
|                         |                          |
|                         +--------------------------+
|                         |                          |
+-------------------------+  backtrace               |
| breakpoints             |                          |
|                         |                          |
+-------------------------+--------------------------+

Screen Demo

Press to toggle Nbgdb or Nbgdbattach.

gdb directly

:Nbgdb t1

gdb attach pid

So far, the attach call by sudo, so maybe we should input the sudo-password. The reason is: gdb-attach-fails-with-ptrace-operation-not-permitted

:Nbgdbattach t1 <t1-pid>

gdb remote target

:Nbgdbattach sysinit/init 10.1.1.125:444

gif

screen

Install

Install if no any plugin manager

The file structure should be clear, just copy the github.vim into ~/.vim/plugin/

Installing when using Vundle

Add the following line to the plugins regions of ~/.vimrc:

Plugin 'huawenyu/neogdb.vim'

Installing when using Pathogen

    cd ~/.vim/bundle
    git clone [email protected]:solars/github-vim.git

Usage

commands

  • :GdbLocal
  • :GdbDebugStop
  • :GdbToggleBreakpoint
  • :GdbClearBreakpoints
  • :GdbContinue
  • :GdbNext
  • :GdbStep
  • :GdbFinish
  • :GdbFrameUp
  • :GdbFrameDown
  • :GdbInterrupt
  • :GdbEvalWord
  • :GdbWatchWord

Default keymaps

  • <F2> Helper Start
  • <F4> continue
  • <F5> next
  • <F6> step
  • <F7> finish
  • <F8> util
  • <F9> Normal-mode: breakpoints
  • <F9> Select-Mode: print

Sample

There have a c file autoload/examples/t1.c in the plugin's dir. Please copy it to your test dir.

    ### compile test
    $ cd /dir/of/file/t1.c
    $ gcc -g -O0 -o t1 t1.c
    ### start gdb
    $ vi t1.c
      If default keymap, <F2>, the command line show `:Nbgdb t1`, <Enter> to start gdb.

Customization

Put these in your ~/.vimrc to customize the keymaps:

keymaps leader

If define g:neobugger_leader, will ignore all g:gdb_keymap_... customized.

let g:neobugger_leader = ';'

Then the keymaps will be g:neobugger_leader + <char>, the <char> like:

  • r: GdbRefresh
  • c: GdbContinue
  • n: GdbNext
  • i: GdbStep
  • N: GdbFinish
  • t: GdbUntil
  • b: GdbToggleBreak
  • a: GdbToggleBreakAll
  • C: GdbClearBreak
  • x: GdbDebugStop
  • k: GdbFrameUp
  • j: GdbFrameDown

keymaps without leader

let g:gdb_keymap_continue = '<f8>'
let g:gdb_keymap_next = '<f10>'
let g:gdb_keymap_step = '<f11>'
" Usually, F23 is just Shift+F11
let g:gdb_keymap_finish = '<f23>'
let g:gdb_keymap_toggle_break = '<f9>'
" Usually, F33 is just Ctrl+F9
let g:gdb_keymap_toggle_break_all = '<f33>'
let g:gdb_keymap_frame_up = '<c-n>'
let g:gdb_keymap_frame_down = '<c-p>'
" Usually, F21 is just Shift+F9
let g:gdb_keymap_clear_break = '<f21>'
" Usually, F17 is just Shift+F5
let g:gdb_keymap_debug_stop = '<f17>'

Miscellaneous

config windows

Current implement only support two kinds of windows: backtrace, breakpoint. The default config is:

  • local-mode, diable these windows
  • attach-mode, open them

But we can modify the default bahaviour by config:

let g:neogdb_window = ['backtrace', 'breakpoint']

Customize attach parameter

The Nbgdbattach always use target remote to connect a real searver which is different in everyone's env.
So we can specific a local host by put these into .vimrc:

if exists("$NBG_ATTACH_REMOTE_STR")
  let g:neogdb_attach_remote_str = $NBG_ATTACH_REMOTE_STR
else
  let g:neogdb_attach_remote_str = 'sysinit/init 192.168.0.180:444'
endif

Or define a env var NBG_ATTACH_REMOTE_STR by putting in .bashrc:

export NBG_ATTACH_REMOTE_STR="sysinit/init 192.168.0.180:444"

Enable restart

By default, if you run Nbgdb or Nbgdbattach when GDB is already started,
the plugin will send an interrupt (<c-c>) followed by a start.
This is in order to speed up the edit-compile-test cycle.
If you instead want an error to be thrown when GDB is already started, change this variable:

let g:restart_app_if_gdb_running = 0

By default, the plugin toggles the breakpoint right after pressing g:gdb_keymap_toggle_break.
If this flag is set to 1, the plugin will require you to confirm the command with Enter which lets you edit the command before issuing it:

others

let g:gdb_require_enter_after_toggling_breakpoint = 0

To send your own commands to GDB:

" Prints the value of the variable under the cursor
nmap <Space>p :call neobugger#gdb#Send("print " . expand('<cword>'))<CR>

Map and unmap callbacks

You can run your own code when Neogdb sets its keymaps.
The plugin will call NeogdbvimNmapCallback on initialization and NeogdbvimUnmapCallback on exiting, if these functions exist.

For example, you can put this in your ~/.vimrc:

function! NeogdbvimNmapCallback()
    " Let fzf.vim open files in the current window by default.
    " This is so that, when navigating files,
    " we don't switch to a new tab and thus *always* see the neogdb's splits. 
    let g:fzf_action = { 'enter': 'edit' }
endfunc

function! NeogdbvimUnmapCallback()
    " Quitting to normal editing. Let fzf.vim open files in the new tab,
    " as usual.
    let g:fzf_action = { 'enter': 'tabnew' }
endfunc

Troubleshooting by log

Enable print c-tyle log

    Plug 'huawenyu/vimlogger'

    " Also append this line to your ~/.vimrc to start our logfile
    silent! call logger#init('ALL', ['/tmp/vim.log'])

Check runtime log

  • Start vim
  • Using another terminal, off couse it's easy if you using tmux which you'll not regret to meet the tools. watching the log by tail -f /tmp/vim.log

License

Vim license, see LICENSE

neogdb.vim's People

Contributors

geneotech avatar huawenyu avatar sakhnik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

neogdb.vim's Issues

layout

Nice project.
Calling `Nbgdb' results in a layout

+---------------+
|               |
|      gdb      |
|               |
+---------------+
|               |
|      file     |
|               |
+---------------+

And not the layout described in the docs

How to change the debugger

I am developing to an ARM system and I use 'arm-linux-gnueabihf-gdb' instead of the regular gdb.
There is a way that I can change the default debugger?

Thanks

Invalid channel id when trying to restart debugger

I'm not sure if I'm exiting properly but when debugging in neovim, I'll enter stop to exit a debug session, but then when I try to start another debug session, I see the following error message in the command bar:

neobugger#Handle module[gdb].Restart() error.Vim(call):E900: Invalid channel id  

Any help with this issue would be appreciated.

module[gdb] does not exist

I love the idea of this addon but can't figure out why it won't load. This is the error I get when I run Nbgdb filename from my nvim. Is there something I am doing wrong in setting up the plugin?
2018-02-04_17 11 18

Unknown function: GdbInit

Running GdbStart gdb produces the error:

Error detected while processing function nvimgdb#Spawn:
line    1:
E117: Unknown function: GdbInit

Error when executing 'GdbLocal'

This plugin is exactly what I was looking for, but unfortunately it doesn't work for me. To test it, I compiled the following "Hello world" program (hello.cc) with debug symbols:

    // a small C++ program
    #include <iostream>
    
    int main()
    {
    	std::cout << "Hello, world!" << std::endl;
    	return 0;
    }

With the file open in Neovim, I then ran the command :GdbLocal hello. Here's an image of the error message I got. Am I doing something wrong, or is that a bug? I'm using Neovim 0.1.7 on Debian Stretch, with neogdb.vim installed using Vim-plug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.