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"
31 #include "breakpoints.h"
40 #define _DEBUG_GDB_IO_
43 static unsigned short gdb_port
;
45 int gdb_last_signal(target_t
*target
)
47 switch (target
->debug_reason
)
49 case DBG_REASON_DBGRQ
:
50 return 0x2; /* SIGINT */
51 case DBG_REASON_BREAKPOINT
:
52 case DBG_REASON_WATCHPOINT
:
53 case DBG_REASON_WPTANDBKPT
:
54 return 0x05; /* SIGTRAP */
55 case DBG_REASON_SINGLESTEP
:
56 return 0x05; /* SIGTRAP */
57 case DBG_REASON_NOTHALTED
:
58 return 0x0; /* no signal... shouldn't happen */
60 ERROR("BUG: undefined debug reason");
65 int gdb_get_char(connection_t
*connection
, int* next_char
)
67 gdb_connection_t
*gdb_con
= connection
->priv
;
70 if (gdb_con
->buf_cnt
-- > 0)
72 *next_char
= *(gdb_con
->buf_p
++);
73 if (gdb_con
->buf_cnt
> 0)
74 connection
->input_pending
= 1;
76 connection
->input_pending
= 0;
79 DEBUG("returned char '%c' (0x%2.2x)", *next_char
, *next_char
);
85 while ((gdb_con
->buf_cnt
= read_socket(connection
->fd
, gdb_con
->buffer
, GDB_BUFFER_SIZE
)) <= 0)
87 if (gdb_con
->buf_cnt
== 0)
88 return ERROR_SERVER_REMOTE_CLOSED
;
91 errno
= WSAGetLastError();
99 return ERROR_SERVER_REMOTE_CLOSED
;
101 ERROR("read: %d", errno
);
111 return ERROR_SERVER_REMOTE_CLOSED
;
113 return ERROR_SERVER_REMOTE_CLOSED
;
115 ERROR("read: %s", strerror(errno
));
121 debug_buffer
= malloc(gdb_con
->buf_cnt
+ 1);
122 memcpy(debug_buffer
, gdb_con
->buffer
, gdb_con
->buf_cnt
);
123 debug_buffer
[gdb_con
->buf_cnt
] = 0;
124 DEBUG("received '%s'", debug_buffer
);
127 gdb_con
->buf_p
= gdb_con
->buffer
;
129 *next_char
= *(gdb_con
->buf_p
++);
130 if (gdb_con
->buf_cnt
> 0)
131 connection
->input_pending
= 1;
133 connection
->input_pending
= 0;
134 #ifdef _DEBUG_GDB_IO_
135 DEBUG("returned char '%c' (0x%2.2x)", *next_char
, *next_char
);
141 int gdb_putback_char(connection_t
*connection
, int last_char
)
143 gdb_connection_t
*gdb_con
= connection
->priv
;
145 if (gdb_con
->buf_p
> gdb_con
->buffer
)
147 *(--gdb_con
->buf_p
) = last_char
;
152 ERROR("BUG: couldn't put character back");
158 int gdb_put_packet(connection_t
*connection
, char *buffer
, int len
)
161 unsigned char my_checksum
= 0;
166 gdb_connection_t
*gdb_con
= connection
->priv
;
168 for (i
= 0; i
< len
; i
++)
169 my_checksum
+= buffer
[i
];
174 debug_buffer
= malloc(len
+ 1);
175 memcpy(debug_buffer
, buffer
, len
);
176 debug_buffer
[len
] = 0;
177 DEBUG("sending packet '$%s#%2.2x'", debug_buffer
, my_checksum
);
180 write_socket(connection
->fd
, "$", 1);
182 write_socket(connection
->fd
, buffer
, len
);
183 write_socket(connection
->fd
, "#", 1);
185 snprintf(checksum
, 3, "%2.2x", my_checksum
);
187 write_socket(connection
->fd
, checksum
, 2);
189 if ((retval
= gdb_get_char(connection
, &reply
)) != ERROR_OK
)
194 else if (reply
== '-')
195 WARNING("negative reply, retrying");
196 else if (reply
== 0x3)
199 if ((retval
= gdb_get_char(connection
, &reply
)) != ERROR_OK
)
203 else if (reply
== '-')
204 WARNING("negative reply, retrying");
207 ERROR("unknown character 0x%2.2x in reply, dropping connection", reply
);
208 return ERROR_SERVER_REMOTE_CLOSED
;
213 ERROR("unknown character 0x%2.2x in reply, dropping connection", reply
);
214 return ERROR_SERVER_REMOTE_CLOSED
;
221 int gdb_get_packet(connection_t
*connection
, char *buffer
, int *len
)
227 int packet_type
= '\0';
229 unsigned char my_checksum
= 0;
230 gdb_connection_t
*gdb_con
= connection
->priv
;
236 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
239 DEBUG("character: '%c'", character
);
246 WARNING("acknowledgment received, but no packet pending");
249 WARNING("negative acknowledgment, but no packet pending");
256 WARNING("ignoring character 0x%x", character
);
259 } while (character
!= '$');
265 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
268 if (character
== '#') break;
270 if (character
== '}')
272 /* data transmitted in binary mode (X packet)
273 * uses 0x7d as escape character */
274 my_checksum
+= character
& 0xff;
275 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
277 my_checksum
+= character
& 0xff;
278 buffer
[count
++] = (character
^ 0x20) & 0xff;
282 my_checksum
+= character
& 0xff;
283 buffer
[count
++] = character
& 0xff;
288 ERROR("packet buffer too small");
289 return ERROR_GDB_BUFFER_TOO_SMALL
;
295 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
297 checksum
[0] = character
;
298 if ((retval
= gdb_get_char(connection
, &character
)) != ERROR_OK
)
300 checksum
[1] = character
;
303 if (my_checksum
== strtoul(checksum
, NULL
, 16))
305 write_socket(connection
->fd
, "+", 1);
309 WARNING("checksum error, requesting retransmission");
310 write_socket(connection
->fd
, "-", 1);
316 int gdb_output(struct command_context_s
*context
, char* line
)
318 connection_t
*connection
= context
->output_handler_priv
;
322 bin_size
= strlen(line
);
324 hex_buffer
= malloc(bin_size
*2 + 4);
327 for (i
=0; i
<bin_size
; i
++)
328 snprintf(hex_buffer
+ 1 + i
*2, 3, "%2.2x", line
[i
]);
329 hex_buffer
[bin_size
*2+1] = '0';
330 hex_buffer
[bin_size
*2+2] = 'a';
331 hex_buffer
[bin_size
*2+3] = 0x0;
333 gdb_put_packet(connection
, hex_buffer
, bin_size
*2 + 3);
339 int gdb_target_callback_event_handler(struct target_s
*target
, enum target_event event
, void *priv
)
341 connection_t
*connection
= priv
;
342 gdb_connection_t
*gdb_connection
= connection
->priv
;
348 case TARGET_EVENT_HALTED
:
349 if (gdb_connection
->frontend_state
== TARGET_RUNNING
)
351 if (gdb_connection
->ctrl_c
)
354 gdb_connection
->ctrl_c
= 0;
358 signal
= gdb_last_signal(target
);
361 snprintf(sig_reply
, 4, "T%2.2x", signal
);
362 gdb_put_packet(connection
, sig_reply
, 3);
363 gdb_connection
->frontend_state
= TARGET_HALTED
;
366 case TARGET_EVENT_RESUMED
:
367 if (gdb_connection
->frontend_state
== TARGET_HALTED
)
369 gdb_connection
->frontend_state
= TARGET_RUNNING
;
379 int gdb_new_connection(connection_t
*connection
)
381 gdb_connection_t
*gdb_connection
= malloc(sizeof(gdb_connection_t
));
382 gdb_service_t
*gdb_service
= connection
->service
->priv
;
386 connection
->priv
= gdb_connection
;
388 /* initialize gdb connection information */
389 gdb_connection
->buf_p
= gdb_connection
->buffer
;
390 gdb_connection
->buf_cnt
= 0;
391 gdb_connection
->ctrl_c
= 0;
392 gdb_connection
->frontend_state
= TARGET_HALTED
;
394 /* output goes through gdb connection */
395 command_set_output_handler(connection
->cmd_ctx
, gdb_output
, connection
);
397 /* register callback to be informed about target events */
398 target_register_event_callback(gdb_target_callback_event_handler
, connection
);
400 /* a gdb session just attached, put the target in halt mode */
401 if (((retval
= gdb_service
->target
->type
->halt(gdb_service
->target
)) != ERROR_OK
) &&
402 (retval
!= ERROR_TARGET_ALREADY_HALTED
))
404 ERROR("error when trying to halt target");
408 while (gdb_service
->target
->state
!= TARGET_HALTED
)
410 gdb_service
->target
->type
->poll(gdb_service
->target
);
413 /* remove the initial ACK from the incoming buffer */
414 if ((retval
= gdb_get_char(connection
, &initial_ack
)) != ERROR_OK
)
417 if (initial_ack
!= '+')
418 gdb_putback_char(connection
, initial_ack
);
423 int gdb_connection_closed(connection_t
*connection
)
425 if (connection
->priv
)
426 free(connection
->priv
);
428 ERROR("BUG: connection->priv == NULL");
430 target_unregister_event_callback(gdb_target_callback_event_handler
, connection
);
435 void gdb_send_error(connection_t
*connection
, u8 the_error
)
438 snprintf(err
, 4, "E%2.2X", the_error
);
439 gdb_put_packet(connection
, err
, 3);
442 int gdb_last_signal_packet(connection_t
*connection
, target_t
*target
, char* packet
, int packet_size
)
447 signal
= gdb_last_signal(target
);
449 snprintf(sig_reply
, 4, "S%2.2x", signal
);
450 gdb_put_packet(connection
, sig_reply
, 3);
455 void gdb_str_to_target(target_t
*target
, char *str
, char *tstr
)
457 int str_len
= strlen(str
);
462 ERROR("BUG: gdb value with uneven number of characters encountered: %s", str
);
466 if (target
->endianness
== TARGET_LITTLE_ENDIAN
)
468 for (i
= 0; i
< str_len
; i
+=2)
470 tstr
[str_len
- i
- 1] = str
[i
+ 1];
471 tstr
[str_len
- i
- 2] = str
[i
];
476 for (i
= 0; i
< str_len
; i
++)
483 void gdb_target_to_str(target_t
*target
, char *tstr
, char *str
)
485 int str_len
= strlen(tstr
);
490 ERROR("BUG: gdb value with uneven number of characters encountered");
494 if (target
->endianness
== TARGET_LITTLE_ENDIAN
)
496 for (i
= 0; i
< str_len
; i
+=2)
498 str
[str_len
- i
- 1] = tstr
[i
+ 1];
499 str
[str_len
- i
- 2] = tstr
[i
];
504 for (i
= 0; i
< str_len
; i
++)
511 int gdb_get_registers_packet(connection_t
*connection
, target_t
*target
, char* packet
, int packet_size
)
516 int reg_packet_size
= 0;
523 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
527 case ERROR_TARGET_NOT_HALTED
:
528 ERROR("gdb requested registers but we're not halted, dropping connection");
529 return ERROR_SERVER_REMOTE_CLOSED
;
531 /* this is a bug condition - get_gdb_reg_list() may not return any other error */
532 ERROR("BUG: unexpected error returned by get_gdb_reg_list()");
537 for (i
= 0; i
< reg_list_size
; i
++)
539 reg_packet_size
+= reg_list
[i
]->size
;
542 reg_packet
= malloc(CEIL(reg_packet_size
, 8) * 2);
543 reg_packet_p
= reg_packet
;
545 for (i
= 0; i
< reg_list_size
; i
++)
547 char *hex_buf
= buf_to_str(reg_list
[i
]->value
, reg_list
[i
]->size
, 16);
548 DEBUG("hex_buf: %s", hex_buf
);
549 gdb_str_to_target(target
, hex_buf
, reg_packet_p
);
550 reg_packet_p
+= CEIL(reg_list
[i
]->size
, 8) * 2;
554 reg_packet_p
= strndup(reg_packet
, CEIL(reg_packet_size
, 8) * 2);
555 DEBUG("reg_packet: %s", reg_packet_p
);
558 gdb_put_packet(connection
, reg_packet
, CEIL(reg_packet_size
, 8) * 2);
566 int gdb_set_registers_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
576 /* skip command character */
582 WARNING("GDB set_registers packet with uneven characters received, dropping connection");
583 return ERROR_SERVER_REMOTE_CLOSED
;
586 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
590 case ERROR_TARGET_NOT_HALTED
:
591 ERROR("gdb tried to registers but we're not halted, dropping connection");
592 return ERROR_SERVER_REMOTE_CLOSED
;
594 /* this is a bug condition - get_gdb_reg_list() may not return any other error */
595 ERROR("BUG: unexpected error returned by get_gdb_reg_list()");
601 for (i
= 0; i
< reg_list_size
; i
++)
605 reg_arch_type_t
*arch_type
;
607 /* convert from GDB-string (target-endian) to hex-string (big-endian) */
608 hex_buf
= malloc(CEIL(reg_list
[i
]->size
, 8) * 2);
609 gdb_target_to_str(target
, packet_p
, hex_buf
);
611 /* convert hex-string to binary buffer */
612 bin_buf
= malloc(CEIL(reg_list
[i
]->size
, 8));
613 str_to_buf(hex_buf
, CEIL(reg_list
[i
]->size
, 8) * 2, bin_buf
, reg_list
[i
]->size
, 16);
615 /* get register arch_type, and call set method */
616 arch_type
= register_get_arch_type(reg_list
[i
]->arch_type
);
617 if (arch_type
== NULL
)
619 ERROR("BUG: encountered unregistered arch type");
622 arch_type
->set(reg_list
[i
], bin_buf
);
624 /* advance packet pointer */
625 packet_p
+= (CEIL(reg_list
[i
]->size
, 8) * 2);
631 /* free reg_t *reg_list[] array allocated by get_gdb_reg_list */
634 gdb_put_packet(connection
, "OK", 2);
639 int gdb_get_register_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
642 int reg_num
= strtoul(packet
+ 1, NULL
, 16);
650 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
654 case ERROR_TARGET_NOT_HALTED
:
655 ERROR("gdb requested registers but we're not halted, dropping connection");
656 return ERROR_SERVER_REMOTE_CLOSED
;
658 /* this is a bug condition - get_gdb_reg_list() may not return any other error */
659 ERROR("BUG: unexpected error returned by get_gdb_reg_list()");
664 if (reg_list_size
<= reg_num
)
666 ERROR("gdb requested a non-existing register");
670 reg_packet
= malloc(CEIL(reg_list
[reg_num
]->size
, 8) * 2);
672 hex_buf
= buf_to_str(reg_list
[reg_num
]->value
, reg_list
[reg_num
]->size
, 16);
674 gdb_str_to_target(target
, hex_buf
, reg_packet
);
676 gdb_put_packet(connection
, reg_packet
, CEIL(reg_list
[reg_num
]->size
, 8) * 2);
685 int gdb_set_register_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
690 int reg_num
= strtoul(packet
+ 1, &separator
, 16);
694 reg_arch_type_t
*arch_type
;
698 if ((retval
= target
->type
->get_gdb_reg_list(target
, ®_list
, ®_list_size
)) != ERROR_OK
)
702 case ERROR_TARGET_NOT_HALTED
:
703 ERROR("gdb tried to set a register but we're not halted, dropping connection");
704 return ERROR_SERVER_REMOTE_CLOSED
;
706 /* this is a bug condition - get_gdb_reg_list() may not return any other error */
707 ERROR("BUG: unexpected error returned by get_gdb_reg_list()");
712 if (reg_list_size
< reg_num
)
714 ERROR("gdb requested a non-existing register");
715 return ERROR_SERVER_REMOTE_CLOSED
;
718 if (*separator
!= '=')
720 ERROR("GDB 'set register packet', but no '=' following the register number");
721 return ERROR_SERVER_REMOTE_CLOSED
;
724 /* convert from GDB-string (target-endian) to hex-string (big-endian) */
725 hex_buf
= malloc(CEIL(reg_list
[reg_num
]->size
, 8) * 2);
726 gdb_target_to_str(target
, separator
+ 1, hex_buf
);
728 /* convert hex-string to binary buffer */
729 bin_buf
= malloc(CEIL(reg_list
[reg_num
]->size
, 8));
730 str_to_buf(hex_buf
, CEIL(reg_list
[reg_num
]->size
, 8) * 2, bin_buf
, reg_list
[reg_num
]->size
, 16);
732 /* get register arch_type, and call set method */
733 arch_type
= register_get_arch_type(reg_list
[reg_num
]->arch_type
);
734 if (arch_type
== NULL
)
736 ERROR("BUG: encountered unregistered arch type");
739 arch_type
->set(reg_list
[reg_num
], bin_buf
);
741 gdb_put_packet(connection
, "OK", 2);
750 int gdb_memory_packet_error(connection_t
*connection
, int retval
)
754 case ERROR_TARGET_NOT_HALTED
:
755 ERROR("gdb tried to read memory but we're not halted, dropping connection");
756 return ERROR_SERVER_REMOTE_CLOSED
;
758 case ERROR_TARGET_DATA_ABORT
:
759 gdb_send_error(connection
, EIO
);
761 case ERROR_TARGET_TRANSLATION_FAULT
:
762 gdb_send_error(connection
, EFAULT
);
764 case ERROR_TARGET_UNALIGNED_ACCESS
:
765 gdb_send_error(connection
, EFAULT
);
768 ERROR("BUG: unexpected error %i", retval
);
775 int gdb_read_memory_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
787 /* skip command character */
790 addr
= strtoul(packet
, &separator
, 16);
792 if (*separator
!= ',')
794 ERROR("incomplete read memory packet received, dropping connection");
795 return ERROR_SERVER_REMOTE_CLOSED
;
798 len
= strtoul(separator
+1, NULL
, 16);
800 buffer
= malloc(len
);
802 DEBUG("addr: 0x%8.8x, len: 0x%8.8x", addr
, len
);
808 retval
= target
->type
->read_memory(target
, addr
, 4, 1, buffer
);
810 retval
= target
->type
->read_memory(target
, addr
, 1, len
, buffer
);
814 retval
= target
->type
->read_memory(target
, addr
, 2, 1, buffer
);
816 retval
= target
->type
->read_memory(target
, addr
, 1, len
, buffer
);
819 if (((addr
% 4) == 0) && ((len
% 4) == 0))
820 retval
= target
->type
->read_memory(target
, addr
, 4, len
/ 4, buffer
);
822 retval
= target
->type
->read_memory(target
, addr
, 1, len
, buffer
);
825 if (retval
== ERROR_OK
)
827 hex_buffer
= malloc(len
* 2 + 1);
829 for (i
=0; i
<len
; i
++)
830 snprintf(hex_buffer
+ 2*i
, 3, "%2.2x", buffer
[i
]);
832 gdb_put_packet(connection
, hex_buffer
, len
* 2);
838 if ((retval
= gdb_memory_packet_error(connection
, retval
)) != ERROR_OK
)
847 int gdb_write_memory_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
858 /* skip command character */
861 addr
= strtoul(packet
, &separator
, 16);
863 if (*separator
!= ',')
865 ERROR("incomplete write memory packet received, dropping connection");
866 return ERROR_SERVER_REMOTE_CLOSED
;
869 len
= strtoul(separator
+1, &separator
, 16);
871 if (*(separator
++) != ':')
873 ERROR("incomplete write memory packet received, dropping connection");
874 return ERROR_SERVER_REMOTE_CLOSED
;
877 buffer
= malloc(len
);
879 DEBUG("addr: 0x%8.8x, len: 0x%8.8x", addr
, len
);
881 for (i
=0; i
<len
; i
++)
884 sscanf(separator
+ 2*i
, "%2x", &tmp
);
891 /* handle sized writes */
894 retval
= target
->type
->write_memory(target
, addr
, 4, 1, buffer
);
896 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
900 retval
= target
->type
->write_memory(target
, addr
, 2, 1, buffer
);
902 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
906 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
908 /* handle bulk writes */
910 retval
= target_write_buffer(target
, addr
, len
, buffer
);
914 if (retval
== ERROR_OK
)
916 gdb_put_packet(connection
, "OK", 2);
920 if ((retval
= gdb_memory_packet_error(connection
, retval
)) != ERROR_OK
)
929 int gdb_write_memory_binary_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
938 /* skip command character */
941 addr
= strtoul(packet
, &separator
, 16);
943 if (*separator
!= ',')
945 ERROR("incomplete write memory binary packet received, dropping connection");
946 return ERROR_SERVER_REMOTE_CLOSED
;
949 len
= strtoul(separator
+1, &separator
, 16);
951 if (*(separator
++) != ':')
953 ERROR("incomplete write memory binary packet received, dropping connection");
954 return ERROR_SERVER_REMOTE_CLOSED
;
960 buffer
= malloc(len
);
962 DEBUG("addr: 0x%8.8x, len: 0x%8.8x", addr
, len
);
964 memcpy( buffer
, separator
, len
);
970 retval
= target
->type
->write_memory(target
, addr
, 4, 1, buffer
);
972 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
976 retval
= target
->type
->write_memory(target
, addr
, 2, 1, buffer
);
978 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
982 retval
= target
->type
->write_memory(target
, addr
, 1, len
, buffer
);
985 retval
= target_write_buffer(target
, addr
, len
, buffer
);
992 if (retval
== ERROR_OK
)
994 gdb_put_packet(connection
, "OK", 2);
998 if ((retval
= gdb_memory_packet_error(connection
, retval
)) != ERROR_OK
)
1005 void gdb_step_continue_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1012 if (packet_size
> 1)
1014 packet
[packet_size
] = 0;
1015 address
= strtoul(packet
+ 1, NULL
, 16);
1022 if (packet
[0] == 'c')
1025 target
->type
->resume(target
, current
, address
, 0, 0); /* resume at current address, don't handle breakpoints, not debugging */
1027 else if (packet
[0] == 's')
1030 target
->type
->step(target
, current
, address
, 0); /* step at current or address, don't handle breakpoints */
1034 int gdb_bp_wp_packet_error(connection_t
*connection
, int retval
)
1038 case ERROR_TARGET_NOT_HALTED
:
1039 ERROR("gdb tried to set a breakpoint but we're not halted, dropping connection");
1040 return ERROR_SERVER_REMOTE_CLOSED
;
1042 case ERROR_TARGET_RESOURCE_NOT_AVAILABLE
:
1043 gdb_send_error(connection
, EBUSY
);
1046 ERROR("BUG: unexpected error %i", retval
);
1053 int gdb_breakpoint_watchpoint_packet(connection_t
*connection
, target_t
*target
, char *packet
, int packet_size
)
1056 enum breakpoint_type bp_type
= BKPT_SOFT
/* dummy init to avoid warning */;
1057 enum watchpoint_rw wp_type
;
1065 type
= strtoul(packet
+ 1, &separator
, 16);
1067 if (type
== 0) /* memory breakpoint */
1068 bp_type
= BKPT_SOFT
;
1069 else if (type
== 1) /* hardware breakpoint */
1070 bp_type
= BKPT_HARD
;
1071 else if (type
== 2) /* write watchpoint */
1072 wp_type
= WPT_WRITE
;
1073 else if (type
== 3) /* read watchpoint */
1075 else if (type
== 4) /* access watchpoint */
1076 wp_type
= WPT_ACCESS
;
1078 if (*separator
!= ',')
1080 ERROR("incomplete breakpoint/watchpoint packet received, dropping connection");
1081 return ERROR_SERVER_REMOTE_CLOSED
;
1084 address
= strtoul(separator
+1, &separator
, 16);
1086 if (*separator
!= ',')
1088 ERROR("incomplete breakpoint/watchpoint packet received, dropping connection");
1089 return ERROR_SERVER_REMOTE_CLOSED
;
1092 size
= strtoul(separator
+1, &separator
, 16);
1098 if (packet
[0] == 'Z')
1100 if ((retval
= breakpoint_add(target
, address
, size
, bp_type
)) != ERROR_OK
)
1102 if ((retval
= gdb_bp_wp_packet_error(connection
, retval
)) != ERROR_OK
)
1107 gdb_put_packet(connection
, "OK", 2);
1112 breakpoint_remove(target
, address
);
1113 gdb_put_packet(connection
, "OK", 2);
1120 if (packet
[0] == 'Z')
1122 if ((retval
= watchpoint_add(target
, address
, size
, type
-2, 0, 0xffffffffu
)) != ERROR_OK
)
1124 if ((retval
= gdb_bp_wp_packet_error(connection
, retval
)) != ERROR_OK
)
1129 gdb_put_packet(connection
, "OK", 2);
1134 watchpoint_remove(target
, address
);
1135 gdb_put_packet(connection
, "OK", 2);
1146 void gdb_query_packet(connection_t
*connection
, char *packet
, int packet_size
)
1148 command_context_t
*cmd_ctx
= connection
->cmd_ctx
;
1150 if (strstr(packet
, "qRcmd,"))
1152 if (packet_size
> 6)
1156 cmd
= malloc((packet_size
- 6)/2 + 1);
1157 for (i
=0; i
< (packet_size
- 6)/2; i
++)
1160 sscanf(packet
+ 6 + 2*i
, "%2x", &tmp
);
1163 cmd
[(packet_size
- 6)/2] = 0x0;
1164 command_run_line(cmd_ctx
, cmd
);
1167 gdb_put_packet(connection
, "OK", 2);
1171 gdb_put_packet(connection
, "", 0);
1174 int gdb_input(connection_t
*connection
)
1176 gdb_service_t
*gdb_service
= connection
->service
->priv
;
1177 target_t
*target
= gdb_service
->target
;
1178 char packet
[GDB_BUFFER_SIZE
];
1181 gdb_connection_t
*gdb_con
= connection
->priv
;
1183 /* drain input buffer */
1186 packet_size
= GDB_BUFFER_SIZE
-1;
1187 if ((retval
= gdb_get_packet(connection
, packet
, &packet_size
)) != ERROR_OK
)
1191 case ERROR_GDB_BUFFER_TOO_SMALL
:
1192 ERROR("BUG: buffer supplied for gdb packet was too small");
1194 case ERROR_SERVER_REMOTE_CLOSED
:
1195 return ERROR_SERVER_REMOTE_CLOSED
;
1197 ERROR("BUG: unexpected error");
1202 /* terminate with zero */
1203 packet
[packet_size
] = 0;
1205 DEBUG("recevied packet: '%s'", packet
);
1207 if (packet_size
> 0)
1213 /* Hct... -- set thread
1214 * we don't have threads, send empty reply */
1215 gdb_put_packet(connection
, NULL
, 0);
1218 gdb_query_packet(connection
, packet
, packet_size
);
1221 retval
= gdb_get_registers_packet(connection
, target
, packet
, packet_size
);
1224 retval
= gdb_set_registers_packet(connection
, target
, packet
, packet_size
);
1227 retval
= gdb_get_register_packet(connection
, target
, packet
, packet_size
);
1230 retval
= gdb_set_register_packet(connection
, target
, packet
, packet_size
);
1233 retval
= gdb_read_memory_packet(connection
, target
, packet
, packet_size
);
1236 retval
= gdb_write_memory_packet(connection
, target
, packet
, packet_size
);
1240 retval
= gdb_breakpoint_watchpoint_packet(connection
, target
, packet
, packet_size
);
1243 gdb_last_signal_packet(connection
, target
, packet
, packet_size
);
1247 gdb_step_continue_packet(connection
, target
, packet
, packet_size
);
1250 target
->type
->resume(target
, 1, 0, 1, 0);
1251 gdb_put_packet(connection
, "OK", 2);
1254 if ((retval
= gdb_write_memory_binary_packet(connection
, target
, packet
, packet_size
)) != ERROR_OK
)
1258 gdb_put_packet(connection
, "OK", 2);
1259 return ERROR_SERVER_REMOTE_CLOSED
;
1261 /* ignore unkown packets */
1262 DEBUG("ignoring 0x%2.2x packet", packet
[0]);
1263 gdb_put_packet(connection
, NULL
, 0);
1267 /* if a packet handler returned an error, exit input loop */
1268 if (retval
!= ERROR_OK
)
1272 if (gdb_con
->ctrl_c
)
1274 if (target
->state
== TARGET_RUNNING
)
1276 target
->type
->halt(target
);
1277 gdb_con
->ctrl_c
= 0;
1281 } while (gdb_con
->buf_cnt
> 0);
1288 gdb_service_t
*gdb_service
;
1289 target_t
*target
= targets
;
1294 WARNING("no gdb ports allocated as no target has been specified");
1300 WARNING("no gdb port specified, using default port 3333");
1306 char service_name
[8];
1308 snprintf(service_name
, 8, "gdb-%2.2i", i
);
1310 gdb_service
= malloc(sizeof(gdb_service_t
));
1311 gdb_service
->target
= target
;
1313 add_service("gdb", CONNECTION_GDB
, gdb_port
+ i
, 1, gdb_new_connection
, gdb_input
, gdb_connection_closed
, gdb_service
);
1315 DEBUG("gdb service for target %s at port %i", target
->type
->name
, gdb_port
+ i
);
1318 target
= target
->next
;
1324 /* daemon configuration command gdb_port */
1325 int handle_gdb_port_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1330 /* only if the port wasn't overwritten by cmdline */
1332 gdb_port
= strtoul(args
[0], NULL
, 0);
1337 int gdb_register_commands(command_context_t
*command_context
)
1339 register_command(command_context
, NULL
, "gdb_port", handle_gdb_port_command
,
1340 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)