threads / discuss / 62782

Using Visual Studio Code to Debug/Trace Git?

Subject: Using Visual Studio Code to Debug/Trace Git?

## tl;dr

5 messages between Jan 10, 2025 and Feb 12, 2025.

replies: 4people: 3as markdown or json

Jon Forrest· Jan 10, 2025, 17:11 UTC · lore

I'm interested in using Visual Studio Code to help understand how git works. I'm thinking it would make it easy to see what actually happens when git commands are run.

What I don't know is how to integrate git's build system into Visual Studio Code. Has anybody tried this? If not, what tools do you use to debug git?

Please note that I'm *not* interested in running git from Visual Studio Code. That's another topic entirely that seems to be well covered on the Web.

Cordially, Jon Forrest

Ben Knoble· Jan 10, 2025, 20:38 UTC · re: Jon Forrest · lore

Re: Using Visual Studio Code to Debug/Trace Git?

Show 10 quoted lines
> 
> Le 10 janv. 2025 à 12:16, Jon Forrest <nobozo@gmail.com> a écrit :
> 
> I'm interested in using Visual Studio Code to help understand
> how git works. I'm thinking it would make it easy to see what
> actually happens when git commands are run.
> 
> What I don't know is how to integrate git's build system into
> Visual Studio Code. Has anybody tried this? If not, what tools
> do you use to debug git?
AFAIK, it’s make (with some autoconf stuff) and C debuggers like gdb/lldb. But maybe someone has a better answer. I’d expect VS Code to support this pretty easily.

Best, D. Ben Knoble

Patrick Steinhardt· Jan 13, 2025, 08:04 UTC · re: Ben Knoble · lore

Re: Using Visual Studio Code to Debug/Trace Git?

On Fri, Jan 10, 2025 at 03:38:51PM -0500, Ben Knoble wrote:
Show 15 quoted lines
> 
> > 
> > Le 10 janv. 2025 à 12:16, Jon Forrest <nobozo@gmail.com> a écrit :
> > 
> > I'm interested in using Visual Studio Code to help understand
> > how git works. I'm thinking it would make it easy to see what
> > actually happens when git commands are run.
> > 
> > What I don't know is how to integrate git's build system into
> > Visual Studio Code. Has anybody tried this? If not, what tools
> > do you use to debug git?
> 
> AFAIK, it’s make (with some autoconf stuff) and C debuggers like
> gdb/lldb. But maybe someone has a better answer. I’d expect VS Code to
> support this pretty easily.
There are two ways to realize what you want right now:
  - Import the CMake build instructions that we have in
    "contrib/buildsystems". It has existed for a rather long time, but
    is not an officially supported way to build Git. It's also lacking a
    couple of features that you can expect from our Makefile, like
    building docs. It may be good enough though.
  - Generate a Visual Studio solution via Meson by installing Meson and
    then running `meson setup --backend=vs2022 build-msvc`. This has
    only landed in Git v2.48 and is thus really new. As such it is still
    marked experimental, but will become an official way to build Git
    and is more feature complete.

I'm aware of an issue with Visual Studio right now though when using it with Meson that keeps it from working -- I'll send a patch series later today to fix that issue, and then it should be a good way to build Git on Windows via MSVC.

Patrick
Jon Forrest· Jan 13, 2025, 17:03 UTC · re: Patrick Steinhardt · lore

Re: Using Visual Studio Code to Debug/Trace Git?

On 1/13/25 12:04 AM, Patrick Steinhardt wrote:
Show 18 quoted lines
> There are two ways to realize what you want right now:
> 
>    - Import the CMake build instructions that we have in
>      "contrib/buildsystems". It has existed for a rather long time, but
>      is not an officially supported way to build Git. It's also lacking a
>      couple of features that you can expect from our Makefile, like
>      building docs. It may be good enough though.
> 
>    - Generate a Visual Studio solution via Meson by installing Meson and
>      then running `meson setup --backend=vs2022 build-msvc`. This has
>      only landed in Git v2.48 and is thus really new. As such it is still
>      marked experimental, but will become an official way to build Git
>      and is more feature complete.
> 
> I'm aware of an issue with Visual Studio right now though when using it
> with Meson that keeps it from working -- I'll send a patch series later
> today to fix that issue, and then it should be a good way to build Git
> on Windows via MSVC.
Thanks for your thoughtful reply. I'll look into what you describe.

In the mean time, I've discovered another method that seems to be working, for the very limited execution tracing I'm doing. What I do, on Fedora 41 Workstation, is to build Git from source using the standard method. This has the side effect of generating various .h files that themselves aren't part of the distribution. Then, using Visual Studio Code, I open the Git source directory, open common-main.c, and then set a breakpoint at main(). I can then click on Run->Start Debugging which starts git and breaks at main(). From there I can set whatever additional breakpoints I want.

This method has allowed me to trace various things but I'm not sure if it's a complete solution, especially when forking new processes or using threads. The one very minor problem I've noticed so far is that the executable file generated by VSC isn't called 'git'.

I welcome corrections or comments.
I hope this helps other people.

Cordially, Jon Forrest

Jon Forrest· Feb 12, 2025, 18:32 UTC · re: Patrick Steinhardt · lore

Re: Using Visual Studio Code to Debug/Trace Git?

Just to follow up on this, I've had surprising success by simply building git the normal way (e.g. make), having VSCode open the directory contain the Git source code, opening common-main.c, and then executing "Start Debugging". I'm able to do full source-level debugging this way.

I'm not entirely sure why this works but it's good enough for me.

I'll be interested in seeing if the new Meson build system works any better in VSCode.

Cordially, Jon Forrest

← back to recent threads