]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Ignore static members in NoOpStructPrinter
authorTom Tromey <tromey@adacore.com>
Mon, 13 Nov 2023 21:03:58 +0000 (14:03 -0700)
committerTom Tromey <tromey@adacore.com>
Fri, 17 Nov 2023 15:36:21 +0000 (08:36 -0700)
Hannes' patch to show local variables in the TUI pointed out that
NoOpStructPrinter should ignore static members.  This patch implements
this.

gdb/python/lib/gdb/printing.py
gdb/testsuite/gdb.dap/ptrref.cc
gdb/testsuite/gdb.dap/ptrref.exp

index dec1351c2d7b84d0dc2f454b14c07e9aa3963d6f..14bd84b5859d90908c06a511808cecb462148621 100644 (file)
@@ -350,7 +350,7 @@ class NoOpStructPrinter(gdb.ValuePrinter):
 
     def children(self):
         for field in self.__ty.fields():
-            if field.name is not None:
+            if hasattr(field, "bitpos") and field.name is not None:
                 yield (field.name, self.__value[field])
 
 
index bfb1afe3d17501de82836ee4a88c8c3b1b8b9000..c9b83cd06122b0fcfe6f5281fe06760cac521614 100644 (file)
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+struct some_struct
+{
+  int x;
+  int y;
+
+  static int z;
+};
+
+int some_struct::z = 37;
+
 void
 func ()
 {
+  some_struct aggregate { 91, 87 };
+
   int value = 23;
 
   int *ptr = &value;
index e0cc74529ab268c372f0df62bfe93355f5f87cae..456774aefbec92ca36ee3107527132b1a1b14e07 100644 (file)
@@ -55,7 +55,7 @@ gdb_assert {[llength $scopes] == 2} "two scopes"
 lassign $scopes scope reg_scope
 gdb_assert {[dict get $scope name] == "Locals"} "scope is locals"
 
-gdb_assert {[dict get $scope namedVariables] == 3} "three vars in scope"
+gdb_assert {[dict get $scope namedVariables] == 4} "three vars in scope"
 
 set num [dict get $scope variablesReference]
 set refs [lindex [dap_check_request_and_response "fetch variables" \
@@ -97,6 +97,13 @@ foreach var [dict get $refs body variables] {
                "$name has exactly one child"
            fetch_pointer $name $var
        }
+       "aggregate" {
+           gdb_assert {[dict get $var variablesReference] != 0} \
+               "$name has children"
+           # This should omit the static field.
+           gdb_assert {[dict get $var namedVariables] == 2} \
+               "$name has exactly 2 children"
+       }
     }
 }