MixedModeStack_demo
CppCliApp.exe
CppCliApp.ilk
CppCliApp.pdb
DiagApp.exe
DiagApp.ilk
DiagApp.pdb
ManagedLib0.dll
ManagedLib0.pdb
MixedLib1.dll
MixedLib1.ilk
MixedLib1.pdb
MixedStackTraceLibrary.dll
MixedStackTraceLibrary.ilk
MixedStackTraceLibrary.pdb
StackTraceLibrary.dll
StackTraceLibrary.pdb
StackWalk64App.exe
StackWalk64App.ilk
StackWalk64App.pdb
MixedModeStack_src
SampleApps
CppCliApp
app.ico
CppCliApp.vcxproj.user
Debug
CppCliApp.Build.CppClean.log
CppCliApp.log
Debug
ManagedLib0
bin
Debug
Release
obj
Debug
TempPE
Properties
MixedLib1
app.ico
Debug
MixedLib1.Build.CppClean.log
MixedLib1.log
MixedLib1.vcxproj.user
MixedStackTraceLibrary
app.ico
Debug
MixedStackTraceLibrary.Build.CppClean.log
MixedStackTraceLibrary.log
MixedStackTraceLibrary.vcxproj.user
sdk
inc
lib
dbgeng.lib
dbghelp.lib
engextcpp.lib
StackTraceLibrary
bin
Debug
Release
obj
Debug
TempPE
Properties
StackwalkApps
Debug
DiagApp
app.ico
Debug
DiagApp.log
DiagApp.vcxproj.user
sdk
inc
lib
dbgeng.lib
dbghelp.lib
engextcpp.lib
xclrdata
StackWalk64App
Debug
StackWalk64App.log
sdk
inc
lib
dbgeng.lib
dbghelp.lib
engextcpp.lib
StackWalk64App.vcxproj.user
|
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mattias H�gstr�m.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------
// DiagApp.cpp : main project file.
#include "stdafx.h"
#include <Windows.h>
#include <mscoree.h>
#include <cor.h>
#include <cordebug.h>
#include "DotNetHelper.h"
#include "Stackwalker.h"
//#include <metahost.h>
//#include <mscoree.h>
#include "xclrdata\xclrdata.h"
#include "xclrdata\xclrdata_i.c"
#include <list>
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "CorGuids.lib")
#pragma comment(lib, "mscoree.lib")
using namespace System;
using namespace System::Threading;
using namespace System::Diagnostics;
using namespace System::Collections::Generic;
int main(array<System::String ^> ^args)
{
if (args->Length != 1)
{
Console::WriteLine("Usage: DiagApp <pId>");
return 0;
}
int pId;
if (int::TryParse(args[0], pId) == false)
{
Console::WriteLine("PId is not a valid integer");
return 0;
}
Process^ process = Process::GetProcessById(pId);
if (process == nullptr)
{
Console::WriteLine(L"Process Id was not found");
return 0;
}
bool isManaged = IsDotNetProcess(pId);
if (isManaged)
Console::WriteLine("Process is managed");
else
Console::WriteLine("Process is native");
bool isClr4 = IsClr4Process(pId);
if (isClr4)
Console::WriteLine("Process is Clr 4");
else
Console::WriteLine("Process is Clr 2");
Stackwalker stackwalker;
bool result = stackwalker.Initialize(pId);
bool result2 = stackwalker.InitCLRDataTarget();
//bool result = stackwalker.AttachProcess(pId, true);
if (result == false)
{
Console::WriteLine("Failed to attach to process");
return 0;
}
stackwalker.SetSymbolPath("C:\\Users\\mattias.hogstrom\\Documents\\Visual Studio 2010\\Projects\\CSharpApp\\CSharpApp\\bin\\Debug;C:\\symbols;c:\\developer");
stackwalker.SetSourcePath("C:\\symbols;C:\\Users\\mattias.hogstrom\\Documents\\Visual Studio 2010\\Projects\\CSharpApp\\CSharpApp");
stackwalker.SetImagePath("C:\\Users\\mattias.hogstrom\\Documents\\Visual Studio 2010\\Projects\\CSharpApp\\CSharpApp\\bin\\Debug");
List<int>^ threadList = gcnew List<int>();
for (int i=0;i<process->Threads->Count;i++)
{
int id = process->Threads[i]->Id;
HANDLE h = OpenThread(THREAD_ALL_ACCESS, FALSE, id);
threadList->Add((int)h);
SuspendThread(h);
}
stackwalker.Run();
Sleep(10000);
stackwalker.Run();
for (int i=0;i<threadList->Count;i++)
{
HANDLE h = (HANDLE)threadList[i];
ResumeThread(h);
CloseHandle(h);
}
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Mattias works at Visma, a leading Nordic ERP solution provider. He has good knowledge in C++/.Net development, test tool development, and debugging. His great passion is memory dump analysis. He likes giving talks and courses.