Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacro.cpp
39644 views
//===-- DWARFDebugMacro.cpp -----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "DWARFDebugMacro.h"9#include "SymbolFileDWARF.h"1011#include "lldb/Symbol/DebugMacros.h"1213#include "DWARFDataExtractor.h"1415using namespace lldb_private;16using namespace lldb_private::dwarf;17using namespace lldb_private::plugin::dwarf;1819DWARFDebugMacroHeader20DWARFDebugMacroHeader::ParseHeader(const DWARFDataExtractor &debug_macro_data,21lldb::offset_t *offset) {22DWARFDebugMacroHeader header;2324// Skip over the version field in header.25header.m_version = debug_macro_data.GetU16(offset);2627uint8_t flags = debug_macro_data.GetU8(offset);28header.m_offset_is_64_bit = (flags & OFFSET_SIZE_MASK) != 0;2930if (flags & DEBUG_LINE_OFFSET_MASK) {31if (header.m_offset_is_64_bit)32header.m_debug_line_offset = debug_macro_data.GetU64(offset);33else34header.m_debug_line_offset = debug_macro_data.GetU32(offset);35}3637// Skip over the operands table if it is present.38if (flags & OPCODE_OPERANDS_TABLE_MASK)39SkipOperandTable(debug_macro_data, offset);4041return header;42}4344void DWARFDebugMacroHeader::SkipOperandTable(45const DWARFDataExtractor &debug_macro_data, lldb::offset_t *offset) {46uint8_t entry_count = debug_macro_data.GetU8(offset);47for (uint8_t i = 0; i < entry_count; i++) {48// Skip over the opcode number.49debug_macro_data.GetU8(offset);5051uint64_t operand_count = debug_macro_data.GetULEB128(offset);5253for (uint64_t j = 0; j < operand_count; j++) {54// Skip over the operand form55debug_macro_data.GetU8(offset);56}57}58}5960void DWARFDebugMacroEntry::ReadMacroEntries(61const DWARFDataExtractor &debug_macro_data,62const DWARFDataExtractor &debug_str_data, const bool offset_is_64_bit,63lldb::offset_t *offset, SymbolFileDWARF *sym_file_dwarf,64DebugMacrosSP &debug_macros_sp) {65llvm::dwarf::MacroEntryType type =66static_cast<llvm::dwarf::MacroEntryType>(debug_macro_data.GetU8(offset));67while (type != 0) {68lldb::offset_t new_offset = 0, str_offset = 0;69uint32_t line = 0;70const char *macro_str = nullptr;71uint32_t debug_line_file_idx = 0;7273switch (type) {74case DW_MACRO_define:75case DW_MACRO_undef:76line = debug_macro_data.GetULEB128(offset);77macro_str = debug_macro_data.GetCStr(offset);78if (type == DW_MACRO_define)79debug_macros_sp->AddMacroEntry(80DebugMacroEntry::CreateDefineEntry(line, macro_str));81else82debug_macros_sp->AddMacroEntry(83DebugMacroEntry::CreateUndefEntry(line, macro_str));84break;85case DW_MACRO_define_strp:86case DW_MACRO_undef_strp:87line = debug_macro_data.GetULEB128(offset);88if (offset_is_64_bit)89str_offset = debug_macro_data.GetU64(offset);90else91str_offset = debug_macro_data.GetU32(offset);92macro_str = debug_str_data.GetCStr(&str_offset);93if (type == DW_MACRO_define_strp)94debug_macros_sp->AddMacroEntry(95DebugMacroEntry::CreateDefineEntry(line, macro_str));96else97debug_macros_sp->AddMacroEntry(98DebugMacroEntry::CreateUndefEntry(line, macro_str));99break;100case DW_MACRO_start_file:101line = debug_macro_data.GetULEB128(offset);102debug_line_file_idx = debug_macro_data.GetULEB128(offset);103debug_macros_sp->AddMacroEntry(104DebugMacroEntry::CreateStartFileEntry(line, debug_line_file_idx));105break;106case DW_MACRO_end_file:107// This operation has no operands.108debug_macros_sp->AddMacroEntry(DebugMacroEntry::CreateEndFileEntry());109break;110case DW_MACRO_import:111if (offset_is_64_bit)112new_offset = debug_macro_data.GetU64(offset);113else114new_offset = debug_macro_data.GetU32(offset);115debug_macros_sp->AddMacroEntry(DebugMacroEntry::CreateIndirectEntry(116sym_file_dwarf->ParseDebugMacros(&new_offset)));117break;118default:119// TODO: Add support for other standard operations.120// TODO: Provide mechanism to hook handling of non-standard/extension121// operands.122return;123}124type = static_cast<llvm::dwarf::MacroEntryType>(125debug_macro_data.GetU8(offset));126}127}128129130