@@ -118,8 +118,8 @@ void Debugger::Hook(lua_State* L, lua_Debug* ar) {
118118 }
119119 luaThreadExecutors.clear ();
120120 }
121- const auto * bp = FindBreakPoint (L, ar);
122- if (bp) {
121+ auto * bp = FindBreakPoint (L, ar);
122+ if (bp && ProcessBreakPoint (bp) ) {
123123 HandleBreak (L);
124124 return ;
125125 }
@@ -159,7 +159,7 @@ bool Debugger::GetStacks(lua_State* L, std::vector<Stack*>& stacks, StackAllocat
159159 if (!lua_getinfo (L, " nSlu" , &ar)) {
160160 continue ;
161161 }
162- auto stack = alloc ();
162+ auto * stack = alloc ();
163163 stack->file = GetFile (L, &ar);
164164 stack->functionName = getDebugName (&ar) == nullptr ? " " : getDebugName (&ar);
165165 stack->level = level;
@@ -510,11 +510,14 @@ void ParsePathParts(const std::string& file, std::vector<std::string>& paths) {
510510
511511void Debugger::AddBreakPoint (const BreakPoint& breakPoint) {
512512 std::lock_guard <std::mutex> lock (mutexBP);
513- const auto bp = new BreakPoint ();
513+ auto * const bp = new BreakPoint ();
514514 bp->file = breakPoint.file ;
515515 std::transform (bp->file .begin (), bp->file .end (), bp->file .begin (), tolower);
516516 bp->condition = breakPoint.condition ;
517+ bp->hitCondition = breakPoint.hitCondition ;
518+ bp->logMessage = breakPoint.logMessage ;
517519 bp->line = breakPoint.line ;
520+ bp->hitCount = 0 ;
518521 ParsePathParts (bp->file , bp->pathParts );
519522 breakPoints.push_back (bp);
520523 RefreshLineSet ();
@@ -639,6 +642,25 @@ bool Debugger::CreateEnv(int stackLevel) {
639642 return true ;
640643}
641644
645+ bool Debugger::ProcessBreakPoint (BreakPoint* bp) {
646+ if (!bp->condition .empty ()) {
647+ EvalContext ctx{};
648+ ctx.expr = bp->condition ;
649+ bool suc = DoEval (&ctx);
650+ return suc && ctx.result .valueType == LUA_TBOOLEAN && ctx.result .value == " true" ;
651+ }
652+ if (!bp->logMessage .empty ()) {
653+ EmmyFacade::Get ()->SendLog (LogType::Info, bp->logMessage .c_str ());
654+ return false ;
655+ }
656+ if (!bp->hitCondition .empty ()) {
657+ bp->hitCount ++;
658+ // TODO check hit condition
659+ return false ;
660+ }
661+ return true ;
662+ }
663+
642664void Debugger::SetHookState (lua_State* L, HookState* newState) {
643665 hookState = nullptr ;
644666 if (newState->Start (this , L)) {
@@ -765,7 +787,7 @@ BreakPoint* Debugger::FindBreakPoint(const std::string& file, int line) {
765787 ParsePathParts (lowerCaseFile, pathParts);
766788 auto it = breakPoints.begin ();
767789 while (it != breakPoints.end ()) {
768- const auto bp = *it;
790+ auto * const bp = *it;
769791 if (bp->line == line) {
770792 // full match: bp(a/b/c), file(a/b/c)
771793 if (bp->file == lowerCaseFile) {
0 commit comments