gdb在显示第一行代码之前挂起

时间:2014-09-24 16:51:09

标签: gcc gdb

我试图运行以下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,以便我可以调试此程序。

1 个答案:

答案 0 :(得分:0)

我必须在gdb中“启动”该程序。这对我来说非常愚蠢。