Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /waitfordebugger argument to MGCB. #8227

Merged
merged 6 commits into from
Jun 10, 2024

Conversation

dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Mar 12, 2024

The call to System.Diagnostics.Debugger.Launch is
not supported on Unix based platforms. This makes
debugging MGCB.exe and Content Pipeline extensions
difficult.

So lets add a new argument which will make MGCB.exe
wait for a debugger to attach. Also add a extra
update to the launch.json to demonstrate how to
attach the dotnet debugger to an existing process.

This new system will also work on Windows.

To use this in VSCode you can add the following to the
launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Process",
            "type": "coreclr",
            "request": "attach",
            "processId": "${input.processid}",
        }
    ],
    "inputs": [
        {
            "id": "processid",
            "type": "promptString",
            "default": "0",
            "description": "Enter Process Id of process to attach to."
        }
    ]
}

you can then add the following to your csproj.

<MonoGameMGCBAdditionalArguments>/waitfordebugger</MonoGameMGCBAdditionalArguments>

This will cause the MGCB.exe to print the ProcessId
to the console during the build and wait for the debugger
to attach. Once you have the ProcessId you can run the
VSCode Attach to Process and enter the ProcessId when prompted.
The debugger should then attach.

If you want to prcess without attaching the debugger just hit any
key in the console or terminal windows where MGCB.exe is running.

@dellis1972 dellis1972 marked this pull request as ready for review April 7, 2024 18:04
@Akarinnnnn
Copy link

/d switch also seem to wait for debugger, too.
image

@dellis1972
Copy link
Contributor Author

/d switch also seem to wait for debugger, too. image

That switch will Launch Visual Studio on windows. It does nothing on MacOS/Linux.

The call to `System.Diagnostics.Debugger.Launch` is
not supported on Unix based platforms. This makes
debugging `MGCB.exe` and Content Pipeline extensions
difficult.

So lets add a new argument which will make `MGCB.exe`
wait for a debugger to attach. Also add a extra
update to the `launch.json` to demonstrate how to
attach the `dotnet` debugger to an existing process.

This new system will also work on Windows.

To use this in VSCode you can add the following to the
`launch.json`

```json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Process",
            "type": "coreclr",
            "request": "attach",
            "processId": "${input.processid}",
        }
    ],
    "inputs": [
        {
            "id": "processid",
            "type": "promptString",
            "default": "0",
            "description": "Enter Process Id of process to attach to."
        }
    ]
}
```

you can then add the following to your `csproj`.

```
<MonoGameMGCBAdditionalArguments>/waitfordebugger</MonoGameMGCBAdditionalArguments>
```

This will cause the `MGCB.exe` to print the ProcessId
to the console during the build and wait for the debugger
to attach. Once you have the ProcessId you can run the
VSCode `Attach to Process` and enter the ProcessId when prompted.
The debugger should then attach.

If you want to prcess without attaching the debugger just hit any
key in the console or terminal windows where `MGCB.exe` is running.
@SimonDarksideJ
Copy link
Contributor

Is the PR ready for re-review yet @dellis1972 ?

@dellis1972 dellis1972 changed the title Add /waitfordebugger argument to MGCB. Update /launchdebugger argument to MGCB to work on MacOS/Linux. Jun 8, 2024
@dellis1972
Copy link
Contributor Author

@SimonDarksideJ it is.

Copy link
Contributor

@SimonDarksideJ SimonDarksideJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@dellis1972
Copy link
Contributor Author

ok gonna revert back to the new /waitfordebugger option as Debugger.Launch on windows only offers a VS option. VSCode or other IDE's are not supported 🤦 . So for VSCode / Rider to work we need to have a separate option

@dellis1972 dellis1972 changed the title Update /launchdebugger argument to MGCB to work on MacOS/Linux. Add /waitfordebugger argument to MGCB. Jun 9, 2024
@dellis1972 dellis1972 merged commit b1244f1 into MonoGame:develop Jun 10, 2024
4 checks passed
@dellis1972 dellis1972 deleted the attachdebugger branch June 10, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants