簡體   English   中英

gdb運行程序問題

[英]gdb run program questions

需要調試的程序:~/bin/tryIt(生成:gcc -g -Wall -o try try.c) gdb 版本:GNU gdb (GDB) 8.3

在為所有試驗設置相同的斷點后運行程序 tryIt 的問題: 1. 有不同的 bash 運行 tryIT,有時它是 OS(MAC OS 最新版本) bash: ~/bin/tryIt

有時它是 GDB bash:~/Library/Caches/gdb/bin/bash。

Q:為什么GDB使用不同的bash來處理程序? 如何控制/選擇一個運行?

  1. 有時正在運行的程序確實在斷點處停止並顯示 gdb 提示符。 似乎它仍在運行,但有時它會在斷點處停止。
    並且這似乎是隨機發生的(僅 10% 停止)並且與運行程序的 bash 不匹配。

Q:斷點停不下來是什么原因

  1. 當程序無法在斷點處停止時(顯示為:[New Thread 0x1703 of process 14771]),Ctrl+C 不能停止程序,kill -9 也不能殺死正在運行的程序(無論哪個 bash 調用它),都必須殺死 gdb 並再次執行所有操作。

在網上搜索了所有解決方案(包括 stackoverflow.com),都沒有奏效。 雖然不嘗試一種更改 gdb 源代碼的解決方案。

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;
}


我自己找出了如何回答 Q1。

編輯 ~/.gdbinit 文件。 如果它不存在,請創建它。 添加一行:set startup-with-shell disable

然后重新運行gdb,它會一直顯示進程~/bin/tryIt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM