Lua debugger: fix crash printing nested or deep objects.
Example of offending code: > script debug yes OK > eval "local a = {1} a[1] = a\nprint(a)" 0 1) * Stopped at 1, stop reason = step over 2) -> 1 local a = {1} a[1] = a > next 1) * Stopped at 2, stop reason = step over 2) -> 2 print(a) > print ... server crash ... Close #2955.
This commit is contained in:
parent
1e7a8f8221
commit
a75aa4bf92
@ -1846,9 +1846,13 @@ void ldbList(int around, int context) {
|
|||||||
*
|
*
|
||||||
* The element is not automatically removed from the stack, nor it is
|
* The element is not automatically removed from the stack, nor it is
|
||||||
* converted to a different type. */
|
* converted to a different type. */
|
||||||
sds ldbCatStackValue(sds s, lua_State *lua, int idx) {
|
#define LDB_MAX_VALUES_DEPTH (LUA_MINSTACK/2)
|
||||||
|
sds ldbCatStackValueRec(sds s, lua_State *lua, int idx, int level) {
|
||||||
int t = lua_type(lua,idx);
|
int t = lua_type(lua,idx);
|
||||||
|
|
||||||
|
if (level++ == LDB_MAX_VALUES_DEPTH)
|
||||||
|
return sdscat(s,"<max recursion level reached! Nested table?>");
|
||||||
|
|
||||||
switch(t) {
|
switch(t) {
|
||||||
case LUA_TSTRING:
|
case LUA_TSTRING:
|
||||||
{
|
{
|
||||||
@ -1883,13 +1887,13 @@ sds ldbCatStackValue(sds s, lua_State *lua, int idx) {
|
|||||||
lua_tonumber(lua,-2) != expected_index)) is_array = 0;
|
lua_tonumber(lua,-2) != expected_index)) is_array = 0;
|
||||||
/* Stack now: table, key, value */
|
/* Stack now: table, key, value */
|
||||||
/* Array repr. */
|
/* Array repr. */
|
||||||
repr1 = ldbCatStackValue(repr1,lua,-1);
|
repr1 = ldbCatStackValueRec(repr1,lua,-1,level);
|
||||||
repr1 = sdscatlen(repr1,"; ",2);
|
repr1 = sdscatlen(repr1,"; ",2);
|
||||||
/* Full repr. */
|
/* Full repr. */
|
||||||
repr2 = sdscatlen(repr2,"[",1);
|
repr2 = sdscatlen(repr2,"[",1);
|
||||||
repr2 = ldbCatStackValue(repr2,lua,-2);
|
repr2 = ldbCatStackValueRec(repr2,lua,-2,level);
|
||||||
repr2 = sdscatlen(repr2,"]=",2);
|
repr2 = sdscatlen(repr2,"]=",2);
|
||||||
repr2 = ldbCatStackValue(repr2,lua,-1);
|
repr2 = ldbCatStackValueRec(repr2,lua,-1,level);
|
||||||
repr2 = sdscatlen(repr2,"; ",2);
|
repr2 = sdscatlen(repr2,"; ",2);
|
||||||
lua_pop(lua,1); /* Stack: table, key. Ready for next iteration. */
|
lua_pop(lua,1); /* Stack: table, key. Ready for next iteration. */
|
||||||
expected_index++;
|
expected_index++;
|
||||||
@ -1926,6 +1930,12 @@ sds ldbCatStackValue(sds s, lua_State *lua, int idx) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Higher level wrapper for ldbCatStackValueRec() that just uses an initial
|
||||||
|
* recursion level of '0'. */
|
||||||
|
sds ldbCatStackValue(sds s, lua_State *lua, int idx) {
|
||||||
|
return ldbCatStackValueRec(s,lua,idx,0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Produce a debugger log entry representing the value of the Lua object
|
/* Produce a debugger log entry representing the value of the Lua object
|
||||||
* currently on the top of the stack. The element is ot popped nor modified.
|
* currently on the top of the stack. The element is ot popped nor modified.
|
||||||
* Check ldbCatStackValue() for the actual implementation. */
|
* Check ldbCatStackValue() for the actual implementation. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user