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 | { |
| 28 | } |
| 29 | |
| 30 | SBFunction::SBFunction (lldb_private::Function *lldb_object_ptr) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 31 | m_opaque_ptr (lldb_object_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | { |
| 33 | } |
| 34 | |
| 35 | SBFunction::~SBFunction () |
| 36 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 37 | m_opaque_ptr = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | bool |
| 41 | SBFunction::IsValid () const |
| 42 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 43 | return m_opaque_ptr != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | const char * |
| 47 | SBFunction::GetName() const |
| 48 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame^] | 49 | const char *cstr = NULL; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 50 | if (m_opaque_ptr) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame^] | 51 | cstr = m_opaque_ptr->GetMangled().GetName().AsCString(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 52 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame^] | 53 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 54 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame^] | 55 | { |
| 56 | if (cstr) |
| 57 | log->Printf ("SBFunction(%p)::GetName () => \"%s\"", m_opaque_ptr, cstr); |
| 58 | else |
| 59 | log->Printf ("SBFunction(%p)::GetName () => NULL", m_opaque_ptr); |
| 60 | } |
| 61 | return cstr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | const char * |
| 65 | SBFunction::GetMangledName () const |
| 66 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame^] | 67 | const char *cstr = NULL; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 68 | if (m_opaque_ptr) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame^] | 69 | cstr = m_opaque_ptr->GetMangled().GetMangledName().AsCString(); |
| 70 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 71 | if (log) |
| 72 | { |
| 73 | if (cstr) |
| 74 | log->Printf ("SBFunction(%p)::GetMangledName () => \"%s\"", m_opaque_ptr, cstr); |
| 75 | else |
| 76 | log->Printf ("SBFunction(%p)::GetMangledName () => NULL", m_opaque_ptr); |
| 77 | } |
| 78 | return cstr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | bool |
| 82 | SBFunction::operator == (const SBFunction &rhs) const |
| 83 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 84 | return m_opaque_ptr == rhs.m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 92 | |
| 93 | bool |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 94 | SBFunction::GetDescription (SBStream &s) |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 95 | { |
| 96 | if (m_opaque_ptr) |
| 97 | { |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 98 | s.Printf ("SBFunction: id = 0x%8.8x, name = %s", |
| 99 | m_opaque_ptr->GetID(), |
| 100 | m_opaque_ptr->GetName().AsCString()); |
| 101 | Type *func_type = m_opaque_ptr->GetType(); |
| 102 | if (func_type) |
| 103 | s.Printf(", type = %s", func_type->GetName().AsCString()); |
| 104 | return true; |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 105 | } |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 106 | s.Printf ("No value"); |
| 107 | return false; |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 108 | } |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 109 | |
| 110 | SBInstructionList |
| 111 | SBFunction::GetInstructions (SBTarget target) |
| 112 | { |
| 113 | SBInstructionList sb_instructions; |
| 114 | if (m_opaque_ptr) |
| 115 | { |
| 116 | ExecutionContext exe_ctx; |
| 117 | if (target.IsValid()) |
| 118 | { |
| 119 | target->CalculateExecutionContext (exe_ctx); |
| 120 | exe_ctx.process = target->GetProcessSP().get(); |
| 121 | } |
| 122 | Module *module = m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule(); |
| 123 | if (module) |
| 124 | { |
| 125 | sb_instructions.SetDisassembler (Disassembler::DisassembleRange (module->GetArchitecture(), |
| 126 | exe_ctx, |
| 127 | m_opaque_ptr->GetAddressRange())); |
| 128 | } |
| 129 | } |
| 130 | return sb_instructions; |
| 131 | } |
| 132 | |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 133 | lldb_private::Function * |
| 134 | SBFunction::get () |
| 135 | { |
| 136 | return m_opaque_ptr; |
| 137 | } |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 138 | |