Raised This Month: $319 Target: $400
 79%   Almost there!

Extension dev issue - VSCode debug

Post New Thread Reply   
Thread Tools Display Modes
Author Message
Junior Member
Join Date: Jul 2015
Location: Spain
Old 08-17-2021 , 14:27   Extension dev issue - VSCode debug
Reply With Quote #1

Hi friends,

I have an important issue on a SM extension I'm developing which seems to be caused by Linux environment reasons and not by a MM/SM bug, but I only can conceive it's better to first ask here, hoping any advanced guy has any clue. Here's my setup:
  • OS: Windows 10
  • IDE: VSCode (Windows)
  • SRCDS is installed under WSL 2 (Windows Subsystem for Linux)
  • Game/mod of interest: HL2DM

My problem is that, while both running normally the server (not GDB debugging) and with GDB manually on command line only, SourceMod correctly loads using HL2DM files (e.g. sourcemod.2.hl2dm.so, gamedata and such), and my extension and everything works great. but, when I debug via VSCode (which uses a native GDB integration tool, https://code.visualstudio.com/docs/c...json-reference), then SM detects it as wrong game/mod instead (concretely SSDK2013), causing it to complain about missing gamedata for instance (which is normal for base SSDK2013 mods; some gamedata files have been missing for it for long).

The left picture shows the affected execution when debugging from VSCode, and the right one reflects an stable launch with command line GDB debugging, highlighting the HL2DM SM binary being correctly loaded.

I guess VSCode messes up symbols somehow, but my debugging JSON script doesn't apparently contain anything wrong (which I attach below if anyone is used to the same IDE and tools, containing few minor edits to expand some variables from dependent base configs), so I don't know what could be different from debugging from command line, which works fine.

Would anyone happen to know what this wrong game detection could be caused for? Or even anything in general terms, really.

Overall the issue limits me in that I wish to work with breakpoints while I'm developing, and due to this limitation I can only print debug with logging as an alternative.

Many thanks
Attached Thumbnails
Click image for larger version

Name:	Proof 1.PNG
Views:	43
Size:	85.9 KB
ID:	190923   Click image for larger version

Name:	Proof 2.PNG
Views:	39
Size:	94.3 KB
ID:	190924  
Attached Files
File Type: txt launch.txt (613 Bytes, 25 views)

Last edited by AdRiAnIlloO; 08-17-2021 at 14:43.
AdRiAnIlloO is offline
Junior Member
Join Date: Jul 2015
Location: Spain
Old 08-17-2021 , 16:21   Re: Extension dev issue - VSCode debug
Reply With Quote #2

Alright. So, I came with the cause of the problem from the server view -which is not a MM fault itself, but a concrete environment difference-. By analyzing the Metamod source code I reached the game/mod detection part which allows the concrete binary selection, and could then analyze the case.

First off, for reference, the loader does this under Linux: https://github.com/alliedmodders/met...oader.cpp#L247.

So I investigated what the contents of the cmdline file for the SRCDS process were. It turns out that under the two aforementioned correct run setup alternatives, the cached arguments stored in the descriptor are split by null terminators (\0s), which MM exactly uses to parse the cached startup arguments and eventually detect the -game one. Example:

[email protected]:~/Source/metamod$ cat /proc/26584/cmdline 
Well, so the problem is that under the affected debugging way (VSCode cppdbg), this file separates the arguments with spaces intead, like:

[email protected]:~/hl2rp_server$ cat /proc/27479/cmdline
/home/adrian/.steam/steamcmd/hl2rp_server/srcds_linux-norestart -nowatchdog -game hl2mp +sv_cheats 1 +map rp_c18_v1 -debug
I will then try to check how to adapt the launch settings from VScode or change anything anywhere near to solve it, or contact Microsoft in the worst case. Turns out it's a VSCode issue.

EDIT: Upon recently realizing the fault was potentially mine (was filling JSON array-like arguments as a whole string rather than by one argument per item) and fixing the space separators issue, the same SDK2013 misdetection problem is still happening. Currently investigating what else may be wrong.

Last edited by AdRiAnIlloO; 08-17-2021 at 17:04.
AdRiAnIlloO is offline
Junior Member
Join Date: Jul 2015
Location: Spain
Old 08-17-2021 , 17:56   Re: Extension dev issue - VSCode debug
Reply With Quote #3

Alright, here's the final full solution. When configuring your .vscode/launch.json (for debugging), don't set the SRCDS arguments like this:

"args": [
  "-game hl2mp +sv_cheats 1 +map dm_lockdown"
because this will cause whole "human-perceptible" arguments to be treated as a single argument to Linux, due to VSCode string quoting mechanism on launch around arguments.

Instead, wrap at least each of the two game argument tokens into a single array element:

"args": [
  "+sv_cheats 1 +map dm_lockdown"
This way Metamod core will be able to properly detect the game (in this case HL2DM) since cmdline file will have a \0 separator between both tokens -as MM requires-, while the remaining tokens, getting separated by a space in the cmdline file (which server parses fine), shouldn't be any problem for MM as it may not use them.

Hope this helps anyone.

Last edited by AdRiAnIlloO; 08-17-2021 at 18:06.
AdRiAnIlloO is offline

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -4. The time now is 20:31.

Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode