Skip to content

Instantly share code, notes, and snippets.

@JaySon-Huang
Last active December 14, 2023 18:23
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JaySon-Huang/63dcc6c011feb5bd6deb1ef0cf1a9b96 to your computer and use it in GitHub Desktop.
Save JaySon-Huang/63dcc6c011feb5bd6deb1ef0cf1a9b96 to your computer and use it in GitHub Desktop.
Get VSCode CodeLLDB plugin work on CentOS 7

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
@JaySon-Huang
Copy link
Author

JaySon-Huang commented Aug 23, 2021

Further update:
If you set the LD_LIBRARY_PATH variable, then the lldb will try to find libraries on those paths, the glibc-2.18 in rpath will be ignored.

You may need to add these snippets in your settings.json to make it work

    "lldb.adapterEnv": {
        "LD_LIBRARY_PATH": "",
    }

@VergeDX
Copy link

VergeDX commented Nov 29, 2023

Confirm works on version 1.10.0, thanks for the magic script!!

@marklakata
Copy link

To build glibc, the configuration file may fail with a make check. The check is not able to recognize gnu make 4 or newer. Edit the configure file, line 4775 from

  3.79* | 3.[89]*)

to

  3.79* | 3.[89]* | 4.*)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment