]> git.saurik.com Git - apple/xnu.git/blobdiff - tools/lldbmacros/utils.py
xnu-3248.40.184.tar.gz
[apple/xnu.git] / tools / lldbmacros / utils.py
index 104a528cc8b0e56efa08dce656872c17d90f70b4..68161d7c3bd46ab696329de6f3756f7cf3529038 100644 (file)
@@ -27,6 +27,8 @@ def lldb_run_command(cmdstring):
     lldb_run_command_state['active'] = False
     if res.Succeeded():
         retval = res.GetOutput()
+    else:
+        retval = "ERROR:" + res.GetError()
     return retval
 
 def EnableLLDBAPILogging():
@@ -44,9 +46,9 @@ def EnableLLDBAPILogging():
     cmd_str = enable_log_base_cmd + ' kdp-remote packets'
     print cmd_str
     print lldb_run_command(cmd_str)
-    print lldb_run_command("verison")
+    print lldb_run_command("version")
     print "Please collect the logs from %s for filing a radar. If you had encountered an exception in a lldbmacro command please re-run it." % logfile_name
-    print "Please make sure to provide the output of 'verison', 'image list' and output of command that failed."
+    print "Please make sure to provide the output of 'version', 'image list' and output of command that failed."
     return
 
 def GetConnectionProtocol():
@@ -111,6 +113,8 @@ def GetLongestMatchOption(searchstr, options=[], ignore_case=True):
         so = o
         if ignore_case:
             so = o.lower()
+        if so == searchstr:
+            return [o]
         if so.find(searchstr) >=0 :
             found_options.append(o)
     return found_options
@@ -358,6 +362,22 @@ def loadDSYM(uuid, load_address):
     debuglog(cmd_str)
     lldb.debugger.HandleCommand(cmd_str)
 
+def RunShellCommand(command):
+    """ Run a shell command in subprocess.
+        params: command with arguments to run
+        returns: (exit_code, stdout, stderr)
+    """
+    import shlex, subprocess
+    cmd_args = shlex.split(command)
+    output_str = ""
+    exit_code = 0
+    try:
+        output_str = subprocess.check_output(cmd_args, stderr=subprocess.STDOUT)
+    except subprocess.CalledProcessError, e:
+        exit_code = e.returncode
+    finally:
+        return (exit_code, output_str, '')
+
 def dsymForUUID(uuid):
     """ Get dsym informaiton by calling dsymForUUID 
         params: uuid - str - uuid string from executable. eg. 4DD2344C0-4A81-3EAB-BDCF-FEAFED9EB73E
@@ -389,3 +409,15 @@ def debuglog(s):
     if config['debug']:
       print "DEBUG:",s
     return None
+
+def IsAppleInternal():
+    """ check if apple_internal modules are available
+        returns: True if apple_internal module is present
+    """
+    import imp
+    try:
+        imp.find_module("apple_internal")
+        retval = True
+    except ImportError:
+        retval = False
+    return retval