1ac7ddfbfSEd Maste //===-- DWARFDebugMacinfoEntry.cpp ------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "DWARFDebugMacinfoEntry.h"
11ac7ddfbfSEd Maste
12*f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
13ac7ddfbfSEd Maste
14ac7ddfbfSEd Maste using namespace lldb_private;
15ac7ddfbfSEd Maste using namespace std;
16ac7ddfbfSEd Maste
DWARFDebugMacinfoEntry()17435933ddSDimitry Andric DWARFDebugMacinfoEntry::DWARFDebugMacinfoEntry()
18435933ddSDimitry Andric : m_type_code(0), m_line(0), m_op2() {
19ac7ddfbfSEd Maste m_op2.cstr = NULL;
20ac7ddfbfSEd Maste }
21ac7ddfbfSEd Maste
~DWARFDebugMacinfoEntry()22435933ddSDimitry Andric DWARFDebugMacinfoEntry::~DWARFDebugMacinfoEntry() {}
23ac7ddfbfSEd Maste
GetCString() const24435933ddSDimitry Andric const char *DWARFDebugMacinfoEntry::GetCString() const {
25435933ddSDimitry Andric switch (m_type_code) {
26ac7ddfbfSEd Maste case 0:
27ac7ddfbfSEd Maste case DW_MACINFO_start_file:
28ac7ddfbfSEd Maste case DW_MACINFO_end_file:
29ac7ddfbfSEd Maste return NULL;
30ac7ddfbfSEd Maste default:
31ac7ddfbfSEd Maste break;
32ac7ddfbfSEd Maste }
33ac7ddfbfSEd Maste return m_op2.cstr;
34ac7ddfbfSEd Maste }
35ac7ddfbfSEd Maste
Dump(Stream * s) const36435933ddSDimitry Andric void DWARFDebugMacinfoEntry::Dump(Stream *s) const {
37435933ddSDimitry Andric if (m_type_code) {
38ac7ddfbfSEd Maste s->PutCString(DW_MACINFO_value_to_name(m_type_code));
39ac7ddfbfSEd Maste
40435933ddSDimitry Andric switch (m_type_code) {
41ac7ddfbfSEd Maste case DW_MACINFO_define:
42ac7ddfbfSEd Maste s->Printf(" line:%u #define %s\n", (uint32_t)m_line, m_op2.cstr);
43ac7ddfbfSEd Maste break;
44ac7ddfbfSEd Maste
45ac7ddfbfSEd Maste case DW_MACINFO_undef:
46ac7ddfbfSEd Maste s->Printf(" line:%u #undef %s\n", (uint32_t)m_line, m_op2.cstr);
47ac7ddfbfSEd Maste break;
48ac7ddfbfSEd Maste
49ac7ddfbfSEd Maste default:
50ac7ddfbfSEd Maste s->Printf(" line:%u str: '%s'\n", (uint32_t)m_line, m_op2.cstr);
51ac7ddfbfSEd Maste break;
52ac7ddfbfSEd Maste
53ac7ddfbfSEd Maste case DW_MACINFO_start_file:
54435933ddSDimitry Andric s->Printf(" line:%u file index: '%u'\n", (uint32_t)m_line,
55435933ddSDimitry Andric (uint32_t)m_op2.file_idx);
56ac7ddfbfSEd Maste break;
57ac7ddfbfSEd Maste
58ac7ddfbfSEd Maste case DW_MACINFO_end_file:
59ac7ddfbfSEd Maste break;
60ac7ddfbfSEd Maste }
61435933ddSDimitry Andric } else {
62ac7ddfbfSEd Maste s->PutCString(" END\n");
63ac7ddfbfSEd Maste }
64ac7ddfbfSEd Maste }
65ac7ddfbfSEd Maste
Extract(const DWARFDataExtractor & mac_info_data,lldb::offset_t * offset_ptr)66435933ddSDimitry Andric bool DWARFDebugMacinfoEntry::Extract(const DWARFDataExtractor &mac_info_data,
67435933ddSDimitry Andric lldb::offset_t *offset_ptr) {
68435933ddSDimitry Andric if (mac_info_data.ValidOffset(*offset_ptr)) {
69ac7ddfbfSEd Maste m_type_code = mac_info_data.GetU8(offset_ptr);
70ac7ddfbfSEd Maste
71435933ddSDimitry Andric switch (m_type_code) {
72ac7ddfbfSEd Maste
73ac7ddfbfSEd Maste case DW_MACINFO_define:
74ac7ddfbfSEd Maste case DW_MACINFO_undef:
75ac7ddfbfSEd Maste // 2 operands:
76ac7ddfbfSEd Maste // Arg 1: operand encodes the line number of the source line on which
77ac7ddfbfSEd Maste // the relevant defining or undefining pre-processor directives
78ac7ddfbfSEd Maste // appeared.
79ac7ddfbfSEd Maste m_line = mac_info_data.GetULEB128(offset_ptr);
80ac7ddfbfSEd Maste // Arg 2: define string
81ac7ddfbfSEd Maste m_op2.cstr = mac_info_data.GetCStr(offset_ptr);
82ac7ddfbfSEd Maste break;
83ac7ddfbfSEd Maste
84ac7ddfbfSEd Maste case DW_MACINFO_start_file:
85ac7ddfbfSEd Maste // 2 operands:
86ac7ddfbfSEd Maste // Op 1: line number of the source line on which the inclusion
87ac7ddfbfSEd Maste // pre-processor directive occurred.
88ac7ddfbfSEd Maste m_line = mac_info_data.GetULEB128(offset_ptr);
89ac7ddfbfSEd Maste // Op 2: a source file name index to a file number in the statement
90ac7ddfbfSEd Maste // information table for the relevant compilation unit.
91ac7ddfbfSEd Maste m_op2.file_idx = mac_info_data.GetULEB128(offset_ptr);
92ac7ddfbfSEd Maste break;
93ac7ddfbfSEd Maste
94ac7ddfbfSEd Maste case 0: // End of list
95ac7ddfbfSEd Maste case DW_MACINFO_end_file:
96ac7ddfbfSEd Maste // No operands
97ac7ddfbfSEd Maste m_line = DW_INVALID_OFFSET;
98ac7ddfbfSEd Maste m_op2.cstr = NULL;
99ac7ddfbfSEd Maste break;
100ac7ddfbfSEd Maste default:
101ac7ddfbfSEd Maste // Vendor specific entries always have a ULEB128 and a string
102ac7ddfbfSEd Maste m_line = mac_info_data.GetULEB128(offset_ptr);
103ac7ddfbfSEd Maste m_op2.cstr = mac_info_data.GetCStr(offset_ptr);
104ac7ddfbfSEd Maste break;
105ac7ddfbfSEd Maste }
106ac7ddfbfSEd Maste return true;
107435933ddSDimitry Andric } else
108ac7ddfbfSEd Maste m_type_code = 0;
109ac7ddfbfSEd Maste
110ac7ddfbfSEd Maste return false;
111ac7ddfbfSEd Maste }
112