diff --git a/src/debug_lldb.cc b/src/debug_lldb.cc index 70bbe0a..f70b3aa 100644 --- a/src/debug_lldb.cc +++ b/src/debug_lldb.cc @@ -89,7 +89,7 @@ std::tuple, std::string, std::vector > Deb void Debug::LLDB::start(const std::string &command, const boost::filesystem::path &path, const std::vector > &breakpoints, - const std::string &remote_host) { + const std::vector &startup_commands, const std::string &remote_host) { if(!debugger) { lldb::SBDebugger::Initialize(); debugger=std::make_unique(lldb::SBDebugger::Create(true, log, nullptr)); @@ -181,6 +181,12 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat debug_thread.join(); for(auto &handler: on_start) handler(*process); + + for(auto &command: startup_commands) { + lldb::SBCommandReturnObject command_return_object; + debugger->GetCommandInterpreter().HandleCommand(command.c_str(), command_return_object, false); + } + debug_thread=std::thread([this]() { lldb::SBEvent event; while(true) { diff --git a/src/debug_lldb.h b/src/debug_lldb.h index 71934cc..42560c3 100644 --- a/src/debug_lldb.h +++ b/src/debug_lldb.h @@ -47,7 +47,7 @@ namespace Debug { void start(const std::string &command, const boost::filesystem::path &path="", const std::vector > &breakpoints={}, - const std::string &remote_host=""); + const std::vector &startup_commands={}, const std::string &remote_host=""); void continue_debug(); //can't use continue as function name void stop(); void kill(); diff --git a/src/project.cc b/src/project.cc index b36baaf..952e3ba 100644 --- a/src/project.cc +++ b/src/project.cc @@ -365,7 +365,19 @@ void Project::LLDB::debug_start() { }); on_event_it=std::prev(Debug::LLDB::get().on_event.end()); - Debug::LLDB::get().start(*run_arguments, *project_path, breakpoints, remote_host); + std::vector startup_commands; + if(dynamic_cast(self->build.get())) { + std::stringstream istream, ostream; + if(Terminal::get().process(istream, ostream, "rustc --print sysroot")==0) { + auto sysroot=ostream.str(); + while(!sysroot.empty() && (sysroot.back()=='\n' || sysroot.back()=='\r')) + sysroot.pop_back(); + startup_commands.emplace_back("command script import \""+sysroot+"/lib/rustlib/etc/lldb_rust_formatters.py\""); + startup_commands.emplace_back("type summary add --no-value --python-function lldb_rust_formatters.print_val -x \".*\" --category Rust"); + startup_commands.emplace_back("type category enable Rust"); + } + } + Debug::LLDB::get().start(*run_arguments, *project_path, breakpoints, std::move(startup_commands), remote_host); }); } });