This is an automated email from Gerrit.

"Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>" just uploaded a new patch 
set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8488

-- gerrit

commit 49b2a71e14c268d2857566531e1578a0a48f05cc
Author: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>
Date:   Thu Sep 12 15:16:45 2024 +0300

    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 <evgeniy.nayda...@syntacore.com>

diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 2db3123a04..854c4dc65d 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -1781,18 +1781,9 @@ static int gdb_breakpoint_watchpoint_packet(struct 
connection *connection,
                case 1:
                        if (packet[0] == 'Z') {
                                retval = breakpoint_add(target, address, size, 
bp_type);
-                               if (retval == ERROR_NOT_IMPLEMENTED) {
-                                       /* Send empty reply to report that 
breakpoints of this type are not supported */
-                                       gdb_put_packet(connection, "", 0);
-                               } else if (retval != ERROR_OK) {
-                                       retval = gdb_error(connection, retval);
-                                       if (retval != ERROR_OK)
-                                               return retval;
-                               } else
-                                       gdb_put_packet(connection, "OK", 2);
                        } else {
-                               breakpoint_remove(target, address);
-                               gdb_put_packet(connection, "OK", 2);
+                               assert(packet[0] == 'z');
+                               retval = breakpoint_remove(target, address);
                        }
                        break;
                case 2:
@@ -1801,26 +1792,26 @@ static int gdb_breakpoint_watchpoint_packet(struct 
connection *connection,
                {
                        if (packet[0] == 'Z') {
                                retval = watchpoint_add(target, address, size, 
wp_type, 0, WATCHPOINT_IGNORE_DATA_VALUE_MASK);
-                               if (retval == ERROR_NOT_IMPLEMENTED) {
-                                       /* Send empty reply to report that 
watchpoints of this type are not supported */
-                                       gdb_put_packet(connection, "", 0);
-                               } else if (retval != ERROR_OK) {
-                                       retval = gdb_error(connection, retval);
-                                       if (retval != ERROR_OK)
-                                               return retval;
-                               } else
-                                       gdb_put_packet(connection, "OK", 2);
                        } else {
-                               watchpoint_remove(target, address);
-                               gdb_put_packet(connection, "OK", 2);
+                               assert(packet[0] == 'z');
+                               retval = watchpoint_remove(target, address);
                        }
                        break;
                }
                default:
+               {
+                       retval = ERROR_NOT_IMPLEMENTED;
                        break;
+               }
        }
 
-       return ERROR_OK;
+       if (retval == ERROR_NOT_IMPLEMENTED) {
+               /* Send empty reply to report that watchpoints of this type are 
not supported */
+               return gdb_put_packet(connection, "", 0);
+       }
+       if (retval != ERROR_OK)
+               return gdb_error(connection, retval);
+       return gdb_put_packet(connection, "OK", 2);
 }
 
 /* print out a string and allocate more space as needed,

-- 

Reply via email to