aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2011-03-19 01:24:25 +0000
committerJohnny Chen <johnny.chen@apple.com>2011-03-19 01:24:25 +0000
commitce1eefdeb2a1d460daa64befd393858c5db02ee0 (patch)
tree3572a03027294f680816587862901b32b9f719ec /utils
parentb1888f24fa181489840b9acf193e224d125d0776 (diff)
downloadlldb-ce1eefdeb2a1d460daa64befd393858c5db02ee0.tar.gz
Modify disasm.py to better deal with the objc method name which has ':' in them.
Add a utility similar to disasm.py, but which provides a shell-like environment for invoking llvm-mc. git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@127936 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rwxr-xr-xutils/test/disasm.py7
-rwxr-xr-xutils/test/llvm-mc-shell.py100
2 files changed, 105 insertions, 2 deletions
diff --git a/utils/test/disasm.py b/utils/test/disasm.py
index 938e5fa52..83b113147 100755
--- a/utils/test/disasm.py
+++ b/utils/test/disasm.py
@@ -80,9 +80,12 @@ def do_llvm_mc_disassembly(exe, func, mc, mc_options = None):
gdb.sendline('x /%db %s' % (addr_diff, prev_addr))
gdb.expect(gdb_prompt)
x_output = gdb.before
- memory_dump = x_output.split(os.linesep)[-1].split(':')[-1].strip()
+ # Get the last output line from the gdb examine memory command,
+ # split the string into a 3-tuple with separator '>:' to handle
+ # objc method names.
+ memory_dump = x_output.split(os.linesep)[-1].partition('>:')[2].strip()
#print "\nbytes:", memory_dump
- disasm_str = prev_line.split(':')[1]
+ disasm_str = prev_line.partition('>:')[2]
print >> mc_input, '%s # %s' % (memory_dump, disasm_str)
# We're done with the processing. Assign the current line to be prev_line.
diff --git a/utils/test/llvm-mc-shell.py b/utils/test/llvm-mc-shell.py
new file mode 100755
index 000000000..0df0745d0
--- /dev/null
+++ b/utils/test/llvm-mc-shell.py
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+
+"""
+Run llvm-mc interactively.
+
+"""
+
+import os
+import sys
+from optparse import OptionParser
+
+def is_exe(fpath):
+ """Check whether fpath is an executable."""
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+def which(program):
+ """Find the full path to a program, or return None."""
+ fpath, fname = os.path.split(program)
+ if fpath:
+ if is_exe(program):
+ return program
+ else:
+ for path in os.environ["PATH"].split(os.pathsep):
+ exe_file = os.path.join(path, program)
+ if is_exe(exe_file):
+ return exe_file
+ return None
+
+def llvm_mc_loop(mc, mc_options):
+ contents = []
+ fname = 'mc-input.txt'
+ sys.stdout.write("Enter your input to llvm-mc. A line starting with 'END' terminates the cuurent batch of input.\n")
+ sys.stdout.write("Enter 'quit' or Ctrl-D to quit the program.\n")
+ while True:
+ sys.stdout.write("> ")
+ next = sys.stdin.readline()
+ # EOF => terminate this llvm-mc shell
+ if not next or next.startswith('quit'):
+ sys.stdout.write('\n')
+ sys.exit(0)
+ # 'END' => send the current batch of input to llvm-mc
+ if next.startswith('END'):
+ # Write contents to our file and clear the contents.
+ with open(fname, 'w') as f:
+ f.writelines(contents)
+ # Clear the list: replace all items with an empty list.
+ contents[:] = []
+
+ # Invoke llvm-mc with our newly created file.
+ mc_cmd = '%s %s %s' % (mc, mc_options, fname)
+ sys.stdout.write("Executing command: %s\n" % mc_cmd)
+ os.system(mc_cmd)
+ else:
+ # Keep accumulating our input.
+ contents.append(next)
+
+def main():
+ # This is to set up the Python path to include the pexpect-2.4 dir.
+ # Remember to update this when/if things change.
+ scriptPath = sys.path[0]
+ sys.path.append(os.path.join(scriptPath, os.pardir, os.pardir, 'test', 'pexpect-2.4'))
+
+ parser = OptionParser(usage="""\
+Do llvm-mc interactively within a shell-like environment. A batch of input is
+submitted to llvm-mc to execute whenever you terminate the current batch by
+inputing a line which starts with 'END'. Quit the program by either 'quit' or
+Ctrl-D.
+
+Usage: %prog [options]
+""")
+ parser.add_option('-m', '--llvm-mc',
+ type='string', action='store',
+ dest='llvm_mc',
+ help="""The llvm-mc executable full path, if specified.
+ Otherwise, it must be present in your PATH environment.""")
+
+ parser.add_option('-o', '--options',
+ type='string', action='store',
+ dest='llvm_mc_options',
+ help="""The options passed to 'llvm-mc' command if specified.""")
+
+ opts, args = parser.parse_args()
+
+ llvm_mc = opts.llvm_mc if opts.llvm_mc else which('llvm-mc')
+ if not llvm_mc:
+ parser.print_help()
+ sys.exit(1)
+
+ # This is optional. For example:
+ # --options='-disassemble -triple=arm-apple-darwin -debug-only=arm-disassembler'
+ llvm_mc_options = opts.llvm_mc_options
+
+ # We have parsed the options.
+ print "llvm-mc:", llvm_mc
+ print "llvm-mc options:", llvm_mc_options
+
+ llvm_mc_loop(llvm_mc, llvm_mc_options)
+
+if __name__ == '__main__':
+ main()