7
31
Fork
You've already forked blackmagic
23

armv8m: make the debugger handle better faults through ICSR #2187

Merged
mean00 merged 1 commit from better_handle_armv8_faults_v2 into main 2026年02月11日 13:04:33 +01:00
mean00 commented 2026年02月01日 19:15:49 +01:00 (Migrated from github.com)
Copy link

Detailed description

The ArmV8m does not handle faults the same way. The two main differences are :

  • The fault will trigger BEFORE executing the fault rather than after
  • The info is split between between DFSR and the new ICSR

As a result the current code does not handle fault very well.
Put a breakpoint on a fault (for example asm("udf #0") and try to "si" on it.

Gdb will appear to get stuck there because the debugger will see the state BEFORE the fault is actually executed and as a result not detect the fault.

The MR adds a separate path that , for ArmV8M, it checks if a fault is pending on ICSR
The "si" command on a fault now works and you proceed on to the handler.

I tested it on a RP2350 and on another CortexM33 successfully.
I'm not convinced all cases are covered as some parts are configurable, but at least it's working better.

Not sure either if the new two new registers should be renamed with V8M in the name or something.

Your checklist for this pull request

Closing issues

N/A

<!-- Filling this template is mandatory --> ## Detailed description The ArmV8m does not handle faults the same way. The two main differences are : - The fault will trigger BEFORE executing the fault rather than after - The info is split between between DFSR and the new ICSR - As a result the current code does not handle fault very well. Put a breakpoint on a fault (for example __asm__("udf #0") and try to "si" on it. Gdb will appear to get stuck there because the debugger will see the state BEFORE the fault is actually executed and as a result not detect the fault. The MR adds a separate path that , for ArmV8M, it checks if a fault is pending on ICSR The "si" command on a fault now works and you proceed on to the handler. I tested it on a RP2350 and on another CortexM33 successfully. I'm not convinced all cases are covered as some parts are configurable, but at least it's working better. Not sure either if the new two new registers should be renamed with _V8M_ in the name or something. ## Your checklist for this pull request * [x] I've read the [Code of Conduct](https://github.com/blackmagic-debug/blackmagic/blob/main/CODE_OF_CONDUCT.md) * [x] I've read the [guidelines for contributing](https://github.com/blackmagic-debug/blackmagic/blob/main/CONTRIBUTING.md) to this repository * [x] It builds for hardware native (see [Building the firmware](https://github.com/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-firmware)) * [x] It builds as BMDA (see [Building the BMDA](https://github.com/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-app)) * [x] I've tested it to the best of my ability * [x] My commit messages provide a useful short description of what the commits do ## Closing issues N/A
dragonmux left a comment
Copy link

Got a few notes on going through this PR - with them fixed though we'll be happy to merge this.

Got a few notes on going through this PR - with them fixed though we'll be happy to merge this.
@ -864,7 +864,21 @@ static target_halt_reason_e cortexm_halt_poll(target_s *target, target_addr64_t
priv->dcache_enabled = ccr & CORTEXM_CCR_DCACHE_ENABLE;

Given pending is unsigned, perhaps (pending > 0U && pending < 8U)? - also please let clang-format run here, the { should be on this line (or, well.. more the point.. aren't necessary with this if block at all).

Perhaps re-express this as fault_state = pending > 0U && pending < 8U;?

Given `pending` is unsigned, perhaps `(pending > 0U && pending < 8U)`? - also please let `clang-format` run here, the `{` should be on this line (or, well.. more the point.. aren't necessary with this `if` block at all). Perhaps re-express this as `fault_state = pending > 0U && pending < 8U;`?

Please drop the else block braces, they're not necessary and not part of the code base code style.

Please drop the else block braces, they're not necessary and not part of the code base code style.

Rather than using !! which is inobvious, please use != 0U on the end of the expression for the bool conversion - it won't change codegen, but it does improve code clarity by better expression your intent, which isn't to double negate the value, but rather to check the value is not 0.

Rather than using `!!` which is inobvious, please use `!= 0U` on the end of the expression for the bool conversion - it won't change codegen, but it does improve code clarity by better expression your intent, which isn't to double negate the value, but rather to check the value is not 0.
@ -69,6 +69,9 @@ extern unsigned cortexm_wait_timeout;
#define CORTEXM_DWT_MASK(i) (CORTEXM_DWT_BASE + 0x024U + (0x10U * (i)))

ARMv8

`ARMv8`
@ -188,6 +191,10 @@ extern unsigned cortexm_wait_timeout;
#define CORTEXM_XPSR_THUMB (1U << 24U)

Please suffix the numbers here with U so the bit shifting and masking is done unsigned.

Please suffix the numbers here with `U` so the bit shifting and masking is done unsigned.

ARMv8-M

`ARMv8-M`
mean00 commented 2026年02月04日 07:20:28 +01:00 (Migrated from github.com)
Copy link

I'll update the MR this weekend
Thank you

I'll update the MR this weekend Thank you
mean00 (Migrated from github.com) reviewed 2026年02月07日 16:02:25 +01:00
@ -188,6 +191,10 @@ extern unsigned cortexm_wait_timeout;
#define CORTEXM_XPSR_THUMB (1U << 24U)
mean00 (Migrated from github.com) commented 2026年02月07日 16:02:25 +01:00
Copy link

done

done
mean00 (Migrated from github.com) reviewed 2026年02月07日 16:02:32 +01:00
@ -69,6 +69,9 @@ extern unsigned cortexm_wait_timeout;
#define CORTEXM_DWT_MASK(i) (CORTEXM_DWT_BASE + 0x024U + (0x10U * (i)))
mean00 (Migrated from github.com) commented 2026年02月07日 16:02:31 +01:00
Copy link

done

done
mean00 (Migrated from github.com) reviewed 2026年02月07日 16:02:39 +01:00
@ -188,6 +191,10 @@ extern unsigned cortexm_wait_timeout;
#define CORTEXM_XPSR_THUMB (1U << 24U)
mean00 (Migrated from github.com) commented 2026年02月07日 16:02:38 +01:00
Copy link

done

done
mean00 (Migrated from github.com) reviewed 2026年02月07日 16:02:45 +01:00
@ -864,7 +864,21 @@ static target_halt_reason_e cortexm_halt_poll(target_s *target, target_addr64_t
priv->dcache_enabled = ccr & CORTEXM_CCR_DCACHE_ENABLE;
mean00 (Migrated from github.com) commented 2026年02月07日 16:02:45 +01:00
Copy link

done

done
mean00 (Migrated from github.com) reviewed 2026年02月07日 16:02:56 +01:00
@ -864,7 +864,21 @@ static target_halt_reason_e cortexm_halt_poll(target_s *target, target_addr64_t
priv->dcache_enabled = ccr & CORTEXM_CCR_DCACHE_ENABLE;
mean00 (Migrated from github.com) commented 2026年02月07日 16:02:56 +01:00
Copy link

done

done
mean00 (Migrated from github.com) reviewed 2026年02月07日 16:03:05 +01:00
@ -864,7 +864,21 @@ static target_halt_reason_e cortexm_halt_poll(target_s *target, target_addr64_t
priv->dcache_enabled = ccr & CORTEXM_CCR_DCACHE_ENABLE;
mean00 (Migrated from github.com) commented 2026年02月07日 16:03:05 +01:00
Copy link

done

done
mean00 commented 2026年02月07日 16:04:36 +01:00 (Migrated from github.com)
Copy link

I think i got all the remarks as a separate commit for easy review
If that's ok, i'll squash them, it takes 10 sec to do so
Thank you

I think i got all the remarks as a separate commit for easy review If that's ok, i'll squash them, it takes 10 sec to do so Thank you
dragonmux left a comment
Copy link

This is looking better - there is one small note we have and once that's been addressed, we'll approve and merge this.

This is looking better - there is one small note we have and once that's been addressed, we'll approve and merge this.
@ -864,7 +864,21 @@ static target_halt_reason_e cortexm_halt_poll(target_s *target, target_addr64_t
priv->dcache_enabled = ccr & CORTEXM_CCR_DCACHE_ENABLE;

These are still missing their U suffixes to make the comparisons unsigned.

We think fault_state = pending > 0U && pending < 8U; with the comment on the line before would be more concise and should also be a clang-tidy lint.

These are still missing their `U` suffixes to make the comparisons unsigned. We think `fault_state = pending > 0U && pending < 8U;` with the comment on the line before would be more concise and should also be a `clang-tidy` lint.
mean00 commented 2026年02月10日 19:53:56 +01:00 (Migrated from github.com)
Copy link

This time i think it's correct. I've squashed it as the last change was really small & easy to check.
(slightly altered the commit comment to be in line with the naming for ARMv8-M)
Thank you.

This time i think it's correct. I've squashed it as the last change was really small & easy to check. (slightly altered the commit comment to be in line with the naming for ARMv8-M) Thank you.

It would technically be cortexm: for the commit message suffix as it's not based on the concept touched, but which file is touched.. however, we're going to approve and merge this as it stands as it looks good.

It would technically be `cortexm: ` for the commit message suffix as it's not based on the concept touched, but which file is touched.. however, we're going to approve and merge this as it stands as it looks good.
dragonmux left a comment
Copy link

LGTM. Thank you for the contribution!

We'll do some cleanup after in a follow-up PR we have to do anyway (comment style, if with assign to true into straight truthy assignment) but this looks all functional which is the important part.

LGTM. Thank you for the contribution! We'll do some cleanup after in a follow-up PR we have to do anyway (comment style, `if` with assign to `true` into straight truthy assignment) but this looks all functional which is the important part.
Sign in to join this conversation.
No reviewers
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic!2187
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "better_handle_armv8_faults_v2"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?