@@ -371,11 +371,13 @@ static int gdb_write(struct connection *connection, void *data, int len)
371371 return ERROR_SERVER_REMOTE_CLOSED ;
372372}
373373
374- static void gdb_log_incoming_packet (char * packet )
374+ static void gdb_log_incoming_packet (struct connection * connection , char * packet )
375375{
376376 if (!LOG_LEVEL_IS (LOG_LVL_DEBUG ))
377377 return ;
378378
379+ struct target * target = get_target_from_connection (connection );
380+
379381 /* Avoid dumping non-printable characters to the terminal */
380382 const unsigned packet_len = strlen (packet );
381383 const char * nonprint = find_nonprint_char (packet , packet_len );
@@ -389,25 +391,31 @@ static void gdb_log_incoming_packet(char *packet)
389391 if (packet_prefix_printable ) {
390392 const unsigned int prefix_len = colon - packet + 1 ; /* + 1 to include the ':' */
391393 const unsigned int payload_len = packet_len - prefix_len ;
392- LOG_DEBUG ("received packet: %.*s<binary-data-%u-bytes>" , prefix_len , packet , payload_len );
394+ LOG_TARGET_DEBUG (target , "received packet: %.*s<binary-data-%u-bytes>" , prefix_len ,
395+ packet , payload_len );
393396 } else {
394- LOG_DEBUG ( "received packet: <binary-data-%u-bytes>" , packet_len );
397+ LOG_TARGET_DEBUG ( target , "received packet: <binary-data-%u-bytes>" , packet_len );
395398 }
396399 } else {
397400 /* All chars printable, dump the packet as is */
398- LOG_DEBUG ( "received packet: %s" , packet );
401+ LOG_TARGET_DEBUG ( target , "received packet: %s" , packet );
399402 }
400403}
401404
402- static void gdb_log_outgoing_packet (char * packet_buf , unsigned int packet_len , unsigned char checksum )
405+ static void gdb_log_outgoing_packet (struct connection * connection , char * packet_buf ,
406+ unsigned int packet_len , unsigned char checksum )
403407{
404408 if (!LOG_LEVEL_IS (LOG_LVL_DEBUG ))
405409 return ;
406410
411+ struct target * target = get_target_from_connection (connection );
412+
407413 if (find_nonprint_char (packet_buf , packet_len ))
408- LOG_DEBUG ("sending packet: $<binary-data-%u-bytes>#%2.2x" , packet_len , checksum );
414+ LOG_TARGET_DEBUG (target , "sending packet: $<binary-data-%u-bytes>#%2.2x" ,
415+ packet_len , checksum );
409416 else
410- LOG_DEBUG ("sending packet: $%.*s#%2.2x'" , packet_len , packet_buf , checksum );
417+ LOG_TARGET_DEBUG (target , "sending packet: $%.*s#%2.2x" , packet_len , packet_buf ,
418+ checksum );
411419}
412420
413421static int gdb_put_packet_inner (struct connection * connection ,
@@ -450,7 +458,7 @@ static int gdb_put_packet_inner(struct connection *connection,
450458#endif
451459
452460 while (1 ) {
453- gdb_log_outgoing_packet (buffer , len , my_checksum );
461+ gdb_log_outgoing_packet (connection , buffer , len , my_checksum );
454462
455463 char local_buffer [1024 ];
456464 local_buffer [0 ] = '$' ;
@@ -483,22 +491,27 @@ static int gdb_put_packet_inner(struct connection *connection,
483491 if (retval != ERROR_OK )
484492 return retval ;
485493
486- if (reply == '+' )
494+ if (reply == '+' ) {
495+ gdb_log_incoming_packet (connection , "+" );
487496 break ;
488- else if (reply == '-' ) {
497+ } else if (reply == '-' ) {
489498 /* Stop sending output packets for now */
490499 gdb_con -> output_flag = GDB_OUTPUT_NO ;
500+ gdb_log_incoming_packet (connection , "-" );
491501 LOG_WARNING ("negative reply, retrying" );
492502 } else if (reply == 0x3 ) {
493503 gdb_con -> ctrl_c = true;
504+ gdb_log_incoming_packet (connection , "<Ctrl-C>" );
494505 retval = gdb_get_char (connection , & reply );
495506 if (retval != ERROR_OK )
496507 return retval ;
497- if (reply == '+' )
508+ if (reply == '+' ) {
509+ gdb_log_incoming_packet (connection , "+" );
498510 break ;
499- else if (reply == '-' ) {
511+ } else if (reply == '-' ) {
500512 /* Stop sending output packets for now */
501513 gdb_con -> output_flag = GDB_OUTPUT_NO ;
514+ gdb_log_incoming_packet (connection , "-" );
502515 LOG_WARNING ("negative reply, retrying" );
503516 } else if (reply == '$' ) {
504517 LOG_ERROR ("GDB missing ack(1) - assumed good" );
@@ -675,6 +688,7 @@ static int gdb_get_packet_inner(struct connection *connection,
675688 case '$' :
676689 break ;
677690 case '+' :
691+ gdb_log_incoming_packet (connection , "+" );
678692 /* According to the GDB documentation
679693 * (https://sourceware.org/gdb/onlinedocs/gdb/Packet-Acknowledgment.html):
680694 * "gdb sends a final `+` acknowledgment of the stub's `OK`
@@ -692,9 +706,11 @@ static int gdb_get_packet_inner(struct connection *connection,
692706 }
693707 break ;
694708 case '-' :
709+ gdb_log_incoming_packet (connection , "-" );
695710 LOG_WARNING ("negative acknowledgment, but no packet pending" );
696711 break ;
697712 case 0x3 :
713+ gdb_log_incoming_packet (connection , "<Ctrl-C>" );
698714 gdb_con -> ctrl_c = true;
699715 * len = 0 ;
700716 return ERROR_OK ;
@@ -3461,9 +3477,10 @@ static int gdb_input_inner(struct connection *connection)
34613477 /* terminate with zero */
34623478 gdb_packet_buffer [packet_size ] = '\0' ;
34633479
3464- gdb_log_incoming_packet (gdb_packet_buffer );
3465-
34663480 if (packet_size > 0 ) {
3481+
3482+ gdb_log_incoming_packet (connection , gdb_packet_buffer );
3483+
34673484 retval = ERROR_OK ;
34683485 switch (packet [0 ]) {
34693486 case 'T' : /* Is thread alive? */
0 commit comments