How to debug git source code on a mac

Heba Waly
2 min readDec 23, 2019

--

I’ve recently started contributing to git (refer to my previous post to read about outreachy internships) and I wanted to debug the project on my macOS environment using Xcode. But I couldn’t figure out a way to debug git using it, so I decided to find another alternative …

Going through the documentation, I found a paragraph about debugging in the CodingGuidelines file, it suggested running GIT_DEBUGGER=1 ./bin-wrappers/git commit to run GDB or replace 1 by another debugger name. So I decided to install GDB and try it out.

After installing GDB and running the command above, I got an error message saying:

Unable to find Mach task port for process-id 49902: (os/kern) failure (0x5).
(please check gdb is codesigned — see taskgated(8))

Googling the error, I realized that it’s a known issue, many folks on the internet provided a solution for it. After following a few with no luck it was time to try something else.

So I decided to give LLDB a try as it is the default debugger in Xcode. Accordingly it must already be installed and ready to use on my machine.

Following the instructions from git documentation, I ran GIT_DEBUGGER=lldb ./bin-wrappers/git commit but then I got an error: bash: commit: command not found. looks like lldb is expecting an executable. So I tried:

GIT_DEBUGGER=lldb ./bin-wrappers/git 
run commit

This time the commit command was run successfully by the debugger. Then we can set a breakpoint at the cmd_commit function, which is the function called when you run git commit.

b cmd_commit

The output should look similar to this screenshot

Then run the commit command one more time

The debugger will stop at the first line of the cmd_commit function. next you can use step or s to step in, next or n to step over, continue or c to continue till the next breakpoint or the end of the process.

To show the contents of a variable use p

Here’s a mapping of GDB command to LLDB ones & Happy debugging :)

--

--

Heba Waly

Software engineer, mom and a traveler. I document stories and experiences from my daily life that I find interesting and worth sharing