[llvm] r335561 - [gdb] Escape unprintable bytes in SmallString and StringRef
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 25 17:41:50 PDT 2018
Author: maskray
Date: Mon Jun 25 17:41:49 2018
New Revision: 335561
URL: http://llvm.org/viewvc/llvm-project?rev=335561&view=rev
Log:
[gdb] Escape unprintable bytes in SmallString and StringRef
Modified:
llvm/trunk/utils/gdb-scripts/prettyprinters.py
Modified: llvm/trunk/utils/gdb-scripts/prettyprinters.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gdb-scripts/prettyprinters.py?rev=335561&r1=335560&r2=335561&view=diff
==============================================================================
--- llvm/trunk/utils/gdb-scripts/prettyprinters.py (original)
+++ llvm/trunk/utils/gdb-scripts/prettyprinters.py Mon Jun 25 17:41:49 2018
@@ -11,6 +11,8 @@ class Iterator:
def children(self):
return self
+def escape_bytes(val, l):
+ return '"' + val.string(encoding='Latin-1', length=l).encode('unicode_escape').decode() + '"'
class SmallStringPrinter:
"""Print an llvm::SmallString object."""
@@ -21,10 +23,7 @@ class SmallStringPrinter:
def to_string(self):
begin = self.val['BeginX']
end = self.val['EndX']
- return begin.cast(gdb.lookup_type("char").pointer()).string(length = end - begin)
-
- def display_hint (self):
- return 'string'
+ return escape_bytes(begin.cast(gdb.lookup_type('char').pointer()), end - begin)
class StringRefPrinter:
"""Print an llvm::StringRef object."""
@@ -33,10 +32,7 @@ class StringRefPrinter:
self.val = val
def to_string(self):
- return self.val['Data'].string(encoding='Latin-1', length=self.val['Length'])
-
- def display_hint (self):
- return 'string'
+ return escape_bytes(self.val['Data'], self.val['Length'])
class SmallVectorPrinter:
"""Print an llvm::SmallVector object."""
More information about the llvm-commits
mailing list