2003-09-09 07:01:01 +00:00
|
|
|
/* Helper routines for libthread_db.
|
2023-01-06 21:08:04 +00:00
|
|
|
Copyright (C) 2003-2023 Free Software Foundation, Inc.
|
2003-09-09 07:01:01 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2003-09-09 07:01:01 +00:00
|
|
|
|
|
|
|
#include "thread_dbP.h"
|
|
|
|
#include <byteswap.h>
|
|
|
|
#include <assert.h>
|
2013-05-01 15:46:34 +00:00
|
|
|
#include <stdint.h>
|
2003-09-09 07:01:01 +00:00
|
|
|
|
|
|
|
td_err_e
|
|
|
|
_td_check_sizeof (td_thragent_t *ta, uint32_t *sizep, int sizep_name)
|
|
|
|
{
|
|
|
|
if (*sizep == 0)
|
|
|
|
{
|
|
|
|
psaddr_t descptr;
|
|
|
|
ps_err_e err = td_lookup (ta->ph, sizep_name, &descptr);
|
|
|
|
if (err == PS_NOSYM)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
if (err == PS_OK)
|
|
|
|
err = ps_pdread (ta->ph, descptr, sizep, sizeof *sizep);
|
|
|
|
if (err != PS_OK)
|
|
|
|
return TD_ERR;
|
|
|
|
if (*sizep & 0xff000000U)
|
|
|
|
*sizep = bswap_32 (*sizep);
|
|
|
|
}
|
|
|
|
return TD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
td_err_e
|
|
|
|
_td_locate_field (td_thragent_t *ta,
|
|
|
|
db_desc_t desc, int descriptor_name,
|
|
|
|
psaddr_t idx, psaddr_t *address)
|
|
|
|
{
|
|
|
|
uint32_t elemsize;
|
|
|
|
|
|
|
|
if (DB_DESC_SIZE (desc) == 0)
|
|
|
|
{
|
|
|
|
/* Read the information about this field from the inferior. */
|
|
|
|
psaddr_t descptr;
|
|
|
|
ps_err_e err = td_lookup (ta->ph, descriptor_name, &descptr);
|
|
|
|
if (err == PS_NOSYM)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
if (err == PS_OK)
|
|
|
|
err = ps_pdread (ta->ph, descptr, desc, DB_SIZEOF_DESC);
|
|
|
|
if (err != PS_OK)
|
|
|
|
return TD_ERR;
|
|
|
|
if (DB_DESC_SIZE (desc) == 0)
|
|
|
|
return TD_DBERR;
|
|
|
|
if (DB_DESC_SIZE (desc) & 0xff000000U)
|
|
|
|
{
|
|
|
|
/* Byte-swap these words, though we leave the size word
|
|
|
|
in native order as the handy way to distinguish. */
|
|
|
|
DB_DESC_OFFSET (desc) = bswap_32 (DB_DESC_OFFSET (desc));
|
|
|
|
DB_DESC_NELEM (desc) = bswap_32 (DB_DESC_NELEM (desc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 04:14:11 +00:00
|
|
|
if (idx != 0 && DB_DESC_NELEM (desc) != 0
|
|
|
|
&& idx - (psaddr_t) 0 > DB_DESC_NELEM (desc))
|
2003-09-09 07:01:01 +00:00
|
|
|
/* This is an internal indicator to callers with nonzero IDX
|
|
|
|
that the IDX value is too big. */
|
|
|
|
return TD_NOAPLIC;
|
|
|
|
|
|
|
|
elemsize = DB_DESC_SIZE (desc);
|
|
|
|
if (elemsize & 0xff000000U)
|
|
|
|
elemsize = bswap_32 (elemsize);
|
|
|
|
|
2004-03-25 03:54:03 +00:00
|
|
|
*address += (int32_t) DB_DESC_OFFSET (desc);
|
|
|
|
*address += (elemsize / 8 * (idx - (psaddr_t) 0));
|
2003-09-09 07:01:01 +00:00
|
|
|
return TD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
td_err_e
|
|
|
|
_td_fetch_value (td_thragent_t *ta,
|
|
|
|
db_desc_t desc, int descriptor_name,
|
|
|
|
psaddr_t idx, psaddr_t address,
|
|
|
|
psaddr_t *result)
|
|
|
|
{
|
|
|
|
ps_err_e err;
|
|
|
|
td_err_e terr = _td_locate_field (ta, desc, descriptor_name, idx, &address);
|
|
|
|
if (terr != TD_OK)
|
|
|
|
return terr;
|
|
|
|
|
|
|
|
if (DB_DESC_SIZE (desc) == 8 || DB_DESC_SIZE (desc) == bswap_32 (8))
|
|
|
|
{
|
|
|
|
uint8_t value;
|
|
|
|
err = ps_pdread (ta->ph, address, &value, sizeof value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == 32)
|
|
|
|
{
|
|
|
|
uint32_t value;
|
|
|
|
err = ps_pdread (ta->ph, address, &value, sizeof value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == 64)
|
|
|
|
{
|
|
|
|
uint64_t value;
|
|
|
|
if (sizeof (psaddr_t) < 8)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
err = ps_pdread (ta->ph, address, &value, sizeof value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == bswap_32 (32))
|
|
|
|
{
|
|
|
|
uint32_t value;
|
|
|
|
err = ps_pdread (ta->ph, address, &value, sizeof value);
|
|
|
|
value = bswap_32 (value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == bswap_32 (64))
|
|
|
|
{
|
|
|
|
uint64_t value;
|
|
|
|
if (sizeof (psaddr_t) < 8)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
err = ps_pdread (ta->ph, address, &value, sizeof value);
|
|
|
|
value = bswap_64 (value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TD_DBERR;
|
|
|
|
|
|
|
|
return err == PS_OK ? TD_OK : TD_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
td_err_e
|
|
|
|
_td_store_value (td_thragent_t *ta,
|
2020-10-08 18:46:03 +00:00
|
|
|
db_desc_t desc, int descriptor_name, psaddr_t idx,
|
2003-09-09 07:01:01 +00:00
|
|
|
psaddr_t address, psaddr_t widened_value)
|
|
|
|
{
|
|
|
|
ps_err_e err;
|
|
|
|
td_err_e terr = _td_locate_field (ta, desc, descriptor_name, idx, &address);
|
|
|
|
if (terr != TD_OK)
|
|
|
|
return terr;
|
|
|
|
|
|
|
|
if (DB_DESC_SIZE (desc) == 8 || DB_DESC_SIZE (desc) == bswap_32 (8))
|
|
|
|
{
|
|
|
|
uint8_t value = widened_value - (psaddr_t) 0;
|
|
|
|
err = ps_pdwrite (ta->ph, address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == 32)
|
|
|
|
{
|
|
|
|
uint32_t value = widened_value - (psaddr_t) 0;
|
|
|
|
err = ps_pdwrite (ta->ph, address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == 64)
|
|
|
|
{
|
|
|
|
uint64_t value = widened_value - (psaddr_t) 0;
|
|
|
|
if (sizeof (psaddr_t) < 8)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
err = ps_pdwrite (ta->ph, address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == bswap_32 (32))
|
|
|
|
{
|
|
|
|
uint32_t value = widened_value - (psaddr_t) 0;
|
|
|
|
value = bswap_32 (value);
|
|
|
|
err = ps_pdwrite (ta->ph, address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == bswap_32 (64))
|
|
|
|
{
|
|
|
|
uint64_t value = widened_value - (psaddr_t) 0;
|
|
|
|
if (sizeof (psaddr_t) < 8)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
value = bswap_64 (value);
|
|
|
|
err = ps_pdwrite (ta->ph, address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TD_DBERR;
|
|
|
|
|
|
|
|
return err == PS_OK ? TD_OK : TD_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
td_err_e
|
|
|
|
_td_fetch_value_local (td_thragent_t *ta,
|
|
|
|
db_desc_t desc, int descriptor_name, psaddr_t idx,
|
|
|
|
void *address,
|
|
|
|
psaddr_t *result)
|
|
|
|
{
|
|
|
|
td_err_e terr = _td_locate_field (ta, desc, descriptor_name, idx, &address);
|
|
|
|
if (terr != TD_OK)
|
|
|
|
return terr;
|
|
|
|
|
|
|
|
if (DB_DESC_SIZE (desc) == 8 || DB_DESC_SIZE (desc) == bswap_32 (8))
|
|
|
|
{
|
|
|
|
uint8_t value;
|
|
|
|
memcpy (&value, address, sizeof value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == 32)
|
|
|
|
{
|
|
|
|
uint32_t value;
|
|
|
|
memcpy (&value, address, sizeof value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == 64)
|
|
|
|
{
|
|
|
|
uint64_t value;
|
|
|
|
if (sizeof (psaddr_t) < 8)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
memcpy (&value, address, sizeof value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == bswap_32 (32))
|
|
|
|
{
|
|
|
|
uint32_t value;
|
|
|
|
memcpy (&value, address, sizeof value);
|
|
|
|
value = bswap_32 (value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == bswap_32 (64))
|
|
|
|
{
|
|
|
|
uint64_t value;
|
|
|
|
if (sizeof (psaddr_t) < 8)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
memcpy (&value, address, sizeof value);
|
|
|
|
value = bswap_64 (value);
|
|
|
|
*result = (psaddr_t) 0 + value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TD_DBERR;
|
|
|
|
|
|
|
|
return TD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
td_err_e
|
|
|
|
_td_store_value_local (td_thragent_t *ta,
|
2020-10-08 18:46:03 +00:00
|
|
|
db_desc_t desc, int descriptor_name, psaddr_t idx,
|
2003-09-09 07:01:01 +00:00
|
|
|
void *address, psaddr_t widened_value)
|
|
|
|
{
|
|
|
|
td_err_e terr = _td_locate_field (ta, desc, descriptor_name, idx, &address);
|
|
|
|
if (terr != TD_OK)
|
|
|
|
return terr;
|
|
|
|
|
|
|
|
if (DB_DESC_SIZE (desc) == 8 || DB_DESC_SIZE (desc) == bswap_32 (8))
|
|
|
|
{
|
|
|
|
uint8_t value = widened_value - (psaddr_t) 0;
|
|
|
|
memcpy (address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == 32)
|
|
|
|
{
|
|
|
|
uint32_t value = widened_value - (psaddr_t) 0;
|
|
|
|
memcpy (address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == 64)
|
|
|
|
{
|
|
|
|
uint64_t value = widened_value - (psaddr_t) 0;
|
|
|
|
if (sizeof (psaddr_t) < 8)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
memcpy (address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == bswap_32 (32))
|
|
|
|
{
|
|
|
|
uint32_t value = widened_value - (psaddr_t) 0;
|
|
|
|
value = bswap_32 (value);
|
|
|
|
memcpy (address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else if (DB_DESC_SIZE (desc) == bswap_32 (64))
|
|
|
|
{
|
|
|
|
uint64_t value = widened_value - (psaddr_t) 0;
|
|
|
|
if (sizeof (psaddr_t) < 8)
|
|
|
|
return TD_NOCAPAB;
|
|
|
|
value = bswap_64 (value);
|
|
|
|
memcpy (address, &value, sizeof value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TD_DBERR;
|
|
|
|
|
|
|
|
return TD_OK;
|
|
|
|
}
|