-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Files for GDB-coreutils dem that illustrate ELF startup
Copying compile_coreutils.sh and gdb-coreutils.txt to the same directory and then executing the script downloads the glibc and coreutils source, compiles coreutils, and illustrates ELF startup with GDB. Inspired by https://0xax.gitbooks.io/linux-insides/content/Misc/program_startup.html, which is now a bit out of date.
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
# | ||
set -u | ||
set -e | ||
|
||
if [[ ! -n $(which gcc) || ! -n $(which gdb) ]]; then | ||
echo "Install gcc and gdb to proceed." | ||
exit 1 | ||
else | ||
echo "Found GCC and GDB, proceeding." | ||
fi | ||
# This demo would also likely work on derivatives like Mint or Ubuntu. | ||
if [[ ! -f /etc/debian_version ]]; then | ||
echo "Sorry, this is a Debian demo." | ||
else | ||
echo "Confirmed Debian, proceeding." | ||
fi | ||
readonly GDBFILE="$(readlink -f gdb-coreutils.txt)" | ||
if [[ ! -n "$GDBFILE" ]]; then | ||
echo "GDB commands file is missing." | ||
exit 1 | ||
else | ||
echo "Found GDB commands file." | ||
fi | ||
|
||
readonly TESTDIR=./coreutils | ||
mkdir "$TESTDIR" | ||
|
||
# Install glibc sources. | ||
cd "$TESTDIR" | ||
echo "Getting glibc source." | ||
apt-get -q source glibc | ||
# du -hcs glibc-2.24/ | ||
# 225M glibc-2.24/ | ||
readonly GLIBCDIR="$(find . -name "glibc*" -type d)" | ||
|
||
# Compile coreutils. | ||
echo "Getting coreutils source." | ||
apt-get -q source coreutils | ||
TARBALL="$(ls coreutils*orig.tar.xz)" | ||
tar xfJ "$TARBALL" | ||
readonly COREUTILSDIR="$(find . -name "coreutils-*" -type d)" | ||
|
||
# Build coreutils. | ||
cd "$COREUTILSDIR" | ||
echo "Configuring coreutils" | ||
# Semicolon matters; 'configure' seems to eat the next line otherwise. | ||
./configure -q; echo "Compiling coreutils" | ||
make -s | ||
|
||
# Run coreutils under GDB. | ||
ln -s "$(readlink -f ../"$GLIBCDIR"/sysdeps)" ../sysdeps | ||
ln -s "$(readlink -f ../"$GLIBCDIR"/csu)" ../csu | ||
gdb --command="$GDBFILE" src/date |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# GDB commands to examine the start-up of an ELF binary with glibc. | ||
# Inspired by https://0xax.gitbooks.io/linux-insides/content/Misc/program_startup.html, | ||
# which is a bit out-of-date. | ||
run | ||
info functions | ||
b _init | ||
run | ||
l 40,100 | ||
# Also interesting: | ||
# info files | ||
# Then break at "Entry point": | ||
# b *(0x????) | ||
# or, "info address _start" | ||
|