From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24689 invoked by alias); 7 Aug 2014 18:29:15 -0000 Mailing-List: contact gdb-prs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-prs-owner@sourceware.org Received: (qmail 24666 invoked by uid 48); 7 Aug 2014 18:29:14 -0000 From: "petedeas at fastmail dot fm" To: gdb-prs@sourceware.org Subject: [Bug c++/17240] New: Printing member variable of a function-local class goes wrong if outer scope has a variable with the same name. Date: Thu, 07 Aug 2014 18:29:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: c++ X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: petedeas at fastmail dot fm X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-q3/txt/msg00229.txt.bz2 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 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: . Find the GDB manual and other documentation resources online at: . 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.