forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathDevToolsPluginHost.ts
More file actions
145 lines (121 loc) · 6.48 KB
/
Copy pathDevToolsPluginHost.ts
File metadata and controls
145 lines (121 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2023 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import type {Chrome} from '../../../extension-api/ExtensionAPI.js';
import {DEFAULT_MODULE_CONFIGURATIONS, type ModuleConfigurations} from './ModuleConfiguration.js';
import type {WasmValue} from './WasmTypes.js';
import {type AsyncHostInterface, type WorkerInterface, WorkerRPC} from './WorkerRPC.js';
export class WorkerPlugin implements Chrome.DevTools.LanguageExtensionPlugin, AsyncHostInterface {
private readonly worker = new Worker('DevToolsPluginWorkerMain.bundle.js', {type: 'module'});
private readonly rpc = new WorkerRPC<AsyncHostInterface, WorkerInterface>(this.worker, this);
getWasmLinearMemory(offset: number, length: number, stopId: unknown): Promise<ArrayBuffer> {
return chrome.devtools.languageServices.getWasmLinearMemory(offset, length, stopId);
}
getWasmLocal(local: number, stopId: unknown): Promise<WasmValue> {
return chrome.devtools.languageServices.getWasmLocal(local, stopId);
}
getWasmGlobal(global: number, stopId: unknown): Promise<WasmValue> {
return chrome.devtools.languageServices.getWasmGlobal(global, stopId);
}
getWasmOp(op: number, stopId: unknown): Promise<WasmValue> {
return chrome.devtools.languageServices.getWasmOp(op, stopId);
}
reportResourceLoad(resourceUrl: string, status: {success: boolean, errorMessage?: string, size?: number}):
Promise<void> {
return chrome.devtools.languageServices.reportResourceLoad(resourceUrl, status);
}
static async create(
moduleConfigurations: ModuleConfigurations = DEFAULT_MODULE_CONFIGURATIONS,
logPluginApiCalls = false): Promise<WorkerPlugin> {
const plugin = new WorkerPlugin();
await plugin.rpc.sendMessage('hello', moduleConfigurations, logPluginApiCalls);
return plugin;
}
addRawModule(rawModuleId: string, symbolsURL: string, rawModule: Chrome.DevTools.RawModule): Promise<string[]|{
missingSymbolFiles: string[],
}> {
return this.rpc.sendMessage('addRawModule', rawModuleId, symbolsURL, rawModule);
}
removeRawModule(rawModuleId: string): Promise<void> {
return this.rpc.sendMessage('removeRawModule', rawModuleId);
}
sourceLocationToRawLocation(sourceLocation: Chrome.DevTools.SourceLocation):
Promise<Chrome.DevTools.RawLocationRange[]> {
return this.rpc.sendMessage('sourceLocationToRawLocation', sourceLocation);
}
rawLocationToSourceLocation(rawLocation: Chrome.DevTools.RawLocation): Promise<Chrome.DevTools.SourceLocation[]> {
return this.rpc.sendMessage('rawLocationToSourceLocation', rawLocation);
}
getScopeInfo(type: string): Promise<Chrome.DevTools.ScopeInfo> {
return this.rpc.sendMessage('getScopeInfo', type);
}
listVariablesInScope(rawLocation: Chrome.DevTools.RawLocation): Promise<Chrome.DevTools.Variable[]> {
return this.rpc.sendMessage('listVariablesInScope', rawLocation);
}
getFunctionInfo(rawLocation: Chrome.DevTools.RawLocation):
Promise<{frames: Chrome.DevTools.FunctionInfo[], missingSymbolFiles: string[]}|
{frames: Chrome.DevTools.FunctionInfo[]}|{missingSymbolFiles: string[]}> {
return this.rpc.sendMessage('getFunctionInfo', rawLocation);
}
getInlinedFunctionRanges(rawLocation: Chrome.DevTools.RawLocation): Promise<Chrome.DevTools.RawLocationRange[]> {
return this.rpc.sendMessage('getInlinedFunctionRanges', rawLocation);
}
getInlinedCalleesRanges(rawLocation: Chrome.DevTools.RawLocation): Promise<Chrome.DevTools.RawLocationRange[]> {
return this.rpc.sendMessage('getInlinedCalleesRanges', rawLocation);
}
getMappedLines(rawModuleId: string, sourceFileURL: string): Promise<number[]|undefined> {
return this.rpc.sendMessage('getMappedLines', rawModuleId, sourceFileURL);
}
evaluate(expression: string, context: Chrome.DevTools.RawLocation, stopId: unknown):
Promise<Chrome.DevTools.RemoteObject|Chrome.DevTools.ForeignObject|null> {
return this.rpc.sendMessage('evaluate', expression, context, stopId);
}
getProperties(objectId: Chrome.DevTools.RemoteObjectId): Promise<Chrome.DevTools.PropertyDescriptor[]> {
return this.rpc.sendMessage('getProperties', objectId);
}
releaseObject(objectId: Chrome.DevTools.RemoteObjectId): Promise<void> {
return this.rpc.sendMessage('releaseObject', objectId);
}
}
export interface Storage {
onChanged: Chrome.DevTools
.EventSink<(changes: {[key: string]: {oldValue: unknown, newValue: unknown}}, namespace: string) => unknown>;
local:
{set<ResultT>(value: ResultT): void, get<ResultT>(keys: ResultT, callback: (result: ResultT) => unknown): void};
}
export declare const chrome: Chrome.DevTools.Chrome&{storage?: Storage};
if (typeof chrome?.storage !== 'undefined') {
const {storage} = chrome;
const {languageServices} = chrome.devtools;
async function registerPlugin(moduleConfigurations: ModuleConfigurations, logPluginApiCalls: boolean):
Promise<Chrome.DevTools.LanguageExtensionPlugin> {
const plugin = await WorkerPlugin.create(moduleConfigurations, logPluginApiCalls);
await languageServices.registerLanguageExtensionPlugin(
plugin, 'C/C++ DevTools Support (DWARF)',
{language: 'WebAssembly', symbol_types: ['EmbeddedDWARF', 'ExternalDWARF']});
return plugin;
}
async function unregisterPlugin(plugin: Chrome.DevTools.LanguageExtensionPlugin): Promise<void> {
await languageServices.unregisterLanguageExtensionPlugin(plugin);
}
const defaultConfig = {
moduleConfigurations: DEFAULT_MODULE_CONFIGURATIONS,
logPluginApiCalls: false,
};
chrome.storage.local.get(defaultConfig, ({moduleConfigurations, logPluginApiCalls}) => {
let pluginPromise = registerPlugin(moduleConfigurations, logPluginApiCalls);
storage.onChanged.addListener(changes => {
// Note that this doesn't use optional chaining '?.' as it is problematic in vscode.
const moduleConfigurations =
changes['moduleConfigurations'] !== undefined ? changes['moduleConfigurations'].newValue : undefined;
const logPluginApiCalls =
changes['logPluginApiCalls'] !== undefined ? changes['logPluginApiCalls'].newValue : undefined;
if (moduleConfigurations || logPluginApiCalls !== undefined) {
storage.local.get(defaultConfig, ({moduleConfigurations, logPluginApiCalls}) => {
pluginPromise =
pluginPromise.then(unregisterPlugin).then(() => registerPlugin(moduleConfigurations, logPluginApiCalls));
});
}
});
});
}