Skip to content

Commit 2eca2b1

Browse files
Add string number to output and check it's valid
Adjust the display_hint type and the formatting to show string as before except after the number
1 parent 199243d commit 2eca2b1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

scripts/pretty-printers/gdb/pretty_printers.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,30 @@ def to_string(self):
2323
# Addresses are usually {address} {optional type_name}
2424
typed_pointer = "((const {} *){})".format(self.val.type, raw_address.split(None, 1)[0])
2525

26+
string_no = self.val["no"]
27+
2628
# Check that the pointer is not null.
2729
null_ptr = gdb.parse_and_eval("{} == 0".format(typed_pointer))
2830
if null_ptr.is_optimized_out:
29-
return "<Ptr optimized out>"
31+
return "{}: <Ptr optimized out>".format(string_no)
3032
if null_ptr:
3133
return ""
3234

33-
# If it isn't attempt to find the string.
35+
table_len = gdb.parse_and_eval("get_string_container().string_vector.size()")
36+
if table_len.is_optimized_out:
37+
return "{}: <Table len optimized out>".format(string_no)
38+
if string_no >= table_len:
39+
return "{} index ({}) out of range".format(self.val.type, string_no)
40+
3441
value = gdb.parse_and_eval("{}->c_str()".format(typed_pointer))
3542
if value.is_optimized_out:
36-
return "<Optimized out>"
37-
return value
43+
return "{}: <Optimized out>".format(string_no)
44+
return "{}: \"{}\"".format(string_no, value.string().replace("\0", "").replace("\"", "\\\""))
3845
except:
3946
return ""
4047

4148
def display_hint(self):
42-
return "string"
49+
return None
4350

4451

4552
class InstructionPrettyPrinter:

0 commit comments

Comments
 (0)