1//===-- SWIG Interface for SBFunction ---------------------------*- C++ -*-===//
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
9namespace lldb {
10
11%feature("docstring",
12"Represents a generic function, which can be inlined or not.
13
14For example (from test/lldbutil.py, but slightly modified for doc purpose),
15
16        ...
17
18        frame = thread.GetFrameAtIndex(i)
19        addr = frame.GetPCAddress()
20        load_addr = addr.GetLoadAddress(target)
21        function = frame.GetFunction()
22        mod_name = frame.GetModule().GetFileSpec().GetFilename()
23
24        if not function:
25            # No debug info for 'function'.
26            symbol = frame.GetSymbol()
27            file_addr = addr.GetFileAddress()
28            start_addr = symbol.GetStartAddress().GetFileAddress()
29            symbol_name = symbol.GetName()
30            symbol_offset = file_addr - start_addr
31            print >> output, '  frame #{num}: {addr:#016x} {mod}`{symbol} + {offset}'.format(
32                num=i, addr=load_addr, mod=mod_name, symbol=symbol_name, offset=symbol_offset)
33        else:
34            # Debug info is available for 'function'.
35            func_name = frame.GetFunctionName()
36            file_name = frame.GetLineEntry().GetFileSpec().GetFilename()
37            line_num = frame.GetLineEntry().GetLine()
38            print >> output, '  frame #{num}: {addr:#016x} {mod}`{func} at {file}:{line} {args}'.format(
39                num=i, addr=load_addr, mod=mod_name,
40                func='%s [inlined]' % func_name] if frame.IsInlined() else func_name,
41                file=file_name, line=line_num, args=get_args_as_string(frame, showFuncName=False))
42
43        ...") SBFunction;
44class SBFunction
45{
46public:
47
48    SBFunction ();
49
50    SBFunction (const lldb::SBFunction &rhs);
51
52    ~SBFunction ();
53
54    bool
55    IsValid () const;
56
57    explicit operator bool() const;
58
59    const char *
60    GetName() const;
61
62    const char *
63    GetDisplayName() const;
64
65    const char *
66    GetMangledName () const;
67
68    lldb::SBInstructionList
69    GetInstructions (lldb::SBTarget target);
70
71    lldb::SBInstructionList
72    GetInstructions (lldb::SBTarget target, const char *flavor);
73
74    lldb::SBAddress
75    GetStartAddress ();
76
77    lldb::SBAddress
78    GetEndAddress ();
79
80    const char *
81    GetArgumentName (uint32_t arg_idx);
82
83    uint32_t
84    GetPrologueByteSize ();
85
86    lldb::SBType
87    GetType ();
88
89    lldb::SBBlock
90    GetBlock ();
91
92    lldb::LanguageType
93    GetLanguage ();
94
95    %feature("docstring", "
96    Returns true if the function was compiled with optimization.
97    Optimization, in this case, is meant to indicate that the debugger
98    experience may be confusing for the user -- variables optimized away,
99    stepping jumping between source lines -- and the driver may want to
100    provide some guidance to the user about this.
101    Returns false if unoptimized, or unknown.") GetIsOptimized;
102    bool
103    GetIsOptimized();
104
105    bool
106    GetDescription (lldb::SBStream &description);
107
108    bool
109    operator == (const lldb::SBFunction &rhs) const;
110
111    bool
112    operator != (const lldb::SBFunction &rhs) const;
113
114    STRING_EXTENSION(SBFunction)
115
116#ifdef SWIGPYTHON
117    %pythoncode %{
118        def get_instructions_from_current_target (self):
119            return self.GetInstructions (target)
120
121        addr = property(GetStartAddress, None, doc='''A read only property that returns an lldb object that represents the start address (lldb.SBAddress) for this function.''')
122        end_addr = property(GetEndAddress, None, doc='''A read only property that returns an lldb object that represents the end address (lldb.SBAddress) for this function.''')
123        block = property(GetBlock, None, doc='''A read only property that returns an lldb object that represents the top level lexical block (lldb.SBBlock) for this function.''')
124        instructions = property(get_instructions_from_current_target, None, doc='''A read only property that returns an lldb object that represents the instructions (lldb.SBInstructionList) for this function.''')
125        mangled = property(GetMangledName, None, doc='''A read only property that returns the mangled (linkage) name for this function as a string.''')
126        name = property(GetName, None, doc='''A read only property that returns the name for this function as a string.''')
127        prologue_size = property(GetPrologueByteSize, None, doc='''A read only property that returns the size in bytes of the prologue instructions as an unsigned integer.''')
128        type = property(GetType, None, doc='''A read only property that returns an lldb object that represents the return type (lldb.SBType) for this function.''')
129    %}
130#endif
131
132};
133
134} // namespace lldb
135