Skip to content

Commit 9e72147

Browse files
author
Pavel Zeman
committed
Initial commit
1 parent 5005b64 commit 9e72147

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+19075
-0
lines changed

nstack.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio 14
3+
VisualStudioVersion = 14.0.25420.1
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nstack", "nstack\nstack.csproj", "{87F332C5-C3B3-4606-8885-742B6E5FC141}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{87F332C5-C3B3-4606-8885-742B6E5FC141}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{87F332C5-C3B3-4606-8885-742B6E5FC141}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{87F332C5-C3B3-4606-8885-742B6E5FC141}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{87F332C5-C3B3-4606-8885-742B6E5FC141}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(TestCaseManagementSettings) = postSolution
22+
CategoryFile = mse.vsmdi
23+
EndGlobalSection
24+
EndGlobal

nstack/CorApi/AppDomain.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//---------------------------------------------------------------------
2+
// This file is part of the CLR Managed Debugger (mdbg) Sample.
3+
//
4+
// Copyright (C) Microsoft Corporation. All rights reserved.
5+
//---------------------------------------------------------------------
6+
using System;
7+
using System.Text;
8+
9+
using Microsoft.Samples.Debugging.CorDebug.NativeApi;
10+
11+
namespace Microsoft.Samples.Debugging.CorDebug
12+
{
13+
public sealed class CorAppDomain : CorController
14+
{
15+
/** Create an CorAppDomain object. */
16+
internal CorAppDomain (ICorDebugAppDomain appDomain)
17+
: base (appDomain)
18+
{
19+
}
20+
21+
/** Get the ICorDebugAppDomain interface back from the Controller. */
22+
private ICorDebugAppDomain _ad ()
23+
{
24+
return (ICorDebugAppDomain) GetController();
25+
}
26+
27+
/** Get the process containing the CorAppDomain. */
28+
public CorProcess Process
29+
{
30+
get
31+
{
32+
ICorDebugProcess proc = null;
33+
_ad().GetProcess (out proc);
34+
return CorProcess.GetCorProcess (proc);
35+
}
36+
}
37+
38+
/** The name of the CorAppDomain */
39+
public String Name
40+
{
41+
get
42+
{
43+
uint size = 0;
44+
_ad().GetName (0, out size, null);
45+
StringBuilder szName = new StringBuilder((int)size);
46+
_ad().GetName ((uint)szName.Capacity, out size, szName);
47+
return szName.ToString();
48+
}
49+
}
50+
51+
/**
52+
* Attach the AppDomain to receive all CorAppDomain related events (e.g.
53+
* load assembly, load module, etc.) in order to debug the AppDomain.
54+
*/
55+
public void Attach ()
56+
{
57+
_ad().Attach ();
58+
}
59+
60+
/** Get the ID of this CorAppDomain */
61+
public int Id
62+
{
63+
get
64+
{
65+
uint id = 0;
66+
_ad().GetID (out id);
67+
return (int) id;
68+
}
69+
}
70+
}
71+
}

nstack/CorApi/Assembly.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//---------------------------------------------------------------------
2+
// This file is part of the CLR Managed Debugger (mdbg) Sample.
3+
//
4+
// Copyright (C) Microsoft Corporation. All rights reserved.
5+
//---------------------------------------------------------------------
6+
using System;
7+
8+
using Microsoft.Samples.Debugging.CorDebug.NativeApi;
9+
10+
namespace Microsoft.Samples.Debugging.CorDebug
11+
{
12+
/**
13+
* Information about an Assembly being debugged.
14+
*/
15+
public sealed class CorAssembly : WrapperBase
16+
{
17+
private ICorDebugAssembly m_asm;
18+
19+
internal CorAssembly (ICorDebugAssembly managedAssembly)
20+
:base(managedAssembly)
21+
{
22+
m_asm = managedAssembly;
23+
}
24+
25+
/** Get the AppDomain containing the assembly. */
26+
public CorAppDomain AppDomain
27+
{
28+
get
29+
{
30+
ICorDebugAppDomain ad = null;
31+
m_asm.GetAppDomain (out ad);
32+
return new CorAppDomain (ad);
33+
}
34+
}
35+
36+
37+
/** The name of the assembly. */
38+
public String Name
39+
{
40+
get
41+
{
42+
char[] name = new char[300];
43+
uint sz = 0;
44+
m_asm.GetName ((uint) name.Length, out sz, name);
45+
// ``sz'' includes terminating null; String doesn't handle null,
46+
// so we "forget" it.
47+
return new String (name, 0, (int) (sz-1));
48+
}
49+
}
50+
51+
} /* class Assembly */
52+
} /* namespace debugging */

nstack/CorApi/ChainEnumerator.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//---------------------------------------------------------------------
2+
// This file is part of the CLR Managed Debugger (mdbg) Sample.
3+
//
4+
// Copyright (C) Microsoft Corporation. All rights reserved.
5+
//---------------------------------------------------------------------
6+
using System;
7+
using System.Collections;
8+
9+
using Microsoft.Samples.Debugging.CorDebug.NativeApi;
10+
11+
namespace Microsoft.Samples.Debugging.CorDebug
12+
{
13+
/**
14+
* Exposes an enumerator for Chains.
15+
*
16+
* This is horribly broken at this point, as Chains aren't implemented yet.
17+
*/
18+
internal class CorChainEnumerator : IEnumerable, IEnumerator, ICloneable
19+
{
20+
private ICorDebugChainEnum m_enum;
21+
22+
private CorChain m_chain;
23+
24+
internal CorChainEnumerator (ICorDebugChainEnum chainEnumerator)
25+
{
26+
m_enum = chainEnumerator;
27+
}
28+
29+
//
30+
// ICloneable interface
31+
//
32+
public Object Clone ()
33+
{
34+
ICorDebugEnum clone = null;
35+
m_enum.Clone (out clone);
36+
return new CorChainEnumerator ((ICorDebugChainEnum)clone);
37+
}
38+
39+
//
40+
// IEnumerable interface
41+
//
42+
public IEnumerator GetEnumerator ()
43+
{
44+
return this;
45+
}
46+
47+
//
48+
// IEnumerator interface
49+
//
50+
public bool MoveNext ()
51+
{
52+
ICorDebugChain[] a = new ICorDebugChain[1];
53+
uint c = 0;
54+
int r = m_enum.Next ((uint)a.Length, a, out c);
55+
if (r==0 && c==1) // S_OK && we got 1 new element
56+
m_chain = new CorChain (a[0]);
57+
else
58+
m_chain = null;
59+
return m_chain != null;
60+
}
61+
62+
public void Reset ()
63+
{
64+
m_enum.Reset ();
65+
m_chain = null;
66+
}
67+
68+
public Object Current
69+
{
70+
get
71+
{
72+
return m_chain;
73+
}
74+
}
75+
} /* class ChainEnumerator */
76+
} /* namespace */

nstack/CorApi/Class.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//---------------------------------------------------------------------
2+
// This file is part of the CLR Managed Debugger (mdbg) Sample.
3+
//
4+
// Copyright (C) Microsoft Corporation. All rights reserved.
5+
//---------------------------------------------------------------------
6+
using System;
7+
8+
using Microsoft.Samples.Debugging.CorDebug.NativeApi;
9+
10+
namespace Microsoft.Samples.Debugging.CorDebug
11+
{
12+
public sealed class CorClass : WrapperBase
13+
{
14+
internal ICorDebugClass m_class;
15+
16+
internal CorClass (ICorDebugClass managedClass)
17+
: base(managedClass)
18+
{
19+
m_class = managedClass;
20+
}
21+
22+
23+
/** The module containing the class */
24+
public CorModule Module
25+
{
26+
get
27+
{
28+
ICorDebugModule m = null;
29+
m_class.GetModule (out m);
30+
return new CorModule (m);
31+
}
32+
}
33+
34+
/** The metadata typedef token of the class. */
35+
public int Token
36+
{
37+
get
38+
{
39+
uint td = 0;
40+
m_class.GetToken (out td);
41+
return (int) td;
42+
}
43+
}
44+
45+
46+
public CorType GetParameterizedType(CorElementType elementType, CorType[] typeArguments)
47+
{
48+
ICorDebugType[] types = null;
49+
uint length = 0;
50+
if (typeArguments != null)
51+
{
52+
types = new ICorDebugType[typeArguments.Length];
53+
for (int i = 0; i < typeArguments.Length; i++)
54+
types[i] = typeArguments[i].m_type;
55+
length = (uint)typeArguments.Length;
56+
}
57+
58+
ICorDebugType pType;
59+
(m_class as ICorDebugClass2).GetParameterizedType(elementType, length, types, out pType);
60+
return pType==null?null:new CorType (pType);
61+
}
62+
63+
64+
} /* class Class */
65+
66+
} /* namespace */

nstack/CorApi/Constants.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//---------------------------------------------------------------------
2+
// This file is part of the CLR Managed Debugger (mdbg) Sample.
3+
//
4+
// Copyright (C) Microsoft Corporation. All rights reserved.
5+
//---------------------------------------------------------------------
6+
using System;
7+
8+
namespace Microsoft.Samples.Debugging.CorDebug
9+
{
10+
11+
public enum CorDebuggerVersion
12+
{
13+
RTM = 1, //v1.0
14+
Everett = 2, //v1.1
15+
Whidbey = 3, //v2.0
16+
}
17+
18+
19+
20+
public abstract class TokenUtils
21+
{
22+
public static int RidFromToken(int token)
23+
{
24+
return (int)( (UInt32)token & 0x00ffffff);
25+
}
26+
27+
public static bool IsNullToken(int token)
28+
{
29+
return (RidFromToken(token)==0);
30+
}
31+
}
32+
33+
34+
}

0 commit comments

Comments
 (0)