Skip to content

Instantly share code, notes, and snippets.

@dcci
Created February 25, 2019 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcci/94a4936a227d9c7627b91ae9575b7b68 to your computer and use it in GitHub Desktop.
Save dcci/94a4936a227d9c7627b91ae9575b7b68 to your computer and use it in GitHub Desktop.
$ cat mi-driver.py
from builtins import bytes
import subprocess
import sys
from subprocess import Popen
from subprocess import PIPE
def sendCmd(process, command):
command += "\n"
by_str = bytes(command, 'utf-8')
process.stdin.write(by_str)
process.stdin.flush()
def readOutputLine(process):
byte_str = process.stdout.readline()
return byte_str.decode("utf-8").strip("\n")
def spawnMI(mi_path):
args = [mi_path]
return Popen(args, stdout=PIPE, stdin=PIPE, stderr=PIPE)
def compare(expected, actual):
if expected == actual:
return
print("Mismatch in reply!")
print("Expected: " + expected)
print("Actual: " + actual)
def main():
mi_path = "/Users/davide/work/llvm-project-20170507/build-py/bin/lldb-mi"
proc = spawnMI(mi_path)
reply = readOutputLine(proc)
print(reply)
sendCmd(proc, "-unknown-command")
reply = readOutputLine(proc)
print(reply)
return
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment