Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: tools/gdb/gdb_chrome.py

Issue 2897573004: Add a GDB pretty printer for base::flat_map. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gdb/gdb_chrome.py
diff --git a/tools/gdb/gdb_chrome.py b/tools/gdb/gdb_chrome.py
index 4f6976c2fd3c4c84951260c48fb1395ea036bb81..f3073e382239431b8172edc1696e366aeddf9c34 100644
--- a/tools/gdb/gdb_chrome.py
+++ b/tools/gdb/gdb_chrome.py
@@ -14,6 +14,12 @@ Add this to your gdb by amending your ~/.gdbinit as follows:
Use
(gdb) p /r any_variable
to print |any_variable| without using any printers.
+
+To interactively type Python for development of the printers:
+ (gdb) python foo = gdb.parse_and_eval('bar')
+to put the C++ value 'bar' in the current scope into a Python variable 'foo'.
+Then you can interact with that variable:
+ (gdb) python print foo['impl_']
"""
import datetime
@@ -240,6 +246,20 @@ class ManualConstructorPrinter(object):
pp_set.add_printer('base::ManualConstructor', '^base::ManualConstructor<.*>$', ManualConstructorPrinter)
+class FlatMapPrinter(object):
+ def __init__(self, val):
+ self.val = val
+
+ def to_string(self):
+ # It would be nice to match the output of std::map which is a little
+ # nicer than printing the vector of pairs. But iterating over it in
+ # Python is much more complicated and this output is reasonable.
+ # (Without this printer, a flat_map will output 7 lines of internal
+ # template goop before the vector contents.)
+ return 'base::flat_map with ' + str(self.val['impl_']['body_'])
+pp_set.add_printer('base::flat_map', '^base::flat_map<.*>$', FlatMapPrinter)
+
+
class ValuePrinter(object):
def __init__(self, val):
self.val = val
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698