andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 1 | # Linux — Building and Debugging GTK |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 2 | |
| 3 | Sometimes installing the debug packages for gtk and glib isn't quite enough. |
| 4 | (For instance, if the artifacts from -O2 are driving you bonkers in gdb, you |
| 5 | might want to rebuild with -O0.) |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 6 | Here's how to build from source and use your local version without installing |
| 7 | it. |
| 8 | |
| 9 | [TOC] |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 10 | |
| 11 | ## 32-bit systems |
| 12 | |
| 13 | On Ubuntu, to download and build glib and gtk suitable for debugging: |
| 14 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 15 | 1. If you don't have a gpg key yet, generate one with `gpg --gen-key`. |
| 16 | 2. Create file `~/.devscripts` containing `DEBSIGN_KEYID=yourkey`, e.g. |
| 17 | `DEBSIGN_KEYID=CC91A262` (See |
| 18 | http://www.debian.org/doc/maint-guide/ch-build.en.html) |
| 19 | 3. If you're on a 32 bit system, do: |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 20 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 21 | ```shell |
| 22 | #!/bin/sh |
| 23 | set -x |
| 24 | set -e |
| 25 | # Workaround for "E: Build-dependencies for glib2.0 could not be satisfied" |
| 26 | # See also https://bugs.launchpad.net/ubuntu/+source/apt/+bug/245068 |
| 27 | sudo apt-get install libgamin-dev |
| 28 | sudo apt-get build-dep glib2.0 gtk+2.0 |
| 29 | rm -rf ~/mylibs |
| 30 | mkdir ~/mylibs |
| 31 | cd ~/mylibs |
| 32 | apt-get source glib2.0 gtk+2.0 |
| 33 | cd glib2.0* |
| 34 | DEB_BUILD_OPTIONS="nostrip noopt debug" debuild |
| 35 | cd ../gtk+2.0* |
| 36 | DEB_BUILD_OPTIONS="nostrip noopt debug" debuild |
| 37 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 38 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 39 | This should take about an hour. If it gets stuck waiting for a zombie, |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 40 | you may have to kill its closest parent (the makefile uses subshells, |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 41 | and bash seems to get confused). When I did this, it continued successfully. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 42 | |
| 43 | At the very end, it will prompt you for the passphrase for your gpg key. |
| 44 | |
| 45 | Then, to run an app with those libraries, do e.g. |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 46 | |
| 47 | export LD_LIBRARY_PATH=$HOME/mylibs/gtk+2.0-2.16.1/debian/install/shared/usr/lib:$HOME/mylibs/gtk+2.0-2.20.1/debian/install/shared/usr/lib |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 48 | |
| 49 | gdb ignores that variable, so in the debugger, you would have to do something like |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 50 | |
| 51 | set solib-search-path $HOME/mylibs/gtk+2.0-2.16.1/debian/install/shared/usr/lib:$HOME/mylibs/gtk+2.0-2.20.1/debian/install/shared/usr/lib |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 52 | |
| 53 | See also http://sources.redhat.com/gdb/current/onlinedocs/gdb_17.html |
| 54 | |
| 55 | ## 64-bit systems |
| 56 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 57 | If you're on a 64 bit system, you can do the above on a 32 |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 58 | bit system, and copy the result. Or try one of the following: |
| 59 | |
| 60 | ### Building your own GTK |
| 61 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 62 | ```shell |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 63 | apt-get source glib-2.0 gtk+-2.0 |
| 64 | |
| 65 | export CFLAGS='-m32 -g' |
| 66 | export LDFLAGS=-L/usr/lib32 |
| 67 | export LD_LIBRARY_PATH=/work/32/lib |
| 68 | export PKG_CONFIG_PATH=/work/32/lib/pkgconfig |
| 69 | |
| 70 | # glib |
| 71 | setarch i386 ./configure --prefix=/work/32 --enable-debug=yes |
| 72 | |
| 73 | # gtk |
| 74 | setarch i386 ./configure --prefix=/work/32 --enable-debug=yes --without-libtiff |
| 75 | ``` |
| 76 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 77 | ### ia32-libs |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 78 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 79 | _Note: Evan tried this and didn't get any debug libs at the end._ |
| 80 | |
| 81 | Or you could try this instead: |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 82 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 83 | ``` |
| 84 | #!/bin/sh |
| 85 | set -x |
| 86 | set -e |
| 87 | sudo apt-get build-dep ia32-libs |
| 88 | rm -rf ~/mylibs |
| 89 | mkdir ~/mylibs |
| 90 | cd ~/mylibs |
| 91 | apt-get source ia32-libs |
| 92 | cd ia32-libs* |
| 93 | DEB_BUILD_OPTIONS="nostrip noopt debug" debuild |
| 94 | ``` |
| 95 | |
| 96 | By default, this just grabs and unpacks prebuilt libraries; see |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 97 | ia32-libs-2.7ubuntu6/fetch-and-build which documents a BUILD variable which |
| 98 | would force actual building. This would take way longer, since it builds dozens |
| 99 | of libraries. I haven't tried it yet. |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 100 | |
| 101 | #### Possible Issues |
| 102 | |
| 103 | debuild may fail with |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 104 | |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 105 | ``` |
| 106 | gpg: [stdin]: clearsign failed: secret key not available |
| 107 | debsign: gpg error occurred! Aborting.... |
| 108 | ``` |
andybons | 3322f76 | 2015-08-24 21:37:09 | [diff] [blame] | 109 | |
andybons | ad92aa3 | 2015-08-31 02:27:44 | [diff] [blame] | 110 | if you forget to create `~/.devscripts` with the right contents. |
| 111 | |
| 112 | The build may fail with a `FAIL: abicheck.sh` if gold is your system linker. Use |
| 113 | ld instead. |