Jim Ingham | ea401ec | 2019-03-06 22:43:25 +0000 | [diff] [blame] | 1 | //===-- ClangExpressionSourceCode.cpp ---------------------------*- C++ -*-===// |
Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Jim Ingham | ea401ec | 2019-03-06 22:43:25 +0000 | [diff] [blame] | 9 | #include "ClangExpressionSourceCode.h" |
Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 10 | |
Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 11 | #include "clang/Basic/CharInfo.h" |
| 12 | #include "llvm/ADT/StringRef.h" |
| 13 | |
Sean Callanan | 4dbb271 | 2015-09-25 20:35:58 +0000 | [diff] [blame] | 14 | #include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h" |
| 15 | #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/Block.h" |
Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/CompileUnit.h" |
| 18 | #include "lldb/Symbol/DebugMacros.h" |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 19 | #include "lldb/Symbol/TypeSystem.h" |
Siva Chandra | 03ff5c8 | 2016-02-05 19:10:04 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/VariableList.h" |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 21 | #include "lldb/Target/ExecutionContext.h" |
Siva Chandra | 03ff5c8 | 2016-02-05 19:10:04 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Language.h" |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Platform.h" |
Sean Callanan | 68f85e7 | 2015-04-30 21:49:58 +0000 | [diff] [blame] | 24 | #include "lldb/Target/StackFrame.h" |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Target.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 26 | #include "lldb/Utility/StreamString.h" |
Sean Callanan | 9bc8384 | 2011-09-26 18:45:31 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace lldb_private; |
| 29 | |
Jim Ingham | ea401ec | 2019-03-06 22:43:25 +0000 | [diff] [blame] | 30 | const char *ClangExpressionSourceCode::g_expression_prefix = R"( |
Sean Callanan | 68f85e7 | 2015-04-30 21:49:58 +0000 | [diff] [blame] | 31 | #ifndef NULL |
Greg Clayton | 399107a | 2013-02-13 23:57:48 +0000 | [diff] [blame] | 32 | #define NULL (__null) |
Sean Callanan | 68f85e7 | 2015-04-30 21:49:58 +0000 | [diff] [blame] | 33 | #endif |
| 34 | #ifndef Nil |
Greg Clayton | 399107a | 2013-02-13 23:57:48 +0000 | [diff] [blame] | 35 | #define Nil (__null) |
Sean Callanan | 68f85e7 | 2015-04-30 21:49:58 +0000 | [diff] [blame] | 36 | #endif |
| 37 | #ifndef nil |
Greg Clayton | 399107a | 2013-02-13 23:57:48 +0000 | [diff] [blame] | 38 | #define nil (__null) |
Sean Callanan | 68f85e7 | 2015-04-30 21:49:58 +0000 | [diff] [blame] | 39 | #endif |
| 40 | #ifndef YES |
Greg Clayton | 399107a | 2013-02-13 23:57:48 +0000 | [diff] [blame] | 41 | #define YES ((BOOL)1) |
Sean Callanan | 68f85e7 | 2015-04-30 21:49:58 +0000 | [diff] [blame] | 42 | #endif |
| 43 | #ifndef NO |
Greg Clayton | 399107a | 2013-02-13 23:57:48 +0000 | [diff] [blame] | 44 | #define NO ((BOOL)0) |
Sean Callanan | 68f85e7 | 2015-04-30 21:49:58 +0000 | [diff] [blame] | 45 | #endif |
Reid Kleckner | 56d861f | 2014-07-29 21:59:33 +0000 | [diff] [blame] | 46 | typedef __INT8_TYPE__ int8_t; |
| 47 | typedef __UINT8_TYPE__ uint8_t; |
| 48 | typedef __INT16_TYPE__ int16_t; |
| 49 | typedef __UINT16_TYPE__ uint16_t; |
| 50 | typedef __INT32_TYPE__ int32_t; |
| 51 | typedef __UINT32_TYPE__ uint32_t; |
| 52 | typedef __INT64_TYPE__ int64_t; |
| 53 | typedef __UINT64_TYPE__ uint64_t; |
| 54 | typedef __INTPTR_TYPE__ intptr_t; |
| 55 | typedef __UINTPTR_TYPE__ uintptr_t; |
Greg Clayton | 399107a | 2013-02-13 23:57:48 +0000 | [diff] [blame] | 56 | typedef __SIZE_TYPE__ size_t; |
| 57 | typedef __PTRDIFF_TYPE__ ptrdiff_t; |
| 58 | typedef unsigned short unichar; |
Kate Stone | cc391a0 | 2015-01-21 23:39:16 +0000 | [diff] [blame] | 59 | extern "C" |
| 60 | { |
| 61 | int printf(const char * __restrict, ...); |
| 62 | } |
Greg Clayton | 399107a | 2013-02-13 23:57:48 +0000 | [diff] [blame] | 63 | )"; |
Sean Callanan | a199e82 | 2012-09-13 23:35:30 +0000 | [diff] [blame] | 64 | |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 65 | static const char *c_start_marker = " /*LLDB_BODY_START*/\n "; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 66 | static const char *c_end_marker = ";\n /*LLDB_BODY_END*/\n"; |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 67 | |
Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 68 | namespace { |
| 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | class AddMacroState { |
| 71 | enum State { |
| 72 | CURRENT_FILE_NOT_YET_PUSHED, |
| 73 | CURRENT_FILE_PUSHED, |
| 74 | CURRENT_FILE_POPPED |
| 75 | }; |
Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 76 | |
| 77 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | AddMacroState(const FileSpec ¤t_file, const uint32_t current_file_line) |
| 79 | : m_state(CURRENT_FILE_NOT_YET_PUSHED), m_current_file(current_file), |
| 80 | m_current_file_line(current_file_line) {} |
Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 81 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | void StartFile(const FileSpec &file) { |
| 83 | m_file_stack.push_back(file); |
| 84 | if (file == m_current_file) |
| 85 | m_state = CURRENT_FILE_PUSHED; |
| 86 | } |
| 87 | |
| 88 | void EndFile() { |
| 89 | if (m_file_stack.size() == 0) |
| 90 | return; |
| 91 | |
| 92 | FileSpec old_top = m_file_stack.back(); |
| 93 | m_file_stack.pop_back(); |
| 94 | if (old_top == m_current_file) |
| 95 | m_state = CURRENT_FILE_POPPED; |
| 96 | } |
| 97 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 98 | // An entry is valid if it occurs before the current line in the current |
| 99 | // file. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | bool IsValidEntry(uint32_t line) { |
| 101 | switch (m_state) { |
| 102 | case CURRENT_FILE_NOT_YET_PUSHED: |
| 103 | return true; |
| 104 | case CURRENT_FILE_PUSHED: |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 105 | // If we are in file included in the current file, the entry should be |
| 106 | // added. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | if (m_file_stack.back() != m_current_file) |
| 108 | return true; |
| 109 | |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 110 | return line < m_current_file_line; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | default: |
| 112 | return false; |
Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 113 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 114 | } |
Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 115 | |
| 116 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | std::vector<FileSpec> m_file_stack; |
| 118 | State m_state; |
| 119 | FileSpec m_current_file; |
| 120 | uint32_t m_current_file_line; |
Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } // anonymous namespace |
| 124 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 125 | static void AddMacros(const DebugMacros *dm, CompileUnit *comp_unit, |
| 126 | AddMacroState &state, StreamString &stream) { |
| 127 | if (dm == nullptr) |
| 128 | return; |
| 129 | |
| 130 | for (size_t i = 0; i < dm->GetNumMacroEntries(); i++) { |
| 131 | const DebugMacroEntry &entry = dm->GetMacroEntryAtIndex(i); |
| 132 | uint32_t line; |
| 133 | |
| 134 | switch (entry.GetType()) { |
| 135 | case DebugMacroEntry::DEFINE: |
| 136 | if (state.IsValidEntry(entry.GetLineNumber())) |
| 137 | stream.Printf("#define %s\n", entry.GetMacroString().AsCString()); |
| 138 | else |
Siva Chandra | d8335e9 | 2015-12-16 00:22:08 +0000 | [diff] [blame] | 139 | return; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 140 | break; |
| 141 | case DebugMacroEntry::UNDEF: |
| 142 | if (state.IsValidEntry(entry.GetLineNumber())) |
| 143 | stream.Printf("#undef %s\n", entry.GetMacroString().AsCString()); |
| 144 | else |
| 145 | return; |
| 146 | break; |
| 147 | case DebugMacroEntry::START_FILE: |
| 148 | line = entry.GetLineNumber(); |
| 149 | if (state.IsValidEntry(line)) |
| 150 | state.StartFile(entry.GetFileSpec(comp_unit)); |
| 151 | else |
| 152 | return; |
| 153 | break; |
| 154 | case DebugMacroEntry::END_FILE: |
| 155 | state.EndFile(); |
| 156 | break; |
| 157 | case DebugMacroEntry::INDIRECT: |
| 158 | AddMacros(entry.GetIndirectDebugMacros(), comp_unit, state, stream); |
| 159 | break; |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 160 | default: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 161 | // This is an unknown/invalid entry. Ignore. |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 167 | /// Checks if the expression body contains the given variable as a token. |
| 168 | /// \param body The expression body. |
| 169 | /// \param var The variable token we are looking for. |
| 170 | /// \return True iff the expression body containes the variable as a token. |
| 171 | static bool ExprBodyContainsVar(llvm::StringRef body, llvm::StringRef var) { |
| 172 | assert(var.find_if([](char c) { return !clang::isIdentifierBody(c); }) == |
| 173 | llvm::StringRef::npos && |
| 174 | "variable contains non-identifier chars?"); |
| 175 | |
| 176 | size_t start = 0; |
| 177 | // Iterate over all occurences of the variable string in our expression. |
| 178 | while ((start = body.find(var, start)) != llvm::StringRef::npos) { |
| 179 | // We found our variable name in the expression. Check that the token |
| 180 | // that contains our needle is equal to our variable and not just contains |
| 181 | // the character sequence by accident. |
| 182 | // Prevents situations where we for example inlcude the variable 'FOO' in an |
| 183 | // expression like 'FOObar + 1'. |
| 184 | bool has_characters_before = |
| 185 | start != 0 && clang::isIdentifierBody(body[start - 1]); |
| 186 | bool has_characters_after = |
| 187 | start + var.size() < body.size() && |
| 188 | clang::isIdentifierBody(body[start + var.size()]); |
| 189 | |
| 190 | // Our token just contained the variable name as a substring. Continue |
| 191 | // searching the rest of the expression. |
| 192 | if (has_characters_before || has_characters_after) { |
| 193 | ++start; |
| 194 | continue; |
| 195 | } |
| 196 | return true; |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | static void AddLocalVariableDecls(const lldb::VariableListSP &var_list_sp, |
Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 202 | StreamString &stream, |
| 203 | const std::string &expr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | for (size_t i = 0; i < var_list_sp->GetSize(); i++) { |
| 205 | lldb::VariableSP var_sp = var_list_sp->GetVariableAtIndex(i); |
| 206 | |
| 207 | ConstString var_name = var_sp->GetName(); |
Raphael Isemann | 05cfdb0 | 2019-04-26 07:21:36 +0000 | [diff] [blame] | 208 | if (!var_name || var_name == "this" || var_name == ".block_descriptor") |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 209 | continue; |
| 210 | |
Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 211 | if (!expr.empty() && !ExprBodyContainsVar(expr, var_name.GetStringRef())) |
| 212 | continue; |
| 213 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 214 | stream.Printf("using $__lldb_local_vars::%s;\n", var_name.AsCString()); |
| 215 | } |
| 216 | } |
| 217 | |
Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 218 | bool ClangExpressionSourceCode::GetText( |
| 219 | std::string &text, lldb::LanguageType wrapping_language, bool static_method, |
| 220 | ExecutionContext &exe_ctx, bool add_locals, bool force_add_all_locals, |
| 221 | llvm::ArrayRef<std::string> modules) const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 222 | const char *target_specific_defines = "typedef signed char BOOL;\n"; |
| 223 | std::string module_macros; |
| 224 | |
| 225 | Target *target = exe_ctx.GetTargetPtr(); |
| 226 | if (target) { |
| 227 | if (target->GetArchitecture().GetMachine() == llvm::Triple::aarch64) { |
| 228 | target_specific_defines = "typedef bool BOOL;\n"; |
| 229 | } |
| 230 | if (target->GetArchitecture().GetMachine() == llvm::Triple::x86_64) { |
| 231 | if (lldb::PlatformSP platform_sp = target->GetPlatform()) { |
| 232 | static ConstString g_platform_ios_simulator("ios-simulator"); |
| 233 | if (platform_sp->GetPluginName() == g_platform_ios_simulator) { |
| 234 | target_specific_defines = "typedef bool BOOL;\n"; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if (ClangModulesDeclVendor *decl_vendor = |
| 240 | target->GetClangModulesDeclVendor()) { |
| 241 | ClangPersistentVariables *persistent_vars = |
| 242 | llvm::cast<ClangPersistentVariables>( |
| 243 | target->GetPersistentExpressionStateForLanguage( |
| 244 | lldb::eLanguageTypeC)); |
| 245 | const ClangModulesDeclVendor::ModuleVector &hand_imported_modules = |
| 246 | persistent_vars->GetHandLoadedClangModules(); |
| 247 | ClangModulesDeclVendor::ModuleVector modules_for_macros; |
| 248 | |
| 249 | for (ClangModulesDeclVendor::ModuleID module : hand_imported_modules) { |
| 250 | modules_for_macros.push_back(module); |
| 251 | } |
| 252 | |
| 253 | if (target->GetEnableAutoImportClangModules()) { |
| 254 | if (StackFrame *frame = exe_ctx.GetFramePtr()) { |
| 255 | if (Block *block = frame->GetFrameBlock()) { |
| 256 | SymbolContext sc; |
| 257 | |
| 258 | block->CalculateSymbolContext(&sc); |
| 259 | |
| 260 | if (sc.comp_unit) { |
| 261 | StreamString error_stream; |
| 262 | |
| 263 | decl_vendor->AddModulesForCompileUnit( |
| 264 | *sc.comp_unit, modules_for_macros, error_stream); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | decl_vendor->ForEachMacro( |
| 271 | modules_for_macros, |
| 272 | [&module_macros](const std::string &expansion) -> bool { |
| 273 | module_macros.append(expansion); |
| 274 | module_macros.append("\n"); |
| 275 | return false; |
| 276 | }); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | StreamString debug_macros_stream; |
| 281 | StreamString lldb_local_var_decls; |
| 282 | if (StackFrame *frame = exe_ctx.GetFramePtr()) { |
| 283 | const SymbolContext &sc = frame->GetSymbolContext( |
| 284 | lldb::eSymbolContextCompUnit | lldb::eSymbolContextLineEntry); |
| 285 | |
| 286 | if (sc.comp_unit && sc.line_entry.IsValid()) { |
| 287 | DebugMacros *dm = sc.comp_unit->GetDebugMacros(); |
| 288 | if (dm) { |
| 289 | AddMacroState state(sc.line_entry.file, sc.line_entry.line); |
| 290 | AddMacros(dm, sc.comp_unit, state, debug_macros_stream); |
| 291 | } |
| 292 | } |
| 293 | |
Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 294 | if (add_locals) { |
| 295 | if (Language::LanguageIsCPlusPlus(frame->GetLanguage())) { |
| 296 | if (target->GetInjectLocalVariables(&exe_ctx)) { |
| 297 | lldb::VariableListSP var_list_sp = |
| 298 | frame->GetInScopeVariableList(false, true); |
Raphael Isemann | 71569d0 | 2019-05-02 10:12:56 +0000 | [diff] [blame] | 299 | AddLocalVariableDecls(var_list_sp, lldb_local_var_decls, |
| 300 | force_add_all_locals ? "" : m_body); |
Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 301 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if (m_wrap) { |
| 307 | switch (wrapping_language) { |
| 308 | default: |
| 309 | return false; |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 310 | case lldb::eLanguageTypeC: |
| 311 | case lldb::eLanguageTypeC_plus_plus: |
| 312 | case lldb::eLanguageTypeObjC: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 313 | break; |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 314 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 315 | |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 316 | // Generate a list of @import statements that will import the specified |
| 317 | // module into our expression. |
| 318 | std::string module_imports; |
| 319 | for (const std::string &module : modules) { |
| 320 | module_imports.append("@import "); |
| 321 | module_imports.append(module); |
| 322 | module_imports.append(";\n"); |
| 323 | } |
| 324 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 325 | StreamString wrap_stream; |
| 326 | |
| 327 | wrap_stream.Printf("%s\n%s\n%s\n%s\n%s\n", module_macros.c_str(), |
| 328 | debug_macros_stream.GetData(), g_expression_prefix, |
| 329 | target_specific_defines, m_prefix.c_str()); |
| 330 | |
| 331 | // First construct a tagged form of the user expression so we can find it |
| 332 | // later: |
| 333 | std::string tagged_body; |
| 334 | switch (wrapping_language) { |
| 335 | default: |
| 336 | tagged_body = m_body; |
| 337 | break; |
| 338 | case lldb::eLanguageTypeC: |
| 339 | case lldb::eLanguageTypeC_plus_plus: |
| 340 | case lldb::eLanguageTypeObjC: |
| 341 | tagged_body.append(c_start_marker); |
| 342 | tagged_body.append(m_body); |
| 343 | tagged_body.append(c_end_marker); |
| 344 | break; |
| 345 | } |
| 346 | switch (wrapping_language) { |
| 347 | default: |
| 348 | break; |
| 349 | case lldb::eLanguageTypeC: |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 350 | wrap_stream.Printf("%s" |
| 351 | "void \n" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 352 | "%s(void *$__lldb_arg) \n" |
| 353 | "{ \n" |
| 354 | " %s; \n" |
| 355 | "%s" |
| 356 | "} \n", |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 357 | module_imports.c_str(), m_name.c_str(), |
| 358 | lldb_local_var_decls.GetData(), tagged_body.c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 359 | break; |
| 360 | case lldb::eLanguageTypeC_plus_plus: |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 361 | wrap_stream.Printf("%s" |
| 362 | "void \n" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 363 | "$__lldb_class::%s(void *$__lldb_arg) \n" |
| 364 | "{ \n" |
| 365 | " %s; \n" |
| 366 | "%s" |
| 367 | "} \n", |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 368 | module_imports.c_str(), m_name.c_str(), |
| 369 | lldb_local_var_decls.GetData(), tagged_body.c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 370 | break; |
| 371 | case lldb::eLanguageTypeObjC: |
| 372 | if (static_method) { |
| 373 | wrap_stream.Printf( |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 374 | "%s" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 375 | "@interface $__lldb_objc_class ($__lldb_category) \n" |
| 376 | "+(void)%s:(void *)$__lldb_arg; \n" |
| 377 | "@end \n" |
| 378 | "@implementation $__lldb_objc_class ($__lldb_category) \n" |
| 379 | "+(void)%s:(void *)$__lldb_arg \n" |
| 380 | "{ \n" |
| 381 | "%s" |
| 382 | "} \n" |
| 383 | "@end \n", |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 384 | module_imports.c_str(), m_name.c_str(), m_name.c_str(), |
| 385 | tagged_body.c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 386 | } else { |
| 387 | wrap_stream.Printf( |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 388 | "%s" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 389 | "@interface $__lldb_objc_class ($__lldb_category) \n" |
| 390 | "-(void)%s:(void *)$__lldb_arg; \n" |
| 391 | "@end \n" |
| 392 | "@implementation $__lldb_objc_class ($__lldb_category) \n" |
| 393 | "-(void)%s:(void *)$__lldb_arg \n" |
| 394 | "{ \n" |
| 395 | "%s" |
| 396 | "} \n" |
| 397 | "@end \n", |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 398 | module_imports.c_str(), m_name.c_str(), m_name.c_str(), |
| 399 | tagged_body.c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 400 | } |
| 401 | break; |
| 402 | } |
| 403 | |
| 404 | text = wrap_stream.GetString(); |
| 405 | } else { |
| 406 | text.append(m_body); |
| 407 | } |
| 408 | |
| 409 | return true; |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Jim Ingham | ea401ec | 2019-03-06 22:43:25 +0000 | [diff] [blame] | 412 | bool ClangExpressionSourceCode::GetOriginalBodyBounds( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 413 | std::string transformed_text, lldb::LanguageType wrapping_language, |
| 414 | size_t &start_loc, size_t &end_loc) { |
| 415 | const char *start_marker; |
| 416 | const char *end_marker; |
| 417 | |
| 418 | switch (wrapping_language) { |
| 419 | default: |
| 420 | return false; |
| 421 | case lldb::eLanguageTypeC: |
| 422 | case lldb::eLanguageTypeC_plus_plus: |
| 423 | case lldb::eLanguageTypeObjC: |
| 424 | start_marker = c_start_marker; |
| 425 | end_marker = c_end_marker; |
| 426 | break; |
| 427 | } |
| 428 | |
| 429 | start_loc = transformed_text.find(start_marker); |
| 430 | if (start_loc == std::string::npos) |
| 431 | return false; |
| 432 | start_loc += strlen(start_marker); |
| 433 | end_loc = transformed_text.find(end_marker); |
Jonas Devlieghere | a6682a4 | 2018-12-15 00:15:33 +0000 | [diff] [blame] | 434 | return end_loc != std::string::npos; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 435 | } |