std*_*err 5 c debugging stack trace vxworks
出于故障排除的原因,我希望能够检索并打印当前运行的函数的调用程序堆栈.我尝试过以下方法:
/*******************************************************************************
* *
* * 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());
}
Run Code Online (Sandbox Code Playgroud)
但我得到:
JPAX-DP> DbgTest
trcStack aborted: error in top frame
value = 0 = 0x0
Run Code Online (Sandbox Code Playgroud)
这甚至可能吗?我怎样才能做到这一点?我看到,对于taskRegsGet(),他们说:
只有当已知任务处于稳定的非执行状态时,此例程才有效.例如,自我检查是不可取的,因为结果是不可预测的.
但是我应该采用其他什么方法?
编译器是diab和cpu archpowerpc
您提到 taskRegsGet() 提到不建议从当前正在运行的任务中调用。但是我看到有人使用 taskDelay(1) 并带有注释“强制上下文保存”。我不能将其归功于它,也不知道它有多可靠,或者它可能有什么副作用,但它可能有助于获取有关当前任务的正确信息:
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 */
Run Code Online (Sandbox Code Playgroud)