Browse Source

Thread safe debug implementation, and can now go to debug stop

merge-requests/365/head
eidheim 10 years ago
parent
commit
0843bff569
  1. 2
      src/debug.cc
  2. 1
      src/files.h
  3. 7
      src/menu.cc
  4. 84
      src/window.cc
  5. 10
      src/window.h

2
src/debug.cc

@ -56,7 +56,7 @@ void Debug::start(std::shared_ptr<std::vector<std::pair<boost::filesystem::path,
lldb::SBEvent event; lldb::SBEvent event;
while(true) { while(true) {
event_mutex.lock(); event_mutex.lock();
if(listener.WaitForEvent(1, event)) { if(listener.GetNextEvent(event)) {
if((event.GetType() & lldb::SBProcess::eBroadcastBitStateChanged)>0) { if((event.GetType() & lldb::SBProcess::eBroadcastBitStateChanged)>0) {
auto state=process->GetStateFromEvent(event); auto state=process->GetStateFromEvent(event);
this->state=state; this->state=state;

1
src/files.h

@ -101,6 +101,7 @@ const std::string configjson =
" \"debug_start_continue\": \"<primary>y\",\n" " \"debug_start_continue\": \"<primary>y\",\n"
" \"debug_stop\": \"<primary><shift>y\",\n" " \"debug_stop\": \"<primary><shift>y\",\n"
" \"debug_kill\": \"<primary><shift>k\",\n" " \"debug_kill\": \"<primary><shift>k\",\n"
" \"debug_goto_stop\": \"<primary><shift>l\",\n"
" \"debug_run_command\": \"<alt><shift>Return\",\n" " \"debug_run_command\": \"<alt><shift>Return\",\n"
" \"debug_toggle_breakpoint\": \"<primary>b\",\n" " \"debug_toggle_breakpoint\": \"<primary>b\",\n"
#ifdef __linux #ifdef __linux

7
src/menu.cc

@ -301,6 +301,13 @@ Menu::Menu() {
+accels["debug_toggle_breakpoint"]+ //For Ubuntu... +accels["debug_toggle_breakpoint"]+ //For Ubuntu...
" </item>" " </item>"
" </section>" " </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Go _to _Stop</attribute>"
" <attribute name='action'>app.debug_goto_stop</attribute>"
+accels["debug_goto_stop"]+ //For Ubuntu...
" </item>"
" </section>"
" </submenu>" " </submenu>"
"" ""
" <submenu>" " <submenu>"

84
src/window.cc

@ -47,7 +47,7 @@ Window::Window() : compiling(false), debugging(false) {
terminal_vbox.pack_start(terminal_scrolled_window); terminal_vbox.pack_start(terminal_scrolled_window);
info_and_status_hbox.pack_start(notebook.info, Gtk::PACK_SHRINK); info_and_status_hbox.pack_start(notebook.info, Gtk::PACK_SHRINK);
info_and_status_hbox.set_center_widget(debug_status); info_and_status_hbox.set_center_widget(debug_status_label);
info_and_status_hbox.pack_end(notebook.status, Gtk::PACK_SHRINK); info_and_status_hbox.pack_end(notebook.status, Gtk::PACK_SHRINK);
terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK); terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK);
vpaned.pack2(terminal_vbox, true, true); vpaned.pack2(terminal_vbox, true, true);
@ -114,6 +114,37 @@ Window::Window() : compiling(false), debugging(false) {
about.hide(); about.hide();
}); });
debug_update_stop_line.connect([this](){
debug_stop_line_mutex.lock();
for(int c=0;c<notebook.size();c++) {
auto view=notebook.get_view(c);
if(view->file_path==debug_last_stop_line.first) {
auto start_iter=view->get_buffer()->get_iter_at_line(debug_last_stop_line.second-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, "debug_stop");
break;
}
}
//Add debug stop source mark
for(int c=0;c<notebook.size();c++) {
auto view=notebook.get_view(c);
if(view->file_path==debug_stop_line.first) {
view->get_source_buffer()->create_source_mark("debug_stop", view->get_buffer()->get_iter_at_line(debug_stop_line.second-1));
debug_last_stop_line=debug_stop_line;
}
}
debug_stop_line_mutex.unlock();
});
debug_update_status.connect([this](){
debug_status_mutex.lock();
if(debug_status.empty())
debug_status_label.set_text("");
else
debug_status_label.set_text("debug: "+debug_status);
debug_status_mutex.unlock();
});
about.set_version(Config::get().window.version); about.set_version(Config::get().window.version);
about.set_authors({"(in order of appearance)", about.set_authors({"(in order of appearance)",
"Ted Johan Kristoffersen", "Ted Johan Kristoffersen",
@ -682,32 +713,17 @@ void Window::set_menu_actions() {
debugging=false; debugging=false;
Terminal::get().async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n'); Terminal::get().async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n');
}, [this](const std::string &status) { }, [this](const std::string &status) {
//TODO: move to main thread debug_status_mutex.lock();
if(status.empty()) debug_status=status;
debug_status.set_text(""); debug_status_mutex.unlock();
else debug_update_status();
debug_status.set_text("debug: "+status);
}, [this](const boost::filesystem::path &file_path, int line_nr) { }, [this](const boost::filesystem::path &file_path, int line_nr) {
//TODO: move to main thread debug_stop_line_mutex.lock();
debug_stop_line.first=file_path;
debug_stop_line.second=line_nr;
debug_stop_line_mutex.unlock();
debug_update_stop_line();
//Remove debug stop source mark //Remove debug stop source mark
for(int c=0;c<notebook.size();c++) {
auto view=notebook.get_view(c);
if(view->file_path==debug_last_stop_line.first) {
auto start_iter=view->get_buffer()->get_iter_at_line(debug_last_stop_line.second-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, "debug_stop");
break;
}
}
//Add debug stop source mark
for(int c=0;c<notebook.size();c++) {
auto view=notebook.get_view(c);
if(view->file_path==file_path) {
view->get_source_buffer()->create_source_mark("debug_stop", view->get_buffer()->get_iter_at_line(line_nr-1));
debug_last_stop_line={file_path, line_nr};
}
}
}); });
} }
}); });
@ -763,6 +779,24 @@ void Window::set_menu_actions() {
view->get_source_buffer()->create_source_mark("debug_breakpoint", view->get_buffer()->get_insert()->get_iter()); view->get_source_buffer()->create_source_mark("debug_breakpoint", view->get_buffer()->get_insert()->get_iter());
} }
}); });
menu.add_action("debug_goto_stop", [this](){
if(debugging) {
debug_stop_line_mutex.lock();
auto debug_stop_line_copy=debug_stop_line;
debug_stop_line_mutex.unlock();
notebook.open(debug_stop_line_copy.first);
if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view();
debug_update_stop_line();
while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false);
if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view) {
view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line(debug_stop_line_copy.second-1));
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
}
}
}
});
menu.add_action("next_tab", [this]() { menu.add_action("next_tab", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {

10
src/window.h

@ -33,10 +33,18 @@ private:
EntryBox entry_box; EntryBox entry_box;
std::atomic<bool> compiling; std::atomic<bool> compiling;
std::atomic<bool> debugging; std::atomic<bool> debugging;
Gtk::Label debug_status; Gtk::Label debug_status_label;
std::pair<boost::filesystem::path, int> debug_last_stop_line; std::pair<boost::filesystem::path, int> debug_last_stop_line;
std::pair<boost::filesystem::path, int> debug_stop_line;
std::mutex debug_stop_line_mutex;
Glib::Dispatcher debug_update_stop_line;
std::string debug_status;
std::mutex debug_status_mutex;
Glib::Dispatcher debug_update_status;
void configure(); void configure();
void set_menu_actions(); void set_menu_actions();
void activate_menu_items(bool activate=true); void activate_menu_items(bool activate=true);

Loading…
Cancel
Save