Browse Source

Debug variables now in tooltips, still some work left before creating the debug integration branch though

merge-requests/365/head
eidheim 10 years ago
parent
commit
3244ec68f7
  1. 56
      src/debug.cc
  2. 3
      src/debug.h
  3. 1
      src/files.h
  4. 5
      src/menu.cc
  5. 9
      src/source_clang.cc
  6. 23
      src/window.cc
  7. 1
      src/window.h

56
src/debug.cc

@ -9,6 +9,7 @@
#include "lldb/API/SBBreakpoint.h" #include "lldb/API/SBBreakpoint.h"
#include "lldb/API/SBThread.h" #include "lldb/API/SBThread.h"
#include "lldb/API/SBStream.h" #include "lldb/API/SBStream.h"
#include "lldb/API/SBDeclaration.h"
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; using namespace std;
@ -57,19 +58,28 @@ void Debug::start(const boost::filesystem::path &project_path, const boost::file
auto state=process->GetStateFromEvent(event); auto state=process->GetStateFromEvent(event);
bool expected=false; bool expected=false;
if(state==lldb::StateType::eStateStopped && stopped.compare_exchange_strong(expected, true)) { if(state==lldb::StateType::eStateStopped && stopped.compare_exchange_strong(expected, true)) {
cout << "NumThreads: " << process->GetNumThreads() << endl; for(uint32_t thread_index=0;thread_index<process->GetNumThreads();thread_index++) {
for(uint32_t thread_index_id=0;thread_index_id<process->GetNumThreads();thread_index_id++) { auto thread=process->GetThreadAtIndex(thread_index);
auto thread=process->GetThreadAtIndex(thread_index_id);
cout << "NumFrames: " << thread.GetNumFrames() << endl;
for(uint32_t frame_index=0;frame_index<thread.GetNumFrames();frame_index++) { for(uint32_t frame_index=0;frame_index<thread.GetNumFrames();frame_index++) {
auto frame=thread.GetFrameAtIndex(frame_index); auto frame=thread.GetFrameAtIndex(frame_index);
auto values=frame.GetVariables(true, true, true, true); auto values=frame.GetVariables(false, true, true, false);
cout << "variables.GetSize(): " << values.GetSize() << endl;
for(uint32_t value_index=0;value_index<values.GetSize();value_index++) { for(uint32_t value_index=0;value_index<values.GetSize();value_index++) {
auto value=values.GetValueAtIndex(value_index); cout << thread_index << ", " << frame_index << endl;
lldb::SBStream stream; lldb::SBStream stream;
auto value=values.GetValueAtIndex(value_index);
cout << value.GetFrame().GetSymbol().GetName() << endl;
auto declaration = value.GetDeclaration();
if(declaration.IsValid())
cout << declaration.GetFileSpec().GetFilename() << ":" << declaration.GetLine() << ":" << declaration.GetColumn() << endl;
value.GetDescription(stream); value.GetDescription(stream);
cout << stream.GetData(); cout << " " << stream.GetData() << endl;
stream.Clear();
value.GetData().GetDescription(stream);
cout << " " << stream.GetData() << endl;
} }
} }
} }
@ -98,8 +108,38 @@ void Debug::start(const boost::filesystem::path &project_path, const boost::file
debug_thread.detach(); debug_thread.detach();
} }
void Debug::stop() {
auto error=process->Kill();
if(error.Fail()) {
cerr << "Error (debug): " << error.GetCString() << endl; //TODO: output to terminal instead
return;
}
}
void Debug::continue_debug() { void Debug::continue_debug() {
bool expected=true; bool expected=true;
if(stopped.compare_exchange_strong(expected, false)) if(stopped.compare_exchange_strong(expected, false))
process->Continue(); process->Continue();
} }
std::string Debug::get_value(const std::string &variable) {
if(stopped) {
for(uint32_t thread_index=0;thread_index<process->GetNumThreads();thread_index++) {
auto thread=process->GetThreadAtIndex(thread_index);
for(uint32_t frame_index=0;frame_index<thread.GetNumFrames();frame_index++) {
auto frame=thread.GetFrameAtIndex(frame_index);
auto values=frame.GetVariables(false, true, false, false);
for(uint32_t value_index=0;value_index<values.GetSize();value_index++) {
lldb::SBStream stream;
auto value=values.GetValueAtIndex(value_index);
if(value.GetName()==variable) {
value.GetDescription(stream);
return stream.GetData();
}
}
}
}
}
return std::string();
}

3
src/debug.h

@ -16,8 +16,11 @@ public:
} }
void start(const boost::filesystem::path &project_path, const boost::filesystem::path &executable, const boost::filesystem::path &path="", std::function<void(int exit_status)> callback=nullptr); void start(const boost::filesystem::path &project_path, const boost::filesystem::path &executable, const boost::filesystem::path &path="", std::function<void(int exit_status)> callback=nullptr);
void stop();
void continue_debug(); //can't use continue as function name void continue_debug(); //can't use continue as function name
std::string get_value(const std::string &variable);
std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > breakpoints; std::unordered_map<std::string, std::vector<std::pair<std::string, int> > > breakpoints;
private: private:

1
src/files.h

@ -99,6 +99,7 @@ const std::string configjson =
" \"kill_last_running\": \"<primary>Escape\",\n" " \"kill_last_running\": \"<primary>Escape\",\n"
" \"force_kill_last_running\": \"<primary><shift>Escape\",\n" " \"force_kill_last_running\": \"<primary><shift>Escape\",\n"
" \"debug_start\": \"<primary>y\",\n" " \"debug_start\": \"<primary>y\",\n"
" \"debug_stop\": \"\",\n"
" \"debug_continue\": \"<primary><shift>y\",\n" " \"debug_continue\": \"<primary><shift>y\",\n"
" \"debug_toggle_breakpoint\": \"<primary>b\",\n" " \"debug_toggle_breakpoint\": \"<primary>b\",\n"
#ifdef __linux #ifdef __linux

5
src/menu.cc

@ -276,6 +276,11 @@ Menu::Menu() {
" <attribute name='action'>app.debug_start</attribute>" " <attribute name='action'>app.debug_start</attribute>"
+accels["debug_start"]+ //For Ubuntu... +accels["debug_start"]+ //For Ubuntu...
" </item>" " </item>"
" <item>"
" <attribute name='label' translatable='yes'>_Stop</attribute>"
" <attribute name='action'>app.debug_stop</attribute>"
+accels["debug_stop"]+ //For Ubuntu...
" </item>"
" </section>" " </section>"
" <section>" " <section>"
" <item>" " <item>"

9
src/source_clang.cc

@ -2,6 +2,7 @@
#include "config.h" #include "config.h"
#include "terminal.h" #include "terminal.h"
#include "cmake.h" #include "cmake.h"
#include "debug.h"
namespace sigc { namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE #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(); auto brief_comment=token.get_cursor().get_brief_comments();
if(brief_comment!="") if(brief_comment!="")
tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "\n\n"+brief_comment, "def:note"); 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; return tooltip_buffer;
}; };

23
src/window.cc

@ -22,7 +22,7 @@ namespace sigc {
#endif #endif
} }
Window::Window() : compiling(false) { Window::Window() : compiling(false), debugging(false) {
JDEBUG("start"); JDEBUG("start");
set_title("juCi++"); set_title("juCi++");
set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK|Gdk::LEAVE_NOTIFY_MASK); 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](){ menu.add_action("debug_start", [this](){
if(compiling) if(debugging)
return; return;
boost::filesystem::path cmake_path; boost::filesystem::path cmake_path;
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
@ -638,7 +638,7 @@ void Window::set_menu_actions() {
return; return;
if(!CMake::create_debug_build(project_path)) if(!CMake::create_debug_build(project_path))
return; return;
compiling=true; debugging=true;
auto executable_path_string=executable_path.string(); auto executable_path_string=executable_path.string();
size_t pos=executable_path_string.find(project_path.string()); size_t pos=executable_path_string.find(project_path.string());
if(pos!=std::string::npos) { 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().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){ 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) { if(exit_status==EXIT_SUCCESS) {
auto executable_path_spaces_fixed=executable_path.string(); auto executable_path_spaces_fixed=executable_path.string();
char last_char=0; char last_char=0;
@ -659,6 +658,7 @@ void Window::set_menu_actions() {
last_char=executable_path_spaces_fixed[c]; 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){ 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'); 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"); 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](){ menu.add_action("debug_toggle_breakpoint", [this](){
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view(); 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()); 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]() { menu.add_action("next_tab", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {

1
src/window.h

@ -32,6 +32,7 @@ private:
Gtk::AboutDialog about; Gtk::AboutDialog about;
EntryBox entry_box; EntryBox entry_box;
std::atomic<bool> compiling; std::atomic<bool> compiling;
std::atomic<bool> debugging;
void configure(); void configure();
void set_menu_actions(); void set_menu_actions();

Loading…
Cancel
Save