From patchwork Sat Mar 23 23:04:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 31958 Received: (qmail 83867 invoked by alias); 23 Mar 2019 23:05:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 83772 invoked by uid 89); 23 Mar 2019 23:05:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=forces, typedefs, UD:elements, predefined X-HELO: mail-wm1-f41.google.com Received: from mail-wm1-f41.google.com (HELO mail-wm1-f41.google.com) (209.85.128.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 23 Mar 2019 23:04:59 +0000 Received: by mail-wm1-f41.google.com with SMTP id 4so5397098wmf.1 for ; Sat, 23 Mar 2019 16:04:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=8sPZu+vNdYYK6tS+/A/r0j9kGnN7ubGrRSSbcD91ZgU=; b=VnjHxdc/giDPHiV7NN1TH4QiN72ufRN2e3DWEXQHWs4yF5FPbm0Okk13XR6H2KfUyL Zxj0TkvnCAieMAkX5VulWKEOu1T3IVlTzkIPMGY0nUtHd8NtNcDA/OqjqHYuqpw1SFZc hX0ZlUanpVjHHew1yskR1edL/68dC9KuzXW7vfhePNRNr+jE+QRR8QZS94f4LKpt3HSI 6U7w1mEm1K+RMVZDh5Qx354fpS1/wLa4py3UovALNIRrVyGiiVHh5EdHtKEnsn96qt1J wPcuKdrijmIde1McOVajyD4SDzG0BxxjyrE0V2RNGipr5MaRdcZjzjKvj0KjwEBUIfFC VuWw== Return-Path: Received: from localhost (host86-174-153-232.range86-174.btcentralplus.com. [86.174.153.232]) by smtp.gmail.com with ESMTPSA id h1sm10251471wmb.5.2019.03.23.16.04.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Mar 2019 16:04:55 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/3] gdb: Make python display_hint None handling defined behaviour Date: Sat, 23 Mar 2019 23:04:44 +0000 Message-Id: <74c9886b523c8116691457826dc011cb74266b33.1553382150.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes The documentation say that the display_hint method must return a string to serve as a display hint, and then goes on to list some acceptable strings. However, if we don't supply the display_hint method then we get a default display style behaviour and there's currently no way (in the python api) to force this default behaviour. The guile api allows #f to be used in order to force the default display style behaviour, and this is documented. Currently, using None in the python api also forces the default display behaviour. This commit extends the documentation to make returning None from the display_hint method and official mechanism by which the user can get the default display style. I've extended one of the existing tests to cover this case. gdb/doc/ChangeLog: * python.texi (Pretty Printing API): Document use of None for the display_hint. gdb/testsuite/ChangeLog: * gdb.python/py-prettyprint.c (struct container) : New field. (make_container): Initialise new field. * gdb.python/py-prettyprint.exp: Add new tests. * gdb.python/py-prettyprint.py (class ContainerPrinter) : New method. --- gdb/doc/ChangeLog | 5 +++++ gdb/doc/python.texi | 5 ++++- gdb/testsuite/ChangeLog | 9 +++++++++ gdb/testsuite/gdb.python/py-prettyprint.c | 2 ++ gdb/testsuite/gdb.python/py-prettyprint.exp | 15 ++++++++++++++- gdb/testsuite/gdb.python/py-prettyprint.py | 6 ++++++ 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 6fadaffa371..56c925d4dd2 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -1294,7 +1294,7 @@ printed. This method is optional. If it does exist, this method must return a -string. +string or the special value @code{None}. Some display hints are predefined by @value{GDBN}: @@ -1317,6 +1317,9 @@ adding quotation marks, possibly escaping some characters, respecting @code{set print elements}, and the like. @end table + +The special value @code{None} causes @value{GDBN} to apply the default +display rules. @end defun @defun pretty_printer.to_string (self) diff --git a/gdb/testsuite/gdb.python/py-prettyprint.c b/gdb/testsuite/gdb.python/py-prettyprint.c index 01fdf8a96e6..1b9aeb4b679 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.c +++ b/gdb/testsuite/gdb.python/py-prettyprint.c @@ -175,6 +175,7 @@ struct container string name; int len; int *elements; + int is_map_p; }; typedef struct container zzz_type; @@ -195,6 +196,7 @@ make_container (const char *s) result.name = make_string (s); result.len = 0; result.elements = 0; + result.is_map_p = 0; return result; } diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp index 335908279c9..82e7e650316 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.exp +++ b/gdb/testsuite/gdb.python/py-prettyprint.exp @@ -109,7 +109,12 @@ proc run_lang_tests {exefile lang} { gdb_test_no_output "set python print-stack full" gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val" - gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}" + gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}" \ + "print c, pretty printing on, default display hint" + + gdb_test_no_output "set variable c.is_map_p=1" + gdb_test "print c" " = container \"container\" with 2 elements = \{$nl \\\[23\\\] = 72$nl\}" \ + "print c, pretty printing on, display hint is now map" gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}" @@ -117,6 +122,14 @@ proc run_lang_tests {exefile lang} { gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \ "print nstype on one line" + # Now we have pretty printing turned off, try printing 'c' again. + gdb_test "print c" " = container \"container\" with 2 elements = \{\\\[23\\\] = 72\}" \ + "print c, pretty printing off, display hint is now map" + + gdb_test_no_output "set variable c.is_map_p=0" + gdb_test "print c" " = container \"container\" with 2 elements = \{\\\[0\\\] = 23, \\\[1\\\] = 72\}" \ + "print c, pretty printing off, default display hint" + # Check that GDB doesn't lose typedefs when looking for a printer. gdb_test "print an_int" " = -1" gdb_test "print (int) an_int" " = -1" diff --git a/gdb/testsuite/gdb.python/py-prettyprint.py b/gdb/testsuite/gdb.python/py-prettyprint.py index 92fe81525b1..43727f7231d 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.py +++ b/gdb/testsuite/gdb.python/py-prettyprint.py @@ -56,6 +56,12 @@ class ContainerPrinter (object): def children(self): return _iterator(self.val['elements'], self.val['len']) + def display_hint (self): + if (self.val['is_map_p']): + return 'map' + else: + return None + # Treats a container as array. class ArrayPrinter (object): def __init__(self, val):