class Function

Defined at line 36 of file ../../src/developer/debug/zxdb/symbols/function.h

Represents a function (a "subprogram" in DWARF parlance). This is different than a "FunctionType"

which is the type used to represent function pointers.

Some functions in DWARF are "implementations" that have code ranges associated with them, and

some are "specifications" (akin to C forward declarations) that don't. The context about the

namespaces and parent classes comes from the specification, while the implementation of the

function may be outside of any namespace or class definitions.

It seems Clang puts the function parameters in both places, some attributes like DW_AT_frame_base

will only be on the implementation, and others like DW_AT_decl_file/line, DW_AT_accessibility,

and the return type (DW_AT_type) are only on the specification.

In the case of an implementation, the decoder will attempt to fill in the attributes from the

specification automatically so this Function object will have full context. Be aware that this

won't necessarily match the DIE that generated the object.

NAMING: The "full name" (as returned by Symbol::GetFullName()) of a function is the qualified

name without any return types or parameters. Some callers may want parameters, we can add a

helper function in the future if necessary (for display we would often want to syntax highlight

these differently so this is often better done at a different layer).

Public Methods

fxl::RefPtr<CodeBlock> GetContainingBlock ()

CodeBlock override:

Defined at line 22 of file ../../src/developer/debug/zxdb/symbols/function.cc

const Variable * GetObjectPointerVariable ()

Defined at line 36 of file ../../src/developer/debug/zxdb/symbols/function.cc

const std::string & GetAssignedName ()

Symbol overrides.

Defined at line 44 of file ../../src/developer/debug/zxdb/symbols/function.h

bool is_inline ()

Returns true if this function is an inlined function instance.

Defined at line 47 of file ../../src/developer/debug/zxdb/symbols/function.h

const UncachedLazySymbol & containing_block ()

The containing block is the CodeBlock that contains an inlined function. This will be null for

non-inlined functions.

Use GetContainingBlock() to access this containing block while falling back to the parent which

will transparently handle inlines vs. non-inlines.

For inlined functions, Symbol::parent() will contain the lexical parent of the inlined function

(a class or namespace) while the containing block will be the CodeBlock (of any type) that the

code is inlined into.

"Uncached" symbols must be used for all upward-pointing symbol references to prevent cycles.

Defined at line 60 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_containing_block (UncachedLazySymbol c)

Defined at line 61 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_assigned_name (std::string n)

Unmangled name. Does not include any class or namespace qualifications. (see

Symbol::GetAssignedName)

Defined at line 65 of file ../../src/developer/debug/zxdb/symbols/function.h

const std::string & linkage_name ()

Mangled name.

Defined at line 68 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_linkage_name (std::string n)

Defined at line 69 of file ../../src/developer/debug/zxdb/symbols/function.h

const FileLine & decl_line ()

The location in the source code of the declaration. May be empty.

Defined at line 72 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_decl_line (FileLine decl)

Defined at line 73 of file ../../src/developer/debug/zxdb/symbols/function.h

const FileLine & call_line ()

For inline functions, this can be set to indicate the call location.

Defined at line 76 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_call_line (FileLine call)

Defined at line 77 of file ../../src/developer/debug/zxdb/symbols/function.h

const LazySymbol & return_type ()

The return value type. This should be some kind of Type object. Will be empty for void return

types.

Defined at line 81 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_return_type (const LazySymbol & rt)

Defined at line 82 of file ../../src/developer/debug/zxdb/symbols/function.h

const std::vector<LazySymbol> & parameters ()

Parameters passed to the function. These should be Variable objects.

Defined at line 85 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_parameters (std::vector<LazySymbol> p)

Defined at line 86 of file ../../src/developer/debug/zxdb/symbols/function.h

const std::vector<LazySymbol> & template_params ()

Template parameters if this function is a template instantiation.

Defined at line 89 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_template_params (std::vector<LazySymbol> p)

Defined at line 90 of file ../../src/developer/debug/zxdb/symbols/function.h

const VariableLocation & frame_base ()

The frame base is the location where "fbreg" expressions are evaluated relative to (this will

be most local variables in a function). This can be an empty location if there's no frame base

or it's not needed (e.g. for inline functions).

When compiled with full stack frames, this will usually evaluate to the contents of the CPU's

"BP" register, but can be different or arbitrarily complicated, especially when things are

optimized.

Defined at line 99 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_frame_base (VariableLocation base)

Defined at line 100 of file ../../src/developer/debug/zxdb/symbols/function.h

const LazySymbol & object_pointer ()

The object pointer is the "this" object for the current function. Quick summary: Use

GetObjectPointerVariable() to retrieve "this".

The object_pointer() will be a reference to a parameter (object type Variable). It should

theoretically match one of the entries in the parameters() list but we can't guarantee what the

compiler has generated. The variable will be the implicit object ("this") pointer for member

functions. For nonmember or static member functions the object pointer will be null.

For inlined functions the location on the object_pointer variable may be wrong. Typically an

inlined subroutine consists of two entries:

Shared entry for all inlined instances:

(1) DW_TAG_subprogram "InlinedFunc"

DW_AT_object_pointer = reference to (2)

(2) DW_TAG_formal_parameter "this"

<info

on the parameter>

Specific inlined function instance:

(3) DW_TAG_inlined_subroutine "InlinedFunc"

DW_AT_abstract_origin = reference to (1)

(4) DW_TAG_formal_parameter "this"

DW_AT_abstract_origin = reference to (2)

<info

on parameter, possibly different than (2)>

Looking at the object pointer will give the variable on the abstract origin, while the inlined

subroutine will have its own declaration for "this" which will have a location specific to this

inlined instantiation.

The GetObjectPointerVariable() function handles this case and returns the correct resulting

variable. It will return null if there is no object pointer.

Defined at line 132 of file ../../src/developer/debug/zxdb/symbols/function.h

void set_object_pointer (const LazySymbol & op)

Defined at line 133 of file ../../src/developer/debug/zxdb/symbols/function.h

Protected Methods

const Function * AsFunction ()

Symbol protected overrides.

Defined at line 34 of file ../../src/developer/debug/zxdb/symbols/function.cc

Friends

class MakeRefCountedHelper
class RefCountedThreadSafe