NOI Linux下Emacs && gdb调试方法

时间:2023-03-10 01:21:51
NOI Linux下Emacs && gdb调试方法

1. 首先要配置emacs文件:

 (global-linum-mode t)
(show-paren-mode t)
(global-set-key (kbd "C-s") 'save-buffer)
(global-set-key (kbd "RET") 'newline-and-indent)
(global-set-key [f9] 'compile)
(global-set-key [C-f7] 'gud-gdb)
(global-set-key (kbd "C-z") 'undo)
(global-set-key (kbd "C-c") 'kill-ring-save)
(global-set-key (kbd "C-v") 'yank)
(global-set-key (kbd "C-a") 'mark-whole-buffer)
(global-set-key (kbd "C-y") 'kill-whole-line)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(inhibit-startup-screen t)
'(show-paren-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 113 :width normal :foundry "bitstream" :family "Courier 10 Pitch")))))

就是C-c, C-v, C-a, C-s, C-z, C-F7 和 F9的快捷键设置

2. 程序编译

先F9,输入 g++ -o xxx xxx.cpp -g -Wall (-Wl,-stack=1000000) 编译

C-F7调出gdb

3. gdb调试命令

先打:

 b main
r

进入调试,各种调试命令:

单步执行:

n 表示next执行下一行,会跳过函数

s 同理,但不会跳过,而且会进入系统函数= =

fin 表示跳出当前函数,且返回函数值 ex:"Value returned is $1 = (const int &) @0x8058cfc: 1"

b x if xxx 调到x行,并且满足xxx

查看变量:

p x 查看当前变量x的值(同时可以查看数组,显示就和P的一样。。)

disp x 永久查看变量x的值

und 一次性去除所有查看信息

断点:

b x 在line x设置一个断点

c 跳到下一个断点

d 去掉所有断点

其他:

k 杀死进程

q 退出gdb

两次C-c 死循环时退出程序

set print pretty on/off 调试的时候看变量的格式修改

(p.s.  这里的C代表Ctrl键)