-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGDBDataInterface.py
35 lines (32 loc) · 1.48 KB
/
GDBDataInterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gdb
class UnacceptableTypeException(Exception):
pass
class GDBDataExtractor():
def __init__(self, variableName: str) -> None:
self.variableName = variableName
def __call__(self):
buffer = gdb.parse_and_eval(self.variableName)
if buffer.type.code != gdb.TYPE_CODE_ARRAY:
raise UnacceptableTypeException(f"{self.variableName} is not an array")
valueArray = []
gdbOutputString = buffer.format_string(max_elements=0, max_depth=-1)
splitArray = gdbOutputString.split(',')
for string in splitArray:
leftIndex = string.find('{')
rightIndex = string.find('}')
if leftIndex == -1 and rightIndex == -1:
try:
valueArray.append(float(string))
except ValueError:
raise UnacceptableTypeException(f"Unable to interrupt {self.variableName} as an value array")
elif leftIndex == -1 and rightIndex != -1:
try:
valueArray.append(float(string[:rightIndex]))
except ValueError:
raise UnacceptableTypeException(f"Unable to interrupt {self.variableName} as an value array")
else:
try:
valueArray.append(float(string[leftIndex+1:-1]))
except ValueError:
raise UnacceptableTypeException(f"Unable to interrupt {self.variableName} as an value array")
return valueArray