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 | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Module.h" |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/Function.h" |
| 15 | #include "lldb/Symbol/Symbol.h" |
| 16 | #include "lldb/Symbol/SymbolContext.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | |
| 22 | |
| 23 | SBSymbolContext::SBSymbolContext () : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 24 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | { |
| 26 | } |
| 27 | |
| 28 | SBSymbolContext::SBSymbolContext (const SymbolContext *sc_ptr) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 29 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | { |
| 31 | if (sc_ptr) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 32 | m_opaque_ap.reset (new SymbolContext (*sc_ptr)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | SBSymbolContext::SBSymbolContext (const SBSymbolContext& rhs) : |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 36 | m_opaque_ap () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | { |
| 38 | if (rhs.IsValid()) |
Caroline Tice | e49ec18 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 39 | { |
| 40 | if (m_opaque_ap.get()) |
| 41 | *m_opaque_ap = *rhs.m_opaque_ap; |
| 42 | else |
| 43 | ref() = *rhs.m_opaque_ap; |
| 44 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | SBSymbolContext::~SBSymbolContext () |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | const SBSymbolContext & |
| 52 | SBSymbolContext::operator = (const SBSymbolContext &rhs) |
| 53 | { |
| 54 | if (this != &rhs) |
| 55 | { |
| 56 | if (rhs.IsValid()) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 57 | 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] | 58 | } |
| 59 | return *this; |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | SBSymbolContext::SetSymbolContext (const SymbolContext *sc_ptr) |
| 64 | { |
| 65 | if (sc_ptr) |
| 66 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 67 | if (m_opaque_ap.get()) |
| 68 | *m_opaque_ap = *sc_ptr; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | else |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 70 | m_opaque_ap.reset (new SymbolContext (*sc_ptr)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | } |
| 72 | else |
| 73 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 74 | if (m_opaque_ap.get()) |
Greg Clayton | a7e864c | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 75 | m_opaque_ap->Clear(true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | bool |
| 80 | SBSymbolContext::IsValid () const |
| 81 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 82 | return m_opaque_ap.get() != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
| 86 | |
| 87 | SBModule |
| 88 | SBSymbolContext::GetModule () |
| 89 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 90 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | SBModule sb_module; |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 93 | ModuleSP module_sp; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 94 | if (m_opaque_ap.get()) |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 95 | { |
| 96 | module_sp = m_opaque_ap->module_sp; |
| 97 | sb_module.SetSP (module_sp); |
| 98 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 99 | |
| 100 | if (log) |
| 101 | { |
| 102 | SBStream sstr; |
| 103 | sb_module.GetDescription (sstr); |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 104 | log->Printf ("SBSymbolContext(%p)::GetModule () => SBModule(%p): %s", |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 105 | m_opaque_ap.get(), module_sp.get(), sstr.GetData()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | return sb_module; |
| 109 | } |
| 110 | |
| 111 | SBCompileUnit |
| 112 | SBSymbolContext::GetCompileUnit () |
| 113 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 114 | return SBCompileUnit (m_opaque_ap.get() ? m_opaque_ap->comp_unit : NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | SBFunction |
| 118 | SBSymbolContext::GetFunction () |
| 119 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 120 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 121 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 122 | Function *function = NULL; |
| 123 | |
| 124 | if (m_opaque_ap.get()) |
| 125 | function = m_opaque_ap->function; |
| 126 | |
| 127 | SBFunction sb_function (function); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 128 | |
| 129 | if (log) |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 130 | log->Printf ("SBSymbolContext(%p)::GetFunction () => SBFunction(%p)", |
| 131 | m_opaque_ap.get(), function); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 132 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 133 | return sb_function; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | SBBlock |
| 137 | SBSymbolContext::GetBlock () |
| 138 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 139 | return SBBlock (m_opaque_ap.get() ? m_opaque_ap->block : NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | SBLineEntry |
| 143 | SBSymbolContext::GetLineEntry () |
| 144 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 145 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 146 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 147 | SBLineEntry sb_line_entry; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 148 | if (m_opaque_ap.get()) |
| 149 | sb_line_entry.SetLineEntry (m_opaque_ap->line_entry); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 150 | |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 151 | if (log) |
| 152 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 153 | log->Printf ("SBSymbolContext(%p)::GetLineEntry () => SBLineEntry(%p)", |
| 154 | m_opaque_ap.get(), sb_line_entry.get()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 157 | return sb_line_entry; |
| 158 | } |
| 159 | |
| 160 | SBSymbol |
| 161 | SBSymbolContext::GetSymbol () |
| 162 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 163 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 164 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 165 | Symbol *symbol = NULL; |
| 166 | |
| 167 | if (m_opaque_ap.get()) |
| 168 | symbol = m_opaque_ap->symbol; |
| 169 | |
| 170 | SBSymbol sb_symbol (symbol); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 171 | |
| 172 | if (log) |
| 173 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 174 | log->Printf ("SBSymbolContext(%p)::GetSymbol () => SBSymbol(%p)", |
| 175 | m_opaque_ap.get(), symbol); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 178 | return sb_symbol; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 181 | void |
| 182 | SBSymbolContext::SetModule (lldb::SBModule module) |
| 183 | { |
Greg Clayton | 0416bdf | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 184 | ref().module_sp = module.GetSP(); |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | void |
| 188 | SBSymbolContext::SetCompileUnit (lldb::SBCompileUnit compile_unit) |
| 189 | { |
| 190 | ref().comp_unit = compile_unit.get(); |
| 191 | } |
| 192 | |
| 193 | void |
| 194 | SBSymbolContext::SetFunction (lldb::SBFunction function) |
| 195 | { |
| 196 | ref().function = function.get(); |
| 197 | } |
| 198 | |
| 199 | void |
| 200 | SBSymbolContext::SetBlock (lldb::SBBlock block) |
| 201 | { |
Greg Clayton | 7dd5c51 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 202 | ref().block = block.GetPtr(); |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void |
| 206 | SBSymbolContext::SetLineEntry (lldb::SBLineEntry line_entry) |
| 207 | { |
| 208 | if (line_entry.IsValid()) |
| 209 | ref().line_entry = line_entry.ref(); |
| 210 | else |
| 211 | ref().line_entry.Clear(); |
| 212 | } |
| 213 | |
| 214 | void |
| 215 | SBSymbolContext::SetSymbol (lldb::SBSymbol symbol) |
| 216 | { |
| 217 | ref().symbol = symbol.get(); |
| 218 | } |
| 219 | |
| 220 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | lldb_private::SymbolContext* |
| 222 | SBSymbolContext::operator->() const |
| 223 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 224 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 227 | |
| 228 | const lldb_private::SymbolContext& |
| 229 | SBSymbolContext::operator*() const |
| 230 | { |
| 231 | assert (m_opaque_ap.get()); |
| 232 | return *m_opaque_ap.get(); |
| 233 | } |
| 234 | |
| 235 | |
| 236 | lldb_private::SymbolContext& |
| 237 | SBSymbolContext::operator*() |
| 238 | { |
| 239 | if (m_opaque_ap.get() == NULL) |
| 240 | m_opaque_ap.reset (new SymbolContext); |
| 241 | return *m_opaque_ap.get(); |
| 242 | } |
| 243 | |
Caroline Tice | e49ec18 | 2010-09-22 23:01:29 +0000 | [diff] [blame] | 244 | lldb_private::SymbolContext& |
| 245 | SBSymbolContext::ref() |
| 246 | { |
| 247 | if (m_opaque_ap.get() == NULL) |
| 248 | m_opaque_ap.reset (new SymbolContext); |
| 249 | return *m_opaque_ap.get(); |
| 250 | } |
| 251 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | lldb_private::SymbolContext * |
Greg Clayton | 466f6c4 | 2010-09-10 18:31:35 +0000 | [diff] [blame] | 253 | SBSymbolContext::get() const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 254 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 255 | return m_opaque_ap.get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 258 | bool |
| 259 | SBSymbolContext::GetDescription (SBStream &description) |
| 260 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 261 | Stream &strm = description.ref(); |
| 262 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 263 | if (m_opaque_ap.get()) |
| 264 | { |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 265 | m_opaque_ap->GetDescription (&strm, lldb::eDescriptionLevelFull, NULL); |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 266 | } |
| 267 | else |
Greg Clayton | 96154be | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 268 | strm.PutCString ("No value"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 269 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 270 | return true; |
| 271 | } |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 272 | |
| 273 | SBSymbolContext |
Greg Clayton | 2f57db0 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 274 | SBSymbolContext::GetParentOfInlinedScope (const SBAddress &curr_frame_pc, |
| 275 | SBAddress &parent_frame_addr) const |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 276 | { |
| 277 | SBSymbolContext sb_sc; |
| 278 | if (m_opaque_ap.get() && curr_frame_pc.IsValid()) |
| 279 | { |
Greg Clayton | 2f57db0 | 2011-10-01 00:45:15 +0000 | [diff] [blame] | 280 | if (m_opaque_ap->GetParentOfInlinedScope (curr_frame_pc.ref(), sb_sc.ref(), parent_frame_addr.ref())) |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 281 | return sb_sc; |
| 282 | } |
| 283 | return SBSymbolContext(); |
| 284 | } |
| 285 | |