Add pretty-printer for CORE_ADDR

Message ID 1530126295-3218-1-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi June 27, 2018, 7:04 p.m. UTC
  Add a pretty-printer that prints CORE_ADDR values in hex.

gdb/ChangeLog:

	* gdb-gdb.py.in (CoreAddrPrettyPrinter): New class.
	(type_lookup_function): Recognize CORE_ADDR values.
---
 gdb/gdb-gdb.py.in | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Comments

Pedro Alves June 27, 2018, 7:18 p.m. UTC | #1
On 06/27/2018 08:04 PM, Simon Marchi wrote:
> Add a pretty-printer that prints CORE_ADDR values in hex.

Yes please!
 
Thanks,
Pedro Alves
  
Simon Marchi June 27, 2018, 7:25 p.m. UTC | #2
On 2018-06-27 15:18, Pedro Alves wrote:
> On 06/27/2018 08:04 PM, Simon Marchi wrote:
>> Add a pretty-printer that prints CORE_ADDR values in hex.
> 
> Yes please!

Thanks, pushed.

Simon
  

Patch

diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index cde6068..aeaf69d 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -222,6 +222,16 @@  class StructMainTypePrettyPrinter:
 
         return "\n{" + ",\n ".join(fields) + "}"
 
+
+class CoreAddrPrettyPrinter:
+
+    def __init__(self, val):
+        self._val = val
+
+    def to_string(self):
+        return hex(int(self._val))
+
+
 def type_lookup_function(val):
     """A routine that returns the correct pretty printer for VAL
     if appropriate.  Returns None otherwise.
@@ -230,6 +240,8 @@  def type_lookup_function(val):
         return StructTypePrettyPrinter(val)
     elif val.type.tag == "main_type":
         return StructMainTypePrettyPrinter(val)
+    elif val.type.name == 'CORE_ADDR':
+        return CoreAddrPrettyPrinter(val)
     return None
 
 def register_pretty_printer(objfile):