简体   繁体   中英

Address of a variable does not matches in gdb

I am using Intel's ICC compiler for NetBSD systems. I have been fighting with a bug, and got surprised even more when I observed that from the core dump - address of a symbol from two different mechanisms in gdb are not same.

The variable connection_out seems to have different address when checked with " info symbol connection_out " and p &connection_out .

Does it looks like a compiler problem where badf_errcnt which was optimized into CPU registers, is assigned a memory location, and thereafter compiler got confused between two ?

EDIT1 : the variable connection_out is a static int global variable

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.

I don't think the compiler is confused, but gdb may very well be confused, or at least working with too little information.

It does not appear as if ICC is providing sufficient symbolic debugger information for gdb , thus you're not seeing anything very useful. Was the code compiled with the correct options to record debug information in the generated binary? (ie -g and maybe also -O0 )

Have you tried using idbc (the Intel debugger)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM