From: Sergio Durigan Junior <sergiodj@redhat.com>
authorSergio Durigan Junior <sergiodj@redhat.com>
Thu, 14 Mar 2013 11:13:36 +0000 (11:13 +0000)
committerSergio Durigan Junior <sergiodj@redhat.com>
Thu, 14 Mar 2013 11:13:36 +0000 (11:13 +0000)
Subject: [PATCH] Fix for PR c++/15203 and PR c++/15210
Date: Sat, 09 Mar 2013 02:50:49 -0300 (5 days, 4 hours, 57 minutes ago)
Message-ID: <m3a9qdnmti.fsf@redhat.com>

Hi,

This bug was reported internally at our Bugzilla, along with a proposed
fix.  After talking to Keith about it, he investigated and came up with
another patch needed to really fix the issue on CVS HEAD.

The first part of the fix is the patch to cp-namespace.c.  It handles
the case when we are accessing a static variable inside a function
(inside a class) by the full linespec (is it right, Keith?).  E.g.:

    class foo
    {
    public:
        int bar()
        {
            static int var = 0;
        }
    };

And then, printing the value of `var':

    (gdb) print 'foo::bar()::var'

GDB would fall in an internal_error:

    gdb/cp-namespace.c:816: internal-error: cp_lookup_nested_symbol called on a non-aggregate type.

This is because `cp_lookup_nested_symbol' is not handling the case when
TYPE_CODE is either _FUNC or _METHOD.  This patch fixes it by returning
NULL in this case.

The second part of the fix is the patch to elfread.c.  It is needed
because the BSF_GNU_UNIQUE flag was added to some symbols in
<http://sourceware.org/ml/binutils/2009-06/msg00016.html>.  Because of
that, (still) the command:

    (gdb) print 'foo::bar()::var'

where `var' is a static variable returns:

    "No symbol "foo::bar()::var" in current context."

So with the second patch applied the command finally DTRT:

    (gdb) print 'foo::bar()::var'
    $1 = 0

This may not be the ideal solution, according to Keith it would be good
to implement productions on c-exp.y in order to recognize
CLASS::FUNCTION::VARIABLE, but it is a solution which works with what we
have today.

I regtested it in Fedora 17 x86_64 with -m64 and -m32, including
gdbserver, without regressions.

gdb/:
2013-03-14  Keith Seitz  <keiths@redhat.com>
    Alan Matsuoka  <alanm@redhat.com>

PR c++/15203
PR c++/15210
* cp-namespace.c (cp_lookup_nested_symbol): Handle TYPE_CODE_FUNC and
TYPE_CODE_METHOD.
* elfread.c (elf_symtab_read): Handle BSF_GNU_UNIQUE for certain
symbols.

gdb/testsuite/:
2013-03-14  Sergio Durigan Junior  <sergiodj@redhat.com>

PR c++/15203
PR c++/15210
* gdb.cp/m-static.cc (keepalive_int): New function.
(gnu_obj_1::method): New variable `sintvar', call `keepalive_int'.
* gdb.cp/m-static.exp: New test for `sintvar'.

gdb/ChangeLog
gdb/cp-namespace.c
gdb/elfread.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.cp/m-static.cc
gdb/testsuite/gdb.cp/m-static.exp

index 4d608f5514403fcc72f04a7f40ef4674a7ea64f0..2d911aad6616af6a3a84b17a3e7e9054a509d717 100644 (file)
@@ -1,3 +1,13 @@
+2013-03-14  Keith Seitz  <keiths@redhat.com>
+           Alan Matsuoka  <alanm@redhat.com>
+
+       PR c++/15203
+       PR c++/15210
+       * cp-namespace.c (cp_lookup_nested_symbol): Handle TYPE_CODE_FUNC and
+       TYPE_CODE_METHOD.
+       * elfread.c (elf_symtab_read): Handle BSF_GNU_UNIQUE for certain
+       symbols.
+
 2013-03-14  Yao Qi  <yao@codesourcery.com>
 
        * tracepoint.c (tfile_write_status): Write 'stop_desc' of trace
index 279021e046f4a4dee3eb8a94c5834001262c6780..add4ccb913a47637f4617a1324c58e364bcdb825 100644 (file)
@@ -812,6 +812,11 @@ cp_lookup_nested_symbol (struct type *parent_type,
           base classes.  */
        return find_symbol_in_baseclass (parent_type, nested_name, block);
       }
+
+    case TYPE_CODE_FUNC:
+    case TYPE_CODE_METHOD:
+      return NULL;
+
     default:
       internal_error (__FILE__, __LINE__,
                      _("cp_lookup_nested_symbol called "
index 6ab3a6a0a864ae637f6e16cd6656413787d39e49..14952b80bcf2ebb5bd5bb003238deb080d266eb4 100644 (file)
@@ -357,7 +357,8 @@ elf_symtab_read (struct objfile *objfile, int type,
        }
       else if (sym->flags & BSF_SECTION_SYM)
        continue;
-      else if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK))
+      else if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK
+                            | BSF_GNU_UNIQUE))
        {
          struct minimal_symbol *msym;
 
@@ -413,7 +414,7 @@ elf_symtab_read (struct objfile *objfile, int type,
            }
          else if (sym->section->flags & SEC_CODE)
            {
-             if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
+             if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
                {
                  if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
                    ms_type = mst_text_gnu_ifunc;
@@ -443,7 +444,7 @@ elf_symtab_read (struct objfile *objfile, int type,
            }
          else if (sym->section->flags & SEC_ALLOC)
            {
-             if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
+             if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
                {
                  if (sym->section->flags & SEC_LOAD)
                    {
index f4863a18e975aaa5abb1e82436c2e4e30d538412..8dac760424f2431660972c6a3eb1dc312bb73fb0 100644 (file)
@@ -1,3 +1,11 @@
+2013-03-14  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       PR c++/15203
+       PR c++/15210
+       * gdb.cp/m-static.cc (keepalive_int): New function.
+       (gnu_obj_1::method): New variable `sintvar', call `keepalive_int'.
+       * gdb.cp/m-static.exp: New test for `sintvar'.
+
 2013-03-14  Yao Qi  <yao@codesourcery.com>
 
        * gdb.trace/tstatus.exp (run_trace_experiment): Save the output
index 8472988391cd170117fd311ff1ece16a07943312..eadbdfc44ba824f03ee2da609a3346699fc84b4f 100644 (file)
@@ -3,6 +3,7 @@
 enum region { oriental, egyptian, greek, etruscan, roman };
 
 void keepalive(bool *var) { }
+void keepalive_int (int *var) { }
 
 // Test one.
 class gnu_obj_1
@@ -21,8 +22,11 @@ public:
 
   long method ()
   {
+    static int sintvar = 4;
     static bool svar = true;
+
     keepalive (&svar);
+    keepalive_int (&sintvar);
     return key2;
   }
 };
index ae4b2ad8ee2b94ff20b07d1039bcd7ac0ac464b7..5d1cb8b1aa20427aa69709e2601e58ae5885853f 100644 (file)
@@ -52,6 +52,11 @@ gdb_continue_to_breakpoint "end of constructors"
 
 # One.
 
+# simple object, static const int, accessing via 'class::method::variable'
+# Regression test for PR c++/15203 and PR c++/15210
+gdb_test "print 'gnu_obj_1::method()::sintvar'" "\\$\[0-9\]+ = 4" \
+    "simple object, static const int, accessing via 'class::method::variable"
+
 # simple object, static const bool
 gdb_test "print test1.test" "\\$\[0-9\]* = true" "simple object, static const bool"
 
This page took 0.040599 seconds and 4 git commands to generate.