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