Browse Source

Added debug stack backtrace

merge-requests/365/head
eidheim 10 years ago
parent
commit
a655b61ea8
  1. 27
      src/debug.cc
  2. 9
      src/debug.h
  3. 3
      src/files.h
  4. 7
      src/menu.cc
  5. 65
      src/window.cc

27
src/debug.cc

@ -254,6 +254,33 @@ std::pair<std::string, std::string> Debug::run_command(const std::string &comman
return command_return;
}
std::vector<Debug::Frame> Debug::get_backtrace() {
std::vector<Frame> backtrace;
event_mutex.lock();
if(state==lldb::StateType::eStateStopped) {
auto thread=process->GetSelectedThread();
for(uint32_t c_f=0;c_f<thread.GetNumFrames();c_f++) {
Frame backtrace_frame;
auto frame=thread.GetFrameAtIndex(c_f);
backtrace_frame.function_name=frame.GetFunctionName();
auto line_entry=frame.GetLineEntry();
if(line_entry.IsValid()) {
lldb::SBStream stream;
line_entry.GetFileSpec().GetDescription(stream);
auto column=line_entry.GetColumn();
if(column==0)
column=1;
backtrace_frame.file_path=stream.GetData();
backtrace_frame.line_nr=line_entry.GetLine();
backtrace_frame.line_index=column;
}
backtrace.emplace_back(backtrace_frame);
}
}
event_mutex.unlock();
return backtrace;
}
void Debug::delete_debug() {
kill();
if(debug_thread.joinable())

9
src/debug.h

@ -10,6 +10,14 @@
#include <mutex>
class Debug {
public:
class Frame {
public:
std::string file_path;
std::string function_name;
int line_nr;
int line_index;
};
private:
Debug();
public:
@ -30,6 +38,7 @@ public:
void step_into();
void step_out();
std::pair<std::string, std::string> run_command(const std::string &command);
std::vector<Frame> get_backtrace();
void delete_debug(); //can't use delete as function name

3
src/files.h

@ -2,7 +2,7 @@
#define JUCI_FILES_H_
#include <string>
#define JUCI_VERSION "1.1.0-2"
#define JUCI_VERSION "1.1.0-3"
const std::string configjson =
"{\n"
@ -106,6 +106,7 @@ const std::string configjson =
" \"debug_step_over\": \"<primary>n\",\n"
" \"debug_step_into\": \"<primary>t\",\n"
" \"debug_step_out\": \"<primary><shift>t\",\n"
" \"debug_backtrace\": \"<primary><shift>n\",\n"
" \"debug_run_command\": \"<alt><shift>Return\",\n"
" \"debug_toggle_breakpoint\": \"<primary>b\",\n"
" \"debug_goto_stop\": \"<primary><shift>l\",\n"

7
src/menu.cc

@ -316,6 +316,13 @@ Menu::Menu() {
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Backtrace</attribute>"
" <attribute name='action'>app.debug_backtrace</attribute>"
+accels["debug_backtrace"]+ //For Ubuntu...
" </item>"
" </section>"
" <section>"
" <item>"
" <attribute name='label' translatable='yes'>_Run Command</attribute>"
" <attribute name='action'>app.debug_run_command</attribute>"
+accels["debug_run_command"]+ //For Ubuntu...

65
src/window.cc

@ -151,6 +151,7 @@ Window::Window() : compiling(false), debugging(false) {
menu.actions["debug_step_over"]->set_enabled(false);
menu.actions["debug_step_into"]->set_enabled(false);
menu.actions["debug_step_out"]->set_enabled(false);
menu.actions["debug_backtrace"]->set_enabled(false);
menu.actions["debug_run_command"]->set_enabled(false);
menu.actions["debug_goto_stop"]->set_enabled(false);
debug_update_status.connect([this](){
@ -163,6 +164,7 @@ Window::Window() : compiling(false), debugging(false) {
menu.actions["debug_step_over"]->set_enabled(false);
menu.actions["debug_step_into"]->set_enabled(false);
menu.actions["debug_step_out"]->set_enabled(false);
menu.actions["debug_backtrace"]->set_enabled(false);
menu.actions["debug_run_command"]->set_enabled(false);
menu.actions["debug_goto_stop"]->set_enabled(false);
}
@ -174,6 +176,7 @@ Window::Window() : compiling(false), debugging(false) {
menu.actions["debug_step_over"]->set_enabled();
menu.actions["debug_step_into"]->set_enabled();
menu.actions["debug_step_out"]->set_enabled();
menu.actions["debug_backtrace"]->set_enabled();
menu.actions["debug_run_command"]->set_enabled();
menu.actions["debug_goto_stop"]->set_enabled();
}
@ -912,6 +915,68 @@ void Window::set_menu_actions() {
if(debugging)
Debug::get().step_out();
});
menu.add_action("debug_backtrace", [this]() {
if(debugging && notebook.get_current_page()!=-1) {
auto backtrace=Debug::get().get_backtrace();
auto view=notebook.get_current_view();
auto buffer=view->get_buffer();
auto iter=buffer->get_insert()->get_iter();
Gdk::Rectangle visible_rect;
view->get_visible_rect(visible_rect);
Gdk::Rectangle iter_rect;
view->get_iter_location(iter, iter_rect);
iter_rect.set_width(1);
if(!visible_rect.intersects(iter_rect)) {
view->get_iter_at_location(iter, 0, visible_rect.get_y()+visible_rect.get_height()/3);
}
view->selection_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*view, buffer->create_mark(iter), true, true));
auto rows=std::make_shared<std::unordered_map<std::string, Debug::Frame> >();
if(backtrace.size()==0)
return;
std::string project_path;
auto cmake=get_cmake();
if(cmake)
project_path=cmake->project_path.string();
for(auto &frame: backtrace) {
std::string row;
if(frame.file_path.empty())
row=frame.function_name;
else {
auto file_path=frame.file_path;
if(!project_path.empty()) {
auto pos=file_path.find(project_path);
if(pos==0)
file_path.erase(0, project_path.size()+1);
}
row="<b>"+Glib::Markup::escape_text(file_path)+":"+std::to_string(frame.line_nr)+"</b> "+Glib::Markup::escape_text(frame.function_name);
}
(*rows)[row]=frame;
view->selection_dialog->add_row(row);
}
view->selection_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) {
auto frame=rows->at(selected);
if(!frame.file_path.empty()) {
notebook.open(frame.file_path);
if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view();
view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(frame.line_nr-1, frame.line_index-1));
while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false);
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);
}
}
};
view->selection_dialog->show();
}
});
menu.add_action("debug_run_command", [this]() {
entry_box.clear();
entry_box.entries.emplace_back(last_run_debug_command, [this](const std::string& content){

Loading…
Cancel
Save