1 //===-- StackFrame.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_StackFrame_h_
11 #define liblldb_StackFrame_h_
17 // Other libraries and framework includes
19 #include "lldb/Core/Error.h"
20 #include "lldb/Core/Flags.h"
21 #include "lldb/Core/Scalar.h"
22 #include "lldb/Core/StreamString.h"
23 #include "lldb/Core/UserID.h"
24 #include "lldb/Core/ValueObjectList.h"
25 #include "lldb/Symbol/SymbolContext.h"
26 #include "lldb/Target/ExecutionContextScope.h"
27 #include "lldb/Target/StackID.h"
29 namespace lldb_private {
31 /// @class StackFrame StackFrame.h "lldb/Target/StackFrame.h"
33 /// @brief This base class provides an interface to stack frames.
35 /// StackFrames may have a Canonical Frame Address (CFA) or not.
36 /// A frame may have a plain pc value or it may have a pc value + stop_id
37 /// to indicate a specific point in the debug session so the correct section
38 /// load list is used for symbolication.
40 /// Local variables may be available, or not. A register context may be
41 /// available, or not.
44 public ExecutionContextScope,
45 public std::enable_shared_from_this<StackFrame>
48 enum ExpressionPathOption
50 eExpressionPathOptionCheckPtrVsMember = (1u << 0),
51 eExpressionPathOptionsNoFragileObjcIvar = (1u << 1),
52 eExpressionPathOptionsNoSyntheticChildren = (1u << 2),
53 eExpressionPathOptionsNoSyntheticArrayRange = (1u << 3),
54 eExpressionPathOptionsAllowDirectIVarAccess = (1u << 4),
55 eExpressionPathOptionsInspectAnonymousUnions = (1u << 5)
58 //------------------------------------------------------------------
59 /// Construct a StackFrame object without supplying a RegisterContextSP.
61 /// This is the one constructor that doesn't take a RegisterContext
62 /// parameter. This ctor may be called when creating a history StackFrame;
63 /// these are used if we've collected a stack trace of pc addresses at
64 /// some point in the past. We may only have pc values. We may have pc
65 /// values and the stop_id when the stack trace was recorded. We may have a
66 /// CFA, or more likely, we won't.
68 /// @param [in] thread_sp
69 /// The Thread that this frame belongs to.
71 /// @param [in] frame_idx
72 /// This StackFrame's frame index number in the Thread. If inlined stack
73 /// frames are being created, this may differ from the concrete_frame_idx
74 /// which is the frame index without any inlined stack frames.
76 /// @param [in] concrete_frame_idx
77 /// The StackFrame's frame index number in the Thread without any inlined
78 /// stack frames being included in the index.
81 /// The Canonical Frame Address (this terminology from DWARF) for this
82 /// stack frame. The CFA for a stack frame does not change over the
83 /// span of the stack frame's existence. It is often the value of the
84 /// caller's stack pointer before the call instruction into this frame's
85 /// function. It is usually not the same as the frame pointer register's
88 /// @param [in] cfa_is_valid
89 /// A history stack frame may not have a CFA value collected. We want to
90 /// distinguish between "no CFA available" and a CFA of
91 /// LLDB_INVALID_ADDRESS.
94 /// The current pc value of this stack frame.
96 /// @param [in] stop_id
97 /// The stop_id which should be used when looking up symbols for the pc value,
98 /// if appropriate. This argument is ignored if stop_id_is_valid is false.
100 /// @param [in] stop_id_is_valid
101 /// If the stop_id argument provided is not needed for this StackFrame, this
102 /// should be false. If this is a history stack frame and we know the stop_id
103 /// when the pc value was collected, that stop_id should be provided and this
106 /// @param [in] is_history_frame
107 /// If this is a historical stack frame -- possibly without CFA or registers or
108 /// local variables -- then this should be set to true.
110 /// @param [in] sc_ptr
111 /// Optionally seed the StackFrame with the SymbolContext information that has
112 /// already been discovered.
113 //------------------------------------------------------------------
114 StackFrame (const lldb::ThreadSP &thread_sp,
115 lldb::user_id_t frame_idx,
116 lldb::user_id_t concrete_frame_idx,
121 bool stop_id_is_valid,
122 bool is_history_frame,
123 const SymbolContext *sc_ptr);
125 StackFrame (const lldb::ThreadSP &thread_sp,
126 lldb::user_id_t frame_idx,
127 lldb::user_id_t concrete_frame_idx,
128 const lldb::RegisterContextSP ®_context_sp,
131 const SymbolContext *sc_ptr);
133 StackFrame (const lldb::ThreadSP &thread_sp,
134 lldb::user_id_t frame_idx,
135 lldb::user_id_t concrete_frame_idx,
136 const lldb::RegisterContextSP ®_context_sp,
139 const SymbolContext *sc_ptr);
141 ~StackFrame() override;
146 return m_thread_wp.lock();
152 //------------------------------------------------------------------
153 /// Get an Address for the current pc value in this StackFrame.
155 /// May not be the same as the actual PC value for inlined stack frames.
158 /// The Address object set to the current PC value.
159 //------------------------------------------------------------------
161 GetFrameCodeAddress();
163 //------------------------------------------------------------------
164 /// Change the pc value for a given thread.
166 /// Change the current pc value for the frame on this thread.
169 /// The load address that the pc will be set to.
172 /// true if the pc was changed. false if this failed -- possibly
173 /// because this frame is not a live StackFrame.
174 //------------------------------------------------------------------
176 ChangePC (lldb::addr_t pc);
178 //------------------------------------------------------------------
179 /// Provide a SymbolContext for this StackFrame's current pc value.
181 /// The StackFrame maintains this SymbolContext and adds additional information
182 /// to it on an as-needed basis. This helps to avoid different functions
183 /// looking up symbolic information for a given pc value multiple times.
185 /// @params [in] resolve_scope
186 /// Flags from the SymbolContextItem enumerated type which specify what
187 /// type of symbol context is needed by this caller.
190 /// A SymbolContext reference which includes the types of information
191 /// requested by resolve_scope, if they are available.
192 //------------------------------------------------------------------
194 GetSymbolContext (uint32_t resolve_scope);
196 //------------------------------------------------------------------
197 /// Return the Canonical Frame Address (DWARF term) for this frame.
199 /// The CFA is typically the value of the stack pointer register before
200 /// the call invocation is made. It will not change during the lifetime
201 /// of a stack frame. It is often not the same thing as the frame pointer
204 /// Live StackFrames will always have a CFA but other types of frames may
205 /// not be able to supply one.
207 /// @param [out] value
208 /// The address of the CFA for this frame, if available.
210 /// @param [out] error_ptr
211 /// If there is an error determining the CFA address, this may contain a
212 /// string explaining the failure.
215 /// Returns true if the CFA value was successfully set in value. Some
216 /// frames may be unable to provide this value; they will return false.
217 //------------------------------------------------------------------
219 GetFrameBaseValue(Scalar &value, Error *error_ptr);
221 //------------------------------------------------------------------
222 /// Get the current lexical scope block for this StackFrame, if possible.
224 /// If debug information is available for this stack frame, return a
225 /// pointer to the innermost lexical Block that the frame is currently
229 /// A pointer to the current Block. nullptr is returned if this can
231 //------------------------------------------------------------------
235 //------------------------------------------------------------------
236 /// Get the RegisterContext for this frame, if possible.
238 /// Returns a shared pointer to the RegisterContext for this stack frame.
239 /// Only a live StackFrame object will be able to return a RegisterContext -
240 /// callers must be prepared for an empty shared pointer being returned.
242 /// Even a live StackFrame RegisterContext may not be able to provide all
243 /// registers. Only the currently executing frame (frame 0) can reliably
244 /// provide every register in the register context.
247 /// The RegisterContext shared point for this frame.
248 //------------------------------------------------------------------
249 lldb::RegisterContextSP
250 GetRegisterContext ();
252 const lldb::RegisterContextSP &
253 GetRegisterContextSP () const
255 return m_reg_context_sp;
258 //------------------------------------------------------------------
259 /// Retrieve the list of variables that are in scope at this StackFrame's pc.
261 /// A frame that is not live may return an empty VariableList for a given
262 /// pc value even though variables would be available at this point if
263 /// it were a live stack frame.
265 /// @param[in] get_file_globals
266 /// Whether to also retrieve compilation-unit scoped variables
267 /// that are visible to the entire compilation unit (e.g. file
268 /// static in C, globals that are homed in this CU).
271 /// A pointer to a list of variables.
272 //------------------------------------------------------------------
274 GetVariableList (bool get_file_globals);
276 //------------------------------------------------------------------
277 /// Retrieve the list of variables that are in scope at this StackFrame's pc.
279 /// A frame that is not live may return an empty VariableListSP for a
280 /// given pc value even though variables would be available at this point
281 /// if it were a live stack frame.
283 /// @param[in] get_file_globals
284 /// Whether to also retrieve compilation-unit scoped variables
285 /// that are visible to the entire compilation unit (e.g. file
286 /// static in C, globals that are homed in this CU).
289 /// A pointer to a list of variables.
290 //------------------------------------------------------------------
292 GetInScopeVariableList (bool get_file_globals);
294 //------------------------------------------------------------------
295 /// Create a ValueObject for a variable name / pathname, possibly
296 /// including simple dereference/child selection syntax.
298 /// @param[in] var_expr
299 /// The string specifying a variable to base the VariableObject off
302 /// @param[in] use_dynamic
303 /// Whether the correct dynamic type of an object pointer should be
304 /// determined before creating the object, or if the static type is
305 /// sufficient. One of the DynamicValueType enumerated values.
307 /// @param[in] options
308 /// An unsigned integer of flags, values from StackFrame::ExpressionPathOption
310 /// @param[in] var_sp
311 /// A VariableSP that will be set to the variable described in the
315 /// Record any errors encountered while evaluating var_expr.
318 /// A shared pointer to the ValueObject described by var_expr.
319 //------------------------------------------------------------------
321 GetValueForVariableExpressionPath (const char *var_expr,
322 lldb::DynamicValueType use_dynamic,
324 lldb::VariableSP &var_sp,
327 //------------------------------------------------------------------
328 /// Determine whether this StackFrame has debug information available or not
331 // true if debug information is available for this frame (function,
332 // compilation unit, block, etc.)
333 //------------------------------------------------------------------
335 HasDebugInformation ();
337 //------------------------------------------------------------------
338 /// Return the disassembly for the instructions of this StackFrame's function
339 /// as a single C string.
342 // C string with the assembly instructions for this function.
343 //------------------------------------------------------------------
347 //------------------------------------------------------------------
348 /// Print a description for this frame using the frame-format formatter settings.
351 /// The Stream to print the description to.
353 /// @param [in] frame_marker
354 /// Optional string that will be prepended to the frame output description.
355 //------------------------------------------------------------------
357 DumpUsingSettingsFormat(Stream *strm, const char *frame_marker = nullptr);
359 //------------------------------------------------------------------
360 /// Print a description for this frame using a default format.
363 /// The Stream to print the description to.
365 /// @param [in] show_frame_index
366 /// Whether to print the frame number or not.
368 /// @param [in] show_fullpaths
369 /// Whether to print the full source paths or just the file base name.
370 //------------------------------------------------------------------
372 Dump (Stream *strm, bool show_frame_index, bool show_fullpaths);
374 //------------------------------------------------------------------
375 /// Print a description of this stack frame and/or the source context/assembly
376 /// for this stack frame.
379 /// The Stream to send the output to.
381 /// @param[in] show_frame_info
382 /// If true, print the frame info by calling DumpUsingSettingsFormat().
384 /// @param[in] show_source
385 /// If true, print source or disassembly as per the user's settings.
387 /// @param[in] frame_marker
388 /// Passed to DumpUsingSettingsFormat() for the frame info printing.
391 /// Returns true if successful.
392 //------------------------------------------------------------------
394 GetStatus(Stream &strm,
395 bool show_frame_info,
397 const char *frame_marker = nullptr);
399 //------------------------------------------------------------------
400 /// Query whether this frame is a concrete frame on the call stack,
401 /// or if it is an inlined frame derived from the debug information
402 /// and presented by the debugger.
405 /// true if this is an inlined frame.
406 //------------------------------------------------------------------
410 //------------------------------------------------------------------
411 /// Query this frame to find what frame it is in this Thread's StackFrameList.
414 /// StackFrame index 0 indicates the currently-executing function. Inline
415 /// frames are included in this frame index count.
416 //------------------------------------------------------------------
418 GetFrameIndex () const;
420 //------------------------------------------------------------------
421 /// Query this frame to find what frame it is in this Thread's StackFrameList,
422 /// not counting inlined frames.
425 /// StackFrame index 0 indicates the currently-executing function. Inline
426 /// frames are not included in this frame index count; their concrete
427 /// frame index will be the same as the concrete frame that they are
429 //------------------------------------------------------------------
431 GetConcreteFrameIndex () const
433 return m_concrete_frame_index;
436 //------------------------------------------------------------------
437 /// Create a ValueObject for a given Variable in this StackFrame.
439 /// @params [in] variable_sp
440 /// The Variable to base this ValueObject on
442 /// @params [in] use_dynamic
443 /// Whether the correct dynamic type of the variable should be
444 /// determined before creating the ValueObject, or if the static type
445 /// is sufficient. One of the DynamicValueType enumerated values.
448 // A ValueObject for this variable.
449 //------------------------------------------------------------------
451 GetValueObjectForFrameVariable (const lldb::VariableSP &variable_sp, lldb::DynamicValueType use_dynamic);
453 //------------------------------------------------------------------
454 /// Add an arbitrary Variable object (e.g. one that specifics a global or static)
455 /// to a StackFrame's list of ValueObjects.
457 /// @params [in] variable_sp
458 /// The Variable to base this ValueObject on
460 /// @params [in] use_dynamic
461 /// Whether the correct dynamic type of the variable should be
462 /// determined before creating the ValueObject, or if the static type
463 /// is sufficient. One of the DynamicValueType enumerated values.
466 // A ValueObject for this variable.
467 //------------------------------------------------------------------
469 TrackGlobalVariable (const lldb::VariableSP &variable_sp, lldb::DynamicValueType use_dynamic);
471 //------------------------------------------------------------------
472 /// Query this frame to determine what the default language should be
473 /// when parsing expressions given the execution context.
476 /// The language of the frame if known, else lldb::eLanguageTypeUnknown.
477 //------------------------------------------------------------------
481 //------------------------------------------------------------------
482 // lldb::ExecutionContextScope pure virtual functions
483 //------------------------------------------------------------------
485 CalculateTarget() override;
488 CalculateProcess() override;
491 CalculateThread() override;
494 CalculateStackFrame() override;
497 CalculateExecutionContext(ExecutionContext &exe_ctx) override;
500 friend class StackFrameList;
503 SetSymbolContextScope (SymbolContextScope *symbol_scope);
506 UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame);
509 UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame);
512 HasCachedData () const;
515 //------------------------------------------------------------------
516 // For StackFrame only
517 //------------------------------------------------------------------
518 lldb::ThreadWP m_thread_wp;
519 uint32_t m_frame_index;
520 uint32_t m_concrete_frame_index;
521 lldb::RegisterContextSP m_reg_context_sp;
523 Address m_frame_code_addr; // The frame code address (might not be the same as the actual PC for inlined frames) as a section/offset address
527 Error m_frame_base_error;
528 bool m_cfa_is_valid; // Does this frame have a CFA? Different from CFA == LLDB_INVALID_ADDRESS
530 bool m_stop_id_is_valid; // Does this frame have a stop_id? Use it when referring to the m_frame_code_addr.
531 bool m_is_history_frame;
532 lldb::VariableListSP m_variable_list_sp;
533 ValueObjectList m_variable_list_value_objects; // Value objects for each variable in m_variable_list_sp
534 StreamString m_disassembly;
537 DISALLOW_COPY_AND_ASSIGN (StackFrame);
540 } // namespace lldb_private
542 #endif // liblldb_StackFrame_h_