cleanup to test build issue

This commit is contained in:
Dagen Brock 2017-01-22 19:13:18 -06:00
parent 35daae6815
commit b9eb3fde74

View File

@ -153,9 +153,9 @@ do_go_debug()
clear_halt(); clear_halt();
printf("calling run_prog()\n"); glog("calling run_prog()");
run_prog(); // also calls debug_server_poll() run_prog(); // also calls debug_server_poll()
printf("left run_prog()\n"); glog("left run_prog()");
step_count++; step_count++;
// so this is a break... // so this is a break...
@ -187,22 +187,20 @@ void debug_pop_message() {
// adds message to end of queue and ups the counter // adds message to end of queue and ups the counter
void debug_push_message(G_DBG_COMMANDS msg_type, char *msg_ptr, int msg_len) { void debug_push_message(G_DBG_COMMANDS msg_type, char *msg_ptr, int msg_len) {
printf("GOT: %d\n", (int) msg_type); glogf("debug_push_message() GOT: %d", (int) msg_type);
dbg_cmd_queue[dbg_cmd_queue_len].command = msg_type; dbg_cmd_queue[dbg_cmd_queue_len].command = msg_type;
memcpy(dbg_cmd_queue[dbg_cmd_queue_len].cdata, msg_ptr, msg_len); // stripping that first char memcpy(dbg_cmd_queue[dbg_cmd_queue_len].cdata, msg_ptr, msg_len); // stripping that first char
dbg_cmd_queue[dbg_cmd_queue_len].cdata[msg_len+1] = '\0'; // terminator dbg_cmd_queue[dbg_cmd_queue_len].cdata[msg_len+1] = '\0'; // terminator
dbg_cmd_queue_len++; // INC POINTER dbg_cmd_queue_len++; // INC POINTER
} }
// this should be sufficient :P // this should be sufficient
int debug_events_waiting() { int debug_events_waiting() {
//printf("dbg_cmd_queue_len: %d\n", dbg_cmd_queue_len);
return dbg_cmd_queue_len; return dbg_cmd_queue_len;
} }
// handle event onfront of queue and remove it // handle event onfront of queue and remove it
void debug_handle_event() void debug_handle_event() {
{
while (debug_events_waiting() > 0) { while (debug_events_waiting() > 0) {
switch (dbg_cmd_queue[0].command) { switch (dbg_cmd_queue[0].command) {
case G_DBG_COMMAND_TEST: //0 case G_DBG_COMMAND_TEST: //0
@ -262,28 +260,25 @@ void debug_handle_event()
} }
} }
void push_api_msg(int size, char *msg_str) void push_api_msg(int size, char *msg_str) {
{
if (dbg_msg_queue_len < DBG_MSG_QUEUE_MAXLEN) { if (dbg_msg_queue_len < DBG_MSG_QUEUE_MAXLEN) {
dbg_msg_queue[dbg_msg_queue_len].msg_size = size; dbg_msg_queue[dbg_msg_queue_len].msg_size = size;
dbg_msg_queue[dbg_msg_queue_len].msg_str = msg_str; dbg_msg_queue[dbg_msg_queue_len].msg_str = msg_str;
//printf("Latest message : \n%s\n", dbg_msg_queue[dbg_msg_queue_len].msg_str); //printf("Latest message : \n%s\n", dbg_msg_queue[dbg_msg_queue_len].msg_str);
dbg_msg_queue_len++; // INC POINTER dbg_msg_queue_len++; // INC POINTER
} else { } else {
printf("ABORT! MESSAGE QUEUE FULL!\n"); glog("ABORT! Message dropped because dbg_msg_queue is full.");
} }
} }
void api_push_memack() void api_push_memack() {
{
int size = snprintf(tmp_buffer_4k, sizeof(tmp_buffer_4k),"{\"type\":\"memack\"}"); int size = snprintf(tmp_buffer_4k, sizeof(tmp_buffer_4k),"{\"type\":\"memack\"}");
char *msg = (char*)malloc(sizeof(char) * size); char *msg = (char*)malloc(sizeof(char) * size);
strcpy(msg,tmp_buffer_4k); strcpy(msg,tmp_buffer_4k);
push_api_msg(size, msg); push_api_msg(size, msg);
} }
void api_push_cpu() void api_push_cpu() {
{
Engine_reg *eptr; Engine_reg *eptr;
eptr = &engine; eptr = &engine;
int tmp_acc, tmp_x, tmp_y, tmp_psw; int tmp_acc, tmp_x, tmp_y, tmp_psw;
@ -307,8 +302,7 @@ void api_push_cpu()
push_api_msg(size, msg); push_api_msg(size, msg);
} }
void api_push_brk() void api_push_brk() {
{
int i; int i;
// build our json array of breakpoints // build our json array of breakpoints
tmp_buffer2_4k[0] = '\0'; // start with empty string tmp_buffer2_4k[0] = '\0'; // start with empty string
@ -330,8 +324,7 @@ void api_push_brk()
} }
void api_push_stack() void api_push_stack() {
{
Engine_reg *eptr; Engine_reg *eptr;
eptr = &engine; eptr = &engine;
int kpc, stack; int kpc, stack;
@ -360,8 +353,7 @@ void api_push_stack()
} }
void api_push_disassembly_start() void api_push_disassembly_start() {
{
int size = snprintf(tmp_buffer_4k, sizeof(tmp_buffer_4k),"{\"type\":\"dis0\"}"); int size = snprintf(tmp_buffer_4k, sizeof(tmp_buffer_4k),"{\"type\":\"dis0\"}");
char *msg = (char*)malloc(sizeof(char) * size); char *msg = (char*)malloc(sizeof(char) * size);
strcpy(msg,tmp_buffer_4k); strcpy(msg,tmp_buffer_4k);
@ -369,8 +361,7 @@ void api_push_disassembly_start()
} }
void api_push_disassembly() void api_push_disassembly() {
{
int byte_size; int byte_size;
int size_mem_imm, size_x_imm; int size_mem_imm, size_x_imm;
@ -400,8 +391,7 @@ void api_push_disassembly()
} }
} }
void api_push_disassembly_chain() void api_push_disassembly_chain() {
{
int byte_size; int byte_size;
int size_mem_imm, size_x_imm; int size_mem_imm, size_x_imm;
@ -423,18 +413,7 @@ void api_push_disassembly_chain()
} }
void api_push_dump(int bank, int start, int end) void api_push_dump(int bank, int start, int end) {
{
// printf("YAY! %s\n",str );
// printf("BANK %02X : %04X - %04X\n", bank, start, end);
//
// const char foostr[] = "Bleep Blop Bloop!";
// int l = b64encode_len(strlen(foostr));
// char *msg = (char*)malloc(sizeof(char) * l);
// //int b64encode(char *encoded, const char *string, int len)
// int num = b64encode(msg, foostr, l);
// printf("b64: %s\n", msg);
char *post_str = "\"}}"; char *post_str = "\"}}";
int pre_size = snprintf(tmp_buffer_4k, sizeof(tmp_buffer_4k), int pre_size = snprintf(tmp_buffer_4k, sizeof(tmp_buffer_4k),
"{\"type\":\"mem\",\"data\":{\"bank\":\"%02X\",\"start\":\"%04X\",\"end\":\"%04X\",\"b64data\":\"", "{\"type\":\"mem\",\"data\":{\"bank\":\"%02X\",\"start\":\"%04X\",\"end\":\"%04X\",\"b64data\":\"",
@ -466,14 +445,12 @@ void api_push_dump(int bank, int start, int end)
} }
} }
void event_cpu_info() void event_cpu_info() {
{
api_push_cpu(); api_push_cpu();
api_write_socket(); api_write_socket();
} }
void event_pause() void event_pause() {
{
if (debug_pause) { if (debug_pause) {
// UNPAUSE // UNPAUSE
debug_pause = 0; debug_pause = 0;
@ -492,8 +469,7 @@ void event_pause()
// test command stubs for more interactive testing // test command stubs for more interactive testing
void event_test_command(char *str) void event_test_command(char *str) {
{
int addr = 0; int addr = 0;
sscanf(str, "%06X", &addr); sscanf(str, "%06X", &addr);
int foo = get_byte_at_address(addr); int foo = get_byte_at_address(addr);
@ -501,15 +477,13 @@ void event_test_command(char *str)
set_byte_at_address(addr,foo); set_byte_at_address(addr,foo);
} }
void event_test_command_bankptr(char *str) void event_test_command_bankptr(char *str) {
{
int bank = 0; int bank = 0;
sscanf(str, "%02X", &bank); sscanf(str, "%02X", &bank);
show_bankptrs(bank); show_bankptrs(bank);
} }
void event_hello() void event_hello() {
{
api_push_stack(); api_push_stack();
api_push_cpu(); api_push_cpu();
api_push_disassembly(); api_push_disassembly();
@ -518,8 +492,7 @@ void event_hello()
api_write_socket(); api_write_socket();
} }
void event_did_step(int step_count) void event_did_step(int step_count) {
{
api_push_stack(); api_push_stack();
api_push_cpu(); api_push_cpu();
api_push_disassembly(); api_push_disassembly();
@ -530,8 +503,7 @@ void event_did_step(int step_count)
} }
void event_get_mem(char *str) void event_get_mem(char *str) {
{
unsigned int bank = 0; unsigned int bank = 0;
unsigned int start = 0; unsigned int start = 0;
unsigned int end = 0; unsigned int end = 0;
@ -547,8 +519,8 @@ void event_get_mem(char *str)
} }
void handle_set_bytes(int address, char *bytes_data)
{ void handle_set_bytes(int address, char *bytes_data) {
int byte; int byte;
while (sscanf(bytes_data, "%02x", &byte) == 1) { while (sscanf(bytes_data, "%02x", &byte) == 1) {
printf("$%02x <---- BYTE @ $%06X\n", byte, address ); printf("$%02x <---- BYTE @ $%06X\n", byte, address );
@ -559,9 +531,7 @@ void handle_set_bytes(int address, char *bytes_data)
} }
/// HERE Zzzzzzzz void event_set_mem(char *str) {
void event_set_mem(char *str)
{
int address = 0; int address = 0;
char *bytes_data = NULL; char *bytes_data = NULL;
@ -584,10 +554,9 @@ void event_set_mem(char *str)
} }
void handle_emu_cmd(char cmd_char, char *cmd_data) void handle_emu_cmd(char cmd_char, char *cmd_data) {
{
int int_value = 0; // reuseable variable int int_value = 0; // reuseable variable
//printf("CMD: %c\tDATA: %s\n", cmd_char, cmd_data);
switch (cmd_char) { switch (cmd_char) {
// f = fullscreen // f = fullscreen
case 'f': case 'f':
@ -610,8 +579,7 @@ void handle_emu_cmd(char cmd_char, char *cmd_data)
} }
} }
void event_emu_cmd(char *str) void event_emu_cmd(char *str) {
{
// split our commands on spaces // split our commands on spaces
char cmd_char = '\0'; char cmd_char = '\0';
char *cmd_data = NULL; char *cmd_data = NULL;
@ -634,8 +602,7 @@ void event_emu_cmd(char *str)
} }
void event_add_brk(char *str) void event_add_brk(char *str) {
{
int addr = 0; int addr = 0;
sscanf(str, "%06X", &addr); sscanf(str, "%06X", &addr);
addr = addr & 0xFFFFFF; // 24 bit KPC address for 65816 addr = addr & 0xFFFFFF; // 24 bit KPC address for 65816
@ -646,8 +613,8 @@ void event_add_brk(char *str)
return; return;
} }
void event_del_brk(char *str)
{ void event_del_brk(char *str) {
int addr = 0; int addr = 0;
sscanf(str, "%06X", &addr); sscanf(str, "%06X", &addr);
addr = addr & 0xFFFFFF; // 24 bit KPC address for 65816 addr = addr & 0xFFFFFF; // 24 bit KPC address for 65816
@ -658,8 +625,8 @@ void event_del_brk(char *str)
return; return;
} }
void event_get_brk(char *str)
{ void event_get_brk(char *str) {
api_push_brk(); api_push_brk();
api_write_socket(); api_write_socket();
@ -667,9 +634,7 @@ void event_get_brk(char *str)
} }
void handle_cpu_cmd(char cmd_char, char *cmd_data) {
void handle_cpu_cmd(char cmd_char, char *cmd_data)
{
Engine_reg *eptr; Engine_reg *eptr;
eptr = &engine; eptr = &engine;
int new_acc, new_x, new_y; int new_acc, new_x, new_y;
@ -723,16 +688,14 @@ void handle_cpu_cmd(char cmd_char, char *cmd_data)
} }
void event_set_cpu(char *str) void event_set_cpu(char *str) {
{
// split our commands on spaces // split our commands on spaces
char cmd_char = '\0'; char cmd_char = '\0';
char *cmd_data = NULL; char *cmd_data = NULL;
char * pch; char * pch;
pch = strtok (str," "); pch = strtok (str," ");
while (pch != NULL) while (pch != NULL) {
{
cmd_char = pch[0]; cmd_char = pch[0];
cmd_data = pch+1; cmd_data = pch+1;
if (cmd_data[0] == '\0') { if (cmd_data[0] == '\0') {
@ -753,8 +716,7 @@ void event_set_cpu(char *str)
void debug_init() void debug_init() {
{
if (g_dbg_enable_port > 0) { if (g_dbg_enable_port > 0) {
// g_dbg_enable_port should be enabled by // g_dbg_enable_port should be enabled by
glogf("Debug port enabled on: %d", g_dbg_enable_port); glogf("Debug port enabled on: %d", g_dbg_enable_port);
@ -769,8 +731,7 @@ void debug_init()
} }
void debug_setup_socket() void debug_setup_socket() {
{
/*************************************************************/ /*************************************************************/
/* Create an AF_INET stream socket to receive incoming */ /* Create an AF_INET stream socket to receive incoming */
/* connections on */ /* connections on */
@ -823,8 +784,7 @@ void debug_setup_socket()
/* Set the listen back log */ /* Set the listen back log */
/*************************************************************/ /*************************************************************/
rc = listen(listen_sd, 32); rc = listen(listen_sd, 32);
if (rc < 0) if (rc < 0) {
{
perror("listen() failed"); perror("listen() failed");
close(listen_sd); close(listen_sd);
exit(-1); exit(-1);
@ -850,8 +810,7 @@ void debug_setup_socket()
} }
// builds our big json array of commands eg "[{},{},{},...]" // builds our big json array of commands eg "[{},{},{},...]"
void api_write_socket() void api_write_socket() {
{
const char *comma = ","; const char *comma = ",";
const char *lbrack = "["; const char *lbrack = "[";
const char *rbrack = "]\r\n\r\n"; const char *rbrack = "]\r\n\r\n";
@ -882,22 +841,19 @@ void api_write_socket()
free(message_string); // assuming it was all written :P free(message_string); // assuming it was all written :P
} }
void write_array_start() void write_array_start() {
{
const char *brack = "["; const char *brack = "[";
write(debugger_sd, brack, strlen(brack)); write(debugger_sd, brack, strlen(brack));
} }
void write_array_end() void write_array_end() {
{
const char *brack = "]\r\n\r\n"; const char *brack = "]\r\n\r\n";
write(debugger_sd, brack, strlen(brack)); write(debugger_sd, brack, strlen(brack));
} }
void write_array_next() void write_array_next() {
{
const char *com = ", "; // i'm so neat const char *com = ", "; // i'm so neat
write(debugger_sd, com, strlen(com)); write(debugger_sd, com, strlen(com));
} }
@ -905,8 +861,7 @@ void write_array_next()
// // write(debugger_sd, buffer, strlen(buffer)); // // write(debugger_sd, buffer, strlen(buffer));
//also for base 64 http://stackoverflow.com/questions/342409/how-do-i-base64-encode-decode-in-c //also for base 64 http://stackoverflow.com/questions/342409/how-do-i-base64-encode-decode-in-c
//http://stackoverflow.com/questions/32749925/sending-a-file-over-a-tcp-ip-socket-web-server //http://stackoverflow.com/questions/32749925/sending-a-file-over-a-tcp-ip-socket-web-server
int writeDataToClient(int sckt, const void *data, int datalen) int writeDataToClient(int sckt, const void *data, int datalen) {
{
const char *pdata = (const char*) data; const char *pdata = (const char*) data;
while (datalen > 0){ while (datalen > 0){
@ -927,14 +882,12 @@ int writeDataToClient(int sckt, const void *data, int datalen)
} }
int writeStrToClient(int sckt, const char *str) int writeStrToClient(int sckt, const char *str) {
{
return writeDataToClient(sckt, str, strlen(str)); return writeDataToClient(sckt, str, strlen(str));
} }
// @todo: probably clean up- this was a hack to allow preloading commands // @todo: probably clean up- this was a hack to allow preloading commands
void debug_wait_hello() void debug_wait_hello() {
{
int hello_received = FALSE; int hello_received = FALSE;
timeout = 1000; // 1 sec timeout = 1000; // 1 sec
while (hello_received == FALSE) { while (hello_received == FALSE) {
@ -951,8 +904,7 @@ void debug_wait_hello()
timeout = 0; // instantaneous timeout = 0; // instantaneous
} }
void debug_server_poll() void debug_server_poll() {
{
if (end_server == FALSE) { if (end_server == FALSE) {
/***********************************************************/ /***********************************************************/
/* Call poll() and wait for it to complete/timeout. */ /* Call poll() and wait for it to complete/timeout. */
@ -995,7 +947,7 @@ void debug_server_poll()
/* log and end the server. */ /* log and end the server. */
/*********************************************************/ /*********************************************************/
if(fds[i].revents != POLLIN) { if(fds[i].revents != POLLIN) {
printf(" Error! revents = %d\n", fds[i].revents); glogf("Error! revents = %d", fds[i].revents);
end_server = TRUE; end_server = TRUE;
break; break;
} }
@ -1004,7 +956,7 @@ void debug_server_poll()
/*******************************************************/ /*******************************************************/
/* Listening descriptor is readable. */ /* Listening descriptor is readable. */
/*******************************************************/ /*******************************************************/
printf(" Listening socket is readable\n"); glog("Listening socket is readable");
/*******************************************************/ /*******************************************************/
/* Accept all incoming connections that are */ /* Accept all incoming connections that are */
@ -1032,7 +984,7 @@ void debug_server_poll()
/* Add the new incoming connection to the */ /* Add the new incoming connection to the */
/* pollfd structure */ /* pollfd structure */
/*****************************************************/ /*****************************************************/
glogf(" New incoming connection - %d\n", new_sd); glogf("New incoming connection - %d", new_sd);
fds[nfds].fd = new_sd; fds[nfds].fd = new_sd;
fds[nfds].events = POLLIN; fds[nfds].events = POLLIN;
nfds++; nfds++;
@ -1070,8 +1022,7 @@ void debug_server_poll()
/*****************************************************/ /*****************************************************/
rc = recv(fds[i].fd, buffer, sizeof(buffer), 0); rc = recv(fds[i].fd, buffer, sizeof(buffer), 0);
if (rc < 0) { if (rc < 0) {
if (errno != EWOULDBLOCK) if (errno != EWOULDBLOCK) {
{
perror(" recv() failed"); perror(" recv() failed");
close_conn = TRUE; close_conn = TRUE;
} }
@ -1156,12 +1107,12 @@ void debug_server_poll()
break; break;
default: default:
printf("UNKNOWN COMMAND - DISCARDED\n"); glog("UNKNOWN COMMAND - DISCARDED");
} }
} else { } else {
printf("COMMAND QUEUE FULL! ABORT!\n"); glog("COMMAND QUEUE FULL! ABORT!");
// @TODO probably send error response // @TODO probably send error response
} }