Skip to content

Commit 127cabb

Browse files
committed
New Black version wants new tuple unpacking syntax
1 parent f72b57a commit 127cabb

8 files changed

Lines changed: 26 additions & 26 deletions

File tree

commands/golang.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def __call__(
119119
address = int(address_or_name, 0)
120120
function_mapping = go_find_func(address)
121121
if function_mapping is not None:
122-
(entry, gofunc) = function_mapping
122+
entry, gofunc = function_mapping
123123
output_line(f"{hex(entry)} - {gofunc.name} (file address = {hex(gofunc.file_addr)})")
124124
else:
125125
print_message(MSG_TYPE.ERROR, f"Could not find function containing address {hex(address)}")

common/golang/analysis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def go_get_function_from_pc(pc: pointer, function_start: pointer, function_name:
131131
"""
132132
record = go_find_func(pc)
133133
if record is not None:
134-
(entry, gofunc) = record
134+
entry, gofunc = record
135135
return (entry, gofunc.name)
136136
return (function_start, function_name)
137137

@@ -335,7 +335,7 @@ def go_annotate_pointer_line(
335335
LLEFState.go_state.type_guesses.add(object_ptr, referenced_type_struct)
336336
unpacked_data = attempt_object_unpack(proc, object_ptr, settings, col_settings)
337337
if unpacked_data:
338-
(_, next_pointer_unpacked) = unpacked_data
338+
_, next_pointer_unpacked = unpacked_data
339339

340340
# Markup line with identified Go data type.
341341
go_type_name = color_string(referenced_type_struct.header.name, col_settings.go_type_color)
@@ -351,7 +351,7 @@ def go_annotate_pointer_line(
351351
unpacked_data = attempt_object_unpack(proc, pointer_to_annotate, settings, col_settings)
352352
object_at_pointer = None
353353
if unpacked_data:
354-
(resolved_type, object_at_pointer) = unpacked_data
354+
resolved_type, object_at_pointer = unpacked_data
355355
if object_at_pointer:
356356
line += f" {GLYPHS.RIGHT_ARROW.value} {resolved_type} {object_at_pointer}"
357357

@@ -420,7 +420,7 @@ def go_stop_hook(exe_ctx: SBExecutionContext, arch: BaseArch, settings: LLEFSett
420420
return
421421

422422
arg_registers = get_arg_registers(arch)
423-
(go_min_version, _) = LLEFState.go_state.pclntab_info.version_bounds
423+
go_min_version, _ = LLEFState.go_state.pclntab_info.version_bounds
424424
if go_min_version >= 17:
425425
# HOOK TASK 1:
426426
# Register-straddling interface/string guessing. Needs register-based calling convention (Go >= 1.17).
@@ -452,7 +452,7 @@ def go_stop_hook(exe_ctx: SBExecutionContext, arch: BaseArch, settings: LLEFSett
452452
pc = frame.GetPC()
453453
record = go_find_func(pc)
454454
if record is not None and LLEFState.go_state.moduledata_info is not None:
455-
(entry, gofunc) = record
455+
entry, gofunc = record
456456
if entry != LLEFState.go_state.prev_func:
457457
LLEFState.go_state.prev_func = entry
458458
# Either this function was just called, or we stopped in the middle of it.

common/golang/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,4 @@ class GoDataNilInterface(GoData):
248248
"""
249249

250250
def __str__(self) -> str:
251-
return "<nil interface>"
251+
return "<nil interface>"

common/golang/moduledata_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_name(self, type_section: bytes, name_offset: int, header: TypeHeader) ->
5555
# Check that pointer + offset doesn't exceed the end pointer for the types section.
5656
if self.types + name_offset < self.etypes:
5757
# Module data layout depends on the Go version.
58-
(go_min_version, go_max_version) = LLEFState.go_state.pclntab_info.version_bounds
58+
go_min_version, go_max_version = LLEFState.go_state.pclntab_info.version_bounds
5959
if go_min_version >= 17:
6060
length, name_offset = read_varint(type_section, name_offset)
6161
if self.types + name_offset + length <= self.etypes:
@@ -166,7 +166,7 @@ def parse(self, proc: SBProcess, data: SBData, target: SBTarget) -> Union[Module
166166

167167
offsets = None
168168

169-
(min_go, max_go) = LLEFState.go_state.pclntab_info.version_bounds
169+
min_go, max_go = LLEFState.go_state.pclntab_info.version_bounds
170170
if min_go == 7 and max_go == 7:
171171
offsets = GO_MD_7_ONLY
172172
if min_go >= 8 and max_go <= 15:

common/golang/static.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def parse_pclntab(proc: SBProcess, target: SBTarget, buf: SBData, file_addr: int
3030
err = SBError()
3131
first8bytes = buf.ReadRawData(err, 0, 8)
3232
if err.Success() and first8bytes is not None:
33-
(magic, pad, min_instr_size, ptr_size) = struct.unpack("<IHBB", first8bytes)
33+
magic, pad, min_instr_size, ptr_size = struct.unpack("<IHBB", first8bytes)
3434

3535
parser = PCLnTabParser(file_addr, magic, pad, min_instr_size, ptr_size)
3636

common/golang/type_getter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def __map_to_type(self, map_repr: str) -> Union[GoTypeMap, None]:
226226
resolved.key_type = key_type
227227
resolved.child_type = val_type
228228

229-
(go_min_version, _) = self.__version
229+
go_min_version, _ = self.__version
230230
if go_min_version < 24:
231231
# Old map type.
232232
bucket_str = (

common/golang/types.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
GoDataFloat,
2828
GoDataInteger,
2929
GoDataMap,
30+
GoDataNilInterface,
3031
GoDataPointer,
3132
GoDataSlice,
3233
GoDataString,
3334
GoDataStruct,
3435
GoDataUnparsed,
35-
GoDataNilInterface
3636
)
3737
from common.golang.util_stateless import entropy, rate_candidate_length, read_varint
3838

@@ -455,7 +455,7 @@ class GoTypeArray(GoType):
455455
length: int
456456

457457
def populate(self, type_section: bytes, offset: int, info: PopulateInfo) -> Union[list[int], None]:
458-
(sub_elem, sup_slice, this_len) = struct.unpack_from("<" + info.ptr_specifier * 3, type_section, offset)
458+
sub_elem, sup_slice, this_len = struct.unpack_from("<" + info.ptr_specifier * 3, type_section, offset)
459459
self.child_addr = sub_elem
460460
self.length = this_len
461461
return [sub_elem, sup_slice]
@@ -517,7 +517,7 @@ class GoTypeChan(GoType):
517517
direction: int
518518

519519
def populate(self, type_section: bytes, offset: int, info: PopulateInfo) -> Union[list[int], None]:
520-
(sub_elem, direction) = struct.unpack_from("<" + info.ptr_specifier * 2, type_section, offset)
520+
sub_elem, direction = struct.unpack_from("<" + info.ptr_specifier * 2, type_section, offset)
521521
self.child_addr = sub_elem
522522
self.direction = direction
523523
return [sub_elem]
@@ -553,7 +553,7 @@ class GoTypeFunc(GoType):
553553

554554
def populate(self, type_section: bytes, offset: int, info: PopulateInfo) -> Union[list[int], None]:
555555
# the size of param count fields and the uncommon offset addition is NOT pointer size dependent.
556-
(num_param_in, num_param_out) = struct.unpack_from("<HH", type_section, offset)
556+
num_param_in, num_param_out = struct.unpack_from("<HH", type_section, offset)
557557

558558
# We consumed 32 bits. On 32-bit, read the next byte: on 64-bit, need 32 bits of padding.
559559
offset += info.ptr_size
@@ -626,16 +626,16 @@ class GoTypeInterface(GoType):
626626

627627
def populate(self, type_section: bytes, offset: int, info: PopulateInfo) -> Union[list[pointer], None]:
628628
self.methods = []
629-
(go_min_version, _) = self.version
630-
(methods_base, methods_len) = struct.unpack_from(
629+
go_min_version, _ = self.version
630+
methods_base, methods_len = struct.unpack_from(
631631
"<" + info.ptr_specifier * 2, type_section, offset + info.ptr_size
632632
)
633633
# Each method structure in the methods table is a struct of two 32-bit integers.
634634
for i in range(methods_len):
635635
imethod_ptr = methods_base + i * 8
636636
if info.types <= imethod_ptr < info.etypes:
637637
imethod_offset = imethod_ptr - info.types
638-
(name_off, type_off) = struct.unpack_from("<II", type_section, imethod_offset)
638+
name_off, type_off = struct.unpack_from("<II", type_section, imethod_offset)
639639

640640
name_off += 1
641641
if go_min_version <= 16:
@@ -701,7 +701,7 @@ def extract_at(self, info: ExtractInfo, addr: pointer, dereferenced_pointers: se
701701
data_pointer = safe_read_unsigned(info, addr + info.ptr_size, info.ptr_size)
702702
if data_pointer is not None:
703703
extracted = interface_type.extract_at(info, data_pointer, dereferenced_pointers, depth)
704-
else:
704+
else:
705705
extracted = GoDataBad(heuristic=Confidence.JUNK.to_float())
706706
else:
707707
extracted = GoDataBad(heuristic=Confidence.JUNK.to_float())
@@ -725,7 +725,7 @@ class GoTypeMap(GoType):
725725
bucket_type: Union[GoType, None]
726726

727727
def populate(self, type_section: bytes, offset: int, info: PopulateInfo) -> Union[list[pointer], None]:
728-
(self.key_addr, self.child_addr, self.bucket_addr) = struct.unpack_from(
728+
self.key_addr, self.child_addr, self.bucket_addr = struct.unpack_from(
729729
"<" + info.ptr_specifier * 3, type_section, offset
730730
)
731731
self.key_type = None
@@ -750,7 +750,7 @@ def extract_at(self, info: ExtractInfo, addr: pointer, dereferenced_pointers: se
750750
extracted: Union[GoData, None] = None
751751

752752
if self.bucket_type is not None:
753-
(go_min_version, _) = self.version
753+
go_min_version, _ = self.version
754754
# Minimum version is only lifted to 24 if we are sure the new map implementation is being used
755755
# (the programmer can choose to use the old version even in 1.24).
756756
parser: Union[SwissMapParser, NoSwissMapParser]
@@ -965,16 +965,16 @@ class GoTypeStruct(GoType):
965965
fields: list[GoTypeStructField]
966966

967967
def populate(self, type_section: bytes, offset: int, info: PopulateInfo) -> Union[list[pointer], None]:
968-
(go_min_version, go_max_version) = self.version
969-
(_, fields_addr, fields_len) = struct.unpack_from("<" + info.ptr_specifier * 3, type_section, offset)
968+
go_min_version, go_max_version = self.version
969+
_, fields_addr, fields_len = struct.unpack_from("<" + info.ptr_specifier * 3, type_section, offset)
970970
self.fields = []
971971

972972
for i in range(fields_len):
973973
# Each field struct is 3 pointers wide.
974974
addr = fields_addr + i * 3 * info.ptr_size
975975
if info.types <= addr < info.etypes:
976976
field_struct_offset = addr - info.types
977-
(field_name_ptr, field_type, field_offset) = struct.unpack_from(
977+
field_name_ptr, field_type, field_offset = struct.unpack_from(
978978
"<" + info.ptr_specifier * 3, type_section, field_struct_offset
979979
)
980980

@@ -1384,7 +1384,7 @@ def parse(self, addr: pointer, nest_depth: int) -> GoData:
13841384
entries = None
13851385
break
13861386
# The next line is well-typed because if entries is None, then we already broke.
1387-
entries.extend(from_table) # type:ignore[union-attr]
1387+
entries.extend(from_table) # type: ignore[union-attr]
13881388

13891389
if entries is not None and len(entries) > 0:
13901390
# A valid map.

common/golang/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def go_find_func_name_offset(pc: int) -> tuple[str, int]:
108108
"""
109109
record = go_find_func(pc)
110110
if record is not None:
111-
(entry, gofunc) = record
111+
entry, gofunc = record
112112
return (gofunc.name, pc - entry)
113113

114114
# otherwise, gracefully fail for display purposes

0 commit comments

Comments
 (0)