Created
April 11, 2020 16:57
-
-
Save salewski/0df6a5684dc73e4792b4124b53218a29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Downloads and unpacks (in subdirs of the current directory) all of the | |
# Debian source packages associated with the *-dbgsym and *-dbg packages whose | |
# symbols are referenced by the specified program ('/usr/bin/someprogram' in | |
# the snippet below). Takes pains to ensure the downloaded source packages are | |
# at the exact same version number as the corresponding *-dbgsym/*-dbg | |
# packages. | |
# | |
# Assumes you are in the directory beneath which you would like the sources to | |
# be unpacked (by 'apt-get source'). Each unique package will have a separate | |
# subdirectory. We are not clever about avoiding duplicates, but 'apt-get source' | |
# already is. | |
# | |
# Motivation: | |
# ----------- | |
# Helps prepare for a gdb(1) debugging session for a given program (assuming | |
# that program was installed by the Debian packaging system). Easier than | |
# manually tracking down all dependencies manually. For such work, you need | |
# the debug symbols for all dependencies (provided in the *-dbgsym or *-dbg | |
# packages) and also the source code (the part fetched by this gist). | |
# | |
# For the most part, gdb(1) will automatically find the debug symbols from the | |
# installed *-dbgsym and *-dbg packages, but you will need to use one or more | |
# gdb 'directory' commands to tell it where the source code lives (for use by | |
# the gdb 'list' command, and similar). | |
# | |
# Background context: | |
# ------------------- | |
# The 'find-dbgsym-packages(1)' program comes from the 'debian-goodies' Debian | |
# package, but its default behavior (as provided by debian-goodies-0.84) is to | |
# only print the names of *-dbgsym and *-dbg packages that are not already | |
# installed. Internally, it is using the `eu-unstrip' program (provided by the | |
# 'elfutils' package) to decide whether or not to print the *-dbgsym/*-dbg | |
# package name for a given dependency by parsing the output of this | |
# invocation: | |
# | |
# eu-unstrip --list-only --executable | |
# | |
# The 'find-dbgsym-package' program explicitly filters out the names of the | |
# packages when it detects their associated debug symbols are already present. | |
# | |
# This gist uses a quick 'n dirty modified version that does not do that | |
# filtering out: | |
# | |
# $ diff tt/find-dbgsym-packages tt/find-dbgsym-packages-ALJUNK-HACKED-TO-NOT-IGNORE-ALREADY-INSTALLED-DBGSYM-PACKAGES | |
# 116,118c116,118 | |
# < if ($debug ne '-') { | |
# < next; | |
# < } | |
# --- | |
# > # if ($debug ne '-') { | |
# > # next; | |
# > # } | |
# | |
# Single line, for easier copy/pasting: | |
# | |
$ ./tt/find-dbgsym-packages-ALJUNK-HACKED-TO-NOT-IGNORE-ALREADY-INSTALLED-DBGSYM-PACKAGES /usr/bin/someprogram | tr ' ' '\n' | while read -r pkg_dbgsym; do pkg_raw=$(echo "${pkg_dbgsym}" | sed -e 's/^\(.\{1,\}\)[-]\(dbg\|dbgsym\)$/\1/'); echo $pkg_raw; done | while read -r pkg; do iver=$(dpkg-query --show --showformat '${Version}' "${pkg}"); ( set -x; test -d "./${pkg}-${iver}" || apt-get source ${pkg}=${iver} && sleep 2); done | |
# Multiple lines, for better readability here: | |
# | |
$ ./tt/find-dbgsym-packages-ALJUNK-HACKED-TO-NOT-IGNORE-ALREADY-INSTALLED-DBGSYM-PACKAGES /usr/bin/someprogram \ | |
> | tr ' ' '\n' \ | |
> | while read -r pkg_dbgsym; do | |
> pkg_raw=$(echo "${pkg_dbgsym}" \ | |
> | sed -e 's/^\(.\{1,\}\)[-]\(dbg\|dbgsym\)$/\1/' \ | |
> );\ | |
> echo $pkg_raw ;\ | |
> done \ | |
> | while read -r pkg; do | |
> iver=$(dpkg-query --show --showformat '${Version}' "${pkg}"); | |
> ( set -x; \ | |
> test -d "./${pkg}-${iver}" || apt-get source ${pkg}=${iver} && sleep 2 | |
> );\ | |
> done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment