2012-11-13 4 views
1

나는이 방법으로 strace를 사용하고 그런 다음 strace를 출력 처리

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

내가 나오지와 클리어 파일 목록을 얻고있다 :

/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 
:

sed -n 's/.*open("\(.*\)".*)\s*=.*/\1/p' out_configure.log out_make.log | sort -u 

은 출력 예입니다

내 문제는 전체 이름이 아닌 항목 (예 : "util.c"또는 "./util_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 

하지만 파이썬 내 지식은 매우 좋지 않습니다.

오류가 있습니까? 아니면 실수입니까?

+3

strace는 시스템 호출이 기록 될 때이를 기록합니다. 프로그램이'open ("util_charset.c", ...)'을 요구하면, 그것은 기록 될 이름입니다. 상대 경로 이름 ('open ("subdir/file.c", ...)'을 포함하여)을 해석 할 수 있도록 프로세스의 현재 디렉토리를 알아야합니다. 이를 위해서는 프로세스 시작시의 현재 디렉토리와 프로세스 실행 중에 변경된 모든 프로세스의 현재 디렉토리를 알아야합니다. 예를 들어, 프로그램 소스 코드의 구 버전과 새 버전이있는 두 개의 디렉토리가 있다면, 어떤 빌드가 추적되었는지'strace' 출력에서 ​​말할 수 없을 수도 있습니다. –

답변

0

이들은 사용자가 만드는 응용 프로그램과 관련된 로컬 파일입니다.

다른 파일로 목록을 구문 분석 한 다음 /로 시작하거나 /로 시작하지 않는 파일을 찾아 스크립트 내에서 경로를 매핑하는 find를 수행 할 수 있습니다. 아래의 예에서

나는 아파치 구축되었고, 그 같은 파일

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 숨겨진 폴더에 (서버 폴더의 빌드 프로세스의 일부를) 출연 : 여기 무엇을하는 하나의 라이너 당신이 필요합니다

command="sed -n 's/.*open(\"\(.*\)\".*)\s*=.*/\1/p' out_configure.log out_make.log | sort -u"; echo "remote: " && echo $command| /bin/sh|grep "^/" ;echo "______________________"; echo "local" && echo $command|/bin/sh|grep -v "^/" |xargs -I {} find . -name {} -print 
2

내가이 작업을 수행하기 위해, 당신은 또한 chdir() 시스템 호출을 추적해야합니다 생각합니다. 후 처리는 더 복잡 할 것이므로 chdir()을 해석 할 때마다 현재 작업 디렉토리가 변경 될 때이를 추적해야하기 때문에 awk, perl, python 또는 후 처리를 위해 다른 것으로 전환해야 할 수도 있습니다. open() 호출은 상대 경로이거나 로컬 경로이므로 (예 : 전체 경로가 아님) 현재 경로를 앞에두고 ../ 등의 항목을 조정해야합니다.

관련 문제