target: get_gdb_arch() accepts target via const pointer 93/8093/2
authorEvgeniy Naydanov <evgeniy.naydanov@syntacore.com>
Fri, 12 Jan 2024 13:29:32 +0000 (16:29 +0300)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 28 Jan 2024 14:18:54 +0000 (14:18 +0000)
The function in question does not need to change target state. It is a
target-type-dependant function, however, IMHO, it is safe to assume that
any target type would not need to change type-independant state of a
target to figure out the arch.

Change-Id: I607cb3aee6529cd5a97bc1200a0226cf6ef43caf
Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8093
Tested-by: jenkins
Reviewed-by: Jan Matyas <jan.matyas@codasip.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
13 files changed:
src/target/arm.h
src/target/armv4_5.c
src/target/armv8.c
src/target/esirisc.c
src/target/esirisc.h
src/target/mem_ap.c
src/target/riscv/riscv.c
src/target/stm8.c
src/target/target.c
src/target/target.h
src/target/target_type.h
src/target/xtensa/xtensa.c
src/target/xtensa/xtensa.h

index d5053afb814d2d61fc8114af2f3a9d58e661b56d..486666b5c6b0abd07d96afb012cc7c8500847384 100644 (file)
@@ -257,7 +257,7 @@ struct arm {
 };
 
 /** Convert target handle to generic ARM target state handle. */
-static inline struct arm *target_to_arm(struct target *target)
+static inline struct arm *target_to_arm(const struct target *target)
 {
        assert(target);
        return target->arch_info;
@@ -293,11 +293,11 @@ extern const struct command_registration arm_command_handlers[];
 extern const struct command_registration arm_all_profiles_command_handlers[];
 
 int arm_arch_state(struct target *target);
-const char *arm_get_gdb_arch(struct target *target);
+const char *arm_get_gdb_arch(const struct target *target);
 int arm_get_gdb_reg_list(struct target *target,
                struct reg **reg_list[], int *reg_list_size,
                enum target_register_class reg_class);
-const char *armv8_get_gdb_arch(struct target *target);
+const char *armv8_get_gdb_arch(const struct target *target);
 int armv8_get_gdb_reg_list(struct target *target,
                struct reg **reg_list[], int *reg_list_size,
                enum target_register_class reg_class);
index 7debb94984882b02ab4269efc7fa70293c9d6da1..1886d5e1f6a612847402446d7dd40cfe44e2e12a 100644 (file)
@@ -1264,7 +1264,7 @@ const struct command_registration arm_command_handlers[] = {
  * same way as a gdb for arm. This can be changed later on. User can still
  * set the specific architecture variant with the gdb command.
  */
-const char *arm_get_gdb_arch(struct target *target)
+const char *arm_get_gdb_arch(const struct target *target)
 {
        return "arm";
 }
index daf1ffca387e6f6cfb5f20e9413e74f61ea28d61..bf582ff801287a8f4585581ccd5619170d10b863 100644 (file)
@@ -1865,7 +1865,7 @@ const struct command_registration armv8_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-const char *armv8_get_gdb_arch(struct target *target)
+const char *armv8_get_gdb_arch(const struct target *target)
 {
        struct arm *arm = target_to_arm(target);
        return arm->core_state == ARM_STATE_AARCH64 ? "aarch64" : "arm";
index 561edb255a766e18497cdc1e8efe87af247b4c3d..c9ac1d606c3873aebf4687f699c51fd678fd49da 100644 (file)
@@ -1248,7 +1248,7 @@ static int esirisc_arch_state(struct target *target)
        return ERROR_OK;
 }
 
-static const char *esirisc_get_gdb_arch(struct target *target)
+static const char *esirisc_get_gdb_arch(const struct target *target)
 {
        struct esirisc_common *esirisc = target_to_esirisc(target);
 
index 7496b1eda7a51ffab7d3a30761860bb7e6b3311b..6f8cd147223a4b8dc4f1f2af1694b0e9c934cc52 100644 (file)
@@ -106,7 +106,7 @@ struct esirisc_reg {
        int (*write)(struct reg *reg);
 };
 
-static inline struct esirisc_common *target_to_esirisc(struct target *target)
+static inline struct esirisc_common *target_to_esirisc(const struct target *target)
 {
        return (struct esirisc_common *)target->arch_info;
 }
index 50dc91c7b77215a3d70d89330eeb20c7da3270e9..5c81e3a75f5f37d01279c2237bfc0c3a7268f095 100644 (file)
@@ -182,7 +182,7 @@ static struct reg_arch_type mem_ap_reg_arch_type = {
        .set = mem_ap_reg_set,
 };
 
-static const char *mem_ap_get_gdb_arch(struct target *target)
+static const char *mem_ap_get_gdb_arch(const struct target *target)
 {
        return "arm";
 }
index cb8d04f20176c49fe3e63839ae9c1a73bb048b6c..d895ca3726c063e0d529f71e513bd00632c63fb1 100644 (file)
@@ -1744,7 +1744,7 @@ static int riscv_write_memory(struct target *target, target_addr_t address,
        return tt->write_memory(target, address, size, count, buffer);
 }
 
-static const char *riscv_get_gdb_arch(struct target *target)
+static const char *riscv_get_gdb_arch(const struct target *target)
 {
        switch (riscv_xlen(target)) {
                case 32:
index ad4a45298106103c684d450ca79361adbee0c57b..227101b6f08b102389774f0c831467a82b70ceed 100644 (file)
@@ -1158,7 +1158,7 @@ static int stm8_write_core_reg(struct target *target, unsigned int num)
        return ERROR_OK;
 }
 
-static const char *stm8_get_gdb_arch(struct target *target)
+static const char *stm8_get_gdb_arch(const struct target *target)
 {
        return "stm8";
 }
index a411270e2299bd82a9d74d497fe78799afc94401..45698a66c59879a6221ddb4b2b3ee32d2583922c 100644 (file)
@@ -1358,7 +1358,7 @@ int target_hit_watchpoint(struct target *target,
        return target->type->hit_watchpoint(target, hit_watchpoint);
 }
 
-const char *target_get_gdb_arch(struct target *target)
+const char *target_get_gdb_arch(const struct target *target)
 {
        if (!target->type->get_gdb_arch)
                return NULL;
index bd01f5eb6859752ecf1e8db2b1d889a82a5897d6..1713448ce868e019da64bc614168ac56522df2b1 100644 (file)
@@ -501,7 +501,7 @@ int target_hit_watchpoint(struct target *target,
  *
  * This routine is a wrapper for target->type->get_gdb_arch.
  */
-const char *target_get_gdb_arch(struct target *target);
+const char *target_get_gdb_arch(const struct target *target);
 
 /**
  * Obtain the registers for GDB.
index 678ce0f466ec0e30f4d257292430d714dddc842a..bc42c2d16e630a3516868cb7033a6679c127e669 100644 (file)
@@ -83,7 +83,7 @@ struct target_type {
         * 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);
+       const char *(*get_gdb_arch)(const struct target *target);
 
        /**
         * Target register access for GDB.  Do @b not call this function
index b516c17ab886f093a80c6284b198c7d906489c9c..fb7748aa2d10b75016270f2091d201ce5dde208a 100644 (file)
@@ -3442,7 +3442,7 @@ void xtensa_target_deinit(struct target *target)
        free(xtensa->core_config);
 }
 
-const char *xtensa_get_gdb_arch(struct target *target)
+const char *xtensa_get_gdb_arch(const struct target *target)
 {
        return "xtensa";
 }
index f799208f0bb605ac3109dd7329ca8424e5313b91..a220021a68d9edf805d5e9edd98c5ce9e8ade468 100644 (file)
@@ -422,7 +422,7 @@ int xtensa_run_algorithm(struct target *target,
        target_addr_t entry_point, target_addr_t exit_point,
        unsigned int timeout_ms, void *arch_info);
 void xtensa_set_permissive_mode(struct target *target, bool state);
-const char *xtensa_get_gdb_arch(struct target *target);
+const char *xtensa_get_gdb_arch(const struct target *target);
 int xtensa_gdb_query_custom(struct target *target, const char *packet, char **response_p);
 
 COMMAND_HELPER(xtensa_cmd_xtdef_do, struct xtensa *xtensa);

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)