Skip to content

Commit

Permalink
rtos: Fix reading Zephyr thread name and update debug symbol names (#…
Browse files Browse the repository at this point in the history
…1320)

* rtos: Fix reading Zephyr thread name

The Zephyr thread structure was changed to hold a buffered copy of the
thread name rather than a pointer to the thread name, in order to fix
potential access issues when reading from user mode. This was
implemented in Zephyr v2.0.0 and backported to the 1.14 LTS branch.

See zephyrproject-rtos/zephyr#17071 for further
details.

Signed-off-by: Maureen Helm <[email protected]>

* rtos: Update Zephyr debug symbol names

Zephyr thread awareness was first introduced for OpenOCD, then later
extended to include pyOCD and J-Link. The debug symbol names were
renamed to reflect that this support is no longer specific to OpenOCD.
The old symbols were deprecated in Zephyr v2.6.0 and will be removed
after two releases.

See zephyrproject-rtos/zephyr#33283 for further
details.

Signed-off-by: Maureen Helm <[email protected]>
  • Loading branch information
MaureenHelm authored Jan 24, 2022
1 parent 0a4b44c commit 4eb314e
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions pyocd/rtos/zephyr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2016-2020 Arm Limited
# Copyright (c) 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -192,12 +193,8 @@ def update_info(self):
self._state = self._target_context.read8(self._base + self._offsets["t_state"])

if self._provider.version > 0:
addr = self._target_context.read32(self._base + self._offsets["t_name"])
if addr != 0:
self._name = read_c_string(self._target_context, addr)
else:
self._name = "Unnamed"

addr = self._base + self._offsets["t_name"]
self._name = read_c_string(self._target_context, addr)

except exceptions.TransferError:
LOG.debug("Transfer error while reading thread info")
Expand Down Expand Up @@ -246,8 +243,8 @@ class ZephyrThreadProvider(ThreadProvider):
## Required Zephyr symbols.
ZEPHYR_SYMBOLS = [
"_kernel",
"_kernel_openocd_offsets",
"_kernel_openocd_size_t_size",
"_kernel_thread_info_offsets",
"_kernel_thread_info_size_t_size",
]

ZEPHYR_OFFSETS = [
Expand Down Expand Up @@ -286,15 +283,15 @@ def init(self, symbolProvider):

def _get_offsets(self):
# Read the kernel and thread structure member offsets
size = self._target_context.read8(self._symbols["_kernel_openocd_size_t_size"])
LOG.debug("_kernel_openocd_size_t_size = %d", size)
size = self._target_context.read8(self._symbols["_kernel_thread_info_size_t_size"])
LOG.debug("_kernel_thread_info_size_t_size = %d", size)
if size != 4:
LOG.error("Unsupported _kernel_openocd_size_t_size")
LOG.error("Unsupported _kernel_thread_info_size_t_size")
return None

offsets = {}
for index, name in enumerate(self.ZEPHYR_OFFSETS):
offset = self._symbols["_kernel_openocd_offsets"] + index * size
offset = self._symbols["_kernel_thread_info_offsets"] + index * size
offsets[name] = self._target_context.read32(offset)
LOG.debug("%s = 0x%04x", name, offsets[name])

Expand Down

0 comments on commit 4eb314e

Please sign in to comment.