|
From: <sv...@va...> - 2005-06-02 03:39:39
|
Author: njn Date: 2005-06-02 04:39:33 +0100 (Thu, 02 Jun 2005) New Revision: 3838 Added: trunk/coregrind/m_libcbase.c trunk/coregrind/pub_core_libcbase.h trunk/include/pub_tool_libcbase.h Modified: trunk/cachegrind/amd64/cg_arch.c trunk/cachegrind/arm/cg_arch.c trunk/cachegrind/cg_main.c trunk/cachegrind/x86/cg_arch.c trunk/coregrind/Makefile.am trunk/coregrind/amd64/state.c trunk/coregrind/core.h trunk/coregrind/m_aspacemgr/aspacemgr.c trunk/coregrind/m_aspacemgr/read_procselfmaps.c trunk/coregrind/m_debuginfo/dwarf.c trunk/coregrind/m_debuginfo/stabs.c trunk/coregrind/m_debuginfo/symtab.c trunk/coregrind/m_debuginfo/symtypes.c trunk/coregrind/m_demangle/cp-demangle.c trunk/coregrind/m_demangle/cplus-dem.c trunk/coregrind/m_demangle/demangle.c trunk/coregrind/m_demangle/dyn-string.c trunk/coregrind/m_errormgr.c trunk/coregrind/m_main.c trunk/coregrind/m_mallocfree.c trunk/coregrind/m_redir.c trunk/coregrind/m_replacemalloc/replacemalloc_core.c trunk/coregrind/m_scheduler/scheduler.c trunk/coregrind/m_sigframe/sigframe-amd64-linux.c trunk/coregrind/m_sigframe/sigframe-x86-linux.c trunk/coregrind/m_signals.c trunk/coregrind/m_skiplist.c trunk/coregrind/m_stacktrace.c trunk/coregrind/m_syscalls/syscalls.c trunk/coregrind/m_translate.c trunk/coregrind/m_transtab.c trunk/coregrind/vg_mylibc.c trunk/coregrind/x86/state.c trunk/helgrind/hg_main.c trunk/include/Makefile.am trunk/include/tool.h trunk/massif/ms_main.c trunk/memcheck/mac_leakcheck.c trunk/memcheck/mac_malloc_wrappers.c trunk/memcheck/mac_shared.c trunk/memcheck/mc_main.c Log: Started modularising vg_mylibc. Put all the standalone stuff -- ie. not relying on any other modules -- in m_libcbase. Also converted the 'size' parameters to functions like VG_(memcpy) and VG_(strncpy) from Int to SizeT, as they should be. Also removed VG_(atoll16) and VG_(toupper), which weren't being used. Also made VG_(atoll36) less flexible -- it now only does base-36 numbers instead of any base in the range 2..36, since base-36 is the only one we need. As part of that, I fixed a horrible bug in it which caused it to return incorrect answers for any number containing the digits 'A'..'I'! (Eg. for "A; it would return 17 instead of 10!) Had to disable the assertions in VG_(string_match), since this module can= 't see vg_assert, which wasn't ideal but also isn't a disaster. Modified: trunk/cachegrind/amd64/cg_arch.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/cachegrind/amd64/cg_arch.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/cachegrind/amd64/cg_arch.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -30,6 +30,7 @@ =20 #include "tool.h" #include "cg_arch.h" +#include "pub_tool_libcbase.h" =20 // All CPUID info taken from sandpile.org/a32/cpuid.htm */ // Probably only works for Intel and AMD chips, and probably only for so= me of Modified: trunk/cachegrind/arm/cg_arch.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/cachegrind/arm/cg_arch.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/cachegrind/arm/cg_arch.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -30,6 +30,7 @@ =20 #include "tool.h" #include "cg_arch.h" +#include "pub_tool_libcbase.h" =20 void VGA_(configure_caches)(cache_t* I1c, cache_t* D1c, cache_t* L2c, Bool all_caches_clo_defined) Modified: trunk/cachegrind/cg_main.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/cachegrind/cg_main.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/cachegrind/cg_main.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -32,6 +32,7 @@ #include "tool.h" #include "pub_tool_debuginfo.h" #include "pub_tool_hashtable.h" +#include "pub_tool_libcbase.h" #include "pub_tool_mallocfree.h" #include "pub_tool_options.h" #include "pub_tool_profile.h" Modified: trunk/cachegrind/x86/cg_arch.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/cachegrind/x86/cg_arch.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/cachegrind/x86/cg_arch.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -29,6 +29,7 @@ */ =20 #include "tool.h" +#include "pub_tool_libcbase.h" #include "cg_arch.h" =20 // All CPUID info taken from sandpile.org/a32/cpuid.htm */ Modified: trunk/coregrind/Makefile.am =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/Makefile.am 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/Makefile.am 2005-06-02 03:39:33 UTC (rev 3838) @@ -46,6 +46,7 @@ pub_core_errormgr.h \ pub_core_execontext.h \ pub_core_hashtable.h \ + pub_core_libcbase.h \ pub_core_main.h \ pub_core_mallocfree.h \ pub_core_options.h \ @@ -87,6 +88,7 @@ m_errormgr.c \ m_execontext.c \ m_hashtable.c \ + m_libcbase.c \ m_main.c \ m_mallocfree.c \ m_options.c \ Modified: trunk/coregrind/amd64/state.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/amd64/state.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/amd64/state.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -29,6 +29,7 @@ */ =20 #include "core.h" +#include "pub_core_libcbase.h" #include "pub_core_tooliface.h" #include <sys/ptrace.h> =20 Modified: trunk/coregrind/core.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/core.h 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/core.h 2005-06-02 03:39:33 UTC (rev 3838) @@ -49,14 +49,12 @@ /* Max length of a text fragment used to construct error messages. */ #define VG_ERRTXT_LEN 4096 =20 -/* Useful macros */ -/* a - alignment - must be a power of 2 */ +// 'a' -- the alignment -- must be a power of 2 #define ROUNDDN(p, a) ((Addr)(p) & ~((Addr)(a)-1)) #define ROUNDUP(p, a) ROUNDDN((p)+(a)-1, (a)) #define PGROUNDDN(p) ROUNDDN(p, VKI_PAGE_SIZE) #define PGROUNDUP(p) ROUNDUP(p, VKI_PAGE_SIZE) =20 - /* --------------------------------------------------------------------- Environment variables ------------------------------------------------------------------ */ Modified: trunk/coregrind/m_aspacemgr/aspacemgr.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-06-01 17:35:23 UTC (rev = 3837) +++ trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-06-02 03:39:33 UTC (rev = 3838) @@ -32,6 +32,7 @@ =20 #include "core.h" #include "pub_core_aspacemgr.h" +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "pub_core_syscalls.h" #include "pub_core_tooliface.h" Modified: trunk/coregrind/m_aspacemgr/read_procselfmaps.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_aspacemgr/read_procselfmaps.c 2005-06-01 17:35:23 U= TC (rev 3837) +++ trunk/coregrind/m_aspacemgr/read_procselfmaps.c 2005-06-02 03:39:33 U= TC (rev 3838) @@ -32,8 +32,8 @@ =20 #include "core.h" #include "pub_core_aspacemgr.h" +#include "pub_core_libcbase.h" =20 - /* Size of a smallish table used to read /proc/self/map entries. */ #define M_PROCMAP_BUF 50000 =20 Modified: trunk/coregrind/m_debuginfo/dwarf.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_debuginfo/dwarf.c 2005-06-01 17:35:23 UTC (rev 3837= ) +++ trunk/coregrind/m_debuginfo/dwarf.c 2005-06-02 03:39:33 UTC (rev 3838= ) @@ -29,6 +29,7 @@ */ =20 #include "core.h" +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "priv_symtab.h" =20 Modified: trunk/coregrind/m_debuginfo/stabs.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_debuginfo/stabs.c 2005-06-01 17:35:23 UTC (rev 3837= ) +++ trunk/coregrind/m_debuginfo/stabs.c 2005-06-02 03:39:33 UTC (rev 3838= ) @@ -29,6 +29,7 @@ */ =20 #include "core.h" +#include "pub_core_libcbase.h" #include "priv_symtab.h" =20 #include <a.out.h> /* stabs defns */ Modified: trunk/coregrind/m_debuginfo/symtab.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_debuginfo/symtab.c 2005-06-01 17:35:23 UTC (rev 383= 7) +++ trunk/coregrind/m_debuginfo/symtab.c 2005-06-02 03:39:33 UTC (rev 383= 8) @@ -32,6 +32,7 @@ #include "core.h" #include "pub_core_aspacemgr.h" #include "pub_core_demangle.h" +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "pub_core_profile.h" #include "pub_core_redir.h" Modified: trunk/coregrind/m_debuginfo/symtypes.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_debuginfo/symtypes.c 2005-06-01 17:35:23 UTC (rev 3= 837) +++ trunk/coregrind/m_debuginfo/symtypes.c 2005-06-02 03:39:33 UTC (rev 3= 838) @@ -31,6 +31,7 @@ #include "core.h" #include "pub_core_debuginfo.h" #include "pub_core_debuglog.h" /* VG_(debugLog_vprintf) */ +#include "pub_core_libcbase.h" #include "pub_core_tooliface.h" #include "priv_symtypes.h" =20 Modified: trunk/coregrind/m_demangle/cp-demangle.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_demangle/cp-demangle.c 2005-06-01 17:35:23 UTC (rev= 3837) +++ trunk/coregrind/m_demangle/cp-demangle.c 2005-06-02 03:39:33 UTC (rev= 3838) @@ -41,6 +41,7 @@ #endif*/ =20 #include "core.h" +#include "pub_core_libcbase.h" #include "ansidecl.h" #include "dyn-string.h" #include "demangle.h" @@ -1408,7 +1409,7 @@ } =20 if (base =3D=3D 36) { - *value =3D VG_(atoll36) (36, dyn_string_buf (number)); + *value =3D VG_(atoll36) (dyn_string_buf (number)); } else { *value =3D VG_(atoll) (dyn_string_buf (number)); } Modified: trunk/coregrind/m_demangle/cplus-dem.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_demangle/cplus-dem.c 2005-06-01 17:35:23 UTC (rev 3= 837) +++ trunk/coregrind/m_demangle/cplus-dem.c 2005-06-02 03:39:33 UTC (rev 3= 838) @@ -38,6 +38,7 @@ =20 #include "safe-ctype.h" #include "core.h" +#include "pub_core_libcbase.h" =20 /*#include <sys/types.h> #include <string.h> Modified: trunk/coregrind/m_demangle/demangle.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_demangle/demangle.c 2005-06-01 17:35:23 UTC (rev 38= 37) +++ trunk/coregrind/m_demangle/demangle.c 2005-06-02 03:39:33 UTC (rev 38= 38) @@ -30,6 +30,7 @@ =20 #include "core.h" #include "pub_core_demangle.h" +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "pub_core_profile.h" #include "demangle.h" Modified: trunk/coregrind/m_demangle/dyn-string.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_demangle/dyn-string.c 2005-06-01 17:35:23 UTC (rev = 3837) +++ trunk/coregrind/m_demangle/dyn-string.c 2005-06-02 03:39:33 UTC (rev = 3838) @@ -32,6 +32,7 @@ #endif*/ =20 #include "core.h" +#include "pub_core_libcbase.h" #include "ansidecl.h" #include "dyn-string.h" =20 Modified: trunk/coregrind/m_errormgr.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_errormgr.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_errormgr.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -32,6 +32,7 @@ #include "pub_core_debuginfo.h" #include "pub_core_errormgr.h" #include "pub_core_execontext.h" +#include "pub_core_libcbase.h" #include "pub_core_main.h" // for VG_(start_debugger)() #include "pub_core_options.h" #include "pub_core_stacktrace.h" Added: trunk/coregrind/m_libcbase.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_libcbase.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_libcbase.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -0,0 +1,477 @@ + +/*--------------------------------------------------------------------*/ +/*--- Entirely standalone libc stuff. m_libcbase.c ---*/ +/*--------------------------------------------------------------------*/ +=20 +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2000-2005 Julian Seward=20 + js...@ac... + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307, USA. + + The GNU General Public License is contained in the file COPYING. +*/ + +#include "tool.h" // XXX: temporary, for NULL, VG_(), Char, etc +#include "pub_core_libcbase.h" + +/* --------------------------------------------------------------------- + Char functions. + ------------------------------------------------------------------ */ + +Bool VG_(isspace) ( Char c ) +{ + return (c =3D=3D ' ' || c =3D=3D '\n' || c =3D=3D '\t' ||=20 + c =3D=3D '\f' || c =3D=3D '\v' || c =3D=3D '\r'); +} + +Bool VG_(isdigit) ( Char c ) +{ + return (c >=3D '0' && c <=3D '9'); +} + +/* --------------------------------------------------------------------- + Converting strings to numbers + ------------------------------------------------------------------ */ + +Long VG_(atoll) ( Char* str ) +{ + Bool neg =3D False; + Long n =3D 0; + if (*str =3D=3D '-') { str++; neg =3D True; }; + while (*str >=3D '0' && *str <=3D '9') { + n =3D 10*n + (Long)(*str - '0'); + str++; + } + if (neg) n =3D -n; + return n; +} + +Long VG_(atoll36) ( Char* str ) +{ + Bool neg =3D False; + Long n =3D 0; + if (*str =3D=3D '-') { str++; neg =3D True; }; + while (True) { + Char c =3D *str; + if (c >=3D '0' && c <=3D (Char)'9') { + n =3D 36*n + (Long)(c - '0'); + } + else=20 + if (c >=3D 'A' && c <=3D (Char)'Z') { + n =3D 36*n + (Long)((c - 'A') + 10); + } + else=20 + if (c >=3D 'a' && c <=3D (Char)'z') { + n =3D 36*n + (Long)((c - 'a') + 10); + } + else { + break; + } + str++; + } + if (neg) n =3D -n; + return n; +} + +/* --------------------------------------------------------------------- + String functions + ------------------------------------------------------------------ */ + +Int VG_(strlen) ( const Char* str ) +{ + Int i =3D 0; + while (str[i] !=3D 0) i++; + return i; +} + +Char* VG_(strcat) ( Char* dest, const Char* src ) +{ + Char* dest_orig =3D dest; + while (*dest) dest++; + while (*src) *dest++ =3D *src++; + *dest =3D 0; + return dest_orig; +} + +Char* VG_(strncat) ( Char* dest, const Char* src, SizeT n ) +{ + Char* dest_orig =3D dest; + while (*dest) dest++; + while (*src && n > 0) { *dest++ =3D *src++; n--; } + *dest =3D 0; + return dest_orig; +} + +Char* VG_(strpbrk) ( const Char* s, const Char* accept ) +{ + const Char* a; + while (*s) { + a =3D accept; + while (*a) + if (*a++ =3D=3D *s) + return (Char *) s; + s++; + } + return NULL; +} + +Char* VG_(strcpy) ( Char* dest, const Char* src ) +{ + Char* dest_orig =3D dest; + while (*src) *dest++ =3D *src++; + *dest =3D 0; + return dest_orig; +} + +/* Copy bytes, not overrunning the end of dest and always ensuring + zero termination. */ +void VG_(strncpy_safely) ( Char* dest, const Char* src, SizeT ndest ) +{ + Int i =3D 0; + while (True) { + dest[i] =3D 0; + if (src[i] =3D=3D 0) return; + if (i >=3D ndest-1) return; + dest[i] =3D src[i]; + i++; + } +} + +Char* VG_(strncpy) ( Char* dest, const Char* src, SizeT ndest ) +{ + Int i =3D 0; + while (True) { + if (i >=3D ndest) return dest; /* reached limit */ + dest[i] =3D src[i]; + if (src[i++] =3D=3D 0) { + /* reached NUL; pad rest with zeroes as required */ + while (i < ndest) dest[i++] =3D 0; + return dest; + } + } +} + +Int VG_(strcmp) ( const Char* s1, const Char* s2 ) +{ + while (True) { + if (*s1 =3D=3D 0 && *s2 =3D=3D 0) return 0; + if (*s1 =3D=3D 0) return -1; + if (*s2 =3D=3D 0) return 1; + + if (*(UChar*)s1 < *(UChar*)s2) return -1; + if (*(UChar*)s1 > *(UChar*)s2) return 1; + + s1++; s2++; + } +} + +static Bool isterm ( Char c ) +{ + return ( VG_(isspace)(c) || 0 =3D=3D c ); +} + +Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 ) +{ + while (True) { + if (isterm(*s1) && isterm(*s2)) return 0; + if (isterm(*s1)) return -1; + if (isterm(*s2)) return 1; + + if (*(UChar*)s1 < *(UChar*)s2) return -1; + if (*(UChar*)s1 > *(UChar*)s2) return 1; + + s1++; s2++; + } +} + +Int VG_(strncmp) ( const Char* s1, const Char* s2, SizeT nmax ) +{ + Int n =3D 0; + while (True) { + if (n >=3D nmax) return 0; + if (*s1 =3D=3D 0 && *s2 =3D=3D 0) return 0; + if (*s1 =3D=3D 0) return -1; + if (*s2 =3D=3D 0) return 1; + + if (*(UChar*)s1 < *(UChar*)s2) return -1; + if (*(UChar*)s1 > *(UChar*)s2) return 1; + + s1++; s2++; n++; + } +} + +Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, SizeT nmax ) +{ + Int n =3D 0; + while (True) { + if (n >=3D nmax) return 0; + if (isterm(*s1) && isterm(*s2)) return 0; + if (isterm(*s1)) return -1; + if (isterm(*s2)) return 1; + + if (*(UChar*)s1 < *(UChar*)s2) return -1; + if (*(UChar*)s1 > *(UChar*)s2) return 1; + + s1++; s2++; n++; + } +} + +Char* VG_(strstr) ( const Char* haystack, Char* needle ) +{ + Int n;=20 + if (haystack =3D=3D NULL) + return NULL; + n =3D VG_(strlen)(needle); + while (True) { + if (haystack[0] =3D=3D 0)=20 + return NULL; + if (VG_(strncmp)(haystack, needle, n) =3D=3D 0)=20 + return (Char*)haystack; + haystack++; + } +} + +Char* VG_(strchr) ( const Char* s, Char c ) +{ + while (True) { + if (*s =3D=3D c) return (Char*)s; + if (*s =3D=3D 0) return NULL; + s++; + } +} + +Char* VG_(strrchr) ( const Char* s, Char c ) +{ + Int n =3D VG_(strlen)(s); + while (--n > 0) { + if (s[n] =3D=3D c) return (Char*)s + n; + } + return NULL; +} + +/* --------------------------------------------------------------------- + A simple string matching routine, purloined from Hugs98. + '*' matches any sequence of zero or more characters + '?' matches any single character exactly=20 + '\c' matches the character c only (ignoring special chars) + c matches the character c only + ------------------------------------------------------------------ */ + +/* Keep track of recursion depth. */ +static Int recDepth; + +// Nb: vg_assert disabled because we can't use it from this module... +static Bool string_match_wrk ( const Char* pat, const Char* str ) +{ + //vg_assert(recDepth >=3D 0 && recDepth < 500); + recDepth++; + for (;;) { + switch (*pat) { + case '\0':recDepth--; + return (*str=3D=3D'\0'); + case '*': do { + if (string_match_wrk(pat+1,str)) { + recDepth--; + return True; + } + } while (*str++); + recDepth--; + return False; + case '?': if (*str++=3D=3D'\0') { + recDepth--; + return False; + } + pat++; + break; + case '\\':if (*++pat =3D=3D '\0') { + recDepth--; + return False; /* spurious trailing \ in pattern */ + } + /* falls through to ... */ + default : if (*pat++ !=3D *str++) { + recDepth--; + return False; + } + break; + } + } +} + +Bool VG_(string_match) ( const Char* pat, const Char* str ) +{ + Bool b; + recDepth =3D 0; + b =3D string_match_wrk ( pat, str ); + //vg_assert(recDepth =3D=3D 0); + /* + VG_(printf)("%s %s %s\n", + b?"TRUE ":"FALSE", pat, str); + */ + return b; +} + + +/* --------------------------------------------------------------------- + mem* functions + ------------------------------------------------------------------ */ + +void* VG_(memcpy) ( void *dest, const void *src, SizeT sz ) +{ + const Char *s =3D (const Char *)src; + Char *d =3D (Char *)dest; + + while (sz--) + *d++ =3D *s++; + + return dest; +} + +void* VG_(memset) ( void *dest, Int c, SizeT sz ) +{ + Char *d =3D (Char *)dest; + + while (sz--) + *d++ =3D c; + + return dest; +} + +Int VG_(memcmp) ( const void* s1, const void* s2, SizeT n ) +{ + Int res; + UChar a0; + UChar b0; + + while (n !=3D 0) { + a0 =3D ((UChar *) s1)[0]; + b0 =3D ((UChar *) s2)[0]; + s1 +=3D 1; + s2 +=3D 1; + res =3D a0 - b0; + if (res !=3D 0) + return res; + n -=3D 1; + } + return 0; +} + +/* --------------------------------------------------------------------- + Misc useful functions + ------------------------------------------------------------------ */ + +Int VG_(log2) ( Int x )=20 +{ + Int i; + /* Any more than 32 and we overflow anyway... */ + for (i =3D 0; i < 32; i++) { + if (1 << i =3D=3D x) return i; + } + return -1; +} + + +// Generic shell sort. Like stdlib.h's qsort(). +void VG_(ssort)( void* base, SizeT nmemb, SizeT size, + Int (*compar)(void*, void*) ) +{ + Int incs[14] =3D { 1, 4, 13, 40, 121, 364, 1093, 3280, + 9841, 29524, 88573, 265720, + 797161, 2391484 }; + Int lo =3D 0; + Int hi =3D nmemb-1; + Int i, j, h, bigN, hp; + + bigN =3D hi - lo + 1; if (bigN < 2) return; + hp =3D 0; while (hp < 14 && incs[hp] < bigN) hp++; hp--; + + #define SORT \ + for ( ; hp >=3D 0; hp--) { \ + h =3D incs[hp]; \ + for (i =3D lo + h; i <=3D hi; i++) { \ + ASSIGN(v,0, a,i); \ + j =3D i; \ + while (COMPAR(a,(j-h), v,0) > 0) { \ + ASSIGN(a,j, a,(j-h)); \ + j =3D j - h; \ + if (j <=3D (lo + h - 1)) break; \ + } \ + ASSIGN(a,j, v,0); \ + } \ + } + + // Specialised cases + if (sizeof(ULong) =3D=3D size) { + + #define ASSIGN(dst, dsti, src, srci) \ + (dst)[(dsti)] =3D (src)[(srci)]; =20 + =20 + #define COMPAR(dst, dsti, src, srci) \ + compar( (void*)(& (dst)[(dsti)]), (void*)(& (src)[(srci)]) ) + + ULong* a =3D (ULong*)base; + ULong v[1]; + + SORT; + + } else if (sizeof(UInt) =3D=3D size) { + + UInt* a =3D (UInt*)base; + UInt v[1]; + + SORT; + + } else if (sizeof(UShort) =3D=3D size) { + UShort* a =3D (UShort*)base; + UShort v[1]; + + SORT; + + } else if (sizeof(UChar) =3D=3D size) { + UChar* a =3D (UChar*)base; + UChar v[1]; + + SORT; + + #undef ASSIGN + #undef COMPAR + + // General case + } else { + char* a =3D base; + char v[size]; // will be at least 'size' bytes + + #define ASSIGN(dst, dsti, src, srci) \ + VG_(memcpy)( &dst[size*(dsti)], &src[size*(srci)], size ); + + #define COMPAR(dst, dsti, src, srci) \ + compar( &dst[size*(dsti)], &src[size*(srci)] ) + + SORT; + + #undef ASSIGN + #undef COMPAR + } + #undef SORT +} + +/*--------------------------------------------------------------------*/ +/*--- end ---*/ +/*--------------------------------------------------------------------*/ + Modified: trunk/coregrind/m_main.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_main.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_main.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -36,6 +36,7 @@ #include "pub_core_debuglog.h" #include "pub_core_errormgr.h" #include "pub_core_execontext.h" +#include "pub_core_libcbase.h" #include "pub_core_main.h" #include "pub_core_options.h" #include "pub_core_profile.h" Modified: trunk/coregrind/m_mallocfree.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_mallocfree.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_mallocfree.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -32,6 +32,7 @@ =20 #include "core.h" #include "pub_core_aspacemgr.h" +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "pub_core_profile.h" #include "valgrind.h" Modified: trunk/coregrind/m_redir.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_redir.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_redir.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -32,6 +32,7 @@ #include "core.h" =20 #include "pub_core_aspacemgr.h" +#include "pub_core_libcbase.h" #include "pub_core_skiplist.h" #include "pub_core_options.h" #include "pub_core_redir.h" Modified: trunk/coregrind/m_replacemalloc/replacemalloc_core.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_replacemalloc/replacemalloc_core.c 2005-06-01 17:35= :23 UTC (rev 3837) +++ trunk/coregrind/m_replacemalloc/replacemalloc_core.c 2005-06-02 03:39= :33 UTC (rev 3838) @@ -29,6 +29,7 @@ */ =20 #include "core.h" +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "pub_core_replacemalloc.h" =20 Modified: trunk/coregrind/m_scheduler/scheduler.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_scheduler/scheduler.c 2005-06-01 17:35:23 UTC (rev = 3837) +++ trunk/coregrind/m_scheduler/scheduler.c 2005-06-02 03:39:33 UTC (rev = 3838) @@ -63,6 +63,7 @@ #include "pub_core_aspacemgr.h" #include "pub_core_dispatch.h" #include "pub_core_errormgr.h" +#include "pub_core_libcbase.h" #include "pub_core_main.h" #include "pub_core_options.h" #include "pub_core_profile.h" Modified: trunk/coregrind/m_sigframe/sigframe-amd64-linux.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_sigframe/sigframe-amd64-linux.c 2005-06-01 17:35:23= UTC (rev 3837) +++ trunk/coregrind/m_sigframe/sigframe-amd64-linux.c 2005-06-02 03:39:33= UTC (rev 3838) @@ -31,6 +31,7 @@ =20 #include "core.h" #include "pub_core_aspacemgr.h" +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "pub_core_sigframe.h" #include "pub_core_signals.h" Modified: trunk/coregrind/m_sigframe/sigframe-x86-linux.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_sigframe/sigframe-x86-linux.c 2005-06-01 17:35:23 U= TC (rev 3837) +++ trunk/coregrind/m_sigframe/sigframe-x86-linux.c 2005-06-02 03:39:33 U= TC (rev 3838) @@ -31,6 +31,7 @@ =20 #include "core.h" #include "pub_core_aspacemgr.h" /* find_segment */ +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "pub_core_sigframe.h" #include "pub_core_signals.h" Modified: trunk/coregrind/m_signals.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_signals.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_signals.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -83,6 +83,7 @@ =20 #include "pub_core_aspacemgr.h" #include "pub_core_errormgr.h" +#include "pub_core_libcbase.h" #include "pub_core_main.h" #include "pub_core_options.h" #include "pub_core_signals.h" Modified: trunk/coregrind/m_skiplist.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_skiplist.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_skiplist.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -87,6 +87,7 @@ */ =20 #include "core.h" +#include "pub_core_libcbase.h" #include "pub_core_skiplist.h" =20 #include <stdlib.h> Modified: trunk/coregrind/m_stacktrace.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_stacktrace.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_stacktrace.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -30,6 +30,7 @@ =20 #include "core.h" #include "pub_core_aspacemgr.h" +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "pub_core_profile.h" #include "pub_core_stacktrace.h" Modified: trunk/coregrind/m_syscalls/syscalls.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_syscalls/syscalls.c 2005-06-01 17:35:23 UTC (rev 38= 37) +++ trunk/coregrind/m_syscalls/syscalls.c 2005-06-02 03:39:33 UTC (rev 38= 38) @@ -31,6 +31,7 @@ #include "core.h" #include "pub_core_debuglog.h" #include "pub_core_aspacemgr.h" +#include "pub_core_libcbase.h" #include "pub_core_main.h" #include "pub_core_profile.h" #include "pub_core_stacktrace.h" Modified: trunk/coregrind/m_translate.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_translate.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_translate.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -31,6 +31,7 @@ =20 #include "core.h" #include "pub_core_aspacemgr.h" +#include "pub_core_libcbase.h" #include "pub_core_main.h" // for VG_(bbs_done) #include "pub_core_options.h" #include "pub_core_profile.h" Modified: trunk/coregrind/m_transtab.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/m_transtab.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/m_transtab.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -31,6 +31,7 @@ =20 #include "core.h" #include "pub_core_debuginfo.h" +#include "pub_core_libcbase.h" #include "pub_core_options.h" #include "pub_core_tooliface.h" // XXX: this module should not depend on m_translate! Added: trunk/coregrind/pub_core_libcbase.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/pub_core_libcbase.h 2005-06-01 17:35:23 UTC (rev 3837= ) +++ trunk/coregrind/pub_core_libcbase.h 2005-06-02 03:39:33 UTC (rev 3838= ) @@ -0,0 +1,46 @@ + +/*--------------------------------------------------------------------*/ +/*--- Standalone libc stuff. pub_core_libcbase.h ---*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2000-2005 Julian Seward + js...@ac... + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307, USA. + + The GNU General Public License is contained in the file COPYING. +*/ + +#ifndef __PUB_CORE_LIBCBASE_H +#define __PUB_CORE_LIBCBASE_H + +//-------------------------------------------------------------------- +// PURPOSE: This module contains all the libc code that is entirely +// standalone (other than the VG_() macro and some types defined=20 +// elsewhere): string functions, char functions, and a few other things= . +//-------------------------------------------------------------------- + +#include "pub_tool_libcbase.h" + +#endif // __PUB_CORE_LIBCBASE_H + +/*--------------------------------------------------------------------*/ +/*--- end ---*/ +/*--------------------------------------------------------------------*/ Modified: trunk/coregrind/vg_mylibc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/vg_mylibc.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/vg_mylibc.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -33,6 +33,7 @@ #include "core.h" #include "pub_core_aspacemgr.h" #include "pub_core_debuglog.h" /* VG_(debugLog_vprintf) */ +#include "pub_core_libcbase.h" #include "pub_core_main.h" #include "pub_core_options.h" #include "pub_core_stacktrace.h" @@ -508,334 +509,10 @@ return ret; } =20 - /* --------------------------------------------------------------------- - Misc str* functions. + strdup() ------------------------------------------------------------------ */ =20 -Bool VG_(isspace) ( Char c ) -{ - return (c =3D=3D ' ' || c =3D=3D '\n' || c =3D=3D '\t' ||=20 - c =3D=3D '\f' || c =3D=3D '\v' || c =3D=3D '\r'); -} - -Bool VG_(isdigit) ( Char c ) -{ - return (c >=3D '0' && c <=3D '9'); -} - -Int VG_(strlen) ( const Char* str ) -{ - Int i =3D 0; - while (str[i] !=3D 0) i++; - return i; -} - - -Long VG_(atoll) ( Char* str ) -{ - Bool neg =3D False; - Long n =3D 0; - if (*str =3D=3D '-') { str++; neg =3D True; }; - while (*str >=3D '0' && *str <=3D '9') { - n =3D 10*n + (Long)(*str - '0'); - str++; - } - if (neg) n =3D -n; - return n; -} - - -Long VG_(atoll16) ( Char* str ) -{ - Bool neg =3D False; - Long n =3D 0; - if (*str =3D=3D '-') { str++; neg =3D True; }; - while (True) { - if (*str >=3D '0' && *str <=3D '9') { - n =3D 16*n + (Long)(*str - '0'); - } - else=20 - if (*str >=3D 'A' && *str <=3D 'F') { - n =3D 16*n + (Long)((*str - 'A') + 10); - } - else=20 - if (*str >=3D 'a' && *str <=3D 'f') { - n =3D 16*n + (Long)((*str - 'a') + 10); - } - else { - break; - } - str++; - } - if (neg) n =3D -n; - return n; -} - -Long VG_(atoll36) ( UInt base, Char* str ) -{ - Bool neg =3D False; - Long n =3D 0; - vg_assert(base >=3D 2 && base <=3D 36); - if (*str =3D=3D '-') { str++; neg =3D True; }; - while (True) { - if (*str >=3D '0'=20 - && *str <=3D (Char)('9' - (10 - base))) { - n =3D base*n + (Long)(*str - '0'); - } - else=20 - if (base > 10 && *str >=3D 'A'=20 - && *str <=3D (Char)('Z' - (36 - base))) { - n =3D base*n + (Long)((*str - 'A') + 10); - } - else=20 - if (base > 10 && *str >=3D 'a'=20 - && *str <=3D (Char)('z' - (36 - base))) { - n =3D base*n + (Long)((*str - 'a') + 10); - } - else { - break; - } - str++; - } - if (neg) n =3D -n; - return n; -} - - -Char* VG_(strcat) ( Char* dest, const Char* src ) -{ - Char* dest_orig =3D dest; - while (*dest) dest++; - while (*src) *dest++ =3D *src++; - *dest =3D 0; - return dest_orig; -} - - -Char* VG_(strncat) ( Char* dest, const Char* src, Int n ) -{ - Char* dest_orig =3D dest; - while (*dest) dest++; - while (*src && n > 0) { *dest++ =3D *src++; n--; } - *dest =3D 0; - return dest_orig; -} - - -Char* VG_(strpbrk) ( const Char* s, const Char* accept ) -{ - const Char* a; - while (*s) { - a =3D accept; - while (*a) - if (*a++ =3D=3D *s) - return (Char *) s; - s++; - } - return NULL; -} - - -Char* VG_(strcpy) ( Char* dest, const Char* src ) -{ - Char* dest_orig =3D dest; - while (*src) *dest++ =3D *src++; - *dest =3D 0; - return dest_orig; -} - - -/* Copy bytes, not overrunning the end of dest and always ensuring - zero termination. */ -void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest ) -{ - Int i; - vg_assert(ndest > 0); - i =3D 0; - while (True) { - dest[i] =3D 0; - if (src[i] =3D=3D 0) return; - if (i >=3D ndest-1) return; - dest[i] =3D src[i]; - i++; - } -} - - -Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest ) -{ - Int i =3D 0; - while (True) { - if (i >=3D ndest) return dest; /* reached limit */ - dest[i] =3D src[i]; - if (src[i++] =3D=3D 0) { - /* reached NUL; pad rest with zeroes as required */ - while (i < ndest) dest[i++] =3D 0; - return dest; - } - } -} - - -Int VG_(strcmp) ( const Char* s1, const Char* s2 ) -{ - while (True) { - if (*s1 =3D=3D 0 && *s2 =3D=3D 0) return 0; - if (*s1 =3D=3D 0) return -1; - if (*s2 =3D=3D 0) return 1; - - if (*(UChar*)s1 < *(UChar*)s2) return -1; - if (*(UChar*)s1 > *(UChar*)s2) return 1; - - s1++; s2++; - } -} - -static Bool isterm ( Char c ) -{ - return ( VG_(isspace)(c) || 0 =3D=3D c ); -} - - -Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 ) -{ - while (True) { - if (isterm(*s1) && isterm(*s2)) return 0; - if (isterm(*s1)) return -1; - if (isterm(*s2)) return 1; - - if (*(UChar*)s1 < *(UChar*)s2) return -1; - if (*(UChar*)s1 > *(UChar*)s2) return 1; - - s1++; s2++; - } -} - - -Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax ) -{ - Int n =3D 0; - while (True) { - if (n >=3D nmax) return 0; - if (*s1 =3D=3D 0 && *s2 =3D=3D 0) return 0; - if (*s1 =3D=3D 0) return -1; - if (*s2 =3D=3D 0) return 1; - - if (*(UChar*)s1 < *(UChar*)s2) return -1; - if (*(UChar*)s1 > *(UChar*)s2) return 1; - - s1++; s2++; n++; - } -} - - -Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax ) -{ - Int n =3D 0; - while (True) { - if (n >=3D nmax) return 0; - if (isterm(*s1) && isterm(*s2)) return 0; - if (isterm(*s1)) return -1; - if (isterm(*s2)) return 1; - - if (*(UChar*)s1 < *(UChar*)s2) return -1; - if (*(UChar*)s1 > *(UChar*)s2) return 1; - - s1++; s2++; n++; - } -} - - -Char* VG_(strstr) ( const Char* haystack, Char* needle ) -{ - Int n;=20 - if (haystack =3D=3D NULL) - return NULL; - n =3D VG_(strlen)(needle); - while (True) { - if (haystack[0] =3D=3D 0)=20 - return NULL; - if (VG_(strncmp)(haystack, needle, n) =3D=3D 0)=20 - return (Char*)haystack; - haystack++; - } -} - - -Char* VG_(strchr) ( const Char* s, Char c ) -{ - while (True) { - if (*s =3D=3D c) return (Char*)s; - if (*s =3D=3D 0) return NULL; - s++; - } -} - - -Char* VG_(strrchr) ( const Char* s, Char c ) -{ - Int n =3D VG_(strlen)(s); - while (--n > 0) { - if (s[n] =3D=3D c) return (Char*)s + n; - } - return NULL; -} - - -void* VG_(memcpy) ( void *dest, const void *src, Int sz ) -{ - const Char *s =3D (const Char *)src; - Char *d =3D (Char *)dest; - vg_assert(sz >=3D 0); - - while (sz--) - *d++ =3D *s++; - - return dest; -} - - -void* VG_(memset) ( void *dest, Int c, Int sz ) -{ - Char *d =3D (Char *)dest; - vg_assert(sz >=3D 0); - - while (sz--) - *d++ =3D c; - - return dest; -} - -Int VG_(memcmp) ( const void* s1, const void* s2, Int n ) -{ - Int res; - UChar a0; - UChar b0; - vg_assert(n >=3D 0); - - while (n !=3D 0) { - a0 =3D ((UChar *) s1)[0]; - b0 =3D ((UChar *) s2)[0]; - s1 +=3D 1; - s2 +=3D 1; - res =3D a0 - b0; - if (res !=3D 0) - return res; - n -=3D 1; - } - return 0; -} - -Char VG_(toupper) ( Char c ) -{ - if (c >=3D 'a' && c <=3D 'z') - return c + ('A' - 'a');=20 - else - return c; -} - - /* Inline just for the wrapper VG_(strdup) below */ __inline__ Char* VG_(arena_strdup) ( ArenaId aid, const Char* s ) { @@ -861,67 +538,6 @@ } =20 /* --------------------------------------------------------------------- - A simple string matching routine, purloined from Hugs98. - '*' matches any sequence of zero or more characters - '?' matches any single character exactly=20 - '\c' matches the character c only (ignoring special chars) - c matches the character c only - ------------------------------------------------------------------ */ - -/* Keep track of recursion depth. */ -static Int recDepth; - -static Bool string_match_wrk ( const Char* pat, const Char* str ) -{ - vg_assert(recDepth >=3D 0 && recDepth < 500); - recDepth++; - for (;;) { - switch (*pat) { - case '\0' : recDepth--; - return (*str=3D=3D'\0'); - case '*' : do { - if (string_match_wrk(pat+1,str)) { - recDepth--; - return True; - } - } while (*str++); - recDepth--; - return False; - case '?' : if (*str++=3D=3D'\0') { - recDepth--; - return False; - } - pat++; - break; - case '\\' : if (*++pat =3D=3D '\0') { - recDepth--; - return False; /* spurious trailing \ in pattern = */ - } - /* falls through to ... */ - default : if (*pat++ !=3D *str++) { - recDepth--; - return False; - } - break; - } - } -} - -Bool VG_(string_match) ( const Char* pat, const Char* str ) -{ - Bool b; - recDepth =3D 0; - b =3D string_match_wrk ( pat, str ); - vg_assert(recDepth =3D=3D 0); - /* - VG_(printf)("%s %s %s\n", - b?"TRUE ":"FALSE", pat, str); - */ - return b; -} - - -/* --------------------------------------------------------------------- Assertery. ------------------------------------------------------------------ */ =20 @@ -1586,106 +1202,6 @@ } =20 /* --------------------------------------------------------------------- - Generally useful... - ------------------------------------------------------------------ */ - -Int VG_(log2) ( Int x )=20 -{ - Int i; - /* Any more than 32 and we overflow anyway... */ - for (i =3D 0; i < 32; i++) { - if (1 << i =3D=3D x) return i; - } - return -1; -} - - -// Generic shell sort. Like stdlib.h's qsort(). -void VG_(ssort)( void* base, SizeT nmemb, SizeT size, - Int (*compar)(void*, void*) ) -{ - Int incs[14] =3D { 1, 4, 13, 40, 121, 364, 1093, 3280, - 9841, 29524, 88573, 265720, - 797161, 2391484 }; - Int lo =3D 0; - Int hi =3D nmemb-1; - Int i, j, h, bigN, hp; - - bigN =3D hi - lo + 1; if (bigN < 2) return; - hp =3D 0; while (hp < 14 && incs[hp] < bigN) hp++; hp--; - vg_assert(0 <=3D hp && hp < 14); - - #define SORT \ - for ( ; hp >=3D 0; hp--) { \ - h =3D incs[hp]; \ - for (i =3D lo + h; i <=3D hi; i++) { \ - ASSIGN(v,0, a,i); \ - j =3D i; \ - while (COMPAR(a,(j-h), v,0) > 0) { \ - ASSIGN(a,j, a,(j-h)); \ - j =3D j - h; \ - if (j <=3D (lo + h - 1)) break; \ - } \ - ASSIGN(a,j, v,0); \ - } \ - } - - // Specialised cases - if (sizeof(ULong) =3D=3D size) { - - #define ASSIGN(dst, dsti, src, srci) \ - (dst)[(dsti)] =3D (src)[(srci)]; =20 - =20 - #define COMPAR(dst, dsti, src, srci) \ - compar( (void*)(& (dst)[(dsti)]), (void*)(& (src)[(srci)]) ) - - ULong* a =3D (ULong*)base; - ULong v[1]; - - SORT; - - } else if (sizeof(UInt) =3D=3D size) { - - UInt* a =3D (UInt*)base; - UInt v[1]; - - SORT; - - } else if (sizeof(UShort) =3D=3D size) { - UShort* a =3D (UShort*)base; - UShort v[1]; - - SORT; - - } else if (sizeof(UChar) =3D=3D size) { - UChar* a =3D (UChar*)base; - UChar v[1]; - - SORT; - - #undef ASSIGN - #undef COMPAR - - // General case - } else { - char* a =3D base; - char v[size]; // will be at least 'size' bytes - - #define ASSIGN(dst, dsti, src, srci) \ - VG_(memcpy)( &dst[size*(dsti)], &src[size*(srci)], size ); - - #define COMPAR(dst, dsti, src, srci) \ - compar( &dst[size*(dsti)], &src[size*(srci)] ) - - SORT; - - #undef ASSIGN - #undef COMPAR - } - #undef SORT -} - -/* --------------------------------------------------------------------- Gruesome hackery for connecting to a logging server over the network. This is all very Linux-kernel specific. ------------------------------------------------------------------ */ Modified: trunk/coregrind/x86/state.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/coregrind/x86/state.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/coregrind/x86/state.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -29,6 +29,7 @@ */ =20 #include "core.h" +#include "pub_core_libcbase.h" #include "pub_core_tooliface.h" #include "vki_unistd.h" #include <sys/ptrace.h> Modified: trunk/helgrind/hg_main.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/helgrind/hg_main.c 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/helgrind/hg_main.c 2005-06-02 03:39:33 UTC (rev 3838) @@ -32,6 +32,7 @@ #include "tool.h" #include "pub_tool_debuginfo.h" #include "pub_tool_hashtable.h" +#include "pub_tool_libcbase.h" #include "pub_tool_mallocfree.h" #include "pub_tool_options.h" #include "pub_tool_profile.h" Modified: trunk/include/Makefile.am =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/include/Makefile.am 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/include/Makefile.am 2005-06-02 03:39:33 UTC (rev 3838) @@ -8,6 +8,7 @@ pub_tool_errormgr.h \ pub_tool_execontext.h \ pub_tool_hashtable.h \ + pub_tool_libcbase.h \ pub_tool_mallocfree.h \ pub_tool_options.h \ pub_tool_profile.h \ Added: trunk/include/pub_tool_libcbase.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/include/pub_tool_libcbase.h 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/include/pub_tool_libcbase.h 2005-06-02 03:39:33 UTC (rev 3838) @@ -0,0 +1,115 @@ + +/*--------------------------------------------------------------------*/ +/*--- Standalone libc stuff. pub_tool_libcbase.h ---*/ +/*--------------------------------------------------------------------*/ + +/* + This file is part of Valgrind, a dynamic binary instrumentation + framework. + + Copyright (C) 2000-2005 Julian Seward + js...@ac... + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307, USA. + + The GNU General Public License is contained in the file COPYING. +*/ + +#ifndef __PUB_TOOL_LIBCBASE_H +#define __PUB_TOOL_LIBCBASE_H + +/* --------------------------------------------------------------------- + Char functions. + ------------------------------------------------------------------ */ + +extern Bool VG_(isspace) ( Char c ); +extern Bool VG_(isdigit) ( Char c ); + +/* --------------------------------------------------------------------- + Converting strings to numbers + ------------------------------------------------------------------ */ + +extern Long VG_(atoll) ( Char* str ); // base 10 +extern Long VG_(atoll36) ( Char* str ); // base 36 + +/* --------------------------------------------------------------------- + String functions and macros + ------------------------------------------------------------------ */ + +/* Use this for normal null-termination-style string comparison */ +#define VG_STREQ(s1,s2) (s1 !=3D NULL && s2 !=3D NULL \ + && VG_(strcmp)((s1),(s2))=3D=3D0) + +extern Int VG_(strlen) ( const Char* str ); +extern Char* VG_(strcat) ( Char* dest, const Char* src ); +extern Char* VG_(strncat) ( Char* dest, const Char* src, SizeT n = ); +extern Char* VG_(strpbrk) ( const Char* s, const Char* accpt ); +extern Char* VG_(strcpy) ( Char* dest, const Char* src ); +extern Char* VG_(strncpy) ( Char* dest, const Char* src, SizeT nd= est ); +extern Int VG_(strcmp) ( const Char* s1, const Char* s2 ); +extern Int VG_(strncmp) ( const Char* s1, const Char* s2, SizeT= nmax ); +extern Char* VG_(strstr) ( const Char* haystack, Char* needle ); +extern Char* VG_(strchr) ( const Char* s, Char c ); +extern Char* VG_(strrchr) ( const Char* s, Char c ); +extern Char* VG_(strdup) ( const Char* s); + +/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */ +extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 ); +extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, SizeT= nmax ); + +/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as= the + last character. */ +extern void VG_(strncpy_safely) ( Char* dest, const Char* src, SizeT nd= est ); + +/* Mini-regexp function. Searches for 'pat' in 'str'. Supports + * meta-symbols '*' and '?'. '\' escapes meta-symbols. */ +extern Bool VG_(string_match) ( const Char* pat, const Char* str ); + +/* --------------------------------------------------------------------- + mem* functions + ------------------------------------------------------------------ */ + +extern void* VG_(memcpy) ( void *d, const void *s, SizeT sz ); +extern void* VG_(memset) ( void *s, Int c, SizeT sz ); +extern Int VG_(memcmp) ( const void* s1, const void* s2, SizeT n ); + +/* --------------------------------------------------------------------- + Address computation helpers + ------------------------------------------------------------------ */ + +// Check if an address/whatever is aligned +#define VG_IS_4_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)0x= 3))) +#define VG_IS_8_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)0x= 7))) +#define VG_IS_16_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)0x= f))) +#define VG_IS_WORD_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)(s= izeof(Addr)-1)))) +#define VG_IS_PAGE_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)(V= KI_PAGE_SIZE-1)))) + +/* --------------------------------------------------------------------- + Misc useful functions + ------------------------------------------------------------------ */ + +/* Like qsort(), but does shell-sort. The size=3D=3D1/2/4 cases are spe= cialised. */ +extern void VG_(ssort)( void* base, SizeT nmemb, SizeT size, + Int (*compar)(void*, void*) ); + +/* Returns the base-2 logarithm of x. */ +extern Int VG_(log2) ( Int x ); + +#endif // __PUB_TOOL_LIBCBASE_H + +/*--------------------------------------------------------------------*/ +/*--- end ---*/ +/*--------------------------------------------------------------------*/ Modified: trunk/include/tool.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/include/tool.h 2005-06-01 17:35:23 UTC (rev 3837) +++ trunk/include/tool.h 2005-06-02 03:39:33 UTC (rev 3838) @@ -63,11 +63,6 @@ /* Path to all our library/aux files */ extern const Char *VG_(libdir); =20 - -/* Use this for normal null-termination-style string comparison */ -#define VG_STREQ(s1,s2) (s1 !=3D NULL && s2 !=3D NULL \ - && VG_(strcmp)((s1),(s2))=3D=3D0) - /* Client args */ extern Int VG_(client_argc); extern Char** VG_(client_argv); @@ -101,17 +96,6 @@ /*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/ =20 /* ------------------------------------------------------------------ */ -/* General stuff */ - -/* Check if an address/whatever is aligned */ -#define VG_IS_4_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)0x= 3))) -#define VG_IS_8_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)0x= 7))) -#define VG_IS_16_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)0x= f))) -#define VG_IS_WORD_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)(s= izeof(Addr)-1)))) -#define VG_IS_PAGE_ALIGNED(aaa_p) (0 =3D=3D (((Addr)(aaa_p)) & ((Addr)(V= KI_PAGE_SIZE-1)))) - - -/* ------------------------------------------------------------------ */ /* Thread-related stuff */ =20 /* Special magic value for an invalid ThreadId. It corresponds to @@ -137,17 +121,10 @@ /*=3D=3D=3D Valgrind's version of libc = =3D=3D=3D*/ /*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/ =20 -/* Valgrind doesn't use libc at all, for good reasons (trust us). So he= re - are its own versions of C library functions, but with VG_ prefixes. = Note - that the types of some are slightly different to the real ones. Some - additional useful functions are provided too; descriptions of how the= y - work are given below. */ - #if !defined(NULL) # define NULL ((void*)0) #endif =20 - /* ------------------------------------------------------------------ */ /* stdio.h * @@ -187,64 +164,7 @@ /* Crude stand-in for the glibc system() call. */ extern Int VG_(system) ( Char* cmd ); =20 -extern Long VG_(atoll) ( Char* str ); - -/* Like atoll(), but converts a number of base 16 */ -extern Long VG_(atoll16) ( Char* str ); - -/* Like atoll(), but converts a number of base 2..36 */ -extern Long VG_(atoll36) ( UInt base, Char* str ); - -/* Like qsort(), but does shell-sort. The size=3D=3D1/2/4 cases are spe= cialised. */ -extern void VG_(ssort)( void* base, SizeT nmemb, SizeT size, - Int (*compar)(void*, void*) ); - - /* ------------------------------------------------------------------ */ -/* ctype.h */ -extern Bool VG_(isspace) ( Char c ); -extern Bool VG_(isdigit) ( Char c ); -extern Char VG_(toupper) ( Char c ); - - -/* ------------------------------------------------------------------ */ -/* string.h */ -extern Int VG_(strlen) ( const Char* str ); -extern Char* VG_(strcat) ( Char* dest, const Char* src ); -extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n ); -extern Char* VG_(strpbrk) ( const Char* s, const Char* accpt ); -extern Char* VG_(strcpy) ( Char* dest, const Char* src ); -extern Char* VG_(strncpy) ( Char* dest, const Char* src... [truncated message content] |