blob: c6c2d751183c0963e5cb85cf115bfb5933d6ece4 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBModule.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/SBModule.h"
Greg Clayton466f6c42010-09-10 18:31:35 +000011#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBFileSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013#include "lldb/API/SBFileSpec.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000014#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/Module.h"
Caroline Tice7826c882010-10-26 03:11:13 +000016#include "lldb/Core/Log.h"
Greg Clayton135adf22010-10-31 19:57:43 +000017#include "lldb/Core/StreamString.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018
19using namespace lldb;
Caroline Tice7826c882010-10-26 03:11:13 +000020using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000021
22
23SBModule::SBModule () :
Greg Clayton63094e02010-06-23 01:19:29 +000024 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000025{
26}
27
28SBModule::SBModule (const lldb::ModuleSP& module_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000029 m_opaque_sp (module_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000030{
31}
32
33SBModule::~SBModule ()
34{
35}
36
37bool
38SBModule::IsValid () const
39{
Greg Clayton63094e02010-06-23 01:19:29 +000040 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000041}
42
43SBFileSpec
44SBModule::GetFileSpec () const
45{
Caroline Tice7826c882010-10-26 03:11:13 +000046 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
47
Chris Lattner24943d22010-06-08 16:52:24 +000048 SBFileSpec file_spec;
Greg Clayton63094e02010-06-23 01:19:29 +000049 if (m_opaque_sp)
50 file_spec.SetFileSpec(m_opaque_sp->GetFileSpec());
Caroline Tice7826c882010-10-26 03:11:13 +000051
52 if (log)
53 {
Greg Clayton49ce6822010-10-31 03:01:06 +000054 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
55 m_opaque_sp.get(), file_spec.get());
Caroline Tice7826c882010-10-26 03:11:13 +000056 }
57
Chris Lattner24943d22010-06-08 16:52:24 +000058 return file_spec;
59}
60
61const uint8_t *
62SBModule::GetUUIDBytes () const
63{
Caroline Tice7826c882010-10-26 03:11:13 +000064 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
65
Greg Claytona66ba462010-10-30 04:51:46 +000066 const uint8_t *uuid_bytes = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +000067 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +000068 uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes();
Caroline Tice7826c882010-10-26 03:11:13 +000069
70 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +000071 {
72 if (uuid_bytes)
73 {
74 StreamString s;
75 m_opaque_sp->GetUUID().Dump (&s);
76 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData());
77 }
78 else
79 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get());
80 }
81 return uuid_bytes;
Chris Lattner24943d22010-06-08 16:52:24 +000082}
83
84
85bool
86SBModule::operator == (const SBModule &rhs) const
87{
Greg Clayton63094e02010-06-23 01:19:29 +000088 if (m_opaque_sp)
89 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +000090 return false;
91}
92
93bool
94SBModule::operator != (const SBModule &rhs) const
95{
Greg Clayton63094e02010-06-23 01:19:29 +000096 if (m_opaque_sp)
97 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +000098 return false;
99}
100
101lldb::ModuleSP &
102SBModule::operator *()
103{
Greg Clayton63094e02010-06-23 01:19:29 +0000104 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000105}
106
107lldb_private::Module *
108SBModule::operator ->()
109{
Greg Clayton63094e02010-06-23 01:19:29 +0000110 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000111}
112
113const lldb_private::Module *
114SBModule::operator ->() const
115{
Greg Clayton63094e02010-06-23 01:19:29 +0000116 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000117}
118
119lldb_private::Module *
120SBModule::get()
121{
Greg Clayton63094e02010-06-23 01:19:29 +0000122 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000123}
124
125const lldb_private::Module *
126SBModule::get() const
127{
Greg Clayton63094e02010-06-23 01:19:29 +0000128 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000129}
130
131
132void
133SBModule::SetModule (const lldb::ModuleSP& module_sp)
134{
Greg Clayton63094e02010-06-23 01:19:29 +0000135 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000136}
137
Greg Clayton466f6c42010-09-10 18:31:35 +0000138
139bool
140SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr)
141{
142 if (m_opaque_sp)
143 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr);
144
145 addr->Clear();
146 return false;
147}
148
149SBSymbolContext
150SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
151{
152 SBSymbolContext sb_sc;
153 if (m_opaque_sp && addr.IsValid())
154 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc);
155 return sb_sc;
156}
157
Caroline Tice98f930f2010-09-20 05:20:02 +0000158bool
159SBModule::GetDescription (SBStream &description)
160{
161 if (m_opaque_sp)
162 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000163 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000164 m_opaque_sp->GetDescription (description.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000165 }
166 else
167 description.Printf ("No value");
168
169 return true;
170}