gdb: enable target description support by default
[openocd.git] / src / server / gdb_server.c
index 14925a2bf48329daa6557a7894166d837c52cd4b..a930ec4106b845603b722afcafa1012769fc3c6f 100644 (file)
@@ -122,8 +122,8 @@ static int gdb_report_data_abort;
 
 /* set if we are sending target descriptions to gdb
  * via qXfer:features:read packet */
-/* disabled by default */
-static int gdb_use_target_description;
+/* enabled by default */
+static int gdb_use_target_description = 1;
 
 /* current processing free-run type, used by file-I/O */
 static char gdb_running_type;
@@ -702,40 +702,44 @@ static void gdb_signal_reply(struct target *target, struct connection *connectio
        int sig_reply_len;
        int signal_var;
 
-       if (gdb_connection->ctrl_c) {
-               signal_var = 0x2;
-               gdb_connection->ctrl_c = 0;
-       } else
-               signal_var = gdb_last_signal(target);
+       if (target->debug_reason == DBG_REASON_EXIT) {
+               sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "W00");
+       } else {
+               if (gdb_connection->ctrl_c) {
+                       signal_var = 0x2;
+                       gdb_connection->ctrl_c = 0;
+               } else
+                       signal_var = gdb_last_signal(target);
 
-       stop_reason[0] = '\0';
-       if (target->debug_reason == DBG_REASON_WATCHPOINT) {
-               enum watchpoint_rw hit_wp_type;
-               uint32_t hit_wp_address;
+               stop_reason[0] = '\0';
+               if (target->debug_reason == DBG_REASON_WATCHPOINT) {
+                       enum watchpoint_rw hit_wp_type;
+                       uint32_t hit_wp_address;
 
-               if (watchpoint_hit(target, &hit_wp_type, &hit_wp_address) == ERROR_OK) {
+                       if (watchpoint_hit(target, &hit_wp_type, &hit_wp_address) == ERROR_OK) {
 
-                       switch (hit_wp_type) {
-                               case WPT_WRITE:
-                                       snprintf(stop_reason, sizeof(stop_reason),
-                                                       "watch:%08x;", hit_wp_address);
-                                       break;
-                               case WPT_READ:
-                                       snprintf(stop_reason, sizeof(stop_reason),
-                                                       "rwatch:%08x;", hit_wp_address);
-                                       break;
-                               case WPT_ACCESS:
-                                       snprintf(stop_reason, sizeof(stop_reason),
-                                                       "awatch:%08x;", hit_wp_address);
-                                       break;
-                               default:
-                                       break;
+                               switch (hit_wp_type) {
+                                       case WPT_WRITE:
+                                               snprintf(stop_reason, sizeof(stop_reason),
+                                                               "watch:%08x;", hit_wp_address);
+                                               break;
+                                       case WPT_READ:
+                                               snprintf(stop_reason, sizeof(stop_reason),
+                                                               "rwatch:%08x;", hit_wp_address);
+                                               break;
+                                       case WPT_ACCESS:
+                                               snprintf(stop_reason, sizeof(stop_reason),
+                                                               "awatch:%08x;", hit_wp_address);
+                                               break;
+                                       default:
+                                               break;
+                               }
                        }
                }
-       }
 
-       sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "T%2.2x%s",
-                       signal_var, stop_reason);
+               sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "T%2.2x%s",
+                               signal_var, stop_reason);
+       }
 
        gdb_put_packet(connection, sig_reply, sig_reply_len);
        gdb_connection->frontend_state = TARGET_HALTED;
@@ -860,6 +864,10 @@ static int gdb_target_callback_event_handler(struct target *target,
 {
        int retval;
        struct connection *connection = priv;
+       struct gdb_service *gdb_service = connection->service->priv;
+
+       if (gdb_service->target != target)
+               return ERROR_OK;
 
        switch (event) {
                case TARGET_EVENT_GDB_HALT:
@@ -898,7 +906,7 @@ static int gdb_new_connection(struct connection *connection)
        gdb_connection->closed = 0;
        gdb_connection->busy = 0;
        gdb_connection->noack_mode = 0;
-       gdb_connection->sync = true;
+       gdb_connection->sync = false;
        gdb_connection->mem_write_error = false;
        gdb_connection->attached = true;
 
@@ -1820,6 +1828,8 @@ static int gdb_memory_map(struct connection *connection,
 static const char *gdb_get_reg_type_name(enum reg_type type)
 {
        switch (type) {
+               case REG_TYPE_INT:
+                       return "int";
                case REG_TYPE_INT8:
                        return "int8";
                case REG_TYPE_INT16:
@@ -1844,6 +1854,8 @@ static const char *gdb_get_reg_type_name(enum reg_type type)
                        return "code_ptr";
                case REG_TYPE_DATA_PTR:
                        return "data_ptr";
+               case REG_TYPE_FLOAT:
+                       return "float";
                case REG_TYPE_IEEE_SINGLE:
                        return "ieee_single";
                case REG_TYPE_IEEE_DOUBLE:
@@ -2142,6 +2154,50 @@ static int gdb_get_target_description_chunk(struct target *target, char **chunk,
        return ERROR_OK;
 }
 
+static int gdb_target_description_supported(struct target *target, int *supported)
+{
+       int retval = ERROR_OK;
+       struct reg **reg_list = NULL;
+       int reg_list_size = 0;
+       int feature_list_size = 0;
+
+       retval = target_get_gdb_reg_list(target, &reg_list,
+                       &reg_list_size, REG_CLASS_ALL);
+       if (retval != ERROR_OK) {
+               LOG_ERROR("get register list failed");
+               goto error;
+       }
+
+       if (reg_list_size <= 0) {
+               retval = ERROR_FAIL;
+               goto error;
+       }
+
+       char **features = NULL;
+       /* Get a list of available target registers features */
+       retval = get_reg_features_list(target, &features, &feature_list_size, reg_list, reg_list_size);
+       if (retval != ERROR_OK) {
+               LOG_ERROR("Can't get the registers feature list");
+               goto error;
+       }
+
+       if (supported) {
+               if (feature_list_size)
+                       *supported = 1;
+               else
+                       *supported = 0;
+       }
+
+error:
+       if (reg_list != NULL)
+               free(reg_list);
+
+       if (features != NULL)
+               free(features);
+
+       return retval;
+}
+
 static int gdb_query_packet(struct connection *connection,
                char *packet, int packet_size)
 {
@@ -2206,11 +2262,26 @@ static int gdb_query_packet(struct connection *connection,
                }
        } else if (strncmp(packet, "qSupported", 10) == 0) {
                /* we currently support packet size and qXfer:memory-map:read (if enabled)
-                * disable qXfer:features:read for the moment */
+                * qXfer:features:read is supported for some targets */
                int retval = ERROR_OK;
                char *buffer = NULL;
                int pos = 0;
                int size = 0;
+               int gdb_target_desc_supported = 0;
+
+               /* we need to test that the target supports target descriptions */
+               retval = gdb_target_description_supported(target, &gdb_target_desc_supported);
+               if (retval != ERROR_OK) {
+                       LOG_INFO("Failed detecting Target Description Support, disabling");
+                       gdb_target_desc_supported = 0;
+               }
+
+               /* support may be disabled globally */
+               if (gdb_use_target_description == 0) {
+                       if (gdb_target_desc_supported)
+                               LOG_WARNING("Target Descriptions Supported, but disabled");
+                       gdb_target_desc_supported = 0;
+               }
 
                xml_printf(&retval,
                        &buffer,
@@ -2219,7 +2290,7 @@ static int gdb_query_packet(struct connection *connection,
                        "PacketSize=%x;qXfer:memory-map:read%c;qXfer:features:read%c;QStartNoAckMode+",
                        (GDB_BUFFER_SIZE - 1),
                        ((gdb_use_memory_map == 1) && (flash_get_bank_count() > 0)) ? '+' : '-',
-                       (gdb_use_target_description == 1) ? '+' : '-');
+                       (gdb_target_desc_supported == 1) ? '+' : '-');
 
                if (retval != ERROR_OK) {
                        gdb_send_error(connection, 01);
@@ -2928,16 +2999,16 @@ COMMAND_HANDLER(handle_gdb_save_tdesc_command)
 
        int retval = fileio_open(&fileio, tdesc_filename, FILEIO_WRITE, FILEIO_TEXT);
 
-       free(tdesc_filename);
-
        if (retval != ERROR_OK) {
                LOG_WARNING("Can't open %s for writing", tdesc_filename);
+               free(tdesc_filename);
                return ERROR_FAIL;
        }
 
        retval = fileio_write(&fileio, tdesc_length, tdesc, &size_written);
 
        fileio_close(&fileio);
+       free(tdesc_filename);
 
        if (retval != ERROR_OK) {
                LOG_WARNING("Error while writing the tdesc file");

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)