2018-07-22 14:58:24 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "ChildInternal.h"
|
|
|
|
|
|
|
|
#include "ProcessRecordReplay.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace recordreplay {
|
|
|
|
namespace navigation {
|
|
|
|
|
|
|
|
typedef js::BreakpointPosition BreakpointPosition;
|
|
|
|
typedef js::ExecutionPoint ExecutionPoint;
|
|
|
|
|
|
|
|
static void
|
|
|
|
BreakpointPositionToString(const BreakpointPosition& aPos, nsAutoCString& aStr)
|
|
|
|
{
|
|
|
|
aStr.AppendPrintf("{ Kind: %s, Script: %d, Offset: %d, Frame: %d }",
|
|
|
|
aPos.KindString(), (int) aPos.mScript, (int) aPos.mOffset, (int) aPos.mFrameIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ExecutionPointToString(const ExecutionPoint& aPoint, nsAutoCString& aStr)
|
|
|
|
{
|
|
|
|
aStr.AppendPrintf("{ Checkpoint %d", (int) aPoint.mCheckpoint);
|
|
|
|
if (aPoint.HasPosition()) {
|
|
|
|
aStr.AppendPrintf(" Progress %llu Position ", aPoint.mProgress);
|
|
|
|
BreakpointPositionToString(aPoint.mPosition, aStr);
|
|
|
|
}
|
|
|
|
aStr.AppendPrintf(" }");
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation State
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// The navigation state of a recording/replaying process describes where the
|
|
|
|
// process currently is and what it is doing in order to respond to messages
|
|
|
|
// from the middleman process.
|
|
|
|
//
|
|
|
|
// At all times, the navigation state will be in exactly one of the following
|
|
|
|
// phases:
|
|
|
|
//
|
2018-08-18 18:39:48 +03:00
|
|
|
// - Paused: The process is paused somewhere.
|
2018-07-22 14:58:24 +03:00
|
|
|
// - Forward: The process is running forward and scanning for breakpoint hits.
|
|
|
|
// - ReachBreakpoint: The process is running forward from a checkpoint to a
|
|
|
|
// particular execution point before the next checkpoint.
|
|
|
|
// - FindLastHit: The process is running forward and keeping track of the last
|
|
|
|
// point a breakpoint was hit within an execution region.
|
|
|
|
//
|
|
|
|
// This file manages data associated with each of these phases and the
|
|
|
|
// transitions that occur between them as the process executes or new
|
|
|
|
// messages are received from the middleman.
|
|
|
|
|
|
|
|
typedef AllocPolicy<MemoryKind::Navigation> UntrackedAllocPolicy;
|
|
|
|
|
|
|
|
// Abstract class for where we are at in the navigation state machine.
|
|
|
|
// Each subclass has a single instance contained in NavigationState (see below)
|
|
|
|
// and it and all its data are allocated using untracked memory that is not
|
|
|
|
// affected by restoring earlier checkpoints.
|
|
|
|
class NavigationPhase
|
|
|
|
{
|
|
|
|
// All virtual members should only be accessed through NavigationState.
|
|
|
|
friend class NavigationState;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MOZ_NORETURN void Unsupported(const char* aOperation) {
|
|
|
|
nsAutoCString str;
|
|
|
|
ToString(str);
|
|
|
|
|
|
|
|
Print("Operation %s not supported: %s\n", aOperation, str.get());
|
|
|
|
MOZ_CRASH("Unsupported navigation operation");
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void ToString(nsAutoCString& aStr) = 0;
|
|
|
|
|
|
|
|
// The process has just reached or rewound to a checkpoint.
|
|
|
|
virtual void AfterCheckpoint(const CheckpointId& aCheckpoint) {
|
|
|
|
Unsupported("AfterCheckpoint");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when some position with an installed handler has been reached.
|
|
|
|
virtual void PositionHit(const ExecutionPoint& aPoint) {
|
|
|
|
Unsupported("PositionHit");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called after receiving a resume command from the middleman.
|
|
|
|
virtual void Resume(bool aForward) {
|
|
|
|
Unsupported("Resume");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called after the middleman tells us to rewind to a specific checkpoint.
|
|
|
|
virtual void RestoreCheckpoint(size_t aCheckpoint) {
|
|
|
|
Unsupported("RestoreCheckpoint");
|
|
|
|
}
|
|
|
|
|
2018-08-03 02:27:39 +03:00
|
|
|
// Called after the middleman tells us to run forward to a specific point.
|
|
|
|
virtual void RunToPoint(const ExecutionPoint& aTarget) {
|
|
|
|
Unsupported("RunToPoint");
|
|
|
|
}
|
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
// Process an incoming debugger request from the middleman.
|
|
|
|
virtual void HandleDebuggerRequest(js::CharBuffer* aRequestBuffer) {
|
|
|
|
Unsupported("HandleDebuggerRequest");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when a debugger request wants to try an operation that may
|
|
|
|
// trigger an unhandled divergence from the recording.
|
|
|
|
virtual bool MaybeDivergeFromRecording() {
|
|
|
|
Unsupported("MaybeDivergeFromRecording");
|
|
|
|
}
|
|
|
|
|
2018-11-06 20:37:22 +03:00
|
|
|
// Get the current execution point.
|
|
|
|
virtual ExecutionPoint CurrentExecutionPoint() {
|
|
|
|
Unsupported("CurrentExecutionPoint");
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called when execution reaches the endpoint of the recording.
|
|
|
|
virtual void HitRecordingEndpoint(const ExecutionPoint& aPoint) {
|
|
|
|
Unsupported("HitRecordingEndpoint");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Information about a debugger request sent by the middleman.
|
|
|
|
struct RequestInfo
|
|
|
|
{
|
|
|
|
// JSON contents for the request and response.
|
|
|
|
InfallibleVector<char16_t, 0, UntrackedAllocPolicy> mRequestBuffer;
|
|
|
|
InfallibleVector<char16_t, 0, UntrackedAllocPolicy> mResponseBuffer;
|
|
|
|
|
|
|
|
// Whether processing this request triggered an unhandled divergence.
|
|
|
|
bool mUnhandledDivergence;
|
|
|
|
|
|
|
|
RequestInfo() : mUnhandledDivergence(false) {}
|
|
|
|
|
|
|
|
RequestInfo(const RequestInfo& o)
|
|
|
|
: mUnhandledDivergence(o.mUnhandledDivergence)
|
|
|
|
{
|
|
|
|
mRequestBuffer.append(o.mRequestBuffer.begin(), o.mRequestBuffer.length());
|
|
|
|
mResponseBuffer.append(o.mResponseBuffer.begin(), o.mResponseBuffer.length());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
typedef InfallibleVector<RequestInfo, 4, UntrackedAllocPolicy> UntrackedRequestVector;
|
|
|
|
|
|
|
|
typedef InfallibleVector<uint32_t> BreakpointVector;
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
// Phase when the replaying process is paused.
|
|
|
|
class PausedPhase final : public NavigationPhase
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
2018-08-18 18:39:48 +03:00
|
|
|
// Location of the pause.
|
2018-07-22 14:58:24 +03:00
|
|
|
ExecutionPoint mPoint;
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
// Whether we are paused at the end of the recording.
|
|
|
|
bool mRecordingEndpoint;
|
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
// All debugger requests we have seen while paused here.
|
|
|
|
UntrackedRequestVector mRequests;
|
|
|
|
|
|
|
|
// Index of the request currently being processed. Normally this is the
|
|
|
|
// last entry in |mRequests|, though may be earlier if we are recovering
|
|
|
|
// from an unhandled divergence.
|
|
|
|
size_t mRequestIndex;
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
// Whether we have saved a temporary checkpoint.
|
|
|
|
bool mSavedTemporaryCheckpoint;
|
|
|
|
|
|
|
|
// Whether we had to restore a checkpoint to deal with an unhandled
|
|
|
|
// recording divergence, and haven't finished rehandling old requests.
|
|
|
|
bool mRecoveringFromDivergence;
|
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
// Set when we were told to resume forward and need to clean up our state.
|
|
|
|
bool mResumeForward;
|
|
|
|
|
|
|
|
public:
|
2018-08-18 18:39:48 +03:00
|
|
|
void Enter(const ExecutionPoint& aPoint,
|
|
|
|
const BreakpointVector& aBreakpoints = BreakpointVector(),
|
|
|
|
bool aRewind = false, bool aRecordingEndpoint = false);
|
2018-07-22 14:58:24 +03:00
|
|
|
|
|
|
|
void ToString(nsAutoCString& aStr) override {
|
2018-08-18 18:39:48 +03:00
|
|
|
aStr.AppendPrintf("Paused RecoveringFromDivergence %d", mRecoveringFromDivergence);
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AfterCheckpoint(const CheckpointId& aCheckpoint) override;
|
|
|
|
void PositionHit(const ExecutionPoint& aPoint) override;
|
|
|
|
void Resume(bool aForward) override;
|
|
|
|
void RestoreCheckpoint(size_t aCheckpoint) override;
|
2018-08-18 18:39:48 +03:00
|
|
|
void RunToPoint(const ExecutionPoint& aTarget) override;
|
2018-07-22 14:58:24 +03:00
|
|
|
void HandleDebuggerRequest(js::CharBuffer* aRequestBuffer) override;
|
|
|
|
bool MaybeDivergeFromRecording() override;
|
2018-11-06 20:37:22 +03:00
|
|
|
ExecutionPoint CurrentExecutionPoint() override;
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
bool EnsureTemporaryCheckpoint();
|
2018-07-22 14:58:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Phase when execution is proceeding forwards in search of breakpoint hits.
|
|
|
|
class ForwardPhase final : public NavigationPhase
|
|
|
|
{
|
|
|
|
// Some execution point in the recent past. There are no checkpoints or
|
|
|
|
// breakpoint hits between this point and the current point of execution.
|
|
|
|
ExecutionPoint mPoint;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Enter(const ExecutionPoint& aPoint);
|
|
|
|
|
|
|
|
void ToString(nsAutoCString& aStr) override {
|
|
|
|
aStr.AppendPrintf("Forward");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AfterCheckpoint(const CheckpointId& aCheckpoint) override;
|
|
|
|
void PositionHit(const ExecutionPoint& aPoint) override;
|
|
|
|
void HitRecordingEndpoint(const ExecutionPoint& aPoint) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Phase when the replaying process is running forward from a checkpoint to a
|
|
|
|
// breakpoint at a particular execution point.
|
|
|
|
class ReachBreakpointPhase final : public NavigationPhase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
// Where to start running from.
|
|
|
|
CheckpointId mStart;
|
|
|
|
|
|
|
|
// The point we are running to.
|
|
|
|
ExecutionPoint mPoint;
|
|
|
|
|
|
|
|
// Point at which to decide whether to save a temporary checkpoint.
|
|
|
|
Maybe<ExecutionPoint> mTemporaryCheckpoint;
|
|
|
|
|
|
|
|
// Whether we have saved a temporary checkpoint at the specified point.
|
|
|
|
bool mSavedTemporaryCheckpoint;
|
|
|
|
|
|
|
|
// The time at which we started running forward from the initial
|
|
|
|
// checkpoint, in microseconds.
|
|
|
|
double mStartTime;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Enter(const CheckpointId& aStart,
|
2018-08-03 02:27:39 +03:00
|
|
|
bool aRewind,
|
2018-07-22 14:58:24 +03:00
|
|
|
const ExecutionPoint& aPoint,
|
|
|
|
const Maybe<ExecutionPoint>& aTemporaryCheckpoint);
|
|
|
|
|
|
|
|
void ToString(nsAutoCString& aStr) override {
|
|
|
|
aStr.AppendPrintf("ReachBreakpoint: ");
|
|
|
|
ExecutionPointToString(mPoint, aStr);
|
|
|
|
if (mTemporaryCheckpoint.isSome()) {
|
|
|
|
aStr.AppendPrintf(" TemporaryCheckpoint: ");
|
|
|
|
ExecutionPointToString(mTemporaryCheckpoint.ref(), aStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AfterCheckpoint(const CheckpointId& aCheckpoint) override;
|
|
|
|
void PositionHit(const ExecutionPoint& aPoint) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Phase when the replaying process is searching forward from a checkpoint to
|
|
|
|
// find the last point a breakpoint is hit before reaching an execution point.
|
|
|
|
class FindLastHitPhase final : public NavigationPhase
|
|
|
|
{
|
|
|
|
// Where we started searching from.
|
|
|
|
CheckpointId mStart;
|
|
|
|
|
|
|
|
// Endpoint of the search, nothing if the endpoint is the next checkpoint.
|
|
|
|
Maybe<ExecutionPoint> mEnd;
|
|
|
|
|
|
|
|
// Counter that increases as we run forward, for ordering hits.
|
|
|
|
size_t mCounter;
|
|
|
|
|
|
|
|
// All positions we are interested in hits for, including all breakpoint
|
|
|
|
// positions (and possibly other positions).
|
|
|
|
struct TrackedPosition {
|
|
|
|
BreakpointPosition mPosition;
|
|
|
|
|
|
|
|
// The last time this was hit so far, or invalid.
|
|
|
|
ExecutionPoint mLastHit;
|
|
|
|
|
|
|
|
// The value of the counter when the last hit occurred.
|
|
|
|
size_t mLastHitCount;
|
|
|
|
|
|
|
|
explicit TrackedPosition(const BreakpointPosition& aPosition)
|
|
|
|
: mPosition(aPosition), mLastHitCount(0)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
InfallibleVector<TrackedPosition, 4, UntrackedAllocPolicy> mTrackedPositions;
|
|
|
|
|
|
|
|
const TrackedPosition& FindTrackedPosition(const BreakpointPosition& aPos);
|
|
|
|
void OnRegionEnd();
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Note: this always rewinds.
|
|
|
|
void Enter(const CheckpointId& aStart, const Maybe<ExecutionPoint>& aEnd);
|
|
|
|
|
|
|
|
void ToString(nsAutoCString& aStr) override {
|
|
|
|
aStr.AppendPrintf("FindLastHit");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AfterCheckpoint(const CheckpointId& aCheckpoint) override;
|
|
|
|
void PositionHit(const ExecutionPoint& aPoint) override;
|
|
|
|
void HitRecordingEndpoint(const ExecutionPoint& aPoint) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Structure which manages state about the breakpoints in existence and about
|
|
|
|
// how the process is being navigated through. This is allocated in untracked
|
|
|
|
// memory and its contents will not change when restoring an earlier
|
|
|
|
// checkpoint.
|
|
|
|
class NavigationState
|
|
|
|
{
|
|
|
|
// When replaying, the last known recording endpoint. There may be other,
|
|
|
|
// later endpoints we haven't been informed about.
|
|
|
|
ExecutionPoint mRecordingEndpoint;
|
|
|
|
size_t mRecordingEndpointIndex;
|
|
|
|
|
|
|
|
// The last checkpoint we ran forward or rewound to.
|
|
|
|
CheckpointId mLastCheckpoint;
|
|
|
|
|
|
|
|
// The locations of all temporary checkpoints we have saved. Temporary
|
|
|
|
// checkpoints are taken immediately prior to reaching these points.
|
|
|
|
InfallibleVector<ExecutionPoint, 0, UntrackedAllocPolicy> mTemporaryCheckpoints;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// All the currently installed breakpoints, indexed by their ID.
|
|
|
|
InfallibleVector<BreakpointPosition, 4, UntrackedAllocPolicy> mBreakpoints;
|
|
|
|
|
|
|
|
BreakpointPosition& GetBreakpoint(size_t id) {
|
|
|
|
while (id >= mBreakpoints.length()) {
|
|
|
|
mBreakpoints.emplaceBack();
|
|
|
|
}
|
|
|
|
return mBreakpoints[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckpointId LastCheckpoint() {
|
|
|
|
return mLastCheckpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The current phase of the process.
|
|
|
|
NavigationPhase* mPhase;
|
|
|
|
|
|
|
|
void SetPhase(NavigationPhase* phase) {
|
|
|
|
mPhase = phase;
|
|
|
|
|
|
|
|
if (SpewEnabled()) {
|
|
|
|
nsAutoCString str;
|
|
|
|
mPhase->ToString(str);
|
|
|
|
|
|
|
|
PrintSpew("SetNavigationPhase %s\n", str.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
PausedPhase mPausedPhase;
|
2018-07-22 14:58:24 +03:00
|
|
|
ForwardPhase mForwardPhase;
|
|
|
|
ReachBreakpointPhase mReachBreakpointPhase;
|
|
|
|
FindLastHitPhase mFindLastHitPhase;
|
|
|
|
|
|
|
|
// For testing, specify that temporary checkpoints should be taken regardless
|
|
|
|
// of how much time has elapsed.
|
|
|
|
bool mAlwaysSaveTemporaryCheckpoints;
|
|
|
|
|
2018-11-06 20:37:41 +03:00
|
|
|
// Progress counts for all checkpoints that have been encountered.
|
|
|
|
InfallibleVector<ProgressCounter, 0, UntrackedAllocPolicy> mCheckpointProgress;
|
2018-08-03 02:26:25 +03:00
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
// Note: NavigationState is initially zeroed.
|
|
|
|
NavigationState()
|
|
|
|
: mPhase(&mForwardPhase)
|
|
|
|
{
|
|
|
|
if (IsReplaying()) {
|
|
|
|
// The recording must include everything up to the first
|
|
|
|
// checkpoint. After that point we will ask the record/replay
|
|
|
|
// system to notify us about any further endpoints.
|
2018-11-06 20:37:41 +03:00
|
|
|
mRecordingEndpoint = ExecutionPoint(CheckpointId::First, 0);
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
2018-11-06 20:37:41 +03:00
|
|
|
mCheckpointProgress.append(0);
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AfterCheckpoint(const CheckpointId& aCheckpoint) {
|
|
|
|
mLastCheckpoint = aCheckpoint;
|
|
|
|
|
|
|
|
// Forget any temporary checkpoints we just rewound past, or made
|
|
|
|
// obsolete by reaching the next normal checkpoint.
|
|
|
|
while (mTemporaryCheckpoints.length() > aCheckpoint.mTemporary) {
|
|
|
|
mTemporaryCheckpoints.popBack();
|
|
|
|
}
|
|
|
|
|
2018-11-06 20:37:41 +03:00
|
|
|
// Update the progress counter for each normal checkpoint.
|
|
|
|
if (!aCheckpoint.mTemporary) {
|
|
|
|
ProgressCounter progress = *ExecutionProgressCounter();
|
|
|
|
if (aCheckpoint.mNormal < mCheckpointProgress.length()) {
|
|
|
|
MOZ_RELEASE_ASSERT(progress == mCheckpointProgress[aCheckpoint.mNormal]);
|
|
|
|
} else {
|
|
|
|
MOZ_RELEASE_ASSERT(aCheckpoint.mNormal == mCheckpointProgress.length());
|
|
|
|
mCheckpointProgress.append(progress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
mPhase->AfterCheckpoint(aCheckpoint);
|
|
|
|
|
|
|
|
// Make sure we don't run past the end of the recording.
|
|
|
|
if (!aCheckpoint.mTemporary) {
|
2018-11-06 20:37:41 +03:00
|
|
|
CheckForRecordingEndpoint(CheckpointExecutionPoint(aCheckpoint.mNormal));
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(IsRecording() ||
|
|
|
|
aCheckpoint.mNormal <= mRecordingEndpoint.mCheckpoint);
|
2018-08-18 18:39:48 +03:00
|
|
|
if (aCheckpoint.mNormal == mRecordingEndpoint.mCheckpoint &&
|
|
|
|
mRecordingEndpoint.HasPosition()) {
|
2018-07-22 14:58:24 +03:00
|
|
|
js::EnsurePositionHandler(mRecordingEndpoint.mPosition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PositionHit(const ExecutionPoint& aPoint) {
|
|
|
|
mPhase->PositionHit(aPoint);
|
|
|
|
CheckForRecordingEndpoint(aPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Resume(bool aForward) {
|
|
|
|
mPhase->Resume(aForward);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreCheckpoint(size_t aCheckpoint) {
|
|
|
|
mPhase->RestoreCheckpoint(aCheckpoint);
|
|
|
|
}
|
|
|
|
|
2018-08-03 02:27:39 +03:00
|
|
|
void RunToPoint(const ExecutionPoint& aTarget) {
|
|
|
|
mPhase->RunToPoint(aTarget);
|
|
|
|
}
|
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
void HandleDebuggerRequest(js::CharBuffer* aRequestBuffer) {
|
|
|
|
mPhase->HandleDebuggerRequest(aRequestBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MaybeDivergeFromRecording() {
|
|
|
|
return mPhase->MaybeDivergeFromRecording();
|
|
|
|
}
|
|
|
|
|
2018-11-06 20:37:22 +03:00
|
|
|
ExecutionPoint CurrentExecutionPoint() {
|
|
|
|
return mPhase->CurrentExecutionPoint();
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetRecordingEndpoint(size_t aIndex, const ExecutionPoint& aEndpoint) {
|
|
|
|
// Ignore endpoints older than the last one we know about.
|
|
|
|
if (aIndex <= mRecordingEndpointIndex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_RELEASE_ASSERT(mRecordingEndpoint.mCheckpoint <= aEndpoint.mCheckpoint);
|
|
|
|
mRecordingEndpointIndex = aIndex;
|
|
|
|
mRecordingEndpoint = aEndpoint;
|
|
|
|
if (aEndpoint.HasPosition()) {
|
|
|
|
js::EnsurePositionHandler(aEndpoint.mPosition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckForRecordingEndpoint(const ExecutionPoint& aPoint) {
|
|
|
|
while (aPoint == mRecordingEndpoint) {
|
|
|
|
// The recording ended after the checkpoint, but maybe there is
|
|
|
|
// another, later endpoint now. This may call back into
|
|
|
|
// setRecordingEndpoint and notify us there is more recording data
|
|
|
|
// available.
|
|
|
|
if (!recordreplay::HitRecordingEndpoint()) {
|
|
|
|
mPhase->HitRecordingEndpoint(mRecordingEndpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-06 20:37:22 +03:00
|
|
|
ExecutionPoint LastRecordingEndpoint() {
|
|
|
|
// Get the last recording endpoint in the recording file.
|
|
|
|
while (recordreplay::HitRecordingEndpoint()) {}
|
|
|
|
return mRecordingEndpoint;
|
|
|
|
}
|
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
size_t NumTemporaryCheckpoints() {
|
|
|
|
return mTemporaryCheckpoints.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SaveTemporaryCheckpoint(const ExecutionPoint& aPoint) {
|
|
|
|
MOZ_RELEASE_ASSERT(aPoint.mCheckpoint == mLastCheckpoint.mNormal);
|
|
|
|
mTemporaryCheckpoints.append(aPoint);
|
|
|
|
return NewCheckpoint(/* aTemporary = */ true);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExecutionPoint LastTemporaryCheckpointLocation() {
|
|
|
|
MOZ_RELEASE_ASSERT(!mTemporaryCheckpoints.empty());
|
|
|
|
return mTemporaryCheckpoints.back();
|
|
|
|
}
|
2018-11-06 20:37:41 +03:00
|
|
|
|
|
|
|
ExecutionPoint CheckpointExecutionPoint(size_t aCheckpoint) {
|
|
|
|
MOZ_RELEASE_ASSERT(aCheckpoint < mCheckpointProgress.length());
|
|
|
|
return ExecutionPoint(aCheckpoint, mCheckpointProgress[aCheckpoint]);
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static NavigationState* gNavigation;
|
|
|
|
|
|
|
|
static void
|
|
|
|
GetAllBreakpointHits(const ExecutionPoint& aPoint, BreakpointVector& aHitBreakpoints)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(aPoint.HasPosition());
|
|
|
|
for (size_t id = 0; id < gNavigation->mBreakpoints.length(); id++) {
|
|
|
|
const BreakpointPosition& breakpoint = gNavigation->mBreakpoints[id];
|
|
|
|
if (breakpoint.IsValid() && breakpoint.Subsumes(aPoint.mPosition)) {
|
|
|
|
aHitBreakpoints.append(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2018-08-18 18:39:48 +03:00
|
|
|
// Paused Phase
|
2018-07-22 14:58:24 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ThisProcessCanRewind()
|
|
|
|
{
|
|
|
|
return HasSavedCheckpoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-08-18 18:39:48 +03:00
|
|
|
PausedPhase::Enter(const ExecutionPoint& aPoint, const BreakpointVector& aBreakpoints,
|
|
|
|
bool aRewind, bool aRecordingEndpoint)
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
|
|
|
mPoint = aPoint;
|
2018-08-18 18:39:48 +03:00
|
|
|
mRecordingEndpoint = aRecordingEndpoint;
|
2018-07-22 14:58:24 +03:00
|
|
|
mRequests.clear();
|
|
|
|
mRequestIndex = 0;
|
2018-08-18 18:39:48 +03:00
|
|
|
mSavedTemporaryCheckpoint = false;
|
|
|
|
mRecoveringFromDivergence = false;
|
2018-07-22 14:58:24 +03:00
|
|
|
mResumeForward = false;
|
|
|
|
|
|
|
|
gNavigation->SetPhase(this);
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
// Breakpoints will never be hit if we are at a checkpoint.
|
|
|
|
MOZ_RELEASE_ASSERT(aPoint.HasPosition() || aBreakpoints.empty());
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
if (aRewind) {
|
|
|
|
MOZ_RELEASE_ASSERT(!aPoint.HasPosition());
|
|
|
|
RestoreCheckpointAndResume(CheckpointId(aPoint.mCheckpoint));
|
|
|
|
Unreachable();
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
if (aPoint.HasPosition()) {
|
|
|
|
child::HitBreakpoint(aRecordingEndpoint, aBreakpoints.begin(), aBreakpoints.length());
|
|
|
|
} else {
|
|
|
|
child::HitCheckpoint(aPoint.mCheckpoint, aRecordingEndpoint);
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-08-18 18:39:48 +03:00
|
|
|
PausedPhase::AfterCheckpoint(const CheckpointId& aCheckpoint)
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
2018-08-18 18:39:48 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mRecoveringFromDivergence);
|
|
|
|
if (!aCheckpoint.mTemporary) {
|
|
|
|
// We just rewound here, and are now where we should pause.
|
2018-11-06 20:37:41 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mPoint == gNavigation->CheckpointExecutionPoint(aCheckpoint.mNormal));
|
2018-08-18 18:39:48 +03:00
|
|
|
child::HitCheckpoint(mPoint.mCheckpoint, mRecordingEndpoint);
|
|
|
|
} else {
|
|
|
|
// We just saved or restored the temporary checkpoint taken while
|
|
|
|
// processing debugger requests here.
|
|
|
|
MOZ_RELEASE_ASSERT(ThisProcessCanRewind());
|
|
|
|
MOZ_RELEASE_ASSERT(mSavedTemporaryCheckpoint);
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-08-18 18:39:48 +03:00
|
|
|
PausedPhase::PositionHit(const ExecutionPoint& aPoint)
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
|
|
|
// Ignore positions hit while paused (we're probably doing an eval).
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-08-18 18:39:48 +03:00
|
|
|
PausedPhase::Resume(bool aForward)
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(!mRecoveringFromDivergence);
|
2018-08-18 18:39:48 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mResumeForward);
|
2018-07-22 14:58:24 +03:00
|
|
|
|
|
|
|
if (aForward) {
|
2018-08-18 18:39:48 +03:00
|
|
|
// If we have saved any temporary checkpoint, we performed an operation
|
|
|
|
// that may have side effects. Clear these unwanted changes by restoring
|
|
|
|
// the temporary checkpoint we saved earlier.
|
|
|
|
if (mSavedTemporaryCheckpoint) {
|
2018-07-22 14:58:24 +03:00
|
|
|
mResumeForward = true;
|
2018-08-18 18:39:48 +03:00
|
|
|
RestoreCheckpointAndResume(gNavigation->LastCheckpoint());
|
2018-07-22 14:58:24 +03:00
|
|
|
Unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
js::ClearPausedState();
|
|
|
|
|
|
|
|
// Run forward from the current execution point.
|
|
|
|
gNavigation->mForwardPhase.Enter(mPoint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search backwards in the execution space.
|
2018-08-18 18:39:48 +03:00
|
|
|
if (mPoint.HasPosition()) {
|
|
|
|
CheckpointId start = gNavigation->LastCheckpoint();
|
|
|
|
|
|
|
|
// Skip over any temporary checkpoint we saved.
|
|
|
|
if (mSavedTemporaryCheckpoint) {
|
|
|
|
MOZ_RELEASE_ASSERT(start.mTemporary);
|
|
|
|
start.mTemporary--;
|
|
|
|
}
|
|
|
|
gNavigation->mFindLastHitPhase.Enter(start, Some(mPoint));
|
|
|
|
} else {
|
|
|
|
// We can't rewind past the beginning of the replay.
|
|
|
|
MOZ_RELEASE_ASSERT(mPoint.mCheckpoint != CheckpointId::First);
|
|
|
|
|
|
|
|
CheckpointId start(mPoint.mCheckpoint - 1);
|
|
|
|
gNavigation->mFindLastHitPhase.Enter(start, Nothing());
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
Unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-08-18 18:39:48 +03:00
|
|
|
PausedPhase::RestoreCheckpoint(size_t aCheckpoint)
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
2018-11-06 20:37:41 +03:00
|
|
|
ExecutionPoint target = gNavigation->CheckpointExecutionPoint(aCheckpoint);
|
2018-08-18 18:39:48 +03:00
|
|
|
bool rewind = target != mPoint;
|
|
|
|
Enter(target, BreakpointVector(), rewind, /* aRecordingEndpoint = */ false);
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-08-18 18:39:48 +03:00
|
|
|
PausedPhase::RunToPoint(const ExecutionPoint& aTarget)
|
|
|
|
{
|
|
|
|
// This may only be used when we are paused at a normal checkpoint.
|
|
|
|
MOZ_RELEASE_ASSERT(!mPoint.HasPosition());
|
|
|
|
size_t checkpoint = mPoint.mCheckpoint;
|
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(aTarget.mCheckpoint == checkpoint);
|
|
|
|
ResumeExecution();
|
|
|
|
gNavigation->mReachBreakpointPhase.Enter(CheckpointId(checkpoint), /* aRewind = */ false,
|
|
|
|
aTarget, /* aTemporaryCheckpoint = */ Nothing());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PausedPhase::HandleDebuggerRequest(js::CharBuffer* aRequestBuffer)
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(!mRecoveringFromDivergence);
|
2018-08-18 18:39:48 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mResumeForward);
|
2018-07-22 14:58:24 +03:00
|
|
|
|
|
|
|
mRequests.emplaceBack();
|
2018-08-18 18:39:48 +03:00
|
|
|
size_t index = mRequests.length() - 1;
|
|
|
|
mRequests[index].mRequestBuffer.append(aRequestBuffer->begin(), aRequestBuffer->length());
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
mRequestIndex = index;
|
2018-07-22 14:58:24 +03:00
|
|
|
|
|
|
|
js::CharBuffer responseBuffer;
|
|
|
|
js::ProcessRequest(aRequestBuffer->begin(), aRequestBuffer->length(), &responseBuffer);
|
|
|
|
|
|
|
|
delete aRequestBuffer;
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
if (gNavigation->mPhase != this) {
|
|
|
|
// We saved a temporary checkpoint by calling MaybeDivergeFromRecording
|
|
|
|
// within ProcessRequest, then restored it while scanning backwards.
|
|
|
|
ResumeExecution();
|
|
|
|
return;
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
if (!mResumeForward && !mRecoveringFromDivergence) {
|
|
|
|
// We processed this request normally. Remember the response and send it to
|
|
|
|
// the middleman process.
|
|
|
|
MOZ_RELEASE_ASSERT(index == mRequestIndex);
|
|
|
|
mRequests[index].mResponseBuffer.append(responseBuffer.begin(), responseBuffer.length());
|
|
|
|
child::RespondToRequest(responseBuffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mResumeForward) {
|
|
|
|
// We rewound to erase side effects from the temporary checkpoint we saved
|
|
|
|
// under ProcessRequest. Just start running forward.
|
|
|
|
MOZ_RELEASE_ASSERT(!mRecoveringFromDivergence);
|
|
|
|
gNavigation->mForwardPhase.Enter(mPoint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We rewound after having an unhandled recording divergence while processing
|
|
|
|
// mRequests[index] or some later request. We need to redo all requests up to
|
|
|
|
// the last request we received.
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
// Remember that the last request triggered an unhandled divergence.
|
2018-07-22 14:58:24 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mRequests.back().mUnhandledDivergence);
|
|
|
|
mRequests.back().mUnhandledDivergence = true;
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
for (size_t i = index; i < mRequests.length(); i++) {
|
2018-07-22 14:58:24 +03:00
|
|
|
RequestInfo& info = mRequests[i];
|
|
|
|
mRequestIndex = i;
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
if (i == index) {
|
|
|
|
// We just performed this request, and responseBuffer has the right contents.
|
|
|
|
} else {
|
|
|
|
responseBuffer.clear();
|
|
|
|
js::ProcessRequest(info.mRequestBuffer.begin(), info.mRequestBuffer.length(),
|
|
|
|
&responseBuffer);
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
|
|
|
|
if (i < mRequests.length() - 1) {
|
|
|
|
// This is an old request, and we don't need to send another
|
|
|
|
// response to it. Make sure the response we just generated matched
|
|
|
|
// the earlier one we sent, though.
|
|
|
|
MOZ_RELEASE_ASSERT(responseBuffer.length() == info.mResponseBuffer.length());
|
|
|
|
MOZ_RELEASE_ASSERT(memcmp(responseBuffer.begin(), info.mResponseBuffer.begin(),
|
|
|
|
responseBuffer.length() * sizeof(char16_t)) == 0);
|
|
|
|
} else {
|
|
|
|
// This is the current request we need to respond to.
|
|
|
|
MOZ_RELEASE_ASSERT(info.mResponseBuffer.empty());
|
|
|
|
info.mResponseBuffer.append(responseBuffer.begin(), responseBuffer.length());
|
|
|
|
child::RespondToRequest(responseBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We've finished recovering, and can now process new incoming requests.
|
|
|
|
mRecoveringFromDivergence = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-08-18 18:39:48 +03:00
|
|
|
PausedPhase::MaybeDivergeFromRecording()
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
|
|
|
if (!ThisProcessCanRewind()) {
|
|
|
|
// Recording divergence is not supported if we can't rewind. We can't
|
|
|
|
// simply allow execution to proceed from here as if we were not
|
|
|
|
// diverged, since any events or other activity that show up afterwards
|
|
|
|
// will not be reflected in the recording.
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-18 18:39:48 +03:00
|
|
|
|
2018-10-17 18:59:32 +03:00
|
|
|
size_t index = mRequestIndex;
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
if (!EnsureTemporaryCheckpoint()) {
|
|
|
|
// One of the premature exit cases was hit in EnsureTemporaryCheckpoint.
|
|
|
|
// Don't allow any operations that can diverge from the recording.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-10-17 18:59:32 +03:00
|
|
|
if (mRequests[index].mUnhandledDivergence) {
|
2018-08-18 18:39:48 +03:00
|
|
|
// We tried to process this request before and had an unhandled divergence.
|
|
|
|
// Disallow the request handler from doing anything that might diverge from
|
|
|
|
// the recording.
|
2018-07-22 14:58:24 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-18 18:39:48 +03:00
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
DivergeFromRecording();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
bool
|
|
|
|
PausedPhase::EnsureTemporaryCheckpoint()
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
2018-08-18 18:39:48 +03:00
|
|
|
if (mSavedTemporaryCheckpoint) {
|
|
|
|
return true;
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
// We need to save a temporary checkpoint that we can restore if we hit
|
|
|
|
// a recording divergence.
|
|
|
|
mSavedTemporaryCheckpoint = true;
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
size_t index = mRequestIndex;
|
|
|
|
if (gNavigation->SaveTemporaryCheckpoint(mPoint)) {
|
|
|
|
// We just saved the temporary checkpoint.
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
// We just rewound here.
|
|
|
|
if (gNavigation->mPhase != this) {
|
|
|
|
// We are no longer paused at this point. We should be searching
|
|
|
|
// backwards in the region after this temporary checkpoint was taken.
|
|
|
|
// Return false to ensure we don't perform any side effects before
|
|
|
|
// resuming forward.
|
|
|
|
return false;
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
// We are still paused at this point. Either we had an unhandled
|
|
|
|
// recording divergence, or we intentionally rewound to erase side
|
|
|
|
// effects that occurred while paused here.
|
|
|
|
MOZ_RELEASE_ASSERT(!mRecoveringFromDivergence);
|
2018-08-03 02:27:39 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
if (mResumeForward) {
|
|
|
|
// We can't diverge from the recording before resuming forward execution.
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
mRecoveringFromDivergence = true;
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
if (index == mRequestIndex) {
|
|
|
|
// We had an unhandled divergence for the same request where we
|
|
|
|
// created the temporary checkpoint. mUnhandledDivergence hasn't been
|
|
|
|
// set yet, but return now to avoid triggering the same divergence
|
|
|
|
// and rewinding again.
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
|
2018-08-18 18:39:48 +03:00
|
|
|
// Allow the caller to check mUnhandledDivergence.
|
|
|
|
return true;
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ExecutionPoint
|
2018-11-06 20:37:22 +03:00
|
|
|
PausedPhase::CurrentExecutionPoint()
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
2018-08-18 18:39:48 +03:00
|
|
|
return mPoint;
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ForwardPhase
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void
|
|
|
|
ForwardPhase::Enter(const ExecutionPoint& aPoint)
|
|
|
|
{
|
|
|
|
mPoint = aPoint;
|
|
|
|
|
|
|
|
gNavigation->SetPhase(this);
|
|
|
|
|
|
|
|
// Install handlers for all breakpoints.
|
|
|
|
for (const BreakpointPosition& breakpoint : gNavigation->mBreakpoints) {
|
|
|
|
if (breakpoint.IsValid()) {
|
|
|
|
js::EnsurePositionHandler(breakpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResumeExecution();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ForwardPhase::AfterCheckpoint(const CheckpointId& aCheckpoint)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(!aCheckpoint.mTemporary &&
|
|
|
|
aCheckpoint.mNormal == mPoint.mCheckpoint + 1);
|
2018-11-06 20:37:41 +03:00
|
|
|
gNavigation->mPausedPhase.Enter(gNavigation->CheckpointExecutionPoint(aCheckpoint.mNormal));
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ForwardPhase::PositionHit(const ExecutionPoint& aPoint)
|
|
|
|
{
|
|
|
|
BreakpointVector hitBreakpoints;
|
|
|
|
GetAllBreakpointHits(aPoint, hitBreakpoints);
|
|
|
|
|
|
|
|
if (!hitBreakpoints.empty()) {
|
2018-08-18 18:39:48 +03:00
|
|
|
gNavigation->mPausedPhase.Enter(aPoint, hitBreakpoints);
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ForwardPhase::HitRecordingEndpoint(const ExecutionPoint& aPoint)
|
|
|
|
{
|
2018-08-18 18:39:48 +03:00
|
|
|
nsAutoCString str;
|
|
|
|
ExecutionPointToString(aPoint, str);
|
|
|
|
|
|
|
|
// Use an empty vector even if there are breakpoints here. If we started
|
|
|
|
// running forward from aPoint and immediately hit the recording endpoint,
|
|
|
|
// we don't want to hit the breakpoints again.
|
|
|
|
gNavigation->mPausedPhase.Enter(aPoint, BreakpointVector(),
|
|
|
|
/* aRewind = */ false, /* aRecordingEndpoint = */ true);
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ReachBreakpointPhase
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void
|
|
|
|
ReachBreakpointPhase::Enter(const CheckpointId& aStart,
|
2018-08-03 02:27:39 +03:00
|
|
|
bool aRewind,
|
2018-07-22 14:58:24 +03:00
|
|
|
const ExecutionPoint& aPoint,
|
|
|
|
const Maybe<ExecutionPoint>& aTemporaryCheckpoint)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(aPoint.HasPosition());
|
|
|
|
MOZ_RELEASE_ASSERT(aTemporaryCheckpoint.isNothing() ||
|
|
|
|
(aTemporaryCheckpoint.ref().HasPosition() &&
|
|
|
|
aTemporaryCheckpoint.ref() != aPoint));
|
|
|
|
mStart = aStart;
|
|
|
|
mPoint = aPoint;
|
|
|
|
mTemporaryCheckpoint = aTemporaryCheckpoint;
|
|
|
|
mSavedTemporaryCheckpoint = false;
|
|
|
|
|
|
|
|
gNavigation->SetPhase(this);
|
|
|
|
|
2018-08-03 02:27:39 +03:00
|
|
|
if (aRewind) {
|
|
|
|
RestoreCheckpointAndResume(aStart);
|
|
|
|
Unreachable();
|
|
|
|
} else {
|
|
|
|
AfterCheckpoint(aStart);
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ReachBreakpointPhase::AfterCheckpoint(const CheckpointId& aCheckpoint)
|
|
|
|
{
|
|
|
|
if (aCheckpoint == mStart && mTemporaryCheckpoint.isSome()) {
|
|
|
|
js::EnsurePositionHandler(mTemporaryCheckpoint.ref().mPosition);
|
|
|
|
|
|
|
|
// Remember the time we started running forwards from the initial checkpoint.
|
|
|
|
mStartTime = CurrentTime();
|
|
|
|
} else {
|
|
|
|
MOZ_RELEASE_ASSERT((aCheckpoint == mStart && mTemporaryCheckpoint.isNothing()) ||
|
|
|
|
(aCheckpoint == mStart.NextCheckpoint(/* aTemporary = */ true) &&
|
|
|
|
mSavedTemporaryCheckpoint));
|
|
|
|
}
|
|
|
|
|
|
|
|
js::EnsurePositionHandler(mPoint.mPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The number of milliseconds to elapse during a ReachBreakpoint search before
|
|
|
|
// we will save a temporary checkpoint.
|
|
|
|
static const double kTemporaryCheckpointThresholdMs = 10;
|
|
|
|
|
|
|
|
void
|
|
|
|
AlwaysSaveTemporaryCheckpoints()
|
|
|
|
{
|
|
|
|
gNavigation->mAlwaysSaveTemporaryCheckpoints = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ReachBreakpointPhase::PositionHit(const ExecutionPoint& aPoint)
|
|
|
|
{
|
|
|
|
if (mTemporaryCheckpoint.isSome() && mTemporaryCheckpoint.ref() == aPoint) {
|
|
|
|
// We've reached the point at which we have the option of saving a
|
|
|
|
// temporary checkpoint.
|
|
|
|
double elapsedMs = (CurrentTime() - mStartTime) / 1000.0;
|
|
|
|
if (elapsedMs >= kTemporaryCheckpointThresholdMs ||
|
|
|
|
gNavigation->mAlwaysSaveTemporaryCheckpoints)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(!mSavedTemporaryCheckpoint);
|
|
|
|
mSavedTemporaryCheckpoint = true;
|
|
|
|
|
|
|
|
if (!gNavigation->SaveTemporaryCheckpoint(aPoint)) {
|
|
|
|
// We just restored the checkpoint, and could be in any phase.
|
|
|
|
gNavigation->PositionHit(aPoint);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPoint == aPoint) {
|
|
|
|
BreakpointVector hitBreakpoints;
|
|
|
|
GetAllBreakpointHits(aPoint, hitBreakpoints);
|
2018-08-18 18:39:48 +03:00
|
|
|
gNavigation->mPausedPhase.Enter(aPoint, hitBreakpoints);
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FindLastHitPhase
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void
|
|
|
|
FindLastHitPhase::Enter(const CheckpointId& aStart, const Maybe<ExecutionPoint>& aEnd)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(aEnd.isNothing() || aEnd.ref().HasPosition());
|
|
|
|
|
|
|
|
mStart = aStart;
|
|
|
|
mEnd = aEnd;
|
|
|
|
mCounter = 0;
|
|
|
|
mTrackedPositions.clear();
|
|
|
|
|
|
|
|
gNavigation->SetPhase(this);
|
|
|
|
|
|
|
|
// All breakpoints are tracked positions.
|
|
|
|
for (const BreakpointPosition& breakpoint : gNavigation->mBreakpoints) {
|
|
|
|
if (breakpoint.IsValid()) {
|
|
|
|
mTrackedPositions.emplaceBack(breakpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Entry points to scripts containing breakpoints are tracked positions.
|
|
|
|
for (const BreakpointPosition& breakpoint : gNavigation->mBreakpoints) {
|
|
|
|
Maybe<BreakpointPosition> entry = GetEntryPosition(breakpoint);
|
|
|
|
if (entry.isSome()) {
|
|
|
|
mTrackedPositions.emplaceBack(entry.ref());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RestoreCheckpointAndResume(mStart);
|
|
|
|
Unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FindLastHitPhase::AfterCheckpoint(const CheckpointId& aCheckpoint)
|
|
|
|
{
|
|
|
|
if (aCheckpoint == mStart.NextCheckpoint(/* aTemporary = */ false)) {
|
|
|
|
// We reached the next checkpoint, and are done searching.
|
|
|
|
MOZ_RELEASE_ASSERT(mEnd.isNothing());
|
|
|
|
OnRegionEnd();
|
|
|
|
Unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are at the start of the search.
|
|
|
|
MOZ_RELEASE_ASSERT(aCheckpoint == mStart);
|
|
|
|
|
|
|
|
for (const TrackedPosition& tracked : mTrackedPositions) {
|
|
|
|
js::EnsurePositionHandler(tracked.mPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mEnd.isSome()) {
|
|
|
|
js::EnsurePositionHandler(mEnd.ref().mPosition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FindLastHitPhase::PositionHit(const ExecutionPoint& aPoint)
|
|
|
|
{
|
|
|
|
if (mEnd.isSome() && mEnd.ref() == aPoint) {
|
|
|
|
OnRegionEnd();
|
|
|
|
Unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
++mCounter;
|
|
|
|
|
|
|
|
for (TrackedPosition& tracked : mTrackedPositions) {
|
|
|
|
if (tracked.mPosition.Subsumes(aPoint.mPosition)) {
|
|
|
|
tracked.mLastHit = aPoint;
|
|
|
|
tracked.mLastHitCount = mCounter;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FindLastHitPhase::HitRecordingEndpoint(const ExecutionPoint& aPoint)
|
|
|
|
{
|
|
|
|
OnRegionEnd();
|
|
|
|
Unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
const FindLastHitPhase::TrackedPosition&
|
|
|
|
FindLastHitPhase::FindTrackedPosition(const BreakpointPosition& aPos)
|
|
|
|
{
|
|
|
|
for (const TrackedPosition& tracked : mTrackedPositions) {
|
|
|
|
if (tracked.mPosition == aPos) {
|
|
|
|
return tracked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MOZ_CRASH("Could not find tracked position");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FindLastHitPhase::OnRegionEnd()
|
|
|
|
{
|
|
|
|
// Find the point of the last hit which coincides with a breakpoint.
|
|
|
|
Maybe<TrackedPosition> lastBreakpoint;
|
|
|
|
for (const BreakpointPosition& breakpoint : gNavigation->mBreakpoints) {
|
|
|
|
if (!breakpoint.IsValid()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const TrackedPosition& tracked = FindTrackedPosition(breakpoint);
|
|
|
|
if (tracked.mLastHit.HasPosition() &&
|
|
|
|
(lastBreakpoint.isNothing() ||
|
|
|
|
lastBreakpoint.ref().mLastHitCount < tracked.mLastHitCount))
|
|
|
|
{
|
|
|
|
lastBreakpoint = Some(tracked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastBreakpoint.isNothing()) {
|
|
|
|
// No breakpoints were encountered in the search space.
|
|
|
|
if (mStart.mTemporary) {
|
|
|
|
// We started searching forwards from a temporary checkpoint.
|
|
|
|
// Continue searching backwards without notifying the middleman.
|
|
|
|
CheckpointId start = mStart;
|
|
|
|
start.mTemporary--;
|
|
|
|
ExecutionPoint end = gNavigation->LastTemporaryCheckpointLocation();
|
2018-08-18 18:39:48 +03:00
|
|
|
if (end.HasPosition()) {
|
|
|
|
gNavigation->mFindLastHitPhase.Enter(start, Some(end));
|
|
|
|
Unreachable();
|
|
|
|
} else {
|
|
|
|
// The last temporary checkpoint may be at the same execution point as
|
|
|
|
// the last normal checkpoint, if it was created while handling
|
|
|
|
// debugger requests there.
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
2018-08-18 18:39:48 +03:00
|
|
|
|
|
|
|
// Rewind to the last normal checkpoint and pause.
|
2018-11-06 20:37:41 +03:00
|
|
|
gNavigation->mPausedPhase.Enter(gNavigation->CheckpointExecutionPoint(mStart.mNormal),
|
|
|
|
BreakpointVector(), /* aRewind = */ true);
|
2018-08-18 18:39:48 +03:00
|
|
|
Unreachable();
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// When running backwards, we don't want to place temporary checkpoints at
|
|
|
|
// the breakpoint where we are going to stop at. If the user continues
|
|
|
|
// rewinding then we will just have to discard the checkpoint and waste the
|
|
|
|
// work we did in saving it.
|
|
|
|
//
|
|
|
|
// Instead, try to place a temporary checkpoint at the last time the
|
|
|
|
// breakpoint's script was entered. This optimizes for the case of stepping
|
|
|
|
// around within a frame.
|
|
|
|
Maybe<BreakpointPosition> baseEntry = GetEntryPosition(lastBreakpoint.ref().mPosition);
|
|
|
|
if (baseEntry.isSome()) {
|
|
|
|
const TrackedPosition& tracked = FindTrackedPosition(baseEntry.ref());
|
|
|
|
if (tracked.mLastHit.HasPosition() &&
|
|
|
|
tracked.mLastHitCount < lastBreakpoint.ref().mLastHitCount)
|
|
|
|
{
|
2018-08-03 02:27:39 +03:00
|
|
|
gNavigation->mReachBreakpointPhase.Enter(mStart, /* aRewind = */ true,
|
|
|
|
lastBreakpoint.ref().mLastHit,
|
2018-07-22 14:58:24 +03:00
|
|
|
Some(tracked.mLastHit));
|
|
|
|
Unreachable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// There was no suitable place for a temporary checkpoint, so rewind to the
|
|
|
|
// last checkpoint and play forward to the last breakpoint hit we found.
|
2018-08-03 02:27:39 +03:00
|
|
|
gNavigation->mReachBreakpointPhase.Enter(mStart, /* aRewind = */ true,
|
|
|
|
lastBreakpoint.ref().mLastHit, Nothing());
|
2018-07-22 14:58:24 +03:00
|
|
|
Unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Hooks
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsInitialized()
|
|
|
|
{
|
|
|
|
return !!gNavigation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BeforeCheckpoint()
|
|
|
|
{
|
|
|
|
if (!IsInitialized()) {
|
|
|
|
void* navigationMem =
|
|
|
|
AllocateMemory(sizeof(NavigationState), MemoryKind::Navigation);
|
|
|
|
gNavigation = new (navigationMem) NavigationState();
|
|
|
|
|
|
|
|
js::SetupDevtoolsSandbox();
|
2018-11-06 20:37:41 +03:00
|
|
|
|
|
|
|
// Set the progress counter to zero before the first checkpoint. Execution
|
|
|
|
// that occurred before this checkpoint cannot be rewound to.
|
|
|
|
*ExecutionProgressCounter() = 0;
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoDisallowThreadEvents disallow;
|
|
|
|
|
|
|
|
// Reset the debugger to a consistent state before each checkpoint.
|
|
|
|
js::ClearPositionHandlers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AfterCheckpoint(const CheckpointId& aCheckpoint)
|
|
|
|
{
|
|
|
|
AutoDisallowThreadEvents disallow;
|
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(IsRecordingOrReplaying());
|
|
|
|
gNavigation->AfterCheckpoint(aCheckpoint);
|
|
|
|
}
|
|
|
|
|
2018-10-17 19:32:13 +03:00
|
|
|
size_t
|
|
|
|
LastNormalCheckpoint()
|
|
|
|
{
|
|
|
|
return gNavigation->LastCheckpoint().mNormal;
|
|
|
|
}
|
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
void
|
|
|
|
DebuggerRequest(js::CharBuffer* aRequestBuffer)
|
|
|
|
{
|
|
|
|
gNavigation->HandleDebuggerRequest(aRequestBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetBreakpoint(size_t aId, const BreakpointPosition& aPosition)
|
|
|
|
{
|
|
|
|
gNavigation->GetBreakpoint(aId) = aPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Resume(bool aForward)
|
|
|
|
{
|
|
|
|
// For the primordial resume sent at startup, the navigation state will not
|
|
|
|
// have been initialized yet.
|
|
|
|
if (!gNavigation) {
|
|
|
|
ResumeExecution();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gNavigation->Resume(aForward);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RestoreCheckpoint(size_t aId)
|
|
|
|
{
|
|
|
|
gNavigation->RestoreCheckpoint(aId);
|
|
|
|
}
|
|
|
|
|
2018-08-03 02:27:39 +03:00
|
|
|
void
|
|
|
|
RunToPoint(const ExecutionPoint& aTarget)
|
|
|
|
{
|
|
|
|
gNavigation->RunToPoint(aTarget);
|
|
|
|
}
|
|
|
|
|
2018-07-22 14:58:24 +03:00
|
|
|
ExecutionPoint
|
|
|
|
GetRecordingEndpoint()
|
|
|
|
{
|
2018-11-06 20:37:22 +03:00
|
|
|
if (IsRecording()) {
|
|
|
|
return gNavigation->CurrentExecutionPoint();
|
|
|
|
} else {
|
|
|
|
return gNavigation->LastRecordingEndpoint();
|
|
|
|
}
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetRecordingEndpoint(size_t aIndex, const ExecutionPoint& aEndpoint)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(IsReplaying());
|
|
|
|
gNavigation->SetRecordingEndpoint(aIndex, aEndpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ProgressCounter gProgressCounter;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
MOZ_EXPORT ProgressCounter*
|
|
|
|
RecordReplayInterface_ExecutionProgressCounter()
|
|
|
|
{
|
|
|
|
return &gProgressCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
2018-08-03 02:26:25 +03:00
|
|
|
ExecutionPoint
|
2018-11-06 20:37:22 +03:00
|
|
|
CurrentExecutionPoint(const Maybe<BreakpointPosition>& aPosition)
|
2018-07-22 14:58:24 +03:00
|
|
|
{
|
2018-11-06 20:37:22 +03:00
|
|
|
if (aPosition.isSome()) {
|
|
|
|
return ExecutionPoint(gNavigation->LastCheckpoint().mNormal,
|
|
|
|
gProgressCounter, aPosition.ref());
|
|
|
|
}
|
|
|
|
return gNavigation->CurrentExecutionPoint();
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PositionHit(const BreakpointPosition& position)
|
|
|
|
{
|
|
|
|
AutoDisallowThreadEvents disallow;
|
2018-11-06 20:37:22 +03:00
|
|
|
gNavigation->PositionHit(CurrentExecutionPoint(Some(position)));
|
2018-08-03 02:26:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
MOZ_EXPORT ProgressCounter
|
|
|
|
RecordReplayInterface_NewTimeWarpTarget()
|
|
|
|
{
|
2018-10-17 18:33:00 +03:00
|
|
|
if (AreThreadEventsDisallowed()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-03 02:26:25 +03:00
|
|
|
// NewTimeWarpTarget() must be called at consistent points between recording
|
|
|
|
// and replaying.
|
2018-10-17 18:33:00 +03:00
|
|
|
RecordReplayAssert("NewTimeWarpTarget");
|
2018-08-03 02:26:25 +03:00
|
|
|
|
|
|
|
if (!gNavigation) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Advance the progress counter for each time warp target. This can be called
|
|
|
|
// at any place and any number of times where recorded events are allowed.
|
|
|
|
ProgressCounter progress = ++gProgressCounter;
|
|
|
|
|
|
|
|
PositionHit(BreakpointPosition(BreakpointPosition::WarpTarget));
|
|
|
|
return progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
ExecutionPoint
|
|
|
|
TimeWarpTargetExecutionPoint(ProgressCounter aTarget)
|
|
|
|
{
|
2018-11-06 20:37:41 +03:00
|
|
|
// To construct an ExecutionPoint, we need the most recent checkpoint prior
|
|
|
|
// to aTarget. We could do a binary search here, but this code is cold and a
|
|
|
|
// linear search is more straightforwardly correct.
|
|
|
|
size_t checkpoint;
|
|
|
|
for (checkpoint = gNavigation->mCheckpointProgress.length() - 1;
|
|
|
|
checkpoint >= CheckpointId::First;
|
|
|
|
checkpoint--)
|
|
|
|
{
|
|
|
|
if (gNavigation->mCheckpointProgress[checkpoint] < aTarget) {
|
2018-08-03 02:26:25 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-11-06 20:37:41 +03:00
|
|
|
MOZ_RELEASE_ASSERT(checkpoint >= CheckpointId::First);
|
2018-08-03 02:26:25 +03:00
|
|
|
|
2018-11-06 20:37:41 +03:00
|
|
|
return ExecutionPoint(checkpoint, aTarget,
|
2018-08-03 02:26:25 +03:00
|
|
|
BreakpointPosition(BreakpointPosition::WarpTarget));
|
2018-07-22 14:58:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MaybeDivergeFromRecording()
|
|
|
|
{
|
|
|
|
return gNavigation->MaybeDivergeFromRecording();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace navigation
|
|
|
|
} // namespace recordreplay
|
|
|
|
} // namespace mozilla
|