blob: 55e691bb583729883c16c737b8ef9ea3a8383075 [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"
17#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 {
54 SBStream sstr;
55 file_spec.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +000056 log->Printf ("SBModule(%p)::GetFileSpec () => SBFileSpec(%p): %s", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +000057 file_spec.get(), sstr.GetData());
Caroline Tice7826c882010-10-26 03:11:13 +000058 }
59
Chris Lattner24943d22010-06-08 16:52:24 +000060 return file_spec;
61}
62
63const uint8_t *
64SBModule::GetUUIDBytes () const
65{
Caroline Tice7826c882010-10-26 03:11:13 +000066 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
67
Greg Claytona66ba462010-10-30 04:51:46 +000068 const uint8_t *uuid_bytes = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +000069 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +000070 uuid_bytes = (const uint8_t *)m_opaque_sp->GetUUID().GetBytes();
Caroline Tice7826c882010-10-26 03:11:13 +000071
72 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +000073 {
74 if (uuid_bytes)
75 {
76 StreamString s;
77 m_opaque_sp->GetUUID().Dump (&s);
78 log->Printf ("SBModule(%p)::GetUUIDBytes () => %s", m_opaque_sp.get(), s.GetData());
79 }
80 else
81 log->Printf ("SBModule(%p)::GetUUIDBytes () => NULL", m_opaque_sp.get());
82 }
83 return uuid_bytes;
Chris Lattner24943d22010-06-08 16:52:24 +000084}
85
86
87bool
88SBModule::operator == (const SBModule &rhs) const
89{
Greg Clayton63094e02010-06-23 01:19:29 +000090 if (m_opaque_sp)
91 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +000092 return false;
93}
94
95bool
96SBModule::operator != (const SBModule &rhs) const
97{
Greg Clayton63094e02010-06-23 01:19:29 +000098 if (m_opaque_sp)
99 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000100 return false;
101}
102
103lldb::ModuleSP &
104SBModule::operator *()
105{
Greg Clayton63094e02010-06-23 01:19:29 +0000106 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000107}
108
109lldb_private::Module *
110SBModule::operator ->()
111{
Greg Clayton63094e02010-06-23 01:19:29 +0000112 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000113}
114
115const lldb_private::Module *
116SBModule::operator ->() const
117{
Greg Clayton63094e02010-06-23 01:19:29 +0000118 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000119}
120
121lldb_private::Module *
122SBModule::get()
123{
Greg Clayton63094e02010-06-23 01:19:29 +0000124 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000125}
126
127const lldb_private::Module *
128SBModule::get() const
129{
Greg Clayton63094e02010-06-23 01:19:29 +0000130 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000131}
132
133
134void
135SBModule::SetModule (const lldb::ModuleSP& module_sp)
136{
Greg Clayton63094e02010-06-23 01:19:29 +0000137 m_opaque_sp = module_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000138}
139
Greg Clayton466f6c42010-09-10 18:31:35 +0000140
141bool
142SBModule::ResolveFileAddress (lldb::addr_t vm_addr, SBAddress& addr)
143{
144 if (m_opaque_sp)
145 return m_opaque_sp->ResolveFileAddress (vm_addr, *addr);
146
147 addr->Clear();
148 return false;
149}
150
151SBSymbolContext
152SBModule::ResolveSymbolContextForAddress (const SBAddress& addr, uint32_t resolve_scope)
153{
154 SBSymbolContext sb_sc;
155 if (m_opaque_sp && addr.IsValid())
156 m_opaque_sp->ResolveSymbolContextForAddress (*addr, resolve_scope, *sb_sc);
157 return sb_sc;
158}
159
Caroline Tice98f930f2010-09-20 05:20:02 +0000160bool
161SBModule::GetDescription (SBStream &description)
162{
163 if (m_opaque_sp)
164 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000165 description.ref();
Caroline Tice7826c882010-10-26 03:11:13 +0000166 m_opaque_sp->GetDescription (description.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000167 }
168 else
169 description.Printf ("No value");
170
171 return true;
172}