A debug build takes noticeably longer to produce and is much larger, and
it is not needed for a production crash binary: gdb is configured with
"-g -O2" and crash compiles its own files with -g.
Add a global DEBUG=1 switch which builds both crash and the embedded gdb
with -g. Without it no -g is used anywhere.
gdb compiles its .c sources as C++, using $(CXX) -x c++ with CXXFLAGS, so
CXXFLAGS has to be filtered as well as CFLAGS. The build-time
CFLAGS_FOR_BUILD and CXXFLAGS_FOR_BUILD are filtered too.
The two gdb Makefile.in files are added to the list of files which are
restored from the tarball before the patch is re-applied, as required for
any gdb file whose hunks are modified.
Assisted-by: LLM
Signed-off-by: Dave Young <yangrr.2009(a)tsinghua.org.cn>
---
Makefile | 13 ++++++++++++-
README | 10 ++++++++++
gdb-16.2.patch | 22 +++++++++++++++++++---
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index c392c23b7327..ae29ea5b5737 100644
--- a/Makefile
+++ b/Makefile
@@ -258,7 +258,18 @@ GDB_FLAGS=
# TARGET_CFLAGS will be configured automatically by configure
TARGET_CFLAGS=
-CRASH_CFLAGS=-g -D${TARGET} ${TARGET_CFLAGS} ${GDB_FLAGS} ${CFLAGS}
+#
+# Debug information (-g) is not built by default. Use "make DEBUG=1" to
+# build both crash and the embedded gdb module with debug information.
+#
+ifeq ($(DEBUG),1)
+DEBUG_CFLAGS=-g
+else
+DEBUG_CFLAGS=
+endif
+export DEBUG
+
+CRASH_CFLAGS=$(DEBUG_CFLAGS) -D${TARGET} ${TARGET_CFLAGS} ${GDB_FLAGS} ${CFLAGS}
GPL_FILES=
TAR_FILES=${SOURCE_FILES} Makefile ${GPL_FILES} README crash-release crash.8 \
diff --git a/README b/README
index 69232eb4861b..a4e22d95093a 100644
--- a/README
+++ b/README
@@ -84,6 +84,16 @@
$ cd crash-9.0.x
$ make
+ By default, debug information (-g) is not built into either crash or the
+ embedded gdb module. To build both with debug information:
+
+ $ make DEBUG=1
+
+ Changing the target ("make target=...") or toggling DEBUG on an existing
+ build tree does not recompile objects that are already up to date. Run
+ "make clean" before rebuilding, and also remove the gdb-16.2 directory if
+ the embedded gdb was configured for a different target.
+
To cross compile the crash utility for aarch64 on x86_64:
$ make CROSS_COMPILE=aarch64-linux-gnu- -j`nproc`
diff --git a/gdb-16.2.patch b/gdb-16.2.patch
index 78cf605a83bb..1317959d768f 100644
--- a/gdb-16.2.patch
+++ b/gdb-16.2.patch
@@ -9,6 +9,8 @@
# to all subsequent patch applications.
tar xvzmf gdb-16.2.tar.gz \
+ gdb-16.2/Makefile.in \
+ gdb-16.2/gdb/Makefile.in \
gdb-16.2/gdb/symfile.c \
gdb-16.2/gdb/symtab.c
@@ -17,25 +19,33 @@ exit 0
--- gdb-16.2/Makefile.in.orig
+++ gdb-16.2/Makefile.in
@@ -369,6 +369,9 @@ CC_FOR_BUILD = @CC_FOR_BUILD@
- CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
+-CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
++CFLAGS_FOR_BUILD = $(filter-out -g,@CFLAGS_FOR_BUILD@) $(if $(filter 1,$(DEBUG)),-g)
CPP_FOR_BUILD = @CPP_FOR_BUILD@
CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@
+ifeq (${CRASH_TARGET}, PPC64)
+CFLAGS_FOR_BUILD += -m64 -fPIC
+endif
- CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@
+-CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@
++CXXFLAGS_FOR_BUILD = $(filter-out -g,@CXXFLAGS_FOR_BUILD@) $(if $(filter
1,$(DEBUG)),-g)
CXX_FOR_BUILD = @CXX_FOR_BUILD@
DLLTOOL_FOR_BUILD = @DLLTOOL_FOR_BUILD@
@@ -441,6 +444,9 @@ GNATBIND = @GNATBIND@
GNATMAKE = @GNATMAKE@
- CFLAGS = @CFLAGS@
+-CFLAGS = @CFLAGS@
++CFLAGS = $(filter-out -g,@CFLAGS@) $(if $(filter 1,$(DEBUG)),-g)
+ifeq (${CRASH_TARGET}, PPC64)
+CFLAGS += -m64 -fPIC
+endif
LDFLAGS = @LDFLAGS@
LIBCFLAGS = $(CFLAGS)
CXXFLAGS = @CXXFLAGS@
+@@ -446,3 +452,3 @@
+-CXXFLAGS = @CXXFLAGS@
++CXXFLAGS = $(filter-out -g,@CXXFLAGS@) $(if $(filter 1,$(DEBUG)),-g)
+ LIBCXXFLAGS = $(CXXFLAGS) -fno-implicit-templates
+ GOCFLAGS = $(CFLAGS)
--- gdb-16.2/gdb/Makefile.in.orig
+++ gdb-16.2/gdb/Makefile.in
@@ -603,7 +603,7 @@ CONFIG_DEP_SUBDIR = $(addsuffix /$(DEPDIR),$(CONFIG_SRC_SUBDIR))
@@ -47,6 +57,12 @@ exit 0
GDB_INCLUDED_HEADER = -include $(srcdir)/defs.h
GDB_CFLAGS = \
-I. \
+@@ -623,3 +623,3 @@
+-CFLAGS = @CFLAGS@
++CFLAGS = $(filter-out -g,@CFLAGS@) $(if $(filter 1,$(DEBUG)),-g)
+-CXXFLAGS = @CXXFLAGS@
++CXXFLAGS = $(filter-out -g,@CXXFLAGS@) $(if $(filter 1,$(DEBUG)),-g)
+ CPPFLAGS = @CPPFLAGS@
@@ -1220,6 +1220,7 @@ COMMON_SFILES = \
symmisc.c \
symtab.c \
--
2.51.1