target, register: allow a register hidden from gdb and 'reg' cmd 25/5325/4
authorTomas Vanek <vanekt@fbl.cz>
Sun, 20 Oct 2019 07:40:34 +0000 (09:40 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 15 Nov 2020 21:05:37 +0000 (21:05 +0000)
Introduce a 'hidden' flag in struct reg to support a register cache
containing different views of same data: e.g. Cortex-M has
primask, basepri, faultmask and control registers accessed
as one word. With the hidden flag we can add an reg_list item
corresponding to hw access without exposing the register to user level.

All the struct reg are allocated with calloc() but one in xscale.c
allocated by malloc(). Change this one to use calloc() as well
to guarantee initial value hidden=false

Change-Id: I8da9f5a5a60777ae7ef943a841307487bd80fc6f
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5325
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/server/gdb_server.c
src/target/register.h
src/target/target.c
src/target/xscale.c

index bb4c1317de90ff5a4f0296640bfb188deff0bc42..792bbdceaaec6c2bb116879e2a31d5746d0becb7 100644 (file)
@@ -1189,7 +1189,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)
+               if (reg_list[i] == NULL || reg_list[i]->exist == false || reg_list[i]->hidden)
                        continue;
                reg_packet_size += DIV_ROUND_UP(reg_list[i]->size, 8) * 2;
        }
@@ -1203,7 +1203,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)
+               if (reg_list[i] == NULL || reg_list[i]->exist == false || reg_list[i]->hidden)
                        continue;
                if (!reg_list[i]->valid) {
                        retval = reg_list[i]->type->get(reg_list[i]);
@@ -2176,7 +2176,7 @@ static int get_reg_features_list(struct target *target, char const **feature_lis
        *feature_list = calloc(1, sizeof(char *));
 
        for (int i = 0; i < reg_list_size; i++) {
-               if (reg_list[i]->exist == false)
+               if (reg_list[i]->exist == false || reg_list[i]->hidden)
                        continue;
 
                if (reg_list[i]->feature != NULL
@@ -2270,7 +2270,7 @@ static int gdb_generate_target_description(struct target *target, char **tdesc_o
                        int i;
                        for (i = 0; i < reg_list_size; i++) {
 
-                               if (reg_list[i]->exist == false)
+                               if (reg_list[i]->exist == false || reg_list[i]->hidden)
                                        continue;
 
                                if (strcmp(reg_list[i]->feature->name, features[current_feature]))
index 7c53d6e16deb531c82879001f494f98df69a7da7..1bae81183e77279a5f79b41b336123a0d422db45 100644 (file)
@@ -134,6 +134,8 @@ struct reg {
        bool valid;
        /* When false, the register doesn't actually exist in the target. */
        bool exist;
+       /* Hide the register from gdb and omit it in 'reg' cmd output */
+       bool hidden;
        /* Size of the register in bits. */
        uint32_t size;
        /* Used for generating XML description of registers. Can be set to NULL for
index 9d4fe77214fd802c6cdd7667e99324b662bd28f0..3c1a6338e915a561fb1d08f7f4ee79161753dc2c 100644 (file)
@@ -3037,7 +3037,7 @@ COMMAND_HANDLER(handle_reg_command)
                        for (i = 0, reg = cache->reg_list;
                                        i < cache->num_regs;
                                        i++, reg++, count++) {
-                               if (reg->exist == false)
+                               if (reg->exist == false || reg->hidden)
                                        continue;
                                /* only print cached values if they are valid */
                                if (reg->valid) {
index aaaed0ebb2d0cfc0b7fd8987bbf26c617df66c8d..b25999d3c65ccf0d619d46b96efed69d0e00dcef 100644 (file)
@@ -2882,7 +2882,7 @@ static void xscale_build_reg_cache(struct target *target)
        /* fill in values for the xscale reg cache */
        (*cache_p)->name = "XScale registers";
        (*cache_p)->next = NULL;
-       (*cache_p)->reg_list = malloc(num_regs * sizeof(struct reg));
+       (*cache_p)->reg_list = calloc(num_regs, sizeof(struct reg));
        (*cache_p)->num_regs = num_regs;
 
        for (i = 0; i < num_regs; i++) {

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)