Browse Source

Can now add/remove breakpoints when debug process is in stop state

merge-requests/365/head
eidheim 10 years ago
parent
commit
4d64edde46
  1. 53
      src/debug.cc
  2. 6
      src/debug.h
  3. 16
      src/window.cc

53
src/debug.cc

@ -12,6 +12,7 @@
#include <lldb/API/SBDeclaration.h>
#include <lldb/API/SBCommandInterpreter.h>
#include <lldb/API/SBCommandReturnObject.h>
#include <lldb/API/SBBreakpointLocation.h>
using namespace std; //TODO: remove
@ -223,6 +224,22 @@ std::string Debug::get_value(const std::string &variable, const boost::filesyste
return variable_value;
}
bool Debug::is_invalid() {
bool invalid;
event_mutex.lock();
invalid=state==lldb::StateType::eStateInvalid;
event_mutex.unlock();
return invalid;
}
bool Debug::is_stopped() {
bool stopped;
event_mutex.lock();
stopped=state==lldb::StateType::eStateStopped;
event_mutex.unlock();
return stopped;
}
bool Debug::is_running() {
bool running;
event_mutex.lock();
@ -231,6 +248,42 @@ bool Debug::is_running() {
return running;
}
void Debug::add_breakpoint(const boost::filesystem::path &file_path, int line_nr) {
event_mutex.lock();
if(state==lldb::eStateStopped) {
if(!(process->GetTarget().BreakpointCreateByLocation(file_path.string().c_str(), line_nr)).IsValid())
Terminal::get().async_print("Error (debug): Could not create breakpoint at: "+file_path.string()+":"+std::to_string(line_nr)+'\n', true);
}
event_mutex.unlock();
}
void Debug::remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) {
event_mutex.lock();
if(state==lldb::eStateStopped) {
auto target=process->GetTarget();
for(int line_nr_try=line_nr;line_nr_try<line_count;line_nr_try++) {
for(uint32_t b_index=0;b_index<target.GetNumBreakpoints();b_index++) {
auto breakpoint=target.GetBreakpointAtIndex(b_index);
for(uint32_t l_index=0;l_index<breakpoint.GetNumLocations();l_index++) {
auto line_entry=breakpoint.GetLocationAtIndex(l_index).GetAddress().GetLineEntry();
if(line_entry.GetLine()==line_nr_try) {
auto file_spec=line_entry.GetFileSpec();
boost::filesystem::path breakpoint_path=file_spec.GetDirectory();
breakpoint_path/=file_spec.GetFilename();
if(breakpoint_path==file_path) {
if(!target.BreakpointDelete(breakpoint.GetID()))
Terminal::get().async_print("Error (debug): Could not delete breakpoint at: "+file_path.string()+":"+std::to_string(line_nr)+'\n', true);
event_mutex.unlock();
return;
}
}
}
}
}
}
event_mutex.unlock();
}
void Debug::write(const std::string &buffer) {
event_mutex.lock();
if(state==lldb::StateType::eStateRunning) {

6
src/debug.h

@ -32,7 +32,13 @@ public:
std::string get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr);
bool is_invalid();
bool is_stopped();
bool is_running();
void add_breakpoint(const boost::filesystem::path &file_path, int line_nr);
void remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count);
void write(const std::string &buffer);
private:

16
src/window.cc

@ -771,18 +771,26 @@ void Window::set_menu_actions() {
entry_box.show();
});
menu.add_action("debug_toggle_breakpoint", [this](){
bool debug_is_stopped=Debug::get().is_stopped();
if(Debug::get().is_invalid() || debug_is_stopped) {
if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view();
auto line_nr=view->get_buffer()->get_insert()->get_iter().get_line()+1;
auto line_nr=view->get_buffer()->get_insert()->get_iter().get_line();
if(view->get_source_buffer()->get_source_marks_at_line(line_nr-1, "debug_breakpoint").size()>0) {
auto start_iter=view->get_buffer()->get_iter_at_line(line_nr-1);
if(view->get_source_buffer()->get_source_marks_at_line(line_nr, "debug_breakpoint").size()>0) {
auto start_iter=view->get_buffer()->get_iter_at_line(line_nr);
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_breakpoint");
if(debug_is_stopped)
Debug::get().remove_breakpoint(view->file_path, line_nr+1, view->get_buffer()->get_line_count()+1);
}
else
else {
view->get_source_buffer()->create_source_mark("debug_breakpoint", view->get_buffer()->get_insert()->get_iter());
if(debug_is_stopped)
Debug::get().add_breakpoint(view->file_path, line_nr+1);
}
}
}
});
menu.add_action("debug_goto_stop", [this](){

Loading…
Cancel
Save