{"thread":{"id":"51759","subject":"How to build to debug with gdb?","startedAt":"2019-08-27T16:27:30Z","lastAt":"2019-08-28T12:44:00Z","messageCount":9,"participants":["Giuseppe Crino'","Matheus Tavares Bernardino","Randall S. Becker","Johannes Sixt","SZEDER Gábor"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"381371","messageId":"20190827162725.GA29263@instance-template-2.europe-west6-a.c.vaulted-journal-250706.internal","threadId":"51759","inReplyTo":null,"subject":"How to build to debug with gdb?","fromName":"Giuseppe Crino'","fromEmail":"giuscri@gmail.com","sentAt":"2019-08-27T16:27:25Z","receivedAt":"2019-08-27T16:27:30Z","isPatch":false,"sender":{"key":"giuscri@gmail.com","avatar":"https://gravatar.com/avatar/0d6b46f6496321ee3646c8712de0b475e225f393a8c72d2c2385d7820b74dd90?d=mp&s=160"},"body":"Hello, to debug some issues I built and installed git via\n\n$ make prefix=/usr/local DEVELOPER=1 CFLAGS=\"-O0 -g\"\n$ sudo make install\n$ git --version # git version 2.23.0.40.g4d8aada92f \n\nBut it seems there's still some optimization going on that prevents gdb from working correctly.\n\nFor example\n\n(gdb) b builtin/config.c:752\nBreakpoint 1 at 0x43942: file builtin/config.c, line 752.\n(gdb) r config --global --edit\nStarting program: /usr/local/bin/git config --global --edit\n[Thread debugging using libthread_db enabled]\nUsing host libthread_db library \"/lib/x86_64-linux-gnu/libth\nread_db.so.1\".\n\nBreakpoint 1, cmd_config (argc=0, argv=<optimized out>,\n    prefix=<optimized out>) at builtin/config.c:753\n    753                             if (fd >= 0) {\n    (gdb) p fd\n    $1 = <optimized out>\n\n What am I missing?\n\n -Giuseppe\n"},{"id":"381375","messageId":"CAHd-oW6MtoYAwv36_Jsx5qQzvLguXdvrA6NRA+D3ayHGmfVSqw@mail.gmail.com","threadId":"51759","inReplyTo":"20190827162725.GA29263@instance-template-2.europe-west6-a.c.vaulted-journal-250706.internal","subject":"Re: How to build to debug with gdb?","fromName":"Matheus Tavares Bernardino","fromEmail":"matheus.bernardino@usp.br","sentAt":"2019-08-27T17:55:46Z","receivedAt":"2019-08-27T17:56:00Z","isPatch":false,"sender":{"key":"matheus.tavb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701583?v=4"},"body":"On Tue, Aug 27, 2019 at 1:27 PM Giuseppe Crino' <giuscri@gmail.com> wrote:\n>\n> Hello, to debug some issues I built and installed git via\n>\n> $ make prefix=/usr/local DEVELOPER=1 CFLAGS=\"-O0 -g\"\n> $ sudo make install\n> $ git --version # git version 2.23.0.40.g4d8aada92f\n\nHmm, could it be perhaps that CFLAGS is being overwritten? To debug\nGit with GDB I always add this to my config.mak file:\n\nCFLAGS += -g3 -O0\nLDFLAGS += -g3 -O0\n\nAnd then just compile with `make`. Maybe give it a try?\n\n> But it seems there's still some optimization going on that prevents gdb from working correctly.\n>\n> For example\n>\n> (gdb) b builtin/config.c:752\n> Breakpoint 1 at 0x43942: file builtin/config.c, line 752.\n> (gdb) r config --global --edit\n> Starting program: /usr/local/bin/git config --global --edit\n> [Thread debugging using libthread_db enabled]\n> Using host libthread_db library \"/lib/x86_64-linux-gnu/libth\n> read_db.so.1\".\n>\n> Breakpoint 1, cmd_config (argc=0, argv=<optimized out>,\n>     prefix=<optimized out>) at builtin/config.c:753\n>     753                             if (fd >= 0) {\n>     (gdb) p fd\n>     $1 = <optimized out>\n>\n>  What am I missing?\n>\n>  -Giuseppe\n"},{"id":"381376","messageId":"018f01d55d02$5e89e1f0$1b9da5d0$@nexbridge.com","threadId":"51759","inReplyTo":"CAHd-oW6MtoYAwv36_Jsx5qQzvLguXdvrA6NRA+D3ayHGmfVSqw@mail.gmail.com","subject":"RE: How to build to debug with gdb?","fromName":"Randall S. Becker","fromEmail":"rsbecker@nexbridge.com","sentAt":"2019-08-27T18:07:57Z","receivedAt":"2019-08-27T18:08:10Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On August 27, 2019 1:56 PM, Matheus Tavares Bernardino wrote:\n> On Tue, Aug 27, 2019 at 1:27 PM Giuseppe Crino' <giuscri@gmail.com>\n> wrote:\n> > Hello, to debug some issues I built and installed git via\n> >\n> > $ make prefix=/usr/local DEVELOPER=1 CFLAGS=\"-O0 -g\"\n> > $ sudo make install\n> > $ git --version # git version 2.23.0.40.g4d8aada92f\n> \n> Hmm, could it be perhaps that CFLAGS is being overwritten? To debug Git\n> with GDB I always add this to my config.mak file:\n> \n> CFLAGS += -g3 -O0\n> LDFLAGS += -g3 -O0\n> \n> And then just compile with `make`. Maybe give it a try?\n> \n> > But it seems there's still some optimization going on that prevents gdb\n> from working correctly.\n> >\n> > For example\n> >\n> > (gdb) b builtin/config.c:752\n> > Breakpoint 1 at 0x43942: file builtin/config.c, line 752.\n> > (gdb) r config --global --edit\n> > Starting program: /usr/local/bin/git config --global --edit [Thread\n> > debugging using libthread_db enabled] Using host libthread_db library\n> > \"/lib/x86_64-linux-gnu/libth read_db.so.1\".\n> >\n> > Breakpoint 1, cmd_config (argc=0, argv=<optimized out>,\n> >     prefix=<optimized out>) at builtin/config.c:753\n> >     753                             if (fd >= 0) {\n> >     (gdb) p fd\n> >     $1 = <optimized out>\n> >\n> >  What am I missing?\n\nGiven 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?\n\nJust a thought.\n\nRandall\n\n"},{"id":"381378","messageId":"1d44d8d6-6c6f-591e-dd2c-5102c9fd7d11@kdbg.org","threadId":"51759","inReplyTo":"20190827162725.GA29263@instance-template-2.europe-west6-a.c.vaulted-journal-250706.internal","subject":"Re: How to build to debug with gdb?","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2019-08-27T18:34:23Z","receivedAt":"2019-08-27T18:34:27Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 27.08.19 um 18:27 schrieb Giuseppe Crino':\n> Hello, to debug some issues I built and installed git via\n> \n> $ make prefix=/usr/local DEVELOPER=1 CFLAGS=\"-O0 -g\"\n> $ sudo make install\n> $ git --version # git version 2.23.0.40.g4d8aada92f \n> \n> But it seems there's still some optimization going on that prevents gdb from working correctly.\n\nThat is because the command sequence above does not do what you think it\ndoes. Didn't you notice that everything was recompiled during `sudo make\ninstall`?\n\nYou must run\n\n  sudo make prefix=/usr/local DEVELOPER=1 CFLAGS=\"-O0 -g\" install\n\n-- Hannes\n"},{"id":"381379","messageId":"20190827183640.GC8571@szeder.dev","threadId":"51759","inReplyTo":"20190827162725.GA29263@instance-template-2.europe-west6-a.c.vaulted-journal-250706.internal","subject":"Re: How to build to debug with gdb?","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-08-27T18:36:40Z","receivedAt":"2019-08-27T18:36:47Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Aug 27, 2019 at 04:27:25PM +0000, Giuseppe Crino' wrote:\n> Hello, to debug some issues I built and installed git via\n> \n> $ make prefix=/usr/local DEVELOPER=1 CFLAGS=\"-O0 -g\"\n> $ sudo make install\n\nWhat do the output of these two command look like?  After the first\ncommand build Git with the custom prefix and CFLAGS, the second\ncommand is supposed to start with printing \"* new build flags\" and\nthen to build Git again with the default prefix and CFLAGS.\n\n>  What am I missing?\n\nJust a couple hundred lines worth of build output :)\n\nTry using the same build flags for the install, i.e.:\n\n  make prefix=/usr/local DEVELOPER=1 CFLAGS=\"-O0 -g\" install\n\n"},{"id":"381421","messageId":"20190828081557.GA18785@instance-template-2.europe-west6-a.c.vaulted-journal-250706.internal","threadId":"51759","inReplyTo":"1d44d8d6-6c6f-591e-dd2c-5102c9fd7d11@kdbg.org","subject":"Re: How to build to debug with gdb?","fromName":"Giuseppe Crino'","fromEmail":"giuscri@gmail.com","sentAt":"2019-08-28T08:15:57Z","receivedAt":"2019-08-28T08:16:02Z","isPatch":false,"sender":{"key":"giuscri@gmail.com","avatar":"https://gravatar.com/avatar/0d6b46f6496321ee3646c8712de0b475e225f393a8c72d2c2385d7820b74dd90?d=mp&s=160"},"body":"On Tue, Aug 27, 2019 at 08:36:40PM +0200, SZEDER Gábor wrote:\n> Try using the same build flags for the install, i.e.:\n> \n>   make prefix=/usr/local DEVELOPER=1 CFLAGS=\"-O0 -g\" install\n\nYes, now it works thanks!\n\nOn Tue, Aug 27, 2019 at 08:34:23PM +0200, Johannes Sixt wrote:\n> That is because the command sequence above does not do what you think it\n> does. Didn't you notice that everything was recompiled during `sudo make\n> install`?\n\nShouldn't be this documented somewhere?\n\nTo my knowledge `make install` is expected to copy artifacts of the\nbuild under prefix. It's unusual to me that `install` has the `all`\ntarget as prerequisite.\n"},{"id":"381431","messageId":"20190828103217.GA6400@szeder.dev","threadId":"51759","inReplyTo":"20190828081557.GA18785@instance-template-2.europe-west6-a.c.vaulted-journal-250706.internal","subject":"Re: How to build to debug with gdb?","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-08-28T10:32:17Z","receivedAt":"2019-08-28T10:32:25Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Wed, Aug 28, 2019 at 08:15:57AM +0000, Giuseppe Crino' wrote:\n> On Tue, Aug 27, 2019 at 08:36:40PM +0200, SZEDER Gábor wrote:\n> > Try using the same build flags for the install, i.e.:\n> > \n> >   make prefix=/usr/local DEVELOPER=1 CFLAGS=\"-O0 -g\" install\n> \n> Yes, now it works thanks!\n> \n> On Tue, Aug 27, 2019 at 08:34:23PM +0200, Johannes Sixt wrote:\n> > That is because the command sequence above does not do what you think it\n> > does. Didn't you notice that everything was recompiled during `sudo make\n> > install`?\n> \n> Shouldn't be this documented somewhere?\n\nWell, perhaps.\nBut would users actually read it?  Dunno.\n\nCase in point: the first few lines of 'INSTALL' already tell you to\nbuild and install Git with the following commands:\n\n  $ make prefix=/usr all doc info ;# as yourself\n  # make prefix=/usr install install-doc install-html install-info ;# as root\n\nNote the same 'prefix=...' in both commands, yet you omitted it when\nyou ran 'make install' ;)\n\n> To my knowledge `make install` is expected to copy artifacts of the\n> build under prefix. It's unusual to me that `install` has the `all`\n> target as prerequisite.\n\nI don't think it's unusual at all that the 'install' target depends on\n'all'.  A quick and incomprehensive survey of Makefiles from a few\nopen source projects that I happen to have lying around seems to\nconfirm this.\n\nWhat might be unusual (but is rather convenient for developers) is\nthat Git's build process checks the build flags, and rebuilds the\nwhole thing after the flags changed.\n\n"},{"id":"381432","messageId":"20190828110046.GB4450@instance-template-2.europe-west6-a.c.vaulted-journal-250706.internal","threadId":"51759","inReplyTo":"20190828103217.GA6400@szeder.dev","subject":"Re: How to build to debug with gdb?","fromName":"Giuseppe Crino'","fromEmail":"giuscri@gmail.com","sentAt":"2019-08-28T11:00:46Z","receivedAt":"2019-08-28T11:00:52Z","isPatch":false,"sender":{"key":"giuscri@gmail.com","avatar":"https://gravatar.com/avatar/0d6b46f6496321ee3646c8712de0b475e225f393a8c72d2c2385d7820b74dd90?d=mp&s=160"},"body":"On Wed, Aug 28, 2019 at 12:32:17PM +0200, SZEDER Gábor wrote:\n> I don't think it's unusual at all that the 'install' target depends on\n> 'all'.  A quick and incomprehensive survey of Makefiles from a few\n> open source projects that I happen to have lying around seems to\n> confirm this.\n> \n> What might be unusual (but is rather convenient for developers) is\n> that Git's build process checks the build flags, and rebuilds the\n> whole thing after the flags changed.\n\nMaybe I'm biased by my incompetence with Makefile's but since rebuilding\nthe project with `install` but different flags from the first make is\nunusual this is worth mentioning to developers.\n"},{"id":"381437","messageId":"20190828124354.GA7585@instance-template-2.europe-west6-a.c.vaulted-journal-250706.internal","threadId":"51759","inReplyTo":"20190828110046.GB4450@instance-template-2.europe-west6-a.c.vaulted-journal-250706.internal","subject":"Re: How to build to debug with gdb?","fromName":"Giuseppe Crino'","fromEmail":"giuscri@gmail.com","sentAt":"2019-08-28T12:43:54Z","receivedAt":"2019-08-28T12:44:00Z","isPatch":false,"sender":{"key":"giuscri@gmail.com","avatar":"https://gravatar.com/avatar/0d6b46f6496321ee3646c8712de0b475e225f393a8c72d2c2385d7820b74dd90?d=mp&s=160"},"body":"On Wed, Aug 28, 2019 at 11:00:46AM +0000, Giuseppe Crino' wrote:\n> Maybe I'm biased by my incompetence with Makefile's but since rebuilding\n> the project with `install` but different flags from the first make is\n> unusual this is worth mentioning to developers.\n\nDefinitely *not* sarcastic\n"}]}