From b30f2da8a4fade44ddb60f099663097244e32c88 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 28 Dec 2015 21:38:01 +0100 Subject: [PATCH] Debugging fixes --- src/debug.cc | 8 ++++---- src/debug.h | 4 +--- src/notebook.cc | 13 ------------- src/window.cc | 50 ++++++++++++++++++++++++++++++------------------- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/debug.cc b/src/debug.cc index e79ca82..ca4db81 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -24,9 +24,9 @@ Debug::Debug(): stopped(false) { debugger=lldb::SBDebugger::Create(true, log, nullptr); } -void Debug::start(const boost::filesystem::path &project_path, const boost::filesystem::path &executable, +void Debug::start(std::shared_ptr > > breakpoints, const boost::filesystem::path &executable, const boost::filesystem::path &path, std::function callback) { - std::thread debug_thread([this, project_path, executable, path, callback]() { + std::thread debug_thread([this, breakpoints, executable, path, callback]() { auto target=debugger.CreateTarget(executable.string().c_str()); auto listener=lldb::SBListener("juCi++ lldb listener"); @@ -35,8 +35,8 @@ void Debug::start(const boost::filesystem::path &project_path, const boost::file return; } - for(auto &breakpoint: breakpoints[project_path.string()]) { - if(!(target.BreakpointCreateByLocation(breakpoint.first.c_str(), breakpoint.second)).IsValid()) { + for(auto &breakpoint: *breakpoints) { + if(!(target.BreakpointCreateByLocation(breakpoint.first.string().c_str(), breakpoint.second)).IsValid()) { cerr << "Error: Could not create breakpoint at: " << breakpoint.first << ":" << breakpoint.second << endl; //TODO: output to terminal instead return; } diff --git a/src/debug.h b/src/debug.h index 971338a..7b4356c 100644 --- a/src/debug.h +++ b/src/debug.h @@ -15,14 +15,12 @@ public: return singleton; } - void start(const boost::filesystem::path &project_path, const boost::filesystem::path &executable, const boost::filesystem::path &path="", std::function callback=nullptr); + void start(std::shared_ptr > > breakpoints, const boost::filesystem::path &executable, const boost::filesystem::path &path="", std::function callback=nullptr); void stop(); void continue_debug(); //can't use continue as function name std::string get_value(const std::string &variable); - std::unordered_map > > breakpoints; - private: lldb::SBDebugger debugger; std::unique_ptr process; diff --git a/src/notebook.cc b/src/notebook.cc index 88ee923..744459b 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -310,19 +310,6 @@ bool Notebook::close(int page) { #endif auto source_view=source_views.at(index); - - //Remove breakpoints - auto it=Debug::get().breakpoints.find(source_view->project_path.string()); - if(it!=Debug::get().breakpoints.end()) { - auto filename=source_view->file_path.filename().string(); - for(auto it_bp=it->second.begin();it_bp!=it->second.end();) { - if(it_bp->first==filename) - it_bp=it->second.erase(it_bp); - else - it_bp++; - } - } - if(auto source_clang_view=dynamic_cast(source_view)) source_clang_view->async_delete(); else diff --git a/src/window.cc b/src/window.cc index 9f3dfd8..c4ac90d 100644 --- a/src/window.cc +++ b/src/window.cc @@ -645,8 +645,29 @@ void Window::set_menu_actions() { executable_path_string.replace(pos, project_path.string().size(), debug_build_path.string()); executable_path=executable_path_string; } + + auto breakpoints=std::make_shared > >(); + for(int c=0;cproject_path) { + auto iter=view->get_buffer()->begin(); + if(view->get_source_buffer()->get_source_marks_at_iter(iter, "breakpoint").size()>0) + breakpoints->emplace_back(view->file_path.filename(), iter.get_line()+1); + while(view->get_source_buffer()->forward_iter_to_source_mark(iter, "breakpoint")) + breakpoints->emplace_back(view->file_path.filename(), iter.get_line()+1); + } + } + /*for(int c=0;cproject_path) { + for(int line_nr=0;line_nrget_buffer()->get_line_count();line_nr++) { + //if(view->get_source_buffer()->get_source_marks_at_line(line_nr, "breakpoint").size()>0) + // breakpoints->emplace_back(view->file_path.filename(), line_nr+1); + } + } + }*/ Terminal::get().print("Compiling and running "+executable_path.string()+"\n"); - Terminal::get().async_process(Config::get().terminal.make_command, debug_build_path, [this, project_path, executable_path, debug_build_path](int exit_status){ + Terminal::get().async_process(Config::get().terminal.make_command, debug_build_path, [this, breakpoints, executable_path, debug_build_path](int exit_status){ if(exit_status==EXIT_SUCCESS) { auto executable_path_spaces_fixed=executable_path.string(); char last_char=0; @@ -657,7 +678,8 @@ void Window::set_menu_actions() { } last_char=executable_path_spaces_fixed[c]; } - Debug::get().start(project_path, executable_path_spaces_fixed, debug_build_path, [this, executable_path](int exit_status){ + + Debug::get().start(breakpoints, executable_path_spaces_fixed, debug_build_path, [this, executable_path](int exit_status){ debugging=false; Terminal::get().async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n'); }); @@ -683,26 +705,16 @@ void Window::set_menu_actions() { menu.add_action("debug_toggle_breakpoint", [this](){ if(notebook.get_current_page()!=-1) { auto view=notebook.get_current_view(); - auto &project_path_string=view->project_path.string(); - auto filename=view->file_path.filename().string(); auto line_nr=view->get_buffer()->get_insert()->get_iter().get_line()+1; - auto it=Debug::get().breakpoints.find(project_path_string); - if(it!=Debug::get().breakpoints.end()) { - for(auto it_bp=it->second.begin();it_bp!=it->second.end();it_bp++) { - if(it_bp->first==filename && it_bp->second==line_nr) { - //Remove breakpoint - it->second.erase(it_bp); - auto start_iter=view->get_buffer()->get_iter_at_line(line_nr-1); - auto end_iter=start_iter; - while(!end_iter.ends_line() && end_iter.forward_char()) {} - view->get_source_buffer()->remove_source_marks(start_iter, end_iter, "breakpoint"); - return; - } - } + if(view->get_source_buffer()->get_source_marks_at_line(line_nr-1, "breakpoint").size()>0) { + auto start_iter=view->get_buffer()->get_iter_at_line(line_nr-1); + auto end_iter=start_iter; + while(!end_iter.ends_line() && end_iter.forward_char()) {} + view->get_source_buffer()->remove_source_marks(start_iter, end_iter, "breakpoint"); } - Debug::get().breakpoints[project_path_string].emplace_back(filename, line_nr); - auto mark=view->get_source_buffer()->create_source_mark("breakpoint", view->get_buffer()->get_insert()->get_iter()); + else + view->get_source_buffer()->create_source_mark("breakpoint", view->get_buffer()->get_insert()->get_iter()); } });