]> git.sur5r.net Git - openocd/commitdiff
gdb_server: add support for architecture element
authorSteven Stallion <stallion@squareup.com>
Tue, 21 Mar 2017 15:33:09 +0000 (10:33 -0500)
committerMatthias Welwarsky <matthias@welwarsky.de>
Tue, 16 Oct 2018 10:58:10 +0000 (11:58 +0100)
This change adds optional support for a target to report architecture
information in the target description to GDB. This is needed by some GDB
implementations to properly support remote target with custom behavior.
More information on the architecture element can be found here:

    https://sourceware.org/gdb/onlinedocs/gdb/Target-Description-Format.html#Target-Description-Format

Change-Id: I57b19cae5ac3496256e4e5cc52cf6526ca5c322d
Signed-off-by: Steven Stallion <stallion@squareup.com>
Reviewed-on: http://openocd.zylin.com/4078
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
src/server/gdb_server.c
src/target/target.c
src/target/target.h
src/target/target_type.h

index 2b3057a1a91e21671fcfa8e1f141abd8eff827aa..13e5aca6a482b1b36060a187ecf933da832346a8 100644 (file)
@@ -2196,6 +2196,7 @@ static int gdb_generate_target_description(struct target *target, char **tdesc_o
        int retval = ERROR_OK;
        struct reg **reg_list = NULL;
        int reg_list_size;
+       char const *architecture;
        char const **features = NULL;
        char const **arch_defined_types = NULL;
        int feature_list_size = 0;
@@ -2237,6 +2238,12 @@ static int gdb_generate_target_description(struct target *target, char **tdesc_o
                        "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n"
                        "<target version=\"1.0\">\n");
 
+       /* generate architecture element if supported by target */
+       architecture = target_get_gdb_arch(target);
+       if (architecture != NULL)
+               xml_printf(&retval, &tdesc, &pos, &size,
+                               "<architecture>%s</architecture>\n", architecture);
+
        /* generate target description according to register list */
        if (features != NULL) {
                while (features[current_feature]) {
@@ -2386,6 +2393,8 @@ static int gdb_target_description_supported(struct target *target, int *supporte
        char const **features = NULL;
        int feature_list_size = 0;
 
+       char const *architecture = target_get_gdb_arch(target);
+
        retval = target_get_gdb_reg_list(target, &reg_list,
                        &reg_list_size, REG_CLASS_ALL);
        if (retval != ERROR_OK) {
@@ -2407,7 +2416,7 @@ static int gdb_target_description_supported(struct target *target, int *supporte
        }
 
        if (supported) {
-               if (feature_list_size)
+               if (architecture || feature_list_size)
                        *supported = 1;
                else
                        *supported = 0;
index 3aaebcd49f4666f351dc93a3aef23f7755513835..c1ccf962e9cd514f12394d6f2e089d60e9738d9b 100644 (file)
@@ -1199,6 +1199,13 @@ int target_hit_watchpoint(struct target *target,
        return target->type->hit_watchpoint(target, hit_watchpoint);
 }
 
+const char *target_get_gdb_arch(struct target *target)
+{
+       if (target->type->get_gdb_arch == NULL)
+               return NULL;
+       return target->type->get_gdb_arch(target);
+}
+
 int target_get_gdb_reg_list(struct target *target,
                struct reg **reg_list[], int *reg_list_size,
                enum target_register_class reg_class)
index fe7e1a7db8e18993f0832ebce8460e013cd9a2e2..5457f0abf63f2240f3b2a294b6312a10d2e899ed 100644 (file)
@@ -472,6 +472,13 @@ int target_remove_watchpoint(struct target *target,
 int target_hit_watchpoint(struct target *target,
                struct watchpoint **watchpoint);
 
+/**
+ * Obtain the architecture for GDB.
+ *
+ * This routine is a wrapper for target->type->get_gdb_arch.
+ */
+const char *target_get_gdb_arch(struct target *target);
+
 /**
  * Obtain the registers for GDB.
  *
index fbbd57d980590e7ec8166cca723ce80098ff17d4..a8928911f65661453b0550416a25c222aa072f64 100644 (file)
@@ -88,6 +88,15 @@ struct target_type {
        int (*deassert_reset)(struct target *target);
        int (*soft_reset_halt)(struct target *target);
 
+       /**
+        * Target architecture for GDB.
+        *
+        * The string returned by this function will not be automatically freed;
+        * if dynamic allocation is used for this value, it must be managed by
+        * the target, ideally by caching the result for subsequent calls.
+        */
+       const char *(*get_gdb_arch)(struct target *target);
+
        /**
         * Target register access for GDB.  Do @b not call this function
         * directly, use target_get_gdb_reg_list() instead.