This is an automated email from Gerrit.

Steven Stallion ([email protected]) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/4113

-- gerrit

commit ecf3408d349ec6a79a662e6a0a813fb7eb27ed27
Author: Steven Stallion <[email protected]>
Date:   Mon May 1 14:38:35 2017 -0500

    register: support non-existent registers
    
    This patch fixes a number of bugs caused by incomplete support for
    non-existent registers. This is needed for targets that provide optional
    registers or non-linear register numbers.
    
    Change-Id: I216196e0051f28887a2c3da410959382369eed80
    Signed-off-by: Steven Stallion <[email protected]>

diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 483e551..35b8514 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -1156,6 +1156,8 @@ 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)
+                       continue;
                reg_packet_size += DIV_ROUND_UP(reg_list[i]->size, 8) * 2;
 
        assert(reg_packet_size > 0);
@@ -1167,6 +1169,8 @@ 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)
+                       continue;
                if (!reg_list[i]->valid)
                        reg_list[i]->type->get(reg_list[i]);
                gdb_str_to_target(target, reg_packet_p, reg_list[i]);
diff --git a/src/target/register.c b/src/target/register.c
index 1d63e12..8506414 100644
--- a/src/target/register.c
+++ b/src/target/register.c
@@ -44,6 +44,8 @@ struct reg *register_get_by_name(struct reg_cache *first,
 
        while (cache) {
                for (i = 0; i < cache->num_regs; i++) {
+                       if (cache->reg_list[i].exist == false)
+                               continue;
                        if (strcmp(cache->reg_list[i].name, name) == 0)
                                return &(cache->reg_list[i]);
                }
@@ -84,6 +86,8 @@ void register_cache_invalidate(struct reg_cache *cache)
        struct reg *reg = cache->reg_list;
 
        for (unsigned n = cache->num_regs; n != 0; n--, reg++) {
+               if (reg->exist == false)
+                       continue;
                reg->valid = 0;
                reg->dirty = 0;
        }
diff --git a/src/target/target.c b/src/target/target.c
index e04ecc4..24c18a1 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -2738,6 +2738,8 @@ COMMAND_HANDLER(handle_reg_command)
                        for (i = 0, reg = cache->reg_list;
                                        i < cache->num_regs;
                                        i++, reg++, count++) {
+                               if (reg->exist == false)
+                                       continue;
                                /* only print cached values if they are valid */
                                if (reg->valid) {
                                        value = buf_to_str(reg->value,
@@ -2791,14 +2793,15 @@ COMMAND_HANDLER(handle_reg_command)
                /* access a single register by its name */
                reg = register_get_by_name(target->reg_cache, CMD_ARGV[0], 1);
 
-               if (!reg) {
-                       command_print(CMD_CTX, "register %s not found in 
current target", CMD_ARGV[0]);
-                       return ERROR_OK;
-               }
+               if (!reg)
+                       goto not_found;
        }
 
        assert(reg != NULL); /* give clang a hint that we *know* reg is != NULL 
here */
 
+       if (!reg->exist)
+               goto not_found;
+
        /* display a register */
        if ((CMD_ARGC == 1) || ((CMD_ARGC == 2) && !((CMD_ARGV[1][0] >= '0')
                        && (CMD_ARGV[1][0] <= '9')))) {
@@ -2832,6 +2835,10 @@ COMMAND_HANDLER(handle_reg_command)
        }
 
        return ERROR_COMMAND_SYNTAX_ERROR;
+
+not_found:
+       command_print(CMD_CTX, "register %s not found in current target", 
CMD_ARGV[0]);
+       return ERROR_OK;
 }
 
 COMMAND_HANDLER(handle_poll_command)

-- 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to