server/gdb: Use get_target_from_connection() 77/4277/2
authorMarc Schink <openocd-dev@marcschink.de>
Thu, 22 Sep 2016 20:36:28 +0000 (22:36 +0200)
committerSpencer Oliver <spen@spen-soft.co.uk>
Wed, 6 Dec 2017 21:01:33 +0000 (21:01 +0000)
Change-Id: I2c66bf6da734a3b71e358553943e9fc3c6578c39
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/4277
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
src/server/gdb_server.c

index 483e5510b115234d5d4243fa5cb8c9e8d7b6a1e7..d7fff66a06e32bd9f1278d667fa92075d4143bd8 100644 (file)
@@ -917,10 +917,11 @@ static int gdb_target_callback_event_handler(struct target *target,
 static int gdb_new_connection(struct connection *connection)
 {
        struct gdb_connection *gdb_connection = malloc(sizeof(struct gdb_connection));
-       struct gdb_service *gdb_service = connection->service->priv;
+       struct target *target;
        int retval;
        int initial_ack;
 
+       target = get_target_from_connection(connection);
        connection->priv = gdb_connection;
 
        /* initialize gdb connection information */
@@ -949,12 +950,12 @@ static int gdb_new_connection(struct connection *connection)
         * GDB session could leave dangling breakpoints if e.g. communication
         * timed out.
         */
-       breakpoint_clear_target(gdb_service->target);
-       watchpoint_clear_target(gdb_service->target);
+       breakpoint_clear_target(target);
+       watchpoint_clear_target(target);
 
        /* clean previous rtos session if supported*/
-       if ((gdb_service->target->rtos) && (gdb_service->target->rtos->type->clean))
-               gdb_service->target->rtos->type->clean(gdb_service->target);
+       if ((target->rtos) && (target->rtos->type->clean))
+               target->rtos->type->clean(target);
 
        /* remove the initial ACK from the incoming buffer */
        retval = gdb_get_char(connection, &initial_ack);
@@ -966,7 +967,7 @@ static int gdb_new_connection(struct connection *connection)
         */
        if (initial_ack != '+')
                gdb_putback_char(connection, initial_ack);
-       target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_ATTACH);
+       target_call_event_callbacks(target, TARGET_EVENT_GDB_ATTACH);
 
        if (gdb_use_memory_map) {
                /* Connect must fail if the memory map can't be set up correctly.
@@ -978,7 +979,7 @@ static int gdb_new_connection(struct connection *connection)
                for (i = 0; i < flash_get_bank_count(); i++) {
                        struct flash_bank *p;
                        p = get_flash_bank_by_num_noprobe(i);
-                       if (p->target != gdb_service->target)
+                       if (p->target != target)
                                continue;
                        retval = get_flash_bank_by_num(i, &p);
                        if (retval != ERROR_OK) {
@@ -992,8 +993,8 @@ static int gdb_new_connection(struct connection *connection)
        gdb_actual_connections++;
        LOG_DEBUG("New GDB Connection: %d, Target %s, state: %s",
                        gdb_actual_connections,
-                       target_name(gdb_service->target),
-                       target_state_name(gdb_service->target));
+                       target_name(target),
+                       target_state_name(target));
 
        /* DANGER! If we fail subsequently, we must remove this handler,
         * otherwise we occasionally see crashes as the timer can invoke the
@@ -1007,9 +1008,11 @@ static int gdb_new_connection(struct connection *connection)
 
 static int gdb_connection_closed(struct connection *connection)
 {
-       struct gdb_service *gdb_service = connection->service->priv;
+       struct target *target;
        struct gdb_connection *gdb_connection = connection->priv;
 
+       target = get_target_from_connection(connection);
+
        /* we're done forwarding messages. Tear down callback before
         * cleaning up connection.
         */
@@ -1017,8 +1020,8 @@ static int gdb_connection_closed(struct connection *connection)
 
        gdb_actual_connections--;
        LOG_DEBUG("GDB Close, Target: %s, state: %s, gdb_actual_connections=%d",
-               target_name(gdb_service->target),
-               target_state_name(gdb_service->target),
+               target_name(target),
+               target_state_name(target),
                gdb_actual_connections);
 
        /* see if an image built with vFlash commands is left */
@@ -1029,7 +1032,7 @@ static int gdb_connection_closed(struct connection *connection)
        }
 
        /* if this connection registered a debug-message receiver delete it */
-       delete_debug_msg_receiver(connection->cmd_ctx, gdb_service->target);
+       delete_debug_msg_receiver(connection->cmd_ctx, target);
 
        if (connection->priv) {
                free(connection->priv);
@@ -1039,9 +1042,9 @@ static int gdb_connection_closed(struct connection *connection)
 
        target_unregister_event_callback(gdb_target_callback_event_handler, connection);
 
-       target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_END);
+       target_call_event_callbacks(target, TARGET_EVENT_GDB_END);
 
-       target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_DETACH);
+       target_call_event_callbacks(target, TARGET_EVENT_GDB_DETACH);
 
        return ERROR_OK;
 }
@@ -2558,9 +2561,11 @@ static int gdb_v_packet(struct connection *connection,
                char const *packet, int packet_size)
 {
        struct gdb_connection *gdb_connection = connection->priv;
-       struct gdb_service *gdb_service = connection->service->priv;
+       struct target *target;
        int result;
 
+       target = get_target_from_connection(connection);
+
        /* if flash programming disabled - send a empty reply */
 
        if (gdb_flash_program == 0) {
@@ -2597,18 +2602,18 @@ static int gdb_v_packet(struct connection *connection,
                flash_set_dirty();
 
                /* perform any target specific operations before the erase */
-               target_call_event_callbacks(gdb_service->target,
+               target_call_event_callbacks(target,
                        TARGET_EVENT_GDB_FLASH_ERASE_START);
 
                /* vFlashErase:addr,length messages require region start and
                 * end to be "block" aligned ... if padding is ever needed,
                 * GDB will have become dangerously confused.
                 */
-               result = flash_erase_address_range(gdb_service->target,
-                               false, addr, length);
+               result = flash_erase_address_range(target, false, addr,
+                       length);
 
                /* perform any target specific operations after the erase */
-               target_call_event_callbacks(gdb_service->target,
+               target_call_event_callbacks(target,
                        TARGET_EVENT_GDB_FLASH_ERASE_END);
 
                /* perform erase */
@@ -2663,10 +2668,12 @@ static int gdb_v_packet(struct connection *connection,
 
                /* process the flashing buffer. No need to erase as GDB
                 * always issues a vFlashErase first. */
-               target_call_event_callbacks(gdb_service->target,
+               target_call_event_callbacks(target,
                                TARGET_EVENT_GDB_FLASH_WRITE_START);
-               result = flash_write(gdb_service->target, gdb_connection->vflash_image, &written, 0);
-               target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_FLASH_WRITE_END);
+               result = flash_write(target, gdb_connection->vflash_image,
+                       &written, 0);
+               target_call_event_callbacks(target,
+                       TARGET_EVENT_GDB_FLASH_WRITE_END);
                if (result != ERROR_OK) {
                        if (result == ERROR_FLASH_DST_OUT_OF_BANK)
                                gdb_put_packet(connection, "E.memtype", 9);
@@ -2690,9 +2697,8 @@ static int gdb_v_packet(struct connection *connection,
 
 static int gdb_detach(struct connection *connection)
 {
-       struct gdb_service *gdb_service = connection->service->priv;
-
-       target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_DETACH);
+       target_call_event_callbacks(get_target_from_connection(connection),
+               TARGET_EVENT_GDB_DETACH);
 
        return gdb_put_packet(connection, "OK", 2);
 }
@@ -2771,14 +2777,15 @@ static int gdb_input_inner(struct connection *connection)
        /* Do not allocate this on the stack */
        static char gdb_packet_buffer[GDB_BUFFER_SIZE];
 
-       struct gdb_service *gdb_service = connection->service->priv;
-       struct target *target = gdb_service->target;
+       struct target *target;
        char const *packet = gdb_packet_buffer;
        int packet_size;
        int retval;
        struct gdb_connection *gdb_con = connection->priv;
        static int extended_protocol;
 
+       target = get_target_from_connection(connection);
+
        /* drain input buffer. If one of the packets fail, then an error
         * packet is replied, if applicable.
         *
@@ -2948,8 +2955,8 @@ static int gdb_input_inner(struct connection *connection)
                                        break;
                                case 'R':
                                        /* handle extended restart packet */
-                                       breakpoint_clear_target(gdb_service->target);
-                                       watchpoint_clear_target(gdb_service->target);
+                                       breakpoint_clear_target(target);
+                                       watchpoint_clear_target(target);
                                        command_run_linef(connection->cmd_ctx, "ocd_gdb_restart %s",
                                                        target_name(target));
                                        /* set connection as attached after reset */

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)