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 | { |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 33 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 34 | |
| 35 | if (log) |
| 36 | { |
| 37 | SBStream sstr; |
| 38 | GetDescription (sstr); |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 39 | log->Printf ("SBFunction::SBFunction (lldb_object_ptr=%p) => this.obj = %p ('%s')", lldb_object_ptr, |
| 40 | m_opaque_ptr, sstr.GetData()); |
| 41 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 42 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | SBFunction::~SBFunction () |
| 46 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 47 | m_opaque_ptr = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | bool |
| 51 | SBFunction::IsValid () const |
| 52 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 53 | return m_opaque_ptr != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | const char * |
| 57 | SBFunction::GetName() const |
| 58 | { |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 59 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); |
| 60 | |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 61 | //if (log) |
| 62 | // log->Printf ("SBFunction::GetName ()"); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 63 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 64 | if (m_opaque_ptr) |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 65 | { |
| 66 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 67 | log->Printf ("SBFunction::GetName (this.obj=%p) => '%s'", m_opaque_ptr, |
| 68 | m_opaque_ptr->GetMangled().GetName().AsCString()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 69 | return m_opaque_ptr->GetMangled().GetName().AsCString(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | if (log) |
Caroline Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 73 | log->Printf ("SBFunction::GetName (this.obj=%p) => NULL", m_opaque_ptr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | return NULL; |
| 75 | } |
| 76 | |
| 77 | const char * |
| 78 | SBFunction::GetMangledName () const |
| 79 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 80 | if (m_opaque_ptr) |
| 81 | return m_opaque_ptr->GetMangled().GetMangledName().AsCString(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | return NULL; |
| 83 | } |
| 84 | |
| 85 | bool |
| 86 | SBFunction::operator == (const SBFunction &rhs) const |
| 87 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 88 | return m_opaque_ptr == rhs.m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | bool |
| 92 | SBFunction::operator != (const SBFunction &rhs) const |
| 93 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 94 | return m_opaque_ptr != rhs.m_opaque_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 95 | } |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 96 | |
| 97 | bool |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 98 | SBFunction::GetDescription (SBStream &s) |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 99 | { |
| 100 | if (m_opaque_ptr) |
| 101 | { |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 102 | 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 Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 109 | } |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 110 | s.Printf ("No value"); |
| 111 | return false; |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 112 | } |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 113 | |
| 114 | SBInstructionList |
| 115 | SBFunction::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 Tice | 61ba7ec | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 137 | lldb_private::Function * |
| 138 | SBFunction::get () |
| 139 | { |
| 140 | return m_opaque_ptr; |
| 141 | } |
Greg Clayton | 5c4c746 | 2010-10-06 03:09:58 +0000 | [diff] [blame] | 142 | |