threads / discuss / 46995

How can I debug git source code interactively with debugger like gdb?

Subject: How can I debug git source code interactively with debugger like gdb?

## tl;dr

3 messages between Oct 18, 2017 and Oct 18, 2017.

replies: 2people: 3as markdown or json

小川恭史· Oct 18, 2017, 19:42 UTC · lore
I wanna learn how daily git command works when I run specific git command.

I wanna know which function is actually called then, how variables changes its value, and how some object is stored into database.

How can I debug git source code interactively with debugger like gdb?
Brandon Williams· Oct 18, 2017, 19:56 UTC · re: 小川恭史 · lore

Re: How can I debug git source code interactively with debugger like gdb?

On 10/19, 小川恭史 wrote:
Show 6 quoted lines
> I wanna learn how daily git command works when I run specific git command.
> 
> I wanna know which function is actually called then, how variables
> changes its value, and how some object is stored into database.
> 
> How can I debug git source code interactively with debugger like gdb?

I have had to do this in the past when trying to track down particularly nasty bugs. If you build git from source (you may need to turn on debugging info) you'll be able to find a script '/bin-wrappers/git' which you can use by making sure the environment variable 'GIT_TEST_GDB' is set. This will launch it under gdb. For example:

  GIT_TEST_GDB=1 ./bin-wrappers/git status
-- 
Brandon Williams
Stefan Beller· Oct 18, 2017, 19:57 UTC · re: 小川恭史 · lore

Re: How can I debug git source code interactively with debugger like gdb?

On Wed, Oct 18, 2017 at 12:42 PM, 小川恭史 <aiueogawa217@gmail.com> wrote:
> I wanna learn how daily git command works when I run specific git command.
1. Obtain the sources and compile Git yourself
    (git clone https://kernel.googlesource.com/pub/scm/git/git
     cd git && make && make install).
   Documentation/* and the Makefile are pretty verbose if you want
   to compile for some non-mainstream hardware or OS.
2. "gdb git" and debug away.
  Note, that some Git commands call other git commands,
  So running the command with "GIT_TRACE=1 git <cmd>"
  first may be helpful for diagnosis as well.
  (See the general git man page that has a couple of env vars
   that aid in debugging)
> I wanna know which function is actually called then, how variables
> changes its value, and how some object is stored into database.

For understanding Gits model, it may be easier to read a book, such as "git from the bottom up" as that conveys the concepts better.

The source code is riddled with handling corner cases, error handling and other implementation details that are usually not interesting but rather tedious.

> How can I debug git source code interactively with debugger like gdb?
Also checkout ddd, a graphical frontend of gdb.

Cheers, Stefan

← back to recent threads