forked from nmap/nmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed some old debug code no longer used/needed. Added a new stack …
…dump function that provides a clean output of the stack with positive and negative stack indices.
- Loading branch information
batrick
committed
Nov 18, 2008
1 parent
20cf487
commit 085eecb
Showing
3 changed files
with
33 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,35 @@ | ||
#include "nse_debug.h" | ||
#include "output.h" | ||
|
||
void l_dumpStack(lua_State *L) { | ||
int stack_height = lua_gettop(L); | ||
int i; | ||
|
||
log_write(LOG_PLAIN, "-== Stack Dump Begin ==-\n"); | ||
for(i = -1; i >= 0 - stack_height; i--) { | ||
log_write(LOG_PLAIN, "%d: ", i); | ||
l_dumpValue(L, i); | ||
void stack_dump (lua_State *L) | ||
{ | ||
int i, top = lua_gettop(L); | ||
for (i = 1; i <= top; i++) | ||
{ /* repeat for each level */ | ||
int t = lua_type(L, i); | ||
printf("[%d, %d] = ", i, (-top + i - 1)); | ||
switch (t) | ||
{ | ||
case LUA_TSTRING: /* strings */ | ||
printf("'%s'", lua_tostring(L, i)); | ||
break; | ||
case LUA_TBOOLEAN: /* booleans */ | ||
printf(lua_toboolean(L, i) ? "true" : "false"); | ||
break; | ||
case LUA_TNUMBER: /* numbers */ | ||
printf("%g", lua_tonumber(L, i)); | ||
break; | ||
case LUA_TTABLE: | ||
case LUA_TTHREAD: | ||
case LUA_TFUNCTION: | ||
case LUA_TUSERDATA: | ||
case LUA_TLIGHTUSERDATA: | ||
printf("%s: %p", lua_typename(L, t), lua_topointer(L, i)); | ||
break; | ||
default: /* other values */ | ||
printf("%s", lua_typename(L, t)); | ||
break; | ||
} | ||
printf("\n"); | ||
} | ||
|
||
log_write(LOG_PLAIN, "-== Stack Dump End ==-\n"); | ||
} | ||
|
||
void l_dumpValue(lua_State *L, int i) { | ||
switch (lua_type(L, i)) | ||
{ | ||
case LUA_TTABLE: | ||
l_dumpTable(L, i); | ||
break; | ||
case LUA_TFUNCTION: | ||
l_dumpFunction(L, i); | ||
break; | ||
case LUA_TSTRING: | ||
log_write(LOG_PLAIN, "string '%s'\n", lua_tostring(L, i)); | ||
break; | ||
case LUA_TBOOLEAN: | ||
log_write(LOG_PLAIN, "boolean: %s\n", | ||
lua_toboolean(L, i) ? "true" : "false"); | ||
break; | ||
case LUA_TNUMBER: | ||
log_write(LOG_PLAIN, "number: %g\n", lua_tonumber(L, i)); | ||
break; | ||
default: | ||
log_write(LOG_PLAIN, "%s\n", lua_typename(L, lua_type(L, i))); | ||
} | ||
} | ||
|
||
void l_dumpTable(lua_State *L, int index) { | ||
log_write(LOG_PLAIN, "table\n"); | ||
lua_pushnil(L); | ||
|
||
if (index<0) --index; | ||
while(lua_next(L, index) != 0) | ||
{ | ||
l_dumpValue(L, -2); | ||
l_dumpValue(L, -1); | ||
lua_pop(L, 1); | ||
} | ||
} | ||
|
||
void l_dumpFunction(lua_State *L, int index) { | ||
// lua_Debug ar; | ||
|
||
log_write(LOG_PLAIN, "function\n"); | ||
|
||
// lua_pushvalue(L, index); | ||
// lua_getinfo(L, ">n", &ar); | ||
// | ||
// log_write(LOG_PLAIN, "\tname: %s %s\n", ar.namewhat, ar.name); | ||
fflush(stdout); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters