blob: 459ead23650b9be0f5f28eece968d5a9f661ed0e [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{
Caroline Tice7826c882010-10-26 03:11:13 +000028 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
29
30 if (log)
31 log->Printf ("SBFunction::SBFunction () ==> this = %p", this);
Chris Lattner24943d22010-06-08 16:52:24 +000032}
33
34SBFunction::SBFunction (lldb_private::Function *lldb_object_ptr) :
Greg Clayton63094e02010-06-23 01:19:29 +000035 m_opaque_ptr (lldb_object_ptr)
Chris Lattner24943d22010-06-08 16:52:24 +000036{
Caroline Tice7826c882010-10-26 03:11:13 +000037 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE);
38
39 if (log)
40 {
41 SBStream sstr;
42 GetDescription (sstr);
43 log->Printf ("SBFunction::SBFunction (lldb_Private::Function *lldb_object_ptr) lldb_object_ptr = %p "
44 " ==> this = %p (%s)", lldb_object_ptr, this, sstr.GetData());
45 }
Chris Lattner24943d22010-06-08 16:52:24 +000046}
47
48SBFunction::~SBFunction ()
49{
Greg Clayton63094e02010-06-23 01:19:29 +000050 m_opaque_ptr = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000051}
52
53bool
54SBFunction::IsValid () const
55{
Greg Clayton63094e02010-06-23 01:19:29 +000056 return m_opaque_ptr != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000057}
58
59const char *
60SBFunction::GetName() const
61{
Caroline Tice7826c882010-10-26 03:11:13 +000062 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
63
64 if (log)
65 log->Printf ("SBFunction::GetName ()");
66
Greg Clayton63094e02010-06-23 01:19:29 +000067 if (m_opaque_ptr)
Caroline Tice7826c882010-10-26 03:11:13 +000068 {
69 if (log)
70 log->Printf ("SBFunction::GetName ==> %s", m_opaque_ptr->GetMangled().GetName().AsCString());
Greg Clayton63094e02010-06-23 01:19:29 +000071 return m_opaque_ptr->GetMangled().GetName().AsCString();
Caroline Tice7826c882010-10-26 03:11:13 +000072 }
73
74 if (log)
75 log->Printf ("SBFunction::GetName ==> NULL");
Chris Lattner24943d22010-06-08 16:52:24 +000076 return NULL;
77}
78
79const char *
80SBFunction::GetMangledName () const
81{
Greg Clayton63094e02010-06-23 01:19:29 +000082 if (m_opaque_ptr)
83 return m_opaque_ptr->GetMangled().GetMangledName().AsCString();
Chris Lattner24943d22010-06-08 16:52:24 +000084 return NULL;
85}
86
87bool
88SBFunction::operator == (const SBFunction &rhs) const
89{
Greg Clayton63094e02010-06-23 01:19:29 +000090 return m_opaque_ptr == rhs.m_opaque_ptr;
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}
Caroline Tice98f930f2010-09-20 05:20:02 +000098
99bool
Greg Claytond8c62532010-10-07 04:19:01 +0000100SBFunction::GetDescription (SBStream &s)
Caroline Tice98f930f2010-09-20 05:20:02 +0000101{
102 if (m_opaque_ptr)
103 {
Greg Claytond8c62532010-10-07 04:19:01 +0000104 s.Printf ("SBFunction: id = 0x%8.8x, name = %s",
105 m_opaque_ptr->GetID(),
106 m_opaque_ptr->GetName().AsCString());
107 Type *func_type = m_opaque_ptr->GetType();
108 if (func_type)
109 s.Printf(", type = %s", func_type->GetName().AsCString());
110 return true;
Caroline Tice98f930f2010-09-20 05:20:02 +0000111 }
Greg Claytond8c62532010-10-07 04:19:01 +0000112 s.Printf ("No value");
113 return false;
Caroline Tice98f930f2010-09-20 05:20:02 +0000114}
Greg Clayton5c4c7462010-10-06 03:09:58 +0000115
116SBInstructionList
117SBFunction::GetInstructions (SBTarget target)
118{
119 SBInstructionList sb_instructions;
120 if (m_opaque_ptr)
121 {
122 ExecutionContext exe_ctx;
123 if (target.IsValid())
124 {
125 target->CalculateExecutionContext (exe_ctx);
126 exe_ctx.process = target->GetProcessSP().get();
127 }
128 Module *module = m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule();
129 if (module)
130 {
131 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture(),
132 exe_ctx,
133 m_opaque_ptr->GetAddressRange()));
134 }
135 }
136 return sb_instructions;
137}
138
139