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"
35 #include "configuration.h"
43 #define _DEBUG_GDB_IO_
46 extern int gdb_error(connection_t
*connection
, int retval
);
47 static unsigned short gdb_port
;
48 static const char *DIGITS
= "0123456789abcdef";
50 static void gdb_log_callback(void *priv
, const char *file
, int line
,
51 const char *function
, const char *string
);
61 /* target behaviour on gdb detach */
62 enum gdb_detach_mode detach_mode
= GDB_DETACH_RESUME
;
64 /* set if we are sending a memory map to gdb
65 * via qXfer:memory-map:read packet */
66 /* enabled by default*/
67 int gdb_use_memory_map
= 1;
68 /* enabled by default*/
69 int gdb_flash_program
= 1;
71 /* if set, data aborts cause an error to be reported in memory read packets
72 * see the code in gdb_read_memory_packet() for further explanations */
73 int gdb_report_data_abort
= 0;
75 int gdb_last_signal(target_t
*target
)
77 switch (target
->debug_reason
)
79 case DBG_REASON_DBGRQ
:
80 return 0x2; /* SIGINT */
81 case DBG_REASON_BREAKPOINT
:
82 case DBG_REASON_WATCHPOINT
:
83 case DBG_REASON_WPTANDBKPT
:
84 return 0x05; /* SIGTRAP */
85 case DBG_REASON_SINGLESTEP
:
86 return 0x05; /* SIGTRAP */
87 case DBG_REASON_NOTHALTED
:
88 return 0x0; /* no signal... shouldn't happen */
90 LOG_USER("undefined debug reason %d - target needs reset", target
->debug_reason
);
95 int check_pending(connection_t
*connection
, int timeout_s
, int *got_data
)
97 /* a non-blocking socket will block if there is 0 bytes available on the socket,
98 * but return with as many bytes as are available immediately
102 gdb_connection_t
*gdb_con
= connection
->priv
;
108 if (gdb_con
->buf_cnt
>0)
115 FD_SET(connection
->fd
, &read_fds
);
117 tv
.tv_sec
= timeout_s
;
119 if (select(connection
->fd
+ 1, &read_fds
, NULL
, NULL
, &tv
) == 0)
121 /* This can typically be because a "monitor" command took too long
122 * before printing any progress messages
126 return ERROR_GDB_TIMEOUT
;
132 *got_data
=FD_ISSET(connection
->fd
, &read_fds
)!=0;
136 int gdb_get_char(connection_t
*connection
, int* next_char
)
138 gdb_connection_t
*gdb_con
= connection
->priv
;
141 #ifdef _DEBUG_GDB_IO_
145 if (gdb_con
->buf_cnt
-- > 0)
147 *next_char
= *(gdb_con
->buf_p
++);
148 if (gdb_con
->buf_cnt
> 0)
149 connection
->input_pending
= 1;
151 connection
->input_pending
= 0;
153 #ifdef _DEBUG_GDB_IO_
154 LOG_DEBUG("returned char '%c' (0x%2.2x)", *next_char
, *next_char
);
162 retval
=check_pending(connection
, 1, NULL
);
163 if (retval
!=ERROR_OK
)
165 gdb_con
->buf_cnt
= read_socket(connection
->fd
, gdb_con
->buffer
, GDB_BUFFER_SIZE
);
166 if (gdb_con
->buf_cnt
> 0)
170 if (gdb_con
->buf_cnt
== 0)
173 return ERROR_SERVER_REMOTE_CLOSED
;
177 errno
= WSAGetLastError();
184 case WSAECONNABORTED
:
186 return ERROR_SERVER_REMOTE_CLOSED
;
189 return ERROR_SERVER_REMOTE_CLOSED
;
191 LOG_ERROR("read: %d", errno
);
202 return ERROR_SERVER_REMOTE_CLOSED
;
205 return ERROR_SERVER_REMOTE_CLOSED
;
207 LOG_ERROR("read: %s", strerror(errno
));
209 return ERROR_SERVER_REMOTE_CLOSED
;
214 #ifdef _DEBUG_GDB_IO_
215 debug_buffer
= malloc(gdb_con
->buf_cnt
+ 1);
216 memcpy(debug_buffer
, gdb_con
->buffer
, gdb_con
->buf_cnt
);
217 debug_buffer
[gdb_con
->buf_cnt
] = 0;
218 LOG_DEBUG("received '%s'", debug_buffer
);
222 gdb_con
->buf_p
= gdb_con
->buffer
;
224 *next_char
= *(gdb_con
->buf_p
++);
225 if (gdb_con
->buf_cnt
> 0)
226 connection
->input_pending
= 1;
228 connection
->input_pending
= 0;
229 #ifdef _DEBUG_GDB_IO_
230 LOG_DEBUG("returned char '%c' (0x%2.2x)", *next_char
, *next_char
);
236 int gdb_putback_char(connection_t
*connection
, int last_char
)
238 gdb_connection_t
*gdb_con
= connection
->priv
;
240 if (gdb_con
->buf_p
> gdb_con
->buffer
)
242 *(--gdb_con
->buf_p
) = last_char
;
247 LOG_ERROR("BUG: couldn't put character back");
253 /* The only way we can detect that the socket is closed is the first time
254 * we write to it, we will fail. Subsequent write operations will
255 * succeed. Shudder! */
256 int gdb_write(connection_t
*connection
, void *data
, int len
)
258 gdb_connection_t
*gdb_con
= connection
->priv
;
260 return ERROR_SERVER_REMOTE_CLOSED
;
262 if (write_socket(connection
->fd
, data
, len
) == len
)
267 return ERROR_SERVER_REMOTE_CLOSED
;
270 int gdb_put_packet_inner(connection_t
*connection
, char *buffer
, int len
)
273 unsigned char my_checksum
= 0;
274 #ifdef _DEBUG_GDB_IO_
279 gdb_connection_t
*gdb_con
= connection
->priv
;
281 for (i
= 0; i
< len
; i
++)
282 my_checksum
+= buffer
[i
];
284 #ifdef _DEBUG_GDB_IO_
286 * At this point we should have nothing in the input queue from GDB,
287 * however sometimes '-' is sent even though we've already received
288 * an ACK (+) for everything we've sent off.
294 if ((retval
=check_pending(connection
, 0, &gotdata
))!=ERROR_OK
)
298 if ((retval
= gdb_get_char(connection
, &reply
)) != ERROR_OK
)
300 LOG_WARNING("Discard unexpected char %c", reply
);
307 #ifdef _DEBUG_GDB_IO_
308 debug_buffer
= malloc(len
+ 1);
309 memcpy(debug_buffer
, buffer
, len
);
310 debug_buffer
[len
] = 0;
311 LOG_DEBUG("sending packet '$%s#%2.2x'", debug_buffer
, my_checksum
);
315 char local_buffer
[1024];
316 local_buffer
[0] = '$';
317 if (len
+4 <= sizeof(local_buffer
))
319 /* performance gain on smaller packets by only a single call to gdb_write() */
320 memcpy(local_buffer
+1, buffer
, len
++);
321 local_buffer
[len
++] = '#';
322 local_buffer
[len
++] = DIGITS
[(my_checksum
>> 4) & 0xf];
323 local_buffer
[len
++] = DIGITS
[my_checksum
& 0xf];
324 gdb_write(connection
, local_buffer
, len
);
328 /* larger packets are transmitted directly from caller supplied buffer
329 by several calls to gdb_write() to avoid dynamic allocation */
330 local_buffer
[1] = '#';
331 local_buffer
[2] = DIGITS
[(my_checksum
>> 4) & 0xf];
332 local_buffer
[3] = DIGITS
[my_checksum
& 0xf];
333 gdb_write(connection
, local_buffer
, 1);
334 gdb_write(connection
, buffer
, len
);
335 gdb_write(connection
, local_buffer
+1, 3);
338 if ((retval
= gdb_get_char(connection
, &reply
)) != ERROR_OK
)
343 else if (reply
== '-')
345 /* Stop sending output packets for now */
346 log_remove_callback(gdb_log_callback
, connection
);
347 LOG_WARNING("negative reply, retrying");
349 else if (reply
== 0x3)
352 if ((retval
= gdb_get_char(connection
, &reply
)) != ERROR_OK
)
356 else if (reply
== '-')
358 /* Stop sending output packets for now */
359 log_remove_callback(gdb_log_callback
, connection
);
360 LOG_WARNING("negative reply, retrying");
364 LOG_ERROR("unknown character 0x%2.2x in reply, dropping connection", reply
);
366 return ERROR_SERVER_REMOTE_CLOSED
;
371 LOG_ERROR("unknown character 0x%2.2x in reply, dropping connection", reply
);
373 return ERROR_SERVER_REMOTE_CLOSED
;
377 return ERROR_SERVER_REMOTE_CLOSED
;
382 int gdb_put_packet(connection_t
*connection
, char *buffer
, int len
)
384 gdb_connection_t
*gdb_con
= connection
->priv
;
386 int retval
= gdb_put_packet_inner(connection
, buffer
, len
);
391 int gdb_get_packet_inner(connection_t
*connection
, char *buffer
, int *len
)
397 unsigned char my_checksum
= 0;
398 gdb_connection_t
*gdb_con
= connection
->priv
;
404 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
407 #ifdef _DEBUG_GDB_IO_
408 LOG_DEBUG("character: '%c'", character
);
416 LOG_WARNING("acknowledgment received, but no packet pending");
419 LOG_WARNING("negative acknowledgment, but no packet pending");
426 LOG_WARNING("ignoring character 0x%x", character
);
429 } while (character
!= '$');
434 gdb_connection_t
*gdb_con
= connection
->priv
;
437 /* The common case is that we have an entire packet with no escape chars.
438 * We need to leave at least 2 bytes in the buffer to have
439 * gdb_get_char() update various bits and bobs correctly.
441 if ((gdb_con
->buf_cnt
> 2) && ((gdb_con
->buf_cnt
+count
) < *len
))
443 /* The compiler will struggle a bit with constant propagation and
444 * aliasing, so we help it by showing that these values do not
445 * change inside the loop
448 char *buf
= gdb_con
->buf_p
;
449 int run
= gdb_con
->buf_cnt
- 2;
456 if (character
== '#')
458 /* Danger! character can be '#' when esc is
459 * used so we need an explicit boolean for done here.
465 if (character
== '}')
467 /* data transmitted in binary mode (X packet)
468 * uses 0x7d as escape character */
469 my_checksum
+= character
& 0xff;
472 my_checksum
+= character
& 0xff;
473 buffer
[count
++] = (character
^ 0x20) & 0xff;
476 my_checksum
+= character
& 0xff;
477 buffer
[count
++] = character
& 0xff;
481 gdb_con
->buf_cnt
-= i
;
487 LOG_ERROR("packet buffer too small");
488 return ERROR_GDB_BUFFER_TOO_SMALL
;
491 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
494 if (character
== '#')
497 if (character
== '}')
499 /* data transmitted in binary mode (X packet)
500 * uses 0x7d as escape character */
501 my_checksum
+= character
& 0xff;
502 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
504 my_checksum
+= character
& 0xff;
505 buffer
[count
++] = (character
^ 0x20) & 0xff;
509 my_checksum
+= character
& 0xff;
510 buffer
[count
++] = character
& 0xff;
517 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
519 checksum
[0] = character
;
520 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
522 checksum
[1] = character
;
525 if (my_checksum
== strtoul(checksum
, NULL
, 16))
527 gdb_write(connection
, "+", 1);
531 LOG_WARNING("checksum error, requesting retransmission");
532 gdb_write(connection
, "-", 1);
535 return ERROR_SERVER_REMOTE_CLOSED
;
540 int gdb_get_packet(connection_t
*connection
, char *buffer
, int *len
)
542 gdb_connection_t
*gdb_con
= connection
->priv
;
544 int retval
= gdb_get_packet_inner(connection
, buffer
, len
);
549 int gdb_output_con(connection_t
*connection
, const char* line
)
554 bin_size
= strlen(line
);
556 hex_buffer
= malloc(bin_size
*2 + 2);
557 if (hex_buffer
== NULL
)
558 return ERROR_GDB_BUFFER_TOO_SMALL
;
561 for (i
=0; i
<bin_size
; i
++)
562 snprintf(hex_buffer
+ 1 + i
*2, 3, "%2.2x", line
[i
]);
563 hex_buffer
[bin_size
*2+1] = 0;
565 gdb_put_packet(connection
, hex_buffer
, bin_size
*2 + 1);
571 int gdb_output(struct command_context_s
*context
, char* line
)
573 /* this will be dumped to the log and also sent as an O packet if possible */
574 LOG_USER_N("%s", line
);
578 int gdb_program_handler(struct target_s
*target
, enum target_event event
, void *priv
)
581 struct command_context_s
*cmd_ctx
= priv
;
583 if (target
->gdb_program_script
)
585 script
= open_file_from_path(target
->gdb_program_script
, "r");
588 LOG_ERROR("couldn't open script file %s", target
->gdb_program_script
);
592 LOG_INFO("executing gdb_program script '%s'", target
->gdb_program_script
);
593 command_run_file(cmd_ctx
, script
, COMMAND_EXEC
);
596 jtag_execute_queue();
602 int gdb_target_callback_event_handler(struct target_s
*target
, enum target_event event
, void *priv
)
604 connection_t
*connection
= priv
;
605 gdb_connection_t
*gdb_connection
= connection
->priv
;
611 case TARGET_EVENT_HALTED
:
612 /* In the GDB protocol when we are stepping or coninuing execution,
613 * we have a lingering reply. Upon receiving a halted event
614 * when we have that lingering packet, we reply to the original
615 * step or continue packet.
617 * Executing monitor commands can bring the target in and
618 * out of the running state so we'll see lots of TARGET_EVENT_XXX
619 * that are to be ignored.
621 if (gdb_connection
->frontend_state
== TARGET_RUNNING
)
623 /* stop forwarding log packets! */
624 log_remove_callback(gdb_log_callback
, connection
);
626 if (gdb_connection
->ctrl_c
)
629 gdb_connection
->ctrl_c
= 0;
633 signal
= gdb_last_signal(target
);
636 snprintf(sig_reply
, 4, "T%2.2x", signal
);
637 gdb_put_packet(connection
, sig_reply
, 3);
638 gdb_connection
->frontend_state
= TARGET_HALTED
;
641 case TARGET_EVENT_GDB_PROGRAM
:
642 gdb_program_handler(target
, event
, connection
->cmd_ctx
);
652 int gdb_new_connection(connection_t
*connection
)
654 gdb_connection_t
*gdb_connection
= malloc(sizeof(gdb_connection_t
));
655 gdb_service_t
*gdb_service
= connection
->service
->priv
;
659 connection
->priv
= gdb_connection
;
661 /* initialize gdb connection information */
662 gdb_connection
->buf_p
= gdb_connection
->buffer
;
663 gdb_connection
->buf_cnt
= 0;
664 gdb_connection
->ctrl_c
= 0;
665 gdb_connection
->frontend_state
= TARGET_HALTED
;
666 gdb_connection
->vflash_image
= NULL
;
667 gdb_connection
->closed
= 0;
668 gdb_connection
->busy
= 0;
670 /* send ACK to GDB for debug request */
671 gdb_write(connection
, "+", 1);
673 /* output goes through gdb connection */
674 command_set_output_handler(connection
->cmd_ctx
, gdb_output
, connection
);
676 /* register callback to be informed about target events */
677 target_register_event_callback(gdb_target_callback_event_handler
, connection
);
679 /* a gdb session just attached, try to put the target in halt mode.
683 * If the halt fails(e.g. target needs a reset, JTAG communication not
684 * working, etc.), then the GDB connect will succeed as
685 * the get_gdb_reg_list() will lie and return a register list with
688 * This allows GDB monitor commands to be run from a GDB init script to
689 * initialize the target
691 * Also, since the halt() is asynchronous target connect will be
692 * instantaneous and thus avoiding annoying timeout problems during
695 target_halt(gdb_service
->target
);
697 /* remove the initial ACK from the incoming buffer */
698 if ((retval
= gdb_get_char(connection
, &initial_ack
)) != ERROR_OK
)
701 /* FIX!!!??? would we actually ever receive a + here???
704 if (initial_ack
!= '+')
705 gdb_putback_char(connection
, initial_ack
);
710 int gdb_connection_closed(connection_t
*connection
)
712 gdb_service_t
*gdb_service
= connection
->service
->priv
;
713 gdb_connection_t
*gdb_connection
= connection
->priv
;
715 /* see if an image built with vFlash commands is left */
716 if (gdb_connection
->vflash_image
)
718 image_close(gdb_connection
->vflash_image
);
719 free(gdb_connection
->vflash_image
);
720 gdb_connection
->vflash_image
= NULL
;
723 /* if this connection registered a debug-message receiver delete it */
724 delete_debug_msg_receiver(connection
->cmd_ctx
, gdb_service
->target
);
726 if (connection
->priv
)
728 free(connection
->priv
);
729 connection
->priv
= NULL
;
733 LOG_ERROR("BUG: connection->priv == NULL");
736 target_unregister_event_callback(gdb_target_callback_event_handler
, connection
);
737 log_remove_callback(gdb_log_callback
, connection
);
742 void gdb_send_error(connection_t
*connection
, u8 the_error
)
745 snprintf(err
, 4, "E%2.2X", the_error
);
746 gdb_put_packet(connection
, err
, 3);
749 int gdb_last_signal_packet(connection_t
*connection
, target_t
*target
, char* packet
, int packet_size
)
754 signal
= gdb_last_signal(target
);
756 snprintf(sig_reply
, 4, "S%2.2x", signal
);
757 gdb_put_packet(connection
, sig_reply
, 3);
762 /* Convert register to string of bits. NB! The # of bits in the
763 * register might be non-divisible by 8(a byte), in which
764 * case an entire byte is shown. */
765 void gdb_str_to_target(target_t
*target
, char *tstr
, reg_t
*reg
)
772 buf_len
= CEIL(reg
->size
, 8);
774 for (i
= 0; i
< buf_len
; i
++)
776 tstr
[i
*2] = DIGITS
[(buf
[i
]>>4) & 0xf];
777 tstr
[i
*2+1] = DIGITS
[buf
[i
]&0xf];
781 void gdb_target_to_str(target_t
*target
, char *tstr
, char *str
)
783 int str_len
= strlen(tstr
);
788 LOG_ERROR("BUG: gdb value with uneven number of characters encountered");
792 for (i
= 0; i
< str_len
; i
+=2)
794 str
[str_len
- i
- 1] = tstr
[i
+ 1];
795 str
[str_len
- i
- 2] = tstr
[i
];
799 int gdb_get_registers_packet(connection_t
*connection
, target_t
*target
, char* packet
, int packet_size
)
804 int reg_packet_size
= 0;
809 #ifdef _DEBUG_GDB_IO_
813 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
815 return gdb_error(connection
, retval
);
818 for (i
= 0; i
< reg_list_size
; i
++)
820 reg_packet_size
+= reg_list
[i
]->size
;
823 reg_packet
= malloc(CEIL(reg_packet_size
, 8) * 2);
824 reg_packet_p
= reg_packet
;
826 for (i
= 0; i
< reg_list_size
; i
++)
828 gdb_str_to_target(target
, reg_packet_p
, reg_list
[i
]);
829 reg_packet_p
+= CEIL(reg_list
[i
]->size
, 8) * 2;
832 #ifdef _DEBUG_GDB_IO_
835 reg_packet_p
= strndup(reg_packet
, CEIL(reg_packet_size
, 8) * 2);
836 LOG_DEBUG("reg_packet: %s", reg_packet_p
);
841 gdb_put_packet(connection
, reg_packet
, CEIL(reg_packet_size
, 8) * 2);
849 int gdb_set_registers_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
857 #ifdef _DEBUG_GDB_IO_
861 /* skip command character */
867 LOG_WARNING("GDB set_registers packet with uneven characters received, dropping connection");
868 return ERROR_SERVER_REMOTE_CLOSED
;
871 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
873 return gdb_error(connection
, retval
);
877 for (i
= 0; i
< reg_list_size
; i
++)
881 reg_arch_type_t
*arch_type
;
883 /* convert from GDB-string (target-endian) to hex-string (big-endian) */
884 hex_buf
= malloc(CEIL(reg_list
[i
]->size
, 8) * 2);
885 gdb_target_to_str(target
, packet_p
, hex_buf
);
887 /* convert hex-string to binary buffer */
888 bin_buf
= malloc(CEIL(reg_list
[i
]->size
, 8));
889 str_to_buf(hex_buf
, CEIL(reg_list
[i
]->size
, 8) * 2, bin_buf
, reg_list
[i
]->size
, 16);
891 /* get register arch_type, and call set method */
892 arch_type
= register_get_arch_type(reg_list
[i
]->arch_type
);
893 if (arch_type
== NULL
)
895 LOG_ERROR("BUG: encountered unregistered arch type");
898 arch_type
->set(reg_list
[i
], bin_buf
);
900 /* advance packet pointer */
901 packet_p
+= (CEIL(reg_list
[i
]->size
, 8) * 2);
907 /* free reg_t *reg_list[] array allocated by get_gdb_reg_list */
910 gdb_put_packet(connection
, "OK", 2);
915 int gdb_get_register_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
918 int reg_num
= strtoul(packet
+ 1, NULL
, 16);
923 #ifdef _DEBUG_GDB_IO_
927 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
929 return gdb_error(connection
, retval
);
932 if (reg_list_size
<= reg_num
)
934 LOG_ERROR("gdb requested a non-existing register");
938 reg_packet
= malloc(CEIL(reg_list
[reg_num
]->size
, 8) * 2);
940 gdb_str_to_target(target
, reg_packet
, reg_list
[reg_num
]);
942 gdb_put_packet(connection
, reg_packet
, CEIL(reg_list
[reg_num
]->size
, 8) * 2);
950 int gdb_set_register_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
955 int reg_num
= strtoul(packet
+ 1, &separator
, 16);
959 reg_arch_type_t
*arch_type
;
963 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
965 return gdb_error(connection
, retval
);
968 if (reg_list_size
< reg_num
)
970 LOG_ERROR("gdb requested a non-existing register");
971 return ERROR_SERVER_REMOTE_CLOSED
;
974 if (*separator
!= '=')
976 LOG_ERROR("GDB 'set register packet', but no '=' following the register number");
977 return ERROR_SERVER_REMOTE_CLOSED
;
980 /* convert from GDB-string (target-endian) to hex-string (big-endian) */
981 hex_buf
= malloc(CEIL(reg_list
[reg_num
]->size
, 8) * 2);
982 gdb_target_to_str(target
, separator
+ 1, hex_buf
);
984 /* convert hex-string to binary buffer */
985 bin_buf
= malloc(CEIL(reg_list
[reg_num
]->size
, 8));
986 str_to_buf(hex_buf
, CEIL(reg_list
[reg_num
]->size
, 8) * 2, bin_buf
, reg_list
[reg_num
]->size
, 16);
988 /* get register arch_type, and call set method */
989 arch_type
= register_get_arch_type(reg_list
[reg_num
]->arch_type
);
990 if (arch_type
== NULL
)
992 LOG_ERROR("BUG: encountered unregistered arch type");
995 arch_type
->set(reg_list
[reg_num
], bin_buf
);
997 gdb_put_packet(connection
, "OK", 2);
1006 int gdb_error(connection_t
*connection
, int retval
)
1010 case ERROR_TARGET_DATA_ABORT
:
1011 gdb_send_error(connection
, EIO
);
1013 case ERROR_TARGET_TRANSLATION_FAULT
:
1014 gdb_send_error(connection
, EFAULT
);
1016 case ERROR_TARGET_UNALIGNED_ACCESS
:
1017 gdb_send_error(connection
, EFAULT
);
1019 case ERROR_TARGET_NOT_HALTED
:
1020 gdb_send_error(connection
, EFAULT
);
1023 /* This could be that the target reset itself. */
1024 LOG_ERROR("unexpected error %i", retval
);
1025 gdb_send_error(connection
, EFAULT
);
1032 /* We don't have to worry about the default 2 second timeout for GDB packets,
1033 * because GDB breaks up large memory reads into smaller reads.
1035 * 8191 bytes by the looks of it. Why 8191 bytes instead of 8192?????
1037 int gdb_read_memory_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1046 int retval
= ERROR_OK
;
1048 /* skip command character */
1051 addr
= strtoul(packet
, &separator
, 16);
1053 if (*separator
!= ',')
1055 LOG_ERROR("incomplete read memory packet received, dropping connection");
1056 return ERROR_SERVER_REMOTE_CLOSED
;
1059 len
= strtoul(separator
+1, NULL
, 16);
1061 buffer
= malloc(len
);
1063 LOG_DEBUG("addr: 0x%8.8x, len: 0x%8.8x", addr
, len
);
1065 retval
= target_read_buffer(target
, addr
, len
, buffer
);
1067 if ((retval
== ERROR_TARGET_DATA_ABORT
) && (!gdb_report_data_abort
))
1069 /* TODO : Here we have to lie and send back all zero's lest stack traces won't work.
1070 * At some point this might be fixed in GDB, in which case this code can be removed.
1072 * OpenOCD developers are acutely aware of this problem, but there is nothing
1073 * gained by involving the user in this problem that hopefully will get resolved
1076 * http://sourceware.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gdb&pr=2395
1078 * For now, the default is to fix up things to make current GDB versions work.
1079 * This can be overwritten using the gdb_report_data_abort <'enable'|'disable'> command.
1081 memset(buffer
, 0, len
);
1085 if (retval
== ERROR_OK
)
1087 hex_buffer
= malloc(len
* 2 + 1);
1090 for (i
= 0; i
< len
; i
++)
1093 hex_buffer
[2 * i
] = DIGITS
[(t
>> 4) & 0xf];
1094 hex_buffer
[2 * i
+ 1] = DIGITS
[t
& 0xf];
1097 gdb_put_packet(connection
, hex_buffer
, len
* 2);
1103 retval
= gdb_error(connection
, retval
);
1111 int gdb_write_memory_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1122 /* skip command character */
1125 addr
= strtoul(packet
, &separator
, 16);
1127 if (*separator
!= ',')
1129 LOG_ERROR("incomplete write memory packet received, dropping connection");
1130 return ERROR_SERVER_REMOTE_CLOSED
;
1133 len
= strtoul(separator
+1, &separator
, 16);
1135 if (*(separator
++) != ':')
1137 LOG_ERROR("incomplete write memory packet received, dropping connection");
1138 return ERROR_SERVER_REMOTE_CLOSED
;
1141 buffer
= malloc(len
);
1143 LOG_DEBUG("addr: 0x%8.8x, len: 0x%8.8x", addr
, len
);
1145 for (i
=0; i
<len
; i
++)
1148 sscanf(separator
+ 2*i
, "%2x", &tmp
);
1152 retval
= target_write_buffer(target
, addr
, len
, buffer
);
1154 if (retval
== ERROR_OK
)
1156 gdb_put_packet(connection
, "OK", 2);
1160 retval
= gdb_error(connection
, retval
);
1168 int gdb_write_memory_binary_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1176 /* skip command character */
1179 addr
= strtoul(packet
, &separator
, 16);
1181 if (*separator
!= ',')
1183 LOG_ERROR("incomplete write memory binary packet received, dropping connection");
1184 return ERROR_SERVER_REMOTE_CLOSED
;
1187 len
= strtoul(separator
+1, &separator
, 16);
1189 if (*(separator
++) != ':')
1191 LOG_ERROR("incomplete write memory binary packet received, dropping connection");
1192 return ERROR_SERVER_REMOTE_CLOSED
;
1198 LOG_DEBUG("addr: 0x%8.8x, len: 0x%8.8x", addr
, len
);
1200 retval
= target_write_buffer(target
, addr
, len
, (u8
*)separator
);
1203 if (retval
== ERROR_OK
)
1205 gdb_put_packet(connection
, "OK", 2);
1209 if ((retval
= gdb_error(connection
, retval
)) != ERROR_OK
)
1216 void gdb_step_continue_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1223 if (packet_size
> 1)
1225 packet
[packet_size
] = 0;
1226 address
= strtoul(packet
+ 1, NULL
, 16);
1233 if (packet
[0] == 'c')
1235 LOG_DEBUG("continue");
1236 target_resume(target
, current
, address
, 0, 0); /* resume at current address, don't handle breakpoints, not debugging */
1238 else if (packet
[0] == 's')
1241 target
->type
->step(target
, current
, address
, 0); /* step at current or address, don't handle breakpoints */
1245 int gdb_breakpoint_watchpoint_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1248 enum breakpoint_type bp_type
= BKPT_SOFT
/* dummy init to avoid warning */;
1249 enum watchpoint_rw wp_type
;
1257 type
= strtoul(packet
+ 1, &separator
, 16);
1259 if (type
== 0) /* memory breakpoint */
1260 bp_type
= BKPT_SOFT
;
1261 else if (type
== 1) /* hardware breakpoint */
1262 bp_type
= BKPT_HARD
;
1263 else if (type
== 2) /* write watchpoint */
1264 wp_type
= WPT_WRITE
;
1265 else if (type
== 3) /* read watchpoint */
1267 else if (type
== 4) /* access watchpoint */
1268 wp_type
= WPT_ACCESS
;
1270 if (*separator
!= ',')
1272 LOG_ERROR("incomplete breakpoint/watchpoint packet received, dropping connection");
1273 return ERROR_SERVER_REMOTE_CLOSED
;
1276 address
= strtoul(separator
+1, &separator
, 16);
1278 if (*separator
!= ',')
1280 LOG_ERROR("incomplete breakpoint/watchpoint packet received, dropping connection");
1281 return ERROR_SERVER_REMOTE_CLOSED
;
1284 size
= strtoul(separator
+1, &separator
, 16);
1290 if (packet
[0] == 'Z')
1292 if ((retval
= breakpoint_add(target
, address
, size
, bp_type
)) != ERROR_OK
)
1294 if ((retval
= gdb_error(connection
, retval
)) != ERROR_OK
)
1299 gdb_put_packet(connection
, "OK", 2);
1304 breakpoint_remove(target
, address
);
1305 gdb_put_packet(connection
, "OK", 2);
1312 if (packet
[0] == 'Z')
1314 if ((retval
= watchpoint_add(target
, address
, size
, type
-2, 0, 0xffffffffu
)) != ERROR_OK
)
1316 if ((retval
= gdb_error(connection
, retval
)) != ERROR_OK
)
1321 gdb_put_packet(connection
, "OK", 2);
1326 watchpoint_remove(target
, address
);
1327 gdb_put_packet(connection
, "OK", 2);
1338 /* print out a string and allocate more space as needed, mainly used for XML at this point */
1339 void xml_printf(int *retval
, char **xml
, int *pos
, int *size
, const char *fmt
, ...)
1341 if (*retval
!= ERROR_OK
)
1349 if ((*xml
== NULL
) || (!first
))
1351 /* start by 0 to exercise all the code paths.
1352 * Need minimum 2 bytes to fit 1 char and 0 terminator. */
1354 *size
= *size
* 2 + 2;
1356 *xml
= realloc(*xml
, *size
);
1361 *retval
= ERROR_SERVER_REMOTE_CLOSED
;
1369 ret
= vsnprintf(*xml
+ *pos
, *size
- *pos
, fmt
, ap
);
1371 if ((ret
> 0) && ((ret
+ 1) < *size
- *pos
))
1376 /* there was just enough or not enough space, allocate more. */
1381 static int decode_xfer_read(char *buf
, char **annex
, int *ofs
, unsigned int *len
)
1385 /* Extract and NUL-terminate the annex. */
1387 while (*buf
&& *buf
!= ':')
1393 /* After the read marker and annex, qXfer looks like a
1394 * traditional 'm' packet. */
1396 *ofs
= strtoul(buf
, &separator
, 16);
1398 if (*separator
!= ',')
1401 *len
= strtoul(separator
+1, NULL
, 16);
1406 int gdb_calc_blocksize(flash_bank_t
*bank
)
1409 int block_size
= 0xffffffff;
1411 /* loop through all sectors and return smallest sector size */
1413 for (i
= 0; i
< bank
->num_sectors
; i
++)
1415 if (bank
->sectors
[i
].size
< block_size
)
1416 block_size
= bank
->sectors
[i
].size
;
1422 int gdb_query_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1424 command_context_t
*cmd_ctx
= connection
->cmd_ctx
;
1426 if (strstr(packet
, "qRcmd,"))
1428 if (packet_size
> 6)
1432 cmd
= malloc((packet_size
- 6)/2 + 1);
1433 for (i
=0; i
< (packet_size
- 6)/2; i
++)
1436 sscanf(packet
+ 6 + 2*i
, "%2x", &tmp
);
1439 cmd
[(packet_size
- 6)/2] = 0x0;
1441 /* We want to print all debug output to GDB connection */
1442 log_add_callback(gdb_log_callback
, connection
);
1443 target_call_timer_callbacks_now();
1444 command_run_line(cmd_ctx
, cmd
);
1445 target_call_timer_callbacks_now();
1446 log_remove_callback(gdb_log_callback
, connection
);
1449 gdb_put_packet(connection
, "OK", 2);
1452 else if (strstr(packet
, "qCRC:"))
1454 if (packet_size
> 5)
1463 /* skip command character */
1466 addr
= strtoul(packet
, &separator
, 16);
1468 if (*separator
!= ',')
1470 LOG_ERROR("incomplete read memory packet received, dropping connection");
1471 return ERROR_SERVER_REMOTE_CLOSED
;
1474 len
= strtoul(separator
+ 1, NULL
, 16);
1476 retval
= target_checksum_memory(target
, addr
, len
, &checksum
);
1478 if (retval
== ERROR_OK
)
1480 snprintf(gdb_reply
, 10, "C%8.8x", checksum
);
1481 gdb_put_packet(connection
, gdb_reply
, 9);
1485 if ((retval
= gdb_error(connection
, retval
)) != ERROR_OK
)
1492 else if (strstr(packet
, "qSupported"))
1494 /* we currently support packet size and qXfer:memory-map:read (if enabled)
1495 * disable qXfer:features:read for the moment */
1496 int retval
= ERROR_OK
;
1497 char *buffer
= NULL
;
1501 xml_printf(&retval
, &buffer
, &pos
, &size
,
1502 "PacketSize=%x;qXfer:memory-map:read%c;qXfer:features:read-",
1503 (GDB_BUFFER_SIZE
- 1), gdb_use_memory_map
== 1 ? '+' : '-');
1505 if (retval
!= ERROR_OK
)
1507 gdb_send_error(connection
, 01);
1511 gdb_put_packet(connection
, buffer
, strlen(buffer
));
1516 else if (strstr(packet
, "qXfer:memory-map:read::"))
1518 /* We get away with only specifying flash here. Regions that are not
1519 * specified are treated as if we provided no memory map(if not we
1520 * could detect the holes and mark them as RAM).
1521 * Normally we only execute this code once, but no big deal if we
1522 * have to regenerate it a couple of times. */
1528 int retval
= ERROR_OK
;
1535 /* skip command character */
1538 offset
= strtoul(packet
, &separator
, 16);
1539 length
= strtoul(separator
+ 1, &separator
, 16);
1541 xml_printf(&retval
, &xml
, &pos
, &size
, "<memory-map>\n");
1544 for (i
=0; i
<flash_get_bank_count(); i
++)
1546 p
= get_flash_bank_by_num(i
);
1550 /* if device has uneven sector sizes, eg. str7, lpc
1551 * we pass the smallest sector size to gdb memory map */
1552 blocksize
= gdb_calc_blocksize(p
);
1554 xml_printf(&retval
, &xml
, &pos
, &size
, "<memory type=\"flash\" start=\"0x%x\" length=\"0x%x\">\n" \
1555 "<property name=\"blocksize\">0x%x</property>\n" \
1557 p
->base
, p
->size
, blocksize
);
1560 xml_printf(&retval
, &xml
, &pos
, &size
, "</memory-map>\n");
1562 if (retval
!= ERROR_OK
)
1564 gdb_send_error(connection
, retval
);
1568 if (offset
+ length
> pos
)
1570 length
= pos
- offset
;
1573 char *t
= malloc(length
+ 1);
1575 memcpy(t
+ 1, xml
+ offset
, length
);
1576 gdb_put_packet(connection
, t
, length
+ 1);
1582 else if (strstr(packet
, "qXfer:features:read:"))
1587 int retval
= ERROR_OK
;
1590 unsigned int length
;
1593 /* skip command character */
1596 if (decode_xfer_read(packet
, &annex
, &offset
, &length
) < 0)
1598 gdb_send_error(connection
, 01);
1602 if (strcmp(annex
, "target.xml") != 0)
1604 gdb_send_error(connection
, 01);
1608 xml_printf(&retval
, &xml
, &pos
, &size
, \
1609 "l<target version=\"1.0\">\n<architecture>arm</architecture>\n</target>\n");
1611 if (retval
!= ERROR_OK
)
1613 gdb_send_error(connection
, retval
);
1617 gdb_put_packet(connection
, xml
, strlen(xml
));
1623 gdb_put_packet(connection
, "", 0);
1627 int gdb_v_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1629 gdb_connection_t
*gdb_connection
= connection
->priv
;
1630 gdb_service_t
*gdb_service
= connection
->service
->priv
;
1633 /* if flash programming disabled - send a empty reply */
1635 if (gdb_flash_program
== 0)
1637 gdb_put_packet(connection
, "", 0);
1641 if (strstr(packet
, "vFlashErase:"))
1644 unsigned long length
;
1646 char *parse
= packet
+ 12;
1649 LOG_ERROR("incomplete vFlashErase packet received, dropping connection");
1650 return ERROR_SERVER_REMOTE_CLOSED
;
1653 addr
= strtoul(parse
, &parse
, 16);
1655 if (*(parse
++) != ',' || *parse
== '\0')
1657 LOG_ERROR("incomplete vFlashErase packet received, dropping connection");
1658 return ERROR_SERVER_REMOTE_CLOSED
;
1661 length
= strtoul(parse
, &parse
, 16);
1665 LOG_ERROR("incomplete vFlashErase packet received, dropping connection");
1666 return ERROR_SERVER_REMOTE_CLOSED
;
1669 /* assume all sectors need erasing - stops any problems
1670 * when flash_write is called multiple times */
1673 /* perform any target specific operations before the erase */
1674 target_call_event_callbacks(gdb_service
->target
, TARGET_EVENT_GDB_PROGRAM
);
1677 if ((result
= flash_erase_address_range(gdb_service
->target
, addr
, length
)) != ERROR_OK
)
1679 /* GDB doesn't evaluate the actual error number returned,
1680 * treat a failed erase as an I/O error
1682 gdb_send_error(connection
, EIO
);
1683 LOG_ERROR("flash_erase returned %i", result
);
1686 gdb_put_packet(connection
, "OK", 2);
1691 if (strstr(packet
, "vFlashWrite:"))
1694 unsigned long length
;
1695 char *parse
= packet
+ 12;
1699 LOG_ERROR("incomplete vFlashErase packet received, dropping connection");
1700 return ERROR_SERVER_REMOTE_CLOSED
;
1702 addr
= strtoul(parse
, &parse
, 16);
1703 if (*(parse
++) != ':')
1705 LOG_ERROR("incomplete vFlashErase packet received, dropping connection");
1706 return ERROR_SERVER_REMOTE_CLOSED
;
1708 length
= packet_size
- (parse
- packet
);
1710 /* create a new image if there isn't already one */
1711 if (gdb_connection
->vflash_image
== NULL
)
1713 gdb_connection
->vflash_image
= malloc(sizeof(image_t
));
1714 image_open(gdb_connection
->vflash_image
, "", "build");
1717 /* create new section with content from packet buffer */
1718 image_add_section(gdb_connection
->vflash_image
, addr
, length
, 0x0, (u8
*)parse
);
1720 gdb_put_packet(connection
, "OK", 2);
1725 if (!strcmp(packet
, "vFlashDone"))
1729 /* process the flashing buffer. No need to erase as GDB
1730 * always issues a vFlashErase first. */
1731 if ((result
= flash_write(gdb_service
->target
, gdb_connection
->vflash_image
, &written
, 0)) != ERROR_OK
)
1733 if (result
== ERROR_FLASH_DST_OUT_OF_BANK
)
1734 gdb_put_packet(connection
, "E.memtype", 9);
1736 gdb_send_error(connection
, EIO
);
1740 LOG_DEBUG("wrote %u bytes from vFlash image to flash", written
);
1741 gdb_put_packet(connection
, "OK", 2);
1744 image_close(gdb_connection
->vflash_image
);
1745 free(gdb_connection
->vflash_image
);
1746 gdb_connection
->vflash_image
= NULL
;
1751 gdb_put_packet(connection
, "", 0);
1755 int gdb_detach(connection_t
*connection
, target_t
*target
)
1757 switch( detach_mode
)
1759 case GDB_DETACH_RESUME
:
1760 target_resume(target
, 1, 0, 1, 0);
1763 case GDB_DETACH_RESET
:
1764 target_process_reset(connection
->cmd_ctx
);
1767 case GDB_DETACH_HALT
:
1768 target_halt(target
);
1771 case GDB_DETACH_NOTHING
:
1775 gdb_put_packet(connection
, "OK", 2);
1780 static void gdb_log_callback(void *priv
, const char *file
, int line
,
1781 const char *function
, const char *string
)
1783 connection_t
*connection
= priv
;
1784 gdb_connection_t
*gdb_con
= connection
->priv
;
1788 /* do not reply this using the O packet */
1792 gdb_output_con(connection
, string
);
1795 int gdb_input_inner(connection_t
*connection
)
1797 gdb_service_t
*gdb_service
= connection
->service
->priv
;
1798 target_t
*target
= gdb_service
->target
;
1799 char packet
[GDB_BUFFER_SIZE
];
1802 gdb_connection_t
*gdb_con
= connection
->priv
;
1803 static int extended_protocol
= 0;
1805 /* drain input buffer */
1808 packet_size
= GDB_BUFFER_SIZE
-1;
1809 if ((retval
= gdb_get_packet(connection
, packet
, &packet_size
)) != ERROR_OK
)
1814 /* terminate with zero */
1815 packet
[packet_size
] = 0;
1817 LOG_DEBUG("received packet: '%s'", packet
);
1819 if (packet_size
> 0)
1825 /* Hct... -- set thread
1826 * we don't have threads, send empty reply */
1827 gdb_put_packet(connection
, NULL
, 0);
1830 retval
= gdb_query_packet(connection
, target
, packet
, packet_size
);
1833 retval
= gdb_get_registers_packet(connection
, target
, packet
, packet_size
);
1836 retval
= gdb_set_registers_packet(connection
, target
, packet
, packet_size
);
1839 retval
= gdb_get_register_packet(connection
, target
, packet
, packet_size
);
1842 retval
= gdb_set_register_packet(connection
, target
, packet
, packet_size
);
1845 retval
= gdb_read_memory_packet(connection
, target
, packet
, packet_size
);
1848 retval
= gdb_write_memory_packet(connection
, target
, packet
, packet_size
);
1852 retval
= gdb_breakpoint_watchpoint_packet(connection
, target
, packet
, packet_size
);
1855 gdb_last_signal_packet(connection
, target
, packet
, packet_size
);
1860 if (target
->state
!= TARGET_HALTED
)
1862 /* If the target isn't in the halted state, then we can't
1863 * step/continue. This might be early setup, etc.
1866 snprintf(sig_reply
, 4, "T%2.2x", 2);
1867 gdb_put_packet(connection
, sig_reply
, 3);
1870 /* We're running/stepping, in which case we can
1871 * forward log output until the target is halted
1873 gdb_connection_t
*gdb_con
= connection
->priv
;
1874 gdb_con
->frontend_state
= TARGET_RUNNING
;
1875 log_add_callback(gdb_log_callback
, connection
);
1876 gdb_step_continue_packet(connection
, target
, packet
, packet_size
);
1881 retval
= gdb_v_packet(connection
, target
, packet
, packet_size
);
1884 retval
= gdb_detach(connection
, target
);
1885 extended_protocol
= 0;
1888 if ((retval
= gdb_write_memory_binary_packet(connection
, target
, packet
, packet_size
)) != ERROR_OK
)
1892 if (extended_protocol
!= 0)
1894 gdb_put_packet(connection
, "OK", 2);
1895 return ERROR_SERVER_REMOTE_CLOSED
;
1897 /* handle extended remote protocol */
1898 extended_protocol
= 1;
1899 gdb_put_packet(connection
, "OK", 2);
1902 /* handle extended restart packet */
1903 target_process_reset(connection
->cmd_ctx
);
1906 /* ignore unkown packets */
1907 LOG_DEBUG("ignoring 0x%2.2x packet", packet
[0]);
1908 gdb_put_packet(connection
, NULL
, 0);
1912 /* if a packet handler returned an error, exit input loop */
1913 if (retval
!= ERROR_OK
)
1917 if (gdb_con
->ctrl_c
)
1919 if (target
->state
== TARGET_RUNNING
)
1921 target_halt(target
);
1922 gdb_con
->ctrl_c
= 0;
1926 } while (gdb_con
->buf_cnt
> 0);
1931 int gdb_input(connection_t
*connection
)
1933 int retval
= gdb_input_inner(connection
);
1934 gdb_connection_t
*gdb_con
= connection
->priv
;
1935 if (retval
== ERROR_SERVER_REMOTE_CLOSED
)
1938 /* logging does not propagate the error, yet can set th gdb_con->closed flag */
1939 if (gdb_con
->closed
)
1940 return ERROR_SERVER_REMOTE_CLOSED
;
1942 /* we'll recover from any other errors(e.g. temporary timeouts, etc.) */
1948 gdb_service_t
*gdb_service
;
1949 target_t
*target
= targets
;
1954 LOG_WARNING("no gdb ports allocated as no target has been specified");
1960 LOG_WARNING("no gdb port specified, using default port 3333");
1966 char service_name
[8];
1968 snprintf(service_name
, 8, "gdb-%2.2i", i
);
1970 gdb_service
= malloc(sizeof(gdb_service_t
));
1971 gdb_service
->target
= target
;
1973 add_service("gdb", CONNECTION_GDB
, gdb_port
+ i
, 1, gdb_new_connection
, gdb_input
, gdb_connection_closed
, gdb_service
);
1975 LOG_DEBUG("gdb service for target %s at port %i", target
->type
->name
, gdb_port
+ i
);
1978 target
= target
->next
;
1984 /* daemon configuration command gdb_port */
1985 int handle_gdb_port_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1990 /* only if the port wasn't overwritten by cmdline */
1992 gdb_port
= strtoul(args
[0], NULL
, 0);
1997 int handle_gdb_detach_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2001 if (strcmp(args
[0], "resume") == 0)
2003 detach_mode
= GDB_DETACH_RESUME
;
2006 else if (strcmp(args
[0], "reset") == 0)
2008 detach_mode
= GDB_DETACH_RESET
;
2011 else if (strcmp(args
[0], "halt") == 0)
2013 detach_mode
= GDB_DETACH_HALT
;
2016 else if (strcmp(args
[0], "nothing") == 0)
2018 detach_mode
= GDB_DETACH_NOTHING
;
2023 LOG_WARNING("invalid gdb_detach configuration directive: %s", args
[0]);
2027 int handle_gdb_memory_map_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2031 if (strcmp(args
[0], "enable") == 0)
2033 gdb_use_memory_map
= 1;
2036 else if (strcmp(args
[0], "disable") == 0)
2038 gdb_use_memory_map
= 0;
2043 LOG_WARNING("invalid gdb_memory_map configuration directive: %s", args
[0]);
2047 int handle_gdb_flash_program_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2051 if (strcmp(args
[0], "enable") == 0)
2053 gdb_flash_program
= 1;
2056 else if (strcmp(args
[0], "disable") == 0)
2058 gdb_flash_program
= 0;
2063 LOG_WARNING("invalid gdb_memory_map configuration directive: %s", args
[0]);
2067 int handle_gdb_report_data_abort_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2071 if (strcmp(args
[0], "enable") == 0)
2073 gdb_report_data_abort
= 1;
2076 else if (strcmp(args
[0], "disable") == 0)
2078 gdb_report_data_abort
= 0;
2083 LOG_WARNING("invalid gdb_report_data_abort configuration directive: %s", args
[0]);
2087 int gdb_register_commands(command_context_t
*command_context
)
2089 register_command(command_context
, NULL
, "gdb_port", handle_gdb_port_command
,
2090 COMMAND_CONFIG
, "");
2091 register_command(command_context
, NULL
, "gdb_detach", handle_gdb_detach_command
,
2092 COMMAND_CONFIG
, "");
2093 register_command(command_context
, NULL
, "gdb_memory_map", handle_gdb_memory_map_command
,
2094 COMMAND_CONFIG
, "");
2095 register_command(command_context
, NULL
, "gdb_flash_program", handle_gdb_flash_program_command
,
2096 COMMAND_CONFIG
, "");
2097 register_command(command_context
, NULL
, "gdb_report_data_abort", handle_gdb_report_data_abort_command
,
2098 COMMAND_CONFIG
, "");