This repository was archived by the owner on Sep 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmrisc32-trace-tool.py
More file actions
executable file
·83 lines (74 loc) · 3.12 KB
/
mrisc32-trace-tool.py
File metadata and controls
executable file
·83 lines (74 loc) · 3.12 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# -*- mode: python; tab-width: 4; indent-tabs-mode: nil; -*-
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2019 Marcus Geelnard
#
# This software is provided 'as-is', without any express or implied warranty. In no event will the
# authors be held liable for any damages arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose, including commercial
# applications, and to alter it and redistribute it freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not claim that you wrote
# the original software. If you use this software in a product, an acknowledgment in the
# product documentation would be appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
# being the original software.
#
# 3. This notice may not be removed or altered from any source distribution.
# -------------------------------------------------------------------------------------------------
import argparse
import struct
import sys
def load_record(f):
buf_str = f.read(5*4)
if len(buf_str) < 5*4:
return
buf = struct.unpack('<LLLLL', buf_str)
flags = buf[0]
return {
'valid': True if flags & 1 != 0 else False,
'src_a_valid': True if flags & 2 != 0 else False,
'src_b_valid': True if flags & 4 != 0 else False,
'src_c_valid': True if flags & 8 != 0 else False,
'pc': buf[1],
'src_a': buf[2],
'src_b': buf[3],
'src_c': buf[4]
}
def show(trace_file, show_operands, show_defunct):
with open(trace_file, 'rb') as f:
while True:
trace = load_record(f)
if not trace:
break
if trace['valid'] or show_defunct:
s = f"{trace['pc']:08X}"
if show_operands:
s += ":"
s += f" {trace['src_a']:08X}" if trace['src_a_valid'] else (" " + "-" * 8)
s += f" {trace['src_b']:08X}" if trace['src_b_valid'] else (" " + "-" * 8)
s += f" {trace['src_c']:08X}" if trace['src_c_valid'] else (" " + "-" * 8)
if not trace['valid']:
s += ' [defunct]'
print(s)
def main():
# Parse command line arguments.
parser = argparse.ArgumentParser(
description='Tool for inspecting MRISC32 debug trace files')
parser.add_argument('file', metavar='TRACE_FILE', help='the debug trace file to show')
parser.add_argument('-o', '--operands', action='store_true', help='show operand values')
parser.add_argument('-d', '--defunct', action='store_true', help='show defunct operations (bubbles)')
args = parser.parse_args()
# Show the file.
show(args.file, args.operands, args.defunct)
if __name__ == "__main__":
try:
main()
except (BrokenPipeError, IOError):
pass
try:
sys.stdout.close()
except (BrokenPipeError, IOError):
pass