You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docfx_project/articles/tutorials/debugging/index.md
+80-1Lines changed: 80 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,4 +29,83 @@ Here is how you can enable and use Development environment on Windows:
29
29
5. To unload module, which which was loaded by absolute path, one should also use module's full path, like `lua_run dotnet.unload([[C:\Users\glebc\source\repos\TestModule\bin\Debug\net5.0\TestModule.dll]])`.
30
30
[](images/gmod3.png)
31
31
32
-
## Debugging Gmod.NET modules
32
+
## Debugging Gmod.NET modules
33
+
34
+
Gmod.NET ships with full-featured .NET runtime by Microsoft. In particular, it means that one can use all kinds of .NET debuggers, including debuggers shipped with Visual Studio, Visual Studio for Mac, Visual Studio Code, and JetBrains Rider, or diagnostics tools while development. Here is an instruction on how you can use Visual Studio 2019 on Windows to debug your Gmod.NET module.
35
+
36
+
1. Start Garry's Mod in [Development environment](#development-environment).
37
+
38
+
2. Open your module's project in Visual Studio. For the sake of this tutorial we will be working with module named `ExampleModule` with the single source file `ExampleModule.cs`:
lua.PushString($"Hello, this is LuaFunc. Number of invokations of the function: {luaFuncInvokationCount}");
70
+
lua.MCall(1, 0);
71
+
lua.Pop(1);
72
+
73
+
return0;
74
+
}
75
+
76
+
publicvoidUnload(ILualua)
77
+
{
78
+
lua.PushGlobalTable();
79
+
lua.PushNil();
80
+
lua.SetField(-2, "LuaFunc");
81
+
lua.Pop(1);
82
+
}
83
+
}
84
+
}
85
+
```
86
+
This module adds global Lua function `LuaFunc` which greets user and says how many times it was called.
87
+
88
+
3. Add a breaking point somewhere in your code. We will add one at line 26, where `luaFuncInvokationCount`field is incremented.
89
+
[](images/vs1.png)
90
+
91
+
4. Build your module in `Debug` configuration. In such configuration, additional information for debugger will be generated and no optimizations applied.
92
+
93
+
5. Load Gmod.NET Runtime in game, do not load your module yet.
94
+
95
+
6. In Visual Studio in the top context menu navigate to `Debug > Attach to Process...`
96
+
[](images/vs2.png)
97
+
98
+
7. In the opened window, set debug type to `Managed (.NET Core, .NET 5+) code`.
99
+
[](images/vs3.png)
100
+
101
+
8. Select `gmod.exe` process which has type `Managed (.NET Core, .NET 5+) code` in the list and press `Attach`.
102
+
[](images/vs4.png)
103
+
104
+
9. Immediately after attaching debugger the breaking point may be marked as inactive due to Visual Studio's inability to locate debug symbols. It is OK, since our module (and thus its symbols) is not loaded yet.
105
+
106
+
10. Load module and invoke `LuaFunc`. The breakpoint will be hit and game process paused. From this point you can debug your module as any other .NET application. For example, you can explore and edit current values of variables.
107
+
[](images/vs5.png)
108
+
109
+
11. If you want to update your code, unload your module, stop debugging in Visual Studio, make changes, build your updated module, load it with Gmod.NET Runtime, and reattach Visual Studio debugger by using `Debug > Reattach to Process` option in the Visual Studio top context menu.
110
+
[](images/vs6.png)
111
+
Debugger have to be reattached in order to make changes visible, otherwise Visual Studio will keep outdated symbols and breakpoints in the updated code won't be hit.
0 commit comments