<HTML><BODY><div>Hi, Sergey!</div><div>Thanks for the review!</div><div> </div><div>Here is the new commit message:</div><div>==========================================================================</div><div><div><div>test: adapt tests checking debug line hook trace</div></div><div> </div><div>The LuaJIT's virtual machine interprets the bytecode</div><div><div>following the return from function (i.e. the one succeeding</div><div>the call made) and located on the line other than that return</div><div>bytecode, as a new line trigger for line hooks, unlike Lua</div><div>does.</div><div>Here is an example (it is joined in one line intend):</div></div><div> </div><div><div>debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook()</div></div><div> </div><div>This chunk prints for LuaJIT:</div><div> </div><div><div>LINE: 3</div><div>LINE: 1</div></div><div> </div><div><div>But for Lua 5.1 it is only "LINE: 3" in the output.</div></div><div> </div><div>Those tests are adapted to LuaJIT behavior by changing assertions</div><div><div>considering line events that LuaJIT generates.</div></div><div> </div><div><div>Part of tarantool/tarantool#5870</div><div>Resolves tarantool/tarantool#5693.</div></div></div><div>==========================================================================</div><div> </div><div>And here is the diff:</div><div>==========================================================================</div><div><div><div>diff --git a/test/PUC-Rio-Lua-5.1-tests/db.lua b/test/PUC-Rio-Lua-5.1-tests/db.lua</div><div>index 120fc04c..36adc709 100644</div><div>--- a/test/PUC-Rio-Lua-5.1-tests/db.lua</div><div>+++ b/test/PUC-Rio-Lua-5.1-tests/db.lua</div><div>@@ -24,7 +24,8 @@ LINE: 1</div><div> --]]</div><div> -- But for Lua 5.1 it is only "LINE: 3" in the output.</div><div> -- See also https://github.com/tarantool/tarantool/issues/5693.</div><div>--- This function is modified to correspond with LuaJIT's line triggers.</div><div>+-- This function is modified to correspond with LuaJIT's</div><div>+-- line triggers.</div><div> function test (s, l, p)</div><div>   collectgarbage()   -- avoid gc during trace</div><div>   local function f (event, line)</div><div>@@ -33,11 +34,12 @@ function test (s, l, p)</div><div>     if p then print(l, line) end</div><div>     assert(l == line, "wrong trace!!")</div><div>   end</div><div>-  -- Despite `loadstring` and `debug.sethook` are on the same line, LuaJIT</div><div>-  -- generates separate line events for them. The test is adapted to LuaJIT</div><div>-  -- behavior by adding corresponding line numbers into the test table.</div><div>-  table.insert(l, 1, 41)</div><div>-  table.insert(l, 41)</div><div>+  -- Despite `loadstring` and `debug.sethook` are on the same</div><div>+  -- line, LuaJIT generates separate line events for them. The</div><div>+  -- test is adapted to LuaJIT behavior by adding corresponding</div><div>+  -- line numbers into the test table.</div><div>+  table.insert(l, 1, 43)</div><div>+  table.insert(l, 43)</div><div>   debug.sethook(f,"l"); loadstring(s)(); debug.sethook()</div><div>   assert(table.getn(l) == 0)</div><div> end</div><div>@@ -47,8 +49,8 @@ do</div><div>   local a = debug.getinfo(print)</div><div>   assert(a.what == "C" and a.short_src == "[C]")</div><div>   local b = debug.getinfo(test, "SfL")</div><div>-  assert(b.name == nil and b.what == "Lua" and b.linedefined == 28 and</div><div>-         b.lastlinedefined == b.linedefined + 15 and</div><div>+  assert(b.name == nil and b.what == "Lua" and b.linedefined == 29 and</div><div>+         b.lastlinedefined == b.linedefined + 16 and</div><div>          b.func == test and not string.find(b.short_src, "%["))</div><div>   assert(b.activelines[b.linedefined + 1] and</div><div>          b.activelines[b.lastlinedefined])</div><div>@@ -172,8 +174,9 @@ test([[for i,v in pairs{'a','b'} do</div><div> end</div><div> ]], {1,2,1,2,1,3})</div><div> </div><div>--- Test is adapted to the behaviour of LuaJIT, as it generates only four line</div><div>--- events, unlike Lua, which generates five of them.</div><div>+-- Test is adapted to the behaviour of LuaJIT, as it generates</div><div>+-- only four line events, unlike Lua, which generates five</div><div>+-- of them.</div><div> test([[for i=1,4 do a=1 end]], {1,1,1,1})</div></div></div><div>==========================================================================</div><div> </div><div>New CI branch: <a href="https://github.com/tarantool/tarantool/tree/fckxorg/gh-5693-PUC-Rio-debug-line-hook-full-ci">https://github.com/tarantool/tarantool/tree/fckxorg/gh-5693-PUC-Rio-debug-line-hook-full-ci</a></div><div> </div><div>Best regards,</div><div>Maxim Kokryashkin</div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div> <blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;"><div id=""><div class="js-helper js-readmsg-msg"><div><div id="style_16396683971367256571_BODY">Hi, Maxim!<br>Thanks for the fixes!<br><br>LGTM, except a few nits below.<br><br>Am I right that this CI branch [1] is the latest one?<br><br>Also, please align comments with linewidth 66 symbols.<br><br>On 10.11.21, Maxim Kokryashkin wrote:<br>> The LuaJIT's virtual machine interprets the bytecode<br>> following the return from function (i.e. the one succeeding<br>> the call made) and located on the line other than that return<br>> bytecode, as a new line trigger for line hooks, unlike Lua<br>> does.<br>> Here is an example (it is joined in one line intend):<br>><br>> debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook()<br>><br>> This chunk prints for LuaJIT:<br>><br>> LINE: 3<br>> LINE: 1<br>><br>> But for Lua 5.1 it is only "LINE: 3" in the output.<br>> See also tarantool/tarantool#5693.<br><br>Nit: this see also is excess (as far as this patch resolves the ticket).<br><br>><br>> Those tests are adapted to LuaJIT behavior by changing assertions<br>> considering line events that LuaJIT generates.<br>><br>> Part of tarantool/tarantool#5870<br><br>It's OK to mention that this patch "Resolves tarantool/tarantool#5693".<br><br>> ---<br>> Changes in v2:<br>> - Fixed comments as per review by Sergey<br>> - Added some comments<br>><br>> test/PUC-Rio-Lua-5.1-tests/db.lua | 57 +++++++++++++++++--------------<br>> 1 file changed, 31 insertions(+), 26 deletions(-)<br>><br>> diff --git a/test/PUC-Rio-Lua-5.1-tests/db.lua b/test/PUC-Rio-Lua-5.1-tests/db.lua<br>> index 56f59ea8..120fc04c 100644<br>> --- a/test/PUC-Rio-Lua-5.1-tests/db.lua<br>> +++ b/test/PUC-Rio-Lua-5.1-tests/db.lua<br>> @@ -8,6 +8,23 @@ do<br>> local a=1<br>> end<br>><br>> +-- The LuaJIT's virtual machine interprets the bytecode<br>> +-- following the return from function (i.e. the one succeeding<br>> +-- the call made) and located on the line other than that return<br>> +-- bytecode, as a new line trigger for line hooks, unlike Lua<br>> +-- does.<br>> +-- Here is an example (it is joined in one line intend):<br>> +--[[<br>> +debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook()<br>> +--]]<br>> +-- This chunk prints for LuaJIT:<br>> +--[[<br>> +LINE: 3<br>> +LINE: 1<br>> +--]]<br>> +-- But for Lua 5.1 it is only "LINE: 3" in the output.<br>> +-- See also <a href="https://github.com/tarantool/tarantool/issues/5693" target="_blank">https://github.com/tarantool/tarantool/issues/5693</a>.<br>> +-- This function is modified to correspond with LuaJIT's line triggers.<br>> function test (s, l, p)<br>> collectgarbage() -- avoid gc during trace<br>> local function f (event, line)<br>> @@ -16,6 +33,11 @@ function test (s, l, p)<br>> if p then print(l, line) end<br>> assert(l == line, "wrong trace!!")<br>> end<br>> + -- Despite `loadstring` and `debug.sethook` are on the same line, LuaJIT<br>> + -- generates separate line events for them. The test is adapted to LuaJIT<br>> + -- behavior by adding corresponding line numbers into the test table.<br>> + table.insert(l, 1, 41)<br>> + table.insert(l, 41)<br>> debug.sethook(f,"l"); loadstring(s)(); debug.sethook()<br>> assert(table.getn(l) == 0)<br>> end<br>> @@ -25,8 +47,8 @@ do<br>> local a = debug.getinfo(print)<br>> assert(a.what == "C" and a.short_src == "[C]")<br>> local b = debug.getinfo(test, "SfL")<br>> - assert(b.name == nil and b.what == "Lua" and b.linedefined == 11 and<br>> - b.lastlinedefined == b.linedefined + 10 and<br>> + assert(b.name == nil and b.what == "Lua" and b.linedefined == 28 and<br>> + b.lastlinedefined == b.linedefined + 15 and<br>> b.func == test and not string.find(b.short_src, "%["))<br>> assert(b.activelines[b.linedefined + 1] and<br>> b.activelines[b.lastlinedefined])<br>> @@ -95,26 +117,6 @@ repeat<br>> assert(g(f) == 'a')<br>> until 1<br>><br>> --- FIXME: The LuaJIT's virtual machine interprets the bytecode<br>> --- following the return from function (i.e. the one succeeding<br>> --- the call made) and located on the line other than that return<br>> --- bytecode, as a new line trigger for line hooks, unlike Lua<br>> --- does.<br>> --- Here is an example (it is joined in one line intend):<br>> ---[[<br>> -debug.sethook(function(_, l) print("LINE: "..l) end, "l") loadstring("\n\ns=nil")() debug.sethook()<br>> ---]]<br>> --- This chunk prints for LuaJIT:<br>> ---[[<br>> -LINE: 3<br>> -LINE: 1<br>> ---]]<br>> --- But for Lua 5.1 it is only "LINE: 3" in the output.<br>> --- See also <a href="https://github.com/tarantool/tarantool/issues/5693" target="_blank">https://github.com/tarantool/tarantool/issues/5693</a>.<br>> --- Considering implementation-defined behaviour difference<br>> --- (see also <a href="https://luajit.org/status.html" target="_blank">https://luajit.org/status.html</a>) test is disabled for<br>> --- LuaJIT.<br>> ---[=[<br>> test([[if<br>> math.sin(1)<br>> then<br>> @@ -132,23 +134,25 @@ else<br>> end<br>> ]], {2,5,6})<br>><br>> +-- Test is adapted to the behaviour of LuaJIT.<br>> test([[a=1<br>> repeat<br>> a=a+1<br>> until a==3<br>> -]], {1,3,4,3,4})<br>> +]], {1,2,3,4,2,3,4})<br>><br>> test([[ do<br>> return<br>> end<br>> ]], {2})<br>><br>> +-- Test is adapted to the behaviour of LuaJIT.<br>> test([[local a<br>> a=1<br>> while a<=3 do<br>> a=a+1<br>> end<br>> -]], {2,3,4,3,4,3,4,3,5})<br>> +]], {1,2,3,4,3,4,3,4,3,5})<br>><br>> test([[while math.sin(1) do<br>> if math.sin(1)<br>> @@ -168,8 +172,9 @@ test([[for i,v in pairs{'a','b'} do<br>> end<br>> ]], {1,2,1,2,1,3})<br>><br>> -test([[for i=1,4 do a=1 end]], {1,1,1,1,1})<br>> ---]=]<br>> +-- Test is adapted to the behaviour of LuaJIT, as it generates only four line<br>> +-- events, unlike Lua, which generates five of them.<br>> +test([[for i=1,4 do a=1 end]], {1,1,1,1})<br>><br>><br>> print'+'<br>> --<br>> 2.33.0<br>><br><br>[1]:<br><a href="https://github.com/tarantool/tarantool/tree/fckxorg/gh-5693-PUC-Rio-debug-line-hook" target="_blank">https://github.com/tarantool/tarantool/tree/fckxorg/gh-5693-PUC-Rio-debug-line-hook</a><br><br>--<br>Best regards,<br>Sergey Kaplun</div></div></div></div></blockquote><div> </div></div></blockquote></BODY></HTML>