Skip to content

Commit e6ade35

Browse files
en-scborneoa
authored andcommitted
server/gdb_server: improve error handling for Z/z packet
* Report errors for `z` packet. * Report not supported types as required by GDB Remote Protocol's documentation: > Implementation notes: A remote target shall return an empty string for an unrecognized breakpoint or watchpoint packet type. Link: https://sourceware.org/gdb/current/onlinedocs/gdb.html/Packets.html#insert-breakpoint-or-watchpoint-packet Change-Id: I9130400aca5dbc54fefb413ed74f27d75fe50640 Signed-off-by: Evgeniy Naydanov <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8488 Tested-by: jenkins Reviewed-by: Antonio Borneo <[email protected]>
1 parent 1ae6b07 commit e6ade35

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

src/server/gdb_server.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,18 +1781,9 @@ static int gdb_breakpoint_watchpoint_packet(struct connection *connection,
17811781
case 1:
17821782
if (packet[0] == 'Z') {
17831783
retval = breakpoint_add(target, address, size, bp_type);
1784-
if (retval == ERROR_NOT_IMPLEMENTED) {
1785-
/* Send empty reply to report that breakpoints of this type are not supported */
1786-
gdb_put_packet(connection, "", 0);
1787-
} else if (retval != ERROR_OK) {
1788-
retval = gdb_error(connection, retval);
1789-
if (retval != ERROR_OK)
1790-
return retval;
1791-
} else
1792-
gdb_put_packet(connection, "OK", 2);
17931784
} else {
1794-
breakpoint_remove(target, address);
1795-
gdb_put_packet(connection, "OK", 2);
1785+
assert(packet[0] == 'z');
1786+
retval = breakpoint_remove(target, address);
17961787
}
17971788
break;
17981789
case 2:
@@ -1801,26 +1792,26 @@ static int gdb_breakpoint_watchpoint_packet(struct connection *connection,
18011792
{
18021793
if (packet[0] == 'Z') {
18031794
retval = watchpoint_add(target, address, size, wp_type, 0, WATCHPOINT_IGNORE_DATA_VALUE_MASK);
1804-
if (retval == ERROR_NOT_IMPLEMENTED) {
1805-
/* Send empty reply to report that watchpoints of this type are not supported */
1806-
gdb_put_packet(connection, "", 0);
1807-
} else if (retval != ERROR_OK) {
1808-
retval = gdb_error(connection, retval);
1809-
if (retval != ERROR_OK)
1810-
return retval;
1811-
} else
1812-
gdb_put_packet(connection, "OK", 2);
18131795
} else {
1814-
watchpoint_remove(target, address);
1815-
gdb_put_packet(connection, "OK", 2);
1796+
assert(packet[0] == 'z');
1797+
retval = watchpoint_remove(target, address);
18161798
}
18171799
break;
18181800
}
18191801
default:
1802+
{
1803+
retval = ERROR_NOT_IMPLEMENTED;
18201804
break;
1805+
}
18211806
}
18221807

1823-
return ERROR_OK;
1808+
if (retval == ERROR_NOT_IMPLEMENTED) {
1809+
/* Send empty reply to report that watchpoints of this type are not supported */
1810+
return gdb_put_packet(connection, "", 0);
1811+
}
1812+
if (retval != ERROR_OK)
1813+
return gdb_error(connection, retval);
1814+
return gdb_put_packet(connection, "OK", 2);
18241815
}
18251816

18261817
/* print out a string and allocate more space as needed,

0 commit comments

Comments
 (0)