|
27 | 27 |
|
28 | 28 | _long_int_type = gdb.lookup_type("unsigned long long")
|
29 | 29 |
|
| 30 | +_libcpp_big_endian = False |
30 | 31 |
|
31 | 32 | def addr_as_long(addr):
|
32 | 33 | return int(addr.cast(_long_int_type))
|
@@ -195,19 +196,14 @@ def _get_short_size(self, short_field, short_size):
|
195 | 196 | field = short_field.type.fields()[1].type.fields()[0]
|
196 | 197 | libcpp_abi_alternate_string_layout = field.name and "__padding" in field.name
|
197 | 198 |
|
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 |
| - |
203 | 199 | # This logical structure closely follows the original code (which is clearer
|
204 | 200 | # in C++). Keep them parallel to make them easier to compare.
|
205 | 201 | if libcpp_abi_alternate_string_layout:
|
206 |
| - if libcpp_big_endian: |
| 202 | + if _libcpp_big_endian: |
207 | 203 | return short_size >> 1
|
208 | 204 | else:
|
209 | 205 | return short_size
|
210 |
| - elif libcpp_big_endian: |
| 206 | + elif _libcpp_big_endian: |
211 | 207 | return short_size
|
212 | 208 | else:
|
213 | 209 | return short_size >> 1
|
@@ -969,6 +965,14 @@ def __call__(self, val):
|
969 | 965 | # certain pathological cases. Limit our pretty printers to the progspace.
|
970 | 966 | def _register_libcxx_printers(event):
|
971 | 967 | 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 | + |
972 | 976 | if not getattr(progspace, _libcxx_printer_name, False):
|
973 | 977 | print("Loading libc++ pretty-printers.")
|
974 | 978 | gdb.printing.register_pretty_printer(
|
|
0 commit comments