[ GDB ]
gdb中查看源代码执行路径
tui就是 terminal UI的意思
gdb -tui 代码窗口相关命令:
info win 显示窗口的大小
layout next 切换到下一个布局模式
layout prev 切换到上一个布局模式
layout src 只显示源代码
layout asm 只显示汇编代码
layout split 显示源代码和汇编代码
layout regs 增加寄存器内容显示
focus cmd/src/asm/regs/next/prev 切换当前窗口
refresh 刷新所有窗口
tui reg next 显示下一组寄存器
tui reg system 显示系统寄存器
update 更新源代码窗口和当前执行点
winheight name +/- line 调整name窗口的高度
tabset nchar 设置tab为nchar个字符
gdb在执行中,会自动跟踪代码
调用gdb编译需要在cc后面加 -g参数再加-o;
[root@redhat home]#gdb 调试文件:启动gdb
(gdb) l :(字母l)从第一行开始列出源码
(gdb) break n :在第n行处设置断点
(gdb) break func:在函数func()的入口处设置断点
(gdb) info break: 查看断点信息
(gdb) r:运行程序
(gdb) n:单步执行
(gdb) c:继续运行
(gdb) p 变量 :打印变量的值
(gdb) bt:查看函数堆栈
(gdb) finish:退出函数
(gdb) shell 命令行:执行shell命令行
(gdb) set args 参数:指定运行时的参数
(gdb) show args:查看设置好的参数
(gdb) show paths:查看程序运行路径;
set environment varname [=value] 设置环境变量。如:set env USER=hchen;
show environment [varname] 查看环境变量;
(gdb) cd 相当于shell的cd;
(gdb)pwd :显示当前所在目录
(gdb)info program: 来查看程序的是否在运行,进程号,被暂停的原因。
(gdb)clear 行号n:清除第n行的断点
(gdb)delete 断点号n:删除第n个断点
(gdb)disable 断点号n:暂停第n个断点
(gdb)enable 断点号n:开启第n个断点
(gdb)step:单步调试如果有函数调用,则进入函数;与命令n不同,n是不进入调用的函数的
注意 :如果运行list 命令得到类似如下的打印,那是因为在编译程序时没有加入 -g 选项: (gdb) list 1 ../sysdeps/i386/elf/start.S: No such file or directory. in ../sysdeps/i386/elf/start.S |
当然,gdb的功能远不止这些,包括多进程/多线程/信号/远程调试等功能在这里均没有提及,有需要的读者可以参考其它信息。
#sudo apt-cache search vim
exuberant-ctags - build tag file indexes of source code definitions
linuxdoc-tools - convert LinuxDoc SGML source into other formats
vim - Vi IMproved - enhanced vi editor
vim-common - Vi IMproved - Common files
vim-dbg - Vi IMproved - enhanced vi editor (debugging symbols)
vim-doc - Vi IMproved - HTML documentation
vim-gnome - Vi IMproved - enhanced vi editor - with GNOME2 GUI
vim-gui-common - Vi IMproved - Common GUI files
vim-runtime - Vi IMproved - Runtime files
vim-tiny - Vi IMproved - enhanced vi editor - compact version
transcode-utils - Transcode utility programs
apvlv - PDF viewer with Vim-like behaviour
bicyclerepair - A refactoring tool for python
bleachbit - delete unnecessary files from the system
cernlib-base - CERNLIB data analysis suite - common files
colordiff - tool to colorize 'diff' output
cream - VIM macros that make the VIM easier to use for beginners
dmtcp - Checkpoint/Restart functionality for Linux processes
dmtcp-dbg - Debug package for dmtcp
editmoin - edit MoinMoin wiki pages with your favourite editor
elvis-tiny - Tiny vi compatible editor for the base system
fim - a scriptable frame buffer and ascii art image viewer
get-flash-videos - Video downloader for various Flash-based video hosting sites
global - Source code search and browse tools
glogg - A smart interactive log explorer using Qt4
gramadoir - Irish language grammar checker (integration scripts)
jvim-canna - Japanized VIM (Canna version)
jvim-doc - Documentation for jvim (Japanized VIM)
libdmtcpaware-dev - DMTCP programming interface -- developer package
libdmtcpaware1 - DMTCP programming interface
liblatex-table-perl - Perl extension for the automatic generation of LaTeX tables
libtext-findindent-perl - module to heuristically determine indentation style
libtext-vimcolor-perl - syntax color text in HTML or XML using Vim
libvi-quickfix-perl - Perl support for vim's QuickFix mode
netrik - text mode WWW browser with vi like keybindings
notmuch-vim - thread-based email index, search and tagging (vim interface)
nvi - 4.4BSD re-implementation of vi
nvi-doc - 4.4BSD re-implementation of vi - documentation files
nvi - 4.4BSD re-implementation of vi
nvi-doc - 4.4BSD re-implementation of vi - documentation files
ocaml-tools - tools for OCaml developers
openshot - Create and edit videos and movies
pms - Practical Music Search, an MPD client
ranger - File manager with an ncurses frontend written in Python
shorlfilter - Text filter to shorten long URLs using online redirection database
sisu - documents - structuring, publishing in multiple formats and search
tmux - terminal multiplexer
txt2regex - A Regular Expression "wizard", all written with bash2 builtins
uzbl - Lightweight Webkit browser following the UNIX philosophy
vim-addon-manager - manager of addons for the Vim editor
vim-athena - Vi IMproved - enhanced vi editor - with Athena GUI
vim-gtk - Vi IMproved - enhanced vi editor - with GTK2 GUI
vim-latexsuite - view, edit and compile LaTeX documents from within Vim
vim-lesstif - Vi IMproved - enhanced vi editor (transitional package)
vim-nox - Vi IMproved - enhanced vi editor
vim-rails - plugins for vim to allow easier editing of Rails Applications
vim-scripts - plugins for vim, adding bells and whistles
vim-syntax-go - Syntax files to highlight Go in the Vim editor
vim-syntax-gtk - Syntax files to highlight GTK+ keywords in vim
vim-vimoutliner - script for building an outline editor on top of Vim
vimhelp-de - Vi IMproved - Documentation files (German translation)
zathura - PDF viewer with a minimalistic interface
kdesdk-scripts - scripts and data files for development
vim-puppet - syntax highlighting for puppet manifests in vim
搜索发现apt源没有什么vim gdb整合的软件,意外发现有一些有用的包,可以根据个人需求安装.
sudo apt-get install colordiff
google之后,发现可以通过安装vimgdb实线vim和gdb的整合
[ Useful Link ]
Vim How-to
http://users.skynet.be/antoine.mechelynck/vim/index.htm
Vim Org - Downloading Vim
http://www.vim.org/download.php
vimgdb : Emacs like gdb interface to cterm vim
http://www.vim.org/scripts/script.php?script_id=3039
This script provides an emacs like GDB interface to vim. Woks in cygwin and unix terminals (no need for +clientserver).
Start the program like this
vimgdb <gdb-params> <exe-file> <exe-params>
This will open vim with two windows. Type the gdb commands in bottom window. The top window will show the current file line and breakpoints highlighted.
You can also jump to top window and use the following keys
<F6> run
<F5> continue
<F7> step into
<F8> step over
<F9> toggle break point
Ctr-p Watch the variable under Cursor/Visual selection
watch the output/variables in bottom window.
Known Bugs:
Don't use the quit gdb command (that will hang the vim), instead quit the vim.
install details |
copy the vimgdb, vimgdb_msg to any directory in the system path
|
clewn gdb
Clewn implements full gdb support in the vim editor: breakpoints, watch variables, gdb command completion, assembly windows, etc.
This may be done with clewn or vimGdb. There is also a third way with pyclewn, apython program with more features than clewn and vimGdb, and a tight integration in Vim. See the pyclewn web site for a table listing the differences between all three programs.
Clewn is a program controlling vim through the netBeans socket interface, it runs concurrently with vim and talks to vim. Clewn can only be used with gvim, the graphical implementation of vim, as vim on a terminal does not support netBeans. VimGdb is a vim patch implemented as a vim optional feature.
Both alternatives use the same base source code to interface with gdb. Clewn, as a standalone process, needs its own terminal. This is not the case with vimGdb, but a drawback is that a different patch must be applied to each new Vim version.
They both share the same features set, except clewn supports some features that vimGdb does not have:
mainpage: http://clewn.sourceforge.net/
userguide: http://clewn.sourceforge.net/doc.html
http://blog.csdn.net/dduwayne/article/details/6595674
CGDB
http://cgdb.sourceforge.net/
CGDB is a curses (terminal-based) interface to the GNU Debugger (GDB). Its goal is to be lightweight and responsive; not encumbered with unnecessary features.
The primary feature of CGDB is the constant presence of a source display (screenshots), updated as the program executes, to help keep you focused while debugging. The interface is inspired by the classic Unix text editor, vi. Those familiar with vi (or vim) should feel right at home using CGDB.
The following table lists the differences between clewn, vimGdb and pyclewn.
vimGdb clewn pyclewn platform unix unix all unix platforms supported by python - requires GNU gdb from macports on Mac Os X
Windows (Python 3 only)
language C C Python 2.4 and above Python 3 vim mode vim in a terminal, gvim gvim vim in a terminal (vim 7.3 or aboverequired), gvim vim interface a vim patch a standalone program connected to gvim with a netbeans socket a standalone program connected to vim with a netbeans socket
pyclewn may be started from within vim
vim version a different patch for each vim version vim 6.3 and above vim 7.0 and above debuggers gdb gdb gdb, pdb gdb features
- watched variables
- project file
- tight integration with vim
- gdb/mi interface
- asynchronous gdb commands
- watched variables
- project file
pdb features
- interrupt the debuggee
- attach to a running python process
- the threadstack command
[ Blog ]
gdb简单入门教程
http://os.chinaunix.net/a2005/1211/967/000000967327.shtml
http://fanqiang.chinaunix.net/program/other/2006-07-14/4834.shtml
http://bzhang.iteye.com/blog/376214
gdb中汇编调试
http://blog.sina.com.cn/s/blog_535413540100a82y.html
vim gdb ddd xxgdb精彩的程序调试
http://easwy.com/blog/archives/advanced-vim-skills-vim-gdb-vimgdb/
[ Q&A ]
Q:
上网搜安装教程,安装vim7.2 + vimgdb补丁,那么系统自带的vim7.3怎么办?
A:
可以安装到其它目录就好了,比如/opt或/home/xxx目录里面,然后编辑.bashrc,alias vi=安装路径/vim.
vim-dbg 和Vimgdb插件没关系,Vimgdb可以去 vim 网站下载
Link: http://www.vim.org/scripts/script.php?script_id=3039
集成gdb的vim插件有两个,一个只需要编译一个库,另一个需要先打补丁后编译,楼主问的是需要先打补丁后编译的那个。
在vim里用gdb调试的两种方式
[email protected]:~/source/soft_source$ tar xf pyclewn-1.1.tar.gz
[email protected]:~/source/soft_source$ cd pyclewn-1.1/
[email protected]:~/source/soft_source/pyclewn-1.1$ sudo python setup.py install –force
[email protected]:~/source/soft_source/pyclewn-1.1$ vimdir=$HOME/.vim python setup.py install –force –home=$HOME