aboutsummaryrefslogtreecommitdiff
path: root/src/gdb_packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gdb_packet.c')
-rw-r--r--src/gdb_packet.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/gdb_packet.c b/src/gdb_packet.c
index 958572c..9ce63f2 100644
--- a/src/gdb_packet.c
+++ b/src/gdb_packet.c
@@ -22,20 +22,14 @@
* reception and transmission as well as some convenience functions.
*/
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <stdarg.h>
-
#include "general.h"
#include "gdb_if.h"
#include "gdb_packet.h"
#include "hex_utils.h"
-int
-gdb_getpacket(unsigned char *packet, int size)
+#include <stdarg.h>
+
+int gdb_getpacket(char *packet, int size)
{
unsigned char c;
unsigned char csum;
@@ -54,9 +48,9 @@ gdb_getpacket(unsigned char *packet, int size)
if(i == size) break; /* Oh shit */
if(c == '$') { /* Restart capture */
- i = 0;
- csum = 0;
- continue;
+ i = 0;
+ csum = 0;
+ continue;
}
if(c == '}') { /* escaped char */
c = gdb_if_getchar();
@@ -70,7 +64,7 @@ gdb_getpacket(unsigned char *packet, int size)
recv_csum[0] = gdb_if_getchar();
recv_csum[1] = gdb_if_getchar();
recv_csum[2] = 0;
-
+
/* return packet if checksum matches */
if(csum == strtol(recv_csum, NULL, 16)) break;
@@ -84,7 +78,7 @@ gdb_getpacket(unsigned char *packet, int size)
DEBUG("%s : ", __func__);
for(int j = 0; j < i; j++) {
c = packet[j];
- if ((c >= 32) && (c < 127))
+ if ((c >= 32) && (c < 127))
DEBUG("%c", c);
else
DEBUG("\\x%02X", c);
@@ -94,14 +88,14 @@ gdb_getpacket(unsigned char *packet, int size)
return i;
}
-void gdb_putpacket(unsigned char *packet, int size)
+void gdb_putpacket(const char *packet, int size)
{
int i;
unsigned char csum;
unsigned char c;
char xmit_csum[3];
int tries = 0;
-
+
do {
#ifdef DEBUG_GDBPACKET
DEBUG("%s : ", __func__);
@@ -111,7 +105,7 @@ void gdb_putpacket(unsigned char *packet, int size)
for(i = 0; i < size; i++) {
c = packet[i];
#ifdef DEBUG_GDBPACKET
- if ((c >= 32) && (c < 127))
+ if ((c >= 32) && (c < 127))
DEBUG("%c", c);
else
DEBUG("\\x%02X", c);
@@ -135,7 +129,7 @@ void gdb_putpacket(unsigned char *packet, int size)
} while((gdb_if_getchar_to(2000) != '+') && (tries++ < 3));
}
-void gdb_putpacket_f(const unsigned char *fmt, ...)
+void gdb_putpacket_f(const char *fmt, ...)
{
va_list ap;
char *buf;
@@ -165,7 +159,8 @@ void gdb_outf(const char *fmt, ...)
char *buf;
va_start(ap, fmt);
- vasprintf(&buf, fmt, ap);
+ if (vasprintf(&buf, fmt, ap) < 0)
+ return;
gdb_out(buf);
free(buf);
va_end(ap);