StackWalk64 on IA64

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Riggs

    #1

    StackWalk64 on IA64

    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 = GetCurrentThrea d();
    HANDLE hProcess = GetCurrentProce ss();

    CONTEXT context;
    memset (&context, 0, sizeof(context) );
    context.Context Flags = CONTEXT_CONTROL ;
    success = GetThreadContex t(hThread, &context);

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

    stackFrame.Addr PC.Offset = context.StIIP;
    stackFrame.Addr PC.Mode = AddrModeFlat;
    stackFrame.Addr Stack.Offset = context.IntSp;
    stackFrame.Addr Stack.Mode = AddrModeFlat;
    stackFrame.Addr BStore.Offset = context.RsBSP;
    stackFrame.Addr BStore.Mode = AddrModeFlat;
    DWORD machineType = IMAGE_FILE_MACH INE_IA64;

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

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

    #2
    Re: StackWalk64 on IA64

    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(CopyMe mory(&context, (GetExceptionIn formation())->ContextRecor d,
    sizeof(context) ), EXCEPTION_EXECU TE_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.
    }

    "John Riggs" <j_riggs76@hotm ail.com> wrote in message
    news:4f7a89dd.0 311201443.1fc1b 612@posting.goo gle.com...[color=blue]
    > 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 = GetCurrentThrea d();
    > HANDLE hProcess = GetCurrentProce ss();
    >
    > CONTEXT context;
    > memset (&context, 0, sizeof(context) );
    > context.Context Flags = CONTEXT_CONTROL ;
    > success = GetThreadContex t(hThread, &context);
    >
    > STACKFRAME64 stackFrame;
    > memset (&stackFrame, 0, sizeof(stackFra me));
    >
    > stackFrame.Addr PC.Offset = context.StIIP;
    > stackFrame.Addr PC.Mode = AddrModeFlat;
    > stackFrame.Addr Stack.Offset = context.IntSp;
    > stackFrame.Addr Stack.Mode = AddrModeFlat;
    > stackFrame.Addr BStore.Offset = context.RsBSP;
    > stackFrame.Addr BStore.Mode = AddrModeFlat;
    > DWORD machineType = IMAGE_FILE_MACH INE_IA64;
    >
    > while (success)
    > {
    > success = StackWalk64(mac hineType, hProcess, hThread,
    > &stackFrame, &context, NULL, NULL, NULL, NULL);
    >
    > printf ("%#08x, %#08x\n", (unsigned int)stackFrame. AddrReturn.Offs et,
    > (unsigned int)stackFrame. AddrPC.Offset);
    > }
    > }[/color]


    Comment

    • John Riggs

      #3
      Re: StackWalk64 on IA64

      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

      "clyclopedi c" <nonExist@spaml ess.com> wrote in message news:<OK7BGnIsD HA.2416@TK2MSFT NGP10.phx.gbl>. ..[color=blue]
      > 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(CopyMe mory(&context, (GetExceptionIn formation())->ContextRecor d,
      > sizeof(context) ), EXCEPTION_EXECU TE_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.
      > }
      >[/color]

      Comment

      • clyclopedic

        #4
        Re: StackWalk64 on IA64


        "John Riggs" <j_riggs76@hotm ail.com> wrote in message
        news:4f7a89dd.0 311251609.4fdd2 7a4@posting.goo gle.com...[color=blue]
        > 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?[/color]

        In my implementation I use my own function for ReadMemoryRouti ne. 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 FunctionTableAc cessRoutine and
        GetModuleBaseRo utine parms I pass in SymFunctionTabl eAccess64 and
        SymGetModuleBas e64 from dbghelp.


        Comment

        Working...