1 /* Helper routines for libthread_db.
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include "thread_dbP.h"
24 _td_check_sizeof (td_thragent_t
*ta
, uint32_t *sizep
, int sizep_name
)
29 ps_err_e err
= td_lookup (ta
->ph
, sizep_name
, &descptr
);
33 err
= ps_pdread (ta
->ph
, descptr
, sizep
, sizeof *sizep
);
36 if (*sizep
& 0xff000000U
)
37 *sizep
= bswap_32 (*sizep
);
43 _td_locate_field (td_thragent_t
*ta
,
44 db_desc_t desc
, int descriptor_name
,
45 psaddr_t idx
, psaddr_t
*address
)
49 if (DB_DESC_SIZE (desc
) == 0)
51 /* Read the information about this field from the inferior. */
53 ps_err_e err
= td_lookup (ta
->ph
, descriptor_name
, &descptr
);
57 err
= ps_pdread (ta
->ph
, descptr
, desc
, DB_SIZEOF_DESC
);
60 if (DB_DESC_SIZE (desc
) == 0)
62 if (DB_DESC_SIZE (desc
) & 0xff000000U
)
64 /* Byte-swap these words, though we leave the size word
65 in native order as the handy way to distinguish. */
66 DB_DESC_OFFSET (desc
) = bswap_32 (DB_DESC_OFFSET (desc
));
67 DB_DESC_NELEM (desc
) = bswap_32 (DB_DESC_NELEM (desc
));
71 if (idx
!= 0 && idx
- (psaddr_t
) 0 > DB_DESC_NELEM (desc
))
72 /* This is an internal indicator to callers with nonzero IDX
73 that the IDX value is too big. */
76 elemsize
= DB_DESC_SIZE (desc
);
77 if (elemsize
& 0xff000000U
)
78 elemsize
= bswap_32 (elemsize
);
80 *address
+= (int32_t) DB_DESC_OFFSET (desc
);
81 *address
+= (elemsize
/ 8 * (idx
- (psaddr_t
) 0));
86 _td_fetch_value (td_thragent_t
*ta
,
87 db_desc_t desc
, int descriptor_name
,
88 psaddr_t idx
, psaddr_t address
,
92 td_err_e terr
= _td_locate_field (ta
, desc
, descriptor_name
, idx
, &address
);
96 if (DB_DESC_SIZE (desc
) == 8 || DB_DESC_SIZE (desc
) == bswap_32 (8))
99 err
= ps_pdread (ta
->ph
, address
, &value
, sizeof value
);
100 *result
= (psaddr_t
) 0 + value
;
102 else if (DB_DESC_SIZE (desc
) == 32)
105 err
= ps_pdread (ta
->ph
, address
, &value
, sizeof value
);
106 *result
= (psaddr_t
) 0 + value
;
108 else if (DB_DESC_SIZE (desc
) == 64)
111 if (sizeof (psaddr_t
) < 8)
113 err
= ps_pdread (ta
->ph
, address
, &value
, sizeof value
);
114 *result
= (psaddr_t
) 0 + value
;
116 else if (DB_DESC_SIZE (desc
) == bswap_32 (32))
119 err
= ps_pdread (ta
->ph
, address
, &value
, sizeof value
);
120 value
= bswap_32 (value
);
121 *result
= (psaddr_t
) 0 + value
;
123 else if (DB_DESC_SIZE (desc
) == bswap_32 (64))
126 if (sizeof (psaddr_t
) < 8)
128 err
= ps_pdread (ta
->ph
, address
, &value
, sizeof value
);
129 value
= bswap_64 (value
);
130 *result
= (psaddr_t
) 0 + value
;
135 return err
== PS_OK
? TD_OK
: TD_ERR
;
140 _td_store_value (td_thragent_t
*ta
,
141 uint32_t desc
[2], int descriptor_name
, psaddr_t idx
,
142 psaddr_t address
, psaddr_t widened_value
)
145 td_err_e terr
= _td_locate_field (ta
, desc
, descriptor_name
, idx
, &address
);
149 if (DB_DESC_SIZE (desc
) == 8 || DB_DESC_SIZE (desc
) == bswap_32 (8))
151 uint8_t value
= widened_value
- (psaddr_t
) 0;
152 err
= ps_pdwrite (ta
->ph
, address
, &value
, sizeof value
);
154 else if (DB_DESC_SIZE (desc
) == 32)
156 uint32_t value
= widened_value
- (psaddr_t
) 0;
157 err
= ps_pdwrite (ta
->ph
, address
, &value
, sizeof value
);
159 else if (DB_DESC_SIZE (desc
) == 64)
161 uint64_t value
= widened_value
- (psaddr_t
) 0;
162 if (sizeof (psaddr_t
) < 8)
164 err
= ps_pdwrite (ta
->ph
, address
, &value
, sizeof value
);
166 else if (DB_DESC_SIZE (desc
) == bswap_32 (32))
168 uint32_t value
= widened_value
- (psaddr_t
) 0;
169 value
= bswap_32 (value
);
170 err
= ps_pdwrite (ta
->ph
, address
, &value
, sizeof value
);
172 else if (DB_DESC_SIZE (desc
) == bswap_32 (64))
174 uint64_t value
= widened_value
- (psaddr_t
) 0;
175 if (sizeof (psaddr_t
) < 8)
177 value
= bswap_64 (value
);
178 err
= ps_pdwrite (ta
->ph
, address
, &value
, sizeof value
);
183 return err
== PS_OK
? TD_OK
: TD_ERR
;
187 _td_fetch_value_local (td_thragent_t
*ta
,
188 db_desc_t desc
, int descriptor_name
, psaddr_t idx
,
192 td_err_e terr
= _td_locate_field (ta
, desc
, descriptor_name
, idx
, &address
);
196 if (DB_DESC_SIZE (desc
) == 8 || DB_DESC_SIZE (desc
) == bswap_32 (8))
199 memcpy (&value
, address
, sizeof value
);
200 *result
= (psaddr_t
) 0 + value
;
202 else if (DB_DESC_SIZE (desc
) == 32)
205 memcpy (&value
, address
, sizeof value
);
206 *result
= (psaddr_t
) 0 + value
;
208 else if (DB_DESC_SIZE (desc
) == 64)
211 if (sizeof (psaddr_t
) < 8)
213 memcpy (&value
, address
, sizeof value
);
214 *result
= (psaddr_t
) 0 + value
;
216 else if (DB_DESC_SIZE (desc
) == bswap_32 (32))
219 memcpy (&value
, address
, sizeof value
);
220 value
= bswap_32 (value
);
221 *result
= (psaddr_t
) 0 + value
;
223 else if (DB_DESC_SIZE (desc
) == bswap_32 (64))
226 if (sizeof (psaddr_t
) < 8)
228 memcpy (&value
, address
, sizeof value
);
229 value
= bswap_64 (value
);
230 *result
= (psaddr_t
) 0 + value
;
240 _td_store_value_local (td_thragent_t
*ta
,
241 uint32_t desc
[2], int descriptor_name
, psaddr_t idx
,
242 void *address
, psaddr_t widened_value
)
244 td_err_e terr
= _td_locate_field (ta
, desc
, descriptor_name
, idx
, &address
);
248 if (DB_DESC_SIZE (desc
) == 8 || DB_DESC_SIZE (desc
) == bswap_32 (8))
250 uint8_t value
= widened_value
- (psaddr_t
) 0;
251 memcpy (address
, &value
, sizeof value
);
253 else if (DB_DESC_SIZE (desc
) == 32)
255 uint32_t value
= widened_value
- (psaddr_t
) 0;
256 memcpy (address
, &value
, sizeof value
);
258 else if (DB_DESC_SIZE (desc
) == 64)
260 uint64_t value
= widened_value
- (psaddr_t
) 0;
261 if (sizeof (psaddr_t
) < 8)
263 memcpy (address
, &value
, sizeof value
);
265 else if (DB_DESC_SIZE (desc
) == bswap_32 (32))
267 uint32_t value
= widened_value
- (psaddr_t
) 0;
268 value
= bswap_32 (value
);
269 memcpy (address
, &value
, sizeof value
);
271 else if (DB_DESC_SIZE (desc
) == bswap_32 (64))
273 uint64_t value
= widened_value
- (psaddr_t
) 0;
274 if (sizeof (psaddr_t
) < 8)
276 value
= bswap_64 (value
);
277 memcpy (address
, &value
, sizeof value
);