gdb-common.inc: Use FILESPATHPKG in place of FILESDIR.
[openembedded.git] / lib / oe / qa.py
blob01813931bba233d40d12133f5444f17f14f3f68c
1 class ELFFile:
2 EI_NIDENT = 16
4 EI_CLASS = 4
5 EI_DATA = 5
6 EI_VERSION = 6
7 EI_OSABI = 7
8 EI_ABIVERSION = 8
10 # possible values for EI_CLASS
11 ELFCLASSNONE = 0
12 ELFCLASS32 = 1
13 ELFCLASS64 = 2
15 # possible value for EI_VERSION
16 EV_CURRENT = 1
18 # possible values for EI_DATA
19 ELFDATANONE = 0
20 ELFDATA2LSB = 1
21 ELFDATA2MSB = 2
23 def my_assert(self, expectation, result):
24 if not expectation == result:
25 #print "'%x','%x' %s" % (ord(expectation), ord(result), self.name)
26 raise Exception("This does not work as expected")
28 def __init__(self, name, bits32):
29 self.name = name
30 self.bits32 = bits32
32 def open(self):
33 self.file = file(self.name, "r")
34 self.data = self.file.read(ELFFile.EI_NIDENT+4)
36 self.my_assert(len(self.data), ELFFile.EI_NIDENT+4)
37 self.my_assert(self.data[0], chr(0x7f) )
38 self.my_assert(self.data[1], 'E')
39 self.my_assert(self.data[2], 'L')
40 self.my_assert(self.data[3], 'F')
41 if self.bits32 :
42 self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS32))
43 else:
44 self.my_assert(self.data[ELFFile.EI_CLASS], chr(ELFFile.ELFCLASS64))
45 self.my_assert(self.data[ELFFile.EI_VERSION], chr(ELFFile.EV_CURRENT) )
47 self.sex = self.data[ELFFile.EI_DATA]
48 if self.sex == chr(ELFFile.ELFDATANONE):
49 raise Exception("self.sex == ELFDATANONE")
50 elif self.sex == chr(ELFFile.ELFDATA2LSB):
51 self.sex = "<"
52 elif self.sex == chr(ELFFile.ELFDATA2MSB):
53 self.sex = ">"
54 else:
55 raise Exception("Unknown self.sex")
57 def osAbi(self):
58 return ord(self.data[ELFFile.EI_OSABI])
60 def abiVersion(self):
61 return ord(self.data[ELFFile.EI_ABIVERSION])
63 def isLittleEndian(self):
64 return self.sex == "<"
66 def isBigEngian(self):
67 return self.sex == ">"
69 def machine(self):
70 """
71 We know the sex stored in self.sex and we
72 know the position
73 """
74 import struct
75 (a,) = struct.unpack(self.sex+"H", self.data[18:20])
76 return a