mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 13:11:28 +00:00
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.
This commit is contained in:
89
nse_debug.cc
89
nse_debug.cc
@@ -1,64 +1,35 @@
|
|||||||
#include "nse_debug.h"
|
#include "nse_debug.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
|
|
||||||
void l_dumpStack(lua_State *L) {
|
void stack_dump (lua_State *L)
|
||||||
int stack_height = lua_gettop(L);
|
{
|
||||||
int i;
|
int i, top = lua_gettop(L);
|
||||||
|
for (i = 1; i <= top; i++)
|
||||||
log_write(LOG_PLAIN, "-== Stack Dump Begin ==-\n");
|
{ /* repeat for each level */
|
||||||
for(i = -1; i >= 0 - stack_height; i--) {
|
int t = lua_type(L, i);
|
||||||
log_write(LOG_PLAIN, "%d: ", i);
|
printf("[%d, %d] = ", i, (-top + i - 1));
|
||||||
l_dumpValue(L, i);
|
switch (t)
|
||||||
}
|
{
|
||||||
|
case LUA_TSTRING: /* strings */
|
||||||
log_write(LOG_PLAIN, "-== Stack Dump End ==-\n");
|
printf("'%s'", lua_tostring(L, i));
|
||||||
}
|
break;
|
||||||
|
case LUA_TBOOLEAN: /* booleans */
|
||||||
void l_dumpValue(lua_State *L, int i) {
|
printf(lua_toboolean(L, i) ? "true" : "false");
|
||||||
switch (lua_type(L, i))
|
break;
|
||||||
{
|
case LUA_TNUMBER: /* numbers */
|
||||||
case LUA_TTABLE:
|
printf("%g", lua_tonumber(L, i));
|
||||||
l_dumpTable(L, i);
|
break;
|
||||||
break;
|
case LUA_TTABLE:
|
||||||
case LUA_TFUNCTION:
|
case LUA_TTHREAD:
|
||||||
l_dumpFunction(L, i);
|
case LUA_TFUNCTION:
|
||||||
break;
|
case LUA_TUSERDATA:
|
||||||
case LUA_TSTRING:
|
case LUA_TLIGHTUSERDATA:
|
||||||
log_write(LOG_PLAIN, "string '%s'\n", lua_tostring(L, i));
|
printf("%s: %p", lua_typename(L, t), lua_topointer(L, i));
|
||||||
break;
|
break;
|
||||||
case LUA_TBOOLEAN:
|
default: /* other values */
|
||||||
log_write(LOG_PLAIN, "boolean: %s\n",
|
printf("%s", lua_typename(L, t));
|
||||||
lua_toboolean(L, i) ? "true" : "false");
|
break;
|
||||||
break;
|
}
|
||||||
case LUA_TNUMBER:
|
printf("\n");
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ extern "C" {
|
|||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
void l_dumpStack(lua_State* l);
|
void stack_dump(lua_State *L);
|
||||||
void l_dumpValue(lua_State* l, int index);
|
|
||||||
void l_dumpTable(lua_State *l, int index);
|
|
||||||
void l_dumpFunction(lua_State* l, int index);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -557,9 +557,8 @@ int process_getScriptId(lua_State* L, ScriptResult *sr) {
|
|||||||
lua_getfield(L, 1, FILENAME);
|
lua_getfield(L, 1, FILENAME);
|
||||||
filename = lua_tostring(L, -1);
|
filename = lua_tostring(L, -1);
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
error("%s: The script's 'filename' entry was changed to:",
|
error("%s: The script's 'filename' entry was changed to: %s",
|
||||||
SCRIPT_ENGINE);
|
SCRIPT_ENGINE, luaL_typename(L, -1));
|
||||||
l_dumpValue(L, -1);
|
|
||||||
return SCRIPT_ENGINE_ERROR;
|
return SCRIPT_ENGINE_ERROR;
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user