dont turn on malloc debugging for gdb itself

fix the command such that, when we insert the malloc debugging env vars,
we only do it for the executable itself, not for gdb, or some gdb
operations will be very very slow.

Before this fix, if I did a
   make Cppunit... CPPUNITRACE=...
ran the program, then ran it again, the second time would take
5 min to get going.

Now the second time it runs in seconds.

Change-Id: Id08c3a82679164588b88af65a6a7b5f7dd19ff05
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101318
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/solenv/gbuild/CppunitTest.mk b/solenv/gbuild/CppunitTest.mk
index 4a33ac5..a2243da 100644
--- a/solenv/gbuild/CppunitTest.mk
+++ b/solenv/gbuild/CppunitTest.mk
@@ -25,10 +25,15 @@ gb_CppunitTest_PYTHONDEPS ?= $(call gb_Library_get_target,pyuno_wrapper) $(if $(
ifeq ($(strip $(gb_CppunitTest_GDBTRACE)),)
ifneq ($(strip $(CPPUNITTRACE)),)
ifneq ($(filter gdb,$(CPPUNITTRACE)),)
gb_CppunitTest_GDBTRACE := $(subst gdb,gdb -ex "set environment $(subst =, ,$(gb_CppunitTest_CPPTESTPRECOMMAND))",$(CPPUNITTRACE))
# sneak (a) setting the LD_LIBRARY_PATH, and (b) setting malloc debug flags, into the "gdb --args" command line
gb_CppunitTest_GDBTRACE := $(subst gdb,\
	gdb -ex "set environment $(subst =, ,$(gb_CppunitTest_CPPTESTPRECOMMAND))" $(gb_CppunitTest_malloc_check),\
	$(CPPUNITTRACE))
else ifneq ($(filter lldb,$(CPPUNITTRACE)),)
gb_CppunitTest_PREGDBTRACE := lo_dyldpathfile=$(call var2file,$(shell $(gb_MKTEMP)),500,settings set target.env-vars $(gb_CppunitTest_CPPTESTPRECOMMAND))
gb_CppunitTest_GDBTRACE := $(subst lldb,lldb -s $$lo_dyldpathfile,$(CPPUNITTRACE))
gb_CppunitTest_GDBTRACE := $(subst lldb,\
	lldb -s $$lo_dyldpathfile $(gb_CppunitTest_malloc_check),\
	$(CPPUNITTRACE))
gb_CppunitTest_POSTGDBTRACE := rm $$lo_dyldpathfile
else
gb_CppunitTest_GDBTRACE := $(CPPUNITTRACE)
@@ -127,7 +132,6 @@ else
		$(if $(filter gdb,$(gb_CppunitTest_GDBTRACE)),,$(gb_CppunitTest_CPPTESTPRECOMMAND)) \
		$(if $(G_SLICE),G_SLICE=$(G_SLICE)) \
		$(if $(GLIBCXX_FORCE_NEW),GLIBCXX_FORCE_NEW=$(GLIBCXX_FORCE_NEW)) \
		$(gb_CppunitTest_malloc_check) \
		$(if $(strip $(PYTHON_URE)),\
			PYTHONDONTWRITEBYTECODE=1) \
		$(ICECREAM_RUN) $(gb_CppunitTest_GDBTRACE) $(gb_CppunitTest_VALGRINDTOOL) $(gb_CppunitTest_RR) \
diff --git a/solenv/gbuild/platform/macosx.mk b/solenv/gbuild/platform/macosx.mk
index 431f8e4..863fc43 100644
--- a/solenv/gbuild/platform/macosx.mk
+++ b/solenv/gbuild/platform/macosx.mk
@@ -261,7 +261,7 @@ gb_CppunitTest_CPPTESTPRECOMMAND := \
	$(call gb_Helper_extend_ld_path,$(gb_Library_DLLDIR):$(WORKDIR)/UnpackedTarball/cppunit/src/cppunit/.libs)
gb_CppunitTest_get_filename = libtest_$(1).dylib
gb_CppunitTest_get_ilibfilename = $(gb_CppunitTest_get_filename)
gb_CppunitTest_malloc_check := MallocScribble=1 MallocPreScribble=1
gb_CppunitTest_malloc_check := -Q 'env MallocScribble=1' -Q 'env MallocPreScribble=1'

define gb_CppunitTest_CppunitTest_platform
$(call gb_LinkTarget_get_target,$(2)) : RPATH :=
diff --git a/solenv/gbuild/platform/unxgcc.mk b/solenv/gbuild/platform/unxgcc.mk
index ac62526..7ef9d0b 100644
--- a/solenv/gbuild/platform/unxgcc.mk
+++ b/solenv/gbuild/platform/unxgcc.mk
@@ -288,7 +288,7 @@ gb_CppunitTest_CPPTESTPRECOMMAND := \
    $(call gb_Helper_extend_ld_path,$(WORKDIR)/UnpackedTarball/cppunit/src/cppunit/.libs)
gb_CppunitTest_get_filename = libtest_$(1).so
gb_CppunitTest_get_ilibfilename = $(gb_CppunitTest_get_filename)
gb_CppunitTest_malloc_check := MALLOC_CHECK_=2 MALLOC_PERTURB_=153
gb_CppunitTest_malloc_check := -ex 'set environment MALLOC_CHECK_=2; set environment MALLOC_PERTURB_=153'

define gb_CppunitTest_CppunitTest_platform
$(call gb_LinkTarget_get_target,$(2)) : RPATH := $(call gb_Library__get_rpath,$(call gb_LinkTarget__get_rpath_for_layer,NONE))