113113JERRY_DEBUGGER_VALUE_ARRAY = 8
114114JERRY_DEBUGGER_VALUE_OBJECT = 9
115115
116+
116117def arguments_parse ():
117118 parser = argparse .ArgumentParser (description = "JerryScript debugger client" )
118119
@@ -290,8 +291,8 @@ def __init__(self, channel):
290291 self .src_offset = 0
291292 self .src_offset_diff = 0
292293 self .non_interactive = False
293- self .current_out = b ""
294- self .current_log = b ""
294+ self .current_out = ""
295+ self .current_log = ""
295296 self .channel = channel
296297
297298 config_size = 8
@@ -303,12 +304,12 @@ def __init__(self, channel):
303304 # cpointer_size [1]
304305 result = self .channel .connect (config_size )
305306
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 :
307308 raise Exception ("Unexpected configuration" )
308309
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 ]
312313
313314 if self .little_endian :
314315 self .byte_order = "<"
@@ -396,7 +397,7 @@ def delete(self, args):
396397 "to clear all the given breakpoints\n "
397398 elif args in ['all' , 'pending' , 'active' ]:
398399 if args != "pending" :
399- for i in self .active_breakpoint_list .values ():
400+ for i in list ( self .active_breakpoint_list .values () ):
400401 breakpoint = self .active_breakpoint_list [i .active_index ]
401402 del self .active_breakpoint_list [i .active_index ]
402403 breakpoint .active_index = - 1
@@ -557,6 +558,7 @@ def memstats(self):
557558 self ._exec_command (JERRY_DEBUGGER_MEMSTATS )
558559
559560 def _send_string (self , args , message_type , index = 0 ):
561+ args = args .encode ('utf8' )
560562
561563 # 1: length of type byte
562564 # 4: length of an uint32 value
@@ -680,7 +682,7 @@ def process_messages(self):
680682 if not data : # Break the while loop if there is no more data.
681683 return DebuggerAction (DebuggerAction .END , "" )
682684
683- buffer_type = ord ( data [0 ])
685+ buffer_type = data [0 ]
684686 buffer_size = len (data ) - 1
685687
686688 logging .debug ("Main buffer type: %d, message size: %d" , buffer_type , buffer_size )
@@ -733,11 +735,8 @@ def process_messages(self):
733735 self .prompt = True
734736 return DebuggerAction (DebuggerAction .TEXT , result )
735737
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' )
741740
742741 elif buffer_type == JERRY_DEBUGGER_BACKTRACE_TOTAL :
743742 total = struct .unpack (self .byte_order + self .idx_format , data [1 :])[0 ]
@@ -804,7 +803,7 @@ def process_messages(self):
804803 return DebuggerAction (DebuggerAction .TEXT , result )
805804
806805 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' )
808807
809808 if buffer_type == JERRY_DEBUGGER_SCOPE_VARIABLES_END :
810809 result = self ._process_scope_variables ()
@@ -860,9 +859,9 @@ def print_source(self, line_num, offset):
860859
861860 # pylint: disable=too-many-branches,too-many-locals,too-many-statements
862861 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 ""
866865 stack = [{"line" : 1 ,
867866 "column" : 1 ,
868867 "name" : "" ,
@@ -875,7 +874,7 @@ def _parse_source(self, data):
875874 if data is None :
876875 return "Error: connection lost during source code receiving"
877876
878- buffer_type = ord ( data [0 ])
877+ buffer_type = data [0 ]
879878 buffer_size = len (data ) - 1
880879
881880 logging .debug ("Parser buffer type: %d, message size: %d" , buffer_type , buffer_size )
@@ -894,19 +893,20 @@ def _parse_source(self, data):
894893 function_name += data [1 :]
895894
896895 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' ))
898898
899899 position = struct .unpack (self .byte_order + self .idx_format + self .idx_format ,
900900 data [1 : 1 + 4 + 4 ])
901901
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' ) ,
904904 "line" : position [0 ],
905905 "column" : position [1 ],
906- "name" : function_name ,
906+ "name" : function_name . decode ( 'utf8' ) ,
907907 "lines" : [],
908908 "offsets" : []})
909- function_name = ""
909+ function_name = b ""
910910
911911 elif buffer_type in [JERRY_DEBUGGER_BREAKPOINT_LIST , JERRY_DEBUGGER_BREAKPOINT_OFFSET_LIST ]:
912912 name = "lines"
@@ -933,8 +933,8 @@ def _parse_source(self, data):
933933
934934 # We know the last item in the list is the general byte code.
935935 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' )
938938
939939 function = JerryFunction (stack ,
940940 byte_code_cp ,
@@ -985,7 +985,7 @@ def _parse_source(self, data):
985985 logging .debug ("Pending breakpoints available" )
986986 bp_list = self .pending_breakpoint_list
987987
988- for breakpoint_index , breakpoint in bp_list .items ():
988+ for breakpoint_index , breakpoint in list ( bp_list .items () ):
989989 source_lines = 0
990990 for src in new_function_list .values ():
991991 if (src .source_name == breakpoint .source_name or
@@ -1123,19 +1123,19 @@ def _get_breakpoint(self, breakpoint_data):
11231123 return (function .offsets [nearest_offset ], False )
11241124
11251125 def _process_incoming_text (self , buffer_type , data ):
1126- message = b ""
1126+ message = ""
11271127 msg_type = buffer_type
11281128 while True :
11291129 if buffer_type in [JERRY_DEBUGGER_EVAL_RESULT_END ,
11301130 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' )
11331133 break
11341134 else :
1135- message += data [1 :]
1135+ message += data [1 :]. decode ( 'utf8' )
11361136
11371137 data = self .channel .get_message (True )
1138- buffer_type = ord ( data [0 ])
1138+ buffer_type = data [0 ]
11391139 # Checks if the next frame would be an invalid data frame.
11401140 # If it is not the message type, or the end type of it, an exception is thrown.
11411141 if buffer_type not in [msg_type , msg_type + 1 ]:
@@ -1176,17 +1176,17 @@ def _process_scope_variables(self):
11761176
11771177 while buff_pos != buff_size :
11781178 # Process name
1179- name_length = ord (self .scope_vars [buff_pos : buff_pos + 1 ])
1179+ name_length = ord (self .scope_vars [buff_pos ])
11801180 buff_pos += 1
11811181 name = self .scope_vars [buff_pos :buff_pos + name_length ]
11821182 buff_pos += name_length
11831183
11841184 # Process type
1185- value_type = ord (self .scope_vars [buff_pos : buff_pos + 1 ])
1185+ value_type = ord (self .scope_vars [buff_pos ])
11861186
11871187 buff_pos += 1
11881188
1189- value_length = ord (self .scope_vars [buff_pos : buff_pos + 1 ])
1189+ value_length = ord (self .scope_vars [buff_pos ])
11901190 buff_pos += 1
11911191 value = self .scope_vars [buff_pos : buff_pos + value_length ]
11921192 buff_pos += value_length
@@ -1217,16 +1217,16 @@ def _process_scope(self):
12171217 table = [['level' , 'type' ]]
12181218
12191219 for i , level in enumerate (self .scope_data ):
1220- if ord ( level ) == JERRY_DEBUGGER_SCOPE_WITH :
1220+ if level == JERRY_DEBUGGER_SCOPE_WITH :
12211221 table .append ([str (i ), 'with' ])
1222- elif ord ( level ) == JERRY_DEBUGGER_SCOPE_GLOBAL :
1222+ elif level == JERRY_DEBUGGER_SCOPE_GLOBAL :
12231223 table .append ([str (i ), 'global' ])
1224- elif ord ( level ) == JERRY_DEBUGGER_SCOPE_NON_CLOSURE :
1224+ elif level == JERRY_DEBUGGER_SCOPE_NON_CLOSURE :
12251225 # Currently it is only marks the catch closure.
12261226 table .append ([str (i ), 'catch' ])
1227- elif ord ( level ) == JERRY_DEBUGGER_SCOPE_LOCAL :
1227+ elif level == JERRY_DEBUGGER_SCOPE_LOCAL :
12281228 table .append ([str (i ), 'local' ])
1229- elif ord ( level ) == JERRY_DEBUGGER_SCOPE_CLOSURE :
1229+ elif level == JERRY_DEBUGGER_SCOPE_CLOSURE :
12301230 table .append ([str (i ), 'closure' ])
12311231 else :
12321232 raise Exception ("Unexpected scope chain element" )
0 commit comments