Browse Source

Debugging fixes

merge-requests/365/head
eidheim 10 years ago
parent
commit
924ccfc30d
  1. 27
      src/debug.cc
  2. 2
      src/files.h
  3. 40
      src/window.cc

27
src/debug.cc

@ -19,16 +19,16 @@ void log(const char *msg, void *) {
cout << "debugger log: " << msg << endl; cout << "debugger log: " << msg << endl;
} }
Debug::Debug(): listener("juCi++ lldb listener"), state(lldb::StateType::eStateInvalid), buffer_size(131072) { Debug::Debug(): listener("juCi++ lldb listener"), state(lldb::StateType::eStateInvalid), buffer_size(131072) {}
lldb::SBDebugger::Initialize();
debugger=lldb::SBDebugger::Create(true, log, nullptr);
}
void Debug::start(std::shared_ptr<std::vector<std::pair<boost::filesystem::path, int> > > breakpoints, 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, const boost::filesystem::path &path, std::function<void(int exit_status)> callback,
std::function<void(const std::string &status)> status_callback, std::function<void(const std::string &status)> status_callback,
std::function<void(const boost::filesystem::path &file_path, int line_nr, int line_index)> stop_callback) { std::function<void(const boost::filesystem::path &file_path, int line_nr, int line_index)> stop_callback) {
if(!debugger.IsValid()) {
lldb::SBDebugger::Initialize();
debugger=lldb::SBDebugger::Create(true, log, nullptr);
}
auto target=debugger.CreateTarget(executable.string().c_str()); auto target=debugger.CreateTarget(executable.string().c_str());
if(!target.IsValid()) { if(!target.IsValid()) {
@ -49,10 +49,9 @@ void Debug::start(std::shared_ptr<std::vector<std::pair<boost::filesystem::path,
Terminal::get().async_print(std::string("Error (debug): ")+error.GetCString()+'\n', true); Terminal::get().async_print(std::string("Error (debug): ")+error.GetCString()+'\n', true);
return; return;
} }
if(debug_thread.joinable()) if(debug_thread.joinable())
debug_thread.join(); debug_thread.join();
debug_thread=std::thread([this, breakpoints, executable, path, callback, status_callback, stop_callback]() { debug_thread=std::thread([this, callback, status_callback, stop_callback]() {
lldb::SBEvent event; lldb::SBEvent event;
while(true) { while(true) {
event_mutex.lock(); event_mutex.lock();
@ -73,9 +72,16 @@ void Debug::start(std::shared_ptr<std::vector<std::pair<boost::filesystem::path,
if(state==lldb::StateType::eStateStopped) { if(state==lldb::StateType::eStateStopped) {
auto line_entry=process->GetSelectedThread().GetSelectedFrame().GetLineEntry(); auto line_entry=process->GetSelectedThread().GetSelectedFrame().GetLineEntry();
if(stop_callback) { if(stop_callback) {
lldb::SBStream stream; if(line_entry.IsValid()) {
line_entry.GetFileSpec().GetDescription(stream); lldb::SBStream stream;
stop_callback(stream.GetData(), line_entry.GetLine(), line_entry.GetColumn()); 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(); kill();
if(debug_thread.joinable()) if(debug_thread.joinable())
debug_thread.join(); 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) { std::string Debug::get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr) {

2
src/files.h

@ -2,7 +2,7 @@
#define JUCI_FILES_H_ #define JUCI_FILES_H_
#include <string> #include <string>
#define JUCI_VERSION "1.0.2" #define JUCI_VERSION "1.1.0"
const std::string configjson = const std::string configjson =
"{\n" "{\n"

40
src/window.cc

@ -790,25 +790,27 @@ void Window::set_menu_actions() {
debug_stop_mutex.lock(); debug_stop_mutex.lock();
auto debug_stop_copy=debug_stop; auto debug_stop_copy=debug_stop;
debug_stop_mutex.unlock(); debug_stop_mutex.unlock();
notebook.open(debug_stop_copy.first); if(!debug_stop_copy.first.empty()) {
if(notebook.get_current_page()!=-1) { notebook.open(debug_stop_copy.first);
auto view=notebook.get_current_view(); if(notebook.get_current_page()!=-1) {
debug_update_stop(); 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; int line_nr=debug_stop_copy.second.first-1;
if(line_nr<view->get_buffer()->get_line_count()) { int line_index=debug_stop_copy.second.second-1;
auto iter=view->get_buffer()->get_iter_at_line(line_nr); if(line_nr<view->get_buffer()->get_line_count()) {
auto end_line_iter=iter; auto iter=view->get_buffer()->get_iter_at_line(line_nr);
while(!iter.ends_line() && iter.forward_char()) {} auto end_line_iter=iter;
auto line=view->get_buffer()->get_text(iter, end_line_iter); while(!iter.ends_line() && iter.forward_char()) {}
if(line_index<line.bytes()) { auto line=view->get_buffer()->get_text(iter, end_line_iter);
view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(line_nr, line_index)); if(line_index<line.bytes()) {
view->get_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); while(g_main_context_pending(NULL))
if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view) g_main_context_iteration(NULL, false);
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); 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);
}
} }
} }
} }

Loading…
Cancel
Save