-
Notifications
You must be signed in to change notification settings - Fork 30
/
Program.cs
73 lines (63 loc) · 2.78 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using CommandLine;
using SharpDebug.Engine.Debuggers;
using SharpDebug.Engine.Utility;
using DbgEng;
using System;
namespace SharpDebug.Engine.Test
{
class Options
{
[Option('d', "dump", Default = "NativeDumpTest.x64.dmp", HelpText = "Path to memory dump file that will be debugged")]
public string DumpPath { get; set; }
[Option('p', "symbol-path", Default = @"srv*;.\", HelpText = "Symbol path to be set in debugger")]
public string SymbolPath { get; set; }
[Option("use-dwarf", Default = false, HelpText = "Use DWARF symbol provider")]
public bool UseDwarfSymbolProvider { get; set; }
}
class Program
{
static void Main(string[] args)
{
Options options = null;
Parser.Default.ParseArguments<Options>(args)
.WithParsed(o => options = o);
if (options == null)
return;
DebuggerInitialization.OpenDump(options.DumpPath, options.SymbolPath);
Console.WriteLine("Threads: {0}", Thread.All.Length);
Console.WriteLine("Current thread: {0}", Thread.Current.Id);
var frames = Thread.Current.StackTrace.Frames;
Console.WriteLine("Call stack:");
foreach (var frame in frames)
try
{
Console.WriteLine(" {0,3:x} {1}+0x{2:x} ({3}:{4})", frame.FrameNumber, frame.FunctionName, frame.FunctionDisplacement, frame.SourceFileName, frame.SourceFileLine);
}
catch (Exception)
{
Console.WriteLine(" {0,3:x} {1}+0x{2:x}", frame.FrameNumber, frame.FunctionName, frame.FunctionDisplacement);
}
// In order to use console output and error in scripts, we must set it to debug client
DebugOutput captureFlags = DebugOutput.Normal | DebugOutput.Error | DebugOutput.Warning | DebugOutput.Verbose
| DebugOutput.Prompt | DebugOutput.PromptRegisters | DebugOutput.ExtensionWarning | DebugOutput.Debuggee
| DebugOutput.DebuggeePrompt | DebugOutput.Symbols | DebugOutput.Status;
var callbacks = DebuggerOutputToTextWriter.Create(Console.Out, captureFlags);
using (OutputCallbacksSwitcher switcher = OutputCallbacksSwitcher.Create(callbacks))
{
Action action = () =>
{
ScriptExecution.Execute(@"..\..\samples\script.csx", args);
};
DbgEngDll dbgEngDll = Context.Debugger as DbgEngDll;
if (dbgEngDll != null)
{
dbgEngDll.ExecuteAction(action);
}
else
{
action();
}
}
}
}
}