101 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "SymbolFileWasm.h"10#include "Plugins/SymbolFile/DWARF/LogChannelDWARF.h"11#include "Utility/WasmVirtualRegisters.h"12#include "lldb/Utility/LLDBLog.h"13 14using namespace lldb;15using namespace lldb_private;16using namespace lldb_private::plugin::dwarf;17 18SymbolFileWasm::SymbolFileWasm(ObjectFileSP objfile_sp,19 SectionList *dwo_section_list)20 : SymbolFileDWARF(objfile_sp, dwo_section_list) {}21 22SymbolFileWasm::~SymbolFileWasm() = default;23 24lldb::offset_t25SymbolFileWasm::GetVendorDWARFOpcodeSize(const DataExtractor &data,26 const lldb::offset_t data_offset,27 const uint8_t op) const {28 if (op != llvm::dwarf::DW_OP_WASM_location)29 return LLDB_INVALID_OFFSET;30 31 lldb::offset_t offset = data_offset;32 const uint8_t wasm_op = data.GetU8(&offset);33 switch (wasm_op) {34 case 0: // LOCAL35 case 1: // GLOBAL_FIXED36 case 2: // OPERAND_STACK37 data.GetULEB128(&offset);38 break;39 case 3: // GLOBAL_RELOC40 data.GetU32(&offset);41 break;42 default:43 return LLDB_INVALID_OFFSET;44 }45 46 return offset - data_offset;47}48 49bool SymbolFileWasm::ParseVendorDWARFOpcode(uint8_t op,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: // LOCAL69 index = opcodes.GetULEB128(&offset);70 tag = eWasmTagLocal;71 break;72 case 1: // GLOBAL_FIXED73 index = opcodes.GetULEB128(&offset);74 tag = eWasmTagGlobal;75 break;76 case 2: // OPERAND_STACK77 index = opcodes.GetULEB128(&offset);78 tag = eWasmTagOperandStack;79 break;80 case 3: // GLOBAL_RELOC81 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;91 llvm::Error error = DWARFExpression::ReadRegisterValueAsScalar(92 reg_ctx, reg_kind, reg_num, tmp);93 if (error) {94 LLDB_LOG_ERROR(GetLog(DWARFLog::DebugInfo), std::move(error), "{0}");95 return false;96 }97 98 stack.push_back(tmp);99 return true;100}101