v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-module-sourcemap.h
Go to the documentation of this file.
1// Copyright 2019 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_WASM_WASM_MODULE_SOURCEMAP_H_
6#define V8_WASM_WASM_MODULE_SOURCEMAP_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
12#include <string>
13#include <vector>
14
16#include "src/base/macros.h"
17
18namespace v8 {
19
20class String;
21
22namespace internal {
23namespace wasm {
24// The class is for decoding and managing source map generated by a WebAssembly
25// toolchain (e.g. Emscripten). This implementation mostly complies with the
26// specification (https://sourcemaps.info/spec.html), with the following
27// accommodations:
28// 1. "names" field is an empty array in current source maps of Wasm, hence it
29// is not handled;
30// 2. The semicolons divides "mappings" field into groups, each of which
31// represents a line in the generated code. As *.wasm is in binary format, there
32// is one "line" of generated code, and ";" is treated as illegal symbol in
33// "mappings".
34// 3. Though each comma-separated section may contains 1, 4 or 5 fields, we only
35// consider "mappings" with 4 fields, i.e. start line of generated code, index
36// into "sources" fields, start line of source code and start column of source
37// code.
39 public:
41 v8::Local<v8::String> src_map_str);
42
43 // Member valid_ is true only if the source map complies with specification
44 // and can be correctly decoded.
45 bool IsValid() const { return valid_; }
46
47 // Given a function located at [start, end) in Wasm Module, this function
48 // checks if this function has its corresponding source code.
49 bool HasSource(size_t start, size_t end) const;
50
51 // Given a function's base address start and an address addr within, this
52 // function checks if the address can be mapped to an offset in this function.
53 // For example, we have the following memory layout for Wasm functions, foo
54 // and bar, and O1, O2, O3 and O4 are the decoded offsets of source map:
55 //
56 // O1 --- O2 ----- O3 ----- O4
57 // --->|<-foo->|<--bar->|<-----
58 // --------------A-------------
59 //
60 // Address A of function bar should be mapped to its nearest lower offset, O2.
61 // However, O2 is an address of function foo, thus, this mapping is treated as
62 // invalid.
63 bool HasValidEntry(size_t start, size_t addr) const;
64
65 // This function is responsible for looking up an offset's corresponding line
66 // number in source file. It should only be called when current function is
67 // checked with IsValid, HasSource and HasValidEntry.
68 size_t GetSourceLine(size_t wasm_offset) const;
69
70 // This function is responsible for looking up an offset's corresponding
71 // source file name. It should only be called when current function is checked
72 // with IsValid, HasSource and HasValidEntry.
73 std::string GetFilename(size_t wasm_offset) const;
74
75 size_t EstimateCurrentMemoryConsumption() const;
76
77 private:
78 std::vector<size_t> offsets;
79 std::vector<std::string> filenames;
80 std::vector<size_t> file_idxs;
81 std::vector<size_t> source_row;
82 // As column number in source file is always 0 in source map generated by
83 // WebAssembly toolchain, we will not store this value.
84
85 bool valid_ = false;
86
87 bool DecodeMapping(const std::string& s);
88};
89} // namespace wasm
90} // namespace internal
91} // namespace v8
92#endif // V8_WASM_WASM_MODULE_SOURCEMAP_H_
int start
int end
v8_inspector::String16 String
Definition string-util.h:26
Definition c-api.cc:87
#define V8_EXPORT_PRIVATE
Definition macros.h:460