Skip to content

Commit

Permalink
[gdb] Fixed task switching for J-Link
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcekay committed Sep 30, 2024
1 parent 5702485 commit 84a3457
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.5.7

- Fix `px4_switch_task` for J-Link (previously only fixed for ST-LINK).

## 1.5.6

- Fix `px4_switch_task` for NuttX v11.
Expand Down
11 changes: 8 additions & 3 deletions src/emdbg/debug/px4/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,23 @@ def write_register(self, name: str, value: int):
def write_registers(self, values: dict[str, int]):
"""Writes all named registers into the CPU"""
for name, value in values.items():
#
if name in ["control", "faultmask", "primask"]: continue
# GDB does not know SP, only MSP and PSP
if name in ["sp", "r13"]:
name = "msp"
if name == "msp":
# NuttX stores the SP incorrectly (is off by 4 bytes)
self.write_register("r13", value + 4)
self.write_register("r13", value)
# Remove double FP registers
if name.startswith("d"): continue
self.write_register(name, value)

def fix_nuttx_sp(self, regs: dict[str, int]):
"""Fixes stored SP, as NuttX incorrectly stores the SP (is off by 4 bytes)"""
regs["msp"] = regs["msp"] + 4
regs["sp"] = regs["msp"]
regs["r13"] = regs["msp"]
return regs

def lookup_static_symbol_in_function(self, symbol_name: str, function_name: str) -> "gdb.Symbol | None":
"""
Lookup a static symbol inside a function. GDB makes this complicated
Expand Down
1 change: 1 addition & 0 deletions src/emdbg/debug/px4/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def switch_to(self) -> bool:
return False
regs = {name: self._tcb["xcp"]["regs"][offset]
for name, offset in _XCP_REGS_MAP.items()}
regs = self.fix_nuttx_sp(regs)
self.write_registers(regs)
self._is_running_switched = True
return True
Expand Down

0 comments on commit 84a3457

Please sign in to comment.