Browse Source

Now tries to find debug variable based on file_path and line number if possible

merge-requests/365/head
eidheim 10 years ago
parent
commit
8a9c8a3082
  1. 27
      src/debug.cc
  2. 2
      src/debug.h
  3. 3
      src/source_clang.cc

27
src/debug.cc

@ -172,23 +172,48 @@ void Debug::delete_debug() {
debug_thread.join();
}
std::string Debug::get_value(const std::string &variable) {
std::string Debug::get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr) {
std::string variable_value;
event_mutex.lock();
if(state==lldb::StateType::eStateStopped) {
auto frame=process->GetSelectedThread().GetSelectedFrame();
auto values=frame.GetVariables(true, true, true, true);
//First try to find variable based on name, file and line number
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) {
auto declaration=value.GetDeclaration();
if(declaration.IsValid()) {
if(declaration.GetLine()==line_nr) {
auto file_spec=declaration.GetFileSpec();
boost::filesystem::path value_decl_path=file_spec.GetDirectory();
value_decl_path/=file_spec.GetFilename();
if(value_decl_path==file_path) {
value.GetDescription(stream);
variable_value=stream.GetData();
break;
}
}
}
}
}
if(variable_value.empty()) {
//In case a variable is missing file and line number, only do check on name
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);
variable_value=stream.GetData();
break;
}
}
}
}
event_mutex.unlock();
return variable_value;
}

2
src/debug.h

@ -29,7 +29,7 @@ public:
void delete_debug(); //can't use delete as function name
std::string get_value(const std::string &variable);
std::string get_value(const std::string &variable, const boost::filesystem::path &file_path, unsigned int line_nr);
private:
lldb::SBDebugger debugger;

3
src/source_clang.cc

@ -413,7 +413,8 @@ 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());
auto location=token.get_cursor().get_referenced().get_source_location();
auto debug_value=Debug::get().get_value(token.get_spelling(), location.get_path(), location.get_offset().line);
if(!debug_value.empty()) {
debug_value.pop_back();
size_t pos=debug_value.find(" = ");

Loading…
Cancel
Save