LLDB mainline
SymbolFileWasm.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "SymbolFileWasm.h"
13
14using namespace lldb;
15using namespace lldb_private;
16using namespace lldb_private::plugin::dwarf;
17
19 SectionList *dwo_section_list)
20 : SymbolFileDWARF(objfile_sp, dwo_section_list) {}
21
23
26 const lldb::offset_t data_offset,
27 const uint8_t op) const {
28 if (op != llvm::dwarf::DW_OP_WASM_location)
30
31 lldb::offset_t offset = data_offset;
32 const uint8_t wasm_op = data.GetU8(&offset);
33 switch (wasm_op) {
34 case 0: // LOCAL
35 case 1: // GLOBAL_FIXED
36 case 2: // OPERAND_STACK
37 data.GetULEB128(&offset);
38 break;
39 case 3: // GLOBAL_RELOC
40 data.GetU32(&offset);
41 break;
42 default:
44 }
45
46 return offset - data_offset;
47}
48
50 const DataExtractor &opcodes,
51 lldb::offset_t &offset,
52 RegisterContext *reg_ctx,
53 lldb::RegisterKind reg_kind,
54 std::vector<Value> &stack) const {
55 if (op != llvm::dwarf::DW_OP_WASM_location)
56 return false;
57
58 uint32_t index = 0;
59 uint8_t tag = eWasmTagNotAWasmLocation;
60
61 /// |DWARF Location Index | WebAssembly Construct |
62 /// |---------------------|-----------------------|
63 /// |0 | Local |
64 /// |1 or 3 | Global |
65 /// |2 | Operand Stack |
66 const uint8_t wasm_op = opcodes.GetU8(&offset);
67 switch (wasm_op) {
68 case 0: // LOCAL
69 index = opcodes.GetULEB128(&offset);
70 tag = eWasmTagLocal;
71 break;
72 case 1: // GLOBAL_FIXED
73 index = opcodes.GetULEB128(&offset);
74 tag = eWasmTagGlobal;
75 break;
76 case 2: // OPERAND_STACK
77 index = opcodes.GetULEB128(&offset);
79 break;
80 case 3: // GLOBAL_RELOC
81 index = opcodes.GetU32(&offset);
82 tag = eWasmTagGlobal;
83 break;
84 default:
85 return false;
86 }
87
88 const uint32_t reg_num = GetWasmRegister(tag, index);
89
90 Value tmp;
92 reg_ctx, reg_kind, reg_num, tmp);
93 if (error) {
95 return false;
96 }
97
98 stack.push_back(tmp);
99 return true;
100}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
static llvm::Error ReadRegisterValueAsScalar(RegisterContext *reg_ctx, lldb::RegisterKind reg_kind, uint32_t reg_num, Value &value)
An data extractor class.
uint64_t GetULEB128(lldb::offset_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
uint8_t GetU8(lldb::offset_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
SymbolFileDWARF(lldb::ObjectFileSP objfile_sp, SectionList *dwo_section_list)
SymbolFileWasm(lldb::ObjectFileSP objfile_sp, SectionList *dwo_section_list)
lldb::offset_t GetVendorDWARFOpcodeSize(const DataExtractor &data, const lldb::offset_t data_offset, const uint8_t op) const override
bool ParseVendorDWARFOpcode(uint8_t op, const DataExtractor &opcodes, lldb::offset_t &offset, RegisterContext *reg_ctx, lldb::RegisterKind reg_kind, std::vector< Value > &stack) const override
#define LLDB_INVALID_OFFSET
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
uint32_t GetWasmRegister(uint8_t tag, uint32_t index)
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
RegisterKind
Register numbering types.