Remove duplicate code paths for stepping/typing-into the debugger

This commit is contained in:
Aaron Culliney 2016-07-03 14:46:52 -07:00
parent b62f5e9e7f
commit 4ca642a715
3 changed files with 21 additions and 52 deletions

View File

@ -85,6 +85,7 @@ extern const struct opcode_struct *opcodes;
void c_interface_debugging(); void c_interface_debugging();
#endif #endif
void debugger_setInputText(const char *text);
void c_debugger_go(void); void c_debugger_go(void);
bool c_debugger_should_break(void); bool c_debugger_should_break(void);
void c_debugger_set_timeout(const unsigned int secs); void c_debugger_set_timeout(const unsigned int secs);

View File

@ -32,6 +32,8 @@
const struct opcode_struct *opcodes; const struct opcode_struct *opcodes;
static char input_str[1024] = { 0 }; // ASCII values
static stepping_struct_t stepping_struct = { 0 }; static stepping_struct_t stepping_struct = { 0 };
static unsigned int stepping_timeout = 0; static unsigned int stepping_timeout = 0;
@ -1153,16 +1155,12 @@ static int begin_cpu_stepping() {
ERRLOG("pthread_cond_wait : %d", err); ERRLOG("pthread_cond_wait : %d", err);
} }
#if TESTING #if defined(INTERFACE_CLASSIC)
#warning FIXME TODO : this is mis-named now ... GLVideo pushes sync state so we do not need to force poll ... but we need this to type the testing strings ... should refactor to leverage a common codepath, preferablly using the 'typing' mechanism here...
extern void testing_video_sync();
testing_video_sync();
#elif defined(INTERFACE_CLASSIC)
if ((ch = c_mygetch(0)) != -1) { if ((ch = c_mygetch(0)) != -1) {
break; break;
} }
#endif #endif
if ( (stepping_struct.step_type != TYPING) && (idx > textlen) ) { if ( (stepping_struct.step_type == TYPING) && (idx > textlen) ) {
break; // finished typing break; // finished typing
} }
if (stepping_timeout && (stepping_struct.timeout < time(NULL))) { if (stepping_timeout && (stepping_struct.timeout < time(NULL))) {
@ -1495,9 +1493,19 @@ void c_interface_debugging() {
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
debugger testing-driven API debugger testing-driven API
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void debugger_setInputText(const char *text) {
strcat(input_str, text);
}
void c_debugger_go(void) {
void *buf = NULL;
if (strlen(input_str)) {
buf = STRDUP(input_str);
input_str[0] = '\0';
}
void c_debugger_go() {
stepping_struct_t s = (stepping_struct_t){ stepping_struct_t s = (stepping_struct_t){
.step_text = buf,
.step_type = GOING, .step_type = GOING,
.timeout = time(NULL) + stepping_timeout .timeout = time(NULL) + stepping_timeout
}; };
@ -1507,6 +1515,8 @@ void c_debugger_go() {
debugger_go(s); debugger_go(s);
FREE(buf);
is_debugging = false; is_debugging = false;
num_buffer_lines = 0; num_buffer_lines = 0;
} }

View File

@ -11,58 +11,18 @@
#include "testcommon.h" #include "testcommon.h"
#define TESTBUF_SZ 1024
bool test_do_reboot = true; bool test_do_reboot = true;
char mdstr[(SHA_DIGEST_LENGTH*2)+1]; char mdstr[(SHA_DIGEST_LENGTH*2)+1];
static char input_str[TESTBUF_SZ]; // ASCII
static unsigned int input_length = 0;
static unsigned int input_counter = 0;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void test_common_setup() { void test_common_setup(void) {
input_counter = 0;
input_length = 0;
input_str[0] = '\0';
}
// ----------------------------------------------------------------------------
// test video functions and stubs
void testing_video_sync() {
if (!input_length) {
input_length = strlen(input_str);
}
if (input_counter >= input_length) {
return;
}
uint8_t ch = (uint8_t)input_str[input_counter];
if (ch == '\n') {
ch = '\r';
}
if ( (apple_ii_64k[0][0xC000] & 0x80) || (apple_ii_64k[1][0xC000] & 0x80) ) {
// last character typed not processed by emulator...
return;
}
apple_ii_64k[0][0xC000] = ch | 0x80;
apple_ii_64k[1][0xC000] = ch | 0x80;
++input_counter;
} }
void test_type_input(const char *input) { void test_type_input(const char *input) {
strcat(input_str, input); debugger_setInputText(input);
} }
// ----------------------------------------------------------------------------
void test_breakpoint(void *arg) { void test_breakpoint(void *arg) {
fprintf(GREATEST_STDOUT, "DISPLAY NOTE: busy-spinning in test_breakpoint(), needs gdb/lldb intervention to continue...\n"); fprintf(GREATEST_STDOUT, "DISPLAY NOTE: busy-spinning in test_breakpoint(), needs gdb/lldb intervention to continue...\n");
volatile bool debug_continue = false; volatile bool debug_continue = false;
@ -72,9 +32,7 @@ void test_breakpoint(void *arg) {
} }
} }
// ---------------------------------------------------------------------------- void test_common_init(void) {
void test_common_init() {
GREATEST_SET_BREAKPOINT_CB(test_breakpoint, NULL); GREATEST_SET_BREAKPOINT_CB(test_breakpoint, NULL);
do_logging = false;// silence regular emulator logging do_logging = false;// silence regular emulator logging