xref: /freebsd-src/contrib/llvm-project/lldb/source/API/SBFrame.cpp (revision 0eae32dcef82f6f06de6419a0d623d7def0cc8f6)
1 //===-- SBFrame.cpp -------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <algorithm>
10 #include <set>
11 #include <string>
12 
13 #include "lldb/API/SBFrame.h"
14 
15 #include "lldb/lldb-types.h"
16 
17 #include "SBReproducerPrivate.h"
18 #include "Utils.h"
19 #include "lldb/Core/Address.h"
20 #include "lldb/Core/StreamFile.h"
21 #include "lldb/Core/ValueObjectRegister.h"
22 #include "lldb/Core/ValueObjectVariable.h"
23 #include "lldb/Expression/ExpressionVariable.h"
24 #include "lldb/Expression/UserExpression.h"
25 #include "lldb/Host/Host.h"
26 #include "lldb/Symbol/Block.h"
27 #include "lldb/Symbol/Function.h"
28 #include "lldb/Symbol/Symbol.h"
29 #include "lldb/Symbol/SymbolContext.h"
30 #include "lldb/Symbol/Variable.h"
31 #include "lldb/Symbol/VariableList.h"
32 #include "lldb/Target/ExecutionContext.h"
33 #include "lldb/Target/Process.h"
34 #include "lldb/Target/RegisterContext.h"
35 #include "lldb/Target/StackFrame.h"
36 #include "lldb/Target/StackFrameRecognizer.h"
37 #include "lldb/Target/StackID.h"
38 #include "lldb/Target/Target.h"
39 #include "lldb/Target/Thread.h"
40 #include "lldb/Utility/ConstString.h"
41 #include "lldb/Utility/Stream.h"
42 
43 #include "lldb/API/SBAddress.h"
44 #include "lldb/API/SBDebugger.h"
45 #include "lldb/API/SBExpressionOptions.h"
46 #include "lldb/API/SBStream.h"
47 #include "lldb/API/SBSymbolContext.h"
48 #include "lldb/API/SBThread.h"
49 #include "lldb/API/SBValue.h"
50 #include "lldb/API/SBVariablesOptions.h"
51 
52 #include "llvm/Support/PrettyStackTrace.h"
53 
54 using namespace lldb;
55 using namespace lldb_private;
56 
57 SBFrame::SBFrame() : m_opaque_sp(new ExecutionContextRef()) {
58   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBFrame);
59 }
60 
61 SBFrame::SBFrame(const StackFrameSP &lldb_object_sp)
62     : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {
63   LLDB_RECORD_CONSTRUCTOR(SBFrame, (const lldb::StackFrameSP &),
64                           lldb_object_sp);
65 }
66 
67 SBFrame::SBFrame(const SBFrame &rhs) : m_opaque_sp() {
68   LLDB_RECORD_CONSTRUCTOR(SBFrame, (const lldb::SBFrame &), rhs);
69 
70   m_opaque_sp = clone(rhs.m_opaque_sp);
71 }
72 
73 SBFrame::~SBFrame() = default;
74 
75 const SBFrame &SBFrame::operator=(const SBFrame &rhs) {
76   LLDB_RECORD_METHOD(const lldb::SBFrame &,
77                      SBFrame, operator=,(const lldb::SBFrame &), rhs);
78 
79   if (this != &rhs)
80     m_opaque_sp = clone(rhs.m_opaque_sp);
81   return LLDB_RECORD_RESULT(*this);
82 }
83 
84 StackFrameSP SBFrame::GetFrameSP() const {
85   return (m_opaque_sp ? m_opaque_sp->GetFrameSP() : StackFrameSP());
86 }
87 
88 void SBFrame::SetFrameSP(const StackFrameSP &lldb_object_sp) {
89   return m_opaque_sp->SetFrameSP(lldb_object_sp);
90 }
91 
92 bool SBFrame::IsValid() const {
93   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFrame, IsValid);
94   return this->operator bool();
95 }
96 SBFrame::operator bool() const {
97   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFrame, operator bool);
98 
99   std::unique_lock<std::recursive_mutex> lock;
100   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
101 
102   Target *target = exe_ctx.GetTargetPtr();
103   Process *process = exe_ctx.GetProcessPtr();
104   if (target && process) {
105     Process::StopLocker stop_locker;
106     if (stop_locker.TryLock(&process->GetRunLock()))
107       return GetFrameSP().get() != nullptr;
108   }
109 
110   // Without a target & process we can't have a valid stack frame.
111   return false;
112 }
113 
114 SBSymbolContext SBFrame::GetSymbolContext(uint32_t resolve_scope) const {
115   LLDB_RECORD_METHOD_CONST(lldb::SBSymbolContext, SBFrame, GetSymbolContext,
116                            (uint32_t), resolve_scope);
117 
118   SBSymbolContext sb_sym_ctx;
119   std::unique_lock<std::recursive_mutex> lock;
120   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
121   SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope);
122   Target *target = exe_ctx.GetTargetPtr();
123   Process *process = exe_ctx.GetProcessPtr();
124   if (target && process) {
125     Process::StopLocker stop_locker;
126     if (stop_locker.TryLock(&process->GetRunLock())) {
127       if (StackFrame *frame = exe_ctx.GetFramePtr())
128         sb_sym_ctx = frame->GetSymbolContext(scope);
129     }
130   }
131 
132   return LLDB_RECORD_RESULT(sb_sym_ctx);
133 }
134 
135 SBModule SBFrame::GetModule() const {
136   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBModule, SBFrame, GetModule);
137 
138   SBModule sb_module;
139   ModuleSP module_sp;
140   std::unique_lock<std::recursive_mutex> lock;
141   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
142 
143   StackFrame *frame = nullptr;
144   Target *target = exe_ctx.GetTargetPtr();
145   Process *process = exe_ctx.GetProcessPtr();
146   if (target && process) {
147     Process::StopLocker stop_locker;
148     if (stop_locker.TryLock(&process->GetRunLock())) {
149       frame = exe_ctx.GetFramePtr();
150       if (frame) {
151         module_sp = frame->GetSymbolContext(eSymbolContextModule).module_sp;
152         sb_module.SetSP(module_sp);
153       }
154     }
155   }
156 
157   return LLDB_RECORD_RESULT(sb_module);
158 }
159 
160 SBCompileUnit SBFrame::GetCompileUnit() const {
161   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBCompileUnit, SBFrame,
162                                    GetCompileUnit);
163 
164   SBCompileUnit sb_comp_unit;
165   std::unique_lock<std::recursive_mutex> lock;
166   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
167 
168   StackFrame *frame = nullptr;
169   Target *target = exe_ctx.GetTargetPtr();
170   Process *process = exe_ctx.GetProcessPtr();
171   if (target && process) {
172     Process::StopLocker stop_locker;
173     if (stop_locker.TryLock(&process->GetRunLock())) {
174       frame = exe_ctx.GetFramePtr();
175       if (frame) {
176         sb_comp_unit.reset(
177             frame->GetSymbolContext(eSymbolContextCompUnit).comp_unit);
178       }
179     }
180   }
181 
182   return LLDB_RECORD_RESULT(sb_comp_unit);
183 }
184 
185 SBFunction SBFrame::GetFunction() const {
186   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBFunction, SBFrame, GetFunction);
187 
188   SBFunction sb_function;
189   std::unique_lock<std::recursive_mutex> lock;
190   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
191 
192   StackFrame *frame = nullptr;
193   Target *target = exe_ctx.GetTargetPtr();
194   Process *process = exe_ctx.GetProcessPtr();
195   if (target && process) {
196     Process::StopLocker stop_locker;
197     if (stop_locker.TryLock(&process->GetRunLock())) {
198       frame = exe_ctx.GetFramePtr();
199       if (frame) {
200         sb_function.reset(
201             frame->GetSymbolContext(eSymbolContextFunction).function);
202       }
203     }
204   }
205 
206   return LLDB_RECORD_RESULT(sb_function);
207 }
208 
209 SBSymbol SBFrame::GetSymbol() const {
210   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBSymbol, SBFrame, GetSymbol);
211 
212   SBSymbol sb_symbol;
213   std::unique_lock<std::recursive_mutex> lock;
214   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
215 
216   StackFrame *frame = nullptr;
217   Target *target = exe_ctx.GetTargetPtr();
218   Process *process = exe_ctx.GetProcessPtr();
219   if (target && process) {
220     Process::StopLocker stop_locker;
221     if (stop_locker.TryLock(&process->GetRunLock())) {
222       frame = exe_ctx.GetFramePtr();
223       if (frame) {
224         sb_symbol.reset(frame->GetSymbolContext(eSymbolContextSymbol).symbol);
225       }
226     }
227   }
228 
229   return LLDB_RECORD_RESULT(sb_symbol);
230 }
231 
232 SBBlock SBFrame::GetBlock() const {
233   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBlock, SBFrame, GetBlock);
234 
235   SBBlock sb_block;
236   std::unique_lock<std::recursive_mutex> lock;
237   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
238 
239   StackFrame *frame = nullptr;
240   Target *target = exe_ctx.GetTargetPtr();
241   Process *process = exe_ctx.GetProcessPtr();
242   if (target && process) {
243     Process::StopLocker stop_locker;
244     if (stop_locker.TryLock(&process->GetRunLock())) {
245       frame = exe_ctx.GetFramePtr();
246       if (frame)
247         sb_block.SetPtr(frame->GetSymbolContext(eSymbolContextBlock).block);
248     }
249   }
250   return LLDB_RECORD_RESULT(sb_block);
251 }
252 
253 SBBlock SBFrame::GetFrameBlock() const {
254   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBBlock, SBFrame, GetFrameBlock);
255 
256   SBBlock sb_block;
257   std::unique_lock<std::recursive_mutex> lock;
258   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
259 
260   StackFrame *frame = nullptr;
261   Target *target = exe_ctx.GetTargetPtr();
262   Process *process = exe_ctx.GetProcessPtr();
263   if (target && process) {
264     Process::StopLocker stop_locker;
265     if (stop_locker.TryLock(&process->GetRunLock())) {
266       frame = exe_ctx.GetFramePtr();
267       if (frame)
268         sb_block.SetPtr(frame->GetFrameBlock());
269     }
270   }
271   return LLDB_RECORD_RESULT(sb_block);
272 }
273 
274 SBLineEntry SBFrame::GetLineEntry() const {
275   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBLineEntry, SBFrame, GetLineEntry);
276 
277   SBLineEntry sb_line_entry;
278   std::unique_lock<std::recursive_mutex> lock;
279   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
280 
281   StackFrame *frame = nullptr;
282   Target *target = exe_ctx.GetTargetPtr();
283   Process *process = exe_ctx.GetProcessPtr();
284   if (target && process) {
285     Process::StopLocker stop_locker;
286     if (stop_locker.TryLock(&process->GetRunLock())) {
287       frame = exe_ctx.GetFramePtr();
288       if (frame) {
289         sb_line_entry.SetLineEntry(
290             frame->GetSymbolContext(eSymbolContextLineEntry).line_entry);
291       }
292     }
293   }
294   return LLDB_RECORD_RESULT(sb_line_entry);
295 }
296 
297 uint32_t SBFrame::GetFrameID() const {
298   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBFrame, GetFrameID);
299 
300   uint32_t frame_idx = UINT32_MAX;
301 
302   std::unique_lock<std::recursive_mutex> lock;
303   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
304 
305   StackFrame *frame = exe_ctx.GetFramePtr();
306   if (frame)
307     frame_idx = frame->GetFrameIndex();
308 
309   return frame_idx;
310 }
311 
312 lldb::addr_t SBFrame::GetCFA() const {
313   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::addr_t, SBFrame, GetCFA);
314 
315   std::unique_lock<std::recursive_mutex> lock;
316   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
317 
318   StackFrame *frame = exe_ctx.GetFramePtr();
319   if (frame)
320     return frame->GetStackID().GetCallFrameAddress();
321   return LLDB_INVALID_ADDRESS;
322 }
323 
324 addr_t SBFrame::GetPC() const {
325   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::addr_t, SBFrame, GetPC);
326 
327   addr_t addr = LLDB_INVALID_ADDRESS;
328   std::unique_lock<std::recursive_mutex> lock;
329   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
330 
331   StackFrame *frame = nullptr;
332   Target *target = exe_ctx.GetTargetPtr();
333   Process *process = exe_ctx.GetProcessPtr();
334   if (target && process) {
335     Process::StopLocker stop_locker;
336     if (stop_locker.TryLock(&process->GetRunLock())) {
337       frame = exe_ctx.GetFramePtr();
338       if (frame) {
339         addr = frame->GetFrameCodeAddress().GetOpcodeLoadAddress(
340             target, AddressClass::eCode);
341       }
342     }
343   }
344 
345   return addr;
346 }
347 
348 bool SBFrame::SetPC(addr_t new_pc) {
349   LLDB_RECORD_METHOD(bool, SBFrame, SetPC, (lldb::addr_t), new_pc);
350 
351   bool ret_val = false;
352   std::unique_lock<std::recursive_mutex> lock;
353   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
354 
355   Target *target = exe_ctx.GetTargetPtr();
356   Process *process = exe_ctx.GetProcessPtr();
357   if (target && process) {
358     Process::StopLocker stop_locker;
359     if (stop_locker.TryLock(&process->GetRunLock())) {
360       if (StackFrame *frame = exe_ctx.GetFramePtr()) {
361         if (RegisterContextSP reg_ctx_sp = frame->GetRegisterContext()) {
362           ret_val = reg_ctx_sp->SetPC(new_pc);
363         }
364       }
365     }
366   }
367 
368   return ret_val;
369 }
370 
371 addr_t SBFrame::GetSP() const {
372   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::addr_t, SBFrame, GetSP);
373 
374   addr_t addr = LLDB_INVALID_ADDRESS;
375   std::unique_lock<std::recursive_mutex> lock;
376   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
377 
378   Target *target = exe_ctx.GetTargetPtr();
379   Process *process = exe_ctx.GetProcessPtr();
380   if (target && process) {
381     Process::StopLocker stop_locker;
382     if (stop_locker.TryLock(&process->GetRunLock())) {
383       if (StackFrame *frame = exe_ctx.GetFramePtr()) {
384         if (RegisterContextSP reg_ctx_sp = frame->GetRegisterContext()) {
385           addr = reg_ctx_sp->GetSP();
386         }
387       }
388     }
389   }
390 
391   return addr;
392 }
393 
394 addr_t SBFrame::GetFP() const {
395   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::addr_t, SBFrame, GetFP);
396 
397   addr_t addr = LLDB_INVALID_ADDRESS;
398   std::unique_lock<std::recursive_mutex> lock;
399   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
400 
401   Target *target = exe_ctx.GetTargetPtr();
402   Process *process = exe_ctx.GetProcessPtr();
403   if (target && process) {
404     Process::StopLocker stop_locker;
405     if (stop_locker.TryLock(&process->GetRunLock())) {
406       if (StackFrame *frame = exe_ctx.GetFramePtr()) {
407         if (RegisterContextSP reg_ctx_sp = frame->GetRegisterContext()) {
408           addr = reg_ctx_sp->GetFP();
409         }
410       }
411     }
412   }
413 
414   return addr;
415 }
416 
417 SBAddress SBFrame::GetPCAddress() const {
418   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBAddress, SBFrame, GetPCAddress);
419 
420   SBAddress sb_addr;
421   std::unique_lock<std::recursive_mutex> lock;
422   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
423 
424   StackFrame *frame = exe_ctx.GetFramePtr();
425   Target *target = exe_ctx.GetTargetPtr();
426   Process *process = exe_ctx.GetProcessPtr();
427   if (target && process) {
428     Process::StopLocker stop_locker;
429     if (stop_locker.TryLock(&process->GetRunLock())) {
430       frame = exe_ctx.GetFramePtr();
431       if (frame)
432         sb_addr.SetAddress(frame->GetFrameCodeAddress());
433     }
434   }
435   return LLDB_RECORD_RESULT(sb_addr);
436 }
437 
438 void SBFrame::Clear() {
439   LLDB_RECORD_METHOD_NO_ARGS(void, SBFrame, Clear);
440 
441   m_opaque_sp->Clear();
442 }
443 
444 lldb::SBValue SBFrame::GetValueForVariablePath(const char *var_path) {
445   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, GetValueForVariablePath,
446                      (const char *), var_path);
447 
448   SBValue sb_value;
449   std::unique_lock<std::recursive_mutex> lock;
450   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
451 
452   StackFrame *frame = exe_ctx.GetFramePtr();
453   Target *target = exe_ctx.GetTargetPtr();
454   if (frame && target) {
455     lldb::DynamicValueType use_dynamic =
456         frame->CalculateTarget()->GetPreferDynamicValue();
457     sb_value = GetValueForVariablePath(var_path, use_dynamic);
458   }
459   return LLDB_RECORD_RESULT(sb_value);
460 }
461 
462 lldb::SBValue SBFrame::GetValueForVariablePath(const char *var_path,
463                                                DynamicValueType use_dynamic) {
464   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, GetValueForVariablePath,
465                      (const char *, lldb::DynamicValueType), var_path,
466                      use_dynamic);
467 
468   SBValue sb_value;
469   if (var_path == nullptr || var_path[0] == '\0') {
470     return LLDB_RECORD_RESULT(sb_value);
471   }
472 
473   std::unique_lock<std::recursive_mutex> lock;
474   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
475 
476   StackFrame *frame = nullptr;
477   Target *target = exe_ctx.GetTargetPtr();
478   Process *process = exe_ctx.GetProcessPtr();
479   if (target && process) {
480     Process::StopLocker stop_locker;
481     if (stop_locker.TryLock(&process->GetRunLock())) {
482       frame = exe_ctx.GetFramePtr();
483       if (frame) {
484         VariableSP var_sp;
485         Status error;
486         ValueObjectSP value_sp(frame->GetValueForVariableExpressionPath(
487             var_path, eNoDynamicValues,
488             StackFrame::eExpressionPathOptionCheckPtrVsMember |
489                 StackFrame::eExpressionPathOptionsAllowDirectIVarAccess,
490             var_sp, error));
491         sb_value.SetSP(value_sp, use_dynamic);
492       }
493     }
494   }
495   return LLDB_RECORD_RESULT(sb_value);
496 }
497 
498 SBValue SBFrame::FindVariable(const char *name) {
499   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindVariable, (const char *),
500                      name);
501 
502   SBValue value;
503   std::unique_lock<std::recursive_mutex> lock;
504   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
505 
506   StackFrame *frame = exe_ctx.GetFramePtr();
507   Target *target = exe_ctx.GetTargetPtr();
508   if (frame && target) {
509     lldb::DynamicValueType use_dynamic =
510         frame->CalculateTarget()->GetPreferDynamicValue();
511     value = FindVariable(name, use_dynamic);
512   }
513   return LLDB_RECORD_RESULT(value);
514 }
515 
516 SBValue SBFrame::FindVariable(const char *name,
517                               lldb::DynamicValueType use_dynamic) {
518   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindVariable,
519                      (const char *, lldb::DynamicValueType), name, use_dynamic);
520 
521   VariableSP var_sp;
522   SBValue sb_value;
523 
524   if (name == nullptr || name[0] == '\0') {
525     return LLDB_RECORD_RESULT(sb_value);
526   }
527 
528   ValueObjectSP value_sp;
529   std::unique_lock<std::recursive_mutex> lock;
530   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
531 
532   StackFrame *frame = nullptr;
533   Target *target = exe_ctx.GetTargetPtr();
534   Process *process = exe_ctx.GetProcessPtr();
535   if (target && process) {
536     Process::StopLocker stop_locker;
537     if (stop_locker.TryLock(&process->GetRunLock())) {
538       frame = exe_ctx.GetFramePtr();
539       if (frame) {
540         value_sp = frame->FindVariable(ConstString(name));
541 
542         if (value_sp)
543           sb_value.SetSP(value_sp, use_dynamic);
544       }
545     }
546   }
547 
548   return LLDB_RECORD_RESULT(sb_value);
549 }
550 
551 SBValue SBFrame::FindValue(const char *name, ValueType value_type) {
552   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindValue,
553                      (const char *, lldb::ValueType), name, value_type);
554 
555   SBValue value;
556   std::unique_lock<std::recursive_mutex> lock;
557   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
558 
559   StackFrame *frame = exe_ctx.GetFramePtr();
560   Target *target = exe_ctx.GetTargetPtr();
561   if (frame && target) {
562     lldb::DynamicValueType use_dynamic =
563         frame->CalculateTarget()->GetPreferDynamicValue();
564     value = FindValue(name, value_type, use_dynamic);
565   }
566   return LLDB_RECORD_RESULT(value);
567 }
568 
569 SBValue SBFrame::FindValue(const char *name, ValueType value_type,
570                            lldb::DynamicValueType use_dynamic) {
571   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindValue,
572                      (const char *, lldb::ValueType, lldb::DynamicValueType),
573                      name, value_type, use_dynamic);
574 
575   SBValue sb_value;
576 
577   if (name == nullptr || name[0] == '\0') {
578     return LLDB_RECORD_RESULT(sb_value);
579   }
580 
581   ValueObjectSP value_sp;
582   std::unique_lock<std::recursive_mutex> lock;
583   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
584 
585   StackFrame *frame = nullptr;
586   Target *target = exe_ctx.GetTargetPtr();
587   Process *process = exe_ctx.GetProcessPtr();
588   if (target && process) {
589     Process::StopLocker stop_locker;
590     if (stop_locker.TryLock(&process->GetRunLock())) {
591       frame = exe_ctx.GetFramePtr();
592       if (frame) {
593         VariableList variable_list;
594 
595         switch (value_type) {
596         case eValueTypeVariableGlobal:      // global variable
597         case eValueTypeVariableStatic:      // static variable
598         case eValueTypeVariableArgument:    // function argument variables
599         case eValueTypeVariableLocal:       // function local variables
600         case eValueTypeVariableThreadLocal: // thread local variables
601         {
602           SymbolContext sc(frame->GetSymbolContext(eSymbolContextBlock));
603 
604           const bool can_create = true;
605           const bool get_parent_variables = true;
606           const bool stop_if_block_is_inlined_function = true;
607 
608           if (sc.block)
609             sc.block->AppendVariables(
610                 can_create, get_parent_variables,
611                 stop_if_block_is_inlined_function,
612                 [frame](Variable *v) { return v->IsInScope(frame); },
613                 &variable_list);
614           if (value_type == eValueTypeVariableGlobal) {
615             const bool get_file_globals = true;
616             VariableList *frame_vars = frame->GetVariableList(get_file_globals);
617             if (frame_vars)
618               frame_vars->AppendVariablesIfUnique(variable_list);
619           }
620           ConstString const_name(name);
621           VariableSP variable_sp(
622               variable_list.FindVariable(const_name, value_type));
623           if (variable_sp) {
624             value_sp = frame->GetValueObjectForFrameVariable(variable_sp,
625                                                              eNoDynamicValues);
626             sb_value.SetSP(value_sp, use_dynamic);
627           }
628         } break;
629 
630         case eValueTypeRegister: // stack frame register value
631         {
632           RegisterContextSP reg_ctx(frame->GetRegisterContext());
633           if (reg_ctx) {
634             if (const RegisterInfo *reg_info =
635                     reg_ctx->GetRegisterInfoByName(name)) {
636               value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_info);
637               sb_value.SetSP(value_sp);
638             }
639           }
640         } break;
641 
642         case eValueTypeRegisterSet: // A collection of stack frame register
643                                     // values
644         {
645           RegisterContextSP reg_ctx(frame->GetRegisterContext());
646           if (reg_ctx) {
647             const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
648             for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) {
649               const RegisterSet *reg_set = reg_ctx->GetRegisterSet(set_idx);
650               if (reg_set &&
651                   ((reg_set->name && strcasecmp(reg_set->name, name) == 0) ||
652                    (reg_set->short_name &&
653                     strcasecmp(reg_set->short_name, name) == 0))) {
654                 value_sp =
655                     ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx);
656                 sb_value.SetSP(value_sp);
657                 break;
658               }
659             }
660           }
661         } break;
662 
663         case eValueTypeConstResult: // constant result variables
664         {
665           ConstString const_name(name);
666           ExpressionVariableSP expr_var_sp(
667               target->GetPersistentVariable(const_name));
668           if (expr_var_sp) {
669             value_sp = expr_var_sp->GetValueObject();
670             sb_value.SetSP(value_sp, use_dynamic);
671           }
672         } break;
673 
674         default:
675           break;
676         }
677       }
678     }
679   }
680 
681   return LLDB_RECORD_RESULT(sb_value);
682 }
683 
684 bool SBFrame::IsEqual(const SBFrame &that) const {
685   LLDB_RECORD_METHOD_CONST(bool, SBFrame, IsEqual, (const lldb::SBFrame &),
686                            that);
687 
688   lldb::StackFrameSP this_sp = GetFrameSP();
689   lldb::StackFrameSP that_sp = that.GetFrameSP();
690   return (this_sp && that_sp && this_sp->GetStackID() == that_sp->GetStackID());
691 }
692 
693 bool SBFrame::operator==(const SBFrame &rhs) const {
694   LLDB_RECORD_METHOD_CONST(bool, SBFrame, operator==,(const lldb::SBFrame &),
695                            rhs);
696 
697   return IsEqual(rhs);
698 }
699 
700 bool SBFrame::operator!=(const SBFrame &rhs) const {
701   LLDB_RECORD_METHOD_CONST(bool, SBFrame, operator!=,(const lldb::SBFrame &),
702                            rhs);
703 
704   return !IsEqual(rhs);
705 }
706 
707 SBThread SBFrame::GetThread() const {
708   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBThread, SBFrame, GetThread);
709 
710   std::unique_lock<std::recursive_mutex> lock;
711   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
712 
713   ThreadSP thread_sp(exe_ctx.GetThreadSP());
714   SBThread sb_thread(thread_sp);
715 
716   return LLDB_RECORD_RESULT(sb_thread);
717 }
718 
719 const char *SBFrame::Disassemble() const {
720   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBFrame, Disassemble);
721 
722   const char *disassembly = nullptr;
723   std::unique_lock<std::recursive_mutex> lock;
724   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
725 
726   StackFrame *frame = nullptr;
727   Target *target = exe_ctx.GetTargetPtr();
728   Process *process = exe_ctx.GetProcessPtr();
729   if (target && process) {
730     Process::StopLocker stop_locker;
731     if (stop_locker.TryLock(&process->GetRunLock())) {
732       frame = exe_ctx.GetFramePtr();
733       if (frame) {
734         disassembly = frame->Disassemble();
735       }
736     }
737   }
738 
739   return disassembly;
740 }
741 
742 SBValueList SBFrame::GetVariables(bool arguments, bool locals, bool statics,
743                                   bool in_scope_only) {
744   LLDB_RECORD_METHOD(lldb::SBValueList, SBFrame, GetVariables,
745                      (bool, bool, bool, bool), arguments, locals, statics,
746                      in_scope_only);
747 
748   SBValueList value_list;
749   std::unique_lock<std::recursive_mutex> lock;
750   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
751 
752   StackFrame *frame = exe_ctx.GetFramePtr();
753   Target *target = exe_ctx.GetTargetPtr();
754   if (frame && target) {
755     lldb::DynamicValueType use_dynamic =
756         frame->CalculateTarget()->GetPreferDynamicValue();
757     const bool include_runtime_support_values =
758         target ? target->GetDisplayRuntimeSupportValues() : false;
759 
760     SBVariablesOptions options;
761     options.SetIncludeArguments(arguments);
762     options.SetIncludeLocals(locals);
763     options.SetIncludeStatics(statics);
764     options.SetInScopeOnly(in_scope_only);
765     options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
766     options.SetUseDynamic(use_dynamic);
767 
768     value_list = GetVariables(options);
769   }
770   return LLDB_RECORD_RESULT(value_list);
771 }
772 
773 lldb::SBValueList SBFrame::GetVariables(bool arguments, bool locals,
774                                         bool statics, bool in_scope_only,
775                                         lldb::DynamicValueType use_dynamic) {
776   LLDB_RECORD_METHOD(lldb::SBValueList, SBFrame, GetVariables,
777                      (bool, bool, bool, bool, lldb::DynamicValueType),
778                      arguments, locals, statics, in_scope_only, use_dynamic);
779 
780   std::unique_lock<std::recursive_mutex> lock;
781   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
782 
783   Target *target = exe_ctx.GetTargetPtr();
784   const bool include_runtime_support_values =
785       target ? target->GetDisplayRuntimeSupportValues() : false;
786   SBVariablesOptions options;
787   options.SetIncludeArguments(arguments);
788   options.SetIncludeLocals(locals);
789   options.SetIncludeStatics(statics);
790   options.SetInScopeOnly(in_scope_only);
791   options.SetIncludeRuntimeSupportValues(include_runtime_support_values);
792   options.SetUseDynamic(use_dynamic);
793   return LLDB_RECORD_RESULT(GetVariables(options));
794 }
795 
796 SBValueList SBFrame::GetVariables(const lldb::SBVariablesOptions &options) {
797   LLDB_RECORD_METHOD(lldb::SBValueList, SBFrame, GetVariables,
798                      (const lldb::SBVariablesOptions &), options);
799 
800   SBValueList value_list;
801   std::unique_lock<std::recursive_mutex> lock;
802   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
803 
804   StackFrame *frame = nullptr;
805   Target *target = exe_ctx.GetTargetPtr();
806 
807   const bool statics = options.GetIncludeStatics();
808   const bool arguments = options.GetIncludeArguments();
809   const bool recognized_arguments =
810         options.GetIncludeRecognizedArguments(SBTarget(exe_ctx.GetTargetSP()));
811   const bool locals = options.GetIncludeLocals();
812   const bool in_scope_only = options.GetInScopeOnly();
813   const bool include_runtime_support_values =
814       options.GetIncludeRuntimeSupportValues();
815   const lldb::DynamicValueType use_dynamic = options.GetUseDynamic();
816 
817 
818   std::set<VariableSP> variable_set;
819   Process *process = exe_ctx.GetProcessPtr();
820   if (target && process) {
821     Process::StopLocker stop_locker;
822     if (stop_locker.TryLock(&process->GetRunLock())) {
823       frame = exe_ctx.GetFramePtr();
824       if (frame) {
825         VariableList *variable_list = nullptr;
826         variable_list = frame->GetVariableList(true);
827         if (variable_list) {
828           const size_t num_variables = variable_list->GetSize();
829           if (num_variables) {
830             for (const VariableSP &variable_sp : *variable_list) {
831               if (variable_sp) {
832                 bool add_variable = false;
833                 switch (variable_sp->GetScope()) {
834                 case eValueTypeVariableGlobal:
835                 case eValueTypeVariableStatic:
836                 case eValueTypeVariableThreadLocal:
837                   add_variable = statics;
838                   break;
839 
840                 case eValueTypeVariableArgument:
841                   add_variable = arguments;
842                   break;
843 
844                 case eValueTypeVariableLocal:
845                   add_variable = locals;
846                   break;
847 
848                 default:
849                   break;
850                 }
851                 if (add_variable) {
852                   // Only add variables once so we don't end up with duplicates
853                   if (variable_set.find(variable_sp) == variable_set.end())
854                     variable_set.insert(variable_sp);
855                   else
856                     continue;
857 
858                   if (in_scope_only && !variable_sp->IsInScope(frame))
859                     continue;
860 
861                   ValueObjectSP valobj_sp(frame->GetValueObjectForFrameVariable(
862                       variable_sp, eNoDynamicValues));
863 
864                   if (!include_runtime_support_values && valobj_sp != nullptr &&
865                       valobj_sp->IsRuntimeSupportValue())
866                     continue;
867 
868                   SBValue value_sb;
869                   value_sb.SetSP(valobj_sp, use_dynamic);
870                   value_list.Append(value_sb);
871                 }
872               }
873             }
874           }
875         }
876         if (recognized_arguments) {
877           auto recognized_frame = frame->GetRecognizedFrame();
878           if (recognized_frame) {
879             ValueObjectListSP recognized_arg_list =
880                 recognized_frame->GetRecognizedArguments();
881             if (recognized_arg_list) {
882               for (auto &rec_value_sp : recognized_arg_list->GetObjects()) {
883                 SBValue value_sb;
884                 value_sb.SetSP(rec_value_sp, use_dynamic);
885                 value_list.Append(value_sb);
886               }
887             }
888           }
889         }
890       }
891     }
892   }
893 
894   return LLDB_RECORD_RESULT(value_list);
895 }
896 
897 SBValueList SBFrame::GetRegisters() {
898   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBValueList, SBFrame, GetRegisters);
899 
900   SBValueList value_list;
901   std::unique_lock<std::recursive_mutex> lock;
902   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
903 
904   StackFrame *frame = nullptr;
905   Target *target = exe_ctx.GetTargetPtr();
906   Process *process = exe_ctx.GetProcessPtr();
907   if (target && process) {
908     Process::StopLocker stop_locker;
909     if (stop_locker.TryLock(&process->GetRunLock())) {
910       frame = exe_ctx.GetFramePtr();
911       if (frame) {
912         RegisterContextSP reg_ctx(frame->GetRegisterContext());
913         if (reg_ctx) {
914           const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
915           for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx) {
916             value_list.Append(
917                 ValueObjectRegisterSet::Create(frame, reg_ctx, set_idx));
918           }
919         }
920       }
921     }
922   }
923 
924   return LLDB_RECORD_RESULT(value_list);
925 }
926 
927 SBValue SBFrame::FindRegister(const char *name) {
928   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, FindRegister, (const char *),
929                      name);
930 
931   SBValue result;
932   ValueObjectSP value_sp;
933   std::unique_lock<std::recursive_mutex> lock;
934   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
935 
936   StackFrame *frame = nullptr;
937   Target *target = exe_ctx.GetTargetPtr();
938   Process *process = exe_ctx.GetProcessPtr();
939   if (target && process) {
940     Process::StopLocker stop_locker;
941     if (stop_locker.TryLock(&process->GetRunLock())) {
942       frame = exe_ctx.GetFramePtr();
943       if (frame) {
944         RegisterContextSP reg_ctx(frame->GetRegisterContext());
945         if (reg_ctx) {
946           if (const RegisterInfo *reg_info =
947                   reg_ctx->GetRegisterInfoByName(name)) {
948             value_sp = ValueObjectRegister::Create(frame, reg_ctx, reg_info);
949             result.SetSP(value_sp);
950           }
951         }
952       }
953     }
954   }
955 
956   return LLDB_RECORD_RESULT(result);
957 }
958 
959 bool SBFrame::GetDescription(SBStream &description) {
960   LLDB_RECORD_METHOD(bool, SBFrame, GetDescription, (lldb::SBStream &),
961                      description);
962 
963   Stream &strm = description.ref();
964 
965   std::unique_lock<std::recursive_mutex> lock;
966   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
967 
968   StackFrame *frame;
969   Target *target = exe_ctx.GetTargetPtr();
970   Process *process = exe_ctx.GetProcessPtr();
971   if (target && process) {
972     Process::StopLocker stop_locker;
973     if (stop_locker.TryLock(&process->GetRunLock())) {
974       frame = exe_ctx.GetFramePtr();
975       if (frame) {
976         frame->DumpUsingSettingsFormat(&strm);
977       }
978     }
979 
980   } else
981     strm.PutCString("No value");
982 
983   return true;
984 }
985 
986 SBValue SBFrame::EvaluateExpression(const char *expr) {
987   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, EvaluateExpression, (const char *),
988                      expr);
989 
990   SBValue result;
991   std::unique_lock<std::recursive_mutex> lock;
992   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
993 
994   StackFrame *frame = exe_ctx.GetFramePtr();
995   Target *target = exe_ctx.GetTargetPtr();
996   if (frame && target) {
997     SBExpressionOptions options;
998     lldb::DynamicValueType fetch_dynamic_value =
999         frame->CalculateTarget()->GetPreferDynamicValue();
1000     options.SetFetchDynamicValue(fetch_dynamic_value);
1001     options.SetUnwindOnError(true);
1002     options.SetIgnoreBreakpoints(true);
1003     if (target->GetLanguage() != eLanguageTypeUnknown)
1004       options.SetLanguage(target->GetLanguage());
1005     else
1006       options.SetLanguage(frame->GetLanguage());
1007     return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
1008   }
1009   return LLDB_RECORD_RESULT(result);
1010 }
1011 
1012 SBValue
1013 SBFrame::EvaluateExpression(const char *expr,
1014                             lldb::DynamicValueType fetch_dynamic_value) {
1015   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1016                      (const char *, lldb::DynamicValueType), expr,
1017                      fetch_dynamic_value);
1018 
1019   SBExpressionOptions options;
1020   options.SetFetchDynamicValue(fetch_dynamic_value);
1021   options.SetUnwindOnError(true);
1022   options.SetIgnoreBreakpoints(true);
1023   std::unique_lock<std::recursive_mutex> lock;
1024   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1025 
1026   StackFrame *frame = exe_ctx.GetFramePtr();
1027   Target *target = exe_ctx.GetTargetPtr();
1028   if (target && target->GetLanguage() != eLanguageTypeUnknown)
1029     options.SetLanguage(target->GetLanguage());
1030   else if (frame)
1031     options.SetLanguage(frame->GetLanguage());
1032   return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
1033 }
1034 
1035 SBValue SBFrame::EvaluateExpression(const char *expr,
1036                                     lldb::DynamicValueType fetch_dynamic_value,
1037                                     bool unwind_on_error) {
1038   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1039                      (const char *, lldb::DynamicValueType, bool), expr,
1040                      fetch_dynamic_value, unwind_on_error);
1041 
1042   SBExpressionOptions options;
1043   std::unique_lock<std::recursive_mutex> lock;
1044   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1045 
1046   options.SetFetchDynamicValue(fetch_dynamic_value);
1047   options.SetUnwindOnError(unwind_on_error);
1048   options.SetIgnoreBreakpoints(true);
1049   StackFrame *frame = exe_ctx.GetFramePtr();
1050   Target *target = exe_ctx.GetTargetPtr();
1051   if (target && target->GetLanguage() != eLanguageTypeUnknown)
1052     options.SetLanguage(target->GetLanguage());
1053   else if (frame)
1054     options.SetLanguage(frame->GetLanguage());
1055   return LLDB_RECORD_RESULT(EvaluateExpression(expr, options));
1056 }
1057 
1058 lldb::SBValue SBFrame::EvaluateExpression(const char *expr,
1059                                           const SBExpressionOptions &options) {
1060   LLDB_RECORD_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1061                      (const char *, const lldb::SBExpressionOptions &), expr,
1062                      options);
1063 
1064   Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
1065 
1066   SBValue expr_result;
1067 
1068   if (expr == nullptr || expr[0] == '\0') {
1069     return LLDB_RECORD_RESULT(expr_result);
1070   }
1071 
1072   ValueObjectSP expr_value_sp;
1073 
1074   std::unique_lock<std::recursive_mutex> lock;
1075   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1076 
1077 
1078   StackFrame *frame = nullptr;
1079   Target *target = exe_ctx.GetTargetPtr();
1080   Process *process = exe_ctx.GetProcessPtr();
1081 
1082   if (target && process) {
1083     Process::StopLocker stop_locker;
1084     if (stop_locker.TryLock(&process->GetRunLock())) {
1085       frame = exe_ctx.GetFramePtr();
1086       if (frame) {
1087         std::unique_ptr<llvm::PrettyStackTraceFormat> stack_trace;
1088         if (target->GetDisplayExpressionsInCrashlogs()) {
1089           StreamString frame_description;
1090           frame->DumpUsingSettingsFormat(&frame_description);
1091           stack_trace = std::make_unique<llvm::PrettyStackTraceFormat>(
1092               "SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value "
1093               "= %u) %s",
1094               expr, options.GetFetchDynamicValue(),
1095               frame_description.GetData());
1096         }
1097 
1098         target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());
1099         expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue());
1100       }
1101     }
1102   }
1103 
1104   LLDB_LOGF(expr_log,
1105             "** [SBFrame::EvaluateExpression] Expression result is "
1106             "%s, summary %s **",
1107             expr_result.GetValue(), expr_result.GetSummary());
1108 
1109   return LLDB_RECORD_RESULT(expr_result);
1110 }
1111 
1112 bool SBFrame::IsInlined() {
1113   LLDB_RECORD_METHOD_NO_ARGS(bool, SBFrame, IsInlined);
1114 
1115   return static_cast<const SBFrame *>(this)->IsInlined();
1116 }
1117 
1118 bool SBFrame::IsInlined() const {
1119   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFrame, IsInlined);
1120 
1121   std::unique_lock<std::recursive_mutex> lock;
1122   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1123 
1124   StackFrame *frame = nullptr;
1125   Target *target = exe_ctx.GetTargetPtr();
1126   Process *process = exe_ctx.GetProcessPtr();
1127   if (target && process) {
1128     Process::StopLocker stop_locker;
1129     if (stop_locker.TryLock(&process->GetRunLock())) {
1130       frame = exe_ctx.GetFramePtr();
1131       if (frame) {
1132 
1133         Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
1134         if (block)
1135           return block->GetContainingInlinedBlock() != nullptr;
1136       }
1137     }
1138   }
1139   return false;
1140 }
1141 
1142 bool SBFrame::IsArtificial() {
1143   LLDB_RECORD_METHOD_NO_ARGS(bool, SBFrame, IsArtificial);
1144 
1145   return static_cast<const SBFrame *>(this)->IsArtificial();
1146 }
1147 
1148 bool SBFrame::IsArtificial() const {
1149   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBFrame, IsArtificial);
1150 
1151   std::unique_lock<std::recursive_mutex> lock;
1152   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1153 
1154   StackFrame *frame = exe_ctx.GetFramePtr();
1155   if (frame)
1156     return frame->IsArtificial();
1157 
1158   return false;
1159 }
1160 
1161 const char *SBFrame::GetFunctionName() {
1162   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBFrame, GetFunctionName);
1163 
1164   return static_cast<const SBFrame *>(this)->GetFunctionName();
1165 }
1166 
1167 lldb::LanguageType SBFrame::GuessLanguage() const {
1168   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::LanguageType, SBFrame, GuessLanguage);
1169 
1170   std::unique_lock<std::recursive_mutex> lock;
1171   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1172 
1173   StackFrame *frame = nullptr;
1174   Target *target = exe_ctx.GetTargetPtr();
1175   Process *process = exe_ctx.GetProcessPtr();
1176   if (target && process) {
1177     Process::StopLocker stop_locker;
1178     if (stop_locker.TryLock(&process->GetRunLock())) {
1179       frame = exe_ctx.GetFramePtr();
1180       if (frame) {
1181         return frame->GuessLanguage();
1182       }
1183     }
1184   }
1185   return eLanguageTypeUnknown;
1186 }
1187 
1188 const char *SBFrame::GetFunctionName() const {
1189   LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBFrame, GetFunctionName);
1190 
1191   const char *name = nullptr;
1192   std::unique_lock<std::recursive_mutex> lock;
1193   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1194 
1195   StackFrame *frame = nullptr;
1196   Target *target = exe_ctx.GetTargetPtr();
1197   Process *process = exe_ctx.GetProcessPtr();
1198   if (target && process) {
1199     Process::StopLocker stop_locker;
1200     if (stop_locker.TryLock(&process->GetRunLock())) {
1201       frame = exe_ctx.GetFramePtr();
1202       if (frame) {
1203         SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1204                                                  eSymbolContextBlock |
1205                                                  eSymbolContextSymbol));
1206         if (sc.block) {
1207           Block *inlined_block = sc.block->GetContainingInlinedBlock();
1208           if (inlined_block) {
1209             const InlineFunctionInfo *inlined_info =
1210                 inlined_block->GetInlinedFunctionInfo();
1211             name = inlined_info->GetName().AsCString();
1212           }
1213         }
1214 
1215         if (name == nullptr) {
1216           if (sc.function)
1217             name = sc.function->GetName().GetCString();
1218         }
1219 
1220         if (name == nullptr) {
1221           if (sc.symbol)
1222             name = sc.symbol->GetName().GetCString();
1223         }
1224       }
1225     }
1226   }
1227   return name;
1228 }
1229 
1230 const char *SBFrame::GetDisplayFunctionName() {
1231   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBFrame, GetDisplayFunctionName);
1232 
1233   const char *name = nullptr;
1234 
1235   std::unique_lock<std::recursive_mutex> lock;
1236   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
1237 
1238   StackFrame *frame = nullptr;
1239   Target *target = exe_ctx.GetTargetPtr();
1240   Process *process = exe_ctx.GetProcessPtr();
1241   if (target && process) {
1242     Process::StopLocker stop_locker;
1243     if (stop_locker.TryLock(&process->GetRunLock())) {
1244       frame = exe_ctx.GetFramePtr();
1245       if (frame) {
1246         SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
1247                                                  eSymbolContextBlock |
1248                                                  eSymbolContextSymbol));
1249         if (sc.block) {
1250           Block *inlined_block = sc.block->GetContainingInlinedBlock();
1251           if (inlined_block) {
1252             const InlineFunctionInfo *inlined_info =
1253                 inlined_block->GetInlinedFunctionInfo();
1254             name = inlined_info->GetDisplayName().AsCString();
1255           }
1256         }
1257 
1258         if (name == nullptr) {
1259           if (sc.function)
1260             name = sc.function->GetDisplayName().GetCString();
1261         }
1262 
1263         if (name == nullptr) {
1264           if (sc.symbol)
1265             name = sc.symbol->GetDisplayName().GetCString();
1266         }
1267       }
1268     }
1269   }
1270   return name;
1271 }
1272 
1273 namespace lldb_private {
1274 namespace repro {
1275 
1276 template <>
1277 void RegisterMethods<SBFrame>(Registry &R) {
1278   LLDB_REGISTER_CONSTRUCTOR(SBFrame, ());
1279   LLDB_REGISTER_CONSTRUCTOR(SBFrame, (const lldb::StackFrameSP &));
1280   LLDB_REGISTER_CONSTRUCTOR(SBFrame, (const lldb::SBFrame &));
1281   LLDB_REGISTER_METHOD(const lldb::SBFrame &,
1282                        SBFrame, operator=,(const lldb::SBFrame &));
1283   LLDB_REGISTER_METHOD_CONST(bool, SBFrame, IsValid, ());
1284   LLDB_REGISTER_METHOD_CONST(bool, SBFrame, operator bool, ());
1285   LLDB_REGISTER_METHOD_CONST(lldb::SBSymbolContext, SBFrame, GetSymbolContext,
1286                              (uint32_t));
1287   LLDB_REGISTER_METHOD_CONST(lldb::SBModule, SBFrame, GetModule, ());
1288   LLDB_REGISTER_METHOD_CONST(lldb::SBCompileUnit, SBFrame, GetCompileUnit,
1289                              ());
1290   LLDB_REGISTER_METHOD_CONST(lldb::SBFunction, SBFrame, GetFunction, ());
1291   LLDB_REGISTER_METHOD_CONST(lldb::SBSymbol, SBFrame, GetSymbol, ());
1292   LLDB_REGISTER_METHOD_CONST(lldb::SBBlock, SBFrame, GetBlock, ());
1293   LLDB_REGISTER_METHOD_CONST(lldb::SBBlock, SBFrame, GetFrameBlock, ());
1294   LLDB_REGISTER_METHOD_CONST(lldb::SBLineEntry, SBFrame, GetLineEntry, ());
1295   LLDB_REGISTER_METHOD_CONST(uint32_t, SBFrame, GetFrameID, ());
1296   LLDB_REGISTER_METHOD_CONST(lldb::addr_t, SBFrame, GetCFA, ());
1297   LLDB_REGISTER_METHOD_CONST(lldb::addr_t, SBFrame, GetPC, ());
1298   LLDB_REGISTER_METHOD(bool, SBFrame, SetPC, (lldb::addr_t));
1299   LLDB_REGISTER_METHOD_CONST(lldb::addr_t, SBFrame, GetSP, ());
1300   LLDB_REGISTER_METHOD_CONST(lldb::addr_t, SBFrame, GetFP, ());
1301   LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBFrame, GetPCAddress, ());
1302   LLDB_REGISTER_METHOD(void, SBFrame, Clear, ());
1303   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, GetValueForVariablePath,
1304                        (const char *));
1305   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, GetValueForVariablePath,
1306                        (const char *, lldb::DynamicValueType));
1307   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, FindVariable, (const char *));
1308   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, FindVariable,
1309                        (const char *, lldb::DynamicValueType));
1310   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, FindValue,
1311                        (const char *, lldb::ValueType));
1312   LLDB_REGISTER_METHOD(
1313       lldb::SBValue, SBFrame, FindValue,
1314       (const char *, lldb::ValueType, lldb::DynamicValueType));
1315   LLDB_REGISTER_METHOD_CONST(bool, SBFrame, IsEqual, (const lldb::SBFrame &));
1316   LLDB_REGISTER_METHOD_CONST(bool,
1317                              SBFrame, operator==,(const lldb::SBFrame &));
1318   LLDB_REGISTER_METHOD_CONST(bool,
1319                              SBFrame, operator!=,(const lldb::SBFrame &));
1320   LLDB_REGISTER_METHOD_CONST(lldb::SBThread, SBFrame, GetThread, ());
1321   LLDB_REGISTER_METHOD_CONST(const char *, SBFrame, Disassemble, ());
1322   LLDB_REGISTER_METHOD(lldb::SBValueList, SBFrame, GetVariables,
1323                        (bool, bool, bool, bool));
1324   LLDB_REGISTER_METHOD(lldb::SBValueList, SBFrame, GetVariables,
1325                        (bool, bool, bool, bool, lldb::DynamicValueType));
1326   LLDB_REGISTER_METHOD(lldb::SBValueList, SBFrame, GetVariables,
1327                        (const lldb::SBVariablesOptions &));
1328   LLDB_REGISTER_METHOD(lldb::SBValueList, SBFrame, GetRegisters, ());
1329   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, FindRegister, (const char *));
1330   LLDB_REGISTER_METHOD(bool, SBFrame, GetDescription, (lldb::SBStream &));
1331   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1332                        (const char *));
1333   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1334                        (const char *, lldb::DynamicValueType));
1335   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1336                        (const char *, lldb::DynamicValueType, bool));
1337   LLDB_REGISTER_METHOD(lldb::SBValue, SBFrame, EvaluateExpression,
1338                        (const char *, const lldb::SBExpressionOptions &));
1339   LLDB_REGISTER_METHOD(bool, SBFrame, IsInlined, ());
1340   LLDB_REGISTER_METHOD_CONST(bool, SBFrame, IsInlined, ());
1341   LLDB_REGISTER_METHOD(bool, SBFrame, IsArtificial, ());
1342   LLDB_REGISTER_METHOD_CONST(bool, SBFrame, IsArtificial, ());
1343   LLDB_REGISTER_METHOD(const char *, SBFrame, GetFunctionName, ());
1344   LLDB_REGISTER_METHOD_CONST(lldb::LanguageType, SBFrame, GuessLanguage, ());
1345   LLDB_REGISTER_METHOD_CONST(const char *, SBFrame, GetFunctionName, ());
1346   LLDB_REGISTER_METHOD(const char *, SBFrame, GetDisplayFunctionName, ());
1347 }
1348 
1349 }
1350 }
1351