gdb_server -- symbol cleanup
[openocd.git] / src / server / gdb_server.c
index 21cd0fed9f050cfa798665fa7518bd2dcfa556a5..b2527d21d818e2f12324b0ca576c1a5a11423b41 100644 (file)
@@ -2,7 +2,7 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
- *   Copyright (C) 2007,2008 Øyvind Harboe                                 *
+ *   Copyright (C) 2007-2009 Øyvind Harboe                                 *
  *   oyvind.harboe@zylin.com                                               *
  *                                                                         *
  *   Copyright (C) 2008 by Spencer Oliver                                  *
 #include <target/target_request.h>
 #include <target/register.h>
 #include "server.h"
-#include <flash/flash.h>
+#include <flash/nor/core.h>
 #include "gdb_server.h"
 #include <target/image.h>
 #include <jtag/jtag.h>
 
 
+/**
+ * @file
+ * GDB server implementation.
+ *
+ * This implements the GDB Remote Serial Protocol, over TCP connections,
+ * giving GDB access to the JTAG or other hardware debugging facilities
+ * found in most modern embedded processors.
+ */
+
+/* private connection data for GDB */
+struct gdb_connection
+{
+       char buffer[GDB_BUFFER_SIZE];
+       char *buf_p;
+       int buf_cnt;
+       int ctrl_c;
+       enum target_state frontend_state;
+       struct image *vflash_image;
+       int closed;
+       int busy;
+       int noack_mode;
+       bool sync;      /* set flag to true if you want the next stepi to return immediately.
+                      allowing GDB to pick up a fresh set of register values from the target
+                      without modifying the target state. */
+
+};
+
+
 #if 0
 #define _DEBUG_GDB_IO_
 #endif
@@ -46,10 +74,10 @@ static struct gdb_connection *current_gdb_connection;
 static int gdb_breakpoint_override;
 static enum breakpoint_type gdb_breakpoint_override_type;
 
-extern int gdb_error(struct connection *connection, int retval);
+static int gdb_error(struct connection *connection, int retval);
 static unsigned short gdb_port = 3333;
 static unsigned short gdb_port_next = 0;
-static const char *DIGITS = "0123456789abcdef";
+static const char DIGITS[16] = "0123456789abcdef";
 
 static void gdb_log_callback(void *priv, const char *file, unsigned line,
                const char *function, const char *string);
@@ -61,15 +89,17 @@ int gdb_actual_connections;
 /* set if we are sending a memory map to gdb
  * via qXfer:memory-map:read packet */
 /* enabled by default*/
-int gdb_use_memory_map = 1;
+static int gdb_use_memory_map = 1;
 /* enabled by default*/
-int gdb_flash_program = 1;
+static int gdb_flash_program = 1;
 
 /* if set, data aborts cause an error to be reported in memory read packets
- * see the code in gdb_read_memory_packet() for further explanations */
-int gdb_report_data_abort = 0;
+ * see the code in gdb_read_memory_packet() for further explanations.
+ * Disabled by default.
+ */
+static int gdb_report_data_abort;
 
-int gdb_last_signal(struct target *target)
+static int gdb_last_signal(struct target *target)
 {
        switch (target->debug_reason)
        {
@@ -89,7 +119,8 @@ int gdb_last_signal(struct target *target)
        }
 }
 
-int check_pending(struct connection *connection, int timeout_s, int *got_data)
+static int check_pending(struct connection *connection,
+               int timeout_s, int *got_data)
 {
        /* a non-blocking socket will block if there is 0 bytes available on the socket,
         * but return with as many bytes as are available immediately
@@ -130,30 +161,11 @@ int check_pending(struct connection *connection, int timeout_s, int *got_data)
        return ERROR_OK;
 }
 
-int gdb_get_char(struct connection *connection, int* next_char)
+static int gdb_get_char_inner(struct connection *connection, int* next_char)
 {
        struct gdb_connection *gdb_con = connection->priv;
        int retval = ERROR_OK;
 
-#ifdef _DEBUG_GDB_IO_
-       char *debug_buffer;
-#endif
-
-       if (gdb_con->buf_cnt-- > 0)
-       {
-               *next_char = *(gdb_con->buf_p++);
-               if (gdb_con->buf_cnt > 0)
-                       connection->input_pending = 1;
-               else
-                       connection->input_pending = 0;
-
-#ifdef _DEBUG_GDB_IO_
-               LOG_DEBUG("returned char '%c' (0x%2.2x)", *next_char, *next_char);
-#endif
-
-               return ERROR_OK;
-       }
-
        for (;;)
        {
                if (connection->service->type == CONNECTION_PIPE)
@@ -238,7 +250,51 @@ int gdb_get_char(struct connection *connection, int* next_char)
        return retval;
 }
 
-int gdb_putback_char(struct connection *connection, int last_char)
+/**
+ * The cool thing about this fn is that it allows buf_p and buf_cnt to be
+ * held in registers in the inner loop.
+ *
+ * For small caches and embedded systems this is important!
+ */
+static inline int gdb_get_char_fast(struct connection *connection, int* next_char, char **buf_p, int *buf_cnt)
+{
+       int retval = ERROR_OK;
+
+       if ((*buf_cnt)-- > 0)
+       {
+               *next_char = **buf_p;
+               (*buf_p)++;
+               if (*buf_cnt > 0)
+                       connection->input_pending = 1;
+               else
+                       connection->input_pending = 0;
+
+#ifdef _DEBUG_GDB_IO_
+               LOG_DEBUG("returned char '%c' (0x%2.2x)", *next_char, *next_char);
+#endif
+
+               return ERROR_OK;
+       }
+
+       struct gdb_connection *gdb_con = connection->priv;
+       gdb_con->buf_p = *buf_p;
+       gdb_con->buf_cnt = *buf_cnt;
+       retval = gdb_get_char_inner(connection, next_char);
+       *buf_p = gdb_con->buf_p;
+       *buf_cnt = gdb_con->buf_cnt;
+
+       return retval;
+}
+
+
+static int gdb_get_char(struct connection *connection, int* next_char)
+{
+       struct gdb_connection *gdb_con = connection->priv;
+       return gdb_get_char_fast(connection, next_char, &gdb_con->buf_p, &gdb_con->buf_cnt);
+}
+
+
+static int gdb_putback_char(struct connection *connection, int last_char)
 {
        struct gdb_connection *gdb_con = connection->priv;
 
@@ -258,7 +314,7 @@ int gdb_putback_char(struct connection *connection, int last_char)
 /* The only way we can detect that the socket is closed is the first time
  * we write to it, we will fail. Subsequent write operations will
  * succeed. Shudder! */
-int gdb_write(struct connection *connection, void *data, int len)
+static int gdb_write(struct connection *connection, void *data, int len)
 {
        struct gdb_connection *gdb_con = connection->priv;
        if (gdb_con->closed)
@@ -283,7 +339,8 @@ int gdb_write(struct connection *connection, void *data, int len)
        return ERROR_SERVER_REMOTE_CLOSED;
 }
 
-int gdb_put_packet_inner(struct connection *connection, char *buffer, int len)
+static int gdb_put_packet_inner(struct connection *connection,
+               char *buffer, int len)
 {
        int i;
        unsigned char my_checksum = 0;
@@ -306,7 +363,8 @@ int gdb_put_packet_inner(struct connection *connection, char *buffer, int len)
        int gotdata;
        for (;;)
        {
-               if ((retval = check_pending(connection, 0, &gotdata)) != ERROR_OK)
+               retval = check_pending(connection, 0, &gotdata);
+               if (retval != ERROR_OK)
                        return retval;
                if (!gotdata)
                        break;
@@ -424,7 +482,7 @@ int gdb_put_packet_inner(struct connection *connection, char *buffer, int len)
        return ERROR_OK;
 }
 
-int gdb_put_packet(struct connection *connection, char *buffer, int len)
+static int gdb_put_packet(struct connection *connection, char *buffer, int len)
 {
        struct gdb_connection *gdb_con = connection->priv;
        gdb_con->busy = 1;
@@ -442,27 +500,33 @@ static __inline__ int fetch_packet(struct connection *connection, int *checksum_
        unsigned char my_checksum = 0;
        char checksum[3];
        int character;
-       int retval;
+       int retval = ERROR_OK;
 
        struct gdb_connection *gdb_con = connection->priv;
        my_checksum = 0;
        int count = 0;
        count = 0;
+
+       /* move this over into local variables to use registers and give the
+        * more freedom to optimize */
+       char *buf_p = gdb_con->buf_p;
+       int buf_cnt = gdb_con->buf_cnt;
+
        for (;;)
        {
                /* The common case is that we have an entire packet with no escape chars.
                 * We need to leave at least 2 bytes in the buffer to have
                 * gdb_get_char() update various bits and bobs correctly.
                 */
-               if ((gdb_con->buf_cnt > 2) && ((gdb_con->buf_cnt + count) < *len))
+               if ((buf_cnt > 2) && ((buf_cnt + count) < *len))
                {
                        /* The compiler will struggle a bit with constant propagation and
                         * aliasing, so we help it by showing that these values do not
                         * change inside the loop
                         */
                        int i;
-                       char *buf = gdb_con->buf_p;
-                       int run = gdb_con->buf_cnt - 2;
+                       char *buf = buf_p;
+                       int run = buf_cnt - 2;
                        i = 0;
                        int done = 0;
                        while (i < run)
@@ -494,19 +558,21 @@ static __inline__ int fetch_packet(struct connection *connection, int *checksum_
                                        buffer[count++] = character & 0xff;
                                }
                        }
-                       gdb_con->buf_p += i;
-                       gdb_con->buf_cnt -= i;
+                       buf_p += i;
+                       buf_cnt -= i;
                        if (done)
                                break;
                }
                if (count > *len)
                {
                        LOG_ERROR("packet buffer too small");
-                       return ERROR_GDB_BUFFER_TOO_SMALL;
+                       retval = ERROR_GDB_BUFFER_TOO_SMALL;
+                       break;
                }
 
-               if ((retval = gdb_get_char(connection, &character)) != ERROR_OK)
-                       return retval;
+               retval = gdb_get_char_fast(connection, &character, &buf_p, &buf_cnt);
+               if (retval != ERROR_OK)
+                       break;
 
                if (character == '#')
                        break;
@@ -516,8 +582,11 @@ static __inline__ int fetch_packet(struct connection *connection, int *checksum_
                        /* data transmitted in binary mode (X packet)
                         * uses 0x7d as escape character */
                        my_checksum += character & 0xff;
-                       if ((retval = gdb_get_char(connection, &character)) != ERROR_OK)
-                               return retval;
+
+                       retval = gdb_get_char_fast(connection, &character, &buf_p, &buf_cnt);
+                       if (retval != ERROR_OK)
+                               break;
+
                        my_checksum += character & 0xff;
                        buffer[count++] = (character ^ 0x20) & 0xff;
                }
@@ -528,6 +597,12 @@ static __inline__ int fetch_packet(struct connection *connection, int *checksum_
                }
        }
 
+       gdb_con->buf_p = buf_p;
+       gdb_con->buf_cnt = buf_cnt;
+
+       if (retval != ERROR_OK)
+               return retval;
+
        *len = count;
 
        if ((retval = gdb_get_char(connection, &character)) != ERROR_OK)
@@ -546,7 +621,8 @@ static __inline__ int fetch_packet(struct connection *connection, int *checksum_
        return ERROR_OK;
 }
 
-int gdb_get_packet_inner(struct connection *connection, char *buffer, int *len)
+static int gdb_get_packet_inner(struct connection *connection,
+               char *buffer, int *len)
 {
        int character;
        int retval;
@@ -621,7 +697,7 @@ int gdb_get_packet_inner(struct connection *connection, char *buffer, int *len)
        return ERROR_OK;
 }
 
-int gdb_get_packet(struct connection *connection, char *buffer, int *len)
+static int gdb_get_packet(struct connection *connection, char *buffer, int *len)
 {
        struct gdb_connection *gdb_con = connection->priv;
        gdb_con->busy = 1;
@@ -630,7 +706,7 @@ int gdb_get_packet(struct connection *connection, char *buffer, int *len)
        return retval;
 }
 
-int gdb_output_con(struct connection *connection, const char* line)
+static int gdb_output_con(struct connection *connection, const char* line)
 {
        char *hex_buffer;
        int i, bin_size;
@@ -652,7 +728,7 @@ int gdb_output_con(struct connection *connection, const char* line)
        return retval;
 }
 
-int gdb_output(struct command_context *context, const char* line)
+static int gdb_output(struct command_context *context, const char* line)
 {
        /* this will be dumped to the log and also sent as an O packet if possible */
        LOG_USER_N("%s", line);
@@ -697,7 +773,8 @@ static void gdb_frontend_halted(struct target *target, struct connection *connec
        }
 }
 
-int gdb_target_callback_event_handler(struct target *target, enum target_event event, void *priv)
+static int gdb_target_callback_event_handler(struct target *target,
+               enum target_event event, void *priv)
 {
        int retval;
        struct connection *connection = priv;
@@ -725,7 +802,7 @@ int gdb_target_callback_event_handler(struct target *target, enum target_event e
        return ERROR_OK;
 }
 
-int gdb_new_connection(struct connection *connection)
+static int gdb_new_connection(struct connection *connection)
 {
        struct gdb_connection *gdb_connection = malloc(sizeof(struct gdb_connection));
        struct gdb_service *gdb_service = connection->service->priv;
@@ -781,7 +858,7 @@ int gdb_new_connection(struct connection *connection)
        return ERROR_OK;
 }
 
-int gdb_connection_closed(struct connection *connection)
+static int gdb_connection_closed(struct connection *connection)
 {
        struct gdb_service *gdb_service = connection->service->priv;
        struct gdb_connection *gdb_connection = connection->priv;
@@ -828,14 +905,15 @@ int gdb_connection_closed(struct connection *connection)
        return ERROR_OK;
 }
 
-void gdb_send_error(struct connection *connection, uint8_t the_error)
+static void gdb_send_error(struct connection *connection, uint8_t the_error)
 {
        char err[4];
        snprintf(err, 4, "E%2.2X", the_error);
        gdb_put_packet(connection, err, 3);
 }
 
-int gdb_last_signal_packet(struct connection *connection, struct target *target, char* packet, int packet_size)
+static int gdb_last_signal_packet(struct connection *connection,
+               struct target *target, char* packet, int packet_size)
 {
        char sig_reply[4];
        int signal;
@@ -865,7 +943,8 @@ static int gdb_reg_pos(struct target *target, int pos, int len)
  * The format of reg->value is little endian
  *
  */
-void gdb_str_to_target(struct target *target, char *tstr, struct reg *reg)
+static void gdb_str_to_target(struct target *target,
+               char *tstr, struct reg *reg)
 {
        int i;
 
@@ -882,7 +961,7 @@ void gdb_str_to_target(struct target *target, char *tstr, struct reg *reg)
        }
 }
 
-static int hextoint(char c)
+static int hextoint(int c)
 {
        if (c>='0'&&c<='9')
        {
@@ -898,7 +977,8 @@ static int hextoint(char c)
 }
 
 /* copy over in register buffer */
-void gdb_target_to_reg(struct target *target, char *tstr, int str_len, uint8_t *bin)
+static void gdb_target_to_reg(struct target *target,
+               char *tstr, int str_len, uint8_t *bin)
 {
        if (str_len % 2)
        {
@@ -917,7 +997,8 @@ void gdb_target_to_reg(struct target *target, char *tstr, int str_len, uint8_t *
        }
 }
 
-int gdb_get_registers_packet(struct connection *connection, struct target *target, char* packet, int packet_size)
+static int gdb_get_registers_packet(struct connection *connection,
+               struct target *target, char* packet, int packet_size)
 {
        struct reg **reg_list;
        int reg_list_size;
@@ -967,7 +1048,8 @@ int gdb_get_registers_packet(struct connection *connection, struct target *targe
        return ERROR_OK;
 }
 
-int gdb_set_registers_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_set_registers_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        int i;
        struct reg **reg_list;
@@ -1025,7 +1107,8 @@ int gdb_set_registers_packet(struct connection *connection, struct target *targe
        return ERROR_OK;
 }
 
-int gdb_get_register_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_get_register_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        char *reg_packet;
        int reg_num = strtoul(packet + 1, NULL, 16);
@@ -1060,7 +1143,8 @@ int gdb_get_register_packet(struct connection *connection, struct target *target
        return ERROR_OK;
 }
 
-int gdb_set_register_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_set_register_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        char *separator;
        uint8_t *bin_buf;
@@ -1106,7 +1190,7 @@ int gdb_set_register_packet(struct connection *connection, struct target *target
        return ERROR_OK;
 }
 
-int gdb_error(struct connection *connection, int retval)
+static int gdb_error(struct connection *connection, int retval)
 {
        switch (retval)
        {
@@ -1137,7 +1221,8 @@ int gdb_error(struct connection *connection, int retval)
  *
  * 8191 bytes by the looks of it. Why 8191 bytes instead of 8192?????
  */
-int gdb_read_memory_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_read_memory_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        char *separator;
        uint32_t addr = 0;
@@ -1211,7 +1296,8 @@ int gdb_read_memory_packet(struct connection *connection, struct target *target,
        return retval;
 }
 
-int gdb_write_memory_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_write_memory_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        char *separator;
        uint32_t addr = 0;
@@ -1268,7 +1354,8 @@ int gdb_write_memory_packet(struct connection *connection, struct target *target
        return retval;
 }
 
-int gdb_write_memory_binary_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_write_memory_binary_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        char *separator;
        uint32_t addr = 0;
@@ -1316,7 +1403,8 @@ int gdb_write_memory_binary_packet(struct connection *connection, struct target
        return ERROR_OK;
 }
 
-int gdb_step_continue_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_step_continue_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        int current = 0;
        uint32_t address = 0x0;
@@ -1349,11 +1437,12 @@ int gdb_step_continue_packet(struct connection *connection, struct target *targe
        return retval;
 }
 
-int gdb_breakpoint_watchpoint_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_breakpoint_watchpoint_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        int type;
        enum breakpoint_type bp_type = BKPT_SOFT /* dummy init to avoid warning */;
-       enum watchpoint_rw wp_type;
+       enum watchpoint_rw wp_type = WPT_READ /* dummy init to avoid warning */;
        uint32_t address;
        uint32_t size;
        char *separator;
@@ -1373,6 +1462,12 @@ int gdb_breakpoint_watchpoint_packet(struct connection *connection, struct targe
                wp_type = WPT_READ;
        else if (type == 4) /* access watchpoint */
                wp_type = WPT_ACCESS;
+       else
+       {
+               LOG_ERROR("invalid gdb watch/breakpoint type(%d), dropping connection", type);
+               return ERROR_SERVER_REMOTE_CLOSED;
+       }
+
 
        if (gdb_breakpoint_override && ((bp_type == BKPT_SOFT)||(bp_type == BKPT_HARD)))
        {
@@ -1423,7 +1518,7 @@ int gdb_breakpoint_watchpoint_packet(struct connection *connection, struct targe
                {
                        if (packet[0] == 'Z')
                        {
-                               if ((retval = watchpoint_add(target, address, size, type-2, 0, 0xffffffffu)) != ERROR_OK)
+                               if ((retval = watchpoint_add(target, address, size, wp_type, 0, 0xffffffffu)) != ERROR_OK)
                                {
                                        if ((retval = gdb_error(connection, retval)) != ERROR_OK)
                                                return retval;
@@ -1447,8 +1542,11 @@ int gdb_breakpoint_watchpoint_packet(struct connection *connection, struct targe
        return ERROR_OK;
 }
 
-/* print out a string and allocate more space as needed, mainly used for XML at this point */
-void xml_printf(int *retval, char **xml, int *pos, int *size, const char *fmt, ...)
+/* print out a string and allocate more space as needed,
+ * mainly used for XML at this point
+ */
+static void xml_printf(int *retval, char **xml, int *pos, int *size,
+               const char *fmt, ...)
 {
        if (*retval != ERROR_OK)
        {
@@ -1515,7 +1613,7 @@ static int decode_xfer_read(char *buf, char **annex, int *ofs, unsigned int *len
        return 0;
 }
 
-int gdb_calc_blocksize(struct flash_bank *bank)
+static int gdb_calc_blocksize(struct flash_bank *bank)
 {
        uint32_t i;
        uint32_t block_size = 0xffffffff;
@@ -1549,7 +1647,8 @@ static int compare_bank (const void * a, const void * b)
        }
 }
 
-int gdb_query_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_query_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        struct command_context *cmd_ctx = connection->cmd_ctx;
        struct gdb_connection *gdb_connection = connection->priv;
@@ -1805,7 +1904,8 @@ int gdb_query_packet(struct connection *connection, struct target *target, char
        return ERROR_OK;
 }
 
-int gdb_v_packet(struct connection *connection, struct target *target, char *packet, int packet_size)
+static int gdb_v_packet(struct connection *connection,
+               struct target *target, char *packet, int packet_size)
 {
        struct gdb_connection *gdb_connection = connection->priv;
        struct gdb_service *gdb_service = connection->service->priv;
@@ -1852,9 +1952,19 @@ int gdb_v_packet(struct connection *connection, struct target *target, char *pac
                flash_set_dirty();
 
                /* perform any target specific operations before the erase */
-               target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_FLASH_ERASE_START);
-               result = flash_erase_address_range(gdb_service->target, addr, length);
-               target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_FLASH_ERASE_END);
+               target_call_event_callbacks(gdb_service->target,
+                               TARGET_EVENT_GDB_FLASH_ERASE_START);
+
+               /* vFlashErase:addr,length messages require region start and
+                * end to be "block" aligned ... if padding is ever needed,
+                * GDB will have become dangerously confused.
+                */
+               result = flash_erase_address_range(gdb_service->target,
+                               false, addr, length);
+
+               /* perform any target specific operations after the erase */
+               target_call_event_callbacks(gdb_service->target,
+                               TARGET_EVENT_GDB_FLASH_ERASE_END);
 
                /* perform erase */
                if (result != ERROR_OK)
@@ -1942,11 +2052,12 @@ int gdb_v_packet(struct connection *connection, struct target *target, char *pac
        return ERROR_OK;
 }
 
-int gdb_detach(struct connection *connection, struct target *target)
+static int gdb_detach(struct connection *connection, struct target *target)
 {
        struct gdb_service *gdb_service = connection->service->priv;
 
-       target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_DETACH);
+       target_call_event_callbacks(gdb_service->target,
+                       TARGET_EVENT_GDB_DETACH);
 
        return gdb_put_packet(connection, "OK", 2);
 }
@@ -1966,9 +2077,6 @@ static void gdb_log_callback(void *priv, const char *file, unsigned line,
        gdb_output_con(connection, string);
 }
 
-/* Do not allocate this on the stack */
-char gdb_packet_buffer[GDB_BUFFER_SIZE];
-
 static void gdb_sig_halted(struct connection *connection)
 {
        char sig_reply[4];
@@ -1977,8 +2085,11 @@ static void gdb_sig_halted(struct connection *connection)
 
 }
 
-int gdb_input_inner(struct connection *connection)
+static int gdb_input_inner(struct connection *connection)
 {
+       /* Do not allocate this on the stack */
+       static char gdb_packet_buffer[GDB_BUFFER_SIZE];
+
        struct gdb_service *gdb_service = connection->service->priv;
        struct target *target = gdb_service->target;
        char *packet = gdb_packet_buffer;
@@ -1991,10 +2102,9 @@ int gdb_input_inner(struct connection *connection)
        do
        {
                packet_size = GDB_BUFFER_SIZE-1;
-               if ((retval = gdb_get_packet(connection, packet, &packet_size)) != ERROR_OK)
-               {
+               retval = gdb_get_packet(connection, packet, &packet_size);
+               if (retval != ERROR_OK)
                        return retval;
-               }
 
                /* terminate with zero */
                packet[packet_size] = 0;
@@ -2026,32 +2136,48 @@ int gdb_input_inner(struct connection *connection)
                                        break;
                                case 'q':
                                case 'Q':
-                                       retval = gdb_query_packet(connection, target, packet, packet_size);
+                                       retval = gdb_query_packet(connection,
+                                                       target, packet,
+                                                       packet_size);
                                        break;
                                case 'g':
-                                       retval = gdb_get_registers_packet(connection, target, packet, packet_size);
+                                       retval = gdb_get_registers_packet(
+                                                       connection, target,
+                                                       packet, packet_size);
                                        break;
                                case 'G':
-                                       retval = gdb_set_registers_packet(connection, target, packet, packet_size);
+                                       retval = gdb_set_registers_packet(
+                                                       connection, target,
+                                                       packet, packet_size);
                                        break;
                                case 'p':
-                                       retval = gdb_get_register_packet(connection, target, packet, packet_size);
+                                       retval = gdb_get_register_packet(
+                                                       connection, target,
+                                                       packet, packet_size);
                                        break;
                                case 'P':
-                                       retval = gdb_set_register_packet(connection, target, packet, packet_size);
+                                       retval = gdb_set_register_packet(
+                                                       connection, target,
+                                                       packet, packet_size);
                                        break;
                                case 'm':
-                                       retval = gdb_read_memory_packet(connection, target, packet, packet_size);
+                                       retval = gdb_read_memory_packet(
+                                                       connection, target,
+                                                       packet, packet_size);
                                        break;
                                case 'M':
-                                       retval = gdb_write_memory_packet(connection, target, packet, packet_size);
+                                       retval = gdb_write_memory_packet(
+                                                       connection, target,
+                                                       packet, packet_size);
                                        break;
                                case 'z':
                                case 'Z':
                                        retval = gdb_breakpoint_watchpoint_packet(connection, target, packet, packet_size);
                                        break;
                                case '?':
-                                       gdb_last_signal_packet(connection, target, packet, packet_size);
+                                       gdb_last_signal_packet(
+                                                       connection, target,
+                                                       packet, packet_size);
                                        break;
                                case 'c':
                                case 's':
@@ -2113,14 +2239,19 @@ int gdb_input_inner(struct connection *connection)
                                        }
                                        break;
                                case 'v':
-                                       retval = gdb_v_packet(connection, target, packet, packet_size);
+                                       retval = gdb_v_packet(
+                                                       connection, target,
+                                                       packet, packet_size);
                                        break;
                                case 'D':
                                        retval = gdb_detach(connection, target);
                                        extended_protocol = 0;
                                        break;
                                case 'X':
-                                       if ((retval = gdb_write_memory_binary_packet(connection, target, packet, packet_size)) != ERROR_OK)
+                                       retval = gdb_write_memory_binary_packet(
+                                                       connection, target,
+                                                       packet, packet_size);
+                                       if (retval != ERROR_OK)
                                                return retval;
                                        break;
                                case 'k':
@@ -2175,7 +2306,7 @@ int gdb_input_inner(struct connection *connection)
        return ERROR_OK;
 }
 
-int gdb_input(struct connection *connection)
+static int gdb_input(struct connection *connection)
 {
        int retval = gdb_input_inner(connection);
        struct gdb_connection *gdb_con = connection->priv;
@@ -2211,7 +2342,7 @@ static int gdb_target_start(struct target *target, uint16_t port)
        return ERROR_OK;
 }
 
-int gdb_target_add_one(struct target *target)
+static int gdb_target_add_one(struct target *target)
 {
        if (gdb_port == 0 && server_use_pipes == 0)
        {
@@ -2350,7 +2481,7 @@ COMMAND_HANDLER(handle_gdb_breakpoint_override_command)
 static const struct command_registration gdb_command_handlers[] = {
        {
                .name = "gdb_sync",
-               .handler = &handle_gdb_sync_command,
+               .handler = handle_gdb_sync_command,
                .mode = COMMAND_ANY,
                .help = "next stepi will return immediately allowing "
                        "GDB to fetch register state without affecting "
@@ -2358,39 +2489,41 @@ static const struct command_registration gdb_command_handlers[] = {
        },
        {
                .name = "gdb_port",
-               .handler = &handle_gdb_port_command,
+               .handler = handle_gdb_port_command,
                .mode = COMMAND_ANY,
-               .help = "daemon configuration command gdb_port",
-               .usage = "<port>",
+               .help = "Display or specify base port on which to listen "
+                       "for incoming GDB connections.  "
+                       "No arguments reports GDB port; zero disables.",
+               .usage = "[port_num]",
        },
        {
                .name = "gdb_memory_map",
-               .handler = &handle_gdb_memory_map_command,
+               .handler = handle_gdb_memory_map_command,
                .mode = COMMAND_CONFIG,
                .help = "enable or disable memory map",
-               .usage = "enable|disable"
+               .usage = "('enable'|'disable')"
        },
        {
                .name = "gdb_flash_program",
-               .handler = &handle_gdb_flash_program_command,
+               .handler = handle_gdb_flash_program_command,
                .mode = COMMAND_CONFIG,
                .help = "enable or disable flash program",
-               .usage = "enable|disable"
+               .usage = "('enable'|'disable')"
        },
        {
                .name = "gdb_report_data_abort",
-               .handler = &handle_gdb_report_data_abort_command,
+               .handler = handle_gdb_report_data_abort_command,
                .mode = COMMAND_CONFIG,
                .help = "enable or disable reporting data aborts",
-               .usage = "enable|disable"
+               .usage = "('enable'|'disable')"
        },
        {
                .name = "gdb_breakpoint_override",
-               .handler = &handle_gdb_breakpoint_override_command,
-               .mode = COMMAND_EXEC,
-               .help = "force type of breakpoint "
-                       "used by gdb 'break' commands.",
-               .usage = "hard|soft|disable",
+               .handler = handle_gdb_breakpoint_override_command,
+               .mode = COMMAND_ANY,
+               .help = "Display or specify type of breakpoint "
+                       "to be used by gdb 'break' commands.",
+               .usage = "('hard'|'soft'|'disable')"
        },
        COMMAND_REGISTRATION_DONE
 };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)