| 414 | } |
| 415 | |
| 416 | bool CeDebugger::CheckConditionalBreakpoint(CeBreakpoint* breakpoint) |
| 417 | { |
| 418 | auto _SplitExpr = [&](const StringImpl& expr, StringImpl& outExpr, StringImpl& outSubject) |
| 419 | { |
| 420 | int crPos = (int)expr.IndexOf('\n'); |
| 421 | if (crPos != -1) |
| 422 | { |
| 423 | outExpr += expr.Substring(0, crPos); |
| 424 | outSubject += expr.Substring(crPos + 1); |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | outExpr += expr; |
| 429 | } |
| 430 | }; |
| 431 | |
| 432 | if (breakpoint->mCondition != NULL) |
| 433 | { |
| 434 | ClearCallStack(); |
| 435 | |
| 436 | auto conditional = breakpoint->mCondition; |
| 437 | if (conditional->mDbgEvaluationContext == NULL) |
| 438 | { |
| 439 | StringT<256> expr; |
| 440 | StringT<256> subjectExpr; |
| 441 | _SplitExpr(conditional->mExpr, expr, subjectExpr); |
| 442 | |
| 443 | conditional->mDbgEvaluationContext = new CeEvaluationContext(this, expr); |
| 444 | conditional->mDbgEvaluationContext->mCallStackIdx = -1; |
| 445 | } |
| 446 | |
| 447 | CeDbgState dbgState; |
| 448 | BfTypedValue result = conditional->mDbgEvaluationContext->EvaluateInContext(BfTypedValue(), &dbgState); |
| 449 | |
| 450 | if (conditional->mDbgEvaluationContext->mPassInstance->HasFailed()) |
| 451 | { |
| 452 | String errorStr = "FAILED"; |
| 453 | for (auto error : conditional->mDbgEvaluationContext->mPassInstance->mErrors) |
| 454 | { |
| 455 | if (!error->mIsWarning) |
| 456 | errorStr = error->mError; |
| 457 | } |
| 458 | String condError = StrFormat("error Conditional breakpoint expression '%s' failed: %s", conditional->mExpr.c_str(), errorStr.c_str()); |
| 459 | mDebugManager->mOutMessages.push_back(condError); |
| 460 | return true; |
| 461 | } |
| 462 | else if (dbgState.mBlockedSideEffects) |
| 463 | { |
| 464 | mDebugManager->mOutMessages.push_back(StrFormat("error Conditional breakpoint expression '%s' contained function calls, which is not allowed", conditional->mExpr.c_str())); |
| 465 | return true; |
| 466 | } |
| 467 | else if ((!result) || (!result.mType->IsBoolean())) |
| 468 | { |
| 469 | mDebugManager->mOutMessages.push_back(StrFormat("error Conditional breakpoint expression '%s' must result in a boolean value", conditional->mExpr.c_str())); |
| 470 | return true; |
| 471 | } |
| 472 | else if (ValueToInt(result) <= 0) |
| 473 | return false; |
no test coverage detected