1ac7ddfbfSEd Maste //===-- SBModule.cpp --------------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "lldb/API/SBModule.h"
11ac7ddfbfSEd Maste #include "lldb/API/SBAddress.h"
12ac7ddfbfSEd Maste #include "lldb/API/SBFileSpec.h"
13ac7ddfbfSEd Maste #include "lldb/API/SBModuleSpec.h"
14ac7ddfbfSEd Maste #include "lldb/API/SBProcess.h"
15ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
16ac7ddfbfSEd Maste #include "lldb/API/SBSymbolContextList.h"
17435933ddSDimitry Andric #include "lldb/Core/Module.h"
18ac7ddfbfSEd Maste #include "lldb/Core/Section.h"
19ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectList.h"
20ac7ddfbfSEd Maste #include "lldb/Core/ValueObjectVariable.h"
21ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectFile.h"
224bb0738eSEd Maste #include "lldb/Symbol/SymbolFile.h"
23ac7ddfbfSEd Maste #include "lldb/Symbol/SymbolVendor.h"
24ac7ddfbfSEd Maste #include "lldb/Symbol/Symtab.h"
259f2f44ceSEd Maste #include "lldb/Symbol/TypeSystem.h"
26ac7ddfbfSEd Maste #include "lldb/Symbol/VariableList.h"
27ac7ddfbfSEd Maste #include "lldb/Target/Target.h"
28f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
29f678e45dSDimitry Andric #include "lldb/Utility/StreamString.h"
30ac7ddfbfSEd Maste
31ac7ddfbfSEd Maste using namespace lldb;
32ac7ddfbfSEd Maste using namespace lldb_private;
33ac7ddfbfSEd Maste
SBModule()34435933ddSDimitry Andric SBModule::SBModule() : m_opaque_sp() {}
35ac7ddfbfSEd Maste
SBModule(const lldb::ModuleSP & module_sp)36435933ddSDimitry Andric SBModule::SBModule(const lldb::ModuleSP &module_sp) : m_opaque_sp(module_sp) {}
37ac7ddfbfSEd Maste
SBModule(const SBModuleSpec & module_spec)38435933ddSDimitry Andric SBModule::SBModule(const SBModuleSpec &module_spec) : m_opaque_sp() {
39ac7ddfbfSEd Maste ModuleSP module_sp;
405517e702SDimitry Andric Status error = ModuleList::GetSharedModule(*module_spec.m_opaque_ap,
415517e702SDimitry Andric module_sp, NULL, NULL, NULL);
42ac7ddfbfSEd Maste if (module_sp)
43ac7ddfbfSEd Maste SetSP(module_sp);
44ac7ddfbfSEd Maste }
45ac7ddfbfSEd Maste
SBModule(const SBModule & rhs)46435933ddSDimitry Andric SBModule::SBModule(const SBModule &rhs) : m_opaque_sp(rhs.m_opaque_sp) {}
47ac7ddfbfSEd Maste
SBModule(lldb::SBProcess & process,lldb::addr_t header_addr)48435933ddSDimitry Andric SBModule::SBModule(lldb::SBProcess &process, lldb::addr_t header_addr)
49435933ddSDimitry Andric : m_opaque_sp() {
50ac7ddfbfSEd Maste ProcessSP process_sp(process.GetSP());
51435933ddSDimitry Andric if (process_sp) {
52ac7ddfbfSEd Maste m_opaque_sp = process_sp->ReadModuleFromMemory(FileSpec(), header_addr);
53435933ddSDimitry Andric if (m_opaque_sp) {
54ac7ddfbfSEd Maste Target &target = process_sp->GetTarget();
55ac7ddfbfSEd Maste bool changed = false;
5612b93ac6SEd Maste m_opaque_sp->SetLoadAddress(target, 0, true, changed);
57ac7ddfbfSEd Maste target.GetImages().Append(m_opaque_sp);
58ac7ddfbfSEd Maste }
59ac7ddfbfSEd Maste }
60ac7ddfbfSEd Maste }
61ac7ddfbfSEd Maste
operator =(const SBModule & rhs)62435933ddSDimitry Andric const SBModule &SBModule::operator=(const SBModule &rhs) {
63ac7ddfbfSEd Maste if (this != &rhs)
64ac7ddfbfSEd Maste m_opaque_sp = rhs.m_opaque_sp;
65ac7ddfbfSEd Maste return *this;
66ac7ddfbfSEd Maste }
67ac7ddfbfSEd Maste
~SBModule()68435933ddSDimitry Andric SBModule::~SBModule() {}
69ac7ddfbfSEd Maste
IsValid() const70435933ddSDimitry Andric bool SBModule::IsValid() const { return m_opaque_sp.get() != NULL; }
71ac7ddfbfSEd Maste
Clear()72435933ddSDimitry Andric void SBModule::Clear() { m_opaque_sp.reset(); }
73ac7ddfbfSEd Maste
GetFileSpec() const74435933ddSDimitry Andric SBFileSpec SBModule::GetFileSpec() const {
75ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
76ac7ddfbfSEd Maste
77ac7ddfbfSEd Maste SBFileSpec file_spec;
78ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
79ac7ddfbfSEd Maste if (module_sp)
80ac7ddfbfSEd Maste file_spec.SetFileSpec(module_sp->GetFileSpec());
81ac7ddfbfSEd Maste
82ac7ddfbfSEd Maste if (log)
83ac7ddfbfSEd Maste log->Printf("SBModule(%p)::GetFileSpec () => SBFileSpec(%p)",
840127ef0fSEd Maste static_cast<void *>(module_sp.get()),
850127ef0fSEd Maste static_cast<const void *>(file_spec.get()));
86ac7ddfbfSEd Maste
87ac7ddfbfSEd Maste return file_spec;
88ac7ddfbfSEd Maste }
89ac7ddfbfSEd Maste
GetPlatformFileSpec() const90435933ddSDimitry Andric lldb::SBFileSpec SBModule::GetPlatformFileSpec() const {
91ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
92ac7ddfbfSEd Maste
93ac7ddfbfSEd Maste SBFileSpec file_spec;
94ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
95ac7ddfbfSEd Maste if (module_sp)
96ac7ddfbfSEd Maste file_spec.SetFileSpec(module_sp->GetPlatformFileSpec());
97ac7ddfbfSEd Maste
98ac7ddfbfSEd Maste if (log)
99ac7ddfbfSEd Maste log->Printf("SBModule(%p)::GetPlatformFileSpec () => SBFileSpec(%p)",
1000127ef0fSEd Maste static_cast<void *>(module_sp.get()),
1010127ef0fSEd Maste static_cast<const void *>(file_spec.get()));
102ac7ddfbfSEd Maste
103ac7ddfbfSEd Maste return file_spec;
104ac7ddfbfSEd Maste }
105ac7ddfbfSEd Maste
SetPlatformFileSpec(const lldb::SBFileSpec & platform_file)106435933ddSDimitry Andric bool SBModule::SetPlatformFileSpec(const lldb::SBFileSpec &platform_file) {
107ac7ddfbfSEd Maste bool result = false;
108ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
109ac7ddfbfSEd Maste
110ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
111435933ddSDimitry Andric if (module_sp) {
112ac7ddfbfSEd Maste module_sp->SetPlatformFileSpec(*platform_file);
113ac7ddfbfSEd Maste result = true;
114ac7ddfbfSEd Maste }
115ac7ddfbfSEd Maste
116ac7ddfbfSEd Maste if (log)
117ac7ddfbfSEd Maste log->Printf("SBModule(%p)::SetPlatformFileSpec (SBFileSpec(%p (%s)) => %i",
1180127ef0fSEd Maste static_cast<void *>(module_sp.get()),
1190127ef0fSEd Maste static_cast<const void *>(platform_file.get()),
1200127ef0fSEd Maste platform_file->GetPath().c_str(), result);
121ac7ddfbfSEd Maste return result;
122ac7ddfbfSEd Maste }
123ac7ddfbfSEd Maste
GetRemoteInstallFileSpec()124435933ddSDimitry Andric lldb::SBFileSpec SBModule::GetRemoteInstallFileSpec() {
125b952cd58SEd Maste SBFileSpec sb_file_spec;
126b952cd58SEd Maste ModuleSP module_sp(GetSP());
127b952cd58SEd Maste if (module_sp)
128b952cd58SEd Maste sb_file_spec.SetFileSpec(module_sp->GetRemoteInstallFileSpec());
129b952cd58SEd Maste return sb_file_spec;
130b952cd58SEd Maste }
131b952cd58SEd Maste
SetRemoteInstallFileSpec(lldb::SBFileSpec & file)132435933ddSDimitry Andric bool SBModule::SetRemoteInstallFileSpec(lldb::SBFileSpec &file) {
133b952cd58SEd Maste ModuleSP module_sp(GetSP());
134435933ddSDimitry Andric if (module_sp) {
135b952cd58SEd Maste module_sp->SetRemoteInstallFileSpec(file.ref());
136b952cd58SEd Maste return true;
137b952cd58SEd Maste }
138b952cd58SEd Maste return false;
139b952cd58SEd Maste }
140ac7ddfbfSEd Maste
GetUUIDBytes() const141435933ddSDimitry Andric const uint8_t *SBModule::GetUUIDBytes() const {
142ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
143ac7ddfbfSEd Maste
144ac7ddfbfSEd Maste const uint8_t *uuid_bytes = NULL;
145ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
146ac7ddfbfSEd Maste if (module_sp)
1474ba319b5SDimitry Andric uuid_bytes = module_sp->GetUUID().GetBytes().data();
148ac7ddfbfSEd Maste
149435933ddSDimitry Andric if (log) {
150435933ddSDimitry Andric if (uuid_bytes) {
151ac7ddfbfSEd Maste StreamString s;
152ac7ddfbfSEd Maste module_sp->GetUUID().Dump(&s);
1530127ef0fSEd Maste log->Printf("SBModule(%p)::GetUUIDBytes () => %s",
1540127ef0fSEd Maste static_cast<void *>(module_sp.get()), s.GetData());
155435933ddSDimitry Andric } else
1560127ef0fSEd Maste log->Printf("SBModule(%p)::GetUUIDBytes () => NULL",
1570127ef0fSEd Maste static_cast<void *>(module_sp.get()));
158ac7ddfbfSEd Maste }
159ac7ddfbfSEd Maste return uuid_bytes;
160ac7ddfbfSEd Maste }
161ac7ddfbfSEd Maste
GetUUIDString() const162435933ddSDimitry Andric const char *SBModule::GetUUIDString() const {
163ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
164ac7ddfbfSEd Maste
1651c3bbb01SEd Maste const char *uuid_cstr = NULL;
166ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
167435933ddSDimitry Andric if (module_sp) {
1684ba319b5SDimitry Andric // We are going to return a "const char *" value through the public API, so
1694ba319b5SDimitry Andric // we need to constify it so it gets added permanently the string pool and
1704ba319b5SDimitry Andric // then we don't need to worry about the lifetime of the string as it will
1714ba319b5SDimitry Andric // never go away once it has been put into the ConstString string pool
1721c3bbb01SEd Maste uuid_cstr = ConstString(module_sp->GetUUID().GetAsString()).GetCString();
1731c3bbb01SEd Maste }
1741c3bbb01SEd Maste
175435933ddSDimitry Andric if (uuid_cstr && uuid_cstr[0]) {
1761c3bbb01SEd Maste if (log)
177435933ddSDimitry Andric log->Printf("SBModule(%p)::GetUUIDString () => %s",
178435933ddSDimitry Andric static_cast<void *>(module_sp.get()), uuid_cstr);
1791c3bbb01SEd Maste return uuid_cstr;
180ac7ddfbfSEd Maste }
181ac7ddfbfSEd Maste
182ac7ddfbfSEd Maste if (log)
183435933ddSDimitry Andric log->Printf("SBModule(%p)::GetUUIDString () => NULL",
184435933ddSDimitry Andric static_cast<void *>(module_sp.get()));
1851c3bbb01SEd Maste return NULL;
186ac7ddfbfSEd Maste }
187ac7ddfbfSEd Maste
operator ==(const SBModule & rhs) const188435933ddSDimitry Andric bool SBModule::operator==(const SBModule &rhs) const {
189ac7ddfbfSEd Maste if (m_opaque_sp)
190ac7ddfbfSEd Maste return m_opaque_sp.get() == rhs.m_opaque_sp.get();
191ac7ddfbfSEd Maste return false;
192ac7ddfbfSEd Maste }
193ac7ddfbfSEd Maste
operator !=(const SBModule & rhs) const194435933ddSDimitry Andric bool SBModule::operator!=(const SBModule &rhs) const {
195ac7ddfbfSEd Maste if (m_opaque_sp)
196ac7ddfbfSEd Maste return m_opaque_sp.get() != rhs.m_opaque_sp.get();
197ac7ddfbfSEd Maste return false;
198ac7ddfbfSEd Maste }
199ac7ddfbfSEd Maste
GetSP() const200435933ddSDimitry Andric ModuleSP SBModule::GetSP() const { return m_opaque_sp; }
201ac7ddfbfSEd Maste
SetSP(const ModuleSP & module_sp)202435933ddSDimitry Andric void SBModule::SetSP(const ModuleSP &module_sp) { m_opaque_sp = module_sp; }
203ac7ddfbfSEd Maste
ResolveFileAddress(lldb::addr_t vm_addr)204435933ddSDimitry Andric SBAddress SBModule::ResolveFileAddress(lldb::addr_t vm_addr) {
205ac7ddfbfSEd Maste lldb::SBAddress sb_addr;
206ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
207435933ddSDimitry Andric if (module_sp) {
208ac7ddfbfSEd Maste Address addr;
209ac7ddfbfSEd Maste if (module_sp->ResolveFileAddress(vm_addr, addr))
210ac7ddfbfSEd Maste sb_addr.ref() = addr;
211ac7ddfbfSEd Maste }
212ac7ddfbfSEd Maste return sb_addr;
213ac7ddfbfSEd Maste }
214ac7ddfbfSEd Maste
215ac7ddfbfSEd Maste SBSymbolContext
ResolveSymbolContextForAddress(const SBAddress & addr,uint32_t resolve_scope)216435933ddSDimitry Andric SBModule::ResolveSymbolContextForAddress(const SBAddress &addr,
217435933ddSDimitry Andric uint32_t resolve_scope) {
218ac7ddfbfSEd Maste SBSymbolContext sb_sc;
219ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
220*b5893f02SDimitry Andric SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
221ac7ddfbfSEd Maste if (module_sp && addr.IsValid())
222*b5893f02SDimitry Andric module_sp->ResolveSymbolContextForAddress(addr.ref(), scope, *sb_sc);
223ac7ddfbfSEd Maste return sb_sc;
224ac7ddfbfSEd Maste }
225ac7ddfbfSEd Maste
GetDescription(SBStream & description)226435933ddSDimitry Andric bool SBModule::GetDescription(SBStream &description) {
227ac7ddfbfSEd Maste Stream &strm = description.ref();
228ac7ddfbfSEd Maste
229ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
230435933ddSDimitry Andric if (module_sp) {
231ac7ddfbfSEd Maste module_sp->GetDescription(&strm);
232435933ddSDimitry Andric } else
233ac7ddfbfSEd Maste strm.PutCString("No value");
234ac7ddfbfSEd Maste
235ac7ddfbfSEd Maste return true;
236ac7ddfbfSEd Maste }
237ac7ddfbfSEd Maste
GetNumCompileUnits()238435933ddSDimitry Andric uint32_t SBModule::GetNumCompileUnits() {
239ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
240435933ddSDimitry Andric if (module_sp) {
241ac7ddfbfSEd Maste return module_sp->GetNumCompileUnits();
242ac7ddfbfSEd Maste }
243ac7ddfbfSEd Maste return 0;
244ac7ddfbfSEd Maste }
245ac7ddfbfSEd Maste
GetCompileUnitAtIndex(uint32_t index)246435933ddSDimitry Andric SBCompileUnit SBModule::GetCompileUnitAtIndex(uint32_t index) {
247ac7ddfbfSEd Maste SBCompileUnit sb_cu;
248ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
249435933ddSDimitry Andric if (module_sp) {
250ac7ddfbfSEd Maste CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(index);
251ac7ddfbfSEd Maste sb_cu.reset(cu_sp.get());
252ac7ddfbfSEd Maste }
253ac7ddfbfSEd Maste return sb_cu;
254ac7ddfbfSEd Maste }
255ac7ddfbfSEd Maste
2564ba319b5SDimitry Andric SBSymbolContextList
FindCompileUnits(const SBFileSpec & sb_file_spec)2574ba319b5SDimitry Andric SBModule::FindCompileUnits(const SBFileSpec &sb_file_spec) {
2584ba319b5SDimitry Andric SBSymbolContextList sb_sc_list;
2594ba319b5SDimitry Andric const ModuleSP module_sp(GetSP());
2604ba319b5SDimitry Andric if (sb_file_spec.IsValid() && module_sp) {
2614ba319b5SDimitry Andric const bool append = true;
2624ba319b5SDimitry Andric module_sp->FindCompileUnits(*sb_file_spec, append, *sb_sc_list);
2634ba319b5SDimitry Andric }
2644ba319b5SDimitry Andric return sb_sc_list;
2654ba319b5SDimitry Andric }
2664ba319b5SDimitry Andric
GetUnifiedSymbolTable(const lldb::ModuleSP & module_sp)267435933ddSDimitry Andric static Symtab *GetUnifiedSymbolTable(const lldb::ModuleSP &module_sp) {
268435933ddSDimitry Andric if (module_sp) {
269ac7ddfbfSEd Maste SymbolVendor *symbols = module_sp->GetSymbolVendor();
270ac7ddfbfSEd Maste if (symbols)
271ac7ddfbfSEd Maste return symbols->GetSymtab();
272ac7ddfbfSEd Maste }
273ac7ddfbfSEd Maste return NULL;
274ac7ddfbfSEd Maste }
275ac7ddfbfSEd Maste
GetNumSymbols()276435933ddSDimitry Andric size_t SBModule::GetNumSymbols() {
277ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
278435933ddSDimitry Andric if (module_sp) {
279ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable(module_sp);
280ac7ddfbfSEd Maste if (symtab)
281ac7ddfbfSEd Maste return symtab->GetNumSymbols();
282ac7ddfbfSEd Maste }
283ac7ddfbfSEd Maste return 0;
284ac7ddfbfSEd Maste }
285ac7ddfbfSEd Maste
GetSymbolAtIndex(size_t idx)286435933ddSDimitry Andric SBSymbol SBModule::GetSymbolAtIndex(size_t idx) {
287ac7ddfbfSEd Maste SBSymbol sb_symbol;
288ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
289ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable(module_sp);
290ac7ddfbfSEd Maste if (symtab)
291ac7ddfbfSEd Maste sb_symbol.SetSymbol(symtab->SymbolAtIndex(idx));
292ac7ddfbfSEd Maste return sb_symbol;
293ac7ddfbfSEd Maste }
294ac7ddfbfSEd Maste
FindSymbol(const char * name,lldb::SymbolType symbol_type)295435933ddSDimitry Andric lldb::SBSymbol SBModule::FindSymbol(const char *name,
296435933ddSDimitry Andric lldb::SymbolType symbol_type) {
297ac7ddfbfSEd Maste SBSymbol sb_symbol;
298435933ddSDimitry Andric if (name && name[0]) {
299ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
300ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable(module_sp);
301ac7ddfbfSEd Maste if (symtab)
302435933ddSDimitry Andric sb_symbol.SetSymbol(symtab->FindFirstSymbolWithNameAndType(
303435933ddSDimitry Andric ConstString(name), symbol_type, Symtab::eDebugAny,
304435933ddSDimitry Andric Symtab::eVisibilityAny));
305ac7ddfbfSEd Maste }
306ac7ddfbfSEd Maste return sb_symbol;
307ac7ddfbfSEd Maste }
308ac7ddfbfSEd Maste
FindSymbols(const char * name,lldb::SymbolType symbol_type)309435933ddSDimitry Andric lldb::SBSymbolContextList SBModule::FindSymbols(const char *name,
310435933ddSDimitry Andric lldb::SymbolType symbol_type) {
311ac7ddfbfSEd Maste SBSymbolContextList sb_sc_list;
312435933ddSDimitry Andric if (name && name[0]) {
313ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
314ac7ddfbfSEd Maste Symtab *symtab = GetUnifiedSymbolTable(module_sp);
315435933ddSDimitry Andric if (symtab) {
316ac7ddfbfSEd Maste std::vector<uint32_t> matching_symbol_indexes;
317435933ddSDimitry Andric const size_t num_matches = symtab->FindAllSymbolsWithNameAndType(
318435933ddSDimitry Andric ConstString(name), symbol_type, matching_symbol_indexes);
319435933ddSDimitry Andric if (num_matches) {
320ac7ddfbfSEd Maste SymbolContext sc;
321ac7ddfbfSEd Maste sc.module_sp = module_sp;
322ac7ddfbfSEd Maste SymbolContextList &sc_list = *sb_sc_list;
323435933ddSDimitry Andric for (size_t i = 0; i < num_matches; ++i) {
324ac7ddfbfSEd Maste sc.symbol = symtab->SymbolAtIndex(matching_symbol_indexes[i]);
325ac7ddfbfSEd Maste if (sc.symbol)
326ac7ddfbfSEd Maste sc_list.Append(sc);
327ac7ddfbfSEd Maste }
328ac7ddfbfSEd Maste }
329ac7ddfbfSEd Maste }
330ac7ddfbfSEd Maste }
331ac7ddfbfSEd Maste return sb_sc_list;
332ac7ddfbfSEd Maste }
333ac7ddfbfSEd Maste
GetNumSections()334435933ddSDimitry Andric size_t SBModule::GetNumSections() {
335ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
336435933ddSDimitry Andric if (module_sp) {
337ac7ddfbfSEd Maste // Give the symbol vendor a chance to add to the unified section list.
338ac7ddfbfSEd Maste module_sp->GetSymbolVendor();
339ac7ddfbfSEd Maste SectionList *section_list = module_sp->GetSectionList();
340ac7ddfbfSEd Maste if (section_list)
341ac7ddfbfSEd Maste return section_list->GetSize();
342ac7ddfbfSEd Maste }
343ac7ddfbfSEd Maste return 0;
344ac7ddfbfSEd Maste }
345ac7ddfbfSEd Maste
GetSectionAtIndex(size_t idx)346435933ddSDimitry Andric SBSection SBModule::GetSectionAtIndex(size_t idx) {
347ac7ddfbfSEd Maste SBSection sb_section;
348ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
349435933ddSDimitry Andric if (module_sp) {
350ac7ddfbfSEd Maste // Give the symbol vendor a chance to add to the unified section list.
351ac7ddfbfSEd Maste module_sp->GetSymbolVendor();
352ac7ddfbfSEd Maste SectionList *section_list = module_sp->GetSectionList();
353ac7ddfbfSEd Maste
354ac7ddfbfSEd Maste if (section_list)
355ac7ddfbfSEd Maste sb_section.SetSP(section_list->GetSectionAtIndex(idx));
356ac7ddfbfSEd Maste }
357ac7ddfbfSEd Maste return sb_section;
358ac7ddfbfSEd Maste }
359ac7ddfbfSEd Maste
FindFunctions(const char * name,uint32_t name_type_mask)360435933ddSDimitry Andric lldb::SBSymbolContextList SBModule::FindFunctions(const char *name,
361435933ddSDimitry Andric uint32_t name_type_mask) {
362ac7ddfbfSEd Maste lldb::SBSymbolContextList sb_sc_list;
363ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
364435933ddSDimitry Andric if (name && module_sp) {
365ac7ddfbfSEd Maste const bool append = true;
366ac7ddfbfSEd Maste const bool symbols_ok = true;
367ac7ddfbfSEd Maste const bool inlines_ok = true;
368*b5893f02SDimitry Andric FunctionNameType type = static_cast<FunctionNameType>(name_type_mask);
369*b5893f02SDimitry Andric module_sp->FindFunctions(ConstString(name), NULL, type, symbols_ok,
370*b5893f02SDimitry Andric inlines_ok, append, *sb_sc_list);
371ac7ddfbfSEd Maste }
372ac7ddfbfSEd Maste return sb_sc_list;
373ac7ddfbfSEd Maste }
374ac7ddfbfSEd Maste
FindGlobalVariables(SBTarget & target,const char * name,uint32_t max_matches)375435933ddSDimitry Andric SBValueList SBModule::FindGlobalVariables(SBTarget &target, const char *name,
376435933ddSDimitry Andric uint32_t max_matches) {
377ac7ddfbfSEd Maste SBValueList sb_value_list;
378ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
379435933ddSDimitry Andric if (name && module_sp) {
380ac7ddfbfSEd Maste VariableList variable_list;
381435933ddSDimitry Andric const uint32_t match_count = module_sp->FindGlobalVariables(
3824ba319b5SDimitry Andric ConstString(name), NULL, max_matches, variable_list);
383ac7ddfbfSEd Maste
384435933ddSDimitry Andric if (match_count > 0) {
385435933ddSDimitry Andric for (uint32_t i = 0; i < match_count; ++i) {
386ac7ddfbfSEd Maste lldb::ValueObjectSP valobj_sp;
387ac7ddfbfSEd Maste TargetSP target_sp(target.GetSP());
388435933ddSDimitry Andric valobj_sp = ValueObjectVariable::Create(
389435933ddSDimitry Andric target_sp.get(), variable_list.GetVariableAtIndex(i));
390ac7ddfbfSEd Maste if (valobj_sp)
391ac7ddfbfSEd Maste sb_value_list.Append(SBValue(valobj_sp));
392ac7ddfbfSEd Maste }
393ac7ddfbfSEd Maste }
394ac7ddfbfSEd Maste }
395ac7ddfbfSEd Maste
396ac7ddfbfSEd Maste return sb_value_list;
397ac7ddfbfSEd Maste }
398ac7ddfbfSEd Maste
FindFirstGlobalVariable(lldb::SBTarget & target,const char * name)399435933ddSDimitry Andric lldb::SBValue SBModule::FindFirstGlobalVariable(lldb::SBTarget &target,
400435933ddSDimitry Andric const char *name) {
401ac7ddfbfSEd Maste SBValueList sb_value_list(FindGlobalVariables(target, name, 1));
402ac7ddfbfSEd Maste if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0)
403ac7ddfbfSEd Maste return sb_value_list.GetValueAtIndex(0);
404ac7ddfbfSEd Maste return SBValue();
405ac7ddfbfSEd Maste }
406ac7ddfbfSEd Maste
FindFirstType(const char * name_cstr)407435933ddSDimitry Andric lldb::SBType SBModule::FindFirstType(const char *name_cstr) {
408ac7ddfbfSEd Maste SBType sb_type;
409ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
410435933ddSDimitry Andric if (name_cstr && module_sp) {
411ac7ddfbfSEd Maste SymbolContext sc;
412ac7ddfbfSEd Maste const bool exact_match = false;
413ac7ddfbfSEd Maste ConstString name(name_cstr);
414ac7ddfbfSEd Maste
415ac7ddfbfSEd Maste sb_type = SBType(module_sp->FindFirstType(sc, name, exact_match));
416ac7ddfbfSEd Maste
417435933ddSDimitry Andric if (!sb_type.IsValid()) {
418435933ddSDimitry Andric TypeSystem *type_system =
419435933ddSDimitry Andric module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
4209f2f44ceSEd Maste if (type_system)
4219f2f44ceSEd Maste sb_type = SBType(type_system->GetBuiltinTypeByName(name));
4229f2f44ceSEd Maste }
423ac7ddfbfSEd Maste }
424ac7ddfbfSEd Maste return sb_type;
425ac7ddfbfSEd Maste }
426ac7ddfbfSEd Maste
GetBasicType(lldb::BasicType type)427435933ddSDimitry Andric lldb::SBType SBModule::GetBasicType(lldb::BasicType type) {
428ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
429435933ddSDimitry Andric if (module_sp) {
430435933ddSDimitry Andric TypeSystem *type_system =
431435933ddSDimitry Andric module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
4329f2f44ceSEd Maste if (type_system)
4339f2f44ceSEd Maste return SBType(type_system->GetBasicTypeFromAST(type));
4349f2f44ceSEd Maste }
435ac7ddfbfSEd Maste return SBType();
436ac7ddfbfSEd Maste }
437ac7ddfbfSEd Maste
FindTypes(const char * type)438435933ddSDimitry Andric lldb::SBTypeList SBModule::FindTypes(const char *type) {
439ac7ddfbfSEd Maste SBTypeList retval;
440ac7ddfbfSEd Maste
441ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
442435933ddSDimitry Andric if (type && module_sp) {
443ac7ddfbfSEd Maste TypeList type_list;
444ac7ddfbfSEd Maste const bool exact_match = false;
445ac7ddfbfSEd Maste ConstString name(type);
4464bb0738eSEd Maste llvm::DenseSet<SymbolFile *> searched_symbol_files;
447435933ddSDimitry Andric const uint32_t num_matches = module_sp->FindTypes(
448*b5893f02SDimitry Andric name, exact_match, UINT32_MAX, searched_symbol_files, type_list);
449ac7ddfbfSEd Maste
450435933ddSDimitry Andric if (num_matches > 0) {
451435933ddSDimitry Andric for (size_t idx = 0; idx < num_matches; idx++) {
452ac7ddfbfSEd Maste TypeSP type_sp(type_list.GetTypeAtIndex(idx));
453ac7ddfbfSEd Maste if (type_sp)
454ac7ddfbfSEd Maste retval.Append(SBType(type_sp));
455ac7ddfbfSEd Maste }
456435933ddSDimitry Andric } else {
457435933ddSDimitry Andric TypeSystem *type_system =
458435933ddSDimitry Andric module_sp->GetTypeSystemForLanguage(eLanguageTypeC);
459435933ddSDimitry Andric if (type_system) {
4609f2f44ceSEd Maste CompilerType compiler_type = type_system->GetBuiltinTypeByName(name);
4619f2f44ceSEd Maste if (compiler_type)
4629f2f44ceSEd Maste retval.Append(SBType(compiler_type));
4639f2f44ceSEd Maste }
464ac7ddfbfSEd Maste }
465ac7ddfbfSEd Maste }
466ac7ddfbfSEd Maste
467ac7ddfbfSEd Maste return retval;
468ac7ddfbfSEd Maste }
469ac7ddfbfSEd Maste
GetTypeByID(lldb::user_id_t uid)470435933ddSDimitry Andric lldb::SBType SBModule::GetTypeByID(lldb::user_id_t uid) {
47112b93ac6SEd Maste ModuleSP module_sp(GetSP());
472435933ddSDimitry Andric if (module_sp) {
47312b93ac6SEd Maste SymbolVendor *vendor = module_sp->GetSymbolVendor();
474435933ddSDimitry Andric if (vendor) {
47512b93ac6SEd Maste Type *type_ptr = vendor->ResolveTypeUID(uid);
47612b93ac6SEd Maste if (type_ptr)
47712b93ac6SEd Maste return SBType(type_ptr->shared_from_this());
47812b93ac6SEd Maste }
47912b93ac6SEd Maste }
48012b93ac6SEd Maste return SBType();
48112b93ac6SEd Maste }
48212b93ac6SEd Maste
GetTypes(uint32_t type_mask)483435933ddSDimitry Andric lldb::SBTypeList SBModule::GetTypes(uint32_t type_mask) {
484ac7ddfbfSEd Maste SBTypeList sb_type_list;
485ac7ddfbfSEd Maste
486ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
487*b5893f02SDimitry Andric if (!module_sp)
488*b5893f02SDimitry Andric return sb_type_list;
489ac7ddfbfSEd Maste SymbolVendor *vendor = module_sp->GetSymbolVendor();
490*b5893f02SDimitry Andric if (!vendor)
491*b5893f02SDimitry Andric return sb_type_list;
492*b5893f02SDimitry Andric
493*b5893f02SDimitry Andric TypeClass type_class = static_cast<TypeClass>(type_mask);
494ac7ddfbfSEd Maste TypeList type_list;
495*b5893f02SDimitry Andric vendor->GetTypes(NULL, type_class, type_list);
496ac7ddfbfSEd Maste sb_type_list.m_opaque_ap->Append(type_list);
497ac7ddfbfSEd Maste return sb_type_list;
498ac7ddfbfSEd Maste }
499ac7ddfbfSEd Maste
FindSection(const char * sect_name)500435933ddSDimitry Andric SBSection SBModule::FindSection(const char *sect_name) {
501ac7ddfbfSEd Maste SBSection sb_section;
502ac7ddfbfSEd Maste
503ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
504435933ddSDimitry Andric if (sect_name && module_sp) {
505ac7ddfbfSEd Maste // Give the symbol vendor a chance to add to the unified section list.
506ac7ddfbfSEd Maste module_sp->GetSymbolVendor();
507ac7ddfbfSEd Maste SectionList *section_list = module_sp->GetSectionList();
508435933ddSDimitry Andric if (section_list) {
509ac7ddfbfSEd Maste ConstString const_sect_name(sect_name);
510ac7ddfbfSEd Maste SectionSP section_sp(section_list->FindSectionByName(const_sect_name));
511435933ddSDimitry Andric if (section_sp) {
512ac7ddfbfSEd Maste sb_section.SetSP(section_sp);
513ac7ddfbfSEd Maste }
514ac7ddfbfSEd Maste }
515ac7ddfbfSEd Maste }
516ac7ddfbfSEd Maste return sb_section;
517ac7ddfbfSEd Maste }
518ac7ddfbfSEd Maste
GetByteOrder()519435933ddSDimitry Andric lldb::ByteOrder SBModule::GetByteOrder() {
520ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
521ac7ddfbfSEd Maste if (module_sp)
522ac7ddfbfSEd Maste return module_sp->GetArchitecture().GetByteOrder();
523ac7ddfbfSEd Maste return eByteOrderInvalid;
524ac7ddfbfSEd Maste }
525ac7ddfbfSEd Maste
GetTriple()526435933ddSDimitry Andric const char *SBModule::GetTriple() {
527ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
528435933ddSDimitry Andric if (module_sp) {
529ac7ddfbfSEd Maste std::string triple(module_sp->GetArchitecture().GetTriple().str());
5304ba319b5SDimitry Andric // Unique the string so we don't run into ownership issues since the const
5314ba319b5SDimitry Andric // strings put the string into the string pool once and the strings never
5324ba319b5SDimitry Andric // comes out
533ac7ddfbfSEd Maste ConstString const_triple(triple.c_str());
534ac7ddfbfSEd Maste return const_triple.GetCString();
535ac7ddfbfSEd Maste }
536ac7ddfbfSEd Maste return NULL;
537ac7ddfbfSEd Maste }
538ac7ddfbfSEd Maste
GetAddressByteSize()539435933ddSDimitry Andric uint32_t SBModule::GetAddressByteSize() {
540ac7ddfbfSEd Maste ModuleSP module_sp(GetSP());
541ac7ddfbfSEd Maste if (module_sp)
542ac7ddfbfSEd Maste return module_sp->GetArchitecture().GetAddressByteSize();
543ac7ddfbfSEd Maste return sizeof(void *);
544ac7ddfbfSEd Maste }
545ac7ddfbfSEd Maste
GetVersion(uint32_t * versions,uint32_t num_versions)546435933ddSDimitry Andric uint32_t SBModule::GetVersion(uint32_t *versions, uint32_t num_versions) {
5474ba319b5SDimitry Andric llvm::VersionTuple version;
5484ba319b5SDimitry Andric if (ModuleSP module_sp = GetSP())
5494ba319b5SDimitry Andric version = module_sp->GetVersion();
5504ba319b5SDimitry Andric uint32_t result = 0;
5514ba319b5SDimitry Andric if (!version.empty())
5524ba319b5SDimitry Andric ++result;
5534ba319b5SDimitry Andric if (version.getMinor())
5544ba319b5SDimitry Andric ++result;
5554ba319b5SDimitry Andric if(version.getSubminor())
5564ba319b5SDimitry Andric ++result;
5574ba319b5SDimitry Andric
5584ba319b5SDimitry Andric if (!versions)
5594ba319b5SDimitry Andric return result;
5604ba319b5SDimitry Andric
5614ba319b5SDimitry Andric if (num_versions > 0)
5624ba319b5SDimitry Andric versions[0] = version.empty() ? UINT32_MAX : version.getMajor();
5634ba319b5SDimitry Andric if (num_versions > 1)
5644ba319b5SDimitry Andric versions[1] = version.getMinor().getValueOr(UINT32_MAX);
5654ba319b5SDimitry Andric if (num_versions > 2)
5664ba319b5SDimitry Andric versions[2] = version.getSubminor().getValueOr(UINT32_MAX);
5674ba319b5SDimitry Andric for (uint32_t i = 3; i < num_versions; ++i)
568ac7ddfbfSEd Maste versions[i] = UINT32_MAX;
5694ba319b5SDimitry Andric return result;
570ac7ddfbfSEd Maste }
571ac7ddfbfSEd Maste
GetSymbolFileSpec() const572435933ddSDimitry Andric lldb::SBFileSpec SBModule::GetSymbolFileSpec() const {
5731c3bbb01SEd Maste lldb::SBFileSpec sb_file_spec;
5741c3bbb01SEd Maste ModuleSP module_sp(GetSP());
575435933ddSDimitry Andric if (module_sp) {
5761c3bbb01SEd Maste SymbolVendor *symbol_vendor_ptr = module_sp->GetSymbolVendor();
5771c3bbb01SEd Maste if (symbol_vendor_ptr)
5781c3bbb01SEd Maste sb_file_spec.SetFileSpec(symbol_vendor_ptr->GetMainFileSpec());
5791c3bbb01SEd Maste }
5801c3bbb01SEd Maste return sb_file_spec;
5811c3bbb01SEd Maste }
5821c3bbb01SEd Maste
GetObjectFileHeaderAddress() const583435933ddSDimitry Andric lldb::SBAddress SBModule::GetObjectFileHeaderAddress() const {
5841c3bbb01SEd Maste lldb::SBAddress sb_addr;
5851c3bbb01SEd Maste ModuleSP module_sp(GetSP());
586435933ddSDimitry Andric if (module_sp) {
5871c3bbb01SEd Maste ObjectFile *objfile_ptr = module_sp->GetObjectFile();
5881c3bbb01SEd Maste if (objfile_ptr)
589*b5893f02SDimitry Andric sb_addr.ref() = objfile_ptr->GetBaseAddress();
590*b5893f02SDimitry Andric }
591*b5893f02SDimitry Andric return sb_addr;
592*b5893f02SDimitry Andric }
593*b5893f02SDimitry Andric
GetObjectFileEntryPointAddress() const594*b5893f02SDimitry Andric lldb::SBAddress SBModule::GetObjectFileEntryPointAddress() const {
595*b5893f02SDimitry Andric lldb::SBAddress sb_addr;
596*b5893f02SDimitry Andric ModuleSP module_sp(GetSP());
597*b5893f02SDimitry Andric if (module_sp) {
598*b5893f02SDimitry Andric ObjectFile *objfile_ptr = module_sp->GetObjectFile();
599*b5893f02SDimitry Andric if (objfile_ptr)
600*b5893f02SDimitry Andric sb_addr.ref() = objfile_ptr->GetEntryPointAddress();
6011c3bbb01SEd Maste }
6021c3bbb01SEd Maste return sb_addr;
6031c3bbb01SEd Maste }
604