Skip to content

Commit

Permalink
Fix filter bugs in btrace mode
Browse files Browse the repository at this point in the history
Signed-off-by: Peace Lee <iipeace5@gmail.com>
  • Loading branch information
iipeace committed Mar 7, 2020
1 parent 3dd4663 commit 1dbff57
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__credits__ = "Peace Lee"
__license__ = "GPLv2"
__version__ = "3.9.6"
__revision__ = "200306"
__revision__ = "200308"
__maintainer__ = "Peace Lee"
__email__ = "iipeace5@gmail.com"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -14231,13 +14231,13 @@ def printHelp():
# {0:1} {1:1} -g a.out -c write\\|kill

- Handle write function calls for a specific thread and modify specific memory value
# {0:1} {1:1} -g a.out -c write\\|setmem:0x1234:aaaa:4
# {0:1} {1:1} -g a.out -c write\\|wrmem:0x1234:aaaa:4

- Handle write function calls for a specific thread and modify specific memory value from 1st argument value
# {0:1} {1:1} -g a.out -c write\\|setmem:0:aaaa:4
# {0:1} {1:1} -g a.out -c write\\|wrmem:0:aaaa:4

- Handle printf function calls for a specific thread and print 10-length string that 1st argument point to
# {0:1} {1:1} -g a.out -c printf\\|getmem:0:10
# {0:1} {1:1} -g a.out -c printf\\|rdmem:0:10

- Handle write function calls for a specific thread and return a specific value
# {0:1} {1:1} -g a.out -c write\\|ret:3
Expand Down Expand Up @@ -24288,9 +24288,9 @@ def doCommonJobs(pids, procList):
execCmd = None
lockObj = None
procList = {}
bpList = {}
targetBpList = {}
targetBpFileList = {}
bpList = {}

# check input #
if len(SysMgr.filterGroup) == 0 and \
Expand Down Expand Up @@ -30883,12 +30883,16 @@ def __init__(self, pid=None, execCmd=None, attach=True):
self.totalCall = long(0)
self.callTable = {}
self.fileTable = {}
self.bpList = {}
self.exceptBpList = {}
self.targetBpList = {}
self.targetBpFileList = {}
self.bpList = {}
self.libcLoaded = False
self.defaulttargetBpFileList = {}
self.defaultTargetBpList = {'mmap': 0, 'mmap64': 0}
self.dftBpFileList = {}
self.dftBpSymList = {\
'mmap': 0,\
'mmap64': 0,\
}

self.backtrace = {
'x86': self.getBacktrace_X86,
Expand Down Expand Up @@ -31324,9 +31328,9 @@ def printCmdErr(cmdset, cmd):
cmdformat = "VAL"
elif cmd == 'setarg':
cmdformat = "R0:R1"
elif cmd == 'setmem':
elif cmd == 'wrmem':
cmdformat = "ADDR|REG:VAL:SIZE"
elif cmd == 'getmem':
elif cmd == 'rdmem':
cmdformat = "ADDR|REG:SIZE"
elif cmd == 'jump':
cmdformat = "SYMBOL|ADDR#ARG0#ARG1"
Expand Down Expand Up @@ -31419,7 +31423,7 @@ def printCmdErr(cmdset, cmd):
self.setRegs()
self.updateRegs()

elif cmd == 'setmem':
elif cmd == 'wrmem':
if len(cmdset) == 1:
printCmdErr(cmdval, cmd)

Expand Down Expand Up @@ -31456,7 +31460,7 @@ def printCmdErr(cmdset, cmd):
"Fail to write '%s' to %s" % (val, addr))
sys.exit(0)

elif cmd == 'getmem':
elif cmd == 'rdmem':
if len(cmdset) == 1:
printCmdErr(cmdval, cmd)

Expand Down Expand Up @@ -31650,8 +31654,8 @@ def injectBpList(self, symlist, binlist=None, verb=True):
cmdList = []

# add default breakpoints such as mmap symbols #
for lib in (self.defaulttargetBpFileList.keys()):
for dsym in list(self.defaultTargetBpList.keys()):
for lib in (self.dftBpFileList.keys()):
for dsym in list(self.dftBpSymList.keys()):
ret = self.getAddrBySymbol(dsym, binary=lib)
if not ret:
continue
Expand All @@ -31660,6 +31664,9 @@ def injectBpList(self, symlist, binlist=None, verb=True):
ret = self.injectBreakpoint(\
addr, dsym, fname=lib, reins=True)

# register exceptional address #
self.exceptBpList[addr] = 0

# add breakpoints requested by user #
for value in symlist:
# parse symbol and commands #
Expand Down Expand Up @@ -31693,7 +31700,7 @@ def injectBpList(self, symlist, binlist=None, verb=True):
if not ret:
if self.execCmd or \
value == '' or \
value in self.defaultTargetBpList:
value in self.dftBpSymList:
continue

SysMgr.printErr(\
Expand Down Expand Up @@ -31731,6 +31738,7 @@ def injectBpList(self, symlist, binlist=None, verb=True):
SysMgr.printWarn(\
"Fail to inject breakpoint to %s(%s) for %s thread" % \
(value, hex(addr), self.pid))
self.exceptBpList.pop(addr, None)

UtilMgr.deleteProgress()

Expand Down Expand Up @@ -32786,9 +32794,9 @@ def loadSymbols(self):
for fpath in list(self.pmap.keys()):
fname = os.path.basename(fpath)
if fname.startswith('ld-'):
self.defaulttargetBpFileList[fpath] = 0
self.dftBpFileList[fpath] = 0
if fname.startswith('libc-'):
self.defaulttargetBpFileList[fpath] = 0
self.dftBpFileList[fpath] = 0

# load file-mapped objects #
for mfile in list(self.pmap.keys()):
Expand Down Expand Up @@ -33503,16 +33511,11 @@ def handleBreakpoint(self, printStat=False, checkArg=None):
self.readArgs()[4] > 0:
self.needMapScan = True

# composite symbol and command set #
if cmd:
symCmd = '%s|%s' % (sym, '|'.join(cmd))
else:
symCmd = sym

# print context info #
if printStat and \
(len(self.targetBpList) == 0 or symCmd in self.targetBpList) and \
(len(self.targetBpFileList) == 0 or fname in self.targetBpFileList):
addr not in self.exceptBpList and \
(len(self.targetBpFileList) == 0 or \
fname in self.targetBpFileList):
# build arguments string #
if SysMgr.showAll:
# read args #
Expand Down

0 comments on commit 1dbff57

Please sign in to comment.