This repository has been archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
pllua_debug.c
92 lines (81 loc) · 2.6 KB
/
pllua_debug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "pllua_debug.h"
/* PostgreSQL */
#include <postgres.h>
#include <fmgr.h>
#include <funcapi.h>
#include <access/heapam.h>
#if PG_VERSION_NUM >= 90300
#include <access/htup_details.h>
#endif
#include <catalog/namespace.h>
#include <catalog/pg_proc.h>
#include <catalog/pg_type.h>
#include <commands/trigger.h>
#include <executor/spi.h>
#include <nodes/makefuncs.h>
#include <parser/parse_type.h>
#include <utils/array.h>
#include <utils/builtins.h>
#include <utils/datum.h>
#include <utils/lsyscache.h>
#include <utils/memutils.h>
#include <utils/rel.h>
#include <utils/syscache.h>
#include <utils/typcache.h>
static char *_location;
void setLINE(char *location)
{
_location = location;
}
const char *getLINE(void)
{
return _location;
}
#define DMP 2
void stackDump(lua_State *L) {
int i=lua_gettop(L);
ereport(INFO, (errmsg("%s", "---------------- Stack Dump ----------------")));
while( i ) {
int t = lua_type(L, i);
switch (t) {
case LUA_TSTRING:
ereport(INFO, (errmsg("%d:`%s'", i, lua_tostring(L, i))));
break;
case LUA_TBOOLEAN:
ereport(INFO, (errmsg("%d: %s",i,lua_toboolean(L, i) ? "true" : "false")));
break;
case LUA_TNUMBER:
ereport(INFO, (errmsg("%d: %g", i, lua_tonumber(L, i))));
break;
case LUA_TTABLE:
ereport(INFO, (errmsg("%d: table", i)));
if (DMP==1){
/* table is in the stack at index 't' */
lua_pushnil(L); /* first key */
while (lua_next(L, i) != 0) {
/* uses 'key' (at index -2) and 'value' (at index -1) */
ereport(INFO, (errmsg("===%s - %s\n",
lua_tostring(L, -2),
lua_typename(L, lua_type(L, -1)))));
/* removes 'value'; keeps 'key' for next iteration */
lua_pop(L, 1);
}
}else if (DMP == 2){
int cnt = 0;
lua_pushnil(L); /* first key */
while (lua_next(L, i) != 0) {
++cnt;
/* removes 'value'; keeps 'key' for next iteration */
lua_pop(L, 1);
}
ereport(INFO, (errmsg("===length %i: table", cnt)));
}
break;
default:
ereport(INFO, (errmsg("%d: %s", i, lua_typename(L, t))));
break;
}
i--;
}
ereport(INFO, (errmsg("%s","--------------- Stack Dump Finished ---------------" )));
}