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

Debugging simple console app on windows.... #92

Closed
amine-aboufirass opened this issue Jun 10, 2022 · 33 comments
Closed

Debugging simple console app on windows.... #92

amine-aboufirass opened this issue Jun 10, 2022 · 33 comments

Comments

@amine-aboufirass
Copy link

I'm interested in giving this debugger a try but it looks like there are only instructions for building the code from source. Would be nice if there were instructions for just installing using the binaries for a given release.

@viewizard
Copy link
Member

viewizard commented Jun 10, 2022

Not sure what kind of instruction you need for binaries... all you need is unzip it in folder you like and execute netcoredbg.exe (win) or netcoredbg (linux/mac) binary file in terminal you like. Same usage as all CLI programs have.

Might be interested for you:
https://github.com/Samsung/netcoredbg#running-netcoredbg
https://github.com/Samsung/netcoredbg/blob/master/doc/cli.md

@amine-aboufirass
Copy link
Author

@viewizard I figured as much and got it to work. Still, it would be nice to have a couple of lines somewhere in the readme file to explain it to novice users. If you like I'd be more than happy to add that in for you.

I'm having a bit of trouble getting it to run for a simple console app in C# though. I tried something like this:

netcoredbg --interpreter=cli -- dotnet .\longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.exe

Then file Program.cs and then run but nothing happened. What am I doing wrong here?

@viewizard
Copy link
Member

netcoredbg --interpreter=cli -- dotnet .\longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.exe

Then file Program.cs and then run but nothing happened. What am I doing wrong here?

I believe, you should use .dll for debug instead, since .exe is just wrapper in order to start .dll as common executable file.

@amine-aboufirass
Copy link
Author

@viewizard OK... I had no idea executables were just wrappers around the DLLs. That's very good to know.

I have several DLLs for my simple Console app:

longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.dll
longest_common_prefix\obj\Debug\net6.0\longest_common_prefix.dll
longest_common_prefix\obj\Debug\net6.0\ref\longest_common_prefix.dll
longest_common_prefix\obj\Debug\net6.0\refint\longest_common_prefix.dll

Which one should I use for netcoredbg?

@viewizard
Copy link
Member

@gbalykov
Copy link
Member

After this command:

netcoredbg --interpreter=cli -- dotnet .\longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.dll

simply type r and enter

@amine-aboufirass
Copy link
Author

amine-aboufirass commented Jun 10, 2022

@viewizard and @gbalykov Thank you for your help. It is getting a bit clearer. Unfortunately I still can't get it to work. Here's a couple of attempts. In the fourth attempt I am trying to follow the recommendations provided in the walkthrough more or less exactly:

First attempt

$ netcoredbg --interpreter=cli -- dotnet .\longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.dll
ncdb> run

Second attempt

$ netcoredbg --interpreter=cli -- dotnet .\longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.dll
ncdb> r

Third attempt

$ netcoredbg --interpreter=cli -- dotnet $ .\longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.dll
ncdb> file dotnet
ncdb> r

Fourth attempt

$ netcoredbg --interpreter=cli
ncdb> file dotnet .\longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.dll
ncdb> set args longest_common_prefix/Program.cs
ncdb> break longest_common_prefix/Program.cs:50
ncdb> run

In all cases, after I press enter on run or r, nothing happens and the prompt exits out of ncdb. Any assistance would be most welcome.

@viewizard
Copy link
Member

If you start dotnet .\longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.dll without debugger, is it works?
Please provide your output for dotnet --info.
Any chance you could share sources for project, so, we could test from our side?

@amine-aboufirass
Copy link
Author

dotnet .\longest_common_prefix\bin\Debug\net6.0\longest_common_prefix.dll generates the same output as dotnet run --project=longest_common_prefix so I assume it works.

The output for dotnet --info is as follows:

.NET SDK (reflecting any global.json):
 Version:   6.0.300
 Commit:    8473146e7d

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.300\

Host (useful for support):
  Version: 6.0.5
  Commit:  70ae3df4a6

.NET SDKs installed:
  6.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

I'm happy to share the source code, it's just a dummy example in Program.cs which generates a runtime error:

using System;
using System.Reflection;


public class Solution 
{
    public string LongestCommonPrefix(string[] strs)
    {
        bool isEqual = true;
        int count = 0;
        List<char> chars = new List<char>();
        string result = "";

        while (isEqual)
        {
            chars.Clear();

            foreach (string str in strs)
            {
                chars.Add(str[count]);    
            }

            isEqual = chars.Distinct().ToList().Count == 1;

            if (isEqual)
            {
                result += chars[0];
            }

            count += 1;
        }

        return result;
    }
}

class Test
{
    
    public static void Main()
    {
        // Contraints include following:
        // 1 <= strs.length <= 200
        // 0 <= strs[i].length <= 200
        //strs[i] consists of only lower-case English letters

        List<string[]> inputs = new List<string[]>();

        inputs.Add(new string[] {"flower", "flow", "flight"});
        inputs.Add(new string[] {"dog", "racecar", "car"});
        inputs.Add(new string[] {"mamba", "mam", "ma"});
        Solution s = new Solution();

        foreach (string[] strs in inputs)
        {
            Console.WriteLine(s.LongestCommonPrefix(strs));
        }

    }
}

With the following project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <EmbedAllSources>true</EmbedAllSources>
  </PropertyGroup>

</Project>

@viewizard
Copy link
Member

I can confirm, this looks like some issue in CLI:

PS C:\Users\m.kurinnoi\Desktop\test> C:\Users\m.kurinnoi\Desktop\netcoredbg-win64\netcoredbg\netcoredbg.exe --interpreter=cli -- dotnet C:\Users\m.kurinnoi\Desktop\test\bin\Debug\net6.0\test.dll
ncdb> r
PS C:\Users\m.kurinnoi\Desktop\test>

in the same time MI/GDB works as it should:

PS C:\Users\m.kurinnoi\Desktop\test> C:\Users\m.kurinnoi\Desktop\netcoredbg-win64\netcoredbg\netcoredbg.exe --interpreter=mi -- dotnet C:\Users\m.kurinnoi\Desktop\test\bin\Debug\net6.0\test.dll
(gdb)
-exec-run
^running
(gdb)
=library-loaded,id="{5956701c-92ec-47bc-9814-5555cd08eafc}",target-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Private.CoreLib.dll",host-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Private.CoreLib.dll",symbols-loaded="0",base-address="0x7ffb24670000",size="10629120"
=thread-created,id="22264"
=library-loaded,id="{b2aa3046-c3bf-4fdb-a916-1317e491da55}",target-name="C:\\Users\\m.kurinnoi\\Desktop\\test\\bin\\Debug\\net6.0\\test.dll",host-name="C:\\Users\\m.kurinnoi\\Desktop\\test\\bin\\Debug\\net6.0\\test.dll",symbols-loaded="1",base-address="0x14165ef0000",size="32768"
=library-loaded,id="{b7719cbc-99c9-4742-9ac4-9e89adf467de}",target-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Runtime.dll",host-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Runtime.dll",symbols-loaded="0",base-address="0x14165f00000",size="57344"
=library-loaded,id="{8fa4bb97-9fd7-44da-a990-deab5d5c387d}",target-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Collections.dll",host-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Collections.dll",symbols-loaded="0",base-address="0x7ffb3dae0000",size="262144"
=library-loaded,id="{bb8c8507-5772-4b77-88c5-a4af222a586f}",target-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Console.dll",host-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Console.dll",symbols-loaded="0",base-address="0x7ffb4e380000",size="155648"
*stopped,reason="entry-point-hit",thread-id="22264",stopped-threads="all",frame={file="Program.cs",fullname="C:\\Users\\m.kurinnoi\\Desktop\\test\\Program.cs",line="41",col="5",end-line="41",end-col="6",clr-addr={module-id="{b2aa3046-c3bf-4fdb-a916-1317e491da55}",method-token="0x06000007",il-offset="0",native-offset="85"},func="Test.Main()",addr="0x000000236637e8f0"}
(gdb)
-exec-continue
^running
(gdb)
=library-loaded,id="{66769cbf-eae1-4a56-a4cf-5a826836f68d}",target-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Linq.dll",host-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Linq.dll",symbols-loaded="0",base-address="0x7ffb27f20000",size="532480"
=library-loaded,id="{cbd304c3-b4d5-446c-84d9-48a2ed97a98c}",target-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Threading.dll",host-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Threading.dll",symbols-loaded="0",base-address="0x7ffb51760000",size="77824"
=library-loaded,id="{c125529b-99ec-46dc-a160-fc4c66d91452}",target-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Text.Encoding.Extensions.dll",host-name="C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\6.0.5\\System.Text.Encoding.Extensions.dll",symbols-loaded="0",base-address="0x14165f10000",size="32768"
=message,text="fl\r\n",send-to="output-window"
=message,text="\r\n",send-to="output-window"
*stopped,reason="exception-received",exception-name="System.IndexOutOfRangeException",exception="Index was outside the bounds of the array.",exception-stage="unhandled",exception-category="clr",thread-id="22264",stopped-threads="all",frame={clr-addr={module-id="{5956701c-92ec-47bc-9814-5555cd08eafc}",method-token="0x06001cb1",il-offset="5",native-offset="53"},func="System.ThrowHelper.ThrowIndexOutOfRangeException()",addr="0x000000236637e7b0"}
(gdb)
-gdb-exit
*stopped,reason="exited",exit-code="0"
(gdb)
^exit
(gdb)
PS C:\Users\m.kurinnoi\Desktop\test>

You could use MI/GDB for now, we don't have docs for this protocol, but you could see all implemented commands in sources:
https://github.com/Samsung/netcoredbg/blob/master/src/protocols/miprotocol.cpp#L675-L1077
this protocol looks close to CLI, for example
run process: -exec-run
set breakpoint: -break-insert Program.cs:10
continue execution: -exec-continue
exit from debugger: -gdb-exit

@amine-aboufirass
Copy link
Author

amine-aboufirass commented Jun 10, 2022

@viewizard what's the difference between the MI/GDB and CLI? What advantages does the CLI have which MI/GDB doesn't?

Also it's quite surprising that the CLI is "broken" for pretty much the simplest possible C# application, namely a console app. One might wonder whether the CLI really works at all? Does it work for other .NET templates?

Sorry, I'm not trying to undermine your work but just trying to understand what I'm missing here...

@amine-aboufirass
Copy link
Author

@viewizard Also, I just gave MI/GDB a try. It's very cryptic and difficult to read... also is there a way to print out the value of just one variable?

@viewizard
Copy link
Member

viewizard commented Jun 10, 2022

@viewizard what's the difference between the MI/GDB and CLI? What advantages does the CLI have which MI/GDB doesn't?

MI/GDB aimed for parce by computer, for GUI/plugin usage, CLI aimed for humans.

Also it's quite surprising that the CLI is "broken" for pretty much the simplest possible C# application, namely a console app. One might wonder whether the CLI really works at all? Does it work for other .NET templates?

Sorry, I'm not trying to undermine your work but just trying to understand what I'm missing here...

This is OK :-), this looks like some code was added in CLI protocol, but not tested well or even don't work from the beginning. Note, initially we have only VSCode and MI/GDB protocols support.
I just found, that this issue connected to Windows only, CLI works well on Linux:

$ /home/viewizard/Desktop/projects/netcoredbg/bin/netcoredbg --interpreter=cli -- dotnet '/home/viewizard/Desktop/projects_test/test_unhand_exception/bin/Debug/net6.0/test.dll' 
ncdb> break Program.cs:50
 Breakpoint 1 at Program.cs:50 --pending, warning: No executable code of the debugger's target code type is associated with this line.
ncdb> r
^running

thread created, id: 75461

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.3/System.Private.CoreLib.dll
no symbols loaded, base address: 0x7f009b250000, size: 10601472(0xa1c400)

library loaded: /home/viewizard/Desktop/projects_test/test_unhand_exception/bin/Debug/net6.0/test.dll
symbols loaded, base address: 0x7f0115ad1000, size: 6144(0x1800)
breakpoint modified,  Breakpoint 1 at /home/viewizard/Desktop/projects_test/test_unhand_exception/Program.cs:50

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

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.3/System.Collections.dll
no symbols loaded, base address: 0x7f009bdd0000, size: 455168(0x6f200)

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

stopped, reason: breakpoint 1 hit, thread id: 75461, stopped threads: all, times= 1, frame={Test.Main() at /home/viewizard/Desktop/projects_test/test_unhand_exception/Program.cs:50
}
ncdb> c
^running

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.3/System.Linq.dll
no symbols loaded, base address: 0x7f009bec0000, size: 726016(0xb1400)

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

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


stopped, reason: exception received, name: System.IndexOutOfRangeException, exception: Index was outside the bounds of the array., stage: unhandled, category: clr, thread id: 75461, stopped-threads: all, frame={System.ThrowHelper.ThrowIndexOutOfRangeException()
}
ncdb> c
^running
Unhandled exception. 
library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.3/System.Diagnostics.StackTrace.dll
no symbols loaded, base address: 0x7f009c080000, size: 222720(0x36600)

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.3/System.Reflection.Metadata.dll
no symbols loaded, base address: 0x7f009c0d0000, size: 1301504(0x13dc00)

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.3/System.Collections.Immutable.dll
no symbols loaded, base address: 0x7f009c230000, size: 785920(0xbfe00)

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

library loaded: /home/viewizard/Desktop/SDK/dotnet-sdk/shared/Microsoft.NETCore.App/6.0.3/System.Text.Encoding.Extensions.dll
no symbols loaded, base address: 0x7f0110208000, size: 5632(0x1600)
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.String.get_Chars(Int32 index)
   at Solution.LongestCommonPrefix(String[] strs) in /home/viewizard/Desktop/projects_test/test_unhand_exception/Program.cs:line 20
   at Test.Main() in /home/viewizard/Desktop/projects_test/test_unhand_exception/Program.cs:line 56

stopped, reason: exited, exit-code: 1
^exit

@amine-aboufirass amine-aboufirass changed the title No instructions on how to install from binaries Debugging simple console app on windows.... Jun 10, 2022
@amine-aboufirass
Copy link
Author

Any pointers on how to fix this so Windows users can also use the CLI?

@viewizard
Copy link
Member

@viewizard Also, I just gave MI/GDB a try. It's very cryptic and difficult to read... also is there a way to print out the value of just one variable?

< (gdb)
> -var-create - * "litDouble"
< ^done,name="var22",value="310.1",attributes="editable",exp="litDouble",numchild="0",type="double",thread-id="76281"
< (gdb)
> -var-create - * "varDecimal"
< ^done,name="var23",value="12",attributes="editable",exp="varDecimal",numchild="0",type="decimal",thread-id="76281"

in case you need static field:

< (gdb)
> -var-create - * "TestSetVarStruct.static_field_i"
< ^done,name="var38",value="3001",attributes="editable",exp="TestSetVarStruct.static_field_i",numchild="0",type="int",thread-id="76281"

in case you need some class/struct (ts4 is object instance of class):

< (gdb)
> -var-create - * "ts4"
< ^done,name="var4",value="{MITestVariables.TestStruct4}",attributes="editable",exp="ts4",numchild="2",type="MITestVariables.TestStruct4",thread-id="76281"
< (gdb)
> -var-list-children --simple-values "var4"
< ^done,numchild="2",children=[child={name="var5",value="666",attributes="editable",exp="val1",numchild="0",type="int",thread-id="76281"},child={name="var6",value="888",attributes="editable",exp="val3",numchild="0",type="int",thread-id="76281"}],has_more="0"

Any pointers on how to fix this so Windows users can also use the CLI?

We will investigate this issue, have no idea what is wrong for now, so, no ideas how to fix this.

@viewizard
Copy link
Member

@awa5114 looks like I found issue, during Win x86 support and code refactoring I lost static keyword... unfortunately, this code related only for Windows + CLI that we don't test in CI and nobody noticed this mistake during review. Here is patch that fix issue:

From 28defb5d7130d1f7a6736c46e5f7eb177743c010 Mon Sep 17 00:00:00 2001
From: Mikhail Kurinnoi <m.kurinnoi@samsung.com>
Date: Fri, 10 Jun 2022 18:01:42 +0300
Subject: [PATCH] Fix CLI work on Windows.

---
 src/utils/iosystem_win32.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/utils/iosystem_win32.cpp b/src/utils/iosystem_win32.cpp
index d206c6c..dc2d4e9 100644
--- a/src/utils/iosystem_win32.cpp
+++ b/src/utils/iosystem_win32.cpp
@@ -525,7 +525,7 @@ Class::IOSystem::StdFiles Class::get_std_files()
         std::max_align_t align_field;
         char mem[sizeof(Handles)];
     };
-    mem_align_t mem_align_tmp;
+    static mem_align_t mem_align_tmp;
     char * const mem = mem_align_tmp.mem;
 
     Handles& handles = *new (mem) Handles {
-- 
2.25.1

amine-aboufirass added a commit to amine-aboufirass/netcoredbg that referenced this issue Jun 13, 2022
@amine-aboufirass
Copy link
Author

amine-aboufirass commented Jun 13, 2022

@viewizard I've CCed you on a separate discussion here. Please take a look because @tommcdon makes an interesting point about the dbgshim dependency.

I added your proposed patch to my personal fork and I'm now trying to rebuild. I go into the build directory and run the following command:

cmake -G "Visual Studio 17 2022" -S ../ -B ./

This seems to work but I don't really see the resulting binaries anywhere, namely:

  • dbgshim.dll
  • ManagedPart.dll
  • Microsoft.CodeAnalysis.Csharp.dll
  • Microsoft.CodeAnalysis.Csharp.Scripting.dll
  • Microsoft.CodeAnalysis.dll
  • Microsoft.CodeAnalysis.Scripting.dll
  • netcoredbg.exe

So then I tried the following from within the build folder:

cmake --build . --target install

I'm not terribly familiar with CMake. How do I rebuild the code such that I can use the (patched) binaries? Where can I find the binaries in my local repo?

@viewizard
Copy link
Member

@viewizard I've CCed you on a separate discussion here. Please take a look because @tommcdon makes an interesting point about the dbgshim dependency.

We know about this upcoming changes in runtime 7.0, but it still in development. For now, we use (netcoredbg build script download it) .Net SDK 6.0 during build process and we use dbgshim from it. This will be revised after runtime 7.0 release.

I'm not terribly familiar with CMake. How do I rebuild the code such that I can use the (patched) binaries? Where can I find the binaries in my local repo?

Try -DCMAKE_INSTALL_PREFIX="%cd%\..\bin" or -DCMAKE_INSTALL_PREFIX="..\bin" (https://cmake.org/cmake/help/v3.0/variable/CMAKE_INSTALL_PREFIX.html).
Usually all you need is provide install path at first cmake call:

cmake .. -G "Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX="..\bin"
cmake --build . --target install

in this case you will see ./bin directory with all "installed" inside netcoredbg files right before your ./build directory.

@viewizard
Copy link
Member

It looks like the file does get run through the debugger now. But when I place a breakpoint I get a warning

This is correct behaviour, since you setup breakpoint before process start (and PDB loaded). But as soon as you have it started (ncdb> run), breakpoint was resolved at module load:

breakpoint modified,  Breakpoint 1 at C:\Users\aa\Desktop\TEMP\csharp_codility\longest_common_prefix\Program.cs:60

and after that you have break at this breakpoint:

stopped, reason: breakpoint 1 hit, thread id: 16452, stopped threads: all, times= 1, frame={Test.Main() at C:\Users\aa\Desktop\TEMP\csharp_codility\longest_common_prefix\Program.cs:60
}

Furthermore, the list does not "List source code lines, 5 by default." as the CLI doc explains.

Hmm, have no idea why you don't see sources, this should be investigated first.

ncdb> print inputs[0]
Error: 0x80004002: Indicates a bad cast condition

You can't print System.Collections.Generic.List<string[]> element by index, netcoredbg don't support this (at least for now), only simple arrays are supported.

@amine-aboufirass
Copy link
Author

amine-aboufirass commented Jun 14, 2022

You can't print System.Collections.Generic.List<string[]> element by index, netcoredbg don't support this (at least for now), only simple arrays are supported.

That's a little bit disappointing, one would think that indexing a list was pretty basic functionality. Perhaps netcoredbg was not built with C# debugging in mind? Would it be easy to add that in? I can maybe fool around with it a bit in my fork...

@alpencolt
Copy link
Contributor

@awa5114 CLI was introduced only in the end of 2021 and not all scenarios are possible now. We've made indexing for primitive types, but indexing in objects are more complex we have to find proper overlapped method and invoke it.
We'll implement it in nearest releases, thank you for feedback.

Now you can examine such values by calling my_list._items[i]

@viewizard
Copy link
Member

Eval for List[index] should work now. This feature added by commit c76038c

@amine-aboufirass
Copy link
Author

@viewizard I just gave netcoredbg another go and deduced that the CLI debugger is still not working for Windows. Has this issue been looked at yet? Being able to index a list is important but having binaries that work for Windows is more important IMO. Is it not just a simple matter of making a PR with your proposed fix using the static keyword?

@viewizard
Copy link
Member

Is it not just a simple matter of making a PR with your proposed fix using the static keyword?

We already have it in upstream code -

static mem_align_t mem_align_tmp;

Initial Windows terminal related issue should be fixed by 29c44a2 in Jul 18, 2022.
You mean, you can't start CLI in Windows terminal again?

@amine-aboufirass
Copy link
Author

amine-aboufirass commented Sep 21, 2023

I downloaded the most recent binaries today and I can't debug as shown below:

$ netcoredbg --interpreter=cli -- dotnet .\bin\Debug\net7.0\BasicDeserialize.dll
ncdb> break Program.cs:12
ncdb> r
$ 

It just exits out again without breaking... This happens on all terminals, not just Windows Terminal.

@gbalykov
Copy link
Member

Which version of windows do you use? Can you try to run netcoredbg tests? See more details at https://github.com/Samsung/netcoredbg/blob/master/test-suite/README.md

powershell.exe -executionpolicy bypass -File run_tests.ps1

@viewizard
Copy link
Member

Hmm... just tested latest release build on Windows x64 with fresh "dotnet new console" project:

> .\netcoredbg.exe
ncdb> file dotnet
ncdb> set args 1.dll
ncdb> b Program.cs:2
 Breakpoint 1 at Program.cs:2 --pending, warning: No executable code of the debugger's target code type is associated with this line.
ncdb> r
^running

library loaded: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.9\System.Private.CoreLib.dll
no symbols loaded, base address: 0x7fffa03e0000, size: 11644928(0xb1b000)

thread created, id: 12884

library loaded: C:\Users\m.kurinnoi\Desktop\1\bin\Debug\net7.0\1.dll
symbols loaded, base address: 0x1ee58400000, size: 32768(0x8000)
breakpoint modified,  Breakpoint 1 at C:\Users\m.kurinnoi\Desktop\1\Program.cs:2

library loaded: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.9\System.Runtime.dll
no symbols loaded, base address: 0x1ee58620000, size: 57344(0xe000)

library loaded: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.9\System.Console.dll
no symbols loaded, base address: 0x7fffd7070000, size: 172032(0x2a000)

stopped, reason: breakpoint 1 hit, thread id: 12884, stopped threads: all, times= 1, frame={Program.<Main>$() at C:\Users\m.kurinnoi\Desktop\1\Program.cs:2}
ncdb> bt
#0: 0x00007fff415606cd 1.dll` Program.<Main>$() at C:\Users\m.kurinnoi\Desktop\1\Program.cs:2

ncdb> c
^running

library loaded: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.9\System.Threading.dll
no symbols loaded, base address: 0x7fffedac0000, size: 77824(0x13000)

library loaded: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.9\System.Text.Encoding.Extensions.dll
no symbols loaded, base address: 0x1ee58630000, size: 32768(0x8000)

library loaded: C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.9\System.Runtime.InteropServices.dll
no symbols loaded, base address: 0x7fffedb00000, size: 53248(0xd000)
Hello, World!

thread created, id: 25540

stopped, reason: exited, exit-code: 0
^exit

works just fine...

@amine-aboufirass
Copy link
Author

@viewizard not for me it doesn't

$ netcoredbg.exe
ncdb> file dotnet
ncdb> set args .\bin\Debug\net7.0\BasicDeserialize.dll
ncdb> b Program.cs:12
ncdb> r
$

Here's the version info for the netcoredbg executable, which version are you using?

NET Core debugger 2.0.0-78 (becef4b, Release)

Copyright (c) 2020 Samsung Electronics Co., LTD
Distributed under the MIT License.
See the LICENSE file in the project root for more information.

@gbalykov
Copy link
Member

@amine-aboufirass you seem to be using very old version, try the latest one https://github.com/Samsung/netcoredbg/releases/tag/3.0.0-1006

@amine-aboufirass
Copy link
Author

Yes I just tried and it worked, thanks,.

@gbalykov
Copy link
Member

Closing this. If you have any more questions, please reopen

@amine-aboufirass
Copy link
Author

Ok, yeah it does work but it's weird because l/list doesn't seem to work...

@gbalykov
Copy link
Member

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

No branches or pull requests

4 participants