[Lldb-commits] [PATCH] D120792: [lldb] Fix python errors in gdbremote.py

Dominic Chen via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 1 22:59:45 PST 2022


ddcc created this revision.
ddcc added reviewers: kastiglione, jingham, JDevlieghere, clayborg.
Herald added a project: All.
ddcc requested review of this revision.
Herald added a project: LLDB.

Fix exceptions encountered while debugging gdb protocol


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120792

Files:
  lldb/examples/python/gdbremote.py


Index: lldb/examples/python/gdbremote.py
===================================================================
--- lldb/examples/python/gdbremote.py
+++ lldb/examples/python/gdbremote.py
@@ -260,6 +260,12 @@
         dest='verbose',
         help='display verbose debug info',
         default=False)
+    parser.add_option(
+        '--plot',
+        action='store_true',
+        dest='plot',
+        help='plot packet latencies by packet type',
+        default=False)
     parser.add_option(
         '-q',
         '--quiet',
@@ -556,11 +562,11 @@
         return kvp
 
     def split(self, ch):
-        return string.split(self.str, ch)
+        return self.str.split(ch)
 
     def split_hex(self, ch, byte_order):
         hex_values = list()
-        strings = string.split(self.str, ch)
+        strings = self.str.split(ch)
         for str in strings:
             hex_values.append(Packet(str).get_hex_uint(byte_order))
         return hex_values
@@ -888,7 +894,7 @@
 
 
 def cmd_vAttach(options, cmd, args):
-    (extra_command, args) = string.split(args, ';')
+    (extra_command, args) = args.split(';')
     if extra_command:
         print("%s%s(%s)" % (cmd, extra_command, args))
     else:
@@ -1212,9 +1218,11 @@
 
 def rsp_json(options, cmd, cmd_args, rsp):
     print('%s() reply:' % (cmd))
-    json_tree = json.loads(rsp)
-    print(json.dumps(json_tree, indent=4, separators=(',', ': ')))
-
+    try:
+        json_tree = json.loads(rsp)
+        print(json.dumps(json_tree, indent=4, separators=(',', ': ')))
+    except json.JSONDecodeError:
+        return
 
 def rsp_jGetLoadedDynamicLibrariesInfos(options, cmd, cmd_args, rsp):
     if cmd_args:
@@ -1541,7 +1549,7 @@
                 print("  %24s %11.6f  %5.2f%% %6d %9.6f" % (
                         item, packet_total_time, packet_percent, packet_count,
                         float(packet_total_time) / float(packet_count)))
-        if options.plot:
+        if options and options.plot:
             plot_latencies(packet_times)
 
 if __name__ == '__main__':
@@ -1558,12 +1566,6 @@
         dest='verbose',
         help='display verbose debug info',
         default=False)
-    parser.add_option(
-        '--plot',
-        action='store_true',
-        dest='plot',
-        help='plot packet latencies by packet type',
-        default=False)
     parser.add_option(
         '-q',
         '--quiet',


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120792.412327.patch
Type: text/x-patch
Size: 2399 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220302/ef008225/attachment-0001.bin>


More information about the lldb-commits mailing list