From 6d6d2f31da96e95a0fccd5373cdb575a2a7a3684 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 10 Jan 2016 22:41:43 +0100 Subject: [PATCH] Added return value (lldb supports this when doing step out) --- src/debug.cc | 23 +++++++++++++++++++++++ src/debug.h | 1 + src/source_clang.cc | 30 +++++++++++++++++++----------- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/debug.cc b/src/debug.cc index 161f8a2..6e83e68 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -375,6 +375,29 @@ std::string Debug::get_value(const std::string &variable, const boost::filesyste return variable_value; } +std::string Debug::get_return_value(const std::string &variable, 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) { + auto thread=process->GetSelectedThread(); + auto thread_return_value=thread.GetStopReturnValue(); + if(thread_return_value.IsValid()) { + auto line_entry=thread.GetSelectedFrame().GetLineEntry(); + if(line_entry.IsValid()) { + lldb::SBStream stream; + line_entry.GetFileSpec().GetDescription(stream); + if(boost::filesystem::path(stream.GetData())==file_path && line_entry.GetLine()==line_nr && line_entry.GetColumn()==line_index) { + lldb::SBStream stream; + thread_return_value.GetDescription(stream); + return_value=stream.GetData(); + } + } + } + } + event_mutex.unlock(); + return return_value; +} + bool Debug::is_invalid() { bool invalid; event_mutex.lock(); diff --git a/src/debug.h b/src/debug.h index c8af1dc..45b9a0e 100644 --- a/src/debug.h +++ b/src/debug.h @@ -46,6 +46,7 @@ public: 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); + std::string get_return_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr, unsigned int line_index); bool is_invalid(); bool is_stopped(); diff --git a/src/source_clang.cc b/src/source_clang.cc index d3c6268..142d563 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -417,18 +417,26 @@ 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 - auto location=token.get_cursor().get_referenced().get_source_location(); - Glib::ustring debug_value=Debug::get().get_value(token.get_spelling(), location.get_path(), location.get_offset().line); - if(!debug_value.empty()) { - size_t pos=debug_value.find(" = "); - if(pos!=Glib::ustring::npos) { - Glib::ustring::iterator iter; - while(!debug_value.validate(iter)) { - auto next_char_iter=iter; - next_char_iter++; - debug_value.replace(iter, next_char_iter, "?"); + if(Debug::get().is_stopped()) { + auto location=token.get_cursor().get_referenced().get_source_location(); + Glib::ustring value_type="Value"; + Glib::ustring debug_value=Debug::get().get_value(token.get_spelling(), location.get_path(), location.get_offset().line); + if(debug_value.empty()) { + value_type="Return value"; + auto location=token.get_cursor().get_source_location(); + debug_value=Debug::get().get_return_value(token.get_spelling(), location.get_path(), location.get_offset().line, location.get_offset().index); + } + if(!debug_value.empty()) { + size_t pos=debug_value.find(" = "); + if(pos!=Glib::ustring::npos) { + Glib::ustring::iterator iter; + while(!debug_value.validate(iter)) { + auto next_char_iter=iter; + next_char_iter++; + debug_value.replace(iter, next_char_iter, "?"); + } + tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "\n\n"+value_type+": "+debug_value.substr(pos+3, debug_value.size()-(pos+3)-1), "def:note"); } - tooltip_buffer->insert_with_tag(tooltip_buffer->get_insert()->get_iter(), "\n\nValue: "+debug_value.substr(pos+3, debug_value.size()-(pos+3)-1), "def:note"); } } #endif