DBG: added TraceSetLogFile command
This commit is contained in:
parent
8fa4dde358
commit
24cb79324e
|
|
@ -154,7 +154,6 @@ bool cbDebugTraceSetCommand(int argc, char* argv[])
|
|||
bool cbDebugTraceSetSwitchCondition(int argc, char* argv[])
|
||||
{
|
||||
auto condition = argc > 1 ? argv[1] : "";
|
||||
dputs(condition);
|
||||
if(!dbgsettraceswitchcondition(condition))
|
||||
{
|
||||
dprintf(QT_TRANSLATE_NOOP("DBG", "Invalid expression \"%s\"\n"), condition);
|
||||
|
|
@ -162,3 +161,9 @@ bool cbDebugTraceSetSwitchCondition(int argc, char* argv[])
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cbDebugTraceSetLogFile(int argc, char* argv[])
|
||||
{
|
||||
auto fileName = argc > 1 ? argv[1] : "";
|
||||
return dbgsettracelogfile(fileName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,4 +12,5 @@ bool cbDebugRunToParty(int argc, char* argv[]);
|
|||
bool cbDebugRunToUserCode(int argc, char* argv[]);
|
||||
bool cbDebugTraceSetLog(int argc, char* argv[]);
|
||||
bool cbDebugTraceSetCommand(int argc, char* argv[]);
|
||||
bool cbDebugTraceSetSwitchCondition(int argc, char* argv[]);
|
||||
bool cbDebugTraceSetSwitchCondition(int argc, char* argv[]);
|
||||
bool cbDebugTraceSetLogFile(int argc, char* argv[]);
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
#include "simplescript.h"
|
||||
#include "capstone_wrapper.h"
|
||||
#include "cmd-watch-control.h"
|
||||
#include "filemap.h"
|
||||
|
||||
struct TraceCondition
|
||||
{
|
||||
|
|
@ -75,6 +76,28 @@ struct TraceState
|
|||
return traceCondition->condition.IsValidExpression();
|
||||
}
|
||||
|
||||
bool InitLogFile()
|
||||
{
|
||||
if(logFile.empty())
|
||||
return true;
|
||||
auto hFile = CreateFileW(logFile.c_str(), GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
logWriter = new BufferedWriter(hFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
void LogWrite(String text)
|
||||
{
|
||||
if(logWriter)
|
||||
{
|
||||
logWriter->Write(text.c_str(), text.size());
|
||||
logWriter->Write("\n", 1);
|
||||
}
|
||||
else
|
||||
dprintf_untranslated("%s\n", text.c_str());
|
||||
}
|
||||
|
||||
bool IsActive() const
|
||||
{
|
||||
return traceCondition != nullptr;
|
||||
|
|
@ -150,6 +173,11 @@ struct TraceState
|
|||
return switchCondition && switchCondition->Evaluate(defaultValue);
|
||||
}
|
||||
|
||||
void SetLogFile(const char* fileName)
|
||||
{
|
||||
logFile = StringUtils::Utf8ToUtf16(fileName);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
delete traceCondition;
|
||||
|
|
@ -160,6 +188,9 @@ struct TraceState
|
|||
cmdCondition = nullptr;
|
||||
delete switchCondition;
|
||||
switchCondition = nullptr;
|
||||
logFile.clear();
|
||||
delete logWriter;
|
||||
logWriter = nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -168,6 +199,8 @@ private:
|
|||
TextCondition* cmdCondition = nullptr;
|
||||
TextCondition* switchCondition = nullptr;
|
||||
String emptyString;
|
||||
WString logFile;
|
||||
BufferedWriter* logWriter = nullptr;
|
||||
};
|
||||
|
||||
static PROCESS_INFORMATION g_pi = {0, 0, 0, 0};
|
||||
|
|
@ -242,7 +275,9 @@ bool dbgsettracecondition(const String & expression, duint maxSteps)
|
|||
{
|
||||
if(dbgtraceactive())
|
||||
return false;
|
||||
if(traceState.InitTraceCondition(expression, maxSteps))
|
||||
if(!traceState.InitTraceCondition(expression, maxSteps))
|
||||
return false;
|
||||
if(traceState.InitLogFile())
|
||||
return true;
|
||||
dbgcleartracestate();
|
||||
return false;
|
||||
|
|
@ -274,6 +309,12 @@ bool dbgtraceactive()
|
|||
return traceState.IsActive();
|
||||
}
|
||||
|
||||
bool dbgsettracelogfile(const char* fileName)
|
||||
{
|
||||
traceState.SetLogFile(fileName);
|
||||
return true;
|
||||
}
|
||||
|
||||
static DWORD WINAPI memMapThread(void* ptr)
|
||||
{
|
||||
while(!bStopMemMapThread)
|
||||
|
|
@ -1280,7 +1321,7 @@ static void cbTraceUniversalConditionalStep(duint cip, bool bStepInto, void(*cal
|
|||
auto switchCondition = traceState.EvaluateSwitch(false);
|
||||
if(logCondition) //log
|
||||
{
|
||||
dprintf_untranslated("%s\n", stringformatinline(traceState.LogText()).c_str());
|
||||
traceState.LogWrite(stringformatinline(traceState.LogText()));
|
||||
}
|
||||
if(cmdCondition) //command
|
||||
{
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ bool dbgsettracelog(const String & expression, const String & text);
|
|||
bool dbgsettracecmd(const String & expression, const String & text);
|
||||
bool dbgsettraceswitchcondition(const String & expression);
|
||||
bool dbgtraceactive();
|
||||
bool dbgsettracelogfile(const char* fileName);
|
||||
void dbgsetdebuggeeinitscript(const char* fileName);
|
||||
const char* dbggetdebuggeeinitscript();
|
||||
void dbgsetforeground();
|
||||
|
|
|
|||
|
|
@ -219,6 +219,7 @@ static void registercommands()
|
|||
dbgcmdnew("TraceSetLog,SetTraceLog", cbDebugTraceSetLog, true); //Set trace log text + condition
|
||||
dbgcmdnew("TraceSetCommand,SetTraceCommand", cbDebugTraceSetCommand, true); //Set trace command text + condition
|
||||
dbgcmdnew("TraceSetSwitchCondition,SetTraceSwitchCondition", cbDebugTraceSetSwitchCondition, true); //Set trace switch condition
|
||||
dbgcmdnew("TraceSetLogFile,SetTraceLogFile", cbDebugTraceSetLogFile, true); //Set trace log file
|
||||
|
||||
//thread control
|
||||
dbgcmdnew("createthread,threadcreate,newthread,threadnew", cbDebugCreatethread, true); //create thread
|
||||
|
|
|
|||
Loading…
Reference in New Issue