代码拉取完成,页面将自动刷新
#!/usr/bin/python
# Copyright (c) 2014, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
import lldb
import imp
import os
import shlex
import sys
from optparse import OptionParser
import fblldbbase as fb
def __lldb_init_module(debugger, dict):
filePath = os.path.realpath(__file__)
lldbHelperDir = os.path.dirname(filePath)
commandsDirectory = os.path.join(lldbHelperDir, 'commands')
loadCommandsInDirectory(commandsDirectory)
def loadCommandsInDirectory(commandsDirectory):
for file in os.listdir(commandsDirectory):
fileName, fileExtension = os.path.splitext(file)
if fileExtension == '.py':
module = imp.load_source(fileName, os.path.join(commandsDirectory, file))
if hasattr(module, 'lldbinit'):
module.lldbinit()
if hasattr(module, 'lldbcommands'):
module._loadedFunctions = {}
for command in module.lldbcommands():
loadCommand(module, command, commandsDirectory, fileName, fileExtension)
def loadCommand(module, command, directory, filename, extension):
func = makeRunCommand(command, os.path.join(directory, filename + extension))
name = command.name()
key = filename + '_' + name
module._loadedFunctions[key] = func
functionName = '__' + key
lldb.debugger.HandleCommand('script ' + functionName + ' = sys.modules[\'' + module.__name__ + '\']._loadedFunctions[\'' + key + '\']')
lldb.debugger.HandleCommand('command script add -f ' + functionName + ' ' + name)
def makeRunCommand(command, filename):
def runCommand(debugger, input, result, dict):
splitInput = shlex.split(input)
options = None
args = None
# OptionParser will throw in the case where you want just one big long argument and no
# options and you enter something that starts with '-' in the argument. e.g.:
# somecommand -[SomeClass someSelector:]
# This solves that problem by prepending a '--' so that OptionParser does the right
# thing.
options = command.options()
if len(options) == 0:
if '--' not in splitInput:
splitInput.insert(0, '--')
parser = optionParserForCommand(command)
(options, args) = parser.parse_args(splitInput)
# When there are more args than the command has declared, assume
# the initial args form an expression and combine them into a single arg.
if len(args) > len(command.args()):
overhead = len(args) - len(command.args())
head = args[:overhead + 1] # Take N+1 and reduce to 1.
args = [' '.join(head)] + args[-overhead:]
if validateArgsForCommand(args, command):
command.run(args, options)
runCommand.__doc__ = helpForCommand(command, filename)
return runCommand
def validateArgsForCommand(args, command):
if len(args) < len(command.args()):
defaultArgs = [arg.default for arg in command.args()]
defaultArgsToAppend = defaultArgs[len(args):]
index = len(args)
for defaultArg in defaultArgsToAppend:
if not defaultArg:
arg = command.args()[index]
print 'Whoops! You are missing the <' + arg.argName + '> argument.'
print '\nUsage: ' + usageForCommand(command)
return
index += 1
args.extend(defaultArgsToAppend)
return True
def optionParserForCommand(command):
parser = OptionParser()
for argument in command.options():
if argument.boolean:
parser.add_option(argument.shortName, argument.longName, dest=argument.argName,
help=argument.help, action=("store_false" if argument.default else "store_true"))
else:
parser.add_option(argument.shortName, argument.longName, dest=argument.argName,
help=argument.help, default=argument.default)
return parser
def helpForCommand(command, filename):
help = command.description()
argSyntax = ''
optionSyntax = ''
if command.args():
help += '\n\nArguments:'
for arg in command.args():
help += '\n <' + arg.argName + '>; Type: ' + arg.argType + '; ' + arg.help
argSyntax += ' <' + arg.argName + '>'
if command.options():
help += '\n\nOptions:'
for option in command.options():
optionFlag = ''
if option.longName and option.shortName:
optionFlag = option.longName + '/' + option.shortName
elif option.longName:
optionFlag = option.longName
else:
optionFlag = optiob.shortName
help += '\n ' + optionFlag + ' '
if not option.boolean:
help += '<' + option.argName + '>; Type: ' + option.argType
help += '; ' + option.help
optionSyntax += ' [{name}{arg}]'.format(
name=(option.longName or option.shortName),
arg=('' if option.boolean else ('=' + option.argName))
)
help += '\n\nSyntax: ' + command.name() + optionSyntax + argSyntax
help += '\n\nThis command is implemented as %s in %s.' % (command.__class__.__name__, filename)
help += '\n\n(LLDB adds the next line, sorry...)'
return help
def usageForCommand(command):
usage = command.name()
for arg in command.args():
if arg.default:
usage += ' [' + arg.argName + ']'
else:
usage += ' ' + arg.argName
return usage
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。