blob: 8bd623b3b853ce04bd39177c6d3e98a0cbf5f0a3 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBFrame.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
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBFrame.h"
Chris Lattner24943d22010-06-08 16:52:24 +000011
12#include <string>
13#include <algorithm>
14
15#include "lldb/lldb-types.h"
16
17#include "lldb/Core/Address.h"
18#include "lldb/Core/ConstString.h"
Caroline Tice7826c882010-10-26 03:11:13 +000019#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Core/Stream.h"
21#include "lldb/Core/StreamFile.h"
22#include "lldb/Core/ValueObjectRegister.h"
23#include "lldb/Core/ValueObjectVariable.h"
Greg Claytond1719722010-10-05 03:13:51 +000024#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Symbol/Block.h"
26#include "lldb/Symbol/SymbolContext.h"
27#include "lldb/Symbol/VariableList.h"
28#include "lldb/Symbol/Variable.h"
29#include "lldb/Target/ExecutionContext.h"
30#include "lldb/Target/Target.h"
31#include "lldb/Target/Process.h"
32#include "lldb/Target/RegisterContext.h"
33#include "lldb/Target/StackFrame.h"
34#include "lldb/Target/Thread.h"
35
Eli Friedman7a62c8b2010-06-09 07:44:37 +000036#include "lldb/API/SBDebugger.h"
37#include "lldb/API/SBValue.h"
38#include "lldb/API/SBAddress.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000039#include "lldb/API/SBStream.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000040#include "lldb/API/SBSymbolContext.h"
41#include "lldb/API/SBThread.h"
Chris Lattner24943d22010-06-08 16:52:24 +000042
43using namespace lldb;
44using namespace lldb_private;
45
46SBFrame::SBFrame () :
Greg Clayton63094e02010-06-23 01:19:29 +000047 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000048{
49}
50
Greg Clayton4e9267d2010-12-14 18:39:31 +000051SBFrame::SBFrame (const StackFrameSP &lldb_object_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000052 m_opaque_sp (lldb_object_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000053{
Greg Clayton4e9267d2010-12-14 18:39:31 +000054 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +000055
56 if (log)
57 {
58 SBStream sstr;
59 GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +000060 log->Printf ("SBFrame::SBFrame (sp=%p) => SBFrame(%p): %s",
61 lldb_object_sp.get(), m_opaque_sp.get(), sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +000062
Caroline Tice7826c882010-10-26 03:11:13 +000063 }
Chris Lattner24943d22010-06-08 16:52:24 +000064}
65
Greg Clayton538eb822010-11-05 23:17:00 +000066SBFrame::SBFrame(const SBFrame &rhs) :
67 m_opaque_sp (rhs.m_opaque_sp)
68{
69}
70
71const SBFrame &
72SBFrame::operator = (const SBFrame &rhs)
73{
74 if (this != &rhs)
75 m_opaque_sp = rhs.m_opaque_sp;
76 return *this;
77}
78
Chris Lattner24943d22010-06-08 16:52:24 +000079SBFrame::~SBFrame()
80{
81}
82
83
84void
Greg Clayton4e9267d2010-12-14 18:39:31 +000085SBFrame::SetFrame (const StackFrameSP &lldb_object_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000086{
Greg Claytona66ba462010-10-30 04:51:46 +000087 void *old_ptr = m_opaque_sp.get();
Greg Clayton63094e02010-06-23 01:19:29 +000088 m_opaque_sp = lldb_object_sp;
Greg Clayton4e9267d2010-12-14 18:39:31 +000089 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +000090
91 if (log)
92 {
93 log->Printf ("SBFrame(%p)::SetFrame(sp=%p) := SBFrame(%p)",
94 old_ptr, lldb_object_sp.get(), m_opaque_sp.get());
95 }
96
Chris Lattner24943d22010-06-08 16:52:24 +000097}
98
99
100bool
101SBFrame::IsValid() const
102{
Greg Clayton63094e02010-06-23 01:19:29 +0000103 return (m_opaque_sp.get() != NULL);
Chris Lattner24943d22010-06-08 16:52:24 +0000104}
105
106SBSymbolContext
107SBFrame::GetSymbolContext (uint32_t resolve_scope) const
108{
Caroline Tice7826c882010-10-26 03:11:13 +0000109
Chris Lattner24943d22010-06-08 16:52:24 +0000110 SBSymbolContext sb_sym_ctx;
Greg Clayton63094e02010-06-23 01:19:29 +0000111 if (m_opaque_sp)
112 sb_sym_ctx.SetSymbolContext(&m_opaque_sp->GetSymbolContext (resolve_scope));
Caroline Tice7826c882010-10-26 03:11:13 +0000113
Greg Clayton4e9267d2010-12-14 18:39:31 +0000114 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000115 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000116 log->Printf ("SBFrame(%p)::GetSymbolContext (resolve_scope=0x%8.8x) => SBSymbolContext(%p)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000117 m_opaque_sp.get(), resolve_scope, sb_sym_ctx.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000118
Chris Lattner24943d22010-06-08 16:52:24 +0000119 return sb_sym_ctx;
120}
121
122SBModule
123SBFrame::GetModule () const
124{
Greg Claytondd62d722010-12-14 04:58:53 +0000125 SBModule sb_module;
126 if (m_opaque_sp)
127 *sb_module = m_opaque_sp->GetSymbolContext (eSymbolContextModule).module_sp;
128
Greg Clayton4e9267d2010-12-14 18:39:31 +0000129 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000130 if (log)
131 log->Printf ("SBFrame(%p)::GetModule () => SBModule(%p)",
132 m_opaque_sp.get(), sb_module.get());
133
Chris Lattner24943d22010-06-08 16:52:24 +0000134 return sb_module;
135}
136
137SBCompileUnit
138SBFrame::GetCompileUnit () const
139{
Greg Claytondd62d722010-12-14 04:58:53 +0000140 SBCompileUnit sb_comp_unit;
141 if (m_opaque_sp)
142 sb_comp_unit.reset (m_opaque_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000143 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000144 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000145 log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)",
146 m_opaque_sp.get(), sb_comp_unit.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000147
Chris Lattner24943d22010-06-08 16:52:24 +0000148 return sb_comp_unit;
149}
150
151SBFunction
152SBFrame::GetFunction () const
153{
Greg Claytondd62d722010-12-14 04:58:53 +0000154 SBFunction sb_function;
155 if (m_opaque_sp)
156 sb_function.reset(m_opaque_sp->GetSymbolContext (eSymbolContextFunction).function);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000157 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000158 if (log)
159 log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)",
160 m_opaque_sp.get(), sb_function.get());
161
Chris Lattner24943d22010-06-08 16:52:24 +0000162 return sb_function;
163}
164
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000165SBSymbol
166SBFrame::GetSymbol () const
167{
Greg Claytondd62d722010-12-14 04:58:53 +0000168 SBSymbol sb_symbol;
169 if (m_opaque_sp)
170 sb_symbol.reset(m_opaque_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000171 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000172 if (log)
173 log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)",
174 m_opaque_sp.get(), sb_symbol.get());
Greg Clayton8f1e08b2010-10-04 18:37:52 +0000175 return sb_symbol;
176}
177
Chris Lattner24943d22010-06-08 16:52:24 +0000178SBBlock
179SBFrame::GetBlock () const
180{
Greg Claytondd62d722010-12-14 04:58:53 +0000181 SBBlock sb_block;
182 if (m_opaque_sp)
183 sb_block.reset (m_opaque_sp->GetSymbolContext (eSymbolContextBlock).block);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000184 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000185 if (log)
186 log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)",
187 m_opaque_sp.get(), sb_block.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000188 return sb_block;
189}
190
Greg Clayton69aa5d92010-09-07 04:20:48 +0000191SBBlock
192SBFrame::GetFrameBlock () const
193{
Greg Claytondd62d722010-12-14 04:58:53 +0000194 SBBlock sb_block;
195 if (m_opaque_sp)
196 sb_block.reset(m_opaque_sp->GetFrameBlock ());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000197 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000198 if (log)
199 log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)",
200 m_opaque_sp.get(), sb_block.get());
Greg Clayton69aa5d92010-09-07 04:20:48 +0000201 return sb_block;
202}
203
Chris Lattner24943d22010-06-08 16:52:24 +0000204SBLineEntry
205SBFrame::GetLineEntry () const
206{
Greg Claytondd62d722010-12-14 04:58:53 +0000207 SBLineEntry sb_line_entry;
208 if (m_opaque_sp)
209 sb_line_entry.SetLineEntry (m_opaque_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry);
Greg Clayton4e9267d2010-12-14 18:39:31 +0000210 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000211 if (log)
212 log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)",
213 m_opaque_sp.get(), sb_line_entry.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000214 return sb_line_entry;
215}
216
217uint32_t
218SBFrame::GetFrameID () const
219{
Greg Claytona66ba462010-10-30 04:51:46 +0000220 uint32_t frame_idx = m_opaque_sp ? m_opaque_sp->GetFrameIndex () : UINT32_MAX;
221
Greg Clayton4e9267d2010-12-14 18:39:31 +0000222 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000223 if (log)
224 log->Printf ("SBFrame(%p)::GetFrameID () => %u",
225 m_opaque_sp.get(), frame_idx);
226 return frame_idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000227}
228
Greg Clayton4e9267d2010-12-14 18:39:31 +0000229addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000230SBFrame::GetPC () const
231{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000232 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton63094e02010-06-23 01:19:29 +0000233 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000234 addr = m_opaque_sp->GetFrameCodeAddress().GetLoadAddress (&m_opaque_sp->GetThread().GetProcess().GetTarget());
235
Greg Clayton4e9267d2010-12-14 18:39:31 +0000236 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000237 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000238 log->Printf ("SBFrame(%p)::GetPC () => 0x%llx", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000239
240 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000241}
242
243bool
Greg Clayton4e9267d2010-12-14 18:39:31 +0000244SBFrame::SetPC (addr_t new_pc)
Chris Lattner24943d22010-06-08 16:52:24 +0000245{
Caroline Tice7826c882010-10-26 03:11:13 +0000246 bool ret_val = false;
Greg Clayton63094e02010-06-23 01:19:29 +0000247 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000248 ret_val = m_opaque_sp->GetRegisterContext()->SetPC (new_pc);
249
Greg Clayton4e9267d2010-12-14 18:39:31 +0000250 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000251 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000252 log->Printf ("SBFrame(%p)::SetPC (new_pc=0x%llx) => %i",
253 m_opaque_sp.get(), new_pc, ret_val);
Caroline Tice7826c882010-10-26 03:11:13 +0000254
255 return ret_val;
Chris Lattner24943d22010-06-08 16:52:24 +0000256}
257
Greg Clayton4e9267d2010-12-14 18:39:31 +0000258addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000259SBFrame::GetSP () const
260{
Greg Claytona66ba462010-10-30 04:51:46 +0000261 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton63094e02010-06-23 01:19:29 +0000262 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000263 addr = m_opaque_sp->GetRegisterContext()->GetSP();
Greg Clayton4e9267d2010-12-14 18:39:31 +0000264 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000265 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000266 log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", m_opaque_sp.get(), addr);
Greg Claytona66ba462010-10-30 04:51:46 +0000267
268 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000269}
270
271
Greg Clayton4e9267d2010-12-14 18:39:31 +0000272addr_t
Chris Lattner24943d22010-06-08 16:52:24 +0000273SBFrame::GetFP () const
274{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000275 addr_t addr = LLDB_INVALID_ADDRESS;
Greg Clayton63094e02010-06-23 01:19:29 +0000276 if (m_opaque_sp)
Caroline Tice7826c882010-10-26 03:11:13 +0000277 addr = m_opaque_sp->GetRegisterContext()->GetFP();
278
Greg Clayton4e9267d2010-12-14 18:39:31 +0000279 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000280 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000281 log->Printf ("SBFrame(%p)::GetFP () => 0x%llx", m_opaque_sp.get(), addr);
Caroline Tice7826c882010-10-26 03:11:13 +0000282 return addr;
Chris Lattner24943d22010-06-08 16:52:24 +0000283}
284
285
286SBAddress
287SBFrame::GetPCAddress () const
288{
289 SBAddress sb_addr;
Greg Clayton63094e02010-06-23 01:19:29 +0000290 if (m_opaque_sp)
Greg Claytonb04e7a82010-08-24 21:05:24 +0000291 sb_addr.SetAddress (&m_opaque_sp->GetFrameCodeAddress());
Greg Clayton4e9267d2010-12-14 18:39:31 +0000292 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000293 if (log)
294 log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", m_opaque_sp.get(), sb_addr.get());
Chris Lattner24943d22010-06-08 16:52:24 +0000295 return sb_addr;
296}
297
298void
299SBFrame::Clear()
300{
Greg Clayton63094e02010-06-23 01:19:29 +0000301 m_opaque_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000302}
303
304SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000305SBFrame::FindVariable (const char *name)
Chris Lattner24943d22010-06-08 16:52:24 +0000306{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000307 VariableSP var_sp;
308 if (m_opaque_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000309 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000310 VariableList variable_list;
Chris Lattner24943d22010-06-08 16:52:24 +0000311
Greg Claytondd62d722010-12-14 04:58:53 +0000312 SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock));
Chris Lattner24943d22010-06-08 16:52:24 +0000313
Greg Claytondd62d722010-12-14 04:58:53 +0000314 if (sc.block)
Chris Lattner24943d22010-06-08 16:52:24 +0000315 {
Greg Claytondd62d722010-12-14 04:58:53 +0000316 const bool can_create = true;
317 const bool get_parent_variables = true;
318 const bool stop_if_block_is_inlined_function = true;
319
320 if (sc.block->AppendVariables (can_create,
321 get_parent_variables,
322 stop_if_block_is_inlined_function,
323 &variable_list))
324 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000325 var_sp = variable_list.FindVariable (ConstString(name));
Greg Claytondd62d722010-12-14 04:58:53 +0000326 }
Chris Lattner24943d22010-06-08 16:52:24 +0000327 }
Chris Lattner24943d22010-06-08 16:52:24 +0000328 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000329
330 SBValue sb_value;
Greg Claytona66ba462010-10-30 04:51:46 +0000331
332 if (var_sp)
333 *sb_value = ValueObjectSP (new ValueObjectVariable (var_sp));
334
Greg Clayton4e9267d2010-12-14 18:39:31 +0000335 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000336 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000337 log->Printf ("SBFrame(%p)::FindVariable (name=\"%s\") => SBValue(%p)",
338 m_opaque_sp.get(), name, sb_value.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000339
Chris Lattner24943d22010-06-08 16:52:24 +0000340 return sb_value;
341}
342
343SBValue
Greg Clayton4e9267d2010-12-14 18:39:31 +0000344SBFrame::FindValue (const char *name, ValueType value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000345{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000346 SBValue sb_value;
347 if (m_opaque_sp && name && name[0])
Chris Lattner24943d22010-06-08 16:52:24 +0000348 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000349
350 switch (value_type)
Chris Lattner24943d22010-06-08 16:52:24 +0000351 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000352 case eValueTypeVariableGlobal: // global variable
353 case eValueTypeVariableStatic: // static variable
354 case eValueTypeVariableArgument: // function argument variables
355 case eValueTypeVariableLocal: // function local variables
Chris Lattner24943d22010-06-08 16:52:24 +0000356 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000357 VariableList *variable_list = m_opaque_sp->GetVariableList(true);
358
359 SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock));
360
361 const bool can_create = true;
362 const bool get_parent_variables = true;
363 const bool stop_if_block_is_inlined_function = true;
364
365 if (sc.block && sc.block->AppendVariables (can_create,
366 get_parent_variables,
367 stop_if_block_is_inlined_function,
368 variable_list))
Johnny Chenc35750a2010-11-19 18:07:14 +0000369 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000370 ConstString const_name(name);
371 const uint32_t num_variables = variable_list->GetSize();
372 for (uint32_t i = 0; i < num_variables; ++i)
Johnny Chenc35750a2010-11-19 18:07:14 +0000373 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000374 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
375 if (variable_sp &&
376 variable_sp->GetScope() == value_type &&
377 variable_sp->GetName() == const_name)
378 {
379 *sb_value = ValueObjectSP (new ValueObjectVariable (variable_sp));
380 break;
381 }
Johnny Chenc35750a2010-11-19 18:07:14 +0000382 }
383 }
Chris Lattner24943d22010-06-08 16:52:24 +0000384 }
Greg Clayton4e9267d2010-12-14 18:39:31 +0000385 break;
386
387 case eValueTypeRegister: // stack frame register value
388 {
389 RegisterContext *reg_ctx = m_opaque_sp->GetRegisterContext();
390 if (reg_ctx)
391 {
392 const uint32_t num_regs = reg_ctx->GetRegisterCount();
393 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx)
394 {
395 const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex (reg_idx);
396 if (reg_info &&
397 ((reg_info->name && strcasecmp (reg_info->name, name) == 0) ||
398 (reg_info->alt_name && strcasecmp (reg_info->alt_name, name) == 0)))
399 {
400 *sb_value = ValueObjectSP (new ValueObjectRegister (NULL, reg_ctx, reg_idx));
401 }
402 }
403 }
404 }
405 break;
406
407 case eValueTypeRegisterSet: // A collection of stack frame register values
408 {
409 RegisterContext *reg_ctx = m_opaque_sp->GetRegisterContext();
410 if (reg_ctx)
411 {
412 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
413 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
414 {
415 const RegisterSet *reg_set = reg_ctx->GetRegisterSet (set_idx);
416 if (reg_set &&
417 ((reg_set->name && strcasecmp (reg_set->name, name) == 0) ||
418 (reg_set->short_name && strcasecmp (reg_set->short_name, name) == 0)))
419 {
420 *sb_value = ValueObjectSP (new ValueObjectRegisterSet (NULL, reg_ctx, set_idx));
421 }
422 }
423 }
424 }
425 break;
426
427 case eValueTypeConstResult: // constant result variables
428 {
429 ConstString const_name(name);
430 ClangExpressionVariableSP expr_var_sp (m_opaque_sp->GetThread().GetProcess().GetTarget().GetPersistentVariables().GetVariable (const_name));
431 if (expr_var_sp)
432 *sb_value = expr_var_sp->GetValueObject();
433 }
434 break;
435
436 default:
437 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000438 }
439 }
Caroline Tice98f930f2010-09-20 05:20:02 +0000440
Greg Clayton4e9267d2010-12-14 18:39:31 +0000441 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000442 if (log)
Greg Clayton4e9267d2010-12-14 18:39:31 +0000443 log->Printf ("SBFrame(%p)::FindVariableInScope (name=\"%s\", value_type=%i) => SBValue(%p)",
444 m_opaque_sp.get(), name, value_type, sb_value.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000445
446
Chris Lattner24943d22010-06-08 16:52:24 +0000447 return sb_value;
448}
449
450bool
451SBFrame::operator == (const SBFrame &rhs) const
452{
Greg Clayton63094e02010-06-23 01:19:29 +0000453 return m_opaque_sp.get() == rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000454}
455
456bool
457SBFrame::operator != (const SBFrame &rhs) const
458{
Greg Clayton63094e02010-06-23 01:19:29 +0000459 return m_opaque_sp.get() != rhs.m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000460}
461
462lldb_private::StackFrame *
463SBFrame::operator->() const
464{
Greg Clayton63094e02010-06-23 01:19:29 +0000465 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000466}
467
468lldb_private::StackFrame *
469SBFrame::get() const
470{
Greg Clayton63094e02010-06-23 01:19:29 +0000471 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000472}
473
474
475SBThread
476SBFrame::GetThread () const
477{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000478 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000479
Greg Claytondd62d722010-12-14 04:58:53 +0000480 SBThread sb_thread;
481 if (m_opaque_sp)
482 sb_thread.SetThread (m_opaque_sp->GetThread().GetSP());
Caroline Tice7826c882010-10-26 03:11:13 +0000483
484 if (log)
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000485 {
486 SBStream sstr;
487 sb_thread.GetDescription (sstr);
Greg Claytona66ba462010-10-30 04:51:46 +0000488 log->Printf ("SBFrame(%p)::GetThread () => SBThread(%p): %s", m_opaque_sp.get(),
489 sb_thread.get(), sstr.GetData());
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000490 }
Caroline Tice7826c882010-10-26 03:11:13 +0000491
Chris Lattner24943d22010-06-08 16:52:24 +0000492 return sb_thread;
493}
494
495const char *
496SBFrame::Disassemble () const
497{
Greg Claytona66ba462010-10-30 04:51:46 +0000498 const char *disassembly = NULL;
Greg Clayton63094e02010-06-23 01:19:29 +0000499 if (m_opaque_sp)
Greg Claytona66ba462010-10-30 04:51:46 +0000500 disassembly = m_opaque_sp->Disassemble();
Greg Clayton4e9267d2010-12-14 18:39:31 +0000501 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytona66ba462010-10-30 04:51:46 +0000502
503 if (log)
504 log->Printf ("SBFrame(%p)::Disassemble () => %s", m_opaque_sp.get(), disassembly);
505
506 return disassembly;
Chris Lattner24943d22010-06-08 16:52:24 +0000507}
508
509
Chris Lattner24943d22010-06-08 16:52:24 +0000510SBValueList
511SBFrame::GetVariables (bool arguments,
512 bool locals,
513 bool statics,
514 bool in_scope_only)
515{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000516 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000517
518 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000519 log->Printf ("SBFrame(%p)::GetVariables (arguments=%i, locals=%i, statics=%i, in_scope_only=%i)",
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000520 m_opaque_sp.get(),
Greg Claytona66ba462010-10-30 04:51:46 +0000521 arguments,
522 locals,
523 statics,
524 in_scope_only);
Caroline Tice7826c882010-10-26 03:11:13 +0000525
Chris Lattner24943d22010-06-08 16:52:24 +0000526 SBValueList value_list;
Greg Clayton63094e02010-06-23 01:19:29 +0000527 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000528 {
529 size_t i;
Greg Clayton17dae082010-09-02 02:59:18 +0000530 VariableList *variable_list = m_opaque_sp->GetVariableList(true);
Chris Lattner24943d22010-06-08 16:52:24 +0000531 if (variable_list)
532 {
533 const size_t num_variables = variable_list->GetSize();
534 if (num_variables)
535 {
536 for (i = 0; i < num_variables; ++i)
537 {
538 VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
539 if (variable_sp)
540 {
541 bool add_variable = false;
542 switch (variable_sp->GetScope())
543 {
544 case eValueTypeVariableGlobal:
545 case eValueTypeVariableStatic:
546 add_variable = statics;
547 break;
548
549 case eValueTypeVariableArgument:
550 add_variable = arguments;
551 break;
552
553 case eValueTypeVariableLocal:
554 add_variable = locals;
555 break;
Greg Clayton54e7afa2010-07-09 20:39:50 +0000556
557 default:
558 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000559 }
560 if (add_variable)
561 {
Greg Clayton63094e02010-06-23 01:19:29 +0000562 if (in_scope_only && !variable_sp->IsInScope(m_opaque_sp.get()))
Chris Lattner24943d22010-06-08 16:52:24 +0000563 continue;
564
Greg Clayton17dae082010-09-02 02:59:18 +0000565 value_list.Append(m_opaque_sp->GetValueObjectForFrameVariable (variable_sp));
Chris Lattner24943d22010-06-08 16:52:24 +0000566 }
567 }
568 }
569 }
Greg Clayton17dae082010-09-02 02:59:18 +0000570 }
Chris Lattner24943d22010-06-08 16:52:24 +0000571 }
Caroline Tice7826c882010-10-26 03:11:13 +0000572
573 if (log)
574 {
Greg Claytona66ba462010-10-30 04:51:46 +0000575 log->Printf ("SBFrame(%p)::GetVariables (...) => SBValueList(%p)", m_opaque_sp.get(),
Caroline Tice61ba7ec2010-10-26 23:49:36 +0000576 value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000577 }
578
Chris Lattner24943d22010-06-08 16:52:24 +0000579 return value_list;
580}
581
Greg Clayton4e9267d2010-12-14 18:39:31 +0000582SBValueList
Chris Lattner24943d22010-06-08 16:52:24 +0000583SBFrame::GetRegisters ()
584{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000585 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Tice7826c882010-10-26 03:11:13 +0000586
Chris Lattner24943d22010-06-08 16:52:24 +0000587 SBValueList value_list;
Greg Clayton63094e02010-06-23 01:19:29 +0000588 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000589 {
Greg Clayton63094e02010-06-23 01:19:29 +0000590 RegisterContext *reg_ctx = m_opaque_sp->GetRegisterContext();
Chris Lattner24943d22010-06-08 16:52:24 +0000591 if (reg_ctx)
592 {
593 const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
594 for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
595 {
Greg Claytonbf8e42b2010-10-14 22:52:14 +0000596 value_list.Append(ValueObjectSP (new ValueObjectRegisterSet (NULL, reg_ctx, set_idx)));
Chris Lattner24943d22010-06-08 16:52:24 +0000597 }
598 }
599 }
Caroline Tice7826c882010-10-26 03:11:13 +0000600
601 if (log)
Greg Claytona66ba462010-10-30 04:51:46 +0000602 log->Printf ("SBFrame(%p)::Registers () => SBValueList(%p)", m_opaque_sp.get(), value_list.get());
Caroline Tice7826c882010-10-26 03:11:13 +0000603
Chris Lattner24943d22010-06-08 16:52:24 +0000604 return value_list;
605}
606
Caroline Tice98f930f2010-09-20 05:20:02 +0000607bool
608SBFrame::GetDescription (SBStream &description)
609{
610 if (m_opaque_sp)
611 {
Greg Clayton49ce6822010-10-31 03:01:06 +0000612 Stream &s = description.ref();
613 m_opaque_sp->DumpUsingSettingsFormat (&s);
Caroline Tice98f930f2010-09-20 05:20:02 +0000614 }
615 else
616 description.Printf ("No value");
617
618 return true;
619}
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000620
Greg Clayton4e9267d2010-12-14 18:39:31 +0000621SBValue
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000622SBFrame::EvaluateExpression (const char *expr)
623{
Greg Clayton4e9267d2010-12-14 18:39:31 +0000624 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Sean Callanan94d255f2010-12-07 22:55:01 +0000625
Greg Clayton4e9267d2010-12-14 18:39:31 +0000626 LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Greg Claytona66ba462010-10-30 04:51:46 +0000627
Greg Clayton4e9267d2010-12-14 18:39:31 +0000628 SBValue expr_result;
Greg Claytona66ba462010-10-30 04:51:46 +0000629 if (log)
630 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\")...", m_opaque_sp.get(), expr);
631
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000632 if (m_opaque_sp)
633 {
Greg Clayton4e9267d2010-12-14 18:39:31 +0000634 ExecutionResults exe_results;
Greg Clayton427f2902010-12-14 02:59:59 +0000635 const bool unwind_on_error = true;
636
637 exe_results = m_opaque_sp->GetThread().GetProcess().GetTarget().EvaluateExpression(expr, m_opaque_sp.get(), unwind_on_error, *expr_result);
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000638 }
Greg Claytona66ba462010-10-30 04:51:46 +0000639
Sean Callanan94d255f2010-12-07 22:55:01 +0000640 if (expr_log)
641 expr_log->Printf("** [SBFrame::EvaluateExpression] Expression result is %s, summary %s **", expr_result.GetValue(*this), expr_result.GetSummary(*this));
642
Greg Claytona66ba462010-10-30 04:51:46 +0000643 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000644 log->Printf ("SBFrame(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr, expr_result.get());
Greg Claytona66ba462010-10-30 04:51:46 +0000645
Greg Clayton49ce6822010-10-31 03:01:06 +0000646 return expr_result;
Greg Clayton66ed2fb2010-10-05 00:00:42 +0000647}