From 9ee3255f5fc543cbb66f3b1b05943ba61f974f10 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 6 Jan 2016 09:21:49 +0100 Subject: [PATCH] Improved debug menu activation/deactivation, and now does no debug initialization before debug is run --- src/debug.cc | 15 ++++++++------- src/debug.h | 4 ++-- src/window.cc | 19 +++++++++++++++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/debug.cc b/src/debug.cc index 50b4b5a..d26d31c 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -27,7 +27,7 @@ void log(const char *msg, void *) { cout << "debugger log: " << msg << endl; } -Debug::Debug(): listener("juCi++ lldb listener"), state(lldb::StateType::eStateInvalid), buffer_size(131072) { +Debug::Debug(): state(lldb::StateType::eStateInvalid), buffer_size(131072) { #ifdef __APPLE__ auto debugserver_path=boost::filesystem::path("/usr/local/opt/llvm/bin/debugserver"); if(boost::filesystem::exists(debugserver_path)) @@ -40,9 +40,10 @@ void Debug::start(const std::string &command, const boost::filesystem::path &pat std::function callback, std::function status_callback, std::function stop_callback) { - if(!debugger.IsValid()) { + if(!debugger) { lldb::SBDebugger::Initialize(); - debugger=lldb::SBDebugger::Create(true, log, nullptr); + debugger=std::unique_ptr(new lldb::SBDebugger(lldb::SBDebugger::Create(true, log, nullptr))); + listener=std::unique_ptr(new lldb::SBListener("juCi++ lldb listener")); } //Create executable string and argument array @@ -78,7 +79,7 @@ void Debug::start(const std::string &command, const boost::filesystem::path &pat argv[c]=arguments[c].c_str(); argv[arguments.size()]=NULL; - auto target=debugger.CreateTarget(executable.c_str()); + auto target=debugger->CreateTarget(executable.c_str()); if(!target.IsValid()) { Terminal::get().async_print("Error (debug): Could not create debug target to: "+executable+'\n', true); if(callback) @@ -99,7 +100,7 @@ void Debug::start(const std::string &command, const boost::filesystem::path &pat } lldb::SBError error; - process = std::unique_ptr(new lldb::SBProcess(target.Launch(listener, argv, (const char**)environ, nullptr, nullptr, nullptr, path.string().c_str(), lldb::eLaunchFlagNone, false, error))); + process = std::unique_ptr(new lldb::SBProcess(target.Launch(*listener, argv, (const char**)environ, nullptr, nullptr, nullptr, path.string().c_str(), lldb::eLaunchFlagNone, false, error))); if(error.Fail()) { Terminal::get().async_print(std::string("Error (debug): ")+error.GetCString()+'\n', true); if(callback) @@ -112,7 +113,7 @@ void Debug::start(const std::string &command, const boost::filesystem::path &pat lldb::SBEvent event; while(true) { event_mutex.lock(); - if(listener.GetNextEvent(event)) { + if(listener->GetNextEvent(event)) { if((event.GetType() & lldb::SBProcess::eBroadcastBitStateChanged)>0) { auto state=process->GetStateFromEvent(event); this->state=state; @@ -271,7 +272,7 @@ std::pair Debug::run_command(const std::string &comman event_mutex.lock(); if(state==lldb::StateType::eStateStopped) { lldb::SBCommandReturnObject command_return_object; - debugger.GetCommandInterpreter().HandleCommand(command.c_str(), command_return_object, true); + debugger->GetCommandInterpreter().HandleCommand(command.c_str(), command_return_object, true); command_return.first=command_return_object.GetOutput(); command_return.second=command_return_object.GetError(); } diff --git a/src/debug.h b/src/debug.h index bd6c541..9ae597c 100644 --- a/src/debug.h +++ b/src/debug.h @@ -54,8 +54,8 @@ public: void write(const std::string &buffer); private: - lldb::SBDebugger debugger; - lldb::SBListener listener; + std::unique_ptr debugger; + std::unique_ptr listener; std::unique_ptr process; std::thread debug_thread; diff --git a/src/window.cc b/src/window.cc index 9d2e6b5..bfb80ea 100644 --- a/src/window.cc +++ b/src/window.cc @@ -963,10 +963,10 @@ void Window::set_menu_actions() { entry_box.show(); }); menu.add_action("debug_toggle_breakpoint", [this](){ - bool debug_is_stopped_or_running=Debug::get().is_stopped() || Debug::get().is_running(); - if(Debug::get().is_invalid() || debug_is_stopped_or_running) { - if(notebook.get_current_page()!=-1) { - auto view=notebook.get_current_view(); + if(notebook.get_current_page()!=-1) { + auto view=notebook.get_current_view(); + bool debug_is_stopped_or_running=Debug::get().is_stopped() || Debug::get().is_running(); + if(Debug::get().is_invalid() || debug_is_stopped_or_running) { auto line_nr=view->get_buffer()->get_insert()->get_iter().get_line(); if(view->get_source_buffer()->get_source_marks_at_line(line_nr, "debug_breakpoint").size()>0) { @@ -1057,6 +1057,17 @@ void Window::activate_menu_items(bool activate) { menu.actions["source_rename"]->set_enabled(activate ? static_cast(notebook.get_current_view()->rename_similar_tokens) : false); menu.actions["source_goto_next_diagnostic"]->set_enabled(activate ? static_cast(notebook.get_current_view()->goto_next_diagnostic) : false); menu.actions["source_apply_fix_its"]->set_enabled(activate ? static_cast(notebook.get_current_view()->apply_fix_its) : false); +#ifdef JUCI_ENABLE_DEBUG + if(notebook.get_current_page()!=-1) { + auto view=notebook.get_current_view(); + if(view->language->get_id()=="c" || view->language->get_id()=="cpp" || view->language->get_id()=="objc" || view->language->get_id()=="chdr" || view->language->get_id()=="cpphdr") + menu.actions["debug_toggle_breakpoint"]->set_enabled(true); + else + menu.actions["debug_toggle_breakpoint"]->set_enabled(false); + } + else + menu.actions["debug_toggle_breakpoint"]->set_enabled(false); +#endif } bool Window::on_key_press_event(GdkEventKey *event) {