Need help with configuring HashLink Debugger for vscode

Here’s my launch.json

{
        "name": "HashLink",
        "type": "hl",
        "request": "launch",
        "cwd": "${workspaceFolder}/Export/hl/bin",
        "hxml": "${workspaceFolder}/Export/hl/haxe/debug.hxml",
        "program": "${workspaceFolder}/Export/hl/obj/ApplicationMain.hl"
    }

I need to set the cwd to the directory with lime.hdll otherwise hl cannot find it. Alternatively I’ve tried copying the hdll to the obj directory with ‘ApplicationMain.hl’ and that works too.

When I tried starting the debugger I kept running into an ‘Access Violation’. It took a while but I realised I needed to run vscode in Administrator Mode.
Now it runs, but it doesn’t hit any breakpoints.
I’ve realised however, if I throw an error in my Main class, vscode opens a new Main.hx window with the text ‘Unknown file Main.hx’.

I’m guessing it can’t find my source files so it can’t monitor any breakpoints.
Any ideas how to fix this?

You’d need to replace -cp Source in the hxml with an absolute path (copy it to a new hxml file next to it so it doesn’t get overwritten on build).

I have a fork of the HashLink extension I was working:

I think it would be best to remove the requirement for a cwd + HXML file (which wasn’t working properly for me) and allow only the executable

I was having a series of issues in getting the HashLink debugger set up, with errors similar to what @gpstudios_tom mentioned (not finding lime.hdll, not finding ApplicationMain.hl, inability to load “default” asset library, etc).

I look forward to when the debugger no longer needs an hxml file to run, but in the meantime, I managed to throw together a PowerShell script that seems to accomplish what @Gama11 suggested through automation.

I store the script Copy-Hxml.ps1 in the .vscode directory with the following contents:

# Run from the project root directory (not .vscode folder)

Get-Content ./Export/hl/haxe/debug.hxml |
ForEach-Object {
    If ($_ -match '\w:[\\/]') {
        $_
    }
    Else {
        $fullPath = Join-Path -Path (Get-Location) -ChildPath ($_ -replace '-\w{2}\s', '')
        $_ -replace '(-\w{2}\s).*', ('$1' + $fullPath)
    }
} |
Set-Content ./Export/hl/haxe/debugAbsolutePath.hxml

My tasks.json looks like this:

{
    "version": "2.0.0",
    "tasks": [
        // Other tasks
        {
            "label": "Copy HXML",
            "type": "shell",
            "command": "${workspaceFolder}/.vscode/Copy-Hxml.ps1"
        }
    ]
}

And finally my launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "HashLink",
            "type": "hl",
            "request": "launch",
            "hl": "C:/HaxeToolkit/hl-1.10.0-win/hl.exe",
            "cwd": "${workspaceFolder}/Export/hl/bin",
            "hxml": "${workspaceFolder}/Export/hl/haxe/debugAbsolutePath.hxml",
            "preLaunchTask": "Copy HXML"
        }
    ]
}

Now, regardless of how the debug.hxml file looks when OpenFL builds it, any argument of the form -\w{2} will be modified to use an absolute file path. (I needed the generic regex to find both -cp and -hl.)

I will definitely be refactoring this hack to be more extensible and generic (the regex bit is embarrassingly inelegant), but I wanted to document my progress online before I drifted away to other projects.

Hope this helps someone!

1 Like