Clickhouse: Broken pretty print in gdb

Created on 11 Aug 2020  路  4Comments  路  Source: ClickHouse/ClickHouse

I'm following storage_log.cpp step by step. But when I'm trying to print string info at L45 by print column.name in gdb 9.1, it outputs:

$1 = {
  <std::__1::__basic_string_common<true>> = {<No data fields>},
  members of std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >:
  static __short_mask = 1,
  static __long_mask = 1,

But when I'm debugging a simple program like this, it prints well:

#include <string>

int main() {
  std::string s = "a";
  return 0;
}

The compiling args I found in compile_commands.json:

  "command": "/bin/c++  -DAWS_SDK_VERSION_MAJOR=1 -DAWS_SDK_VERSION_MINOR=7 -DAWS_SDK_VERSION_PATCH=231 -DBOOST_SYSTEM_NO_DEPRECATED -DENABLE_CURL_CLIENT -DENABLE_OPENSSL_ENCRYPTION -DGTEST_HAS_POSIX_RE=0 -DPOCO_STATIC -DPOCO_UNBUNDLED_ZLIB -DSTD_EXCEPTION_HAS_STACK_TRACE=1 -DUNALIGNED_OK -DUSE_REPLXX=1 -DWITH_GZFILEOP -DX86_64 -DZLIB_COMPAT -Iincludes/configs -I../contrib/jemalloc-cmake/include -I../contrib/jemalloc-cmake/include_linux_x86_64 -Isrc/Core/include -I../src -Isrc -I../base/common/.. -Ibase/common/.. -I../contrib/replxx/include -I../contrib/zlib-ng -Icontrib/zlib-ng -I../contrib/cityhash102/include -I../contrib/aws-c-common/include -I../contrib/aws-c-event-stream/include -Icontrib/aws-s3-cmake/include -I../base/mysqlxx/include -I../contrib/mariadb-connector-c/include -Icontrib/mariadb-connector-c/include -I../base/consistent-hashing -I../base/consistent-hashing-sumbur -I../contrib/libfarmhash -I../contrib/libmetrohash/src -I../contrib/murmurhash/include -isystem ../contrib/libcxx/include -isystem ../contrib/libcxxabi/include -isystem ../contrib/libunwind/include -isystem ../contrib/googletest/googletest/include -isystem ../contrib/googletest/googletest -isystem ../contrib/llvm/llvm/include -isystem contrib/llvm/llvm/include -isystem ../contrib/pdqsort -isystem ../contrib/libpcg-random/include -isystem ../contrib/double-conversion -isystem ../contrib/aws/aws-cpp-sdk-s3/include -isystem ../contrib/aws/aws-cpp-sdk-core/include -isystem ../contrib/libhdfs3/include -isystem ../contrib/re2 -isystem ../contrib/poco/Util/include -isystem ../contrib/poco/Foundation/include -isystem ../contrib/poco/XML/include -isystem ../contrib/poco/JSON/include -isystem ../contrib/boost -isystem ../contrib/fmtlib-cmake/../fmtlib/include -isystem ../contrib/ryu -isystem ../contrib/poco/Net/include -isystem contrib/re2_st -isystem ../contrib/croaring -isystem ../contrib/base64 -isystem ../contrib/fastops -isystem ../contrib/openssl-cmake/linux_x86_64/include -isystem ../contrib/openssl/include -isystem ../contrib/libc-headers/x86_64-linux-gnu -isystem ../contrib/libc-headers   -fdiagnostics-color=always -std=c++2a -fsized-deallocation  -pipe -msse4.1 -msse4.2 -mpopcnt   -Wall  -Wnon-virtual-dtor -Wno-array-bounds -Werror -Wextra -g -O0 -g3 -ggdb3 -fno-inline  -D_LIBCPP_DEBUG=0   -D OS_LINUX -fno-tree-loop-distribute-patterns -Wbool-compare -Wcast-align -Wcast-qual -Wdelete-incomplete -Wdisabled-optimization -Wduplicated-cond -Wenum-compare -Winit-self -Wlogical-not-parentheses -Wlogical-op -Wmaybe-uninitialized -Wmisleading-indentation -Wmissing-include-dirs -Wnon-virtual-dtor -Wno-return-local-addr -Wodr -Wold-style-cast -Wplacement-new=2 -Wpointer-arith -Wredundant-decls -Wreorder -Wshadow -Wshift-negative-value -Wsized-deallocation -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wsuggest-override -Wswitch-bool -Wtautological-compare -Wtrampolines -Wunused -Wvector-operation-performance -Wno-zero-as-null-pointer-constant -Wno-undef -Wno-sign-compare -Wno-used-but-marked-unused -Wno-missing-noreturn -Wno-gnu-zero-variadic-macro-arguments -nostdinc++ -pthread -Wno-documentation -o src/CMakeFiles/unit_tests_dbms.dir/Storages/tests/gtest_storage_log.cpp.o -c /home/user/ClickHouse/src/Storages/tests/gtest_storage_log.cpp",

I'm using g++ 9.3 on Ubuntu 20.04 and build debug version by:

cmake -D CMAKE_BUILD_TYPE=Debug ..

Any suggestion would be helpful.

development question

All 4 comments

It turns out that ClickHouse use libraries inside contrib by default:

https://github.com/ClickHouse/ClickHouse/blob/3756f6d6796c57eb464ee235108495fedd1fc999/CMakeLists.txt#L226

so it use contrib/libcxx instead of libstdc++.

To pretty print libcxx in gdb, you could either:

  • Follow this to add extension for gdb. Or llvm's one suggested by @vladimir-golovchenko
  • Use lldb instead. I'm using this method and it works okay at this moment. (oops bugs, see comments below)

@zingdle

could you provide your launch.json? I could not get the desired result from lldb.


I could successfully attach to clickhouse-server using gdb, but there is a problem with pretty printing for libcxx. libcxx-pretty-printers is failed on 'stack overflow'-error (it looks like it cycling on traversing of an object).

I checked the chromium-repo to find which printer used by that team - it is llvm-project/libcxx/utils/gdb/libcxx/printers.py.

At first glance, It works fine.

launch.json:

{
    "version": "0.2.0",
    "configurations": [    
        {
            "name": "gdb (llvm printer): debugging of local ClickHouse server",
            "type": "cppdbg",
            "request": "attach",
            "program": "${workspaceFolder}/build/programs/clickhouse-server",
            "processId": "${command:pickProcess}",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "ignore SIGUSR1 signal",
                    "text": "handle SIGUSR1 nostop noprint pass"
                },
                {
                    "description": "register pretty printers for libc++ (https://github.com/llvm/llvm-project/blob/master/libcxx/utils/gdb/libcxx/printers.py)",
                    "text": "python import sys; sys.path.insert(0, 'local_path_to_printers.py'); from printers import register_libcxx_printer_loader; register_libcxx_printer_loader()"
                }               
            ]  
        }              
    ]
}

@vladimir-golovchenko Sorry, I'm using gdb in console and I don't have a launch.json for vscode. Thanks for sharing your updated solution!

As for lldb, I encountered segfault when printing some variables so I switch back to gdb. libcxx-pretty-printers currently works for me, but I'll definitely consider llvm's one as another good choice. :P

Also, I'm wondering does ClickHouse have a mailing list or something similar for developers' discussion? @filimonov @alexey-milovidov

Was this page helpful?
0 / 5 - 0 ratings

Related issues

derekperkins picture derekperkins  路  3Comments

bseng picture bseng  路  3Comments

amonakhov picture amonakhov  路  3Comments

fizerkhan picture fizerkhan  路  3Comments

igor-sh8 picture igor-sh8  路  3Comments