Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build OpenSSL on Linux with -g for debugging

I have a segfault coming from OpenSSL (specifically SSL_read) that I'd like to debug. I think the best step to take here is to build the library myself with debug symbols so I can step into the function and see the command it's happening on. It's not clear to me how to a) build the library myself and b) hack the makefile to give me the debug symbols. Does anyone have experience doing this with this specific library, or have general guidelines on this sort of build and modify approach?

Got this error:

./config -d
Operating system: x86_64-whatever-linux2
This system (debug-linux-x86_64) is not supported. See file INSTALL for details.

Not sure what to do here. OS info:

$ cat /proc/version
Linux version 3.2.0-24-virtual (buildd@yellow) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.31ubuntu5) ) #37-Ubuntu SMP Wed Apr 25 10:17:19 UTC 2012
$ uname -srvio
Linux 3.2.0-24-virtual #37-Ubuntu SMP Wed Apr 25 10:17:19 UTC 2012 x86_64 GNU/Linux
like image 504
djechlin Avatar asked Jun 20 '12 23:06

djechlin


People also ask

How do I debug OpenSSL library?

Go to Run | Debug Configurations: Create a new "C/C++ Application" configuration. Choose your OpenSSL project (openssl) and C/C++ Application ( apps/openssl ):


3 Answers

You can follow the simple instructions mentioned here for building OpenSSL. For making a debug build, add the -d flag when you run ./config, i.e. ./config -d [other options]. Building OpenSSL is mentioned in detail here.

like image 133
panickal Avatar answered Oct 31 '22 22:10

panickal


On new versions of OpenSSL, it looks like flags passed to ./Configure get injected directly into the gcc line when compiling. I just did ./Configure -g linux-x86_64 and successfully got debugging symbols in my build.

like image 40
Tony Arkles Avatar answered Oct 31 '22 21:10

Tony Arkles


After running the regular configure step, do the following from the shell:

$ find . -name Makefile | xargs sed -i -e 's#-O3#-g#g'

It modifies the generated makefiles; instead of optimization option -O3 it puts in the -g option (generate debug symbols).

like image 28
MichaelMoser Avatar answered Oct 31 '22 23:10

MichaelMoser