@@ -111,26 +111,6 @@ def safe_range(val):
111
111
# threshold in case the data was corrupted
112
112
return range (safety_limit (int (val )))
113
113
114
- try :
115
- os_fsencode = os .fsencode
116
- except AttributeError :
117
- def os_fsencode (filename ):
118
- if not isinstance (filename , unicode ):
119
- return filename
120
- encoding = sys .getfilesystemencoding ()
121
- if encoding == 'mbcs' :
122
- # mbcs doesn't support surrogateescape
123
- return filename .encode (encoding )
124
- encoded = []
125
- for char in filename :
126
- # surrogateescape error handler
127
- if 0xDC80 <= ord (char ) <= 0xDCFF :
128
- byte = chr (ord (char ) - 0xDC00 )
129
- else :
130
- byte = char .encode (encoding )
131
- encoded .append (byte )
132
- return '' .join (encoded )
133
-
134
114
class StringTruncated (RuntimeError ):
135
115
pass
136
116
@@ -174,16 +154,12 @@ def __init__(self, gdbval, cast_to=None):
174
154
175
155
def field (self , name ):
176
156
'''
177
- Get the gdb.Value for the given field within the PyObject, coping with
178
- some python 2 versus python 3 differences.
157
+ Get the gdb.Value for the given field within the PyObject.
179
158
180
159
Various libpython types are defined using the "PyObject_HEAD" and
181
160
"PyObject_VAR_HEAD" macros.
182
161
183
- In Python 2, this these are defined so that "ob_type" and (for a var
184
- object) "ob_size" are fields of the type in question.
185
-
186
- In Python 3, this is defined as an embedded PyVarObject type thus:
162
+ In Python, this is defined as an embedded PyVarObject type thus:
187
163
PyVarObject ob_base;
188
164
so that the "ob_size" field is located insize the "ob_base" field, and
189
165
the "ob_type" is most easily accessed by casting back to a (PyObject*).
@@ -204,8 +180,7 @@ def field(self, name):
204
180
205
181
def pyop_field (self , name ):
206
182
'''
207
- Get a PyObjectPtr for the given PyObject* field within this PyObject,
208
- coping with some python 2 versus python 3 differences.
183
+ Get a PyObjectPtr for the given PyObject* field within this PyObject.
209
184
'''
210
185
return PyObjectPtr .from_pyobject_ptr (self .field (name ))
211
186
@@ -924,7 +899,7 @@ def proxyval(self, visited):
924
899
return result
925
900
926
901
def write_repr (self , out , visited ):
927
- # Write this out as a Python 3 int literal, i.e. without the "L" suffix
902
+ # Write this out as a Python int literal
928
903
proxy = self .proxyval (visited )
929
904
out .write ("%s" % proxy )
930
905
@@ -1170,7 +1145,7 @@ def current_line(self):
1170
1145
1171
1146
filename = self .filename ()
1172
1147
try :
1173
- with open (os_fsencode (filename ), 'r' , encoding = "utf-8" ) as fp :
1148
+ with open (os . fsencode (filename ), 'r' , encoding = "utf-8" ) as fp :
1174
1149
lines = fp .readlines ()
1175
1150
except IOError :
1176
1151
return None
@@ -1263,7 +1238,7 @@ def proxyval(self, visited):
1263
1238
return set (members )
1264
1239
1265
1240
def write_repr (self , out , visited ):
1266
- # Emulate Python 3 's set_repr
1241
+ # Emulate Python's set_repr
1267
1242
tp_name = self .safe_tp_name ()
1268
1243
1269
1244
# Guard against infinite loops:
@@ -1272,13 +1247,13 @@ def write_repr(self, out, visited):
1272
1247
return
1273
1248
visited .add (self .as_address ())
1274
1249
1275
- # Python 3 's set_repr special-cases the empty set:
1250
+ # Python's set_repr special-cases the empty set:
1276
1251
if not self .field ('used' ):
1277
1252
out .write (tp_name )
1278
1253
out .write ('()' )
1279
1254
return
1280
1255
1281
- # Python 3 uses {} for set literals:
1256
+ # Python uses {} for set literals:
1282
1257
if tp_name != 'set' :
1283
1258
out .write (tp_name )
1284
1259
out .write ('(' )
@@ -1309,13 +1284,13 @@ def proxyval(self, visited):
1309
1284
return str (self )
1310
1285
1311
1286
def write_repr (self , out , visited ):
1312
- # Write this out as a Python 3 bytes literal, i.e. with a "b" prefix
1287
+ # Write this out as a Python bytes literal, i.e. with a "b" prefix
1313
1288
1314
- # Get a PyStringObject* within the Python 2 gdb process:
1289
+ # Get a PyStringObject* within the Python gdb process:
1315
1290
proxy = self .proxyval (visited )
1316
1291
1317
- # Transliteration of Python 3 's Objects/bytesobject.c:PyBytes_Repr
1318
- # to Python 2 code:
1292
+ # Transliteration of Python's Objects/bytesobject.c:PyBytes_Repr
1293
+ # to Python code:
1319
1294
quote = "'"
1320
1295
if "'" in proxy and not '"' in proxy :
1321
1296
quote = '"'
@@ -1380,7 +1355,7 @@ class PyTypeObjectPtr(PyObjectPtr):
1380
1355
1381
1356
1382
1357
def _unichr_is_printable (char ):
1383
- # Logic adapted from Python 3 's Tools/unicode/makeunicodedata.py
1358
+ # Logic adapted from Python's Tools/unicode/makeunicodedata.py
1384
1359
if char == u" " :
1385
1360
return True
1386
1361
import unicodedata
@@ -1416,17 +1391,17 @@ def proxyval(self, visited):
1416
1391
1417
1392
# Convert the int code points to unicode characters, and generate a
1418
1393
# local unicode instance.
1419
- result = u '' .join (map (chr , code_points ))
1394
+ result = '' .join (map (chr , code_points ))
1420
1395
return result
1421
1396
1422
1397
def write_repr (self , out , visited ):
1423
- # Write this out as a Python 3 str literal, i.e. without a "u" prefix
1398
+ # Write this out as a Python str literal
1424
1399
1425
- # Get a PyUnicodeObject* within the Python 2 gdb process:
1400
+ # Get a PyUnicodeObject* within the Python gdb process:
1426
1401
proxy = self .proxyval (visited )
1427
1402
1428
- # Transliteration of Python 3 's Object/unicodeobject.c:unicode_repr
1429
- # to Python 2 :
1403
+ # Transliteration of Python's Object/unicodeobject.c:unicode_repr
1404
+ # to Python:
1430
1405
if "'" in proxy and '"' not in proxy :
1431
1406
quote = '"'
1432
1407
else :
@@ -1477,7 +1452,7 @@ def write_repr(self, out, visited):
1477
1452
# (categories Z* and C* except ASCII space)
1478
1453
if not printable :
1479
1454
if ch2 is not None :
1480
- # Match Python 3 's representation of non-printable
1455
+ # Match Python's representation of non-printable
1481
1456
# wide characters.
1482
1457
code = (ord (ch ) & 0x03FF ) << 10
1483
1458
code |= ord (ch2 ) & 0x03FF
@@ -1608,8 +1583,8 @@ def pretty_printer_lookup(gdbval):
1608
1583
if the code is autoloaded by gdb when visiting libpython.so, provided
1609
1584
that this python file is installed to the same path as the library (or its
1610
1585
.debug file) plus a "-gdb.py" suffix, e.g:
1611
- /usr/lib/libpython2.6 .so.1.0-gdb.py
1612
- /usr/lib/debug/usr/lib/libpython2.6 .so.1.0.debug-gdb.py
1586
+ /usr/lib/libpython3.12 .so.1.0-gdb.py
1587
+ /usr/lib/debug/usr/lib/libpython3.12 .so.1.0.debug-gdb.py
1613
1588
"""
1614
1589
def register (obj ):
1615
1590
if obj is None :
@@ -1928,7 +1903,7 @@ def invoke(self, args, from_tty):
1928
1903
start = 1
1929
1904
1930
1905
try :
1931
- f = open (os_fsencode (filename ), 'r' , encoding = "utf-8" )
1906
+ f = open (os . fsencode (filename ), 'r' , encoding = "utf-8" )
1932
1907
except IOError as err :
1933
1908
sys .stdout .write ('Unable to open %s: %s\n '
1934
1909
% (filename , err ))
0 commit comments