public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17240] New: Printing member variable of a function-local class goes wrong if outer scope has a variable with the same name.
@ 2014-08-07 18:29 petedeas at fastmail dot fm
  2024-04-28 16:13 ` [Bug c++/17240] " ssbssa at sourceware dot org
  0 siblings, 1 reply; 2+ messages in thread
From: petedeas at fastmail dot fm @ 2014-08-07 18:29 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17240

            Bug ID: 17240
           Summary: Printing member variable of a function-local class
                    goes wrong if outer scope has a variable with the same
                    name.
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: petedeas at fastmail dot fm

Release: gdb-7.8.50.20140807

$ uname -a
Linux petebox 3.15.1-gentoo #1 SMP Sat Jun 21 15:14:16 BST 2014 x86_64 Intel(R)
Core(TM) i3 CPU M 370 @ 2.40GHz GenuineIntel GNU/Linux

$ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.3/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.8.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.8.3/work/gcc-4.8.3/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.3
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.3
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.3/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.3/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.3/include/g++-v4
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.8.3/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--enable-checking=release --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.8.3 p1.1, pie-0.5.9' --enable-libstdcxx-time
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64
--disable-altivec --disable-fixed-point --enable-targets=all --disable-libgcj
--enable-libgomp --disable-libmudflap --disable-libssp --enable-lto
--without-cloog
Thread model: posix
gcc version 4.8.3 (Gentoo 4.8.3 p1.1, pie-0.5.9)

When a local class has a member variable with the same name as a variable in
the containing function, gdb resolves the name incorrectly when the currently
selected frame is a member function of the class. The transcript at the end
shows a replication: w.n in the outer function scope and n in the member
function scope should refer to the same variable.

Debug info is DWARF 2.

Built with gcc -g3 demo.cpp -o demo:

// Start of file

int main(int argc, const char *argv[])
{
        struct wrapper {
                int n;

                wrapper(int input_n) : n(input_n) { };

                bool is_even() {
                        return n % 2 == 0;
                }
        };

        int n = 4;
        wrapper w(n);
        w.is_even();
}

// EOF

$ gdb -nx demo
GNU gdb (Gentoo 7.8 vanilla) 7.8
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from demo...done.
(gdb) show configuration
This GDB was configured as follows:
   configure --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
             --with-auto-load-dir=$debugdir:$datadir/auto-load
             --with-auto-load-safe-path=$debugdir:$datadir/auto-load
             --without-expat
             --with-gdb-datadir=/usr/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/lib64/gdb (relocatable)
             --without-libunwind-ia64
             --with-lzma
             --with-python=/usr (relocatable)
             --without-guile
             --with-separate-debug-dir=/usr/lib/debug (relocatable)
             --with-zlib
             --without-babeltrace

("Relocatable" means the directory can be moved with the GDB installation
tree, and GDB will still find it.)
(gdb) b main::wrapper::is_even
Breakpoint 1 at 0x4005dc: file demo.cpp, line 11.
(gdb) r
Starting program: /home/pete/gdb/scope/demo
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

Breakpoint 1, wrapper::is_even (this=0x7fffffffdf10) at demo.cpp:11
11                              return n % 2 == 0;
(gdb) p n
$1 = 32767
(gdb) p &n
$2 = (int *) 0x7fffffffdeec
(gdb) up
#1  0x000000000040061f in main (argc=1, argv=0x7fffffffe018) at demo.cpp:17
17              w.is_even();
(gdb) p w.n
$3 = 4
(gdb) p &w.n
$4 = (int *) 0x7fffffffdf10
(gdb) p n
$5 = 4
(gdb) p &n
$6 = (int *) 0x7fffffffdf1c

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-28 16:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-07 18:29 [Bug c++/17240] New: Printing member variable of a function-local class goes wrong if outer scope has a variable with the same name petedeas at fastmail dot fm
2024-04-28 16:13 ` [Bug c++/17240] " ssbssa at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).