113
113
JERRY_DEBUGGER_VALUE_ARRAY = 8
114
114
JERRY_DEBUGGER_VALUE_OBJECT = 9
115
115
116
+
116
117
def arguments_parse ():
117
118
parser = argparse .ArgumentParser (description = "JerryScript debugger client" )
118
119
@@ -290,8 +291,8 @@ def __init__(self, channel):
290
291
self .src_offset = 0
291
292
self .src_offset_diff = 0
292
293
self .non_interactive = False
293
- self .current_out = b ""
294
- self .current_log = b ""
294
+ self .current_out = ""
295
+ self .current_log = ""
295
296
self .channel = channel
296
297
297
298
config_size = 8
@@ -303,12 +304,12 @@ def __init__(self, channel):
303
304
# cpointer_size [1]
304
305
result = self .channel .connect (config_size )
305
306
306
- if len (result ) != config_size or ord ( result [0 ]) != JERRY_DEBUGGER_CONFIGURATION :
307
+ if len (result ) != config_size or result [0 ] != JERRY_DEBUGGER_CONFIGURATION :
307
308
raise Exception ("Unexpected configuration" )
308
309
309
- self .little_endian = ord ( result [1 ]) & JERRY_DEBUGGER_LITTLE_ENDIAN
310
- self .max_message_size = ord ( result [6 ])
311
- self .cp_size = ord ( result [7 ])
310
+ self .little_endian = result [1 ] & JERRY_DEBUGGER_LITTLE_ENDIAN
311
+ self .max_message_size = result [6 ]
312
+ self .cp_size = result [7 ]
312
313
313
314
if self .little_endian :
314
315
self .byte_order = "<"
@@ -396,7 +397,7 @@ def delete(self, args):
396
397
"to clear all the given breakpoints\n "
397
398
elif args in ['all' , 'pending' , 'active' ]:
398
399
if args != "pending" :
399
- for i in self .active_breakpoint_list .values ():
400
+ for i in list ( self .active_breakpoint_list .values () ):
400
401
breakpoint = self .active_breakpoint_list [i .active_index ]
401
402
del self .active_breakpoint_list [i .active_index ]
402
403
breakpoint .active_index = - 1
@@ -557,6 +558,7 @@ def memstats(self):
557
558
self ._exec_command (JERRY_DEBUGGER_MEMSTATS )
558
559
559
560
def _send_string (self , args , message_type , index = 0 ):
561
+ args = args .encode ('utf8' )
560
562
561
563
# 1: length of type byte
562
564
# 4: length of an uint32 value
@@ -680,7 +682,7 @@ def process_messages(self):
680
682
if not data : # Break the while loop if there is no more data.
681
683
return DebuggerAction (DebuggerAction .END , "" )
682
684
683
- buffer_type = ord ( data [0 ])
685
+ buffer_type = data [0 ]
684
686
buffer_size = len (data ) - 1
685
687
686
688
logging .debug ("Main buffer type: %d, message size: %d" , buffer_type , buffer_size )
@@ -733,11 +735,8 @@ def process_messages(self):
733
735
self .prompt = True
734
736
return DebuggerAction (DebuggerAction .TEXT , result )
735
737
736
- elif buffer_type == JERRY_DEBUGGER_EXCEPTION_STR :
737
- self .exception_string += data [1 :]
738
-
739
- elif buffer_type == JERRY_DEBUGGER_EXCEPTION_STR_END :
740
- self .exception_string += data [1 :]
738
+ elif buffer_type in [JERRY_DEBUGGER_EXCEPTION_STR , JERRY_DEBUGGER_EXCEPTION_STR_END ]:
739
+ self .exception_string += data [1 :].decode ('utf8' )
741
740
742
741
elif buffer_type == JERRY_DEBUGGER_BACKTRACE_TOTAL :
743
742
total = struct .unpack (self .byte_order + self .idx_format , data [1 :])[0 ]
@@ -804,7 +803,7 @@ def process_messages(self):
804
803
return DebuggerAction (DebuggerAction .TEXT , result )
805
804
806
805
elif buffer_type in [JERRY_DEBUGGER_SCOPE_VARIABLES , JERRY_DEBUGGER_SCOPE_VARIABLES_END ]:
807
- self .scope_vars += "" . join ( data [1 :])
806
+ self .scope_vars += data [1 :]. decode ( 'utf8' )
808
807
809
808
if buffer_type == JERRY_DEBUGGER_SCOPE_VARIABLES_END :
810
809
result = self ._process_scope_variables ()
@@ -860,9 +859,9 @@ def print_source(self, line_num, offset):
860
859
861
860
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
862
861
def _parse_source (self , data ):
863
- source_code = ""
864
- source_code_name = ""
865
- function_name = ""
862
+ source_code = b ""
863
+ source_code_name = b ""
864
+ function_name = b ""
866
865
stack = [{"line" : 1 ,
867
866
"column" : 1 ,
868
867
"name" : "" ,
@@ -875,7 +874,7 @@ def _parse_source(self, data):
875
874
if data is None :
876
875
return "Error: connection lost during source code receiving"
877
876
878
- buffer_type = ord ( data [0 ])
877
+ buffer_type = data [0 ]
879
878
buffer_size = len (data ) - 1
880
879
881
880
logging .debug ("Parser buffer type: %d, message size: %d" , buffer_type , buffer_size )
@@ -894,19 +893,20 @@ def _parse_source(self, data):
894
893
function_name += data [1 :]
895
894
896
895
elif buffer_type == JERRY_DEBUGGER_PARSE_FUNCTION :
897
- logging .debug ("Source name: %s, function name: %s" , source_code_name , function_name )
896
+ logging .debug ("Source name: %s, function name: %s" , source_code_name .decode ('utf8' ),
897
+ function_name .decode ('utf8' ))
898
898
899
899
position = struct .unpack (self .byte_order + self .idx_format + self .idx_format ,
900
900
data [1 : 1 + 4 + 4 ])
901
901
902
- stack .append ({"source" : source_code ,
903
- "source_name" : source_code_name ,
902
+ stack .append ({"source" : source_code . decode ( 'utf8' ) ,
903
+ "source_name" : source_code_name . decode ( 'utf8' ) ,
904
904
"line" : position [0 ],
905
905
"column" : position [1 ],
906
- "name" : function_name ,
906
+ "name" : function_name . decode ( 'utf8' ) ,
907
907
"lines" : [],
908
908
"offsets" : []})
909
- function_name = ""
909
+ function_name = b ""
910
910
911
911
elif buffer_type in [JERRY_DEBUGGER_BREAKPOINT_LIST , JERRY_DEBUGGER_BREAKPOINT_OFFSET_LIST ]:
912
912
name = "lines"
@@ -933,8 +933,8 @@ def _parse_source(self, data):
933
933
934
934
# We know the last item in the list is the general byte code.
935
935
if not stack :
936
- func_desc ["source" ] = source_code
937
- func_desc ["source_name" ] = source_code_name
936
+ func_desc ["source" ] = source_code . decode ( 'utf8' )
937
+ func_desc ["source_name" ] = source_code_name . decode ( 'utf8' )
938
938
939
939
function = JerryFunction (stack ,
940
940
byte_code_cp ,
@@ -985,7 +985,7 @@ def _parse_source(self, data):
985
985
logging .debug ("Pending breakpoints available" )
986
986
bp_list = self .pending_breakpoint_list
987
987
988
- for breakpoint_index , breakpoint in bp_list .items ():
988
+ for breakpoint_index , breakpoint in list ( bp_list .items () ):
989
989
source_lines = 0
990
990
for src in new_function_list .values ():
991
991
if (src .source_name == breakpoint .source_name or
@@ -1123,19 +1123,19 @@ def _get_breakpoint(self, breakpoint_data):
1123
1123
return (function .offsets [nearest_offset ], False )
1124
1124
1125
1125
def _process_incoming_text (self , buffer_type , data ):
1126
- message = b ""
1126
+ message = ""
1127
1127
msg_type = buffer_type
1128
1128
while True :
1129
1129
if buffer_type in [JERRY_DEBUGGER_EVAL_RESULT_END ,
1130
1130
JERRY_DEBUGGER_OUTPUT_RESULT_END ]:
1131
- subtype = ord ( data [- 1 ])
1132
- message += data [1 :- 1 ]
1131
+ subtype = data [- 1 ]
1132
+ message += data [1 :- 1 ]. decode ( 'utf8' )
1133
1133
break
1134
1134
else :
1135
- message += data [1 :]
1135
+ message += data [1 :]. decode ( 'utf8' )
1136
1136
1137
1137
data = self .channel .get_message (True )
1138
- buffer_type = ord ( data [0 ])
1138
+ buffer_type = data [0 ]
1139
1139
# Checks if the next frame would be an invalid data frame.
1140
1140
# If it is not the message type, or the end type of it, an exception is thrown.
1141
1141
if buffer_type not in [msg_type , msg_type + 1 ]:
@@ -1176,17 +1176,17 @@ def _process_scope_variables(self):
1176
1176
1177
1177
while buff_pos != buff_size :
1178
1178
# Process name
1179
- name_length = ord (self .scope_vars [buff_pos : buff_pos + 1 ])
1179
+ name_length = ord (self .scope_vars [buff_pos ])
1180
1180
buff_pos += 1
1181
1181
name = self .scope_vars [buff_pos :buff_pos + name_length ]
1182
1182
buff_pos += name_length
1183
1183
1184
1184
# Process type
1185
- value_type = ord (self .scope_vars [buff_pos : buff_pos + 1 ])
1185
+ value_type = ord (self .scope_vars [buff_pos ])
1186
1186
1187
1187
buff_pos += 1
1188
1188
1189
- value_length = ord (self .scope_vars [buff_pos : buff_pos + 1 ])
1189
+ value_length = ord (self .scope_vars [buff_pos ])
1190
1190
buff_pos += 1
1191
1191
value = self .scope_vars [buff_pos : buff_pos + value_length ]
1192
1192
buff_pos += value_length
@@ -1217,16 +1217,16 @@ def _process_scope(self):
1217
1217
table = [['level' , 'type' ]]
1218
1218
1219
1219
for i , level in enumerate (self .scope_data ):
1220
- if ord ( level ) == JERRY_DEBUGGER_SCOPE_WITH :
1220
+ if level == JERRY_DEBUGGER_SCOPE_WITH :
1221
1221
table .append ([str (i ), 'with' ])
1222
- elif ord ( level ) == JERRY_DEBUGGER_SCOPE_GLOBAL :
1222
+ elif level == JERRY_DEBUGGER_SCOPE_GLOBAL :
1223
1223
table .append ([str (i ), 'global' ])
1224
- elif ord ( level ) == JERRY_DEBUGGER_SCOPE_NON_CLOSURE :
1224
+ elif level == JERRY_DEBUGGER_SCOPE_NON_CLOSURE :
1225
1225
# Currently it is only marks the catch closure.
1226
1226
table .append ([str (i ), 'catch' ])
1227
- elif ord ( level ) == JERRY_DEBUGGER_SCOPE_LOCAL :
1227
+ elif level == JERRY_DEBUGGER_SCOPE_LOCAL :
1228
1228
table .append ([str (i ), 'local' ])
1229
- elif ord ( level ) == JERRY_DEBUGGER_SCOPE_CLOSURE :
1229
+ elif level == JERRY_DEBUGGER_SCOPE_CLOSURE :
1230
1230
table .append ([str (i ), 'closure' ])
1231
1231
else :
1232
1232
raise Exception ("Unexpected scope chain element" )
0 commit comments