blob: eed84d5c6083b24525681e07af560bd04e28e288 [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"
13#include "lldb/Core/Module.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014#include "lldb/Symbol/Symbol.h"
Greg Clayton5c4c7462010-10-06 03:09:58 +000015#include "lldb/Target/ExecutionContext.h"
16#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017
18using namespace lldb;
Greg Clayton5c4c7462010-10-06 03:09:58 +000019using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000020
21SBSymbol::SBSymbol () :
Greg Clayton63094e02010-06-23 01:19:29 +000022 m_opaque_ptr (NULL)
Chris Lattner24943d22010-06-08 16:52:24 +000023{
24}
25
26SBSymbol::SBSymbol (lldb_private::Symbol *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000027 m_opaque_ptr (lldb_object_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +000028{
29}
30
31SBSymbol::~SBSymbol ()
32{
Greg Clayton63094e02010-06-23 01:19:29 +000033 m_opaque_ptr = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000034}
35
36bool
37SBSymbol::IsValid () const
38{
Greg Clayton63094e02010-06-23 01:19:29 +000039 return m_opaque_ptr != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000040}
41
42const char *
43SBSymbol::GetName() const
44{
Greg Clayton63094e02010-06-23 01:19:29 +000045 if (m_opaque_ptr)
46 return m_opaque_ptr->GetMangled().GetName().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000047 return NULL;
48}
49
50const char *
51SBSymbol::GetMangledName () const
52{
Greg Clayton63094e02010-06-23 01:19:29 +000053 if (m_opaque_ptr)
54 return m_opaque_ptr->GetMangled().GetMangledName().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000055 return NULL;
56}
57
58
59bool
60SBSymbol::operator == (const SBSymbol &rhs) const
61{
Greg Clayton63094e02010-06-23 01:19:29 +000062 return m_opaque_ptr == rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000063}
64
65bool
66SBSymbol::operator != (const SBSymbol &rhs) const
67{
Greg Clayton63094e02010-06-23 01:19:29 +000068 return m_opaque_ptr != rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000069}
Caroline Tice98f930f2010-09-20 05:20:02 +000070
71bool
72SBSymbol::GetDescription (SBStream &description)
73{
74 if (m_opaque_ptr)
75 {
Caroline Ticee49ec182010-09-22 23:01:29 +000076 description.ref();
77 m_opaque_ptr->GetDescription (description.get(),
78 lldb::eDescriptionLevelFull, NULL);
Caroline Tice98f930f2010-09-20 05:20:02 +000079 }
80 else
81 description.Printf ("No value");
82
83 return true;
84}
Greg Clayton5c4c7462010-10-06 03:09:58 +000085
86
87
88SBInstructionList
89SBSymbol::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