Skip to content

Commit 9b36c1c

Browse files
Determine endianness at a time when it doesn't inadvertantly clear gdb's wrap_buffer via gdb.execute.
Summary: I haven't managed a small reproduction for this bug, it involves complicated and deeply nested data structures with a wide variety of pretty printers. But in general, we shouldn't be combining gdb's command line interface (via gdb.execute) with pretty-printers. Subscribers: christof, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68306 llvm-svn: 373402
1 parent 0da163a commit 9b36c1c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

libcxx/utils/gdb/libcxx/printers.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
_long_int_type = gdb.lookup_type("unsigned long long")
2929

30+
_libcpp_big_endian = False
3031

3132
def addr_as_long(addr):
3233
return int(addr.cast(_long_int_type))
@@ -195,19 +196,14 @@ def _get_short_size(self, short_field, short_size):
195196
field = short_field.type.fields()[1].type.fields()[0]
196197
libcpp_abi_alternate_string_layout = field.name and "__padding" in field.name
197198

198-
# Strictly, this only tells us the current mode, not how libcxx was
199-
# compiled.
200-
libcpp_big_endian = "big endian" in gdb.execute("show endian",
201-
to_string=True)
202-
203199
# This logical structure closely follows the original code (which is clearer
204200
# in C++). Keep them parallel to make them easier to compare.
205201
if libcpp_abi_alternate_string_layout:
206-
if libcpp_big_endian:
202+
if _libcpp_big_endian:
207203
return short_size >> 1
208204
else:
209205
return short_size
210-
elif libcpp_big_endian:
206+
elif _libcpp_big_endian:
211207
return short_size
212208
else:
213209
return short_size >> 1
@@ -969,6 +965,14 @@ def __call__(self, val):
969965
# certain pathological cases. Limit our pretty printers to the progspace.
970966
def _register_libcxx_printers(event):
971967
progspace = event.new_objfile.progspace
968+
# It would be ideal to get the endianness at print time, but
969+
# gdb.execute clears gdb's internal wrap buffer, removing any values
970+
# already generated as part of a larger data structure, and there is
971+
# no python api to get the endianness. Mixed-endianness debugging
972+
# rare enough that this workaround should be adequate.
973+
_libcpp_big_endian = "big endian" in gdb.execute("show endian",
974+
to_string=True)
975+
972976
if not getattr(progspace, _libcxx_printer_name, False):
973977
print("Loading libc++ pretty-printers.")
974978
gdb.printing.register_pretty_printer(

0 commit comments

Comments
 (0)