From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 5FBD46F864; Fri, 4 Dec 2026 23:04:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5FBD46F864 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1796414691; bh=vyIV5nLYX4/vYa2lBPLYDPRFP9gMqa8qbL/3noO1QAU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Ck7T1iyY4cMonSxmHgHit+02OB2Co+QaWjp1yR9TrLqdw1YAVI7Hu4MqLSKbhDq7a 8v7C1kHcCCaI5m1lzq/xrmeqXIvLf5rPETAjcTFNx+jCgUWvWO12BlsI+6QaBXNwk0 +rz4L90kLB5Y0PX0L2FgUZSRUwJn2RXLdvTmOQfc= Received: from send174.i.mail.ru (send174.i.mail.ru [95.163.59.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 94E0D6F864 for ; Fri, 4 Dec 2026 23:03:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 94E0D6F864 Received: by exim-smtp-654cd6fddf-k5fh4 with esmtpa (envelope-from ) id 1xZZV2-00000000BLH-41SE; Fri, 04 Dec 2026 23:03:21 +0300 To: Sergey Kaplun , Sergey Bronnikov , Evgeniy Temirgaleev Date: Fri, 4 Dec 2026 23:03:04 +0300 Message-ID: <10189fbca6be567d54795a24179fe8105ede822a.1796410322.git.m.elhimov@vk.team> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-618D5548: 40581BF15683D4E033594132A326AF8B87671813BF1953501F67736ADFEE08CC2B707D9E90ECD5E3 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD93D020E295BD594874E4ABECB93D4B0328F818289A16FA633182A05F5380850404C228DA9ACA6FE2723F48B285DCB79523DE06ABAFEAF67055D50ECFCE5AA8935D6A80CCE374E938A2F7B8F85B30CF495 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7F6EE1C40B2E8BE15EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB55337566DDB58AA132F92B63E85556002FF74F11A2A1BBC6BFCD7AB0CBBAF45C2F5638F18EEF46B7454FC60B9742502CCDD46D0D062BEEFFB5F8EA3EBA3038C0950A5D36D5E8D9A59859A8B60EB4BD9B449F67A576E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A3920E30A4C9C8E338DA08981F302C1AC52F43847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A554710B807644E5375002B1117B3ED696AE6F621B47D010C2E772F934B9BCD185C21EFC0AA0C58C2ABFBD89AD4F5B216C1E618B5D5F965AFD06CBA4EB72A0A67C6A186E92D2455F1313753DE987AAD7D72AE163D1C3AA1A87BF01DF27239040A731003CB1AAE6ED6E6235F7413FD0BFE82CDDB5C2166FA0C3E99897350C7C491EC627013B076BABB6939BCEF9C803809F171B36006FE6251A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34C77DD89D51EBB774225B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D6598B83D9826861165CA7EFE3288FC7F6E58F1D3980D1090A5B111C930526C9031D4C2B09D253C91DE2B8341EE9D5BE9A0AE93C58BB7D3DB0FC3BD0C96F8DD5C34E32FAF6415725FD719350E1BD188BD56E4C41F94D744909CE9D6718F459EE2962AE54DA86D399E591103B389C0A9E82E8 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWMmolxgYeyMke+eya20PhEY= X-Mailru-Sender: 49D287FBCBBF3A5CED14BED3BAAFB6991669DDA9602C022FB951B70A5BD4BD8E564AD72543D705C052685D71546B8E9EEAA2F645D7D0C73F8B67290C0B8F2C0D12EEFBA914E8A1CE696B58449F085A8023028798991C5DA182F85D6DCAB44FBA5FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit v2 3/7] dbg: handle missing cmd arg in a dbg-agnostic way X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mikhail Elhimov via Tarantool-patches Reply-To: Mikhail Elhimov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" * unified handling of command-level error for consistency (introduced special exception for LLDB that works similar to `gdb.GdbError`, i.e. doesn't cause traceback to be printed) * `dbg.eval` no longer accept `None` argument (previously that way both GDB and LLDB implicitly handled missing command argument which eventually resulted in a poor-informative error) --- src/luajit_dbg.py | 65 ++++++++---- .../debug-extension-tests.py | 98 +++++++++++++++++-- 2 files changed, 133 insertions(+), 30 deletions(-) diff --git a/src/luajit_dbg.py b/src/luajit_dbg.py index cfc3961c..7d8f2766 100644 --- a/src/luajit_dbg.py +++ b/src/luajit_dbg.py @@ -273,9 +273,6 @@ class _GDBDebugger(Debugger): return None def eval(self, expr): - if not expr: - return None - return gdb.parse_and_eval(expr) def detect_arch(self): @@ -672,9 +669,6 @@ class _LLDBDebugger(Debugger): return None def eval(self, expr): - if not expr: - return None - process = self.target.GetProcess() thread = process.GetSelectedThread() frame = thread.GetSelectedFrame() @@ -709,8 +703,13 @@ class _LLDBDebugger(Debugger): def write(self, msg): sys.stdout.write(msg) + class DbgError(Exception): + '''Raised to indicate an error during command execution. + Doesn't cause a traceback to be printed (like gdb.GdbError for GDB).''' + pass + def error(self, errmsg): - return Exception(errmsg) + return self.DbgError(errmsg) def check_libluajit(self): # TODO: Implement postpone loading for LLDB too. @@ -753,12 +752,27 @@ class _LLDBDebugger(Debugger): def __call__(ljbase, debugger, args, exe_ctx, result): try: ljbase.execute(args) - except Exception as e: + except _LLDBDebugger.DbgError as e: msg = 'Failed to execute command `{}`: {}'.format( ljbase.name, e ) result.SetError(msg) + # `result` is an output argument of LLDB command + # handler. If an error message is set, LLDB + # displays it in the session. But such a message + # is missing in the output when the same problem + # occurs in batch mode, so in order to be able to + # catch this kind of error in batch mode it is + # needed to put it into stderr explicitly. + # Also to avoid duplication of the same error + # message in interactive mode, it should be done + # in batch mode only. There is no official way to + # check if LLDB is in the batch mode so one of the + # recommended workarounds is used below that + # checks if tty is not used for standard input. + if not sys.stdin.isatty(): + result.PutError(lldb.SBFile.Create(sys.stderr, True)) @abc.abstractmethod def execute(ljbase, args): @@ -2929,6 +2943,15 @@ def dump_jslots(J): return '\n'.join(dump) +# Extension commands helpers. #################################### + + +def cast_command_arg(typestr, arg): + if not arg: + raise dbg.error('Argument is required') + return dbg.cast(typestr, dbg.eval(arg)) + + # Extension commands. ############################################ @@ -2976,7 +2999,7 @@ https://github.com/tarantool/tarantool/wiki/LuaJIT-Bytecodes. ''' def execute(self, arg): - dbg.print(dump_bc(dbg.cast('BCIns *', dbg.eval(arg))[0])) + dbg.print(dump_bc(cast_command_arg('BCIns *', arg)[0])) class LJDumpCType(dbg.LJBase): @@ -2988,7 +3011,7 @@ and dumps the ID and the name for this C data type. ''' def execute(self, arg): - dbg.print(dump_ctype(dbg.cast('CType *', dbg.eval(arg)))) + dbg.print(dump_ctype(cast_command_arg('CType *', arg))) class LJDumpFunc(dbg.LJBase): @@ -3013,7 +3036,7 @@ function: ''' def execute(self, arg): - dbg.print(dump_func(dbg.cast('GCfuncC *', dbg.eval(arg)))) + dbg.print(dump_func(cast_command_arg('GCfuncC *', arg))) class LJGC(dbg.LJBase): @@ -3068,7 +3091,7 @@ error message occurs. ''' def execute(self, arg): - dbg.print(dump_gcobj(dbg.cast('GCobj *', dbg.eval(arg)))) + dbg.print(dump_gcobj(cast_command_arg('GCobj *', arg))) class LJDumpIR(dbg.LJBase): @@ -3085,7 +3108,7 @@ https://github.com/tarantool/tarantool/wiki/LuaJIT-SSA-IR. ''' def execute(self, arg): - dbg.print(dump_irins(dbg.cast('IRIns *', dbg.eval(arg)))) + dbg.print(dump_irins(cast_command_arg('IRIns *', arg))) class LJDumpJSlots(dbg.LJBase): @@ -3102,7 +3125,8 @@ when there is no coroutine to be inspected in the debugged frame. ''' def execute(self, arg): - dbg.print(dump_jslots(J(G(L(dbg.eval(arg)))))) + lstate = L(dbg.eval(arg) if arg else None) + dbg.print(dump_jslots(J(G(lstate)))) class LJDumpProto(dbg.LJBase): @@ -3127,7 +3151,7 @@ function: ''' def execute(self, arg): - dbg.print(dump_proto(dbg.cast('GCproto *', dbg.eval(arg)))) + dbg.print(dump_proto(cast_command_arg('GCproto *', arg))) class LJDumpStack(dbg.LJBase): @@ -3164,7 +3188,8 @@ If L is omitted, the main coroutine is used. ''' def execute(self, arg): - dbg.print(dump_stack(L(dbg.eval(arg)))) + lstate = L(dbg.eval(arg) if arg else None) + dbg.print(dump_stack(lstate)) class LJState(dbg.LJBase): @@ -3199,7 +3224,7 @@ is replaced with the corresponding error when decoding fails. ''' def execute(self, arg): - string = dbg.cast('GCstr *', dbg.eval(arg)) + string = cast_command_arg('GCstr *', arg) dbg.print("String: {body} [{len} bytes] with hash {hash}".format( body=strdata(string), hash=strx64(string['hash']), @@ -3220,7 +3245,7 @@ The command receives a GCtab address and dumps the table contents: ''' def execute(self, arg): - t = dbg.cast('GCtab *', dbg.eval(arg)) + t = cast_command_arg('GCtab *', arg) array = mref('TValue *', t['array']) nodes = mref('struct Node *', t['node']) mt = gcval(t['metatable']) @@ -3283,7 +3308,7 @@ error message occurs. ''' def execute(self, arg): - dbg.print(dump_tvalue(dbg.cast('TValue *', dbg.eval(arg)))) + dbg.print(dump_tvalue(cast_command_arg('TValue *', arg))) class LJDumpTrace(dbg.LJBase): @@ -3302,7 +3327,7 @@ Trace may be preceded with /FLAGS: def execute(self, arg): arg, flags = dbg.extract_flags(arg, 'rs') - dbg.print(dump_trace(dbg.cast('GCtrace *', dbg.eval(arg)), flags)) + dbg.print(dump_trace(cast_command_arg('GCtrace *', arg), flags)) def load(event=None): diff --git a/test/tarantool-debugger-tests/debug-extension-tests.py b/test/tarantool-debugger-tests/debug-extension-tests.py index ab44121c..75459378 100644 --- a/test/tarantool-debugger-tests/debug-extension-tests.py +++ b/test/tarantool-debugger-tests/debug-extension-tests.py @@ -1,6 +1,7 @@ # This file provides tests for LuaJIT debug extensions for lldb # and gdb. +import functools import os import re import subprocess @@ -10,6 +11,11 @@ import unittest from threading import Timer +# Assume not cross-platform debugging. +machine = os.uname().machine +if machine not in ['x86_64', 'arm64', 'aarch64']: + raise Exception('{}: Unknown architecture in testing'.format(machine)) + LEGACY = re.match(r'^2\.', sys.version) LUAJIT_BINARY = os.environ['LUAJIT_TEST_BINARY'] @@ -19,6 +25,13 @@ LLDB = 'lldb' in DEBUGGER EXTENSION = EXTENSION_PATH + '/luajit_dbg.py' TIMEOUT = 10 +# List of regex that specifies lines to be wiped out from the +# debugger output before checking against test's pattern. +# In case some specific line need to be removed, just append this +# list with the corresponding regex (use the strictest regex +# possible to avoid accidental removing of useful data). +RX_LINES_TO_REMOVE = [] + if LLDB: INFERIOR_ARGS = '--' LOAD_EXTENSION = 'command script import ' + EXTENSION @@ -35,6 +48,23 @@ if LLDB: '--source-quietly', '--source' ] + + # While executing an extension commands, LLDB might produce + # errors that cannot be caught in the extension. The internal + # parser does some processing in background and might emit + # an error message into stderr asynchronously. + # Also, the internal parser has a kind of fallback mechanism + # that might resolve the problem to proceed working correctly, + # but there is no way to "cancel" the mentioned error message, + # which might affect tests in this case. + if machine in ['arm64', 'aarch64']: + # This error occurs on ARM while parsing `union FPRCBArg` + # (it looks like either offset of `f` field or size of + # `union FPRCBArg` is identified incorrectly). + RX_LINES_TO_REMOVE.append( + r".*DW_TAG_member 'f' refers to type \w+ which extends beyond.*", + ) + else: # GDB. INFERIOR_ARGS = '--args' @@ -68,12 +98,12 @@ def execute_process(cmd, timeout=TIMEOUT): process = subprocess.Popen( cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stderr=subprocess.STDOUT, # This prevents sending of SIGSTTOU to the test when # running by `make'. Stdin is unused anyway. stdin=subprocess.DEVNULL ) - timer = Timer(TIMEOUT, process.kill) + timer = Timer(timeout, process.kill) timer.start() stdout, _ = process.communicate() timer.cancel() @@ -87,16 +117,31 @@ def execute_process(cmd, timeout=TIMEOUT): process = subprocess.run( cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stderr=subprocess.STDOUT, # This prevents sending of SIGSTTOU to the test when # running by `make'. Stdin is unused anyway. stdin=subprocess.DEVNULL, universal_newlines=True, - timeout=TIMEOUT + timeout=timeout, ) return process.stdout +# Decorator that wipes out lines from the function result. +def filterout_result(rx_lines): + def decorator(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + result = func(*args, **kwargs) + return re.sub(r'^({})\n'.format('|'.join(rx_lines)), + '', result, flags=re.M) + return wrapper + return decorator + + +if RX_LINES_TO_REMOVE: + execute_process = filterout_result(RX_LINES_TO_REMOVE)(execute_process) + IS_DUALNUM = execute_process([ LUAJIT_BINARY, '-e', "print(require('ffi').abi('dualnum'))" ]).strip() == 'true' @@ -114,17 +159,12 @@ RX_P = 'p64' if IS_GC64 else 'p32' RX_INT = r'integer' if IS_DUALNUM else r'number' RX_ISDUALNUM = r'True' if IS_DUALNUM else r'False' - -# Assume not cross-platform debugging. -machine = os.uname().machine if machine == 'x86_64': RX_GPR = r'r\w\w' RX_FPR = r'xmm\d+' elif machine == 'arm64' or machine == 'aarch64': RX_GPR = r'x\d+' RX_FPR = r'd\d+' -else: - raise Exception('Unknown architecture in testing') class TestCaseBase(unittest.TestCase): @@ -1051,7 +1091,45 @@ class TestLJCTypeBase(TestCaseBase): pattern = r'\[\d+\] ' -for test_cls in TestCaseBase.__subclasses__(): +class TestMissingArgBase(TestCaseBase): + location = 'lj_cf_print' + lua_script = 'print(1)' + pattern = r'Argument is required\n' + + @classmethod + def setUpClass(cls): + cls.extension_cmds = '{}\n'.format(cls.cmd_name) + super(TestMissingArgBase, cls).setUpClass() + + +# Generate the bunch of tests to check the "missing arg" error +# with various commands. +for cmd_name in [ + 'lj-bc', + 'lj-ctype', + 'lj-func', + 'lj-gco', + 'lj-proto', + 'lj-str', + 'lj-tab', + 'lj-tv', +]: + test_class_name = 'TestMissingArg_' + cmd_name.replace('-', '_') + globals()[test_class_name] = \ + type(test_class_name, (TestMissingArgBase,), dict(cmd_name=cmd_name)) + + +def get_leaf_subclasses(cls): + subclasses = cls.__subclasses__() + if not subclasses: + yield cls + else: + for sub in subclasses: + for leaf in get_leaf_subclasses(sub): + yield leaf + + +for test_cls in get_leaf_subclasses(TestCaseBase): test_cls.test = lambda self: self.check() if __name__ == '__main__': -- 2.55.0