Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBSymbolContext.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/SBSymbolContext.h" |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 11 | #include "lldb/API/SBStream.h" |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Log.h" |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 13 | #include "lldb/Symbol/Function.h" |
| 14 | #include "lldb/Symbol/Symbol.h" |
| 15 | #include "lldb/Symbol/SymbolContext.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | |
| 17 | using namespace lldb; |
| 18 | using namespace lldb_private; |
| 19 | |
| 20 | |
| 21 | |
| 22 | SBSymbolContext::SBSymbolContext () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 23 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | { |
| 25 | } |
| 26 | |
| 27 | SBSymbolContext::SBSymbolContext (const SymbolContext *sc_ptr) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 28 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | { |
| 30 | if (sc_ptr) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 31 | m_opaque_ap.reset (new SymbolContext (*sc_ptr)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | SBSymbolContext::SBSymbolContext (const SBSymbolContext& rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 35 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | { |
| 37 | if (rhs.IsValid()) |
Caroline Tice | e49ec18 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 38 | { |
| 39 | if (m_opaque_ap.get()) |
| 40 | *m_opaque_ap = *rhs.m_opaque_ap; |
| 41 | else |
| 42 | ref() = *rhs.m_opaque_ap; |
| 43 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | SBSymbolContext::~SBSymbolContext () |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | const SBSymbolContext & |
| 51 | SBSymbolContext::operator = (const SBSymbolContext &rhs) |
| 52 | { |
| 53 | if (this != &rhs) |
| 54 | { |
| 55 | if (rhs.IsValid()) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 56 | m_opaque_ap.reset (new lldb_private::SymbolContext(*rhs.m_opaque_ap.get())); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | } |
| 58 | return *this; |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | SBSymbolContext::SetSymbolContext (const SymbolContext *sc_ptr) |
| 63 | { |
| 64 | if (sc_ptr) |
| 65 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 66 | if (m_opaque_ap.get()) |
| 67 | *m_opaque_ap = *sc_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | else |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 69 | m_opaque_ap.reset (new SymbolContext (*sc_ptr)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | } |
| 71 | else |
| 72 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 73 | if (m_opaque_ap.get()) |
| 74 | m_opaque_ap->Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | bool |
| 79 | SBSymbolContext::IsValid () const |
| 80 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 81 | return m_opaque_ap.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
| 85 | |
| 86 | SBModule |
| 87 | SBSymbolContext::GetModule () |
| 88 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 89 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 90 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 91 | SBModule sb_module; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 92 | if (m_opaque_ap.get()) |
| 93 | sb_module.SetModule(m_opaque_ap->module_sp); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 94 | |
| 95 | if (log) |
| 96 | { |
| 97 | SBStream sstr; |
| 98 | sb_module.GetDescription (sstr); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 99 | log->Printf ("SBSymbolContext(%p)::GetModule () => SBModule(%p): %s", |
| 100 | m_opaque_ap.get(), sb_module.get(), sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | return sb_module; |
| 104 | } |
| 105 | |
| 106 | SBCompileUnit |
| 107 | SBSymbolContext::GetCompileUnit () |
| 108 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 109 | return SBCompileUnit (m_opaque_ap.get() ? m_opaque_ap->comp_unit : NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | SBFunction |
| 113 | SBSymbolContext::GetFunction () |
| 114 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 115 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 116 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 117 | Function *function = NULL; |
| 118 | |
| 119 | if (m_opaque_ap.get()) |
| 120 | function = m_opaque_ap->function; |
| 121 | |
| 122 | SBFunction sb_function (function); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 123 | |
| 124 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 125 | log->Printf ("SBSymbolContext(%p)::GetFunction () => SBFunction(%p)", |
| 126 | m_opaque_ap.get(), function); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 127 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 128 | return sb_function; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | SBBlock |
| 132 | SBSymbolContext::GetBlock () |
| 133 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 134 | return SBBlock (m_opaque_ap.get() ? m_opaque_ap->block : NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | SBLineEntry |
| 138 | SBSymbolContext::GetLineEntry () |
| 139 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 140 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 141 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | SBLineEntry sb_line_entry; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 143 | if (m_opaque_ap.get()) |
| 144 | sb_line_entry.SetLineEntry (m_opaque_ap->line_entry); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 146 | if (log) |
| 147 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 148 | log->Printf ("SBSymbolContext(%p)::GetLineEntry () => SBLineEntry(%p)", |
| 149 | m_opaque_ap.get(), sb_line_entry.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | return sb_line_entry; |
| 153 | } |
| 154 | |
| 155 | SBSymbol |
| 156 | SBSymbolContext::GetSymbol () |
| 157 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 158 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 159 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 160 | Symbol *symbol = NULL; |
| 161 | |
| 162 | if (m_opaque_ap.get()) |
| 163 | symbol = m_opaque_ap->symbol; |
| 164 | |
| 165 | SBSymbol sb_symbol (symbol); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 166 | |
| 167 | if (log) |
| 168 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 169 | log->Printf ("SBSymbolContext(%p)::GetSymbol () => SBSymbol(%p)", |
| 170 | m_opaque_ap.get(), symbol); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 173 | return sb_symbol; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | lldb_private::SymbolContext* |
| 177 | SBSymbolContext::operator->() const |
| 178 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 179 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 182 | |
| 183 | const lldb_private::SymbolContext& |
| 184 | SBSymbolContext::operator*() const |
| 185 | { |
| 186 | assert (m_opaque_ap.get()); |
| 187 | return *m_opaque_ap.get(); |
| 188 | } |
| 189 | |
| 190 | |
| 191 | lldb_private::SymbolContext& |
| 192 | SBSymbolContext::operator*() |
| 193 | { |
| 194 | if (m_opaque_ap.get() == NULL) |
| 195 | m_opaque_ap.reset (new SymbolContext); |
| 196 | return *m_opaque_ap.get(); |
| 197 | } |
| 198 | |
Caroline Tice | e49ec18 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 199 | lldb_private::SymbolContext& |
| 200 | SBSymbolContext::ref() |
| 201 | { |
| 202 | if (m_opaque_ap.get() == NULL) |
| 203 | m_opaque_ap.reset (new SymbolContext); |
| 204 | return *m_opaque_ap.get(); |
| 205 | } |
| 206 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | lldb_private::SymbolContext * |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 208 | SBSymbolContext::get() const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 210 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 213 | bool |
| 214 | SBSymbolContext::GetDescription (SBStream &description) |
| 215 | { |
| 216 | if (m_opaque_ap.get()) |
| 217 | { |
Caroline Tice | e49ec18 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 218 | description.ref(); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 219 | m_opaque_ap->GetDescription (description.get(), lldb::eDescriptionLevelFull, NULL); |
| 220 | } |
| 221 | else |
| 222 | description.Printf ("No value"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 223 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 224 | return true; |
| 225 | } |