strace输出处理

2024-10-01 19:18:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我是这样使用strace的: 在

strace -xf -eopen -o out_configure.log ./configure
strace -xf -eopen -o out_make.log make

然后我得到了sed的清晰文件列表: 在

^{pr2}$

有一个输出示例:

/usr/share/locale-langpack/en.utf8/LC_MESSAGES/gcc-4.6.mo
/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/gcc-4.6.mo
/usr/share/locale-langpack/en.utf8/LC_MESSAGES/grep.mo
/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/grep.mo
/usr/share/locale-langpack/en.utf8/LC_MESSAGES/make.mo
/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/make.mo
/usr/share/locale/locale.alias
/usr/share/misc/magic.mgc
/usr/x86_64-linux-gnu/lib64/libc_r.a
/usr/x86_64-linux-gnu/lib64/libc_r.so
/usr/x86_64-linux-gnu/lib64/libsendfile.a
/usr/x86_64-linux-gnu/lib64/libsendfile.so
/usr/x86_64-linux-gnu/lib64/libtruerand.a
/usr/x86_64-linux-gnu/lib64/libtruerand.so
/usr/x86_64-linux-gnu/lib64/libuuid.a
/usr/x86_64-linux-gnu/lib64/libuuid.so
util.c
util_cfgtree.c
./util_cfgtree.h
util_cfgtree.h
util_cfgtree.i
./util_cfgtree.lo
util_cfgtree.lo
util_cfgtree.loT
util_cfgtree.o
util_cfgtree.s
util_charset.c
./util_charset.h

我的问题是非全名条目(例如“util.c”或“../util\u cfgtree.h”)。 有没有办法在strace输出中获取全名?在

我写了这个剧本:

#!/usr/bin/python
# coding=UTF8
import subprocess
import os

fileList = []
for dirname, dirnames, filenames in os.walk(os.path.abspath('.')):
    for filename in filenames:
        fileList.append(os.path.join(dirname, filename))

straceProcess = subprocess.Popen("strace -s 1000 -xf -o out_configure.sed.log ./configure".split(), stdout=subprocess.PIPE).communicate()[0]
straceProcess2 = subprocess.Popen("strace -s 1000 -xf -o out_make.sed.log make".split(), stdout=subprocess.PIPE).communicate()[0]


f = open("out_configure.sed.log", "r+")
n = open("out_make.sed.log", "r+")

lines = []
for l in f:
    lines.append(l)
for l in n:
    lines.append(l)

f.close()
n.close()

pids = {}

filesInUse = []
currentDir = os.path.abspath('.')
for line in lines:
    parts = line.split()

if not pids.has_key(parts[0]):
    pids[parts[0]] = currentDir

if parts[1].startswith("clone"):
    pid = parts[parts.__len__() - 1]
    if not pids.has_key(pid):
        pids[pid] = os.path.abspath(pids.get(parts[0]))


elif parts[1].startswith("chdir"):
    if parts[1].split("\"")[1].startswith("/"):
        pids[parts[0]] = os.path.abspath(parts[1].split("\"")[1])

    elif parts[1].split("\"")[1].startswith("."):
        pids[parts[0]] = os.path.abspath(pids.get(pids[parts[0]]) + '/' + parts[1].split("\"")[1])
    else:
        pids[parts[0]] = os.path.abspath(pids.get(parts[0]) + '/' + parts[1].split("\"")[1])

elif parts[1].startswith("open("):
    if parts[1].split("\"")[1].startswith("/"):
        filesInUse.append(os.path.abspath(parts[1].split("\"")[1]))
    elif parts[1].split("\"")[1].startswith("."):
        filesInUse.append(os.path.abspath(pids.get(parts[0]) + '/' + parts[1].split("\"")[1]))
    else:
        filesInUse.append(os.path.abspath(pids.get(parts[0]) + '/' + parts[1].split("\"")[1]))


for l in filesInUse:
    if l in fileList:
        fileList.remove(l)

for l in fileList:
    print  l

但是我对Python的了解很差。在

是否有错误或错误的解决方案?在


Tags: pathgnushareoslinuxusrutillocale
2条回答

这些是与您正在制作的应用程序相关的本地文件。在

您可以将列表解析为另一个文件,然后查找以./或不以/开头的任何内容,并在脚本中执行find-within脚本来映射路径。在

在下面的例子中,我正在构建apache,这些文件出现在一个隐藏的文件夹中(它的构建过程的一部分在服务器文件夹中)

find . -name vhost.o
./server/.libs/vhost.o
./server/vhost.o

ls  server/.libs/
config.o      core_filters.o  eoc_bucket.o    exports.o        libmain.a   listen.o  main.o        protocol.o  request.o     util_cfgtree.o  util_debug.o   util_filter.o  util.o       util_script.o  util_xml.o
connection.o  core.o          error_bucket.o  gen_test_char.o  libmain.la  log.o     mpm_common.o  provider.o  scoreboard.o  util_charset.o  util_ebcdic.o  util_md5.o     util_pcre.o  util_time.o    vhost.o

E2A: 这里有一个可以满足您需要的一行程序:

^{pr2}$

我认为为了做到这一点,您还需要跟踪chdir()系统调用。后处理会更复杂,并且您可能需要切换到awkperlpython或其他方式进行后期处理,因为您需要解释每个{}以跟踪当前工作目录的变化,然后,对于open()调用,无论是相对的还是本地的(即,不是完整路径),您需要预先设置当前路径,并对../等进行任何调整

相关问题 更多 >

    热门问题