Back to index

glibc  2.9
backtracesymsfd.c
Go to the documentation of this file.
00001 /* Write formatted list with names for addresses in backtrace to a file.
00002    Copyright (C) 1998, 2003, 2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
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 <execinfo.h>
00022 #include <string.h>
00023 #include <sys/uio.h>
00024 
00025 #include <stdio-common/_itoa.h>
00026 #include <not-cancel.h>
00027 
00028 #if __ELF_NATIVE_CLASS == 32
00029 # define WORD_WIDTH 8
00030 #else
00031 /* We assume 64bits.  */
00032 # define WORD_WIDTH 16
00033 #endif
00034 
00035 
00036 void
00037 __backtrace_symbols_fd (array, size, fd)
00038      void *const *array;
00039      int size;
00040      int fd;
00041 {
00042   struct iovec iov[3];
00043   int cnt;
00044 
00045   for (cnt = 0; cnt < size; ++cnt)
00046     {
00047       char buf[WORD_WIDTH];
00048 
00049       iov[0].iov_base = (void *) "[0x";
00050       iov[0].iov_len = 3;
00051 
00052       iov[1].iov_base = _itoa_word ((unsigned long int) array[cnt],
00053                                 &buf[WORD_WIDTH], 16, 0);
00054       iov[1].iov_len = &buf[WORD_WIDTH] - (char *) iov[1].iov_base;
00055 
00056       iov[2].iov_base = (void *) "]\n";
00057       iov[2].iov_len = 2;
00058 
00059       /* We prefer to use the non-cancelable interface if it is available.  */
00060       writev_not_cancel_no_status (fd, iov, 3);
00061     }
00062 }
00063 weak_alias (__backtrace_symbols_fd, backtrace_symbols_fd)
00064 libc_hidden_def (__backtrace_symbols_fd)