================ @@ -0,0 +1,542 @@ +#include "RPCLibrarySourceEmitter.h" +#include "RPCCommon.h" + +#include "clang/AST/AST.h" +#include "clang/Frontend/CompilerInstance.h" + +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/raw_ostream.h" +#include <string> + +using namespace clang; +using namespace lldb_rpc_gen; + +static constexpr llvm::StringRef ReturnVariableName("__result"); + +// This map stores any method that needs custom logic with a struct that +// tells us where the logic needs to be inserted and what code needs to be +// inserted. The code here is stored as a raw string literal. +const llvm::StringMap<RPCLibrarySourceEmitter::CustomLogic> + CustomLogicForMethods = { + {"_ZN4lldb10SBDebugger6CreateEbPFvPKcPvES3_", + {RPCLibrarySourceEmitter::CustomLogicLocation::eAfterDecode, R"code( + // Now source the .lldbinit files manually since we can't rely on the + // LLDB.framework on the other side to have special support for sourcing the right file + // since it would try to source "~/.lldbinit-lldb-rpc-server" followed by + // "~/.lldbinit". We want it to try "~.lldbinit-%s" where %s is the + // current program basename followed by "~/.lldbinit". + + if (source_init_files && __result.ObjectRefIsValid()) { + const char *program_basename = rpc::GetProgramBasename(); + if (program_basename) { + char init_path[PATH_MAX]; + snprintf(init_path, sizeof(init_path), "~/.lldbinit-%s", + program_basename); + lldb_rpc::SBFileSpec program_init_file(connection, init_path, true); + if (program_init_file.Exists()) { + char command_str[PATH_MAX]; + snprintf(command_str, sizeof(command_str), + "command source -s 1 -c 1 -e 0 '%s'", init_path); + __result.HandleCommand(command_str); + } else { + __result.HandleCommand("command source -s 1 -c 1 -e 0 '~/.lldbinit'"); + } + } + })code"}}, +}; + +static std::string GetLocalObjectRefCtor(const std::string &ClassName) { + return "rpc::LocalObjectRef(LLDB_RPC_INVALID_CONNECTION_ID, eClass_lldb_" + + ClassName + ", LLDB_RPC_INVALID_OBJECT_ID)"; +} + +static std::string GetObjectRefCtor(const std::string &ClassName) { + return "rpc::ObjectRef(LLDB_RPC_INVALID_CONNECTION_ID, eClass_lldb_" + + ClassName + ", LLDB_RPC_INVALID_OBJECT_ID)"; +} + +void RPCLibrarySourceEmitter::EmitCopyCtor() { + EmitLine("lldb_rpc::" + CurrentClass + "::" + CurrentClass + + "(const lldb_rpc::" + CurrentClass + " &rhs) = default;"); +} + +void RPCLibrarySourceEmitter::EmitCopyAssign() { + EmitLine("lldb_rpc::" + CurrentClass + " &lldb_rpc::" + CurrentClass + + "::operator=(const lldb_rpc::" + CurrentClass + " &rhs) = default;"); +} + +void RPCLibrarySourceEmitter::EmitMoveCtor() { + EmitLine("lldb_rpc::" + CurrentClass + "::" + CurrentClass + + "(lldb_rpc::" + CurrentClass + " &&rhs) = default;"); +} + +void RPCLibrarySourceEmitter::EmitMoveAssign() { + EmitLine("lldb_rpc::" + CurrentClass + " &lldb_rpc::" + CurrentClass + + "::operator=(lldb_rpc::" + CurrentClass + " &&rhs) = default;"); +} + +void RPCLibrarySourceEmitter::EmitMethod(const Method &method) { + if (method.IsCopyCtor) { + CopyCtorEmitted = true; ---------------- DavidSpickett wrote:
Like before, set these to true after you've done the emission. https://github.com/llvm/llvm-project/pull/147655 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits