using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Mse.Library;
using System.Diagnostics;
using Microsoft.Samples.Debugging.CorDebug;
using Microsoft.Samples.Debugging.CorPublish;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Process [] processes = Process.GetProcessesByName("Sample");
            if (processes.Length == 0)
            {
                return;
            }

            int targetProcessId = processes[0].Id;

            string txt = CorDebugger.GetDefaultDebuggerVersion();
            CorDebugger debugger = new CorDebugger(txt);
            using (ProcessInfo procInfo = new ProcessInfo(targetProcessId, debugger))
            {
                procInfo.UpdateAllStackTraces(0);

                foreach (var info in procInfo.ThreadInfos)
                {
                    Console.WriteLine("================");
                    foreach (var frame in info.Value.FrameStack)
                    {
                        Console.WriteLine(frame.FunctionShortName);
                    }
                }
            }

        }
    }
}
