Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++][PowerPC] libcxx/gdb/gdb_pretty_printer_test.sh.cpp LIT test case failure on LLVM 13 #51017

Closed
amy-kwan opened this issue Aug 30, 2021 · 11 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@amy-kwan
Copy link
Contributor

Bugzilla Link 51675
Resolution FIXED
Resolved on Sep 03, 2021 22:30
Version trunk
OS Linux
Blocks #50580
CC @ldionne,@tstellar
Fixed by commit(s) 217c6d6 1c3fcc8

Extended Description

The gdb_pretty_printer_test.sh.cpp was recently enabled to run on PowerPC since this commit:

commit 6427c53
Author: Louis Dionne ldionne.2@gmail.com
Date: Wed Mar 24 16:45:55 2021 -0400

[libc++] Use add_lit_testsuite to register the libc++ test suite

The Runtimes build uses variables set by add_lit_testsuite to discover
tests suites to run.

Differential Revision: https://reviews.llvm.org/D97913

I happen to test on one of our RHEL 8.2 machines, and the following behaviour of this test occurs during run time:

$ "/usr/bin/gdb" "-nx" "-batch" "-iex" "set autoload off" "-ex" "source /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/../../../utils/gdb/libcxx/printers.py" "-ex" "python register_libcxx_printer_loader()" "-ex" "source /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py" "/home/amyk/llvm/dev/build/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe"
No symbol table is loaded. Use the "file" command.
Breakpoint 1 at 0x10002968: file llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp, line 67.
Loading libc++ pretty-printers.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/power9/libthread_db.so.1".
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:170
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:174
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:179
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:184
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:217
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:222
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:243
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:246
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:249
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:257
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:603
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:639
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:643
PASS: llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:648
[Inferior 1 (process 708433) exited normally]
FAILED 82 cases

Investigation is ongoing...

@amy-kwan
Copy link
Contributor Author

Interestingly, I found this test fails for us on Ubuntu as well, although in a different way. It looks like there is a Python error, but the return code is 0 so the testing didn't initially report that there is a test failure.

$ /usr/bin/gdb -nx -batch -iex "set autoload off" -ex "source /data/amyk/llvm_trunk/llvm-project/libcxx/test/libcxx/gdb/../../../utils/gdb/libcxx/printers.py" -ex "python register_libcxx_printer_loader()" -ex "source /data/amyk/llvm_trunk/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py" /data/amyk/llvm_trunk/rel13/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe
No symbol table is loaded. Use the "file" command.
Breakpoint 1 at 0x10002788: file /data/amyk/llvm_trunk/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp, line 67.
Traceback (most recent call last):
File "/data/amyk/llvm_trunk/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py", line 107, in
test_bp.commands = "print_and_compare\ncontinue"
AttributeError: attribute 'commands' of 'gdb.Breakpoint' objects is not writable

$ echo $?
0

According to https://sourceware.org/gdb/current/onlinedocs/gdb/Breakpoints-In-Python.html#Breakpoints-In-Python, 'commands' should definitely be writable...

@amy-kwan
Copy link
Contributor Author

Louis, do you happen to have any knowledge on what could be going on with either of these issues?

@amy-kwan
Copy link
Contributor Author

In terms of the

"AttributeError: attribute 'commands' of 'gdb.Breakpoint' objects is not writable"

error seen on the Ubuntu machine I was testing on, it seems like this maybe related to the version of GDB that is on the system.

It looks like GDB 8.2 allows commands to be writable (https://sourceware.org/bugzilla/show_bug.cgi?id=22731), but the default GDB on the system is GDB 8.1.1.

If I use a GDB 8.2, I see the same failure on Ubuntu that I originally reported on RHEL (with the test failing 82 cases).

@amy-kwan
Copy link
Contributor Author

amy-kwan commented Sep 1, 2021

Within libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp, it looks like the commented out tests are the ones that fail and have the "value has been optimized out" messages:

. . .

int main(int, char**) {
framework_self_test();

// string_test();
a_namespace::string_view_test();

// u32string_test();
tuple_test();
// unique_ptr_test();
// shared_ptr_test();
bitset_test();
// list_test();
// deque_test();
// map_test();
// multimap_test();
// queue_test();
// priority_queue_test();
// stack_test();
// set_test();
// multiset_test();
// vector_test();
// set_iterator_test();
// map_iterator_test();
// unordered_set_test();
// unordered_multiset_test();
// unordered_map_test();
// unordered_multimap_test();
// unordered_map_iterator_test();
// unordered_set_iterator_test();
pointer_negative_test();
streampos_test();
return 0;
}

For instance, if I look only string_test() specifically through gdb and:

  • add a breakpoint at line 67 (where StopForDebugger is),
  • run the program,
  • print the value before StopForDebugger,
  • step to the next instruction,
  • print the value after StopForDebugger,
    After this, I can already see that the value in ComparePrettyPrintToChars is optimized out:

(gdb) p value
$1 = {<std::__1::__basic_string_common> = {}, static __short_mask = 1,
static __long_mask = 1,
_r = {<std::__1::__compressed_pair_elem<std::__1::basic_string<char, std::__1::char_traits, std::__1::alloc
ator >::__rep, 0, false>> = {_value = {{__l = {_cap = 7742651371507444500, _size = 140733200099940,
_data = 0xf63d4e2e <error: Cannot access memory at address 0xf63d4e2e>}, __s = {{_size = 20 '\024',
__lx = 20 '\024'}, _data = "kdjflskdjf\000\377\177\000\000.N=\366\000\000\000"}, __r = {__words = {
7742651371507444500, 140733200099940,
4131212846}}}}}, <std::__1::__compressed_pair_elem<std::__1::allocator, 1, true>> = {<std::__1::a
llocator> = {<std::__1::__non_trivial_if<true, std::__1::allocator >> = {}, }, }, }, static npos = 18446744073709551615}

(gdb) stepi

(gdb) p value
$2 =

@amy-kwan
Copy link
Contributor Author

amy-kwan commented Sep 1, 2021

I've added Sterling Augustine to this Bugzilla in case Sterling has any insight of what might be going on. I believe Sterling has contributed to the gdb pretty printers test case in the past.

I am not sure if this is expected, but I've also tried to wrap the variable in a MarkAsLive call:

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
index 2d8e9620089a..6f8e0b4f7d81 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
@@ -146,11 +146,13 @@ template class UncompressibleAllocator : public std::allocator {

void string_test() {
std::string short_string("kdjflskdjf");

  • MarkAsLive(short_string);
    // The display_hint "string" adds quotes the printed result.
    ComparePrettyPrintToChars(short_string, ""kdjflskdjf"");

    std::basic_string<char, std::char_traits, UncompressibleAllocator>
    long_string("mehmet bizim dostumuz agzi kirik testimiz");

  • MarkAsLive(long_string);
    ComparePrettyPrintToChars(long_string,
    ""mehmet bizim dostumuz agzi kirik testimiz"");
    }

Although, this doesn't seem to prevent any variables from being optimized out.

@amy-kwan
Copy link
Contributor Author

amy-kwan commented Sep 1, 2021

My full compile command looks like:

$ clang++ -v --gcc-toolchain=/usr --target=powerpc64le-unknown-linux-gnu /home/amyk/llvm/upstream/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp -o /home/amyk/llvm/upstream/build/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe -include /home/amyk/llvm/upstream/llvm-project/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/amyk/llvm/upstream/build/include/c++/v1 -I/home/amyk/llvm/upstream/build/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/amyk/llvm/upstream/llvm-project/libcxx/test/support -std=c++20 -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -g -lc++experimental -L/home/amyk/llvm/upstream/build/./lib -Wl,-rpath,/home/amyk/llvm/upstream/build/./lib -L/home/amyk/llvm/upstream/build/./lib -Wl,-rpath,/home/amyk/llvm/upstream/build/./lib -nodefaultlibs -lc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc -latomic
clang version 14.0.0
Target: powerpc64le-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/amyk/llvm/upstream/build/bin
Found candidate GCC installation: /usr/lib/gcc/ppc64le-redhat-linux/8
Selected GCC installation: /usr/lib/gcc/ppc64le-redhat-linux/8
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/home/amyk/llvm/upstream/build/bin/clang-14" -cc1 -triple powerpc64le-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-file-name gdb_pretty_printer_test.sh.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu ppc64le -mfloat-abi hard -target-abi elfv2 -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/amyk -nostdinc++ -resource-dir /home/amyk/llvm/upstream/build/lib/clang/14.0.0 -include /home/amyk/llvm/upstream/llvm-project/libcxx/test/support/nasty_macros.h -I /home/amyk/llvm/upstream/build/include/c++/v1 -I /home/amyk/llvm/upstream/build/projects/libcxx/include/c++build -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -I /home/amyk/llvm/upstream/llvm-project/libcxx/test/support -D _LIBCPP_DISABLE_AVAILABILITY -D _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D _LIBCPP_HAS_THREAD_API_PTHREAD -D _LIBCPP_ABI_VERSION=1 -internal-isystem /home/amyk/llvm/upstream/build/lib/clang/14.0.0/include/ppc_wrappers -internal-isystem /home/amyk/llvm/upstream/build/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/ppc64le-redhat-linux/8/../../../../ppc64le-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Werror=thread-safety -Wuser-defined-warnings -Wno-macro-redefined -Wno-macro-redefined -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/home/amyk -ferror-limit 19 -fcoroutines-ts -fno-signed-char -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/gdb_pretty_printer_test-e486e6.o -x c++ /home/amyk/llvm/upstream/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
clang -cc1 version 14.0.0 based upon LLVM 14.0.0git default target powerpc64le-unknown-linux-gnu
ignoring nonexistent directory "/usr/lib/gcc/ppc64le-redhat-linux/8/../../../../ppc64le-redhat-linux/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/home/amyk/llvm/upstream/build/include/c++/v1
/home/amyk/llvm/upstream/build/projects/libcxx/include/c++build
/home/amyk/llvm/upstream/llvm-project/libcxx/test/support
/home/amyk/llvm/upstream/build/lib/clang/14.0.0/include/ppc_wrappers
/home/amyk/llvm/upstream/build/lib/clang/14.0.0/include
/usr/local/include
/usr/include
End of search list.
"/home/amyk/llvm/upstream/build/bin/ld.lld" --eh-frame-hdr -m elf64lppc -dynamic-linker /lib64/ld64.so.2 -o /home/amyk/llvm/upstream/build/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe /usr/lib/gcc/ppc64le-redhat-linux/8/../../../../lib64/crt1.o /usr/lib/gcc/ppc64le-redhat-linux/8/../../../../lib64/crti.o /usr/lib/gcc/ppc64le-redhat-linux/8/crtbegin.o -L/home/amyk/llvm/upstream/build/./lib -L/home/amyk/llvm/upstream/build/./lib -L/usr/lib/gcc/ppc64le-redhat-linux/8 -L/usr/lib/gcc/ppc64le-redhat-linux/8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/amyk/llvm/upstream/build/bin/../lib -L/lib -L/usr/lib /tmp/gdb_pretty_printer_test-e486e6.o -lc++experimental -rpath /home/amyk/llvm/upstream/build/./lib -rpath /home/amyk/llvm/upstream/build/./lib -lc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc -latomic /usr/lib/gcc/ppc64le-redhat-linux/8/crtend.o /usr/lib/gcc/ppc64le-redhat-linux/8/../../../../lib64/crtn.o

And while I'm looking at string_test() specifically, it's run as:

$ /usr/bin/gdb -nx -batch -iex "set autoload off" -ex "source /home/amyk/llvm/upstream/llvm-project/libcxx/test/libcxx/gdb/../../../utils/gdb/libcxx/printers.py" -ex "python register_libcxx_printer_loader()" -ex "source /home/amyk/llvm/upstream/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py" /home/amyk/llvm/upstream/build/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe
No symbol table is loaded. Use the "file" command.
Breakpoint 1 at 0x10034208: file llvm/upstream/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp, line 67.
Loading libc++ pretty-printers.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/power9/libthread_db.so.1".
FAIL: Something is wrong in the test framework.
value has been optimized out
FAIL: Something is wrong in the test framework.
value has been optimized out
[Inferior 1 (process 3208683) exited normally]
FAILED 2 cases

I'm seeing it failing right when it prints the value at:

s = gdb.execute("p value", to_string=True)

inside libcxx/gdb/gdb_pretty_printer_test.py.

@llvmbot
Copy link
Member

llvmbot commented Sep 1, 2021

I don't know exactly what is going on here, but gdb's "Value has been optimized out" error message is often misleading. Sometimes it prints it when it just can't find a symbol, sometimes when it can find a symbol but the pc is inside a range that isn't covered by the location list, or some other situation. So the term, "optimized out" isn't quite right. It should more properly read something like, "can't find debug info for symbol at pc. Maybe it was optimized out, but maybe something else."

The test itself does take steps to prevent optimizing the local variables--they are passed as arguments into functions that have optimization turned off, and these arguments are the ones that are actually pretty printed, rather than the local variables down in the tests functions themselves, so I wouldn't expect the MarkAsLive change as given here to affect anything.

My guess is that the debug info is slightly different than what it should be. Perhaps the dwarf range for value is off by one instruction or similar?

@amy-kwan
Copy link
Contributor Author

amy-kwan commented Sep 2, 2021

I don't know exactly what is going on here, but gdb's "Value has been
optimized out" error message is often misleading. Sometimes it prints it
when it just can't find a symbol, sometimes when it can find a symbol but
the pc is inside a range that isn't covered by the location list, or some
other situation. So the term, "optimized out" isn't quite right. It should
more properly read something like, "can't find debug info for symbol at pc.
Maybe it was optimized out, but maybe something else."

The test itself does take steps to prevent optimizing the local
variables--they are passed as arguments into functions that have
optimization turned off, and these arguments are the ones that are actually
pretty printed, rather than the local variables down in the tests functions
themselves, so I wouldn't expect the MarkAsLive change as given here to
affect anything.

My guess is that the debug info is slightly different than what it should
be. Perhaps the dwarf range for value is off by one instruction or similar?

Thanks for your response, Sterling. The issue very well could be something debug info related.

I was also experimenting and found that adding MarkAsLive() calls inside the pretty printer comparison functions resolves this issue. So, the change like the following:

diff --git a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
index 2d8e9620089a..7c8d307d19fb 100644
--- a/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
+++ b/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp
@@ -92,24 +92,28 @@ void MarkAsLive(Type &&) {}
template void ComparePrettyPrintToChars(
TypeToPrint value,
const char *expectation) {

  • MarkAsLive(value);
    StopForDebugger(&value, &expectation);
    }

template void ComparePrettyPrintToRegex(
TypeToPrint value,
const char *expectation) {

  • MarkAsLive(value);
    StopForDebugger(&value, &expectation);
    }

void CompareExpressionPrettyPrintToChars(
std::string value,
const char *expectation) {

  • MarkAsLive(value);
    StopForDebugger(&value, &expectation);
    }

void CompareExpressionPrettyPrintToRegex(
std::string value,
const char *expectation) {

  • MarkAsLive(value);
    StopForDebugger(&value, &expectation);
    }

This compiles and runs successfully:

$ clang++ --gcc-toolchain=/usr --target=powerpc64le-unknown-linux-gnu /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp -o /home/amyk/llvm/dev/build/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe -include /home/amyk/llvm/dev/llvm-project/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/amyk/llvm/dev/build/include/c++/v1 -I/home/amyk/llvm/dev/build/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/amyk/llvm/dev/llvm-project/libcxx/test/support -std=c++20 -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -g -lc++experimental -L/home/amyk/llvm/dev/build/./lib -Wl,-rpath,/home/amyk/llvm/dev/build/./lib -L/home/amyk/llvm/dev/build/./lib -Wl,-rpath,/home/amyk/llvm/dev/build/./lib -nodefaultlibs -lc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc -latomic

$ /usr/bin/gdb -nx -batch -iex "set autoload off" -ex "source /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/../../../utils/gdb/libcxx/printers.py" -ex "python register_libcxx_printer_loader()" -ex "source /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.py" /home/amyk/llvm/dev/build/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe
No symbol table is loaded. Use the "file" command.
Breakpoint 1 at 0x10034788: file /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp, line 67.
Loading libc++ pretty-printers.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/power9/libthread_db.so.1".
PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:154
PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:158
PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:174
PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:178
PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:183

. . .

PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:647
PASS: /home/amyk/llvm/dev/llvm-project/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp:652
[Inferior 1 (process 2897242) exited normally]

I was wondering if this is an appropriate change for gdb_pretty_printer_test.sh.cpp?

@llvmbot
Copy link
Member

llvmbot commented Sep 2, 2021

I'm puzzled that it is necessary. Passing the value to an OPT_NONE function should work, and does most everyone. But it is also harmless, so I think this change is OK.

@amy-kwan
Copy link
Contributor Author

amy-kwan commented Sep 2, 2021

I'm puzzled that it is necessary. Passing the value to an OPT_NONE function
should work, and does most everyone. But it is also harmless, so I think
this change is OK.

Yeah, I agree.
Thanks for getting back to me regarding this change. I've posted https://reviews.llvm.org/D109204 up for review.

@ldionne
Copy link
Member

ldionne commented Sep 3, 2021

Fixed on main and cherry-picked to release/13.x as

commit 1c3fcc8 (HEAD -> release/13.x)
Author: Amy Kwan amy.kwan1@ibm.com
Date: Fri Sep 3 14:53:57 2021 -0400

[libc++][NFC] Mark values in gdb pretty print comparison functions as live to prevent values being optimized out.

It appears when testing LLVM 13 on Power, we run into failures with the
`libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp` test case optimizing
values out.

Despite some the functions in the test already being marked with optnone,
adding the `MarkAsLive()` calls inside of the pretty printer comparison functions
resolves the issues of the values being optimized out.

This patch aims to address llvm/llvm-project#51017 .

Differential Revision: https://reviews.llvm.org/D109204

(cherry picked from commit 217c6d643124be312f4a99b203118744edb9d54c)

Thanks a lot!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

3 participants