llvm.org GIT mirror llvm / d411816
[gdb] Escape unprintable bytes in SmallString and StringRef git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335561 91177308-0d34-0410-b5e6-96231b3b80d8 Fangrui Song 2 years ago
1 changed file(s) with 4 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1010 def children(self):
1111 return self
1212
13 def escape_bytes(val, l):
14 return '"' + val.string(encoding='Latin-1', length=l).encode('unicode_escape').decode() + '"'
1315
1416 class SmallStringPrinter:
1517 """Print an llvm::SmallString object."""
2022 def to_string(self):
2123 begin = self.val['BeginX']
2224 end = self.val['EndX']
23 return begin.cast(gdb.lookup_type("char").pointer()).string(length = end - begin)
24
25 def display_hint (self):
26 return 'string'
25 return escape_bytes(begin.cast(gdb.lookup_type('char').pointer()), end - begin)
2726
2827 class StringRefPrinter:
2928 """Print an llvm::StringRef object."""
3231 self.val = val
3332
3433 def to_string(self):
35 return self.val['Data'].string(encoding='Latin-1', length=self.val['Length'])
36
37 def display_hint (self):
38 return 'string'
34 return escape_bytes(self.val['Data'], self.val['Length'])
3935
4036 class SmallVectorPrinter:
4137 """Print an llvm::SmallVector object."""