xref: /openbsd-src/gnu/llvm/lldb/bindings/interface/SBFunction.i (revision be691f3bb6417f04a68938fadbcaee2d5795e764)
1061da546Spatrick //===-- SWIG Interface for SBFunction ---------------------------*- C++ -*-===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9061da546Spatrick namespace lldb {
10061da546Spatrick 
11061da546Spatrick %feature("docstring",
12061da546Spatrick "Represents a generic function, which can be inlined or not.
13061da546Spatrick 
14*be691f3bSpatrick For example (from test/lldbutil.py, but slightly modified for doc purpose),::
15061da546Spatrick 
16061da546Spatrick         ...
17061da546Spatrick 
18061da546Spatrick         frame = thread.GetFrameAtIndex(i)
19061da546Spatrick         addr = frame.GetPCAddress()
20061da546Spatrick         load_addr = addr.GetLoadAddress(target)
21061da546Spatrick         function = frame.GetFunction()
22061da546Spatrick         mod_name = frame.GetModule().GetFileSpec().GetFilename()
23061da546Spatrick 
24061da546Spatrick         if not function:
25061da546Spatrick             # No debug info for 'function'.
26061da546Spatrick             symbol = frame.GetSymbol()
27061da546Spatrick             file_addr = addr.GetFileAddress()
28061da546Spatrick             start_addr = symbol.GetStartAddress().GetFileAddress()
29061da546Spatrick             symbol_name = symbol.GetName()
30061da546Spatrick             symbol_offset = file_addr - start_addr
31061da546Spatrick             print >> output, '  frame #{num}: {addr:#016x} {mod}`{symbol} + {offset}'.format(
32061da546Spatrick                 num=i, addr=load_addr, mod=mod_name, symbol=symbol_name, offset=symbol_offset)
33061da546Spatrick         else:
34061da546Spatrick             # Debug info is available for 'function'.
35061da546Spatrick             func_name = frame.GetFunctionName()
36061da546Spatrick             file_name = frame.GetLineEntry().GetFileSpec().GetFilename()
37061da546Spatrick             line_num = frame.GetLineEntry().GetLine()
38061da546Spatrick             print >> output, '  frame #{num}: {addr:#016x} {mod}`{func} at {file}:{line} {args}'.format(
39061da546Spatrick                 num=i, addr=load_addr, mod=mod_name,
40061da546Spatrick                 func='%s [inlined]' % func_name] if frame.IsInlined() else func_name,
41061da546Spatrick                 file=file_name, line=line_num, args=get_args_as_string(frame, showFuncName=False))
42061da546Spatrick 
43061da546Spatrick         ...") SBFunction;
44061da546Spatrick class SBFunction
45061da546Spatrick {
46061da546Spatrick public:
47061da546Spatrick 
48061da546Spatrick     SBFunction ();
49061da546Spatrick 
50061da546Spatrick     SBFunction (const lldb::SBFunction &rhs);
51061da546Spatrick 
52061da546Spatrick     ~SBFunction ();
53061da546Spatrick 
54061da546Spatrick     bool
55061da546Spatrick     IsValid () const;
56061da546Spatrick 
57061da546Spatrick     explicit operator bool() const;
58061da546Spatrick 
59061da546Spatrick     const char *
60061da546Spatrick     GetName() const;
61061da546Spatrick 
62061da546Spatrick     const char *
63061da546Spatrick     GetDisplayName() const;
64061da546Spatrick 
65061da546Spatrick     const char *
66061da546Spatrick     GetMangledName () const;
67061da546Spatrick 
68061da546Spatrick     lldb::SBInstructionList
69061da546Spatrick     GetInstructions (lldb::SBTarget target);
70061da546Spatrick 
71061da546Spatrick     lldb::SBInstructionList
72061da546Spatrick     GetInstructions (lldb::SBTarget target, const char *flavor);
73061da546Spatrick 
74061da546Spatrick     lldb::SBAddress
75061da546Spatrick     GetStartAddress ();
76061da546Spatrick 
77061da546Spatrick     lldb::SBAddress
78061da546Spatrick     GetEndAddress ();
79061da546Spatrick 
80061da546Spatrick     const char *
81061da546Spatrick     GetArgumentName (uint32_t arg_idx);
82061da546Spatrick 
83061da546Spatrick     uint32_t
84061da546Spatrick     GetPrologueByteSize ();
85061da546Spatrick 
86061da546Spatrick     lldb::SBType
87061da546Spatrick     GetType ();
88061da546Spatrick 
89061da546Spatrick     lldb::SBBlock
90061da546Spatrick     GetBlock ();
91061da546Spatrick 
92061da546Spatrick     lldb::LanguageType
93061da546Spatrick     GetLanguage ();
94061da546Spatrick 
95061da546Spatrick     %feature("docstring", "
96061da546Spatrick     Returns true if the function was compiled with optimization.
97061da546Spatrick     Optimization, in this case, is meant to indicate that the debugger
98061da546Spatrick     experience may be confusing for the user -- variables optimized away,
99061da546Spatrick     stepping jumping between source lines -- and the driver may want to
100061da546Spatrick     provide some guidance to the user about this.
101061da546Spatrick     Returns false if unoptimized, or unknown.") GetIsOptimized;
102061da546Spatrick     bool
103061da546Spatrick     GetIsOptimized();
104061da546Spatrick 
105061da546Spatrick     bool
106061da546Spatrick     GetDescription (lldb::SBStream &description);
107061da546Spatrick 
108061da546Spatrick     bool
109061da546Spatrick     operator == (const lldb::SBFunction &rhs) const;
110061da546Spatrick 
111061da546Spatrick     bool
112061da546Spatrick     operator != (const lldb::SBFunction &rhs) const;
113061da546Spatrick 
114061da546Spatrick     STRING_EXTENSION(SBFunction)
115061da546Spatrick 
116061da546Spatrick #ifdef SWIGPYTHON
117061da546Spatrick     %pythoncode %{
118061da546Spatrick         def get_instructions_from_current_target (self):
119061da546Spatrick             return self.GetInstructions (target)
120061da546Spatrick 
121061da546Spatrick         addr = property(GetStartAddress, None, doc='''A read only property that returns an lldb object that represents the start address (lldb.SBAddress) for this function.''')
122061da546Spatrick         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.''')
123061da546Spatrick         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.''')
124061da546Spatrick         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.''')
125061da546Spatrick         mangled = property(GetMangledName, None, doc='''A read only property that returns the mangled (linkage) name for this function as a string.''')
126061da546Spatrick         name = property(GetName, None, doc='''A read only property that returns the name for this function as a string.''')
127061da546Spatrick         prologue_size = property(GetPrologueByteSize, None, doc='''A read only property that returns the size in bytes of the prologue instructions as an unsigned integer.''')
128061da546Spatrick         type = property(GetType, None, doc='''A read only property that returns an lldb object that represents the return type (lldb.SBType) for this function.''')
129061da546Spatrick     %}
130061da546Spatrick #endif
131061da546Spatrick 
132061da546Spatrick };
133061da546Spatrick 
134061da546Spatrick } // namespace lldb
135