// main debugger loop int bf_debugger( bf_code_t *bf ){ bf_code_t *dbf = bf; //bf_code_t *dbf = new( bf_code_t ); //memcpy( dbf, bf, sizeof( bf_code_t )); char buf[256]; int lret = 0; int broke; bfid_brkp_t *temp; bfid_cmd_hook_t *hook; if ( !bfid_initialized ) bfid_init( ); dbf->debugging = 1; interrupted = 1; signal( SIGINT, (__sighandler_t)debug_signal ); printf( "[>] yabi debugger v0.99\n" ); while ( dbf->debugging ){ if ( interrupted ){ if ( lret ) printf( "[%d] ", lret ); else printf( "[ ] " ); printf( "> " ); fgets( buf, 256, stdin ); if ( strlen( buf ) < 2 ) continue; if (( lret = bfid_execcmd( dbf, buf )) < 0 ) printf( "Unknown command.\n" ); } else { if ( dbf->ip < dbf->codesize ){ bf_step( dbf ); for ( temp = brkp_list; temp; temp = temp->next ){ broke = 0; if ( temp->type == BRK_IP && temp->val == dbf->ip ){ interrupted = broke = 1; } else if ( temp->type == BRK_MEM && temp->val == dbf->ptr ){ interrupted = broke = 1; } else if ( temp->type == BRK_INSTR && temp->val == dbf->code[ dbf->ip ]){ interrupted = broke = 1; } if ( broke ){ sprintf( buf, "%u\0", dbf->ip ); set_variable( "ip", buf ); sprintf( buf, "%u\0", dbf->ptr ); set_variable( "ptr", buf ); for ( hook = temp->hooks; hook; hook = hook->next ){ if ( bfid_execcmd( dbf, hook->cmd ) < 0 ) printf( "[ ] Unknown hook command: \"%s\"\n", hook->cmd ); } } } } else { printf( "Program terminated.\n" ); interrupted = 1; } } } //free( dbf ); return 0; }
// main debugger loop int bf_debugger( Emulator_t *em ) { Emulator_t *dem = em; char buf[256]; int lret = 0; int broke; int i; bfid_brkp_t *temp; bfid_cmd_hook_t *hook; if ( !bfid_initialized ) bfid_init( ); dem->Debugging = 1; interrupted = 1; signal( SIGINT, (__sighandler_t)debug_signal ); printf( "[>] Unnamed NES debugger v0.01\n" ); while ( dem->Debugging ) { if ( interrupted ) { if ( lret ) printf( "[%x] ", lret & 0xff ); else printf( "[ ] " ); printf( "> " ); fgets( buf, 256, stdin ); if ( strlen( buf ) < 2 ) continue; if (( lret = bfid_execcmd( dem, buf )) < 0 ) { printf( "Unknown command.\n" ); continue; } sprintf( buf, "%u\0", dem->Cpus[0].pCounter ); set_variable( "ip", buf ); sprintf( buf, "%u\0", dem->Cpus[0].sPointer ); set_variable( "ptr", buf ); } else { for ( i = 0; i < dem->cpuNo; i++ ) { CpuStep( &dem->Cpus[i] ); // Check for breakpoints on the cpu for ( temp = brkp_list; temp; temp = temp->next ) { broke = 0; if ( temp->type == BRK_IP && temp->val == dem->Cpus[i].pCounter ) { interrupted = broke = 1; } else if ( temp->type == BRK_MEM && temp->val == dem->Cpus[i].sPointer ) { interrupted = broke = 1; } else if ( temp->type == BRK_INSTR && //temp->val == dem->Cpus[i].memory[ dem->Cpus[i].pCounter ]){ temp->val == ReadByte( dem->Cpus[i].memory, dem->Cpus[i].pCounter )) { interrupted = broke = 1; } if ( broke ) { sprintf( buf, "%u\0", dem->Cpus[i].pCounter ); set_variable( "ip", buf ); sprintf( buf, "%u\0", dem->Cpus[i].sPointer ); set_variable( "ptr", buf ); if ( get_variable( "quiet" ) && strcmp( get_variable( "quiet" ), "true" )) { printf( "[ ] cpu%d: breakpoint %d\n", i, temp->i ); } for ( hook = temp->hooks; hook; hook = hook->next ) { if ( bfid_execcmd( dem, hook->cmd ) < 0 ) printf( "[ ] Unknown hook command: \"%s\"\n", hook->cmd ); } } } } } } return 0; }