fune/devtools/client/shared/thread-utils.js
Alexandre Poirot 79a3ae0b0f Bug 1720512 - [devtools] Avoid storing and restoring broken breakpoints. r=jdescottes,bomsy
This is a bit surprising that broken breakpoints are stored
as the frontend seems to try to do a couple of assertions:
https://searchfox.org/mozilla-central/rev/c0fc8c4852e927b0ae75d893d35772b8c60ee06b/devtools/client/debugger/src/utils/breakpoint/index.js#84-106

But at least, now, we start using same assertions in both sides.

Differential Revision: https://phabricator.services.mozilla.com/D120002
2021-07-19 15:30:34 +00:00

90 lines
3.2 KiB
JavaScript

/* 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/. */
"use strict";
var Services = require("Services");
const asyncStoreHelper = require("devtools/client/shared/async-store-helper");
const {
validateBreakpointLocation,
} = require("devtools/shared/validate-breakpoint.jsm");
const asyncStore = asyncStoreHelper("debugger", {
pendingBreakpoints: ["pending-breakpoints", {}],
tabs: ["tabs", []],
xhrBreakpoints: ["xhr-breakpoints", []],
eventListenerBreakpoints: ["event-listener-breakpoints", undefined],
tabsBlackBoxed: ["tabsBlackBoxed", []],
});
exports.asyncStore = asyncStore;
exports.getThreadOptions = async function() {
return {
pauseOnExceptions: Services.prefs.getBoolPref(
"devtools.debugger.pause-on-exceptions"
),
ignoreCaughtExceptions: Services.prefs.getBoolPref(
"devtools.debugger.ignore-caught-exceptions"
),
shouldShowOverlay: Services.prefs.getBoolPref(
"devtools.debugger.features.overlay"
),
shouldIncludeSavedFrames: Services.prefs.getBoolPref(
"devtools.debugger.features.async-captured-stacks"
),
shouldIncludeAsyncLiveFrames: Services.prefs.getBoolPref(
"devtools.debugger.features.async-live-stacks"
),
skipBreakpoints: Services.prefs.getBoolPref(
"devtools.debugger.skip-pausing"
),
logEventBreakpoints: Services.prefs.getBoolPref(
"devtools.debugger.log-event-breakpoints"
),
// This option is always true. See Bug 1654590 for removal.
observeAsmJS: true,
breakpoints: sanitizeBreakpoints(await asyncStore.pendingBreakpoints),
// XXX: `event-listener-breakpoints` is a copy of the event-listeners state
// of the debugger panel. The `active` property is therefore linked to
// the `active` property of the state.
// See devtools/client/debugger/src/reducers/event-listeners.js
eventBreakpoints:
((await asyncStore.eventListenerBreakpoints) || {}).active || [],
};
};
/**
* Bug 1720512 - We used to store invalid breakpoints, leading to blank debugger.
* Filter out only the one that look invalid.
*/
function sanitizeBreakpoints(breakpoints) {
if (typeof breakpoints != "object") {
return {};
}
// We are not doing any assertion against keys,
// as it looks like we are never using them anywhere in frontend, nor backend.
const validBreakpoints = {};
for (const key in breakpoints) {
const bp = breakpoints[key];
try {
if (!bp) {
throw new Error("Undefined breakpoint");
}
// Debugger's main.js's `syncBreakpoints` will only use generatedLocation
// when restoring breakpoints.
validateBreakpointLocation(bp.generatedLocation);
// But Toolbox will still pass location to thread actor's reconfigure
// for target that don't support watcher+BreakpointListActor
validateBreakpointLocation(bp.location);
validBreakpoints[key] = bp;
} catch (e) {
console.error(
"Ignore invalid breakpoint from debugger store",
bp,
e.message
);
}
}
return validBreakpoints;
}
exports.sanitizeBreakpoints = sanitizeBreakpoints;