public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: pmuldoon@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  archer-pmuldoon-pretty-printers-lookup: Account for a Py_Incref(null) bug. Convert pretty-print testsuite.
Date: Mon, 09 Feb 2009 14:17:00 -0000	[thread overview]
Message-ID: <20090209141702.18125.qmail@sourceware.org> (raw)

The branch, archer-pmuldoon-pretty-printers-lookup has been updated
       via  1f68dc61fb7c0e20e96439e16ca08643a822fad1 (commit)
      from  5e79d7e4f26c7cf2b7d4dd9a5ee41d8674e02c3d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 1f68dc61fb7c0e20e96439e16ca08643a822fad1
Author: Phil Muldoon <pmuldoon@redhat.com>
Date:   Mon Feb 9 14:15:30 2009 +0000

    Account for a Py_Incref(null) bug. Convert pretty-print testsuite.

-----------------------------------------------------------------------

Summary of changes:
 gdb/python/python.c                            |   17 +++---
 gdb/testsuite/gdb.python/python-prettyprint.py |   65 +++++++++++++++++-------
 2 files changed, 54 insertions(+), 28 deletions(-)

First 500 lines of diff:
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 027526f..c5097b6 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -869,7 +869,7 @@ find_pretty_printer (struct value *value)
 {
 
   PyObject *pp_list = NULL;
-  PyObject *function = NULL;
+  PyObject *function = Py_None;
   struct objfile *obj;
 
   /* Look at the pretty-printer dictionary for each objfile.  */
@@ -1274,7 +1274,7 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
 			  const struct value_print_options *options,
 			  const struct language_defn *language)
 {
-  PyObject *func = NULL;
+  PyObject *printer = NULL;
   struct value *value;
   char *hint = NULL;
   struct cleanup *cleanups;
@@ -1290,23 +1290,22 @@ apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
   value = value_from_contents_and_address (type, valaddr, address);
 
   /* Find the constructor.  */
-  func = find_pretty_printer (value);
-  if (func == Py_None)
+  printer = find_pretty_printer (value);
+  if (printer == Py_None)
     goto done;
 
   /* If we are printing a map, we want some special formatting.  */
-  hint = gdbpy_get_display_hint (func);
+  hint = gdbpy_get_display_hint (printer);
   make_cleanup (free_current_contents, &hint);
 
   /* Print the section */
-  print_string_repr (func, hint, stream, recurse, options, language);
-  print_children (func, hint, stream, recurse, options, language);
-  make_cleanup_py_decref (func);
+  print_string_repr (printer, hint, stream, recurse, options, language);
+  print_children (printer, hint, stream, recurse, options, language);
+  make_cleanup_py_decref (printer);
   result = 1;
 
 
  done:
-  Py_DECREF(func);
   do_cleanups (cleanups);
   return result;
 }
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.py b/gdb/testsuite/gdb.python/python-prettyprint.py
index ecd4fc6..fcedb66 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.py
+++ b/gdb/testsuite/gdb.python/python-prettyprint.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2008 Free Software Foundation, Inc.
+# Copyright (C) 2008, 2009 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
@@ -16,6 +16,8 @@
 # This file is part of the GDB testsuite.  It tests python pretty
 # printers.
 
+import re
+
 # Test returning a Value from a printer.
 class string_print:
     def __init__(self, val):
@@ -76,21 +78,46 @@ class pp_sss:
     def to_string(self):
         return "a=<" + str(self.val['a']) + "> b=<" + str(self.val["b"]) + ">"
 
-gdb.pretty_printers['^struct s$']   = pp_s
-gdb.pretty_printers['^s$']   = pp_s
-gdb.pretty_printers['^S$']   = pp_s
-
-gdb.pretty_printers['^struct ss$']  = pp_ss
-gdb.pretty_printers['^ss$']  = pp_ss
-
-gdb.pretty_printers['^const S &$']   = pp_s
-gdb.pretty_printers['^SSS$']  = pp_sss
-
-# Note that we purposely omit the typedef names here.
-# Printer lookup is based on canonical name.
-# However, we do need both tagged and untagged variants, to handle
-# both the C and C++ cases.
-gdb.pretty_printers['^struct string_repr$'] = string_print
-gdb.pretty_printers['^struct container$'] = ContainerPrinter
-gdb.pretty_printers['^string_repr$'] = string_print
-gdb.pretty_printers['^container$'] = ContainerPrinter
+def lookup_function (val):
+    "Look-up and return a pretty-printer that can print val."
+    # Extract the type from the value.
+    typename =  val.type ().tag ()
+
+    if (typename == None):
+        return None
+
+    # Iterate over local dictionary of types to determine
+    # if a printer is registered for that type. Return an
+    # instantiation of the printer if found.
+    for function in pretty_printers_dict:
+        if function.search(typename):
+            return pretty_printers_dict[function] (val)
+        
+    # Cannot find a pretty printer. Return None.
+
+    return None
+
+
+def register_pretty_printers ():
+    pretty_printers_dict[re.compile('^struct s$')]   = pp_s
+    pretty_printers_dict[re.compile('^s$')]   = pp_s
+    pretty_printers_dict[re.compile('^S$')]   = pp_s
+
+    pretty_printers_dict[re.compile('^struct ss$')]  = pp_ss
+    pretty_printers_dict[re.compile('^ss$')]  = pp_ss
+    pretty_printers_dict[re.compile('^const S &$')]   = pp_s
+    pretty_printers_dict[re.compile('^SSS$')]  = pp_sss
+    
+    # Note that we purposely omit the typedef names here.
+    # Printer lookup is based on canonical name.
+    # However, we do need both tagged and untagged variants, to handle
+    # both the C and C++ cases.
+    pretty_printers_dict[re.compile('^struct string_repr$')] = string_print
+    pretty_printers_dict[re.compile('^struct container$')] = ContainerPrinter
+    pretty_printers_dict[re.compile('^string_repr$')] = string_print
+    pretty_printers_dict[re.compile('^container$')] = ContainerPrinter
+    
+pretty_printers_dict = {}
+
+register_pretty_printers ()
+gdb.pretty_printers.append (lookup_function)


hooks/post-receive
--
Repository for Project Archer.


                 reply	other threads:[~2009-02-09 14:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090209141702.18125.qmail@sourceware.org \
    --to=pmuldoon@sourceware.org \
    --cc=archer-commits@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).