kipp8r
asked on
Reading a register
Is there a way in C/C++ to read a register such as the stack pointer(SP) ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://msdn2.microsoft.com/en-us/library/45yd4tzz(VS.80).aspx
ASKER
I understand know. Can this be used to read another processes registers?
No. These values are valid only for current ("RUNNING") process.
Information (register values) for other processes are stored in their PCB structures and are written in the registers when they get processor.
Information (register values) for other processes are stored in their PCB structures and are written in the registers when they get processor.
ASKER
Is there anyway to read the registers of another process. I've noticed windows has a GetWindowThreadProcessId() function. Basically I'm trying to output the values of the registers when the SP gets to a specific address. So I can get some debug information on my software.
Of course there is all debugger do make that. So just search for debugger development and see what you can get from it.
Regards
Friedrich
Regards
Friedrich
>> So I can get some debug information on my software.
Maybe it's better to just run your program in a debugger, and get the information that way ?
Maybe it's better to just run your program in a debugger, and get the information that way ?
ASKER
Debugging with another program would be too easy...lol...besides I want to log the values. I found this though. The win32 debug API.
if (WaitForDebugEvent( &devent , 0))
{
switch(devent.dwDebugEvent Code)
{
case CREATE_PROCESS_DEBUG_EVENT :
h = ::OpenThread(THREAD_ALL_AC CESS, false, devent.dwThreadId);
// your handler here
break;
case EXIT_PROCESS_DEBUG_EVENT:
// your handler here
break;
case EXCEPTION_DEBUG_EVENT:
// your handler here
break;
}
ContinueDebugEvent(devent. dwProcessI d , devent.dwThreadId , DBG_CONTINUE);
}
else
{
// other operations
}
}
::GetThreadContext(h,&rx);
if (WaitForDebugEvent( &devent , 0))
{
switch(devent.dwDebugEvent
{
case CREATE_PROCESS_DEBUG_EVENT
h = ::OpenThread(THREAD_ALL_AC
// your handler here
break;
case EXIT_PROCESS_DEBUG_EVENT:
// your handler here
break;
case EXCEPTION_DEBUG_EVENT:
// your handler here
break;
}
ContinueDebugEvent(devent.
}
else
{
// other operations
}
}
::GetThreadContext(h,&rx);