GDB使用shell命令和make命令

  • 内容
  • 评论
  • 相关

GDB 中可以使用 shell 命令,也就是说可以实现 shell 中的功能,这样可以极大的提高我们调试程序的效率。GDB 中还可以使用 make 命令,这样就可以不退出 gdb 调试界也可以重新编译程序。

使用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

在 gdb中与 shell 中的命令使用格式和方法基本上是相同的。

注意:调用 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 程序和 shell make <make-args> 相同。

注意:使用 make 命令的前提是当前目录下有 Makefile 文件,并且 Makefile 文件记录了程序重建的规则命令,如果没有 Makefile, make 命令就不会执行。

本文标题:GDB使用shell命令和make命令

本文地址:https://www.hosteonscn.com/7937.html

评论

0条评论

发表评论

邮箱地址不会被公开。 必填项已用*标注