Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,82 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --validate-asm
Debug = debug.Debug
// Initialized in setup().
var exception;
var break_count;
var num_wasm_scripts;
var module;
var expected_stack_entries = [];
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
++break_count;
// Request frame details.
var num_frames = exec_state.frameCount();
assertEquals(
expected_stack_entries.length, num_frames, 'number of frames');
print('Stack Trace (length ' + num_frames + '):');
for (var i = 0; i < num_frames; ++i) {
var frame = exec_state.frame(i);
var line = frame.sourceLine();
var column = frame.sourceColumn() + 1;
var funcName = frame.func().name();
print(
' [' + i + '] ' + funcName + ' (' + line + ':' + column + ')');
assertEquals(
expected_stack_entries[i][0], funcName, 'function name at ' + i);
assertEquals(expected_stack_entries[i][1], line, 'line at ' + i);
assertEquals(expected_stack_entries[i][2], column, 'column at ' + i);
}
}
} catch (e) {
print('exception: ' + e);
exception = e;
}
};
function generateWasmFromAsmJs(stdlib, foreign, heap) {
'use asm';
var debugger_fun = foreign.call_debugger;
function callDebugger() {
debugger_fun();
}
function redirectFun() {
callDebugger();
}
return redirectFun;
}
function call_debugger() {
debugger;
}
function setup() {
exception = null;
break_count = 0;
}
(function FrameInspection() {
setup();
var fun =
generateWasmFromAsmJs(this, {'call_debugger': call_debugger}, undefined);
expected_stack_entries = [
['call_debugger', 58, 3], // --
['callDebugger', 49, 5], // --
['redirectFun', 52, 5], // --
['FrameInspection', 78, 3], // --
['', 82, 3]
];
Debug.setListener(listener);
fun();
Debug.setListener(null);
assertEquals(1, break_count);
if (exception) throw exception;
})();

View File

@ -0,0 +1,24 @@
// Copyright 2024 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test that there is no lock-order inversion between the `allocation_mutex_`
// (used by `NativeModule::EstimateCurrentMemoryConsumption`) and the `mutex_`
// (used by `DebugInfoImpl::SetBreakpoint`) when running concurrently in
// multiple isolates (see `run-tests.py --isolates`).
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const body_f = [kExprI32Const, 123];
const offset_in_body = body_f.indexOf(kExprI32Const);
builder.addFunction('f', kSig_i_v).addBody(body_f).exportFunc();
const instance = builder.instantiate();
Debug = debug.Debug;
const breakpoint = Debug.setBreakPoint(instance.exports.f, 0, offset_in_body);
%EstimateCurrentMemoryConsumption();

View File

@ -0,0 +1,78 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test setting and removing breakpoints in Wasm.
// Similar tests exist as inspector tests already, but inspector tests are not
// run concurrently in multiple isolates (see `run-tests.py --isolates`).
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const body_a = [
kExprLocalGet, 0, // local.get i0
kExprI32Const, 1, // i32.const 1
kExprI32Add // i32.add i0 1
];
const fun_a = builder.addFunction('a', kSig_i_i).addBody(body_a).exportFunc();
const body_b = [
kExprLocalGet, 0, // local.get i0
kExprCallFunction, fun_a.index, // call a
kExprLocalGet, 1, // local.get i1
kExprI32Sub, // i32.sub a(i0) i1
kExprCallFunction, fun_a.index, // call a
];
const fun_b = builder.addFunction('b', kSig_i_ii).addBody(body_b).exportFunc();
const instance = builder.instantiate();
Debug = debug.Debug;
const a_localget_offset = body_a.indexOf(kExprLocalGet);
const a_const_offset = body_a.indexOf(kExprI32Const);
const a_add_offset = body_a.indexOf(kExprI32Add);
const b_sub_offset = body_b.indexOf(kExprI32Sub);
const expected_breaks = [
`$a:1:${fun_a.body_offset + a_add_offset}`, // break in a at i32.add
`$b:1:${fun_b.body_offset + b_sub_offset}`, // break in b at i32.sub
`$a:1:${fun_a.body_offset + a_localget_offset}`, // break in a at local.get i0
`$a:1:${fun_a.body_offset + a_const_offset}` // break in a at i32.const 1
];
let error;
function onBreak(event, exec_state, data) {
try {
if (event != Debug.DebugEvent.Break) return;
if (error) return;
const pos =
[data.functionName(), data.sourceLine(), data.sourceColumn()].join(':');
const loc = [pos, data.sourceLineText()].join(':');
print(`Break at ${loc}`);
assertTrue(expected_breaks.length > 0, 'expecting more breaks');
const expected_pos = expected_breaks.shift();
assertEquals(expected_pos, pos);
// When we stop in b, we add another breakpoint in a at offset 0 and remove
// the existing breakpoint.
if (data.functionName() === '$b') {
Debug.setBreakPoint(instance.exports.a, 0, a_localget_offset);
Debug.clearBreakPoint(breakpoint_a);
}
// When we stop at a at local.get, we set another breakpoint *in the same
// function*, one instruction later (at i32.const).
if (data.functionName() === '$a' &&
data.sourceColumn() == fun_a.body_offset) {
Debug.setBreakPoint(instance.exports.a, 0, a_const_offset);
}
} catch (e) {
if (!error) error = e;
}
}
Debug.setListener(onBreak);
const breakpoint_a = Debug.setBreakPoint(instance.exports.a, 0, a_add_offset);
const breakpoint_b = Debug.setBreakPoint(instance.exports.b, 0, b_sub_offset);
print('Running b(11).');
const result = instance.exports.b(11);
print('Returned from wasm.');
if (error) throw error;
assertEquals(0, expected_breaks.length, 'all breaks were hit');

View File

@ -0,0 +1,7 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-test-streaming
d8.file.execute('test/debugger/debug/wasm/debug-enabled-tier-down-wasm.js');

View File

@ -0,0 +1,45 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --enable-testing-opcode-in-wasm
// Test that tiering up and tiering down works even if functions cannot be
// compiled with Liftoff.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
// Create a simple Wasm module.
function create_builder(i) {
const builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_i_i)
.addBody([
kExprLocalGet, 0, kExprNopForTestingUnsupportedInLiftoff,
...wasmI32Const(i), kExprI32Add
])
.exportFunc();
return builder;
}
const instance = create_builder(0).instantiate();
// Test recompilation.
const Debug = new DebugWrapper();
Debug.enable();
assertFalse(%IsLiftoffFunction(instance.exports.main));
const newInstance = create_builder(1).instantiate();
assertFalse(%IsLiftoffFunction(newInstance.exports.main));
// Async.
async function testTierDownToLiftoffAsync() {
Debug.disable();
const asyncInstance = await create_builder(2).asyncInstantiate();
// Test recompilation.
Debug.enable();
assertFalse(%IsLiftoffFunction(asyncInstance.exports.main));
const newAsyncInstance = await create_builder(3).asyncInstantiate();
assertFalse(%IsLiftoffFunction(newAsyncInstance.exports.main));
}
assertPromiseResult(testTierDownToLiftoffAsync());

View File

@ -0,0 +1,77 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
const num_functions = 200;
// Create a simple Wasm module.
function create_builder(delta = 0) {
const builder = new WasmModuleBuilder();
for (let i = 0; i < num_functions; ++i) {
builder.addFunction('f' + i, kSig_i_v)
.addBody(wasmI32Const(i + delta))
.exportFunc();
}
return builder;
}
function checkDebugCode(instance) {
for (let i = 0; i < num_functions; ++i) {
// Call the function once because of lazy compilation.
instance.exports['f' + i]();
assertTrue(%IsWasmDebugFunction(instance.exports['f' + i]));
}
}
function waitForNoDebugCode(instance) {
// Busy waiting until all functions left debug mode.
let num_liftoff_functions = 0;
while (true) {
num_liftoff_functions = 0;
for (let i = 0; i < num_functions; ++i) {
if (%IsWasmDebugFunction(instance.exports['f' + i])) {
num_liftoff_functions++;
}
}
if (num_liftoff_functions == 0) return;
}
}
const Debug = new DebugWrapper();
(function testEnterDebugMode() {
// In the 'isolates' test, this test runs in parallel to itself on two
// isolates. All checks below should still hold.
const instance = create_builder(0).instantiate();
Debug.enable();
checkDebugCode(instance);
const instance2 = create_builder(1).instantiate();
checkDebugCode(instance2);
Debug.disable();
// Eventually the instances will have completely left debug mode again.
waitForNoDebugCode(instance);
waitForNoDebugCode(instance2);
})();
// Test async compilation.
assertPromiseResult((async function testEnterDebugModeAsync() {
// First test: enable the debugger *after* compiling the module.
const instance = await create_builder(2).asyncInstantiate();
Debug.enable();
checkDebugCode(instance);
const instance2 = await create_builder(3).asyncInstantiate();
checkDebugCode(instance2);
Debug.disable();
waitForNoDebugCode(instance);
waitForNoDebugCode(instance2);
// Second test: enable the debugger *while* compiling the module.
const instancePromise = create_builder(4).asyncInstantiate();
Debug.enable();
const instance3 = await instancePromise;
checkDebugCode(instance3);
Debug.disable();
waitForNoDebugCode(instance3);
})());

View File

@ -0,0 +1,92 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder();
builder.addFunction('sub', kSig_i_ii)
// input is 2 args of type int and output is int
.addBody([
kExprLocalGet, 0, // local.get i0
kExprLocalGet, 1, // local.get i1
kExprI32Sub]) // i32.sub i0 i1
.exportFunc();
const instance = builder.instantiate();
const wasm_f = instance.exports.sub;
Debug = debug.Debug;
var exception = null;
var js_break_line = 0;
var break_count = 0;
var wasm_break_count = 0;
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
print(event_data.sourceLineText());
print(event_data.functionName());
if (event_data.sourceLineText() == 'Debug.setListener(null);') {
return;
}
if (event_data.functionName() == 'f') {
break_count++;
assertTrue(
event_data.sourceLineText().indexOf(`Line ${js_break_line}.`) > 0);
js_break_line++;
} else {
assertTrue(event_data.functionName() == '$sub');
wasm_break_count++;
}
exec_state.prepareStep(Debug.StepAction.StepInto);
} catch (e) {
exception = e;
print(e);
}
};
function f() {
var result = wasm_f(3, 2); // Line 0.
result++; // Line 1.
return result; // Line 2.
}
assertEquals(2, f());
Debug.setListener(listener);
// Set a breakpoint on line 0.
Debug.setBreakPoint(f, 1);
// Set a breakpoint on line 2.
Debug.setBreakPoint(f, 3);
f();
Debug.setListener(null);
var break_count2 = 0;
// In the second execution, only break at javascript frame.
function listener2(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
try {
print(event_data.sourceLineText());
if (event_data.sourceLineText() == 'Debug.setListener(null);') {
return;
}
print(event_data.functionName());
assertTrue(event_data.sourceLineText().indexOf(`Line `) > 0);
assertEquals(event_data.functionName(), 'f');
break_count2++;
exec_state.prepareStep(Debug.StepAction.StepOut);
} catch (e) {
exception = e;
print(e);
}
};
Debug.setListener(listener2);
f();
Debug.setListener(null);
assertEquals(3, break_count);
assertEquals(3, js_break_line);
assertEquals(4, wasm_break_count);
assertEquals(2, break_count2);
assertNull(exception);

View File

@ -0,0 +1,59 @@
// Copyright 2024 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test setting "Never Pause Here" breakpoint in Wasm.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const body_a = [
kExprUnreachable, // unreachable
];
const fun_a = builder.addFunction('a', kSig_v_v).addBody(body_a).exportFunc();
const instance = builder.instantiate();
Debug = debug.Debug;
const expected_breaks = [
`$a:1:${fun_a.body_offset}`, // break in a at unreachable
];
let error;
function onBreak(event, exec_state, data) {
try {
assertFalse(event == Debug.DebugEvent.Break, 'no breakpoints trigger');
if (event != Debug.DebugEvent.Exception) return;
if (error) return;
const pos =
[data.functionName(), data.sourceLine(), data.sourceColumn()].join(':');
const loc = [pos, data.sourceLineText()].join(':');
print(`Break at ${loc}`);
assertTrue(expected_breaks.length > 0, 'expecting more breaks');
const expected_pos = expected_breaks.shift();
assertEquals(expected_pos, pos);
} catch (e) {
if (!error) error = e;
}
}
function testWrapper() {
print('Running a().');
try {
instance.exports.a();
print('Exited normally???');
error = new Error('Function should exit with Wasm trap');
} catch(e) {
print('Exception thrown');
}
print('Returned from wasm.');
}
Debug.setBreakOnException();
Debug.setListener(onBreak);
testWrapper();
assertEquals(0, expected_breaks.length, 'all breaks were hit');
const breakpoint_a = Debug.setBreakPoint(instance.exports.a, 0, 0, 'false');
testWrapper();
if (error) throw error;

View File

@ -0,0 +1,68 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
Debug = debug.Debug
var exception = null;
var break_count = 0;
const expected_frames = [
// func-name; wasm?; pos; line; col
['call_debugger', false], // --
['$wasm_2', true, 56, 1, 60], // --
['$wasm_1', true, 52, 1, 55], // --
['testFrameInspection', false], // --
['', false]
];
function listener(event, exec_state, event_data, data) {
if (event != Debug.DebugEvent.Break) return;
++break_count;
try {
var frame_count = exec_state.frameCount();
assertEquals(expected_frames.length, frame_count, 'frame count');
for (var i = 0; i < frame_count; ++i) {
var frame = exec_state.frame(i);
assertEquals(expected_frames[i][0], frame.func().name(), 'name at ' + i);
if (expected_frames[i][1]) { // wasm frame?
assertEquals(expected_frames[i][3], frame.sourceLine(), 'line at ' + i);
assertEquals(expected_frames[i][4], frame.sourceColumn(),
'column at ' + i);
}
}
} catch (e) {
exception = e;
}
};
var builder = new WasmModuleBuilder();
// wasm_1 calls wasm_2 on offset 2.
// wasm_2 calls call_debugger on offset 1.
builder.addImport("mod", 'func', kSig_v_v);
builder.addFunction('wasm_1', kSig_v_v)
.addBody([kExprNop, kExprCallFunction, 2])
.exportAs('main');
builder.addFunction('wasm_2', kSig_v_v).addBody([kExprCallFunction, 0]);
function call_debugger() {
debugger;
}
var module = builder.instantiate({mod: {func: call_debugger}});
(function testFrameInspection() {
Debug.setListener(listener);
module.exports.main();
Debug.setListener(null);
assertEquals(1, break_count);
if (exception) throw exception;
})();

View File

@ -0,0 +1,74 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test stepping from JS through Wasm.
// A similar test exists as an inspector test already, but inspector tests are
// not run concurrently in multiple isolates (see `run-tests.py --isolates`).
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
const imp_fun = builder.addImport('imp', 'ort', kSig_i_v);
const sub_fun = builder.addFunction('sub', kSig_i_ii).addBody([
kExprLocalGet, 0, // local.get i0
kExprLocalGet, 1, // local.get i1
kExprI32Sub // i32.sub i0 i1
]);
builder.addFunction('main', kSig_i_v)
.addBody([
kExprCallFunction, imp_fun, // call import
kExprI32Const, 3, // i32.const 3
kExprCallFunction, sub_fun.index // call 'sub'
])
.exportFunc();
// Compute the line number of the 'imported' function (to avoid hard-coding it).
const import_line_nr = parseInt((new Error()).stack.match(/:([0-9]+):/)[1]) + 1;
function imported() {
debugger;
return 7;
}
const instance = builder.instantiate({imp: {ort: imported}});
Debug = debug.Debug;
const expected_breaks = [
`imported:${import_line_nr + 1}:2`, // debugger;
`imported:${import_line_nr + 2}:2`, // return 7;
`imported:${import_line_nr + 2}:11`, // return 7;
'$main:1:68', // i32.const 3
'$main:1:70', // call 'sub'
'$sub:1:58', // local.get i0
'$sub:1:60', // local.get i1
'$sub:1:62', // i32.sub
'$sub:1:63', // end
'$main:1:72' // end
];
let error;
function onBreak(event, exec_state, data) {
try {
if (event != Debug.DebugEvent.Break) return;
if (error) return;
if (data.sourceLineText().indexOf('Main returned.') >= 0) {
assertEquals(0, expected_breaks.length, 'hit all expected breaks');
return;
}
const pos =
[data.functionName(), data.sourceLine(), data.sourceColumn()].join(':');
const loc = [pos, data.sourceLineText()].join(':');
print(`Break at ${loc}`);
assertTrue(expected_breaks.length > 0, 'expecting more breaks');
const expected_pos = expected_breaks.shift();
assertEquals(expected_pos, pos);
exec_state.prepareStep(Debug.StepAction.StepInto);
} catch (e) {
if (!error) error = e;
}
}
Debug.setListener(onBreak);
print('Running main.');
const result = instance.exports.main();
print('Main returned.');
if (error) throw error;
assertEquals(4, result);