I'm using the following script to build the following Artifex MuPDF package:
#!/bin/bash
#########
# FILES #
#########
PACKAGE_NAME=mupdf-1.12.0-source
PACKAGE_TAR_FILE=${PACKAGE_NAME}.tar.xz
PACKAGE_FTP_SITE=https://mupdf.com/downloads/
####################################
# REMOVE OLD STUFF JUST TO BE SURE #
####################################
rm -rf build
rm -rf ${PACKAGE_NAME}
rm -rf ${PACKAGE_TAR_FILE}
#####################################
# Get source code for buggy package #
#####################################
wget ${PACKAGE_FTP_SITE}/${PACKAGE_TAR_FILE}
######################
# Unpack it here ... #
######################
tar xf ${PACKAGE_TAR_FILE}
#################
# Configure ... #
#################
cd ${PACKAGE_NAME}
###############
# Make it !!! #
###############
XCFLAGS="-g -O0" make
I use XCFLAGS instead of CFLAGS to enable a debug build, because that what it says in the makefile:
Do not specify CFLAGS or LIBS on the make invocation line - specify XCFLAGS or XLIBS instead. Make ignores any lines in the makefile that set a variable that was set on the command line.
However, when I launch the gdb session, it says that the target is built without debug symbols:
$ gdb --args ./mupdf-1.12.0-source/build/release/mutool poster ~/Downloads/mutool_poster_crash
Reading symbols from ./mupdf-1.12.0-source/build/release/mutool...(no debugging symbols found)...done.
How can I find out what's going on? Thanks!
I use XCFLAGS instead of CFLAGS to enable a debug build
That isn't how you make a debug build. See the targets in the makefile:
build ?= release
OUT := build/$(build)
default: all
...
...
all: libs apps
clean:
rm -rf $(OUT)
nuke:
rm -rf build/* generated $(NAME_GEN)
release:
$(MAKE) build=release
debug:
$(MAKE) build=debug
The default build is a release type build, i.e.
OUT := build/release
and that's what you've made:
./mupdf-1.12.0-source/build/release/mutool
^^^^^^^^^^^^^
The release build strips the executable:
mupdf-1.12.0-source$ XCFLAGS="-g -O0" make
...
mupdf-1.12.0-source$ file build/release/mutool
build/release/mutool: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), \
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, \
BuildID[sha1]=a77cfe62290635ba12ae8327e24ee545c4dc1ded, \
stripped
^^^^^^^^
So it doesn't matter if you compiled with -g -O0
. The debug info has been stripped.
Make a debug build like this:
mupdf-1.12.0-source$ make debug
which will not strip the executable:
mupdf-1.12.0-source$ file build/debug/mutool
build/debug/mutool: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), \
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, \
BuildID[sha1]=c43e5aceb02812e1f77d2f00b7f75e4629128aac, \
with debug_info, not stripped
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can of course still add any extra XCFLAGS
or XLIBS
options you want.