Browse Source

Improved debug menu activation/deactivation, and now does no debug initialization before debug is run

merge-requests/365/head
eidheim 10 years ago
parent
commit
9ee3255f5f
  1. 15
      src/debug.cc
  2. 4
      src/debug.h
  3. 15
      src/window.cc

15
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<void(int exit_status)> callback,
std::function<void(const std::string &status)> status_callback,
std::function<void(const boost::filesystem::path &file_path, int line_nr, int line_index)> stop_callback) {
if(!debugger.IsValid()) {
if(!debugger) {
lldb::SBDebugger::Initialize();
debugger=lldb::SBDebugger::Create(true, log, nullptr);
debugger=std::unique_ptr<lldb::SBDebugger>(new lldb::SBDebugger(lldb::SBDebugger::Create(true, log, nullptr)));
listener=std::unique_ptr<lldb::SBListener>(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<lldb::SBProcess>(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<lldb::SBProcess>(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<std::string, std::string> 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();
}

4
src/debug.h

@ -54,8 +54,8 @@ public:
void write(const std::string &buffer);
private:
lldb::SBDebugger debugger;
lldb::SBListener listener;
std::unique_ptr<lldb::SBDebugger> debugger;
std::unique_ptr<lldb::SBListener> listener;
std::unique_ptr<lldb::SBProcess> process;
std::thread debug_thread;

15
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();
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<bool>(notebook.get_current_view()->rename_similar_tokens) : false);
menu.actions["source_goto_next_diagnostic"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_next_diagnostic) : false);
menu.actions["source_apply_fix_its"]->set_enabled(activate ? static_cast<bool>(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) {

Loading…
Cancel
Save