1 //===-- Function.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_Function_h_
11 #define liblldb_Function_h_
13 #include "lldb/Core/ClangForward.h"
14 #include "lldb/Core/AddressRange.h"
15 #include "lldb/Symbol/Block.h"
16 #include "lldb/Symbol/Declaration.h"
17 #include "lldb/Expression/DWARFExpression.h"
18 #include "lldb/Core/Mangled.h"
19 #include "lldb/Core/UserID.h"
21 namespace lldb_private {
23 //----------------------------------------------------------------------
24 /// @class FunctionInfo Function.h "lldb/Symbol/Function.h"
25 /// @brief A class that contains generic function information.
27 /// This provides generic function information that gets resused between
28 /// inline functions and function types.
29 //----------------------------------------------------------------------
33 //------------------------------------------------------------------
34 /// Construct with the function method name and optional declaration
38 /// A C string name for the method name for this function. This
39 /// value should not be the mangled named, but the simple method
42 /// @param[in] decl_ptr
43 /// Optional declaration information that describes where the
44 /// function was declared. This can be NULL.
45 //------------------------------------------------------------------
46 FunctionInfo (const char *name, const Declaration *decl_ptr);
48 //------------------------------------------------------------------
49 /// Construct with the function method name and optional declaration
53 /// A name for the method name for this function. This value
54 /// should not be the mangled named, but the simple method name.
56 /// @param[in] decl_ptr
57 /// Optional declaration information that describes where the
58 /// function was declared. This can be NULL.
59 //------------------------------------------------------------------
60 FunctionInfo (const ConstString& name, const Declaration *decl_ptr);
62 //------------------------------------------------------------------
65 /// The destructor is virtual since classes inherit from this class.
66 //------------------------------------------------------------------
70 //------------------------------------------------------------------
71 /// Compare two function information objects.
73 /// First compares the method names, and if equal, then compares
74 /// the declaration information.
77 /// The Left Hand Side const FunctionInfo object reference.
80 /// The Right Hand Side const FunctionInfo object reference.
83 /// @li -1 if lhs < rhs
84 /// @li 0 if lhs == rhs
85 /// @li 1 if lhs > rhs
86 //------------------------------------------------------------------
88 Compare (const FunctionInfo& lhs, const FunctionInfo& rhs);
90 //------------------------------------------------------------------
91 /// Dump a description of this object to a Stream.
93 /// Dump a description of the contents of this object to the
94 /// supplied stream \a s.
97 /// The stream to which to dump the object descripton.
98 //------------------------------------------------------------------
100 Dump (Stream *s, bool show_fullpaths) const;
102 //------------------------------------------------------------------
103 /// Get accessor for the declaration information.
106 /// A reference to the declaration object.
107 //------------------------------------------------------------------
111 //------------------------------------------------------------------
112 /// Get const accessor for the declaration information.
115 /// A const reference to the declaration object.
116 //------------------------------------------------------------------
118 GetDeclaration () const;
120 //------------------------------------------------------------------
121 /// Get accessor for the method name.
124 /// A const reference to the method name object.
125 //------------------------------------------------------------------
129 //------------------------------------------------------------------
130 /// Get the memory cost of this object.
133 /// The number of bytes that this object occupies in memory.
134 /// The returned value does not include the bytes for any
135 /// shared string values.
137 /// @see ConstString::StaticMemorySize ()
138 //------------------------------------------------------------------
143 //------------------------------------------------------------------
145 //------------------------------------------------------------------
146 ConstString m_name; ///< Function method name (not a mangled name).
147 Declaration m_declaration; ///< Information describing where this function information was defined.
151 //----------------------------------------------------------------------
152 /// @class InlineFunctionInfo Function.h "lldb/Symbol/Function.h"
153 /// @brief A class that describes information for an inlined function.
154 //----------------------------------------------------------------------
155 class InlineFunctionInfo : public FunctionInfo
158 //------------------------------------------------------------------
159 /// Construct with the function method name, mangled name, and
160 /// optional declaration information.
163 /// A C string name for the method name for this function. This
164 /// value should not be the mangled named, but the simple method
167 /// @param[in] mangled
168 /// A C string name for the mangled name for this function. This
169 /// value can be NULL if there is no mangled information.
171 /// @param[in] decl_ptr
172 /// Optional declaration information that describes where the
173 /// function was declared. This can be NULL.
175 /// @param[in] call_decl_ptr
176 /// Optional calling location declaration information that
177 /// describes from where this inlined function was called.
178 //------------------------------------------------------------------
179 InlineFunctionInfo(const char *name, const char *mangled, const Declaration *decl_ptr, const Declaration *call_decl_ptr);
181 //------------------------------------------------------------------
182 /// Construct with the function method name, mangled name, and
183 /// optional declaration information.
186 /// A name for the method name for this function. This value
187 /// should not be the mangled named, but the simple method name.
189 /// @param[in] mangled
190 /// A name for the mangled name for this function. This value
191 /// can be empty if there is no mangled information.
193 /// @param[in] decl_ptr
194 /// Optional declaration information that describes where the
195 /// function was declared. This can be NULL.
197 /// @param[in] call_decl_ptr
198 /// Optional calling location declaration information that
199 /// describes from where this inlined function was called.
200 //------------------------------------------------------------------
201 InlineFunctionInfo(const ConstString& name, const Mangled &mangled, const Declaration *decl_ptr, const Declaration *call_decl_ptr);
203 //------------------------------------------------------------------
205 //------------------------------------------------------------------
206 ~InlineFunctionInfo();
208 //------------------------------------------------------------------
209 /// Compare two inlined function information objects.
211 /// First compares the FunctionInfo objects, and if equal,
212 /// compares the mangled names.
215 /// The Left Hand Side const InlineFunctionInfo object
219 /// The Right Hand Side const InlineFunctionInfo object
223 /// @li -1 if lhs < rhs
224 /// @li 0 if lhs == rhs
225 /// @li 1 if lhs > rhs
226 //------------------------------------------------------------------
228 Compare(const InlineFunctionInfo& lhs, const InlineFunctionInfo& rhs);
230 //------------------------------------------------------------------
231 /// Dump a description of this object to a Stream.
233 /// Dump a description of the contents of this object to the
234 /// supplied stream \a s.
237 /// The stream to which to dump the object descripton.
238 //------------------------------------------------------------------
240 Dump(Stream *s, bool show_fullpaths) const;
243 DumpStopContext (Stream *s) const;
248 //------------------------------------------------------------------
249 /// Get accessor for the call site declaration information.
252 /// A reference to the declaration object.
253 //------------------------------------------------------------------
257 //------------------------------------------------------------------
258 /// Get const accessor for the call site declaration information.
261 /// A const reference to the declaration object.
262 //------------------------------------------------------------------
264 GetCallSite () const;
266 //------------------------------------------------------------------
267 /// Get accessor for the mangled name object.
270 /// A reference to the mangled name object.
271 //------------------------------------------------------------------
275 //------------------------------------------------------------------
276 /// Get const accessor for the mangled name object.
279 /// A const reference to the mangled name object.
280 //------------------------------------------------------------------
284 //------------------------------------------------------------------
285 /// Get the memory cost of this object.
288 /// The number of bytes that this object occupies in memory.
289 /// The returned value does not include the bytes for any
290 /// shared string values.
292 /// @see ConstString::StaticMemorySize ()
293 //------------------------------------------------------------------
298 //------------------------------------------------------------------
300 //------------------------------------------------------------------
301 Mangled m_mangled; ///< Mangled inlined function name (can be empty if there is no mangled information).
302 Declaration m_call_decl;
305 //----------------------------------------------------------------------
306 /// @class Function Function.h "lldb/Symbol/Function.h"
307 /// @brief A class that describes a function.
309 /// Functions belong to CompileUnit objects (Function::m_comp_unit),
310 /// have unique user IDs (Function::UserID), know how to reconstruct
311 /// their symbol context (Function::SymbolContextScope), have a
312 /// specific function type (Function::m_type_uid), have a simple
313 /// method name (FunctionInfo::m_name), be declared at a specific
314 /// location (FunctionInfo::m_declaration), possibly have mangled
315 /// names (Function::m_mangled), an optional return type
316 /// (Function::m_type), and contains lexical blocks
317 /// (Function::m_blocks).
319 /// The function inforation is split into a few pieces:
320 /// @li The concrete instance information
321 /// @li The abstract information
323 /// The abstract information is found in the function type (Type) that
324 /// describes a function information, return type and parameter types.
326 /// The concreate information is the address range information and
327 /// specific locations for an instance of this function.
328 //----------------------------------------------------------------------
331 public SymbolContextScope
334 //------------------------------------------------------------------
335 /// Construct with a compile unit, function UID, function type UID,
336 /// optional mangled name, function type, and a section offset
337 /// based address range.
339 /// @param[in] comp_unit
340 /// The compile unit to which this function belongs.
342 /// @param[in] func_uid
343 /// The UID for this function. This value is provided by the
344 /// SymbolFile plug-in and can be any value that allows
345 /// the plug-in to quickly find and parse more detailed
346 /// information when and if more information is needed.
348 /// @param[in] func_type_uid
349 /// The type UID for the function Type to allow for lazy type
350 /// parsing from the debug information.
352 /// @param[in] mangled
353 /// The optional mangled name for this function. If empty, there
354 /// is no mangled information.
356 /// @param[in] func_type
357 /// The optional function type. If NULL, the function type will
358 /// be parsed on demand when accessed using the
359 /// Function::GetType() function by asking the SymbolFile
360 /// plug-in to get the type for \a func_type_uid.
363 /// The section offset based address for this function.
364 //------------------------------------------------------------------
366 CompileUnit *comp_unit,
367 lldb::user_id_t func_uid,
368 lldb::user_id_t func_type_uid,
369 const Mangled &mangled,
371 const AddressRange& range);
373 //------------------------------------------------------------------
374 /// Construct with a compile unit, function UID, function type UID,
375 /// optional mangled name, function type, and a section offset
376 /// based address range.
378 /// @param[in] comp_unit
379 /// The compile unit to which this function belongs.
381 /// @param[in] func_uid
382 /// The UID for this function. This value is provided by the
383 /// SymbolFile plug-in and can be any value that allows
384 /// the plug-in to quickly find and parse more detailed
385 /// information when and if more information is needed.
387 /// @param[in] func_type_uid
388 /// The type UID for the function Type to allow for lazy type
389 /// parsing from the debug information.
391 /// @param[in] mangled
392 /// The optional mangled name for this function. If empty, there
393 /// is no mangled information.
395 /// @param[in] func_type
396 /// The optional function type. If NULL, the function type will
397 /// be parsed on demand when accessed using the
398 /// Function::GetType() function by asking the SymbolFile
399 /// plug-in to get the type for \a func_type_uid.
402 /// The section offset based address for this function.
403 //------------------------------------------------------------------
405 CompileUnit *comp_unit,
406 lldb::user_id_t func_uid,
407 lldb::user_id_t func_type_uid,
410 const AddressRange& range);
412 //------------------------------------------------------------------
414 //------------------------------------------------------------------
417 //------------------------------------------------------------------
418 /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
420 /// @see SymbolContextScope
421 //------------------------------------------------------------------
423 CalculateSymbolContext(SymbolContext* sc);
425 virtual lldb::ModuleSP
426 CalculateSymbolContextModule ();
428 virtual CompileUnit *
429 CalculateSymbolContextCompileUnit ();
432 CalculateSymbolContextFunction ();
440 //------------------------------------------------------------------
441 /// Find the file and line number of the source location of the start
442 /// of the function. This will use the declaration if present and fall
443 /// back on the line table if that fails. So there may NOT be a line
444 /// table entry for this source file/line combo.
446 /// @param[out] source_file
449 /// @param[out] line_no
451 //------------------------------------------------------------------
453 GetStartLineSourceInfo (FileSpec &source_file, uint32_t &line_no);
455 //------------------------------------------------------------------
456 /// Find the file and line number of the source location of the end
460 /// @param[out] source_file
463 /// @param[out] line_no
465 //------------------------------------------------------------------
467 GetEndLineSourceInfo (FileSpec &source_file, uint32_t &line_no);
469 //------------------------------------------------------------------
470 /// Get accessor for the block list.
473 /// The block list object that describes all lexical blocks
477 //------------------------------------------------------------------
479 GetBlock (bool can_create);
481 //------------------------------------------------------------------
482 /// Get accessor for the compile unit that owns this function.
485 /// A compile unit object pointer.
486 //------------------------------------------------------------------
490 //------------------------------------------------------------------
491 /// Get const accessor for the compile unit that owns this function.
494 /// A const compile unit object pointer.
495 //------------------------------------------------------------------
497 GetCompileUnit() const;
500 GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target);
502 //------------------------------------------------------------------
503 /// Get accessor for the frame base location.
506 /// A location expression that describes the function frame
508 //------------------------------------------------------------------
510 GetFrameBaseExpression()
515 //------------------------------------------------------------------
516 /// Get const accessor for the frame base location.
519 /// A const compile unit object pointer.
520 //------------------------------------------------------------------
521 const DWARFExpression &
522 GetFrameBaseExpression() const
530 return m_mangled.GetName();
539 //------------------------------------------------------------------
540 /// Get the DeclContext for this function, if available.
543 /// The DeclContext, or NULL if none exists.
544 //------------------------------------------------------------------
546 GetClangDeclContext();
548 //------------------------------------------------------------------
549 /// Get accessor for the type that describes the function
550 /// return value type, and paramter types.
553 /// A type object pointer.
554 //------------------------------------------------------------------
558 //------------------------------------------------------------------
559 /// Get const accessor for the type that describes the function
560 /// return value type, and paramter types.
563 /// A const type object pointer.
564 //------------------------------------------------------------------
572 GetPrologueByteSize ();
574 //------------------------------------------------------------------
575 /// Dump a description of this object to a Stream.
577 /// Dump a description of the contents of this object to the
578 /// supplied stream \a s.
581 /// The stream to which to dump the object descripton.
583 /// @param[in] show_context
584 /// If \b true, variables will dump their symbol context
586 //------------------------------------------------------------------
588 Dump(Stream *s, bool show_context) const;
590 //------------------------------------------------------------------
591 /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*)
593 /// @see SymbolContextScope
594 //------------------------------------------------------------------
596 DumpSymbolContext(Stream *s);
598 //------------------------------------------------------------------
599 /// Get the memory cost of this object.
602 /// The number of bytes that this object occupies in memory.
603 /// The returned value does not include the bytes for any
604 /// shared string values.
606 /// @see ConstString::StaticMemorySize ()
607 //------------------------------------------------------------------
612 GetInstructions (const ExecutionContext &exe_ctx,
614 bool prefer_file_cache);
617 GetDisassembly (const ExecutionContext &exe_ctx,
619 bool prefer_file_cache,
626 flagsCalculatedPrologueSize = (1 << 0) ///< Have we already tried to calculate the prologue size?
631 //------------------------------------------------------------------
633 //------------------------------------------------------------------
634 CompileUnit *m_comp_unit; ///< The compile unit that owns this function.
635 lldb::user_id_t m_type_uid; ///< The user ID of for the prototype Type for this function.
636 Type * m_type; ///< The function prototype type for this function that include the function info (FunctionInfo), return type and parameters.
637 Mangled m_mangled; ///< The mangled function name if any, if empty, there is no mangled information.
638 Block m_block; ///< All lexical blocks contained in this function.
639 AddressRange m_range; ///< The function address range that covers the widest range needed to contain all blocks
640 DWARFExpression m_frame_base; ///< The frame base expression for variables that are relative to the frame pointer.
642 uint32_t m_prologue_byte_size; ///< Compute the prologue size once and cache it
644 DISALLOW_COPY_AND_ASSIGN(Function);
647 } // namespace lldb_private
649 #endif // liblldb_Function_h_