llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.38k stars 12.15k forks source link

LLDB cannot print STL container variables #54576

Open zzh1010016195 opened 2 years ago

zzh1010016195 commented 2 years ago

LLDB cannot print the variable when compiler is g++ and a container instantiates another. System: Ubuntu 20.04 Complier: g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

#include <string>
#include <vector>

struct bar {
  int var1;
};

struct foo {
  int var1;
  bar* my_bar_pointer;
  bar my_bar_object;
  foo* next_foo;
};

int fun(std::vector<std::string> var) {
  return var.size(); // breakpoint 1
}

int main(int argc, char const *argv[]) {
  int var1 = 0;
  int var2 = 1;
  std::string str1 = "a";
  std::string str2 = "b";
  std::vector<std::string> vec;
  fun(vec);
  bar bar1 = {2};
  bar* bar2 = &bar1; 
  foo foo1 = {3,&bar1, bar1, NULL};
  return 0; // breakpoint 2
}

Below is the result of p var.

* thread #1, name = 'test', stop reason = breakpoint 1.1
    frame #0: 0x00005555555552d9 test`fun(var=size=0) at test.cpp:16:18
   13   };
   14   
   15   int fun(std::vector<std::string> var) {
-> 16     return var.size(); // breakpoint 1
   17   }
   18   
   19   int main(int argc, char const *argv[]) {
(lldb) p var
error: expression failed to parse:
error: <lldb wrapper prefix>:45:31: no member named 'var' in namespace '$__lldb_local_vars'
    using $__lldb_local_vars::var;
          ~~~~~~~~~~~~~~~~~~~~^
error: <user expression 0>:1:1: use of undeclared identifier 'var'
var
^
(lldb)

The source is a test case for LLDB, lldb/test/API/tools/lldb-vscode/completions/main.cpp. I found that a few test cases failed when the test compiler was gcc.

llvmbot commented 2 years ago

@llvm/issue-subscribers-lldb

jimingham commented 2 years ago

It would be interesting to see the result of v var in this context. The error is because we are trying to realize the value of var so that we can inject it into the expression context, and for some reason that didn't work. It's likely there's something in the location expression for this var that we don't get right, in which case v var will also fail.