Debug Clickhouse With VSCode On Mac

Clone Source Code

  1. git clone https://github.com/ClickHouse/ClickHouse.git
  2. git pull && git submodule update –init –recursive

Install Tools

  1. brew install cmake ninja clang
  2. vscode install plugins
    1. https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools
    2. https://marketplace.visualstudio.com/items?itemName=twxs.cmake
    3. https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb

Compile Source Code with VSCode

  1. use mkdir -p Clickhouse/build to create directory for binary files
  2. create file .vscode/task.json to config vscode tasks
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    {
    "tasks": [
    {
    "type": "shell",
    "label": "clang",
    "command": "cd ClickHouse/build; cmake .. -DCMAKE_C_COMPILER=`brew --prefix llvm`/bin/clang -DCMAKE_CXX_COMPILER=`brew --prefix llvm`/bin/clang++ -DCMAKE_PREFIX_PATH=`brew --prefix llvm` -DCMAKE_BUILD_TYPE=Debug -DENABLE_JEMALLOC=0 -DENABLE_LIBRARIES=ON"
    },
    {
    "type": "shell",
    "label": "ninja",
    "dependsOn": "clang",
    "command": "cd ClickHouse/build; ninja -j 4 clickhouse-server"
    },
    {
    "type": "shell",
    "label": "Pull Master",
    "command": "git pull && git submodule update --init --recursive"
    }
    ],
    "version": "2.0.0"
    }

Debug Clickhouse Server

  1. create .vscode/launch.json to config debug info
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Clickhouse Server",
    "type": "lldb",
    "request": "launch",
    "program": "ClickHouse/build/programs/clickhouse-server",
    "args": [
    "server", "--config", "ClickHouse/programs/server/config.xml"
    ],
    "preLaunchTask": "ninja"
    }
    ]
    }
  2. Click F5 to run VSCode Debug

Test Debug

  1. use curl -sS "localhost:8123" -d "show databases" to visit local clickhouse-server
    https://clickhouse.tech/docs/en/interfaces/http/#cli-queries-with-parameters