Skip to content

Commit 91b2134

Browse files
committed
Add support for debugging workers.
1 parent da46dde commit 91b2134

File tree

1 file changed

+28
-17
lines changed
  • pebble_tool/commands/sdk/project

1 file changed

+28
-17
lines changed

pebble_tool/commands/sdk/project/debug.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ class GdbCommand(PebbleCommand):
1919
valid_connections = {'emulator'}
2020

2121
@classmethod
22-
def _find_app_load_offset(cls, fw_elf):
23-
elf_sections = subprocess.check_output(["arm-none-eabi-readelf", "-s", fw_elf])
22+
def _find_app_load_offset(cls, fw_elf, kind):
23+
elf_sections = subprocess.check_output(["arm-none-eabi-readelf", "-W", "-s", fw_elf])
2424

2525
# Figure out where we load the app into firmware memory
2626
for line in elf_sections.split(b'\n'):
27-
if b'__app_flash_load_start__' in line:
27+
if b'__{}_flash_load_start__'.format(kind) in line:
2828
return int(line.split()[1], 16)
2929
else:
30-
raise ToolError("Couldn't find the app address offset.")
30+
raise ToolError("Couldn't find the {} address offset.".format(kind))
3131

3232
@classmethod
3333
def _find_real_app_section_offsets(cls, base_addr, app_elf_path):
@@ -41,6 +41,16 @@ def _find_real_app_section_offsets(cls, base_addr, app_elf_path):
4141
offsets[cols[1][1:]] = int(cols[3], 16) + base_addr
4242
return offsets
4343

44+
def _get_symbol_command(self, elf, kind):
45+
base_address = self._find_app_load_offset(self._fw_elf, kind)
46+
offsets = self._find_real_app_section_offsets(base_address, elf)
47+
48+
add_symbol_file = 'add-symbol-file "{elf}" {text} '.format(elf=elf, **offsets)
49+
del offsets['text']
50+
add_symbol_file += ' '.join('-s .{} {}'.format(k, v) for k, v in iteritems(offsets))
51+
52+
return add_symbol_file
53+
4454
def __call__(self, args):
4555
super(GdbCommand, self).__call__(args)
4656
# We poke around in the ManagedEmulatorTransport, so it's important that we actually have one.
@@ -54,36 +64,37 @@ def __call__(self, args):
5464
raise ToolError("The emulator does not have gdb support. Try killing and re-running it.")
5565

5666
sdk_root = sdk_manager.path_for_sdk(sdk_version)
57-
fw_elf = os.path.join(sdk_root, 'pebble', platform, 'qemu', '{}_sdk_debug.elf'.format(platform))
58-
if not os.path.exists(fw_elf):
59-
raise ToolError("SDK {} does not support app debugging. You need at least SDK 3.10.".format(sdk_version))
67+
self._fw_elf = os.path.join(sdk_root, 'pebble', platform, 'qemu', '{}_sdk_debug.elf'.format(platform))
6068

61-
base_address = self._find_app_load_offset(fw_elf)
69+
if not os.path.exists(self._fw_elf):
70+
raise ToolError("SDK {} does not support app debugging. You need at least SDK 3.10.".format(sdk_version))
6271

6372
app_elf_path = os.path.join(os.getcwd(), 'build', platform, 'pebble-app.elf')
6473
if not os.path.exists(app_elf_path):
6574
raise ToolError("No app debugging information available. "
6675
"You must be in a project directory and have built the app.")
6776

68-
offsets = self._find_real_app_section_offsets(base_address, app_elf_path)
69-
70-
add_symbol_file = 'add-symbol-file "{elf}" {text} '.format(elf=app_elf_path, **offsets)
71-
del offsets['text']
72-
add_symbol_file += ' '.join('-s .{} {}'.format(k, v) for k, v in iteritems(offsets))
73-
7477
gdb_commands = [
7578
"set charset US-ASCII", # Avoid a bug in the ancient version of libiconv apple ships.
7679
"target remote :{}".format(gdb_port),
7780
"set confirm off",
78-
add_symbol_file,
81+
self._get_symbol_command(app_elf_path, 'app')
82+
]
83+
84+
# Optionally add the worker symbols, if any exist.
85+
worker_elf_path = os.path.join(os.getcwd(), 'build', platform, 'pebble-worker.elf')
86+
if os.path.exists(worker_elf_path):
87+
gdb_commands.append(self._get_symbol_command(worker_elf_path, 'worker'))
88+
89+
gdb_commands.extend([
7990
"set confirm on",
8091
"break app_crashed", # app crashes (as of FW 3.10) go through this symbol for our convenience.
8192
'echo \nPress ctrl-D or type \'quit\' to exit.\n',
8293
'echo Try `pebble gdb --help` for a short cheat sheet.\n',
8394
'echo Note that the emulator does not yet crash on memory access violations.\n'
84-
]
95+
])
8596

86-
gdb_args = ['arm-none-eabi-gdb', fw_elf, '-q'] + ['--ex={}'.format(x) for x in gdb_commands]
97+
gdb_args = ['arm-none-eabi-gdb', self._fw_elf, '-q'] + ['--ex={}'.format(x) for x in gdb_commands]
8798

8899
# Ignore SIGINT, or we'll die every time the user tries to pause execution.
89100
signal.signal(signal.SIGINT, signal.SIG_IGN)

0 commit comments

Comments
 (0)