std::ostream &DebugLog( DebugLevel lev, DebugClass cl ) { // Error are always logged, they are important, // Messages from D_MAIN come from debugmsg and are equally important. if( ( ( lev & debugLevel ) && ( cl & debugClass ) ) || lev & D_ERROR || cl & D_MAIN ) { debugFile.file << std::endl; debugFile.currentTime() << " "; if( lev != debugLevel ) { debugFile.file << lev; } if( cl != debugClass ) { debugFile.file << cl; } debugFile.file << ": "; // Backtrace on error. #ifdef BACKTRACE if( lev == D_ERROR ) { int count = backtrace( tracePtrs, TRACE_SIZE ); char **funcNames = backtrace_symbols( tracePtrs, count ); for( int i = 0; i < count; ++i ) { debugFile.file << "\n\t(" << funcNames[i] << "), "; } debugFile.file << "\n\t"; free( funcNames ); } #endif return debugFile.file; } return nullStream; }
std::ostream & dout(DebugLevel lev,DebugClass cl) { if( (lev & debugLevel) && (cl & debugClass) ) { debugFile.file << std::endl; debugFile.currentTime() << " "; if( lev != debugLevel ) debugFile.file << lev; if( cl != debugClass ) debugFile.file << cl; debugFile.file << ": "; // Backtrace on error. #if !(defined _WIN32 || defined WINDOWS) if( lev == D_ERROR ) { int count = backtrace( tracePtrs, TRACE_SIZE ); char** funcNames = backtrace_symbols( tracePtrs, count ); for(int i = 0; i < count; ++i) debugFile.file << "\n\t(" << funcNames[i] << "), "; debugFile.file << "\n\t"; free(funcNames); } #endif return debugFile.file; } return nullStream; }
//----------- StartMilliCount void StartMilliCount() { #ifdef TIMETRACE if (g_DebugFile.m_UseDebug) g_DebugFile._StartMilliCount(); #endif // TIMETRACE }
//----------- TraceMilliDiff void TraceMilliDiff(char* msg) { #ifdef TIMETRACE if (g_DebugFile.m_UseDebug) g_DebugFile._TraceMilliDiff(msg); #endif // TIMETRACE }
//----------- DebugTrace void DebugTrace(char* strarg, ...) { if (g_DebugFile.m_UseDebug) { va_list args; va_start(args, strarg); g_DebugFile.Trace(DEFAULT, strarg, args); va_end(args); } }
//----------- CurrentDateTime struct tm* CurrentDateTime() { #ifdef TIMETRACE if (g_DebugFile.m_UseDebug) return g_DebugFile._CurrentDateTime(); else return NULL; #endif // TIMETRACE return NULL; }
//----------- TimeTrace void TimeTrace(char* strarg, ...) { #ifdef TIMETRACE if (g_DebugFile.m_UseDebug) { va_list args; va_start(args, strarg); g_DebugFile._TimeTrace(strarg, args); va_end(args); } #endif // TIMETRACE }
//----------- CurrentDateTimeStr char* CurrentDateTimeStr() { #ifdef TIMETRACE if (g_DebugFile.m_UseDebug) { struct tm* ptm = g_DebugFile._CurrentDateTime(); return (ptm != NULL ? asctime(ptm) : ""); } else return ""; #endif // TIMETRACE return "-TIMETRACE DISABLED-"; }
void setupDebug() { int level = 0; #ifdef DEBUG_INFO level |= D_INFO; #endif #ifdef DEBUG_WARNING level |= D_WARNING; #endif #ifdef DEBUG_ERROR level |= D_ERROR; #endif #ifdef DEBUG_PEDANTIC_INFO level |= D_PEDANTIC_INFO; #endif if( level != 0 ) { limitDebugLevel( level ); } int cl = 0; #ifdef DEBUG_ENABLE_MAIN cl |= D_MAIN; #endif #ifdef DEBUG_ENABLE_MAP cl |= D_MAP; #endif #ifdef DEBUG_ENABLE_MAP_GEN cl |= D_MAP_GEN; #endif #ifdef DEBUG_ENABLE_GAME cl |= D_GAME; #endif if( cl != 0 ) { limitDebugClass( cl ); } debugFile.init( FILENAMES["debug"] ); }
void EditFiles::onIdle() { idleHighlight(); for(auto &fv : mFileViews) { if(fv->mDesiredLine != -1) { #if(DBG_EDITF) sDbgFile.printflush("onIdle file %s line %d\n", fv->getFileEditView().getFileName().c_str(), fv->mDesiredLine); #endif fv->mFileView.gotoLine(fv->mDesiredLine); gtk_widget_grab_focus(GTK_WIDGET(fv->mFileView.getTextView())); fv->mDesiredLine = -1; } } }
//----------- DebugTrace2 void DebugTrace2(int type, char* strarg, ...) { try { if (g_DebugFile.m_UseDebug) { va_list args; va_start(args, strarg); g_DebugFile.Trace(type, strarg, args); va_end(args); } } catch(...) { throw; } }
extern "C" G_MODULE_EXPORT gboolean on_DebugViewVariable_activate(GtkWidget *widget, GdkEvent *event, gpointer user_data) { if(sEditFiles && sEditFiles->checkDebugger()) { FileEditView const *view = sEditFiles->getEditView(); if(view) { sEditFiles->showInteractNotebookTab("Data"); sEditFiles->getDebugger().startGetVariable( Gui::getSelectedText(view->getTextView())); #if(DBG_EDITF) const char *str = Gui::getSelectedText(view->getTextView()); sDbgFile.printflush("ViewVar %s\n", str); #endif } } return false; }
void EditFiles::viewFile(OovStringRef const fn, int lineNum) { FilePath fp; fp.getAbsolutePath(fn, FP_File); auto iter = std::find_if(mFileViews.begin(), mFileViews.end(), [fp](std::unique_ptr<ScrolledFileView> const &fv) -> bool { return fv->mFilename.comparePaths(fp) == 0; }); if(iter == mFileViews.end()) { GtkNotebook *book = nullptr; if(putInMainWindow(fn)) book = mSourceBook; else book = mHeaderBook; if(book) { GtkWidget *scrolled = gtk_scrolled_window_new(nullptr, nullptr); GtkWidget *editView = gtk_text_view_new(); /// @todo - use make_unique when supported. ScrolledFileView *scrolledView = new ScrolledFileView(mDebugger); scrolledView->mFileView.init(GTK_TEXT_VIEW(editView), this); OovStatus status = scrolledView->mFileView.openTextFile(fp); if(status.needReport()) { OovString err = "Unable to open file "; err += fp; status.report(ET_Error, err); } scrolledView->mScrolled = GTK_SCROLLED_WINDOW(scrolled); scrolledView->mFilename = fp; gtk_container_add(GTK_CONTAINER(scrolled), editView); Gui::appendPage(book, scrolled, newTabLabel(fp.getName(), scrolledView->getViewTopParent())); gtk_widget_show_all(scrolled); scrolledView->mLeftMargin.setupMargin(GTK_TEXT_VIEW(editView)); // Set up the windows to draw the line numbers in the left margin. // GTK has changed, and different setups are required for different // versions of GTK. // This is not allowed for a text view // gtk_widget_set_app_paintable(editView, true); #if(USE_DRAW_LAYER) overrideDrawLayer(editView); // If the left window is not created, errors display, "Attempt to // convert text buffer coordinates to coordinates for a nonexistent // buffer or private child window of GtkTextView". So create a // window that is only one pixel wide, and draw the line numbers // on the main text view window. gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(editView), GTK_TEXT_WINDOW_LEFT, 1); gtk_text_view_set_left_margin(GTK_TEXT_VIEW(editView), scrolledView->mLeftMargin.getMarginWidth()); #else // The margin is drawn on the border window. gtk_text_view_set_border_window_size(GTK_TEXT_VIEW(editView), GTK_TEXT_WINDOW_LEFT, scrolledView->mLeftMargin.getMarginWidth()); g_signal_connect(editView, "draw", G_CALLBACK(onTextViewDraw), scrolledView); #endif g_signal_connect(editView, "focus_in_event", G_CALLBACK(on_EditFiles_focus_in_event), NULL); g_signal_connect(editView, "key_press_event", G_CALLBACK(on_EditFiles_key_press_event), NULL); g_signal_connect(editView, "button_press_event", G_CALLBACK(on_EditFiles_button_press_event), NULL); mFileViews.push_back(std::unique_ptr<ScrolledFileView>(scrolledView)); #if(DBG_EDITF) sDbgFile.printflush("viewFile count %d, line %d\n", mFileViews.size(), lineNum); #endif iter = mFileViews.end()-1; } } GtkNotebook *notebook = (*iter)->getBook(); if(notebook) { int pageIndex = getPageNumber(notebook, (*iter)->getTextView()); Gui::setCurrentPage(notebook, pageIndex); // focus is set after the screen is displayed by onIdle // gtk_widget_grab_focus(GTK_WIDGET((*iter).getTextView())); #if(DBG_EDITF) sDbgFile.printflush("viewFile %d\n", pageIndex); #endif if(lineNum > 1) { (*iter)->mDesiredLine = lineNum; } } }
void deinitDebug() { debugFile.deinit(); }
void logProc(char const *str, const void *ptr, int val) { sDebugQueue.printflush("%s %p %d\n", str, ptr, val); }