Samsung / netcoredbg

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

Allow reading from stdin #167

Closed Armando-CodeCafe closed 3 months ago

Armando-CodeCafe commented 3 months ago

Currently it is not possible to read from STDIN while debugging an application. This makes is pretty much impossible to debug console applications as the moment a single Console.ReadLine() is met the application will throw a System.InvalidOperation Exception due to the console class not being able to read from anything.

Is there plans to implement this? shouldnt be all to hard considering almost every debugger can do this either natively or by running a seperate console to do the work from.

viewizard commented 3 months ago

Not sure we will implement this for MI/GDB or VSCode protocols, since this mean support external console for application stdin/stdout, that not in plans.

Works fine with CLI:

viewizard@VirtualBox123:~/Desktop/projects/netcoredbg/bin$ ./netcoredbg -- dotnet '/home/viewizard/Desktop/projects_test/test_interop/bin/Debug/net6.0/test_interop.dll'
ncdb> r

thread created, id: 5595
^running

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.22/System.Private.CoreLib.dll
no symbols loaded, base address: 0x7f4f102b0000, size: 10610176(0xa1e600)

library loaded: /home/viewizard/Desktop/projects_test/test_interop/bin/Debug/net6.0/test_interop.dll
symbols loaded, base address: 0x7f4f882b3000, size: 6144(0x1800)

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.22/System.Runtime.dll
no symbols loaded, base address: 0x7f4f882ab000, size: 32256(0x7e00)

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.22/System.Threading.Thread.dll
no symbols loaded, base address: 0x7f4f882a9000, size: 5632(0x1600)

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.22/System.Console.dll
no symbols loaded, base address: 0x7f4f10e30000, size: 376832(0x5c000)

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.22/System.Runtime.InteropServices.dll
no symbols loaded, base address: 0x7f4f10e90000, size: 238592(0x3a400)

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.22/System.Threading.dll
no symbols loaded, base address: 0x7f4f10ed0000, size: 266752(0x41200)

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.22/Microsoft.Win32.Primitives.dll
no symbols loaded, base address: 0x7f4f10f40000, size: 210944(0x33800)
Managed: Start

thread created, id: 5618
start thread1
mmmmm234234234
Managed: test input=mmmmm234234234
Managed: test output
Native: Start
native_method_test1

thread exited, id: 5618
werwerwer1234234234234234
Native: test input=werwerwer1234234234234234
native_method_test1
native_method_test2
test_delegate
test_delegate
Native: test output
Native: End

thread created, id: 5620

thread exited, id: 5620
Managed: End

thread created, id: 5616

stopped, reason: exited, exit-code: 0
^exit
Armando-CodeCafe commented 3 months ago

Hmm odd, whenever running this from cli with a simple console app it always returns a System.InvalidOperation with a message saying the application is probably not ran through an interactive console or stdin is being redirected

Armando-CodeCafe commented 3 months ago

Update: found out readline is fine but readkey returns the error. Could be due to some oddities in how console.readkey deals with terminal events?

viewizard commented 3 months ago

I also could reproduce this issue with Console.ReadKey(). Looks like Console.ReadKey() can't work with layer we have implemented over real console for debuggee process.