├── LICENSE ├── README.md ├── appveyor.yml ├── dbgmem_test.lua ├── luadbg.sln ├── luadbg ├── ReadMe.txt ├── dllmain.cpp ├── inc │ ├── dbgeng.h │ ├── dbghelp.h │ ├── engextcpp.cpp │ ├── engextcpp.hpp │ ├── extsfns.h │ └── wdbgexts.h ├── lib │ ├── amd64 │ │ ├── dbgeng.lib │ │ ├── dbghelp.lib │ │ └── engextcpp.lib │ ├── i386 │ │ ├── dbgeng.lib │ │ ├── dbghelp.lib │ │ └── engextcpp.lib │ ├── ia64 │ │ ├── dbgeng.lib │ │ ├── dbghelp.lib │ │ └── engextcpp.lib │ └── x86 │ │ ├── dbgeng.lib │ │ ├── dbghelp.lib │ │ └── engextcpp.lib ├── lua_src │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lbitlib.c │ ├── lcode.c │ ├── lcode.h │ ├── lcorolib.c │ ├── lctype.c │ ├── lctype.h │ ├── ldblib.c │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── linit.c │ ├── liolib.c │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── loslib.c │ ├── lparser.c │ ├── lparser.h │ ├── lprefix.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltm.c │ ├── ltm.h │ ├── lua.c │ ├── lua.h │ ├── lua.hpp │ ├── luac.c │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lutf8lib.c │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ └── lzio.h ├── luadbg.cpp ├── luadbg.def ├── luadbg.rc ├── luadbg.vcxproj ├── luadbg.vcxproj.filters ├── luadbg_v15.vcxproj ├── luadbg_v15.vcxproj.filters ├── resource.h ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── luadbg_v15.sln └── module_test.lua /README.md: -------------------------------------------------------------------------------- 1 | # luadbg 2 | Lua Extension for Windbg 3 | 4 | [![Build status](https://ci.appveyor.com/api/projects/status/ph0hc250i7grvv53?svg=true)](https://ci.appveyor.com/project/0cch/luadbg) 5 | 6 | ![](https://0cch.com/uploads/2016/11/20161116113129.png) 7 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.2.3.{build} 2 | pull_requests: 3 | do_not_increment_build_number: true 4 | skip_tags: true 5 | configuration: Release 6 | build_script: 7 | - MSBuild.exe "luadbg_v15.sln" /verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /p:Configuration=Release /p:Platform="Win32" 8 | - MSBuild.exe "luadbg_v15.sln" /verbosity:minimal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /p:Configuration=Release /p:Platform="x64" 9 | - mkdir bin\x86 10 | - mkdir bin\x64 11 | - copy Release\luadbg_v15.dll bin\x86\luadbg.dll 12 | - copy x64\Release\luadbg_v15.dll bin\x64\luadbg.dll 13 | - 7z a -tzip luadbg.zip bin\* 14 | artifacts: 15 | - path: luadbg.zip 16 | name: luadbg.zip 17 | deploy: 18 | - provider: GitHub 19 | auth_token: 20 | secure: joiNNJe1EegeE9zcyLWRXU2XjaIG27B66Lq6IOkMNS+h+W7PEU2bNW+ByAe31RBv 21 | artifact: luadbg.zip 22 | draft: true 23 | -------------------------------------------------------------------------------- /dbgmem_test.lua: -------------------------------------------------------------------------------- 1 | a = dbgmem.new(evalmasm("@esp") , 0x20) 2 | print(string.format("addr =%x", a:offset())) 3 | print("size =",a:size()) 4 | print("cached size =", a:cachedsize()) 5 | print("before swap, a[0]=",a[0],",a1=",a[1]) 6 | t = a[1] 7 | a[1] = a[0] 8 | a[0] = t 9 | print("after swap, a[0]=",a[0],",a1=",a[1]) 10 | print("to hex string=", a:tohexstring()) 11 | print("from hex string=",a:fromhexstring("FFEE")) 12 | c = "abc\123\0cba" 13 | a:setstring(c) 14 | print("set string =", a:getstring()) 15 | 16 | 17 | -------------------------------------------------------------------------------- /luadbg.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "luadbg", "luadbg\luadbg.vcxproj", "{806415C6-30D2-46EE-853E-97EA20154953}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {806415C6-30D2-46EE-853E-97EA20154953}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {806415C6-30D2-46EE-853E-97EA20154953}.Debug|Win32.Build.0 = Debug|Win32 16 | {806415C6-30D2-46EE-853E-97EA20154953}.Debug|x64.ActiveCfg = Debug|x64 17 | {806415C6-30D2-46EE-853E-97EA20154953}.Debug|x64.Build.0 = Debug|x64 18 | {806415C6-30D2-46EE-853E-97EA20154953}.Release|Win32.ActiveCfg = Release|Win32 19 | {806415C6-30D2-46EE-853E-97EA20154953}.Release|Win32.Build.0 = Release|Win32 20 | {806415C6-30D2-46EE-853E-97EA20154953}.Release|x64.ActiveCfg = Release|x64 21 | {806415C6-30D2-46EE-853E-97EA20154953}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /luadbg/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | DYNAMIC LINK LIBRARY : luadbg Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this luadbg DLL for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your luadbg application. 9 | 10 | 11 | luadbg.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | luadbg.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | luadbg.cpp 25 | This is the main DLL source file. 26 | 27 | When created, this DLL does not export any symbols. As a result, it 28 | will not produce a .lib file when it is built. If you wish this project 29 | to be a project dependency of some other project, you will either need to 30 | add code to export some symbols from the DLL so that an export library 31 | will be produced, or you can set the Ignore Input Library property to Yes 32 | on the General propert page of the Linker folder in the project's Property 33 | Pages dialog box. 34 | 35 | ///////////////////////////////////////////////////////////////////////////// 36 | Other standard files: 37 | 38 | StdAfx.h, StdAfx.cpp 39 | These files are used to build a precompiled header (PCH) file 40 | named luadbg.pch and a precompiled types file named StdAfx.obj. 41 | 42 | ///////////////////////////////////////////////////////////////////////////// 43 | Other notes: 44 | 45 | AppWizard uses "TODO:" comments to indicate parts of the source code you 46 | should add to or customize. 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | -------------------------------------------------------------------------------- /luadbg/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "stdafx.h" 3 | /* 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | */ -------------------------------------------------------------------------------- /luadbg/lib/amd64/dbgeng.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/amd64/dbgeng.lib -------------------------------------------------------------------------------- /luadbg/lib/amd64/dbghelp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/amd64/dbghelp.lib -------------------------------------------------------------------------------- /luadbg/lib/amd64/engextcpp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/amd64/engextcpp.lib -------------------------------------------------------------------------------- /luadbg/lib/i386/dbgeng.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/i386/dbgeng.lib -------------------------------------------------------------------------------- /luadbg/lib/i386/dbghelp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/i386/dbghelp.lib -------------------------------------------------------------------------------- /luadbg/lib/i386/engextcpp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/i386/engextcpp.lib -------------------------------------------------------------------------------- /luadbg/lib/ia64/dbgeng.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/ia64/dbgeng.lib -------------------------------------------------------------------------------- /luadbg/lib/ia64/dbghelp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/ia64/dbghelp.lib -------------------------------------------------------------------------------- /luadbg/lib/ia64/engextcpp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/ia64/engextcpp.lib -------------------------------------------------------------------------------- /luadbg/lib/x86/dbgeng.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/x86/dbgeng.lib -------------------------------------------------------------------------------- /luadbg/lib/x86/dbghelp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/x86/dbghelp.lib -------------------------------------------------------------------------------- /luadbg/lib/x86/engextcpp.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/lib/x86/engextcpp.lib -------------------------------------------------------------------------------- /luadbg/lua_src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /luadbg/lua_src/lauxlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lauxlib.h,v 1.129 2015/11/23 11:29:43 roberto Exp $ 3 | ** Auxiliary functions for building Lua libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lauxlib_h 9 | #define lauxlib_h 10 | 11 | 12 | #include 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | 18 | 19 | /* extra error code for 'luaL_load' */ 20 | #define LUA_ERRFILE (LUA_ERRERR+1) 21 | 22 | 23 | typedef struct luaL_Reg { 24 | const char *name; 25 | lua_CFunction func; 26 | } luaL_Reg; 27 | 28 | 29 | #define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number)) 30 | 31 | LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz); 32 | #define luaL_checkversion(L) \ 33 | luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES) 34 | 35 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 36 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 37 | LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); 38 | LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg); 39 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, 40 | size_t *l); 41 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, 42 | const char *def, size_t *l); 43 | LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg); 44 | LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def); 45 | 46 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg); 47 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg, 48 | lua_Integer def); 49 | 50 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 51 | LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t); 52 | LUALIB_API void (luaL_checkany) (lua_State *L, int arg); 53 | 54 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 55 | LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); 56 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); 57 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 58 | 59 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); 60 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); 61 | 62 | LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def, 63 | const char *const lst[]); 64 | 65 | LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); 66 | LUALIB_API int (luaL_execresult) (lua_State *L, int stat); 67 | 68 | /* predefined references */ 69 | #define LUA_NOREF (-2) 70 | #define LUA_REFNIL (-1) 71 | 72 | LUALIB_API int (luaL_ref) (lua_State *L, int t); 73 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 74 | 75 | LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, 76 | const char *mode); 77 | 78 | #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) 79 | 80 | LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, 81 | const char *name, const char *mode); 82 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 83 | 84 | LUALIB_API lua_State *(luaL_newstate) (void); 85 | 86 | LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); 87 | 88 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, 89 | const char *r); 90 | 91 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); 92 | 93 | LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname); 94 | 95 | LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1, 96 | const char *msg, int level); 97 | 98 | LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, 99 | lua_CFunction openf, int glb); 100 | 101 | /* 102 | ** =============================================================== 103 | ** some useful macros 104 | ** =============================================================== 105 | */ 106 | 107 | 108 | #define luaL_newlibtable(L,l) \ 109 | lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) 110 | 111 | #define luaL_newlib(L,l) \ 112 | (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) 113 | 114 | #define luaL_argcheck(L, cond,arg,extramsg) \ 115 | ((void)((cond) || luaL_argerror(L, (arg), (extramsg)))) 116 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 117 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 118 | 119 | #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) 120 | 121 | #define luaL_dofile(L, fn) \ 122 | (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 123 | 124 | #define luaL_dostring(L, s) \ 125 | (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 126 | 127 | #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 128 | 129 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 130 | 131 | #define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) 132 | 133 | 134 | /* 135 | ** {====================================================== 136 | ** Generic Buffer manipulation 137 | ** ======================================================= 138 | */ 139 | 140 | typedef struct luaL_Buffer { 141 | char *b; /* buffer address */ 142 | size_t size; /* buffer size */ 143 | size_t n; /* number of characters in buffer */ 144 | lua_State *L; 145 | char initb[LUAL_BUFFERSIZE]; /* initial buffer */ 146 | } luaL_Buffer; 147 | 148 | 149 | #define luaL_addchar(B,c) \ 150 | ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \ 151 | ((B)->b[(B)->n++] = (c))) 152 | 153 | #define luaL_addsize(B,s) ((B)->n += (s)) 154 | 155 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); 156 | LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz); 157 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); 158 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); 159 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); 160 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); 161 | LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz); 162 | LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); 163 | 164 | #define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE) 165 | 166 | /* }====================================================== */ 167 | 168 | 169 | 170 | /* 171 | ** {====================================================== 172 | ** File handles for IO library 173 | ** ======================================================= 174 | */ 175 | 176 | /* 177 | ** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and 178 | ** initial structure 'luaL_Stream' (it may contain other fields 179 | ** after that initial structure). 180 | */ 181 | 182 | #define LUA_FILEHANDLE "FILE*" 183 | 184 | 185 | typedef struct luaL_Stream { 186 | FILE *f; /* stream (NULL for incompletely created streams) */ 187 | lua_CFunction closef; /* to close stream (NULL for closed streams) */ 188 | } luaL_Stream; 189 | 190 | /* }====================================================== */ 191 | 192 | 193 | 194 | /* compatibility with old module system */ 195 | #if defined(LUA_COMPAT_MODULE) 196 | 197 | LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname, 198 | int sizehint); 199 | LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, 200 | const luaL_Reg *l, int nup); 201 | 202 | #define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0)) 203 | 204 | #endif 205 | 206 | 207 | /* 208 | ** {================================================================== 209 | ** "Abstraction Layer" for basic report of messages and errors 210 | ** =================================================================== 211 | */ 212 | 213 | /* print a string */ 214 | #if !defined(lua_writestring) 215 | #define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout) 216 | #endif 217 | 218 | /* print a newline and flush the output */ 219 | #if !defined(lua_writeline) 220 | #define lua_writeline() (lua_writestring("\n", 1), fflush(stdout)) 221 | #endif 222 | 223 | /* print an error message */ 224 | #if !defined(lua_writestringerror) 225 | #define lua_writestringerror(s,p) \ 226 | (fprintf(stderr, (s), (p)), fflush(stderr)) 227 | #endif 228 | 229 | /* }================================================================== */ 230 | 231 | 232 | /* 233 | ** {============================================================ 234 | ** Compatibility with deprecated conversions 235 | ** ============================================================= 236 | */ 237 | #if defined(LUA_COMPAT_APIINTCASTS) 238 | 239 | #define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a)) 240 | #define luaL_optunsigned(L,a,d) \ 241 | ((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d))) 242 | 243 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) 244 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) 245 | 246 | #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) 247 | #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) 248 | 249 | #endif 250 | /* }============================================================ */ 251 | 252 | 253 | 254 | #endif 255 | 256 | 257 | -------------------------------------------------------------------------------- /luadbg/lua_src/lbitlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lbitlib.c,v 1.30 2015/11/11 19:08:09 roberto Exp $ 3 | ** Standard library for bitwise operations 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lbitlib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lua.h" 14 | 15 | #include "lauxlib.h" 16 | #include "lualib.h" 17 | 18 | 19 | #if defined(LUA_COMPAT_BITLIB) /* { */ 20 | 21 | 22 | #define pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n)) 23 | #define checkunsigned(L,i) ((lua_Unsigned)luaL_checkinteger(L,i)) 24 | 25 | 26 | /* number of bits to consider in a number */ 27 | #if !defined(LUA_NBITS) 28 | #define LUA_NBITS 32 29 | #endif 30 | 31 | 32 | /* 33 | ** a lua_Unsigned with its first LUA_NBITS bits equal to 1. (Shift must 34 | ** be made in two parts to avoid problems when LUA_NBITS is equal to the 35 | ** number of bits in a lua_Unsigned.) 36 | */ 37 | #define ALLONES (~(((~(lua_Unsigned)0) << (LUA_NBITS - 1)) << 1)) 38 | 39 | 40 | /* macro to trim extra bits */ 41 | #define trim(x) ((x) & ALLONES) 42 | 43 | 44 | /* builds a number with 'n' ones (1 <= n <= LUA_NBITS) */ 45 | #define mask(n) (~((ALLONES << 1) << ((n) - 1))) 46 | 47 | 48 | 49 | static lua_Unsigned andaux (lua_State *L) { 50 | int i, n = lua_gettop(L); 51 | lua_Unsigned r = ~(lua_Unsigned)0; 52 | for (i = 1; i <= n; i++) 53 | r &= checkunsigned(L, i); 54 | return trim(r); 55 | } 56 | 57 | 58 | static int b_and (lua_State *L) { 59 | lua_Unsigned r = andaux(L); 60 | pushunsigned(L, r); 61 | return 1; 62 | } 63 | 64 | 65 | static int b_test (lua_State *L) { 66 | lua_Unsigned r = andaux(L); 67 | lua_pushboolean(L, r != 0); 68 | return 1; 69 | } 70 | 71 | 72 | static int b_or (lua_State *L) { 73 | int i, n = lua_gettop(L); 74 | lua_Unsigned r = 0; 75 | for (i = 1; i <= n; i++) 76 | r |= checkunsigned(L, i); 77 | pushunsigned(L, trim(r)); 78 | return 1; 79 | } 80 | 81 | 82 | static int b_xor (lua_State *L) { 83 | int i, n = lua_gettop(L); 84 | lua_Unsigned r = 0; 85 | for (i = 1; i <= n; i++) 86 | r ^= checkunsigned(L, i); 87 | pushunsigned(L, trim(r)); 88 | return 1; 89 | } 90 | 91 | 92 | static int b_not (lua_State *L) { 93 | lua_Unsigned r = ~checkunsigned(L, 1); 94 | pushunsigned(L, trim(r)); 95 | return 1; 96 | } 97 | 98 | 99 | static int b_shift (lua_State *L, lua_Unsigned r, lua_Integer i) { 100 | if (i < 0) { /* shift right? */ 101 | i = -i; 102 | r = trim(r); 103 | if (i >= LUA_NBITS) r = 0; 104 | else r >>= i; 105 | } 106 | else { /* shift left */ 107 | if (i >= LUA_NBITS) r = 0; 108 | else r <<= i; 109 | r = trim(r); 110 | } 111 | pushunsigned(L, r); 112 | return 1; 113 | } 114 | 115 | 116 | static int b_lshift (lua_State *L) { 117 | return b_shift(L, checkunsigned(L, 1), luaL_checkinteger(L, 2)); 118 | } 119 | 120 | 121 | static int b_rshift (lua_State *L) { 122 | return b_shift(L, checkunsigned(L, 1), -luaL_checkinteger(L, 2)); 123 | } 124 | 125 | 126 | static int b_arshift (lua_State *L) { 127 | lua_Unsigned r = checkunsigned(L, 1); 128 | lua_Integer i = luaL_checkinteger(L, 2); 129 | if (i < 0 || !(r & ((lua_Unsigned)1 << (LUA_NBITS - 1)))) 130 | return b_shift(L, r, -i); 131 | else { /* arithmetic shift for 'negative' number */ 132 | if (i >= LUA_NBITS) r = ALLONES; 133 | else 134 | r = trim((r >> i) | ~(trim(~(lua_Unsigned)0) >> i)); /* add signal bit */ 135 | pushunsigned(L, r); 136 | return 1; 137 | } 138 | } 139 | 140 | 141 | static int b_rot (lua_State *L, lua_Integer d) { 142 | lua_Unsigned r = checkunsigned(L, 1); 143 | int i = d & (LUA_NBITS - 1); /* i = d % NBITS */ 144 | r = trim(r); 145 | if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ 146 | r = (r << i) | (r >> (LUA_NBITS - i)); 147 | pushunsigned(L, trim(r)); 148 | return 1; 149 | } 150 | 151 | 152 | static int b_lrot (lua_State *L) { 153 | return b_rot(L, luaL_checkinteger(L, 2)); 154 | } 155 | 156 | 157 | static int b_rrot (lua_State *L) { 158 | return b_rot(L, -luaL_checkinteger(L, 2)); 159 | } 160 | 161 | 162 | /* 163 | ** get field and width arguments for field-manipulation functions, 164 | ** checking whether they are valid. 165 | ** ('luaL_error' called without 'return' to avoid later warnings about 166 | ** 'width' being used uninitialized.) 167 | */ 168 | static int fieldargs (lua_State *L, int farg, int *width) { 169 | lua_Integer f = luaL_checkinteger(L, farg); 170 | lua_Integer w = luaL_optinteger(L, farg + 1, 1); 171 | luaL_argcheck(L, 0 <= f, farg, "field cannot be negative"); 172 | luaL_argcheck(L, 0 < w, farg + 1, "width must be positive"); 173 | if (f + w > LUA_NBITS) 174 | luaL_error(L, "trying to access non-existent bits"); 175 | *width = (int)w; 176 | return (int)f; 177 | } 178 | 179 | 180 | static int b_extract (lua_State *L) { 181 | int w; 182 | lua_Unsigned r = trim(checkunsigned(L, 1)); 183 | int f = fieldargs(L, 2, &w); 184 | r = (r >> f) & mask(w); 185 | pushunsigned(L, r); 186 | return 1; 187 | } 188 | 189 | 190 | static int b_replace (lua_State *L) { 191 | int w; 192 | lua_Unsigned r = trim(checkunsigned(L, 1)); 193 | lua_Unsigned v = trim(checkunsigned(L, 2)); 194 | int f = fieldargs(L, 3, &w); 195 | lua_Unsigned m = mask(w); 196 | r = (r & ~(m << f)) | ((v & m) << f); 197 | pushunsigned(L, r); 198 | return 1; 199 | } 200 | 201 | 202 | static const luaL_Reg bitlib[] = { 203 | {"arshift", b_arshift}, 204 | {"band", b_and}, 205 | {"bnot", b_not}, 206 | {"bor", b_or}, 207 | {"bxor", b_xor}, 208 | {"btest", b_test}, 209 | {"extract", b_extract}, 210 | {"lrotate", b_lrot}, 211 | {"lshift", b_lshift}, 212 | {"replace", b_replace}, 213 | {"rrotate", b_rrot}, 214 | {"rshift", b_rshift}, 215 | {NULL, NULL} 216 | }; 217 | 218 | 219 | 220 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 221 | luaL_newlib(L, bitlib); 222 | return 1; 223 | } 224 | 225 | 226 | #else /* }{ */ 227 | 228 | 229 | LUAMOD_API int luaopen_bit32 (lua_State *L) { 230 | return luaL_error(L, "library 'bit32' has been deprecated"); 231 | } 232 | 233 | #endif /* } */ 234 | -------------------------------------------------------------------------------- /luadbg/lua_src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.64 2016/01/05 16:22:37 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, 28 | OPR_DIV, 29 | OPR_IDIV, 30 | OPR_BAND, OPR_BOR, OPR_BXOR, 31 | OPR_SHL, OPR_SHR, 32 | OPR_CONCAT, 33 | OPR_EQ, OPR_LT, OPR_LE, 34 | OPR_NE, OPR_GT, OPR_GE, 35 | OPR_AND, OPR_OR, 36 | OPR_NOBINOPR 37 | } BinOpr; 38 | 39 | 40 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 41 | 42 | 43 | /* get (pointer to) instruction of given 'expdesc' */ 44 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) 45 | 46 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 47 | 48 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 49 | 50 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 51 | 52 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 53 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 54 | LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); 55 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 56 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 57 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 58 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 59 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 60 | LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n); 61 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 62 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 63 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 64 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 65 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 66 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 67 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 68 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 69 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 70 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 71 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 72 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 73 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 74 | LUAI_FUNC int luaK_jump (FuncState *fs); 75 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 76 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 77 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 78 | LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level); 79 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 80 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 81 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 82 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 83 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 84 | expdesc *v2, int line); 85 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 86 | 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /luadbg/lua_src/lcorolib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcorolib.c,v 1.10 2016/04/11 19:19:55 roberto Exp $ 3 | ** Coroutine Library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lcorolib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lauxlib.h" 18 | #include "lualib.h" 19 | 20 | 21 | static lua_State *getco (lua_State *L) { 22 | lua_State *co = lua_tothread(L, 1); 23 | luaL_argcheck(L, co, 1, "thread expected"); 24 | return co; 25 | } 26 | 27 | 28 | static int auxresume (lua_State *L, lua_State *co, int narg) { 29 | int status; 30 | if (!lua_checkstack(co, narg)) { 31 | lua_pushliteral(L, "too many arguments to resume"); 32 | return -1; /* error flag */ 33 | } 34 | if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) { 35 | lua_pushliteral(L, "cannot resume dead coroutine"); 36 | return -1; /* error flag */ 37 | } 38 | lua_xmove(L, co, narg); 39 | status = lua_resume(co, L, narg); 40 | if (status == LUA_OK || status == LUA_YIELD) { 41 | int nres = lua_gettop(co); 42 | if (!lua_checkstack(L, nres + 1)) { 43 | lua_pop(co, nres); /* remove results anyway */ 44 | lua_pushliteral(L, "too many results to resume"); 45 | return -1; /* error flag */ 46 | } 47 | lua_xmove(co, L, nres); /* move yielded values */ 48 | return nres; 49 | } 50 | else { 51 | lua_xmove(co, L, 1); /* move error message */ 52 | return -1; /* error flag */ 53 | } 54 | } 55 | 56 | 57 | static int luaB_coresume (lua_State *L) { 58 | lua_State *co = getco(L); 59 | int r; 60 | r = auxresume(L, co, lua_gettop(L) - 1); 61 | if (r < 0) { 62 | lua_pushboolean(L, 0); 63 | lua_insert(L, -2); 64 | return 2; /* return false + error message */ 65 | } 66 | else { 67 | lua_pushboolean(L, 1); 68 | lua_insert(L, -(r + 1)); 69 | return r + 1; /* return true + 'resume' returns */ 70 | } 71 | } 72 | 73 | 74 | static int luaB_auxwrap (lua_State *L) { 75 | lua_State *co = lua_tothread(L, lua_upvalueindex(1)); 76 | int r = auxresume(L, co, lua_gettop(L)); 77 | if (r < 0) { 78 | if (lua_type(L, -1) == LUA_TSTRING) { /* error object is a string? */ 79 | luaL_where(L, 1); /* add extra info */ 80 | lua_insert(L, -2); 81 | lua_concat(L, 2); 82 | } 83 | return lua_error(L); /* propagate error */ 84 | } 85 | return r; 86 | } 87 | 88 | 89 | static int luaB_cocreate (lua_State *L) { 90 | lua_State *NL; 91 | luaL_checktype(L, 1, LUA_TFUNCTION); 92 | NL = lua_newthread(L); 93 | lua_pushvalue(L, 1); /* move function to top */ 94 | lua_xmove(L, NL, 1); /* move function from L to NL */ 95 | return 1; 96 | } 97 | 98 | 99 | static int luaB_cowrap (lua_State *L) { 100 | luaB_cocreate(L); 101 | lua_pushcclosure(L, luaB_auxwrap, 1); 102 | return 1; 103 | } 104 | 105 | 106 | static int luaB_yield (lua_State *L) { 107 | return lua_yield(L, lua_gettop(L)); 108 | } 109 | 110 | 111 | static int luaB_costatus (lua_State *L) { 112 | lua_State *co = getco(L); 113 | if (L == co) lua_pushliteral(L, "running"); 114 | else { 115 | switch (lua_status(co)) { 116 | case LUA_YIELD: 117 | lua_pushliteral(L, "suspended"); 118 | break; 119 | case LUA_OK: { 120 | lua_Debug ar; 121 | if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ 122 | lua_pushliteral(L, "normal"); /* it is running */ 123 | else if (lua_gettop(co) == 0) 124 | lua_pushliteral(L, "dead"); 125 | else 126 | lua_pushliteral(L, "suspended"); /* initial state */ 127 | break; 128 | } 129 | default: /* some error occurred */ 130 | lua_pushliteral(L, "dead"); 131 | break; 132 | } 133 | } 134 | return 1; 135 | } 136 | 137 | 138 | static int luaB_yieldable (lua_State *L) { 139 | lua_pushboolean(L, lua_isyieldable(L)); 140 | return 1; 141 | } 142 | 143 | 144 | static int luaB_corunning (lua_State *L) { 145 | int ismain = lua_pushthread(L); 146 | lua_pushboolean(L, ismain); 147 | return 2; 148 | } 149 | 150 | 151 | static const luaL_Reg co_funcs[] = { 152 | {"create", luaB_cocreate}, 153 | {"resume", luaB_coresume}, 154 | {"running", luaB_corunning}, 155 | {"status", luaB_costatus}, 156 | {"wrap", luaB_cowrap}, 157 | {"yield", luaB_yield}, 158 | {"isyieldable", luaB_yieldable}, 159 | {NULL, NULL} 160 | }; 161 | 162 | 163 | 164 | LUAMOD_API int luaopen_coroutine (lua_State *L) { 165 | luaL_newlib(L, co_funcs); 166 | return 1; 167 | } 168 | 169 | -------------------------------------------------------------------------------- /luadbg/lua_src/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 20 | 0x00, /* EOZ */ 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 22 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 26 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 27 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 28 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 29 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 30 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 31 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 32 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 33 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 34 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 35 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 36 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ 42 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ 48 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ 50 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 | }; 54 | 55 | #endif /* } */ 56 | -------------------------------------------------------------------------------- /luadbg/lua_src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h,v 1.12 2011/07/15 12:50:29 roberto Exp $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | /* 65 | ** this 'ltolower' only works for alphabetic characters 66 | */ 67 | #define ltolower(c) ((c) | ('A' ^ 'a')) 68 | 69 | 70 | /* two more entries for 0 and -1 (EOZ) */ 71 | LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; 72 | 73 | 74 | #else /* }{ */ 75 | 76 | /* 77 | ** use standard C ctypes 78 | */ 79 | 80 | #include 81 | 82 | 83 | #define lislalpha(c) (isalpha(c) || (c) == '_') 84 | #define lislalnum(c) (isalnum(c) || (c) == '_') 85 | #define lisdigit(c) (isdigit(c)) 86 | #define lisspace(c) (isspace(c)) 87 | #define lisprint(c) (isprint(c)) 88 | #define lisxdigit(c) (isxdigit(c)) 89 | 90 | #define ltolower(c) (tolower(c)) 91 | 92 | #endif /* } */ 93 | 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /luadbg/lua_src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.14 2015/05/22 17:45:56 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 24 | const TValue *p2); 25 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 26 | const TValue *p2, 27 | const char *msg); 28 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 29 | const TValue *p2); 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 31 | const TValue *p2); 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 34 | TString *src, int line); 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); 37 | 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /luadbg/lua_src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 21 | ** at every check. 22 | */ 23 | #define luaD_checkstackaux(L,n,pre,pos) \ 24 | if (L->stack_last - L->top <= (n)) \ 25 | { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); } 26 | 27 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 28 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 29 | 30 | 31 | 32 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 33 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 34 | 35 | 36 | /* type of protected functions, to be ran by 'runprotected' */ 37 | typedef void (*Pfunc) (lua_State *L, void *ud); 38 | 39 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 40 | const char *mode); 41 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 45 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 46 | ptrdiff_t oldtop, ptrdiff_t ef); 47 | LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 48 | int nres); 49 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 50 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 51 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 52 | LUAI_FUNC void luaD_inctop (lua_State *L); 53 | 54 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 55 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /luadbg/lua_src/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c,v 2.37 2015/10/08 15:53:49 roberto Exp $ 3 | ** save precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ldump_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lobject.h" 18 | #include "lstate.h" 19 | #include "lundump.h" 20 | 21 | 22 | typedef struct { 23 | lua_State *L; 24 | lua_Writer writer; 25 | void *data; 26 | int strip; 27 | int status; 28 | } DumpState; 29 | 30 | 31 | /* 32 | ** All high-level dumps go through DumpVector; you can change it to 33 | ** change the endianness of the result 34 | */ 35 | #define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D) 36 | 37 | #define DumpLiteral(s,D) DumpBlock(s, sizeof(s) - sizeof(char), D) 38 | 39 | 40 | static void DumpBlock (const void *b, size_t size, DumpState *D) { 41 | if (D->status == 0 && size > 0) { 42 | lua_unlock(D->L); 43 | D->status = (*D->writer)(D->L, b, size, D->data); 44 | lua_lock(D->L); 45 | } 46 | } 47 | 48 | 49 | #define DumpVar(x,D) DumpVector(&x,1,D) 50 | 51 | 52 | static void DumpByte (int y, DumpState *D) { 53 | lu_byte x = (lu_byte)y; 54 | DumpVar(x, D); 55 | } 56 | 57 | 58 | static void DumpInt (int x, DumpState *D) { 59 | DumpVar(x, D); 60 | } 61 | 62 | 63 | static void DumpNumber (lua_Number x, DumpState *D) { 64 | DumpVar(x, D); 65 | } 66 | 67 | 68 | static void DumpInteger (lua_Integer x, DumpState *D) { 69 | DumpVar(x, D); 70 | } 71 | 72 | 73 | static void DumpString (const TString *s, DumpState *D) { 74 | if (s == NULL) 75 | DumpByte(0, D); 76 | else { 77 | size_t size = tsslen(s) + 1; /* include trailing '\0' */ 78 | const char *str = getstr(s); 79 | if (size < 0xFF) 80 | DumpByte(cast_int(size), D); 81 | else { 82 | DumpByte(0xFF, D); 83 | DumpVar(size, D); 84 | } 85 | DumpVector(str, size - 1, D); /* no need to save '\0' */ 86 | } 87 | } 88 | 89 | 90 | static void DumpCode (const Proto *f, DumpState *D) { 91 | DumpInt(f->sizecode, D); 92 | DumpVector(f->code, f->sizecode, D); 93 | } 94 | 95 | 96 | static void DumpFunction(const Proto *f, TString *psource, DumpState *D); 97 | 98 | static void DumpConstants (const Proto *f, DumpState *D) { 99 | int i; 100 | int n = f->sizek; 101 | DumpInt(n, D); 102 | for (i = 0; i < n; i++) { 103 | const TValue *o = &f->k[i]; 104 | DumpByte(ttype(o), D); 105 | switch (ttype(o)) { 106 | case LUA_TNIL: 107 | break; 108 | case LUA_TBOOLEAN: 109 | DumpByte(bvalue(o), D); 110 | break; 111 | case LUA_TNUMFLT: 112 | DumpNumber(fltvalue(o), D); 113 | break; 114 | case LUA_TNUMINT: 115 | DumpInteger(ivalue(o), D); 116 | break; 117 | case LUA_TSHRSTR: 118 | case LUA_TLNGSTR: 119 | DumpString(tsvalue(o), D); 120 | break; 121 | default: 122 | lua_assert(0); 123 | } 124 | } 125 | } 126 | 127 | 128 | static void DumpProtos (const Proto *f, DumpState *D) { 129 | int i; 130 | int n = f->sizep; 131 | DumpInt(n, D); 132 | for (i = 0; i < n; i++) 133 | DumpFunction(f->p[i], f->source, D); 134 | } 135 | 136 | 137 | static void DumpUpvalues (const Proto *f, DumpState *D) { 138 | int i, n = f->sizeupvalues; 139 | DumpInt(n, D); 140 | for (i = 0; i < n; i++) { 141 | DumpByte(f->upvalues[i].instack, D); 142 | DumpByte(f->upvalues[i].idx, D); 143 | } 144 | } 145 | 146 | 147 | static void DumpDebug (const Proto *f, DumpState *D) { 148 | int i, n; 149 | n = (D->strip) ? 0 : f->sizelineinfo; 150 | DumpInt(n, D); 151 | DumpVector(f->lineinfo, n, D); 152 | n = (D->strip) ? 0 : f->sizelocvars; 153 | DumpInt(n, D); 154 | for (i = 0; i < n; i++) { 155 | DumpString(f->locvars[i].varname, D); 156 | DumpInt(f->locvars[i].startpc, D); 157 | DumpInt(f->locvars[i].endpc, D); 158 | } 159 | n = (D->strip) ? 0 : f->sizeupvalues; 160 | DumpInt(n, D); 161 | for (i = 0; i < n; i++) 162 | DumpString(f->upvalues[i].name, D); 163 | } 164 | 165 | 166 | static void DumpFunction (const Proto *f, TString *psource, DumpState *D) { 167 | if (D->strip || f->source == psource) 168 | DumpString(NULL, D); /* no debug info or same source as its parent */ 169 | else 170 | DumpString(f->source, D); 171 | DumpInt(f->linedefined, D); 172 | DumpInt(f->lastlinedefined, D); 173 | DumpByte(f->numparams, D); 174 | DumpByte(f->is_vararg, D); 175 | DumpByte(f->maxstacksize, D); 176 | DumpCode(f, D); 177 | DumpConstants(f, D); 178 | DumpUpvalues(f, D); 179 | DumpProtos(f, D); 180 | DumpDebug(f, D); 181 | } 182 | 183 | 184 | static void DumpHeader (DumpState *D) { 185 | DumpLiteral(LUA_SIGNATURE, D); 186 | DumpByte(LUAC_VERSION, D); 187 | DumpByte(LUAC_FORMAT, D); 188 | DumpLiteral(LUAC_DATA, D); 189 | DumpByte(sizeof(int), D); 190 | DumpByte(sizeof(size_t), D); 191 | DumpByte(sizeof(Instruction), D); 192 | DumpByte(sizeof(lua_Integer), D); 193 | DumpByte(sizeof(lua_Number), D); 194 | DumpInteger(LUAC_INT, D); 195 | DumpNumber(LUAC_NUM, D); 196 | } 197 | 198 | 199 | /* 200 | ** dump Lua function as precompiled chunk 201 | */ 202 | int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, 203 | int strip) { 204 | DumpState D; 205 | D.L = L; 206 | D.writer = w; 207 | D.data = data; 208 | D.strip = strip; 209 | D.status = 0; 210 | DumpHeader(&D); 211 | DumpByte(f->sizeupvalues, &D); 212 | DumpFunction(f, NULL, &D); 213 | return D.status; 214 | } 215 | 216 | -------------------------------------------------------------------------------- /luadbg/lua_src/lfunc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.c,v 2.45 2014/11/02 19:19:04 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lfunc_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lfunc.h" 18 | #include "lgc.h" 19 | #include "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | 23 | 24 | 25 | CClosure *luaF_newCclosure (lua_State *L, int n) { 26 | GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n)); 27 | CClosure *c = gco2ccl(o); 28 | c->nupvalues = cast_byte(n); 29 | return c; 30 | } 31 | 32 | 33 | LClosure *luaF_newLclosure (lua_State *L, int n) { 34 | GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n)); 35 | LClosure *c = gco2lcl(o); 36 | c->p = NULL; 37 | c->nupvalues = cast_byte(n); 38 | while (n--) c->upvals[n] = NULL; 39 | return c; 40 | } 41 | 42 | /* 43 | ** fill a closure with new closed upvalues 44 | */ 45 | void luaF_initupvals (lua_State *L, LClosure *cl) { 46 | int i; 47 | for (i = 0; i < cl->nupvalues; i++) { 48 | UpVal *uv = luaM_new(L, UpVal); 49 | uv->refcount = 1; 50 | uv->v = &uv->u.value; /* make it closed */ 51 | setnilvalue(uv->v); 52 | cl->upvals[i] = uv; 53 | } 54 | } 55 | 56 | 57 | UpVal *luaF_findupval (lua_State *L, StkId level) { 58 | UpVal **pp = &L->openupval; 59 | UpVal *p; 60 | UpVal *uv; 61 | lua_assert(isintwups(L) || L->openupval == NULL); 62 | while (*pp != NULL && (p = *pp)->v >= level) { 63 | lua_assert(upisopen(p)); 64 | if (p->v == level) /* found a corresponding upvalue? */ 65 | return p; /* return it */ 66 | pp = &p->u.open.next; 67 | } 68 | /* not found: create a new upvalue */ 69 | uv = luaM_new(L, UpVal); 70 | uv->refcount = 0; 71 | uv->u.open.next = *pp; /* link it to list of open upvalues */ 72 | uv->u.open.touched = 1; 73 | *pp = uv; 74 | uv->v = level; /* current value lives in the stack */ 75 | if (!isintwups(L)) { /* thread not in list of threads with upvalues? */ 76 | L->twups = G(L)->twups; /* link it to the list */ 77 | G(L)->twups = L; 78 | } 79 | return uv; 80 | } 81 | 82 | 83 | void luaF_close (lua_State *L, StkId level) { 84 | UpVal *uv; 85 | while (L->openupval != NULL && (uv = L->openupval)->v >= level) { 86 | lua_assert(upisopen(uv)); 87 | L->openupval = uv->u.open.next; /* remove from 'open' list */ 88 | if (uv->refcount == 0) /* no references? */ 89 | luaM_free(L, uv); /* free upvalue */ 90 | else { 91 | setobj(L, &uv->u.value, uv->v); /* move value to upvalue slot */ 92 | uv->v = &uv->u.value; /* now current value lives here */ 93 | luaC_upvalbarrier(L, uv); 94 | } 95 | } 96 | } 97 | 98 | 99 | Proto *luaF_newproto (lua_State *L) { 100 | GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto)); 101 | Proto *f = gco2p(o); 102 | f->k = NULL; 103 | f->sizek = 0; 104 | f->p = NULL; 105 | f->sizep = 0; 106 | f->code = NULL; 107 | f->cache = NULL; 108 | f->sizecode = 0; 109 | f->lineinfo = NULL; 110 | f->sizelineinfo = 0; 111 | f->upvalues = NULL; 112 | f->sizeupvalues = 0; 113 | f->numparams = 0; 114 | f->is_vararg = 0; 115 | f->maxstacksize = 0; 116 | f->locvars = NULL; 117 | f->sizelocvars = 0; 118 | f->linedefined = 0; 119 | f->lastlinedefined = 0; 120 | f->source = NULL; 121 | return f; 122 | } 123 | 124 | 125 | void luaF_freeproto (lua_State *L, Proto *f) { 126 | luaM_freearray(L, f->code, f->sizecode); 127 | luaM_freearray(L, f->p, f->sizep); 128 | luaM_freearray(L, f->k, f->sizek); 129 | luaM_freearray(L, f->lineinfo, f->sizelineinfo); 130 | luaM_freearray(L, f->locvars, f->sizelocvars); 131 | luaM_freearray(L, f->upvalues, f->sizeupvalues); 132 | luaM_free(L, f); 133 | } 134 | 135 | 136 | /* 137 | ** Look for n-th local variable at line 'line' in function 'func'. 138 | ** Returns NULL if not found. 139 | */ 140 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { 141 | int i; 142 | for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) { 143 | if (pc < f->locvars[i].endpc) { /* is variable active? */ 144 | local_number--; 145 | if (local_number == 0) 146 | return getstr(f->locvars[i].varname); 147 | } 148 | } 149 | return NULL; /* not found */ 150 | } 151 | 152 | -------------------------------------------------------------------------------- /luadbg/lua_src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | /* 33 | ** Upvalues for Lua closures 34 | */ 35 | struct UpVal { 36 | TValue *v; /* points to stack or to its own value */ 37 | lu_mem refcount; /* reference counter */ 38 | union { 39 | struct { /* (when open) */ 40 | UpVal *next; /* linked list */ 41 | int touched; /* mark to avoid cycles with dead threads */ 42 | } open; 43 | TValue value; /* the value (when closed) */ 44 | } u; 45 | }; 46 | 47 | #define upisopen(up) ((up)->v != &(up)->u.value) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 57 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 58 | int pc); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /luadbg/lua_src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 2.91 2015/12/21 13:02:14 roberto Exp $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | /* 15 | ** Collectable objects may have one of three colors: white, which 16 | ** means the object is not marked; gray, which means the 17 | ** object is marked, but its references may be not marked; and 18 | ** black, which means that the object and all its references are marked. 19 | ** The main invariant of the garbage collector, while marking objects, 20 | ** is that a black object can never point to a white one. Moreover, 21 | ** any gray object must be in a "gray list" (gray, grayagain, weak, 22 | ** allweak, ephemeron) so that it can be visited again before finishing 23 | ** the collection cycle. These lists have no meaning when the invariant 24 | ** is not being enforced (e.g., sweep phase). 25 | */ 26 | 27 | 28 | 29 | /* how much to allocate before next GC step */ 30 | #if !defined(GCSTEPSIZE) 31 | /* ~100 small strings */ 32 | #define GCSTEPSIZE (cast_int(100 * sizeof(TString))) 33 | #endif 34 | 35 | 36 | /* 37 | ** Possible states of the Garbage Collector 38 | */ 39 | #define GCSpropagate 0 40 | #define GCSatomic 1 41 | #define GCSswpallgc 2 42 | #define GCSswpfinobj 3 43 | #define GCSswptobefnz 4 44 | #define GCSswpend 5 45 | #define GCScallfin 6 46 | #define GCSpause 7 47 | 48 | 49 | #define issweepphase(g) \ 50 | (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend) 51 | 52 | 53 | /* 54 | ** macro to tell when main invariant (white objects cannot point to black 55 | ** ones) must be kept. During a collection, the sweep 56 | ** phase may break the invariant, as objects turned white may point to 57 | ** still-black objects. The invariant is restored when sweep ends and 58 | ** all objects are white again. 59 | */ 60 | 61 | #define keepinvariant(g) ((g)->gcstate <= GCSatomic) 62 | 63 | 64 | /* 65 | ** some useful bit tricks 66 | */ 67 | #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) 68 | #define setbits(x,m) ((x) |= (m)) 69 | #define testbits(x,m) ((x) & (m)) 70 | #define bitmask(b) (1<<(b)) 71 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 72 | #define l_setbit(x,b) setbits(x, bitmask(b)) 73 | #define resetbit(x,b) resetbits(x, bitmask(b)) 74 | #define testbit(x,b) testbits(x, bitmask(b)) 75 | 76 | 77 | /* Layout for bit use in 'marked' field: */ 78 | #define WHITE0BIT 0 /* object is white (type 0) */ 79 | #define WHITE1BIT 1 /* object is white (type 1) */ 80 | #define BLACKBIT 2 /* object is black */ 81 | #define FINALIZEDBIT 3 /* object has been marked for finalization */ 82 | /* bit 7 is currently used by tests (luaL_checkmemory) */ 83 | 84 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 85 | 86 | 87 | #define iswhite(x) testbits((x)->marked, WHITEBITS) 88 | #define isblack(x) testbit((x)->marked, BLACKBIT) 89 | #define isgray(x) /* neither white nor black */ \ 90 | (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT))) 91 | 92 | #define tofinalize(x) testbit((x)->marked, FINALIZEDBIT) 93 | 94 | #define otherwhite(g) ((g)->currentwhite ^ WHITEBITS) 95 | #define isdeadm(ow,m) (!(((m) ^ WHITEBITS) & (ow))) 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->marked) 97 | 98 | #define changewhite(x) ((x)->marked ^= WHITEBITS) 99 | #define gray2black(x) l_setbit((x)->marked, BLACKBIT) 100 | 101 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 102 | 103 | 104 | /* 105 | ** Does one step of collection when debt becomes positive. 'pre'/'pos' 106 | ** allows some adjustments to be done only when needed. macro 107 | ** 'condchangemem' is used only for heavy tests (forcing a full 108 | ** GC cycle on every opportunity) 109 | */ 110 | #define luaC_condGC(L,pre,pos) \ 111 | { if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \ 112 | condchangemem(L,pre,pos); } 113 | 114 | /* more often than not, 'pre'/'pos' are empty */ 115 | #define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0) 116 | 117 | 118 | #define luaC_barrier(L,p,v) ( \ 119 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 120 | luaC_barrier_(L,obj2gco(p),gcvalue(v)) : cast_void(0)) 121 | 122 | #define luaC_barrierback(L,p,v) ( \ 123 | (iscollectable(v) && isblack(p) && iswhite(gcvalue(v))) ? \ 124 | luaC_barrierback_(L,p) : cast_void(0)) 125 | 126 | #define luaC_objbarrier(L,p,o) ( \ 127 | (isblack(p) && iswhite(o)) ? \ 128 | luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0)) 129 | 130 | #define luaC_upvalbarrier(L,uv) ( \ 131 | (iscollectable((uv)->v) && !upisopen(uv)) ? \ 132 | luaC_upvalbarrier_(L,uv) : cast_void(0)) 133 | 134 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 135 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); 136 | LUAI_FUNC void luaC_step (lua_State *L); 137 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 138 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 139 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 140 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 141 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, Table *o); 142 | LUAI_FUNC void luaC_upvalbarrier_ (lua_State *L, UpVal *uv); 143 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 144 | LUAI_FUNC void luaC_upvdeccount (lua_State *L, UpVal *uv); 145 | 146 | 147 | #endif 148 | -------------------------------------------------------------------------------- /luadbg/lua_src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove _PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {"_G", luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | #if defined(LUA_COMPAT_BITLIB) 54 | {LUA_BITLIBNAME, luaopen_bit32}, 55 | #endif 56 | {NULL, NULL} 57 | }; 58 | 59 | 60 | LUALIB_API void luaL_openlibs (lua_State *L) { 61 | const luaL_Reg *lib; 62 | /* "require" functions from 'loadedlibs' and set results to global table */ 63 | for (lib = loadedlibs; lib->func; lib++) { 64 | luaL_requiref(L, lib->name, lib->func, 1); 65 | lua_pop(L, 1); /* remove lib */ 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /luadbg/lua_src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.79 2016/05/02 14:02:12 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | 17 | #if !defined(LUA_ENV) 18 | #define LUA_ENV "_ENV" 19 | #endif 20 | 21 | 22 | /* 23 | * WARNING: if you change the order of this enumeration, 24 | * grep "ORDER RESERVED" 25 | */ 26 | enum RESERVED { 27 | /* terminal symbols denoted by reserved words */ 28 | TK_AND = FIRST_RESERVED, TK_BREAK, 29 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 30 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 31 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 32 | /* other terminal symbols */ 33 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 34 | TK_SHL, TK_SHR, 35 | TK_DBCOLON, TK_EOS, 36 | TK_FLT, TK_INT, TK_NAME, TK_STRING 37 | }; 38 | 39 | /* number of reserved words */ 40 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | lua_Integer i; 46 | TString *ts; 47 | } SemInfo; /* semantics information */ 48 | 49 | 50 | typedef struct Token { 51 | int token; 52 | SemInfo seminfo; 53 | } Token; 54 | 55 | 56 | /* state of the lexer plus state of the parser when shared by all 57 | functions */ 58 | typedef struct LexState { 59 | int current; /* current character (charint) */ 60 | int linenumber; /* input line counter */ 61 | int lastline; /* line of last token 'consumed' */ 62 | Token t; /* current token */ 63 | Token lookahead; /* look ahead token */ 64 | struct FuncState *fs; /* current function (parser) */ 65 | struct lua_State *L; 66 | ZIO *z; /* input stream */ 67 | Mbuffer *buff; /* buffer for tokens */ 68 | Table *h; /* to avoid collection/reuse strings */ 69 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 70 | TString *source; /* current source name */ 71 | TString *envn; /* environment variable name */ 72 | } LexState; 73 | 74 | 75 | LUAI_FUNC void luaX_init (lua_State *L); 76 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 77 | TString *source, int firstchar); 78 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 79 | LUAI_FUNC void luaX_next (LexState *ls); 80 | LUAI_FUNC int luaX_lookahead (LexState *ls); 81 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 82 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /luadbg/lua_src/llimits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llimits.h,v 1.141 2015/11/19 19:16:22 roberto Exp $ 3 | ** Limits, basic types, and some other 'installation-dependent' definitions 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llimits_h 8 | #define llimits_h 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | #include "lua.h" 16 | 17 | /* 18 | ** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count 19 | ** the total memory used by Lua (in bytes). Usually, 'size_t' and 20 | ** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines. 21 | */ 22 | #if defined(LUAI_MEM) /* { external definitions? */ 23 | typedef LUAI_UMEM lu_mem; 24 | typedef LUAI_MEM l_mem; 25 | #elif LUAI_BITSINT >= 32 /* }{ */ 26 | typedef size_t lu_mem; 27 | typedef ptrdiff_t l_mem; 28 | #else /* 16-bit ints */ /* }{ */ 29 | typedef unsigned long lu_mem; 30 | typedef long l_mem; 31 | #endif /* } */ 32 | 33 | 34 | /* chars used as small naturals (so that 'char' is reserved for characters) */ 35 | typedef unsigned char lu_byte; 36 | 37 | 38 | /* maximum value for size_t */ 39 | #define MAX_SIZET ((size_t)(~(size_t)0)) 40 | 41 | /* maximum size visible for Lua (must be representable in a lua_Integer */ 42 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ 43 | : (size_t)(LUA_MAXINTEGER)) 44 | 45 | 46 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)) 47 | 48 | #define MAX_LMEM ((l_mem)(MAX_LUMEM >> 1)) 49 | 50 | 51 | #define MAX_INT INT_MAX /* maximum value of an int */ 52 | 53 | 54 | /* 55 | ** conversion of pointer to unsigned integer: 56 | ** this is for hashing only; there is no problem if the integer 57 | ** cannot hold the whole pointer value 58 | */ 59 | #define point2uint(p) ((unsigned int)((size_t)(p) & UINT_MAX)) 60 | 61 | 62 | 63 | /* type to ensure maximum alignment */ 64 | #if defined(LUAI_USER_ALIGNMENT_T) 65 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; 66 | #else 67 | typedef union { 68 | lua_Number n; 69 | double u; 70 | void *s; 71 | lua_Integer i; 72 | long l; 73 | } L_Umaxalign; 74 | #endif 75 | 76 | 77 | 78 | /* types of 'usual argument conversions' for lua_Number and lua_Integer */ 79 | typedef LUAI_UACNUMBER l_uacNumber; 80 | typedef LUAI_UACINT l_uacInt; 81 | 82 | 83 | /* internal assertions for in-house debugging */ 84 | #if defined(lua_assert) 85 | #define check_exp(c,e) (lua_assert(c), (e)) 86 | /* to avoid problems with conditions too long */ 87 | #define lua_longassert(c) ((c) ? (void)0 : lua_assert(0)) 88 | #else 89 | #define lua_assert(c) ((void)0) 90 | #define check_exp(c,e) (e) 91 | #define lua_longassert(c) ((void)0) 92 | #endif 93 | 94 | /* 95 | ** assertion for checking API calls 96 | */ 97 | #if !defined(luai_apicheck) 98 | #define luai_apicheck(l,e) lua_assert(e) 99 | #endif 100 | 101 | #define api_check(l,e,msg) luai_apicheck(l,(e) && msg) 102 | 103 | 104 | /* macro to avoid warnings about unused variables */ 105 | #if !defined(UNUSED) 106 | #define UNUSED(x) ((void)(x)) 107 | #endif 108 | 109 | 110 | /* type casts (a macro highlights casts in the code) */ 111 | #define cast(t, exp) ((t)(exp)) 112 | 113 | #define cast_void(i) cast(void, (i)) 114 | #define cast_byte(i) cast(lu_byte, (i)) 115 | #define cast_num(i) cast(lua_Number, (i)) 116 | #define cast_int(i) cast(int, (i)) 117 | #define cast_uchar(i) cast(unsigned char, (i)) 118 | 119 | 120 | /* cast a signed lua_Integer to lua_Unsigned */ 121 | #if !defined(l_castS2U) 122 | #define l_castS2U(i) ((lua_Unsigned)(i)) 123 | #endif 124 | 125 | /* 126 | ** cast a lua_Unsigned to a signed lua_Integer; this cast is 127 | ** not strict ISO C, but two-complement architectures should 128 | ** work fine. 129 | */ 130 | #if !defined(l_castU2S) 131 | #define l_castU2S(i) ((lua_Integer)(i)) 132 | #endif 133 | 134 | 135 | /* 136 | ** non-return type 137 | */ 138 | #if defined(__GNUC__) 139 | #define l_noret void __attribute__((noreturn)) 140 | #elif defined(_MSC_VER) && _MSC_VER >= 1200 141 | #define l_noret void __declspec(noreturn) 142 | #else 143 | #define l_noret void 144 | #endif 145 | 146 | 147 | 148 | /* 149 | ** maximum depth for nested C calls and syntactical nested non-terminals 150 | ** in a program. (Value must fit in an unsigned short int.) 151 | */ 152 | #if !defined(LUAI_MAXCCALLS) 153 | #define LUAI_MAXCCALLS 200 154 | #endif 155 | 156 | 157 | 158 | /* 159 | ** type for virtual-machine instructions; 160 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 161 | */ 162 | #if LUAI_BITSINT >= 32 163 | typedef unsigned int Instruction; 164 | #else 165 | typedef unsigned long Instruction; 166 | #endif 167 | 168 | 169 | 170 | /* 171 | ** Maximum length for short strings, that is, strings that are 172 | ** internalized. (Cannot be smaller than reserved words or tags for 173 | ** metamethods, as these strings must be internalized; 174 | ** #("function") = 8, #("__newindex") = 10.) 175 | */ 176 | #if !defined(LUAI_MAXSHORTLEN) 177 | #define LUAI_MAXSHORTLEN 40 178 | #endif 179 | 180 | 181 | /* 182 | ** Initial size for the string table (must be power of 2). 183 | ** The Lua core alone registers ~50 strings (reserved words + 184 | ** metaevent keys + a few others). Libraries would typically add 185 | ** a few dozens more. 186 | */ 187 | #if !defined(MINSTRTABSIZE) 188 | #define MINSTRTABSIZE 128 189 | #endif 190 | 191 | 192 | /* 193 | ** Size of cache for strings in the API. 'N' is the number of 194 | ** sets (better be a prime) and "M" is the size of each set (M == 1 195 | ** makes a direct cache.) 196 | */ 197 | #if !defined(STRCACHE_N) 198 | #define STRCACHE_N 53 199 | #define STRCACHE_M 2 200 | #endif 201 | 202 | 203 | /* minimum size for string buffer */ 204 | #if !defined(LUA_MINBUFFER) 205 | #define LUA_MINBUFFER 32 206 | #endif 207 | 208 | 209 | /* 210 | ** macros that are executed whenever program enters the Lua core 211 | ** ('lua_lock') and leaves the core ('lua_unlock') 212 | */ 213 | #if !defined(lua_lock) 214 | #define lua_lock(L) ((void) 0) 215 | #define lua_unlock(L) ((void) 0) 216 | #endif 217 | 218 | /* 219 | ** macro executed during Lua functions at points where the 220 | ** function can yield. 221 | */ 222 | #if !defined(luai_threadyield) 223 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 224 | #endif 225 | 226 | 227 | /* 228 | ** these macros allow user-specific actions on threads when you defined 229 | ** LUAI_EXTRASPACE and need to do something extra when a thread is 230 | ** created/deleted/resumed/yielded. 231 | */ 232 | #if !defined(luai_userstateopen) 233 | #define luai_userstateopen(L) ((void)L) 234 | #endif 235 | 236 | #if !defined(luai_userstateclose) 237 | #define luai_userstateclose(L) ((void)L) 238 | #endif 239 | 240 | #if !defined(luai_userstatethread) 241 | #define luai_userstatethread(L,L1) ((void)L) 242 | #endif 243 | 244 | #if !defined(luai_userstatefree) 245 | #define luai_userstatefree(L,L1) ((void)L) 246 | #endif 247 | 248 | #if !defined(luai_userstateresume) 249 | #define luai_userstateresume(L,n) ((void)L) 250 | #endif 251 | 252 | #if !defined(luai_userstateyield) 253 | #define luai_userstateyield(L,n) ((void)L) 254 | #endif 255 | 256 | 257 | 258 | /* 259 | ** The luai_num* macros define the primitive operations over numbers. 260 | */ 261 | 262 | /* floor division (defined as 'floor(a/b)') */ 263 | #if !defined(luai_numidiv) 264 | #define luai_numidiv(L,a,b) ((void)L, l_floor(luai_numdiv(L,a,b))) 265 | #endif 266 | 267 | /* float division */ 268 | #if !defined(luai_numdiv) 269 | #define luai_numdiv(L,a,b) ((a)/(b)) 270 | #endif 271 | 272 | /* 273 | ** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when 274 | ** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of 275 | ** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b) 276 | ** ~= floor(a/b)'. That happens when the division has a non-integer 277 | ** negative result, which is equivalent to the test below. 278 | */ 279 | #if !defined(luai_nummod) 280 | #define luai_nummod(L,a,b,m) \ 281 | { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); } 282 | #endif 283 | 284 | /* exponentiation */ 285 | #if !defined(luai_numpow) 286 | #define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b)) 287 | #endif 288 | 289 | /* the others are quite standard operations */ 290 | #if !defined(luai_numadd) 291 | #define luai_numadd(L,a,b) ((a)+(b)) 292 | #define luai_numsub(L,a,b) ((a)-(b)) 293 | #define luai_nummul(L,a,b) ((a)*(b)) 294 | #define luai_numunm(L,a) (-(a)) 295 | #define luai_numeq(a,b) ((a)==(b)) 296 | #define luai_numlt(a,b) ((a)<(b)) 297 | #define luai_numle(a,b) ((a)<=(b)) 298 | #define luai_numisnan(a) (!luai_numeq((a), (a))) 299 | #endif 300 | 301 | 302 | 303 | 304 | 305 | /* 306 | ** macro to control inclusion of some hard tests on stack reallocation 307 | */ 308 | #if !defined(HARDSTACKTESTS) 309 | #define condmovestack(L,pre,pos) ((void)0) 310 | #else 311 | /* realloc stack keeping its size */ 312 | #define condmovestack(L,pre,pos) \ 313 | { int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_); pos; } 314 | #endif 315 | 316 | #if !defined(HARDMEMTESTS) 317 | #define condchangemem(L,pre,pos) ((void)0) 318 | #else 319 | #define condchangemem(L,pre,pos) \ 320 | { if (G(L)->gcrunning) { pre; luaC_fullgc(L, 0); pos; } } 321 | #endif 322 | 323 | #endif 324 | -------------------------------------------------------------------------------- /luadbg/lua_src/lmathlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmathlib.c,v 1.117 2015/10/02 15:39:23 roberto Exp $ 3 | ** Standard mathematical library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lmathlib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | #include 15 | 16 | #include "lua.h" 17 | 18 | #include "lauxlib.h" 19 | #include "lualib.h" 20 | 21 | 22 | #undef PI 23 | #define PI (l_mathop(3.141592653589793238462643383279502884)) 24 | 25 | 26 | #if !defined(l_rand) /* { */ 27 | #if defined(LUA_USE_POSIX) 28 | #define l_rand() random() 29 | #define l_srand(x) srandom(x) 30 | #define L_RANDMAX 2147483647 /* (2^31 - 1), following POSIX */ 31 | #else 32 | #define l_rand() rand() 33 | #define l_srand(x) srand(x) 34 | #define L_RANDMAX RAND_MAX 35 | #endif 36 | #endif /* } */ 37 | 38 | 39 | static int math_abs (lua_State *L) { 40 | if (lua_isinteger(L, 1)) { 41 | lua_Integer n = lua_tointeger(L, 1); 42 | if (n < 0) n = (lua_Integer)(0u - (lua_Unsigned)n); 43 | lua_pushinteger(L, n); 44 | } 45 | else 46 | lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1))); 47 | return 1; 48 | } 49 | 50 | static int math_sin (lua_State *L) { 51 | lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1))); 52 | return 1; 53 | } 54 | 55 | static int math_cos (lua_State *L) { 56 | lua_pushnumber(L, l_mathop(cos)(luaL_checknumber(L, 1))); 57 | return 1; 58 | } 59 | 60 | static int math_tan (lua_State *L) { 61 | lua_pushnumber(L, l_mathop(tan)(luaL_checknumber(L, 1))); 62 | return 1; 63 | } 64 | 65 | static int math_asin (lua_State *L) { 66 | lua_pushnumber(L, l_mathop(asin)(luaL_checknumber(L, 1))); 67 | return 1; 68 | } 69 | 70 | static int math_acos (lua_State *L) { 71 | lua_pushnumber(L, l_mathop(acos)(luaL_checknumber(L, 1))); 72 | return 1; 73 | } 74 | 75 | static int math_atan (lua_State *L) { 76 | lua_Number y = luaL_checknumber(L, 1); 77 | lua_Number x = luaL_optnumber(L, 2, 1); 78 | lua_pushnumber(L, l_mathop(atan2)(y, x)); 79 | return 1; 80 | } 81 | 82 | 83 | static int math_toint (lua_State *L) { 84 | int valid; 85 | lua_Integer n = lua_tointegerx(L, 1, &valid); 86 | if (valid) 87 | lua_pushinteger(L, n); 88 | else { 89 | luaL_checkany(L, 1); 90 | lua_pushnil(L); /* value is not convertible to integer */ 91 | } 92 | return 1; 93 | } 94 | 95 | 96 | static void pushnumint (lua_State *L, lua_Number d) { 97 | lua_Integer n; 98 | if (lua_numbertointeger(d, &n)) /* does 'd' fit in an integer? */ 99 | lua_pushinteger(L, n); /* result is integer */ 100 | else 101 | lua_pushnumber(L, d); /* result is float */ 102 | } 103 | 104 | 105 | static int math_floor (lua_State *L) { 106 | if (lua_isinteger(L, 1)) 107 | lua_settop(L, 1); /* integer is its own floor */ 108 | else { 109 | lua_Number d = l_mathop(floor)(luaL_checknumber(L, 1)); 110 | pushnumint(L, d); 111 | } 112 | return 1; 113 | } 114 | 115 | 116 | static int math_ceil (lua_State *L) { 117 | if (lua_isinteger(L, 1)) 118 | lua_settop(L, 1); /* integer is its own ceil */ 119 | else { 120 | lua_Number d = l_mathop(ceil)(luaL_checknumber(L, 1)); 121 | pushnumint(L, d); 122 | } 123 | return 1; 124 | } 125 | 126 | 127 | static int math_fmod (lua_State *L) { 128 | if (lua_isinteger(L, 1) && lua_isinteger(L, 2)) { 129 | lua_Integer d = lua_tointeger(L, 2); 130 | if ((lua_Unsigned)d + 1u <= 1u) { /* special cases: -1 or 0 */ 131 | luaL_argcheck(L, d != 0, 2, "zero"); 132 | lua_pushinteger(L, 0); /* avoid overflow with 0x80000... / -1 */ 133 | } 134 | else 135 | lua_pushinteger(L, lua_tointeger(L, 1) % d); 136 | } 137 | else 138 | lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1), 139 | luaL_checknumber(L, 2))); 140 | return 1; 141 | } 142 | 143 | 144 | /* 145 | ** next function does not use 'modf', avoiding problems with 'double*' 146 | ** (which is not compatible with 'float*') when lua_Number is not 147 | ** 'double'. 148 | */ 149 | static int math_modf (lua_State *L) { 150 | if (lua_isinteger(L ,1)) { 151 | lua_settop(L, 1); /* number is its own integer part */ 152 | lua_pushnumber(L, 0); /* no fractional part */ 153 | } 154 | else { 155 | lua_Number n = luaL_checknumber(L, 1); 156 | /* integer part (rounds toward zero) */ 157 | lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n); 158 | pushnumint(L, ip); 159 | /* fractional part (test needed for inf/-inf) */ 160 | lua_pushnumber(L, (n == ip) ? l_mathop(0.0) : (n - ip)); 161 | } 162 | return 2; 163 | } 164 | 165 | 166 | static int math_sqrt (lua_State *L) { 167 | lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1))); 168 | return 1; 169 | } 170 | 171 | 172 | static int math_ult (lua_State *L) { 173 | lua_Integer a = luaL_checkinteger(L, 1); 174 | lua_Integer b = luaL_checkinteger(L, 2); 175 | lua_pushboolean(L, (lua_Unsigned)a < (lua_Unsigned)b); 176 | return 1; 177 | } 178 | 179 | static int math_log (lua_State *L) { 180 | lua_Number x = luaL_checknumber(L, 1); 181 | lua_Number res; 182 | if (lua_isnoneornil(L, 2)) 183 | res = l_mathop(log)(x); 184 | else { 185 | lua_Number base = luaL_checknumber(L, 2); 186 | #if !defined(LUA_USE_C89) 187 | if (base == 2.0) res = l_mathop(log2)(x); else 188 | #endif 189 | if (base == 10.0) res = l_mathop(log10)(x); 190 | else res = l_mathop(log)(x)/l_mathop(log)(base); 191 | } 192 | lua_pushnumber(L, res); 193 | return 1; 194 | } 195 | 196 | static int math_exp (lua_State *L) { 197 | lua_pushnumber(L, l_mathop(exp)(luaL_checknumber(L, 1))); 198 | return 1; 199 | } 200 | 201 | static int math_deg (lua_State *L) { 202 | lua_pushnumber(L, luaL_checknumber(L, 1) * (l_mathop(180.0) / PI)); 203 | return 1; 204 | } 205 | 206 | static int math_rad (lua_State *L) { 207 | lua_pushnumber(L, luaL_checknumber(L, 1) * (PI / l_mathop(180.0))); 208 | return 1; 209 | } 210 | 211 | 212 | static int math_min (lua_State *L) { 213 | int n = lua_gettop(L); /* number of arguments */ 214 | int imin = 1; /* index of current minimum value */ 215 | int i; 216 | luaL_argcheck(L, n >= 1, 1, "value expected"); 217 | for (i = 2; i <= n; i++) { 218 | if (lua_compare(L, i, imin, LUA_OPLT)) 219 | imin = i; 220 | } 221 | lua_pushvalue(L, imin); 222 | return 1; 223 | } 224 | 225 | 226 | static int math_max (lua_State *L) { 227 | int n = lua_gettop(L); /* number of arguments */ 228 | int imax = 1; /* index of current maximum value */ 229 | int i; 230 | luaL_argcheck(L, n >= 1, 1, "value expected"); 231 | for (i = 2; i <= n; i++) { 232 | if (lua_compare(L, imax, i, LUA_OPLT)) 233 | imax = i; 234 | } 235 | lua_pushvalue(L, imax); 236 | return 1; 237 | } 238 | 239 | /* 240 | ** This function uses 'double' (instead of 'lua_Number') to ensure that 241 | ** all bits from 'l_rand' can be represented, and that 'RANDMAX + 1.0' 242 | ** will keep full precision (ensuring that 'r' is always less than 1.0.) 243 | */ 244 | static int math_random (lua_State *L) { 245 | lua_Integer low, up; 246 | double r = (double)l_rand() * (1.0 / ((double)L_RANDMAX + 1.0)); 247 | switch (lua_gettop(L)) { /* check number of arguments */ 248 | case 0: { /* no arguments */ 249 | lua_pushnumber(L, (lua_Number)r); /* Number between 0 and 1 */ 250 | return 1; 251 | } 252 | case 1: { /* only upper limit */ 253 | low = 1; 254 | up = luaL_checkinteger(L, 1); 255 | break; 256 | } 257 | case 2: { /* lower and upper limits */ 258 | low = luaL_checkinteger(L, 1); 259 | up = luaL_checkinteger(L, 2); 260 | break; 261 | } 262 | default: return luaL_error(L, "wrong number of arguments"); 263 | } 264 | /* random integer in the interval [low, up] */ 265 | luaL_argcheck(L, low <= up, 1, "interval is empty"); 266 | luaL_argcheck(L, low >= 0 || up <= LUA_MAXINTEGER + low, 1, 267 | "interval too large"); 268 | r *= (double)(up - low) + 1.0; 269 | lua_pushinteger(L, (lua_Integer)r + low); 270 | return 1; 271 | } 272 | 273 | 274 | static int math_randomseed (lua_State *L) { 275 | l_srand((unsigned int)(lua_Integer)luaL_checknumber(L, 1)); 276 | (void)l_rand(); /* discard first value to avoid undesirable correlations */ 277 | return 0; 278 | } 279 | 280 | 281 | static int math_type (lua_State *L) { 282 | if (lua_type(L, 1) == LUA_TNUMBER) { 283 | if (lua_isinteger(L, 1)) 284 | lua_pushliteral(L, "integer"); 285 | else 286 | lua_pushliteral(L, "float"); 287 | } 288 | else { 289 | luaL_checkany(L, 1); 290 | lua_pushnil(L); 291 | } 292 | return 1; 293 | } 294 | 295 | 296 | /* 297 | ** {================================================================== 298 | ** Deprecated functions (for compatibility only) 299 | ** =================================================================== 300 | */ 301 | #if defined(LUA_COMPAT_MATHLIB) 302 | 303 | static int math_cosh (lua_State *L) { 304 | lua_pushnumber(L, l_mathop(cosh)(luaL_checknumber(L, 1))); 305 | return 1; 306 | } 307 | 308 | static int math_sinh (lua_State *L) { 309 | lua_pushnumber(L, l_mathop(sinh)(luaL_checknumber(L, 1))); 310 | return 1; 311 | } 312 | 313 | static int math_tanh (lua_State *L) { 314 | lua_pushnumber(L, l_mathop(tanh)(luaL_checknumber(L, 1))); 315 | return 1; 316 | } 317 | 318 | static int math_pow (lua_State *L) { 319 | lua_Number x = luaL_checknumber(L, 1); 320 | lua_Number y = luaL_checknumber(L, 2); 321 | lua_pushnumber(L, l_mathop(pow)(x, y)); 322 | return 1; 323 | } 324 | 325 | static int math_frexp (lua_State *L) { 326 | int e; 327 | lua_pushnumber(L, l_mathop(frexp)(luaL_checknumber(L, 1), &e)); 328 | lua_pushinteger(L, e); 329 | return 2; 330 | } 331 | 332 | static int math_ldexp (lua_State *L) { 333 | lua_Number x = luaL_checknumber(L, 1); 334 | int ep = (int)luaL_checkinteger(L, 2); 335 | lua_pushnumber(L, l_mathop(ldexp)(x, ep)); 336 | return 1; 337 | } 338 | 339 | static int math_log10 (lua_State *L) { 340 | lua_pushnumber(L, l_mathop(log10)(luaL_checknumber(L, 1))); 341 | return 1; 342 | } 343 | 344 | #endif 345 | /* }================================================================== */ 346 | 347 | 348 | 349 | static const luaL_Reg mathlib[] = { 350 | {"abs", math_abs}, 351 | {"acos", math_acos}, 352 | {"asin", math_asin}, 353 | {"atan", math_atan}, 354 | {"ceil", math_ceil}, 355 | {"cos", math_cos}, 356 | {"deg", math_deg}, 357 | {"exp", math_exp}, 358 | {"tointeger", math_toint}, 359 | {"floor", math_floor}, 360 | {"fmod", math_fmod}, 361 | {"ult", math_ult}, 362 | {"log", math_log}, 363 | {"max", math_max}, 364 | {"min", math_min}, 365 | {"modf", math_modf}, 366 | {"rad", math_rad}, 367 | {"random", math_random}, 368 | {"randomseed", math_randomseed}, 369 | {"sin", math_sin}, 370 | {"sqrt", math_sqrt}, 371 | {"tan", math_tan}, 372 | {"type", math_type}, 373 | #if defined(LUA_COMPAT_MATHLIB) 374 | {"atan2", math_atan}, 375 | {"cosh", math_cosh}, 376 | {"sinh", math_sinh}, 377 | {"tanh", math_tanh}, 378 | {"pow", math_pow}, 379 | {"frexp", math_frexp}, 380 | {"ldexp", math_ldexp}, 381 | {"log10", math_log10}, 382 | #endif 383 | /* placeholders */ 384 | {"pi", NULL}, 385 | {"huge", NULL}, 386 | {"maxinteger", NULL}, 387 | {"mininteger", NULL}, 388 | {NULL, NULL} 389 | }; 390 | 391 | 392 | /* 393 | ** Open math library 394 | */ 395 | LUAMOD_API int luaopen_math (lua_State *L) { 396 | luaL_newlib(L, mathlib); 397 | lua_pushnumber(L, PI); 398 | lua_setfield(L, -2, "pi"); 399 | lua_pushnumber(L, (lua_Number)HUGE_VAL); 400 | lua_setfield(L, -2, "huge"); 401 | lua_pushinteger(L, LUA_MAXINTEGER); 402 | lua_setfield(L, -2, "maxinteger"); 403 | lua_pushinteger(L, LUA_MININTEGER); 404 | lua_setfield(L, -2, "mininteger"); 405 | return 1; 406 | } 407 | 408 | -------------------------------------------------------------------------------- /luadbg/lua_src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.91 2015/03/06 19:45:54 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lmem_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lgc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstate.h" 23 | 24 | 25 | 26 | /* 27 | ** About the realloc function: 28 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 29 | ** ('osize' is the old size, 'nsize' is the new size) 30 | ** 31 | ** * frealloc(ud, NULL, x, s) creates a new block of size 's' (no 32 | ** matter 'x'). 33 | ** 34 | ** * frealloc(ud, p, x, 0) frees the block 'p' 35 | ** (in this specific case, frealloc must return NULL); 36 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 37 | ** (which is equivalent to free(NULL) in ISO C) 38 | ** 39 | ** frealloc returns NULL if it cannot create or reallocate the area 40 | ** (any reallocation to an equal or smaller size cannot fail!) 41 | */ 42 | 43 | 44 | 45 | #define MINSIZEARRAY 4 46 | 47 | 48 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 49 | int limit, const char *what) { 50 | void *newblock; 51 | int newsize; 52 | if (*size >= limit/2) { /* cannot double it? */ 53 | if (*size >= limit) /* cannot grow even a little? */ 54 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); 55 | newsize = limit; /* still have at least one free place */ 56 | } 57 | else { 58 | newsize = (*size)*2; 59 | if (newsize < MINSIZEARRAY) 60 | newsize = MINSIZEARRAY; /* minimum size */ 61 | } 62 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 63 | *size = newsize; /* update only when everything else is OK */ 64 | return newblock; 65 | } 66 | 67 | 68 | l_noret luaM_toobig (lua_State *L) { 69 | luaG_runerror(L, "memory allocation error: block too big"); 70 | } 71 | 72 | 73 | 74 | /* 75 | ** generic allocation routine. 76 | */ 77 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 78 | void *newblock; 79 | global_State *g = G(L); 80 | size_t realosize = (block) ? osize : 0; 81 | lua_assert((realosize == 0) == (block == NULL)); 82 | #if defined(HARDMEMTESTS) 83 | if (nsize > realosize && g->gcrunning) 84 | luaC_fullgc(L, 1); /* force a GC whenever possible */ 85 | #endif 86 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); 87 | if (newblock == NULL && nsize > 0) { 88 | lua_assert(nsize > realosize); /* cannot fail when shrinking a block */ 89 | if (g->version) { /* is state fully built? */ 90 | luaC_fullgc(L, 1); /* try to free some memory... */ 91 | newblock = (*g->frealloc)(g->ud, block, osize, nsize); /* try again */ 92 | } 93 | if (newblock == NULL) 94 | luaD_throw(L, LUA_ERRMEM); 95 | } 96 | lua_assert((nsize == 0) == (newblock == NULL)); 97 | g->GCdebt = (g->GCdebt + nsize) - realosize; 98 | return newblock; 99 | } 100 | 101 | -------------------------------------------------------------------------------- /luadbg/lua_src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.43 2014/12/19 17:26:14 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | /* 18 | ** This macro reallocs a vector 'b' from 'on' to 'n' elements, where 19 | ** each element has size 'e'. In case of arithmetic overflow of the 20 | ** product 'n'*'e', it raises an error (calling 'luaM_toobig'). Because 21 | ** 'e' is always constant, it avoids the runtime division MAX_SIZET/(e). 22 | ** 23 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 24 | ** comparison avoids a runtime comparison when overflow cannot occur. 25 | ** The compiler should be able to optimize the real test by itself, but 26 | ** when it does it, it may give a warning about "comparison is always 27 | ** false due to limited range of data type"; the +1 tricks the compiler, 28 | ** avoiding this warning but also this optimization.) 29 | */ 30 | #define luaM_reallocv(L,b,on,n,e) \ 31 | (((sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) \ 32 | ? luaM_toobig(L) : cast_void(0)) , \ 33 | luaM_realloc_(L, (b), (on)*(e), (n)*(e))) 34 | 35 | /* 36 | ** Arrays of chars do not need any test 37 | */ 38 | #define luaM_reallocvchar(L,b,on,n) \ 39 | cast(char *, luaM_realloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 40 | 41 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 42 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 43 | #define luaM_freearray(L, b, n) luaM_realloc_(L, (b), (n)*sizeof(*(b)), 0) 44 | 45 | #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s)) 46 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 47 | #define luaM_newvector(L,n,t) \ 48 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 49 | 50 | #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s)) 51 | 52 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 53 | if ((nelems)+1 > (size)) \ 54 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 55 | 56 | #define luaM_reallocvector(L, v,oldn,n,t) \ 57 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 58 | 59 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 60 | 61 | /* not to be called directly */ 62 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 63 | size_t size); 64 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 65 | size_t size_elem, int limit, 66 | const char *what); 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /luadbg/lua_src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.55 2015/01/05 13:48:33 roberto Exp $ 3 | ** Opcodes for Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lopcodes.h" 16 | 17 | 18 | /* ORDER OP */ 19 | 20 | LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { 21 | "MOVE", 22 | "LOADK", 23 | "LOADKX", 24 | "LOADBOOL", 25 | "LOADNIL", 26 | "GETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "SETTABUP", 30 | "SETUPVAL", 31 | "SETTABLE", 32 | "NEWTABLE", 33 | "SELF", 34 | "ADD", 35 | "SUB", 36 | "MUL", 37 | "MOD", 38 | "POW", 39 | "DIV", 40 | "IDIV", 41 | "BAND", 42 | "BOR", 43 | "BXOR", 44 | "SHL", 45 | "SHR", 46 | "UNM", 47 | "BNOT", 48 | "NOT", 49 | "LEN", 50 | "CONCAT", 51 | "JMP", 52 | "EQ", 53 | "LT", 54 | "LE", 55 | "TEST", 56 | "TESTSET", 57 | "CALL", 58 | "TAILCALL", 59 | "RETURN", 60 | "FORLOOP", 61 | "FORPREP", 62 | "TFORCALL", 63 | "TFORLOOP", 64 | "SETLIST", 65 | "CLOSURE", 66 | "VARARG", 67 | "EXTRAARG", 68 | NULL 69 | }; 70 | 71 | 72 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 73 | 74 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 75 | /* T A B C mode opcode */ 76 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 77 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 78 | ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ 79 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 80 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ 81 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 82 | ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ 83 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 84 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABUP */ 85 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 86 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 87 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 88 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 89 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 90 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 91 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 92 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 93 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 94 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 95 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_IDIV */ 96 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BAND */ 97 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BOR */ 98 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_BXOR */ 99 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHL */ 100 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SHR */ 101 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 102 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_BNOT */ 103 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 104 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 105 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 106 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 107 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 108 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 109 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 110 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TEST */ 111 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 112 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 113 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 114 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 115 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 116 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 117 | ,opmode(0, 0, OpArgN, OpArgU, iABC) /* OP_TFORCALL */ 118 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_TFORLOOP */ 119 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 120 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 121 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 122 | ,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */ 123 | }; 124 | 125 | -------------------------------------------------------------------------------- /luadbg/lua_src/lopcodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.h,v 1.148 2014/10/25 11:50:46 roberto Exp $ 3 | ** Opcodes for Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lopcodes_h 8 | #define lopcodes_h 9 | 10 | #include "llimits.h" 11 | 12 | 13 | /*=========================================================================== 14 | We assume that instructions are unsigned numbers. 15 | All instructions have an opcode in the first 6 bits. 16 | Instructions can have the following fields: 17 | 'A' : 8 bits 18 | 'B' : 9 bits 19 | 'C' : 9 bits 20 | 'Ax' : 26 bits ('A', 'B', and 'C' together) 21 | 'Bx' : 18 bits ('B' and 'C' together) 22 | 'sBx' : signed Bx 23 | 24 | A signed argument is represented in excess K; that is, the number 25 | value is the unsigned value minus K. K is exactly the maximum value 26 | for that argument (so that -max is represented by 0, and +max is 27 | represented by 2*max), which is half the maximum for the corresponding 28 | unsigned argument. 29 | ===========================================================================*/ 30 | 31 | 32 | enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ 33 | 34 | 35 | /* 36 | ** size and position of opcode arguments. 37 | */ 38 | #define SIZE_C 9 39 | #define SIZE_B 9 40 | #define SIZE_Bx (SIZE_C + SIZE_B) 41 | #define SIZE_A 8 42 | #define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A) 43 | 44 | #define SIZE_OP 6 45 | 46 | #define POS_OP 0 47 | #define POS_A (POS_OP + SIZE_OP) 48 | #define POS_C (POS_A + SIZE_A) 49 | #define POS_B (POS_C + SIZE_C) 50 | #define POS_Bx POS_C 51 | #define POS_Ax POS_A 52 | 53 | 54 | /* 55 | ** limits for opcode arguments. 56 | ** we use (signed) int to manipulate most arguments, 57 | ** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) 58 | */ 59 | #if SIZE_Bx < LUAI_BITSINT-1 60 | #define MAXARG_Bx ((1<>1) /* 'sBx' is signed */ 62 | #else 63 | #define MAXARG_Bx MAX_INT 64 | #define MAXARG_sBx MAX_INT 65 | #endif 66 | 67 | #if SIZE_Ax < LUAI_BITSINT-1 68 | #define MAXARG_Ax ((1<>POS_OP) & MASK1(SIZE_OP,0))) 90 | #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ 91 | ((cast(Instruction, o)<>pos) & MASK1(size,0))) 94 | #define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \ 95 | ((cast(Instruction, v)<> RK(C) */ 199 | OP_UNM,/* A B R(A) := -R(B) */ 200 | OP_BNOT,/* A B R(A) := ~R(B) */ 201 | OP_NOT,/* A B R(A) := not R(B) */ 202 | OP_LEN,/* A B R(A) := length of R(B) */ 203 | 204 | OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ 205 | 206 | OP_JMP,/* A sBx pc+=sBx; if (A) close all upvalues >= R(A - 1) */ 207 | OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */ 208 | OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */ 209 | OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */ 210 | 211 | OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ 212 | OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ 213 | 214 | OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ 215 | OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ 216 | OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ 217 | 218 | OP_FORLOOP,/* A sBx R(A)+=R(A+2); 219 | if R(A) > 4) & 3)) 283 | #define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) 284 | #define testAMode(m) (luaP_opmodes[m] & (1 << 6)) 285 | #define testTMode(m) (luaP_opmodes[m] & (1 << 7)) 286 | 287 | 288 | LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ 289 | 290 | 291 | /* number of list items to accumulate before a SETLIST instruction */ 292 | #define LFIELDS_PER_FLUSH 50 293 | 294 | 295 | #endif 296 | -------------------------------------------------------------------------------- /luadbg/lua_src/loslib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: loslib.c,v 1.64 2016/04/18 13:06:55 roberto Exp $ 3 | ** Standard Operating System library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define loslib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "lua.h" 20 | 21 | #include "lauxlib.h" 22 | #include "lualib.h" 23 | 24 | 25 | /* 26 | ** {================================================================== 27 | ** List of valid conversion specifiers for the 'strftime' function; 28 | ** options are grouped by length; group of length 2 start with '||'. 29 | ** =================================================================== 30 | */ 31 | #if !defined(LUA_STRFTIMEOPTIONS) /* { */ 32 | 33 | /* options for ANSI C 89 */ 34 | #define L_STRFTIMEC89 "aAbBcdHIjmMpSUwWxXyYZ%" 35 | 36 | /* options for ISO C 99 and POSIX */ 37 | #define L_STRFTIMEC99 "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%" \ 38 | "||" "EcECExEXEyEY" "OdOeOHOIOmOMOSOuOUOVOwOWOy" 39 | 40 | /* options for Windows */ 41 | #define L_STRFTIMEWIN "aAbBcdHIjmMpSUwWxXyYzZ%" \ 42 | "||" "#c#x#d#H#I#j#m#M#S#U#w#W#y#Y" 43 | 44 | #if defined(LUA_USE_WINDOWS) 45 | #define LUA_STRFTIMEOPTIONS L_STRFTIMEWIN 46 | #elif defined(LUA_USE_C89) 47 | #define LUA_STRFTIMEOPTIONS L_STRFTIMEC89 48 | #else /* C99 specification */ 49 | #define LUA_STRFTIMEOPTIONS L_STRFTIMEC99 50 | #endif 51 | 52 | #endif /* } */ 53 | /* }================================================================== */ 54 | 55 | 56 | /* 57 | ** {================================================================== 58 | ** Configuration for time-related stuff 59 | ** =================================================================== 60 | */ 61 | 62 | #if !defined(l_time_t) /* { */ 63 | /* 64 | ** type to represent time_t in Lua 65 | */ 66 | #define l_timet lua_Integer 67 | #define l_pushtime(L,t) lua_pushinteger(L,(lua_Integer)(t)) 68 | 69 | static time_t l_checktime (lua_State *L, int arg) { 70 | lua_Integer t = luaL_checkinteger(L, arg); 71 | luaL_argcheck(L, (time_t)t == t, arg, "time out-of-bounds"); 72 | return (time_t)t; 73 | } 74 | 75 | #endif /* } */ 76 | 77 | 78 | #if !defined(l_gmtime) /* { */ 79 | /* 80 | ** By default, Lua uses gmtime/localtime, except when POSIX is available, 81 | ** where it uses gmtime_r/localtime_r 82 | */ 83 | 84 | #if defined(LUA_USE_POSIX) /* { */ 85 | 86 | #define l_gmtime(t,r) gmtime_r(t,r) 87 | #define l_localtime(t,r) localtime_r(t,r) 88 | 89 | #else /* }{ */ 90 | 91 | /* ISO C definitions */ 92 | #define l_gmtime(t,r) ((void)(r)->tm_sec, gmtime(t)) 93 | #define l_localtime(t,r) ((void)(r)->tm_sec, localtime(t)) 94 | 95 | #endif /* } */ 96 | 97 | #endif /* } */ 98 | 99 | /* }================================================================== */ 100 | 101 | 102 | /* 103 | ** {================================================================== 104 | ** Configuration for 'tmpnam': 105 | ** By default, Lua uses tmpnam except when POSIX is available, where 106 | ** it uses mkstemp. 107 | ** =================================================================== 108 | */ 109 | #if !defined(lua_tmpnam) /* { */ 110 | 111 | #if defined(LUA_USE_POSIX) /* { */ 112 | 113 | #include 114 | 115 | #define LUA_TMPNAMBUFSIZE 32 116 | 117 | #if !defined(LUA_TMPNAMTEMPLATE) 118 | #define LUA_TMPNAMTEMPLATE "/tmp/lua_XXXXXX" 119 | #endif 120 | 121 | #define lua_tmpnam(b,e) { \ 122 | strcpy(b, LUA_TMPNAMTEMPLATE); \ 123 | e = mkstemp(b); \ 124 | if (e != -1) close(e); \ 125 | e = (e == -1); } 126 | 127 | #else /* }{ */ 128 | 129 | /* ISO C definitions */ 130 | #define LUA_TMPNAMBUFSIZE L_tmpnam 131 | #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } 132 | 133 | #endif /* } */ 134 | 135 | #endif /* } */ 136 | /* }================================================================== */ 137 | 138 | 139 | 140 | 141 | static int os_execute (lua_State *L) { 142 | const char *cmd = luaL_optstring(L, 1, NULL); 143 | int stat = system(cmd); 144 | if (cmd != NULL) 145 | return luaL_execresult(L, stat); 146 | else { 147 | lua_pushboolean(L, stat); /* true if there is a shell */ 148 | return 1; 149 | } 150 | } 151 | 152 | 153 | static int os_remove (lua_State *L) { 154 | const char *filename = luaL_checkstring(L, 1); 155 | return luaL_fileresult(L, remove(filename) == 0, filename); 156 | } 157 | 158 | 159 | static int os_rename (lua_State *L) { 160 | const char *fromname = luaL_checkstring(L, 1); 161 | const char *toname = luaL_checkstring(L, 2); 162 | return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); 163 | } 164 | 165 | 166 | static int os_tmpname (lua_State *L) { 167 | char buff[LUA_TMPNAMBUFSIZE]; 168 | int err; 169 | lua_tmpnam(buff, err); 170 | if (err) 171 | return luaL_error(L, "unable to generate a unique filename"); 172 | lua_pushstring(L, buff); 173 | return 1; 174 | } 175 | 176 | 177 | static int os_getenv (lua_State *L) { 178 | lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */ 179 | return 1; 180 | } 181 | 182 | 183 | static int os_clock (lua_State *L) { 184 | lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); 185 | return 1; 186 | } 187 | 188 | 189 | /* 190 | ** {====================================================== 191 | ** Time/Date operations 192 | ** { year=%Y, month=%m, day=%d, hour=%H, min=%M, sec=%S, 193 | ** wday=%w+1, yday=%j, isdst=? } 194 | ** ======================================================= 195 | */ 196 | 197 | static void setfield (lua_State *L, const char *key, int value) { 198 | lua_pushinteger(L, value); 199 | lua_setfield(L, -2, key); 200 | } 201 | 202 | static void setboolfield (lua_State *L, const char *key, int value) { 203 | if (value < 0) /* undefined? */ 204 | return; /* does not set field */ 205 | lua_pushboolean(L, value); 206 | lua_setfield(L, -2, key); 207 | } 208 | 209 | 210 | /* 211 | ** Set all fields from structure 'tm' in the table on top of the stack 212 | */ 213 | static void setallfields (lua_State *L, struct tm *stm) { 214 | setfield(L, "sec", stm->tm_sec); 215 | setfield(L, "min", stm->tm_min); 216 | setfield(L, "hour", stm->tm_hour); 217 | setfield(L, "day", stm->tm_mday); 218 | setfield(L, "month", stm->tm_mon + 1); 219 | setfield(L, "year", stm->tm_year + 1900); 220 | setfield(L, "wday", stm->tm_wday + 1); 221 | setfield(L, "yday", stm->tm_yday + 1); 222 | setboolfield(L, "isdst", stm->tm_isdst); 223 | } 224 | 225 | 226 | static int getboolfield (lua_State *L, const char *key) { 227 | int res; 228 | res = (lua_getfield(L, -1, key) == LUA_TNIL) ? -1 : lua_toboolean(L, -1); 229 | lua_pop(L, 1); 230 | return res; 231 | } 232 | 233 | 234 | /* maximum value for date fields (to avoid arithmetic overflows with 'int') */ 235 | #if !defined(L_MAXDATEFIELD) 236 | #define L_MAXDATEFIELD (INT_MAX / 2) 237 | #endif 238 | 239 | static int getfield (lua_State *L, const char *key, int d, int delta) { 240 | int isnum; 241 | int t = lua_getfield(L, -1, key); /* get field and its type */ 242 | lua_Integer res = lua_tointegerx(L, -1, &isnum); 243 | if (!isnum) { /* field is not an integer? */ 244 | if (t != LUA_TNIL) /* some other value? */ 245 | return luaL_error(L, "field '%s' is not an integer", key); 246 | else if (d < 0) /* absent field; no default? */ 247 | return luaL_error(L, "field '%s' missing in date table", key); 248 | res = d; 249 | } 250 | else { 251 | if (!(-L_MAXDATEFIELD <= res && res <= L_MAXDATEFIELD)) 252 | return luaL_error(L, "field '%s' is out-of-bound", key); 253 | res -= delta; 254 | } 255 | lua_pop(L, 1); 256 | return (int)res; 257 | } 258 | 259 | 260 | static const char *checkoption (lua_State *L, const char *conv, char *buff) { 261 | const char *option; 262 | int oplen = 1; 263 | for (option = LUA_STRFTIMEOPTIONS; *option != '\0'; option += oplen) { 264 | if (*option == '|') /* next block? */ 265 | oplen++; /* next length */ 266 | else if (memcmp(conv, option, oplen) == 0) { /* match? */ 267 | memcpy(buff, conv, oplen); /* copy valid option to buffer */ 268 | buff[oplen] = '\0'; 269 | return conv + oplen; /* return next item */ 270 | } 271 | } 272 | luaL_argerror(L, 1, 273 | lua_pushfstring(L, "invalid conversion specifier '%%%s'", conv)); 274 | return conv; /* to avoid warnings */ 275 | } 276 | 277 | 278 | /* maximum size for an individual 'strftime' item */ 279 | #define SIZETIMEFMT 250 280 | 281 | 282 | static int os_date (lua_State *L) { 283 | const char *s = luaL_optstring(L, 1, "%c"); 284 | time_t t = luaL_opt(L, l_checktime, 2, time(NULL)); 285 | struct tm tmr, *stm; 286 | if (*s == '!') { /* UTC? */ 287 | stm = l_gmtime(&t, &tmr); 288 | s++; /* skip '!' */ 289 | } 290 | else 291 | stm = l_localtime(&t, &tmr); 292 | if (stm == NULL) /* invalid date? */ 293 | luaL_error(L, "time result cannot be represented in this installation"); 294 | if (strcmp(s, "*t") == 0) { 295 | lua_createtable(L, 0, 9); /* 9 = number of fields */ 296 | setallfields(L, stm); 297 | } 298 | else { 299 | char cc[4]; /* buffer for individual conversion specifiers */ 300 | luaL_Buffer b; 301 | cc[0] = '%'; 302 | luaL_buffinit(L, &b); 303 | while (*s) { 304 | if (*s != '%') /* not a conversion specifier? */ 305 | luaL_addchar(&b, *s++); 306 | else { 307 | size_t reslen; 308 | char *buff = luaL_prepbuffsize(&b, SIZETIMEFMT); 309 | s = checkoption(L, s + 1, cc + 1); /* copy specifier to 'cc' */ 310 | reslen = strftime(buff, SIZETIMEFMT, cc, stm); 311 | luaL_addsize(&b, reslen); 312 | } 313 | } 314 | luaL_pushresult(&b); 315 | } 316 | return 1; 317 | } 318 | 319 | 320 | static int os_time (lua_State *L) { 321 | time_t t; 322 | if (lua_isnoneornil(L, 1)) /* called without args? */ 323 | t = time(NULL); /* get current time */ 324 | else { 325 | struct tm ts; 326 | luaL_checktype(L, 1, LUA_TTABLE); 327 | lua_settop(L, 1); /* make sure table is at the top */ 328 | ts.tm_sec = getfield(L, "sec", 0, 0); 329 | ts.tm_min = getfield(L, "min", 0, 0); 330 | ts.tm_hour = getfield(L, "hour", 12, 0); 331 | ts.tm_mday = getfield(L, "day", -1, 0); 332 | ts.tm_mon = getfield(L, "month", -1, 1); 333 | ts.tm_year = getfield(L, "year", -1, 1900); 334 | ts.tm_isdst = getboolfield(L, "isdst"); 335 | t = mktime(&ts); 336 | setallfields(L, &ts); /* update fields with normalized values */ 337 | } 338 | if (t != (time_t)(l_timet)t || t == (time_t)(-1)) 339 | luaL_error(L, "time result cannot be represented in this installation"); 340 | l_pushtime(L, t); 341 | return 1; 342 | } 343 | 344 | 345 | static int os_difftime (lua_State *L) { 346 | time_t t1 = l_checktime(L, 1); 347 | time_t t2 = l_checktime(L, 2); 348 | lua_pushnumber(L, (lua_Number)difftime(t1, t2)); 349 | return 1; 350 | } 351 | 352 | /* }====================================================== */ 353 | 354 | 355 | static int os_setlocale (lua_State *L) { 356 | static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, 357 | LC_NUMERIC, LC_TIME}; 358 | static const char *const catnames[] = {"all", "collate", "ctype", "monetary", 359 | "numeric", "time", NULL}; 360 | const char *l = luaL_optstring(L, 1, NULL); 361 | int op = luaL_checkoption(L, 2, "all", catnames); 362 | lua_pushstring(L, setlocale(cat[op], l)); 363 | return 1; 364 | } 365 | 366 | 367 | static int os_exit (lua_State *L) { 368 | int status; 369 | if (lua_isboolean(L, 1)) 370 | status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE); 371 | else 372 | status = (int)luaL_optinteger(L, 1, EXIT_SUCCESS); 373 | if (lua_toboolean(L, 2)) 374 | lua_close(L); 375 | if (L) exit(status); /* 'if' to avoid warnings for unreachable 'return' */ 376 | return 0; 377 | } 378 | 379 | 380 | static const luaL_Reg syslib[] = { 381 | {"clock", os_clock}, 382 | {"date", os_date}, 383 | {"difftime", os_difftime}, 384 | {"execute", os_execute}, 385 | {"exit", os_exit}, 386 | {"getenv", os_getenv}, 387 | {"remove", os_remove}, 388 | {"rename", os_rename}, 389 | {"setlocale", os_setlocale}, 390 | {"time", os_time}, 391 | {"tmpname", os_tmpname}, 392 | {NULL, NULL} 393 | }; 394 | 395 | /* }====================================================== */ 396 | 397 | 398 | 399 | LUAMOD_API int luaopen_os (lua_State *L) { 400 | luaL_newlib(L, syslib); 401 | return 1; 402 | } 403 | 404 | -------------------------------------------------------------------------------- /luadbg/lua_src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.76 2015/12/30 18:16:13 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression and variable descriptor. 17 | ** Code generation for variables and expressions can be delayed to allow 18 | ** optimizations; An 'expdesc' structure describes a potentially-delayed 19 | ** variable/expression. It has a description of its "main" value plus a 20 | ** list of conditional jumps that can also produce its value (generated 21 | ** by short-circuit operators 'and'/'or'). 22 | */ 23 | 24 | /* kinds of variables/expressions */ 25 | typedef enum { 26 | VVOID, /* when 'expdesc' describes the last expression a list, 27 | this kind means an empty list (so, no expression) */ 28 | VNIL, /* constant nil */ 29 | VTRUE, /* constant true */ 30 | VFALSE, /* constant false */ 31 | VK, /* constant in 'k'; info = index of constant in 'k' */ 32 | VKFLT, /* floating constant; nval = numerical float value */ 33 | VKINT, /* integer constant; nval = numerical integer value */ 34 | VNONRELOC, /* expression has its value in a fixed register; 35 | info = result register */ 36 | VLOCAL, /* local variable; info = local register */ 37 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ 38 | VINDEXED, /* indexed variable; 39 | ind.vt = whether 't' is register or upvalue; 40 | ind.t = table register or upvalue; 41 | ind.idx = key's R/K index */ 42 | VJMP, /* expression is a test/comparison; 43 | info = pc of corresponding jump instruction */ 44 | VRELOCABLE, /* expression can put result in any register; 45 | info = instruction pc */ 46 | VCALL, /* expression is a function call; info = instruction pc */ 47 | VVARARG /* vararg expression; info = instruction pc */ 48 | } expkind; 49 | 50 | 51 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXED) 52 | #define vkisinreg(k) ((k) == VNONRELOC || (k) == VLOCAL) 53 | 54 | typedef struct expdesc { 55 | expkind k; 56 | union { 57 | lua_Integer ival; /* for VKINT */ 58 | lua_Number nval; /* for VKFLT */ 59 | int info; /* for generic use */ 60 | struct { /* for indexed variables (VINDEXED) */ 61 | short idx; /* index (R/K) */ 62 | lu_byte t; /* table (register or upvalue) */ 63 | lu_byte vt; /* whether 't' is register (VLOCAL) or upvalue (VUPVAL) */ 64 | } ind; 65 | } u; 66 | int t; /* patch list of 'exit when true' */ 67 | int f; /* patch list of 'exit when false' */ 68 | } expdesc; 69 | 70 | 71 | /* description of active local variable */ 72 | typedef struct Vardesc { 73 | short idx; /* variable index in stack */ 74 | } Vardesc; 75 | 76 | 77 | /* description of pending goto statements and label statements */ 78 | typedef struct Labeldesc { 79 | TString *name; /* label identifier */ 80 | int pc; /* position in code */ 81 | int line; /* line where it appeared */ 82 | lu_byte nactvar; /* local level where it appears in current block */ 83 | } Labeldesc; 84 | 85 | 86 | /* list of labels or gotos */ 87 | typedef struct Labellist { 88 | Labeldesc *arr; /* array */ 89 | int n; /* number of entries in use */ 90 | int size; /* array size */ 91 | } Labellist; 92 | 93 | 94 | /* dynamic structures used by the parser */ 95 | typedef struct Dyndata { 96 | struct { /* list of active local variables */ 97 | Vardesc *arr; 98 | int n; 99 | int size; 100 | } actvar; 101 | Labellist gt; /* list of pending gotos */ 102 | Labellist label; /* list of active labels */ 103 | } Dyndata; 104 | 105 | 106 | /* control of blocks */ 107 | struct BlockCnt; /* defined in lparser.c */ 108 | 109 | 110 | /* state needed to generate code for a given function */ 111 | typedef struct FuncState { 112 | Proto *f; /* current function header */ 113 | struct FuncState *prev; /* enclosing function */ 114 | struct LexState *ls; /* lexical state */ 115 | struct BlockCnt *bl; /* chain of current blocks */ 116 | int pc; /* next position to code (equivalent to 'ncode') */ 117 | int lasttarget; /* 'label' of last 'jump label' */ 118 | int jpc; /* list of pending jumps to 'pc' */ 119 | int nk; /* number of elements in 'k' */ 120 | int np; /* number of elements in 'p' */ 121 | int firstlocal; /* index of first local var (in Dyndata array) */ 122 | short nlocvars; /* number of elements in 'f->locvars' */ 123 | lu_byte nactvar; /* number of active local variables */ 124 | lu_byte nups; /* number of upvalues */ 125 | lu_byte freereg; /* first free register */ 126 | } FuncState; 127 | 128 | 129 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 130 | Dyndata *dyd, const char *name, int firstchar); 131 | 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /luadbg/lua_src/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /luadbg/lua_src/lstate.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstate.c,v 2.133 2015/11/13 12:16:51 roberto Exp $ 3 | ** Global State 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lstate_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | #include 15 | 16 | #include "lua.h" 17 | 18 | #include "lapi.h" 19 | #include "ldebug.h" 20 | #include "ldo.h" 21 | #include "lfunc.h" 22 | #include "lgc.h" 23 | #include "llex.h" 24 | #include "lmem.h" 25 | #include "lstate.h" 26 | #include "lstring.h" 27 | #include "ltable.h" 28 | #include "ltm.h" 29 | 30 | 31 | #if !defined(LUAI_GCPAUSE) 32 | #define LUAI_GCPAUSE 200 /* 200% */ 33 | #endif 34 | 35 | #if !defined(LUAI_GCMUL) 36 | #define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */ 37 | #endif 38 | 39 | 40 | /* 41 | ** a macro to help the creation of a unique random seed when a state is 42 | ** created; the seed is used to randomize hashes. 43 | */ 44 | #if !defined(luai_makeseed) 45 | #include 46 | #define luai_makeseed() cast(unsigned int, time(NULL)) 47 | #endif 48 | 49 | 50 | 51 | /* 52 | ** thread state + extra space 53 | */ 54 | typedef struct LX { 55 | lu_byte extra_[LUA_EXTRASPACE]; 56 | lua_State l; 57 | } LX; 58 | 59 | 60 | /* 61 | ** Main thread combines a thread state and the global state 62 | */ 63 | typedef struct LG { 64 | LX l; 65 | global_State g; 66 | } LG; 67 | 68 | 69 | 70 | #define fromstate(L) (cast(LX *, cast(lu_byte *, (L)) - offsetof(LX, l))) 71 | 72 | 73 | /* 74 | ** Compute an initial seed as random as possible. Rely on Address Space 75 | ** Layout Randomization (if present) to increase randomness.. 76 | */ 77 | #define addbuff(b,p,e) \ 78 | { size_t t = cast(size_t, e); \ 79 | memcpy(b + p, &t, sizeof(t)); p += sizeof(t); } 80 | 81 | static unsigned int makeseed (lua_State *L) { 82 | char buff[4 * sizeof(size_t)]; 83 | unsigned int h = luai_makeseed(); 84 | int p = 0; 85 | addbuff(buff, p, L); /* heap variable */ 86 | addbuff(buff, p, &h); /* local variable */ 87 | addbuff(buff, p, luaO_nilobject); /* global variable */ 88 | addbuff(buff, p, &lua_newstate); /* public function */ 89 | lua_assert(p == sizeof(buff)); 90 | return luaS_hash(buff, p, h); 91 | } 92 | 93 | 94 | /* 95 | ** set GCdebt to a new value keeping the value (totalbytes + GCdebt) 96 | ** invariant (and avoiding underflows in 'totalbytes') 97 | */ 98 | void luaE_setdebt (global_State *g, l_mem debt) { 99 | l_mem tb = gettotalbytes(g); 100 | lua_assert(tb > 0); 101 | if (debt < tb - MAX_LMEM) 102 | debt = tb - MAX_LMEM; /* will make 'totalbytes == MAX_LMEM' */ 103 | g->totalbytes = tb - debt; 104 | g->GCdebt = debt; 105 | } 106 | 107 | 108 | CallInfo *luaE_extendCI (lua_State *L) { 109 | CallInfo *ci = luaM_new(L, CallInfo); 110 | lua_assert(L->ci->next == NULL); 111 | L->ci->next = ci; 112 | ci->previous = L->ci; 113 | ci->next = NULL; 114 | L->nci++; 115 | return ci; 116 | } 117 | 118 | 119 | /* 120 | ** free all CallInfo structures not in use by a thread 121 | */ 122 | void luaE_freeCI (lua_State *L) { 123 | CallInfo *ci = L->ci; 124 | CallInfo *next = ci->next; 125 | ci->next = NULL; 126 | while ((ci = next) != NULL) { 127 | next = ci->next; 128 | luaM_free(L, ci); 129 | L->nci--; 130 | } 131 | } 132 | 133 | 134 | /* 135 | ** free half of the CallInfo structures not in use by a thread 136 | */ 137 | void luaE_shrinkCI (lua_State *L) { 138 | CallInfo *ci = L->ci; 139 | CallInfo *next2; /* next's next */ 140 | /* while there are two nexts */ 141 | while (ci->next != NULL && (next2 = ci->next->next) != NULL) { 142 | luaM_free(L, ci->next); /* free next */ 143 | L->nci--; 144 | ci->next = next2; /* remove 'next' from the list */ 145 | next2->previous = ci; 146 | ci = next2; /* keep next's next */ 147 | } 148 | } 149 | 150 | 151 | static void stack_init (lua_State *L1, lua_State *L) { 152 | int i; CallInfo *ci; 153 | /* initialize stack array */ 154 | L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue); 155 | L1->stacksize = BASIC_STACK_SIZE; 156 | for (i = 0; i < BASIC_STACK_SIZE; i++) 157 | setnilvalue(L1->stack + i); /* erase new stack */ 158 | L1->top = L1->stack; 159 | L1->stack_last = L1->stack + L1->stacksize - EXTRA_STACK; 160 | /* initialize first ci */ 161 | ci = &L1->base_ci; 162 | ci->next = ci->previous = NULL; 163 | ci->callstatus = 0; 164 | ci->func = L1->top; 165 | setnilvalue(L1->top++); /* 'function' entry for this 'ci' */ 166 | ci->top = L1->top + LUA_MINSTACK; 167 | L1->ci = ci; 168 | } 169 | 170 | 171 | static void freestack (lua_State *L) { 172 | if (L->stack == NULL) 173 | return; /* stack not completely built yet */ 174 | L->ci = &L->base_ci; /* free the entire 'ci' list */ 175 | luaE_freeCI(L); 176 | lua_assert(L->nci == 0); 177 | luaM_freearray(L, L->stack, L->stacksize); /* free stack array */ 178 | } 179 | 180 | 181 | /* 182 | ** Create registry table and its predefined values 183 | */ 184 | static void init_registry (lua_State *L, global_State *g) { 185 | TValue temp; 186 | /* create registry */ 187 | Table *registry = luaH_new(L); 188 | sethvalue(L, &g->l_registry, registry); 189 | luaH_resize(L, registry, LUA_RIDX_LAST, 0); 190 | /* registry[LUA_RIDX_MAINTHREAD] = L */ 191 | setthvalue(L, &temp, L); /* temp = L */ 192 | luaH_setint(L, registry, LUA_RIDX_MAINTHREAD, &temp); 193 | /* registry[LUA_RIDX_GLOBALS] = table of globals */ 194 | sethvalue(L, &temp, luaH_new(L)); /* temp = new table (global table) */ 195 | luaH_setint(L, registry, LUA_RIDX_GLOBALS, &temp); 196 | } 197 | 198 | 199 | /* 200 | ** open parts of the state that may cause memory-allocation errors. 201 | ** ('g->version' != NULL flags that the state was completely build) 202 | */ 203 | static void f_luaopen (lua_State *L, void *ud) { 204 | global_State *g = G(L); 205 | UNUSED(ud); 206 | stack_init(L, L); /* init stack */ 207 | init_registry(L, g); 208 | luaS_init(L); 209 | luaT_init(L); 210 | luaX_init(L); 211 | g->gcrunning = 1; /* allow gc */ 212 | g->version = lua_version(NULL); 213 | luai_userstateopen(L); 214 | } 215 | 216 | 217 | /* 218 | ** preinitialize a thread with consistent values without allocating 219 | ** any memory (to avoid errors) 220 | */ 221 | static void preinit_thread (lua_State *L, global_State *g) { 222 | G(L) = g; 223 | L->stack = NULL; 224 | L->ci = NULL; 225 | L->nci = 0; 226 | L->stacksize = 0; 227 | L->twups = L; /* thread has no upvalues */ 228 | L->errorJmp = NULL; 229 | L->nCcalls = 0; 230 | L->hook = NULL; 231 | L->hookmask = 0; 232 | L->basehookcount = 0; 233 | L->allowhook = 1; 234 | resethookcount(L); 235 | L->openupval = NULL; 236 | L->nny = 1; 237 | L->status = LUA_OK; 238 | L->errfunc = 0; 239 | } 240 | 241 | 242 | static void close_state (lua_State *L) { 243 | global_State *g = G(L); 244 | luaF_close(L, L->stack); /* close all upvalues for this thread */ 245 | luaC_freeallobjects(L); /* collect all objects */ 246 | if (g->version) /* closing a fully built state? */ 247 | luai_userstateclose(L); 248 | luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size); 249 | freestack(L); 250 | lua_assert(gettotalbytes(g) == sizeof(LG)); 251 | (*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */ 252 | } 253 | 254 | 255 | LUA_API lua_State *lua_newthread (lua_State *L) { 256 | global_State *g = G(L); 257 | lua_State *L1; 258 | lua_lock(L); 259 | luaC_checkGC(L); 260 | /* create new thread */ 261 | L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l; 262 | L1->marked = luaC_white(g); 263 | L1->tt = LUA_TTHREAD; 264 | /* link it on list 'allgc' */ 265 | L1->next = g->allgc; 266 | g->allgc = obj2gco(L1); 267 | /* anchor it on L stack */ 268 | setthvalue(L, L->top, L1); 269 | api_incr_top(L); 270 | preinit_thread(L1, g); 271 | L1->hookmask = L->hookmask; 272 | L1->basehookcount = L->basehookcount; 273 | L1->hook = L->hook; 274 | resethookcount(L1); 275 | /* initialize L1 extra space */ 276 | memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread), 277 | LUA_EXTRASPACE); 278 | luai_userstatethread(L, L1); 279 | stack_init(L1, L); /* init stack */ 280 | lua_unlock(L); 281 | return L1; 282 | } 283 | 284 | 285 | void luaE_freethread (lua_State *L, lua_State *L1) { 286 | LX *l = fromstate(L1); 287 | luaF_close(L1, L1->stack); /* close all upvalues for this thread */ 288 | lua_assert(L1->openupval == NULL); 289 | luai_userstatefree(L, L1); 290 | freestack(L1); 291 | luaM_free(L, l); 292 | } 293 | 294 | 295 | LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { 296 | int i; 297 | lua_State *L; 298 | global_State *g; 299 | LG *l = cast(LG *, (*f)(ud, NULL, LUA_TTHREAD, sizeof(LG))); 300 | if (l == NULL) return NULL; 301 | L = &l->l.l; 302 | g = &l->g; 303 | L->next = NULL; 304 | L->tt = LUA_TTHREAD; 305 | g->currentwhite = bitmask(WHITE0BIT); 306 | L->marked = luaC_white(g); 307 | preinit_thread(L, g); 308 | g->frealloc = f; 309 | g->ud = ud; 310 | g->mainthread = L; 311 | g->seed = makeseed(L); 312 | g->gcrunning = 0; /* no GC while building state */ 313 | g->GCestimate = 0; 314 | g->strt.size = g->strt.nuse = 0; 315 | g->strt.hash = NULL; 316 | setnilvalue(&g->l_registry); 317 | g->panic = NULL; 318 | g->version = NULL; 319 | g->gcstate = GCSpause; 320 | g->gckind = KGC_NORMAL; 321 | g->allgc = g->finobj = g->tobefnz = g->fixedgc = NULL; 322 | g->sweepgc = NULL; 323 | g->gray = g->grayagain = NULL; 324 | g->weak = g->ephemeron = g->allweak = NULL; 325 | g->twups = NULL; 326 | g->totalbytes = sizeof(LG); 327 | g->GCdebt = 0; 328 | g->gcfinnum = 0; 329 | g->gcpause = LUAI_GCPAUSE; 330 | g->gcstepmul = LUAI_GCMUL; 331 | for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL; 332 | if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) { 333 | /* memory allocation error: free partial state */ 334 | close_state(L); 335 | L = NULL; 336 | } 337 | return L; 338 | } 339 | 340 | 341 | LUA_API void lua_close (lua_State *L) { 342 | L = G(L)->mainthread; /* only the main thread can be closed */ 343 | lua_lock(L); 344 | close_state(L); 345 | } 346 | 347 | 348 | -------------------------------------------------------------------------------- /luadbg/lua_src/lstate.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstate.h,v 2.130 2015/12/16 16:39:38 roberto Exp $ 3 | ** Global State 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstate_h 8 | #define lstate_h 9 | 10 | #include "lua.h" 11 | 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | #include "lzio.h" 15 | 16 | 17 | /* 18 | 19 | ** Some notes about garbage-collected objects: All objects in Lua must 20 | ** be kept somehow accessible until being freed, so all objects always 21 | ** belong to one (and only one) of these lists, using field 'next' of 22 | ** the 'CommonHeader' for the link: 23 | ** 24 | ** 'allgc': all objects not marked for finalization; 25 | ** 'finobj': all objects marked for finalization; 26 | ** 'tobefnz': all objects ready to be finalized; 27 | ** 'fixedgc': all objects that are not to be collected (currently 28 | ** only small strings, such as reserved words). 29 | 30 | */ 31 | 32 | 33 | struct lua_longjmp; /* defined in ldo.c */ 34 | 35 | 36 | /* 37 | ** Atomic type (relative to signals) to better ensure that 'lua_sethook' 38 | ** is thread safe 39 | */ 40 | #if !defined(l_signalT) 41 | #include 42 | #define l_signalT sig_atomic_t 43 | #endif 44 | 45 | 46 | /* extra stack space to handle TM calls and some other extras */ 47 | #define EXTRA_STACK 5 48 | 49 | 50 | #define BASIC_STACK_SIZE (2*LUA_MINSTACK) 51 | 52 | 53 | /* kinds of Garbage Collection */ 54 | #define KGC_NORMAL 0 55 | #define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */ 56 | 57 | 58 | typedef struct stringtable { 59 | TString **hash; 60 | int nuse; /* number of elements */ 61 | int size; 62 | } stringtable; 63 | 64 | 65 | /* 66 | ** Information about a call. 67 | ** When a thread yields, 'func' is adjusted to pretend that the 68 | ** top function has only the yielded values in its stack; in that 69 | ** case, the actual 'func' value is saved in field 'extra'. 70 | ** When a function calls another with a continuation, 'extra' keeps 71 | ** the function index so that, in case of errors, the continuation 72 | ** function can be called with the correct top. 73 | */ 74 | typedef struct CallInfo { 75 | StkId func; /* function index in the stack */ 76 | StkId top; /* top for this function */ 77 | struct CallInfo *previous, *next; /* dynamic call link */ 78 | union { 79 | struct { /* only for Lua functions */ 80 | StkId base; /* base for this function */ 81 | const Instruction *savedpc; 82 | } l; 83 | struct { /* only for C functions */ 84 | lua_KFunction k; /* continuation in case of yields */ 85 | ptrdiff_t old_errfunc; 86 | lua_KContext ctx; /* context info. in case of yields */ 87 | } c; 88 | } u; 89 | ptrdiff_t extra; 90 | short nresults; /* expected number of results from this function */ 91 | lu_byte callstatus; 92 | } CallInfo; 93 | 94 | 95 | /* 96 | ** Bits in CallInfo status 97 | */ 98 | #define CIST_OAH (1<<0) /* original value of 'allowhook' */ 99 | #define CIST_LUA (1<<1) /* call is running a Lua function */ 100 | #define CIST_HOOKED (1<<2) /* call is running a debug hook */ 101 | #define CIST_FRESH (1<<3) /* call is running on a fresh invocation 102 | of luaV_execute */ 103 | #define CIST_YPCALL (1<<4) /* call is a yieldable protected call */ 104 | #define CIST_TAIL (1<<5) /* call was tail called */ 105 | #define CIST_HOOKYIELD (1<<6) /* last hook called yielded */ 106 | #define CIST_LEQ (1<<7) /* using __lt for __le */ 107 | 108 | #define isLua(ci) ((ci)->callstatus & CIST_LUA) 109 | 110 | /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */ 111 | #define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v)) 112 | #define getoah(st) ((st) & CIST_OAH) 113 | 114 | 115 | /* 116 | ** 'global state', shared by all threads of this state 117 | */ 118 | typedef struct global_State { 119 | lua_Alloc frealloc; /* function to reallocate memory */ 120 | void *ud; /* auxiliary data to 'frealloc' */ 121 | l_mem totalbytes; /* number of bytes currently allocated - GCdebt */ 122 | l_mem GCdebt; /* bytes allocated not yet compensated by the collector */ 123 | lu_mem GCmemtrav; /* memory traversed by the GC */ 124 | lu_mem GCestimate; /* an estimate of the non-garbage memory in use */ 125 | stringtable strt; /* hash table for strings */ 126 | TValue l_registry; 127 | unsigned int seed; /* randomized seed for hashes */ 128 | lu_byte currentwhite; 129 | lu_byte gcstate; /* state of garbage collector */ 130 | lu_byte gckind; /* kind of GC running */ 131 | lu_byte gcrunning; /* true if GC is running */ 132 | GCObject *allgc; /* list of all collectable objects */ 133 | GCObject **sweepgc; /* current position of sweep in list */ 134 | GCObject *finobj; /* list of collectable objects with finalizers */ 135 | GCObject *gray; /* list of gray objects */ 136 | GCObject *grayagain; /* list of objects to be traversed atomically */ 137 | GCObject *weak; /* list of tables with weak values */ 138 | GCObject *ephemeron; /* list of ephemeron tables (weak keys) */ 139 | GCObject *allweak; /* list of all-weak tables */ 140 | GCObject *tobefnz; /* list of userdata to be GC */ 141 | GCObject *fixedgc; /* list of objects not to be collected */ 142 | struct lua_State *twups; /* list of threads with open upvalues */ 143 | unsigned int gcfinnum; /* number of finalizers to call in each GC step */ 144 | int gcpause; /* size of pause between successive GCs */ 145 | int gcstepmul; /* GC 'granularity' */ 146 | lua_CFunction panic; /* to be called in unprotected errors */ 147 | struct lua_State *mainthread; 148 | const lua_Number *version; /* pointer to version number */ 149 | TString *memerrmsg; /* memory-error message */ 150 | TString *tmname[TM_N]; /* array with tag-method names */ 151 | struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ 152 | TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */ 153 | } global_State; 154 | 155 | 156 | /* 157 | ** 'per thread' state 158 | */ 159 | struct lua_State { 160 | CommonHeader; 161 | unsigned short nci; /* number of items in 'ci' list */ 162 | lu_byte status; 163 | StkId top; /* first free slot in the stack */ 164 | global_State *l_G; 165 | CallInfo *ci; /* call info for current function */ 166 | const Instruction *oldpc; /* last pc traced */ 167 | StkId stack_last; /* last free slot in the stack */ 168 | StkId stack; /* stack base */ 169 | UpVal *openupval; /* list of open upvalues in this stack */ 170 | GCObject *gclist; 171 | struct lua_State *twups; /* list of threads with open upvalues */ 172 | struct lua_longjmp *errorJmp; /* current error recover point */ 173 | CallInfo base_ci; /* CallInfo for first level (C calling Lua) */ 174 | volatile lua_Hook hook; 175 | ptrdiff_t errfunc; /* current error handling function (stack index) */ 176 | int stacksize; 177 | int basehookcount; 178 | int hookcount; 179 | unsigned short nny; /* number of non-yieldable calls in stack */ 180 | unsigned short nCcalls; /* number of nested C calls */ 181 | l_signalT hookmask; 182 | lu_byte allowhook; 183 | }; 184 | 185 | 186 | #define G(L) (L->l_G) 187 | 188 | 189 | /* 190 | ** Union of all collectable objects (only for conversions) 191 | */ 192 | union GCUnion { 193 | GCObject gc; /* common header */ 194 | struct TString ts; 195 | struct Udata u; 196 | union Closure cl; 197 | struct Table h; 198 | struct Proto p; 199 | struct lua_State th; /* thread */ 200 | }; 201 | 202 | 203 | #define cast_u(o) cast(union GCUnion *, (o)) 204 | 205 | /* macros to convert a GCObject into a specific value */ 206 | #define gco2ts(o) \ 207 | check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts)) 208 | #define gco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u)) 209 | #define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l)) 210 | #define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c)) 211 | #define gco2cl(o) \ 212 | check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl)) 213 | #define gco2t(o) check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h)) 214 | #define gco2p(o) check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p)) 215 | #define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th)) 216 | 217 | 218 | /* macro to convert a Lua object into a GCObject */ 219 | #define obj2gco(v) \ 220 | check_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc))) 221 | 222 | 223 | /* actual number of total bytes allocated */ 224 | #define gettotalbytes(g) cast(lu_mem, (g)->totalbytes + (g)->GCdebt) 225 | 226 | LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt); 227 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 228 | LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L); 229 | LUAI_FUNC void luaE_freeCI (lua_State *L); 230 | LUAI_FUNC void luaE_shrinkCI (lua_State *L); 231 | 232 | 233 | #endif 234 | 235 | -------------------------------------------------------------------------------- /luadbg/lua_src/lstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp $ 3 | ** String table (keeps all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lstring_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | #include "lstring.h" 23 | 24 | 25 | #define MEMERRMSG "not enough memory" 26 | 27 | 28 | /* 29 | ** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to 30 | ** compute its hash 31 | */ 32 | #if !defined(LUAI_HASHLIMIT) 33 | #define LUAI_HASHLIMIT 5 34 | #endif 35 | 36 | 37 | /* 38 | ** equality for long strings 39 | */ 40 | int luaS_eqlngstr (TString *a, TString *b) { 41 | size_t len = a->u.lnglen; 42 | lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR); 43 | return (a == b) || /* same instance or... */ 44 | ((len == b->u.lnglen) && /* equal length and ... */ 45 | (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */ 46 | } 47 | 48 | 49 | unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) { 50 | unsigned int h = seed ^ cast(unsigned int, l); 51 | size_t step = (l >> LUAI_HASHLIMIT) + 1; 52 | for (; l >= step; l -= step) 53 | h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1])); 54 | return h; 55 | } 56 | 57 | 58 | unsigned int luaS_hashlongstr (TString *ts) { 59 | lua_assert(ts->tt == LUA_TLNGSTR); 60 | if (ts->extra == 0) { /* no hash? */ 61 | ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash); 62 | ts->extra = 1; /* now it has its hash */ 63 | } 64 | return ts->hash; 65 | } 66 | 67 | 68 | /* 69 | ** resizes the string table 70 | */ 71 | void luaS_resize (lua_State *L, int newsize) { 72 | int i; 73 | stringtable *tb = &G(L)->strt; 74 | if (newsize > tb->size) { /* grow table if needed */ 75 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); 76 | for (i = tb->size; i < newsize; i++) 77 | tb->hash[i] = NULL; 78 | } 79 | for (i = 0; i < tb->size; i++) { /* rehash */ 80 | TString *p = tb->hash[i]; 81 | tb->hash[i] = NULL; 82 | while (p) { /* for each node in the list */ 83 | TString *hnext = p->u.hnext; /* save next */ 84 | unsigned int h = lmod(p->hash, newsize); /* new position */ 85 | p->u.hnext = tb->hash[h]; /* chain it */ 86 | tb->hash[h] = p; 87 | p = hnext; 88 | } 89 | } 90 | if (newsize < tb->size) { /* shrink table if needed */ 91 | /* vanishing slice should be empty */ 92 | lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL); 93 | luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *); 94 | } 95 | tb->size = newsize; 96 | } 97 | 98 | 99 | /* 100 | ** Clear API string cache. (Entries cannot be empty, so fill them with 101 | ** a non-collectable string.) 102 | */ 103 | void luaS_clearcache (global_State *g) { 104 | int i, j; 105 | for (i = 0; i < STRCACHE_N; i++) 106 | for (j = 0; j < STRCACHE_M; j++) { 107 | if (iswhite(g->strcache[i][j])) /* will entry be collected? */ 108 | g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */ 109 | } 110 | } 111 | 112 | 113 | /* 114 | ** Initialize the string table and the string cache 115 | */ 116 | void luaS_init (lua_State *L) { 117 | global_State *g = G(L); 118 | int i, j; 119 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ 120 | /* pre-create memory-error message */ 121 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); 122 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ 123 | for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ 124 | for (j = 0; j < STRCACHE_M; j++) 125 | g->strcache[i][j] = g->memerrmsg; 126 | } 127 | 128 | 129 | 130 | /* 131 | ** creates a new string object 132 | */ 133 | static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) { 134 | TString *ts; 135 | GCObject *o; 136 | size_t totalsize; /* total size of TString object */ 137 | totalsize = sizelstring(l); 138 | o = luaC_newobj(L, tag, totalsize); 139 | ts = gco2ts(o); 140 | ts->hash = h; 141 | ts->extra = 0; 142 | getstr(ts)[l] = '\0'; /* ending 0 */ 143 | return ts; 144 | } 145 | 146 | 147 | TString *luaS_createlngstrobj (lua_State *L, size_t l) { 148 | TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed); 149 | ts->u.lnglen = l; 150 | return ts; 151 | } 152 | 153 | 154 | void luaS_remove (lua_State *L, TString *ts) { 155 | stringtable *tb = &G(L)->strt; 156 | TString **p = &tb->hash[lmod(ts->hash, tb->size)]; 157 | while (*p != ts) /* find previous element */ 158 | p = &(*p)->u.hnext; 159 | *p = (*p)->u.hnext; /* remove element from its list */ 160 | tb->nuse--; 161 | } 162 | 163 | 164 | /* 165 | ** checks whether short string exists and reuses it or creates a new one 166 | */ 167 | static TString *internshrstr (lua_State *L, const char *str, size_t l) { 168 | TString *ts; 169 | global_State *g = G(L); 170 | unsigned int h = luaS_hash(str, l, g->seed); 171 | TString **list = &g->strt.hash[lmod(h, g->strt.size)]; 172 | lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */ 173 | for (ts = *list; ts != NULL; ts = ts->u.hnext) { 174 | if (l == ts->shrlen && 175 | (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { 176 | /* found! */ 177 | if (isdead(g, ts)) /* dead (but not collected yet)? */ 178 | changewhite(ts); /* resurrect it */ 179 | return ts; 180 | } 181 | } 182 | if (g->strt.nuse >= g->strt.size && g->strt.size <= MAX_INT/2) { 183 | luaS_resize(L, g->strt.size * 2); 184 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ 185 | } 186 | ts = createstrobj(L, l, LUA_TSHRSTR, h); 187 | memcpy(getstr(ts), str, l * sizeof(char)); 188 | ts->shrlen = cast_byte(l); 189 | ts->u.hnext = *list; 190 | *list = ts; 191 | g->strt.nuse++; 192 | return ts; 193 | } 194 | 195 | 196 | /* 197 | ** new string (with explicit length) 198 | */ 199 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 200 | if (l <= LUAI_MAXSHORTLEN) /* short string? */ 201 | return internshrstr(L, str, l); 202 | else { 203 | TString *ts; 204 | if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char)) 205 | luaM_toobig(L); 206 | ts = luaS_createlngstrobj(L, l); 207 | memcpy(getstr(ts), str, l * sizeof(char)); 208 | return ts; 209 | } 210 | } 211 | 212 | 213 | /* 214 | ** Create or reuse a zero-terminated string, first checking in the 215 | ** cache (using the string address as a key). The cache can contain 216 | ** only zero-terminated strings, so it is safe to use 'strcmp' to 217 | ** check hits. 218 | */ 219 | TString *luaS_new (lua_State *L, const char *str) { 220 | unsigned int i = point2uint(str) % STRCACHE_N; /* hash */ 221 | int j; 222 | TString **p = G(L)->strcache[i]; 223 | for (j = 0; j < STRCACHE_M; j++) { 224 | if (strcmp(str, getstr(p[j])) == 0) /* hit? */ 225 | return p[j]; /* that is it */ 226 | } 227 | /* normal route */ 228 | for (j = STRCACHE_M - 1; j > 0; j--) 229 | p[j] = p[j - 1]; /* move out last element */ 230 | /* new element is first in the list */ 231 | p[0] = luaS_newlstr(L, str, strlen(str)); 232 | return p[0]; 233 | } 234 | 235 | 236 | Udata *luaS_newudata (lua_State *L, size_t s) { 237 | Udata *u; 238 | GCObject *o; 239 | if (s > MAX_SIZE - sizeof(Udata)) 240 | luaM_toobig(L); 241 | o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s)); 242 | u = gco2u(o); 243 | u->len = s; 244 | u->metatable = NULL; 245 | setuservalue(L, u, luaO_nilobject); 246 | return u; 247 | } 248 | 249 | -------------------------------------------------------------------------------- /luadbg/lua_src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.61 2015/11/03 15:36:01 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | #define sizelstring(l) (sizeof(union UTString) + ((l) + 1) * sizeof(char)) 16 | 17 | #define sizeludata(l) (sizeof(union UUdata) + (l)) 18 | #define sizeudata(u) sizeludata((u)->len) 19 | 20 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 21 | (sizeof(s)/sizeof(char))-1)) 22 | 23 | 24 | /* 25 | ** test whether a string is a reserved word 26 | */ 27 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 28 | 29 | 30 | /* 31 | ** equality for short strings, which are always internalized 32 | */ 33 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 34 | 35 | 36 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 37 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 38 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 39 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 40 | LUAI_FUNC void luaS_clearcache (global_State *g); 41 | LUAI_FUNC void luaS_init (lua_State *L); 42 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 43 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s); 44 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 45 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 46 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 47 | 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /luadbg/lua_src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.21 2015/11/03 15:47:30 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->i_key.nk.next) 16 | 17 | 18 | /* 'const' to avoid wrong writings that can mess up field 'next' */ 19 | #define gkey(n) cast(const TValue*, (&(n)->i_key.tvk)) 20 | 21 | /* 22 | ** writable version of 'gkey'; allows updates to individual fields, 23 | ** but not to the whole (which has incompatible type) 24 | */ 25 | #define wgkey(n) (&(n)->i_key.nk) 26 | 27 | #define invalidateTMcache(t) ((t)->flags = 0) 28 | 29 | 30 | /* returns the key, given the value of a table entry */ 31 | #define keyfromval(v) \ 32 | (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val)))) 33 | 34 | 35 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 36 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 37 | TValue *value); 38 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 39 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 40 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 41 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 42 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 43 | LUAI_FUNC Table *luaH_new (lua_State *L); 44 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 45 | unsigned int nhsize); 46 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 47 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 48 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 49 | LUAI_FUNC int luaH_getn (Table *t); 50 | 51 | 52 | #if defined(LUA_DEBUG) 53 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 54 | LUAI_FUNC int luaH_isdummy (Node *n); 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /luadbg/lua_src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.37 2016/02/26 19:20:15 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ltm_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lobject.h" 20 | #include "lstate.h" 21 | #include "lstring.h" 22 | #include "ltable.h" 23 | #include "ltm.h" 24 | #include "lvm.h" 25 | 26 | 27 | static const char udatatypename[] = "userdata"; 28 | 29 | LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = { 30 | "no value", 31 | "nil", "boolean", udatatypename, "number", 32 | "string", "table", "function", udatatypename, "thread", 33 | "proto" /* this last case is used for tests only */ 34 | }; 35 | 36 | 37 | void luaT_init (lua_State *L) { 38 | static const char *const luaT_eventname[] = { /* ORDER TM */ 39 | "__index", "__newindex", 40 | "__gc", "__mode", "__len", "__eq", 41 | "__add", "__sub", "__mul", "__mod", "__pow", 42 | "__div", "__idiv", 43 | "__band", "__bor", "__bxor", "__shl", "__shr", 44 | "__unm", "__bnot", "__lt", "__le", 45 | "__concat", "__call" 46 | }; 47 | int i; 48 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 50 | luaC_fix(L, obj2gco(G(L)->tmname[i])); /* never collect these names */ 51 | } 52 | } 53 | 54 | 55 | /* 56 | ** function to be used with macro "fasttm": optimized for absence of 57 | ** tag methods 58 | */ 59 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 60 | const TValue *tm = luaH_getshortstr(events, ename); 61 | lua_assert(event <= TM_EQ); 62 | if (ttisnil(tm)) { /* no tag method? */ 63 | events->flags |= cast_byte(1u<metatable; 75 | break; 76 | case LUA_TUSERDATA: 77 | mt = uvalue(o)->metatable; 78 | break; 79 | default: 80 | mt = G(L)->mt[ttnov(o)]; 81 | } 82 | return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : luaO_nilobject); 83 | } 84 | 85 | 86 | /* 87 | ** Return the name of the type of an object. For tables and userdata 88 | ** with metatable, use their '__name' metafield, if present. 89 | */ 90 | const char *luaT_objtypename (lua_State *L, const TValue *o) { 91 | Table *mt; 92 | if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) || 93 | (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) { 94 | const TValue *name = luaH_getshortstr(mt, luaS_new(L, "__name")); 95 | if (ttisstring(name)) /* is '__name' a string? */ 96 | return getstr(tsvalue(name)); /* use it as type name */ 97 | } 98 | return ttypename(ttnov(o)); /* else use standard type name */ 99 | } 100 | 101 | 102 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 103 | const TValue *p2, TValue *p3, int hasres) { 104 | ptrdiff_t result = savestack(L, p3); 105 | StkId func = L->top; 106 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 107 | setobj2s(L, func + 1, p1); /* 1st argument */ 108 | setobj2s(L, func + 2, p2); /* 2nd argument */ 109 | L->top += 3; 110 | if (!hasres) /* no result? 'p3' is third argument */ 111 | setobj2s(L, L->top++, p3); /* 3rd argument */ 112 | /* metamethod may yield only when called from Lua code */ 113 | if (isLua(L->ci)) 114 | luaD_call(L, func, hasres); 115 | else 116 | luaD_callnoyield(L, func, hasres); 117 | if (hasres) { /* if has result, move it to its place */ 118 | p3 = restorestack(L, result); 119 | setobjs2s(L, p3, --L->top); 120 | } 121 | } 122 | 123 | 124 | int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 125 | StkId res, TMS event) { 126 | const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ 127 | if (ttisnil(tm)) 128 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ 129 | if (ttisnil(tm)) return 0; 130 | luaT_callTM(L, tm, p1, p2, res, 1); 131 | return 1; 132 | } 133 | 134 | 135 | void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 136 | StkId res, TMS event) { 137 | if (!luaT_callbinTM(L, p1, p2, res, event)) { 138 | switch (event) { 139 | case TM_CONCAT: 140 | luaG_concaterror(L, p1, p2); 141 | /* call never returns, but to avoid warnings: *//* FALLTHROUGH */ 142 | case TM_BAND: case TM_BOR: case TM_BXOR: 143 | case TM_SHL: case TM_SHR: case TM_BNOT: { 144 | lua_Number dummy; 145 | if (tonumber(p1, &dummy) && tonumber(p2, &dummy)) 146 | luaG_tointerror(L, p1, p2); 147 | else 148 | luaG_opinterror(L, p1, p2, "perform bitwise operation on"); 149 | } 150 | /* calls never return, but to avoid warnings: *//* FALLTHROUGH */ 151 | default: 152 | luaG_opinterror(L, p1, p2, "perform arithmetic on"); 153 | } 154 | } 155 | } 156 | 157 | 158 | int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, 159 | TMS event) { 160 | if (!luaT_callbinTM(L, p1, p2, L->top, event)) 161 | return -1; /* no metamethod */ 162 | else 163 | return !l_isfalse(L->top); 164 | } 165 | 166 | -------------------------------------------------------------------------------- /luadbg/lua_src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.22 2016/02/26 19:20:15 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_N /* number of elements in the enum */ 44 | } TMS; 45 | 46 | 47 | 48 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 49 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 50 | 51 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 52 | 53 | #define ttypename(x) luaT_typenames_[(x) + 1] 54 | 55 | LUAI_DDEC const char *const luaT_typenames_[LUA_TOTALTAGS]; 56 | 57 | 58 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 59 | 60 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 61 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 62 | TMS event); 63 | LUAI_FUNC void luaT_init (lua_State *L); 64 | 65 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 66 | const TValue *p2, TValue *p3, int hasres); 67 | LUAI_FUNC int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 68 | StkId res, TMS event); 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 70 | StkId res, TMS event); 71 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 72 | const TValue *p2, TMS event); 73 | 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /luadbg/lua_src/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /luadbg/lua_src/luac.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $ 3 | ** Lua compiler (saves bytecodes to files; also lists bytecodes) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define luac_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "lua.h" 19 | #include "lauxlib.h" 20 | 21 | #include "lobject.h" 22 | #include "lstate.h" 23 | #include "lundump.h" 24 | 25 | static void PrintFunction(const Proto* f, int full); 26 | #define luaU_print PrintFunction 27 | 28 | #define PROGNAME "luac" /* default program name */ 29 | #define OUTPUT PROGNAME ".out" /* default output file */ 30 | 31 | static int listing=0; /* list bytecodes? */ 32 | static int dumping=1; /* dump bytecodes? */ 33 | static int stripping=0; /* strip debug information? */ 34 | static char Output[]={ OUTPUT }; /* default output file name */ 35 | static const char* output=Output; /* actual output file name */ 36 | static const char* progname=PROGNAME; /* actual program name */ 37 | 38 | static void fatal(const char* message) 39 | { 40 | fprintf(stderr,"%s: %s\n",progname,message); 41 | exit(EXIT_FAILURE); 42 | } 43 | 44 | static void cannot(const char* what) 45 | { 46 | fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno)); 47 | exit(EXIT_FAILURE); 48 | } 49 | 50 | static void usage(const char* message) 51 | { 52 | if (*message=='-') 53 | fprintf(stderr,"%s: unrecognized option '%s'\n",progname,message); 54 | else 55 | fprintf(stderr,"%s: %s\n",progname,message); 56 | fprintf(stderr, 57 | "usage: %s [options] [filenames]\n" 58 | "Available options are:\n" 59 | " -l list (use -l -l for full listing)\n" 60 | " -o name output to file 'name' (default is \"%s\")\n" 61 | " -p parse only\n" 62 | " -s strip debug information\n" 63 | " -v show version information\n" 64 | " -- stop handling options\n" 65 | " - stop handling options and process stdin\n" 66 | ,progname,Output); 67 | exit(EXIT_FAILURE); 68 | } 69 | 70 | #define IS(s) (strcmp(argv[i],s)==0) 71 | 72 | static int doargs(int argc, char* argv[]) 73 | { 74 | int i; 75 | int version=0; 76 | if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; 77 | for (i=1; itop+(i)) 138 | 139 | static const Proto* combine(lua_State* L, int n) 140 | { 141 | if (n==1) 142 | return toproto(L,-1); 143 | else 144 | { 145 | Proto* f; 146 | int i=n; 147 | if (lua_load(L,reader,&i,"=(" PROGNAME ")",NULL)!=LUA_OK) fatal(lua_tostring(L,-1)); 148 | f=toproto(L,-1); 149 | for (i=0; ip[i]=toproto(L,i-n-1); 152 | if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0; 153 | } 154 | f->sizelineinfo=0; 155 | return f; 156 | } 157 | } 158 | 159 | static int writer(lua_State* L, const void* p, size_t size, void* u) 160 | { 161 | UNUSED(L); 162 | return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0); 163 | } 164 | 165 | static int pmain(lua_State* L) 166 | { 167 | int argc=(int)lua_tointeger(L,1); 168 | char** argv=(char**)lua_touserdata(L,2); 169 | const Proto* f; 170 | int i; 171 | if (!lua_checkstack(L,argc)) fatal("too many input files"); 172 | for (i=0; i1); 179 | if (dumping) 180 | { 181 | FILE* D= (output==NULL) ? stdout : fopen(output,"wb"); 182 | if (D==NULL) cannot("open"); 183 | lua_lock(L); 184 | luaU_dump(L,f,writer,D,stripping); 185 | lua_unlock(L); 186 | if (ferror(D)) cannot("write"); 187 | if (fclose(D)) cannot("close"); 188 | } 189 | return 0; 190 | } 191 | 192 | int main(int argc, char* argv[]) 193 | { 194 | lua_State* L; 195 | int i=doargs(argc,argv); 196 | argc-=i; argv+=i; 197 | if (argc<=0) usage("no input files given"); 198 | L=luaL_newstate(); 199 | if (L==NULL) fatal("cannot create state: not enough memory"); 200 | lua_pushcfunction(L,&pmain); 201 | lua_pushinteger(L,argc); 202 | lua_pushlightuserdata(L,argv); 203 | if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1)); 204 | lua_close(L); 205 | return EXIT_SUCCESS; 206 | } 207 | 208 | /* 209 | ** $Id: luac.c,v 1.75 2015/03/12 01:58:27 lhf Exp $ 210 | ** print bytecodes 211 | ** See Copyright Notice in lua.h 212 | */ 213 | 214 | #include 215 | #include 216 | 217 | #define luac_c 218 | #define LUA_CORE 219 | 220 | #include "ldebug.h" 221 | #include "lobject.h" 222 | #include "lopcodes.h" 223 | 224 | #define VOID(p) ((const void*)(p)) 225 | 226 | static void PrintString(const TString* ts) 227 | { 228 | const char* s=getstr(ts); 229 | size_t i,n=tsslen(ts); 230 | printf("%c",'"'); 231 | for (i=0; ik[i]; 257 | switch (ttype(o)) 258 | { 259 | case LUA_TNIL: 260 | printf("nil"); 261 | break; 262 | case LUA_TBOOLEAN: 263 | printf(bvalue(o) ? "true" : "false"); 264 | break; 265 | case LUA_TNUMFLT: 266 | { 267 | char buff[100]; 268 | sprintf(buff,LUA_NUMBER_FMT,fltvalue(o)); 269 | printf("%s",buff); 270 | if (buff[strspn(buff,"-0123456789")]=='\0') printf(".0"); 271 | break; 272 | } 273 | case LUA_TNUMINT: 274 | printf(LUA_INTEGER_FMT,ivalue(o)); 275 | break; 276 | case LUA_TSHRSTR: case LUA_TLNGSTR: 277 | PrintString(tsvalue(o)); 278 | break; 279 | default: /* cannot happen */ 280 | printf("? type=%d",ttype(o)); 281 | break; 282 | } 283 | } 284 | 285 | #define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-") 286 | #define MYK(x) (-1-(x)) 287 | 288 | static void PrintCode(const Proto* f) 289 | { 290 | const Instruction* code=f->code; 291 | int pc,n=f->sizecode; 292 | for (pc=0; pc0) printf("[%d]\t",line); else printf("[-]\t"); 305 | printf("%-9s\t",luaP_opnames[o]); 306 | switch (getOpMode(o)) 307 | { 308 | case iABC: 309 | printf("%d",a); 310 | if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (MYK(INDEXK(b))) : b); 311 | if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (MYK(INDEXK(c))) : c); 312 | break; 313 | case iABx: 314 | printf("%d",a); 315 | if (getBMode(o)==OpArgK) printf(" %d",MYK(bx)); 316 | if (getBMode(o)==OpArgU) printf(" %d",bx); 317 | break; 318 | case iAsBx: 319 | printf("%d %d",a,sbx); 320 | break; 321 | case iAx: 322 | printf("%d",MYK(ax)); 323 | break; 324 | } 325 | switch (o) 326 | { 327 | case OP_LOADK: 328 | printf("\t; "); PrintConstant(f,bx); 329 | break; 330 | case OP_GETUPVAL: 331 | case OP_SETUPVAL: 332 | printf("\t; %s",UPVALNAME(b)); 333 | break; 334 | case OP_GETTABUP: 335 | printf("\t; %s",UPVALNAME(b)); 336 | if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); } 337 | break; 338 | case OP_SETTABUP: 339 | printf("\t; %s",UPVALNAME(a)); 340 | if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); } 341 | if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); } 342 | break; 343 | case OP_GETTABLE: 344 | case OP_SELF: 345 | if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); } 346 | break; 347 | case OP_SETTABLE: 348 | case OP_ADD: 349 | case OP_SUB: 350 | case OP_MUL: 351 | case OP_POW: 352 | case OP_DIV: 353 | case OP_IDIV: 354 | case OP_BAND: 355 | case OP_BOR: 356 | case OP_BXOR: 357 | case OP_SHL: 358 | case OP_SHR: 359 | case OP_EQ: 360 | case OP_LT: 361 | case OP_LE: 362 | if (ISK(b) || ISK(c)) 363 | { 364 | printf("\t; "); 365 | if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-"); 366 | printf(" "); 367 | if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-"); 368 | } 369 | break; 370 | case OP_JMP: 371 | case OP_FORLOOP: 372 | case OP_FORPREP: 373 | case OP_TFORLOOP: 374 | printf("\t; to %d",sbx+pc+2); 375 | break; 376 | case OP_CLOSURE: 377 | printf("\t; %p",VOID(f->p[bx])); 378 | break; 379 | case OP_SETLIST: 380 | if (c==0) printf("\t; %d",(int)code[++pc]); else printf("\t; %d",c); 381 | break; 382 | case OP_EXTRAARG: 383 | printf("\t; "); PrintConstant(f,ax); 384 | break; 385 | default: 386 | break; 387 | } 388 | printf("\n"); 389 | } 390 | } 391 | 392 | #define SS(x) ((x==1)?"":"s") 393 | #define S(x) (int)(x),SS(x) 394 | 395 | static void PrintHeader(const Proto* f) 396 | { 397 | const char* s=f->source ? getstr(f->source) : "=?"; 398 | if (*s=='@' || *s=='=') 399 | s++; 400 | else if (*s==LUA_SIGNATURE[0]) 401 | s="(bstring)"; 402 | else 403 | s="(string)"; 404 | printf("\n%s <%s:%d,%d> (%d instruction%s at %p)\n", 405 | (f->linedefined==0)?"main":"function",s, 406 | f->linedefined,f->lastlinedefined, 407 | S(f->sizecode),VOID(f)); 408 | printf("%d%s param%s, %d slot%s, %d upvalue%s, ", 409 | (int)(f->numparams),f->is_vararg?"+":"",SS(f->numparams), 410 | S(f->maxstacksize),S(f->sizeupvalues)); 411 | printf("%d local%s, %d constant%s, %d function%s\n", 412 | S(f->sizelocvars),S(f->sizek),S(f->sizep)); 413 | } 414 | 415 | static void PrintDebug(const Proto* f) 416 | { 417 | int i,n; 418 | n=f->sizek; 419 | printf("constants (%d) for %p:\n",n,VOID(f)); 420 | for (i=0; isizelocvars; 427 | printf("locals (%d) for %p:\n",n,VOID(f)); 428 | for (i=0; ilocvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1); 432 | } 433 | n=f->sizeupvalues; 434 | printf("upvalues (%d) for %p:\n",n,VOID(f)); 435 | for (i=0; iupvalues[i].instack,f->upvalues[i].idx); 439 | } 440 | } 441 | 442 | static void PrintFunction(const Proto* f, int full) 443 | { 444 | int i,n=f->sizep; 445 | PrintHeader(f); 446 | PrintCode(f); 447 | if (full) PrintDebug(f); 448 | for (i=0; ip[i],full); 449 | } 450 | -------------------------------------------------------------------------------- /luadbg/lua_src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_UTF8LIBNAME "utf8" 33 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 34 | 35 | #define LUA_BITLIBNAME "bit32" 36 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | 53 | #if !defined(lua_assert) 54 | #define lua_assert(x) ((void)0) 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /luadbg/lua_src/lundump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.c,v 2.44 2015/11/02 16:09:30 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lundump_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lfunc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstring.h" 23 | #include "lundump.h" 24 | #include "lzio.h" 25 | 26 | 27 | #if !defined(luai_verifycode) 28 | #define luai_verifycode(L,b,f) /* empty */ 29 | #endif 30 | 31 | 32 | typedef struct { 33 | lua_State *L; 34 | ZIO *Z; 35 | const char *name; 36 | } LoadState; 37 | 38 | 39 | static l_noret error(LoadState *S, const char *why) { 40 | luaO_pushfstring(S->L, "%s: %s precompiled chunk", S->name, why); 41 | luaD_throw(S->L, LUA_ERRSYNTAX); 42 | } 43 | 44 | 45 | /* 46 | ** All high-level loads go through LoadVector; you can change it to 47 | ** adapt to the endianness of the input 48 | */ 49 | #define LoadVector(S,b,n) LoadBlock(S,b,(n)*sizeof((b)[0])) 50 | 51 | static void LoadBlock (LoadState *S, void *b, size_t size) { 52 | if (luaZ_read(S->Z, b, size) != 0) 53 | error(S, "truncated"); 54 | } 55 | 56 | 57 | #define LoadVar(S,x) LoadVector(S,&x,1) 58 | 59 | 60 | static lu_byte LoadByte (LoadState *S) { 61 | lu_byte x; 62 | LoadVar(S, x); 63 | return x; 64 | } 65 | 66 | 67 | static int LoadInt (LoadState *S) { 68 | int x; 69 | LoadVar(S, x); 70 | return x; 71 | } 72 | 73 | 74 | static lua_Number LoadNumber (LoadState *S) { 75 | lua_Number x; 76 | LoadVar(S, x); 77 | return x; 78 | } 79 | 80 | 81 | static lua_Integer LoadInteger (LoadState *S) { 82 | lua_Integer x; 83 | LoadVar(S, x); 84 | return x; 85 | } 86 | 87 | 88 | static TString *LoadString (LoadState *S) { 89 | size_t size = LoadByte(S); 90 | if (size == 0xFF) 91 | LoadVar(S, size); 92 | if (size == 0) 93 | return NULL; 94 | else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */ 95 | char buff[LUAI_MAXSHORTLEN]; 96 | LoadVector(S, buff, size); 97 | return luaS_newlstr(S->L, buff, size); 98 | } 99 | else { /* long string */ 100 | TString *ts = luaS_createlngstrobj(S->L, size); 101 | LoadVector(S, getstr(ts), size); /* load directly in final place */ 102 | return ts; 103 | } 104 | } 105 | 106 | 107 | static void LoadCode (LoadState *S, Proto *f) { 108 | int n = LoadInt(S); 109 | f->code = luaM_newvector(S->L, n, Instruction); 110 | f->sizecode = n; 111 | LoadVector(S, f->code, n); 112 | } 113 | 114 | 115 | static void LoadFunction(LoadState *S, Proto *f, TString *psource); 116 | 117 | 118 | static void LoadConstants (LoadState *S, Proto *f) { 119 | int i; 120 | int n = LoadInt(S); 121 | f->k = luaM_newvector(S->L, n, TValue); 122 | f->sizek = n; 123 | for (i = 0; i < n; i++) 124 | setnilvalue(&f->k[i]); 125 | for (i = 0; i < n; i++) { 126 | TValue *o = &f->k[i]; 127 | int t = LoadByte(S); 128 | switch (t) { 129 | case LUA_TNIL: 130 | setnilvalue(o); 131 | break; 132 | case LUA_TBOOLEAN: 133 | setbvalue(o, LoadByte(S)); 134 | break; 135 | case LUA_TNUMFLT: 136 | setfltvalue(o, LoadNumber(S)); 137 | break; 138 | case LUA_TNUMINT: 139 | setivalue(o, LoadInteger(S)); 140 | break; 141 | case LUA_TSHRSTR: 142 | case LUA_TLNGSTR: 143 | setsvalue2n(S->L, o, LoadString(S)); 144 | break; 145 | default: 146 | lua_assert(0); 147 | } 148 | } 149 | } 150 | 151 | 152 | static void LoadProtos (LoadState *S, Proto *f) { 153 | int i; 154 | int n = LoadInt(S); 155 | f->p = luaM_newvector(S->L, n, Proto *); 156 | f->sizep = n; 157 | for (i = 0; i < n; i++) 158 | f->p[i] = NULL; 159 | for (i = 0; i < n; i++) { 160 | f->p[i] = luaF_newproto(S->L); 161 | LoadFunction(S, f->p[i], f->source); 162 | } 163 | } 164 | 165 | 166 | static void LoadUpvalues (LoadState *S, Proto *f) { 167 | int i, n; 168 | n = LoadInt(S); 169 | f->upvalues = luaM_newvector(S->L, n, Upvaldesc); 170 | f->sizeupvalues = n; 171 | for (i = 0; i < n; i++) 172 | f->upvalues[i].name = NULL; 173 | for (i = 0; i < n; i++) { 174 | f->upvalues[i].instack = LoadByte(S); 175 | f->upvalues[i].idx = LoadByte(S); 176 | } 177 | } 178 | 179 | 180 | static void LoadDebug (LoadState *S, Proto *f) { 181 | int i, n; 182 | n = LoadInt(S); 183 | f->lineinfo = luaM_newvector(S->L, n, int); 184 | f->sizelineinfo = n; 185 | LoadVector(S, f->lineinfo, n); 186 | n = LoadInt(S); 187 | f->locvars = luaM_newvector(S->L, n, LocVar); 188 | f->sizelocvars = n; 189 | for (i = 0; i < n; i++) 190 | f->locvars[i].varname = NULL; 191 | for (i = 0; i < n; i++) { 192 | f->locvars[i].varname = LoadString(S); 193 | f->locvars[i].startpc = LoadInt(S); 194 | f->locvars[i].endpc = LoadInt(S); 195 | } 196 | n = LoadInt(S); 197 | for (i = 0; i < n; i++) 198 | f->upvalues[i].name = LoadString(S); 199 | } 200 | 201 | 202 | static void LoadFunction (LoadState *S, Proto *f, TString *psource) { 203 | f->source = LoadString(S); 204 | if (f->source == NULL) /* no source in dump? */ 205 | f->source = psource; /* reuse parent's source */ 206 | f->linedefined = LoadInt(S); 207 | f->lastlinedefined = LoadInt(S); 208 | f->numparams = LoadByte(S); 209 | f->is_vararg = LoadByte(S); 210 | f->maxstacksize = LoadByte(S); 211 | LoadCode(S, f); 212 | LoadConstants(S, f); 213 | LoadUpvalues(S, f); 214 | LoadProtos(S, f); 215 | LoadDebug(S, f); 216 | } 217 | 218 | 219 | static void checkliteral (LoadState *S, const char *s, const char *msg) { 220 | char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */ 221 | size_t len = strlen(s); 222 | LoadVector(S, buff, len); 223 | if (memcmp(s, buff, len) != 0) 224 | error(S, msg); 225 | } 226 | 227 | 228 | static void fchecksize (LoadState *S, size_t size, const char *tname) { 229 | if (LoadByte(S) != size) 230 | error(S, luaO_pushfstring(S->L, "%s size mismatch in", tname)); 231 | } 232 | 233 | 234 | #define checksize(S,t) fchecksize(S,sizeof(t),#t) 235 | 236 | static void checkHeader (LoadState *S) { 237 | checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */ 238 | if (LoadByte(S) != LUAC_VERSION) 239 | error(S, "version mismatch in"); 240 | if (LoadByte(S) != LUAC_FORMAT) 241 | error(S, "format mismatch in"); 242 | checkliteral(S, LUAC_DATA, "corrupted"); 243 | checksize(S, int); 244 | checksize(S, size_t); 245 | checksize(S, Instruction); 246 | checksize(S, lua_Integer); 247 | checksize(S, lua_Number); 248 | if (LoadInteger(S) != LUAC_INT) 249 | error(S, "endianness mismatch in"); 250 | if (LoadNumber(S) != LUAC_NUM) 251 | error(S, "float format mismatch in"); 252 | } 253 | 254 | 255 | /* 256 | ** load precompiled chunk 257 | */ 258 | LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) { 259 | LoadState S; 260 | LClosure *cl; 261 | if (*name == '@' || *name == '=') 262 | S.name = name + 1; 263 | else if (*name == LUA_SIGNATURE[0]) 264 | S.name = "binary string"; 265 | else 266 | S.name = name; 267 | S.L = L; 268 | S.Z = Z; 269 | checkHeader(&S); 270 | cl = luaF_newLclosure(L, LoadByte(&S)); 271 | setclLvalue(L, L->top, cl); 272 | luaD_inctop(L); 273 | cl->p = luaF_newproto(L); 274 | LoadFunction(&S, cl->p, NULL); 275 | lua_assert(cl->nupvalues == cl->p->sizeupvalues); 276 | luai_verifycode(L, buff, cl->p); 277 | return cl; 278 | } 279 | 280 | -------------------------------------------------------------------------------- /luadbg/lua_src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /luadbg/lua_src/lutf8lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lutf8lib.c,v 1.15 2015/03/28 19:16:55 roberto Exp $ 3 | ** Standard library for UTF-8 manipulation 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lutf8lib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "lua.h" 19 | 20 | #include "lauxlib.h" 21 | #include "lualib.h" 22 | 23 | #define MAXUNICODE 0x10FFFF 24 | 25 | #define iscont(p) ((*(p) & 0xC0) == 0x80) 26 | 27 | 28 | /* from strlib */ 29 | /* translate a relative string position: negative means back from end */ 30 | static lua_Integer u_posrelat (lua_Integer pos, size_t len) { 31 | if (pos >= 0) return pos; 32 | else if (0u - (size_t)pos > len) return 0; 33 | else return (lua_Integer)len + pos + 1; 34 | } 35 | 36 | 37 | /* 38 | ** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid. 39 | */ 40 | static const char *utf8_decode (const char *o, int *val) { 41 | static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF}; 42 | const unsigned char *s = (const unsigned char *)o; 43 | unsigned int c = s[0]; 44 | unsigned int res = 0; /* final result */ 45 | if (c < 0x80) /* ascii? */ 46 | res = c; 47 | else { 48 | int count = 0; /* to count number of continuation bytes */ 49 | while (c & 0x40) { /* still have continuation bytes? */ 50 | int cc = s[++count]; /* read next byte */ 51 | if ((cc & 0xC0) != 0x80) /* not a continuation byte? */ 52 | return NULL; /* invalid byte sequence */ 53 | res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ 54 | c <<= 1; /* to test next bit */ 55 | } 56 | res |= ((c & 0x7F) << (count * 5)); /* add first byte */ 57 | if (count > 3 || res > MAXUNICODE || res <= limits[count]) 58 | return NULL; /* invalid byte sequence */ 59 | s += count; /* skip continuation bytes read */ 60 | } 61 | if (val) *val = res; 62 | return (const char *)s + 1; /* +1 to include first byte */ 63 | } 64 | 65 | 66 | /* 67 | ** utf8len(s [, i [, j]]) --> number of characters that start in the 68 | ** range [i,j], or nil + current position if 's' is not well formed in 69 | ** that interval 70 | */ 71 | static int utflen (lua_State *L) { 72 | int n = 0; 73 | size_t len; 74 | const char *s = luaL_checklstring(L, 1, &len); 75 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); 76 | lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len); 77 | luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2, 78 | "initial position out of string"); 79 | luaL_argcheck(L, --posj < (lua_Integer)len, 3, 80 | "final position out of string"); 81 | while (posi <= posj) { 82 | const char *s1 = utf8_decode(s + posi, NULL); 83 | if (s1 == NULL) { /* conversion error? */ 84 | lua_pushnil(L); /* return nil ... */ 85 | lua_pushinteger(L, posi + 1); /* ... and current position */ 86 | return 2; 87 | } 88 | posi = s1 - s; 89 | n++; 90 | } 91 | lua_pushinteger(L, n); 92 | return 1; 93 | } 94 | 95 | 96 | /* 97 | ** codepoint(s, [i, [j]]) -> returns codepoints for all characters 98 | ** that start in the range [i,j] 99 | */ 100 | static int codepoint (lua_State *L) { 101 | size_t len; 102 | const char *s = luaL_checklstring(L, 1, &len); 103 | lua_Integer posi = u_posrelat(luaL_optinteger(L, 2, 1), len); 104 | lua_Integer pose = u_posrelat(luaL_optinteger(L, 3, posi), len); 105 | int n; 106 | const char *se; 107 | luaL_argcheck(L, posi >= 1, 2, "out of range"); 108 | luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of range"); 109 | if (posi > pose) return 0; /* empty interval; return no values */ 110 | if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */ 111 | return luaL_error(L, "string slice too long"); 112 | n = (int)(pose - posi) + 1; 113 | luaL_checkstack(L, n, "string slice too long"); 114 | n = 0; 115 | se = s + pose; 116 | for (s += posi - 1; s < se;) { 117 | int code; 118 | s = utf8_decode(s, &code); 119 | if (s == NULL) 120 | return luaL_error(L, "invalid UTF-8 code"); 121 | lua_pushinteger(L, code); 122 | n++; 123 | } 124 | return n; 125 | } 126 | 127 | 128 | static void pushutfchar (lua_State *L, int arg) { 129 | lua_Integer code = luaL_checkinteger(L, arg); 130 | luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range"); 131 | lua_pushfstring(L, "%U", (long)code); 132 | } 133 | 134 | 135 | /* 136 | ** utfchar(n1, n2, ...) -> char(n1)..char(n2)... 137 | */ 138 | static int utfchar (lua_State *L) { 139 | int n = lua_gettop(L); /* number of arguments */ 140 | if (n == 1) /* optimize common case of single char */ 141 | pushutfchar(L, 1); 142 | else { 143 | int i; 144 | luaL_Buffer b; 145 | luaL_buffinit(L, &b); 146 | for (i = 1; i <= n; i++) { 147 | pushutfchar(L, i); 148 | luaL_addvalue(&b); 149 | } 150 | luaL_pushresult(&b); 151 | } 152 | return 1; 153 | } 154 | 155 | 156 | /* 157 | ** offset(s, n, [i]) -> index where n-th character counting from 158 | ** position 'i' starts; 0 means character at 'i'. 159 | */ 160 | static int byteoffset (lua_State *L) { 161 | size_t len; 162 | const char *s = luaL_checklstring(L, 1, &len); 163 | lua_Integer n = luaL_checkinteger(L, 2); 164 | lua_Integer posi = (n >= 0) ? 1 : len + 1; 165 | posi = u_posrelat(luaL_optinteger(L, 3, posi), len); 166 | luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, 167 | "position out of range"); 168 | if (n == 0) { 169 | /* find beginning of current byte sequence */ 170 | while (posi > 0 && iscont(s + posi)) posi--; 171 | } 172 | else { 173 | if (iscont(s + posi)) 174 | luaL_error(L, "initial position is a continuation byte"); 175 | if (n < 0) { 176 | while (n < 0 && posi > 0) { /* move back */ 177 | do { /* find beginning of previous character */ 178 | posi--; 179 | } while (posi > 0 && iscont(s + posi)); 180 | n++; 181 | } 182 | } 183 | else { 184 | n--; /* do not move for 1st character */ 185 | while (n > 0 && posi < (lua_Integer)len) { 186 | do { /* find beginning of next character */ 187 | posi++; 188 | } while (iscont(s + posi)); /* (cannot pass final '\0') */ 189 | n--; 190 | } 191 | } 192 | } 193 | if (n == 0) /* did it find given character? */ 194 | lua_pushinteger(L, posi + 1); 195 | else /* no such character */ 196 | lua_pushnil(L); 197 | return 1; 198 | } 199 | 200 | 201 | static int iter_aux (lua_State *L) { 202 | size_t len; 203 | const char *s = luaL_checklstring(L, 1, &len); 204 | lua_Integer n = lua_tointeger(L, 2) - 1; 205 | if (n < 0) /* first iteration? */ 206 | n = 0; /* start from here */ 207 | else if (n < (lua_Integer)len) { 208 | n++; /* skip current byte */ 209 | while (iscont(s + n)) n++; /* and its continuations */ 210 | } 211 | if (n >= (lua_Integer)len) 212 | return 0; /* no more codepoints */ 213 | else { 214 | int code; 215 | const char *next = utf8_decode(s + n, &code); 216 | if (next == NULL || iscont(next)) 217 | return luaL_error(L, "invalid UTF-8 code"); 218 | lua_pushinteger(L, n + 1); 219 | lua_pushinteger(L, code); 220 | return 2; 221 | } 222 | } 223 | 224 | 225 | static int iter_codes (lua_State *L) { 226 | luaL_checkstring(L, 1); 227 | lua_pushcfunction(L, iter_aux); 228 | lua_pushvalue(L, 1); 229 | lua_pushinteger(L, 0); 230 | return 3; 231 | } 232 | 233 | 234 | /* pattern to match a single UTF-8 character */ 235 | #define UTF8PATT "[\0-\x7F\xC2-\xF4][\x80-\xBF]*" 236 | 237 | 238 | static const luaL_Reg funcs[] = { 239 | {"offset", byteoffset}, 240 | {"codepoint", codepoint}, 241 | {"char", utfchar}, 242 | {"len", utflen}, 243 | {"codes", iter_codes}, 244 | /* placeholders */ 245 | {"charpattern", NULL}, 246 | {NULL, NULL} 247 | }; 248 | 249 | 250 | LUAMOD_API int luaopen_utf8 (lua_State *L) { 251 | luaL_newlib(L, funcs); 252 | lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1); 253 | lua_setfield(L, -2, "charpattern"); 254 | return 1; 255 | } 256 | 257 | -------------------------------------------------------------------------------- /luadbg/lua_src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.40 2016/01/05 16:07:21 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #if !defined(LUA_NOCVTN2S) 17 | #define cvt2str(o) ttisnumber(o) 18 | #else 19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */ 20 | #endif 21 | 22 | 23 | #if !defined(LUA_NOCVTS2N) 24 | #define cvt2num(o) ttisstring(o) 25 | #else 26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */ 27 | #endif 28 | 29 | 30 | /* 31 | ** You can define LUA_FLOORN2I if you want to convert floats to integers 32 | ** by flooring them (instead of raising an error if they are not 33 | ** integral values) 34 | */ 35 | #if !defined(LUA_FLOORN2I) 36 | #define LUA_FLOORN2I 0 37 | #endif 38 | 39 | 40 | #define tonumber(o,n) \ 41 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 42 | 43 | #define tointeger(o,i) \ 44 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I)) 45 | 46 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 47 | 48 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 49 | 50 | 51 | /* 52 | ** fast track for 'gettable': if 't' is a table and 't[k]' is not nil, 53 | ** return 1 with 'slot' pointing to 't[k]' (final result). Otherwise, 54 | ** return 0 (meaning it will have to check metamethod) with 'slot' 55 | ** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise). 56 | ** 'f' is the raw get function to use. 57 | */ 58 | #define luaV_fastget(L,t,k,slot,f) \ 59 | (!ttistable(t) \ 60 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 61 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ 62 | !ttisnil(slot))) /* result not nil? */ 63 | 64 | /* 65 | ** standard implementation for 'gettable' 66 | */ 67 | #define luaV_gettable(L,t,k,v) { const TValue *slot; \ 68 | if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \ 69 | else luaV_finishget(L,t,k,v,slot); } 70 | 71 | 72 | /* 73 | ** Fast track for set table. If 't' is a table and 't[k]' is not nil, 74 | ** call GC barrier, do a raw 't[k]=v', and return true; otherwise, 75 | ** return false with 'slot' equal to NULL (if 't' is not a table) or 76 | ** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro 77 | ** returns true, there is no need to 'invalidateTMcache', because the 78 | ** call is not creating a new entry. 79 | */ 80 | #define luaV_fastset(L,t,k,slot,f,v) \ 81 | (!ttistable(t) \ 82 | ? (slot = NULL, 0) \ 83 | : (slot = f(hvalue(t), k), \ 84 | ttisnil(slot) ? 0 \ 85 | : (luaC_barrierback(L, hvalue(t), v), \ 86 | setobj2t(L, cast(TValue *,slot), v), \ 87 | 1))) 88 | 89 | 90 | #define luaV_settable(L,t,k,v) { const TValue *slot; \ 91 | if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \ 92 | luaV_finishset(L,t,k,v,slot); } 93 | 94 | 95 | 96 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 97 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 98 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 99 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 100 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); 101 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 102 | StkId val, const TValue *slot); 103 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 104 | StkId val, const TValue *slot); 105 | LUAI_FUNC void luaV_finishOp (lua_State *L); 106 | LUAI_FUNC void luaV_execute (lua_State *L); 107 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 108 | LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); 109 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 110 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 111 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /luadbg/lua_src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.37 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /luadbg/lua_src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.31 2015/09/08 15:41:05 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /luadbg/luadbg.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | lua 4 | luacmd 5 | luaload 6 | luaunload 7 | luado 8 | lualist 9 | ;-------------------------------------------------------------------- 10 | ; 11 | ; these are the extension service functions provided for the debugger 12 | ; 13 | ;-------------------------------------------------------------------- 14 | 15 | DebugExtensionNotify 16 | DebugExtensionInitialize 17 | DebugExtensionUninitialize 18 | -------------------------------------------------------------------------------- /luadbg/luadbg.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0cch/luadbg/96957b08e8aae623f088b50a05bb3ee1177c72df/luadbg/luadbg.rc -------------------------------------------------------------------------------- /luadbg/luadbg.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {806415C6-30D2-46EE-853E-97EA20154953} 23 | Win32Proj 24 | luadbg 25 | 26 | 27 | 28 | DynamicLibrary 29 | true 30 | Unicode 31 | 32 | 33 | DynamicLibrary 34 | true 35 | Unicode 36 | 37 | 38 | DynamicLibrary 39 | false 40 | true 41 | Unicode 42 | 43 | 44 | DynamicLibrary 45 | false 46 | true 47 | Unicode 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | true 67 | 68 | 69 | true 70 | 71 | 72 | false 73 | 74 | 75 | false 76 | 77 | 78 | 79 | NotUsing 80 | Level3 81 | Disabled 82 | WIN32;_DEBUG;_WINDOWS;_USRDLL;LUADBG_EXPORTS;%(PreprocessorDefinitions) 83 | ./inc;./lua_src;%(AdditionalIncludeDirectories) 84 | 85 | 86 | Windows 87 | true 88 | luadbg.def 89 | %(AdditionalLibraryDirectories) 90 | 91 | 92 | 93 | 94 | NotUsing 95 | Level3 96 | Disabled 97 | WIN32;_DEBUG;_WINDOWS;_USRDLL;LUADBG_EXPORTS;%(PreprocessorDefinitions) 98 | ./inc;./lua_src;%(AdditionalIncludeDirectories) 99 | 100 | 101 | Windows 102 | true 103 | luadbg.def 104 | %(AdditionalLibraryDirectories) 105 | 106 | 107 | 108 | 109 | Level3 110 | NotUsing 111 | MaxSpeed 112 | true 113 | true 114 | WIN32;NDEBUG;_WINDOWS;_USRDLL;LUADBG_EXPORTS;%(PreprocessorDefinitions) 115 | ./inc;./lua_src;%(AdditionalIncludeDirectories) 116 | 117 | 118 | Windows 119 | true 120 | true 121 | true 122 | luadbg.def 123 | %(AdditionalLibraryDirectories) 124 | 125 | 126 | 127 | 128 | Level3 129 | NotUsing 130 | MaxSpeed 131 | true 132 | true 133 | WIN32;NDEBUG;_WINDOWS;_USRDLL;LUADBG_EXPORTS;%(PreprocessorDefinitions) 134 | ./inc;./lua_src;%(AdditionalIncludeDirectories) 135 | 136 | 137 | Windows 138 | true 139 | true 140 | true 141 | luadbg.def 142 | %(AdditionalLibraryDirectories) 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | false 157 | false 158 | 159 | 160 | 161 | 162 | false 163 | false 164 | 165 | 166 | 167 | 168 | 169 | 170 | NotUsing 171 | NotUsing 172 | NotUsing 173 | NotUsing 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | Create 211 | Create 212 | Create 213 | Create 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /luadbg/luadbg.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {9c3a7509-54e0-40f9-820a-e90e116425f5} 18 | 19 | 20 | 21 | 22 | 23 | Source Files 24 | 25 | 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | luasrc 52 | 53 | 54 | luasrc 55 | 56 | 57 | luasrc 58 | 59 | 60 | luasrc 61 | 62 | 63 | luasrc 64 | 65 | 66 | luasrc 67 | 68 | 69 | luasrc 70 | 71 | 72 | luasrc 73 | 74 | 75 | luasrc 76 | 77 | 78 | luasrc 79 | 80 | 81 | luasrc 82 | 83 | 84 | luasrc 85 | 86 | 87 | luasrc 88 | 89 | 90 | luasrc 91 | 92 | 93 | luasrc 94 | 95 | 96 | luasrc 97 | 98 | 99 | luasrc 100 | 101 | 102 | luasrc 103 | 104 | 105 | luasrc 106 | 107 | 108 | luasrc 109 | 110 | 111 | luasrc 112 | 113 | 114 | luasrc 115 | 116 | 117 | luasrc 118 | 119 | 120 | luasrc 121 | 122 | 123 | luasrc 124 | 125 | 126 | luasrc 127 | 128 | 129 | luasrc 130 | 131 | 132 | luasrc 133 | 134 | 135 | luasrc 136 | 137 | 138 | luasrc 139 | 140 | 141 | luasrc 142 | 143 | 144 | luasrc 145 | 146 | 147 | luasrc 148 | 149 | 150 | 151 | 152 | Resource Files 153 | 154 | 155 | -------------------------------------------------------------------------------- /luadbg/luadbg_v15.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {9602486e-e30c-4cae-8a6a-34b424965ea8} 18 | 19 | 20 | 21 | 22 | 23 | Source Files 24 | 25 | 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | luasrc 52 | 53 | 54 | luasrc 55 | 56 | 57 | luasrc 58 | 59 | 60 | luasrc 61 | 62 | 63 | luasrc 64 | 65 | 66 | luasrc 67 | 68 | 69 | luasrc 70 | 71 | 72 | luasrc 73 | 74 | 75 | luasrc 76 | 77 | 78 | luasrc 79 | 80 | 81 | luasrc 82 | 83 | 84 | luasrc 85 | 86 | 87 | luasrc 88 | 89 | 90 | luasrc 91 | 92 | 93 | luasrc 94 | 95 | 96 | luasrc 97 | 98 | 99 | luasrc 100 | 101 | 102 | luasrc 103 | 104 | 105 | luasrc 106 | 107 | 108 | luasrc 109 | 110 | 111 | luasrc 112 | 113 | 114 | luasrc 115 | 116 | 117 | luasrc 118 | 119 | 120 | luasrc 121 | 122 | 123 | luasrc 124 | 125 | 126 | luasrc 127 | 128 | 129 | luasrc 130 | 131 | 132 | luasrc 133 | 134 | 135 | luasrc 136 | 137 | 138 | luasrc 139 | 140 | 141 | luasrc 142 | 143 | 144 | luasrc 145 | 146 | 147 | luasrc 148 | 149 | 150 | 151 | 152 | Resource Files 153 | 154 | 155 | -------------------------------------------------------------------------------- /luadbg/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by luadbg.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /luadbg/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // luadbg.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /luadbg/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 11 | // Windows Header Files: 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "wdbgexts.h" 24 | #include "dbgeng.h" 25 | 26 | #pragma comment(lib, "dbghelp.lib") 27 | #pragma comment(lib, "dbgeng.lib") 28 | 29 | 30 | // TODO: reference additional headers your program requires here 31 | -------------------------------------------------------------------------------- /luadbg/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /luadbg_v15.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "luadbg_v15", "luadbg\luadbg_v15.vcxproj", "{806415C6-30D2-46EE-853E-97EA20154953}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {806415C6-30D2-46EE-853E-97EA20154953}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {806415C6-30D2-46EE-853E-97EA20154953}.Debug|Win32.Build.0 = Debug|Win32 18 | {806415C6-30D2-46EE-853E-97EA20154953}.Debug|x64.ActiveCfg = Debug|x64 19 | {806415C6-30D2-46EE-853E-97EA20154953}.Debug|x64.Build.0 = Debug|x64 20 | {806415C6-30D2-46EE-853E-97EA20154953}.Release|Win32.ActiveCfg = Release|Win32 21 | {806415C6-30D2-46EE-853E-97EA20154953}.Release|Win32.Build.0 = Release|Win32 22 | {806415C6-30D2-46EE-853E-97EA20154953}.Release|x64.ActiveCfg = Release|x64 23 | {806415C6-30D2-46EE-853E-97EA20154953}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /module_test.lua: -------------------------------------------------------------------------------- 1 | a = dbgmodule.new("ntdll") 2 | print("a name=",a:name()) 3 | print("a addr=",a:addr()) 4 | print("a NtCreateFile=", a.NtCreateFile) 5 | 6 | b = dbgtype.new("ntdll!_peb", evalmasm("@$peb")) 7 | print("_peb name=", b:name()) 8 | print("_peb addr=", b:addr()) 9 | print("_peb size=", b:size()) 10 | print("_peb ProcessParameters offset=", b:fieldoffset("ProcessParameters")) 11 | print("_peb ProcessParameters type=", b:fieldtype("ProcessParameters")) 12 | print("(*_peb.ProcessParameters).MaximumLength=", b.ProcessParameters:deref().MaximumLength) 13 | print("_peb.AppCompatFlags.QuadPart=", b.AppCompatFlags.QuadPart) 14 | print("_peb.UserSharedInfoPtr addr=", string.format("%x",b.UserSharedInfoPtr:addr())) 15 | print("_peb.TlsExpansionBitmapBits[0]=", b.TlsExpansionBitmapBits[0]) --------------------------------------------------------------------------------