Back to index

glibc  2.9
td_ta_new.c
Go to the documentation of this file.
00001 /* Attach to target process.
00002    Copyright (C) 1999,2001,2002,2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@redhat.com>, 1999.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <stddef.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <version.h>
00025 
00026 #include "thread_dbP.h"
00027 
00028 
00029 /* Datatype for the list of known thread agents.  Normally there will
00030    be exactly one so we don't spend much though on making it fast.  */
00031 LIST_HEAD (__td_agent_list);
00032 
00033 
00034 td_err_e
00035 td_ta_new (struct ps_prochandle *ps, td_thragent_t **ta)
00036 {
00037   psaddr_t versaddr;
00038   char versbuf[sizeof (VERSION)];
00039 
00040   LOG ("td_ta_new");
00041 
00042   /* Check whether the versions match.  */
00043   if (td_lookup (ps, SYM_nptl_version, &versaddr) != PS_OK)
00044     return TD_NOLIBTHREAD;
00045   if (ps_pdread (ps, versaddr, versbuf, sizeof (versbuf)) != PS_OK)
00046     return TD_ERR;
00047 
00048   if (memcmp (versbuf, VERSION, sizeof VERSION) != 0)
00049     /* Not the right version.  */
00050     return TD_VERSION;
00051 
00052   /* Fill in the appropriate information.  */
00053   *ta = (td_thragent_t *) calloc (1, sizeof (td_thragent_t));
00054   if (*ta == NULL)
00055     return TD_MALLOC;
00056 
00057   /* Store the proc handle which we will pass to the callback functions
00058      back into the debugger.  */
00059   (*ta)->ph = ps;
00060 
00061   /* Now add the new agent descriptor to the list.  */
00062   list_add (&(*ta)->list, &__td_agent_list);
00063 
00064   return TD_OK;
00065 }