From patchwork Sun Jul 20 23:47:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 2121 Received: (qmail 11361 invoked by alias); 20 Jul 2014 23:47:17 -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 11297 invoked by uid 89); 20 Jul 2014 23:47:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f74.google.com Received: from mail-pa0-f74.google.com (HELO mail-pa0-f74.google.com) (209.85.220.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 20 Jul 2014 23:47:10 +0000 Received: by mail-pa0-f74.google.com with SMTP id lj1so1638541pab.3 for ; Sun, 20 Jul 2014 16:47:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:cc:date:message-id:mime-version :content-type; bh=2lxAFCoJ++T3veYo9klWKaoLsKScqrKGc/g3uIqvnTs=; b=bW06Y5g1qVuu4zYD+X9p/8yHufKL36c+ymn4BBvyIDKL8CHLy6d9ac/qfnF8ydCkWc TlrQQZ8mQulccbjN54hcJOAFoTVuIGflw2Lsf7iydCvAEFe+EKLG4FoMAqA4CX6VkFp8 nYt778if+NQvdGdHrZH3TMYHD89CRuQvzBSJw5nnJOE8e/kDXUBjQOtN80Wb2YkhMNqc L8iSRwbgvK3U1PhR/L0mvX9g3rE/K3tO8xAl4cG0weLV9/+riUlXrmZYk9t/usRtHYMB i9GzEzRA+wAzqXe7v6Lkfyw6yi5v0WnwEMhazXygnN8GapLpRvxXhTVgI0H/2O73ctf4 vrRg== X-Gm-Message-State: ALoCoQklCiafRyYlaE9eqWg+Sfa1owRjfdScbb9t1spP7brvsMNykyt3vF4m6HjbdrC7MKBnVb8k X-Received: by 10.66.157.67 with SMTP id wk3mr10683998pab.24.1405900028968; Sun, 20 Jul 2014 16:47:08 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id p3si917146yho.7.2014.07.20.16.47.08 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 20 Jul 2014 16:47:08 -0700 (PDT) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.44]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 414085A4215; Sun, 20 Jul 2014 16:47:08 -0700 (PDT) From: Doug Evans To: gdb-patches@sourceware.org, eliz@gnu.org Subject: [PATCH, doc RFA] PR guile/17177: replace *pretty-printers* cc: ludo@gnu.org Date: Sun, 20 Jul 2014 16:47:07 -0700 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. This patch implements the fix for pr 17177. Namely it replaces Guile global *pretty-printers* with two functions: pretty-printers, set-pretty-printers!. 2014-07-19 Doug Evans PR guile/17177 * guile/lib/gdb.scm (pretty-printers): Export. (set-pretty-printers!): Export. * guile/lib/gdb/printing.scm (gdb module): Update. (prepend-pretty-printer!, append-pretty-printer!): Update. * guile/scm-pretty-print.c (pretty_printer_list_name): Delete. (pretty_printer_list_var): Delete. (pretty_printer_list): New static global. (gdbscm_pretty_printers): New function. (gdbscm_set_pretty_printers_x): New function. (ppscm_find_pretty_printer_from_gdb): Update. (pretty_printer_functions): Add pretty-printers, set-pretty-printers!. (gdbscm_initialize_pretty_printers): Update. doc/ * guile.texi (Guile Pretty Printing API): Fix typo. Document set-pretty-printers!, pretty-printers. (Selecting Guile Pretty-Printers): Update. Mention program-space based pretty-printers. diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi index 4aaba8a..a6ce2da 100644 --- a/gdb/doc/guile.texi +++ b/gdb/doc/guile.texi @@ -1377,7 +1377,16 @@ Otherwise return @code{#f}. @deffn {Scheme Procedure} set-pretty-printer-enabled! pretty-printer flag Set the enabled flag of @var{pretty-printer} to @var{flag}. -The value returned in unspecified. +The value returned is unspecified. +@end deffn + +@deffn {Scheme Procedure} pretty-printers +Return the list of global pretty-printers. +@end deffn + +@deffn {Scheme Procedure} set-pretty-printers! pretty-printers +Set the list of global pretty-printers to @var{pretty-printers}. +The value returned is unspecified. @end deffn @deffn {Scheme Procedure} make-pretty-printer-worker display-hint to-string children @@ -1476,27 +1485,36 @@ printer exists, then this returns @code{#f}. @subsubsection Selecting Guile Pretty-Printers @cindex selecting guile pretty-printers -The Guile list @code{*pretty-printers*} contains a set of -@code{} registered objects. -Printers in this list are called @code{global} -printers, they're available when debugging any inferior. -In addition to this, each @code{} object contains its -own set of pretty-printers (@pxref{Objfiles In Guile}). +There are three sets of pretty-printers that @value{GDBN} searches: + +@itemize @bullet +@item +Per-objfile list of pretty-printers (@pxref{Objfiles In Guile}). +@item +Per-progspace list of pretty-printers (@pxref{Progspaces In Guile}). +@item +The global list of pretty-printers (@pxref{Guile Pretty Printing API}). +These printers are available when debugging any inferior. +@end itemize Pretty-printer lookup is done by passing the value to be printed to the lookup function of each enabled object in turn. Lookup stops when a lookup function returns a non-@code{#f} value or when the list is exhausted. +Lookup functions must return either a @code{} +object or @code{#f}. Otherwise an exception is thrown. @value{GDBN} first checks the result of @code{objfile-pretty-printers} of each @code{} in the current program space and iteratively calls each enabled lookup function in the list for that @code{} until a non-@code{#f} object is returned. -Lookup functions must return either a @code{} -object or @code{#f}. Otherwise an exception is thrown. If no pretty-printer is found in the objfile lists, @value{GDBN} then -searches the global pretty-printer list, calling each enabled function -until a non-@code{#f} object is returned. +searches the result of @code{progspace-pretty-printers} of the current +program space, calling each enabled function until a non-@code{#f} object +is returned. +After these lists have been exhausted, it tries the global pretty-printers +list, obtained with @code{pretty-printers}, again calling each enabled +function until a non-@code{#f} object is returned. The order in which the objfiles are searched is not specified. For a given list, functions are always invoked from the head of the list, diff --git a/gdb/guile/lib/gdb.scm b/gdb/guile/lib/gdb.scm index 120fcc6..4fd4699 100644 --- a/gdb/guile/lib/gdb.scm +++ b/gdb/guile/lib/gdb.scm @@ -319,6 +319,8 @@ set-pretty-printer-enabled! make-pretty-printer-worker pretty-printer-worker? + pretty-printers + set-pretty-printers! ;; scm-progspace.c diff --git a/gdb/guile/lib/gdb/printing.scm b/gdb/guile/lib/gdb/printing.scm index eac9417..2d1274f 100644 --- a/gdb/guile/lib/gdb/printing.scm +++ b/gdb/guile/lib/gdb/printing.scm @@ -19,7 +19,8 @@ (define-module (gdb printing) #:use-module ((gdb) #:select - (*pretty-printers* pretty-printer? objfile? progspace? + (pretty-printer? objfile? progspace? + pretty-printers set-pretty-printers! objfile-pretty-printers set-objfile-pretty-printers! progspace-pretty-printers set-progspace-pretty-printers!)) #:use-module (gdb init)) @@ -30,7 +31,7 @@ If OBJ is #f, add MATCHER to the global list." (%assert-type (pretty-printer? matcher) matcher SCM_ARG1 'prepend-pretty-printer!) (cond ((eq? obj #f) - (set! *pretty-printers* (cons matcher *pretty-printers*))) + (set-pretty-printers! (cons matcher (pretty-printers)))) ((objfile? obj) (set-objfile-pretty-printers! obj (cons matcher (objfile-pretty-printers obj)))) @@ -46,7 +47,7 @@ If OBJ is #f, add MATCHER to the global list." (%assert-type (pretty-printer? matcher) matcher SCM_ARG1 'append-pretty-printer!) (cond ((eq? obj #f) - (set! *pretty-printers* (append! *pretty-printers* (list matcher)))) + (set-pretty-printers! (append! (pretty-printers) (list matcher)))) ((objfile? obj) (set-objfile-pretty-printers! obj (append! (objfile-pretty-printers obj) (list matcher)))) diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c index e20da68..79b9e64 100644 --- a/gdb/guile/scm-pretty-print.c +++ b/gdb/guile/scm-pretty-print.c @@ -111,11 +111,8 @@ static const char pretty_printer_worker_smob_name[] = static scm_t_bits pretty_printer_smob_tag; static scm_t_bits pretty_printer_worker_smob_tag; -/* Global list of pretty-printers. */ -static const char pretty_printer_list_name[] = "*pretty-printers*"; - -/* The *pretty-printer* variable. */ -static SCM pretty_printer_list_var; +/* The global pretty-printer list. */ +static SCM pretty_printer_list; /* gdb:pp-type-error. */ static SCM pp_type_error_symbol; @@ -239,6 +236,29 @@ gdbscm_set_pretty_printer_enabled_x (SCM self, SCM enabled) return SCM_UNSPECIFIED; } + +/* (pretty-printers) -> list + Returns the list of global pretty-printers. */ + +static SCM +gdbscm_pretty_printers (void) +{ + return pretty_printer_list; +} + +/* (set-pretty-printers! list) -> unspecified + Set the global pretty-printers list. */ + +static SCM +gdbscm_set_pretty_printers_x (SCM printers) +{ + SCM_ASSERT_TYPE (gdbscm_is_true (scm_list_p (printers)), printers, + SCM_ARG1, FUNC_NAME, _("list")); + + pretty_printer_list = printers; + + return SCM_UNSPECIFIED; +} /* Administrivia for pretty-printer-worker smobs. These are created when a matcher recognizes a value. */ @@ -457,11 +477,8 @@ ppscm_find_pretty_printer_from_progspace (SCM value) static SCM ppscm_find_pretty_printer_from_gdb (SCM value) { - SCM pp_list, pp; + SCM pp = ppscm_search_pp_list (pretty_printer_list, value); - /* Fetch the global pretty printer list. */ - pp_list = scm_variable_ref (pretty_printer_list_var); - pp = ppscm_search_pp_list (pp_list, value); return pp; } @@ -1074,6 +1091,15 @@ Create a object.\n\ "\ Return #t if the object is a object." }, + { "pretty-printers", 0, 0, 0, gdbscm_pretty_printers, + "\ +Return the list of global pretty-printers." }, + + { "set-pretty-printers!", 1, 0, 0, + gdbscm_set_pretty_printers_x, + "\ +Set the list of global pretty-printers." }, + END_FUNCTIONS }; @@ -1094,12 +1120,7 @@ gdbscm_initialize_pretty_printers (void) gdbscm_define_functions (pretty_printer_functions, 1); - scm_c_define (pretty_printer_list_name, SCM_EOL); - - pretty_printer_list_var - = scm_c_private_variable (gdbscm_module_name, - pretty_printer_list_name); - gdb_assert (!gdbscm_is_false (pretty_printer_list_var)); + pretty_printer_list = SCM_EOL; pp_type_error_symbol = scm_from_latin1_symbol ("gdb:pp-type-error");