c - Linux 中的 gdb7.7.1。当我尝试运行 gdb 时出现 "no debugging symbols found"

标签 c gdb

我正在做一个选择排序编码并且在某个地方遇到了一个小的逻辑错误(输出跳过了最大数量并且总是在开始时打印 0)。所以我尝试使用 gdb 来调试我的代码。但是我得到“找不到调试符号”。我尝试在将代码编译为 gcc -o -g selection_sort selection_sort.c 时使用 -g。这给出了一些错误的长列表。

selection_sort: In function `__x86.get_pc_thunk.bx': (.text+0x30):
multiple definition of `__x86.get_pc_thunk.bx' /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_info): relocation
0 has invalid symbol index 8 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_info): relocation
1 has invalid symbol index 9 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_info): relocation
2 has invalid symbol index 10 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 0 has invalid symbol index 4 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 1 has invalid symbol index 4 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 2 has invalid symbol index 5 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 3 has invalid symbol index 5 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 4 has invalid symbol index 6 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_ranges):
relocation 5 has invalid symbol index 6
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o:(.gnu.linkonce.t.__x86.get_pc_thunk.bx+0x0):
first defined here selection_sort: In function `_fini': (.fini+0x0):
multiple definition of `_fini'
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o:(.fini+0x0):
first defined here selection_sort: In function `data_start':
(.data+0x0): multiple definition of `__data_start' /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
0 has invalid symbol index 11 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
1 has invalid symbol index 12 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
2 has invalid symbol index 2 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
3 has invalid symbol index 2 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
4 has invalid symbol index 11 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
5 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
6 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
7 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
8 has invalid symbol index 12 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
9 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
10 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
11 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
12 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
13 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
14 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
15 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
16 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
17 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
18 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
19 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
20 has invalid symbol index 13 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation
21 has invalid symbol index 22 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_line): relocation
0 has invalid symbol index 2
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o:(.data+0x0):
first defined here selection_sort: In function `data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i686-linux-gnu/4.8/crtbegin.o:(.data+0x0): first defined
here selection_sort:(.rodata+0x4): multiple definition of
`_IO_stdin_used'
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o:(.rodata.cst4+0x0):
first defined here selection_sort: In function `_start': (.text+0x0):
multiple definition of `_start'
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o:/build/buildd/eglibc-2.19/csu/../sysdeps/i386/start.S:115: first defined here selection_sort:(.rodata+0x0): multiple definition
of `_fp_hw'
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o:(.rodata+0x0):
first defined here selection_sort: In function `_init': (.init+0x0):
multiple definition of `_init' /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_line): relocation
0 has invalid symbol index 4 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_line): relocation
1 has invalid symbol index 5 /usr/bin/ld:
/usr/lib/debug/usr/lib/i386-linux-gnu/crti.o(.debug_line): relocation
2 has invalid symbol index 6
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o:/build/buildd/eglibc-2.19/csu/../sysdeps/i386/crti.S:63:
first defined here /tmp/ccUdOuVC.o: In function `main':
selection_sort.c:(.text+0x0): multiple definition of `main'
selection_sort:(.text+0x100): first defined here
/usr/lib/gcc/i686-linux-gnu/4.8/crtend.o:(.tm_clone_table+0x0):
multiple definition of `__TMC_END__' selection_sort:(.data+0x8): first
defined here /usr/bin/ld: warning: Cannot create .eh_frame_hdr
section, --eh-frame-hdr ignored. /usr/bin/ld: error in
selection_sort(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status.

代码如下:

#include<stdio.h>
int main()
{
     int a[5] = {9,7,1,8,2};
     int min, temp, i, j;
     for( i=0; i<=4; i++)
     {
        min = i;
        for( j=i;j<=4; j++)
        {
           if(a[j+1] < a[min])
           min = j+1;
        }
        if (min != i)
        {
           temp = a[min];
           a[min] = a[i];
           a[i] = temp;
        }
    }
    for( i=0; i<5; i++)
    {
        printf("The sorted array is: %d\n", a[i]);
    }
}

最佳答案

您不能在 -o 之后给 gcc -g 选项:您正在指示 gcc 命名可执行文件 -g 并将先前的可执行文件 selection_sort 与新目标文件链接在一起。

用这个命令编译:

gcc -Wall -g -o selection_sort selection_sort.c 

获得可执行文件后,您就可以开始调试了……您的代码中存在越界数组引用。

关于c - Linux 中的 gdb7.7.1。当我尝试运行 gdb 时出现 "no debugging symbols found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33340856/

相关文章:

c - 在结构中传递 int 指针

c - 如何从 ext2 block 组读取 inode 表?

c - 调用 openssl::i2d_X509 后释放输出缓冲区的正确方法是什么?

c - 检查 ASCII

c++ - 在 gdb/Ubuntu 14.04.4 LTS 中加载 dl-debug.c

c - 为什么我的 .c 编码不能在 GCC 中编译?

代码永远在 C 中运行——我做错了什么?

GDB:更改堆栈内存中的字符串

gdb - 被调试程序的 block 输出(gdb)

gdb - 如何在gdb中的 “something is printed to the terminal”上设置断点?