From 4769c4dc239a405028fada9eee38078b90eebdd3 Mon Sep 17 00:00:00 2001 From: d-w-moore Date: Fri, 1 Jan 2021 21:41:41 -0500 Subject: [PATCH 1/6] [21] add Koutheir's pretty printers for STL in libcxx --- Dockerfile.irods_runner.centos7 | 1 + Dockerfile.irods_runner.ubuntu16 | 1 + Dockerfile.irods_runner.ubuntu18 | 1 + README.md | 49 ++++++++++++++++++++++++++++++++ koutheir-pretty-printers.sh | 49 ++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 koutheir-pretty-printers.sh diff --git a/Dockerfile.irods_runner.centos7 b/Dockerfile.irods_runner.centos7 index 5fbaec3..518e0fb 100644 --- a/Dockerfile.irods_runner.centos7 +++ b/Dockerfile.irods_runner.centos7 @@ -54,6 +54,7 @@ RUN \ rm -rf /var/cache/yum /tmp/* ADD ICAT.sql / +ADD koutheir-pretty-printers.sh / ADD keep_alive.sh /keep_alive.sh RUN chmod +x /keep_alive.sh ENTRYPOINT ["/keep_alive.sh"] diff --git a/Dockerfile.irods_runner.ubuntu16 b/Dockerfile.irods_runner.ubuntu16 index d2451b3..2a61239 100644 --- a/Dockerfile.irods_runner.ubuntu16 +++ b/Dockerfile.irods_runner.ubuntu16 @@ -48,6 +48,7 @@ RUN \ rm -rf /var/lib/apt/lists/* /tmp/* ADD ICAT.sql / +ADD koutheir-pretty-printers.sh / ADD keep_alive.sh /keep_alive.sh RUN chmod +x /keep_alive.sh ENTRYPOINT ["/keep_alive.sh"] diff --git a/Dockerfile.irods_runner.ubuntu18 b/Dockerfile.irods_runner.ubuntu18 index c2c03b2..1739d10 100644 --- a/Dockerfile.irods_runner.ubuntu18 +++ b/Dockerfile.irods_runner.ubuntu18 @@ -59,6 +59,7 @@ RUN \ rm -rf /var/lib/apt/lists/* /tmp/* ADD ICAT.sql / +ADD koutheir-pretty-printers.sh / ADD keep_alive.sh /keep_alive.sh RUN chmod +x /keep_alive.sh ENTRYPOINT ["/keep_alive.sh"] diff --git a/README.md b/README.md index 5c44324..7e31a27 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ This repository contains tools for the running and troubleshooting of a Docker-c 1. [`valgrind`](#valgrind) 1. [`scan-build`](#scan-build) 1. ( `cppcheck`, ... ?) + 1. [Enabling GDB-style pretty printers](#enabling-gdb-style-pretty-printers) --- ## General Setup @@ -265,3 +266,51 @@ The clang static analyzer can be used when building iRODS. cmake -DCLANG_STATIC_ANALYZER=ON -GNinja .. scan-build ninja ``` +--- + +## Enabling GDB-style pretty printers + +Run the provided script to enable debug libraries and pretty printing for the libcxx versions of STL containers. + +``` +root@399b4ef584a7:~# bash /koutheir-pretty-printers.sh + ... +--> Checking out llvm and building debug libraries for cxx and cxxabi. + ... +--> Writing debug shared objects. + ... +--> Creating /root/.gdbinit for gdb and rr. + ... +``` +Then, to verify, using this file, `demo.cc`: +``` +#include +#include +int main() +{ + std::map mymap { + {"key1","value1"}, {"key2","value2"} + }; + return 0; // In rr or gdb, place breakpoint here and examine `mymap' +} +``` +compile: +``` +root@399b4ef584a7:/# /opt/irods-externals/clang6.0-0/bin/clang++ -Wl,-rpath -Wl,/opt/irods-externals/clang-runtime6.0-0/lib -stdlib=libc++ demo.cc -g +``` +and in GDB or RR, run the program. After breaking at the `return 0;` statement, look at the **map** variable - first using the pretty printers, +and then raw - to observe the difference. +``` +root@399b4ef584a7:/# /opt/debug_tools/bin/gdb a.out +(gdb) b +(gdb) r +(gdb) p mymap +$1 = std::__1::map (count=2) = {[0] "key1" = "value1", [1] "key2" = "value + +(gdb) p /r mymap +$2 = {__tree_ = {__begin_node_ = 0x608010, + __pair1_ = {*>, 0, false>> = {__value_ = { __left_ = 0x608010}}, , ... + ( ... more gobbledygook ...) + }, }}} +``` +Fortunately, the pretty printers support the great majority of data structures commonly used in iRODS code (that is: map, list, vector, string, etc.). diff --git a/koutheir-pretty-printers.sh b/koutheir-pretty-printers.sh new file mode 100644 index 0000000..6a5c94d --- /dev/null +++ b/koutheir-pretty-printers.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +[ $(id -u) = 0 ] || { echo "Please run this script as root." >&2; exit 1; } + +if [ -x /usr/bin/zypper ] ;then + pkgtool=zypper # SuSE +elif [ -x /usr/bin/yum ]; then + pkgtool=yum # CentOS, RHEL + yum install -y epel-release +else + pkgtool=apt # Debian, Ubuntu + apt update +fi + +${pkgtool} install -y make git python python3 + +# Build debug versions of stdc++ lib shared objects. + +echo >&2 -e "\n--> Checking out llvm and building debug libraries for cxx and cxxabi.\n" + +cd ~ ; git clone http://github.com/llvm/llvm-project +cd llvm-project && \ + git checkout llvmorg-6.0.0 && \ + mkdir build && \ + cd build && \ + /opt/irods-externals/cmake3.11.4-0/bin/cmake \ + -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" ../llvm && \ + make -j7 cxx cxxabi + +# backup existing shared objects and copy in the debug versions + +echo >&2 -e "\n--> Writing debug shared objects.\n" + +for SHLIB in lib/libc++*.so*; do + for DIR in /opt/irods-externals/clang{,-runtime}6.0-0/; do + [ -f $DIR/$SHLIB -o -L $DIR/$SHLIB ] && mv $DIR/$SHLIB{,.orig} + cp -rp $SHLIB $DIR/lib/. + done +done + +# Install & configure pretty-printers + +echo >&2 -e "\n--> Creating $HOME/.gdbinit for gdb and rr.\n" + +cd ~ ; git clone https://github.com/koutheir/libcxx-pretty-printers +cd libcxx-pretty-printers && git checkout "5ffbf2487bf8da7f08bc1c8650a4396d2ff15403" +PP_SRC_DIR=~/libcxx-pretty-printers/src +cp $PP_SRC_DIR/gdbinit ~/.gdbinit && sed -i -e "s@@$PP_SRC_DIR@" ~/.gdbinit + From 989a7e80e0f9d58c1f2fe15081aa7320475b6101 Mon Sep 17 00:00:00 2001 From: d-w-moore Date: Sun, 3 Jan 2021 22:42:26 -0500 Subject: [PATCH 2/6] generalize parameters in koutheir configure script --- koutheir-pretty-printers.sh | 56 ++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 10 deletions(-) mode change 100644 => 100755 koutheir-pretty-printers.sh diff --git a/koutheir-pretty-printers.sh b/koutheir-pretty-printers.sh old mode 100644 new mode 100755 index 6a5c94d..17e921a --- a/koutheir-pretty-printers.sh +++ b/koutheir-pretty-printers.sh @@ -2,6 +2,32 @@ [ $(id -u) = 0 ] || { echo "Please run this script as root." >&2; exit 1; } +CLANG_VERSION="6.0-0" +CMAKE_PREFIX="/opt/irods-externals/cmake" +LLVM_VERSION="6.0.0" +LIBCXX_PRETTY_PRINTERS_COMMIT="5ffbf2487bf8da7f08bc1c8650a4396d2ff15403" + +# determine maximum cmake version provided by iRODS externals + +cmake_max_version() ( + shopt -s nullglob + max="" + paths=(${CMAKE_PREFIX}*.*.*-*) + [ ${#paths[*]} -gt 0 ] && \ + for y in ${paths[*]}; do + max=$(get_max "${y#${CMAKE_PREFIX}}" "$max") + done + echo $max +) + +get_max() { + local z y=0 IFS=".-"; gt="" + read -a z <<<"$2" + for x in ${1}; do [ ${x:-0} -gt ${z[$((y++))]:-0} ] && gt=1; done + if [ "$gt" ]; then echo "$1" + else echo "$2"; fi +} + if [ -x /usr/bin/zypper ] ;then pkgtool=zypper # SuSE elif [ -x /usr/bin/yum ]; then @@ -12,38 +38,48 @@ else apt update fi +# Need: +# - python so that GDB and RR can load pretty printers +# - git to fetch LLVM source +# - make to build debug libraries + ${pkgtool} install -y make git python python3 # Build debug versions of stdc++ lib shared objects. echo >&2 -e "\n--> Checking out llvm and building debug libraries for cxx and cxxabi.\n" -cd ~ ; git clone http://github.com/llvm/llvm-project -cd llvm-project && \ - git checkout llvmorg-6.0.0 && \ +CMAKE_VERSION=$(cmake_max_version) + +if [ -n "${CMAKE_VERSION}" ]; then + cd ~ ; git clone http://github.com/llvm/llvm-project + cd llvm-project && \ + git checkout llvmorg-${LLVM_VERSION} && \ mkdir build && \ cd build && \ - /opt/irods-externals/cmake3.11.4-0/bin/cmake \ + ${CMAKE_PREFIX}${CMAKE_VERSION}/bin/cmake \ -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" ../llvm && \ make -j7 cxx cxxabi +else + echo >&2 "Need at least one irods-externals-cmake* package installed" + exit 1 +fi # backup existing shared objects and copy in the debug versions echo >&2 -e "\n--> Writing debug shared objects.\n" - for SHLIB in lib/libc++*.so*; do - for DIR in /opt/irods-externals/clang{,-runtime}6.0-0/; do - [ -f $DIR/$SHLIB -o -L $DIR/$SHLIB ] && mv $DIR/$SHLIB{,.orig} - cp -rp $SHLIB $DIR/lib/. + for DIR in /opt/irods-externals/clang{,-runtime}${CLANG_VERSION}/; do + [ -f "$DIR/$SHLIB" -o -L "$DIR/$SHLIB" ] && mv "$DIR/$SHLIB"{,.orig} + cp -rp "$SHLIB" "$DIR"/lib/. done done # Install & configure pretty-printers echo >&2 -e "\n--> Creating $HOME/.gdbinit for gdb and rr.\n" - cd ~ ; git clone https://github.com/koutheir/libcxx-pretty-printers -cd libcxx-pretty-printers && git checkout "5ffbf2487bf8da7f08bc1c8650a4396d2ff15403" +cd libcxx-pretty-printers && git checkout "${LIBCXX_PRETTY_PRINTERS_COMMIT}" PP_SRC_DIR=~/libcxx-pretty-printers/src cp $PP_SRC_DIR/gdbinit ~/.gdbinit && sed -i -e "s@@$PP_SRC_DIR@" ~/.gdbinit From f05d7db686cd8b06031983e6a7e0d3499be7f01c Mon Sep 17 00:00:00 2001 From: d-w-moore Date: Wed, 6 Jan 2021 09:50:18 -0500 Subject: [PATCH 3/6] generalize for max version of named package/dir pattern --- koutheir-pretty-printers.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/koutheir-pretty-printers.sh b/koutheir-pretty-printers.sh index 17e921a..ae94374 100755 --- a/koutheir-pretty-printers.sh +++ b/koutheir-pretty-printers.sh @@ -7,27 +7,39 @@ CMAKE_PREFIX="/opt/irods-externals/cmake" LLVM_VERSION="6.0.0" LIBCXX_PRETTY_PRINTERS_COMMIT="5ffbf2487bf8da7f08bc1c8650a4396d2ff15403" -# determine maximum cmake version provided by iRODS externals +CMAKE_PREFIX="/opt/irods-externals/cmake" +CLANG_PREFIX="/opt/irods-externals/clang" +CLANG_RUNTIME_PREFIX="/opt/irods-externals/clang-runtime" + +# package_max_version determine the maximum of several versions of a package in iRODS externals -cmake_max_version() ( +package_max_version() ( # deliberate subshell + [ -z "$1" ] && exit + PACKAGE_PREFIX=$1 shopt -s nullglob + version_string_pattern="[0-9][-.0-9]*" max="" - paths=(${CMAKE_PREFIX}*.*.*-*) + paths=( ${PACKAGE_PREFIX}${version_string_pattern} ) [ ${#paths[*]} -gt 0 ] && \ for y in ${paths[*]}; do - max=$(get_max "${y#${CMAKE_PREFIX}}" "$max") + max=$(get_max "${y#${PACKAGE_PREFIX}}" "$max") done echo $max ) get_max() { - local z y=0 IFS=".-"; gt="" + local z y=0 gt="" + local IFS=".-" # for splitting version numbers of the form "X[-.]Y..." into (X,Y,...) read -a z <<<"$2" for x in ${1}; do [ ${x:-0} -gt ${z[$((y++))]:-0} ] && gt=1; done if [ "$gt" ]; then echo "$1" else echo "$2"; fi } +LATEST_CLANG_RUNTIME=$(package_max_version $CLANG_RUNTIME_PREFIX) +echo $Y +exit 0; + if [ -x /usr/bin/zypper ] ;then pkgtool=zypper # SuSE elif [ -x /usr/bin/yum ]; then From ede49ff088597228e033de45cc3e1cd90a56f37d Mon Sep 17 00:00:00 2001 From: d-w-moore Date: Wed, 6 Jan 2021 17:28:10 -0500 Subject: [PATCH 4/6] generalization of script for CLANG,LLVM choice --- koutheir-pretty-printers.sh | 50 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/koutheir-pretty-printers.sh b/koutheir-pretty-printers.sh index ae94374..c5b1f0a 100755 --- a/koutheir-pretty-printers.sh +++ b/koutheir-pretty-printers.sh @@ -1,23 +1,33 @@ #!/bin/bash +if [ ${CHK-1} ] ; then [ $(id -u) = 0 ] || { echo "Please run this script as root." >&2; exit 1; } +fi -CLANG_VERSION="6.0-0" -CMAKE_PREFIX="/opt/irods-externals/cmake" -LLVM_VERSION="6.0.0" -LIBCXX_PRETTY_PRINTERS_COMMIT="5ffbf2487bf8da7f08bc1c8650a4396d2ff15403" +# -- BEGIN CONFIGURATION OPTIONS -- CMAKE_PREFIX="/opt/irods-externals/cmake" CLANG_PREFIX="/opt/irods-externals/clang" CLANG_RUNTIME_PREFIX="/opt/irods-externals/clang-runtime" -# package_max_version determine the maximum of several versions of a package in iRODS externals +declare -A LLVM_TO_KOUTHEIR_VERSION_LOOKUP=( + ["6.0.0"]="5ffbf2487bf8da7f08bc1c8650a4396d2ff15403" +) +# -- END CONFIGURATION OPTIONS -- + +# +# package_max_version determine the maximum of several versions of a package in iRODS externals +# package_max_version() ( # deliberate subshell [ -z "$1" ] && exit PACKAGE_PREFIX=$1 shopt -s nullglob - version_string_pattern="[0-9][-.0-9]*" + if [ -n "$2" ]; then + version_string_pattern="$2" + else + version_string_pattern="[0-9][-.0-9]*" + fi max="" paths=( ${PACKAGE_PREFIX}${version_string_pattern} ) [ ${#paths[*]} -gt 0 ] && \ @@ -27,7 +37,7 @@ package_max_version() ( # deliberate subshell echo $max ) -get_max() { +get_max() { # -- get max of two (X,Y,Z) tuples -- local z y=0 gt="" local IFS=".-" # for splitting version numbers of the form "X[-.]Y..." into (X,Y,...) read -a z <<<"$2" @@ -36,9 +46,21 @@ get_max() { else echo "$2"; fi } +CLANG_VERSION=$(package_max_version $CLANG_PREFIX) +if [ -z "$CLANG_VERSION" ] ; then + echo >&2 "ERROR - no Clang compiler found among installed irods-externals*" + exit 2 +fi +LLVM_VERSION=$(echo "$CLANG_VERSION" | sed 's/[-.]/./g') + +LIBCXX_PRETTY_PRINTERS_COMMIT=${LLVM_TO_KOUTHEIR_VERSION_LOOKUP[$LLVM_VERSION]} + +if [ -z "$LIBCXX_PRETTY_PRINTERS_COMMIT" ]; then + echo >&2 "WARNING - no optimal version of libc++ Pretty-Printers found." + echo >&2 " Using the default branch" +fi + LATEST_CLANG_RUNTIME=$(package_max_version $CLANG_RUNTIME_PREFIX) -echo $Y -exit 0; if [ -x /usr/bin/zypper ] ;then pkgtool=zypper # SuSE @@ -61,7 +83,7 @@ ${pkgtool} install -y make git python python3 echo >&2 -e "\n--> Checking out llvm and building debug libraries for cxx and cxxabi.\n" -CMAKE_VERSION=$(cmake_max_version) +CMAKE_VERSION=$(package_max_version $CMAKE_PREFIX) if [ -n "${CMAKE_VERSION}" ]; then cd ~ ; git clone http://github.com/llvm/llvm-project @@ -89,9 +111,15 @@ done # Install & configure pretty-printers +if [ -z "${LIBCXX_PRETTY_PRINTERS_COMMIT}" ]; then + GIT_PPRINTER_CHECKOUT_CMD=":" +else + GIT_PPRINTER_CHECKOUT_CMD="git checkout '${LIBCXX_PRETTY_PRINTERS_COMMIT}'" +fi + echo >&2 -e "\n--> Creating $HOME/.gdbinit for gdb and rr.\n" cd ~ ; git clone https://github.com/koutheir/libcxx-pretty-printers -cd libcxx-pretty-printers && git checkout "${LIBCXX_PRETTY_PRINTERS_COMMIT}" +cd libcxx-pretty-printers && eval "$GIT_PPRINTER_CHECKOUT_CMD" PP_SRC_DIR=~/libcxx-pretty-printers/src cp $PP_SRC_DIR/gdbinit ~/.gdbinit && sed -i -e "s@@$PP_SRC_DIR@" ~/.gdbinit From 699814bc7e3cd49f2848f23ef4cf4ce09efb7d41 Mon Sep 17 00:00:00 2001 From: d-w-moore Date: Thu, 7 Jan 2021 09:38:48 -0500 Subject: [PATCH 5/6] improvements includeing clang version hint --- koutheir-pretty-printers.sh | 88 +++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/koutheir-pretty-printers.sh b/koutheir-pretty-printers.sh index c5b1f0a..e24af93 100755 --- a/koutheir-pretty-printers.sh +++ b/koutheir-pretty-printers.sh @@ -1,11 +1,14 @@ #!/bin/bash -if [ ${CHK-1} ] ; then -[ $(id -u) = 0 ] || { echo "Please run this script as root." >&2; exit 1; } +# ***** While CHECK_* macros are still here, we are still testing :) . + +if [ -n "${CHECK_USER-1}" ] ; then # TODO - remove this if clause + [ $(id -u) = 0 ] || { echo "Please run this script as root." >&2; exit 1; } fi -# -- BEGIN CONFIGURATION OPTIONS -- +# -- Configuration Values. +CLANG_VERSION_HINT="6.*" CMAKE_PREFIX="/opt/irods-externals/cmake" CLANG_PREFIX="/opt/irods-externals/clang" CLANG_RUNTIME_PREFIX="/opt/irods-externals/clang-runtime" @@ -14,10 +17,19 @@ declare -A LLVM_TO_KOUTHEIR_VERSION_LOOKUP=( ["6.0.0"]="5ffbf2487bf8da7f08bc1c8650a4396d2ff15403" ) -# -- END CONFIGURATION OPTIONS -- +# -- Process Command Line Options. + +eval "set --$(/usr/bin/getopt --longoptions "clang-version-hint:" --options "c:" -- "$@")" +for option in "$@"; do + case $option in + --clang-version-hint|-c) CLANG_VERSION_HINT=$2 ; shift 2 ;; + *) shift; break;; + esac +done # -# package_max_version determine the maximum of several versions of a package in iRODS externals +# -- Function package_max_version +# To determine the maximum of several versions of a package in iRODS externals # package_max_version() ( # deliberate subshell [ -z "$1" ] && exit @@ -46,30 +58,30 @@ get_max() { # -- get max of two (X,Y,Z) tuples -- else echo "$2"; fi } -CLANG_VERSION=$(package_max_version $CLANG_PREFIX) +CLANG_VERSION=$(package_max_version $CLANG_PREFIX "$CLANG_VERSION_HINT") + if [ -z "$CLANG_VERSION" ] ; then echo >&2 "ERROR - no Clang compiler found among installed irods-externals*" exit 2 fi + LLVM_VERSION=$(echo "$CLANG_VERSION" | sed 's/[-.]/./g') LIBCXX_PRETTY_PRINTERS_COMMIT=${LLVM_TO_KOUTHEIR_VERSION_LOOKUP[$LLVM_VERSION]} if [ -z "$LIBCXX_PRETTY_PRINTERS_COMMIT" ]; then - echo >&2 "WARNING - no optimal version of libc++ Pretty-Printers found." - echo >&2 " Using the default branch" + echo >&2 "WARNING - no optimal version of libc++ Pretty-Printers found." + echo >&2 " Using the default branch" fi -LATEST_CLANG_RUNTIME=$(package_max_version $CLANG_RUNTIME_PREFIX) - if [ -x /usr/bin/zypper ] ;then - pkgtool=zypper # SuSE + pkgtool=zypper # SuSE elif [ -x /usr/bin/yum ]; then - pkgtool=yum # CentOS, RHEL - yum install -y epel-release + pkgtool=yum # CentOS, RHEL + yum install -y epel-release else - pkgtool=apt # Debian, Ubuntu - apt update + pkgtool=apt # Debian, Ubuntu + apt update fi # Need: @@ -84,6 +96,28 @@ ${pkgtool} install -y make git python python3 echo >&2 -e "\n--> Checking out llvm and building debug libraries for cxx and cxxabi.\n" CMAKE_VERSION=$(package_max_version $CMAKE_PREFIX) +CLANG_PATH=${CLANG_PREFIX}${CLANG_VERSION} +CLANG_RUNTIME_PATH=${CLANG_RUNTIME_PREFIX}${CLANG_VERSION} + + +if [ ! -d "$CLANG_RUNTIME_PATH" ]; then + echo >&2 "Warning - No clang runtime corresponding to clang '${CLANG_VERSION}'." + echo >&2 " Please install it before running this script." + exit 3 +fi + +CMAKE_VERSION=$(package_max_version $CMAKE_PREFIX) + +# +# Print debug values and quit if requested by CHECK_QUIT != "" - TODO - remove this +# +if [ -n "${CHECK_QUIT}" ] ; then + echo CMAKE_VERSION "($CMAKE_VERSION)" + echo CLANG_PATH "($CLANG_PATH)" + echo CLANG_RUNTIME_PATH "($CLANG_RUNTIME_PATH)" + echo LIBCXX_PRETTY_PRINTERS_COMMIT "($LIBCXX_PRETTY_PRINTERS_COMMIT)" + exit 10 +fi if [ -n "${CMAKE_VERSION}" ]; then cd ~ ; git clone http://github.com/llvm/llvm-project @@ -95,11 +129,11 @@ if [ -n "${CMAKE_VERSION}" ]; then -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" ../llvm && \ make -j7 cxx cxxabi else - echo >&2 "Need at least one irods-externals-cmake* package installed" - exit 1 + echo >&2 "Error - Need at least one irods-externals-cmake* package installed" + exit 4 fi -# backup existing shared objects and copy in the debug versions +# -- Backup existing shared objects and copy debug versions in to replace them. echo >&2 -e "\n--> Writing debug shared objects.\n" for SHLIB in lib/libc++*.so*; do @@ -109,7 +143,7 @@ for SHLIB in lib/libc++*.so*; do done done -# Install & configure pretty-printers +# -- Install & configure pretty-printers if [ -z "${LIBCXX_PRETTY_PRINTERS_COMMIT}" ]; then GIT_PPRINTER_CHECKOUT_CMD=":" @@ -118,8 +152,18 @@ else fi echo >&2 -e "\n--> Creating $HOME/.gdbinit for gdb and rr.\n" + cd ~ ; git clone https://github.com/koutheir/libcxx-pretty-printers -cd libcxx-pretty-printers && eval "$GIT_PPRINTER_CHECKOUT_CMD" -PP_SRC_DIR=~/libcxx-pretty-printers/src -cp $PP_SRC_DIR/gdbinit ~/.gdbinit && sed -i -e "s@@$PP_SRC_DIR@" ~/.gdbinit +if cd libcxx-pretty-printers +then + if ! eval "$GIT_PPRINTER_CHECKOUT_CMD" ; then + echo >&2 "Error - Could not find pretty printers repository directory." + exit 5 + fi + PP_SRC_DIR=~/libcxx-pretty-printers/src + cp $PP_SRC_DIR/gdbinit ~/.gdbinit && sed -i -e "s@@$PP_SRC_DIR@" ~/.gdbinit +else + echo >&2 "Error - Could not find pretty printers repository directory." + exit 6 +fi From a926e9da3837a65ce466838c0d45e90b036d8fc9 Mon Sep 17 00:00:00 2001 From: d-w-moore Date: Thu, 7 Jan 2021 16:34:10 -0500 Subject: [PATCH 6/6] codacy --- koutheir-pretty-printers.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/koutheir-pretty-printers.sh b/koutheir-pretty-printers.sh index e24af93..cf2af64 100755 --- a/koutheir-pretty-printers.sh +++ b/koutheir-pretty-printers.sh @@ -46,14 +46,14 @@ package_max_version() ( # deliberate subshell for y in ${paths[*]}; do max=$(get_max "${y#${PACKAGE_PREFIX}}" "$max") done - echo $max + echo "$max" ) get_max() { # -- get max of two (X,Y,Z) tuples -- local z y=0 gt="" local IFS=".-" # for splitting version numbers of the form "X[-.]Y..." into (X,Y,...) read -a z <<<"$2" - for x in ${1}; do [ ${x:-0} -gt ${z[$((y++))]:-0} ] && gt=1; done + for x in ${1}; do [ "${x:-0}" -gt "${z[$((y++))]:-0}" ] && gt=1; done if [ "$gt" ]; then echo "$1" else echo "$2"; fi } @@ -65,7 +65,7 @@ if [ -z "$CLANG_VERSION" ] ; then exit 2 fi -LLVM_VERSION=$(echo "$CLANG_VERSION" | sed 's/[-.]/./g') +LLVM_VERSION=${CLANG_VERSION//[-.]/.} LIBCXX_PRETTY_PRINTERS_COMMIT=${LLVM_TO_KOUTHEIR_VERSION_LOOKUP[$LLVM_VERSION]} @@ -122,10 +122,10 @@ fi if [ -n "${CMAKE_VERSION}" ]; then cd ~ ; git clone http://github.com/llvm/llvm-project cd llvm-project && \ - git checkout llvmorg-${LLVM_VERSION} && \ + git checkout "llvmorg-${LLVM_VERSION}" && \ mkdir build && \ cd build && \ - ${CMAKE_PREFIX}${CMAKE_VERSION}/bin/cmake \ + "${CMAKE_PREFIX}${CMAKE_VERSION}/bin/cmake" \ -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" ../llvm && \ make -j7 cxx cxxabi else