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 */
* 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);
*/
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.
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) {
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
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.
*/
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 */
}
/* 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);
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;
}
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) {
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 */
/* 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);
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);
}
/* 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.
*
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 */