[英]gdb run program questions
program need to be debugged: ~/bin/tryIt (generated: gcc -g -Wall -o try try.c) gdb version: GNU gdb (GDB) 8.3需要调试的程序:~/bin/tryIt(生成:gcc -g -Wall -o try try.c) gdb 版本:GNU gdb (GDB) 8.3
Questions for running the program tryIt after setting a same break point for all the trials: 1. there are different bash run the tryIT, sometimes it's OS (MAC OS latest version) bash: ~/bin/tryIt在为所有试验设置相同的断点后运行程序 tryIt 的问题: 1. 有不同的 bash 运行 tryIT,有时它是 OS(MAC OS 最新版本) bash: ~/bin/tryIt
And sometimes it's GDB bash: ~/Library/Caches/gdb/bin/bash.有时它是 GDB bash:~/Library/Caches/gdb/bin/bash。
Q: Why does GDB use different bash to handle the program? Q:为什么GDB使用不同的bash来处理程序? How to control/choose the one to run?如何控制/选择一个运行?
Q: What's the reason it cannot stop at the break point Q:断点停不下来是什么原因
Searched online for all the solutions for this (include stackoverflow.com), none of them worked.在网上搜索了所有解决方案(包括 stackoverflow.com),都没有奏效。 While not try one solution which is change gdb's source code.虽然不尝试一种更改 gdb 源代码的解决方案。
Source code of tryIt.c tryIt.c 的源代码
#include <stdio.h>
#include <stdlib.h>
typedef struct node NODE;
struct node
{
int x;
char *name;
NODE *next;
};
NODE *getNext(NODE *stNode)
{
return stNode->next;
}
int main()
{
NODE n1, n2, n3;
n1.x = 5;
n1.name = "n1";
n1.next = &n2;
n2.x = 10;
n2.name = "n2";
n2.next = &n3;
n3.x = 20;
n3.name = "n3";
n3.next = NULL;
struct node *nx = getNext(&n1);
printf("Current Node:%s, its value:%d\n", nx->name, nx->x);
NODE *ptr = &n1;
while (ptr != NULL)
{
printf("Current Node:%s, its value:%d\n", ptr->name, ptr->x);
ptr = ptr->next;
}
return 0;
}
I find out how to answer Q1 by myself.我自己找出了如何回答 Q1。
edit ~/.gdbinit file.编辑 ~/.gdbinit 文件。 If it didn't exist, create it.如果它不存在,请创建它。 Add one line: set startup-with-shell disable添加一行:set startup-with-shell disable
Then re-run gdb, it will always show the process ~/bin/tryIt然后重新运行gdb,它会一直显示进程~/bin/tryIt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.