1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 #include "replacements.h"
26 #include "gdb_server.h"
30 #include "binarybuffer.h"
32 #include "breakpoints.h"
34 #include "target_request.h"
42 #define _DEBUG_GDB_IO_
45 static unsigned short gdb_port
;
46 static const char *DIGITS
= "0123456789abcdef";
48 static void gdb_log_callback(void *priv
, const char *file
, int line
,
49 const char *function
, const char *format
, va_list args
);
59 /* target behaviour on gdb detach */
60 enum gdb_detach_mode detach_mode
= GDB_DETACH_RESUME
;
62 /* set if we are sending a memory map to gdb
63 * via qXfer:memory-map:read packet */
64 int gdb_use_memory_map
= 0;
65 int gdb_flash_program
= 0;
67 int gdb_last_signal(target_t
*target
)
69 switch (target
->debug_reason
)
71 case DBG_REASON_DBGRQ
:
72 return 0x2; /* SIGINT */
73 case DBG_REASON_BREAKPOINT
:
74 case DBG_REASON_WATCHPOINT
:
75 case DBG_REASON_WPTANDBKPT
:
76 return 0x05; /* SIGTRAP */
77 case DBG_REASON_SINGLESTEP
:
78 return 0x05; /* SIGTRAP */
79 case DBG_REASON_NOTHALTED
:
80 return 0x0; /* no signal... shouldn't happen */
82 ERROR("BUG: undefined debug reason");
87 int gdb_get_char(connection_t
*connection
, int* next_char
)
89 gdb_connection_t
*gdb_con
= connection
->priv
;
95 if (gdb_con
->buf_cnt
-- > 0)
97 *next_char
= *(gdb_con
->buf_p
++);
98 if (gdb_con
->buf_cnt
> 0)
99 connection
->input_pending
= 1;
101 connection
->input_pending
= 0;
103 #ifdef _DEBUG_GDB_IO_
104 DEBUG("returned char '%c' (0x%2.2x)", *next_char
, *next_char
);
113 /* a non-blocking socket will block if there is 0 bytes available on the socket,
114 * but return with as many bytes as are available immediately
120 FD_SET(connection
->fd
, &read_fds
);
124 if (select(connection
->fd
+ 1, &read_fds
, NULL
, NULL
, &tv
) == 0)
126 /* This can typically be because a "monitor" command took too long
127 * before printing any progress messages
129 return ERROR_GDB_TIMEOUT
;
132 gdb_con
->buf_cnt
= read_socket(connection
->fd
, gdb_con
->buffer
, GDB_BUFFER_SIZE
);
133 if (gdb_con
->buf_cnt
> 0)
137 if (gdb_con
->buf_cnt
== 0)
140 return ERROR_SERVER_REMOTE_CLOSED
;
144 errno
= WSAGetLastError();
151 case WSAECONNABORTED
:
152 return ERROR_SERVER_REMOTE_CLOSED
;
154 return ERROR_SERVER_REMOTE_CLOSED
;
156 ERROR("read: %d", errno
);
166 return ERROR_SERVER_REMOTE_CLOSED
;
168 return ERROR_SERVER_REMOTE_CLOSED
;
170 ERROR("read: %s", strerror(errno
));
171 return ERROR_SERVER_REMOTE_CLOSED
;
176 #ifdef _DEBUG_GDB_IO_
177 debug_buffer
= malloc(gdb_con
->buf_cnt
+ 1);
178 memcpy(debug_buffer
, gdb_con
->buffer
, gdb_con
->buf_cnt
);
179 debug_buffer
[gdb_con
->buf_cnt
] = 0;
180 DEBUG("received '%s'", debug_buffer
);
184 gdb_con
->buf_p
= gdb_con
->buffer
;
186 *next_char
= *(gdb_con
->buf_p
++);
187 if (gdb_con
->buf_cnt
> 0)
188 connection
->input_pending
= 1;
190 connection
->input_pending
= 0;
191 #ifdef _DEBUG_GDB_IO_
192 DEBUG("returned char '%c' (0x%2.2x)", *next_char
, *next_char
);
198 int gdb_putback_char(connection_t
*connection
, int last_char
)
200 gdb_connection_t
*gdb_con
= connection
->priv
;
202 if (gdb_con
->buf_p
> gdb_con
->buffer
)
204 *(--gdb_con
->buf_p
) = last_char
;
209 ERROR("BUG: couldn't put character back");
215 /* The only way we can detect that the socket is closed is the first time
216 * we write to it, we will fail. Subsequent write operations will
217 * succeed. Shudder! */
218 int gdb_write(connection_t
*connection
, void *data
, int len
)
220 gdb_connection_t
*gdb_con
= connection
->priv
;
222 return ERROR_SERVER_REMOTE_CLOSED
;
224 if (write_socket(connection
->fd
, data
, len
) == len
)
229 return ERROR_SERVER_REMOTE_CLOSED
;
232 int gdb_put_packet_inner(connection_t
*connection
, char *buffer
, int len
)
235 unsigned char my_checksum
= 0;
236 #ifdef _DEBUG_GDB_IO_
241 gdb_connection_t
*gdb_con
= connection
->priv
;
243 for (i
= 0; i
< len
; i
++)
244 my_checksum
+= buffer
[i
];
248 #ifdef _DEBUG_GDB_IO_
249 debug_buffer
= malloc(len
+ 1);
250 memcpy(debug_buffer
, buffer
, len
);
251 debug_buffer
[len
] = 0;
252 DEBUG("sending packet '$%s#%2.2x'", debug_buffer
, my_checksum
);
257 gdb_write(connection
, "$", 1);
259 gdb_write(connection
, buffer
, len
);
260 gdb_write(connection
, "#", 1);
262 snprintf(checksum
, 3, "%2.2x", my_checksum
);
264 gdb_write(connection
, checksum
, 2);
266 void *allocated
= NULL
;
267 char stackAlloc
[1024];
268 char *t
= stackAlloc
;
269 int totalLen
= 1 + len
+ 1 + 2;
270 if (totalLen
> sizeof(stackAlloc
))
272 allocated
= malloc(totalLen
);
274 if (allocated
== NULL
)
276 ERROR("Ran out of memory trying to reply packet %d\n", totalLen
);
281 memcpy(t
+ 1, buffer
, len
);
283 t
[1 + len
+ 1] = DIGITS
[(my_checksum
>> 4) & 0xf];
284 t
[1 + len
+ 2] = DIGITS
[my_checksum
& 0xf];
286 gdb_write(connection
, t
, totalLen
);
293 if ((retval
= gdb_get_char(connection
, &reply
)) != ERROR_OK
)
298 else if (reply
== '-')
300 /* Stop sending output packets for now */
301 log_setCallback(NULL
, NULL
);
302 WARNING("negative reply, retrying");
304 else if (reply
== 0x3)
307 if ((retval
= gdb_get_char(connection
, &reply
)) != ERROR_OK
)
311 else if (reply
== '-')
313 /* Stop sending output packets for now */
314 log_setCallback(NULL
, NULL
);
315 WARNING("negative reply, retrying");
319 ERROR("unknown character 0x%2.2x in reply, dropping connection", reply
);
320 return ERROR_SERVER_REMOTE_CLOSED
;
325 ERROR("unknown character 0x%2.2x in reply, dropping connection", reply
);
326 return ERROR_SERVER_REMOTE_CLOSED
;
330 return ERROR_SERVER_REMOTE_CLOSED
;
335 int gdb_put_packet(connection_t
*connection
, char *buffer
, int len
)
337 gdb_connection_t
*gdb_con
= connection
->priv
;
339 int retval
= gdb_put_packet_inner(connection
, buffer
, len
);
344 int gdb_get_packet_inner(connection_t
*connection
, char *buffer
, int *len
)
350 unsigned char my_checksum
= 0;
351 gdb_connection_t
*gdb_con
= connection
->priv
;
357 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
360 #ifdef _DEBUG_GDB_IO_
361 DEBUG("character: '%c'", character
);
369 WARNING("acknowledgment received, but no packet pending");
372 WARNING("negative acknowledgment, but no packet pending");
379 WARNING("ignoring character 0x%x", character
);
382 } while (character
!= '$');
387 gdb_connection_t
*gdb_con
= connection
->priv
;
390 /* The common case is that we have an entire packet with no escape chars.
391 * We need to leave at least 2 bytes in the buffer to have
392 * gdb_get_char() update various bits and bobs correctly.
394 if ((gdb_con
->buf_cnt
> 2) && ((gdb_con
->buf_cnt
+count
) < *len
))
396 /* The compiler will struggle a bit with constant propagation and
397 * aliasing, so we help it by showing that these values do not
398 * change inside the loop
401 char *buf
= gdb_con
->buf_p
;
402 int run
= gdb_con
->buf_cnt
- 2;
409 if (character
== '#')
411 /* Danger! character can be '#' when esc is
412 * used so we need an explicit boolean for done here.
418 if (character
== '}')
420 /* data transmitted in binary mode (X packet)
421 * uses 0x7d as escape character */
422 my_checksum
+= character
& 0xff;
425 my_checksum
+= character
& 0xff;
426 buffer
[count
++] = (character
^ 0x20) & 0xff;
429 my_checksum
+= character
& 0xff;
430 buffer
[count
++] = character
& 0xff;
434 gdb_con
->buf_cnt
-= i
;
440 ERROR("packet buffer too small");
441 return ERROR_GDB_BUFFER_TOO_SMALL
;
444 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
447 if (character
== '#')
450 if (character
== '}')
452 /* data transmitted in binary mode (X packet)
453 * uses 0x7d as escape character */
454 my_checksum
+= character
& 0xff;
455 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
457 my_checksum
+= character
& 0xff;
458 buffer
[count
++] = (character
^ 0x20) & 0xff;
462 my_checksum
+= character
& 0xff;
463 buffer
[count
++] = character
& 0xff;
470 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
472 checksum
[0] = character
;
473 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
475 checksum
[1] = character
;
478 if (my_checksum
== strtoul(checksum
, NULL
, 16))
480 gdb_write(connection
, "+", 1);
484 WARNING("checksum error, requesting retransmission");
485 gdb_write(connection
, "-", 1);
488 return ERROR_SERVER_REMOTE_CLOSED
;
493 int gdb_get_packet(connection_t
*connection
, char *buffer
, int *len
)
495 gdb_connection_t
*gdb_con
= connection
->priv
;
497 int retval
= gdb_get_packet_inner(connection
, buffer
, len
);
502 int gdb_output_con(connection_t
*connection
, char* line
)
507 bin_size
= strlen(line
);
509 hex_buffer
= malloc(bin_size
*2 + 4);
512 for (i
=0; i
<bin_size
; i
++)
513 snprintf(hex_buffer
+ 1 + i
*2, 3, "%2.2x", line
[i
]);
514 hex_buffer
[bin_size
*2+1] = '0';
515 hex_buffer
[bin_size
*2+2] = 'a';
516 hex_buffer
[bin_size
*2+3] = 0x0;
518 gdb_put_packet(connection
, hex_buffer
, bin_size
*2 + 3);
524 int gdb_output(struct command_context_s
*context
, char* line
)
526 /* this will be dumped to the log and also sent as an O packet if possible */
531 int gdb_program_handler(struct target_s
*target
, enum target_event event
, void *priv
)
534 struct command_context_s
*cmd_ctx
= priv
;
536 if (target
->gdb_program_script
)
538 script
= fopen(target
->gdb_program_script
, "r");
541 ERROR("couldn't open script file %s", target
->gdb_program_script
);
545 INFO("executing gdb_program script '%s'", target
->gdb_program_script
);
546 command_run_file(cmd_ctx
, script
, COMMAND_EXEC
);
549 jtag_execute_queue();
555 int gdb_target_callback_event_handler(struct target_s
*target
, enum target_event event
, void *priv
)
557 connection_t
*connection
= priv
;
558 gdb_connection_t
*gdb_connection
= connection
->priv
;
564 case TARGET_EVENT_HALTED
:
565 /* In the GDB protocol when we are stepping or coninuing execution,
566 * we have a lingering reply. Upon receiving a halted event
567 * when we have that lingering packet, we reply to the original
568 * step or continue packet.
570 * Executing monitor commands can bring the target in and
571 * out of the running state so we'll see lots of TARGET_EVENT_XXX
572 * that are to be ignored.
574 if (gdb_connection
->frontend_state
== TARGET_RUNNING
)
576 /* stop forwarding log packets! */
577 log_setCallback(NULL
, NULL
);
579 if (gdb_connection
->ctrl_c
)
582 gdb_connection
->ctrl_c
= 0;
586 signal
= gdb_last_signal(target
);
589 snprintf(sig_reply
, 4, "T%2.2x", signal
);
590 gdb_put_packet(connection
, sig_reply
, 3);
591 gdb_connection
->frontend_state
= TARGET_HALTED
;
594 case TARGET_EVENT_GDB_PROGRAM
:
595 gdb_program_handler(target
, event
, connection
->cmd_ctx
);
604 int gdb_new_connection(connection_t
*connection
)
606 gdb_connection_t
*gdb_connection
= malloc(sizeof(gdb_connection_t
));
607 gdb_service_t
*gdb_service
= connection
->service
->priv
;
611 connection
->priv
= gdb_connection
;
613 /* initialize gdb connection information */
614 gdb_connection
->buf_p
= gdb_connection
->buffer
;
615 gdb_connection
->buf_cnt
= 0;
616 gdb_connection
->ctrl_c
= 0;
617 gdb_connection
->frontend_state
= TARGET_HALTED
;
618 gdb_connection
->vflash_image
= NULL
;
619 gdb_connection
->closed
= 0;
620 gdb_connection
->busy
= 0;
622 /* output goes through gdb connection */
623 command_set_output_handler(connection
->cmd_ctx
, gdb_output
, connection
);
625 /* register callback to be informed about target events */
626 target_register_event_callback(gdb_target_callback_event_handler
, connection
);
628 /* a gdb session just attached, put the target in halt mode */
629 if (((retval
= gdb_service
->target
->type
->halt(gdb_service
->target
)) != ERROR_OK
) &&
630 (retval
!= ERROR_TARGET_ALREADY_HALTED
))
632 ERROR("error(%d) when trying to halt target, falling back to \"reset halt\"", retval
);
633 command_run_line(connection
->cmd_ctx
, "reset halt");
636 /* This will time out after 1 second */
637 command_run_line(connection
->cmd_ctx
, "wait_halt 1");
639 /* remove the initial ACK from the incoming buffer */
640 if ((retval
= gdb_get_char(connection
, &initial_ack
)) != ERROR_OK
)
643 if (initial_ack
!= '+')
644 gdb_putback_char(connection
, initial_ack
);
649 int gdb_connection_closed(connection_t
*connection
)
651 gdb_service_t
*gdb_service
= connection
->service
->priv
;
652 gdb_connection_t
*gdb_connection
= connection
->priv
;
654 /* see if an image built with vFlash commands is left */
655 if (gdb_connection
->vflash_image
)
657 image_close(gdb_connection
->vflash_image
);
658 free(gdb_connection
->vflash_image
);
659 gdb_connection
->vflash_image
= NULL
;
662 /* if this connection registered a debug-message receiver delete it */
663 delete_debug_msg_receiver(connection
->cmd_ctx
, gdb_service
->target
);
665 if (connection
->priv
)
667 free(connection
->priv
);
668 connection
->priv
= NULL
;
672 ERROR("BUG: connection->priv == NULL");
675 target_unregister_event_callback(gdb_target_callback_event_handler
, connection
);
680 void gdb_send_error(connection_t
*connection
, u8 the_error
)
683 snprintf(err
, 4, "E%2.2X", the_error
);
684 gdb_put_packet(connection
, err
, 3);
687 int gdb_last_signal_packet(connection_t
*connection
, target_t
*target
, char* packet
, int packet_size
)
692 signal
= gdb_last_signal(target
);
694 snprintf(sig_reply
, 4, "S%2.2x", signal
);
695 gdb_put_packet(connection
, sig_reply
, 3);
700 /* Convert register to string of bits. NB! The # of bits in the
701 * register might be non-divisible by 8(a byte), in which
702 * case an entire byte is shown. */
703 void gdb_str_to_target(target_t
*target
, char *tstr
, reg_t
*reg
)
710 buf_len
= CEIL(reg
->size
, 8);
712 if (target
->endianness
== TARGET_LITTLE_ENDIAN
)
714 for (i
= 0; i
< buf_len
; i
++)
716 tstr
[i
*2] = DIGITS
[(buf
[i
]>>4) & 0xf];
717 tstr
[i
*2+1] = DIGITS
[buf
[i
]&0xf];
722 for (i
= 0; i
< buf_len
; i
++)
724 tstr
[(buf_len
-1-i
)*2] = DIGITS
[(buf
[i
]>>4)&0xf];
725 tstr
[(buf_len
-1-i
)*2+1] = DIGITS
[buf
[i
]&0xf];
730 void gdb_target_to_str(target_t
*target
, char *tstr
, char *str
)
732 int str_len
= strlen(tstr
);
737 ERROR("BUG: gdb value with uneven number of characters encountered");
741 if (target
->endianness
== TARGET_LITTLE_ENDIAN
)
743 for (i
= 0; i
< str_len
; i
+=2)
745 str
[str_len
- i
- 1] = tstr
[i
+ 1];
746 str
[str_len
- i
- 2] = tstr
[i
];
751 for (i
= 0; i
< str_len
; i
++)
758 int gdb_get_registers_packet(connection_t
*connection
, target_t
*target
, char* packet
, int packet_size
)
763 int reg_packet_size
= 0;
768 #ifdef _DEBUG_GDB_IO_
772 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
776 case ERROR_TARGET_NOT_HALTED
:
777 ERROR("gdb requested registers but we're not halted, dropping connection");
778 return ERROR_SERVER_REMOTE_CLOSED
;
780 /* this is a bug condition - get_gdb_reg_list() may not return any other error */
781 ERROR("BUG: unexpected error returned by get_gdb_reg_list()");
786 for (i
= 0; i
< reg_list_size
; i
++)
788 reg_packet_size
+= reg_list
[i
]->size
;
791 reg_packet
= malloc(CEIL(reg_packet_size
, 8) * 2);
792 reg_packet_p
= reg_packet
;
794 for (i
= 0; i
< reg_list_size
; i
++)
796 gdb_str_to_target(target
, reg_packet_p
, reg_list
[i
]);
797 reg_packet_p
+= CEIL(reg_list
[i
]->size
, 8) * 2;
800 #ifdef _DEBUG_GDB_IO_
803 reg_packet_p
= strndup(reg_packet
, CEIL(reg_packet_size
, 8) * 2);
804 DEBUG("reg_packet: %s", reg_packet_p
);
809 gdb_put_packet(connection
, reg_packet
, CEIL(reg_packet_size
, 8) * 2);
817 int gdb_set_registers_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
825 #ifdef _DEBUG_GDB_IO_
829 /* skip command character */
835 WARNING("GDB set_registers packet with uneven characters received, dropping connection");
836 return ERROR_SERVER_REMOTE_CLOSED
;
839 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
843 case ERROR_TARGET_NOT_HALTED
:
844 ERROR("gdb tried to registers but we're not halted, dropping connection");
845 return ERROR_SERVER_REMOTE_CLOSED
;
847 /* this is a bug condition - get_gdb_reg_list() may not return any other error */
848 ERROR("BUG: unexpected error returned by get_gdb_reg_list()");
854 for (i
= 0; i
< reg_list_size
; i
++)
858 reg_arch_type_t
*arch_type
;
860 /* convert from GDB-string (target-endian) to hex-string (big-endian) */
861 hex_buf
= malloc(CEIL(reg_list
[i
]->size
, 8) * 2);
862 gdb_target_to_str(target
, packet_p
, hex_buf
);
864 /* convert hex-string to binary buffer */
865 bin_buf
= malloc(CEIL(reg_list
[i
]->size
, 8));
866 str_to_buf(hex_buf
, CEIL(reg_list
[i
]->size
, 8) * 2, bin_buf
, reg_list
[i
]->size
, 16);
868 /* get register arch_type, and call set method */
869 arch_type
= register_get_arch_type(reg_list
[i
]->arch_type
);
870 if (arch_type
== NULL
)
872 ERROR("BUG: encountered unregistered arch type");
875 arch_type
->set(reg_list
[i
], bin_buf
);
877 /* advance packet pointer */
878 packet_p
+= (CEIL(reg_list
[i
]->size
, 8) * 2);
884 /* free reg_t *reg_list[] array allocated by get_gdb_reg_list */
887 gdb_put_packet(connection
, "OK", 2);
892 int gdb_get_register_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
895 int reg_num
= strtoul(packet
+ 1, NULL
, 16);
900 #ifdef _DEBUG_GDB_IO_
904 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
908 case ERROR_TARGET_NOT_HALTED
:
909 ERROR("gdb requested registers but we're not halted, dropping connection");
910 return ERROR_SERVER_REMOTE_CLOSED
;
912 /* this is a bug condition - get_gdb_reg_list() may not return any other error */
913 ERROR("BUG: unexpected error returned by get_gdb_reg_list()");
918 if (reg_list_size
<= reg_num
)
920 ERROR("gdb requested a non-existing register");
924 reg_packet
= malloc(CEIL(reg_list
[reg_num
]->size
, 8) * 2);
926 gdb_str_to_target(target
, reg_packet
, reg_list
[reg_num
]);
928 gdb_put_packet(connection
, reg_packet
, CEIL(reg_list
[reg_num
]->size
, 8) * 2);
936 int gdb_set_register_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
941 int reg_num
= strtoul(packet
+ 1, &separator
, 16);
945 reg_arch_type_t
*arch_type
;
949 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
953 case ERROR_TARGET_NOT_HALTED
:
954 ERROR("gdb tried to set a register but we're not halted, dropping connection");
955 return ERROR_SERVER_REMOTE_CLOSED
;
957 /* this is a bug condition - get_gdb_reg_list() may not return any other error */
958 ERROR("BUG: unexpected error returned by get_gdb_reg_list()");
963 if (reg_list_size
< reg_num
)
965 ERROR("gdb requested a non-existing register");
966 return ERROR_SERVER_REMOTE_CLOSED
;
969 if (*separator
!= '=')
971 ERROR("GDB 'set register packet', but no '=' following the register number");
972 return ERROR_SERVER_REMOTE_CLOSED
;
975 /* convert from GDB-string (target-endian) to hex-string (big-endian) */
976 hex_buf
= malloc(CEIL(reg_list
[reg_num
]->size
, 8) * 2);
977 gdb_target_to_str(target
, separator
+ 1, hex_buf
);
979 /* convert hex-string to binary buffer */
980 bin_buf
= malloc(CEIL(reg_list
[reg_num
]->size
, 8));
981 str_to_buf(hex_buf
, CEIL(reg_list
[reg_num
]->size
, 8) * 2, bin_buf
, reg_list
[reg_num
]->size
, 16);
983 /* get register arch_type, and call set method */
984 arch_type
= register_get_arch_type(reg_list
[reg_num
]->arch_type
);
985 if (arch_type
== NULL
)
987 ERROR("BUG: encountered unregistered arch type");
990 arch_type
->set(reg_list
[reg_num
], bin_buf
);
992 gdb_put_packet(connection
, "OK", 2);
1001 int gdb_memory_packet_error(connection_t
*connection
, int retval
)
1005 case ERROR_TARGET_NOT_HALTED
:
1006 ERROR("gdb tried to read memory but we're not halted, dropping connection");
1007 return ERROR_SERVER_REMOTE_CLOSED
;
1008 case ERROR_TARGET_DATA_ABORT
:
1009 gdb_send_error(connection
, EIO
);
1011 case ERROR_TARGET_TRANSLATION_FAULT
:
1012 gdb_send_error(connection
, EFAULT
);
1014 case ERROR_TARGET_UNALIGNED_ACCESS
:
1015 gdb_send_error(connection
, EFAULT
);
1018 /* This could be that the target reset itself. */
1019 ERROR("unexpected error %i. Dropping connection.", retval
);
1020 return ERROR_SERVER_REMOTE_CLOSED
;
1026 /* We don't have to worry about the default 2 second timeout for GDB packets,
1027 * because GDB breaks up large memory reads into smaller reads.
1029 * 8191 bytes by the looks of it. Why 8191 bytes instead of 8192?????
1031 int gdb_read_memory_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1040 int retval
= ERROR_OK
;
1042 /* skip command character */
1045 addr
= strtoul(packet
, &separator
, 16);
1047 if (*separator
!= ',')
1049 ERROR("incomplete read memory packet received, dropping connection");
1050 return ERROR_SERVER_REMOTE_CLOSED
;
1053 len
= strtoul(separator
+1, NULL
, 16);
1055 buffer
= malloc(len
);
1057 DEBUG("addr: 0x%8.8x, len: 0x%8.8x", addr
, len
);
1062 if ((addr
% 4) == 0)
1063 retval
= target
->type
->read_memory(target
, addr
, 4, 1, buffer
);
1065 retval
= target
->type
->read_memory(target
, addr
, 1, len
, buffer
);
1068 if ((addr
% 2) == 0)
1069 retval
= target
->type
->read_memory(target
, addr
, 2, 1, buffer
);
1071 retval
= target
->type
->read_memory(target
, addr
, 1, len
, buffer
);
1075 retval
= target
->type
->read_memory(target
, addr
, 1, len
, buffer
);
1077 /* handle bulk reads */
1079 retval
= target_read_buffer(target
, addr
, len
, buffer
);
1084 if (retval
== ERROR_TARGET_DATA_ABORT
)
1086 /* TODO : Here we have to lie and send back all zero's lest stack traces won't work.
1087 * At some point this might be fixed in GDB, in which case this code can be removed.
1088 * http://sourceware.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gdb&pr=2395
1090 memset(buffer
, 0, len
);
1095 if (retval
== ERROR_OK
)
1097 hex_buffer
= malloc(len
* 2 + 1);
1100 for (i
= 0; i
< len
; i
++)
1103 hex_buffer
[2 * i
] = DIGITS
[(t
>> 4) & 0xf];
1104 hex_buffer
[2 * i
+ 1] = DIGITS
[t
& 0xf];
1107 gdb_put_packet(connection
, hex_buffer
, len
* 2);
1113 retval
= gdb_memory_packet_error(connection
, retval
);
1121 int gdb_write_memory_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1132 /* skip command character */
1135 addr
= strtoul(packet
, &separator
, 16);
1137 if (*separator
!= ',')
1139 ERROR("incomplete write memory packet received, dropping connection");
1140 return ERROR_SERVER_REMOTE_CLOSED
;
1143 len
= strtoul(separator
+1, &separator
, 16);
1145 if (*(separator
++) != ':')
1147 ERROR("incomplete write memory packet received, dropping connection");
1148 return ERROR_SERVER_REMOTE_CLOSED
;
1151 buffer
= malloc(len
);
1153 DEBUG("addr: 0x%8.8x, len: 0x%8.8x", addr
, len
);
1155 for (i
=0; i
<len
; i
++)
1158 sscanf(separator
+ 2*i
, "%2x", &tmp
);
1165 /* handle sized writes */
1167 if ((addr
% 4) == 0)
1168 retval
= target
->type
->write_memory(target
, addr
, 4, 1, buffer
);
1170 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
1173 if ((addr
% 2) == 0)
1174 retval
= target
->type
->write_memory(target
, addr
, 2, 1, buffer
);
1176 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
1180 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
1182 /* handle bulk writes */
1184 retval
= target_write_buffer(target
, addr
, len
, buffer
);
1188 if (retval
== ERROR_OK
)
1190 gdb_put_packet(connection
, "OK", 2);
1194 if ((retval
= gdb_memory_packet_error(connection
, retval
)) != ERROR_OK
)
1203 int gdb_write_memory_binary_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1212 /* skip command character */
1215 addr
= strtoul(packet
, &separator
, 16);
1217 if (*separator
!= ',')
1219 ERROR("incomplete write memory binary packet received, dropping connection");
1220 return ERROR_SERVER_REMOTE_CLOSED
;
1223 len
= strtoul(separator
+1, &separator
, 16);
1225 if (*(separator
++) != ':')
1227 ERROR("incomplete write memory binary packet received, dropping connection");
1228 return ERROR_SERVER_REMOTE_CLOSED
;
1234 buffer
= malloc(len
);
1236 DEBUG("addr: 0x%8.8x, len: 0x%8.8x", addr
, len
);
1238 memcpy( buffer
, separator
, len
);
1243 if ((addr
% 4) == 0)
1244 retval
= target
->type
->write_memory(target
, addr
, 4, 1, buffer
);
1246 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
1249 if ((addr
% 2) == 0)
1250 retval
= target
->type
->write_memory(target
, addr
, 2, 1, buffer
);
1252 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
1256 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
1259 retval
= target_write_buffer(target
, addr
, len
, buffer
);
1266 if (retval
== ERROR_OK
)
1268 gdb_put_packet(connection
, "OK", 2);
1272 if ((retval
= gdb_memory_packet_error(connection
, retval
)) != ERROR_OK
)
1279 void gdb_step_continue_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1286 if (packet_size
> 1)
1288 packet
[packet_size
] = 0;
1289 address
= strtoul(packet
+ 1, NULL
, 16);
1296 if (packet
[0] == 'c')
1299 target
->type
->resume(target
, current
, address
, 0, 0); /* resume at current address, don't handle breakpoints, not debugging */
1301 else if (packet
[0] == 's')
1304 target
->type
->step(target
, current
, address
, 0); /* step at current or address, don't handle breakpoints */
1308 int gdb_bp_wp_packet_error(connection_t
*connection
, int retval
)
1312 case ERROR_TARGET_NOT_HALTED
:
1313 ERROR("gdb tried to set a breakpoint but we're not halted, dropping connection");
1314 return ERROR_SERVER_REMOTE_CLOSED
;
1316 case ERROR_TARGET_RESOURCE_NOT_AVAILABLE
:
1317 gdb_send_error(connection
, EBUSY
);
1320 ERROR("BUG: unexpected error %i", retval
);
1327 int gdb_breakpoint_watchpoint_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1330 enum breakpoint_type bp_type
= BKPT_SOFT
/* dummy init to avoid warning */;
1331 enum watchpoint_rw wp_type
;
1339 type
= strtoul(packet
+ 1, &separator
, 16);
1341 if (type
== 0) /* memory breakpoint */
1342 bp_type
= BKPT_SOFT
;
1343 else if (type
== 1) /* hardware breakpoint */
1344 bp_type
= BKPT_HARD
;
1345 else if (type
== 2) /* write watchpoint */
1346 wp_type
= WPT_WRITE
;
1347 else if (type
== 3) /* read watchpoint */
1349 else if (type
== 4) /* access watchpoint */
1350 wp_type
= WPT_ACCESS
;
1352 if (*separator
!= ',')
1354 ERROR("incomplete breakpoint/watchpoint packet received, dropping connection");
1355 return ERROR_SERVER_REMOTE_CLOSED
;
1358 address
= strtoul(separator
+1, &separator
, 16);
1360 if (*separator
!= ',')
1362 ERROR("incomplete breakpoint/watchpoint packet received, dropping connection");
1363 return ERROR_SERVER_REMOTE_CLOSED
;
1366 size
= strtoul(separator
+1, &separator
, 16);
1372 if (packet
[0] == 'Z')
1374 if ((retval
= breakpoint_add(target
, address
, size
, bp_type
)) != ERROR_OK
)
1376 if ((retval
= gdb_bp_wp_packet_error(connection
, retval
)) != ERROR_OK
)
1381 gdb_put_packet(connection
, "OK", 2);
1386 breakpoint_remove(target
, address
);
1387 gdb_put_packet(connection
, "OK", 2);
1394 if (packet
[0] == 'Z')
1396 if ((retval
= watchpoint_add(target
, address
, size
, type
-2, 0, 0xffffffffu
)) != ERROR_OK
)
1398 if ((retval
= gdb_bp_wp_packet_error(connection
, retval
)) != ERROR_OK
)
1403 gdb_put_packet(connection
, "OK", 2);
1408 watchpoint_remove(target
, address
);
1409 gdb_put_packet(connection
, "OK", 2);
1420 /* print out a string and allocate more space as needed, mainly used for XML at this point */
1421 void xml_printf(int *retval
, char **xml
, int *pos
, int *size
, const char *fmt
, ...)
1423 if (*retval
!= ERROR_OK
)
1431 if ((*xml
== NULL
) || (!first
))
1433 /* start by 0 to exercise all the code paths.
1434 * Need minimum 2 bytes to fit 1 char and 0 terminator. */
1436 *size
= *size
* 2 + 2;
1438 *xml
= realloc(*xml
, *size
);
1443 *retval
= ERROR_SERVER_REMOTE_CLOSED
;
1451 ret
= vsnprintf(*xml
+ *pos
, *size
- *pos
, fmt
, ap
);
1453 if ((ret
> 0) && ((ret
+ 1) < *size
- *pos
))
1458 /* there was just enough or not enough space, allocate more. */
1463 static int decode_xfer_read (char *buf
, char **annex
, int *ofs
, unsigned int *len
)
1467 /* Extract and NUL-terminate the annex. */
1469 while (*buf
&& *buf
!= ':')
1475 /* After the read marker and annex, qXfer looks like a
1476 * traditional 'm' packet. */
1478 *ofs
= strtoul(buf
, &separator
, 16);
1480 if (*separator
!= ',')
1483 *len
= strtoul(separator
+1, NULL
, 16);
1488 int gdb_calc_blocksize(flash_bank_t
*bank
)
1491 int block_size
= 0xffffffff;
1493 /* loop through all sectors and return smallest sector size */
1495 for (i
= 0; i
< bank
->num_sectors
; i
++)
1497 if (bank
->sectors
[i
].size
< block_size
)
1498 block_size
= bank
->sectors
[i
].size
;
1504 int gdb_query_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1506 command_context_t
*cmd_ctx
= connection
->cmd_ctx
;
1508 if (strstr(packet
, "qRcmd,"))
1510 if (packet_size
> 6)
1514 cmd
= malloc((packet_size
- 6)/2 + 1);
1515 for (i
=0; i
< (packet_size
- 6)/2; i
++)
1518 sscanf(packet
+ 6 + 2*i
, "%2x", &tmp
);
1521 cmd
[(packet_size
- 6)/2] = 0x0;
1523 /* We want to print all debug output to GDB connection */
1524 log_setCallback(gdb_log_callback
, connection
);
1525 target_call_timer_callbacks();
1526 command_run_line(cmd_ctx
, cmd
);
1529 gdb_put_packet(connection
, "OK", 2);
1532 else if (strstr(packet
, "qCRC:"))
1534 if (packet_size
> 5)
1543 /* skip command character */
1546 addr
= strtoul(packet
, &separator
, 16);
1548 if (*separator
!= ',')
1550 ERROR("incomplete read memory packet received, dropping connection");
1551 return ERROR_SERVER_REMOTE_CLOSED
;
1554 len
= strtoul(separator
+ 1, NULL
, 16);
1556 retval
= target_checksum_memory(target
, addr
, len
, &checksum
);
1558 if (retval
== ERROR_OK
)
1560 snprintf(gdb_reply
, 10, "C%8.8x", checksum
);
1561 gdb_put_packet(connection
, gdb_reply
, 9);
1565 if ((retval
= gdb_memory_packet_error(connection
, retval
)) != ERROR_OK
)
1572 else if (strstr(packet
, "qSupported"))
1574 /* we currently support packet size and qXfer:memory-map:read (if enabled)
1575 * disable qXfer:features:read for the moment */
1576 int retval
= ERROR_OK
;
1577 char *buffer
= NULL
;
1581 xml_printf(&retval
, &buffer
, &pos
, &size
,
1582 "PacketSize=%x;qXfer:memory-map:read%c;qXfer:features:read-",
1583 (GDB_BUFFER_SIZE
- 1), gdb_use_memory_map
== 1 ? '+' : '-');
1585 if (retval
!= ERROR_OK
)
1587 gdb_send_error(connection
, 01);
1591 gdb_put_packet(connection
, buffer
, strlen(buffer
));
1596 else if (strstr(packet
, "qXfer:memory-map:read::"))
1598 /* We get away with only specifying flash here. Regions that are not
1599 * specified are treated as if we provided no memory map(if not we
1600 * could detect the holes and mark them as RAM).
1601 * Normally we only execute this code once, but no big deal if we
1602 * have to regenerate it a couple of times. */
1608 int retval
= ERROR_OK
;
1615 /* skip command character */
1618 offset
= strtoul(packet
, &separator
, 16);
1619 length
= strtoul(separator
+ 1, &separator
, 16);
1621 xml_printf(&retval
, &xml
, &pos
, &size
, "<memory-map>\n");
1626 p
= get_flash_bank_by_num(i
);
1630 /* if device has uneven sector sizes, eg. str7, lpc
1631 * we pass the smallest sector size to gdb memory map */
1632 blocksize
= gdb_calc_blocksize(p
);
1634 xml_printf(&retval
, &xml
, &pos
, &size
, "<memory type=\"flash\" start=\"0x%x\" length=\"0x%x\">\n" \
1635 "<property name=\"blocksize\">0x%x</property>\n" \
1637 p
->base
, p
->size
, blocksize
);
1641 xml_printf(&retval
, &xml
, &pos
, &size
, "</memory-map>\n");
1643 if (retval
!= ERROR_OK
)
1645 gdb_send_error(connection
, retval
);
1649 if (offset
+ length
> pos
)
1651 length
= pos
- offset
;
1654 char *t
= malloc(length
+ 1);
1656 memcpy(t
+ 1, xml
+ offset
, length
);
1657 gdb_put_packet(connection
, t
, length
+ 1);
1663 else if (strstr(packet
, "qXfer:features:read:"))
1668 int retval
= ERROR_OK
;
1674 /* skip command character */
1677 if (decode_xfer_read( packet
, &annex
, &offset
, &length
) < 0)
1679 gdb_send_error(connection
, 01);
1683 if (strcmp(annex
, "target.xml") != 0)
1685 gdb_send_error(connection
, 01);
1689 xml_printf(&retval
, &xml
, &pos
, &size
, \
1690 "l<target version=\"1.0\">\n<architecture>arm</architecture>\n</target>\n");
1692 if (retval
!= ERROR_OK
)
1694 gdb_send_error(connection
, retval
);
1698 gdb_put_packet(connection
, xml
, strlen(xml
) + 1);
1704 gdb_put_packet(connection
, "", 0);
1708 int gdb_v_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1710 gdb_connection_t
*gdb_connection
= connection
->priv
;
1711 gdb_service_t
*gdb_service
= connection
->service
->priv
;
1714 /* if flash programming disabled - send a empty reply */
1716 if (gdb_flash_program
== 0)
1718 gdb_put_packet(connection
, "", 0);
1722 if (strstr(packet
, "vFlashErase:"))
1725 unsigned long length
;
1727 char *parse
= packet
+ 12;
1730 ERROR("incomplete vFlashErase packet received, dropping connection");
1731 return ERROR_SERVER_REMOTE_CLOSED
;
1734 addr
= strtoul(parse
, &parse
, 16);
1736 if (*(parse
++) != ',' || *parse
== '\0')
1738 ERROR("incomplete vFlashErase packet received, dropping connection");
1739 return ERROR_SERVER_REMOTE_CLOSED
;
1742 length
= strtoul(parse
, &parse
, 16);
1746 ERROR("incomplete vFlashErase packet received, dropping connection");
1747 return ERROR_SERVER_REMOTE_CLOSED
;
1750 /* assume all sectors need erasing - stops any problems
1751 * when flash_write is called multiple times */
1754 /* perform any target specific operations before the erase */
1755 target_call_event_callbacks(gdb_service
->target
, TARGET_EVENT_GDB_PROGRAM
);
1758 if ((result
= flash_erase_address_range(gdb_service
->target
, addr
, length
)) != ERROR_OK
)
1760 /* GDB doesn't evaluate the actual error number returned,
1761 * treat a failed erase as an I/O error
1763 gdb_send_error(connection
, EIO
);
1764 ERROR("flash_erase returned %i", result
);
1767 gdb_put_packet(connection
, "OK", 2);
1772 if (strstr(packet
, "vFlashWrite:"))
1775 unsigned long length
;
1776 char *parse
= packet
+ 12;
1780 ERROR("incomplete vFlashErase packet received, dropping connection");
1781 return ERROR_SERVER_REMOTE_CLOSED
;
1783 addr
= strtoul(parse
, &parse
, 16);
1784 if (*(parse
++) != ':')
1786 ERROR("incomplete vFlashErase packet received, dropping connection");
1787 return ERROR_SERVER_REMOTE_CLOSED
;
1789 length
= packet_size
- (parse
- packet
);
1791 /* create a new image if there isn't already one */
1792 if (gdb_connection
->vflash_image
== NULL
)
1794 gdb_connection
->vflash_image
= malloc(sizeof(image_t
));
1795 image_open(gdb_connection
->vflash_image
, "", "build");
1798 /* create new section with content from packet buffer */
1799 image_add_section(gdb_connection
->vflash_image
, addr
, length
, 0x0, (u8
*)parse
);
1801 gdb_put_packet(connection
, "OK", 2);
1806 if (!strcmp(packet
, "vFlashDone"))
1811 /* process the flashing buffer. No need to erase as GDB
1812 * always issues a vFlashErase first. */
1813 if ((result
= flash_write(gdb_service
->target
, gdb_connection
->vflash_image
, &written
, &error_str
, NULL
, 0)) != ERROR_OK
)
1815 if (result
== ERROR_FLASH_DST_OUT_OF_BANK
)
1816 gdb_put_packet(connection
, "E.memtype", 9);
1818 gdb_send_error(connection
, EIO
);
1822 ERROR("flash writing failed: %s", error_str
);
1828 DEBUG("wrote %u bytes from vFlash image to flash", written
);
1829 gdb_put_packet(connection
, "OK", 2);
1832 image_close(gdb_connection
->vflash_image
);
1833 free(gdb_connection
->vflash_image
);
1834 gdb_connection
->vflash_image
= NULL
;
1839 gdb_put_packet(connection
, "", 0);
1843 int gdb_detach(connection_t
*connection
, target_t
*target
)
1845 switch( detach_mode
)
1847 case GDB_DETACH_RESUME
:
1848 target
->type
->resume(target
, 1, 0, 1, 0);
1851 case GDB_DETACH_RESET
:
1852 target_process_reset(connection
->cmd_ctx
);
1855 case GDB_DETACH_HALT
:
1856 target
->type
->halt(target
);
1859 case GDB_DETACH_NOTHING
:
1863 gdb_put_packet(connection
, "OK", 2);
1868 static void gdb_log_callback(void *priv
, const char *file
, int line
,
1869 const char *function
, const char *format
, va_list args
)
1871 connection_t
*connection
= priv
;
1872 gdb_connection_t
*gdb_con
= connection
->priv
;
1876 /* do not reply this using the O packet */
1880 char *t
= allocPrintf(format
, args
);
1884 gdb_output_con(connection
, t
);
1889 int gdb_input_inner(connection_t
*connection
)
1891 gdb_service_t
*gdb_service
= connection
->service
->priv
;
1892 target_t
*target
= gdb_service
->target
;
1893 char packet
[GDB_BUFFER_SIZE
];
1896 gdb_connection_t
*gdb_con
= connection
->priv
;
1897 static int extended_protocol
= 0;
1899 /* drain input buffer */
1902 packet_size
= GDB_BUFFER_SIZE
-1;
1903 if ((retval
= gdb_get_packet(connection
, packet
, &packet_size
)) != ERROR_OK
)
1908 /* terminate with zero */
1909 packet
[packet_size
] = 0;
1911 DEBUG("received packet: '%s'", packet
);
1913 if (packet_size
> 0)
1919 /* Hct... -- set thread
1920 * we don't have threads, send empty reply */
1921 gdb_put_packet(connection
, NULL
, 0);
1924 retval
= gdb_query_packet(connection
, target
, packet
, packet_size
);
1927 retval
= gdb_get_registers_packet(connection
, target
, packet
, packet_size
);
1930 retval
= gdb_set_registers_packet(connection
, target
, packet
, packet_size
);
1933 retval
= gdb_get_register_packet(connection
, target
, packet
, packet_size
);
1936 retval
= gdb_set_register_packet(connection
, target
, packet
, packet_size
);
1939 retval
= gdb_read_memory_packet(connection
, target
, packet
, packet_size
);
1942 retval
= gdb_write_memory_packet(connection
, target
, packet
, packet_size
);
1946 retval
= gdb_breakpoint_watchpoint_packet(connection
, target
, packet
, packet_size
);
1949 gdb_last_signal_packet(connection
, target
, packet
, packet_size
);
1954 /* We're running/stepping, in which case we can
1955 * forward log output until the target is halted */
1956 gdb_connection_t
*gdb_con
= connection
->priv
;
1957 gdb_con
->frontend_state
= TARGET_RUNNING
;
1958 log_setCallback(gdb_log_callback
, connection
);
1959 gdb_step_continue_packet(connection
, target
, packet
, packet_size
);
1963 retval
= gdb_v_packet(connection
, target
, packet
, packet_size
);
1966 retval
= gdb_detach(connection
, target
);
1967 extended_protocol
= 0;
1970 if ((retval
= gdb_write_memory_binary_packet(connection
, target
, packet
, packet_size
)) != ERROR_OK
)
1974 if (extended_protocol
!= 0)
1976 gdb_put_packet(connection
, "OK", 2);
1977 return ERROR_SERVER_REMOTE_CLOSED
;
1979 /* handle extended remote protocol */
1980 extended_protocol
= 1;
1981 gdb_put_packet(connection
, "OK", 2);
1984 /* handle extended restart packet */
1985 target_process_reset(connection
->cmd_ctx
);
1988 /* ignore unkown packets */
1989 DEBUG("ignoring 0x%2.2x packet", packet
[0]);
1990 gdb_put_packet(connection
, NULL
, 0);
1994 /* if a packet handler returned an error, exit input loop */
1995 if (retval
!= ERROR_OK
)
1999 if (gdb_con
->ctrl_c
)
2001 if (target
->state
== TARGET_RUNNING
)
2003 target
->type
->halt(target
);
2004 gdb_con
->ctrl_c
= 0;
2008 } while (gdb_con
->buf_cnt
> 0);
2013 int gdb_input(connection_t
*connection
)
2015 int retval
= gdb_input_inner(connection
);
2016 if (retval
== ERROR_SERVER_REMOTE_CLOSED
)
2018 /* we'll recover from any other errors(e.g. temporary timeouts, etc.) */
2024 gdb_service_t
*gdb_service
;
2025 target_t
*target
= targets
;
2030 WARNING("no gdb ports allocated as no target has been specified");
2036 WARNING("no gdb port specified, using default port 3333");
2042 char service_name
[8];
2044 snprintf(service_name
, 8, "gdb-%2.2i", i
);
2046 gdb_service
= malloc(sizeof(gdb_service_t
));
2047 gdb_service
->target
= target
;
2049 add_service("gdb", CONNECTION_GDB
, gdb_port
+ i
, 1, gdb_new_connection
, gdb_input
, gdb_connection_closed
, gdb_service
);
2051 DEBUG("gdb service for target %s at port %i", target
->type
->name
, gdb_port
+ i
);
2054 target
= target
->next
;
2060 /* daemon configuration command gdb_port */
2061 int handle_gdb_port_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2066 /* only if the port wasn't overwritten by cmdline */
2068 gdb_port
= strtoul(args
[0], NULL
, 0);
2073 int handle_gdb_detach_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2077 if (strcmp(args
[0], "resume") == 0)
2079 detach_mode
= GDB_DETACH_RESUME
;
2082 else if (strcmp(args
[0], "reset") == 0)
2084 detach_mode
= GDB_DETACH_RESET
;
2087 else if (strcmp(args
[0], "halt") == 0)
2089 detach_mode
= GDB_DETACH_HALT
;
2092 else if (strcmp(args
[0], "nothing") == 0)
2094 detach_mode
= GDB_DETACH_NOTHING
;
2099 WARNING("invalid gdb_detach configuration directive: %s", args
[0]);
2103 int handle_gdb_memory_map_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2107 if (strcmp(args
[0], "enable") == 0)
2109 gdb_use_memory_map
= 1;
2112 else if (strcmp(args
[0], "disable") == 0)
2114 gdb_use_memory_map
= 0;
2119 WARNING("invalid gdb_memory_map configuration directive: %s", args
[0]);
2123 int handle_gdb_flash_program_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2127 if (strcmp(args
[0], "enable") == 0)
2129 gdb_flash_program
= 1;
2132 else if (strcmp(args
[0], "disable") == 0)
2134 gdb_flash_program
= 0;
2139 WARNING("invalid gdb_memory_map configuration directive: %s", args
[0]);
2143 int gdb_register_commands(command_context_t
*command_context
)
2145 register_command(command_context
, NULL
, "gdb_port", handle_gdb_port_command
,
2146 COMMAND_CONFIG
, "");
2147 register_command(command_context
, NULL
, "gdb_detach", handle_gdb_detach_command
,
2148 COMMAND_CONFIG
, "");
2149 register_command(command_context
, NULL
, "gdb_memory_map", handle_gdb_memory_map_command
,
2150 COMMAND_CONFIG
, "");
2151 register_command(command_context
, NULL
, "gdb_flash_program", handle_gdb_flash_program_command
,
2152 COMMAND_CONFIG
, "");
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)