Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Mahmood Naderan <nt_mahmood@yahoo.com>,
	"gdb@sourceware.org" <gdb@sourceware.org>
Subject: Re: Viewing the address of an array in gdb
Date: Fri, 06 Jul 2018 12:06:00 -0000	[thread overview]
Message-ID: <e6892311-f2ca-4673-4f91-23f44a34fba3@redhat.com> (raw)
In-Reply-To: <f88b2580-1a6d-0efd-d95a-03473a6f9705@redhat.com>

On 07/06/2018 01:00 PM, Pedro Alves wrote:
> On 07/06/2018 12:51 PM, Pedro Alves wrote:
>> On 07/06/2018 04:33 AM, Mahmood Naderan via gdb wrote:
>>> Hi,
>>> I have define "char buffer[100]" in a C code. Trying to view the location of buffer in GDB, I see this
> 
> Ah, I missed the "you have defined a buffer yourself" part.
> 
> So what seems to be happening is that there's another symbol also 
> called "buffer" in glibc:
> 
>  (gdb) info symbol buffer
>  buffer in section .bss of /lib64/libc.so.6
> 
> and gdb is picking that symbol instead of yours.
> 
> I can reproduce this if I compile a small program without debug info,
> but with debug info (-g), it works as you'd expect.
> 
> I don't think we have syntax to disambiguate this, like
> 'libc.so.6'::buffer' vs 'program'::buffer, or program#buffer some
> such, unfortunately.
If you can't change the program, you can work around this by
unloading the shared library symbols, so that gdb sees the
program's symbol again.  E.g.:

(gdb) start
Temporary breakpoint 1 at 0x40048b
Starting program: /home/pedro/tmp/buffer 

Temporary breakpoint 1, 0x000000000040048b in main ()
(gdb) info symbol &buffer
buffer in section .bss of /lib64/libc.so.6
(gdb) nosharedlibrary 
(gdb) info symbol &buffer
buffer in section .bss
(gdb) x /30x  &buffer
0x601040 <buffer>:      0x00000000      0x00000000      0x00000000      0x00000000
0x601050 <buffer+16>:   0x00000000      0x00000000      0x00000000      0x00000000
0x601060 <buffer+32>:   0x00000000      0x00000000      0x00000000      0x00000000
0x601070 <buffer+48>:   0x00000000      0x00000000      0x00000000      0x00000000
0x601080 <buffer+64>:   0x00000000      0x00000000      0x00000000      0x00000000
0x601090 <buffer+80>:   0x00000000      0x00000000      0x00000000      0x00000000
0x6010a0 <buffer+96>:   0x00000000      0x00000000      0x00000000      0x00000000
0x6010b0:       0x00000000      0x00000000
(gdb) 

Thanks,
Pedro Alves


  reply	other threads:[~2018-07-06 12:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1377359320.54438.1530847991768.ref@mail.yahoo.com>
2018-07-06  3:33 ` Mahmood Naderan via gdb
2018-07-06 11:51   ` Pedro Alves
2018-07-06 12:00     ` Pedro Alves
2018-07-06 12:06       ` Pedro Alves [this message]
2018-07-06 13:08         ` Mahmood Naderan via gdb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e6892311-f2ca-4673-4f91-23f44a34fba3@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=nt_mahmood@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox