Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Debug capture utility?

106 views
Skip to first unread message

Pierre Landau

unread,
Nov 7, 2001, 4:52:41 PM11/7/01
to
This should be an FAQ. I once saw a standalone program that showed anything
sent through the OutputDebugString() call. This allowed debugging a service
without resorting to DebugBreak() and starting a separate copy of VC. Does
anybody recall where to find this utility?
Thanks!


Randy Charles Morin

unread,
Nov 7, 2001, 7:46:20 PM11/7/01
to
This is from my book "Programming Windows Services"

#include <windows.h>
#include <iostream>

int main( int argc, char ** argv )
{
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = &sd;

std::cerr << "*********************\n"
"Debug Monitor Started\n"
"*********************\n";

if(::InitializeSecurityDescriptor(&sd,
SECURITY_DESCRIPTOR_REVISION) == FALSE)
{
std::cout << "InitializeSecurityDescriptor failed"
<< std::endl;
return 1;
}

if(::SetSecurityDescriptorDacl(&sd, TRUE, (PACL)NULL,
FALSE) == FALSE)
{
std::cout << "SetSecurityDescriptorDacl failed"
<< std::endl;
return 1;
}

HANDLE bufferready = ::CreateEvent(&sa, FALSE, FALSE,
"DBWIN_BUFFER_READY");
if (bufferready == NULL)
{
std::cout << "CreateEvent failed" << std::endl;
return 1;
}

if (GetLastError() == ERROR_ALREADY_EXISTS)
{
std::cout << "Debugger Already Running" << std::endl;
return 1;
}

HANDLE dataready = ::CreateEvent(&sa, FALSE, FALSE,
"DBWIN_DATA_READY");
if (dataready == NULL)
{
std::cout << "CreateEvent failed" << std::endl;
::CloseHandle(bufferready);
return 1;
}

HANDLE buffer = ::CreateFileMapping(INVALID_HANDLE_VALUE,
&sa, PAGE_READWRITE, 0, 4096, "DBWIN_BUFFER");
if (buffer == NULL)
{
std::cout << "CreateFileMapping failed" << std::endl;
::CloseHandle(bufferready);
::CloseHandle(dataready);
return 1;
}

void * str = ::MapViewOfFile(buffer, FILE_MAP_READ, 0, 0,
4096);

if (str == NULL)
{
std::cout << "MapViewOfFile failed" << std::endl;
::CloseHandle(bufferready);
::CloseHandle(dataready);
::CloseHandle(buffer);
return 1;
}

char * string = (char *)str + sizeof(DWORD);
DWORD lastpid = 0xffffffff;
bool cr = true;

while (true)
{
if (::SetEvent(bufferready) == FALSE)
{
std::cout << "SetEvent failed" << std::endl;
::CloseHandle(bufferready);
::CloseHandle(dataready);
::UnmapViewOfFile(str);
::CloseHandle(buffer);
return 1;
};

if (::WaitForSingleObject(dataready, INFINITE)
!= WAIT_OBJECT_0)
{
break;
}
else
{
DWORD pid = *(DWORD *)str;
if (lastpid != pid)
{
lastpid = pid;
if (!cr)
{
std::cerr << std::endl;
cr = true;
}
}

if (cr)
{
std::cerr << lastpid << ":";
}

std::cerr << (char*)string;
cr = (*string &&
(string[::strlen(string) - 1] == '\n'));
}
}

std::cout << "WaitForSingleObject failed" << std::endl;
::CloseHandle(bufferready);
::CloseHandle(dataready);
::UnmapViewOfFile(str);
::CloseHandle(buffer);
return 1;
};

--
Randy Charles Morin
Author of Programming Windows Services
http://www.kbcafe.com

Feel free to contact me by private email or messenger
MSN Messenger - morin...@hotmail.com
Yahoo Messenger - randy...@yahoo.com

"Pierre Landau" <pie...@polymap.net> wrote in message
news:e2TyPa9ZBHA.1432@tkmsftngp04...

Darken Screamer

unread,
Nov 10, 2001, 11:32:34 AM11/10/01
to
Ya, the best one is by Mark Russinovich and is called debugview. You'll
find it here http://www.sysinternals.com/ntw2k/freeware/debugview.shtml

Darren


"Pierre Landau" <pie...@polymap.net> wrote in message
news:e2TyPa9ZBHA.1432@tkmsftngp04...

0 new messages