【发布时间】:2014-09-24 16:51:08
【问题描述】:
我正在尝试运行以下 C 代码。这将被编译并在终端运行,但它没有给出预期的输出。逻辑是错误的,当然。为了调试,使用了 gdb。但是当附加该程序时,gdb 会挂起并发出警告。以下是代码、编译命令、运行代码和示例输出如下所示。
#include <stdio.h>
void array_former(long long int *lst, int *length) {
int i;
long long int value;
for (i=0; i < *length; i++) {
value = lst[i];
if(value < 12)
continue;
lst[*length++] = value / 2;
lst[*length++] = value / 3;
lst[*length++] = value / 4;
}
}
void clear_array(long long int *lst) {
int i;
for(i=0; i<100000; i++)
lst[i] = 0;
}
int main() {
long long int n;
long long int array[100000];
int length, i;
while((n = scanf("%lld", &n)) != EOF) {
clear_array(array);
array[0] = n;
length = 1;
array_former(array, &length);
for(i=0; i<length; i++)
printf("%lld ", array[i]);
}
return 0;
}
命令
gcc -g test.c
gdb ./a.out
在 gdb 控制台:
deepak@ubuntu:~/Desktop$ gdb ./a.out
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/deepak/Desktop/a.out...(no debugging symbols found)...done.
(gdb) r
Starting program: /home/deepak/Desktop/a.out 15
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
[cursor keep blinking for sometime and stops like forever, gdb hangs]
我搜索了上面的警告,发现here那个,可以忽略。
问题:如何让 gdb 在不挂起的情况下运行,以便调试此程序。
【问题讨论】: