Skip to content

Support hardware breakpoint and watchpoint - #22

Open
jserv wants to merge 1 commit into
RinHizakura:mainfrom
jserv:watchpoint
Open

Support hardware breakpoint and watchpoint#22
jserv wants to merge 1 commit into
RinHizakura:mainfrom
jserv:watchpoint

Conversation

@jserv

@jserv jserv commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

This adds GDB RSP support for hardware breakpoints (Z1) and watchpoints (Z2-Z4), enabling memory access debugging in the emulator.

Protocol changes:

  • Extend bp_type_t with BP_HARDWARE, WP_WRITE, WP_READ, WP_ACCESS
  • Handle Z1 (hw breakpoint), Z2 (write), Z3 (read), Z4 (access) packets
  • Add 'len' parameter to set_bp/del_bp for memory region size
  • Advertise hwbreak+ and swbreak+ capabilities in qSupported

This adds GDB RSP support for hardware breakpoints (Z1) and watchpoints
(Z2-Z4), enabling memory access debugging in the emulator.

Protocol changes:
- Extend bp_type_t with BP_HARDWARE, WP_WRITE, WP_READ, WP_ACCESS
- Handle Z1 (hw breakpoint), Z2 (write), Z3 (read), Z4 (access) packets
- Add 'len' parameter to set_bp/del_bp for memory region size
- Advertise hwbreak+ and swbreak+ capabilities in qSupported
@RinHizakura

RinHizakura commented Jan 30, 2026

Copy link
Copy Markdown
Owner

One serious problem is that the commit mixes so many irrelevant changes to the PR topic......

From a collaboration perspective, I don't encourage this approach. Is it possible to make only the changes corresponding to the commit and split it into several commits/PRs?

Comment thread src/gdbstub.c
break;
snprintf(packet_str, sizeof(packet_str), "E%02x", ret & 0xff);
conn_send_pktstr(&gdbstub->priv->conn, packet_str);
return;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we modify lines 204-205 to a single break?

Comment thread src/gdbstub.c
if (regno < 0 || regno >= gdbstub->arch.reg_num) {
SEND_EINVAL(gdbstub);
return;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this piece of code. Such logic should be handled in read_reg by the user themselves.

Comment thread src/gdbstub.c
if (regno < 0 || regno >= gdbstub->arch.reg_num) {
SEND_EINVAL(gdbstub);
return;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Comment thread src/gdbstub.c
if (payload_length > remaining)
payload_length = remaining;
if (payload_length > max_payload)
payload_length = max_payload;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

payload_length  = length > remaining ? remaining : length ;
payload_length  = payload_length > max_payload ? max_payload : payload_length;

Comment thread src/gdbstub.c
/* Enforce SMP limit to prevent buffer overflow */
if (smp >= MAX_SMP_COUNT) {
smp = MAX_SMP_COUNT - 1;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle error like this just gives us a new issue.
Let's check the smp in the initialization and fail early to hint to the user that this is not supported currently.

Comment thread include/gdbstub.h
int smp;
int reg_num;
const char *target_desc; /* XML target description (may be NULL) */
int smp; /* Number of CPUs (0 or 1 for single-core) */

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be a 0 or 1 value for sure.

Comment thread include/gdbstub.h
*
* For watchpoints (WP_WRITE, WP_READ, WP_ACCESS):
* - 'len' parameter is the memory region size in bytes to watch
* - Must be validated by implementation (typical max: 8 bytes)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we explain the len here? This is really confusing.

Comment thread include/gdbstub.h
/**
* Set a breakpoint or watchpoint.
* @param addr Target address
* @param len For BP_*: instruction size; for WP_*: memory region size

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the implementation, BP_* doesn't utilize the len, but here it says it is the instruction size.

Comment thread include/gdbstub.h
/**
* Delete a breakpoint or watchpoint.
* @param addr Target address (must match set_bp call)
* @param len Must match the len used in set_bp

@RinHizakura RinHizakura Feb 11, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I think the delete breakpoint doesn't need to "match" for GDBstub. The user can do anything they want, and gdbstub just needs to report the error if it really doesn't match.

@RinHizakura

Copy link
Copy Markdown
Owner

@jserv I appreciate having a more complete implementation for the mini-gdbstub, but I believe we have code/comments that were generated by AI, but some are incorrect or misleading. As a reviewer, I am really disappointed when I keep finding these AI-generated wrong things.

I am not sure if you have reviewed these codes carefully, but could you please separate the part of the breakpoint supported and the others first? At least don't mess everything in one commit, and I can approach reviewing these codes easily.

@RinHizakura
RinHizakura force-pushed the main branch 2 times, most recently from b40c643 to dac98cc Compare March 5, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants