|
13 | 13 | #include <string> |
14 | 14 | #include <vector> |
15 | 15 |
|
| 16 | +#include "llvm/Support/FormatProviders.h" |
16 | 17 |
|
17 | 18 | #include "lldb/Expression/ExpressionTypeSystemHelper.h" |
18 | 19 | #include "lldb/lldb-forward.h" |
@@ -96,6 +97,62 @@ class Expression { |
96 | 97 | ///invalid. |
97 | 98 | }; |
98 | 99 |
|
| 100 | +/// Holds parsed information about a function call label that |
| 101 | +/// LLDB attaches as an AsmLabel to function AST nodes it parses |
| 102 | +/// from debug-info. |
| 103 | +/// |
| 104 | +/// The format being: |
| 105 | +/// |
| 106 | +/// <prefix>:<module uid>:<symbol uid>:<name> |
| 107 | +/// |
| 108 | +/// The label string needs to stay valid for the entire lifetime |
| 109 | +/// of this object. |
| 110 | +struct FunctionCallLabel { |
| 111 | + /// Unique identifier of the lldb_private::Module |
| 112 | + /// which contains the symbol identified by \c symbol_id. |
| 113 | + lldb::user_id_t module_id; |
| 114 | + |
| 115 | + /// Unique identifier of the function symbol on which to |
| 116 | + /// perform the function call. For example, for DWARF this would |
| 117 | + /// be the DIE UID. |
| 118 | + lldb::user_id_t symbol_id; |
| 119 | + |
| 120 | + /// Name to use when searching for the function symbol in |
| 121 | + /// \c module_id. For most function calls this will be a |
| 122 | + /// mangled name. In cases where a mangled name can't be used, |
| 123 | + /// this will be the function name. |
| 124 | + /// |
| 125 | + /// NOTE: kept as last element so we don't have to worry about |
| 126 | + /// ':' in the mangled name when parsing the label. |
| 127 | + llvm::StringRef lookup_name; |
| 128 | + |
| 129 | + /// Decodes the specified function \c label into a \c FunctionCallLabel. |
| 130 | + static llvm::Expected<FunctionCallLabel> fromString(llvm::StringRef label); |
| 131 | + |
| 132 | + /// Encode this FunctionCallLabel into its string representation. |
| 133 | + /// |
| 134 | + /// The representation roundtrips through \c fromString: |
| 135 | + /// \code{.cpp} |
| 136 | + /// llvm::StringRef encoded = "$__lldb_func:0x0:0x0:_Z3foov"; |
| 137 | + /// FunctionCallLabel label = *fromString(label); |
| 138 | + /// |
| 139 | + /// assert (label.toString() == encoded); |
| 140 | + /// assert (*fromString(label.toString()) == label); |
| 141 | + /// \endcode |
| 142 | + std::string toString() const; |
| 143 | +}; |
| 144 | + |
| 145 | +/// LLDB attaches this prefix to mangled names of functions that get called |
| 146 | +/// from JITted expressions. |
| 147 | +inline constexpr llvm::StringRef FunctionCallLabelPrefix = "$__lldb_func"; |
| 148 | + |
99 | 149 | } // namespace lldb_private |
100 | 150 |
|
| 151 | +namespace llvm { |
| 152 | +template <> struct format_provider<lldb_private::FunctionCallLabel> { |
| 153 | + static void format(const lldb_private::FunctionCallLabel &label, |
| 154 | + raw_ostream &OS, StringRef Style); |
| 155 | +}; |
| 156 | +} // namespace llvm |
| 157 | + |
101 | 158 | #endif // LLDB_EXPRESSION_EXPRESSION_H |
0 commit comments