1 //===-- DWARFDebugMacinfoEntry.cpp ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFDebugMacinfoEntry.h"
12 #include "lldb/Utility/Stream.h"
14 using namespace lldb_private;
17 DWARFDebugMacinfoEntry::DWARFDebugMacinfoEntry()
18 : m_type_code(0), m_line(0), m_op2() {
22 DWARFDebugMacinfoEntry::~DWARFDebugMacinfoEntry() {}
24 const char *DWARFDebugMacinfoEntry::GetCString() const {
25 switch (m_type_code) {
27 case DW_MACINFO_start_file:
28 case DW_MACINFO_end_file:
36 void DWARFDebugMacinfoEntry::Dump(Stream *s) const {
38 s->PutCString(DW_MACINFO_value_to_name(m_type_code));
40 switch (m_type_code) {
41 case DW_MACINFO_define:
42 s->Printf(" line:%u #define %s\n", (uint32_t)m_line, m_op2.cstr);
45 case DW_MACINFO_undef:
46 s->Printf(" line:%u #undef %s\n", (uint32_t)m_line, m_op2.cstr);
50 s->Printf(" line:%u str: '%s'\n", (uint32_t)m_line, m_op2.cstr);
53 case DW_MACINFO_start_file:
54 s->Printf(" line:%u file index: '%u'\n", (uint32_t)m_line,
55 (uint32_t)m_op2.file_idx);
58 case DW_MACINFO_end_file:
62 s->PutCString(" END\n");
66 bool DWARFDebugMacinfoEntry::Extract(const DWARFDataExtractor &mac_info_data,
67 lldb::offset_t *offset_ptr) {
68 if (mac_info_data.ValidOffset(*offset_ptr)) {
69 m_type_code = mac_info_data.GetU8(offset_ptr);
71 switch (m_type_code) {
73 case DW_MACINFO_define:
74 case DW_MACINFO_undef:
76 // Arg 1: operand encodes the line number of the source line on which
77 // the relevant defining or undefining pre-processor directives
79 m_line = mac_info_data.GetULEB128(offset_ptr);
80 // Arg 2: define string
81 m_op2.cstr = mac_info_data.GetCStr(offset_ptr);
84 case DW_MACINFO_start_file:
86 // Op 1: line number of the source line on which the inclusion
87 // pre-processor directive occurred.
88 m_line = mac_info_data.GetULEB128(offset_ptr);
89 // Op 2: a source file name index to a file number in the statement
90 // information table for the relevant compilation unit.
91 m_op2.file_idx = mac_info_data.GetULEB128(offset_ptr);
94 case 0: // End of list
95 case DW_MACINFO_end_file:
97 m_line = DW_INVALID_OFFSET;
101 // Vendor specific entries always have a ULEB128 and a string
102 m_line = mac_info_data.GetULEB128(offset_ptr);
103 m_op2.cstr = mac_info_data.GetCStr(offset_ptr);