From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id EEB98389EC00 for ; Tue, 7 Jun 2022 15:42:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EEB98389EC00 Received: by mail-il1-x130.google.com with SMTP id y16so14485574ili.13 for ; Tue, 07 Jun 2022 08:42:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/i4qU/jsWJjxzl5DvI6lJyWCCSSPEDyc1aDsPOiLqGg=; b=qFcenGPAuxlso1TYsLVq7ZfNSLU2d/V+FzIgekb0T8TheljttSSvGhe/zKtzqjjTtV pA8tNWM/ne5G0uYhFsIgj3Y0tPi9RV3GKSXaDJP4hhkJhqPJvDxiGwnK6XKyg29k6iLO YiJbiQHqzIgPOMsdd8NgAwDT4F4KC2QWHFEdXP9ULKeQEetdIOs2GDcbhU+KBKLJ/C+q NvjYwEid3NoBbI2NCdOWkV51iH5VRhKSEAq3wnUHRr1ElHnAuIVAxnr/SF1Mgb1lWhzd 09pdz7+H6ZCMvks57Zp6ibj44EQUNubSjfYsSq7ouRqV/3kLZsV4t3PzAabQWFudIByG ZdcA== X-Gm-Message-State: AOAM533NB8MsLQVFuUaXYj5udjjQfCGSH4y+6PPEX+uuc/tT12q5ObMG uxBBPI/xFsmmaoeTrJbosiEFGYKV9IgY6A== X-Google-Smtp-Source: ABdhPJwoFguFA7WoCeWeBqmAdiQ4/K5pYr8xuDaiAVmVeWN2cD8BxkNW6xSXnEtlqpuEk5oG2t2EvQ== X-Received: by 2002:a05:6e02:184a:b0:2d3:9f38:138a with SMTP id b10-20020a056e02184a00b002d39f38138amr15946307ilv.124.1654616550200; Tue, 07 Jun 2022 08:42:30 -0700 (PDT) Received: from murgatroyd.Home (71-211-171-143.hlrn.qwest.net. [71.211.171.143]) by smtp.gmail.com with ESMTPSA id a30-20020a02735e000000b0032be3784b9bsm6717375jae.117.2022.06.07.08.42.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 08:42:29 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] Add 'summary' mode to Value.format_string Date: Tue, 7 Jun 2022 09:42:26 -0600 Message-Id: <20220607154226.3281521-3-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607154226.3281521-1-tromey@adacore.com> References: <20220607154226.3281521-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2022 15:42:32 -0000 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'. 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. --- gdb/NEWS | 2 ++ 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, 24 insertions(+), 1 deletion(-) diff --git a/gdb/NEWS b/gdb/NEWS index 6b32afed82c..114818f0ae4 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -70,6 +70,8 @@ maintenance info line-table ** gdb.Value.format_string now uses the format provided by 'print', if it is called during a 'print' or other similar operation. + ** gdb.Value.format_string now accepts the 'summary' keyword. + *** Changes in GDB 12 * DBX mode is deprecated, and will be removed in GDB 13 diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index b9b65369db3..bf57a378a60 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -1153,6 +1153,12 @@ Additionally, @value{GDBN} only styles some value contents, so not every output string will contain escape sequences. 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 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 *unused2) 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 48acfc8d173..54f9025a60b 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -640,6 +640,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) "unions", /* See set print union on|off. */ "address", /* See set print address on|off. */ "styling", /* Should we apply styling. */ + "summary", /* Summary mode for non-scalars. */ /* C++ options. */ "deref_refs", /* No corresponding setting. */ "actual_objects", /* See set print object on|off. */ @@ -688,10 +689,11 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) PyObject *deref_refs_obj = NULL; PyObject *actual_objects_obj = NULL; PyObject *static_members_obj = NULL; + PyObject *summary_obj = NULL; char *format = NULL; if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, - "|O!O!O!O!O!O!O!O!O!O!O!IIIs", + "|O!O!O!O!O!O!O!O!O!O!O!O!IIIs", keywords, &PyBool_Type, &raw_obj, &PyBool_Type, &pretty_arrays_obj, @@ -701,6 +703,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw) &PyBool_Type, &unions_obj, &PyBool_Type, &address_obj, &PyBool_Type, &styling_obj, + &PyBool_Type, &summary_obj, &PyBool_Type, &deref_refs_obj, &PyBool_Type, &actual_objects_obj, &PyBool_Type, &static_members_obj, @@ -731,6 +734,8 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *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; /* 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 0b7cdc18f5f..38794610482 100644 --- a/gdb/testsuite/gdb.python/py-format-string.exp +++ b/gdb/testsuite/gdb.python/py-format-string.exp @@ -1054,6 +1054,12 @@ proc test_print_options {} { "print in binary to fetch options" gdb_test "python print(saved_options\['format'\] == 't')" "True" \ "format was set" + + check_format_string "a_point_t" "summary=True" \ + "No Data" \ + "print in summary mode" + gdb_test "python print(saved_options\['summary'\])" "True" \ + "summary was set" } # 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/gdb.python/py-format-string.py index aa7b10445cd..8eee211a6ad 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 = gdb.print_options() + if saved_options['summary']: + return "No Data" return "Pretty Point (%s, %s)" % (self.val["x"], self.val["y"]) -- 2.34.1