[Lldb-commits] [lldb] cb6c9f7 - [lldb] Make gdbremote.py utility py2and3 compatible

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 13 00:19:11 PST 2020


Author: Pavel Labath
Date: 2020-02-13T09:18:55+01:00
New Revision: cb6c9f731b657807124bcb5a6c1f8aecf25f120b

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

LOG: [lldb] Make gdbremote.py utility py2and3 compatible

Added: 
    

Modified: 
    lldb/examples/python/gdbremote.py

Removed: 
    


################################################################################
diff  --git a/lldb/examples/python/gdbremote.py b/lldb/examples/python/gdbremote.py
index dcacbfccdaff..52601c09d3be 100755
--- a/lldb/examples/python/gdbremote.py
+++ b/lldb/examples/python/gdbremote.py
@@ -16,6 +16,7 @@
 # available.
 #----------------------------------------------------------------------
 
+from __future__ import print_function
 import binascii
 import subprocess
 import json
@@ -324,10 +325,10 @@ def is_hex_byte(str):
 
 def get_hex_string_if_all_printable(str):
     try:
-        s = binascii.unhexlify(str)
+        s = binascii.unhexlify(str).decode()
         if all(c in string.printable for c in s):
             return s
-    except TypeError:
+    except (TypeError, binascii.Error, UnicodeDecodeError):
         pass
     return None
 
@@ -548,10 +549,10 @@ def get_hex_uint(self, byte_order, n=0):
     def get_key_value_pairs(self):
         kvp = list()
         if ';' in self.str:
-            key_value_pairs = string.split(self.str, ';')
+            key_value_pairs = self.str.split(';')
             for key_value_pair in key_value_pairs:
                 if len(key_value_pair):
-                    kvp.append(string.split(key_value_pair, ':'))
+                    kvp.append(key_value_pair.split(':', 1))
         return kvp
 
     def split(self, ch):
@@ -678,7 +679,7 @@ def cmd_qXfer(options, cmd, args):
 
 
 def rsp_qXfer(options, cmd, cmd_args, rsp):
-    data = string.split(cmd_args, ':')
+    data = cmd_args.split(':')
     if data[0] == 'features':
         if data[1] == 'read':
             filename, extension = os.path.splitext(data[2])
@@ -825,8 +826,8 @@ def cmd_vCont(options, cmd, args):
     else:
         got_other_threads = 0
         s = ''
-        for thread_action in string.split(args[1:], ';'):
-            (short_action, thread) = string.split(thread_action, ':')
+        for thread_action in args[1:].split(';'):
+            (short_action, thread) = thread_action.split(':', 1)
             tid = int(thread, 16)
             if short_action == 'c':
                 action = 'continue'
@@ -856,7 +857,7 @@ def rsp_vCont(options, cmd, cmd_args, rsp):
     if cmd_args == '?':
         # Skip the leading 'vCont;'
         rsp = rsp[6:]
-        modes = string.split(rsp, ';')
+        modes = rsp.split(';')
         s = "%s: supported extended continue modes include: " % (cmd)
 
         for i, mode in enumerate(modes):


        


More information about the lldb-commits mailing list