Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBStream.h" |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Disassembler.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame^] | 14 | #include "lldb/Core/Log.h" |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Module.h" |
| 16 | #include "lldb/Symbol/CompileUnit.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/Function.h" |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/Type.h" |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 19 | #include "lldb/Target/ExecutionContext.h" |
| 20 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace lldb; |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 23 | using namespace lldb_private; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
| 25 | SBFunction::SBFunction () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 26 | m_opaque_ptr (NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame^] | 28 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE); |
| 29 | |
| 30 | if (log) |
| 31 | log->Printf ("SBFunction::SBFunction () ==> this = %p", this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | SBFunction::SBFunction (lldb_private::Function *lldb_object_ptr) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 35 | m_opaque_ptr (lldb_object_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame^] | 37 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | SBFunction::~SBFunction () |
| 49 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 50 | m_opaque_ptr = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | bool |
| 54 | SBFunction::IsValid () const |
| 55 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 56 | return m_opaque_ptr != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | const char * |
| 60 | SBFunction::GetName() const |
| 61 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame^] | 62 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 63 | |
| 64 | if (log) |
| 65 | log->Printf ("SBFunction::GetName ()"); |
| 66 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 67 | if (m_opaque_ptr) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame^] | 68 | { |
| 69 | if (log) |
| 70 | log->Printf ("SBFunction::GetName ==> %s", m_opaque_ptr->GetMangled().GetName().AsCString()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 71 | return m_opaque_ptr->GetMangled().GetName().AsCString(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame^] | 72 | } |
| 73 | |
| 74 | if (log) |
| 75 | log->Printf ("SBFunction::GetName ==> NULL"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | return NULL; |
| 77 | } |
| 78 | |
| 79 | const char * |
| 80 | SBFunction::GetMangledName () const |
| 81 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 82 | if (m_opaque_ptr) |
| 83 | return m_opaque_ptr->GetMangled().GetMangledName().AsCString(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | return NULL; |
| 85 | } |
| 86 | |
| 87 | bool |
| 88 | SBFunction::operator == (const SBFunction &rhs) const |
| 89 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 90 | return m_opaque_ptr == rhs.m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | bool |
| 94 | SBFunction::operator != (const SBFunction &rhs) const |
| 95 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 96 | return m_opaque_ptr != rhs.m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 98 | |
| 99 | bool |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 100 | SBFunction::GetDescription (SBStream &s) |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 101 | { |
| 102 | if (m_opaque_ptr) |
| 103 | { |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 104 | 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 Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 111 | } |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 112 | s.Printf ("No value"); |
| 113 | return false; |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 114 | } |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 115 | |
| 116 | SBInstructionList |
| 117 | SBFunction::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 | |