From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 34AAB3857020; Fri, 15 Jul 2022 15:28:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34AAB3857020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Add 'summary' mode to Value.format_string X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: c4a3dbaf1132105586586617a59d0e7566eefd41 X-Git-Newrev: 72be9d6be7de305b34ac298f1466167b9aba9bc2 Message-Id: <20220715152857.34AAB3857020@sourceware.org> Date: Fri, 15 Jul 2022 15:28:57 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jul 2022 15:28:57 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D72be9d6be7de= 305b34ac298f1466167b9aba9bc2 commit 72be9d6be7de305b34ac298f1466167b9aba9bc2 Author: Tom Tromey Date: Tue Jun 7 07:05:02 2022 -0600 Add 'summary' mode to Value.format_string =20 This adds a 'summary' mode to Value.format_string and to gdb.print_options. For the former, it lets Python code format values using this mode. For the latter, it lets a printer potentially detect if it is being called in a backtrace with 'set print frame-arguments' set to 'scalars'. =20 I considered adding a new mode here to let a pretty-printer see whether it was being called in a 'backtrace' context at all, but I'm not sure if this is really desirable. Diff: --- gdb/NEWS | 4 ++++ gdb/doc/python.texi | 6 ++++++ gdb/python/py-prettyprint.c | 2 ++ gdb/python/py-value.c | 7 ++++++- gdb/testsuite/gdb.python/py-format-string.exp | 6 ++++++ gdb/testsuite/gdb.python/py-format-string.py | 2 ++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/gdb/NEWS b/gdb/NEWS index 85e1e108457..4d6de311411 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -156,6 +156,10 @@ GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux* ** gdb.Value.format_string now uses the format provided by 'print', if it is called during a 'print' or other similar operation. =20 + ** gdb.Value.format_string now accepts the 'summary' keyword. This + can be used to request a shorter representation of a value, the + way that 'set print frame-arguments scalars' does. + * New features in the GDB remote stub, GDBserver =20 ** GDBserver is now supported on LoongArch GNU/Linux. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 4573ba67734..5dd907fac42 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -1160,6 +1160,12 @@ Additionally, @value{GDBN} only styles some value co= ntents, so not every output string will contain escape sequences. =20 When @code{False}, which is the default, no output styling is applied. + +@item summary +@code{True} when just a summary should be printed. In this mode, +scalar values are printed in their entirety, but aggregates such as +structures or unions are omitted. This mode is used by @code{set +print frame-arguments scalars} (@pxref{Print Settings}). @end table @end defun =20 diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index 4ef45b283f9..7b2aa588bb0 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -753,6 +753,8 @@ gdbpy_print_options (PyObject *unused1, PyObject *unuse= d2) opts.static_field_print) < 0 || set_boolean (result.get (), "deref_refs", opts.deref_ref) < 0 + || set_boolean (result.get (), "summary", + opts.summary) < 0 || set_unsigned (result.get (), "max_elements", opts.print_max) < 0 || set_unsigned (result.get (), "max_depth", diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 93cb9b99edb..3b75cdaae00 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -641,6 +641,7 @@ valpy_format_string (PyObject *self, PyObject *args, Py= Object *kw) "address", /* See set print address on|off. */ "styling", /* Should we apply styling. */ "nibbles", /* See set print nibbles on|off. */ + "summary", /* Summary mode for non-scalars. */ /* C++ options. */ "deref_refs", /* No corresponding setting. */ "actual_objects", /* See set print object on|off. */ @@ -690,10 +691,11 @@ valpy_format_string (PyObject *self, PyObject *args, = PyObject *kw) PyObject *deref_refs_obj =3D NULL; PyObject *actual_objects_obj =3D NULL; PyObject *static_members_obj =3D NULL; + PyObject *summary_obj =3D NULL; char *format =3D NULL; if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, - "|O!O!O!O!O!O!O!O!O!O!O!O!IIIs", + "|O!O!O!O!O!O!O!O!O!O!O!O!O!IIIs", keywords, &PyBool_Type, &raw_obj, &PyBool_Type, &pretty_arrays_obj, @@ -704,6 +706,7 @@ valpy_format_string (PyObject *self, PyObject *args, Py= Object *kw) &PyBool_Type, &address_obj, &PyBool_Type, &styling_obj, &PyBool_Type, &nibbles_obj, + &PyBool_Type, &summary_obj, &PyBool_Type, &deref_refs_obj, &PyBool_Type, &actual_objects_obj, &PyBool_Type, &static_members_obj, @@ -736,6 +739,8 @@ valpy_format_string (PyObject *self, PyObject *args, Py= Object *kw) return NULL; if (!copy_py_bool_obj (&opts.static_field_print, static_members_obj)) return NULL; + if (!copy_py_bool_obj (&opts.summary, summary_obj)) + return nullptr; =20 /* Numeric arguments for which 0 means unlimited (which we represent as UINT_MAX). Note that the max-depth numeric argument uses -1 as diff --git a/gdb/testsuite/gdb.python/py-format-string.exp b/gdb/testsuite/= gdb.python/py-format-string.exp index 58bbe85f693..c432de97276 100644 --- a/gdb/testsuite/gdb.python/py-format-string.exp +++ b/gdb/testsuite/gdb.python/py-format-string.exp @@ -1127,6 +1127,12 @@ proc test_print_options {} { "print in binary to fetch options" gdb_test "python print(saved_options\['format'\] =3D=3D 't')" "True" \ "format was set" + + check_format_string "a_point_t" "summary=3DTrue" \ + "No Data" \ + "print in summary mode" + gdb_test "python print(saved_options\['summary'\])" "True" \ + "summary was set" } =20 # Run all the tests in common for both C and C++. diff --git a/gdb/testsuite/gdb.python/py-format-string.py b/gdb/testsuite/g= db.python/py-format-string.py index aa7b10445cd..b7e83462502 100644 --- a/gdb/testsuite/gdb.python/py-format-string.py +++ b/gdb/testsuite/gdb.python/py-format-string.py @@ -28,6 +28,8 @@ class PointPrinter(object): def to_string(self): global saved_options saved_options =3D gdb.print_options() + if saved_options["summary"]: + return "No Data" return "Pretty Point (%s, %s)" % (self.val["x"], self.val["y"])