program need to be debugged: ~/bin/tryIt (generated: gcc -g -Wall -o try try.c) gdb version: 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
And sometimes it's GDB bash: ~/Library/Caches/gdb/bin/bash.
Q: Why does GDB use different bash to handle the program? How to control/choose the one to run?
Q: What's the reason it cannot stop at the break point
Searched online for all the solutions for this (include stackoverflow.com), none of them worked. While not try one solution which is change gdb's source code.
Source code of 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.
edit ~/.gdbinit file. If it didn't exist, create it. Add one line: set startup-with-shell disable
Then re-run gdb, it will always show the process ~/bin/tryIt
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.