This is the mail archive of the
archer-commits@sourceware.org
mailing list for the Archer project.
[SCM] archer-jankratochvil-fedora-merge: Use Python pretty-printers if possible to print base classes inside a derived class, when using GDB's internal C++ printer.
- From: jkratoch at sourceware dot org
- To: archer-commits at sourceware dot org
- Date: 5 Apr 2009 19:17:04 -0000
- Subject: [SCM] archer-jankratochvil-fedora-merge: Use Python pretty-printers if possible to print base classes inside a derived class, when using GDB's internal C++ printer.
The branch, archer-jankratochvil-fedora-merge has been updated
via f6273d446ff87e50976600ba3f71b88d61043e20 (commit)
from d144a3633454046aaeae3e2c369c271834431d36 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit f6273d446ff87e50976600ba3f71b88d61043e20
Author: Phil Muldoon <pmuldoon@redhat.com>
Date: Thu Apr 2 17:59:29 2009 +0100
Use Python pretty-printers if possible to print base classes inside a derived class, when using GDB's internal C++ printer.
ChangeLog:
2009-04-02 Phil Muldoon <pmuldoon@redhat.com>
* cp-valprint.c (cp_print_value): Attempt to execute
Python pretty-printers on base class elements.
Testsuite ChangeLog:
2009-04-02 Phil Muldoon <pmuldoon@redhat.com>
* gdb.python/python-prettyprint.exp (run_lang_tests): Add test for
base class printing in a derived class.
* gdb.python/python-prettyprint.c (Vbase1, Vbase2, Vbase3)
(Derived. VirtualTest): New test classes.
* gdb.python/python-prettyprint.py (pp_multiple_virtual)
(pp_vbase1): New pretty-printers.
(register_pretty_printers): Register pp_vbase1, pp_multiple_virtual.
-----------------------------------------------------------------------
Summary of changes:
gdb/cp-valprint.c | 28 +++++++++++++++----
gdb/testsuite/gdb.python/python-prettyprint.c | 34 ++++++++++++++++++++++-
gdb/testsuite/gdb.python/python-prettyprint.exp | 4 ++-
gdb/testsuite/gdb.python/python-prettyprint.py | 17 +++++++++++
4 files changed, 75 insertions(+), 8 deletions(-)
First 500 lines of diff:
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index dcd32cb..4e33fa0 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -36,6 +36,7 @@
#include "valprint.h"
#include "cp-support.h"
#include "language.h"
+#include "python/python.h"
/* Controls printing of vtbl's */
static void
@@ -418,12 +419,27 @@ cp_print_value (struct type *type, struct type *real_type,
if (skip >= 1)
fprintf_filtered (stream, "<invalid address>");
else
- cp_print_value_fields (baseclass, thistype, base_valaddr,
- thisoffset + boffset, address + boffset,
- stream, recurse, options,
- ((struct type **)
- obstack_base (&dont_print_vb_obstack)),
- 0);
+ {
+ int result = 0;
+
+ /* Attempt to run the Python pretty-printers on the
+ baseclass if possible. */
+ if (!options->raw)
+ result = apply_val_pretty_printer (baseclass, base_valaddr,
+ thisoffset + boffset,
+ address + boffset,
+ stream, recurse,
+ options,
+ current_language);
+
+ if (!result)
+ cp_print_value_fields (baseclass, thistype, base_valaddr,
+ thisoffset + boffset, address + boffset,
+ stream, recurse, options,
+ ((struct type **)
+ obstack_base (&dont_print_vb_obstack)),
+ 0);
+ }
fputs_filtered (", ", stream);
flush_it:
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.c b/gdb/testsuite/gdb.python/python-prettyprint.c
index f8c2435..399be23 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.c
+++ b/gdb/testsuite/gdb.python/python-prettyprint.c
@@ -1,6 +1,6 @@
/* This testcase is part of GDB, the GNU debugger.
- Copyright 2008 Free Software Foundation, Inc.
+ Copyright 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
@@ -44,6 +44,35 @@ struct SSS
const S &b;
};
SSS::SSS (int x, const S& r) : a(x), b(r) { }
+
+class VirtualTest
+{
+ private:
+ int value;
+
+ public:
+ VirtualTest ()
+ {
+ value = 1;
+ }
+};
+
+class Vbase1 : public virtual VirtualTest { };
+class Vbase2 : public virtual VirtualTest { };
+class Vbase3 : public virtual VirtualTest { };
+
+class Derived : public Vbase1, public Vbase2, public Vbase3
+{
+ private:
+ int value;
+
+ public:
+ Derived ()
+ {
+ value = 2;
+ }
+};
+
#endif
typedef struct string_repr
@@ -146,6 +175,9 @@ main ()
SSS sss(15, cps);
SSS& ref (sss);
+
+ Derived derived;
+
#endif
add_item (&c, 23); /* MI breakpoint here */
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.exp b/gdb/testsuite/gdb.python/python-prettyprint.exp
index b2ccb2b..f83b1cd 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/python-prettyprint.exp
@@ -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
@@ -76,6 +76,8 @@ proc run_lang_tests {lang} {
gdb_test "print cpssa" " = {{$nl *zss = 11, *$nl *s = a=<12> b=<$hex>$nl *}, {$nl *zss = 13, *$nl *s = a=<14> b=<$hex>$nl *}}"
gdb_test "print sss" "= a=<15> b=< a=<8> b=<$hex>>"
gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>"
+ gdb_test "print derived" \
+ " = \{.*<Vbase1> = pp class name: Vbase1.*<Vbase2> = \{.*<VirtualTest> = pp value variable is: 1,.*members of Vbase2:.*_vptr.Vbase2 = $hex.*<Vbase3> = \{.*members of Vbase3.*members of Derived:.*value = 2.*"
}
gdb_test "print x" " = $hex \"this is x\""
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.py b/gdb/testsuite/gdb.python/python-prettyprint.py
index 0d9cb87..8379ecf 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.py
+++ b/gdb/testsuite/gdb.python/python-prettyprint.py
@@ -78,6 +78,20 @@ class pp_sss:
def to_string(self):
return "a=<" + str(self.val['a']) + "> b=<" + str(self.val["b"]) + ">"
+class pp_multiple_virtual:
+ def __init__ (self, val):
+ self.val = val
+
+ def to_string (self):
+ return "pp value variable is: " + str (self.val['value'])
+
+class pp_vbase1:
+ def __init__ (self, val):
+ self.val = val
+
+ def to_string (self):
+ return "pp class name: " + self.val.type ().tag ()
+
def lookup_function (val):
"Look-up and return a pretty-printer that can print val."
@@ -119,6 +133,9 @@ def register_pretty_printers ():
pretty_printers_dict[re.compile ('^const S &$')] = pp_s
pretty_printers_dict[re.compile ('^SSS$')] = pp_sss
+ pretty_printers_dict[re.compile ('^VirtualTest$')] = pp_multiple_virtual
+ pretty_printers_dict[re.compile ('^Vbase1$')] = pp_vbase1
+
# 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
hooks/post-receive
--
Repository for Project Archer.