From 924ccfc30da585c047b756813826a14efd5bc43e Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 31 Dec 2015 10:20:39 +0100 Subject: [PATCH] Debugging fixes --- src/debug.cc | 27 +++++++++++++++++---------- src/files.h | 2 +- src/window.cc | 40 +++++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/debug.cc b/src/debug.cc index dbf7a8b..5c4da51 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -19,16 +19,16 @@ void log(const char *msg, void *) { cout << "debugger log: " << msg << endl; } -Debug::Debug(): listener("juCi++ lldb listener"), state(lldb::StateType::eStateInvalid), buffer_size(131072) { - lldb::SBDebugger::Initialize(); - - debugger=lldb::SBDebugger::Create(true, log, nullptr); -} +Debug::Debug(): listener("juCi++ lldb listener"), state(lldb::StateType::eStateInvalid), buffer_size(131072) {} void Debug::start(std::shared_ptr > > breakpoints, const boost::filesystem::path &executable, const boost::filesystem::path &path, std::function callback, std::function status_callback, std::function stop_callback) { + if(!debugger.IsValid()) { + lldb::SBDebugger::Initialize(); + debugger=lldb::SBDebugger::Create(true, log, nullptr); + } auto target=debugger.CreateTarget(executable.string().c_str()); if(!target.IsValid()) { @@ -49,10 +49,9 @@ void Debug::start(std::shared_ptrGetSelectedThread().GetSelectedFrame().GetLineEntry(); if(stop_callback) { - lldb::SBStream stream; - line_entry.GetFileSpec().GetDescription(stream); - stop_callback(stream.GetData(), line_entry.GetLine(), line_entry.GetColumn()); + if(line_entry.IsValid()) { + lldb::SBStream stream; + line_entry.GetFileSpec().GetDescription(stream); + auto column=line_entry.GetColumn(); + if(column==0) + column=1; + stop_callback(stream.GetData(), line_entry.GetLine(), column); + } + else + stop_callback("", 0, 0); } } @@ -170,6 +176,7 @@ void Debug::delete_debug() { kill(); if(debug_thread.joinable()) debug_thread.join(); + lldb::SBDebugger::Terminate(); } std::string Debug::get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr) { diff --git a/src/files.h b/src/files.h index 2cf0867..34dca1f 100644 --- a/src/files.h +++ b/src/files.h @@ -2,7 +2,7 @@ #define JUCI_FILES_H_ #include -#define JUCI_VERSION "1.0.2" +#define JUCI_VERSION "1.1.0" const std::string configjson = "{\n" diff --git a/src/window.cc b/src/window.cc index be1d648..ffdc4f1 100644 --- a/src/window.cc +++ b/src/window.cc @@ -790,25 +790,27 @@ void Window::set_menu_actions() { debug_stop_mutex.lock(); auto debug_stop_copy=debug_stop; debug_stop_mutex.unlock(); - notebook.open(debug_stop_copy.first); - if(notebook.get_current_page()!=-1) { - auto view=notebook.get_current_view(); - debug_update_stop(); - - int line_nr=debug_stop_copy.second.first-1; - int line_index= debug_stop_copy.second.second-1; - if(line_nrget_buffer()->get_line_count()) { - auto iter=view->get_buffer()->get_iter_at_line(line_nr); - auto end_line_iter=iter; - while(!iter.ends_line() && iter.forward_char()) {} - auto line=view->get_buffer()->get_text(iter, end_line_iter); - if(line_indexget_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(line_nr, line_index)); - - while(g_main_context_pending(NULL)) - g_main_context_iteration(NULL, false); - if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view) - view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); + if(!debug_stop_copy.first.empty()) { + notebook.open(debug_stop_copy.first); + if(notebook.get_current_page()!=-1) { + auto view=notebook.get_current_view(); + debug_update_stop(); + + int line_nr=debug_stop_copy.second.first-1; + int line_index=debug_stop_copy.second.second-1; + if(line_nrget_buffer()->get_line_count()) { + auto iter=view->get_buffer()->get_iter_at_line(line_nr); + auto end_line_iter=iter; + while(!iter.ends_line() && iter.forward_char()) {} + auto line=view->get_buffer()->get_text(iter, end_line_iter); + if(line_indexget_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(line_nr, line_index)); + + while(g_main_context_pending(NULL)) + g_main_context_iteration(NULL, false); + if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view) + view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); + } } } }