ich eine txt-Datei wie:Txt-Datei Parst eine Liste der .O Dateinamen zu bekommen
test.txt
Symbols from __ctype_tab.o:
Name Value Class Type Size Line Section
__ctype |00000000| D | OBJECT|00000004| |.data
__ctype_tab |00000000| r | OBJECT|00000101| |.rodata
Symbols from _ashldi3.o:
Name Value Class Type Size Line Section
__ashldi3 |00000000| T | FUNC|00000050| |.text
Symbols from _ashrdi3.o:
Name Value Class Type Size Line Section
__ashrdi3 |00000000| T | FUNC|00000058| |.text
Symbols from _fixdfdi.o:
Name Value Class Type Size Line Section
__fixdfdi |00000000| T | FUNC|0000004c| |.text
__fixunsdfdi | | U | NOTYPE| | |*UND*
Symbols from _fixsfdi.o:
Name Value Class Type Size Line Section
__fixsfdi |00000000| T | FUNC|0000004c| |.text
__fixunssfdi | | U | NOTYPE| | |*UND*
Symbols from _fixunssfdi.o:
Name Value Class Type Size Line Section
__cmpdi2 | | U | NOTYPE| | |*UND*
__fixunssfdi |00000000| T | FUNC|00000228| |.text
__floatdidf | | U | NOTYPE| | |*UND*
Was ich tun möchte, ist, werde ich eine Funktion, die gegeben werden Geben Sie NOTYPE ein. Ich muss den TXT suchen und finde heraus, unter welchem .o es definiert ist (dh mit dem Typ FUNC). Wenn ich die .o-Datei bekomme, sehe ich vielleicht andere Funktionen als NOTYPE. Dann muss ich suchen, wo diese definiert sind. Es geht weiter. Schließlich möchte ich eine Liste von Namen aller .o-Dateien zurückgeben, die die Funktionen enthielten.
Mein Stück Code:
notypeDict , funcDict = {} , {}
notypeList , funcList = [] , []
currObj , prevObj = '' , ''
fp = open(r'C:\test.txt','r') # file path cms here
fileList = fp.readlines()
for line in fileList:
if '.o' in line: # line containg .o
currObj=line.split()[-1][0:-1]
if '|' not in line: # line containg |
pass
else: # other lines
dataList=[dataItem.strip() for dataItem in line.strip().split('|')] # a list of each word in line
name=dataList[0].strip() # name of the function
notypeDict[prevObj] = notypeList # notypeDict is a dictionary which contains .o as key and a list of NOTYPE function name
funcDict[prevObj] = funcList # funcDict is a dictionary which contains .o as key and a list of FUNC function names
if prevObj == currObj :
pass
if prevObj != currObj :
notypeList , funcList = [] , []
if dataList[3] == 'NOTYPE' :
notypeList.append(name)
if dataList[3] == 'FUNC' :
funcList.append(name)
prevObj = currObj
print 'notypeDict' , notypeDict
print '\n\nfuncDict' , funcDict
Here i zwei Wörterbücher bekommen, notypeDict und funcDict.
notypeDict hat .o als Schlüssel und eine Liste von NOTYPE-Funktionen als Wert funcDict hat .o als Schlüssel und eine Liste von FUNC-Funktionen als Wert.
Ich habe bis hier erreicht.
Aber keine Ideen, wie Sie vorgehen, um mein Ziel zu erreichen.
Ich denke meine Frage ist klar.
Bitte helfen Sie mir.
Ich stimme zu, Herr über die Verwendung von elif – user46646