- 浏览: 896968 次
- 性别:
- 来自: 太原
文章分类
- 全部博客 (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 18941. 实现像bash那样上下方向键显示^[[A,^[[B,不能 ... -
Linux建立本地cvs服务器
2009-08-14 22:25 1592在RH Linux上快速建立本地CVS服务器的小指南 前提, ... -
如何在 Linux 中执行命令?
2009-08-12 21:01 24201、怎样在后台执行命令 ... -
linux查看命令/文件所在路径的命令及修改
2009-08-12 21:01 36177whereis 用来查看一个命令或者文件所在的绝对路径,而 w ... -
我的 emacs 配置文件
2009-08-11 18:29 3585; Set up nesC syntax highligh ... -
emacs的缩进和自动添加新行
2009-07-27 22:22 6934emacs很强大,但是强大是以复杂的配置为前提的!没有配置好的 ... -
linux share文件
2009-07-27 20:57 2211安装好samba并在share folder中设置好想要共享的 ... -
Emacs学习笔记
2009-07-24 23:09 18091. 如何安装el文件 A:单个文件直接放入 ... -
Ubuntu中emacs23 的字体设置和emacs初始窗口位置的小经验
2009-07-24 19:09 7803Debian users, if your emacs sta ... -
scim 智能拼音消失的恢复办法
2009-07-06 19:48 1521完全删掉~/.scim后重启scim -
Linux 字符操作指令
2009-07-03 01:19 1286awk awk 用来从文本文件中提取字段。缺省地,字段分割符 ... -
Shell编程学习摘录十三--shell函数
2009-07-02 01:16 4148shell允许将一组命令集 ... -
Linux Shell脚本编写详解
2009-07-01 23:56 58611. Linux 脚本编写基础 1.1 语法基本介绍 1 ... -
Grep用法
2009-06-25 23:40 24771. grep简介 grep (global search ... -
ubuntu不能识别U盘的问题
2009-06-19 01:57 21185ubuntu插入u盘后,系统没 ... -
linux编程环境配置
2009-06-16 21:29 1079Gedit 1. 在Edit->Perferen ... -
Ubuntu英文版中显中文
2009-06-16 00:13 2547添加中文语言包 方法1. 在system->找到 ... -
linux之less/more命令
2009-06-11 19:46 4028名称:less 使用权限:所有使用者 使用方式:les ... -
Ubuntu 修改默认启动项
2009-06-05 16:22 1877sudo cp /boot/grub/menu.lst /bo ... -
Emacs 显示行号
2009-04-11 21:52 4567显示行号 把linum.el放到加载路径~/.emacs.d ...
相关推荐
在Emacs中使用GDB调试是软件开发中的一个高效工具,尤其对于C/C++程序员来说。Emacs作为一个强大的文本编辑器,集成了GDB(GNU调试器),使得开发者可以在Emacs环境中直接进行程序的调试工作,无需离开熟悉的开发...
例如,可以通过Elisp编写自定义函数来自动化一些调试任务,或者使用Emacs的Org Mode记录调试笔记。 在学习和使用Emacs-GDB时,建议熟悉Emacs的基本操作,理解GDB的基础命令和调试概念。此外,还可以参考Emacs-GDB的...
gdb集成则允许在Emacs内直接调试程序,使用gud-gdb或ede/gdb等模式,可以设置断点、单步执行、查看变量值等。 为了提高代码质量,可能会集成Flycheck或AStyle这样的静态代码分析工具。Flycheck可以在编写时实时检查...
以上只是EMACS和Verilog-Mode的基础操作和特性,实际上,EMACS拥有极其丰富的扩展和定制能力,通过不断学习和实践,你可以根据个人习惯打造个性化的开发环境,提高工作效率。在EMACS的世界里,"一切皆有可能",这...
3. **集成调试**:Emacs有内置的调试接口,如edebug,可以方便地调试 Lisp 代码,还有诸如 gdb 的集成,用于调试 C/C++ 等语言。 4. **版本控制系统集成**:Emacs与Git等版本控制系统无缝集成,允许用户在编辑器内部...
使用Emacs内置的GDB或TERM时,程序退出后通常需要手动关闭窗口。可以通过定义一个函数`kill-buffer-when-exit`来自动完成此操作: ```lisp (defun kill-buffer-when-exit () "Close associated buffer when a ...
Emacs MIPS Mode是一款专为编辑MIPS汇编代码设计的扩展模式,它是Emacs文本编辑器的一个强大工具,尤其适用于编程、调试和分析MIPS架构的汇编语言程序。MIPS(Microprocessor without Interlocked Pipeline Stages)...
15. **集成调试器**:集成GDB或其他调试器,实现代码调试功能。 文件名“mike_emacs_ok”可能代表这是由用户“Mike”配置的一套Emacs设置,表明他已经测试过并且确认配置正常工作。下载这个配置文件后,用户可以...
4. **自动补全和代码提示**:Emacs有多种补全工具,如company-mode,它们可以与CC Mode一起工作,提供C++函数、类和变量的自动补全。文档会解释如何设置和使用这些工具。 5. **编译和调试**:Emacs可以通过flymake...
9. **调试和分析**:Emacs 可以与 gdb 集成进行程序调试,使用 profiler 包进行性能分析。 10. **集成外部工具**:EmacsPack 可能包含了集成其他工具的配置,如终端模拟器(ansi-term 或 term)、浏览器(eww)和...
使用Emacs集成调试器gdb或者开启终端时,即使gdb或term进程退出后,对应的窗口仍然存在。可以采用下面的方法自动关闭这些窗口: ```elisp (defun kill-buffer-when-exit () "Close associated buffer when a ...
为了方便调试,Zig Mode还可能提供集成的调试工具,如GDB接口。通过这些工具,开发者可以在Emacs内部启动和控制Zig程序的调试过程,查看和修改变量值,设置断点,步进执行等,极大地提升了调试效率。 Emacs Lisp是...
Summary of GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Contributors ...
Compiling for debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Starting your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Your program’s ...
Compiling for debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Starting your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Your program’s ...
此外,Emacs提供了显示行号的功能,只需在用户目录下的.emacs配置文件中添加(global-linum-mode)指令并保存即可。 利用Emacs进行C++程序的调试可以分为几个步骤: 1. 设置断点。在Emacs中,你可以通过输入GDB命令...
9. **调试工具**:如gud(GNU Debugger)集成,可以直接在Emacs中启动GDB进行程序调试,查看变量值、设置断点等。 10. **多语言支持**:Emacs支持多种编程语言,my-init-el可能还包含了对其他语言的支持,以满足...
4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...
4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...