Samsung / netcoredbg

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

Location missing if unhandled Exception occurred in async Main #166

Open itn3000 opened 4 months ago

itn3000 commented 4 months ago

Overview

Cannot get location of unhandled exception occurred in async Main program.

Environment

Steps to reproduce

  1. create new console project
  2. open project with vscode
  3. write following code
  4. start vscode debugging session with following pipeTransport setting

code example

using System;
using System.Threading.Tasks;

class Program
{
    static void Abc()
    {
        throw new Exception();
    }
    static async Task Main()
    {
        await Task.Yield();
        Abc();
    }
}

pipeTransport setting

            "pipeTransport": {
                "pipeCwd": "${workspaceFolder}",
                "pipeProgram": "c:/Windows/System32/cmd.exe",
                "pipeArgs": ["/c"],
                "debuggerPath": "d:/bin/netcoredbg/netcoredbg.exe"
            }

Expected

program stops and display exception message.

Actual

program stopped but no message. callstack information is "Unknown Source"

Additional Information

edit Main function to sync, it works as expected.

gbalykov commented 4 months ago

Thanks for reporting, we'll take a look

viewizard commented 4 months ago

Looks like async methods should care about exceptions in another way:

<- (E) {"body":{"allThreadsStopped":true,"reason":"exception","text":"An unhandled exception of type 'System.Exception' occurred in System.Private.CoreLib.dll","threadId":93289},"event":"stopped","seq":"14","type":"event"}

plus, in this case we have some "exception handler" (not user code) Screenshot 2024-02-28 235650 in the same time, if I click on top frame, I see proper exception data: Screenshot 2024-02-29 001547

For example, MS C# debugger:

<- (E) {"seq":28,"type":"event","event":"stopped","body":{"reason":"exception","threadId":93792,"text":"An exception of type 'System.Exception' occurred in vscode_test.dll but was not handled in user code","allThreadsStopped":true,"source":{"name":"Program.cs","path":"/home/viewizard/Desktop/projects_test/vscode_test/Program.cs"},"line":8,"column":9}}

Screenshot 2024-02-29 001147