gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 01:02:25 25 4
gpt4 key购买 nike

我正在做一个选择排序编码并且在某个地方遇到了一个小的逻辑错误(输出跳过了最大数量并且总是在开始时打印 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com