Skip to content

Instantly share code, notes, and snippets.

@inhzus
Forked from JaySon-Huang/CodeLLDB_CentOS.md
Created October 9, 2024 02:13
Show Gist options
  • Save inhzus/45bba31a2b8e7377fce7308d56f96fab to your computer and use it in GitHub Desktop.
Save inhzus/45bba31a2b8e7377fce7308d56f96fab to your computer and use it in GitHub Desktop.
Get VSCode CodeLLDB plugin work on CentOS 7 (Fish Shell)

I want to debug with CodeLLDB on CentOS 7, but get an error like this:

/home/xxx/.vscode/extensions/vadimcn.vscode-lldb-1.6.1/adapter/codelldb: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /home/xxx/.vscode/extensions/vadimcn.vscode-lldb-1.6.1/adapter/codelldb)

LLDB requires a higher version of glibc.

I get it work by the following steps:

Install glibc-2.18 to my own path

wget http://mirrors.ustc.edu.cn/gnu/libc/glibc-2.18.tar.gz
tar xvf glibc-2.18.tar.gz
cd glibc-2.18 && mkdir build && cd build
unset LD_LIBRARY_PATH # unset LD_LIBRARY_PATH or building glibc could cause error
../configure --prefix=/opt/glibc-2.18 --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
make -j8
make install

Install pathelf and patch all executable binary and libraries

# cat patch-vs-codelldb.sh
# Reference: https://github.com/vadimcn/codelldb/issues/268
# Install patchelf: https://github.com/NixOS/patchelf#compiling-and-testing

#set -x

HOME_DIR="/path/to/your/home"
LLDB_VER="1.6.10"
LLDB_PATH="/${HOME_DIR}/.vscode-server/extensions/vadimcn.vscode-lldb-$LLDB_VER"
PATCH_ELF="/opt/patchelf"
GLIBC_PATH="/opt/glibc-2.18"

for f in `find "$LLDB_PATH" -perm /+x -type f`; do
    #echo "$PATCH_ELF --set-interpreter $GLIBC_PATH/lib/ld-linux-x86-64.so.2 $f"
    $PATCH_ELF --set-interpreter $GLIBC_PATH/lib/ld-linux-x86-64.so.2 $f
    $PATCH_ELF --set-rpath $LLDB_PATH/lldb/lib:$GLIBC_PATH/lib:/usr/local/lib64:/usr/local/lib:/lib64:/usr/lib64 $f
done

for f in `find "$LLDB_PATH" -name '*.so*' `; do
    #echo "  so file: $f"
    #echo "$PATCH_ELF --set-rpath $LLDB_PATH/lldb/lib:$GLIBC_PATH/lib:/lib64:/usr/lib64 $f"
    $PATCH_ELF --set-rpath $LLDB_PATH/lldb/lib:$GLIBC_PATH/lib:/lib64:/usr/lib64 $f
done

Fish:

for f in (find $LLDB_PATH -perm /+x -type f)
    patchelf --set-interpreter $GLIBC_PATH/lib/ld-linux-x86-64.so.2 $f
    patchelf --set-rpath $LLDB_PATH/lldb/lib:$GLIBC_PATH/lib:/usr/local/lib64:/usr/local/lib:/lib64:/usr/lib64 $f
end
for f in (find $LLDB_PATH -name '*.so*')
    patchelf --set-rpath $LLDB_PATH/lldb/lib:$GLIBC_PATH/lib:/lib64:/usr/lib64 $f
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment