git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* How to build to debug with gdb?
@ 2019-08-27 16:27 Giuseppe Crino'
  2019-08-27 17:55 ` Matheus Tavares Bernardino
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Giuseppe Crino' @ 2019-08-27 16:27 UTC (permalink / raw)
  To: git

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 

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?

 -Giuseppe

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to build to debug with gdb?
  2019-08-27 16:27 How to build to debug with gdb? Giuseppe Crino'
@ 2019-08-27 17:55 ` Matheus Tavares Bernardino
  2019-08-27 18:07   ` Randall S. Becker
  2019-08-27 18:34 ` Johannes Sixt
  2019-08-27 18:36 ` SZEDER Gábor
  2 siblings, 1 reply; 9+ messages in thread
From: Matheus Tavares Bernardino @ 2019-08-27 17:55 UTC (permalink / raw)
  To: Giuseppe Crino'; +Cc: git

On Tue, Aug 27, 2019 at 1:27 PM Giuseppe Crino' <giuscri@gmail.com> 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?
>
>  -Giuseppe

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: How to build to debug with gdb?
  2019-08-27 17:55 ` Matheus Tavares Bernardino
@ 2019-08-27 18:07   ` Randall S. Becker
  0 siblings, 0 replies; 9+ messages in thread
From: Randall S. Becker @ 2019-08-27 18:07 UTC (permalink / raw)
  To: 'Matheus Tavares Bernardino',
	'Giuseppe Crino''
  Cc: 'git'

On August 27, 2019 1:56 PM, Matheus Tavares Bernardino wrote:
> On Tue, Aug 27, 2019 at 1:27 PM Giuseppe Crino' <giuscri@gmail.com>
> 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to build to debug with gdb?
  2019-08-27 16:27 How to build to debug with gdb? Giuseppe Crino'
  2019-08-27 17:55 ` Matheus Tavares Bernardino
@ 2019-08-27 18:34 ` Johannes Sixt
  2019-08-27 18:36 ` SZEDER Gábor
  2 siblings, 0 replies; 9+ messages in thread
From: Johannes Sixt @ 2019-08-27 18:34 UTC (permalink / raw)
  To: Giuseppe Crino'; +Cc: git

Am 27.08.19 um 18:27 schrieb Giuseppe Crino':
> 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 
> 
> But it seems there's still some optimization going on that prevents gdb from working correctly.

That is because the command sequence above does not do what you think it
does. Didn't you notice that everything was recompiled during `sudo make
install`?

You must run

  sudo make prefix=/usr/local DEVELOPER=1 CFLAGS="-O0 -g" install

-- Hannes

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to build to debug with gdb?
  2019-08-27 16:27 How to build to debug with gdb? Giuseppe Crino'
  2019-08-27 17:55 ` Matheus Tavares Bernardino
  2019-08-27 18:34 ` Johannes Sixt
@ 2019-08-27 18:36 ` SZEDER Gábor
  2019-08-28  8:15   ` Giuseppe Crino'
  2 siblings, 1 reply; 9+ messages in thread
From: SZEDER Gábor @ 2019-08-27 18:36 UTC (permalink / raw)
  To: Giuseppe Crino'; +Cc: git

On Tue, Aug 27, 2019 at 04:27:25PM +0000, Giuseppe Crino' wrote:
> Hello, to debug some issues I built and installed git via
> 
> $ make prefix=/usr/local DEVELOPER=1 CFLAGS="-O0 -g"
> $ sudo make install

What do the output of these two command look like?  After the first
command build Git with the custom prefix and CFLAGS, the second
command is supposed to start with printing "* new build flags" and
then to build Git again with the default prefix and CFLAGS.

>  What am I missing?

Just a couple hundred lines worth of build output :)

Try using the same build flags for the install, i.e.:

  make prefix=/usr/local DEVELOPER=1 CFLAGS="-O0 -g" install


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to build to debug with gdb?
  2019-08-27 18:36 ` SZEDER Gábor
@ 2019-08-28  8:15   ` Giuseppe Crino'
  2019-08-28 10:32     ` SZEDER Gábor
  0 siblings, 1 reply; 9+ messages in thread
From: Giuseppe Crino' @ 2019-08-28  8:15 UTC (permalink / raw)
  To: SZEDER Gábor, Johannes Sixt; +Cc: Giuseppe Crino', git

On Tue, Aug 27, 2019 at 08:36:40PM +0200, SZEDER Gábor wrote:
> Try using the same build flags for the install, i.e.:
> 
>   make prefix=/usr/local DEVELOPER=1 CFLAGS="-O0 -g" install

Yes, now it works thanks!

On Tue, Aug 27, 2019 at 08:34:23PM +0200, Johannes Sixt wrote:
> That is because the command sequence above does not do what you think it
> does. Didn't you notice that everything was recompiled during `sudo make
> install`?

Shouldn't be this documented somewhere?

To my knowledge `make install` is expected to copy artifacts of the
build under prefix. It's unusual to me that `install` has the `all`
target as prerequisite.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to build to debug with gdb?
  2019-08-28  8:15   ` Giuseppe Crino'
@ 2019-08-28 10:32     ` SZEDER Gábor
  2019-08-28 11:00       ` Giuseppe Crino'
  0 siblings, 1 reply; 9+ messages in thread
From: SZEDER Gábor @ 2019-08-28 10:32 UTC (permalink / raw)
  To: Giuseppe Crino'; +Cc: Johannes Sixt, git

On Wed, Aug 28, 2019 at 08:15:57AM +0000, Giuseppe Crino' wrote:
> On Tue, Aug 27, 2019 at 08:36:40PM +0200, SZEDER Gábor wrote:
> > Try using the same build flags for the install, i.e.:
> > 
> >   make prefix=/usr/local DEVELOPER=1 CFLAGS="-O0 -g" install
> 
> Yes, now it works thanks!
> 
> On Tue, Aug 27, 2019 at 08:34:23PM +0200, Johannes Sixt wrote:
> > That is because the command sequence above does not do what you think it
> > does. Didn't you notice that everything was recompiled during `sudo make
> > install`?
> 
> Shouldn't be this documented somewhere?

Well, perhaps.
But would users actually read it?  Dunno.

Case in point: the first few lines of 'INSTALL' already tell you to
build and install Git with the following commands:

  $ make prefix=/usr all doc info ;# as yourself
  # make prefix=/usr install install-doc install-html install-info ;# as root

Note the same 'prefix=...' in both commands, yet you omitted it when
you ran 'make install' ;)

> To my knowledge `make install` is expected to copy artifacts of the
> build under prefix. It's unusual to me that `install` has the `all`
> target as prerequisite.

I don't think it's unusual at all that the 'install' target depends on
'all'.  A quick and incomprehensive survey of Makefiles from a few
open source projects that I happen to have lying around seems to
confirm this.

What might be unusual (but is rather convenient for developers) is
that Git's build process checks the build flags, and rebuilds the
whole thing after the flags changed.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to build to debug with gdb?
  2019-08-28 10:32     ` SZEDER Gábor
@ 2019-08-28 11:00       ` Giuseppe Crino'
  2019-08-28 12:43         ` Giuseppe Crino'
  0 siblings, 1 reply; 9+ messages in thread
From: Giuseppe Crino' @ 2019-08-28 11:00 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Giuseppe Crino', Johannes Sixt, git

On Wed, Aug 28, 2019 at 12:32:17PM +0200, SZEDER Gábor wrote:
> I don't think it's unusual at all that the 'install' target depends on
> 'all'.  A quick and incomprehensive survey of Makefiles from a few
> open source projects that I happen to have lying around seems to
> confirm this.
> 
> What might be unusual (but is rather convenient for developers) is
> that Git's build process checks the build flags, and rebuilds the
> whole thing after the flags changed.

Maybe I'm biased by my incompetence with Makefile's but since rebuilding
the project with `install` but different flags from the first make is
unusual this is worth mentioning to developers.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to build to debug with gdb?
  2019-08-28 11:00       ` Giuseppe Crino'
@ 2019-08-28 12:43         ` Giuseppe Crino'
  0 siblings, 0 replies; 9+ messages in thread
From: Giuseppe Crino' @ 2019-08-28 12:43 UTC (permalink / raw)
  To: Giuseppe Crino'; +Cc: SZEDER Gábor, Johannes Sixt, git

On Wed, Aug 28, 2019 at 11:00:46AM +0000, Giuseppe Crino' wrote:
> Maybe I'm biased by my incompetence with Makefile's but since rebuilding
> the project with `install` but different flags from the first make is
> unusual this is worth mentioning to developers.

Definitely *not* sarcastic

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-08-28 12:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-27 16:27 How to build to debug with gdb? Giuseppe Crino'
2019-08-27 17:55 ` Matheus Tavares Bernardino
2019-08-27 18:07   ` Randall S. Becker
2019-08-27 18:34 ` Johannes Sixt
2019-08-27 18:36 ` SZEDER Gábor
2019-08-28  8:15   ` Giuseppe Crino'
2019-08-28 10:32     ` SZEDER Gábor
2019-08-28 11:00       ` Giuseppe Crino'
2019-08-28 12:43         ` Giuseppe Crino'

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).