gdb_server: added and improved several debug prints
[openocd.git] / src / server / gdb_server.c
index bc3a675cf682f3be5e52a1b3f0a8d0b97aeca3b7..0d2d1ae2c307eb18ec3321e59c18b31b65d70e75 100644 (file)
@@ -227,6 +227,7 @@ static int gdb_get_char_inner(struct connection *connection, int *next_char)
                if (gdb_con->buf_cnt > 0)
                        break;
                if (gdb_con->buf_cnt == 0) {
+                       LOG_DEBUG("GDB connection closed by the remote client");
                        gdb_con->closed = true;
                        return ERROR_SERVER_REMOTE_CLOSED;
                }
@@ -348,11 +349,15 @@ static int gdb_putback_char(struct connection *connection, int last_char)
 static int gdb_write(struct connection *connection, void *data, int len)
 {
        struct gdb_connection *gdb_con = connection->priv;
-       if (gdb_con->closed)
+       if (gdb_con->closed) {
+               LOG_DEBUG("GDB socket marked as closed, cannot write to it.");
                return ERROR_SERVER_REMOTE_CLOSED;
+       }
 
        if (connection_write(connection, data, len) == len)
                return ERROR_OK;
+
+       LOG_WARNING("Error writing to GDB socket. Dropping the connection.");
        gdb_con->closed = true;
        return ERROR_SERVER_REMOTE_CLOSED;
 }
@@ -1043,7 +1048,7 @@ static int gdb_new_connection(struct connection *connection)
        }
 
        gdb_actual_connections++;
-       log_printf_lf(all_targets->next != NULL ? LOG_LVL_INFO : LOG_LVL_DEBUG,
+       log_printf_lf(all_targets->next ? LOG_LVL_INFO : LOG_LVL_DEBUG,
                        __FILE__, __LINE__, __func__,
                        "New GDB Connection: %d, Target %s, state: %s",
                        gdb_actual_connections,
@@ -1212,7 +1217,7 @@ static int gdb_get_registers_packet(struct connection *connection,
        LOG_DEBUG("-");
 #endif
 
-       if ((target->rtos) && (ERROR_OK == rtos_get_gdb_reg_list(connection)))
+       if ((target->rtos) && (rtos_get_gdb_reg_list(connection) == ERROR_OK))
                return ERROR_OK;
 
        retval = target_get_gdb_reg_list(target, &reg_list, &reg_list_size,
@@ -1221,7 +1226,7 @@ static int gdb_get_registers_packet(struct connection *connection,
                return gdb_error(connection, retval);
 
        for (i = 0; i < reg_list_size; i++) {
-               if (reg_list[i] == NULL || reg_list[i]->exist == false || reg_list[i]->hidden)
+               if (!reg_list[i] || reg_list[i]->exist == false || reg_list[i]->hidden)
                        continue;
                reg_packet_size += DIV_ROUND_UP(reg_list[i]->size, 8) * 2;
        }
@@ -1235,7 +1240,7 @@ static int gdb_get_registers_packet(struct connection *connection,
        reg_packet_p = reg_packet;
 
        for (i = 0; i < reg_list_size; i++) {
-               if (reg_list[i] == NULL || reg_list[i]->exist == false || reg_list[i]->hidden)
+               if (!reg_list[i] || reg_list[i]->exist == false || reg_list[i]->hidden)
                        continue;
                if (!reg_list[i]->valid) {
                        retval = reg_list[i]->type->get(reg_list[i]);
@@ -1342,7 +1347,7 @@ static int gdb_get_register_packet(struct connection *connection,
        LOG_DEBUG("-");
 #endif
 
-       if ((target->rtos) && (ERROR_OK == rtos_get_gdb_reg(connection, reg_num)))
+       if ((target->rtos) && (rtos_get_gdb_reg(connection, reg_num) == ERROR_OK))
                return ERROR_OK;
 
        retval = target_get_gdb_reg_list_noread(target, &reg_list, &reg_list_size,
@@ -1351,7 +1356,7 @@ static int gdb_get_register_packet(struct connection *connection,
                return gdb_error(connection, retval);
 
        if (reg_list_size <= reg_num) {
-               LOG_ERROR("gdb requested a non-existing register");
+               LOG_ERROR("gdb requested a non-existing register (reg_num=%d)", reg_num);
                return ERROR_SERVER_REMOTE_CLOSED;
        }
 
@@ -1399,7 +1404,7 @@ static int gdb_set_register_packet(struct connection *connection,
        gdb_target_to_reg(target, separator + 1, chars, bin_buf);
 
        if ((target->rtos) &&
-                       (ERROR_OK == rtos_set_reg(connection, reg_num, bin_buf))) {
+                       (rtos_set_reg(connection, reg_num, bin_buf) == ERROR_OK)) {
                free(bin_buf);
                gdb_put_packet(connection, "OK", 2);
                return ERROR_OK;
@@ -1413,7 +1418,7 @@ static int gdb_set_register_packet(struct connection *connection,
        }
 
        if (reg_list_size <= reg_num) {
-               LOG_ERROR("gdb requested a non-existing register");
+               LOG_ERROR("gdb requested a non-existing register (reg_num=%d)", reg_num);
                free(bin_buf);
                free(reg_list);
                return ERROR_SERVER_REMOTE_CLOSED;
@@ -1792,14 +1797,14 @@ static __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6))) void xml_printf(
        int first = 1;
 
        for (;; ) {
-               if ((*xml == NULL) || (!first)) {
+               if ((!*xml) || (!first)) {
                        /* start by 0 to exercise all the code paths.
                         * Need minimum 2 bytes to fit 1 char and 0 terminator. */
 
                        *size = *size * 2 + 2;
                        char *t = *xml;
                        *xml = realloc(*xml, *size);
-                       if (*xml == NULL) {
+                       if (!*xml) {
                                free(t);
                                *retval = ERROR_SERVER_REMOTE_CLOSED;
                                return;
@@ -1840,7 +1845,7 @@ static int decode_xfer_read(char const *buf, char **annex, int *ofs, unsigned in
        /* Extract the annex if needed */
        if (annex) {
                *annex = strndup(buf, annex_end - buf);
-               if (*annex == NULL)
+               if (!*annex)
                        return ERROR_FAIL;
        }
 
@@ -2059,7 +2064,7 @@ static int lookup_add_arch_defined_types(char const **arch_defined_types_list[],
 {
        int tbl_sz = *num_arch_defined_types;
 
-       if (type_id != NULL && (strcmp(type_id, ""))) {
+       if (type_id && (strcmp(type_id, ""))) {
                for (int j = 0; j < (tbl_sz + 1); j++) {
                        if (!((*arch_defined_types_list)[j])) {
                                (*arch_defined_types_list)[tbl_sz++] = type_id;
@@ -2224,8 +2229,8 @@ static int get_reg_features_list(struct target *target, char const **feature_lis
                if (reg_list[i]->exist == false || reg_list[i]->hidden)
                        continue;
 
-               if (reg_list[i]->feature != NULL
-                       && reg_list[i]->feature->name != NULL
+               if (reg_list[i]->feature
+                       && reg_list[i]->feature->name
                        && (strcmp(reg_list[i]->feature->name, ""))) {
                        /* We found a feature, check if the feature is already in the
                         * table. If not, allocate a new entry for the table and
@@ -2322,7 +2327,7 @@ static int gdb_generate_target_description(struct target *target, char **tdesc_o
                                        continue;
 
                                const char *type_str;
-                               if (reg_list[i]->reg_data_type != NULL) {
+                               if (reg_list[i]->reg_data_type) {
                                        if (reg_list[i]->reg_data_type->type == REG_TYPE_ARCH_DEFINED) {
                                                /* generate <type... first, if there are architecture-defined types. */
                                                if (lookup_add_arch_defined_types(&arch_defined_types,
@@ -2360,7 +2365,7 @@ static int gdb_generate_target_description(struct target *target, char **tdesc_o
                                xml_printf(&retval, &tdesc, &pos, &size,
                                                " type=\"%s\"", type_str);
 
-                               if (reg_list[i]->group != NULL)
+                               if (reg_list[i]->group)
                                        xml_printf(&retval, &tdesc, &pos, &size,
                                                        " group=\"%s\"", reg_list[i]->group);
 
@@ -2420,7 +2425,7 @@ static int gdb_get_target_description_chunk(struct target *target, struct target
                transfer_type = 'l';
 
        *chunk = malloc(length + 2);
-       if (*chunk == NULL) {
+       if (!*chunk) {
                LOG_ERROR("Unable to allocate memory");
                return ERROR_FAIL;
        }
@@ -2543,7 +2548,7 @@ static int gdb_generate_thread_list(struct target *target, char **thread_list_ou
 static int gdb_get_thread_list_chunk(struct target *target, char **thread_list,
                char **chunk, int32_t offset, uint32_t length)
 {
-       if (*thread_list == NULL) {
+       if (!*thread_list) {
                int retval = gdb_generate_thread_list(target, thread_list);
                if (retval != ERROR_OK) {
                        LOG_ERROR("Unable to Generate Thread List");
@@ -2565,7 +2570,7 @@ static int gdb_get_thread_list_chunk(struct target *target, char **thread_list,
         * of strlen(chunk) word access:
         * Invalid read of size 4
         * Address 0x4479934 is 44 bytes inside a block of size 45 alloc'd */
-       if (*chunk == NULL) {
+       if (!*chunk) {
                LOG_ERROR("Unable to allocate memory");
                return ERROR_FAIL;
        }
@@ -2770,7 +2775,7 @@ static bool gdb_handle_vcont_packet(struct connection *connection, const char *p
 
        /* query for vCont supported */
        if (parse[0] == '?') {
-               if (target->type->step != NULL) {
+               if (target->type->step) {
                        /* gdb doesn't accept c without C and s without S */
                        gdb_put_packet(connection, "vCont;c;C;s;S", 13);
                        return true;
@@ -3006,8 +3011,10 @@ static bool gdb_handle_vrun_packet(struct connection *connection, const char *pa
        free(next_hex_encoded_field(&parse, ';'));
 
        char *cmdline = next_hex_encoded_field(&parse, ';');
-       char *arg;
-       while (cmdline != NULL && (arg = next_hex_encoded_field(&parse, ';')) != NULL) {
+       while (cmdline) {
+               char *arg = next_hex_encoded_field(&parse, ';');
+               if (!arg)
+                       break;
                char *new_cmdline = alloc_printf("%s %s", cmdline, arg);
                free(cmdline);
                free(arg);
@@ -3549,7 +3556,7 @@ static int gdb_target_start(struct target *target, const char *port)
                struct target_list *head;
                struct target *curr;
                head = target->head;
-               while (head != (struct target_list *)NULL) {
+               while (head) {
                        curr = head->target;
                        if (curr != target)
                                curr->gdb_service = gdb_service;

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)