aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-27 13:23:05 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-27 13:23:05 -0300
commitae5b5ba529753c7a653901ffc29b5ea24c3fdf3a (patch)
tree7b1978d77887e38b486accaf7412cc84668e4560
parenta585eae6e7ada1ca9271607a4f48dfb17868ab7b (diff)
downloadlua-ae5b5ba529753c7a653901ffc29b5ea24c3fdf3a.tar.gz
lua-ae5b5ba529753c7a653901ffc29b5ea24c3fdf3a.tar.bz2
lua-ae5b5ba529753c7a653901ffc29b5ea24c3fdf3a.zip
Fixed bug: line hooks in stripped functions
Line-hook handling was accessing debug info. without checking whether it was present.
-rw-r--r--ldebug.c4
-rw-r--r--testes/db.lua19
2 files changed, 21 insertions, 2 deletions
diff --git a/ldebug.c b/ldebug.c
index 9ff7edeb..8cb00e51 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -783,11 +783,13 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
783** previous instruction 'oldpc'. 783** previous instruction 'oldpc'.
784*/ 784*/
785static int changedline (const Proto *p, int oldpc, int newpc) { 785static int changedline (const Proto *p, int oldpc, int newpc) {
786 if (p->lineinfo == NULL) /* no debug information? */
787 return 0;
786 while (oldpc++ < newpc) { 788 while (oldpc++ < newpc) {
787 if (p->lineinfo[oldpc] != 0) 789 if (p->lineinfo[oldpc] != 0)
788 return (luaG_getfuncline(p, oldpc - 1) != luaG_getfuncline(p, newpc)); 790 return (luaG_getfuncline(p, oldpc - 1) != luaG_getfuncline(p, newpc));
789 } 791 }
790 return 0; /* no line changes in the way */ 792 return 0; /* no line changes between positions */
791} 793}
792 794
793 795
diff --git a/testes/db.lua b/testes/db.lua
index 941283f7..5377f6ec 100644
--- a/testes/db.lua
+++ b/testes/db.lua
@@ -884,7 +884,7 @@ end
884 884
885 885
886print("testing debug functions on chunk without debug info") 886print("testing debug functions on chunk without debug info")
887prog = [[-- program to be loaded without debug information 887prog = [[-- program to be loaded without debug information (strip)
888local debug = require'debug' 888local debug = require'debug'
889local a = 12 -- a local variable 889local a = 12 -- a local variable
890 890
@@ -927,6 +927,23 @@ local f = assert(load(string.dump(load(prog), true)))
927 927
928assert(f() == 13) 928assert(f() == 13)
929 929
930do -- bug in 5.4.0: line hooks in stripped code
931 local function foo ()
932 local a = 1
933 local b = 2
934 return b
935 end
936
937 local s = load(string.dump(foo, true))
938 local line = true
939 debug.sethook(function (e, l)
940 assert(e == "line")
941 line = l
942 end, "l")
943 assert(s() == 2); debug.sethook(nil)
944 assert(line == nil) -- hook called withoug debug info for 1st instruction
945end
946
930do -- tests for 'source' in binary dumps 947do -- tests for 'source' in binary dumps
931 local prog = [[ 948 local prog = [[
932 return function (x) 949 return function (x)