Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fixed bug: line hooks in stripped functions
Line-hook handling was accessing debug info. without checking whether
it was present.
  • Loading branch information
roberto-ieru committed Jul 27, 2020
1 parent a585eae commit ae5b5ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ldebug.c
Expand Up @@ -783,11 +783,13 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
** previous instruction 'oldpc'.
*/
static int changedline (const Proto *p, int oldpc, int newpc) {
if (p->lineinfo == NULL) /* no debug information? */
return 0;
while (oldpc++ < newpc) {
if (p->lineinfo[oldpc] != 0)
return (luaG_getfuncline(p, oldpc - 1) != luaG_getfuncline(p, newpc));
}
return 0; /* no line changes in the way */
return 0; /* no line changes between positions */
}


Expand Down
19 changes: 18 additions & 1 deletion testes/db.lua
Expand Up @@ -884,7 +884,7 @@ end


print("testing debug functions on chunk without debug info")
prog = [[-- program to be loaded without debug information
prog = [[-- program to be loaded without debug information (strip)
local debug = require'debug'
local a = 12 -- a local variable
Expand Down Expand Up @@ -927,6 +927,23 @@ local f = assert(load(string.dump(load(prog), true)))

assert(f() == 13)

do -- bug in 5.4.0: line hooks in stripped code
local function foo ()
local a = 1
local b = 2
return b
end

local s = load(string.dump(foo, true))
local line = true
debug.sethook(function (e, l)
assert(e == "line")
line = l
end, "l")
assert(s() == 2); debug.sethook(nil)
assert(line == nil) -- hook called withoug debug info for 1st instruction
end

do -- tests for 'source' in binary dumps
local prog = [[
return function (x)
Expand Down

0 comments on commit ae5b5ba

Please sign in to comment.