Fix gdbclient to work with Python 3.
Test: gdbclient.py -r date Change-Id: I10616c197dd50fe653e56c2e4c39e2371445c72b
This commit is contained in:
@@ -197,7 +197,7 @@ def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path,
|
|||||||
gdbserver_output_path = os.path.join(tempfile.gettempdir(),
|
gdbserver_output_path = os.path.join(tempfile.gettempdir(),
|
||||||
"gdbclient.log")
|
"gdbclient.log")
|
||||||
print("Redirecting gdbserver output to {}".format(gdbserver_output_path))
|
print("Redirecting gdbserver output to {}".format(gdbserver_output_path))
|
||||||
gdbserver_output = file(gdbserver_output_path, 'w')
|
gdbserver_output = open(gdbserver_output_path, 'w')
|
||||||
return device.shell_popen(gdbserver_cmd, stdout=gdbserver_output,
|
return device.shell_popen(gdbserver_cmd, stdout=gdbserver_output,
|
||||||
stderr=gdbserver_output)
|
stderr=gdbserver_output)
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ def find_file(device, executable_path, sysroot, run_as_cmd=None):
|
|||||||
|
|
||||||
for path, found_locally in generate_files():
|
for path, found_locally in generate_files():
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
return (open(path, "r"), found_locally)
|
return (open(path, "rb"), found_locally)
|
||||||
raise RuntimeError('Could not find executable {}'.format(executable_path))
|
raise RuntimeError('Could not find executable {}'.format(executable_path))
|
||||||
|
|
||||||
def find_executable_path(device, executable_name, run_as_cmd=None):
|
def find_executable_path(device, executable_name, run_as_cmd=None):
|
||||||
@@ -318,14 +318,14 @@ def get_binary_arch(binary_file):
|
|||||||
binary = binary_file.read(0x14)
|
binary = binary_file.read(0x14)
|
||||||
except IOError:
|
except IOError:
|
||||||
raise RuntimeError("failed to read binary file")
|
raise RuntimeError("failed to read binary file")
|
||||||
ei_class = ord(binary[0x4]) # 1 = 32-bit, 2 = 64-bit
|
ei_class = binary[0x4] # 1 = 32-bit, 2 = 64-bit
|
||||||
ei_data = ord(binary[0x5]) # Endianness
|
ei_data = binary[0x5] # Endianness
|
||||||
|
|
||||||
assert ei_class == 1 or ei_class == 2
|
assert ei_class == 1 or ei_class == 2
|
||||||
if ei_data != 1:
|
if ei_data != 1:
|
||||||
raise RuntimeError("binary isn't little-endian?")
|
raise RuntimeError("binary isn't little-endian?")
|
||||||
|
|
||||||
e_machine = ord(binary[0x13]) << 8 | ord(binary[0x12])
|
e_machine = binary[0x13] << 8 | binary[0x12]
|
||||||
if e_machine == 0x28:
|
if e_machine == 0x28:
|
||||||
assert ei_class == 1
|
assert ei_class == 1
|
||||||
return "arm"
|
return "arm"
|
||||||
@@ -338,11 +338,6 @@ def get_binary_arch(binary_file):
|
|||||||
elif e_machine == 0x3E:
|
elif e_machine == 0x3E:
|
||||||
assert ei_class == 2
|
assert ei_class == 2
|
||||||
return "x86_64"
|
return "x86_64"
|
||||||
elif e_machine == 0x08:
|
|
||||||
if ei_class == 1:
|
|
||||||
return "mips"
|
|
||||||
else:
|
|
||||||
return "mips64"
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("unknown architecture: 0x{:x}".format(e_machine))
|
raise RuntimeError("unknown architecture: 0x{:x}".format(e_machine))
|
||||||
|
|
||||||
@@ -368,7 +363,7 @@ def start_gdb(gdb_path, gdb_commands, gdb_flags=None, lldb=False):
|
|||||||
|
|
||||||
# Windows disallows opening the file while it's open for writing.
|
# Windows disallows opening the file while it's open for writing.
|
||||||
script_fd, script_path = tempfile.mkstemp()
|
script_fd, script_path = tempfile.mkstemp()
|
||||||
os.write(script_fd, gdb_commands)
|
os.write(script_fd, gdb_commands.encode())
|
||||||
os.close(script_fd)
|
os.close(script_fd)
|
||||||
if lldb:
|
if lldb:
|
||||||
script_parameter = "--source"
|
script_parameter = "--source"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright (C) 2015 The Android Open Source Project
|
# Copyright (C) 2015 The Android Open Source Project
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user