gpt4 book ai didi

c++ - 在 Emacs 中使用 gdb : always show the source code

转载 作者:太空狗 更新时间:2023-10-29 20:25:19 25 4
gpt4 key购买 nike

我是 Vim 用户,对 Emacs 了解不多。我对 Emacs 很感兴趣,因为我发现在 Emacs 中调试更愉快。例如,它提供语法高亮,我可以用鼠标设置断点。

除遇到 printf 外,一切正常。

用于说明的简单代码:

1 #include <stdio.h>
2
3 int main()
4 {
5 int a = 1;
6 printf("%d\n", a);
7 int b = 2;
8 return 0;
9 }

emacs main.c
左键点击下半部分
M-x gdb[返回][返回]
(gdb) b 6
(gdb) r

至此,源代码显示在上半部分,gdb提示符显示在下半部分。这正是我想要的。

(gdb) n

现在源代码消失了,上半部分用来显示标准输出。这真的很不方便。我希望标准输出显示在 gdb 缓冲区中,源代码保留在上缓冲区中,就像 gdb -tui 模式一样。

最佳答案

与其每次都手动设置拆分,不如尝试 telling GDB which windows you want available .

例如:

;; Show main source buffer when using GDB
(setq gdb-show-main t)

现在您可以简单地使用 M-x gdb 来启动 GDB,它应该使您的源代码缓冲区显示在一个拆分窗口中。

顺便说一句,Emacs 的 GDB 接口(interface)支持许多您可能想要启用的其他窗口:

If gdb-many-windows is non-nil, then M-x gdb displays the following frame layout:

+--------------------------------+--------------------------------+
| GUD interaction buffer | Locals/Registers buffer |
|--------------------------------+--------------------------------+
| Primary Source buffer | I/O buffer for debugged pgm |
|--------------------------------+--------------------------------+
| Stack buffer | Breakpoints/Threads buffer |
+--------------------------------+--------------------------------+

If you ever change the window layout, you can restore the "many windows" layout by typing M-x gdb-restore-windows. To toggle between the many windows layout and a simple layout with just the GUD interaction buffer and a source file, type M-x gdb-many-windows.

You may also specify additional GDB-related buffers to display, either in the same frame or a different one. Select the buffers you want by typing M-x gdb-display-BUFFERTYPE-buffer or M-x gdb-frame-BUFFERTYPE-buffer, where BUFFERTYPE is the relevant buffer type, such as breakpoints. You can do the same with the menu bar, with the GDB-Windows and GDB-Frames sub-menus of the GUD menu.

When you finish debugging, kill the GUD interaction buffer with C-x k, which will also kill all the buffers associated with the session. However you need not do this if, after editing and re-compiling your source code within Emacs, you wish to continue debugging. When you restart execution, GDB automatically finds the new executable. Keeping the GUD interaction buffer has the advantage of keeping the shell history as well as GDB's breakpoints. You do need to check that the breakpoints in recently edited source files are still in the right places.

关于c++ - 在 Emacs 中使用 gdb : always show the source code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24386672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com