【发布时间】:2019-01-25 09:42:23
【问题描述】:
我正在开发一个带有 256 kB RAM 和 1 MB 闪存的 Cortex-M4F 嵌入式系统。我的应用程序是用 C++ 编写的,但我使用 GCC 将 Lua 构建并集成为 C 库。我只需要将 l_signalT 定义为无符号 32 位整数。我的测试代码如下:
#include "lua.hpp"
int main(void)
{
while (true)
{
lua_State * L = luaL_newstate();
luaL_dostring(L, "a = 10 + 5");
lua_getglobal(L, "a");
int i = lua_tointeger(L, -1);
printf("%d\n", i);
lua_close(L);
}
}
我正在取消引用空指针。增加堆和栈并没有解决问题。我还在调用 realloc 的分配器中添加了一个 null 测试。 setjmp/longjump 代码中似乎发生了一些事情。我想知道是否有关于如何进一步调试的想法。我添加了一些带有<----- 的cmets,可能需要一些滚动。这实际上是我的堆栈转储。
static void setnodevector (lua_State *L, Table *t, unsigned int size) {
if (size == 0) { /* no elements to hash part? */
t->node = cast(Node *, dummynode); /* use common 'dummynode' */
t->lsizenode = 0; <---- t is zero. Write
does evil.
Hardfault.
static void auxsetnode (lua_State *L, void *ud) {
AuxsetnodeT *asn = cast(AuxsetnodeT *, ud);
setnodevector(L, asn->t, asn->nhsize); <--- Last two values pointed to are zero.
}
<setjmp>
466A mov r2, sp
E8A05FF4 stm r0!, {r2, r4-r12, lr}
EC808B10 vstmia r0, {d8-d15} <------ Part of LUAI_TRY called below. Memory location
2000 movs r0, #0 of ud is cleared here.
4770 bx lr
int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
unsigned short oldnCcalls = L->nCcalls;
struct lua_longjmp lj;
lj.status = LUA_OK;
lj.previous = L->errorJmp; /* chain new error handler */
L->errorJmp = &lj;
LUAI_TRY(L, &lj, <---- Value pointed to by ud is nonzero
(*f)(L, ud); but cleared in setjmp.
);
L->errorJmp = lj.previous; /* restore old error handler */
L->nCcalls = oldnCcalls;
return lj.status;
}
【问题讨论】: