1 //===-- DWARFDebugMacinfoEntry.cpp ------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "DWARFDebugMacinfoEntry.h" 11 12 #include "lldb/Core/Stream.h" 13 14 using namespace lldb_private; 15 using namespace std; 16 17 DWARFDebugMacinfoEntry::DWARFDebugMacinfoEntry() : 18 m_type_code(0), 19 m_line(0), 20 m_op2() 21 { 22 m_op2.cstr = NULL; 23 } 24 25 DWARFDebugMacinfoEntry::~DWARFDebugMacinfoEntry() 26 { 27 } 28 29 const char* 30 DWARFDebugMacinfoEntry::GetCString() const 31 { 32 switch (m_type_code) 33 { 34 case 0: 35 case DW_MACINFO_start_file: 36 case DW_MACINFO_end_file: 37 return NULL; 38 default: 39 break; 40 } 41 return m_op2.cstr; 42 } 43 44 45 46 void 47 DWARFDebugMacinfoEntry::Dump(Stream *s) const 48 { 49 if (m_type_code) 50 { 51 s->PutCString(DW_MACINFO_value_to_name(m_type_code)); 52 53 switch (m_type_code) 54 { 55 case DW_MACINFO_define: 56 s->Printf(" line:%u #define %s\n", (uint32_t)m_line, m_op2.cstr); 57 break; 58 59 case DW_MACINFO_undef: 60 s->Printf(" line:%u #undef %s\n", (uint32_t)m_line, m_op2.cstr); 61 break; 62 63 default: 64 s->Printf(" line:%u str: '%s'\n", (uint32_t)m_line, m_op2.cstr); 65 break; 66 67 case DW_MACINFO_start_file: 68 s->Printf(" line:%u file index: '%u'\n", (uint32_t)m_line, (uint32_t)m_op2.file_idx); 69 break; 70 71 case DW_MACINFO_end_file: 72 break; 73 } 74 } 75 else 76 { 77 s->PutCString(" END\n"); 78 } 79 } 80 81 82 bool 83 DWARFDebugMacinfoEntry::Extract(const DataExtractor& mac_info_data, lldb::offset_t* offset_ptr) 84 { 85 if (mac_info_data.ValidOffset(*offset_ptr)) 86 { 87 m_type_code = mac_info_data.GetU8(offset_ptr); 88 89 switch (m_type_code) 90 { 91 92 case DW_MACINFO_define: 93 case DW_MACINFO_undef: 94 // 2 operands: 95 // Arg 1: operand encodes the line number of the source line on which 96 // the relevant defining or undefining pre-processor directives 97 // appeared. 98 m_line = mac_info_data.GetULEB128(offset_ptr); 99 // Arg 2: define string 100 m_op2.cstr = mac_info_data.GetCStr(offset_ptr); 101 break; 102 103 case DW_MACINFO_start_file: 104 // 2 operands: 105 // Op 1: line number of the source line on which the inclusion 106 // pre-processor directive occurred. 107 m_line = mac_info_data.GetULEB128(offset_ptr); 108 // Op 2: a source file name index to a file number in the statement 109 // information table for the relevant compilation unit. 110 m_op2.file_idx = mac_info_data.GetULEB128(offset_ptr); 111 break; 112 113 case 0: // End of list 114 case DW_MACINFO_end_file: 115 // No operands 116 m_line = DW_INVALID_OFFSET; 117 m_op2.cstr = NULL; 118 break; 119 default: 120 // Vendor specific entries always have a ULEB128 and a string 121 m_line = mac_info_data.GetULEB128(offset_ptr); 122 m_op2.cstr = mac_info_data.GetCStr(offset_ptr); 123 break; 124 } 125 return true; 126 } 127 else 128 m_type_code = 0; 129 130 return false; 131 } 132 133