-
Notifications
You must be signed in to change notification settings - Fork 105
/
run_gdbserver_sim.py
111 lines (90 loc) · 2.76 KB
/
run_gdbserver_sim.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python3
# Python module to run programs on a gdbserver with simulator
# Copyright (C) 2019 Embecosm Limited
#
# Contributor: Jeremy Bennett <[email protected]>
#
# This file is part of Embench.
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Embench module to run benchmark programs.
This version is suitable for a gdbserver with simulator.
"""
__all__ = [
'get_target_args',
'build_benchmark_cmd',
'decode_results',
]
import argparse
import re
from embench_core import log
def get_target_args(remnant):
"""Parse left over arguments"""
parser = argparse.ArgumentParser(description='Get target specific args')
parser.add_argument(
'--gdb-command',
type=str,
default='gdb',
help='Command to invoke GDB',
)
parser.add_argument(
'--gdbserver-command',
type=str,
default='gdbserver',
help='Command to invoke the GDB server',
)
parser.add_argument(
'--gdbserver-target',
type=str,
default='ri5cy',
help='target argument to gdbserver',
)
return parser.parse_args(remnant)
def build_benchmark_cmd(bench, args):
"""Construct the command to run the benchmark. "args" is a
namespace with target specific arguments"""
cmd = [f'{args.gdb_command}']
gdb_comms = [
'set confirm off',
'set style enabled off',
'set height 0',
'file {0}',
f'target remote | {args.gdbserver_command} '
+ f'-c {args.gdbserver_target} --stdin',
'stepi',
'stepi',
'load',
'break start_trigger',
'break stop_trigger',
'break _exit',
'jump *_start',
'monitor cyclecount',
'continue',
'monitor cyclecount',
'continue',
'print $a0',
'detach',
'quit',
]
for arg in gdb_comms:
cmd.extend(['-ex', arg.format(bench)])
return cmd
def decode_results(stdout_str, stderr_str):
"""Extract the results from the output string of the run. Return the
elapsed time in milliseconds or zero if the run failed."""
# Return code is in standard output. We look for the string that means we
# hit a breakpoint on _exit, then for the string returning the value.
rcstr = re.search(
'Breakpoint 3,.*\$1 = (\d+)', stdout_str, re.S
)
if not rcstr:
log.debug('Warning: Failed to find return code')
return 0.0
# The start and end cycle counts are in the stderr string
times = re.search('(\d+)\D+(\d+)', stderr_str, re.S)
if times:
ms_elapsed = float(int(times.group(2)) - int(times.group(1))) / 1000.0
return ms_elapsed
# We must have failed to find a time
log.debug('Warning: Failed to find timing')
return 0.0