1254721Semaste//===-- SBFrame.cpp ---------------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "lldb/API/SBFrame.h" 11254721Semaste 12254721Semaste#include <string> 13254721Semaste#include <algorithm> 14254721Semaste 15254721Semaste#include "lldb/lldb-types.h" 16254721Semaste 17254721Semaste#include "lldb/Core/Address.h" 18254721Semaste#include "lldb/Core/ConstString.h" 19254721Semaste#include "lldb/Core/Log.h" 20254721Semaste#include "lldb/Core/Stream.h" 21254721Semaste#include "lldb/Core/StreamFile.h" 22254721Semaste#include "lldb/Core/ValueObjectRegister.h" 23254721Semaste#include "lldb/Core/ValueObjectVariable.h" 24254721Semaste#include "lldb/Expression/ClangUserExpression.h" 25254721Semaste#include "lldb/Host/Host.h" 26254721Semaste#include "lldb/Symbol/Block.h" 27254721Semaste#include "lldb/Symbol/Function.h" 28254721Semaste#include "lldb/Symbol/Symbol.h" 29254721Semaste#include "lldb/Symbol/SymbolContext.h" 30254721Semaste#include "lldb/Symbol/VariableList.h" 31254721Semaste#include "lldb/Symbol/Variable.h" 32254721Semaste#include "lldb/Target/ExecutionContext.h" 33254721Semaste#include "lldb/Target/Target.h" 34254721Semaste#include "lldb/Target/Process.h" 35254721Semaste#include "lldb/Target/RegisterContext.h" 36254721Semaste#include "lldb/Target/StackFrame.h" 37254721Semaste#include "lldb/Target/StackID.h" 38254721Semaste#include "lldb/Target/Thread.h" 39254721Semaste 40254721Semaste#include "lldb/API/SBDebugger.h" 41254721Semaste#include "lldb/API/SBValue.h" 42254721Semaste#include "lldb/API/SBAddress.h" 43254721Semaste#include "lldb/API/SBExpressionOptions.h" 44254721Semaste#include "lldb/API/SBStream.h" 45254721Semaste#include "lldb/API/SBSymbolContext.h" 46254721Semaste#include "lldb/API/SBThread.h" 47254721Semaste 48254721Semasteusing namespace lldb; 49254721Semasteusing namespace lldb_private; 50254721Semaste 51254721Semaste 52254721SemasteSBFrame::SBFrame () : 53254721Semaste m_opaque_sp (new ExecutionContextRef()) 54254721Semaste{ 55254721Semaste} 56254721Semaste 57254721SemasteSBFrame::SBFrame (const StackFrameSP &lldb_object_sp) : 58254721Semaste m_opaque_sp (new ExecutionContextRef (lldb_object_sp)) 59254721Semaste{ 60254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 61254721Semaste 62254721Semaste if (log) 63254721Semaste { 64254721Semaste SBStream sstr; 65254721Semaste GetDescription (sstr); 66254721Semaste log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s", 67254721Semaste lldb_object_sp.get(), lldb_object_sp.get(), sstr.GetData()); 68254721Semaste 69254721Semaste } 70254721Semaste} 71254721Semaste 72254721SemasteSBFrame::SBFrame(const SBFrame &rhs) : 73254721Semaste m_opaque_sp (new ExecutionContextRef (*rhs.m_opaque_sp)) 74254721Semaste{ 75254721Semaste} 76254721Semaste 77254721Semasteconst SBFrame & 78254721SemasteSBFrame::operator = (const SBFrame &rhs) 79254721Semaste{ 80254721Semaste if (this != &rhs) 81254721Semaste *m_opaque_sp = *rhs.m_opaque_sp; 82254721Semaste return *this; 83254721Semaste} 84254721Semaste 85254721SemasteSBFrame::~SBFrame() 86254721Semaste{ 87254721Semaste} 88254721Semaste 89254721SemasteStackFrameSP 90254721SemasteSBFrame::GetFrameSP() const 91254721Semaste{ 92254721Semaste if (m_opaque_sp) 93254721Semaste return m_opaque_sp->GetFrameSP(); 94254721Semaste return StackFrameSP(); 95254721Semaste} 96254721Semaste 97254721Semastevoid 98254721SemasteSBFrame::SetFrameSP (const StackFrameSP &lldb_object_sp) 99254721Semaste{ 100254721Semaste return m_opaque_sp->SetFrameSP(lldb_object_sp); 101254721Semaste} 102254721Semaste 103254721Semastebool 104254721SemasteSBFrame::IsValid() const 105254721Semaste{ 106254721Semaste return GetFrameSP().get() != NULL; 107254721Semaste} 108254721Semaste 109254721SemasteSBSymbolContext 110254721SemasteSBFrame::GetSymbolContext (uint32_t resolve_scope) const 111254721Semaste{ 112254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 113254721Semaste SBSymbolContext sb_sym_ctx; 114254721Semaste Mutex::Locker api_locker; 115254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 116254721Semaste 117254721Semaste StackFrame *frame = NULL; 118254721Semaste Target *target = exe_ctx.GetTargetPtr(); 119254721Semaste Process *process = exe_ctx.GetProcessPtr(); 120254721Semaste if (target && process) 121254721Semaste { 122254721Semaste Process::StopLocker stop_locker; 123254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 124254721Semaste { 125254721Semaste frame = exe_ctx.GetFramePtr(); 126254721Semaste if (frame) 127254721Semaste { 128254721Semaste sb_sym_ctx.SetSymbolContext(&frame->GetSymbolContext (resolve_scope)); 129254721Semaste } 130254721Semaste else 131254721Semaste { 132254721Semaste if (log) 133254721Semaste log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame."); 134254721Semaste } 135254721Semaste } 136254721Semaste else 137254721Semaste { 138254721Semaste if (log) 139254721Semaste log->Printf ("SBFrame::GetSymbolContext () => error: process is running"); 140254721Semaste } 141254721Semaste } 142254721Semaste 143254721Semaste if (log) 144254721Semaste log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)", 145254721Semaste frame, resolve_scope, sb_sym_ctx.get()); 146254721Semaste 147254721Semaste return sb_sym_ctx; 148254721Semaste} 149254721Semaste 150254721SemasteSBModule 151254721SemasteSBFrame::GetModule () const 152254721Semaste{ 153254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 154254721Semaste SBModule sb_module; 155254721Semaste ModuleSP module_sp; 156254721Semaste Mutex::Locker api_locker; 157254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 158254721Semaste 159254721Semaste StackFrame *frame = NULL; 160254721Semaste Target *target = exe_ctx.GetTargetPtr(); 161254721Semaste Process *process = exe_ctx.GetProcessPtr(); 162254721Semaste if (target && process) 163254721Semaste { 164254721Semaste Process::StopLocker stop_locker; 165254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 166254721Semaste { 167254721Semaste frame = exe_ctx.GetFramePtr(); 168254721Semaste if (frame) 169254721Semaste { 170254721Semaste module_sp = frame->GetSymbolContext (eSymbolContextModule).module_sp; 171254721Semaste sb_module.SetSP (module_sp); 172254721Semaste } 173254721Semaste else 174254721Semaste { 175254721Semaste if (log) 176254721Semaste log->Printf ("SBFrame::GetModule () => error: could not reconstruct frame object for this SBFrame."); 177254721Semaste } 178254721Semaste } 179254721Semaste else 180254721Semaste { 181254721Semaste if (log) 182254721Semaste log->Printf ("SBFrame::GetModule () => error: process is running"); 183254721Semaste } 184254721Semaste } 185254721Semaste 186254721Semaste if (log) 187254721Semaste log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)", 188254721Semaste frame, module_sp.get()); 189254721Semaste 190254721Semaste return sb_module; 191254721Semaste} 192254721Semaste 193254721SemasteSBCompileUnit 194254721SemasteSBFrame::GetCompileUnit () const 195254721Semaste{ 196254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 197254721Semaste SBCompileUnit sb_comp_unit; 198254721Semaste Mutex::Locker api_locker; 199254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 200254721Semaste 201254721Semaste StackFrame *frame = NULL; 202254721Semaste Target *target = exe_ctx.GetTargetPtr(); 203254721Semaste Process *process = exe_ctx.GetProcessPtr(); 204254721Semaste if (target && process) 205254721Semaste { 206254721Semaste Process::StopLocker stop_locker; 207254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 208254721Semaste { 209254721Semaste frame = exe_ctx.GetFramePtr(); 210254721Semaste if (frame) 211254721Semaste { 212254721Semaste sb_comp_unit.reset (frame->GetSymbolContext (eSymbolContextCompUnit).comp_unit); 213254721Semaste } 214254721Semaste else 215254721Semaste { 216254721Semaste if (log) 217254721Semaste log->Printf ("SBFrame::GetCompileUnit () => error: could not reconstruct frame object for this SBFrame."); 218254721Semaste } 219254721Semaste } 220254721Semaste else 221254721Semaste { 222254721Semaste if (log) 223254721Semaste log->Printf ("SBFrame::GetCompileUnit () => error: process is running"); 224254721Semaste } 225254721Semaste } 226254721Semaste if (log) 227254721Semaste log->Printf ("SBFrame(%p)::GetCompileUnit () => SBCompileUnit(%p)", 228254721Semaste frame, sb_comp_unit.get()); 229254721Semaste 230254721Semaste return sb_comp_unit; 231254721Semaste} 232254721Semaste 233254721SemasteSBFunction 234254721SemasteSBFrame::GetFunction () const 235254721Semaste{ 236254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 237254721Semaste SBFunction sb_function; 238254721Semaste Mutex::Locker api_locker; 239254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 240254721Semaste 241254721Semaste StackFrame *frame = NULL; 242254721Semaste Target *target = exe_ctx.GetTargetPtr(); 243254721Semaste Process *process = exe_ctx.GetProcessPtr(); 244254721Semaste if (target && process) 245254721Semaste { 246254721Semaste Process::StopLocker stop_locker; 247254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 248254721Semaste { 249254721Semaste frame = exe_ctx.GetFramePtr(); 250254721Semaste if (frame) 251254721Semaste { 252254721Semaste sb_function.reset(frame->GetSymbolContext (eSymbolContextFunction).function); 253254721Semaste } 254254721Semaste else 255254721Semaste { 256254721Semaste if (log) 257254721Semaste log->Printf ("SBFrame::GetFunction () => error: could not reconstruct frame object for this SBFrame."); 258254721Semaste } 259254721Semaste } 260254721Semaste else 261254721Semaste { 262254721Semaste if (log) 263254721Semaste log->Printf ("SBFrame::GetFunction () => error: process is running"); 264254721Semaste } 265254721Semaste } 266254721Semaste if (log) 267254721Semaste log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", 268254721Semaste frame, sb_function.get()); 269254721Semaste 270254721Semaste return sb_function; 271254721Semaste} 272254721Semaste 273254721SemasteSBSymbol 274254721SemasteSBFrame::GetSymbol () const 275254721Semaste{ 276254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 277254721Semaste SBSymbol sb_symbol; 278254721Semaste Mutex::Locker api_locker; 279254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 280254721Semaste 281254721Semaste StackFrame *frame = NULL; 282254721Semaste Target *target = exe_ctx.GetTargetPtr(); 283254721Semaste Process *process = exe_ctx.GetProcessPtr(); 284254721Semaste if (target && process) 285254721Semaste { 286254721Semaste Process::StopLocker stop_locker; 287254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 288254721Semaste { 289254721Semaste frame = exe_ctx.GetFramePtr(); 290254721Semaste if (frame) 291254721Semaste { 292254721Semaste sb_symbol.reset(frame->GetSymbolContext (eSymbolContextSymbol).symbol); 293254721Semaste } 294254721Semaste else 295254721Semaste { 296254721Semaste if (log) 297254721Semaste log->Printf ("SBFrame::GetSymbol () => error: could not reconstruct frame object for this SBFrame."); 298254721Semaste } 299254721Semaste } 300254721Semaste else 301254721Semaste { 302254721Semaste if (log) 303254721Semaste log->Printf ("SBFrame::GetSymbol () => error: process is running"); 304254721Semaste } 305254721Semaste } 306254721Semaste if (log) 307254721Semaste log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", 308254721Semaste frame, sb_symbol.get()); 309254721Semaste return sb_symbol; 310254721Semaste} 311254721Semaste 312254721SemasteSBBlock 313254721SemasteSBFrame::GetBlock () const 314254721Semaste{ 315254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 316254721Semaste SBBlock sb_block; 317254721Semaste Mutex::Locker api_locker; 318254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 319254721Semaste 320254721Semaste StackFrame *frame = NULL; 321254721Semaste Target *target = exe_ctx.GetTargetPtr(); 322254721Semaste Process *process = exe_ctx.GetProcessPtr(); 323254721Semaste if (target && process) 324254721Semaste { 325254721Semaste Process::StopLocker stop_locker; 326254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 327254721Semaste { 328254721Semaste frame = exe_ctx.GetFramePtr(); 329254721Semaste if (frame) 330254721Semaste { 331254721Semaste sb_block.SetPtr (frame->GetSymbolContext (eSymbolContextBlock).block); 332254721Semaste } 333254721Semaste else 334254721Semaste { 335254721Semaste if (log) 336254721Semaste log->Printf ("SBFrame::GetBlock () => error: could not reconstruct frame object for this SBFrame."); 337254721Semaste } 338254721Semaste } 339254721Semaste else 340254721Semaste { 341254721Semaste if (log) 342254721Semaste log->Printf ("SBFrame(%p)::GetBlock () => error: process is running", frame); 343254721Semaste } 344254721Semaste } 345254721Semaste if (log) 346254721Semaste log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", 347254721Semaste frame, sb_block.GetPtr()); 348254721Semaste return sb_block; 349254721Semaste} 350254721Semaste 351254721SemasteSBBlock 352254721SemasteSBFrame::GetFrameBlock () const 353254721Semaste{ 354254721Semaste SBBlock sb_block; 355254721Semaste Mutex::Locker api_locker; 356254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 357254721Semaste 358254721Semaste StackFrame *frame = NULL; 359254721Semaste Target *target = exe_ctx.GetTargetPtr(); 360254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 361254721Semaste Process *process = exe_ctx.GetProcessPtr(); 362254721Semaste if (target && process) 363254721Semaste { 364254721Semaste Process::StopLocker stop_locker; 365254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 366254721Semaste { 367254721Semaste frame = exe_ctx.GetFramePtr(); 368254721Semaste if (frame) 369254721Semaste { 370254721Semaste sb_block.SetPtr(frame->GetFrameBlock ()); 371254721Semaste } 372254721Semaste else 373254721Semaste { 374254721Semaste if (log) 375254721Semaste log->Printf ("SBFrame::GetFrameBlock () => error: could not reconstruct frame object for this SBFrame."); 376254721Semaste } 377254721Semaste } 378254721Semaste else 379254721Semaste { 380254721Semaste if (log) 381254721Semaste log->Printf ("SBFrame::GetFrameBlock () => error: process is running"); 382254721Semaste } 383254721Semaste } 384254721Semaste if (log) 385254721Semaste log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", 386254721Semaste frame, sb_block.GetPtr()); 387254721Semaste return sb_block; 388254721Semaste} 389254721Semaste 390254721SemasteSBLineEntry 391254721SemasteSBFrame::GetLineEntry () const 392254721Semaste{ 393254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 394254721Semaste SBLineEntry sb_line_entry; 395254721Semaste Mutex::Locker api_locker; 396254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 397254721Semaste 398254721Semaste StackFrame *frame = NULL; 399254721Semaste Target *target = exe_ctx.GetTargetPtr(); 400254721Semaste Process *process = exe_ctx.GetProcessPtr(); 401254721Semaste if (target && process) 402254721Semaste { 403254721Semaste Process::StopLocker stop_locker; 404254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 405254721Semaste { 406254721Semaste frame = exe_ctx.GetFramePtr(); 407254721Semaste if (frame) 408254721Semaste { 409254721Semaste sb_line_entry.SetLineEntry (frame->GetSymbolContext (eSymbolContextLineEntry).line_entry); 410254721Semaste } 411254721Semaste else 412254721Semaste { 413254721Semaste if (log) 414254721Semaste log->Printf ("SBFrame::GetLineEntry () => error: could not reconstruct frame object for this SBFrame."); 415254721Semaste } 416254721Semaste } 417254721Semaste else 418254721Semaste { 419254721Semaste if (log) 420254721Semaste log->Printf ("SBFrame::GetLineEntry () => error: process is running"); 421254721Semaste } 422254721Semaste } 423254721Semaste if (log) 424254721Semaste log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", 425254721Semaste frame, sb_line_entry.get()); 426254721Semaste return sb_line_entry; 427254721Semaste} 428254721Semaste 429254721Semasteuint32_t 430254721SemasteSBFrame::GetFrameID () const 431254721Semaste{ 432254721Semaste uint32_t frame_idx = UINT32_MAX; 433254721Semaste 434254721Semaste ExecutionContext exe_ctx(m_opaque_sp.get()); 435254721Semaste StackFrame *frame = exe_ctx.GetFramePtr(); 436254721Semaste if (frame) 437254721Semaste frame_idx = frame->GetFrameIndex (); 438254721Semaste 439254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 440254721Semaste if (log) 441254721Semaste log->Printf ("SBFrame(%p)::GetFrameID () => %u", 442254721Semaste frame, frame_idx); 443254721Semaste return frame_idx; 444254721Semaste} 445254721Semaste 446254721Semasteaddr_t 447254721SemasteSBFrame::GetPC () const 448254721Semaste{ 449254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 450254721Semaste addr_t addr = LLDB_INVALID_ADDRESS; 451254721Semaste Mutex::Locker api_locker; 452254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 453254721Semaste 454254721Semaste StackFrame *frame = NULL; 455254721Semaste Target *target = exe_ctx.GetTargetPtr(); 456254721Semaste Process *process = exe_ctx.GetProcessPtr(); 457254721Semaste if (target && process) 458254721Semaste { 459254721Semaste Process::StopLocker stop_locker; 460254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 461254721Semaste { 462254721Semaste frame = exe_ctx.GetFramePtr(); 463254721Semaste if (frame) 464254721Semaste { 465254721Semaste addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress (target); 466254721Semaste } 467254721Semaste else 468254721Semaste { 469254721Semaste if (log) 470254721Semaste log->Printf ("SBFrame::GetPC () => error: could not reconstruct frame object for this SBFrame."); 471254721Semaste } 472254721Semaste } 473254721Semaste else 474254721Semaste { 475254721Semaste if (log) 476254721Semaste log->Printf ("SBFrame::GetPC () => error: process is running"); 477254721Semaste } 478254721Semaste } 479254721Semaste 480254721Semaste if (log) 481254721Semaste log->Printf ("SBFrame(%p)::GetPC () => 0x%" PRIx64, frame, addr); 482254721Semaste 483254721Semaste return addr; 484254721Semaste} 485254721Semaste 486254721Semastebool 487254721SemasteSBFrame::SetPC (addr_t new_pc) 488254721Semaste{ 489254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 490254721Semaste bool ret_val = false; 491254721Semaste Mutex::Locker api_locker; 492254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 493254721Semaste 494254721Semaste StackFrame *frame = NULL; 495254721Semaste Target *target = exe_ctx.GetTargetPtr(); 496254721Semaste Process *process = exe_ctx.GetProcessPtr(); 497254721Semaste if (target && process) 498254721Semaste { 499254721Semaste Process::StopLocker stop_locker; 500254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 501254721Semaste { 502254721Semaste frame = exe_ctx.GetFramePtr(); 503254721Semaste if (frame) 504254721Semaste { 505254721Semaste ret_val = frame->GetRegisterContext()->SetPC (new_pc); 506254721Semaste } 507254721Semaste else 508254721Semaste { 509254721Semaste if (log) 510254721Semaste log->Printf ("SBFrame::SetPC () => error: could not reconstruct frame object for this SBFrame."); 511254721Semaste } 512254721Semaste } 513254721Semaste else 514254721Semaste { 515254721Semaste if (log) 516254721Semaste log->Printf ("SBFrame::SetPC () => error: process is running"); 517254721Semaste } 518254721Semaste } 519254721Semaste 520254721Semaste if (log) 521254721Semaste log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%" PRIx64 ") => %i", 522254721Semaste frame, new_pc, ret_val); 523254721Semaste 524254721Semaste return ret_val; 525254721Semaste} 526254721Semaste 527254721Semasteaddr_t 528254721SemasteSBFrame::GetSP () const 529254721Semaste{ 530254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 531254721Semaste addr_t addr = LLDB_INVALID_ADDRESS; 532254721Semaste Mutex::Locker api_locker; 533254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 534254721Semaste 535254721Semaste StackFrame *frame = NULL; 536254721Semaste Target *target = exe_ctx.GetTargetPtr(); 537254721Semaste Process *process = exe_ctx.GetProcessPtr(); 538254721Semaste if (target && process) 539254721Semaste { 540254721Semaste Process::StopLocker stop_locker; 541254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 542254721Semaste { 543254721Semaste frame = exe_ctx.GetFramePtr(); 544254721Semaste if (frame) 545254721Semaste { 546254721Semaste addr = frame->GetRegisterContext()->GetSP(); 547254721Semaste } 548254721Semaste else 549254721Semaste { 550254721Semaste if (log) 551254721Semaste log->Printf ("SBFrame::GetSP () => error: could not reconstruct frame object for this SBFrame."); 552254721Semaste } 553254721Semaste } 554254721Semaste else 555254721Semaste { 556254721Semaste if (log) 557254721Semaste log->Printf ("SBFrame::GetSP () => error: process is running"); 558254721Semaste } 559254721Semaste } 560254721Semaste if (log) 561254721Semaste log->Printf ("SBFrame(%p)::GetSP () => 0x%" PRIx64, frame, addr); 562254721Semaste 563254721Semaste return addr; 564254721Semaste} 565254721Semaste 566254721Semaste 567254721Semasteaddr_t 568254721SemasteSBFrame::GetFP () const 569254721Semaste{ 570254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 571254721Semaste addr_t addr = LLDB_INVALID_ADDRESS; 572254721Semaste Mutex::Locker api_locker; 573254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 574254721Semaste 575254721Semaste StackFrame *frame = NULL; 576254721Semaste Target *target = exe_ctx.GetTargetPtr(); 577254721Semaste Process *process = exe_ctx.GetProcessPtr(); 578254721Semaste if (target && process) 579254721Semaste { 580254721Semaste Process::StopLocker stop_locker; 581254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 582254721Semaste { 583254721Semaste frame = exe_ctx.GetFramePtr(); 584254721Semaste if (frame) 585254721Semaste { 586254721Semaste addr = frame->GetRegisterContext()->GetFP(); 587254721Semaste } 588254721Semaste else 589254721Semaste { 590254721Semaste if (log) 591254721Semaste log->Printf ("SBFrame::GetFP () => error: could not reconstruct frame object for this SBFrame."); 592254721Semaste } 593254721Semaste } 594254721Semaste else 595254721Semaste { 596254721Semaste if (log) 597254721Semaste log->Printf ("SBFrame::GetFP () => error: process is running"); 598254721Semaste } 599254721Semaste } 600254721Semaste 601254721Semaste if (log) 602254721Semaste log->Printf ("SBFrame(%p)::GetFP () => 0x%" PRIx64, frame, addr); 603254721Semaste return addr; 604254721Semaste} 605254721Semaste 606254721Semaste 607254721SemasteSBAddress 608254721SemasteSBFrame::GetPCAddress () const 609254721Semaste{ 610254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 611254721Semaste SBAddress sb_addr; 612254721Semaste Mutex::Locker api_locker; 613254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 614254721Semaste 615254721Semaste StackFrame *frame = exe_ctx.GetFramePtr(); 616254721Semaste Target *target = exe_ctx.GetTargetPtr(); 617254721Semaste Process *process = exe_ctx.GetProcessPtr(); 618254721Semaste if (target && process) 619254721Semaste { 620254721Semaste Process::StopLocker stop_locker; 621254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 622254721Semaste { 623254721Semaste frame = exe_ctx.GetFramePtr(); 624254721Semaste if (frame) 625254721Semaste { 626254721Semaste sb_addr.SetAddress (&frame->GetFrameCodeAddress()); 627254721Semaste } 628254721Semaste else 629254721Semaste { 630254721Semaste if (log) 631254721Semaste log->Printf ("SBFrame::GetPCAddress () => error: could not reconstruct frame object for this SBFrame."); 632254721Semaste } 633254721Semaste } 634254721Semaste else 635254721Semaste { 636254721Semaste if (log) 637254721Semaste log->Printf ("SBFrame::GetPCAddress () => error: process is running"); 638254721Semaste } 639254721Semaste } 640254721Semaste if (log) 641254721Semaste log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", frame, sb_addr.get()); 642254721Semaste return sb_addr; 643254721Semaste} 644254721Semaste 645254721Semastevoid 646254721SemasteSBFrame::Clear() 647254721Semaste{ 648254721Semaste m_opaque_sp->Clear(); 649254721Semaste} 650254721Semaste 651254721Semastelldb::SBValue 652254721SemasteSBFrame::GetValueForVariablePath (const char *var_path) 653254721Semaste{ 654254721Semaste SBValue sb_value; 655254721Semaste ExecutionContext exe_ctx(m_opaque_sp.get()); 656254721Semaste StackFrame *frame = exe_ctx.GetFramePtr(); 657254721Semaste Target *target = exe_ctx.GetTargetPtr(); 658254721Semaste if (frame && target) 659254721Semaste { 660254721Semaste lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 661254721Semaste sb_value = GetValueForVariablePath (var_path, use_dynamic); 662254721Semaste } 663254721Semaste return sb_value; 664254721Semaste} 665254721Semaste 666254721Semastelldb::SBValue 667254721SemasteSBFrame::GetValueForVariablePath (const char *var_path, DynamicValueType use_dynamic) 668254721Semaste{ 669254721Semaste SBValue sb_value; 670254721Semaste Mutex::Locker api_locker; 671254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 672254721Semaste if (var_path == NULL || var_path[0] == '\0') 673254721Semaste { 674254721Semaste if (log) 675254721Semaste log->Printf ("SBFrame::GetValueForVariablePath called with empty variable path."); 676254721Semaste return sb_value; 677254721Semaste } 678254721Semaste 679254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 680254721Semaste 681254721Semaste StackFrame *frame = NULL; 682254721Semaste Target *target = exe_ctx.GetTargetPtr(); 683254721Semaste Process *process = exe_ctx.GetProcessPtr(); 684254721Semaste if (target && process) 685254721Semaste { 686254721Semaste Process::StopLocker stop_locker; 687254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 688254721Semaste { 689254721Semaste frame = exe_ctx.GetFramePtr(); 690254721Semaste if (frame) 691254721Semaste { 692254721Semaste VariableSP var_sp; 693254721Semaste Error error; 694254721Semaste ValueObjectSP value_sp (frame->GetValueForVariableExpressionPath (var_path, 695254721Semaste eNoDynamicValues, 696254721Semaste StackFrame::eExpressionPathOptionCheckPtrVsMember | StackFrame::eExpressionPathOptionsAllowDirectIVarAccess, 697254721Semaste var_sp, 698254721Semaste error)); 699254721Semaste sb_value.SetSP(value_sp, use_dynamic); 700254721Semaste } 701254721Semaste else 702254721Semaste { 703254721Semaste if (log) 704254721Semaste log->Printf ("SBFrame::GetValueForVariablePath () => error: could not reconstruct frame object for this SBFrame."); 705254721Semaste } 706254721Semaste } 707254721Semaste else 708254721Semaste { 709254721Semaste if (log) 710254721Semaste log->Printf ("SBFrame::GetValueForVariablePath () => error: process is running"); 711254721Semaste } 712254721Semaste } 713254721Semaste return sb_value; 714254721Semaste} 715254721Semaste 716254721SemasteSBValue 717254721SemasteSBFrame::FindVariable (const char *name) 718254721Semaste{ 719254721Semaste SBValue value; 720254721Semaste ExecutionContext exe_ctx(m_opaque_sp.get()); 721254721Semaste StackFrame *frame = exe_ctx.GetFramePtr(); 722254721Semaste Target *target = exe_ctx.GetTargetPtr(); 723254721Semaste if (frame && target) 724254721Semaste { 725254721Semaste lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 726254721Semaste value = FindVariable (name, use_dynamic); 727254721Semaste } 728254721Semaste return value; 729254721Semaste} 730254721Semaste 731254721Semaste 732254721SemasteSBValue 733254721SemasteSBFrame::FindVariable (const char *name, lldb::DynamicValueType use_dynamic) 734254721Semaste{ 735254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 736254721Semaste VariableSP var_sp; 737254721Semaste SBValue sb_value; 738254721Semaste 739254721Semaste if (name == NULL || name[0] == '\0') 740254721Semaste { 741254721Semaste if (log) 742254721Semaste log->Printf ("SBFrame::FindVariable called with empty name"); 743254721Semaste return sb_value; 744254721Semaste } 745254721Semaste 746254721Semaste ValueObjectSP value_sp; 747254721Semaste Mutex::Locker api_locker; 748254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 749254721Semaste 750254721Semaste StackFrame *frame = NULL; 751254721Semaste Target *target = exe_ctx.GetTargetPtr(); 752254721Semaste Process *process = exe_ctx.GetProcessPtr(); 753254721Semaste if (target && process) 754254721Semaste { 755254721Semaste Process::StopLocker stop_locker; 756254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 757254721Semaste { 758254721Semaste frame = exe_ctx.GetFramePtr(); 759254721Semaste if (frame) 760254721Semaste { 761254721Semaste VariableList variable_list; 762254721Semaste SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); 763254721Semaste 764254721Semaste if (sc.block) 765254721Semaste { 766254721Semaste const bool can_create = true; 767254721Semaste const bool get_parent_variables = true; 768254721Semaste const bool stop_if_block_is_inlined_function = true; 769254721Semaste 770254721Semaste if (sc.block->AppendVariables (can_create, 771254721Semaste get_parent_variables, 772254721Semaste stop_if_block_is_inlined_function, 773254721Semaste &variable_list)) 774254721Semaste { 775254721Semaste var_sp = variable_list.FindVariable (ConstString(name)); 776254721Semaste } 777254721Semaste } 778254721Semaste 779254721Semaste if (var_sp) 780254721Semaste { 781254721Semaste value_sp = frame->GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); 782254721Semaste sb_value.SetSP(value_sp, use_dynamic); 783254721Semaste } 784254721Semaste } 785254721Semaste else 786254721Semaste { 787254721Semaste if (log) 788254721Semaste log->Printf ("SBFrame::FindVariable () => error: could not reconstruct frame object for this SBFrame."); 789254721Semaste } 790254721Semaste } 791254721Semaste else 792254721Semaste { 793254721Semaste if (log) 794254721Semaste log->Printf ("SBFrame::FindVariable () => error: process is running"); 795254721Semaste } 796254721Semaste } 797254721Semaste 798254721Semaste if (log) 799254721Semaste log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)", 800254721Semaste frame, name, value_sp.get()); 801254721Semaste 802254721Semaste return sb_value; 803254721Semaste} 804254721Semaste 805254721SemasteSBValue 806254721SemasteSBFrame::FindValue (const char *name, ValueType value_type) 807254721Semaste{ 808254721Semaste SBValue value; 809254721Semaste ExecutionContext exe_ctx(m_opaque_sp.get()); 810254721Semaste StackFrame *frame = exe_ctx.GetFramePtr(); 811254721Semaste Target *target = exe_ctx.GetTargetPtr(); 812254721Semaste if (frame && target) 813254721Semaste { 814254721Semaste lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 815254721Semaste value = FindValue (name, value_type, use_dynamic); 816254721Semaste } 817254721Semaste return value; 818254721Semaste} 819254721Semaste 820254721SemasteSBValue 821254721SemasteSBFrame::FindValue (const char *name, ValueType value_type, lldb::DynamicValueType use_dynamic) 822254721Semaste{ 823254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 824254721Semaste SBValue sb_value; 825254721Semaste 826254721Semaste if (name == NULL || name[0] == '\0') 827254721Semaste { 828254721Semaste if (log) 829254721Semaste log->Printf ("SBFrame::FindValue called with empty name."); 830254721Semaste return sb_value; 831254721Semaste } 832254721Semaste 833254721Semaste ValueObjectSP value_sp; 834254721Semaste Mutex::Locker api_locker; 835254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 836254721Semaste 837254721Semaste StackFrame *frame = NULL; 838254721Semaste Target *target = exe_ctx.GetTargetPtr(); 839254721Semaste Process *process = exe_ctx.GetProcessPtr(); 840254721Semaste if (target && process) 841254721Semaste { 842254721Semaste Process::StopLocker stop_locker; 843254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 844254721Semaste { 845254721Semaste frame = exe_ctx.GetFramePtr(); 846254721Semaste if (frame) 847254721Semaste { 848254721Semaste switch (value_type) 849254721Semaste { 850254721Semaste case eValueTypeVariableGlobal: // global variable 851254721Semaste case eValueTypeVariableStatic: // static variable 852254721Semaste case eValueTypeVariableArgument: // function argument variables 853254721Semaste case eValueTypeVariableLocal: // function local variables 854254721Semaste { 855254721Semaste VariableList *variable_list = frame->GetVariableList(true); 856254721Semaste 857254721Semaste SymbolContext sc (frame->GetSymbolContext (eSymbolContextBlock)); 858254721Semaste 859254721Semaste const bool can_create = true; 860254721Semaste const bool get_parent_variables = true; 861254721Semaste const bool stop_if_block_is_inlined_function = true; 862254721Semaste 863254721Semaste if (sc.block && sc.block->AppendVariables (can_create, 864254721Semaste get_parent_variables, 865254721Semaste stop_if_block_is_inlined_function, 866254721Semaste variable_list)) 867254721Semaste { 868254721Semaste ConstString const_name(name); 869254721Semaste const uint32_t num_variables = variable_list->GetSize(); 870254721Semaste for (uint32_t i = 0; i < num_variables; ++i) 871254721Semaste { 872254721Semaste VariableSP variable_sp (variable_list->GetVariableAtIndex(i)); 873254721Semaste if (variable_sp && 874254721Semaste variable_sp->GetScope() == value_type && 875254721Semaste variable_sp->GetName() == const_name) 876254721Semaste { 877254721Semaste value_sp = frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues); 878254721Semaste sb_value.SetSP (value_sp, use_dynamic); 879254721Semaste break; 880254721Semaste } 881254721Semaste } 882254721Semaste } 883254721Semaste } 884254721Semaste break; 885254721Semaste 886254721Semaste case eValueTypeRegister: // stack frame register value 887254721Semaste { 888254721Semaste RegisterContextSP reg_ctx (frame->GetRegisterContext()); 889254721Semaste if (reg_ctx) 890254721Semaste { 891254721Semaste const uint32_t num_regs = reg_ctx->GetRegisterCount(); 892254721Semaste for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 893254721Semaste { 894254721Semaste const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 895254721Semaste if (reg_info && 896254721Semaste ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 897254721Semaste (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 898254721Semaste { 899254721Semaste value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 900254721Semaste sb_value.SetSP (value_sp); 901254721Semaste break; 902254721Semaste } 903254721Semaste } 904254721Semaste } 905254721Semaste } 906254721Semaste break; 907254721Semaste 908254721Semaste case eValueTypeRegisterSet: // A collection of stack frame register values 909254721Semaste { 910254721Semaste RegisterContextSP reg_ctx (frame->GetRegisterContext()); 911254721Semaste if (reg_ctx) 912254721Semaste { 913254721Semaste const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 914254721Semaste for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 915254721Semaste { 916254721Semaste const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx); 917254721Semaste if (reg_set && 918254721Semaste ((reg_set->name && strcasecmp (reg_set->name, name) == 0) || 919254721Semaste (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0))) 920254721Semaste { 921254721Semaste value_sp = ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx); 922254721Semaste sb_value.SetSP (value_sp); 923254721Semaste break; 924254721Semaste } 925254721Semaste } 926254721Semaste } 927254721Semaste } 928254721Semaste break; 929254721Semaste 930254721Semaste case eValueTypeConstResult: // constant result variables 931254721Semaste { 932254721Semaste ConstString const_name(name); 933254721Semaste ClangExpressionVariableSP expr_var_sp (target->GetPersistentVariables().GetVariable (const_name)); 934254721Semaste if (expr_var_sp) 935254721Semaste { 936254721Semaste value_sp = expr_var_sp->GetValueObject(); 937254721Semaste sb_value.SetSP (value_sp, use_dynamic); 938254721Semaste } 939254721Semaste } 940254721Semaste break; 941254721Semaste 942254721Semaste default: 943254721Semaste break; 944254721Semaste } 945254721Semaste } 946254721Semaste else 947254721Semaste { 948254721Semaste if (log) 949254721Semaste log->Printf ("SBFrame::FindValue () => error: could not reconstruct frame object for this SBFrame."); 950254721Semaste } 951254721Semaste } 952254721Semaste else 953254721Semaste { 954254721Semaste if (log) 955254721Semaste log->Printf ("SBFrame::FindValue () => error: process is running"); 956254721Semaste } 957254721Semaste } 958254721Semaste 959254721Semaste if (log) 960254721Semaste log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)", 961254721Semaste frame, name, value_type, value_sp.get()); 962254721Semaste 963254721Semaste 964254721Semaste return sb_value; 965254721Semaste} 966254721Semaste 967254721Semastebool 968254721SemasteSBFrame::IsEqual (const SBFrame &that) const 969254721Semaste{ 970254721Semaste lldb::StackFrameSP this_sp = GetFrameSP(); 971254721Semaste lldb::StackFrameSP that_sp = that.GetFrameSP(); 972254721Semaste return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID()); 973254721Semaste} 974254721Semaste 975254721Semastebool 976254721SemasteSBFrame::operator == (const SBFrame &rhs) const 977254721Semaste{ 978254721Semaste return IsEqual(rhs); 979254721Semaste} 980254721Semaste 981254721Semastebool 982254721SemasteSBFrame::operator != (const SBFrame &rhs) const 983254721Semaste{ 984254721Semaste return !IsEqual(rhs); 985254721Semaste} 986254721Semaste 987254721SemasteSBThread 988254721SemasteSBFrame::GetThread () const 989254721Semaste{ 990254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 991254721Semaste 992254721Semaste ExecutionContext exe_ctx(m_opaque_sp.get()); 993254721Semaste ThreadSP thread_sp (exe_ctx.GetThreadSP()); 994254721Semaste SBThread sb_thread (thread_sp); 995254721Semaste 996254721Semaste if (log) 997254721Semaste { 998254721Semaste SBStream sstr; 999254721Semaste sb_thread.GetDescription (sstr); 1000254721Semaste log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", 1001254721Semaste exe_ctx.GetFramePtr(), 1002254721Semaste thread_sp.get(), 1003254721Semaste sstr.GetData()); 1004254721Semaste } 1005254721Semaste 1006254721Semaste return sb_thread; 1007254721Semaste} 1008254721Semaste 1009254721Semasteconst char * 1010254721SemasteSBFrame::Disassemble () const 1011254721Semaste{ 1012254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1013254721Semaste const char *disassembly = NULL; 1014254721Semaste Mutex::Locker api_locker; 1015254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1016254721Semaste 1017254721Semaste StackFrame *frame = NULL; 1018254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1019254721Semaste Process *process = exe_ctx.GetProcessPtr(); 1020254721Semaste if (target && process) 1021254721Semaste { 1022254721Semaste Process::StopLocker stop_locker; 1023254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 1024254721Semaste { 1025254721Semaste frame = exe_ctx.GetFramePtr(); 1026254721Semaste if (frame) 1027254721Semaste { 1028254721Semaste disassembly = frame->Disassemble(); 1029254721Semaste } 1030254721Semaste else 1031254721Semaste { 1032254721Semaste if (log) 1033254721Semaste log->Printf ("SBFrame::Disassemble () => error: could not reconstruct frame object for this SBFrame."); 1034254721Semaste } 1035254721Semaste } 1036254721Semaste else 1037254721Semaste { 1038254721Semaste if (log) 1039254721Semaste log->Printf ("SBFrame::Disassemble () => error: process is running"); 1040254721Semaste } 1041254721Semaste } 1042254721Semaste 1043254721Semaste if (log) 1044254721Semaste log->Printf ("SBFrame(%p)::Disassemble () => %s", frame, disassembly); 1045254721Semaste 1046254721Semaste return disassembly; 1047254721Semaste} 1048254721Semaste 1049254721Semaste 1050254721SemasteSBValueList 1051254721SemasteSBFrame::GetVariables (bool arguments, 1052254721Semaste bool locals, 1053254721Semaste bool statics, 1054254721Semaste bool in_scope_only) 1055254721Semaste{ 1056254721Semaste SBValueList value_list; 1057254721Semaste ExecutionContext exe_ctx(m_opaque_sp.get()); 1058254721Semaste StackFrame *frame = exe_ctx.GetFramePtr(); 1059254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1060254721Semaste if (frame && target) 1061254721Semaste { 1062254721Semaste lldb::DynamicValueType use_dynamic = frame->CalculateTarget()->GetPreferDynamicValue(); 1063254721Semaste value_list = GetVariables (arguments, locals, statics, in_scope_only, use_dynamic); 1064254721Semaste } 1065254721Semaste return value_list; 1066254721Semaste} 1067254721Semaste 1068254721SemasteSBValueList 1069254721SemasteSBFrame::GetVariables (bool arguments, 1070254721Semaste bool locals, 1071254721Semaste bool statics, 1072254721Semaste bool in_scope_only, 1073254721Semaste lldb::DynamicValueType use_dynamic) 1074254721Semaste{ 1075254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1076254721Semaste 1077254721Semaste SBValueList value_list; 1078254721Semaste Mutex::Locker api_locker; 1079254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1080254721Semaste 1081254721Semaste StackFrame *frame = NULL; 1082254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1083254721Semaste 1084254721Semaste if (log) 1085254721Semaste log->Printf ("SBFrame::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)", 1086254721Semaste arguments, 1087254721Semaste locals, 1088254721Semaste statics, 1089254721Semaste in_scope_only); 1090254721Semaste 1091254721Semaste Process *process = exe_ctx.GetProcessPtr(); 1092254721Semaste if (target && process) 1093254721Semaste { 1094254721Semaste Process::StopLocker stop_locker; 1095254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 1096254721Semaste { 1097254721Semaste frame = exe_ctx.GetFramePtr(); 1098254721Semaste if (frame) 1099254721Semaste { 1100254721Semaste size_t i; 1101254721Semaste VariableList *variable_list = NULL; 1102254721Semaste variable_list = frame->GetVariableList(true); 1103254721Semaste if (variable_list) 1104254721Semaste { 1105254721Semaste const size_t num_variables = variable_list->GetSize(); 1106254721Semaste if (num_variables) 1107254721Semaste { 1108254721Semaste for (i = 0; i < num_variables; ++i) 1109254721Semaste { 1110254721Semaste VariableSP variable_sp (variable_list->GetVariableAtIndex(i)); 1111254721Semaste if (variable_sp) 1112254721Semaste { 1113254721Semaste bool add_variable = false; 1114254721Semaste switch (variable_sp->GetScope()) 1115254721Semaste { 1116254721Semaste case eValueTypeVariableGlobal: 1117254721Semaste case eValueTypeVariableStatic: 1118254721Semaste add_variable = statics; 1119254721Semaste break; 1120254721Semaste 1121254721Semaste case eValueTypeVariableArgument: 1122254721Semaste add_variable = arguments; 1123254721Semaste break; 1124254721Semaste 1125254721Semaste case eValueTypeVariableLocal: 1126254721Semaste add_variable = locals; 1127254721Semaste break; 1128254721Semaste 1129254721Semaste default: 1130254721Semaste break; 1131254721Semaste } 1132254721Semaste if (add_variable) 1133254721Semaste { 1134254721Semaste if (in_scope_only && !variable_sp->IsInScope(frame)) 1135254721Semaste continue; 1136254721Semaste 1137254721Semaste ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable (variable_sp, eNoDynamicValues)); 1138254721Semaste SBValue value_sb; 1139254721Semaste value_sb.SetSP(valobj_sp,use_dynamic); 1140254721Semaste value_list.Append(value_sb); 1141254721Semaste } 1142254721Semaste } 1143254721Semaste } 1144254721Semaste } 1145254721Semaste } 1146254721Semaste } 1147254721Semaste else 1148254721Semaste { 1149254721Semaste if (log) 1150254721Semaste log->Printf ("SBFrame::GetVariables () => error: could not reconstruct frame object for this SBFrame."); 1151254721Semaste } 1152254721Semaste } 1153254721Semaste else 1154254721Semaste { 1155254721Semaste if (log) 1156254721Semaste log->Printf ("SBFrame::GetVariables () => error: process is running"); 1157254721Semaste } 1158254721Semaste } 1159254721Semaste 1160254721Semaste if (log) 1161254721Semaste { 1162254721Semaste log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", frame, value_list.opaque_ptr()); 1163254721Semaste } 1164254721Semaste 1165254721Semaste return value_list; 1166254721Semaste} 1167254721Semaste 1168254721SemasteSBValueList 1169254721SemasteSBFrame::GetRegisters () 1170254721Semaste{ 1171254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1172254721Semaste 1173254721Semaste SBValueList value_list; 1174254721Semaste Mutex::Locker api_locker; 1175254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1176254721Semaste 1177254721Semaste StackFrame *frame = NULL; 1178254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1179254721Semaste Process *process = exe_ctx.GetProcessPtr(); 1180254721Semaste if (target && process) 1181254721Semaste { 1182254721Semaste Process::StopLocker stop_locker; 1183254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 1184254721Semaste { 1185254721Semaste frame = exe_ctx.GetFramePtr(); 1186254721Semaste if (frame) 1187254721Semaste { 1188254721Semaste RegisterContextSP reg_ctx (frame->GetRegisterContext()); 1189254721Semaste if (reg_ctx) 1190254721Semaste { 1191254721Semaste const uint32_t num_sets = reg_ctx->GetRegisterSetCount(); 1192254721Semaste for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) 1193254721Semaste { 1194254721Semaste value_list.Append(ValueObjectRegisterSet::Create (frame, reg_ctx, set_idx)); 1195254721Semaste } 1196254721Semaste } 1197254721Semaste } 1198254721Semaste else 1199254721Semaste { 1200254721Semaste if (log) 1201254721Semaste log->Printf ("SBFrame::GetRegisters () => error: could not reconstruct frame object for this SBFrame."); 1202254721Semaste } 1203254721Semaste } 1204254721Semaste else 1205254721Semaste { 1206254721Semaste if (log) 1207254721Semaste log->Printf ("SBFrame::GetRegisters () => error: process is running"); 1208254721Semaste } 1209254721Semaste } 1210254721Semaste 1211254721Semaste if (log) 1212254721Semaste log->Printf ("SBFrame(%p)::GetRegisters () => SBValueList(%p)", frame, value_list.opaque_ptr()); 1213254721Semaste 1214254721Semaste return value_list; 1215254721Semaste} 1216254721Semaste 1217254721SemasteSBValue 1218254721SemasteSBFrame::FindRegister (const char *name) 1219254721Semaste{ 1220254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1221254721Semaste 1222254721Semaste SBValue result; 1223254721Semaste ValueObjectSP value_sp; 1224254721Semaste Mutex::Locker api_locker; 1225254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1226254721Semaste 1227254721Semaste StackFrame *frame = NULL; 1228254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1229254721Semaste Process *process = exe_ctx.GetProcessPtr(); 1230254721Semaste if (target && process) 1231254721Semaste { 1232254721Semaste Process::StopLocker stop_locker; 1233254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 1234254721Semaste { 1235254721Semaste frame = exe_ctx.GetFramePtr(); 1236254721Semaste if (frame) 1237254721Semaste { 1238254721Semaste RegisterContextSP reg_ctx (frame->GetRegisterContext()); 1239254721Semaste if (reg_ctx) 1240254721Semaste { 1241254721Semaste const uint32_t num_regs = reg_ctx->GetRegisterCount(); 1242254721Semaste for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) 1243254721Semaste { 1244254721Semaste const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx); 1245254721Semaste if (reg_info && 1246254721Semaste ((reg_info->name && strcasecmp (reg_info->name, name) == 0) || 1247254721Semaste (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0))) 1248254721Semaste { 1249254721Semaste value_sp = ValueObjectRegister::Create (frame, reg_ctx, reg_idx); 1250254721Semaste result.SetSP (value_sp); 1251254721Semaste break; 1252254721Semaste } 1253254721Semaste } 1254254721Semaste } 1255254721Semaste } 1256254721Semaste else 1257254721Semaste { 1258254721Semaste if (log) 1259254721Semaste log->Printf ("SBFrame::FindRegister () => error: could not reconstruct frame object for this SBFrame."); 1260254721Semaste } 1261254721Semaste } 1262254721Semaste else 1263254721Semaste { 1264254721Semaste if (log) 1265254721Semaste log->Printf ("SBFrame::FindRegister () => error: process is running"); 1266254721Semaste } 1267254721Semaste } 1268254721Semaste 1269254721Semaste if (log) 1270254721Semaste log->Printf ("SBFrame(%p)::FindRegister () => SBValue(%p)", frame, value_sp.get()); 1271254721Semaste 1272254721Semaste return result; 1273254721Semaste} 1274254721Semaste 1275254721Semastebool 1276254721SemasteSBFrame::GetDescription (SBStream &description) 1277254721Semaste{ 1278254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1279254721Semaste Stream &strm = description.ref(); 1280254721Semaste 1281254721Semaste Mutex::Locker api_locker; 1282254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1283254721Semaste 1284254721Semaste StackFrame *frame; 1285254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1286254721Semaste Process *process = exe_ctx.GetProcessPtr(); 1287254721Semaste if (target && process) 1288254721Semaste { 1289254721Semaste Process::StopLocker stop_locker; 1290254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 1291254721Semaste { 1292254721Semaste frame = exe_ctx.GetFramePtr(); 1293254721Semaste if (frame) 1294254721Semaste { 1295254721Semaste frame->DumpUsingSettingsFormat (&strm); 1296254721Semaste } 1297254721Semaste else 1298254721Semaste { 1299254721Semaste if (log) 1300254721Semaste log->Printf ("SBFrame::GetDescription () => error: could not reconstruct frame object for this SBFrame."); 1301254721Semaste } 1302254721Semaste } 1303254721Semaste else 1304254721Semaste { 1305254721Semaste if (log) 1306254721Semaste log->Printf ("SBFrame::GetDescription () => error: process is running"); 1307254721Semaste } 1308254721Semaste 1309254721Semaste } 1310254721Semaste else 1311254721Semaste strm.PutCString ("No value"); 1312254721Semaste 1313254721Semaste return true; 1314254721Semaste} 1315254721Semaste 1316254721SemasteSBValue 1317254721SemasteSBFrame::EvaluateExpression (const char *expr) 1318254721Semaste{ 1319254721Semaste SBValue result; 1320254721Semaste ExecutionContext exe_ctx(m_opaque_sp.get()); 1321254721Semaste StackFrame *frame = exe_ctx.GetFramePtr(); 1322254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1323254721Semaste if (frame && target) 1324254721Semaste { 1325254721Semaste SBExpressionOptions options; 1326254721Semaste lldb::DynamicValueType fetch_dynamic_value = frame->CalculateTarget()->GetPreferDynamicValue(); 1327254721Semaste options.SetFetchDynamicValue (fetch_dynamic_value); 1328254721Semaste options.SetUnwindOnError (true); 1329254721Semaste return EvaluateExpression (expr, options); 1330254721Semaste } 1331254721Semaste return result; 1332254721Semaste} 1333254721Semaste 1334254721SemasteSBValue 1335254721SemasteSBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value) 1336254721Semaste{ 1337254721Semaste SBExpressionOptions options; 1338254721Semaste options.SetFetchDynamicValue (fetch_dynamic_value); 1339254721Semaste options.SetUnwindOnError (true); 1340254721Semaste return EvaluateExpression (expr, options); 1341254721Semaste} 1342254721Semaste 1343254721SemasteSBValue 1344254721SemasteSBFrame::EvaluateExpression (const char *expr, lldb::DynamicValueType fetch_dynamic_value, bool unwind_on_error) 1345254721Semaste{ 1346254721Semaste SBExpressionOptions options; 1347254721Semaste options.SetFetchDynamicValue (fetch_dynamic_value); 1348254721Semaste options.SetUnwindOnError (unwind_on_error); 1349254721Semaste return EvaluateExpression (expr, options); 1350254721Semaste} 1351254721Semaste 1352254721Semastelldb::SBValue 1353254721SemasteSBFrame::EvaluateExpression (const char *expr, const SBExpressionOptions &options) 1354254721Semaste{ 1355254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1356254721Semaste 1357254721Semaste Log *expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 1358254721Semaste 1359254721Semaste ExecutionResults exe_results = eExecutionSetupError; 1360254721Semaste SBValue expr_result; 1361254721Semaste 1362254721Semaste if (expr == NULL || expr[0] == '\0') 1363254721Semaste { 1364254721Semaste if (log) 1365254721Semaste log->Printf ("SBFrame::EvaluateExpression called with an empty expression"); 1366254721Semaste return expr_result; 1367254721Semaste } 1368254721Semaste 1369254721Semaste ValueObjectSP expr_value_sp; 1370254721Semaste 1371254721Semaste Mutex::Locker api_locker; 1372254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); 1373254721Semaste 1374254721Semaste if (log) 1375254721Semaste log->Printf ("SBFrame()::EvaluateExpression (expr=\"%s\")...", expr); 1376254721Semaste 1377254721Semaste StackFrame *frame = NULL; 1378254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1379254721Semaste Process *process = exe_ctx.GetProcessPtr(); 1380254721Semaste 1381254721Semaste if (target && process) 1382254721Semaste { 1383254721Semaste Process::StopLocker stop_locker; 1384254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 1385254721Semaste { 1386254721Semaste frame = exe_ctx.GetFramePtr(); 1387254721Semaste if (frame) 1388254721Semaste { 1389254721Semaste#ifdef LLDB_CONFIGURATION_DEBUG 1390254721Semaste StreamString frame_description; 1391254721Semaste frame->DumpUsingSettingsFormat (&frame_description); 1392254721Semaste Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", 1393254721Semaste expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str()); 1394254721Semaste#endif 1395254721Semaste exe_results = target->EvaluateExpression (expr, 1396254721Semaste frame, 1397254721Semaste expr_value_sp, 1398254721Semaste options.ref()); 1399254721Semaste expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); 1400254721Semaste#ifdef LLDB_CONFIGURATION_DEBUG 1401254721Semaste Host::SetCrashDescription (NULL); 1402254721Semaste#endif 1403254721Semaste } 1404254721Semaste else 1405254721Semaste { 1406254721Semaste if (log) 1407254721Semaste log->Printf ("SBFrame::EvaluateExpression () => error: could not reconstruct frame object for this SBFrame."); 1408254721Semaste } 1409254721Semaste } 1410254721Semaste else 1411254721Semaste { 1412254721Semaste if (log) 1413254721Semaste log->Printf ("SBFrame::EvaluateExpression () => error: process is running"); 1414254721Semaste } 1415254721Semaste } 1416254721Semaste 1417254721Semaste#ifndef LLDB_DISABLE_PYTHON 1418254721Semaste if (expr_log) 1419254721Semaste expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **", 1420254721Semaste expr_result.GetValue(), 1421254721Semaste expr_result.GetSummary()); 1422254721Semaste 1423254721Semaste if (log) 1424254721Semaste log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", 1425254721Semaste frame, 1426254721Semaste expr, 1427254721Semaste expr_value_sp.get(), 1428254721Semaste exe_results); 1429254721Semaste#endif 1430254721Semaste 1431254721Semaste return expr_result; 1432254721Semaste} 1433254721Semaste 1434254721Semastebool 1435254721SemasteSBFrame::IsInlined() 1436254721Semaste{ 1437254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1438254721Semaste ExecutionContext exe_ctx(m_opaque_sp.get()); 1439254721Semaste StackFrame *frame = NULL; 1440254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1441254721Semaste Process *process = exe_ctx.GetProcessPtr(); 1442254721Semaste if (target && process) 1443254721Semaste { 1444254721Semaste Process::StopLocker stop_locker; 1445254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 1446254721Semaste { 1447254721Semaste frame = exe_ctx.GetFramePtr(); 1448254721Semaste if (frame) 1449254721Semaste { 1450254721Semaste 1451254721Semaste Block *block = frame->GetSymbolContext(eSymbolContextBlock).block; 1452254721Semaste if (block) 1453254721Semaste return block->GetContainingInlinedBlock () != NULL; 1454254721Semaste } 1455254721Semaste else 1456254721Semaste { 1457254721Semaste if (log) 1458254721Semaste log->Printf ("SBFrame::IsInlined () => error: could not reconstruct frame object for this SBFrame."); 1459254721Semaste } 1460254721Semaste } 1461254721Semaste else 1462254721Semaste { 1463254721Semaste if (log) 1464254721Semaste log->Printf ("SBFrame::IsInlined () => error: process is running"); 1465254721Semaste } 1466254721Semaste 1467254721Semaste } 1468254721Semaste return false; 1469254721Semaste} 1470254721Semaste 1471254721Semasteconst char * 1472254721SemasteSBFrame::GetFunctionName() 1473254721Semaste{ 1474254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1475254721Semaste const char *name = NULL; 1476254721Semaste ExecutionContext exe_ctx(m_opaque_sp.get()); 1477254721Semaste StackFrame *frame = NULL; 1478254721Semaste Target *target = exe_ctx.GetTargetPtr(); 1479254721Semaste Process *process = exe_ctx.GetProcessPtr(); 1480254721Semaste if (target && process) 1481254721Semaste { 1482254721Semaste Process::StopLocker stop_locker; 1483254721Semaste if (stop_locker.TryLock(&process->GetRunLock())) 1484254721Semaste { 1485254721Semaste frame = exe_ctx.GetFramePtr(); 1486254721Semaste if (frame) 1487254721Semaste { 1488254721Semaste SymbolContext sc (frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol)); 1489254721Semaste if (sc.block) 1490254721Semaste { 1491254721Semaste Block *inlined_block = sc.block->GetContainingInlinedBlock (); 1492254721Semaste if (inlined_block) 1493254721Semaste { 1494254721Semaste const InlineFunctionInfo* inlined_info = inlined_block->GetInlinedFunctionInfo(); 1495254721Semaste name = inlined_info->GetName().AsCString(); 1496254721Semaste } 1497254721Semaste } 1498254721Semaste 1499254721Semaste if (name == NULL) 1500254721Semaste { 1501254721Semaste if (sc.function) 1502254721Semaste name = sc.function->GetName().GetCString(); 1503254721Semaste } 1504254721Semaste 1505254721Semaste if (name == NULL) 1506254721Semaste { 1507254721Semaste if (sc.symbol) 1508254721Semaste name = sc.symbol->GetName().GetCString(); 1509254721Semaste } 1510254721Semaste } 1511254721Semaste else 1512254721Semaste { 1513254721Semaste if (log) 1514254721Semaste log->Printf ("SBFrame::GetFunctionName () => error: could not reconstruct frame object for this SBFrame."); 1515254721Semaste } 1516254721Semaste } 1517254721Semaste else 1518254721Semaste { 1519254721Semaste if (log) 1520254721Semaste log->Printf ("SBFrame::GetFunctionName() => error: process is running"); 1521254721Semaste 1522254721Semaste } 1523254721Semaste } 1524254721Semaste return name; 1525254721Semaste} 1526254721Semaste 1527