[FEATURE] Please Support Software Breakpoints
- Dominant language
- C
- Stars
- 4k
- Forks
- 1.7k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 237
Description
### Is your feature request related to a problem? Please describe.
Some firmware runs in RAM, such as external SDRAM, where breakpoint instructions can be used to implement an unlimited number of breakpoints.
### Describe the solution you'd like
pseudocode:
```
typedef uint16_t platform_bkpt_t;//armv7m bkpt is 16 bits
#define PLATFORM_BKPT_INSTRUCTION 0xF000
struct debug_point
{
int type;
platform_bkpt_t old_instruction;
uintptr_t address;
void *arg;
debug_callback_t callback;
bool is_active;
bool is_software;
}
list debug_points;
int up_debugpoint_add(int type, void *addr, size_t size,
debug_callback_t callback, void *arg,bool is_software)
{
struct debug_point dp;
dp.address = (uintptr_t)addr;
dp.callback = callback;
dp.arg = arg;
dp.is_active = true;
dp.is_software = is_software;
dp.type = type;
bool is_valid = false;
...
if(is_software)
{
is_valid=true;
if(type is step point)
memcpy(&dp.old_instruction, (void *)addr, sizeof(platform_bkpt_t));
platform_bkpt_t bkpt=PLATFORM_BKPT_INSTRUCTION ;
memcpy(&addr, (void *)&bkpt, sizeof(platform_bkpt_t));
}
else
{
// Add hardware breakpoint
// ...
var hardware_breakpoint_count=debug_points.select(x=>x.is_software==false).Count();//get count of hardware breakpoints
if(hardware_breakpoint_count>=MAX_HARDWARE_BREAKPOINTS)
{
// Error: too many hardware breakpoints
is_valid=false;
}
}
if(is_valid)
{
debug_points.push_back(dp);
}
return 0;
}
int arm_dbgmonitor(int irq, void *context, void *arg)
{
var pc=regs[REG_PC];
var breakpoint=debug_points.find(x=>x.address==pc);
if(breakpoint!=null)
{
if(breakpoint.is_software)
{
// Handle software breakpoint, restore old instruction
if(type is step point)
memcpy((void *)pc, &breakpoint.old_instruction, sizeof(platform_bkpt_t));
}
else
{
// Handle hardware breakpoint
// ...
}
arm_steppoint_match();...
arm_breakpoint_match()..
arm_watchpoint_match()...
}
}
```
### Describe alternatives you've considered
_No response_
### Verification
- [x] I have verified before submitting the report.
Contributor guide
Research direction
Start by locating the existing debug-point entry point up_debugpoint_add and the handlers arm_dbgmonitor, arm_steppoint_match, arm_breakpoint_match, and arm_watchpoint_match. Read how hardware breakpoints are currently represented and handled; done means software breakpoints can be added, tracked, restored, and handled alongside hardware breakpoints without exceeding hardware limits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- devtools, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100