bool Console::Cmd_List(int argc, const char **argv) { Error error = printSource(); if (error.getErrorLevel() != SUCCESS) { printError(argv[0], error); } return true; }
void System::showSystemScreen(bool showSrc) { int prevScreenId; if (showSrc) { prevScreenId = _output->getScreenId(true); _output->selectBackScreen(SOURCE_SCREEN); printSource(); _output->selectBackScreen(prevScreenId); _output->selectFrontScreen(SOURCE_SCREEN); } else { prevScreenId = _output->getScreenId(false); _output->selectFrontScreen(CONSOLE_SCREEN); } if (_userScreenId == -1) { _userScreenId = prevScreenId; } }
bool GLProgram::link() { gl::LinkProgram(m_Handle); GL::Int success = GL::FALSE; gl::GetProgramiv(m_Handle, GL::LINK_STATUS, &success); if (!success) { Z_LOG("Unable to link program.\n---"); printSource(); GL::Int logLength = 0; gl::GetProgramiv(m_Handle, GL::INFO_LOG_LENGTH, &logLength); if (logLength > 0) { std::vector<GL::Char> data; data.resize(size_t(logLength)); gl::GetProgramInfoLog(m_Handle, logLength, &logLength, data.data()); std::string infoLog(data.data(), size_t(logLength)); size_t length = infoLog.length(); if (length > 0 && infoLog[length - 1] != '\n') infoLog += '\n'; if (logLength > 0) Z_LOG("---\n" << infoLog << "---"); } if (logLength <= 0) Z_LOG("---\nInfo log is not available.\n---"); return false; } return true; }
void Console::notifyWatch(const char *filename, const char *symbol, const char *newValue) { debugPrintf("Watch: %s:%s <---- %s\n", filename, symbol, newValue); printSource(0); attach(); onFrame(); }
void Console::notifyStep(const char *filename, int line) { debugPrintf("Step: %s:%d\n", filename, line); printSource(0); attach(); onFrame(); }
void Console::notifyBreakpoint(const char *filename, int line) { debugPrintf("Breakpoint hit %s: %d\n", filename, line); printSource(0); attach(); onFrame(); }
void CDebugHelper::run(lua_State* pState) { char buffer[1024]; char sep[] = " \t\n"; char* next = NULL; char* last = NULL; char* cmd = NULL; m_curFrame = 0; while(true) { printf("(db): "); fgets(buffer, 1024, stdin); if(buffer[0] == '\0') { if(m_lastCmd[0] == '\0') { continue; } else { strcpy(buffer, m_lastCmd); } } else { strcpy(m_lastCmd, buffer); } next = strtok_r(buffer, sep, &last); cmd = next; for(char* p = cmd; *p; ++p) { *p = tolower(*p); } if(strcmp(cmd, "h") == 0 || strcmp(cmd, "help") == 0) { help(); continue; } else if(strcmp(cmd, "c") == 0 || strcmp(cmd, "continue") == 0) { setNoneHook(pState); return; } else if(strcmp(cmd, "bt") == 0) { printBacktrace(pState); continue; } else if(strcmp(cmd, "l") == 0 || strcmp(cmd, "list") == 0) { int beginLine = 0; int endLine = 0; next = strtok_r(NULL, sep, &last); if (next) { beginLine = atoi(next); next = strtok_r(NULL, sep, &last); if (next) { endLine = atoi(next); } } printSource(pState, beginLine, endLine); } else if(strcmp(cmd, "f") == 0 || strcmp(cmd, "frame") == 0) { next = strtok_r(NULL, sep, &last); if(next) { m_curFrame = atoi(next); } printFrame(pState, m_curFrame); continue; } else if(strcmp(cmd, "p") == 0 || strcmp(cmd, "print") == 0) { next = strtok_r(NULL, sep, &last); if (next) { printValue(pState, next); } continue; } else if(strcmp(cmd, "n") == 0 || strcmp(cmd, "next") == 0) { setNextHook(pState); return; } else if(strcmp(cmd, "s") == 0 || strcmp(cmd, "step") == 0) { setStepHook(pState); return; } else if(strcmp(cmd, "return") == 0) { setReturnHook(pState); return; } } }
BOOL execute(UCHAR* _buffer) { if ( !validate(_buffer) ) { #if defined _DEBUG printf("\n--- execute: '%s' is invalid\n", _buffer); #endif return false; } #if defined _DEBUG printf("\n+++ execute: (@ 0x%X) '%s'\n", _buffer, _buffer); #endif int sz=strlen(_buffer); int repeat=0; UCHAR* repeat_start=0; UCHAR* repeat_stop=0; // TODO: crashes here /* with this sc @ +3 [> +10 <-]> -3 .@ < +6 [> +10 <-]> +4 .@ < +6 (crashes here) [> -- -- -- - <-]> .@ < +6 [> +10 <-]> ..@ < +9 [> -9 <-]> - .@ < +6 [> +10 <-]> +4 .@ < +6 [> -7 <-]> - .@ + < +6 [> +10 <-]> ..@ */ UCHAR* repeat_buffer; repeat_buffer=(UCHAR*)calloc(BUFFER_SIZE, sizeof(char)); if ( !repeat_buffer ) { #if defined _DEBUG printf("--- execute: repeat_buffer=NULL\n"); #else printf("error: can't allocate memory\n"); #endif return false; } BOOL repeat_done=false; UCHAR* tmp_buffer; // copy here body of loop cycle if any UCHAR* bf_sp=_buffer; // if ( bfo & BFO_QUICK ) // { // free(repeat_buffer); // printf("not implemented qbf yet\n"); // return false; // } while ( bf_sp<_buffer+sz ) { repeat_done=false; // #if defined _DEBUG // printf("+++ execute: parse '%c'@ 0x%X\n", *bf_sp, bf_sp); // #endif if ( *bf_sp=='@' ) { #if defined _DEBUG printf("\n+++ executeq: breakpoint reached\n"); memDump(); printSource(_buffer, bf_sp); getchar(); #else if ( bfo & BFO_DEBUG ) { printf("\nstop on breakpoint\n"); memDump(); printSource(_buffer, bf_sp); getchar(); } #endif } if ( *bf_sp=='+' ) { #if defined _DEBUG printf("+++ execute: +\n"); #endif if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif (*bf_mp)+=atoi(repeat_buffer); repeat_done=true; memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif } } if ( !repeat_done ) { #if defined _DEBUG printf("%d (0x%0X) @ 0x%X -> ", *bf_mp, *bf_mp, bf_mp); (*bf_mp)++; printf("%d (0x%0X) @ 0x%X\n", *bf_mp, *bf_mp, bf_mp); #else (*bf_mp)++; #endif } if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp=='-' ) { #if defined _DEBUG printf("+++ execute: -\n"); #endif if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif (*bf_mp)-=atoi(repeat_buffer); repeat_done=true; memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif } } if ( !repeat_done ) { #if defined _DEBUG printf("%d (0x%0X) @ 0x%X -> ", *bf_mp, *bf_mp, bf_mp); (*bf_mp)--; printf("%d (0x%0X) @ 0x%X\n", *bf_mp, *bf_mp, bf_mp); #else (*bf_mp)--; #endif } if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp=='>' ) { #if defined _DEBUG printf("+++ execute: >\n"); #endif repeat=1; if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif repeat=atoi(repeat_buffer); memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif } } if ( bf_mp+repeat<=bf_mem+BF_MEMORY_SIZE) { #if defined _DEBUG printf("0x%X -> ", bf_mp); bf_mp+=repeat; printf("0x%X\n", bf_mp); #else bf_mp+=repeat; #endif } else { #if defined _DEBUG printf("--- execute>: out of memory bounds\n"); #else printf("warning: out of memory bounds\n"); #endif if ( bfo & BFO_QUICK ) { bf_mp=bf_mem+BF_MEMORY_SIZE; } } if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp=='<' ) { #if defined _DEBUG printf("+++ execute: <\n"); #endif repeat=1; if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif repeat=atoi(repeat_buffer); memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif } } if ( bf_mp-repeat>=bf_mem ) { #if defined _DEBUG printf("0x%X -> ", bf_mp); bf_mp-=repeat; printf("0x%X\n", bf_mp); #else bf_mp-=repeat; #endif } else { #if defined _DEBUG printf("--- execute<: out of memory bounds\n"); #else printf("warning: out of memory bounds\n"); #endif if ( bfo & BFO_QUICK ) { bf_mp=bf_mem; } } } if ( *bf_sp=='.' ) { #if defined _DEBUG printf("+++ execute: .\n"); #endif #if defined _DEBUG memDump(); #else putchar(*bf_mp); #endif if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp==',' ) { #if defined _DEBUG printf("+++ execute: ,\n"); #endif if ( (bfo & BFO_QUICK) && bf_sp<_buffer+sz+1 ) { if ( *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { repeat_start= ++bf_sp; while ( bf_sp<_buffer+sz+1 && *(bf_sp+1)>=48 && *(bf_sp+1)<=57 ) { bf_sp++; } repeat_stop=bf_sp+1; memcpy(repeat_buffer, repeat_start, abs(repeat_start-repeat_stop)); #if defined _DEBUG printf("+++ executeq: repeat %s(%d) times\n", repeat_buffer, atoi(repeat_buffer)); #endif repeat=atoi(repeat_buffer); memset(repeat_buffer, 0, BUFFER_SIZE); } else { #if defined _DEBUG printf("--- executeq: '%c' NAN\n", *(bf_sp+1)); #endif repeat=1; } } while ( repeat ) { *bf_mp=(UCHAR)getchar(); #if defined _DEBUG printf("+++ execute,: 0x%x\n", *bf_mp); #endif if ( bf_mp<bf_mem+BF_MEMORY_SIZE) { bf_mp++; } else { #if defined _DEBUG printf("--- executeq: out of memory bounds. input into last cell (%d left)\n", repeat); #else printf("warning: out of memory bounds. input into last cell\n"); #endif } repeat--; } if ( used_memory<bf_mp ) { used_memory=bf_mp; } } if ( *bf_sp=='[' ) { #if defined _DEBUG printf("+++ execute[: '[' found @ 0x%X\n", bf_sp); #endif UCHAR* tmp_bf_sp=index(bf_sp, ']')+1; int tmp_sz=abs(bf_sp-tmp_bf_sp); tmp_buffer=(UCHAR*)calloc(tmp_sz, sizeof(char)); if ( tmp_buffer ) { memcpy(tmp_buffer, bf_sp, tmp_sz); tmp_buffer[tmp_sz]=0; } else { #if defined _DEBUG printf("--- execute[: tmp_buffer=NULL\n"); #else printf("error: can't allocate memory\n"); #endif return false; } while ( tmp_buffer && !validate(tmp_buffer) ) { #if defined _DEBUG printf("+++ execute[::searchEndOfCycle: '%s'(%d) is invalid : ++\n", tmp_buffer, tmp_sz); #endif tmp_bf_sp=index(tmp_bf_sp, ']')+1; tmp_sz=abs(bf_sp-tmp_bf_sp); tmp_buffer=(UCHAR*)realloc(tmp_buffer, tmp_sz); memset(tmp_buffer, 0, tmp_sz); if ( tmp_buffer ) { memcpy(tmp_buffer, bf_sp, tmp_sz); tmp_buffer[tmp_sz]=0; } else { #if defined _DEBUG printf("--- execute[: tmp_buffer=NULL\n"); #else printf("error: can't allocate memory\n"); #endif return false; } } if ( tmp_buffer ) { int sz=strlen(tmp_buffer); tmp_buffer[sz-1]=0; while ( *bf_mp ) { #if defined _DEBUG printf("\n+++ execute: recursive calls left: %d\n", *bf_mp); #endif if ( !execute(tmp_buffer+1) ) { #if defined _DEBUG printf("--- execute: error execute while recursive calls\n"); memDump(); #endif return false; } } #if defined _DEBUG printf("+++ execute: exit from recursive call\n\n"); #endif free(tmp_buffer); bf_sp=tmp_bf_sp-1; } } bf_sp++; } free(repeat_buffer); return true; }