@@ -52,6 +52,65 @@ def __call__(self, debugger, args_list, exe_ctx, result):
52
52
import sys
53
53
from abc import abstractmethod
54
54
55
+ # Some methods to translate common value types. Should return a
56
+ # tuple of the value and an error value (True => error) if the
57
+ # type can't be converted. These are called internally when the
58
+ # command line is parsed into the 'dest' properties, you should
59
+ # not need to call them directly.
60
+ # FIXME: Need a way to push the conversion error string back to lldb.
61
+ def to_bool (in_value ):
62
+ error = True
63
+ value = False
64
+ if type (in_value ) != str or len (in_value ) == 0 :
65
+ return (value , error )
66
+
67
+ low_in = in_value .lower ()
68
+ if low_in in ["y" , "yes" , "t" , "true" , "1" ]:
69
+ value = True
70
+ error = False
71
+
72
+ if not value and low_in in ["n" , "no" , "f" , "false" , "0" ]:
73
+ value = False
74
+ error = False
75
+
76
+ return (value , error )
77
+
78
+ def to_int (in_value ):
79
+ #FIXME: Not doing errors yet...
80
+ return (int (in_value ), False )
81
+
82
+ def to_unsigned (in_value ):
83
+ # FIXME: find an unsigned converter...
84
+ # And handle errors.
85
+ return (int (in_value ), False )
86
+
87
+ translators = {
88
+ lldb .eArgTypeBoolean : to_bool ,
89
+ lldb .eArgTypeBreakpointID : to_unsigned ,
90
+ lldb .eArgTypeByteSize : to_unsigned ,
91
+ lldb .eArgTypeCount : to_unsigned ,
92
+ lldb .eArgTypeFrameIndex : to_unsigned ,
93
+ lldb .eArgTypeIndex : to_unsigned ,
94
+ lldb .eArgTypeLineNum : to_unsigned ,
95
+ lldb .eArgTypeNumLines : to_unsigned ,
96
+ lldb .eArgTypeNumberPerLine : to_unsigned ,
97
+ lldb .eArgTypeOffset : to_int ,
98
+ lldb .eArgTypeThreadIndex : to_unsigned ,
99
+ lldb .eArgTypeUnsignedInteger : to_unsigned ,
100
+ lldb .eArgTypeWatchpointID : to_unsigned ,
101
+ lldb .eArgTypeColumnNum : to_unsigned ,
102
+ lldb .eArgTypeRecognizerID : to_unsigned ,
103
+ lldb .eArgTypeTargetID : to_unsigned ,
104
+ lldb .eArgTypeStopHookID : to_unsigned
105
+ }
106
+
107
+ def translate_value (value_type , value ):
108
+ try :
109
+ return translators [value_type ](value )
110
+ except KeyError :
111
+ # If we don't have a translator, return the string value.
112
+ return (value , False )
113
+
55
114
class LLDBOptionValueParser :
56
115
"""
57
116
This class holds the option definitions for the command, and when
@@ -63,68 +122,6 @@ def __init__(self):
63
122
self .options_dict = {}
64
123
self .args_array = []
65
124
66
- # Some methods to translate common value types. Should return a
67
- # tuple of the value and an error value (True => error) if the
68
- # type can't be converted. These are called internally when the
69
- # command line is parsed into the 'dest' properties, you should
70
- # not need to call them directly.
71
- # FIXME: Need a way to push the conversion error string back to lldb.
72
- @staticmethod
73
- def to_bool (in_value ):
74
- error = True
75
- value = False
76
- if type (in_value ) != str or len (in_value ) == 0 :
77
- return (value , error )
78
-
79
- low_in = in_value .lower ()
80
- if low_in in ["y" , "yes" , "t" , "true" , "1" ]:
81
- value = True
82
- error = False
83
-
84
- if not value and low_in in ["n" , "no" , "f" , "false" , "0" ]:
85
- value = False
86
- error = False
87
-
88
- return (value , error )
89
-
90
- @staticmethod
91
- def to_int (in_value ):
92
- #FIXME: Not doing errors yet...
93
- return (int (in_value ), False )
94
-
95
- @staticmethod
96
- def to_unsigned (in_value ):
97
- # FIXME: find an unsigned converter...
98
- # And handle errors.
99
- return (int (in_value ), False )
100
-
101
- translators = {
102
- lldb .eArgTypeBoolean : to_bool ,
103
- lldb .eArgTypeBreakpointID : to_unsigned ,
104
- lldb .eArgTypeByteSize : to_unsigned ,
105
- lldb .eArgTypeCount : to_unsigned ,
106
- lldb .eArgTypeFrameIndex : to_unsigned ,
107
- lldb .eArgTypeIndex : to_unsigned ,
108
- lldb .eArgTypeLineNum : to_unsigned ,
109
- lldb .eArgTypeNumLines : to_unsigned ,
110
- lldb .eArgTypeNumberPerLine : to_unsigned ,
111
- lldb .eArgTypeOffset : to_int ,
112
- lldb .eArgTypeThreadIndex : to_unsigned ,
113
- lldb .eArgTypeUnsignedInteger : to_unsigned ,
114
- lldb .eArgTypeWatchpointID : to_unsigned ,
115
- lldb .eArgTypeColumnNum : to_unsigned ,
116
- lldb .eArgTypeRecognizerID : to_unsigned ,
117
- lldb .eArgTypeTargetID : to_unsigned ,
118
- lldb .eArgTypeStopHookID : to_unsigned
119
- }
120
-
121
- @classmethod
122
- def translate_value (cls , value_type , value ):
123
- try :
124
- return cls .translators [value_type ](value )
125
- except KeyError :
126
- # If we don't have a translator, return the string value.
127
- return (value , False )
128
125
129
126
# FIXME: would this be better done on the C++ side?
130
127
# The common completers are missing some useful ones.
@@ -219,7 +216,7 @@ def set_option_value(self, exe_ctx, opt_name, opt_value):
219
216
if "enum_values" in elem :
220
217
(value , error ) = self .set_enum_value (elem ["enum_values" ], opt_value )
221
218
else :
222
- (value , error ) = __class__ . translate_value (elem ["value_type" ], opt_value )
219
+ (value , error ) = translate_value (elem ["value_type" ], opt_value )
223
220
224
221
if error :
225
222
return False
0 commit comments