diff --git a/src/debug_clang.cc b/src/debug_clang.cc index 565eddf..54f0d45 100644 --- a/src/debug_clang.cc +++ b/src/debug_clang.cc @@ -27,7 +27,7 @@ void log(const char *msg, void *) { std::cout << "debugger log: " << msg << std::endl; } -DebugClang::DebugClang(): state(lldb::StateType::eStateInvalid), buffer_size(131072) { +Debug::Clang::Clang(): state(lldb::StateType::eStateInvalid), buffer_size(131072) { #ifdef __APPLE__ auto debugserver_path=boost::filesystem::path("/usr/local/opt/llvm/bin/debugserver"); if(boost::filesystem::exists(debugserver_path)) @@ -35,7 +35,7 @@ DebugClang::DebugClang(): state(lldb::StateType::eStateInvalid), buffer_size(131 #endif } -void DebugClang::start(const std::string &command, const boost::filesystem::path &path, +void Debug::Clang::start(const std::string &command, const boost::filesystem::path &path, const std::vector > &breakpoints, std::function callback, std::function status_callback, @@ -214,14 +214,14 @@ void DebugClang::start(const std::string &command, const boost::filesystem::path }); } -void DebugClang::continue_debug() { +void Debug::Clang::continue_debug() { event_mutex.lock(); if(state==lldb::StateType::eStateStopped) process->Continue(); event_mutex.unlock(); } -void DebugClang::stop() { +void Debug::Clang::stop() { event_mutex.lock(); if(state==lldb::StateType::eStateRunning) { auto error=process->Stop(); @@ -231,7 +231,7 @@ void DebugClang::stop() { event_mutex.unlock(); } -void DebugClang::kill() { +void Debug::Clang::kill() { event_mutex.lock(); if(process) { auto error=process->Kill(); @@ -241,7 +241,7 @@ void DebugClang::kill() { event_mutex.unlock(); } -void DebugClang::step_over() { +void Debug::Clang::step_over() { event_mutex.lock(); if(state==lldb::StateType::eStateStopped) { process->GetSelectedThread().StepOver(); @@ -249,7 +249,7 @@ void DebugClang::step_over() { event_mutex.unlock(); } -void DebugClang::step_into() { +void Debug::Clang::step_into() { event_mutex.lock(); if(state==lldb::StateType::eStateStopped) { process->GetSelectedThread().StepInto(); @@ -257,7 +257,7 @@ void DebugClang::step_into() { event_mutex.unlock(); } -void DebugClang::step_out() { +void Debug::Clang::step_out() { event_mutex.lock(); if(state==lldb::StateType::eStateStopped) { process->GetSelectedThread().StepOut(); @@ -265,7 +265,7 @@ void DebugClang::step_out() { event_mutex.unlock(); } -std::pair DebugClang::run_command(const std::string &command) { +std::pair Debug::Clang::run_command(const std::string &command) { std::pair command_return; event_mutex.lock(); if(state==lldb::StateType::eStateStopped || state==lldb::StateType::eStateRunning) { @@ -278,7 +278,7 @@ std::pair DebugClang::run_command(const std::string &c return command_return; } -std::vector DebugClang::get_backtrace() { +std::vector Debug::Clang::get_backtrace() { std::vector backtrace; event_mutex.lock(); if(state==lldb::StateType::eStateStopped) { @@ -315,8 +315,8 @@ std::vector DebugClang::get_backtrace() { return backtrace; } -std::vector DebugClang::get_variables() { - std::vector variables; +std::vector Debug::Clang::get_variables() { + std::vector variables; event_mutex.lock(); if(state==lldb::StateType::eStateStopped) { for(uint32_t c_t=0;c_tGetNumThreads();c_t++) { @@ -330,7 +330,7 @@ std::vector DebugClang::get_variables() { auto declaration=value.GetDeclaration(); if(declaration.IsValid()) { - DebugClang::Variable variable; + Debug::Clang::Variable variable; variable.thread_index_id=thread.GetIndexID(); variable.frame_index=c_f; @@ -359,7 +359,7 @@ std::vector DebugClang::get_variables() { return variables; } -void DebugClang::select_frame(uint32_t frame_index, uint32_t thread_index_id) { +void Debug::Clang::select_frame(uint32_t frame_index, uint32_t thread_index_id) { event_mutex.lock(); if(state==lldb::StateType::eStateStopped) { if(thread_index_id!=0) @@ -369,13 +369,13 @@ void DebugClang::select_frame(uint32_t frame_index, uint32_t thread_index_id) { event_mutex.unlock(); } -void DebugClang::delete_debug() { +void Debug::Clang::delete_debug() { kill(); if(debug_thread.joinable()) debug_thread.join(); } -std::string DebugClang::get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) { +std::string Debug::Clang::get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) { std::string variable_value; event_mutex.lock(); if(state==lldb::StateType::eStateStopped) { @@ -417,7 +417,7 @@ std::string DebugClang::get_value(const std::string &variable, const boost::file return variable_value; } -std::string DebugClang::get_return_value(const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) { +std::string Debug::Clang::get_return_value(const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index) { std::string return_value; event_mutex.lock(); if(state==lldb::StateType::eStateStopped) { @@ -441,7 +441,7 @@ std::string DebugClang::get_return_value(const boost::filesystem::path &file_pat return return_value; } -bool DebugClang::is_invalid() { +bool Debug::Clang::is_invalid() { bool invalid; event_mutex.lock(); invalid=state==lldb::StateType::eStateInvalid; @@ -449,7 +449,7 @@ bool DebugClang::is_invalid() { return invalid; } -bool DebugClang::is_stopped() { +bool Debug::Clang::is_stopped() { bool stopped; event_mutex.lock(); stopped=state==lldb::StateType::eStateStopped; @@ -457,7 +457,7 @@ bool DebugClang::is_stopped() { return stopped; } -bool DebugClang::is_running() { +bool Debug::Clang::is_running() { bool running; event_mutex.lock(); running=state==lldb::StateType::eStateRunning; @@ -465,7 +465,7 @@ bool DebugClang::is_running() { return running; } -void DebugClang::add_breakpoint(const boost::filesystem::path &file_path, int line_nr) { +void Debug::Clang::add_breakpoint(const boost::filesystem::path &file_path, int line_nr) { event_mutex.lock(); if(state==lldb::eStateStopped || state==lldb::eStateRunning) { if(!(process->GetTarget().BreakpointCreateByLocation(file_path.string().c_str(), line_nr)).IsValid()) @@ -474,7 +474,7 @@ void DebugClang::add_breakpoint(const boost::filesystem::path &file_path, int li event_mutex.unlock(); } -void DebugClang::remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) { +void Debug::Clang::remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) { event_mutex.lock(); if(state==lldb::eStateStopped || state==lldb::eStateRunning) { auto target=process->GetTarget(); @@ -501,7 +501,7 @@ void DebugClang::remove_breakpoint(const boost::filesystem::path &file_path, int event_mutex.unlock(); } -void DebugClang::write(const std::string &buffer) { +void Debug::Clang::write(const std::string &buffer) { event_mutex.lock(); if(state==lldb::StateType::eStateRunning) { process->PutSTDIN(buffer.c_str(), buffer.size()); diff --git a/src/debug_clang.h b/src/debug_clang.h index 57c1008..0e9001a 100644 --- a/src/debug_clang.h +++ b/src/debug_clang.h @@ -9,75 +9,77 @@ #include #include -class DebugClang { -public: - class Frame { +namespace Debug { + class Clang { public: - uint32_t index; - std::string module_filename; - std::string file_path; - std::string function_name; - int line_nr; - int line_index; - }; - class Variable { + class Frame { + public: + uint32_t index; + std::string module_filename; + std::string file_path; + std::string function_name; + int line_nr; + int line_index; + }; + class Variable { + public: + uint32_t thread_index_id; + uint32_t frame_index; + std::string name; + std::string value; + boost::filesystem::path file_path; + int line_nr; + int line_index; + }; + private: + Clang(); public: - uint32_t thread_index_id; - uint32_t frame_index; - std::string name; - std::string value; - boost::filesystem::path file_path; - int line_nr; - int line_index; - }; -private: - DebugClang(); -public: - static DebugClang &get() { - static DebugClang singleton; - return singleton; - } - - void start(const std::string &command, const boost::filesystem::path &path="", - const std::vector > &breakpoints={}, - std::function callback=nullptr, - std::function status_callback=nullptr, - std::function stop_callback=nullptr); - void continue_debug(); //can't use continue as function name - void stop(); - void kill(); - void step_over(); - void step_into(); - void step_out(); - std::pair run_command(const std::string &command); - std::vector get_backtrace(); - std::vector get_variables(); - void select_frame(uint32_t frame_index, uint32_t thread_index_id=0); - - void delete_debug(); //can't use delete as function name - - std::string get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index); - std::string get_return_value(const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index); - - 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); + static Clang &get() { + static Clang singleton; + return singleton; + } + + void start(const std::string &command, const boost::filesystem::path &path="", + const std::vector > &breakpoints={}, + std::function callback=nullptr, + std::function status_callback=nullptr, + std::function stop_callback=nullptr); + void continue_debug(); //can't use continue as function name + void stop(); + void kill(); + void step_over(); + void step_into(); + void step_out(); + std::pair run_command(const std::string &command); + std::vector get_backtrace(); + std::vector get_variables(); + void select_frame(uint32_t frame_index, uint32_t thread_index_id=0); + + void delete_debug(); //can't use delete as function name + + std::string get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index); + std::string get_return_value(const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index); -private: - std::unique_ptr debugger; - std::unique_ptr listener; - std::unique_ptr process; - std::thread debug_thread; - - lldb::StateType state; - std::mutex event_mutex; - - size_t buffer_size; -}; + 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: + std::unique_ptr debugger; + std::unique_ptr listener; + std::unique_ptr process; + std::thread debug_thread; + + lldb::StateType state; + std::mutex event_mutex; + + size_t buffer_size; + }; +} #endif diff --git a/src/project.cc b/src/project.cc index 8b2a945..fea8312 100644 --- a/src/project.cc +++ b/src/project.cc @@ -273,7 +273,7 @@ void Project::Clang::debug_start() { debugging=false; else { debug_start_mutex.lock(); - DebugClang::get().start(run_arguments, debug_build_path, *breakpoints, [this, run_arguments](int exit_status){ + Debug::Clang::get().start(run_arguments, debug_build_path, *breakpoints, [this, run_arguments](int exit_status){ debugging=false; Terminal::get().async_print(run_arguments+" returned: "+std::to_string(exit_status)+'\n'); }, [this](const std::string &status) { @@ -295,42 +295,42 @@ void Project::Clang::debug_start() { } void Project::Clang::debug_continue() { - DebugClang::get().continue_debug(); + Debug::Clang::get().continue_debug(); } void Project::Clang::debug_stop() { if(debugging) - DebugClang::get().stop(); + Debug::Clang::get().stop(); } void Project::Clang::debug_kill() { if(debugging) - DebugClang::get().kill(); + Debug::Clang::get().kill(); } void Project::Clang::debug_step_over() { if(debugging) - DebugClang::get().step_over(); + Debug::Clang::get().step_over(); } void Project::Clang::debug_step_into() { if(debugging) - DebugClang::get().step_into(); + Debug::Clang::get().step_into(); } void Project::Clang::debug_step_out() { if(debugging) - DebugClang::get().step_out(); + Debug::Clang::get().step_out(); } void Project::Clang::debug_backtrace() { if(debugging && Notebook::get().get_current_page()!=-1) { - auto backtrace=DebugClang::get().get_backtrace(); + auto backtrace=Debug::Clang::get().get_backtrace(); auto view=Notebook::get().get_current_view(); auto iter=view->get_iter_for_dialog(); view->selection_dialog=std::unique_ptr(new SelectionDialog(*view, view->get_buffer()->create_mark(iter), true, true)); - auto rows=std::make_shared >(); + auto rows=std::make_shared >(); if(backtrace.size()==0) return; @@ -358,7 +358,7 @@ void Project::Clang::debug_backtrace() { if(Notebook::get().get_current_page()!=-1) { auto view=Notebook::get().get_current_view(); - DebugClang::get().select_frame(frame.index); + Debug::Clang::get().select_frame(frame.index); view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(frame.line_nr-1, frame.line_index-1)); @@ -375,12 +375,12 @@ void Project::Clang::debug_backtrace() { void Project::Clang::debug_show_variables() { if(debugging && Notebook::get().get_current_page()!=-1) { - auto variables=DebugClang::get().get_variables(); + auto variables=Debug::Clang::get().get_variables(); auto view=Notebook::get().get_current_view(); auto iter=view->get_iter_for_dialog(); view->selection_dialog=std::unique_ptr(new SelectionDialog(*view, view->get_buffer()->create_mark(iter), true, true)); - auto rows=std::make_shared >(); + auto rows=std::make_shared >(); if(variables.size()==0) return; @@ -398,7 +398,7 @@ void Project::Clang::debug_show_variables() { if(Notebook::get().get_current_page()!=-1) { auto view=Notebook::get().get_current_view(); - DebugClang::get().select_frame(variable.frame_index, variable.thread_index_id); + Debug::Clang::get().select_frame(variable.frame_index, variable.thread_index_id); view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(variable.line_nr-1, variable.line_index-1)); @@ -453,31 +453,31 @@ void Project::Clang::debug_show_variables() { void Project::Clang::debug_run_command(const std::string &command) { if(debugging) { - auto command_return=DebugClang::get().run_command(command); + auto command_return=Debug::Clang::get().run_command(command); Terminal::get().async_print(command_return.first); Terminal::get().async_print(command_return.second, true); } } void Project::Clang::debug_add_breakpoint(const boost::filesystem::path &file_path, int line_nr) { - DebugClang::get().add_breakpoint(file_path, line_nr); + Debug::Clang::get().add_breakpoint(file_path, line_nr); } void Project::Clang::debug_remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) { - DebugClang::get().remove_breakpoint(file_path, line_nr, line_count); + Debug::Clang::get().remove_breakpoint(file_path, line_nr, line_count); } bool Project::Clang::debug_is_running() { - return DebugClang::get().is_running(); + return Debug::Clang::get().is_running(); } void Project::Clang::debug_write(const std::string &buffer) { - DebugClang::get().write(buffer); + Debug::Clang::get().write(buffer); } void Project::Clang::debug_delete() { debug_start_mutex.lock(); - DebugClang::get().delete_debug(); + Debug::Clang::get().delete_debug(); debug_start_mutex.unlock(); } #endif diff --git a/src/source_clang.cc b/src/source_clang.cc index 97365b6..3007ef1 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -414,15 +414,15 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle) tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "\n\n"+brief_comment, "def:note"); #ifdef JUCI_ENABLE_DEBUG - if(DebugClang::get().is_stopped()) { + if(Debug::Clang::get().is_stopped()) { auto location=token.get_cursor().get_referenced().get_source_location(); Glib::ustring value_type="Value"; - Glib::ustring debug_value=DebugClang::get().get_value(token.get_spelling(), location.get_path(), location.get_offset().line, location.get_offset().index); + Glib::ustring debug_value=Debug::Clang::get().get_value(token.get_spelling(), location.get_path(), location.get_offset().line, location.get_offset().index); if(debug_value.empty()) { value_type="Return value"; auto cursor=token.get_cursor(); auto offsets=cursor.get_source_range().get_offsets(); - debug_value=DebugClang::get().get_return_value(cursor.get_source_location().get_path(), offsets.first.line, offsets.first.index); + debug_value=Debug::Clang::get().get_return_value(cursor.get_source_location().get_path(), offsets.first.line, offsets.first.index); } if(!debug_value.empty()) { size_t pos=debug_value.find(" = ");