Use INTERNAL_SYSCALL.
[glibc.git] / nptl_db / td_ta_new.c
blobde564edfd845cc0279212fb6cd2a2639230ec913
1 /* Attach to target process.
2 Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <stddef.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <version.h>
26 #include "thread_dbP.h"
29 /* Datatype for the list of known thread agents. Normally there will
30 be exactly one so we don't spend much though on making it fast. */
31 LIST_HEAD (__td_agent_list);
34 td_err_e
35 td_ta_new (struct ps_prochandle *ps, td_thragent_t **ta)
37 psaddr_t addr;
38 psaddr_t versaddr;
39 char versbuf[sizeof (VERSION)];
41 LOG ("td_ta_new");
43 /* Get the global event mask. This is one of the variables which
44 are new in the thread library to enable debugging. If it is
45 not available we cannot debug. */
46 if (td_lookup (ps, SYM_PTHREAD_THREADS_EVENTS, &addr) != PS_OK)
47 return TD_NOLIBTHREAD;
49 /* Check whether the versions match. */
50 if (td_lookup (ps, SYM_PTHREAD_VERSION, &versaddr) != PS_OK)
51 return TD_VERSION;
52 if (ps_pdread (ps, versaddr, versbuf, sizeof (versbuf)) != PS_OK)
53 return TD_ERR;
55 if (versbuf[sizeof (versbuf) - 1] != '\0' || strcmp (versbuf, VERSION) != 0)
56 /* Not the right version. */
57 return TD_VERSION;
59 /* Fill in the appropriate information. */
60 *ta = (td_thragent_t *) malloc (sizeof (td_thragent_t));
61 if (*ta == NULL)
62 return TD_MALLOC;
64 /* Store the proc handle which we will pass to the callback functions
65 back into the debugger. */
66 (*ta)->ph = ps;
68 /* Remember the address. */
69 (*ta)->pthread_threads_eventsp = (td_thr_events_t *) addr;
71 /* Get the pointer to the variable pointing to the thread descriptor
72 with the last event. */
73 if (td_lookup (ps, SYM_PTHREAD_LAST_EVENT, &(*ta)->pthread_last_event)
74 != PS_OK)
76 free_return:
77 free (*ta);
78 return TD_ERR;
82 if (td_lookup (ps, SYM_PTHREAD_STACK_USER, &addr) != PS_OK)
83 goto free_return;
84 /* Cast to the right type. */
85 (*ta)->stack_user = (list_t *) addr;
87 if (td_lookup (ps, SYM_PTHREAD_STACK_USED, &addr) != PS_OK)
88 goto free_return;
89 /* Cast to the right type. */
90 (*ta)->stack_used = (list_t *) addr;
93 if (td_lookup (ps, SYM_PTHREAD_KEYS, &addr) != PS_OK)
94 goto free_return;
95 /* Cast to the right type. */
96 (*ta)->keys = (struct pthread_key_struct *) addr;
99 /* Similarly for the maximum number of thread local data keys. */
100 if (td_lookup (ps, SYM_PTHREAD_KEYS_MAX, &addr) != PS_OK
101 || ps_pdread (ps, addr, &(*ta)->pthread_keys_max, sizeof (int)) != PS_OK)
102 goto free_return;
105 /* And for the size of the second level arrays for the keys. */
106 if (td_lookup (ps, SYM_PTHREAD_SIZEOF_DESCR, &addr) != PS_OK
107 || ps_pdread (ps, addr, &(*ta)->sizeof_descr, sizeof (int)) != PS_OK)
108 goto free_return;
111 /* Now add the new agent descriptor to the list. */
112 list_add (&(*ta)->list, &__td_agent_list);
114 return TD_OK;