- 浏览: 886335 次
- 性别:
- 来自: 太原
文章分类
- 全部博客 (198)
- Linux/Unix (38)
- TinyOS / NS-2 for『WSN』 (44)
- 思想的拼图 (5)
- 开源 OpenSource (2)
- Framework 开发框架 (0)
- Software Engineering 软件工程 (2)
- IT项目管理 (6)
- Networking 网络技术 (2)
- Java (6)
- C语言 ANSI C (22)
- .NET / C# (9)
- C++ (12)
- Web 语言 Html/Xml (5)
- Groovy on Grails (1)
- Algorithm 算法 (1)
- Database 数据库技术 (5)
- Tools (21)
- VM 虚拟机 (3)
- WSN (wireless sensor network) (2)
- Linux 命令专辑 (3)
- PHP (0)
- 办公软件 (3)
最新评论
-
cfczdws:
感谢楼主,查了半天终于发现居然是htmlentities()做 ...
htmlentities()函数把中文转成了乱码 -
decoxiaohan:
这本书的名字 有谁知道????~~~
OMNeT++中文用户手册(完全版) -
huonie:
怎么下载啊
OMNeT++中文用户手册(完全版) -
huonie:
没有内容啊
OMNeT++中文用户手册(完全版) -
kyx0413:
谢谢先 先看看
OMNeT++中文用户手册(完全版)
Emacs Mode for GDB
A graphical user interface is an essential part of any modern debugger. This mode provides one, without losing the power of Emacs.
The GNU symbolic debugger, GDB, is a powerful development tool, but one drawback is it works only from the command line. GDB has some clever features that make it easy to use on the command line, such as completion of GDB command names and procedure names; using Enter to repeat the previous command, which is useful for stepping through a program or looking at a listing; and the read-line interface.
For some tasks, however, it is useful have a graphical user interface (GUI). Graphical front ends are available for GDB, including Insight, but they require a separate editor. Until now, Emacs used a mode that originally was written by Eric Raymond in 1992. This comprised of the GUD buffer, where GDB commands were entered as though on the command line, and the source buffer, where a arrow string ("=>") pointed to the current line of program execution. In this article, I describe a new mode, which I call GDB-UI, that is a part of the next release of Emacs (21.4) and offers the GUI features of many modern debuggers. The advantage of this mode over the other debuggers is the powerful features of Emacs are available for tasks such as editing and searching to provide a truly integrated development environment.
Eric Raymond wrote gud.el, a grand unified debugger mode for running GDB and other debuggers, as part of Emacs. Shortly afterwards, Tom Lord and Jim Kingdon, then working at Cygnus, wrote another mode and called it gdba.el. Their mode was derived from gud.el but was designed for use only with GDB, with which it was distributed.
With gud.el, when GDB ran under Emacs, it used the -fullname option, which made it print a tag, called an annotation, that supplied the current filename, line number and address each time execution stopped. Lord and Kingdon added more annotations to GDB so that a front-end, such as Emacs, could understand better the state of execution. They called this mechanism level 2 annotations, the fullname option being level 1. This allowed Emacs to display more information, including the call stack, local variables of the current stack and the status of any breakpoints. In my opinion, this was a significant improvement, but for some reason their work didn't make its way into the Emacs community. Instead, it fell into disuse and was removed from the GDB distribution. Many GDB users may not have been aware of its existence, however, as it was distributed only with the source code for GDB.
By the time I first came across gdba.el, there had been many developments in Emacs. Notably, it had a toolbar and a speedbar. In addition, the CVS version became available, at Savannah, allowing images to be placed in the fringe to provide breakpoint icons. The resulting file, called gdb-ui.el, tries to use all of these features as well as those in gdba.el. It is stored in the lisp/progmodes sub-directory alongside gud.el.
The following simple program is used to illustrate how GDB-UI works.
myprog.c
1 typedef struct { 2 float a; 3 float b; 4 } substruct; 5 6 struct { 7 int i; 8 substruct r; 9 } c; 10 11 main() { 12 int n = 4; 13 int m[10] = {0,1,4,9,16,25,36,49,64,81}; 14 n = 5; 15 myproc(n); 16 c.i = 1; 17 c.r.a = 0.5; 18 c.r.b = 0.25; 19 }
myproc.c
1 myproc(n) 2 { 3 int p; 4 p = 2*n; 5 printf("Two times %d is %d\n", n, p); 6 }
Compile with the -g option:
cc -g -c myproc.c cc -g -o myprog myprog.c myproc.o
Type M-x gdb in the minibuffer to invoke GDB-UI. If necessary, type in the name of the executable, myprog, and press Enter. Emacs displays the GUD buffer, as it did in previous versions of Emacs. Now set the variable gdb-many-windows to t, either by selecting the checkbox on the menubar (Gud -> GDB-UI-> Display other windows) or through the minibuffer.
Emacs now displays the source code of the main routine, together with the GUD, locals, breakpoint and stack buffers, in a single frame. For the purposes of this tutorial, this arrangement is assumed. More generally, however, if the lisp variable, gdb-many-windows is nil, these other buffers appear only if the user specifically requests them. To do this, select GDB-windows or GDB-Frames from the menubar under the heading GUD and then choose the desired buffer.
If the toolbar is not present, type M-x toolbar-mode. Move the cursor slowly over the icons, and a tooltip tells you what function each button performs. Most of these icons have been taken from the Cygnus Insight debugger, but some are new. In particular, note that the Stop and Go buttons do not stop and start the program but set and clear breakpoints.
At line 14 of the source buffer, left-click in the fringe and a red disk appears. This shows that a breakpoint has been set there. Left-click at the same place again to clear the breakpoint, and observe the disk disappear. The breakpoint also can be set by typing break 14 in the GUD buffer or by leaving the cursor on line 14 and clicking on the Stop button in the toolbar. Try this and then clear the breakpoint again, either by typing clear 14 in the GUD buffer or by leaving the cursor on line 14 and clicking on the Go button in the toolbar.
Set this breakpoint again and another one by typing break myproc in the GUD buffer, and look at the breakpoints buffer. This buffer shows the status of all the breakpoints and is shown in Figure 3 in its own frame.
Position the cursor on the details of the first breakpoint and press the spacebar. Doing this disables the breakpoint, and the breakpoint icon turns grey. Press the spacebar again, and the breakpoint once again is enabled. Right-click on the second breakpoint and the source buffer visits the file containing the breakpoint and displays its location.
With the breakpoint set, click on the Run button, which displays a man running, to start the program. A small arrow appears over the breakpoint icon at line 14, indicating that execution has stopped there.
Look at the locals buffer, and you can see that the value of the local variable n is 4. All local variable that are simple types display their values in this buffer. Complex types, such as arrays, structures and unions, simply give their type as shown in the Figure 4. This is the case for the variable m, which is an array.
Place the cursor on the array name--m, in this case--and click on the button showing a pair of glasses. If it is not present already, the speedbar should appear and display the array name and type. Note, however, that this feature requires GDB 6.0 or later.
Complex data types are represented in the speedbar in a tree format. To see all the values of m, right-click on the tag to the left of the expression. Click there again to contract this expression. These expressions are called watch expressions, and they update whenever a value changes. They should not be confused with watchpoints, which can stop the execution of the program being run under GDB. Structures such as the global variable c have a deeper level of nesting than arrays do, and their values can be explored in a similar manner.
Display the local variable n as a watch expression in the same way, and then step over one statement of myprog using either the toolbar or the GUD buffer. Notice that the font colour of this expression and value turns red to alert you that it has changed.
Resume execution of myprog, which now should stop at myproc. You can go up and down the stack using the toolbar or the GUD buffer. The source buffer updates accordingly, as does the locals buffer. You also can select the frame that you want to examine by right-clicking it in the stack buffer. This buffer displays the call stack, with the current frame displayed in inverse video.
When you have finished debugging, kill the GUD buffer with C-x k, which also kills all the associated buffers. You need not do this if you wish to edit the source code and recompile within Emacs. This has the the advantage of keeping the shell history of the GUD buffer as well as GDB's breakpoints. You need to check, however, that the breakpoints in the recently edited code are where you want them.
This tutorial has covered the most basic features of GDB-UI. Other buffers exist and are left to the reader to explore. They include:
-
Input/Output Buffer: if the lisp variable gdb-use-inferior-io-buffer is non-nil, the executable program being debugged takes its input and displays its output here. Some of the commands from shell mode are available here.
-
Assembler Buffer: displays the current frame as machine code. An overlay arrow points to the current instruction, and you can set and remove breakpoints as with the source buffer. Breakpoint icons also appear in the fringe or margin.
-
Threads Buffer: displays a summary of all threads currently in your program. Point to any thread in the list and press Enter to make it become the current thread; it then displays the associated source in the source buffer. Alternatively, right-click to make the selected thread become the current one.
-
Registers Buffer: displays the values held by the registers.
You may not want to use all of the features described in this article, but many of them are customisable. Please refer to the Emacs Info manual, which is included in the distribution, for more details.
Richard Stallman is the original author of both Emacs and GDB, and at the start of the GNU Project, both programs were distributed on the same tape. Each program has become more complex and now has its own repositories, developers and mailing lists. However, there is a natural relationship between the editor and the debugger, and the mode I have described here tries to re-inforce this idea.
发表评论
-
ksh 使用手记
2009-12-03 20:52 18401. 实现像bash那样上下方向键显示^[[A,^[[B,不能 ... -
Linux建立本地cvs服务器
2009-08-14 22:25 1536在RH Linux上快速建立本地CVS服务器的小指南 前提, ... -
如何在 Linux 中执行命令?
2009-08-12 21:01 23701、怎样在后台执行命令 ... -
linux查看命令/文件所在路径的命令及修改
2009-08-12 21:01 36117whereis 用来查看一个命令或者文件所在的绝对路径,而 w ... -
我的 emacs 配置文件
2009-08-11 18:29 3516; Set up nesC syntax highligh ... -
emacs的缩进和自动添加新行
2009-07-27 22:22 6876emacs很强大,但是强大是以复杂的配置为前提的!没有配置好的 ... -
linux share文件
2009-07-27 20:57 2172安装好samba并在share folder中设置好想要共享的 ... -
Emacs学习笔记
2009-07-24 23:09 17531. 如何安装el文件 A:单个文件直接放入 ... -
Ubuntu中emacs23 的字体设置和emacs初始窗口位置的小经验
2009-07-24 19:09 7757Debian users, if your emacs sta ... -
scim 智能拼音消失的恢复办法
2009-07-06 19:48 1467完全删掉~/.scim后重启scim -
Linux 字符操作指令
2009-07-03 01:19 1254awk awk 用来从文本文件中提取字段。缺省地,字段分割符 ... -
Shell编程学习摘录十三--shell函数
2009-07-02 01:16 4113shell允许将一组命令集 ... -
Linux Shell脚本编写详解
2009-07-01 23:56 58141. Linux 脚本编写基础 1.1 语法基本介绍 1 ... -
Grep用法
2009-06-25 23:40 24421. grep简介 grep (global search ... -
ubuntu不能识别U盘的问题
2009-06-19 01:57 21101ubuntu插入u盘后,系统没 ... -
linux编程环境配置
2009-06-16 21:29 1043Gedit 1. 在Edit->Perferen ... -
Ubuntu英文版中显中文
2009-06-16 00:13 2494添加中文语言包 方法1. 在system->找到 ... -
linux之less/more命令
2009-06-11 19:46 3973名称:less 使用权限:所有使用者 使用方式:les ... -
Ubuntu 修改默认启动项
2009-06-05 16:22 1829sudo cp /boot/grub/menu.lst /bo ... -
Emacs 显示行号
2009-04-11 21:52 4506显示行号 把linum.el放到加载路径~/.emacs.d ...
相关推荐
介绍在Emacs下如何使用GDB进行调试。
在emacs中使用gdb,网页格式,经典。
emacs-gdb:GNU Emacs的GDB图形界面
haskell-mode emacs haskell-mode emacs
这些书籍涵盖了从vi,emacs(编辑器), gcc(编译器), make(工程项目管理), gdb(调试),bash(使用最广泛的shell)等unix环境下开发所需的大部分工具的基本使用和高级功能等.基本上是某方面最经典最权威的著作.(还有一本是...
文件来源:http://jaist.dl.sourceforge.net/project/emacs-bin/releases/emacs-24.4-bin-i686-pc-mingw32.7z ... - 添加新的 rectangular mark mode (C-x SPC) 更多内容请看 etc/NEWS 文件,使用 `C-h n' 命令查看。
这些书籍涵盖了从vi,emacs(编辑器), gcc(编译器), make(工程项目管理), gdb(调试),bash(使用最广泛的shell)等unix环境下开发所需的大部分工具的基本使用和高级功能等.基本上是某方面最经典最权威的著作.(还有一本是...
Major mode for Emacs for editing MATLAB code, and running MATLAB in an inferior shell.zip
这些书籍涵盖了从vi,emacs(编辑器), gcc(编译器), make(工程项目管理), gdb(调试),bash(使用最广泛的shell)等unix环境下开发所需的大部分工具的基本使用和高级功能等.基本上是某方面最经典最权威的著作.(还有一本是...
The.Definitive.Guide.to.GCC.2nd.Edition.2006.pdf Debugging+With+Gdb,+9Th+Ed.pdf Learning_GNU_Emacs_Third_Edition.chm Linux.Commands.Editors.and.Shell.Programming.chm ...Emacs,GCC,Make,GDB,Bash
emacs python-moemacs python-mode 及使用方法de 及使用方法
emacs,最新版,神一样的编辑器,官网下比较慢,这里下载速度可以
Emacs23.1 emacs config for C/C++ 最近更新
和博客 https://blog.csdn.net/tbzj_2000/article/details/81702009 配套的资源包,一次性完成emacs,evil和verilog mode的部署。
emacs,ide,自定义编辑器
关于verilog-mode的简介. 能帮助你在emacs中快速使用verilog-mode.
GNU Emacs for windows
pmwiki-mode是Emacs的一种模式,它允许您从Emacs中浏览PmWiki Wiki,但是其主要目的是让您从Emacs中编辑Wiki页面。
mode-line-stats:一堆易于设置的Emacs mode-line统计信息
这些书籍涵盖了从vi,emacs(编辑器), gcc(编译器), make(工程项目管理), gdb(调试),bash(使用最广泛的shell)等unix环境下开发所需的大部分工具的基本使用和高级功能等.基本上是某方面最经典最权威的著作.(还有一本是...