[Lldb-commits] [lldb] 22d2f3a - Move the parsed_cmd conversion def's to module level functions.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 13 18:08:11 PST 2024


Author: Jim Ingham
Date: 2024-02-13T18:08:02-08:00
New Revision: 22d2f3aa3097feb9a91c6d7b8ef611a1cde6d0d5

URL: https://github.com/llvm/llvm-project/commit/22d2f3aa3097feb9a91c6d7b8ef611a1cde6d0d5
DIFF: https://github.com/llvm/llvm-project/commit/22d2f3aa3097feb9a91c6d7b8ef611a1cde6d0d5.diff

LOG: Move the parsed_cmd conversion def's to module level functions.

Python3.9 does not allow you to put a reference to a class staticmethod
in a table and call it from there.  Python3.10 and following do allow
this, but we still support 3.9.  staticmethod was slightly cleaner,
but this will do.

Added: 
    

Modified: 
    lldb/examples/python/templates/parsed_cmd.py
    lldb/test/API/commands/command/script/add/TestAddParsedCommand.py

Removed: 
    


################################################################################
diff  --git a/lldb/examples/python/templates/parsed_cmd.py b/lldb/examples/python/templates/parsed_cmd.py
index 61ea57c275aae4..06124adf43420a 100644
--- a/lldb/examples/python/templates/parsed_cmd.py
+++ b/lldb/examples/python/templates/parsed_cmd.py
@@ -52,6 +52,65 @@ def __call__(self, debugger, args_list, exe_ctx, result):
 import sys
 from abc import abstractmethod
 
+# Some methods to translate common value types.  Should return a
+# tuple of the value and an error value (True => error) if the
+# type can't be converted.  These are called internally when the
+# command line is parsed into the 'dest' properties, you should
+# not need to call them directly.
+# FIXME: Need a way to push the conversion error string back to lldb.
+def to_bool(in_value):
+    error = True
+    value = False
+    if type(in_value) != str or len(in_value) == 0:
+        return (value, error)
+
+    low_in = in_value.lower()
+    if low_in in ["y", "yes", "t", "true", "1"]:
+        value = True
+        error = False
+        
+    if not value and low_in in ["n", "no", "f", "false", "0"]:
+        value = False
+        error = False
+
+    return (value, error)
+
+def to_int(in_value):
+    #FIXME: Not doing errors yet...
+    return (int(in_value), False)
+
+def to_unsigned(in_value):
+    # FIXME: find an unsigned converter...
+    # And handle errors.
+    return (int(in_value), False)
+
+translators = {
+    lldb.eArgTypeBoolean : to_bool,
+    lldb.eArgTypeBreakpointID : to_unsigned,
+    lldb.eArgTypeByteSize : to_unsigned,
+    lldb.eArgTypeCount : to_unsigned,
+    lldb.eArgTypeFrameIndex : to_unsigned,
+    lldb.eArgTypeIndex : to_unsigned,
+    lldb.eArgTypeLineNum : to_unsigned,
+    lldb.eArgTypeNumLines : to_unsigned,
+    lldb.eArgTypeNumberPerLine : to_unsigned,
+    lldb.eArgTypeOffset : to_int,
+    lldb.eArgTypeThreadIndex : to_unsigned,
+    lldb.eArgTypeUnsignedInteger : to_unsigned,
+    lldb.eArgTypeWatchpointID : to_unsigned,
+    lldb.eArgTypeColumnNum : to_unsigned,
+    lldb.eArgTypeRecognizerID : to_unsigned,
+    lldb.eArgTypeTargetID : to_unsigned,
+    lldb.eArgTypeStopHookID : to_unsigned
+}
+
+def translate_value(value_type, value):
+    try:
+        return translators[value_type](value)
+    except KeyError:
+        # If we don't have a translator, return the string value.
+        return (value, False)
+
 class LLDBOptionValueParser:
     """
     This class holds the option definitions for the command, and when
@@ -63,68 +122,6 @@ def __init__(self):
         self.options_dict = {}
         self.args_array = []
 
-    # Some methods to translate common value types.  Should return a
-    # tuple of the value and an error value (True => error) if the
-    # type can't be converted.  These are called internally when the
-    # command line is parsed into the 'dest' properties, you should
-    # not need to call them directly.
-    # FIXME: Need a way to push the conversion error string back to lldb.
-    @staticmethod
-    def to_bool(in_value):
-        error = True
-        value = False
-        if type(in_value) != str or len(in_value) == 0:
-            return (value, error)
-
-        low_in = in_value.lower()
-        if low_in in ["y", "yes", "t", "true", "1"]:
-            value = True
-            error = False
-            
-        if not value and low_in in ["n", "no", "f", "false", "0"]:
-            value = False
-            error = False
-
-        return (value, error)
-
-    @staticmethod
-    def to_int(in_value):
-        #FIXME: Not doing errors yet...
-        return (int(in_value), False)
-
-    @staticmethod
-    def to_unsigned(in_value):
-        # FIXME: find an unsigned converter...
-        # And handle errors.
-        return (int(in_value), False)
-
-    translators = {
-        lldb.eArgTypeBoolean : to_bool,
-        lldb.eArgTypeBreakpointID : to_unsigned,
-        lldb.eArgTypeByteSize : to_unsigned,
-        lldb.eArgTypeCount : to_unsigned,
-        lldb.eArgTypeFrameIndex : to_unsigned,
-        lldb.eArgTypeIndex : to_unsigned,
-        lldb.eArgTypeLineNum : to_unsigned,
-        lldb.eArgTypeNumLines : to_unsigned,
-        lldb.eArgTypeNumberPerLine : to_unsigned,
-        lldb.eArgTypeOffset : to_int,
-        lldb.eArgTypeThreadIndex : to_unsigned,
-        lldb.eArgTypeUnsignedInteger : to_unsigned,
-        lldb.eArgTypeWatchpointID : to_unsigned,
-        lldb.eArgTypeColumnNum : to_unsigned,
-        lldb.eArgTypeRecognizerID : to_unsigned,
-        lldb.eArgTypeTargetID : to_unsigned,
-        lldb.eArgTypeStopHookID : to_unsigned
-    }
-
-    @classmethod
-    def translate_value(cls, value_type, value):
-        try:
-            return cls.translators[value_type](value)
-        except KeyError:
-            # If we don't have a translator, return the string value.
-            return (value, False)
 
     # FIXME: would this be better done on the C++ side?
     # The common completers are missing some useful ones.
@@ -219,7 +216,7 @@ def set_option_value(self, exe_ctx, opt_name, opt_value):
         if "enum_values" in elem:
             (value, error) = self.set_enum_value(elem["enum_values"], opt_value)
         else:
-            (value, error)  = __class__.translate_value(elem["value_type"], opt_value)
+            (value, error)  = translate_value(elem["value_type"], opt_value)
 
         if error:
             return False

diff  --git a/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py b/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py
index 6cbe888af99dc6..7dba9c6937f211 100644
--- a/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py
+++ b/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py
@@ -13,9 +13,6 @@
 class ParsedCommandTestCase(TestBase):
     NO_DEBUG_INFO_TESTCASE = True
 
-    # This crashes on the x86_64 Debian bot, but the failure is not helpful.
-    # Disable the test while I try to find a way to reproduce.
-    @skipIf(py_version=("<=", (3, 9)))
     def test(self):
         self.pycmd_tests()
 


        


More information about the lldb-commits mailing list