From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86616 invoked by alias); 6 Jul 2018 12:06:43 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 86448 invoked by uid 89); 6 Jul 2018 12:06:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*M:4673, yours X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Jul 2018 12:06:41 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB37972651; Fri, 6 Jul 2018 12:06:39 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5822A79A9; Fri, 6 Jul 2018 12:06:39 +0000 (UTC) Subject: Re: Viewing the address of an array in gdb To: Mahmood Naderan , "gdb@sourceware.org" References: <1377359320.54438.1530847991768.ref@mail.yahoo.com> <1377359320.54438.1530847991768@mail.yahoo.com> From: Pedro Alves Message-ID: Date: Fri, 06 Jul 2018 12:06:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-07/txt/msg00020.txt.bz2 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 : 0x00000000 0x00000000 0x00000000 0x00000000 0x601050 : 0x00000000 0x00000000 0x00000000 0x00000000 0x601060 : 0x00000000 0x00000000 0x00000000 0x00000000 0x601070 : 0x00000000 0x00000000 0x00000000 0x00000000 0x601080 : 0x00000000 0x00000000 0x00000000 0x00000000 0x601090 : 0x00000000 0x00000000 0x00000000 0x00000000 0x6010a0 : 0x00000000 0x00000000 0x00000000 0x00000000 0x6010b0: 0x00000000 0x00000000 (gdb) Thanks, Pedro Alves