blob: a3dc21881f3c1841c840487c4e4801aa69dfa746 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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"
Caroline Tice98f930f2010-09-20 05:20:02 +000011#include "lldb/API/SBStream.h"
Greg Clayton5c4c7462010-10-06 03:09:58 +000012#include "lldb/Core/Disassembler.h"
Caroline Tice7826c882010-10-26 03:11:13 +000013#include "lldb/Core/Log.h"
Greg Clayton5c4c7462010-10-06 03:09:58 +000014#include "lldb/Core/Module.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Symbol/Symbol.h"
Greg Clayton5c4c7462010-10-06 03:09:58 +000016#include "lldb/Target/ExecutionContext.h"
17#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018
19using namespace lldb;
Greg Clayton5c4c7462010-10-06 03:09:58 +000020using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000021
22SBSymbol::SBSymbol () :
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 ("SBSymbol::SBSymbol () ==> this = %p", this);
Chris Lattner24943d22010-06-08 16:52:24 +000029}
30
31SBSymbol::SBSymbol (lldb_private::Symbol *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 ("SBSymbol::SBSymbol (lldb_private::Symbol *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
45SBSymbol::~SBSymbol ()
46{
Greg Clayton63094e02010-06-23 01:19:29 +000047 m_opaque_ptr = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000048}
49
50bool
51SBSymbol::IsValid () const
52{
Greg Clayton63094e02010-06-23 01:19:29 +000053 return m_opaque_ptr != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000054}
55
56const char *
57SBSymbol::GetName() const
58{
Caroline Tice7826c882010-10-26 03:11:13 +000059 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
60
61 if (log)
62 log->Printf ("SBSymbol::GetName ()");
63
Greg Clayton63094e02010-06-23 01:19:29 +000064 if (m_opaque_ptr)
Caroline Tice7826c882010-10-26 03:11:13 +000065 {
66 if (log)
67 log->Printf ("SBSymbol::GetName ==> %s", m_opaque_ptr->GetMangled().GetName().AsCString());
Greg Clayton63094e02010-06-23 01:19:29 +000068 return m_opaque_ptr->GetMangled().GetName().AsCString();
Caroline Tice7826c882010-10-26 03:11:13 +000069 }
70
71 if (log)
72 log->Printf ("SBSymbol::GetName ==> NULL");
73
Chris Lattner24943d22010-06-08 16:52:24 +000074 return NULL;
75}
76
77const char *
78SBSymbol::GetMangledName () const
79{
Greg Clayton63094e02010-06-23 01:19:29 +000080 if (m_opaque_ptr)
81 return m_opaque_ptr->GetMangled().GetMangledName().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000082 return NULL;
83}
84
85
86bool
87SBSymbol::operator == (const SBSymbol &rhs) const
88{
Greg Clayton63094e02010-06-23 01:19:29 +000089 return m_opaque_ptr == rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000090}
91
92bool
93SBSymbol::operator != (const SBSymbol &rhs) const
94{
Greg Clayton63094e02010-06-23 01:19:29 +000095 return m_opaque_ptr != rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000096}
Caroline Tice98f930f2010-09-20 05:20:02 +000097
98bool
99SBSymbol::GetDescription (SBStream &description)
100{
101 if (m_opaque_ptr)
102 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000103 description.ref();
104 m_opaque_ptr->GetDescription (description.get(),
105 lldb::eDescriptionLevelFull, NULL);
Caroline Tice98f930f2010-09-20 05:20:02 +0000106 }
107 else
108 description.Printf ("No value");
109
110 return true;
111}
Greg Clayton5c4c7462010-10-06 03:09:58 +0000112
113
114
115SBInstructionList
116SBSymbol::GetInstructions (SBTarget target)
117{
118 SBInstructionList sb_instructions;
119 if (m_opaque_ptr)
120 {
121 ExecutionContext exe_ctx;
122 if (target.IsValid())
123 target->CalculateExecutionContext (exe_ctx);
124 const AddressRange *symbol_range = m_opaque_ptr->GetAddressRangePtr();
125 if (symbol_range)
126 {
127 Module *module = symbol_range->GetBaseAddress().GetModule();
128 if (module)
129 {
130 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture (),
131 exe_ctx,
132 *symbol_range));
133 }
134 }
135 }
136 return sb_instructions;
137}
138