Browse Source

Debugging fixes

merge-requests/365/head
eidheim 10 years ago
parent
commit
b30f2da8a4
  1. 8
      src/debug.cc
  2. 4
      src/debug.h
  3. 13
      src/notebook.cc
  4. 42
      src/window.cc

8
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<std::vector<std::pair<boost::filesystem::path, int> > > breakpoints, const boost::filesystem::path &executable,
const boost::filesystem::path &path, std::function<void(int exit_status)> 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;
}

4
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<void(int exit_status)> callback=nullptr);
void start(std::shared_ptr<std::vector<std::pair<boost::filesystem::path, int> > > breakpoints, const boost::filesystem::path &executable, const boost::filesystem::path &path="", std::function<void(int exit_status)> 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<std::string, std::vector<std::pair<std::string, int> > > breakpoints;
private:
lldb::SBDebugger debugger;
std::unique_ptr<lldb::SBProcess> process;

13
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::ClangView*>(source_view))
source_clang_view->async_delete();
else

42
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<std::vector<std::pair<boost::filesystem::path, int> > >();
for(int c=0;c<notebook.size();c++) {
auto view=notebook.get_view(c);
if(project_path==view->project_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;c<notebook.size();c++) {
auto view=notebook.get_view(c);
if(project_path==view->project_path) {
for(int line_nr=0;line_nr<view->get_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);
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");
return;
}
}
}
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());
}
});

Loading…
Cancel
Save