blob: e8281a1b19361a6d79417c1b532c41da8a100671 [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{
25}
26
27SBSymbol::SBSymbol (lldb_private::Symbol *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000028 m_opaque_ptr (lldb_object_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +000029{
30}
31
Greg Clayton538eb822010-11-05 23:17:00 +000032SBSymbol::SBSymbol (const lldb::SBSymbol &rhs) :
33 m_opaque_ptr (rhs.m_opaque_ptr)
34{
35}
36
37const SBSymbol &
38SBSymbol::operator = (const SBSymbol &rhs)
39{
40 m_opaque_ptr = rhs.m_opaque_ptr;
41 return *this;
42}
43
44
Chris Lattner24943d22010-06-08 16:52:24 +000045SBSymbol::~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{
Greg Claytona66ba462010-10-30 04:51:46 +000059 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +000060 if (m_opaque_ptr)
Greg Claytona66ba462010-10-30 04:51:46 +000061 name = m_opaque_ptr->GetMangled().GetName().AsCString();
Caroline Tice61ba7ec2010-10-26 23:49:36 +000062
Greg Claytone005f2c2010-11-06 01:53:30 +000063 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000064 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +000065 log->Printf ("SBSymbol(%p)::GetName () => \"%s\"", m_opaque_ptr, name ? name : "");
66 return name;
Chris Lattner24943d22010-06-08 16:52:24 +000067}
68
69const char *
70SBSymbol::GetMangledName () const
71{
Greg Claytona66ba462010-10-30 04:51:46 +000072 const char *name = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +000073 if (m_opaque_ptr)
Greg Claytona66ba462010-10-30 04:51:46 +000074 name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
Greg Claytone005f2c2010-11-06 01:53:30 +000075 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +000076 if (log)
77 log->Printf ("SBSymbol(%p)::GetMangledName () => \"%s\"", m_opaque_ptr, name ? name : "");
78
79 return name;
Chris Lattner24943d22010-06-08 16:52:24 +000080}
81
82
83bool
84SBSymbol::operator == (const SBSymbol &rhs) const
85{
Greg Clayton63094e02010-06-23 01:19:29 +000086 return m_opaque_ptr == rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000087}
88
89bool
90SBSymbol::operator != (const SBSymbol &rhs) const
91{
Greg Clayton63094e02010-06-23 01:19:29 +000092 return m_opaque_ptr != rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000093}
Caroline Tice98f930f2010-09-20 05:20:02 +000094
95bool
96SBSymbol::GetDescription (SBStream &description)
97{
98 if (m_opaque_ptr)
99 {
Caroline Ticee49ec182010-09-22 23:01:29 +0000100 description.ref();
101 m_opaque_ptr->GetDescription (description.get(),
102 lldb::eDescriptionLevelFull, NULL);
Caroline Tice98f930f2010-09-20 05:20:02 +0000103 }
104 else
105 description.Printf ("No value");
106
107 return true;
108}
Greg Clayton5c4c7462010-10-06 03:09:58 +0000109
110
111
112SBInstructionList
113SBSymbol::GetInstructions (SBTarget target)
114{
115 SBInstructionList sb_instructions;
116 if (m_opaque_ptr)
117 {
118 ExecutionContext exe_ctx;
119 if (target.IsValid())
120 target->CalculateExecutionContext (exe_ctx);
121 const AddressRange *symbol_range = m_opaque_ptr->GetAddressRangePtr();
122 if (symbol_range)
123 {
124 Module *module = symbol_range->GetBaseAddress().GetModule();
125 if (module)
126 {
127 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture (),
128 exe_ctx,
129 *symbol_range));
130 }
131 }
132 }
133 return sb_instructions;
134}
135
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000136lldb_private::Symbol *
137SBSymbol::get ()
138{
139 return m_opaque_ptr;
140}