blob: 7852fc8a0d77495dbc78f176e2688c96bb2d3e52 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Ticedde9cff2010-09-20 05:20:02 +000012#include "lldb/API/SBStream.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013#include "lldb/Symbol/CompileUnit.h"
14#include "lldb/Symbol/LineEntry.h"
15#include "lldb/Symbol/LineTable.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000016#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017
18using namespace lldb;
19using namespace lldb_private;
20
21
22SBCompileUnit::SBCompileUnit () :
Greg Clayton66111032010-06-23 01:19:29 +000023 m_opaque_ptr (NULL)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024{
25}
26
27SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) :
Greg Clayton66111032010-06-23 01:19:29 +000028 m_opaque_ptr (lldb_object_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029{
30}
31
Greg Claytonefabb122010-11-05 23:17:00 +000032SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) :
33 m_opaque_ptr (rhs.m_opaque_ptr)
34{
35}
36
37const SBCompileUnit &
38SBCompileUnit::operator = (const SBCompileUnit &rhs)
39{
40 m_opaque_ptr = rhs.m_opaque_ptr;
41 return *this;
42}
43
44
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045SBCompileUnit::~SBCompileUnit ()
46{
Greg Clayton66111032010-06-23 01:19:29 +000047 m_opaque_ptr = NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048}
49
50SBFileSpec
51SBCompileUnit::GetFileSpec () const
52{
53 SBFileSpec file_spec;
Greg Clayton66111032010-06-23 01:19:29 +000054 if (m_opaque_ptr)
55 file_spec.SetFileSpec(*m_opaque_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056 return file_spec;
57}
58
59uint32_t
60SBCompileUnit::GetNumLineEntries () const
61{
Greg Clayton66111032010-06-23 01:19:29 +000062 if (m_opaque_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063 {
Greg Clayton66111032010-06-23 01:19:29 +000064 LineTable *line_table = m_opaque_ptr->GetLineTable ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 if (line_table)
66 return line_table->GetSize();
67 }
68 return 0;
69}
70
71SBLineEntry
72SBCompileUnit::GetLineEntryAtIndex (uint32_t idx) const
73{
Greg Clayton2d4edfb2010-11-06 01:53:30 +000074 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000075
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 SBLineEntry sb_line_entry;
Greg Clayton66111032010-06-23 01:19:29 +000077 if (m_opaque_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078 {
Greg Clayton66111032010-06-23 01:19:29 +000079 LineTable *line_table = m_opaque_ptr->GetLineTable ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080 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 Ticeceb6b132010-10-26 03:11:13 +000087
88 if (log)
89 {
90 SBStream sstr;
91 sb_line_entry.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +000092 log->Printf ("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => SBLineEntry(%p): '%s'",
93 m_opaque_ptr, idx, sb_line_entry.get(), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +000094 }
95
Chris Lattner30fdc8d2010-06-08 16:52:24 +000096 return sb_line_entry;
97}
98
99uint32_t
100SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec) const
101{
Jim Ingham87df91b2011-09-23 00:54:11 +0000102 const bool exact = true;
103 return FindLineEntryIndex (start_idx, line, inline_file_spec, exact);
104}
105
106uint32_t
107SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec, bool exact) const
108{
Greg Clayton2d4edfb2010-11-06 01:53:30 +0000109 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000110
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000111 uint32_t index = UINT32_MAX;
Greg Clayton66111032010-06-23 01:19:29 +0000112 if (m_opaque_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113 {
114 FileSpec file_spec;
115 if (inline_file_spec && inline_file_spec->IsValid())
116 file_spec = inline_file_spec->ref();
117 else
Greg Clayton66111032010-06-23 01:19:29 +0000118 file_spec = *m_opaque_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000119
Caroline Ticeceb6b132010-10-26 03:11:13 +0000120
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000121 index = m_opaque_ptr->FindLineEntry (start_idx,
122 line,
123 inline_file_spec ? inline_file_spec->get() : NULL,
Jim Ingham87df91b2011-09-23 00:54:11 +0000124 exact,
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000125 NULL);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000127
128 if (log)
Caroline Tice750cd172010-10-26 23:49:36 +0000129 {
130 SBStream sstr;
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000131 if (index == UINT32_MAX)
132 {
133 log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => NOT FOUND",
134 m_opaque_ptr, start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL);
135 }
136 else
137 {
138 log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => %u",
139 m_opaque_ptr, start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL, index);
140 }
Caroline Tice750cd172010-10-26 23:49:36 +0000141 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000142
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000143 return index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144}
145
Johnny Chen873a7a42012-03-16 20:46:10 +0000146uint32_t
147SBCompileUnit::GetNumSupportFiles () const
148{
149 if (m_opaque_ptr)
150 {
151 FileSpecList& support_files = m_opaque_ptr->GetSupportFiles ();
152 return support_files.GetSize();
153 }
154 return 0;
155}
156
157SBFileSpec
158SBCompileUnit::GetSupportFileAtIndex (uint32_t idx) const
159{
160 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
161
162 SBFileSpec sb_file_spec;
163 if (m_opaque_ptr)
164 {
165 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles ();
166 FileSpec file_spec = support_files.GetFileSpecAtIndex(idx);
167 sb_file_spec.SetFileSpec(file_spec);
168 }
169
170 if (log)
171 {
172 SBStream sstr;
173 sb_file_spec.GetDescription (sstr);
174 log->Printf ("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => SBFileSpec(%p): '%s'",
175 m_opaque_ptr, idx, sb_file_spec.get(), sstr.GetData());
176 }
177
178 return sb_file_spec;
179}
180
181uint32_t
182SBCompileUnit::FindSupportFileIndex (uint32_t start_idx, const SBFileSpec &sb_file, bool full)
183{
184 if (m_opaque_ptr)
185 {
186 FileSpecList &support_files = m_opaque_ptr->GetSupportFiles ();
187 return support_files.FindFileIndex(start_idx, sb_file.ref(), full);
188 }
189 return 0;
190}
191
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192bool
193SBCompileUnit::IsValid () const
194{
Greg Clayton66111032010-06-23 01:19:29 +0000195 return m_opaque_ptr != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196}
197
198bool
199SBCompileUnit::operator == (const SBCompileUnit &rhs) const
200{
Greg Clayton66111032010-06-23 01:19:29 +0000201 return m_opaque_ptr == rhs.m_opaque_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202}
203
204bool
205SBCompileUnit::operator != (const SBCompileUnit &rhs) const
206{
Greg Clayton66111032010-06-23 01:19:29 +0000207 return m_opaque_ptr != rhs.m_opaque_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208}
209
210const lldb_private::CompileUnit *
211SBCompileUnit::operator->() const
212{
Greg Clayton66111032010-06-23 01:19:29 +0000213 return m_opaque_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214}
215
216const lldb_private::CompileUnit &
217SBCompileUnit::operator*() const
218{
Greg Clayton66111032010-06-23 01:19:29 +0000219 return *m_opaque_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000220}
Caroline Ticedde9cff2010-09-20 05:20:02 +0000221
Greg Clayton8f7180b2011-09-26 07:11:27 +0000222lldb_private::CompileUnit *
223SBCompileUnit::get ()
Caroline Tice750cd172010-10-26 23:49:36 +0000224{
225 return m_opaque_ptr;
226}
Greg Clayton72eff182010-12-14 04:58:53 +0000227
228void
229SBCompileUnit::reset (lldb_private::CompileUnit *lldb_object_ptr)
230{
231 m_opaque_ptr = lldb_object_ptr;
232}
233
Caroline Tice750cd172010-10-26 23:49:36 +0000234
Caroline Ticedde9cff2010-09-20 05:20:02 +0000235bool
236SBCompileUnit::GetDescription (SBStream &description)
237{
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000238 Stream &strm = description.ref();
239
Caroline Ticedde9cff2010-09-20 05:20:02 +0000240 if (m_opaque_ptr)
Caroline Tice201a8852010-09-20 16:21:41 +0000241 {
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000242 m_opaque_ptr->Dump (&strm, false);
Caroline Tice201a8852010-09-20 16:21:41 +0000243 }
Caroline Ticedde9cff2010-09-20 05:20:02 +0000244 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +0000245 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +0000246
247 return true;
248}