Skip to content

Commit 036b375

Browse files
committed
Gdbserver: move gdbserver commands to separate module.
1 parent 4c3047b commit 036b375

File tree

2 files changed

+88
-62
lines changed

2 files changed

+88
-62
lines changed

pyocd/gdbserver/gdbserver.py

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from .symbols import GDBSymbolProvider
4141
from ..rtos import RTOS
4242
from . import signals
43+
from . import gdbserver_commands
4344
from .packet_io import (
4445
CTRL_C,
4546
checksum,
@@ -1204,65 +1205,3 @@ def _option_did_change(self, notification):
12041205
elif notification.event == 'report_core_number':
12051206
self.report_core = notification.data.new_value
12061207

1207-
class ThreadsCommand(CommandBase):
1208-
INFO = {
1209-
'names': ['threads'],
1210-
'group': 'gdbserver',
1211-
'category': 'threads',
1212-
'nargs': 1,
1213-
'usage': "{flush,enable,disable,status}",
1214-
'help': "Control thread awareness.",
1215-
}
1216-
1217-
def parse(self, args):
1218-
self.action = args[0]
1219-
if self.action not in ('flush', 'enable', 'disable', 'status'):
1220-
raise exceptions.CommandError("invalid action")
1221-
1222-
def execute(self):
1223-
# Get the gdbserver for the selected core.
1224-
core_number = self.context.target.selected_core.core_number
1225-
try:
1226-
gdbserver = self.context.session.gdbservers[core_number]
1227-
except KeyError:
1228-
raise exceptions.CommandError("no gdbserver for core #%i" % core_number)
1229-
1230-
if gdbserver.thread_provider is None:
1231-
self.context.write("Threads are unavailable")
1232-
return
1233-
1234-
if self.action == 'flush':
1235-
gdbserver.thread_provider.invalidate()
1236-
self.context.write("Threads flushed")
1237-
elif self.action == 'enable':
1238-
gdbserver.thread_provider.read_from_target = True
1239-
self.context.write("Threads enabled")
1240-
elif self.action == 'disable':
1241-
gdbserver.thread_provider.read_from_target = False
1242-
self.context.write("Threads disabled")
1243-
elif self.action == 'status':
1244-
self.context.write("Threads are " +
1245-
("enabled" if gdbserver.thread_provider.read_from_target else "disabled"))
1246-
1247-
class ArmSemihostingCommand(CommandBase):
1248-
INFO = {
1249-
'names': ['arm'],
1250-
'group': 'gdbserver',
1251-
'category': 'semihosting',
1252-
'nargs': 2,
1253-
'usage': "semihosting {enable,disable}",
1254-
'help': "Enable or disable semihosting.",
1255-
'extra_help': "Provided for compatibility with OpenOCD. The same functionality can be achieved "
1256-
"by setting the 'enable_semihosting' session option.",
1257-
}
1258-
1259-
def parse(self, args):
1260-
if args[0] != 'semihosting':
1261-
raise exceptions.CommandError("invalid action")
1262-
if args[1] not in ('enable', 'disable'):
1263-
raise exceptions.CommandError("invalid action")
1264-
self.action = args[1]
1265-
1266-
def execute(self):
1267-
enable = (self.action == 'enable')
1268-
self.context.session.options['enable_semihosting'] = enable
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# pyOCD debugger
2+
# Copyright (c) 2020 Arm Limited
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import logging
18+
import six
19+
20+
from ..core import exceptions
21+
from ..commands.execution_context import CommandExecutionContext
22+
from ..commands.base import CommandBase
23+
24+
LOG = logging.getLogger(__name__)
25+
26+
class ThreadsCommand(CommandBase):
27+
INFO = {
28+
'names': ['threads'],
29+
'group': 'gdbserver',
30+
'category': 'threads',
31+
'nargs': 1,
32+
'usage': "{flush,enable,disable,status}",
33+
'help': "Control thread awareness.",
34+
}
35+
36+
def parse(self, args):
37+
self.action = args[0]
38+
if self.action not in ('flush', 'enable', 'disable', 'status'):
39+
raise exceptions.CommandError("invalid action")
40+
41+
def execute(self):
42+
# Get the gdbserver for the selected core.
43+
core_number = self.context.target.selected_core.core_number
44+
try:
45+
gdbserver = self.context.session.gdbservers[core_numb
46+
except KeyError:
47+
raise exceptions.CommandError("no gdbserver for core #%i" % core_number)
48+
49+
if gdbserver.thread_provider is None:
50+
self.context.write("Threads are unavailable")
51+
return
52+
53+
if self.action == 'flush':
54+
gdbserver.thread_provider.invalidate()
55+
self.context.write("Threads flushed")
56+
elif self.action == 'enable':
57+
gdbserver.thread_provider.read_from_target = True
58+
self.context.write("Threads enabled")
59+
elif self.action == 'disable':
60+
gdbserver.thread_provider.read_from_target = False
61+
self.context.write("Threads disabled")
62+
elif self.action == 'status':
63+
self.context.write("Threads are " +
64+
("enabled" if gdbserver.thread_provider.read_from_target else "disabled"))
65+
66+
class ArmSemihostingCommand(CommandBase):
67+
INFO = {
68+
'names': ['arm'],
69+
'group': 'gdbserver',
70+
'category': 'semihosting',
71+
'nargs': 2,
72+
'usage': "semihosting {enable,disable}",
73+
'help': "Enable or disable semihosting.",
74+
'extra_help': "Provided for compatibility with OpenOCD. The same functionality can be achieved "
75+
"by setting the 'enable_semihosting' session option.",
76+
}
77+
78+
def parse(self, args):
79+
if args[0] != 'semihosting':
80+
raise exceptions.CommandError("invalid action")
81+
if args[1] not in ('enable', 'disable'):
82+
raise exceptions.CommandError("invalid action")
83+
self.action = args[1]
84+
85+
def execute(self):
86+
enable = (self.action == 'enable')
87+
self.context.session.options['enable_semihosting'] = enable

0 commit comments

Comments
 (0)