]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Omit artificial symbols from DAP variables response
authorTom Tromey <tromey@adacore.com>
Tue, 12 Nov 2024 20:07:46 +0000 (13:07 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 9 Dec 2024 21:05:02 +0000 (14:05 -0700)
While testing DAP, we found a situation where a compiler-generated
variable caused the "variables" request to fail -- the variable in
question being an apparent 67-megabyte string.

It seems to me that artificial variables like this aren't interesting
to DAP users, and the gdb CLI omits these as well.

This patch changes DAP to omit these variables, adding a new
gdb.Symbol.is_artificial attribute to make this possible.

gdb/NEWS
gdb/doc/python.texi
gdb/python/lib/gdb/FrameDecorator.py
gdb/python/lib/gdb/dap/globalvars.py
gdb/python/py-symbol.c
gdb/testsuite/gdb.python/py-sym-artificial.exp [new file with mode: 0644]

index 047f8ad835adf0ac1e7143561db166f1c1974f46..7f0bd7edfc8d16d879d3757028555bb3bf65e8e7 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -89,6 +89,8 @@
   ** The 'qualified' argument to gdb.Breakpoint constructor will no
      longer accept non-bool types.
 
+  ** Added the gdb.Symbol.is_artificial attribute.
+
 * Debugger Adapter Protocol changes
 
   ** The "scopes" request will now return a scope holding global
      (or send a response) until after the "configurationDone" request
      has been sent.
 
+  ** The "variables" request will not return artificial symbols.
+
 * New commands
 
 show jit-reader-directory
index 5cbcc5be2a38097feeefa2d9e9b487a12006110c..063dc7e1c587bf99fc66e3e35831cb5fdf90d9a6 100644 (file)
@@ -6208,6 +6208,11 @@ local variables will require a frame, but other symbols will not.
 @code{True} if the symbol is an argument of a function.
 @end defvar
 
+@defvar Symbol.is_artificial
+@code{True} if the symbol is artificial.  An artificial symbol is one
+that is introduced by the compiler.
+@end defvar
+
 @defvar Symbol.is_constant
 @code{True} if the symbol is a constant.
 @end defvar
index 82412de13f96c8d9ad7fb27b82d16e44da6361e9..5cdfbe1b981a9362945e571683f0663bd342cfcc 100644 (file)
@@ -285,6 +285,9 @@ class FrameVars(object):
                     # returns False for arguments as well.  Anyway,
                     # don't include non-variables here.
                     continue
+                elif sym.is_artificial:
+                    # Skip artificial symbols.
+                    continue
                 lvars.append(SymValueWrapper(frame, sym))
 
             if block.function is not None:
index 38bdc5ca05ccf5c28487d3f243ca7997ceeebdf7..104b242d8968a28fe1da2cec53ef3d2178c56829 100644 (file)
@@ -86,7 +86,7 @@ def get_global_scope(frame):
     syms = []
     block_iter = block
     while block_iter is not None:
-        syms += [sym for sym in block_iter if sym.is_variable]
+        syms += [sym for sym in block_iter if sym.is_variable and not sym.is_artificial]
         block_iter = block_iter.superblock
 
     if len(syms) == 0:
index 24b53bbe38aa3dd80a5c6ce1e7f3cc6c20ea607b..c1f8d6c95e0e31f654d36a5c5d74271c1f9f4d88 100644 (file)
@@ -205,6 +205,18 @@ sympy_is_variable (PyObject *self, void *closure)
                              || theclass == LOC_OPTIMIZED_OUT));
 }
 
+/* Implementation of Symbol.is_artificial.  */
+
+static PyObject *
+sympy_is_artificial (PyObject *self, void *closure)
+{
+  struct symbol *symbol = nullptr;
+
+  SYMPY_REQUIRE_VALID (self, symbol);
+
+  return PyBool_FromLong (symbol->is_artificial ());
+}
+
 /* Implementation of gdb.Symbol.needs_frame -> Boolean.
    Returns true iff the symbol needs a frame for evaluation.  */
 
@@ -709,6 +721,8 @@ to display demangled or mangled names.", NULL },
   { "addr_class", sympy_get_addr_class, NULL, "Address class of the symbol." },
   { "is_argument", sympy_is_argument, NULL,
     "True if the symbol is an argument of a function." },
+  { "is_artificial", sympy_is_artificial, nullptr,
+    "True if the symbol is marked artificial." },
   { "is_constant", sympy_is_constant, NULL,
     "True if the symbol is a constant." },
   { "is_function", sympy_is_function, NULL,
diff --git a/gdb/testsuite/gdb.python/py-sym-artificial.exp b/gdb/testsuite/gdb.python/py-sym-artificial.exp
new file mode 100644 (file)
index 0000000..3ae516c
--- /dev/null
@@ -0,0 +1,62 @@
+# Copyright (C) 2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Test gdb.Symbol.artificial.
+
+load_lib dwarf.exp
+load_lib gdb-python.exp
+
+require dwarf2_support allow_python_tests
+
+# Just use a no-op main.
+standard_testfile py-arch.c -dw.S
+
+set asm_file [standard_output_file ${srcfile2}]
+Dwarf::assemble $asm_file {
+    cu {} {
+       compile_unit {
+           {language @DW_LANG_C}
+           {name py-sym-artificial.c}
+       } {
+           declare_labels signed
+
+           signed: DW_TAG_base_type {
+               {DW_AT_byte_size 1 DW_FORM_sdata}
+               {DW_AT_encoding  @DW_ATE_signed}
+               {DW_AT_name      bool}
+           }
+
+           DW_TAG_variable {
+               {name the_variable}
+               {DW_AT_type :$signed}
+               {artificial 1 DW_FORM_flag_present}
+           }
+       }
+    }
+}
+
+if {[prepare_for_testing "failed to prepare" ${testfile} \
+        [list $srcfile $asm_file] {nodebug}]} {
+    return -1
+}
+
+if {![runto_main]} {
+    return -1
+}
+
+gdb_py_test_silent_cmd "python v = gdb.lookup_symbol('the_variable')" \
+    "get variable" 1
+gdb_test "python print(v\[0\].is_artificial)" True \
+    "variable is artificial"