blob: d85e403a2efd9c05497f042623c08ad68da9aa86 [file] [log] [blame]
Chris Lattner24943d22010-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 Tice98f930f2010-09-20 05:20:02 +000012#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013#include "lldb/Symbol/CompileUnit.h"
14#include "lldb/Symbol/LineEntry.h"
15#include "lldb/Symbol/LineTable.h"
Caroline Tice7826c882010-10-26 03:11:13 +000016#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017
18using namespace lldb;
19using namespace lldb_private;
20
21
22SBCompileUnit::SBCompileUnit () :
Greg Clayton63094e02010-06-23 01:19:29 +000023 m_opaque_ptr (NULL)
Chris Lattner24943d22010-06-08 16:52:24 +000024{
Caroline Tice7826c882010-10-26 03:11:13 +000025 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
26
27 if (log)
28 log->Printf ("SBCompileUnit::SBCompileUnit () ==> this = %p", this);
Chris Lattner24943d22010-06-08 16:52:24 +000029}
30
31SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000032 m_opaque_ptr (lldb_object_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +000033{
Caroline Tice7826c882010-10-26 03:11:13 +000034 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
35
36 if (log)
37 {
38 SBStream sstr;
39 GetDescription (sstr);
40 log->Printf ("SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) lldb_object_ptr = %p"
41 " this = %p (%s)", lldb_object_ptr, this, sstr.GetData());
42 }
Chris Lattner24943d22010-06-08 16:52:24 +000043}
44
45SBCompileUnit::~SBCompileUnit ()
46{
Greg Clayton63094e02010-06-23 01:19:29 +000047 m_opaque_ptr = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000048}
49
50SBFileSpec
51SBCompileUnit::GetFileSpec () const
52{
53 SBFileSpec file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +000054 if (m_opaque_ptr)
55 file_spec.SetFileSpec(*m_opaque_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +000056 return file_spec;
57}
58
59uint32_t
60SBCompileUnit::GetNumLineEntries () const
61{
Greg Clayton63094e02010-06-23 01:19:29 +000062 if (m_opaque_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +000063 {
Greg Clayton63094e02010-06-23 01:19:29 +000064 LineTable *line_table = m_opaque_ptr->GetLineTable ();
Chris Lattner24943d22010-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{
Caroline Tice7826c882010-10-26 03:11:13 +000074 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
75
76 if (log)
77 log->Printf ("SBCompileUnit::GetLineEntryAtIndex (%d)", idx);
78
Chris Lattner24943d22010-06-08 16:52:24 +000079 SBLineEntry sb_line_entry;
Greg Clayton63094e02010-06-23 01:19:29 +000080 if (m_opaque_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +000081 {
Greg Clayton63094e02010-06-23 01:19:29 +000082 LineTable *line_table = m_opaque_ptr->GetLineTable ();
Chris Lattner24943d22010-06-08 16:52:24 +000083 if (line_table)
84 {
85 LineEntry line_entry;
86 if (line_table->GetLineEntryAtIndex(idx, line_entry))
87 sb_line_entry.SetLineEntry(line_entry);
88 }
89 }
Caroline Tice7826c882010-10-26 03:11:13 +000090
91 if (log)
92 {
93 SBStream sstr;
94 sb_line_entry.GetDescription (sstr);
95 log->Printf ("SBCompileUnit::GetLineEntryAtIndex ==> %s", sstr.GetData());
96 }
97
Chris Lattner24943d22010-06-08 16:52:24 +000098 return sb_line_entry;
99}
100
101uint32_t
102SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec) const
103{
Caroline Tice7826c882010-10-26 03:11:13 +0000104 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
105
106 if (log)
107 {
108 SBStream sstr;
109 inline_file_spec->GetDescription (sstr);
110 log->Printf ("SBCompileUnit::FindLineEntryIndex (%d, %d, %s)", start_idx, line, sstr.GetData());
111 }
112
Greg Clayton63094e02010-06-23 01:19:29 +0000113 if (m_opaque_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +0000114 {
115 FileSpec file_spec;
116 if (inline_file_spec && inline_file_spec->IsValid())
117 file_spec = inline_file_spec->ref();
118 else
Greg Clayton63094e02010-06-23 01:19:29 +0000119 file_spec = *m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +0000120
Caroline Tice7826c882010-10-26 03:11:13 +0000121
122 uint32_t ret_value = m_opaque_ptr->FindLineEntry (start_idx,
123 line,
124 inline_file_spec ? inline_file_spec->get() : NULL,
125 NULL);
126 if (log)
127 log->Printf ("SBCompileUnit::FindLineEntryIndex ==> %d", ret_value);
128
129 return ret_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000130 }
Caroline Tice7826c882010-10-26 03:11:13 +0000131
132 if (log)
133 log->Printf ("SBCompileUnit::FindLineEntryIndex ==> %d", UINT32_MAX);
134
Chris Lattner24943d22010-06-08 16:52:24 +0000135 return UINT32_MAX;
136}
137
138bool
139SBCompileUnit::IsValid () const
140{
Greg Clayton63094e02010-06-23 01:19:29 +0000141 return m_opaque_ptr != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000142}
143
144bool
145SBCompileUnit::operator == (const SBCompileUnit &rhs) const
146{
Greg Clayton63094e02010-06-23 01:19:29 +0000147 return m_opaque_ptr == rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +0000148}
149
150bool
151SBCompileUnit::operator != (const SBCompileUnit &rhs) const
152{
Greg Clayton63094e02010-06-23 01:19:29 +0000153 return m_opaque_ptr != rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +0000154}
155
156const lldb_private::CompileUnit *
157SBCompileUnit::operator->() const
158{
Greg Clayton63094e02010-06-23 01:19:29 +0000159 return m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +0000160}
161
162const lldb_private::CompileUnit &
163SBCompileUnit::operator*() const
164{
Greg Clayton63094e02010-06-23 01:19:29 +0000165 return *m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +0000166}
Caroline Tice98f930f2010-09-20 05:20:02 +0000167
168bool
169SBCompileUnit::GetDescription (SBStream &description)
170{
171 if (m_opaque_ptr)
Caroline Ticee7a566e2010-09-20 16:21:41 +0000172 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000173 description.ref();
Caroline Tice98f930f2010-09-20 05:20:02 +0000174 m_opaque_ptr->Dump (description.get(), false);
Caroline Ticee7a566e2010-09-20 16:21:41 +0000175 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000176 else
Caroline Ticee7a566e2010-09-20 16:21:41 +0000177 description.Printf ("No Value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000178
179 return true;
180}