glibc-all-in-one icon indicating copy to clipboard operation
glibc-all-in-one copied to clipboard

Solve the problem of no debugging symbols in high versions of glibc

Open b0ldfrev opened this issue 3 years ago • 9 comments

Solve the problem of no debugging symbols in high versions of glibc

Add cp -r $tmp/usr/lib/debug/.build-id/* /usr/lib/debug/.build-id/ 2>/dev/null to the line above the rm -rf $tmp command of the extract file.

--- extract	2022-10-31 15:36:48.748430597 +0800
+++ extract-patch	2022-10-31 15:42:27.990103399 +0800
@@ -33,8 +33,9 @@
       || cp -rP $tmp/usr/lib/debug/lib/*/* $out 2>/dev/null \
       || cp -rP $tmp/usr/lib/debug/lib32/* $out 2>/dev/null \
       || cp -rP $tmp/usr/lib/debug/.build-id $out 2>/dev/null \
-      || die "Failed to save. Check it manually $tmp"
+      || die "Failed to save. Check it manually $tmp"   
 
+    cp -r  $tmp/usr/lib/debug/.build-id/* /usr/lib/debug/.build-id/ 2>/dev/null
     rm -rf $tmp
 }


The extract script after patch is as follows

#!/bin/bash
cd "$(dirname "$0")"

die() {
  echo >&2 $1
  exit 1
}

usage() {
  echo -e >&2 "Usage: $0 deb output"
  exit 2
}

extract() {
    local deb=`readlink -f $1`
    local out=$2
    if [ ! -d "$out" ]; then
        mkdir $out
    fi
    local tmp=`mktemp -d`

    cd $tmp
    ar xv $deb || die "ar failed"
    if [ -f "data.tar.zst" ];then
        tar -I zstd -xf data.tar.* || die "tar failed"
    else
        tar xf data.tar.* || die "tar failed"
    fi
    cd -

    cp -rP $tmp/lib/*/* $out 2>/dev/null \
      || cp -rP $tmp/lib32/* $out 2>/dev/null \
      || cp -rP $tmp/usr/lib/debug/lib/*/* $out 2>/dev/null \
      || cp -rP $tmp/usr/lib/debug/lib32/* $out 2>/dev/null \
      || cp -rP $tmp/usr/lib/debug/.build-id $out 2>/dev/null \
      || die "Failed to save. Check it manually $tmp"
    
    cp -r  $tmp/usr/lib/debug/.build-id/* /usr/lib/debug/.build-id/ 2>/dev/null
    rm -rf $tmp
}

if [[ $# -ne 2 ]]; then
    usage
fi

extract "$1" "$2"

Note: Because files will be copied to the .build-id directory of the system, root privileges are required every time you run ./download.

Upgrade GDB version (may be required)

If your environment is ubuntu16 or 18, then the default GDB version is lower (GDB < 8.3) and does not support parsing the symbol files in .build-id. In this case, you need to upgrade the GDB version.

Version 9.2 is recommended, use the following methods to complete the upgrade

apt install texinfo
cp `which gdb` `which gdb`-old
cp `which gdbserver` `which gdbserver`-old
wegt http://ftp.gnu.org/gnu/gdb/gdb-9.2.tar.gz
tar -xzvf  gdb-9.2.tar.gz 
cd gdb-9.2 && mkdir build && cd build
../configure --with-python=`which python3` --enable-targets=all
make && make install

b0ldfrev avatar Oct 31 '22 08:10 b0ldfrev

@b0ldfrev Many thanks. It will be great if you create a pull request and become a contributer.

matrix1001 avatar Oct 31 '22 08:10 matrix1001

As for the problem of GDB, maybe you can write it down in the README within your PR?

matrix1001 avatar Oct 31 '22 08:10 matrix1001

@b0ldfrev Many thanks. It will be great if you create a pull request and become a contributer.

ok , i will do this.

b0ldfrev avatar Oct 31 '22 08:10 b0ldfrev

#18 it may not be a good idea to copy '.build-id' to '/usr/lib/debug/.build-id/',since it corrupts the system debug symbols. as you point out, just updating gdb can solve the problem?

matrix1001 avatar Nov 01 '22 14:11 matrix1001

#18 it may not be a good idea to copy '.build-id' to '/usr/lib/debug/.build-id/',since it corrupts the system debug symbols. as you point out, just updating gdb can solve the problem?

Copying .build-id to the system directory will not overwrite the original system debug symbols, because the version id are completely different. If there are two symbol files with the same name, that means that the two files and symbols are consistent. In fact, GDB can " set debug-file-directory" to specify the symbol directory, but this can only be loaded when the program is initialized, and will not work when the attached process is debugged.

b0ldfrev avatar Nov 02 '22 01:11 b0ldfrev

your solution is correct. however, for security reasons, i don't want others to use my tool under root previledge only. can you provide a solution to let users decide? maybe add a command line option?

matrix1001 avatar Nov 02 '22 13:11 matrix1001

your solution is correct. however, for security reasons, i don't want others to use my tool under root previledge only. can you provide a solution to let users decide? maybe add a command line option?

Do you mean to add a Usage to the download program to illustrate the situation?

b0ldfrev avatar Nov 04 '22 03:11 b0ldfrev

correct. for eample: ./download glibc-2.23 --system

matrix1001 avatar Nov 07 '22 13:11 matrix1001

thanks,it's working

YYL-DUCK avatar Jul 22 '23 15:07 YYL-DUCK