1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
//===-- SBFrame.cpp ---------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/API/SBFrame.h"
#include <string>
#include <algorithm>
#include "lldb/lldb-types.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Thread.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBValue.h"
#include "lldb/API/SBAddress.h"
#include "lldb/API/SBSymbolContext.h"
#include "lldb/API/SBThread.h"
using namespace lldb;
using namespace lldb_private;
SBFrame::SBFrame () :
m_opaque_sp ()
{
}
SBFrame::SBFrame (const lldb::StackFrameSP &lldb_object_sp) :
m_opaque_sp (lldb_object_sp)
{
}
SBFrame::~SBFrame()
{
}
void
SBFrame::SetFrame (const lldb::StackFrameSP &lldb_object_sp)
{
m_opaque_sp = lldb_object_sp;
}
bool
SBFrame::IsValid() const
{
return (m_opaque_sp.get() != NULL);
}
SBSymbolContext
SBFrame::GetSymbolContext (uint32_t resolve_scope) const
{
SBSymbolContext sb_sym_ctx;
if (m_opaque_sp)
sb_sym_ctx.SetSymbolContext(&m_opaque_sp->GetSymbolContext (resolve_scope));
return sb_sym_ctx;
}
SBModule
SBFrame::GetModule () const
{
SBModule sb_module (m_opaque_sp->GetSymbolContext (eSymbolContextModule).module_sp);
return sb_module;
}
SBCompileUnit
SBFrame::GetCompileUnit () const
{
SBCompileUnit sb_comp_unit(m_opaque_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
return sb_comp_unit;
}
SBFunction
SBFrame::GetFunction () const
{
SBFunction sb_function(m_opaque_sp->GetSymbolContext (eSymbolContextFunction).function);
return sb_function;
}
SBBlock
SBFrame::GetBlock () const
{
SBBlock sb_block(m_opaque_sp->GetSymbolContext (eSymbolContextBlock).block);
return sb_block;
}
SBLineEntry
SBFrame::GetLineEntry () const
{
SBLineEntry sb_line_entry(&m_opaque_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry);
return sb_line_entry;
}
uint32_t
SBFrame::GetFrameID () const
{
if (m_opaque_sp)
return m_opaque_sp->GetFrameIndex ();
else
return UINT32_MAX;
}
lldb::addr_t
SBFrame::GetPC () const
{
if (m_opaque_sp)
return m_opaque_sp->GetFrameCodeAddress().GetLoadAddress (&m_opaque_sp->GetThread().GetProcess());
return LLDB_INVALID_ADDRESS;
}
bool
SBFrame::SetPC (lldb::addr_t new_pc)
{
if (m_opaque_sp)
return m_opaque_sp->GetRegisterContext()->SetPC (new_pc);
return false;
}
lldb::addr_t
SBFrame::GetSP () const
{
if (m_opaque_sp)
return m_opaque_sp->GetRegisterContext()->GetSP();
return LLDB_INVALID_ADDRESS;
}
lldb::addr_t
SBFrame::GetFP () const
{
if (m_opaque_sp)
return m_opaque_sp->GetRegisterContext()->GetFP();
return LLDB_INVALID_ADDRESS;
}
SBAddress
SBFrame::GetPCAddress () const
{
SBAddress sb_addr;
if (m_opaque_sp)
sb_addr.SetAddress (&m_opaque_sp->GetFrameCodeAddress());
return sb_addr;
}
void
SBFrame::Clear()
{
m_opaque_sp.reset();
}
SBValue
SBFrame::LookupVar (const char *var_name)
{
lldb::VariableSP var_sp;
if (IsValid ())
{
lldb_private::VariableList variable_list;
SBSymbolContext sc = GetSymbolContext (eSymbolContextEverything);
SBBlock block = sc.GetBlock();
if (block.IsValid())
block.AppendVariables (true, true, &variable_list);
const uint32_t num_variables = variable_list.GetSize();
bool found = false;
for (uint32_t i = 0; i < num_variables && !found; ++i)
{
var_sp = variable_list.GetVariableAtIndex(i);
if (var_sp
&& (var_sp.get()->GetName() == lldb_private::ConstString(var_name)))
found = true;
}
if (!found)
var_sp.reset();
}
SBValue sb_value (ValueObjectSP (new ValueObjectVariable (var_sp)));
return sb_value;
}
SBValue
SBFrame::LookupVarInScope (const char *var_name, const char *scope)
{
lldb::VariableSP var_sp;
if (IsValid())
{
std::string scope_str = scope;
lldb::ValueType var_scope = eValueTypeInvalid;
// Convert scope_str to be all lowercase;
std::transform (scope_str.begin(), scope_str.end(), scope_str.begin(), ::tolower);
if (scope_str.compare ("global") == 0)
var_scope = eValueTypeVariableGlobal;
else if (scope_str.compare ("local") == 0)
var_scope = eValueTypeVariableLocal;
else if (scope_str.compare ("parameter") == 0)
var_scope = eValueTypeVariableArgument;
if (var_scope != eValueTypeInvalid)
{
lldb_private::VariableList variable_list;
SBSymbolContext sc = GetSymbolContext (eSymbolContextEverything);
SBBlock block = sc.GetBlock();
if (block.IsValid())
block.AppendVariables (true, true, &variable_list);
const uint32_t num_variables = variable_list.GetSize();
bool found = false;
for (uint32_t i = 0; i < num_variables && !found; ++i)
{
var_sp = variable_list.GetVariableAtIndex(i);
if (var_sp
&& (var_sp.get()->GetName() == lldb_private::ConstString(var_name))
&& var_sp.get()->GetScope() == var_scope)
found = true;
}
if (!found)
var_sp.reset();
}
}
SBValue sb_value (ValueObjectSP (new ValueObjectVariable (var_sp)));
return sb_value;
}
bool
SBFrame::operator == (const SBFrame &rhs) const
{
return m_opaque_sp.get() == rhs.m_opaque_sp.get();
}
bool
SBFrame::operator != (const SBFrame &rhs) const
{
return m_opaque_sp.get() != rhs.m_opaque_sp.get();
}
lldb_private::StackFrame *
SBFrame::operator->() const
{
return m_opaque_sp.get();
}
lldb_private::StackFrame *
SBFrame::get() const
{
return m_opaque_sp.get();
}
SBThread
SBFrame::GetThread () const
{
SBThread sb_thread (m_opaque_sp->GetThread().GetSP());
return sb_thread;
}
const char *
SBFrame::Disassemble () const
{
if (m_opaque_sp)
return m_opaque_sp->Disassemble();
return NULL;
}
lldb_private::StackFrame *
SBFrame::GetLLDBObjectPtr ()
{
return m_opaque_sp.get();
}
SBValueList
SBFrame::GetVariables (bool arguments,
bool locals,
bool statics,
bool in_scope_only)
{
SBValueList value_list;
if (m_opaque_sp)
{
size_t i;
VariableList *variable_list = m_opaque_sp->GetVariableList(true);
if (variable_list)
{
const size_t num_variables = variable_list->GetSize();
if (num_variables)
{
for (i = 0; i < num_variables; ++i)
{
VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
if (variable_sp)
{
bool add_variable = false;
switch (variable_sp->GetScope())
{
case eValueTypeVariableGlobal:
case eValueTypeVariableStatic:
add_variable = statics;
break;
case eValueTypeVariableArgument:
add_variable = arguments;
break;
case eValueTypeVariableLocal:
add_variable = locals;
break;
default:
break;
}
if (add_variable)
{
if (in_scope_only && !variable_sp->IsInScope(m_opaque_sp.get()))
continue;
value_list.Append(m_opaque_sp->GetValueObjectForFrameVariable (variable_sp));
}
}
}
}
}
}
return value_list;
}
lldb::SBValueList
SBFrame::GetRegisters ()
{
SBValueList value_list;
if (m_opaque_sp)
{
RegisterContext *reg_ctx = m_opaque_sp->GetRegisterContext();
if (reg_ctx)
{
const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
{
value_list.Append(ValueObjectSP (new ValueObjectRegisterSet (reg_ctx, set_idx)));
}
}
}
return value_list;
}
|