forked from OSchip/llvm-project
[gdb] Escape unprintable bytes in SmallString and StringRef
llvm-svn: 335561
This commit is contained in:
parent
7bea1aad6a
commit
6a9063743b
|
@ -11,6 +11,8 @@ class Iterator:
|
||||||
def children(self):
|
def children(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def escape_bytes(val, l):
|
||||||
|
return '"' + val.string(encoding='Latin-1', length=l).encode('unicode_escape').decode() + '"'
|
||||||
|
|
||||||
class SmallStringPrinter:
|
class SmallStringPrinter:
|
||||||
"""Print an llvm::SmallString object."""
|
"""Print an llvm::SmallString object."""
|
||||||
|
@ -21,10 +23,7 @@ class SmallStringPrinter:
|
||||||
def to_string(self):
|
def to_string(self):
|
||||||
begin = self.val['BeginX']
|
begin = self.val['BeginX']
|
||||||
end = self.val['EndX']
|
end = self.val['EndX']
|
||||||
return begin.cast(gdb.lookup_type("char").pointer()).string(length = end - begin)
|
return escape_bytes(begin.cast(gdb.lookup_type('char').pointer()), end - begin)
|
||||||
|
|
||||||
def display_hint (self):
|
|
||||||
return 'string'
|
|
||||||
|
|
||||||
class StringRefPrinter:
|
class StringRefPrinter:
|
||||||
"""Print an llvm::StringRef object."""
|
"""Print an llvm::StringRef object."""
|
||||||
|
@ -33,10 +32,7 @@ class StringRefPrinter:
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
||||||
def to_string(self):
|
def to_string(self):
|
||||||
return self.val['Data'].string(encoding='Latin-1', length=self.val['Length'])
|
return escape_bytes(self.val['Data'], self.val['Length'])
|
||||||
|
|
||||||
def display_hint (self):
|
|
||||||
return 'string'
|
|
||||||
|
|
||||||
class SmallVectorPrinter:
|
class SmallVectorPrinter:
|
||||||
"""Print an llvm::SmallVector object."""
|
"""Print an llvm::SmallVector object."""
|
||||||
|
|
Loading…
Reference in New Issue