gpt4 book ai didi

c - 变量的地址与 gdb 中不匹配

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

我正在使用适用于 NetBSD 系统的英特尔 ICC 编译器。我一直在与一个错误作斗争,当我从核心转储中观察到来自 gdb 中两种不同机制的符号地址不相同时,我感到更加惊讶。

使用“info symbol connection_out”和p &connection_out检查时,变量connection_out似乎具有不同的地址。

这是否看起来像一个编译器问题,其中优化为 CPU 寄存器的 badf_errcnt 被分配了一个内存位置,然后编译器在两个位置之间感到困惑?

EDIT1:变量connection_out是一个static int全局变量

gdb$ disassemble sigusr1_rt
Dump of assembler code for function sigusr1_rt:
0x01845000 <+0>: push %ebp
0x01845001 <+1>: mov %esp,%ebp
0x01845003 <+3>: sub $0x8,%esp
0x01845006 <+6>: movl $0x16c156a,0x188f05c
0x01845010 <+16>: mov %ebp,%esp
0x01845012 <+18>: pop %ebp
0x01845013 <+19>: ret
0x01845014 <+20>: lea 0x0(%esi),%esi
0x0184501a <+26>: lea 0x0(%edi),%edi
End of assembler dump.
gdb$ info symbol 0x188f05c
connection_out in section .bss of /sites/eqx/work/swcores/tripunjay/F10ACOREDIR/f10cp_sshd.login-eqx-06.6402/sshd
gdb$ p &connection_out
$10 = (int *) 0x188f048
gdb$ p/d 0x188f05c - 0x188f048
$11 = 20
gdb$ p/x 0x188f05c - 0x188f048
$12 = 0x14
gdb$ info symbol 0x188f048
badf_errcnt.5450.0.13 in section .bss of /sites/eqx/work/swcores/tripunjay/F10ACOREDIR/f10cp_sshd.login-eqx-06.6402/sshd
gdb$ p &badf_errcnt
No symbol "badf_errcnt" in current context.
gdb$ select-frame 5
gdb$ frame
Stack level 5, frame at 0xbb4aca20:
eip = 0x1846007 in wait_until_can_do_something (serverloop.c:404); saved eip 0x1846698
called by frame at 0xbb4b0af0, caller of frame at 0xbb4ac9d0
source language c.
Arglist at 0xbb4aca18, args: readsetp=0xbb4b0ab4, writesetp=0xbb4b0ab8, maxfdp=0x4, nallocp=0xbb4b0abc, max_time_milliseconds=0x0
Locals at 0xbb4aca18, Previous frame's sp is 0xbb4aca20
Saved registers:
ebx at 0xbb4aca00, ebp at 0xbb4aca18, esi at 0xbb4ac9fc, edi at 0xbb4aca04, eip at 0xbb4aca1c
readsetp = 0xbb4b0ab4
writesetp = 0xbb4b0ab8
maxfdp = 0x4
nallocp = 0xbb4b0abc
max_time_milliseconds = 0x0
badf_errcnt = <optimized out>
tv = <optimized out>
tvp = <optimized out>
client_alive_scheduled = 0x0
gdb$ p &badf_errcnt
Can't take address of "badf_errcnt" which isn't an lvalue.

最佳答案

我不认为编译器会感到困惑,但 gdb 很可能会感到困惑,或者至少使用的信息太少。

看起来 ICC 没有为 gdb 提供足够的符号调试器信息,因此您没有看到任何非常有用的信息。代码是否使用正确的选项编译以在生成的二进制文件中记录调试信息? (即-g,也可能是-O0)

您是否尝试过使用idbc(英特尔调试器)?

关于c - 变量的地址与 gdb 中不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29614958/

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