Skip to content

Commit

Permalink
Verbose option to enable Qira debug loggin in QEMU
Browse files Browse the repository at this point in the history
This allows users of Qira to get our custom QEMU build to log
Qira-related debug messages, by providing the -v or --verbose option to
Qira itself.

The QEMU log is stored in /tmp/qira_logs/qemu (along with the other log
files generated by Qira).

The weirdness with changing qemu_args from an array to a hash is because
QEMU's command line parsing does not support providing multiple -d
options that combine, the last one always wins (and multiple values must
be provided comma separated).
  • Loading branch information
Hamled committed Jun 18, 2019
1 parent 776f869 commit d4c030d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions middleware/qira.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
parser.add_argument("--web-port", metavar="PORT", help="listen port for web interface. 3002 by default", type=int, default=qira_config.WEB_PORT)
parser.add_argument("--socat-port", metavar="PORT", help="listen port for socat. 4000 by default", type=int, default=qira_config.SOCAT_PORT)
parser.add_argument('-S', '--static', help="enable static2", action="store_true")
parser.add_argument('-v', '--verbose', help="enable debug logging", action="store_true")
#capstone flag in qira_config for now

# parse arguments, first try
Expand Down Expand Up @@ -73,10 +74,13 @@
os.system("rm -rfv /tmp/qira*")

# qemu args from command line
qemu_args = []
qemu_args = { "args": [], "logs": [] }
if args.gate_trace != None:
qemu_args.append("-gatetrace")
qemu_args.append(args.gate_trace)
qemu_args["args"].append("-gatetrace")
qemu_args["args"].append(args.gate_trace)
if args.verbose != None:
qemu_args["args"].extend(["-D", "/tmp/qira_logs/qemu"])
qemu_args["logs"].append("qira")

# creates the file symlink, program is constant through server run
program = qira_program.Program(args.binary, args.args, qemu_args)
Expand Down
2 changes: 1 addition & 1 deletion middleware/qira_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def get_loads(clnum):

if __name__ == "__main__":
# can run standalone for testing
program = qira_program.Program("/tmp/qira_binary", [])
program = qira_program.Program("/tmp/qira_binary")
trace = program.add_trace("/tmp/qira_logs/0", 0)
while not trace.db.did_update():
time.sleep(0.1)
Expand Down
8 changes: 6 additions & 2 deletions middleware/qira_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def which(prog):

# things that don't cross the fork
class Program:
def __init__(self, prog, args=[], qemu_args=[]):
def __init__(self, prog, args=[], qemu_args={}):
# create the logs dir
try:
os.mkdir(qira_config.TRACE_FILE_BASE)
Expand Down Expand Up @@ -76,7 +76,11 @@ def __init__(self, prog, args=[], qemu_args=[]):
pass

# defaultargs for qira binary
self.defaultargs = ["-strace", "-D", "/dev/null", "-d", "in_asm", "-singlestep"]+qemu_args
logs = ["in_asm"]+qemu_args.get("logs", [])
self.defaultargs = ["-strace",
"-D", "/dev/null",
"-d", ",".join(logs),
"-singlestep"]+qemu_args.get("args", [])
if qira_config.TRACE_LIBRARIES:
self.defaultargs.append("-tracelibraries")

Expand Down

0 comments on commit d4c030d

Please sign in to comment.