]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugMacinfoEntry.cpp
Merge ^/head r312309 through r312623.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DWARFDebugMacinfoEntry.cpp
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), m_line(0), m_op2() {
19   m_op2.cstr = NULL;
20 }
21
22 DWARFDebugMacinfoEntry::~DWARFDebugMacinfoEntry() {}
23
24 const char *DWARFDebugMacinfoEntry::GetCString() const {
25   switch (m_type_code) {
26   case 0:
27   case DW_MACINFO_start_file:
28   case DW_MACINFO_end_file:
29     return NULL;
30   default:
31     break;
32   }
33   return m_op2.cstr;
34 }
35
36 void DWARFDebugMacinfoEntry::Dump(Stream *s) const {
37   if (m_type_code) {
38     s->PutCString(DW_MACINFO_value_to_name(m_type_code));
39
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);
43       break;
44
45     case DW_MACINFO_undef:
46       s->Printf(" line:%u  #undef %s\n", (uint32_t)m_line, m_op2.cstr);
47       break;
48
49     default:
50       s->Printf(" line:%u  str: '%s'\n", (uint32_t)m_line, m_op2.cstr);
51       break;
52
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);
56       break;
57
58     case DW_MACINFO_end_file:
59       break;
60     }
61   } else {
62     s->PutCString(" END\n");
63   }
64 }
65
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);
70
71     switch (m_type_code) {
72
73     case DW_MACINFO_define:
74     case DW_MACINFO_undef:
75       // 2 operands:
76       // Arg 1: operand encodes the line number of the source line on which
77       //      the relevant defining or undefining pre-processor directives
78       //      appeared.
79       m_line = mac_info_data.GetULEB128(offset_ptr);
80       // Arg 2: define string
81       m_op2.cstr = mac_info_data.GetCStr(offset_ptr);
82       break;
83
84     case DW_MACINFO_start_file:
85       // 2 operands:
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);
92       break;
93
94     case 0: // End of list
95     case DW_MACINFO_end_file:
96       // No operands
97       m_line = DW_INVALID_OFFSET;
98       m_op2.cstr = NULL;
99       break;
100     default:
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);
104       break;
105     }
106     return true;
107   } else
108     m_type_code = 0;
109
110   return false;
111 }