Thalia
Thalia

Reputation: 14605

Debugging a c# application in WinDbg

I am trying to debug an application written in C#, on a system where I do not have Visual Studio. The application is not crashing... But I need to determine the values of certain variables, and whether certain parts of the code are accessed, based on a driver that I cannot have access to in the same location where Visual Studio is located.

I am running this test environment in a Virtual machine, with no internet access. I have been unable to install symbol file... but that has been irrelevant so far.

I have been troubleshooting the driver (c/c++) using WinDbg, attached to this application. I was hoping to be able to send debug messages to WinDbg as well, from C#.

System.Diagnostics.Debug.Write("hello world\n");

Did not show up... I don't know if related, but the only different thing that I noticed when adding a Debug.Write was a new exception that I have not seen without the debug calls... (which try to display very innocent variables)

(c78.808): C++ EH exception - code e06d7363 (first chance)
(c78.808): C++ EH exception - code e06d7363 (first chance)
(c78.808): Access violation - code c0000005 (first chance)

How can I send these messages to WinDbg output attached to this application in C# ?

Upvotes: 5

Views: 1496

Answers (2)

user2010489
user2010489

Reputation: 76

Try using DebugView, that should show your debug messages and it has no dependencies, make sure you capture global win32 events and that Visual Studio hasn't got itself attached though.

Upvotes: 3

blabb
blabb

Reputation: 8987

in your project properties check mark BOTH DEFINE TRACE constant and DEFINE DEBUG constant

Debug.WriteLIne as well ad Trace.Writeline output will be visible in windbg

code

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            Console.WriteLine("we should see both Debug and Trace .WriteLine\n");
            System.Diagnostics.Trace.WriteLine("This is From Debug.WriteLine\n");
            System.Diagnostics.Debug.WriteLine("This is From Trace.WriteLine\n");
            System.Diagnostics.Trace.WriteLine("This is From Debug.WriteLine\n");
            System.Diagnostics.Debug.WriteLine("This is From Trace.WriteLine\n");
            Console.WriteLine("watched 2 Dbg and 2 Trace WriteLine in windbg\n");
            System.Diagnostics.Trace.WriteLine("This is From Debug.WriteLine\n");
            System.Diagnostics.Debug.WriteLine("This is From Trace.WriteLine\n");
            System.Diagnostics.Trace.WriteLine("This is From Debug.WriteLine\n");
            System.Diagnostics.Debug.WriteLine("This is From Trace.WriteLine\n");
        }
    }
}

output

:cdb -c "g;q" helloWorld.exe | grep -i WriteLine
we should see both Debug and Trace .WriteLine
This is From Debug.WriteLine
This is From Trace.WriteLine
This is From Debug.WriteLine
This is From Trace.WriteLine
watched 2 Dbg and 2 Trace WriteLine in windbg
This is From Debug.WriteLine
This is From Trace.WriteLine
This is From Debug.WriteLine
This is From Trace.WriteLine

Upvotes: 1

Related Questions