Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBCompileUnit.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 "lldb/API/SBCompileUnit.h" |
| 11 | #include "lldb/API/SBLineEntry.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBStream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Symbol/CompileUnit.h" |
| 14 | #include "lldb/Symbol/LineEntry.h" |
| 15 | #include "lldb/Symbol/LineTable.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | |
| 22 | SBCompileUnit::SBCompileUnit () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 23 | m_opaque_ptr (NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | { |
| 25 | } |
| 26 | |
| 27 | SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 28 | m_opaque_ptr (lldb_object_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
Greg Clayton | 538eb82 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 32 | SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) : |
| 33 | m_opaque_ptr (rhs.m_opaque_ptr) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | const SBCompileUnit & |
| 38 | SBCompileUnit::operator = (const SBCompileUnit &rhs) |
| 39 | { |
| 40 | m_opaque_ptr = rhs.m_opaque_ptr; |
| 41 | return *this; |
| 42 | } |
| 43 | |
| 44 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | SBCompileUnit::~SBCompileUnit () |
| 46 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 47 | m_opaque_ptr = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | SBFileSpec |
| 51 | SBCompileUnit::GetFileSpec () const |
| 52 | { |
| 53 | SBFileSpec file_spec; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 54 | if (m_opaque_ptr) |
| 55 | file_spec.SetFileSpec(*m_opaque_ptr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | return file_spec; |
| 57 | } |
| 58 | |
| 59 | uint32_t |
| 60 | SBCompileUnit::GetNumLineEntries () const |
| 61 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 62 | if (m_opaque_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 64 | LineTable *line_table = m_opaque_ptr->GetLineTable (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | if (line_table) |
| 66 | return line_table->GetSize(); |
| 67 | } |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | SBLineEntry |
| 72 | SBCompileUnit::GetLineEntryAtIndex (uint32_t idx) const |
| 73 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 74 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 75 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | SBLineEntry sb_line_entry; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 77 | if (m_opaque_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 79 | LineTable *line_table = m_opaque_ptr->GetLineTable (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | if (line_table) |
| 81 | { |
| 82 | LineEntry line_entry; |
| 83 | if (line_table->GetLineEntryAtIndex(idx, line_entry)) |
| 84 | sb_line_entry.SetLineEntry(line_entry); |
| 85 | } |
| 86 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 87 | |
| 88 | if (log) |
| 89 | { |
| 90 | SBStream sstr; |
| 91 | sb_line_entry.GetDescription (sstr); |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 92 | log->Printf ("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => SBLineEntry(%p): '%s'", |
| 93 | m_opaque_ptr, idx, sb_line_entry.get(), sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 96 | return sb_line_entry; |
| 97 | } |
| 98 | |
| 99 | uint32_t |
| 100 | SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec) const |
| 101 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 102 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 103 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 104 | uint32_t index = UINT32_MAX; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 105 | if (m_opaque_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | { |
| 107 | FileSpec file_spec; |
| 108 | if (inline_file_spec && inline_file_spec->IsValid()) |
| 109 | file_spec = inline_file_spec->ref(); |
| 110 | else |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 111 | file_spec = *m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 112 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 113 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 114 | index = m_opaque_ptr->FindLineEntry (start_idx, |
| 115 | line, |
| 116 | inline_file_spec ? inline_file_spec->get() : NULL, |
| 117 | NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 119 | |
| 120 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 121 | { |
| 122 | SBStream sstr; |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 123 | if (index == UINT32_MAX) |
| 124 | { |
| 125 | log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => NOT FOUND", |
| 126 | m_opaque_ptr, start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL); |
| 127 | } |
| 128 | else |
| 129 | { |
| 130 | log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => %u", |
| 131 | m_opaque_ptr, start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL, index); |
| 132 | } |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 133 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 134 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 135 | return index; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | bool |
| 139 | SBCompileUnit::IsValid () const |
| 140 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 141 | return m_opaque_ptr != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | bool |
| 145 | SBCompileUnit::operator == (const SBCompileUnit &rhs) const |
| 146 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 147 | return m_opaque_ptr == rhs.m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | bool |
| 151 | SBCompileUnit::operator != (const SBCompileUnit &rhs) const |
| 152 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 153 | return m_opaque_ptr != rhs.m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | const lldb_private::CompileUnit * |
| 157 | SBCompileUnit::operator->() const |
| 158 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 159 | return m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | const lldb_private::CompileUnit & |
| 163 | SBCompileUnit::operator*() const |
| 164 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 165 | return *m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 166 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 167 | |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 168 | const lldb_private::CompileUnit * |
| 169 | SBCompileUnit::get () const |
| 170 | { |
| 171 | return m_opaque_ptr; |
| 172 | } |
| 173 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 174 | bool |
| 175 | SBCompileUnit::GetDescription (SBStream &description) |
| 176 | { |
| 177 | if (m_opaque_ptr) |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 178 | { |
Caroline Tice | e49ec18 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 179 | description.ref(); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 180 | m_opaque_ptr->Dump (description.get(), false); |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 181 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 182 | else |
Caroline Tice | e7a566e | 2010-09-20 16:21:41 +0000 | [diff] [blame] | 183 | description.Printf ("No Value"); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 184 | |
| 185 | return true; |
| 186 | } |