gdb
authorTom Tromey <tromey@redhat.com>
Sat, 13 Mar 2010 00:27:12 +0000 (00:27 +0000)
committerTom Tromey <tromey@redhat.com>
Sat, 13 Mar 2010 00:27:12 +0000 (00:27 +0000)
PR c++/9708:
* dwarf2read.c (die_needs_namespace) <DW_TAG_variable>: A variable
in a lexical block does not need a namespace.
(new_symbol) <DW_TAG_variable>: Put extern variables on
list_in_scope in all cases.
gdb/testsuite
PR c++/9708:
* gdb.cp/m-static.exp: Add regression test.
* gdb.cp/m-static.cc (method): New method.
(main): Call it.

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

index 86b3793ba5310c756b192e3d723b7bba85cdb6a3..d9e6fd89ea6b736ca74e6fff1fcc72736730438d 100644 (file)
@@ -1,3 +1,11 @@
+2010-03-12  Tom Tromey  <tromey@redhat.com>
+
+       PR c++/9708:
+       * dwarf2read.c (die_needs_namespace) <DW_TAG_variable>: A variable
+       in a lexical block does not need a namespace.
+       (new_symbol) <DW_TAG_variable>: Put extern variables on
+       list_in_scope in all cases.
+
 2010-03-12 Stan Shebs  <stan@codesourcery.com>
 
        * ax-gdb.c (gen_expr): Add shift expressions.
index 53e2e1e34d8655286fe8486e56c887c03c15eb45..2d21edbb3ac9e332ce2b853cd082b38fa68529ce 100644 (file)
@@ -3204,6 +3204,8 @@ process_die (struct die_info *die, struct dwarf2_cu *cu)
 static int
 die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
 {
+  struct attribute *attr;
+
   switch (die->tag)
     {
     case DW_TAG_namespace:
@@ -3231,11 +3233,17 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu)
                                      spec_cu);
        }
 
-      if (dwarf2_attr (die, DW_AT_external, cu)
-         || die->parent->tag == DW_TAG_namespace)
-       return 1;
-
-      return 0;
+      attr = dwarf2_attr (die, DW_AT_external, cu);
+      if (attr == NULL && die->parent->tag != DW_TAG_namespace)
+       return 0;
+      /* A variable in a lexical block of some kind does not need a
+        namespace, even though in C++ such variables may be external
+        and have a mangled name.  */
+      if (die->parent->tag ==  DW_TAG_lexical_block
+         || die->parent->tag ==  DW_TAG_try_block
+         || die->parent->tag ==  DW_TAG_catch_block)
+       return 0;
+      return 1;
 
     default:
       return 0;
@@ -8413,7 +8421,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
              var_decode_location (attr, sym, cu);
              attr2 = dwarf2_attr (die, DW_AT_external, cu);
              if (attr2 && (DW_UNSND (attr2) != 0))
-               add_symbol_to_list (sym, &global_symbols);
+               {
+                 struct pending **list_to_add;
+
+                 /* A variable with DW_AT_external is never static,
+                    but it may be block-scoped.  */
+                 list_to_add = (cu->list_in_scope == &file_symbols
+                                ? &global_symbols : cu->list_in_scope);
+                 add_symbol_to_list (sym, list_to_add);
+               }
              else
                add_symbol_to_list (sym, cu->list_in_scope);
            }
index ba8eb863bd0fdf0ef440e675b2e8689675076e56..e25b72778189d2b68967759447fe8365d31f3c47 100644 (file)
@@ -1,3 +1,10 @@
+2010-03-12  Tom Tromey  <tromey@redhat.com>
+
+       PR c++/9708:
+       * gdb.cp/m-static.exp: Add regression test.
+       * gdb.cp/m-static.cc (method): New method.
+       (main): Call it.
+
 2010-03-12  Sami Wagiaalla  <swagiaal@redhat.com>
 
        * gdb.cp/gdb2384-base.h: Created 'namespace B'.
index 2a0b61c344028e94e2563dd1198826734edc116b..7f997efa9640b24f69726c5632379d29ccb18e62 100644 (file)
@@ -15,6 +15,12 @@ protected:
 
 public:
   gnu_obj_1(antiquities a, long l) {}
+
+  long method ()
+  {
+    static bool svar = true;
+    return key2;
+  }
 };
 
 const bool gnu_obj_1::test;
@@ -70,5 +76,8 @@ int main()
 
   test4.dummy = test4.elsewhere;
   test4.dummy = 0;
-  return test4.dummy;  // breakpoint: constructs-done
+
+  test1.method (); // breakpoint: constructs-done
+
+  return test4.dummy;
 }
index f207462302c73c8aa3c3e5cb31afcbb1cd067e75..7b4e0caba2589d7ef7ecd7a7060738f15beec1a7 100644 (file)
@@ -132,5 +132,10 @@ gdb_test "print test4.nowhere" "field nowhere is nonexistent or has been optimis
 # that GDB's current behavior in such situations is either consistent
 # across platforms or optimal, so I'm not including one now.
 
+# Step into test1.method and examine the method-scoped static.
+# This is a regression test for PR 9708.
+gdb_test "step" "gnu_obj_1::method.*"
+gdb_test "print svar" " = true"
+
 gdb_exit
 return 0
This page took 0.125622 seconds and 4 git commands to generate.