Subject: RE: How to build to debug with gdb?

From: "Randall S. Becker" <[email-masked]>
Date: Tue, 27 Aug 2019 14:07:57 -0400

On August 27, 2019 1:56 PM, Matheus Tavares Bernardino wrote:
> On Tue, Aug 27, 2019 at 1:27 PM Giuseppe Crino' <[email-masked]>
> wrote:
> > Hello, to debug some issues I built and installed git via
> >
> > $ make prefix=/usr/local DEVELOPER=1 CFLAGS="-O0 -g"
> > $ sudo make install
> > $ git --version # git version 2.23.0.40.g4d8aada92f
> 
> Hmm, could it be perhaps that CFLAGS is being overwritten? To debug Git
> with GDB I always add this to my config.mak file:
> 
> CFLAGS += -g3 -O0
> LDFLAGS += -g3 -O0
> 
> And then just compile with `make`. Maybe give it a try?
> 
> > But it seems there's still some optimization going on that prevents gdb
> from working correctly.
> >
> > For example
> >
> > (gdb) b builtin/config.c:752
> > Breakpoint 1 at 0x43942: file builtin/config.c, line 752.
> > (gdb) r config --global --edit
> > Starting program: /usr/local/bin/git config --global --edit [Thread
> > debugging using libthread_db enabled] Using host libthread_db library
> > "/lib/x86_64-linux-gnu/libth read_db.so.1".
> >
> > Breakpoint 1, cmd_config (argc=0, argv=<optimized out>,
> >     prefix=<optimized out>) at builtin/config.c:753
> >     753                             if (fd >= 0) {
> >     (gdb) p fd
> >     $1 = <optimized out>
> >
> >  What am I missing?

Given that you are 40 commits in from 2.23.0, is it possible that you have compiled a few objects, like main, using the old CFLAGS? Gdb is notorious for not showing symbols if main does not have it. Have you done a git clean -dxf before building with the new CFLAGS?

Just a thought.

Randall