// 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. #include "src/debug/debug-interface.h" #include "src/wasm/wasm-macro-gen.h" #include "src/wasm/wasm-objects.h" #include "test/cctest/cctest.h" #include "test/cctest/compiler/value-helper.h" #include "test/cctest/wasm/wasm-run-utils.h" #include "test/common/wasm/test-signatures.h" using namespace v8::internal; using namespace v8::internal::wasm; namespace debug = v8::debug; namespace { void CheckLocations( WasmCompiledModule *compiled_module, debug::Location start, debug::Location end, std::initializer_list expected_locations_init) { std::vector locations; bool success = compiled_module->GetPossibleBreakpoints(start, end, &locations); CHECK(success); printf("got %d locations: ", static_cast(locations.size())); for (size_t i = 0, e = locations.size(); i != e; ++i) { printf("%s<%d,%d>", i == 0 ? "" : ", ", locations[i].GetLineNumber(), locations[i].GetColumnNumber()); } printf("\n"); std::vector expected_locations(expected_locations_init); CHECK_EQ(expected_locations.size(), locations.size()); for (size_t i = 0, e = locations.size(); i != e; ++i) { CHECK_EQ(expected_locations[i].GetLineNumber(), locations[i].GetLineNumber()); CHECK_EQ(expected_locations[i].GetColumnNumber(), locations[i].GetColumnNumber()); } } void CheckLocationsFail(WasmCompiledModule *compiled_module, debug::Location start, debug::Location end) { std::vector locations; bool success = compiled_module->GetPossibleBreakpoints(start, end, &locations); CHECK(!success); } } // namespace TEST(CollectPossibleBreakpoints) { WasmRunner runner(kExecuteCompiled); BUILD(runner, WASM_NOP, WASM_I32_ADD(WASM_ZERO, WASM_ONE)); Handle instance = runner.module().instance_object(); std::vector locations; CheckLocations(instance->compiled_module(), {0, 0}, {1, 0}, {{0, 1}, {0, 2}, {0, 4}, {0, 6}}); CheckLocations(instance->compiled_module(), {0, 2}, {0, 4}, {{0, 2}}); CheckLocations(instance->compiled_module(), {0, 2}, {0, 5}, {{0, 2}, {0, 4}}); CheckLocations(instance->compiled_module(), {0, 6}, {0, 7}, {{0, 6}}); CheckLocations(instance->compiled_module(), {0, 6}, {1, 0}, {{0, 6}}); CheckLocations(instance->compiled_module(), {0, 7}, {1, 0}, {}); CheckLocationsFail(instance->compiled_module(), {0, 8}, {1, 0}); }