# Additional Compile Options



## Leander (Apr 27, 2015)

Hi

I'm trying to compile net/openldap24-server with some more debugging feaures, since it constantly crashes for unknown reasons. So my aim is to get something like this for gdb(1) support:

```
cd /usr/ports/net/openldap24-server
ADDITIONAL_OPTIONS='-O0 -g' env BATCH=YES make install clean
cd ~
```
What is the FreeBSD way of achieving something like this?


----------



## Leander (Apr 27, 2015)

There should be a way of achieving this easily, right?


----------



## Leander (Apr 27, 2015)

I've tried
	
	



```
echo '
### Debug OpenLDAP
.if${.CURDIR:M*/ports/net/openldap24-server}
CFLAGS += -g
.endif
' >> /etc/make.conf
```
But no luck ... still getting
	
	



```
root@FreeBSD # gdb /usr/local/libexec/slapd -d -1
gdb: unrecognized option `-g'
Use `gdb --help' for a complete list of options.
```


----------



## Leander (Apr 27, 2015)

```
env BATCH=YES make DEBUG_FLAGS='-g' install clean
```
 is also being ignored ... 

Any hint on how to get this working would be awsome


----------



## tobik@ (Apr 27, 2015)

ports(7) says to set WITH_DEBUG or WITH_DEBUG_PORTS, but I do not know if this works...


----------



## hukadan (Apr 27, 2015)

It seems that the DEBUG option has been removed some time ago. But may be you could take inspiration from this commit to solve your problem.

--- Edit ---

Side note, the commit message was _"Remove DEBUG option for now as it have broke syslog capability."_


----------



## Leander (Apr 27, 2015)

tobik said:


> ports(7) says to set WITH_DEBUG or WITH_DEBUG_PORTS, but I do not know if this works...





hukadan said:


> It seems that the DEBUG option has been removed some time ago. But may be you could take inspiration from this commit to solve your problem.
> 
> --- Edit ---
> 
> Side note, the commit message was _"Remove DEBUG option for now as it have broke syslog capability."_



Thanks for your input. It seems like neither of the both mean the '-g' flag to enable gdb(1) support. It seems like the "DEBUG" / "WITH_DEBUG" option only activates some internal additional debugging features of OpenLDAP. Unfortunately this is not helping, since gdb(1) is the only tool, which can help in my scenario. OpenLDAP brakes constantly, and there is no hint at all - not even in the most deepest debugging level available. So there is really just gdb(1) which leaves a trace of hope to figure out what's going wrong there.


----------



## wblock@ (Apr 27, 2015)

There are two different things here.  WITH_DEBUG is used to build binaries with debugging symbols.  It prevents the normal install from stripping those debug symbols.  This is different from whatever might be done by a particular port.

To use WITH_DEBUG:

```
# cd /usr/ports/net/openldap24-server
# make WITH_DEBUG=yes install
```
The problem might be in dependencies, and to see any detail for those in gdb, they would have to be rebuilt with debug symbols also.

It appears that this port used to enable an internal debug option when DEBUG was set, but that might have been a mistake.  If the code still permits, that option can be enabled by manually editing the CONFIGURE_ARGS value.  What that does depends on the port code.  It is not necessarily related to gdb debugging symbols.


----------



## Leander (Apr 27, 2015)

Thanks - this is exactly what I meant. It doesn't enable the gdb support - it just enables some internal debugging features, which are not related to gdb at all.

So the issue is still unresolved - and my frustration as well . No matter where I try to fit -g it doesn't seem to work. Is there any further hints on where I have to place the -g option for gdb support?


----------



## tobik@ (Apr 27, 2015)

WITH_DEBUG adds -g. Here is the relevant section of /usr/ports/Mk/bsd.port.mk:

```
.if defined(WITH_DEBUG) && !defined(WITHOUT_DEBUG)
.if !defined(INSTALL_STRIPPED)
STRIP=  #none
MAKE_ENV+=  DONTSTRIP=yes
STRIP_CMD=  ${TRUE}
.endif
DEBUG_FLAGS?=   -g
CFLAGS:=        ${CFLAGS:N-O*:N-fno-strict*} ${DEBUG_FLAGS}
.if defined(INSTALL_TARGET)
INSTALL_TARGET:=    ${INSTALL_TARGET:S/^install-strip$/install/g}
.endif
.endif
```
and it here is one line of the output of compiling net/openldap24-server with WITH_DEBUG set:

```
cc -pipe -DMDB_DSYNC=O_SYNC -Dfdatasync=fsync -g -fstack-protector -DLDAP_DEPRECATED -fno-strict-aliasing -I../../include -I../../include -I/usr/local/include -DLBER_LIBRARY -c stdio.c  -fPIC -DPIC -o .libs/stdio.o
```
notice the -g?

For whatever reason slapd still gets stripped of all debugging symbols even with WITH_DEBUG set. However the shared libraries compiled with this port are not stripped (I am checking with file(1)). So it works to some degree and this sounds like a bug in the port to me.


----------



## Leander (Apr 27, 2015)

Thanks for this helpful information. My current knowledge about ports in such deep detail is very low and therefore not really helpful. I informed the port maintainer Xin Li alias delphij@, so he has a good base to fix this as soon as he gets a chance to.


----------



## tobik@ (Apr 27, 2015)

Copy the attached patch to /usr/ports/net/openldap24-server/files/patch-build_top.mk, run `make clean` and try compiling with `make WITH_DEBUG=yes install`. slapd should no longer be stripped then.


----------



## Leander (Apr 27, 2015)

Awesome - Thanks. The compilation seems to work. Unfortunately I have to report, that did not solve the gdb support for slapd.
	
	



```
root@FreeBSD # ls -lach /usr/ports/net/openldap24-server/files/
total 184
drwxr-xr-x  2 root  wheel  1.0K 27 Apr 20:04 .
drwxr-xr-x  4 root  wheel  512B 27 Apr 20:13 ..
-rw-r--r--  1 root  wheel  541B 19 Apr 15:21 extrapatch-Makefile.in
-rw-r--r--  1 root  wheel  536B 19 Apr 15:21 extrapatch-outlook-servers__slapd__schema_prep.c
-rw-r--r--  1 root  wheel  4.6K 19 Apr 15:21 patch-ITS7548
-rw-r--r--  1 root  wheel  887B 19 Apr 15:21 patch-ITS8027
-rw-r--r--  1 root  wheel  888B 19 Apr 15:21 patch-ITS8046
-rw-r--r--  1 root  wheel  840B 19 Apr 15:21 patch-bdb6
-rw-r--r--  1 root  wheel  219B 27 Apr 20:25 patch-build_top.mk
-rw-r--r--  1 root  wheel  729B 19 Apr 15:21 patch-configure
-rw-r--r--  1 root  wheel  5.8K 19 Apr 15:21 patch-des
-rw-r--r--  1 root  wheel  366B 19 Apr 15:21 patch-include__ldap_defaults.h
-rw-r--r--  1 root  wheel  818B 19 Apr 15:21 patch-libraries__libldap__Makefile.in
-rw-r--r--  1 root  wheel  331B 19 Apr 15:21 patch-libraries__libldap__tls_o.c
-rw-r--r--  1 root  wheel  2.8K 19 Apr 15:21 patch-servers__slapd__Makefile.in
-rw-r--r--  1 root  wheel  811B 19 Apr 15:21 patch-servers__slapd__slapd.conf
-rw-r--r--  1 root  wheel  460B 19 Apr 15:21 patch-smbk5pwd-Makefile
-rw-r--r--  1 root  wheel  1.0K 19 Apr 15:21 pkg-deinstall.in
-rw-r--r--  1 root  wheel  398B 19 Apr 15:21 pkg-message.client.in
-rw-r--r--  1 root  wheel  764B 19 Apr 15:21 pkg-message.in
-rw-r--r--  1 root  wheel  3.5K 19 Apr 15:21 slapd.in
```


```
root@FreeBSD # make deinstall clean ; make rmconfig ; env BATCH=YES make WITH_DEBUG=yes install clean
```


```
root@FreeBSD # gdb /usr/local/libexec/slapd -d -1 -f /usr/local/etc/openldap/slapd.conf -u ldap -g ldap -h "ldapi://%2fvar%2frun%2fopenldap%2fldapi/ ldap:/// ldaps:///"
gdb: unrecognized option `-g'
Use `gdb --help' for a complete list of options.
```


----------



## tobik@ (Apr 27, 2015)

`gdb` has no -g option. You want `gdb --args /usr/local/libexec/slapd -d -1 -f /usr/local/etc/openldap/slapd.conf -u ldap -g ldap -h "ldapi://%2fvar%2frun%2fopenldap%2fldapi/ ldap:/// ldaps:///"` to pass all args to slapd and not to gdb.


----------



## Leander (Apr 27, 2015)

Indeed - this two changes (patch and command) did the job. Thank you very much for your effort.

Best regards


----------

