00001 /* 00002 * See the dyninst/COPYRIGHT file for copyright information. 00003 * 00004 * We provide the Paradyn Tools (below described as "Paradyn") 00005 * on an AS IS basis, and do not warrant its validity or performance. 00006 * We reserve the right to update, modify, or discontinue this 00007 * software at any time. We shall have no obligation to supply such 00008 * updates or modifications or any other form of support to you. 00009 * 00010 * By your use of Paradyn, you understand and agree that we (or any 00011 * other person or entity with proprietary rights in Paradyn) are 00012 * under no obligation to provide either maintenance services, 00013 * update services, notices of latent defects, or correction of 00014 * defects for Paradyn. 00015 * 00016 * This library is free software; you can redistribute it and/or 00017 * modify it under the terms of the GNU Lesser General Public 00018 * License as published by the Free Software Foundation; either 00019 * version 2.1 of the License, or (at your option) any later version. 00020 * 00021 * This library is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00024 * Lesser General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU Lesser General Public 00027 * License along with this library; if not, write to the Free Software 00028 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00029 */ 00030 00031 /************************************************************************ 00032 * $Id: Types.C,v 1.7 2007/05/30 19:20:17 legendre Exp $ 00033 * Types.C: commonly used type-handling functions. 00034 ************************************************************************/ 00035 00036 #include "common/h/Types.h" 00037 #include <stdio.h> 00038 #include <assert.h> 00039 00040 // verify the size of the defined Address type 00041 void Address_chk () 00042 { 00043 assert (sizeof(Address) == sizeof(void*)); 00044 } 00045 00046 static const unsigned int _numaddrstrs=8; 00047 // maximum number of addresses per outstanding printf! 00048 static char _addrstr[_numaddrstrs][19]; // "0x"+16+'\0' 00049 00050 // Format an address string according to the size of the Address type. 00051 // Note that "%x" outputs incorrect/incomplete addresses, and that "%lx" 00052 // or system-dependent "%p" (generally also requiring a typecast to (void*)) 00053 // must be used instead! 00054 char *Address_str (Address addr) 00055 { 00056 static int i=0; 00057 i=(i+1)%_numaddrstrs; 00058 if (sizeof(Address) == sizeof(int)) 00059 snprintf(_addrstr[i],19,"0x%08X",(unsigned int)addr); 00060 else 00061 snprintf(_addrstr[i],19,"0x%016lX",(unsigned long)addr); 00062 return (_addrstr[i]); 00063 } 00064 00065 00066 int ThrIDToTid(Dyninst::THR_ID id) 00067 { 00068 #if defined(os_windows) 00069 // This is vista-only; for the time being, we'll return the handle as a dword 00070 // return GetThreadId(id); 00071 return (unsigned long) id; 00072 #else 00073 return (int) id; 00074 #endif 00075 }
1.6.1