gpt4 book ai didi

c - GDB报告(带有列表和框架命令)不列出行号

转载 作者:行者123 更新时间:2023-11-30 16:44:06 25 4
gpt4 key购买 nike

我正在使用 gdb 来找出程序中出现段错误的位置。但是,我的 GDB 报告没有指定行号,它只是命名了函数。

root@brute-force-compute:~# gcc -g -pthread program.c -o program -lmysqlclient
root@brute-force-compute:~# gdb program


(gdb) run --journal --day "Tuesday" --job "iOS" --client "SEAS"
Starting program: /root/serapis --journal --day "Tuesday" --job "iOS" --client "SEAS"
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
__strcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:296
296 ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S: No such file or directory.
(gdb) list
291 in ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S

编辑:使用 -g 标志进行编译

gcc program.c -o program -g -lmysqlclient -l pthread
gdb program
(gdb) run --journal --day "Tuesday" --job "iOS" --client "SEAS"
Program received signal SIGSEGV, Segmentation fault.
__strcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:296
296 ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S: No such file or directory.
(gdb) list
291 in ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S
(gdb) frame
#0 __strcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:296
296 in ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S

第一次尝试:

gcc program.c -o program -lmysqlclient -l pthread
gdb program
(gdb) run --journal --day "Tuesday" --job "iOS" --client "SEAS"
Starting program: root/program --day "Tuesday" --job "iOS" --client "SEAS"
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
__strcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:296
296 ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S: No such file or directory.
(gdb) where
#0 __strcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:296
#1 0x0000000000402c69 in init_journal ()
#2 0x00000000004086d4 in main ()
(gdb)list
291 in ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S
(gdb) frame
#0 __strcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:296
296 in ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S
(gdb) backtrace
#0 __strcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S:296
#1 0x0000000000402c69 in init_journal ()
#2 0x00000000004086d4 in main ()

main中,我这样做:

if(strcmp(argv[1], "--journal") == 0){
printf("\nInitializing single integral machine..\n\n");
char * template = argv[2];
init_journal(day, job, client);
}

其中日期、工作、客户均在 main 中提前设置,如下所示:

   if(strcmp(argv[i], "--day") == 0){
day = argv[++i];
}

我查看了不同的帖子,在这里我看到我应该更改在 gdb 中放入命令行参数的方式:

run $(--journal --day "Tuesday" --job "iOS" --client "SEAS")

然后我得到报告:

Program received signal SIGSEGV, Segmentation fault.
__strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31
31 ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S: No such file or directory.
(gdb) list
26 in ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S
(gdb) frame
#0 __strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31
31 in ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S

最佳答案

gcc program.c -o program -lmysqlclient -l pthread

此命令构建您的程序而不调试信息。在其他微妙的方面它也是不正确的。

你想要:

gcc -g -pthread program.c -o program -lmysqlclient

I looked at different posts and I saw here that I should change how I put in my command line arguments in gdb:

run $(--journal --day "Tuesday" --job "iOS" --client "SEAS")

完全是伪造的命令行。你不应该这样做。

关于c - GDB报告(带有列表和框架命令)不列出行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44725709/

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