StackWalk64 on IA64

J

John Riggs

Hi,
I've been attempting to use StackWalk64 on IA64. Unfortunately, the
Microsoft docs seem to be rather vague as to what is required. My test
program works on the I386, but won't not on the IA64.
On the IA64 the StackWalk64 returns true, so the call thinks it
succeeded. But the resulting StackFrame64 does not have correct data,
and further calls to StackWalk64 return false.
Has anybody gotten this to work that might be able to provide me
with some pointers as to what I am doing wrong? My code is posted
below. I've tried lots of different code hacks to get this to work,
but nothing is helping. I suspect that the thread context is what is
throwing me off, but I've exhausted my leads to track this down.

Thanks,
John


void StackTrace()
{
int success = 0;
HANDLE hThread = GetCurrentThread();
HANDLE hProcess = GetCurrentProcess();

CONTEXT context;
memset (&context, 0, sizeof(context));
context.ContextFlags = CONTEXT_CONTROL;
success = GetThreadContext(hThread, &context);

STACKFRAME64 stackFrame;
memset (&stackFrame, 0, sizeof(stackFrame));

stackFrame.AddrPC.Offset = context.StIIP;
stackFrame.AddrPC.Mode = AddrModeFlat;
stackFrame.AddrStack.Offset = context.IntSp;
stackFrame.AddrStack.Mode = AddrModeFlat;
stackFrame.AddrBStore.Offset = context.RsBSP;
stackFrame.AddrBStore.Mode = AddrModeFlat;
DWORD machineType = IMAGE_FILE_MACHINE_IA64;

while (success)
{
success = StackWalk64(machineType, hProcess, hThread,
&stackFrame, &context, NULL, NULL, NULL, NULL);

printf ("%#08x, %#08x\n", (unsigned int)stackFrame.AddrReturn.Offset,
(unsigned int)stackFrame.AddrPC.Offset);
}
}
 
C

clyclopedic

Change your test program so that it raises an exception and gets the thread
context from the exception information.

CONTEXT context;
char *p = 0;

__try
{
*p = 0; // or create your own exception and Raise() it.
}
__except(CopyMemory(&context, (GetExceptionInformation())->ContextRecord,
sizeof(context)), EXCEPTION_EXECUTE_HANDLER)
{
// run your traceback. But..
// DONT set any initial values in the STACKFRAME64. Let him figure it out
from the context. It works for me.
}
 
J

John Riggs

This still does not work for me. At least now I'm sure that the
context looks correct. But the stack trace still gets nowhere,
certainly not to the previous functions from whence I came.
Perhaps I am missing something. The StackWalk64 has various callback
functions. I have tried initializing the symbols and using the
built-in callbacks, but with both that or passing NULL I get the same
result. Does anybody know whether those functions are needed? If so,
how do I define those functions?
Anything else I might be missing here?

Thank you,
John
 
C

clyclopedic

John Riggs said:
The StackWalk64 has various callback
functions. I have tried initializing the symbols and using the
built-in callbacks, but with both that or passing NULL I get the same
result. Does anybody know whether those functions are needed? If so,
how do I define those functions?

In my implementation I use my own function for ReadMemoryRoutine. For
in-process traces, the function I use simply calls IsBadReadPtr() and if
that's OK, CopyMemory(). I have a different function I use when running as a
debugger on another process. For the FunctionTableAccessRoutine and
GetModuleBaseRoutine parms I pass in SymFunctionTableAccess64 and
SymGetModuleBase64 from dbghelp.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top