Skip to content

Commit

Permalink
Add support for soft-bkpt-as-hard
Browse files Browse the repository at this point in the history
  • Loading branch information
ithinuel committed Oct 18, 2023
1 parent 5284109 commit 675e9d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pyocd/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ class OptionInfo(NamedTuple):
OptionInfo('xpsr_control_fields', bool, False,
"When set to True, XPSR and CONTROL registers will have their respective bitfields defined "
"for presentation in gdb."),
OptionInfo('soft_bkpt_as_hard', bool, False,
"Replace software breakpoints with hardware breakpoints."),
]

## @brief The runtime dictionary of options.
Expand Down
9 changes: 7 additions & 2 deletions pyocd/gdbserver/gdbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,16 @@ def __init__(self, session, core=None):
self.semihost_use_syscalls = session.options.get('semihost_use_syscalls') # Not subscribed.
self.serve_local_only = session.options.get('serve_local_only') # Not subscribed.
self.report_core = session.options.get('report_core_number')
self.soft_bkpt_as_hard = session.options.get('soft_bkpt_as_hard')

# Subscribe to changes for those of the above options that make sense to change at runtime.
self.session.options.subscribe(self._option_did_change, [
'vector_catch',
'step_into_interrupt',
'persist',
'enable_semihosting',
'report_core_number',
'soft_bkpt_as_hard',
])

self.packet_size = 2048
Expand Down Expand Up @@ -464,7 +467,8 @@ def breakpoint(self, data):
# handle software breakpoint Z0/z0
if data[1:2] == b'0':
if data[0:1] == b'Z':
if not self.target.set_breakpoint(addr, Target.BreakpointType.SW):
bkpt_type = Target.BreakpointType.HW if self.soft_bkpt_as_hard else Target.BreakpointType.SW
if not self.target.set_breakpoint(addr, bkpt_type):
return self.create_rsp_packet(b'E01') #EPERM
else:
self.target.remove_breakpoint(addr)
Expand Down Expand Up @@ -1266,4 +1270,5 @@ def _option_did_change(self, notification):
LOG.info("Semihosting %s", ('enabled' if self.enable_semihosting else 'disabled'))
elif notification.event == 'report_core_number':
self.report_core = notification.data.new_value

elif notification.event == 'soft_bkpt_as_hard':
self.soft_bkpt_as_hard = notification.data.new_value
3 changes: 3 additions & 0 deletions pyocd/subcommands/gdbserver_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def get_args(cls) -> List[argparse.ArgumentParser]:
help="Allow single stepping to step into interrupts.")
gdbserver_options.add_argument("-c", "--command", dest="commands", metavar="CMD", action='append', nargs='+',
help="Run command (OpenOCD compatibility).")
gdbserver_options.add_argument("-bh", "--soft-bkpt-as-hard", dest="soft_bkpt_as_hard", default=False, action="store_true",
help="Replace software breakpoints with hardware breakpoints.")

return [cls.CommonOptions.COMMON, cls.CommonOptions.CONNECT, gdbserver_parser]

Expand Down Expand Up @@ -147,6 +149,7 @@ def invoke(self) -> int:
'enable_semihosting' : self._args.enable_semihosting,
'serve_local_only' : self._args.serve_local_only,
'vector_catch' : self._args.vector_catch,
'soft_bkpt_as_hard' : self._args.soft_bkpt_as_hard,
})

# Split list of cores to serve.
Expand Down
3 changes: 2 additions & 1 deletion pyocd/tools/gdb_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def build_parser(self):
parser.add_argument("-s", "--step-int", dest="step_into_interrupt", default=None, action="store_true", help="Allow single stepping to step into interrupts.")
parser.add_argument("-f", "--frequency", dest="frequency", default=None, type=int, help="Set the SWD clock frequency in Hz.")
parser.add_argument("-o", "--persist", dest="persist", default=None, action="store_true", help="Keep GDB server running even after remote has detached.")
parser.add_argument("-bh", "--soft-bkpt-as-hard", dest="soft_bkpt_as_hard", default=False, action="store_true", help="Replace software breakpoints with hardware breakpoints (ignored).")
parser.add_argument("-bh", "--soft-bkpt-as-hard", dest="soft_bkpt_as_hard", default=False, action="store_true", help="Replace software breakpoints with hardware breakpoints.")
group = parser.add_mutually_exclusive_group()
group.add_argument("-ce", "--chip_erase", action="store_true", help="Use chip erase when programming.")
group.add_argument("-se", "--sector_erase", action="store_true", help="Use sector erase when programming.")
Expand Down Expand Up @@ -133,6 +133,7 @@ def get_gdb_server_settings(self, args):
'fast_program' : args.fast_program,
'enable_semihosting' : args.enable_semihosting,
'semihost_console_type' : args.semihost_console_type,
'soft_bkpt_as_hard' : args.soft_bkpt_as_hard,
'telnet_port' : args.telnet_port,
'semihost_use_syscalls' : args.semihost_use_syscalls,
'serve_local_only' : args.serve_local_only,
Expand Down

0 comments on commit 675e9d2

Please sign in to comment.