[Lldb-commits] [lldb] r242490 - Allow gdbremote.py to take input from STDIN and handle "c" and "s" packets.

Greg Clayton gclayton at apple.com
Thu Jul 16 17:19:31 PDT 2015


Author: gclayton
Date: Thu Jul 16 19:19:31 2015
New Revision: 242490

URL: http://llvm.org/viewvc/llvm-project?rev=242490&view=rev
Log:
Allow gdbremote.py to take input from STDIN and handle "c" and "s" packets.

Modified:
    lldb/trunk/examples/python/gdbremote.py

Modified: lldb/trunk/examples/python/gdbremote.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/python/gdbremote.py?rev=242490&r1=242489&r2=242490&view=diff
==============================================================================
--- lldb/trunk/examples/python/gdbremote.py (original)
+++ lldb/trunk/examples/python/gdbremote.py Thu Jul 16 19:19:31 2015
@@ -495,6 +495,8 @@ def rsp_stop_reply(options, cmd, cmd_arg
                     reg_info = g_register_infos[reg_num]
                     key_value_pair[0] = reg_info.name()
                     key_value_pair[1] = reg_info.get_value_from_hex_string (key_value_pair[1])
+            elif key == 'jthreads' or key == 'jstopinfo':
+                key_value_pair[1] = binascii.unhexlify(key_value_pair[1])
         key_value_pairs.insert(0, ['signal', signo])
         dump_key_value_pairs (key_value_pairs)
     elif stop_type == 'W':
@@ -588,6 +590,12 @@ def rsp_dump_key_value_pairs(options, cm
     else:
         print "not supported"
 
+def cmd_c(options, cmd, args):
+    print "continue()"
+
+def cmd_s(options, cmd, args):
+    print "step()"
+    
 def cmd_vCont(options, cmd, args):
     if args == '?':
         print "%s: get supported extended continue modes" % (cmd)
@@ -894,6 +902,8 @@ gdb_remote_commands = {
     'qHostInfo'               : { 'cmd' : cmd_query_packet  , 'rsp' : rsp_dump_key_value_pairs, 'name' : "get host information" },
     'vCont'                   : { 'cmd' : cmd_vCont         , 'rsp' : rsp_vCont               , 'name' : "extended continue command" },
     'vAttach'                 : { 'cmd' : cmd_vAttach       , 'rsp' : rsp_stop_reply          , 'name' : "attach to process" },
+    'c'                       : { 'cmd' : cmd_c             , 'rsp' : rsp_stop_reply          , 'name' : "continue" },
+    's'                       : { 'cmd' : cmd_s             , 'rsp' : rsp_stop_reply          , 'name' : "step" },
     'qRegisterInfo'           : { 'cmd' : cmd_qRegisterInfo , 'rsp' : rsp_qRegisterInfo       , 'name' : "query register info" },
     'qfThreadInfo'            : { 'cmd' : cmd_qThreadInfo   , 'rsp' : rsp_qThreadInfo         , 'name' : "get current thread list" },
     'qsThreadInfo'            : { 'cmd' : cmd_qThreadInfo   , 'rsp' : rsp_qThreadInfo         , 'name' : "get current thread list" },
@@ -918,6 +928,8 @@ gdb_remote_commands = {
 def calculate_mean_and_standard_deviation(floats):
     sum = 0.0
     count = len(floats)
+    if count == 0:
+        return (0.0, 0.0)
     for f in floats:
         sum += f
     mean =  sum / count
@@ -928,8 +940,13 @@ def calculate_mean_and_standard_deviatio
         
     std_dev = math.sqrt(accum / (count-1));
     return (mean, std_dev)
+
+def parse_gdb_log_file(path, options):
+    f = open(path)
+    parse_gdb_log(f)
+    f.close()
     
-def parse_gdb_log_file(file, options):
+def parse_gdb_log(file, options):
     '''Parse a GDB log file that was generated by enabling logging with:
     (lldb) log enable --threadsafe --timestamp --file <FILE> gdb-remote packets
     This log file will contain timestamps and this function will then normalize
@@ -953,7 +970,6 @@ def parse_gdb_log_file(file, options):
     packet_total_times = {}
     packet_times = []
     packet_count = {}
-    file = open(file)
     lines = file.read().splitlines()
     last_command = None
     last_command_args = None
@@ -1100,13 +1116,16 @@ if __name__ == '__main__':
 
     # This script is being run from the command line, create a debugger in case we are
     # going to use any debugger functions in our function.
-    for file in args:
-        print '#----------------------------------------------------------------------'
-        print "# GDB remote log file: '%s'" % file
-        print '#----------------------------------------------------------------------'
-        parse_gdb_log_file (file, options)
-    if options.symbolicator:
-        print '%s' % (options.symbolicator)
+    if len(args):
+        for file in args:
+            print '#----------------------------------------------------------------------'
+            print "# GDB remote log file: '%s'" % file
+            print '#----------------------------------------------------------------------'
+            parse_gdb_log_file (file, options)
+        if options.symbolicator:
+            print '%s' % (options.symbolicator)
+    else:
+        parse_gdb_log(sys.stdin, options)
         
 else:
     import lldb





More information about the lldb-commits mailing list