GDB使用shell命令和make命令
使用shell命令
gdb 中可以使用 Linux 中的 shell 命令,需要使用 gdb 中的 shell 命令实现 ,使用方法如下:shell <command string>
<command string>表示的是 shell 中的命令,例如:
(gdb) shell ls
test test.c
(gdb) shell cat test.c
#include <stdio.h>
#include <stdlib.h>
void func()
{
char *sp = "hello";
free(sp);
}
int main(void)
{
func();
return 0;
}
(gdb) shell cd .. && ls
09 test
注意:调用 Linux 的 shell 来执行 <command string>,环境变量 SHELL 中定义的 Linux 的 shell 将会被用来执行<command string>,如果 SHELL 中没有定义,就会使用 Linux 标准。
使用 make 命令
在 gdb 中执行 make 命令来重建自己的程序,make 命令的使用方法如下:make <make-args>
其中 <make-args>表示参数,例如:
(gdb) shell ls
makefile test.c
(gdb) make
cc -c -o test.o test.c
cc -g -o test.o test
(gdb) make clean
rm -rf *.o test
(gdb) shell make
cc -c -o test.o test.c
cc -g -o test.o test
注意:使用 make 命令的前提是当前目录下有 Makefile 文件,并且 Makefile 文件记录了程序重建的规则命令,如果没有 Makefile, make 命令就不会执行。
关注微信公众号「站长严长生」,在手机上阅读所有教程,随时随地都能学习。本公众号由C语言中文网站长运营,每日更新,坚持原创,敢说真话,凡事有态度。
微信扫描二维码关注公众号