Samsung / netcoredbg

NetCoreDbg is a managed code debugger with MI interface for CoreCLR.
MIT License
780 stars 101 forks source link

Failing to load symbols with NetCoreDbg and Godot #173

Closed SchnozzleCat closed 1 month ago

SchnozzleCat commented 1 month ago

I am trying to attach to a running Godot session with netcoredbg and Neovim. Netcoredbg definitely works with Godot, since VSCode has no issues attaching to a running godot session.

The issue I am running into is that the debugger attaches just fine, but it fails to load the symbols for my Godot project. The DAP log shows the following for my rejected breakpoint:

[ INFO ] 2024-08-01T19:50:33Z+0200 ] ...pack/myNeovimPackages/start/nvim-dap/lua/dap/session.lua:904 ]    "Breakpoint unverified"    {
  id = 2,
  line = 16,
  message = "The breakpoint will not currently be hit. No symbols have been loaded for this document.",
  verified = false
}

Running netcoredbg in CLI mode shows the following:

...

library loaded: /nix/store/bq5bzv8d9dq1jsz40dsfxjsnns8bhaav-godot4-mono-schnozzlecat-4.3.0-rc1/bin/GodotSharp/Api/Debug/GodotPlugins.dll
symbols loaded, base address: 0x7f8aac00f000, size: 12800(0x3200)

...

library loaded: /nix/store/bq5bzv8d9dq1jsz40dsfxjsnns8bhaav-godot4-mono-schnozzlecat-4.3.0-rc1/bin/GodotSharp/Api/Debug/GodotSharp.dll
symbols loaded, base address: 0x7f8a60400000, size: 5344256(0x518c00)

...

library loaded: TestNetCoreDbg
no symbols loaded, base address: 0x7f8aac002000, size: 7168(0x1c00)

Where TestNetCoreDbg is the DLL for my project. It seems to load the DLLs for the Godot<->C# glue code just fine, but for some reason it does not find (?) the PDB for the runtime code specific to the loaded project, even though it is right beside the DLL. Even running the debugger from this folder doesn't seem to do the trick.

image

I've also specified full debug symbols, but that also doesn't seem to help.

<Project Sdk="Godot.NET.Sdk/4.3.0-SchnozzleCat-e83503f.808">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
    <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
    <EnableDynamicLoading>true</EnableDynamicLoading>
    <DebugType>full</DebugType>
  </PropertyGroup>
</Project>

What am I missing here? I've been trying to get this to work for some time now with no avail... Any help is greatly appreciated!

viewizard commented 1 month ago

bq5bzv8d9dq1jsz40dsfxjsnns8bhaav-godot4-mono-schnozzlecat-4.3.0-rc11 looks like mono build, not sure netcoredbg aimed to coreclr only will work proper at all.

SchnozzleCat commented 1 month ago

bq5bzv8d9dq1jsz40dsfxjsnns8bhaav-godot4-mono-schnozzlecat-4.3.0-rc11 looks like mono build, not sure netcoredbg aimed to coreclr only will work proper at all.

This is just historical naming on my part (the package used to be called godot3-mono), the name is up to me as this is built from source.

Since Godot 4.0 it now uses CoreCLR.

Rider also lists the project as using net8.0. image

Netcoredbg can definitely do this, since it works fine with VSCode on Godot 4.0 projects. The issue (from what I can tell), seems to be related to it not loading the symbols for the project DLL correctly, and thus rejecting all breakpoints.

gbalykov commented 1 month ago

@SchnozzleCat is your TestNetCoreDbg.dll built in debug or release? For release you'll need https://github.com/Samsung/netcoredbg/blob/master/docs/cli.md#debugging-release-build-of-dlls.

Also please share version of NetCoreDbg that you use and build command & commit if you built it from source code.

gbalykov commented 1 month ago

no symbols loaded, base address: 0x7f8aac002000, size: 7168(0x1c00)

This looks like there's some mismatch in dll-pdb pair, so please try to set breakpoint in gdb to https://github.com/Samsung/netcoredbg/blob/master/src/managed/interop.cpp#L138, or add printf there with all args of loadSymbolsForModuleDelegate and output to see what's going on.

SchnozzleCat commented 1 month ago

@SchnozzleCat is your TestNetCoreDbg.dll built in debug or release? For release you'll need https://github.com/Samsung/netcoredbg/blob/master/docs/cli.md#debugging-release-build-of-dlls.

Also please share version of NetCoreDbg that you use and build command & commit if you built it from source code.

It should use debug by default but I just tested again with explicitly specifying the configuration and it still fails to load the symbols.

dotnet build --configuration DEBUG
  Determining projects to restore...
  Restored /home/linus/Repositories/testnetcoredbg/TestNetCoreDbg.csproj (in 109 ms).
/home/linus/Repositories/testnetcoredbg/ScriptToDebug.cs(8,9): warning CS0219: The variable 'i' is assigned but its value is never used [/home/linus/Repositories/testnetcoredbg/TestNetCor
eDbg.csproj]
  TestNetCoreDbg -> /home/linus/Repositories/testnetcoredbg/.godot/mono/temp/bin/Debug/TestNetCoreDbg.dll

Build succeeded.

/home/linus/Repositories/testnetcoredbg/ScriptToDebug.cs(8,9): warning CS0219: The variable 'i' is assigned but its value is never used [/home/linus/Repositories/testnetcoredbg/TestNetCor
eDbg.csproj]
    1 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.62

The package comes from my package manager, but that builds from source and caches the binaries. This is my version output:

❯ netcoredbg --version
NET Core debugger 3.0.0-13 (not detected, Release)

Copyright (c) 2020 Samsung Electronics Co., LTD
Distributed under the MIT License.
See the LICENSE file in the project root for more information.

There's a pull request open for Nix that upgrades to 3.1.0-1031, so I'm going to test that next.

SchnozzleCat commented 1 month ago

After upgrading to 3.1.0-1031, everything works perfectly :upside_down_face: . Sorry for wasting your time, and thanks for the help!