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,14 @@
# Metadata information for this directory.
#
# For more information on DIR_METADATA files, see:
# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
#
# For the schema of this file, see Metadata message:
# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
monorail {
component: "Blink>JavaScript>WebAssembly"
}
buganizer_public: {
component_id: 1456332
}

View File

@ -0,0 +1 @@
paolosev@microsoft.com

View File

@ -0,0 +1,58 @@
# 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: -expose-wasm --wasm-gdb-remote --wasm-pause-waiting-for-debugger test/debugging/wasm/gdb-server/test_files/test_basic.js
import sys
import unittest
import gdb_rsp
import test_files.test_basic as test_basic
class Tests(unittest.TestCase):
def test_initial_breakpoint(self):
# Testing that the debuggee suspends when the debugger attaches.
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
reply = connection.RspRequest('?')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
def test_setting_removing_breakpoint(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
func_addr = module_load_addr + test_basic.BREAK_ADDRESS_1
# Set a breakpoint.
reply = connection.RspRequest('Z0,%x,1' % func_addr)
self.assertEqual(reply, 'OK')
# When we run the program, we should hit the breakpoint.
reply = connection.RspRequest('c')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
gdb_rsp.CheckInstructionPtr(connection, func_addr)
# Check that we can remove the breakpoint.
reply = connection.RspRequest('z0,%x,0' % func_addr)
self.assertEqual(reply, 'OK')
# Requesting removing a breakpoint on an address that does not
# have one should return an error.
reply = connection.RspRequest('z0,%x,0' % func_addr)
self.assertEqual(reply, 'E03')
def test_setting_breakpoint_on_invalid_address(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
# Requesting a breakpoint on an invalid address should give an error.
reply = connection.RspRequest('Z0,%x,1' % (1 << 32))
self.assertEqual(reply, 'E03')
def Main():
index = sys.argv.index('--')
args = sys.argv[index + 1:]
# The remaining arguments go to unittest.main().
global COMMAND
COMMAND = args
unittest.main(argv=sys.argv[:index])
if __name__ == '__main__':
Main()

View File

@ -0,0 +1,67 @@
# 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: -expose-wasm --wasm-gdb-remote --wasm-pause-waiting-for-debugger test/debugging/wasm/gdb-server/test_files/test_basic.js
from ctypes import *
import os
import subprocess
import unittest
import sys
import gdb_rsp
import test_files.test_basic as test_basic
# These are set up by Main().
COMMAND = None
class Tests(unittest.TestCase):
def test_disconnect(self):
process = gdb_rsp.PopenDebugStub(COMMAND)
try:
# Connect.
connection = gdb_rsp.GdbRspConnection()
connection.Close()
# Reconnect 3 times.
for _ in range(3):
connection = gdb_rsp.GdbRspConnection()
connection.Close()
finally:
gdb_rsp.KillProcess(process)
def test_kill(self):
process = gdb_rsp.PopenDebugStub(COMMAND)
try:
connection = gdb_rsp.GdbRspConnection()
# Request killing the target.
reply = connection.RspRequest('k')
self.assertEqual(reply, 'OK')
signal = c_byte(process.wait()).value
self.assertEqual(signal, gdb_rsp.RETURNCODE_KILL)
finally:
gdb_rsp.KillProcess(process)
def test_detach(self):
process = gdb_rsp.PopenDebugStub(COMMAND)
try:
connection = gdb_rsp.GdbRspConnection()
# Request detaching from the target.
# This resumes execution, so we get the normal exit() status.
reply = connection.RspRequest('D')
self.assertEqual(reply, 'OK')
finally:
gdb_rsp.KillProcess(process)
def Main():
index = sys.argv.index('--')
args = sys.argv[index + 1:]
# The remaining arguments go to unittest.main().
global COMMAND
COMMAND = args
unittest.main(argv=sys.argv[:index])
if __name__ == '__main__':
Main()

View File

@ -0,0 +1,71 @@
# 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: -expose-wasm --wasm-gdb-remote --wasm-pause-waiting-for-debugger test/debugging/wasm/gdb-server/test_files/test_float.js
import os
import re
import struct
import subprocess
import sys
import unittest
import gdb_rsp
import test_files.test_float as test_float
# These are set up by Main().
COMMAND = None
class Tests(unittest.TestCase):
def RunToWasm(self, connection):
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
breakpoint_addr = module_load_addr + test_float.FUNC_START_ADDR
# Set a breakpoint.
reply = connection.RspRequest('Z0,%x,1' % breakpoint_addr)
self.assertEqual(reply, 'OK')
# When we run the program, we should hit the breakpoint.
reply = connection.RspRequest('c')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
# Remove the breakpoint.
reply = connection.RspRequest('z0,%x,1' % breakpoint_addr)
self.assertEqual(reply, 'OK')
def test_loaded_modules(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
modules = gdb_rsp.GetLoadedModules(connection)
connection.Close()
assert(len(modules) > 0)
def test_wasm_local_float(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
self.RunToWasm(connection)
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
reply = connection.RspRequest('qWasmLocal:0;0')
value = struct.unpack('f', gdb_rsp.DecodeHex(reply))[0]
self.assertEqual(test_float.ARG_0, value)
reply = connection.RspRequest('qWasmLocal:0;1')
value = struct.unpack('f', gdb_rsp.DecodeHex(reply))[0]
self.assertEqual(test_float.ARG_1, value)
# invalid local
reply = connection.RspRequest('qWasmLocal:0;9')
self.assertEqual("E03", reply)
def Main():
index = sys.argv.index('--')
args = sys.argv[index + 1:]
# The remaining arguments go to unittest.main().
global COMMAND
COMMAND = args
unittest.main(argv=sys.argv[:index])
if __name__ == '__main__':
Main()

View File

@ -0,0 +1,222 @@
# 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.
import re
import socket
import struct
import subprocess
import time
import xml.etree.ElementTree
import sys
# Python2 has both int and long, Python3 only has int, which is the same as
# Python2 long.
try:
long
except NameError:
long = int
# Python2 has xrange and range. Python3 range is Python2 xrange.
try:
xrange
except NameError:
xrange = range
SOCKET_ADDR = ('localhost', 8765)
SIGTRAP = 5
SIGSEGV = 11
RETURNCODE_KILL = -9
ARCH = 'wasm32'
REG_DEFS = {
ARCH: [('pc', 'Q'), ],
}
def EnsurePortIsAvailable(addr=SOCKET_ADDR):
# As a validity check, check that the TCP port is available by binding to it
# ourselves (and then unbinding). Otherwise, we could end up talking to an
# old instance of the GDB stub that is still hanging around, or to some
# unrelated service that uses the same port number. Of course, there is still
# a race condition because an unrelated process could bind the port after we
# unbind.
sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
sock.bind(addr)
sock.close()
def RspChecksum(data):
checksum = 0
for char in data:
checksum = (checksum + ord(char)) & 0xff
return checksum
class GdbRspConnection(object):
def __init__(self, addr=SOCKET_ADDR):
self._socket = self._Connect(addr)
def _Connect(self, addr):
# We have to poll because we do not know when the GDB stub has successfully
# done bind() on the TCP port. This is inherently unreliable.
timeout_in_seconds = 10
poll_time_in_seconds = 0.1
for i in xrange(int(timeout_in_seconds / poll_time_in_seconds)):
# On Mac OS X, we have to create a new socket FD for each retry.
sock = socket.socket()
# Do not delay sending small packets. This significantly speeds up debug
# stub tests.
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
try:
sock.connect(addr)
except socket.error:
# Retry after a delay.
time.sleep(poll_time_in_seconds)
else:
return sock
raise Exception('Could not connect to the debug stub in %i seconds'
% timeout_in_seconds)
def _GetReply(self):
reply = ''
message_finished = re.compile('#[0-9a-fA-F]{2}')
while True:
data = self._socket.recv(1024)
if len(data) == 0:
raise AssertionError('EOF on socket reached with '
'incomplete reply message: %r' % reply)
reply += data
if message_finished.match(reply[-3:]):
break
match = re.match('\+?\$([^#]*)#([0-9a-fA-F]{2})$', reply)
if match is None:
raise AssertionError('Unexpected reply message: %r' % reply)
reply_body = match.group(1)
checksum = match.group(2)
expected_checksum = '%02x' % RspChecksum(reply_body)
if checksum != expected_checksum:
raise AssertionError('Bad RSP checksum: %r != %r' %
(checksum, expected_checksum))
# Send acknowledgement.
self._socket.send('+')
return reply_body
# Send an rsp message, but don't wait for or expect a reply.
def RspSendOnly(self, data):
msg = '$%s#%02x' % (data, RspChecksum(data))
return self._socket.send(msg)
def RspRequest(self, data):
self.RspSendOnly(data)
reply = self._GetReply()
return reply
def Close(self):
self._socket.close()
def PopenDebugStub(command):
EnsurePortIsAvailable()
return subprocess.Popen(command)
def KillProcess(process):
if process.returncode is not None:
# kill() won't work if we've already wait()'ed on the process.
return
try:
process.kill()
except OSError:
if sys.platform == 'win32':
# If process is already terminated, kill() throws
# "WindowsError: [Error 5] Access is denied" on Windows.
pass
else:
raise
process.wait()
class LaunchDebugStub(object):
def __init__(self, command):
self._proc = PopenDebugStub(command)
def __enter__(self):
try:
return GdbRspConnection()
except:
KillProcess(self._proc)
raise
def __exit__(self, exc_type, exc_value, traceback):
KillProcess(self._proc)
def AssertEquals(x, y):
if x != y:
raise AssertionError('%r != %r' % (x, y))
def DecodeHex(data):
assert len(data) % 2 == 0, data
return bytes(bytearray([int(data[index * 2 : (index + 1) * 2], 16) for index in xrange(len(data) // 2)]))
def EncodeHex(data):
return ''.join('%02x' % ord(byte) for byte in data)
def DecodeUInt64Array(data):
assert len(data) % 16 == 0, data
result = []
for index in xrange(len(data) // 16):
value = 0
for digit in xrange(7, -1, -1):
value = value * 256 + int(data[index * 16 + digit * 2 : index * 16 + (digit + 1) * 2], 16)
result.append(value)
return result
def AssertReplySignal(reply, signal):
AssertEquals(ParseThreadStopReply(reply)['signal'], signal)
def ParseThreadStopReply(reply):
match = re.match('T([0-9a-f]{2})thread-pcs:([0-9a-f]+);thread:([0-9a-f]+);(library:([0-9a-f]*);)?$', reply)
if not match:
raise AssertionError('Bad thread stop reply: %r' % reply)
return {'signal': int(match.group(1), 16),
'thread_pc': int(match.group(2), 16),
'thread_id': int(match.group(3), 16)}
def CheckInstructionPtr(connection, expected_ip):
ip_value = DecodeRegs(connection.RspRequest('g'))['pc']
AssertEquals(ip_value, expected_ip)
def DecodeRegs(reply):
defs = REG_DEFS[ARCH]
names = [reg_name for reg_name, reg_fmt in defs]
fmt = ''.join([reg_fmt for reg_name, reg_fmt in defs])
values = struct.unpack_from(fmt, DecodeHex(reply))
return dict(zip(names, values))
def GetLoadedModules(connection):
modules = {}
reply = connection.RspRequest('qXfer:libraries:read')
AssertEquals(reply[0], 'l')
library_list = xml.etree.ElementTree.fromstring(reply[1:])
AssertEquals(library_list.tag, 'library-list')
for library in library_list:
AssertEquals(library.tag, 'library')
section = library.find('section')
address = section.get('address')
assert long(address) > 0
modules[long(address)] = library.get('name')
return modules
def GetLoadedModuleAddress(connection):
modules = GetLoadedModules(connection)
assert len(modules) > 0
return modules.keys()[0]
def ReadCodeMemory(connection, address, size):
reply = connection.RspRequest('m%x,%x' % (address, size))
assert not reply.startswith('E'), reply
return DecodeHex(reply)

View File

@ -0,0 +1,113 @@
# 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: -expose-wasm --wasm-gdb-remote --wasm-pause-waiting-for-debugger test/debugging/wasm/gdb-server/test_files/test_memory.js
import struct
import sys
import unittest
import gdb_rsp
import test_files.test_memory as test_memory
# These are set up by Main().
COMMAND = None
class Tests(unittest.TestCase):
# Test that reading from an unreadable address gives a sensible error.
def CheckReadMemoryAtInvalidAddr(self, connection):
mem_addr = 0xffffffff
result = connection.RspRequest('m%x,%x' % (mem_addr, 1))
self.assertEquals(result, 'E02')
def RunToWasm(self, connection, breakpoint_addr):
# Set a breakpoint.
reply = connection.RspRequest('Z0,%x,1' % breakpoint_addr)
self.assertEqual(reply, 'OK')
# When we run the program, we should hit the breakpoint.
reply = connection.RspRequest('c')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
# Remove the breakpoint.
reply = connection.RspRequest('z0,%x,1' % breakpoint_addr)
self.assertEqual(reply, 'OK')
def test_reading_and_writing_memory(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
breakpoint_addr = module_load_addr + test_memory.FUNC0_START_ADDR
self.RunToWasm(connection, breakpoint_addr)
self.CheckReadMemoryAtInvalidAddr(connection)
# Check reading code memory space.
expected_data = b'\0asm'
result = gdb_rsp.ReadCodeMemory(connection, module_load_addr, len(expected_data))
self.assertEqual(result, expected_data)
# Check reading instance memory at a valid range.
module_id = module_load_addr >> 32
reply = connection.RspRequest('qWasmMem:%d;%x;%x' % (module_id, 32, 4))
value = struct.unpack('I', gdb_rsp.DecodeHex(reply))[0]
self.assertEquals(int(value), 0)
# Check reading instance memory at an invalid range.
reply = connection.RspRequest('qWasmMem:%d;%x;%x' % (module_id, 0xf0000000, 4))
self.assertEqual(reply, 'E03')
def test_reading_and_writing_data_section(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
breakpoint_addr = module_load_addr + test_memory.FUNC0_START_ADDR
self.RunToWasm(connection, breakpoint_addr)
# Check reading instance memory at a valid range.
module_id = module_load_addr >> 32
reply = connection.RspRequest('qWasmData:%d;%x;%x' % (module_id, test_memory.DATA_OFFSET, test_memory.DATA_SIZE))
value = struct.unpack('I', gdb_rsp.DecodeHex(reply))[0]
self.assertEquals(int(value), test_memory.DATA_CONTENT)
# Check reading instance memory at an invalid range.
reply = connection.RspRequest('qWasmData:%d;%x;%x' % (module_id, 0xf0000000, 4))
self.assertEqual(reply, 'E03')
def test_wasm_global(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
breakpoint_addr = module_load_addr + test_memory.FUNC0_START_ADDR
self.RunToWasm(connection, breakpoint_addr)
# Check reading valid global.
reply = connection.RspRequest('qWasmGlobal:0;0')
value = struct.unpack('I', gdb_rsp.DecodeHex(reply))[0]
self.assertEqual(0, value)
# Check reading invalid global.
reply = connection.RspRequest('qWasmGlobal:0;9')
self.assertEqual("E03", reply)
def test_wasm_call_stack(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
breakpoint_addr = module_load_addr + test_memory.FUNC0_START_ADDR
self.RunToWasm(connection, breakpoint_addr)
reply = connection.RspRequest('qWasmCallStack')
stack = gdb_rsp.DecodeUInt64Array(reply)
assert(len(stack) > 2) # At least two Wasm frames, plus one or more JS frames.
self.assertEqual(stack[0], module_load_addr + test_memory.FUNC0_START_ADDR)
self.assertEqual(stack[1], module_load_addr + test_memory.FUNC1_RETURN_ADDR)
def Main():
index = sys.argv.index('--')
args = sys.argv[index + 1:]
# The remaining arguments go to unittest.main().
global COMMAND
COMMAND = args
unittest.main(argv=sys.argv[:index])
if __name__ == '__main__':
Main()

View File

@ -0,0 +1,109 @@
# 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: -expose-wasm --wasm-gdb-remote --wasm-pause-waiting-for-debugger test/debugging/wasm/gdb-server/test_files/test_basic.js
import re
import struct
import sys
import unittest
import gdb_rsp
import test_files.test_basic as test_basic
# These are set up by Main().
COMMAND = None
class Tests(unittest.TestCase):
def test_loaded_modules(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
modules = gdb_rsp.GetLoadedModules(connection)
connection.Close()
assert(len(modules) > 0)
def test_checking_thread_state(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
# Query wasm thread id
reply = connection.RspRequest('qfThreadInfo')
match = re.match('m([0-9])$', reply)
if match is None:
raise AssertionError('Bad active thread list reply: %r' % reply)
thread_id = int(match.group(1), 10)
# There should not be other threads.
reply = connection.RspRequest('qsThreadInfo')
self.assertEqual("l", reply)
# Test that valid thread should be alive.
reply = connection.RspRequest('T%d' % (thread_id))
self.assertEqual("OK", reply)
# Test invalid thread id.
reply = connection.RspRequest('T42')
self.assertEqual("E02", reply)
def test_wasm_local(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
breakpoint_addr = module_load_addr + test_basic.BREAK_ADDRESS_2
reply = connection.RspRequest('Z0,%x,1' % breakpoint_addr)
self.assertEqual("OK", reply)
reply = connection.RspRequest('c')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
reply = connection.RspRequest('qWasmLocal:0;0')
value = struct.unpack('I', gdb_rsp.DecodeHex(reply))[0]
self.assertEqual(test_basic.ARG_0, value)
reply = connection.RspRequest('qWasmLocal:0;1')
value = struct.unpack('I', gdb_rsp.DecodeHex(reply))[0]
self.assertEqual(test_basic.ARG_1, value)
# invalid local
reply = connection.RspRequest('qWasmLocal:0;9')
self.assertEqual("E03", reply)
def test_wasm_stack_value(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
breakpoint_addr = module_load_addr + test_basic.BREAK_ADDRESS_2
reply = connection.RspRequest('Z0,%x,1' % breakpoint_addr)
self.assertEqual("OK", reply)
reply = connection.RspRequest('c')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
reply = connection.RspRequest('qWasmStackValue:0;0')
value = struct.unpack('I', gdb_rsp.DecodeHex(reply))[0]
self.assertEqual(test_basic.ARG_0, value)
reply = connection.RspRequest('qWasmStackValue:0;1')
value = struct.unpack('I', gdb_rsp.DecodeHex(reply))[0]
self.assertEqual(test_basic.ARG_1, value)
# invalid index
reply = connection.RspRequest('qWasmStackValue:0;2')
self.assertEqual("E03", reply)
def test_modifying_code_is_disallowed(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
# Pick an arbitrary address in the code segment.
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
breakpoint_addr = module_load_addr + test_basic.BREAK_ADDRESS_1
# Writing to the code area should be disallowed.
data = '\x00'
write_command = 'M%x,%x:%s' % (breakpoint_addr, len(data), gdb_rsp.EncodeHex(data))
reply = connection.RspRequest(write_command)
self.assertEquals(reply, 'E03')
def Main():
index = sys.argv.index('--')
args = sys.argv[index + 1:]
# The remaining arguments go to unittest.main().
global COMMAND
COMMAND = args
unittest.main(argv=sys.argv[:index])
if __name__ == '__main__':
Main()

View File

@ -0,0 +1,56 @@
# 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: -expose-wasm --wasm-gdb-remote --wasm-pause-waiting-for-debugger test/debugging/wasm/gdb-server/test_files/test_basic.js
import sys
import unittest
import gdb_rsp
import test_files.test_basic as test_basic
# These are set up by Main().
COMMAND = None
class Tests(unittest.TestCase):
def test_single_step(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
bp_addr = module_load_addr + test_basic.BREAK_ADDRESS_0
reply = connection.RspRequest('Z0,%x,1' % bp_addr)
self.assertEqual("OK", reply)
reply = connection.RspRequest('c')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
# We expect 's' to stop at the next instruction.
reply = connection.RspRequest('s')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
tid = gdb_rsp.ParseThreadStopReply(reply)['thread_id']
self.assertEqual(tid, 1)
regs = gdb_rsp.DecodeRegs(connection.RspRequest('g'))
self.assertEqual(regs['pc'], module_load_addr + test_basic.BREAK_ADDRESS_1)
# Again.
reply = connection.RspRequest('s')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
tid = gdb_rsp.ParseThreadStopReply(reply)['thread_id']
self.assertEqual(tid, 1)
regs = gdb_rsp.DecodeRegs(connection.RspRequest('g'))
self.assertEqual(regs['pc'], module_load_addr + test_basic.BREAK_ADDRESS_2)
# Check that we can continue after single-stepping.
reply = connection.RspRequest('c')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGTRAP)
def Main():
index = sys.argv.index('--')
args = sys.argv[index + 1:]
# The remaining arguments go to unittest.main().
global COMMAND
COMMAND = args
unittest.main(argv=sys.argv[:index])
if __name__ == '__main__':
Main()

View File

@ -0,0 +1,31 @@
// 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');
var builder = new WasmModuleBuilder();
builder
.addFunction('mul', 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
kExprI32Mul
]) // i32.mul i0 i1
.exportFunc();
const instance = builder.instantiate();
const wasm_f = instance.exports.mul;
function f() {
var result = wasm_f(21, 2);
return result;
}
try {
let val = f();
f();
} catch (e) {
print('*exception:* ' + e);
}

View File

@ -0,0 +1,23 @@
# 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.
# 0x00 (module
# 0x08 [type]
# (type $type0 (func (param i32 i32) (result i32)))
# 0x11 [function]
# 0x15 (export "mul" (func $func0))
# 0x1e [code]
# 0x20 (func $func0 (param $var0 i32) (param $var1 i32) (result i32)
# 0x23 get_local $var0
# 0x25 get_local $var1
# 0x27 i32.mul
# )
# )
# 0x29 [name]
BREAK_ADDRESS_0 = 0x0023
BREAK_ADDRESS_1 = 0x0025
BREAK_ADDRESS_2 = 0x0027
ARG_0 = 21
ARG_1 = 2

View File

@ -0,0 +1,31 @@
// 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');
var builder = new WasmModuleBuilder();
builder
.addFunction('mul', kSig_f_ff)
// input is 2 args of type float and output is float
.addBody([
kExprLocalGet, 0, // local.get f0
kExprLocalGet, 1, // local.get f1
kExprF32Mul, // f32.mul i0 i1
])
.exportFunc();
const instance = builder.instantiate();
const wasm_f = instance.exports.mul;
function f() {
var result = wasm_f(12.0, 3.5);
return result;
}
try {
let val = f();
print('float result: ' + val);
} catch (e) {
print('*exception:* ' + e);
}

View File

@ -0,0 +1,21 @@
# 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.
# 0x00 (module
# 0x08 [type]
# (type $type0 (func (param f32 f32) (result f32)))
# 0x11 [function]
# 0x15 (export "mul" (func $func0))
# 0x1e [code]
# 0x20 (func $func0 (param $var0 f32) (param $var1 f32) (result f32)
# 0x23 get_local $var0
# 0x25 get_local $var1
# 0x27 f32.mul
# )
# )
# 0x29 [name]
ARG_0 = 12.0
ARG_1 = 3.5
FUNC_START_ADDR = 0x23

View File

@ -0,0 +1,51 @@
// 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');
var builder = new WasmModuleBuilder();
builder.addGlobal(kWasmI32, false, false).exportAs('g_n');
builder.addMemory(32, 128);
builder.exportMemoryAs('mem', 0);
builder.addActiveDataSegment(0, [kExprI32Const, 0], [0x2a, 0x2b, 0x2c, 0x2d]);
var func_a_idx =
builder.addFunction('wasm_A', kSig_v_i).addBody([kExprNop, kExprNop]).index;
// wasm_B calls wasm_A <param0> times.
builder.addFunction('wasm_B', kSig_v_i)
.addBody([
kExprLoop,
kWasmVoid, // while
kExprLocalGet,
0, // -
kExprIf,
kWasmVoid, // if <param0> != 0
kExprLocalGet,
0, // -
kExprI32Const,
1, // -
kExprI32Sub, // -
kExprLocalSet,
0, // decrease <param0>
...wasmI32Const(1024), // some longer i32 const (2 byte imm)
kExprCallFunction,
func_a_idx, // -
kExprBr,
1, // continue
kExprEnd, // -
kExprEnd, // break
])
.exportAs('main');
const instance = builder.instantiate();
const wasm_main = instance.exports.main;
function f() {
wasm_main(42);
}
f();

View File

@ -0,0 +1,46 @@
# 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.
# 0x00 (module
# 0x08 [type]
# 0x0a (type $type0 (func (param i32)))
# 0x0f (type $type1 (func (param i32)))
# 0x13 [function]
# 0x18 [memory]
# (memory (;0;) 32 128)
# 0x1f [global]
# 0x27 (global $global0 i32 (i32.const 0))
# 0x29 (export "g_n" (global $global0))
# 0x30 (export "mem" (memory 0))
# 0x36 (export "main" (func $func1))
# 0x3d [code]
# 0x3f (func $func0 (param $var0 i32)
# 0x42 nop
# 0x43 nop
# )
# 0x45 (func $func1 (param $var0 i32)
# 0x47 loop $label0
# 0x49 get_local $var0
# 0x4b if
# 0x4d get_local $var0
# 0x4f i32.const 1
# 0x51 i32.sub
# 0x52 set_local $var0
# 0x54 i32.const 1024
# 0x57 call $func0
# 0x59 br $label0
# 0x5b end
# 0x5c end $label0
# )
# )
# 0x5e [name]
MEM_MIN = 32
MEM_MAX = 128
FUNC0_START_ADDR = 0x42
FUNC1_RETURN_ADDR = 0x59
FUNC1_START_ADDR = 0x47
DATA_OFFSET = 0
DATA_SIZE = 4
DATA_CONTENT = 0x2d2c2b2a

View File

@ -0,0 +1,31 @@
// 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');
var builder = new WasmModuleBuilder();
builder.addMemory(32, 128).exportMemoryAs('mem')
var func_a_idx =
builder.addFunction('wasm_A', kSig_v_v).addBody([
kExprI32Const, 0, // i32.const 0
kExprI32Const, 42, // i32.const 42
kExprI32StoreMem, 0, 0xff, 0xff, 0xff, 0xff, 0x0f, // i32.store offset = -1
]).index;
builder.addFunction('main', kSig_i_v).addBody([
kExprCallFunction, func_a_idx, // call $wasm_A
kExprI32Const, 0 // i32.const 0
])
.exportFunc();
const instance = builder.instantiate();
const main_f = instance.exports.main;
function f() {
var result = main_f();
return result;
}
f();

View File

@ -0,0 +1,28 @@
# 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.
# 0x00 (module
# 0x08 [type]
# 0x0a (type $type0 (func))
# 0x0e (type $type1 (func (result i32)))
# 0x12 [function]
# 0x17 [memory]
# 0x19 (memory $memory0 32 128)
# 0x1e [export]
# 0x20 (export "mem" (memory $memory0))
# 0x27 (export "main" (func $func1))
# 0x2e [code]
# 0x30 (func $func0
# 0x33 i32.const 0
# 0x35 i32.const 42
# 0x37 i32.store offset=-1 align=1
# 0x3e )
# 0x3f (func $func1 (result i32)
# 0x41 call $func0
# 0x43 i32.const 0
# 0x45 )
# 0x46 ...
# )
TRAP_ADDRESS = 0x0037

View File

@ -0,0 +1,37 @@
# 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: -expose-wasm --wasm-gdb-remote --wasm-pause-waiting-for-debugger test/debugging/wasm/gdb-server/test_files/test_trap.js
import sys
import unittest
import gdb_rsp
import test_files.test_trap as test_trap
# These are set up by Main().
COMMAND = None
class Tests(unittest.TestCase):
def test_trap(self):
with gdb_rsp.LaunchDebugStub(COMMAND) as connection:
module_load_addr = gdb_rsp.GetLoadedModuleAddress(connection)
reply = connection.RspRequest('c')
gdb_rsp.AssertReplySignal(reply, gdb_rsp.SIGSEGV)
tid = gdb_rsp.ParseThreadStopReply(reply)['thread_id']
self.assertEqual(tid, 1)
regs = gdb_rsp.DecodeRegs(connection.RspRequest('g'))
self.assertEqual(regs['pc'], module_load_addr + test_trap.TRAP_ADDRESS)
def Main():
index = sys.argv.index('--')
args = sys.argv[index + 1:]
# The remaining arguments go to unittest.main().
global COMMAND
COMMAND = args
unittest.main(argv=sys.argv[:index])
if __name__ == '__main__':
Main()