Skip to content

Commit d7e6ac3

Browse files
Add small GDB plugin
1 parent e757980 commit d7e6ac3

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

gdb/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# linuxdeploy-plugin-gdb
2+
3+
This plugin allows to debug the application within AppImage through GDB.
4+
To allow GDB to find source files, `LINUXDEPLOY_PLUGIN_GDB_SRC` environment variable must be set: this plugin copies source files inside AppDir during AppImage build process.
5+
6+
**:warning: This plugin is experimental and has not been tried with several applications. :warning:**
7+
8+
## Usage
9+
10+
```bash
11+
# get linuxdeploy and linuxdeploy-plugin-gdb
12+
> wget -c "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
13+
> wget -c "https://raw.githubusercontent.com/linuxdeploy/misc-plugins/master/gdb/linuxdeploy-plugin-gdb.sh"
14+
15+
# first option: install your app into your AppDir via `make install` etc.
16+
# second option: bundle your app's main executables manually
17+
# see https://docs.appimage.org/packaging-guide/from-source/native-binaries.html for more information
18+
> [...]
19+
20+
# call through linuxdeploy
21+
> export LINUXDEPLOY_PLUGIN_GDB_SRC="/some/path/to/app/source"
22+
> ./linuxdeploy-x86_64.AppImage --appdir AppDir --plugin gdb --output appimage --icon-file mypackage.png --desktop-file mypackage.desktop
23+
```
24+
25+
## Start GDB
26+
27+
By default, the AppImage works normally. To start GDB, set the `APPIMAGE_USE_GDB` environment variable, like this:
28+
```bash
29+
# start the AmmImage with GDB
30+
> APPIMAGE_USE_GDB=1 ./mypackage-x86_64.AppImage
31+
```

gdb/linuxdeploy-plugin-gdb.sh

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#! /bin/bash
2+
3+
# exit whenever a command called in this script fails
4+
set -e
5+
6+
if [ "$DEBUG" != "" ]; then
7+
set -x
8+
verbose="--verbose"
9+
fi
10+
11+
appdir=""
12+
13+
show_usage() {
14+
echo "Usage: bash $0 --appdir <AppDir>"
15+
echo
16+
echo "Bundles source files for debugging"
17+
echo
18+
echo "Required variables:"
19+
echo " LINUXDEPLOY_PLUGIN_GDB_SRC: path to source directory"
20+
echo
21+
}
22+
23+
while [ "$1" != "" ]; do
24+
case "$1" in
25+
--plugin-api-version)
26+
echo "0"
27+
exit 0
28+
;;
29+
--appdir)
30+
appdir="$2"
31+
shift
32+
shift
33+
;;
34+
--help)
35+
show_usage
36+
exit 0
37+
;;
38+
*)
39+
echo "Invalid argument: $1"
40+
echo
41+
show_usage
42+
exit 2
43+
esac
44+
done
45+
46+
if [[ "$appdir" == "" ]]; then
47+
show_usage
48+
exit 2
49+
fi
50+
51+
if [ -z "$LINUXDEPLOY_PLUGIN_GDB_SRC" ]; then
52+
echo "$0: LINUXDEPLOY_PLUGIN_GDB_SRC environment variable is not set"
53+
show_usage
54+
exit 2
55+
fi
56+
57+
echo "Copying source files"
58+
cp --recursive $verbose "$LINUXDEPLOY_PLUGIN_GDB_SRC" "$appdir/usr/"
59+
60+
echo "Installing new AppRun wrapper"
61+
mv $verbose "$appdir/AppRun.wrapped" "$appdir/AppRun.wrapped.real"
62+
cat > "$appdir/AppRun.wrapped" <<\EOF
63+
#! /bin/bash
64+
65+
if [[ -n "$APPIMAGE_USE_GDB" ]]; then
66+
gdb --cd "$APPDIR/usr/@SRCDIR@" --args "$APPDIR/AppRun.wrapped.real" "$@"
67+
else
68+
exec "$APPDIR/AppRun.wrapped.real" "$@"
69+
fi
70+
EOF
71+
sed -i "s|@SRCDIR@|$(basename "$LINUXDEPLOY_PLUGIN_GDB_SRC")|" "$appdir/AppRun.wrapped"
72+
chmod $verbose 755 "$appdir/AppRun.wrapped"

0 commit comments

Comments
 (0)