1 //===-- SBSymbol.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/SBSymbol.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Disassembler.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Symbol/Symbol.h"
15 #include "lldb/Target/ExecutionContext.h"
16 #include "lldb/Target/Target.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 SBSymbol::SBSymbol () :
22     m_opaque_ptr (NULL)
23 {
24 }
25 
26 SBSymbol::SBSymbol (lldb_private::Symbol *lldb_object_ptr) :
27     m_opaque_ptr (lldb_object_ptr)
28 {
29 }
30 
31 SBSymbol::~SBSymbol ()
32 {
33     m_opaque_ptr = NULL;
34 }
35 
36 bool
37 SBSymbol::IsValid () const
38 {
39     return m_opaque_ptr != NULL;
40 }
41 
42 const char *
43 SBSymbol::GetName() const
44 {
45     if (m_opaque_ptr)
46         return m_opaque_ptr->GetMangled().GetName().AsCString();
47     return NULL;
48 }
49 
50 const char *
51 SBSymbol::GetMangledName () const
52 {
53     if (m_opaque_ptr)
54         return m_opaque_ptr->GetMangled().GetMangledName().AsCString();
55     return NULL;
56 }
57 
58 
59 bool
60 SBSymbol::operator == (const SBSymbol &rhs) const
61 {
62     return m_opaque_ptr == rhs.m_opaque_ptr;
63 }
64 
65 bool
66 SBSymbol::operator != (const SBSymbol &rhs) const
67 {
68     return m_opaque_ptr != rhs.m_opaque_ptr;
69 }
70 
71 bool
72 SBSymbol::GetDescription (SBStream &description)
73 {
74     if (m_opaque_ptr)
75     {
76         description.ref();
77         m_opaque_ptr->GetDescription (description.get(),
78                                       lldb::eDescriptionLevelFull, NULL);
79     }
80     else
81         description.Printf ("No value");
82 
83     return true;
84 }
85 
86 
87 
88 SBInstructionList
89 SBSymbol::GetInstructions (SBTarget target)
90 {
91     SBInstructionList sb_instructions;
92     if (m_opaque_ptr)
93     {
94         ExecutionContext exe_ctx;
95         if (target.IsValid())
96             target->CalculateExecutionContext (exe_ctx);
97         const AddressRange *symbol_range = m_opaque_ptr->GetAddressRangePtr();
98         if (symbol_range)
99         {
100             Module *module = symbol_range->GetBaseAddress().GetModule();
101             if (module)
102             {
103                 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture (),
104                                                                                  exe_ctx,
105                                                                                  *symbol_range));
106             }
107         }
108     }
109     return sb_instructions;
110 }
111 
112