blob: 2efd37c31ba1729da7c0ef33396c781d5fb46aa6 [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{
Caroline Tice61ba7ec2010-10-26 23:49:36 +000033 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Tice7826c882010-10-26 03:11:13 +000034
35 if (log)
36 {
37 SBStream sstr;
38 GetDescription (sstr);
Caroline Tice61ba7ec2010-10-26 23:49:36 +000039 log->Printf ("SBFunction::SBFunction (lldb_object_ptr=%p) => this.obj = %p ('%s')", lldb_object_ptr,
40 m_opaque_ptr, sstr.GetData());
41
Caroline Tice7826c882010-10-26 03:11:13 +000042 }
Chris Lattner24943d22010-06-08 16:52:24 +000043}
44
45SBFunction::~SBFunction ()
46{
Greg Clayton63094e02010-06-23 01:19:29 +000047 m_opaque_ptr = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000048}
49
50bool
51SBFunction::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 *
57SBFunction::GetName() const
58{
Caroline Tice7826c882010-10-26 03:11:13 +000059 Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
60
Caroline Tice61ba7ec2010-10-26 23:49:36 +000061 //if (log)
62 // log->Printf ("SBFunction::GetName ()");
Caroline Tice7826c882010-10-26 03:11:13 +000063
Greg Clayton63094e02010-06-23 01:19:29 +000064 if (m_opaque_ptr)
Caroline Tice7826c882010-10-26 03:11:13 +000065 {
66 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +000067 log->Printf ("SBFunction::GetName (this.obj=%p) => '%s'", m_opaque_ptr,
68 m_opaque_ptr->GetMangled().GetName().AsCString());
Greg Clayton63094e02010-06-23 01:19:29 +000069 return m_opaque_ptr->GetMangled().GetName().AsCString();
Caroline Tice7826c882010-10-26 03:11:13 +000070 }
71
72 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +000073 log->Printf ("SBFunction::GetName (this.obj=%p) => NULL", m_opaque_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +000074 return NULL;
75}
76
77const char *
78SBFunction::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
85bool
86SBFunction::operator == (const SBFunction &rhs) const
87{
Greg Clayton63094e02010-06-23 01:19:29 +000088 return m_opaque_ptr == rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000089}
90
91bool
92SBFunction::operator != (const SBFunction &rhs) const
93{
Greg Clayton63094e02010-06-23 01:19:29 +000094 return m_opaque_ptr != rhs.m_opaque_ptr;
Chris Lattner24943d22010-06-08 16:52:24 +000095}
Caroline Tice98f930f2010-09-20 05:20:02 +000096
97bool
Greg Claytond8c62532010-10-07 04:19:01 +000098SBFunction::GetDescription (SBStream &s)
Caroline Tice98f930f2010-09-20 05:20:02 +000099{
100 if (m_opaque_ptr)
101 {
Greg Claytond8c62532010-10-07 04:19:01 +0000102 s.Printf ("SBFunction: id = 0x%8.8x, name = %s",
103 m_opaque_ptr->GetID(),
104 m_opaque_ptr->GetName().AsCString());
105 Type *func_type = m_opaque_ptr->GetType();
106 if (func_type)
107 s.Printf(", type = %s", func_type->GetName().AsCString());
108 return true;
Caroline Tice98f930f2010-09-20 05:20:02 +0000109 }
Greg Claytond8c62532010-10-07 04:19:01 +0000110 s.Printf ("No value");
111 return false;
Caroline Tice98f930f2010-09-20 05:20:02 +0000112}
Greg Clayton5c4c7462010-10-06 03:09:58 +0000113
114SBInstructionList
115SBFunction::GetInstructions (SBTarget target)
116{
117 SBInstructionList sb_instructions;
118 if (m_opaque_ptr)
119 {
120 ExecutionContext exe_ctx;
121 if (target.IsValid())
122 {
123 target->CalculateExecutionContext (exe_ctx);
124 exe_ctx.process = target->GetProcessSP().get();
125 }
126 Module *module = m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule();
127 if (module)
128 {
129 sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture(),
130 exe_ctx,
131 m_opaque_ptr->GetAddressRange()));
132 }
133 }
134 return sb_instructions;
135}
136
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000137lldb_private::Function *
138SBFunction::get ()
139{
140 return m_opaque_ptr;
141}
Greg Clayton5c4c7462010-10-06 03:09:58 +0000142