mirror of https://github.com/pwndbg/pwndbg
Format shell scripts with shfmt (#1123)
* Add lint.sh script * Format shell scripts with shfmt and add to lint.sh Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
This commit is contained in:
parent
2b62259d7e
commit
cc50024417
|
@ -23,6 +23,7 @@ jobs:
|
|||
pip install isort
|
||||
pip install black
|
||||
pip install flake8
|
||||
sudo snap install shfmt
|
||||
|
||||
- name: Run linters
|
||||
run: |
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
cat > $1.rst <<EOF
|
||||
cat >$1.rst <<EOF
|
||||
:mod:\`pwndbg.$1\` --- pwndbg.$1
|
||||
=============================================
|
||||
|
||||
|
|
3
lint.sh
3
lint.sh
|
@ -6,3 +6,6 @@ set -o errexit
|
|||
isort --check-only --diff pwndbg tests
|
||||
black --diff --check pwndbg tests
|
||||
flake8 --show-source pwndbg tests
|
||||
|
||||
# Indents are four spaces, binary ops can start a line, and indent switch cases
|
||||
shfmt -i 4 -bn -ci -d .
|
|
@ -1,13 +1,13 @@
|
|||
#!/bin/bash
|
||||
# Benchmark context command
|
||||
make test > /dev/null
|
||||
make test >/dev/null
|
||||
git log --abbrev-commit --pretty=oneline HEAD^..HEAD
|
||||
gdb ./test \
|
||||
-ex "source ../gdbinit.py" \
|
||||
-ex "b main" -ex "r" \
|
||||
-ex "python import timeit; print(' 1ST RUN:', timeit.repeat('pwndbg.commands.context.context()', repeat=1, number=1, globals=globals())[0])" \
|
||||
-ex "si" \
|
||||
-ex "python import timeit; print(' 2ND RUN:', timeit.repeat('pwndbg.commands.context.context()', repeat=1, number=1, globals=globals())[0])" \
|
||||
-ex "si" \
|
||||
-ex "python import timeit; print('MULTIPLE RUNS:', timeit.repeat('pwndbg.commands.context.context()', repeat=1, number=10, globals=globals())[0] / 10)" \
|
||||
-ex "quit" | grep 'RUNS*:'
|
||||
-ex "source ../gdbinit.py" \
|
||||
-ex "b main" -ex "r" \
|
||||
-ex "python import timeit; print(' 1ST RUN:', timeit.repeat('pwndbg.commands.context.context()', repeat=1, number=1, globals=globals())[0])" \
|
||||
-ex "si" \
|
||||
-ex "python import timeit; print(' 2ND RUN:', timeit.repeat('pwndbg.commands.context.context()', repeat=1, number=1, globals=globals())[0])" \
|
||||
-ex "si" \
|
||||
-ex "python import timeit; print('MULTIPLE RUNS:', timeit.repeat('pwndbg.commands.context.context()', repeat=1, number=10, globals=globals())[0] / 10)" \
|
||||
-ex "quit" | grep 'RUNS*:'
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
if ! (( $# )); then
|
||||
cat <<- _EOF_
|
||||
if ! (($#)); then
|
||||
cat <<-_EOF_
|
||||
$0: [profile-script]
|
||||
|
||||
Example: $0 context.py
|
||||
_EOF_
|
||||
exit 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
module=$(basename "${1/.py/}")
|
||||
basedir=$(dirname "$0")
|
||||
|
||||
# Quick and dirty script to profile pwndbg using cProfile.
|
||||
make -C "${basedir}" test > /dev/null
|
||||
make -C "${basedir}" test >/dev/null
|
||||
|
||||
gdb "${basedir}/test" \
|
||||
-ex "source ${basedir}/../gdbinit.py" \
|
||||
-ex "b main" \
|
||||
-ex "r" \
|
||||
-ex "python
|
||||
-ex "source ${basedir}/../gdbinit.py" \
|
||||
-ex "b main" \
|
||||
-ex "r" \
|
||||
-ex "python
|
||||
import cProfile;
|
||||
import profiling.${module} as profile;
|
||||
profile.warmup();
|
||||
cProfile.run('profile.run()', '${basedir}/stats')" \
|
||||
-ex "quit"
|
||||
-ex "quit"
|
||||
|
||||
python3 -c "
|
||||
import pstats
|
||||
|
@ -33,7 +33,7 @@ p.strip_dirs().sort_stats('tottime').print_stats(20)
|
|||
"
|
||||
|
||||
if command -v pyprof2calltree >/dev/null 2>&1 && command -v kcachegrind >/dev/null 2>&1; then
|
||||
pyprof2calltree -k -i "${basedir}/stats"
|
||||
pyprof2calltree -k -i "${basedir}/stats"
|
||||
fi
|
||||
|
||||
# vim: ts=4 sw=4 noet
|
||||
|
|
|
@ -16,63 +16,63 @@ echo "ZIGPATH set to $ZIGPATH"
|
|||
# lets overwrite it with a function that just executes things passed to sudo
|
||||
# (yeah it won't work for sudo executed with flags)
|
||||
if ! hash sudo 2>/dev/null && whoami | grep root; then
|
||||
sudo() {
|
||||
${*}
|
||||
}
|
||||
sudo() {
|
||||
${*}
|
||||
}
|
||||
fi
|
||||
|
||||
linux() {
|
||||
uname | grep -i Linux &>/dev/null
|
||||
uname | grep -i Linux &>/dev/null
|
||||
}
|
||||
|
||||
install_apt() {
|
||||
sudo apt-get update || true
|
||||
sudo apt-get install -y \
|
||||
nasm \
|
||||
gcc \
|
||||
libc6-dev \
|
||||
curl \
|
||||
build-essential \
|
||||
gdb
|
||||
test -f /usr/bin/go || sudo apt-ge\t install -y golang
|
||||
sudo apt-get update || true
|
||||
sudo apt-get install -y \
|
||||
nasm \
|
||||
gcc \
|
||||
libc6-dev \
|
||||
curl \
|
||||
build-essential \
|
||||
gdb
|
||||
test -f /usr/bin/go || sudo apt-ge\t install -y golang
|
||||
|
||||
# Install zig to current directory
|
||||
# We use zig to compile some test binaries as it is much easier than with gcc
|
||||
# Install zig to current directory
|
||||
# We use zig to compile some test binaries as it is much easier than with gcc
|
||||
|
||||
ZIG_TAR_URL="https://ziglang.org/builds/zig-linux-x86_64-0.10.0-dev.3685+dae7aeb33.tar.xz"
|
||||
ZIG_TAR_SHA256="dfc8f5ecb651342f1fc2b2828362b62f74fadac9931bda785b80bf7ecfcfabb2"
|
||||
curl --output /tmp/zig.tar.xz "${ZIG_TAR_URL}"
|
||||
ACTUAL_SHA256=$(sha256sum /tmp/zig.tar.xz | cut -d' ' -f1)
|
||||
if [ "${ACTUAL_SHA256}" != "${ZIG_TAR_SHA256}" ]; then
|
||||
echo "Zig binary checksum mismatch"
|
||||
echo "Expected: ${ZIG_TAR_SHA256}"
|
||||
echo "Actual: ${ACTUAL_SHA256}"
|
||||
exit 1
|
||||
fi
|
||||
ZIG_TAR_URL="https://ziglang.org/builds/zig-linux-x86_64-0.10.0-dev.3685+dae7aeb33.tar.xz"
|
||||
ZIG_TAR_SHA256="dfc8f5ecb651342f1fc2b2828362b62f74fadac9931bda785b80bf7ecfcfabb2"
|
||||
curl --output /tmp/zig.tar.xz "${ZIG_TAR_URL}"
|
||||
ACTUAL_SHA256=$(sha256sum /tmp/zig.tar.xz | cut -d' ' -f1)
|
||||
if [ "${ACTUAL_SHA256}" != "${ZIG_TAR_SHA256}" ]; then
|
||||
echo "Zig binary checksum mismatch"
|
||||
echo "Expected: ${ZIG_TAR_SHA256}"
|
||||
echo "Actual: ${ACTUAL_SHA256}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tar -C /tmp -xJf /tmp/zig.tar.xz
|
||||
tar -C /tmp -xJf /tmp/zig.tar.xz
|
||||
|
||||
mv /tmp/zig-linux-x86_64-* ${ZIGPATH} 2>/dev/null >/dev/null || true
|
||||
echo "Zig installed to ${ZIGPATH}"
|
||||
mv /tmp/zig-linux-x86_64-* ${ZIGPATH} 2>/dev/null >/dev/null || true
|
||||
echo "Zig installed to ${ZIGPATH}"
|
||||
}
|
||||
|
||||
if linux; then
|
||||
distro=$(grep "^ID=" /etc/os-release | cut -d'=' -f2 | sed -e 's/"//g')
|
||||
distro=$(grep "^ID=" /etc/os-release | cut -d'=' -f2 | sed -e 's/"//g')
|
||||
|
||||
case $distro in
|
||||
"ubuntu")
|
||||
install_apt
|
||||
;;
|
||||
*) # we can add more install command for each distros.
|
||||
echo "\"$distro\" is not supported distro. Will search for 'apt' or 'dnf' package managers."
|
||||
if hash apt; then
|
||||
install_apt
|
||||
else
|
||||
echo "\"$distro\" is not supported and your distro don't have apt or dnf that we support currently."
|
||||
exit
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
case $distro in
|
||||
"ubuntu")
|
||||
install_apt
|
||||
;;
|
||||
*) # we can add more install command for each distros.
|
||||
echo "\"$distro\" is not supported distro. Will search for 'apt' or 'dnf' package managers."
|
||||
if hash apt; then
|
||||
install_apt
|
||||
else
|
||||
echo "\"$distro\" is not supported and your distro don't have apt or dnf that we support currently."
|
||||
exit
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
python3 -m pip install -r dev-requirements.txt
|
||||
python3 -m pip install -r dev-requirements.txt
|
||||
fi
|
||||
|
|
8
setup.sh
8
setup.sh
|
@ -22,7 +22,7 @@ install_apt() {
|
|||
sudo apt-get update || true
|
||||
sudo apt-get install -y git gdb python3-dev python3-pip python3-setuptools libglib2.0-dev libc6-dbg
|
||||
|
||||
if uname -m | grep x86_64 > /dev/null; then
|
||||
if uname -m | grep x86_64 >/dev/null; then
|
||||
sudo dpkg --add-architecture i386 || true
|
||||
sudo apt-get update || true
|
||||
sudo apt-get install -y libc6-dbg:i386 || true
|
||||
|
@ -51,7 +51,7 @@ install_zypper() {
|
|||
sudo zypper refresh || true
|
||||
sudo zypper install -y gdb gdbserver python-devel python3-devel python2-pip python3-pip glib2-devel make glibc-debuginfo
|
||||
|
||||
if uname -m | grep x86_64 > /dev/null; then
|
||||
if uname -m | grep x86_64 >/dev/null; then
|
||||
sudo zypper install -y glibc-32bit-debuginfo || true
|
||||
fi
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ git submodule update --init --recursive
|
|||
PYVER=$(gdb -batch -q --nx -ex 'pi import platform; print(".".join(platform.python_version_tuple()[:2]))')
|
||||
PYTHON+=$(gdb -batch -q --nx -ex 'pi import sys; print(sys.executable)')
|
||||
if ! osx; then
|
||||
PYTHON+="${PYVER}"
|
||||
PYTHON+="${PYVER}"
|
||||
fi
|
||||
|
||||
# Find the Python site-packages that we need to use so that
|
||||
|
@ -164,5 +164,5 @@ ${PYTHON} -m pip install ${INSTALLFLAGS} -Ur requirements.txt
|
|||
|
||||
# Load Pwndbg into GDB on every launch.
|
||||
if ! grep pwndbg ~/.gdbinit &>/dev/null; then
|
||||
echo "source $PWD/gdbinit.py" >> ~/.gdbinit
|
||||
echo "source $PWD/gdbinit.py" >>~/.gdbinit
|
||||
fi
|
||||
|
|
8
tests.sh
8
tests.sh
|
@ -19,7 +19,7 @@ TEST_NAME_FILTER=""
|
|||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-p|--pdb)
|
||||
-p | --pdb)
|
||||
USE_PDB=1
|
||||
echo "Will run tests with Python debugger"
|
||||
shift
|
||||
|
@ -34,7 +34,6 @@ while [[ $# -gt 0 ]]; do
|
|||
esac
|
||||
done
|
||||
|
||||
|
||||
if [[ -z "$ZIGPATH" ]]; then
|
||||
# If ZIGPATH is not set, set it to $pwd/.zig
|
||||
# In Docker environment this should by default be set to /opt/zig
|
||||
|
@ -42,7 +41,6 @@ if [[ -z "$ZIGPATH" ]]; then
|
|||
fi
|
||||
echo "ZIGPATH set to $ZIGPATH"
|
||||
|
||||
|
||||
cd ./tests/binaries || exit 1
|
||||
make clean && make all || exit 2
|
||||
cd ../../
|
||||
|
@ -76,9 +74,9 @@ for test_case in ${TESTS_LIST}; do
|
|||
|
||||
exit_status=$?
|
||||
if [ ${exit_status} -eq 0 ]; then
|
||||
(( ++tests_passed_or_skipped ))
|
||||
((++tests_passed_or_skipped))
|
||||
else
|
||||
(( ++tests_failed ))
|
||||
((++tests_failed))
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
Loading…
Reference in New Issue