1
0
Fork 0

feat: logsave, logredirect, logredirectstop

This commit is contained in:
Bluefissure 2023-07-15 01:01:22 -05:00 committed by Duncan Ogilvie
parent 6575efc266
commit 956072ad02
7 changed files with 126 additions and 18 deletions

View File

@ -1361,6 +1361,21 @@ BRIDGE_IMPEXP void GuiLogClear()
_gui_sendmessage(GUI_CLEAR_LOG, 0, 0);
}
BRIDGE_IMPEXP void GuiLogSave(const char* filename)
{
_gui_sendmessage(GUI_SAVE_LOG, (void*)filename, 0);
}
BRIDGE_IMPEXP void GuiLogRedirect(const char* filename)
{
_gui_sendmessage(GUI_REDIRECT_LOG, (void*)filename, 0);
}
BRIDGE_IMPEXP void GuiLogRedirectStop()
{
_gui_sendmessage(GUI_STOP_REDIRECT_LOG, 0, 0);
}
BRIDGE_IMPEXP void GuiUpdateEnable(bool updateNow)
{
bDisableGUIUpdate = false;

View File

@ -1276,6 +1276,9 @@ typedef enum
GUI_ADD_MSG_TO_LOG_HTML, // param1=(const char*)msg, param2=unused
GUI_IS_LOG_ENABLED, // param1=unused, param2=unused
GUI_IS_DEBUGGER_FOCUSED, // param1=unused, param2=unused
GUI_SAVE_LOG, // param1=const char* file name,param2=unused
GUI_REDIRECT_LOG, // param1=const char* file name,param2=unused
GUI_STOP_REDIRECT_LOG, // param1=unused, param2=unused
} GUIMSG;
//GUI Typedefs
@ -1345,6 +1348,9 @@ BRIDGE_IMPEXP void GuiSetDebugStateFast(DBGSTATE state);
BRIDGE_IMPEXP void GuiAddLogMessage(const char* msg);
BRIDGE_IMPEXP void GuiAddLogMessageHtml(const char* msg);
BRIDGE_IMPEXP void GuiLogClear();
BRIDGE_IMPEXP void GuiLogSave(const char* filename);
BRIDGE_IMPEXP void GuiLogRedirect(const char* filename);
BRIDGE_IMPEXP void GuiLogRedirectStop();
BRIDGE_IMPEXP void GuiUpdateAllViews();
BRIDGE_IMPEXP void GuiUpdateRegisterView();
BRIDGE_IMPEXP void GuiUpdateDisassemblyView();

View File

@ -50,6 +50,30 @@ static bool cbClearLog(int argc, char* argv[])
return true;
}
static bool cbSaveLog(int argc, char* argv[])
{
if(argc < 2)
GuiLogSave(0);
else
GuiLogSave(argv[1]);
return true;
}
static bool cbRedirectLog(int argc, char* argv[])
{
if(argc < 2)
GuiLogRedirect(0);
else
GuiLogRedirect(argv[1]);
return true;
}
static bool cbStopRedirectLog(int argc, char* argv[])
{
GuiLogRedirectStop();
return true;
}
static bool cbPrintf(int argc, char* argv[])
{
if(argc < 2)
@ -406,6 +430,9 @@ static void registercommands()
dbgcmdnew("EnableLog,LogEnable", cbInstrEnableLog, false); //enable log
dbgcmdnew("DisableLog,LogDisable", cbInstrDisableLog, false); //disable log
dbgcmdnew("ClearLog,cls,lc,lclr", cbClearLog, false); //clear the log
dbgcmdnew("SaveLog,LogSave", cbSaveLog, false); //save the log
dbgcmdnew("RedirectLog,LogRedirect", cbRedirectLog, false); //redirect the log
dbgcmdnew("StopRedirectLog,LogRedirectStop", cbStopRedirectLog, false); //stop redirecting the log
dbgcmdnew("AddFavouriteTool", cbInstrAddFavTool, false); //add favourite tool
dbgcmdnew("AddFavouriteCommand", cbInstrAddFavCmd, false); //add favourite command
dbgcmdnew("AddFavouriteToolShortcut,SetFavouriteToolShortcut", cbInstrSetFavToolShortcut, false); //set favourite tool shortcut

View File

@ -127,6 +127,24 @@ void* Bridge::processMessage(GUIMSG type, void* param1, void* param2)
emit clearLog();
break;
case GUI_SAVE_LOG:
if(!param1)
emit saveLog();
else
emit saveLogToFile(QString((const char*)param1));
break;
case GUI_REDIRECT_LOG:
if(!param1)
emit redirectLogToFile(QString());
else
emit redirectLogToFile(QString((const char*)param1));
break;
case GUI_STOP_REDIRECT_LOG:
emit redirectLogStop();
break;
case GUI_UPDATE_REGISTER_VIEW:
emit updateRegisters();
break;

View File

@ -53,6 +53,10 @@ signals:
void addMsgToLog(QByteArray msg);
void addMsgToLogHtml(QByteArray msg);
void clearLog();
void saveLog();
void saveLogToFile(QString file);
void redirectLogStop();
void redirectLogToFile(QString filename);
void shutdown();
void updateRegisters();
void updateBreakpoints();

View File

@ -38,6 +38,10 @@ LogView::LogView(QWidget* parent) : QTextBrowser(parent), logRedirection(NULL)
connect(Bridge::getBridge(), SIGNAL(addMsgToLog(QByteArray)), this, SLOT(addMsgToLogSlot(QByteArray)));
connect(Bridge::getBridge(), SIGNAL(addMsgToLogHtml(QByteArray)), this, SLOT(addMsgToLogSlotHtml(QByteArray)));
connect(Bridge::getBridge(), SIGNAL(clearLog()), this, SLOT(clearLogSlot()));
connect(Bridge::getBridge(), SIGNAL(saveLog()), this, SLOT(saveSlot()));
connect(Bridge::getBridge(), SIGNAL(saveLogToFile(QString)), this, SLOT(saveSlotToFile(QString)));
connect(Bridge::getBridge(), SIGNAL(redirectLogToFile(QString)), this, SLOT(redirectLogSlotToFile(QString)));
connect(Bridge::getBridge(), SIGNAL(redirectLogStop()), this, SLOT(redirectLogSlotStop()));
connect(Bridge::getBridge(), SIGNAL(setLogEnabled(bool)), this, SLOT(setLoggingEnabled(bool)));
connect(Bridge::getBridge(), SIGNAL(flushLog()), this, SLOT(flushLogSlot()));
connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(onAnchorClicked(QUrl)));
@ -375,30 +379,56 @@ void LogView::clearLogSlot()
this->clear();
}
void LogView::redirectLogSlotStop()
{
if(logRedirection != NULL)
{
fclose(logRedirection);
logRedirection = NULL;
GuiAddLogMessage(tr("Log redirection is stopped.\n").toUtf8().constData());
}
else
{
GuiAddLogMessage(tr("Log is not redirected.\n").toUtf8().constData());
}
}
void LogView::redirectLogSlotToFile(QString filename)
{
if(logRedirection != NULL)
{
fclose(logRedirection);
logRedirection = NULL;
GuiAddLogMessage(tr("Log redirection is stopped.\n").toUtf8().constData());
}
logRedirection = _wfopen(filename.toStdWString().c_str(), L"ab");
if(logRedirection == NULL)
GuiAddLogMessage(tr("_wfopen() failed. Log will not be redirected to %1.\n").arg(QString::fromWCharArray(BridgeUserDirectory())).toUtf8().constData());
else
{
if(utf16Redirect && ftell(logRedirection) == 0)
{
unsigned short BOM = 0xfeff;
fwrite(&BOM, 2, 1, logRedirection);
}
GuiAddLogMessage(tr("Log will be redirected to %1.\n").arg(filename).toUtf8().constData());
}
}
void LogView::redirectLogSlot()
{
if(logRedirection != NULL)
{
fclose(logRedirection);
logRedirection = NULL;
GuiAddLogMessage(tr("Log redirection is stopped.\n").toUtf8().constData());
}
else
{
BrowseDialog browse(this, tr("Redirect log to file"), tr("Enter the file to which you want to redirect log messages."), tr("Log files (*.txt);;All files (*.*)"), QString::fromWCharArray(BridgeUserDirectory()), true);
if(browse.exec() == QDialog::Accepted)
{
logRedirection = _wfopen(browse.path.toStdWString().c_str(), L"ab");
if(logRedirection == NULL)
GuiAddLogMessage(tr("_wfopen() failed. Log will not be redirected to %1.\n").arg(browse.path).toUtf8().constData());
else
{
if(utf16Redirect && ftell(logRedirection) == 0)
{
unsigned short BOM = 0xfeff;
fwrite(&BOM, 2, 1, logRedirection);
}
GuiAddLogMessage(tr("Log will be redirected to %1.\n").arg(browse.path).toUtf8().constData());
}
redirectLogSlotToFile(browse.path);
}
}
}
@ -427,13 +457,8 @@ void LogView::autoScrollSlot()
autoScroll = !autoScroll;
}
/**
* @brief LogView::saveSlot Called by "save" action
*/
void LogView::saveSlot()
void LogView::saveSlotToFile(QString fileName)
{
QString fileName;
fileName = QString("log-%1.txt").arg(QDateTime::currentDateTime().toString().replace(QChar(':'), QChar('-')));
QFile savedLog(fileName);
savedLog.open(QIODevice::Append | QIODevice::Text);
if(savedLog.error() != QFile::NoError)
@ -448,6 +473,16 @@ void LogView::saveSlot()
}
}
/**
* @brief LogView::saveSlot Called by "save" action
*/
void LogView::saveSlot()
{
QString fileName;
fileName = QString("log-%1.txt").arg(QDateTime::currentDateTime().toString().replace(QChar(':'), QChar('-')));
saveSlotToFile(fileName);
}
void LogView::toggleLoggingSlot()
{
setLoggingEnabled(!getLoggingEnabled());

View File

@ -22,6 +22,8 @@ public slots:
void updateStyle();
void addMsgToLogSlot(QByteArray msg); /* Non-HTML Log Function*/
void addMsgToLogSlotHtml(QByteArray msg); /* HTML accepting Log Function */
void redirectLogSlotStop();
void redirectLogSlotToFile(QString directory);
void redirectLogSlot();
void setLoggingEnabled(bool enabled);
void autoScrollSlot();
@ -35,6 +37,7 @@ public slots:
void onAnchorClicked(const QUrl & link);
void clearLogSlot();
void saveSlotToFile(QString filename);
void saveSlot();
void toggleLoggingSlot();
void flushTimerSlot();