* Style cleanup.
* gdb.c -> gdb.cpp git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30025 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -14,7 +14,7 @@ KernelMergeObject kernel_debug.o :
|
|||||||
debug_parser.cpp
|
debug_parser.cpp
|
||||||
debug_variables.cpp
|
debug_variables.cpp
|
||||||
frame_buffer_console.cpp
|
frame_buffer_console.cpp
|
||||||
gdb.c
|
gdb.cpp
|
||||||
tracing.cpp
|
tracing.cpp
|
||||||
user_debugger.cpp
|
user_debugger.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,12 @@
|
|||||||
enum { INIT = 0, CMDREAD, CKSUM1, CKSUM2, WAITACK, QUIT, GDBSTATES };
|
enum { INIT = 0, CMDREAD, CKSUM1, CKSUM2, WAITACK, QUIT, GDBSTATES };
|
||||||
|
|
||||||
|
|
||||||
static char cmd[512];
|
static char sCommand[512];
|
||||||
static int cmd_ptr;
|
static int sCommandIndex;
|
||||||
static int checksum;
|
static int sCheckSum;
|
||||||
|
|
||||||
static char reply[512];
|
static char sReply[512];
|
||||||
|
static char sSafeMemory[512];
|
||||||
static char safe_mem[512];
|
|
||||||
|
|
||||||
|
|
||||||
// utility functions
|
// utility functions
|
||||||
@@ -75,81 +74,77 @@ gdb_nak(void)
|
|||||||
static void
|
static void
|
||||||
gdb_resend_reply(void)
|
gdb_resend_reply(void)
|
||||||
{
|
{
|
||||||
arch_debug_serial_puts(reply);
|
arch_debug_serial_puts(sReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gdb_reply(char const *fmt, ...)
|
gdb_reply(char const* format, ...)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len;
|
int len;
|
||||||
int sum;
|
int sum;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, format);
|
||||||
reply[0] = '$';
|
sReply[0] = '$';
|
||||||
vsprintf(reply + 1, fmt, args);
|
vsprintf(sReply + 1, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
len = strlen(reply);
|
len = strlen(sReply);
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (i = 1; i < len; i++) {
|
for (i = 1; i < len; i++) {
|
||||||
sum += reply[i];
|
sum += sReply[i];
|
||||||
}
|
}
|
||||||
sum %= 256;
|
sum %= 256;
|
||||||
|
|
||||||
sprintf(reply + len, "#%02x", sum);
|
sprintf(sReply + len, "#%02x", sum);
|
||||||
|
|
||||||
gdb_resend_reply();
|
gdb_resend_reply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gdb_regreply(int const *regs, int numregs)
|
gdb_regreply(int const* regs, int numregs)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len;
|
int len;
|
||||||
int sum;
|
int sum;
|
||||||
|
|
||||||
reply[0] = '$';
|
sReply[0] = '$';
|
||||||
for (i = 0; i < numregs; i++) {
|
for (i = 0; i < numregs; i++)
|
||||||
sprintf(reply+1+8*i, "%08lx", B_HOST_TO_BENDIAN_INT32(regs[i]));
|
sprintf(sReply + 1 + 8 * i, "%08lx", B_HOST_TO_BENDIAN_INT32(regs[i]));
|
||||||
}
|
|
||||||
|
|
||||||
len = strlen(reply);
|
len = strlen(sReply);
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (i = 1; i < len; i++) {
|
for (i = 1; i < len; i++)
|
||||||
sum += reply[i];
|
sum += sReply[i];
|
||||||
}
|
|
||||||
sum %= 256;
|
sum %= 256;
|
||||||
|
|
||||||
sprintf(reply + len, "#%02x", sum);
|
sprintf(sReply + len, "#%02x", sum);
|
||||||
|
|
||||||
gdb_resend_reply();
|
gdb_resend_reply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gdb_memreply(char const *bytes, int numbytes)
|
gdb_memreply(char const* bytes, int numbytes)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int len;
|
int len;
|
||||||
int sum;
|
int sum;
|
||||||
|
|
||||||
reply[0] = '$';
|
sReply[0] = '$';
|
||||||
for (i = 0; i < numbytes; i++) {
|
for (i = 0; i < numbytes; i++)
|
||||||
sprintf(reply+1+2*i, "%02x", (uint8)bytes[i]);
|
sprintf(sReply + 1 + 2 * i, "%02x", (uint8)bytes[i]);
|
||||||
}
|
|
||||||
|
|
||||||
len = strlen(reply);
|
len = strlen(sReply);
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (i = 1; i < len; i++) {
|
for (i = 1; i < len; i++)
|
||||||
sum += reply[i];
|
sum += sReply[i];
|
||||||
}
|
|
||||||
sum %= 256;
|
sum %= 256;
|
||||||
|
|
||||||
sprintf(reply + len, "#%02x", sum);
|
sprintf(sReply + len, "#%02x", sum);
|
||||||
|
|
||||||
gdb_resend_reply();
|
gdb_resend_reply();
|
||||||
}
|
}
|
||||||
@@ -165,14 +160,13 @@ gdb_verify_checksum(void)
|
|||||||
int len;
|
int len;
|
||||||
int sum;
|
int sum;
|
||||||
|
|
||||||
len = strlen(cmd);
|
len = strlen(sCommand);
|
||||||
sum = 0;
|
sum = 0;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++)
|
||||||
sum += cmd[i];
|
sum += sCommand[i];
|
||||||
}
|
|
||||||
sum %= 256;
|
sum %= 256;
|
||||||
|
|
||||||
return (sum == checksum) ? 1 : 0;
|
return (sum == sCheckSum) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -188,7 +182,7 @@ gdb_parse_command(void)
|
|||||||
} else
|
} else
|
||||||
gdb_ack();
|
gdb_ack();
|
||||||
|
|
||||||
switch (cmd[0]) {
|
switch (sCommand[0]) {
|
||||||
case 'H':
|
case 'H':
|
||||||
/*
|
/*
|
||||||
* Command H (actually Hct) is used to select
|
* Command H (actually Hct) is used to select
|
||||||
@@ -222,10 +216,10 @@ gdb_parse_command(void)
|
|||||||
* pre-links at 0x80000000. To keep gdb
|
* pre-links at 0x80000000. To keep gdb
|
||||||
* gdb happy we just substract that amount.
|
* gdb happy we just substract that amount.
|
||||||
*/
|
*/
|
||||||
if (strcmp(cmd+1, "Offsets") == 0) {
|
if (strcmp(sCommand + 1, "Offsets") == 0) {
|
||||||
gdb_reply("Text=%x;Data=%x;Bss=%x", 0,
|
gdb_reply("Text=%x;Data=%x;Bss=%x", 0,
|
||||||
((unsigned)(&__data_start))-0x80000000,
|
((unsigned)(&__data_start)) - 0x80000000,
|
||||||
((unsigned)(&__bss_start))-0x80000000);
|
((unsigned)(&__bss_start)) - 0x80000000);
|
||||||
} else
|
} else
|
||||||
gdb_reply("ENS");
|
gdb_reply("ENS");
|
||||||
}
|
}
|
||||||
@@ -269,7 +263,7 @@ gdb_parse_command(void)
|
|||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
{
|
{
|
||||||
char *ptr;
|
char* ptr;
|
||||||
unsigned address;
|
unsigned address;
|
||||||
unsigned len;
|
unsigned len;
|
||||||
|
|
||||||
@@ -278,7 +272,7 @@ gdb_parse_command(void)
|
|||||||
* where AAA is the address and LLL is the
|
* where AAA is the address and LLL is the
|
||||||
* number of bytes.
|
* number of bytes.
|
||||||
*/
|
*/
|
||||||
ptr = cmd+1;
|
ptr = sCommand + 1;
|
||||||
address = 0;
|
address = 0;
|
||||||
len = 0;
|
len = 0;
|
||||||
while (ptr && *ptr && (*ptr != ',')) {
|
while (ptr && *ptr && (*ptr != ',')) {
|
||||||
@@ -287,7 +281,7 @@ gdb_parse_command(void)
|
|||||||
ptr += 1;
|
ptr += 1;
|
||||||
}
|
}
|
||||||
if (*ptr == ',')
|
if (*ptr == ',')
|
||||||
ptr+= 1;
|
ptr += 1;
|
||||||
|
|
||||||
while (ptr && *ptr) {
|
while (ptr && *ptr) {
|
||||||
len <<= 4;
|
len <<= 4;
|
||||||
@@ -295,7 +289,7 @@ gdb_parse_command(void)
|
|||||||
ptr += 1;
|
ptr += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len> 128)
|
if (len > 128)
|
||||||
len = 128;
|
len = 128;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -304,10 +298,10 @@ gdb_parse_command(void)
|
|||||||
* We copy the memory to a safe buffer using
|
* We copy the memory to a safe buffer using
|
||||||
* the bulletproof user_memcpy().
|
* the bulletproof user_memcpy().
|
||||||
*/
|
*/
|
||||||
if (user_memcpy(safe_mem, (char *)address, len) < 0)
|
if (user_memcpy(sSafeMemory, (char*)address, len) < 0)
|
||||||
gdb_reply("E02");
|
gdb_reply("E02");
|
||||||
else
|
else
|
||||||
gdb_memreply(safe_mem, len);
|
gdb_memreply(sSafeMemory, len);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -340,8 +334,8 @@ gdb_init_handler(int input)
|
|||||||
{
|
{
|
||||||
switch (input) {
|
switch (input) {
|
||||||
case '$':
|
case '$':
|
||||||
memset(cmd, 0, sizeof(cmd));
|
memset(sCommand, 0, sizeof(sCommand));
|
||||||
cmd_ptr = 0;
|
sCommandIndex = 0;
|
||||||
return CMDREAD;
|
return CMDREAD;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -368,8 +362,8 @@ gdb_cmdread_handler(int input)
|
|||||||
return CKSUM1;
|
return CKSUM1;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cmd[cmd_ptr] = input;
|
sCommand[sCommandIndex] = input;
|
||||||
cmd_ptr += 1;
|
sCommandIndex += 1;
|
||||||
return CMDREAD;
|
return CMDREAD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -394,7 +388,7 @@ gdb_cksum1_handler(int input)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
checksum = nibble << 4;
|
sCheckSum = nibble << 4;
|
||||||
|
|
||||||
return CKSUM2;
|
return CKSUM2;
|
||||||
}
|
}
|
||||||
@@ -419,7 +413,7 @@ gdb_cksum2_handler(int input)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
checksum += nibble;
|
sCheckSum += nibble;
|
||||||
|
|
||||||
return gdb_parse_command();
|
return gdb_parse_command();
|
||||||
}
|
}
|
||||||
@@ -497,7 +491,7 @@ gdb_state_machine(void)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
cmd_gdb(int argc, char **argv)
|
cmd_gdb(int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void)(argc);
|
(void)(argc);
|
||||||
(void)(argv);
|
(void)(argv);
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
#endif
|
#endif
|
||||||
int cmd_gdb(int, char **);
|
|
||||||
|
int cmd_gdb(int argc, char** argv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user