From 3244ec68f72182c7f9b8c095230034eb0191aa11 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 28 Dec 2015 18:40:52 +0100 Subject: [PATCH] Debug variables now in tooltips, still some work left before creating the debug integration branch though --- src/debug.cc | 56 ++++++++++++++++++++++++++++++++++++++------- src/debug.h | 3 +++ src/files.h | 1 + src/menu.cc | 5 ++++ src/source_clang.cc | 9 ++++++++ src/window.cc | 23 +++++++++++-------- src/window.h | 1 + 7 files changed, 81 insertions(+), 17 deletions(-) diff --git a/src/debug.cc b/src/debug.cc index df21394..e79ca82 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -9,6 +9,7 @@ #include "lldb/API/SBBreakpoint.h" #include "lldb/API/SBThread.h" #include "lldb/API/SBStream.h" +#include "lldb/API/SBDeclaration.h" #include //TODO: remove using namespace std; @@ -57,19 +58,28 @@ void Debug::start(const boost::filesystem::path &project_path, const boost::file auto state=process->GetStateFromEvent(event); bool expected=false; if(state==lldb::StateType::eStateStopped && stopped.compare_exchange_strong(expected, true)) { - cout << "NumThreads: " << process->GetNumThreads() << endl; - for(uint32_t thread_index_id=0;thread_index_idGetNumThreads();thread_index_id++) { - auto thread=process->GetThreadAtIndex(thread_index_id); - cout << "NumFrames: " << thread.GetNumFrames() << endl; + for(uint32_t thread_index=0;thread_indexGetNumThreads();thread_index++) { + auto thread=process->GetThreadAtIndex(thread_index); for(uint32_t frame_index=0;frame_indexKill(); + if(error.Fail()) { + cerr << "Error (debug): " << error.GetCString() << endl; //TODO: output to terminal instead + return; + } +} + void Debug::continue_debug() { bool expected=true; if(stopped.compare_exchange_strong(expected, false)) process->Continue(); } + +std::string Debug::get_value(const std::string &variable) { + if(stopped) { + for(uint32_t thread_index=0;thread_indexGetNumThreads();thread_index++) { + auto thread=process->GetThreadAtIndex(thread_index); + for(uint32_t frame_index=0;frame_index 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 > > breakpoints; private: diff --git a/src/files.h b/src/files.h index 91f2239..ef12530 100644 --- a/src/files.h +++ b/src/files.h @@ -99,6 +99,7 @@ const std::string configjson = " \"kill_last_running\": \"Escape\",\n" " \"force_kill_last_running\": \"Escape\",\n" " \"debug_start\": \"y\",\n" +" \"debug_stop\": \"\",\n" " \"debug_continue\": \"y\",\n" " \"debug_toggle_breakpoint\": \"b\",\n" #ifdef __linux diff --git a/src/menu.cc b/src/menu.cc index a3e8c32..21e19ac 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -276,6 +276,11 @@ Menu::Menu() { " app.debug_start" +accels["debug_start"]+ //For Ubuntu... " " + " " + " _Stop" + " app.debug_stop" + +accels["debug_stop"]+ //For Ubuntu... + " " " " "
" " " diff --git a/src/source_clang.cc b/src/source_clang.cc index 8180d53..68dd90d 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -2,6 +2,7 @@ #include "config.h" #include "terminal.h" #include "cmake.h" +#include "debug.h" namespace sigc { #ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE @@ -412,6 +413,14 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle) auto brief_comment=token.get_cursor().get_brief_comments(); if(brief_comment!="") tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "\n\n"+brief_comment, "def:note"); + auto debug_value=Debug::get().get_value(token.get_spelling()); + if(!debug_value.empty()) { + debug_value.pop_back(); + size_t pos=debug_value.find(" = "); + if(pos!=std::string::npos) + tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "\n\nDebug: "+debug_value.substr(pos+3), "def:note"); + } + return tooltip_buffer; }; diff --git a/src/window.cc b/src/window.cc index fa7f955..9f3dfd8 100644 --- a/src/window.cc +++ b/src/window.cc @@ -22,7 +22,7 @@ namespace sigc { #endif } -Window::Window() : compiling(false) { +Window::Window() : compiling(false), debugging(false) { JDEBUG("start"); set_title("juCi++"); set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK|Gdk::LEAVE_NOTIFY_MASK); @@ -617,7 +617,7 @@ void Window::set_menu_actions() { }); menu.add_action("debug_start", [this](){ - if(compiling) + if(debugging) return; boost::filesystem::path cmake_path; if(notebook.get_current_page()!=-1) @@ -638,7 +638,7 @@ void Window::set_menu_actions() { return; if(!CMake::create_debug_build(project_path)) return; - compiling=true; + debugging=true; auto executable_path_string=executable_path.string(); size_t pos=executable_path_string.find(project_path.string()); if(pos!=std::string::npos) { @@ -647,7 +647,6 @@ void Window::set_menu_actions() { } 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){ - compiling=false; if(exit_status==EXIT_SUCCESS) { auto executable_path_spaces_fixed=executable_path.string(); char last_char=0; @@ -659,6 +658,7 @@ 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){ + debugging=false; Terminal::get().async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n'); }); } @@ -670,6 +670,16 @@ void Window::set_menu_actions() { Terminal::get().print(" "+path.string()+"\n"); } }); + menu.add_action("debug_stop", [this]() { + if(debugging) { + Debug::get().stop(); + } + }); + menu.add_action("debug_continue", [this]() { + if(notebook.get_current_page()!=-1 && debugging) { + Debug::get().continue_debug(); + } + }); menu.add_action("debug_toggle_breakpoint", [this](){ if(notebook.get_current_page()!=-1) { auto view=notebook.get_current_view(); @@ -695,11 +705,6 @@ void Window::set_menu_actions() { auto mark=view->get_source_buffer()->create_source_mark("breakpoint", view->get_buffer()->get_insert()->get_iter()); } }); - menu.add_action("debug_continue", [this]() { - if(notebook.get_current_page()!=-1) { - Debug::get().continue_debug(); - } - }); menu.add_action("next_tab", [this]() { if(notebook.get_current_page()!=-1) { diff --git a/src/window.h b/src/window.h index 2587348..45a592d 100644 --- a/src/window.h +++ b/src/window.h @@ -32,6 +32,7 @@ private: Gtk::AboutDialog about; EntryBox entry_box; std::atomic compiling; + std::atomic debugging; void configure(); void set_menu_actions();