Skip to content

Commit 199243d

Browse files
Check for optimised-out values
1 parent 6b0d606 commit 199243d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

scripts/pretty-printers/gdb/pretty_printers.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ def to_string(self):
2424
typed_pointer = "((const {} *){})".format(self.val.type, raw_address.split(None, 1)[0])
2525

2626
# Check that the pointer is not null.
27-
if gdb.parse_and_eval(typed_pointer + " == 0"):
27+
null_ptr = gdb.parse_and_eval("{} == 0".format(typed_pointer))
28+
if null_ptr.is_optimized_out:
29+
return "<Ptr optimized out>"
30+
if null_ptr:
2831
return ""
2932

3033
# If it isn't attempt to find the string.
31-
value = "(*{})".format(typed_pointer)
32-
return gdb.parse_and_eval(value + ".c_str()")
34+
value = gdb.parse_and_eval("{}->c_str()".format(typed_pointer))
35+
if value.is_optimized_out:
36+
return "<Optimized out>"
37+
return value
3338
except:
3439
return ""
3540

0 commit comments

Comments
 (0)