blob: 54081b55ac3bbea2f05c30c9b364a30c360dc275 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBFunction.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/SBFunction.h"
11#include "lldb/API/SBProcess.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000012#include "lldb/API/SBStream.h"
Greg Clayton5c4c7462010-10-06 03:09:58 +000013#include "lldb/Core/Disassembler.h"
Caroline Tice7826c882010-10-26 03:11:13 +000014#include "lldb/Core/Log.h"
Greg Clayton5c4c7462010-10-06 03:09:58 +000015#include "lldb/Core/Module.h"
16#include "lldb/Symbol/CompileUnit.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Symbol/Function.h"
Greg Claytond8c62532010-10-07 04:19:01 +000018#include "lldb/Symbol/Type.h"
Greg Clayton5c4c7462010-10-06 03:09:58 +000019#include "lldb/Target/ExecutionContext.h"
20#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021
22using namespace lldb;
Greg Clayton5c4c7462010-10-06 03:09:58 +000023using namespace lldb_private;
Chris Lattner24943d22010-06-08 16:52:24 +000024
25SBFunction::SBFunction () :
Greg Clayton63094e02010-06-23 01:19:29 +000026 m_opaque_ptr (NULL)
Chris Lattner24943d22010-06-08 16:52:24 +000027{
28}
29
30SBFunction::SBFunction (lldb_private::Function *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000031 m_opaque_ptr (lldb_object_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +000032{
33}
34
Greg Clayton538eb822010-11-05 23:17:00 +000035SBFunction::SBFunction (const lldb::SBFunction &rhs) :
36 m_opaque_ptr (rhs.m_opaque_ptr)
37{
38}
39
40const SBFunction &
41SBFunction::operator = (const SBFunction &rhs)
42{
43 m_opaque_ptr = rhs.m_opaque_ptr;
44 return *this;
45}
46
Chris Lattner24943d22010-06-08 16:52:24 +000047SBFunction::~SBFunction ()
48{
Greg Clayton63094e02010-06-23 01:19:29 +000049 m_opaque_ptr = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000050}
51
52bool
53SBFunction::IsValid () const
54{
Greg Clayton63094e02010-06-23 01:19:29 +000055 return m_opaque_ptr != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000056}
57
58const char *
59SBFunction::GetName() const
60{
Greg Clayton49ce6822010-10-31 03:01:06 +000061 const char *cstr = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +000062 if (m_opaque_ptr)
Greg Clayton49ce6822010-10-31 03:01:06 +000063 cstr = m_opaque_ptr->GetMangled().GetName().AsCString();
Caroline Tice7826c882010-10-26 03:11:13 +000064
Greg Claytone005f2c2010-11-06 01:53:30 +000065 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000066 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +000067 {
68 if (cstr)
69 log->Printf ("SBFunction(%p)::GetName () => \"%s\"", m_opaque_ptr, cstr);
70 else
71 log->Printf ("SBFunction(%p)::GetName () => NULL", m_opaque_ptr);
72 }
73 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +000074}
75
76const char *
77SBFunction::GetMangledName () const
78{
Greg Clayton49ce6822010-10-31 03:01:06 +000079 const char *cstr = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +000080 if (m_opaque_ptr)
Greg Clayton49ce6822010-10-31 03:01:06 +000081 cstr = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
Greg Claytone005f2c2010-11-06 01:53:30 +000082 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +000083 if (log)
84 {
85 if (cstr)
86 log->Printf ("SBFunction(%p)::GetMangledName () => \"%s\"", m_opaque_ptr, cstr);
87 else
88 log->Printf ("SBFunction(%p)::GetMangledName () => NULL", m_opaque_ptr);
89 }
90 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +000091}
92
93bool
94SBFunction::operator == (const SBFunction &rhs) const
95{
Greg Clayton63094e02010-06-23 01:19:29 +000096 return m_opaque_ptr == rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000097}
98
99bool
100SBFunction::operator != (const SBFunction &rhs) const
101{
Greg Clayton63094e02010-06-23 01:19:29 +0000102 return m_opaque_ptr != rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +0000103}
Caroline Tice98f930f2010-09-20 05:20:02 +0000104
105bool
Greg Claytond8c62532010-10-07 04:19:01 +0000106SBFunction::GetDescription (SBStream &s)
Caroline Tice98f930f2010-09-20 05:20:02 +0000107{
108 if (m_opaque_ptr)
109 {
Greg Claytond8c62532010-10-07 04:19:01 +0000110 s.Printf ("SBFunction: id = 0x%8.8x, name = %s",
111 m_opaque_ptr->GetID(),
112 m_opaque_ptr->GetName().AsCString());
113 Type *func_type = m_opaque_ptr->GetType();
114 if (func_type)
115 s.Printf(", type = %s", func_type->GetName().AsCString());
116 return true;
Caroline Tice98f930f2010-09-20 05:20:02 +0000117 }
Greg Claytond8c62532010-10-07 04:19:01 +0000118 s.Printf ("No value");
119 return false;
Caroline Tice98f930f2010-09-20 05:20:02 +0000120}
Greg Clayton5c4c7462010-10-06 03:09:58 +0000121
122SBInstructionList
123SBFunction::GetInstructions (SBTarget target)
124{
125 SBInstructionList sb_instructions;
126 if (m_opaque_ptr)
127 {
128 ExecutionContext exe_ctx;
129 if (target.IsValid())
130 {
131 target->CalculateExecutionContext (exe_ctx);
132 exe_ctx.process = target->GetProcessSP().get();
133 }
134 Module *module = m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule();
135 if (module)
136 {
137 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture(),
138 exe_ctx,
139 m_opaque_ptr->GetAddressRange()));
140 }
141 }
142 return sb_instructions;
143}
144
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000145lldb_private::Function *
146SBFunction::get ()
147{
148 return m_opaque_ptr;
149}
Greg Clayton5c4c7462010-10-06 03:09:58 +0000150
Greg Claytondd62d722010-12-14 04:58:53 +0000151void
152SBFunction::reset (lldb_private::Function *lldb_object_ptr)
153{
154 m_opaque_ptr = lldb_object_ptr;
155}
156