|
| 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