出于故障排除的原因,我希望能够检索并打印当前运行的函数的调用程序堆栈. 我尝试过以下方法: /******************************************************************************* * * * * xxxTracePrint - stack
我尝试过以下方法:
/******************************************************************************* * * * * xxxTracePrint - stack trace print function * * * * RETURNS: OK or ERROR * */ static void xxxTracePrint ( INSTR *caller, int func, int nargs, int *args ) { char buf [250]; int ix; int len = 0; len += sprintf (&buf [len], "%#10x: %#10x (", (int)caller, func); for (ix = 0; ix < nargs; ix++) { if (ix != 0) len += sprintf (&buf [len], ", "); len += sprintf (&buf [len], "%#x", args [ix]); } len += sprintf (&buf [len], ")\n"); printf (buf); } /******************************************************************************* * * * * xxxTrace - stack trace * * * * RETURNS: OK or ERROR * */ int xxxTrace(int tcb) { REG_SET regs; if (tcb == 0) return (ERROR); taskRegsGet (tcb, ®s); trcStack (®s, (FUNCPTR) xxxTracePrint, tcb); return (OK); } void DbgTest(void) { xxxTrace(taskIdSelf()); }
但我得到:
JPAX-DP> DbgTest trcStack aborted: error in top frame value = 0 = 0x0
这甚至可能吗?我怎样才能做到这一点?我看到,对于taskRegsGet(),他们说:
This routine only works well if the task is known to be in a stable,
non-executing state. Self-examination, for instance, is not advisable,
as results are unpredictable.
但是我应该采用其他什么方法?
编译器是diab和cpu arch powerpc
您提到taskRegsGet()提到不建议从当前正在运行的任务调用.但是我看到有人使用taskDelay(1)和注释’force context save’.我不能相信它,也不知道它有多可靠,或它可能有什么副作用,但它可能有助于获得有关当前任务的正确信息:taskDelay (1); /* Force context save */ taskRegsGet (0, ®s); /* 0 task-id for myself */ trcStack (®s, NULL, 0); /* NULL function pointer for default print fcn, 0 task-id for myself */