Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
b0ldfrev opened this issue Oct 31, 2022 · 9 comments
Open

Comments

@b0ldfrev
Copy link

b0ldfrev commented Oct 31, 2022

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 b0ldfrev changed the title 解决高版本glibc无调试符号问题 Solve the problem of no debugging symbols in high versions of glibc Oct 31, 2022
@matrix1001
Copy link
Owner

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

@matrix1001
Copy link
Owner

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

@b0ldfrev
Copy link
Author

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

ok , i will do this.

@matrix1001
Copy link
Owner

#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?

@b0ldfrev
Copy link
Author

b0ldfrev commented Nov 2, 2022

#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.

@matrix1001
Copy link
Owner

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?

@b0ldfrev
Copy link
Author

b0ldfrev commented Nov 4, 2022

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?

@matrix1001
Copy link
Owner

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

@YYL-DUCK
Copy link

thanks,it's working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants