Thread: [libcw-cvs] [CVS] Module src (Page 4)
Abandoned project
Status: Beta
Brought to you by:
libcw
From: Carlo W. <li...@us...> - 2002-01-09 04:20:27
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-09 04:20:26 UTC Modified files: libcwd/.cvsignore libcwd/NEWS libcwd/README libcwd/README.FreeBSD Log message: README updates. ---------------------- diff included ---------------------- Index: src/libcwd/.cvsignore diff -u src/libcwd/.cvsignore:1.16 src/libcwd/.cvsignore:1.17 --- src/libcwd/.cvsignore:1.16 Thu Dec 27 21:25:27 2001 +++ src/libcwd/.cvsignore Tue Jan 8 20:20:16 2002 @@ -24,6 +24,7 @@ .deps .libs *.lo +.example-project_debug.h-timestamp libcwd.la libcwd.spec libcwd.lsm Index: src/libcwd/NEWS diff -u src/libcwd/NEWS:1.63 src/libcwd/NEWS:1.64 --- src/libcwd/NEWS:1.63 Mon Jan 7 18:36:15 2002 +++ src/libcwd/NEWS Tue Jan 8 20:20:16 2002 @@ -1,6 +1,7 @@ libcwd-0.99.16 - libcwd is now thread-safe. + * libcwd is now thread-safe * + You have to configure using --enable-libcwd-threading. The source file line number lookup was improved for optimized code with inlined functions (-O). @@ -13,6 +14,7 @@ - The configuration option --disable-libcwd-location is fixed. - Automake-1.5 now works. - Autoconf-2.5x now works. + - FreeBSD works (again). API changes: Index: src/libcwd/README diff -u src/libcwd/README:1.9 src/libcwd/README:1.10 --- src/libcwd/README:1.9 Sat Dec 29 20:17:46 2001 +++ src/libcwd/README Tue Jan 8 20:20:16 2002 @@ -49,5 +49,8 @@ cvs -z3 -d:pserver:ano...@cv...:/cvsroot/libcw co libcwd -Updates from within the module's directory do not need the -d parameter. +You don't need the -d parameter inside the module's directory. (Note that you +do need -d after 'update' to savely update new directories that might have been +added. Example: "cd libcw; cvs update -dP". Or add 'update -dP' to your +~/.cvsrc file.) Index: src/libcwd/README.FreeBSD diff -u src/libcwd/README.FreeBSD:1.8 src/libcwd/README.FreeBSD:1.9 --- src/libcwd/README.FreeBSD:1.8 Sun Dec 30 12:05:41 2001 +++ src/libcwd/README.FreeBSD Tue Jan 8 20:20:16 2002 @@ -1,3 +1,9 @@ +9 Januari 2002 + + FreeBSD (4.5-PRERELEASE) now works. Libcwd uses the external command + 'ldd' to get a list of linked libraries. Please be aware that you + have to use `gmake' - FreeBSD's own `make' fails without clear indications. + 30 December 2001 FreeBSD now compiles with g++-2.95.3. ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-09 16:16:18
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-09 16:16:14 UTC Modified files: libcwd/demangle.cc libcwd/demangle3.cc libcwd/testsuite/libcwd.tst/demangler.cc libcwd/testsuite/libcwd.tst/demangler.re Log message: Bug fix in demangle.cc. Added a demangler test for the case that triggered the bug. Note that this same variable makes gdb-5 core dump (see: http://sources.redhat.com/ml/bug-binutils/2002-q1/msg00021.html) ---------------------- diff included ---------------------- Index: src/libcwd/demangle.cc diff -u src/libcwd/demangle.cc:1.23 src/libcwd/demangle.cc:1.24 --- src/libcwd/demangle.cc:1.23 Sat Dec 29 20:17:46 2001 +++ src/libcwd/demangle.cc Wed Jan 9 08:16:04 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/demangle.cc,v 1.23 2001/12/30 04:17:46 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/demangle.cc,v 1.24 2002/01/09 16:16:04 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -24,6 +24,9 @@ // // Currently this file has been tested with gcc-2.95.2 and gcc-2.96 (RedHat). // +// For a standalone demangler, compile this file as: +// g++ -pthread -DSTANDALONE -DCWDEBUG -Iinclude demangle.cc -Wl,-rpath,`pwd`/.libs -L.libs -lcwd -o c++filt +// #undef CPPFILTCOMPATIBLE @@ -798,12 +801,12 @@ // `input' is of the form // - // [m]<digit> + // [m]<digit>[<digit>...] // _[m]<digit>[<digit>...]_ // - bool just_one_digit = (*input != '_'); - if (!just_one_digit) + bool underscore = (*input == '_'); + if (underscore) ++input; bool is_negative = (*input == 'm' && numeric_limits<INTEGRAL_TYPE>::is_signed); if (is_negative) @@ -830,7 +833,7 @@ x = x * 10 - (*input - '0'); output += *input; } - while (isdigit(*++input) && !just_one_digit); + while (isdigit(*++input)); else do { @@ -839,7 +842,10 @@ x = x * 10 + (*input - '0'); output += *input; } - while (isdigit(*++input) && !just_one_digit); + while (isdigit(*++input)); + + if (underscore && *input == '_') + ++input; #ifndef CPPFILTCOMPATIBLE if (!numeric_limits<INTEGRAL_TYPE>::is_signed) Index: src/libcwd/demangle3.cc diff -u src/libcwd/demangle3.cc:1.12 src/libcwd/demangle3.cc:1.13 --- src/libcwd/demangle3.cc:1.12 Sat Dec 29 20:17:46 2001 +++ src/libcwd/demangle3.cc Wed Jan 9 08:16:04 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/demangle3.cc,v 1.12 2001/12/30 04:17:46 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/demangle3.cc,v 1.13 2002/01/09 16:16:04 libcw Exp $ // // Copyright (C) 2001, by // @@ -36,6 +36,9 @@ // // The description of how the mangling is done in the new ABI was found on // http://www.codesourcery.com/cxx-abi/abi.html#mangling +// +// To compile a standalone demangler: +// g++ -pthread -DSTANDALONE -DCWDEBUG -Iinclude demangle3.cc -Wl,-rpath,`pwd`/.libs -L.libs -lcwd -o c++filt // #undef CPPFILTCOMPATIBLE Index: src/libcwd/testsuite/libcwd.tst/demangler.cc diff -u src/libcwd/testsuite/libcwd.tst/demangler.cc:1.7 src/libcwd/testsuite/libcwd.tst/demangler.cc:1.8 --- src/libcwd/testsuite/libcwd.tst/demangler.cc:1.7 Sat Dec 29 20:17:51 2001 +++ src/libcwd/testsuite/libcwd.tst/demangler.cc Wed Jan 9 08:16:04 2002 @@ -18,7 +18,8 @@ "foo__FiPiPPiPPPiPPPPiPPPPPiPPPPPPiPPPPPPPiPPPPPPPPiPPPPPPPPPiPPPPPPPPPPiPPPPPPPPPPPiPPPPPPPPPPPPiPPPPPPPPPPPPPiPPPPPPPPPPPPPPiPPPPPPPPPPPPPPPi", "B__H3Zt1D3ZP1AZRCP1AZPCP1AZt1D3ZP1AZRP1AZPP1AZP1A_X01X01X11PX21_t1D3ZX21ZRX21ZPX21", "SKIPPED", - "_X11TransParseAddress" + "_X11TransParseAddress", + "_t13_Alloc_traits2Zt12basic_string3ZcZt18string_char_traits1ZcZQ45libcw5debug9_private_t17allocator_adaptor3ZcZt24__default_alloc_template2b0i327664b1ZQ45libcw5debug9_private_t17allocator_adaptor3Zt12basic_string3ZcZt18string_char_traits1ZcZQ45libcw5debug9_private_t17allocator_adaptor3ZcZt24__default_alloc_template2b0i327664b1Zt24__default_alloc_template2b0i327664b1._S_instanceless" }; #else char const* test_cases [] = { @@ -33,7 +34,8 @@ "_Z3fooiPiPS_PS0_PS1_PS2_PS3_PS4_PS5_PS6_PS7_PS8_PS9_PSA_PSB_PSC_", "_ZSt1BISt1DIP1ARKS2_PS3_ES0_IS2_RS2_PS2_ES2_ET0_T_SB_SA_PT1_", "_ZngILi42EEvN1AIXplT_Li2EEE1TE", - "_X11TransParseAddress" + "_X11TransParseAddress", + "_ZNSt13_Alloc_traitsISbIcSt18string_char_traitsIcEN5libcw5debug9_private_17allocator_adaptorIcSt24__default_alloc_templateILb0ELi327664EELb1EEEENS5_IS9_S7_Lb1EEEE15_S_instancelessE" }; #endif @@ -303,5 +305,57 @@ } #endif + +namespace std { + template<bool b, int i> + class __default_alloc_template { }; + + template<typename CHAR> + class string_char_traits { }; + + template<class BASIC_STRING, class ADAPTOR> + struct _Alloc_traits { + static char _S_instanceless; + }; + template<class BASIC_STRING, class ADAPTOR> + char _Alloc_traits<BASIC_STRING, ADAPTOR>::_S_instanceless; +} +namespace libcw { + namespace debug { + namespace _private_ { + template<typename CHAR, class ALLOCATOR, bool b> + class allocator_adaptor { }; + } + } +} + +void q(void) +{ + std::_Alloc_traits< + std::basic_string< + char, + std::string_char_traits<char>, + libcw::debug::_private_::allocator_adaptor< + char, + std::__default_alloc_template<false, 327664>, + true + > + >, + libcw::debug::_private_::allocator_adaptor< + std::basic_string< + char, + std::string_char_traits<char>, + libcw::debug::_private_::allocator_adaptor< + char, + std::__default_alloc_template<false, 327664>, + true + > + >, + std::__default_alloc_template<false, 327664>, + true + > + > dummy1; + char x = dummy1._S_instanceless; +} #endif // INSTANTIATE Index: src/libcwd/testsuite/libcwd.tst/demangler.re diff -u src/libcwd/testsuite/libcwd.tst/demangler.re:1.8 src/libcwd/testsuite/libcwd.tst/demangler.re:1.9 --- src/libcwd/testsuite/libcwd.tst/demangler.re:1.8 Tue Jan 8 18:20:52 2002 +++ src/libcwd/testsuite/libcwd.tst/demangler.re Wed Jan 9 08:16:04 2002 @@ -16,3 +16,4 @@ (std::)*D<A\*, A\*&, A\*\*> (std::)*B<(std::)*D<A\*, A\* const&, A\* const\*>, (std::)*D<A\*, A\*&, A\*\*>, A\*>\((std::)*D<A\*, A\* const&, A\* const\*>, (std::)*D<A\*, A\* const&, A\* const\*>, (std::)*D<A\*, A\*&, A\*\*>, A\*\*\) (void operator-<42>\(A<\(42\) \+ \(2\)>::T\)|SKIPPED) _X11TransParseAddress +(std::)*_Alloc_traits<(std::)*basic_string<char, (std::)*string_char_traits<char>, libcw::debug::_private_::allocator_adaptor<char, (std::)*__default_alloc_template<false, 327664>, true> >, libcw::debug::_private_::allocator_adaptor<(std::)*basic_string<char, (std::)*string_char_traits<char>, libcw::debug::_private_::allocator_adaptor<char, (std::)*__default_alloc_template<false, 327664>, true> >, (std::)*__default_alloc_template<false, 327664>, true> >::_S_instanceless ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-10 01:28:58
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-10 01:28:56 UTC Modified files: libcwd/include/libcw/private_allocator.h libcwd/include/libcw/private_threading.h Log message: Work around for bug in gdb-5.x. ---------------------- diff included ---------------------- Index: src/libcwd/include/libcw/private_allocator.h diff -u src/libcwd/include/libcw/private_allocator.h:1.3 src/libcwd/include/libcw/private_allocator.h:1.4 --- src/libcwd/include/libcw/private_allocator.h:1.3 Tue Jan 8 15:04:59 2002 +++ src/libcwd/include/libcw/private_allocator.h Wed Jan 9 17:28:46 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_allocator.h,v 1.3 2002/01/08 23:04:59 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_allocator.h,v 1.4 2002/01/10 01:28:46 libcw Exp $ // // Copyright (C) 2001, by // @@ -44,11 +44,18 @@ // // // This is a random number in the hope nobody else uses it. +#if __GNUC__ == 2 && __GNUC_MINOR__ < 97 +// gdb-5.0 and 5.1 core dump on old-ABI mangled names with integer template parameters larger +// than one digit. See http://sources.redhat.com/ml/bug-binutils/2002-q1/msg00021.html and +// http://sources.redhat.com/ml/bug-binutils/2002-q1/msg00023.html. +int const random_salt = 6; +#else int const random_salt = 327665; +#endif // Dummy mutex instance numbers, these must be negative. int const single_threaded_userspace_instance = -random_salt; // Use std::alloc int const single_threaded_internal_instance = -1; -int const multi_threaded_usrspace_instance = -random_salt; // Use std::alloc +int const multi_threaded_userspace_instance = -random_salt; // Use std::alloc int const multi_threaded_internal_instance = -2; #ifdef DEBUGDEBUG @@ -220,7 +227,7 @@ #define LIBCWD_DEBUGDEBUG_COMMA(x) #endif -#define DEFAULT_ALLOC_USRSPACE(instance) ::libcw::debug::_private_:: \ +#define DEFAULT_ALLOC_USERSPACE(instance) ::libcw::debug::_private_:: \ allocator_adaptor<char, \ ::std::alloc, \ false \ @@ -233,7 +240,7 @@ ::libcw::debug::_private_::multi_threaded_internal_instance, \ ::libcw::debug::_private_::random_salt + \ ::libcw::debug::_private_::instance >, \ - true \ + true \ LIBCWD_DEBUGDEBUG_COMMA(::libcw::debug::_private_::instance)> #ifdef LIBCWD_THREAD_SAFE @@ -254,13 +261,13 @@ // in the case of multi-threading because it can be that the allocator mutex is locked, which would // result in a deadlock if we try to use it again here. #define LIBCWD_MT_INTERNAL_ALLOCATOR DEFAULT_ALLOC_INTERNAL(multi_threaded_internal_instance) -#define LIBCWD_MT_USERSPACE_ALLOCATOR DEFAULT_ALLOC_USRSPACE(multi_threaded_usrspace_instance) +#define LIBCWD_MT_USERSPACE_ALLOCATOR DEFAULT_ALLOC_USERSPACE(multi_threaded_userspace_instance) #else // !LIBCWD_THREAD_SAFE // LIBCWD_MT_*_ALLOCATOR uses the normal default allocator of libstdc++-v3 (alloc) using locking // itself. The userspace allocator shares it memory pool with everything else (that uses this // allocator, which is most of the (userspace) STL). #define LIBCWD_MT_INTERNAL_ALLOCATOR DEFAULT_ALLOC_INTERNAL(single_threaded_internal_instance) -#define LIBCWD_MT_USERSPACE_ALLOCATOR DEFAULT_ALLOC_USRSPACE(single_threaded_userspace_instance) +#define LIBCWD_MT_USERSPACE_ALLOCATOR DEFAULT_ALLOC_USERSPACE(single_threaded_userspace_instance) #endif // !LIBCWD_THREAD_SAFE //--------------------------------------------------------------------------------------------------- Index: src/libcwd/include/libcw/private_threading.h diff -u src/libcwd/include/libcw/private_threading.h:1.5 src/libcwd/include/libcw/private_threading.h:1.6 --- src/libcwd/include/libcw/private_threading.h:1.5 Tue Jan 8 15:04:59 2002 +++ src/libcwd/include/libcw/private_threading.h Wed Jan 9 17:28:46 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.5 2002/01/08 23:04:59 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.6 2002/01/10 01:28:46 libcw Exp $ // // Copyright (C) 2001, by // @@ -120,11 +120,11 @@ object_files_instance, // rwlock end_recursive_types, // Fast mutexes. + memblk_map_instance, // rwlock mutex_initialization_instance, ids_singleton_tct_S_ids_instance, alloc_tag_desc_instance, type_info_of_instance, - memblk_map_instance, // rwlock dlopen_map_instance, write_max_len_instance, debug_objects_instance, // rwlock ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-10 05:04:45
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-10 05:04:44 UTC Modified files: libcwd/acinclude.m4 libcwd/elf32.cc libcwd/testsuite/libcwd.tst/do.cc Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/acinclude.m4 diff -u src/libcwd/acinclude.m4:1.45 src/libcwd/acinclude.m4:1.46 --- src/libcwd/acinclude.m4:1.45 Mon Jan 7 18:12:41 2002 +++ src/libcwd/acinclude.m4 Wed Jan 9 21:04:34 2002 @@ -879,13 +879,13 @@ AC_CANONICAL_HOST case "$host" in *freebsd*) DEBUGOPTS=-ggdb ;; dnl FreeBSD needs -ggdb to include sourcefile:linenumber info in its object files. - *) DEBUGOPTS=-g ;; + *) DEBUGOPTS=-ggdb3 ;; esac AC_SUBST(DEBUGOPTS) dnl Other options if test "$USE_MAINTAINER_MODE" = yes; then -EXTRAOPTS="-O" +EXTRAOPTS="" else EXTRAOPTS="-O" fi Index: src/libcwd/elf32.cc diff -u src/libcwd/elf32.cc:1.29 src/libcwd/elf32.cc:1.30 --- src/libcwd/elf32.cc:1.29 Thu Jan 3 20:22:33 2002 +++ src/libcwd/elf32.cc Wed Jan 9 21:04:34 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.29 2002/01/04 04:22:33 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.30 2002/01/10 05:04:34 libcw Exp $ // // Copyright (C) 2001, by // @@ -614,7 +614,9 @@ object_files_string_set_ct::iterator M_source_iter; Elf32_Half M_line; +#if DEBUGSTABS || DEBUGDWARF friend std::ostream& operator<<(std::ostream& os, location_st const& loc); +#endif }; class object_file_ct; @@ -1910,18 +1912,14 @@ void object_file_ct::register_range(location_st const& location, range_st const& range) { +#if !DEBUGSTABS && !DEBUGDWARF + M_ranges.insert(std::pair<range_st, location_st>(range, location)); +#else if ((DEBUGDWARF && M_dwarf_debug_line_section_index) || (DEBUGSTABS && M_stabs_section_index)) Dout(dc::bfd, std::hex << range.start << " - " << (range.start + range.size) << "; " << location << '.'); -#if DEBUGSTABS || DEBUGDWARF - std::pair<object_files_range_location_map_ct::iterator, bool> p( -#endif - M_ranges.insert(std::pair<range_st, location_st>(range, location)) -#if DEBUGSTABS || DEBUGDWARF - ) -#endif - ; -#if DEBUGSTABS || DEBUGDWARF + + std::pair<object_files_range_location_map_ct::iterator, bool> p(M_ranges.insert(std::pair<range_st, location_st>(range, location))); if (!p.second) { if ((*p.first).second.M_func_iter != location.M_func_iter) Index: src/libcwd/testsuite/libcwd.tst/do.cc diff -u src/libcwd/testsuite/libcwd.tst/do.cc:1.17 src/libcwd/testsuite/libcwd.tst/do.cc:1.18 --- src/libcwd/testsuite/libcwd.tst/do.cc:1.17 Sat Dec 29 20:17:51 2001 +++ src/libcwd/testsuite/libcwd.tst/do.cc Wed Jan 9 21:04:34 2002 @@ -38,6 +38,13 @@ #endif Debug( libcw_do.on() ); +#ifdef DEBUGDEBUG + // Get rid of the `first_time'. + Debug( my_own_do.on() ); + Debug( my_own_do.off() ); + Debug( example::my_own_do.on() ); + Debug( example::my_own_do.off() ); +#endif Debug( dc::notice.on() ); Debug( dc::debug.on() ); ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-10 14:33:14
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-10 14:33:11 UTC Modified files: libcwd/debug.cc Log message: Bug fix for --enable-libcwd-debug --disable-libcwd-debug-output ---------------------- diff included ---------------------- Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.51 src/libcwd/debug.cc:1.52 --- src/libcwd/debug.cc:1.51 Tue Jan 8 15:50:16 2002 +++ src/libcwd/debug.cc Thu Jan 10 06:33:01 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.51 2002/01/08 23:50:16 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.52 2002/01/10 14:33:01 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -954,7 +954,7 @@ // The cast is necessary on platforms where corelim.rlim_max is long long // and libstdc++ was not compiled with support for long long. Dout(dc::warning, "core size is limited (hard limit: " << (unsigned long)(corelim.rlim_max / 1024) << " kb). Core dumps might be truncated!"); -#ifndef DEBUGDEBUG +#ifndef DEBUGDEBUGOUTPUT _off = 0; #endif } @@ -963,7 +963,7 @@ #else _off = -1; Dout(dc::warning, "Please unlimit core size manually"); -#ifndef DEBUGDEBUG +#ifndef DEBUGDEBUGOUTPUT _off = 0; #endif #endif ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-10 18:11:13
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-10 18:11:12 UTC Modified files: libcwd/elf32.cc Log message: Bug fix in line number lookup. ---------------------- diff included ---------------------- Index: src/libcwd/elf32.cc diff -u src/libcwd/elf32.cc:1.30 src/libcwd/elf32.cc:1.31 --- src/libcwd/elf32.cc:1.30 Wed Jan 9 21:04:34 2002 +++ src/libcwd/elf32.cc Thu Jan 10 10:11:02 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.30 2002/01/10 05:04:34 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.31 2002/01/10 18:11:02 libcw Exp $ // // Copyright (C) 2001, by // @@ -839,12 +839,10 @@ M_used = true; return; } + LIBCWD_ASSERT( M_range.start <= M_address ); if (M_range.start == M_address) - { DoutDwarf(dc::bfd, "Skipping M_store: address range is zero."); - return; - } - if (M_range.start) + else if (M_range.start) { DoutDwarf(dc::bfd, "M_store(): Registering new range."); M_range.size = M_address - M_range.start; ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-11 02:23:44
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-11 02:23:42 UTC Modified files: libcwd/elf32.cc libcwd/maintMakefile.in Log message: More bug fixes for (recent changes to) dwarf2. ---------------------- diff included ---------------------- Index: src/libcwd/elf32.cc diff -u src/libcwd/elf32.cc:1.31 src/libcwd/elf32.cc:1.32 --- src/libcwd/elf32.cc:1.31 Thu Jan 10 10:11:02 2002 +++ src/libcwd/elf32.cc Thu Jan 10 18:23:32 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.31 2002/01/10 18:11:02 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.32 2002/01/11 02:23:32 libcw Exp $ // // Copyright (C) 2001, by // @@ -710,6 +710,8 @@ DoutDwarf(dc::bfd, "--> Sequence end."); if (is_valid()) M_store(); + // Invalidate range tracking, we will start all over. + M_range.start = 0; } Elf32_Half get_line(void) const { LIBCWD_ASSERT( (M_flags & 1) ); return M_line; } @@ -796,6 +798,7 @@ object_files_string_set_ct M_source_files; object_files_range_location_map_ct M_ranges; bool M_debug_info_loaded; + bool M_inside_find_nearest_line; Elf32_Word M_stabs_section_index; Elf32_Word M_dwarf_debug_info_section_index; Elf32_Word M_dwarf_debug_abbrev_section_index; @@ -839,7 +842,10 @@ M_used = true; return; } - LIBCWD_ASSERT( M_range.start <= M_address ); +#if DEBUGDWARF + if (M_range.start > M_address) + core_dump(); +#endif if (M_range.start == M_address) DoutDwarf(dc::bfd, "Skipping M_store: address range is zero."); else if (M_range.start) @@ -1866,14 +1872,39 @@ if (!M_debug_info_loaded) { #ifdef LIBCWD_THREAD_SAFE - // `object_files_string' and the STL containers using `_private_::object_files_allocator' in the - // following functions need this lock. - _private_::rwlock_tct<_private_::object_files_instance>::wrlock(); + // `object_files_string' and the STL containers using `_private_::object_files_allocator' in the + // following functions need this lock. + _private_::rwlock_tct<_private_::object_files_instance>::wrlock(); #endif + if (M_inside_find_nearest_line) // Break loop caused by re-entry through a call to malloc. + { + *file = NULL; + *func = symbol->name; + *line = 0; + return; + } + M_inside_find_nearest_line = true; +#if DEBUGSTABS || DEBUGDWARF + int off = libcw::debug::libcw_do._off; + libcw::debug::libcw_do._off = -1; // Force debug output on. + int cnt = 0; + Debug( + while(!dc::bfd.is_on()) + { + ++cnt; + dc::bfd.on(); + } + ); +#endif if (M_dwarf_debug_line_section_index) load_dwarf(); else if (M_stabs_section_index) load_stabs(); +#if DEBUGSTABS || DEBUGDWARF + Debug( while(cnt) { --cnt; dc::bfd.off(); } ); + libcw::debug::libcw_do._off = off; +#endif + M_inside_find_nearest_line = false; #ifdef LIBCWD_THREAD_SAFE _private_::rwlock_tct<_private_::object_files_instance>::wrunlock(); #endif @@ -1964,6 +1995,7 @@ if (DEBUGELF32) Debug( libcw_do.inc_indent(4) ); M_debug_info_loaded = false; + M_inside_find_nearest_line = false; M_stabs_section_index = 0; M_dwarf_debug_line_section_index = 0; for(int i = 0; i < M_header.e_shnum; ++i) Index: src/libcwd/maintMakefile.in diff -u src/libcwd/maintMakefile.in:1.18 src/libcwd/maintMakefile.in:1.19 --- src/libcwd/maintMakefile.in:1.18 Tue Jan 8 17:42:21 2002 +++ src/libcwd/maintMakefile.in Thu Jan 10 18:23:32 2002 @@ -103,16 +103,16 @@ full-check: Makefile @( \ for c in \ - '--enable-maintainer-mode --enable-libcwd-debugm --enable-libcwd-debug --compilers=3.0.3,2.96,2.95.3' \ - '--enable-maintainer-mode --enable-libcwd-threading --compilers=3.0.3,3.0.2,3.0.1,3.0' \ - '--enable-maintainer-mode --compilers=3.0.3,2.96,2.95.3,2.95.1,2.95.2,3.0' \ - '--enable-maintainer-mode --enable-libcwd-threading --enable-libcwd-debugm --compilers=3.0.3' \ + '--enable-maintainer-mode --enable-libcwd-threading --enable-libcwd-debugm --enable-libcwd-debug --disable-libcwd-debug-output --compilers=3.0.3,2.96,2.95.3' \ + '--enable-maintainer-mode --enable-libcwd-debugm --enable-libcwd-debug --disable-libcwd-debug-output --compilers=3.0.3,2.96,2.95.3' \ + '--enable-maintainer-mode --enable-libcwd-threading --enable-libcwd-debugm --compilers=3.0.3,2.96,2.95.3' \ '--enable-maintainer-mode --enable-libcwd-debugm --compilers=3.0.3,2.96,2.95.3' \ - '--enable-maintainer-mode --enable-libcwd-threading --enable-libcwd-debug --disable-libcwd-debug-output --compilers=3.0.3' \ + '--enable-maintainer-mode --enable-libcwd-threading --enable-libcwd-debug --disable-libcwd-debug-output --compilers=3.0.3,2.96,2.95.3' \ '--enable-maintainer-mode --enable-libcwd-debug --disable-libcwd-debug-output --compilers=3.0.3,2.96,2.95.3' \ - '--enable-maintainer-mode --enable-libcwd-threading --enable-libcwd-debugm --enable-libcwd-debug --disable-libcwd-debug-output --compilers=3.0.3' \ - '--enable-maintainer-mode --enable-libcwd-debugm --enable-libcwd-debug --disable-libcwd-debug-output --compilers=3.0.3,2.96,2.95.3' \ - '--enable-maintainer-mode --enable-libcwd-threading --enable-libcwd-debugm --enable-libcwd-debug --compilers=3.0.3' \ + '--enable-maintainer-mode --enable-libcwd-threading --enable-libcwd-debugm --enable-libcwd-debug --compilers=3.0.3,2.96,2.95.3' \ + '--enable-maintainer-mode --enable-libcwd-debugm --enable-libcwd-debug --compilers=3.0.3,2.96,2.95.3' \ + '--enable-maintainer-mode --enable-libcwd-threading --compilers=3.0.3,3.0.2,3.0.1,2.96,2.95.3,2.95.2' \ + '--enable-maintainer-mode --compilers=3.0.3,3.0.2,3.0.1,2.96,2.95.3,2.95.2' \ ; do \ config=`echo $$c | sed -e 's/ --compilers=.*$$//'`; \ case "$$c" in \ ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-11 02:57:57
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-11 02:57:56 UTC Modified files: libcwd/testsuite/libcwd.threads/keys.re Log message: Bug fix. ---------------------- diff included ---------------------- Index: src/libcwd/testsuite/libcwd.threads/keys.re diff -u src/libcwd/testsuite/libcwd.threads/keys.re:1.2 src/libcwd/testsuite/libcwd.threads/keys.re:1.3 --- src/libcwd/testsuite/libcwd.threads/keys.re:1.2 Tue Jan 8 18:20:50 2002 +++ src/libcwd/testsuite/libcwd.threads/keys.re Thu Jan 10 18:57:46 2002 @@ -1,5 +1,5 @@ // input lines 3 -// output till ^WARNING +// output till ^WARNING : Ok ((WARNING : core size is limited.* )*(BFD : Loading debug info from.* )*) ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-11 03:52:12
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-11 03:52:10 UTC Modified files: libcwd/testsuite/.cvsignore libcwd/testsuite/Makefile.in Added files: libcwd/testsuite/libcwd.nodebug/nodebug.exp libcwd/testsuite/libcwd.threads/threads.exp libcwd/testsuite/libcwd.tst/tst.exp Removed files: libcwd/testsuite/libcwd.nodebug/test.exp libcwd/testsuite/libcwd.threads/test.exp libcwd/testsuite/libcwd.tst/test.exp Log message: Don't run the threads tests when no configured with --enable-libcwd-threading ---------------------- diff included ---------------------- Index: src/libcwd/testsuite/.cvsignore diff -u src/libcwd/testsuite/.cvsignore:1.5 src/libcwd/testsuite/.cvsignore:1.6 --- src/libcwd/testsuite/.cvsignore:1.5 Tue Jan 8 10:14:38 2002 +++ src/libcwd/testsuite/.cvsignore Thu Jan 10 19:52:00 2002 @@ -1,5 +1,5 @@ -libcwd.log -libcwd.sum +*.log +*.sum site.exp Makefile nodebug_*_shared Index: src/libcwd/testsuite/Makefile.in diff -u src/libcwd/testsuite/Makefile.in:1.26 src/libcwd/testsuite/Makefile.in:1.27 --- src/libcwd/testsuite/Makefile.in:1.26 Tue Jan 8 10:14:38 2002 +++ src/libcwd/testsuite/Makefile.in Thu Jan 10 19:52:00 2002 @@ -22,6 +22,7 @@ STATICLIBS = $(top_builddir)/.libs/libcwd.a @LIBS@ @LIB_THREADS@ enable_shared = @enable_shared@ enable_static = @enable_static@ +enable_threads = @libcwd_config_threading@ INCLUDES = -Ilibcwd.tst -I$(top_builddir)/include -I$(srcdir)/../include PACKAGE = @PACKAGE@ VERSION = @VERSION@ @@ -46,6 +47,13 @@ STATICNODEBUGTARGETS := STATICTHREADSTARGETS := endif +ifeq ($(enable_threads), yes) +SHAREDTARGETS := $(SHAREDTSTTARGETS) $(SHAREDNODEBUGTARGETS) $(SHAREDTHREADSTARGETS) +EXPECT_SCRIPTS = nodebug.exp threads.exp tst.exp +else +SHAREDTARGETS := $(SHAREDTSTTARGETS) $(SHAREDNODEBUGTARGETS) +EXPECT_SCRIPTS = nodebug.exp tst.exp +endif CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) CXXLINK = $(CXX) $(CXXFLAGS) $(LDFLAGS) @@ -79,7 +87,7 @@ -@rm -f ./tmp? check: site.exp module.so - $(RUNTEST) $(RUNTESTFLAGS) $(FLAGS_TO_PASS) + $(RUNTEST) $(RUNTESTFLAGS) $(FLAGS_TO_PASS) $(EXPECT_SCRIPTS) module.so: module.cc $(top_builddir)/.libs/libcwd.so.* $(CXXCOMPILE) -shared -fpic -DPIC -w $< -o $@ @@ -104,21 +112,20 @@ $(CXXLINK) $< -o $@ $(STATICLIBS) endif -shared: $(SHAREDTSTTARGETS) $(SHAREDNODEBUGTARGETS) $(SHAREDTHREADSTARGETS) -static: $(STATICTSTTARGETS) $(STATICNODEBUGTARGETS) $(STATICTHREADSTARGETS) +shared: $(SHAREDTARGETS) +static: $(STATICTARGETS) run: shared static module.so - @for i in $(SHAREDTSTTARGETS) $(SHAREDNODEBUGTARGETS) $(SHAREDTHREADSTARGETS) \ - $(STATICTSTTARGETS) $(STATICNODEBUGTARGETS) $(STATICTHREADSTARGETS); do \ + @for i in $(SHAREDTARGETS) $(STATICTARGETS); do \ echo -n "$$i: "; if ./$$i 2>/dev/null >/dev/null; then echo "OK"; else echo "ERROR"; fi ; done # Clean rules mostlyclean: rm -f site.bak core *.core *.o clean: mostlyclean - rm -f site.exp libcwd.log libcwd.sum *_*_shared *_*_static module.so .\#* */.\#* + rm -f site.exp *.log *.sum *_*_shared *_*_static module.so .\#* */.\#* distclean: clean - rm -f Makefile *.log *.sum + rm -f Makefile # Uninstall rule uninstall: Index: src/libcwd/testsuite/libcwd.nodebug/nodebug.exp diff -u /dev/null src/libcwd/testsuite/libcwd.nodebug/nodebug.exp:1.1 --- /dev/null Thu Jan 10 19:52:10 2002 +++ src/libcwd/testsuite/libcwd.nodebug/nodebug.exp Thu Jan 10 19:52:00 2002 @@ -0,0 +1,36 @@ +global srcdir subdir +global SHAREDLIBS STATICLIBS + +catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles +#set srcfiles $srcdir/$subdir/type_info.cc +verbose "srcfiles are $srcfiles" + +set prefix "" +foreach x $srcfiles { + regsub "\\.cc$" $x "" prefix + set bname [file tail $prefix] + set args "" + if [file exists ${prefix}.arg] { + set id [open "${prefix}.arg" r]; + set args [read -nonewline $id]; + close $id; + } + set resfile "${prefix}.re" + set options "regexp_match nodebug" + + if [file exists ${prefix}.inp] { + set inpfile ${prefix}.inp + } else { + set inpfile "" + } + verbose "inpfile is $inpfile" + verbose "SHAREDLIBS is \"$SHAREDLIBS\"" + verbose "STATICLIBS is \"$STATICLIBS\"" + + if { $SHAREDLIBS != "" } { + test_libcwd $options "${prefix}.cc" "" $inpfile $resfile $args + } + if { $STATICLIBS != "" } { + test_libcwd "static $options" "${prefix}.cc" "" $inpfile $resfile $args + } +} Index: src/libcwd/testsuite/libcwd.nodebug/test.exp diff -u src/libcwd/testsuite/libcwd.nodebug/test.exp:1.2 src/libcwd/testsuite/libcwd.nodebug/test.exp:removed --- src/libcwd/testsuite/libcwd.nodebug/test.exp:1.2 Thu Oct 12 14:02:56 2000 +++ src/libcwd/testsuite/libcwd.nodebug/test.exp Thu Jan 10 19:52:10 2002 @@ -1,36 +0,0 @@ -global srcdir subdir -global SHAREDLIBS STATICLIBS - -catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles -#set srcfiles $srcdir/$subdir/type_info.cc -verbose "srcfiles are $srcfiles" - -set prefix "" -foreach x $srcfiles { - regsub "\\.cc$" $x "" prefix - set bname [file tail $prefix] - set args "" - if [file exists ${prefix}.arg] { - set id [open "${prefix}.arg" r]; - set args [read -nonewline $id]; - close $id; - } - set resfile "${prefix}.re" - set options "regexp_match nodebug" - - if [file exists ${prefix}.inp] { - set inpfile ${prefix}.inp - } else { - set inpfile "" - } - verbose "inpfile is $inpfile" - verbose "SHAREDLIBS is \"$SHAREDLIBS\"" - verbose "STATICLIBS is \"$STATICLIBS\"" - - if { $SHAREDLIBS != "" } { - test_libcwd $options "${prefix}.cc" "" $inpfile $resfile $args - } - if { $STATICLIBS != "" } { - test_libcwd "static $options" "${prefix}.cc" "" $inpfile $resfile $args - } -} Index: src/libcwd/testsuite/libcwd.threads/test.exp diff -u src/libcwd/testsuite/libcwd.threads/test.exp:1.1 src/libcwd/testsuite/libcwd.threads/test.exp:removed --- src/libcwd/testsuite/libcwd.threads/test.exp:1.1 Tue Jan 8 10:14:39 2002 +++ src/libcwd/testsuite/libcwd.threads/test.exp Thu Jan 10 19:52:10 2002 @@ -1,34 +0,0 @@ -global srcdir subdir -global SHAREDLIBS STATICLIBS - -catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles -# set srcfiles $srcdir/$subdir/keys.cc -verbose "srcfiles are $srcfiles" - -set prefix "" -foreach x $srcfiles { - regsub "\\.cc$" $x "" prefix - set bname [file tail $prefix] - set args "" - if [file exists ${prefix}.arg] { - set id [open "${prefix}.arg" r]; - set args [read -nonewline $id]; - close $id; - } - set resfile "${prefix}.re" - set options "regexp_match" - - if [file exists ${prefix}.inp] { - set inpfile ${prefix}.inp - } else { - set inpfile "" - } - verbose "inpfile is $inpfile" - - if { $SHAREDLIBS != "" } { - test_libcwd $options "${prefix}.cc" "" $inpfile $resfile $args - } - if { $STATICLIBS != "" } { - test_libcwd "static $options" "${prefix}.cc" "" $inpfile $resfile $args - } -} Index: src/libcwd/testsuite/libcwd.threads/threads.exp diff -u /dev/null src/libcwd/testsuite/libcwd.threads/threads.exp:1.1 --- /dev/null Thu Jan 10 19:52:10 2002 +++ src/libcwd/testsuite/libcwd.threads/threads.exp Thu Jan 10 19:52:00 2002 @@ -0,0 +1,34 @@ +global srcdir subdir +global SHAREDLIBS STATICLIBS + +catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles +# set srcfiles $srcdir/$subdir/keys.cc +verbose "srcfiles are $srcfiles" + +set prefix "" +foreach x $srcfiles { + regsub "\\.cc$" $x "" prefix + set bname [file tail $prefix] + set args "" + if [file exists ${prefix}.arg] { + set id [open "${prefix}.arg" r]; + set args [read -nonewline $id]; + close $id; + } + set resfile "${prefix}.re" + set options "regexp_match" + + if [file exists ${prefix}.inp] { + set inpfile ${prefix}.inp + } else { + set inpfile "" + } + verbose "inpfile is $inpfile" + + if { $SHAREDLIBS != "" } { + test_libcwd $options "${prefix}.cc" "" $inpfile $resfile $args + } + if { $STATICLIBS != "" } { + test_libcwd "static $options" "${prefix}.cc" "" $inpfile $resfile $args + } +} Index: src/libcwd/testsuite/libcwd.tst/test.exp diff -u src/libcwd/testsuite/libcwd.tst/test.exp:1.8 src/libcwd/testsuite/libcwd.tst/test.exp:removed --- src/libcwd/testsuite/libcwd.tst/test.exp:1.8 Thu Jan 3 20:22:33 2002 +++ src/libcwd/testsuite/libcwd.tst/test.exp Thu Jan 10 19:52:10 2002 @@ -1,34 +0,0 @@ -global srcdir subdir -global SHAREDLIBS STATICLIBS - -catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles -# set srcfiles $srcdir/$subdir/leak.cc -verbose "srcfiles are $srcfiles" - -set prefix "" -foreach x $srcfiles { - regsub "\\.cc$" $x "" prefix - set bname [file tail $prefix] - set args "" - if [file exists ${prefix}.arg] { - set id [open "${prefix}.arg" r]; - set args [read -nonewline $id]; - close $id; - } - set resfile "${prefix}.re" - set options "regexp_match" - - if [file exists ${prefix}.inp] { - set inpfile ${prefix}.inp - } else { - set inpfile "" - } - verbose "inpfile is $inpfile" - - if { $SHAREDLIBS != "" } { - test_libcwd $options "${prefix}.cc" "" $inpfile $resfile $args - } - if { $STATICLIBS != "" } { - test_libcwd "static $options" "${prefix}.cc" "" $inpfile $resfile $args - } -} Index: src/libcwd/testsuite/libcwd.tst/tst.exp diff -u /dev/null src/libcwd/testsuite/libcwd.tst/tst.exp:1.1 --- /dev/null Thu Jan 10 19:52:10 2002 +++ src/libcwd/testsuite/libcwd.tst/tst.exp Thu Jan 10 19:52:00 2002 @@ -0,0 +1,34 @@ +global srcdir subdir +global SHAREDLIBS STATICLIBS + +catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles +# set srcfiles $srcdir/$subdir/leak.cc +verbose "srcfiles are $srcfiles" + +set prefix "" +foreach x $srcfiles { + regsub "\\.cc$" $x "" prefix + set bname [file tail $prefix] + set args "" + if [file exists ${prefix}.arg] { + set id [open "${prefix}.arg" r]; + set args [read -nonewline $id]; + close $id; + } + set resfile "${prefix}.re" + set options "regexp_match" + + if [file exists ${prefix}.inp] { + set inpfile ${prefix}.inp + } else { + set inpfile "" + } + verbose "inpfile is $inpfile" + + if { $SHAREDLIBS != "" } { + test_libcwd $options "${prefix}.cc" "" $inpfile $resfile $args + } + if { $STATICLIBS != "" } { + test_libcwd "static $options" "${prefix}.cc" "" $inpfile $resfile $args + } +} ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-12 02:54:54
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-12 02:54:52 UTC Modified files: libcwd/acinclude.m4 libcwd/bfd.cc libcwd/configure.in libcwd/debug.cc libcwd/elf32.cc libcwd/include/libcw/class_channel.h libcwd/include/libcw/class_debug.h libcwd/include/libcw/private_threading.h Log message: Left over from previous patch :/ and fix for 2.96 (initialization order fiasco actually). ---------------------- diff included ---------------------- Index: src/libcwd/acinclude.m4 diff -u src/libcwd/acinclude.m4:1.46 src/libcwd/acinclude.m4:1.47 --- src/libcwd/acinclude.m4:1.46 Wed Jan 9 21:04:34 2002 +++ src/libcwd/acinclude.m4 Fri Jan 11 18:54:42 2002 @@ -879,7 +879,7 @@ AC_CANONICAL_HOST case "$host" in *freebsd*) DEBUGOPTS=-ggdb ;; dnl FreeBSD needs -ggdb to include sourcefile:linenumber info in its object files. - *) DEBUGOPTS=-ggdb3 ;; + *) DEBUGOPTS=-g ;; esac AC_SUBST(DEBUGOPTS) Index: src/libcwd/bfd.cc diff -u src/libcwd/bfd.cc:1.90 src/libcwd/bfd.cc:1.91 --- src/libcwd/bfd.cc:1.90 Sun Dec 30 21:01:23 2001 +++ src/libcwd/bfd.cc Fri Jan 11 18:54:42 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.90 2001/12/31 05:01:23 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.91 2002/01/12 02:54:42 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -956,18 +956,10 @@ #ifdef ALWAYS_PRINT_LOADING // We want debug output to BFD - bool const libcwd_was_off = -#ifdef DEBUGDEBUG - false; -#else - true; -#endif - if (libcwd_was_off) - Debug( libcw_do.on() ); - bool bfd_was_off; - Debug( bfd_was_off = !dc::bfd.is_on() ); - if (bfd_was_off) - Debug( dc::bfd.on() ); + libcw::debug::debug_ct::OnOffState state; + Debug( libcw_do.force_on(state) ); + libcw::debug::channel_ct::OnOffState state2; + Debug( dc::bfd.force_on(state2, "BFD") ); #endif // Initialize object files list, we don't really need the @@ -1043,10 +1035,8 @@ BFD_RELEASE_WRITE_LOCK #ifdef ALWAYS_PRINT_LOADING - if (libcwd_was_off) - Debug( libcw_do.off() ); - if (bfd_was_off) - Debug( dc::bfd.off() ); + Debug( dc::bfd.restore(state2) ); + Debug( libcw_do.restore(state) ); #endif WST_initialized = true; // MT: Safe, this function is Single Threaded. Index: src/libcwd/configure.in diff -u src/libcwd/configure.in:1.94 src/libcwd/configure.in:1.95 --- src/libcwd/configure.in:1.94 Tue Jan 8 15:39:18 2002 +++ src/libcwd/configure.in Fri Jan 11 18:54:42 2002 @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_REVISION($Revision: 1.94 $)dnl +AC_REVISION($Revision: 1.95 $)dnl dnl General intialization of `autoconf' varaibles. dnl Ensure that the directory specified with --srcdir was correct @@ -159,8 +159,6 @@ dnl Configuration needed by the testsuite, extract this from the generated 'libtool' enable_shared=`./libtool --config | grep '^build_libtool_libs=' | sed -e 's/build_libtool_libs=//'` enable_static=`./libtool --config | grep '^build_old_libs=' | sed -e 's/build_old_libs=//'` -AC_SUBST(enable_shared) -AC_SUBST(enable_static) if test $enable_shared = yes; then if expr "$host" : ".*openbsd.*" >/dev/null; then AC_MSG_ERROR([ @@ -220,6 +218,7 @@ dnl Configuration needed by the testsuite AC_SUBST(enable_shared) AC_SUBST(enable_static) +AC_SUBST(libcwd_config_threading) if test "$libcwd_config_alloc" = yes; then CW_CONFIG_DEBUGMALLOC=define Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.52 src/libcwd/debug.cc:1.53 --- src/libcwd/debug.cc:1.52 Thu Jan 10 06:33:01 2002 +++ src/libcwd/debug.cc Fri Jan 11 18:54:42 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.52 2002/01/10 14:33:01 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.53 2002/01/12 02:54:42 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -950,22 +950,20 @@ corelim.rlim_cur = corelim.rlim_max; if (corelim.rlim_max != RLIM_INFINITY) { - _off = -1; + OnOffState state; + force_on(state); // The cast is necessary on platforms where corelim.rlim_max is long long // and libstdc++ was not compiled with support for long long. Dout(dc::warning, "core size is limited (hard limit: " << (unsigned long)(corelim.rlim_max / 1024) << " kb). Core dumps might be truncated!"); -#ifndef DEBUGDEBUGOUTPUT - _off = 0; -#endif + restore(state); } if (setrlimit(RLIMIT_CORE, &corelim)) DoutFatal(dc::fatal|error_cf, "unlimit core size failed"); #else - _off = -1; + OnOffState state; + force_on(state); Dout(dc::warning, "Please unlimit core size manually"); -#ifndef DEBUGDEBUGOUTPUT - _off = 0; -#endif + restore(state); #endif } } @@ -1106,10 +1104,10 @@ LIBCWD_TSD_DECLARATION #ifdef LIBCWD_THREAD_SAFE - // MT: Take advantage of the `write_max_len_instance' lock to prevend simultaneous access + // MT: Take advantage of the `write_max_len_instance' lock to prefend simultaneous access // to `next_index' in the case of simultaneously dlopen-loaded libraries. static int next_index; - WNS_index = next_index++; + WNS_index = ++next_index; // Don't use index 0, it is used to make sure that uninitialized channels appear to be off. _private_::mutex_tct<_private_::write_max_len_instance>::unlock(); @@ -1334,6 +1332,49 @@ } } // namespace _private_ + + void debug_ct::force_on(debug_ct::OnOffState& state) + { + NS_init(); + state._off = _off; +#ifdef DEBUGDEBUGOUTPUT + state.first_time = first_time; +#endif + _off = -1; // Turn object on. + } + + void debug_ct::restore(debug_ct::OnOffState const& state) + { +#ifdef DEBUGDEBUGOUTPUT + if (state.first_time != first_time) // state.first_time && !first_time. + core_dump(); // on() was called without first a call to off(). +#endif + if (_off != -1) + core_dump(); // off() and on() where called and not in equal pairs. + _off = state._off; // Restore. + } + + void channel_ct::force_on(channel_ct::OnOffState& state, char const* label) + { + NS_initialize(label); +#ifdef LIBCWD_THREAD_SAFE + LIBCWD_TSD_DECLARATION + int& off_cnt(__libcwd_tsd.off_cnt_array[WNS_index]); +#endif + state.off_cnt = off_cnt; + off_cnt = -1; // Turn channel on. + } + + void channel_ct::restore(channel_ct::OnOffState const& state) + { +#ifdef LIBCWD_THREAD_SAFE + LIBCWD_TSD_DECLARATION + int& off_cnt(__libcwd_tsd.off_cnt_array[WNS_index]); +#endif + if (off_cnt != -1) + core_dump(); // off() and on() where called and not in equal pairs. + off_cnt = state.off_cnt; // Restore. + } } // namespace debug } // namespace libcw Index: src/libcwd/elf32.cc diff -u src/libcwd/elf32.cc:1.32 src/libcwd/elf32.cc:1.33 --- src/libcwd/elf32.cc:1.32 Thu Jan 10 18:23:32 2002 +++ src/libcwd/elf32.cc Fri Jan 11 18:54:42 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.32 2002/01/11 02:23:32 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.33 2002/01/12 02:54:42 libcw Exp $ // // Copyright (C) 2001, by // @@ -1886,23 +1886,18 @@ M_inside_find_nearest_line = true; #if DEBUGSTABS || DEBUGDWARF int off = libcw::debug::libcw_do._off; - libcw::debug::libcw_do._off = -1; // Force debug output on. - int cnt = 0; - Debug( - while(!dc::bfd.is_on()) - { - ++cnt; - dc::bfd.on(); - } - ); + libcw::debug::debug_ct::OnOffState state; + Debug( libcw_do.force_on(state) ); + libcw::debug::channel_ct::OnOffState state2; + Debug( dc::bfd.force_on(state2, "BFD") ); #endif if (M_dwarf_debug_line_section_index) load_dwarf(); else if (M_stabs_section_index) load_stabs(); #if DEBUGSTABS || DEBUGDWARF - Debug( while(cnt) { --cnt; dc::bfd.off(); } ); - libcw::debug::libcw_do._off = off; + Debug( dc::bfd.restore(state2) ); + Debug( libcw_do.restore(state) ); #endif M_inside_find_nearest_line = false; #ifdef LIBCWD_THREAD_SAFE Index: src/libcwd/include/libcw/class_channel.h diff -u src/libcwd/include/libcw/class_channel.h:1.3 src/libcwd/include/libcw/class_channel.h:1.4 --- src/libcwd/include/libcw/class_channel.h:1.3 Tue Jan 8 15:04:59 2002 +++ src/libcwd/include/libcw/class_channel.h Fri Jan 11 18:54:42 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel.h,v 1.3 2002/01/08 23:04:59 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel.h,v 1.4 2002/01/12 02:54:42 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -122,6 +122,13 @@ void off(void); void on(void); + + struct OnOffState { + int off_cnt; + }; + + void force_on(OnOffState& state, char const* label); + void restore(OnOffState const& state); public: //--------------------------------------------------------------------------- Index: src/libcwd/include/libcw/class_debug.h diff -u src/libcwd/include/libcw/class_debug.h:1.2 src/libcwd/include/libcw/class_debug.h:1.3 --- src/libcwd/include/libcw/class_debug.h:1.2 Sat Dec 29 20:17:50 2001 +++ src/libcwd/include/libcw/class_debug.h Fri Jan 11 18:54:42 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.2 2001/12/30 04:17:50 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.3 2002/01/12 02:54:42 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -236,6 +236,16 @@ void set_ostream(std::ostream* os); void off(void); void on(void); + + struct OnOffState { + int _off; +#ifdef DEBUGDEBUGOUTPUT + bool first_time; +#endif + }; + + void force_on(OnOffState& state); + void restore(OnOffState const& state); #ifdef DEBUGDEBUGOUTPUT // Since with DEBUGDEBUG defined we start with _off is -1 instead of 0, Index: src/libcwd/include/libcw/private_threading.h diff -u src/libcwd/include/libcw/private_threading.h:1.6 src/libcwd/include/libcw/private_threading.h:1.7 --- src/libcwd/include/libcw/private_threading.h:1.6 Wed Jan 9 17:28:46 2002 +++ src/libcwd/include/libcw/private_threading.h Fri Jan 11 18:54:42 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.6 2002/01/10 01:28:46 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.7 2002/01/12 02:54:42 libcw Exp $ // // Copyright (C) 2001, by // @@ -474,11 +474,15 @@ TSD new_TSD; S_temporary_instance = &new_TSD; S_initializing = true; - LIBCWD_TSD_DECLARATION - set_alloc_checking_off(LIBCWD_TSD); + set_alloc_checking_off(new_TSD); TSD* instance = new TSD; - set_alloc_checking_on(LIBCWD_TSD); + set_alloc_checking_on(new_TSD); pthread_setspecific(S_key, instance); + // Because pthread_setspecific calls calloc, it is possible that in + // the mean time all of libcwd was initialized. Therefore we need + // to copy the temporary TSD to the real TSD because it might + // contain relevant information. + *instance = new_TSD; // This will not call malloc() et al, and thus not change new_TSD while we're copying it. S_initializing = false; S_WNS_initialized = true; mutex_tct<tsd_initialization_instance>::unlock(); ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-12 15:43:28
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-12 15:43:26 UTC Modified files: libcwd/bfd.cc libcwd/include/libcw/class_debug.h Log message: More initialization order fiasco's. ---------------------- diff included ---------------------- Index: src/libcwd/bfd.cc diff -u src/libcwd/bfd.cc:1.91 src/libcwd/bfd.cc:1.92 --- src/libcwd/bfd.cc:1.91 Fri Jan 11 18:54:42 2002 +++ src/libcwd/bfd.cc Sat Jan 12 07:43:15 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.91 2002/01/12 02:54:42 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.92 2002/01/12 15:43:15 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -926,6 +926,9 @@ // cwbfd:: bool ST_init(void) { + // This must be called before calling ST_init(). + libcw_do.NS_init(); + static bool WST_being_initialized = false; // This should catch it when we call new or malloc while 'internal'. if (WST_being_initialized) Index: src/libcwd/include/libcw/class_debug.h diff -u src/libcwd/include/libcw/class_debug.h:1.3 src/libcwd/include/libcw/class_debug.h:1.4 --- src/libcwd/include/libcw/class_debug.h:1.3 Fri Jan 11 18:54:42 2002 +++ src/libcwd/include/libcw/class_debug.h Sat Jan 12 07:43:15 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.3 2002/01/12 02:54:42 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.4 2002/01/12 15:43:15 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -40,6 +40,9 @@ namespace libcw { namespace debug { +#ifdef DEBUGUSEBFD + namespace cwbfd { bool ST_init(void); } +#endif class channel_ct; class fatal_channel_ct; @@ -215,6 +218,9 @@ friend class channel_ct; friend class fatal_channel_ct; friend void ST_initialize_globals(void); +#ifdef DEBUGUSEBFD + friend bool cwbfd::ST_init(void); +#endif void NS_init(void); // Initialize this object, needed because debug output can be written // from the constructors of (other) global objects, and from the malloc() ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-12 17:42:10
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-12 17:42:09 UTC Modified files: libcwd/debugmalloc.cc Log message: Now we copy the temporary TSD to the real one, we can savely initialize libcwd while being called from pthread_setspecific. Moreover, we MUST initialize it at this point, otherwise the balance between continued_cf and dc::finish might be disturbed (see internal_malloc() test for continued_debug_output). ---------------------- diff included ---------------------- Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.69 src/libcwd/debugmalloc.cc:1.70 --- src/libcwd/debugmalloc.cc:1.69 Tue Jan 8 10:14:37 2002 +++ src/libcwd/debugmalloc.cc Sat Jan 12 09:41:59 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.69 2002/01/08 18:14:37 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.70 2002/01/12 17:41:59 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -1492,10 +1492,6 @@ _private_::set_alloc_checking_on(LIBCWD_TSD); } if (1 -#ifdef LIBCWD_THREAD_SAFE - // Don't initialize libcwd while having only a 'temporal' __libcwd_tsd! - && ::libcw::debug::_private_::thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::initialized() -#endif #ifdef __GLIBCPP__ // "ios_base" is always initialized for libstdc++ version 2. && !_private_::WST_ios_base_initialized && !_private_::inside_ios_base_Init_Init() ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-13 03:14:16
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-13 03:14:15 UTC Modified files: libcwd/debugmalloc.cc Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.70 src/libcwd/debugmalloc.cc:1.71 --- src/libcwd/debugmalloc.cc:1.70 Sat Jan 12 09:41:59 2002 +++ src/libcwd/debugmalloc.cc Sat Jan 12 19:14:05 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.70 2002/01/12 17:41:59 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.71 2002/01/13 03:14:05 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -2105,8 +2105,24 @@ // malloc(3) and calloc(3) replacements: // +#if __GNUC__ >= 3 || __GNUC_MINOR__ >= 97 && defined(LIBCWD_THREAD_SAFE) +#define UNLOCK if (locked) _private_::allocator_unlock(); +#else +#define UNLOCK +#endif + void* __libcwd_malloc(size_t size) { +#if __GNUC__ >= 3 || __GNUC_MINOR__ >= 97 && defined(LIBCWD_THREAD_SAFE) + bool locked = false; + if (_private_::WST_multi_threaded) + { + locked = _private_::allocator_trylock(false); // Fake a std::string (etc) lock. + if (!locked) + core_dump(); + } +#endif + LIBCWD_TSD_DECLARATION #ifdef DEBUGDEBUGMALLOC // We can't use `assert' here, because that can call malloc. @@ -2128,6 +2144,7 @@ DEBUGDEBUGMALLOC_CERR( "DEBUGDEBUGMALLOC: Internal: Entering `__libcwd_malloc(" << size << ")' [" << saved_marker << ']' ); #if !defined(DEBUGDEBUGMALLOC) && !defined(DEBUGMAGICMALLOC) + UNLOCK return __libc_malloc(size); #else // defined(DEBUGDEBUGMALLOC) || defined(DEBUGMAGICMALLOC) @@ -2137,6 +2154,7 @@ DEBUGDEBUGMALLOC_CERR( "DEBUGDEBUGMALLOC: Internal: Leaving `__libcwd_malloc': " << ptr << " [" << saved_marker << ']' ); --__libcwd_tsd.recursive; #endif // DEBUGDEBUGMALLOC + UNLOCK return ptr; #else // DEBUGMAGICMALLOC void* ptr = __libc_malloc(SIZE_PLUS_TWELVE(size)); @@ -2145,6 +2163,7 @@ #ifdef DEBUGDEBUGMALLOC --__libcwd_tsd.recursive; #endif + UNLOCK return NULL; } ((size_t*)ptr)[0] = INTERNAL_MAGIC_MALLOC_BEGIN; @@ -2154,6 +2173,7 @@ DEBUGDEBUGMALLOC_CERR( "DEBUGDEBUGMALLOC: Internal: Leaving `__libcwd_malloc': " << static_cast<size_t*>(ptr) + 2 << " [" << saved_marker << ']' ); --__libcwd_tsd.recursive; #endif // DEBUGDEBUGMALLOC + UNLOCK return static_cast<size_t*>(ptr) + 2; #endif // DEBUGMAGICMALLOC @@ -2179,6 +2199,7 @@ #ifdef DEBUGDEBUGMALLOC --__libcwd_tsd.recursive; #endif + UNLOCK return ptr; } ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-13 03:44:02
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-13 03:44:02 UTC Modified files: libcwd/debugmalloc.cc Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.71 src/libcwd/debugmalloc.cc:1.72 --- src/libcwd/debugmalloc.cc:1.71 Sat Jan 12 19:14:05 2002 +++ src/libcwd/debugmalloc.cc Sat Jan 12 19:43:51 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.71 2002/01/13 03:14:05 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.72 2002/01/13 03:43:51 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -226,7 +226,7 @@ if (!std::__default_alloc_template<true, 0>::_S_node_allocator_lock._M_init_flag) std::__default_alloc_template<true, 0>::_S_node_allocator_lock._M_initialize(); #endif - return __gthread_mutex_trylock(&std::__default_alloc_template<true, 0>::_S_node_allocator_lock._M_lock); + return (__gthread_mutex_trylock(&std::__default_alloc_template<true, 0>::_S_node_allocator_lock._M_lock) == 0); } // The following unlocks the node allocator. @@ -2117,7 +2117,7 @@ bool locked = false; if (_private_::WST_multi_threaded) { - locked = _private_::allocator_trylock(false); // Fake a std::string (etc) lock. + locked = _private_::allocator_trylock(true); // Fake a std::string (etc) lock. if (!locked) core_dump(); } ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-13 04:00:37
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-13 04:00:36 UTC Modified files: libcwd/debugmalloc.cc Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.72 src/libcwd/debugmalloc.cc:1.73 --- src/libcwd/debugmalloc.cc:1.72 Sat Jan 12 19:43:51 2002 +++ src/libcwd/debugmalloc.cc Sat Jan 12 20:00:26 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.72 2002/01/13 03:43:51 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.73 2002/01/13 04:00:26 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -2116,11 +2116,7 @@ #if __GNUC__ >= 3 || __GNUC_MINOR__ >= 97 && defined(LIBCWD_THREAD_SAFE) bool locked = false; if (_private_::WST_multi_threaded) - { locked = _private_::allocator_trylock(true); // Fake a std::string (etc) lock. - if (!locked) - core_dump(); - } #endif LIBCWD_TSD_DECLARATION ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-19 05:09:06
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-19 05:09:04 UTC Modified files: libcwd/NEWS libcwd/acinclude.m4 libcwd/bfd.cc libcwd/debug.cc libcwd/debugmalloc.cc libcwd/documentation/tutorial/faq.m4 libcwd/include/cwd_debug.h libcwd/include/libcw/Makefile.am libcwd/include/libcw/class_channel_set.h libcwd/include/libcw/class_debug.h libcwd/include/libcw/class_debug.inl libcwd/include/libcw/class_debug_string.h libcwd/include/libcw/debug.h libcwd/include/libcw/macro_Libcwd_macros.h libcwd/include/libcw/private_TSD.h libcwd/include/libcw/private_threading.h libcwd/testsuite/libcwd.tst/continued.cc libcwd/testsuite/libcwd.tst/tst.exp libcwd/utils/exec_prog.cc Added files: libcwd/include/libcw/class_always_channel.h libcwd/include/libcw/class_always_channel.inl libcwd/include/libcw/struct_debug_tsd.h Log message: Part 1 of seperation of debug_ct into a thread specific part and a non-thread specific part. Compiles and works with --disable-libcwd-threading only. ---------------------- diff included ---------------------- Index: src/libcwd/NEWS diff -u src/libcwd/NEWS:1.64 src/libcwd/NEWS:1.65 --- src/libcwd/NEWS:1.64 Tue Jan 8 20:20:16 2002 +++ src/libcwd/NEWS Fri Jan 18 21:08:53 2002 @@ -57,6 +57,10 @@ with LIBCWD_ should NOT be used by the user, they are for internal use by libcwd. + debug_ct::get_os() has been removed. Use cwprint or cwprint_using. + Reason: the temporary stringstream that was returned was only valid + inside a Dout to begin with. The use of get_os() was dangerous. + Bug fixes: When using .stabs, each first line of code after a source file scope change Index: src/libcwd/acinclude.m4 diff -u src/libcwd/acinclude.m4:1.47 src/libcwd/acinclude.m4:1.48 --- src/libcwd/acinclude.m4:1.47 Fri Jan 11 18:54:42 2002 +++ src/libcwd/acinclude.m4 Fri Jan 18 21:08:54 2002 @@ -886,6 +886,7 @@ dnl Other options if test "$USE_MAINTAINER_MODE" = yes; then EXTRAOPTS="" +DEBUGOPTS="-ggdb3" else EXTRAOPTS="-O" fi Index: src/libcwd/bfd.cc diff -u src/libcwd/bfd.cc:1.92 src/libcwd/bfd.cc:1.93 --- src/libcwd/bfd.cc:1.92 Sat Jan 12 07:43:15 2002 +++ src/libcwd/bfd.cc Fri Jan 18 21:08:54 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.92 2002/01/12 15:43:15 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.93 2002/01/19 05:08:54 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -835,7 +835,9 @@ }; // cwbfd:: - typedef std::vector<my_link_map> ST_shared_libs_vector_ct; + // Not really necessary to use the `object_files' allocator here, but it + // is used inside that critical area anyway already, so why not. + typedef std::vector<my_link_map, _private_::object_files_allocator::rebind<my_link_map>::other> ST_shared_libs_vector_ct; ST_shared_libs_vector_ct ST_shared_libs; // Written to only in `ST_decode_ldd' which is called from // `cwbfd::ST_init' and read from in a later part of `cwbfd::ST_init'. Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.53 src/libcwd/debug.cc:1.54 --- src/libcwd/debug.cc:1.53 Fri Jan 11 18:54:42 2002 +++ src/libcwd/debug.cc Fri Jan 18 21:08:54 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.53 2002/01/12 02:54:42 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.54 2002/01/19 05:08:54 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -56,38 +56,6 @@ #define DEBUG_CHANNELS_ACQUIRE_WRITE2READ_LOCK #endif // !LIBCWD_THREAD_SAFE -// MULTI THREADING TODO -// -// libcw::debug::libcw_do - -// Global one-time initialization variables that are initialized before main(): -// libcw::debug::_private_::WST_dummy_laf -// libcw::debug::debug_ct::NS_init()::WST_very_first_time - -// Global variables that are initialized before threads are created and not written to afterwards. -// libcw::debug::(anonymous namespace)::WST_max_len -// libcw::debug::ST_initialize_globals()::ST_already_called -// libcw::debug::WST_debug_object_init_magic - -// Global objects that are handled. -// libcw::debug::_private_::debug_objects -// libcw::debug::_private_::debug_channels -// libcw::debug::channels::dc::core -// libcw::debug::channels::dc::debug -// libcw::debug::channels::dc::fatal -// libcw::debug::channels::dc::finish -// libcw::debug::channels::dc::malloc -// libcw::debug::channels::dc::notice -// libcw::debug::channels::dc::system -// libcw::debug::channels::dc::warning -// libcw::debug::channels::dc::continued - -// Static variable that is handled. -// libcw::debug::channel_ct::NS_initialize(char const*)::next_index - -// Global constants. -// __libcwd_version - namespace libcw { namespace debug { @@ -104,23 +72,36 @@ public: void writeto(std::ostream* os LIBCWD_COMMA_TSD_PARAM) { + char* buf; + bool used_malloc = false; int curlen = rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out) - rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); - for (char c = rdbuf()->sgetc(); --curlen >= 0; c = rdbuf()->snextc()) + if (curlen > 512 || !(buf = (char*)alloca(curlen))) { + set_alloc_checking_off(); + buf = (char*)malloc(curlen); + set_alloc_checking_on(); + used_malloc = true; + } + rdbuf()->sgetn(buf, curlen); #ifdef DEBUGMALLOC - // Writing to the final std::ostream (ie std::cerr) must be non-internal! - int saved_internal = __libcwd_tsd.internal; - __libcwd_tsd.internal = 0; - ++__libcwd_tsd.library_call; - ++libcw_do._off; + // Writing to the final std::ostream (ie std::cerr) must be non-internal! + int saved_internal = __libcwd_tsd.internal; + __libcwd_tsd.internal = 0; + ++__libcwd_tsd.library_call; + ++LIBCWD_DO_TSD_MEMBER(libcw_do, _off); #endif - os->put(c); + os->write(buf, curlen); #ifdef DEBUGMALLOC - --libcw_do._off; - --__libcwd_tsd.library_call; - __libcwd_tsd.internal = saved_internal; + --LIBCWD_DO_TSD_MEMBER(libcw_do, _off); + --__libcwd_tsd.library_call; + __libcwd_tsd.internal = saved_internal; #endif - } + if (used_malloc) + { + set_alloc_checking_off(); + free(buf); + set_alloc_checking_on(); + } } void store_position(void) { position = rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); @@ -210,6 +191,16 @@ #endif ; + /** A special channel that is always turned on. + * + * This channel is <EM>%always</EM> on; + * it can not be turned off. + * It is not in the list of debug channels. + * When used with a label it will print as many '>' + * characters as the size of the largest real channel. + */ + always_channel_ct always; + /** A special channel to continue to * write a previous %debug channel. * @@ -420,14 +411,11 @@ char const* label; // The previous label. - std::ostream* saved_os; - // The previous original ostream. - int err; // The current errno. public: - laf_ct(control_flag_t m, char const* l, std::ostream* os, int e) : mask(m), label(l), saved_os(os), err(e) { } + laf_ct(control_flag_t m, char const* l, int e) : mask(m), label(l), err(e) { } }; static inline void write_whitespace_to(std::ostream& os, unsigned int size) @@ -540,13 +528,13 @@ */ void debug_ct::push_margin(void) { - debug_string_stack_element_ct* current_margin_stack = M_margin_stack; LIBCWD_TSD_DECLARATION + debug_string_stack_element_ct* current_margin_stack = LIBCWD_TSD_MEMBER(M_margin_stack); set_alloc_checking_off(LIBCWD_TSD); void* new_debug_string = malloc(sizeof(debug_string_stack_element_ct)); - M_margin_stack = new (new_debug_string) debug_string_stack_element_ct(margin); + LIBCWD_TSD_MEMBER(M_margin_stack) = new (new_debug_string) debug_string_stack_element_ct(margin); set_alloc_checking_on(LIBCWD_TSD); - M_margin_stack->next = current_margin_stack; + LIBCWD_TSD_MEMBER(M_margin_stack)->next = current_margin_stack; } /** @@ -554,15 +542,15 @@ */ void debug_ct::pop_margin(void) { - if (!M_margin_stack) - DoutFatal(dc::core, "Calling `debug_ct::pop_margin' more often than `debug_ct::push_margin'."); - debug_string_stack_element_ct* next = M_margin_stack->next; LIBCWD_TSD_DECLARATION + if (!LIBCWD_TSD_MEMBER(M_margin_stack)) + DoutFatal(dc::core, "Calling `debug_ct::pop_margin' more often than `debug_ct::push_margin'."); + debug_string_stack_element_ct* next = LIBCWD_TSD_MEMBER(M_margin_stack)->next; set_alloc_checking_off(LIBCWD_TSD); - margin.internal_swallow(M_margin_stack->debug_string); - free(M_margin_stack); + margin.internal_swallow(LIBCWD_TSD_MEMBER(M_margin_stack)->debug_string); + free(LIBCWD_TSD_MEMBER(M_margin_stack)); set_alloc_checking_on(LIBCWD_TSD); - M_margin_stack = next; + LIBCWD_TSD_MEMBER(M_margin_stack) = next; } /** @@ -570,12 +558,12 @@ */ void debug_ct::push_marker(void) { - debug_string_stack_element_ct* current_marker_stack = M_marker_stack; LIBCWD_TSD_DECLARATION + debug_string_stack_element_ct* current_marker_stack = LIBCWD_TSD_MEMBER(M_marker_stack); set_alloc_checking_off(LIBCWD_TSD); void* new_debug_string = malloc(sizeof(debug_string_stack_element_ct)); - M_marker_stack = new (new_debug_string) debug_string_stack_element_ct(marker); - M_marker_stack->next = current_marker_stack; + LIBCWD_TSD_MEMBER(M_marker_stack) = new (new_debug_string) debug_string_stack_element_ct(marker); + LIBCWD_TSD_MEMBER(M_marker_stack)->next = current_marker_stack; } /** @@ -583,31 +571,29 @@ */ void debug_ct::pop_marker(void) { - if (!M_marker_stack) - DoutFatal(dc::core, "Calling `debug_ct::pop_marker' more often than `debug_ct::push_marker'."); - debug_string_stack_element_ct* next = M_marker_stack->next; LIBCWD_TSD_DECLARATION + if (!LIBCWD_TSD_MEMBER(M_marker_stack)) + DoutFatal(dc::core, "Calling `debug_ct::pop_marker' more often than `debug_ct::push_marker'."); + debug_string_stack_element_ct* next = LIBCWD_TSD_MEMBER(M_marker_stack)->next; set_alloc_checking_off(LIBCWD_TSD); - marker.internal_swallow(M_marker_stack->debug_string); - free(M_marker_stack); + marker.internal_swallow(LIBCWD_TSD_MEMBER(M_marker_stack)->debug_string); + free(LIBCWD_TSD_MEMBER(M_marker_stack)); set_alloc_checking_on(LIBCWD_TSD); - M_marker_stack = next; + LIBCWD_TSD_MEMBER(M_marker_stack) = next; } /** \} */ - void debug_ct::start(LIBCWD_TSD_PARAM) + void debug_tsd_st::start(debug_ct& debug_object, channel_set_data_st& channel_set LIBCWD_COMMA_TSD_PARAM) { - // It's possible we get here before this debug object is initialized: The order of calling global is undefined :(. - if (!WNS_initialized) // MT: When `WNS_initialized' is false, then `this' is not shared. - NS_init(); #ifdef DEBUGDEBUG - else if (init_magic != WST_debug_object_init_magic || !WST_debug_object_init_magic) - { - FATALDEBUGDEBUG_CERR( "Ack, fatal error in libcwd: `WNS_initialized' true while `init_magic' not set! " - "Please mail the author of libcwd." ); - core_dump(); - } +#ifdef LIBCWD_THREAD_SAFE + // Initialisation of the TSD part should be done from LIBCWD_TSD_DECLARATION inside Dout et al. + LIBCWD_ASSERT( tsd_initialized ); +#else + if (!tsd_initialized) + init(); +#endif #endif set_alloc_checking_off(LIBCWD_TSD); @@ -618,7 +604,8 @@ { if (!(current->mask & continued_expected_maskbit)) { - os->put('\n'); + std::ostream* target_os = (channel_set.mask & cerr_cf) ? &std::cerr : debug_object.real_os; + target_os->put('\n'); char const* channame = (channel_set.mask & finish_maskbit) ? "finish" : "continued"; #ifdef DEBUGUSEBFD DoutFatal(dc::core, "Using `dc::" << channame << "' in " << @@ -633,7 +620,7 @@ // MT: current != _private_::WST_dummy_laf, otherwise we didn't pass the previous if. LIBCWD_ASSERT( current != reinterpret_cast<laf_ct*>(_private_::WST_dummy_laf) ); #endif - current->mask = channel_set.mask; // New bits might have been added + current->mask = channel_set.mask; // New bits might have been added if ((current->mask & finish_maskbit)) current->mask &= ~continued_expected_maskbit; current->err = errno; // Always keep the last errno as set at the start of LibcwDout() @@ -652,21 +639,15 @@ LIBCWD_ASSERT( current != reinterpret_cast<laf_ct*>(_private_::WST_dummy_laf) ); #endif // Write out what is in the buffer till now. - current->oss.writeto(os LIBCWD_COMMA_TSD); + std::ostream* target_os = (channel_set.mask & cerr_cf) ? &std::cerr : debug_object.real_os; + static_cast<buffer_ct*>(current_oss)->writeto(target_os LIBCWD_COMMA_TSD); // Append <unfinished> to it. - os->write("<unfinished>\n", 13); // Continued debug output should end on a space by itself, + target_os->write("<unfinished>\n", 13); // Continued debug output should end on a space by itself, // Truncate the buffer to its prefix and append "<continued>" to it already. - current->oss.restore_position(); - current->oss.write("<continued> ", 12); // therefore we repeat the space here. + static_cast<buffer_ct*>(current_oss)->restore_position(); + static_cast<buffer_ct*>(current_oss)->write("<continued> ", 12); // therefore we repeat the space here. } - // By putting this here instead of in finish(), all nested debug output will go to std::cerr too. - if ((channel_set.mask & cerr_cf)) - { - saved_os = os; - os = &std::cerr; - } - // Is this a nested debug output (the first of a series in the middle of another debug output)? // MT: if current == _private_::WST_dummy_laf then // start_expected is true and this if is skipped. @@ -677,50 +658,54 @@ // Indent nested debug output with 4 extra spaces. indent += 4; - } - // Without a new nested Dout() call, we expect to see a finish() call: The finish belonging to *this* Dout() call. - start_expected = false; // MT: FIXME: NEEDS LOCK till current is changed (maybe more). - - // If this is a `continued' debug output, then we want to print "<unfinished>" if next we see a start(). - unfinished_expected = true; + // If the previous target was written to cerr, then + // write this interrupting output to cerr too. + channel_set.mask |= (current->mask & cerr_cf); + } // Create a new laf. DEBUGDEBUG_CERR( "creating new laf_ct" ); - current = new laf_ct(channel_set.mask, channel_set.label, saved_os, errno); + current = new laf_ct(channel_set.mask, channel_set.label, errno); DEBUGDEBUG_CERR( "current = " << (void*)current ); current_oss = ¤t->oss; DEBUGDEBUG_CERR( "current_oss = " << (void*)current_oss ); DEBUGDEBUG_CERR( "laf_ct created" ); + // Without a new nested Dout() call, we expect to see a finish() call: The finish belonging to *this* Dout() call. + start_expected = false; + + // If this is a `continued' debug output, then we want to print "<unfinished>" if next we see a start(). + unfinished_expected = true; + // Print prefix if requested. // Handle most common case first: no special flags set if (!(channel_set.mask & (noprefix_cf|nolabel_cf|blank_margin_cf|blank_label_cf|blank_marker_cf))) { - current->oss.write(margin.c_str(), margin.size()); - current->oss.write(channel_set.label, WST_max_len); - current->oss.write(marker.c_str(), marker.size()); - write_whitespace_to(current->oss, indent); + static_cast<buffer_ct*>(current_oss)->write(debug_object.margin.c_str(), debug_object.margin.size()); + static_cast<buffer_ct*>(current_oss)->write(channel_set.label, WST_max_len); + static_cast<buffer_ct*>(current_oss)->write(debug_object.marker.c_str(), debug_object.marker.size()); + write_whitespace_to(*current_oss, indent); } else if (!(channel_set.mask & noprefix_cf)) { if ((channel_set.mask & blank_margin_cf)) - write_whitespace_to(current->oss, margin.size()); + write_whitespace_to(*current_oss, debug_object.margin.size()); else - current->oss.write(margin.c_str(), margin.size()); + static_cast<buffer_ct*>(current_oss)->write(debug_object.margin.c_str(), debug_object.margin.size()); #ifndef DEBUGDEBUGOUTPUT if (!(channel_set.mask & nolabel_cf)) #endif { if ((channel_set.mask & blank_label_cf)) - write_whitespace_to(current->oss, WST_max_len); + write_whitespace_to(*current_oss, WST_max_len); else - current->oss.write(channel_set.label, WST_max_len); + static_cast<buffer_ct*>(current_oss)->write(channel_set.label, WST_max_len); if ((channel_set.mask & blank_marker_cf)) - write_whitespace_to(current->oss, marker.size()); + write_whitespace_to(*current_oss, debug_object.marker.size()); else - current->oss.write(marker.c_str(), marker.size()); - write_whitespace_to(current->oss, indent); + static_cast<buffer_ct*>(current_oss)->write(debug_object.marker.c_str(), debug_object.marker.size()); + write_whitespace_to(*current_oss, indent); } } @@ -728,18 +713,19 @@ { // If this is continued debug output, then it makes sense to remember the prefix length, // just in case we need indeed to output <continued> data. - current->oss.store_position(); + static_cast<buffer_ct*>(current_oss)->store_position(); } --_off; DEBUGDEBUG_CERR( "Leaving debug_ct::start(), _off became " << _off ); } - void debug_ct::finish(LIBCWD_TSD_PARAM) + void debug_tsd_st::finish(debug_ct& debug_object, channel_set_data_st& channel_set LIBCWD_COMMA_TSD_PARAM) { #ifdef DEBUGDEBUG LIBCWD_ASSERT( current != reinterpret_cast<laf_ct*>(_private_::WST_dummy_laf) ); #endif + std::ostream* target_os = (current->mask & cerr_cf) ? &std::cerr : debug_object.real_os; // Skip `finish()' for a `continued' debug output. if ((current->mask & continued_cf_maskbit) && !(current->mask & finish_maskbit)) @@ -752,11 +738,11 @@ if ((current->mask & flush_cf)) { // Write buffer to ostream. - current->oss.writeto(os LIBCWD_COMMA_TSD); + static_cast<buffer_ct*>(current_oss)->writeto(target_os LIBCWD_COMMA_TSD); // Flush ostream. Note that in the case of nested debug output this `os' can be an stringstream, // in that case, no actual flushing is done until the debug output to the real ostream has // finished. - *os << std::flush; + *target_os << std::flush; } set_alloc_checking_on(LIBCWD_TSD); return; @@ -766,24 +752,23 @@ DEBUGDEBUG_CERR( "Entering debug_ct::finish(), _off became " << _off ); // Write buffer to ostream. - current->oss.writeto(os LIBCWD_COMMA_TSD); + static_cast<buffer_ct*>(current_oss)->writeto(target_os LIBCWD_COMMA_TSD); channel_set.mask = current->mask; channel_set.label = current->label; - saved_os = current->saved_os; // Handle control flags, if any: if (channel_set.mask == 0) - os->put('\n'); + target_os->put('\n'); else { if ((channel_set.mask & error_cf)) - *os << ": " << strerrno(current->err) << " (" << strerror(current->err) << ')'; + *target_os << ": " << strerrno(current->err) << " (" << strerror(current->err) << ')'; if ((channel_set.mask & coredump_maskbit)) { if (!__libcwd_tsd.recursive_fatal) { __libcwd_tsd.recursive_fatal = true; - *os << std::endl; // First time, try to write a new-line and flush. + *target_os << std::endl; // First time, try to write a new-line and flush. } core_dump(); } @@ -792,7 +777,7 @@ if (!__libcwd_tsd.recursive_fatal) { __libcwd_tsd.recursive_fatal = true; - *os << std::endl; + *target_os << std::endl; } DEBUGDEBUG_CERR( "Deleting `current' " << (void*)current ); delete current; @@ -802,19 +787,17 @@ } if ((channel_set.mask & wait_cf)) { - *os << "\n(type return)"; - if (interactive) + *target_os << "\n(type return)"; + if (debug_object.interactive) { - *os << std::flush; + *target_os << std::flush; while(std::cin.get() != '\n'); } } if (!(channel_set.mask & nonewline_cf)) - *os << '\n'; + *target_os << '\n'; if ((channel_set.mask & flush_cf)) - *os << std::flush; - if ((channel_set.mask & cerr_cf)) - os = saved_os; + *target_os << std::flush; } DEBUGDEBUG_CERR( "Deleting `current' " << (void*)current ); @@ -841,9 +824,8 @@ else { current = reinterpret_cast<laf_ct*>(_private_::WST_dummy_laf); // Used (MT: read-only!) in next debug_ct::start(). - // MT: FIXME: NEEDS LOCK till start_expected is set (maybe more). DEBUGDEBUG_CERR( "current = " << (void*)current ); - current_oss = ¤t->oss; // Used when errornous using dc::continued next. + current_oss = target_os; // Used in start. DEBUGDEBUG_CERR( "current_oss = " << (void*)current_oss ); } @@ -856,12 +838,29 @@ set_alloc_checking_on(LIBCWD_TSD); } - void debug_ct::fatal_finish(LIBCWD_TSD_PARAM) + void debug_tsd_st::fatal_finish(debug_ct& debug_object, channel_set_data_st& channel_set LIBCWD_COMMA_TSD_PARAM) { - finish(LIBCWD_TSD); + finish(debug_object, channel_set LIBCWD_COMMA_TSD); DoutFatal( dc::core, "Don't use `DoutFatal' together with `continued_cf', use `Dout' instead. (This message can also occur when using DoutFatal correctly but from the constructor of a global object)." ); } + /** + * \brief Set output device. + * \ingroup group_destination + * + * Assign a new \c ostream to this %debug object (default is <CODE>std::cerr</CODE>). + */ + void debug_ct::set_ostream(std::ostream* os) + { + LIBCWD_TSD_DECLARATION +#ifdef DEBUGDEBUG + LIBCWD_ASSERT( LIBCWD_TSD_MEMBER(tsd_initialized) ); +#endif + real_os = os; + if (LIBCWD_TSD_MEMBER(laf_stack).size() == 0) + LIBCWD_TSD_MEMBER(current_oss) = real_os; + } + void debug_ct::NS_init(void) { ST_initialize_globals(); // Because all allocations for global objects are internal these days, we use @@ -871,8 +870,13 @@ if (WNS_initialized) return; - _off = 0; // Turn off all debugging until initialization is completed. - DEBUGDEBUG_CERR( "In debug_ct::NS_init(void), _off set to 0" ); +#ifdef DEBUGDEBUG + if (!WST_debug_object_init_magic) + init_debug_object_init_magic(); + init_magic = WST_debug_object_init_magic; + DEBUGDEBUG_CERR( "Set init_magic to " << init_magic ); + DEBUGDEBUG_CERR( "Setting WNS_initialized to true" ); +#endif LIBCWD_TSD_DECLARATION set_alloc_checking_off(LIBCWD_TSD); // debug_objects is internal. @@ -883,13 +887,51 @@ == _private_::debug_objects.write_locked().end()) // Not added before? _private_::debug_objects.write_locked().push_back(this); DEBUG_OBJECTS_RELEASE_WRITE_LOCK + new (_private_::WST_dummy_laf) laf_ct(0, channels::dc::debug.get_label(), 0); // Leaks 24 bytes of memory +#ifndef LIBCWD_THREAD_SAFE + tsd.init(); +#endif + margin.NS_internal_init("", 0); + marker.NS_internal_init(": ", 2); set_alloc_checking_on(LIBCWD_TSD); - // Initialize this debug object: + // This set current_oss and must be called after tsd.init(). set_ostream(&std::cerr); // Write to std::cerr by default. interactive = true; // and thus we're interactive. + + WNS_initialized = true; + + // Unlimit core size. +#ifdef RLIMIT_CORE + struct rlimit corelim; + if (getrlimit(RLIMIT_CORE, &corelim)) + DoutFatal(dc::fatal|error_cf, "getrlimit(RLIMIT_CORE, &corelim)"); + corelim.rlim_cur = corelim.rlim_max; + if (corelim.rlim_max != RLIM_INFINITY) + { + OnOffState state; + force_on(state); + // The cast is necessary on platforms where corelim.rlim_max is long long + // and libstdc++ was not compiled with support for long long. + Dout(dc::warning, "core size is limited (hard limit: " << (unsigned long)(corelim.rlim_max / 1024) << " kb). Core dumps might be truncated!"); + restore(state); + } + if (setrlimit(RLIMIT_CORE, &corelim)) + DoutFatal(dc::fatal|error_cf, "unlimit core size failed"); +#else + OnOffState state; + force_on(state); + Dout(dc::warning, "Please unlimit core size manually"); + restore(state); +#endif + } + + void debug_tsd_st::init(void) + { + _off = 0; // Turn off all debugging until initialization is completed. + DEBUGDEBUG_CERR( "In debug_tsd_st::NS_init(void), _off set to 0" ); + start_expected = true; // Of course, we start with expecting the beginning of a debug output. - continued_channel_set.debug_object = this; // The owner of this continued_channel_set. // Fatal channels need to be marked fatal, otherwise we get into an endless loop // when they are used before they are created. channels::dc::core.NS_initialize("COREDUMP", coredump_maskbit); @@ -908,14 +950,10 @@ channels::dc::system.NS_initialize("SYSTEM"); // `current' needs to be non-zero (saving us a check in start()) and // current.mask needs to be 0 to avoid a crash in start(): - set_alloc_checking_off(LIBCWD_TSD); - current = new (_private_::WST_dummy_laf) laf_ct(0, channels::dc::debug.get_label(), NULL, 0); // Leaks 24 bytes of memory + current = reinterpret_cast<laf_ct*>(_private_::WST_dummy_laf); DEBUGDEBUG_CERR( "current = " << (void*)current ); current_oss = ¤t->oss; DEBUGDEBUG_CERR( "current_oss = " << (void*)current_oss ); - margin.NS_internal_init("", 0); - marker.NS_internal_init(": ", 2); - set_alloc_checking_on(LIBCWD_TSD); laf_stack.init(); continued_stack.init(); @@ -926,46 +964,29 @@ _off = 0; // Don't print debug output till the REAL initialization of the debug system has been performed // (ie, the _application_ start (don't confuse that with the constructor - which does nothing)). #endif - DEBUGDEBUG_CERR( "After debug_ct::NS_init(void), _off set to " << _off ); + DEBUGDEBUG_CERR( "After debug_tsd_st::NS_init(void), _off set to " << _off ); + tsd_initialized = true; + } -#ifdef DEBUGDEBUG - if (!WST_debug_object_init_magic) - init_debug_object_init_magic(); - init_magic = WST_debug_object_init_magic; - DEBUGDEBUG_CERR( "Set init_magic to " << init_magic ); - DEBUGDEBUG_CERR( "Setting WNS_initialized to true" ); -#endif - WNS_initialized = true; + debug_tsd_st::~debug_tsd_st() + { + // Sanity checks: + if (continued_stack.size()) + DoutFatal( dc::core|cerr_cf, "Destructing debug_tsd_st with a non-empty continued_stack (missing dc::finish?)" ); + if (laf_stack.size()) + DoutFatal( dc::core|cerr_cf, "Destructing debug_tsd_st with a non-empty laf_stack" ); - // We want to do the following only once per application. - static bool WST_very_first_time = true; - if (WST_very_first_time) - { - WST_very_first_time = false; - // Unlimit core size. -#ifdef RLIMIT_CORE - struct rlimit corelim; - if (getrlimit(RLIMIT_CORE, &corelim)) - DoutFatal(dc::fatal|error_cf, "getrlimit(RLIMIT_CORE, &corelim)"); - corelim.rlim_cur = corelim.rlim_max; - if (corelim.rlim_max != RLIM_INFINITY) - { - OnOffState state; - force_on(state); - // The cast is necessary on platforms where corelim.rlim_max is long long - // and libstdc++ was not compiled with support for long long. - Dout(dc::warning, "core size is limited (hard limit: " << (unsigned long)(corelim.rlim_max / 1024) << " kb). Core dumps might be truncated!"); - restore(state); - } - if (setrlimit(RLIMIT_CORE, &corelim)) - DoutFatal(dc::fatal|error_cf, "unlimit core size failed"); -#else - OnOffState state; - force_on(state); - Dout(dc::warning, "Please unlimit core size manually"); - restore(state); + ++_off; // Turn all debug output premanently off, otherwise we might re-initialize + // this object again when we try to write debug output to it! + DEBUGDEBUG_CERR( "debug_tsd_st destructed: _off became " << _off ); +#ifdef LIBCWD_THREAD_SAFE + LIBCWD_TSD_DECLARATION + set_alloc_checking_off(LIBCWD_TSD); + marker.ST_internal_deinit(); + margin.ST_internal_deinit(); + set_alloc_checking_on(LIBCWD_TSD); #endif - } + tsd_initialized = false; } /** @@ -973,23 +994,16 @@ */ debug_ct::~debug_ct() { - // Sanity checks: - if (continued_stack.size()) - DoutFatal( dc::core|cerr_cf, "Destructing debug_ct with a non-empty continued_stack" ); - if (laf_stack.size()) - DoutFatal( dc::core|cerr_cf, "Destructing debug_ct with a non-empty laf_stack" ); - - ++_off; // Turn all debug output premanently off, otherwise we might re-initialize - // this object again when we try to write debug output to it! - DEBUGDEBUG_CERR( "debug_ct destructed: _off became " << _off ); WNS_initialized = false; #ifdef DEBUGDEBUG init_magic = 0; #endif LIBCWD_TSD_DECLARATION set_alloc_checking_off(LIBCWD_TSD); +#ifndef LIBCWD_THREAD_SAFE marker.ST_internal_deinit(); margin.ST_internal_deinit(); +#endif DEBUG_OBJECTS_ACQUIRE_WRITE_LOCK { _private_::debug_objects_ct::container_type& objects(_private_::debug_objects.write_locked()); @@ -1055,18 +1069,23 @@ * * Where FOO and BAR are \link preparation user defined channels \endlink in this example. */ - void list_channels_on(debug_ct const& debug_object) + void list_channels_on(debug_ct& debug_object) { - if (debug_object._off < 0) + LIBCWD_TSD_DECLARATION + if (LIBCWD_DO_TSD_MEMBER(debug_object, _off) < 0) { _private_::debug_channels.init(); DEBUG_CHANNELS_ACQUIRE_READ_LOCK for(_private_::debug_channels_ct::container_type::const_iterator i(_private_::debug_channels.read_locked().begin()); i != _private_::debug_channels.read_locked().end(); ++i) { - char const* txt = (*i)->is_on() ? ": Enabled" : ": Disabled"; - debug_object.get_os().write((*i)->get_label(), WST_max_len); - debug_object.get_os() << txt << '\n'; + LibcwDoutScopeBegin(DEBUGCHANNELS, debug_object, dc::always|noprefix_cf); + LibcwDoutStream.write((*i)->get_label(), WST_max_len); + if ((*i)->is_on()) + LibcwDoutStream.write(": Enabled", 9); + else + LibcwDoutStream.write(": Disabled", 10); + LibcwDoutScopeEnd; } DEBUG_CHANNELS_RELEASE_READ_LOCK } @@ -1192,6 +1211,8 @@ WNS_maskbit = maskbit; } + char const always_channel_ct::label[max_label_len_c] = { '>', '>', '>', '>', '>', '>', '>', '>', '>', '>', '>', '>', '>', '>', '>', '>' }; + /** * \brief Turn this channel off. * @@ -1236,7 +1257,7 @@ { #ifdef DEBUGDEBUG DEBUGDEBUG_CERR( "continued_cf detected" ); - if (!debug_object || !debug_object->WNS_initialized) + if (!do_tsd_ptr || !do_tsd_ptr->tsd_initialized) { FATALDEBUGDEBUG_CERR( "Don't use DoutFatal together with continued_cf, use Dout instead." ); core_dump(); @@ -1245,20 +1266,20 @@ mask |= continued_cf_maskbit; if (!on) { - ++(debug_object->off_count); - DEBUGDEBUG_CERR( "Channel is switched off. Increased off_count to " << debug_object->off_count ); + ++(do_tsd_ptr->off_count); + DEBUGDEBUG_CERR( "Channel is switched off. Increased off_count to " << do_tsd_ptr->off_count ); } else { - debug_object->continued_stack.push(debug_object->off_count); - DEBUGDEBUG_CERR( "Channel is switched on. Pushed off_count (" << debug_object->off_count << ") to stack (size now " << - debug_object->continued_stack.size() << ") and set off_count to 0" ); - debug_object->off_count = 0; + do_tsd_ptr->continued_stack.push(do_tsd_ptr->off_count); + DEBUGDEBUG_CERR( "Channel is switched on. Pushed off_count (" << do_tsd_ptr->off_count << ") to stack (size now " << + do_tsd_ptr->continued_stack.size() << ") and set off_count to 0" ); + do_tsd_ptr->off_count = 0; } return *(reinterpret_cast<continued_channel_set_st*>(this)); } - continued_channel_set_st& debug_ct::operator|(continued_channel_ct const& cdc) + continued_channel_set_st& channel_set_bootstrap_st::operator|(continued_channel_ct const& cdc) { #ifdef DEBUGDEBUG if ((cdc.get_maskbit() & continued_maskbit)) @@ -1267,32 +1288,32 @@ DEBUGDEBUG_CERR( "dc::finish detected" ); #endif - if ((continued_channel_set.on = !off_count)) + if ((on = !do_tsd_ptr->off_count)) { DEBUGDEBUG_CERR( "Channel is switched on (off_count is 0)" ); - current->mask |= cdc.get_maskbit(); // We continue with the current channel - continued_channel_set.mask = current->mask; - continued_channel_set.label = current->label; + do_tsd_ptr->current->mask |= cdc.get_maskbit(); // We continue with the current channel + mask = do_tsd_ptr->current->mask; + label = do_tsd_ptr->current->label; if (cdc.get_maskbit() == finish_maskbit) { - off_count = continued_stack.top(); - continued_stack.pop(); - DEBUGDEBUG_CERR( "Restoring off_count to " << off_count << ". Stack size now " << continued_stack.size() ); + do_tsd_ptr->off_count = do_tsd_ptr->continued_stack.top(); + do_tsd_ptr->continued_stack.pop(); + DEBUGDEBUG_CERR( "Restoring off_count to " << do_tsd_ptr->off_count << ". Stack size now " << do_tsd_ptr->continued_stack.size() ); } } else { - DEBUGDEBUG_CERR( "Channel is switched off (off_count is " << off_count << ')' ); + DEBUGDEBUG_CERR( "Channel is switched off (off_count is " << do_tsd_ptr->off_count << ')' ); if (cdc.get_maskbit() == finish_maskbit) { DEBUGDEBUG_CERR( "` decrementing off_count with 1" ); - --off_count; + --(do_tsd_ptr->off_count); } } - return continued_channel_set; + return *reinterpret_cast<continued_channel_set_st*>(this); } - channel_set_st& debug_ct::operator|(fatal_channel_ct const&) + channel_set_st& channel_set_bootstrap_st::operator|(fatal_channel_ct const&) { #ifdef DEBUGUSEBFD DoutFatal(dc::fatal, location_ct((char*)__builtin_return_address(0) + libcw::debug::builtin_return_address_offset) << @@ -1303,7 +1324,7 @@ #endif } - channel_set_st& debug_ct::operator&(channel_ct const&) + channel_set_st& channel_set_bootstrap_st::operator&(channel_ct const&) { #ifdef DEBUGUSEBFD DoutFatal(dc::fatal, location_ct((char*)__builtin_return_address(0) + libcw::debug::builtin_return_address_offset) << @@ -1336,22 +1357,23 @@ void debug_ct::force_on(debug_ct::OnOffState& state) { NS_init(); - state._off = _off; + LIBCWD_TSD_DECLARATION + state._off = LIBCWD_TSD_MEMBER(_off); #ifdef DEBUGDEBUGOUTPUT - state.first_time = first_time; + state.first_time = LIBCWD_TSD_MEMBER(first_time); #endif - _off = -1; // Turn object on. + LIBCWD_TSD_MEMBER(_off) = -1; // Turn object on. } void debug_ct::restore(debug_ct::OnOffState const& state) { #ifdef DEBUGDEBUGOUTPUT - if (state.first_time != first_time) // state.first_time && !first_time. - core_dump(); // on() was called without first a call to off(). + if (state.first_time != LIBCWD_TSD_MEMBER(first_time)) // state.first_time && !first_time. + core_dump(); // on() was called without first a call to off(). #endif - if (_off != -1) - core_dump(); // off() and on() where called and not in equal pairs. - _off = state._off; // Restore. + if (LIBCWD_TSD_MEMBER(_off) != -1) + core_dump(); // off() and on() where called and not in equal pairs. + LIBCWD_TSD_MEMBER(_off) = state._off; // Restore. } void channel_ct::force_on(channel_ct::OnOffState& state, char const* label) Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.73 src/libcwd/debugmalloc.cc:1.74 --- src/libcwd/debugmalloc.cc:1.73 Sat Jan 12 20:00:26 2002 +++ src/libcwd/debugmalloc.cc Fri Jan 18 21:08:54 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.73 2002/01/13 04:00:26 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.74 2002/01/19 05:08:54 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -285,58 +285,61 @@ #define DEBUGDEBUG_ELSE_DoutFatalInternal(data) #endif -#define DoutInternal( cntrl, data ) \ - do \ - { \ - DEBUGDEBUG_DoutInternal_MARKER; \ - if (__libcwd_tsd.library_call == 0 && libcw_do._off < 0) \ - { \ - DEBUGDEBUG_CERR( "Entering 'DoutInternal(cntrl, \"" << data << "\")'. internal == " << __libcwd_tsd.internal << '.' ); \ - bool on; \ - { \ - using namespace channels; \ - on = (libcw_do|cntrl).on; \ - } \ - if (on) \ - { \ - libcw_do.start(LIBCWD_TSD); \ - ++libcw_do._off; \ - _private_::no_alloc_ostream_ct no_alloc_ostream(*libcw_do.current_oss); \ - no_alloc_ostream << data; \ - --libcw_do._off; \ - libcw_do.finish(LIBCWD_TSD); \ - } \ - DEBUGDEBUG_CERR( "Leaving 'DoutInternal(cntrl, \"" << data << "\")'. internal = " << __libcwd_tsd.internal << '.' ); \ - } \ - DEBUGDEBUG_ELSE_DoutInternal(data) \ +#define DoutInternal( cntrl, data ) \ + do \ + { \ + DEBUGDEBUG_DoutInternal_MARKER; \ + if (__libcwd_tsd.library_call == 0 && LIBCWD_DO_TSD_MEMBER(libcw_do, _off) < 0) \ + { \ + DEBUGDEBUG_CERR( "Entering 'DoutInternal(cntrl, \"" << data << "\")'. internal == " << __libcwd_tsd.internal << '.' ); \ + channel_set_bootstrap_st channel_set(LIBCWD_DO_TSD(libcw_do) LIBCWD_COMMA_TSD); \ + bool on; \ + { \ + using namespace channels; \ + on = (channel_set|cntrl).on; \ + } \ + if (on) \ + { \ + LIBCWD_DO_TSD(libcw_do).start(libcw_do, channel_set LIBCWD_COMMA_TSD); \ + ++ LIBCWD_DO_TSD_MEMBER(libcw_do, _off); \ + _private_::no_alloc_ostream_ct no_alloc_ostream(*LIBCWD_DO_TSD_MEMBER(libcw_do, current_oss)); \ + no_alloc_ostream << data; \ + -- LIBCWD_DO_TSD_MEMBER(libcw_do, _off); \ + LIBCWD_DO_TSD(libcw_do).finish(libcw_do, channel_set LIBCWD_COMMA_TSD); \ + } \ + DEBUGDEBUG_CERR( "Leaving 'DoutInternal(cntrl, \"" << data << "\")'. internal = " << __libcwd_tsd.internal << '.' ); \ + } \ + DEBUGDEBUG_ELSE_DoutInternal(data) \ } while(0) -#define DoutFatalInternal( cntrl, data ) \ - do \ - { \ - DEBUGDEBUG_DoutFatalInternal_MARKER; \ - if (__libcwd_tsd.library_call < 2) \ - { \ - DEBUGDEBUG_CERR( "Entering 'DoutFatalInternal(cntrl, \"" << data << "\")'. internal == " << __libcwd_tsd.internal << "; setting internal to 0." ); \ - __libcwd_tsd.internal = 0; \ - { \ - using namespace channels; \ - libcw_do&cntrl; \ - } \ - libcw_do.start(LIBCWD_TSD); \ - ++libcw_do._off; \ - _private_::no_alloc_ostream_ct no_alloc_ostream(*libcw_do.current_oss); \ - no_alloc_ostream << data; \ - --libcw_do._off; \ - libcw_do.fatal_finish(LIBCWD_TSD); /* Never returns */ \ - LIBCWD_ASSERT( !"Bug in libcwd!" ); \ - } \ - else \ - { \ - DEBUGDEBUG_ELSE_DoutFatalInternal(data) \ - LIBCWD_ASSERT( !"See msg above." ); \ - core_dump(); \ - } \ +#define DoutFatalInternal( cntrl, data ) \ + do \ + { \ + DEBUGDEBUG_DoutFatalInternal_MARKER; \ + if (__libcwd_tsd.library_call < 2) \ + { \ + DEBUGDEBUG_CERR( "Entering 'DoutFatalInternal(cntrl, \"" << data << "\")'. internal == " << \ + __libcwd_tsd.internal << "; setting internal to 0." ); \ + __libcwd_tsd.internal = 0; \ + channel_set_bootstrap_st channel_set(LIBCWD_DO_TSD(libcw_do) LIBCWD_COMMA_TSD); \ + { \ + using namespace channels; \ + channel_set&cntrl; \ + } \ + LIBCWD_DO_TSD(libcw_do).start(libcw_do, channel_set LIBCWD_COMMA_TSD); \ + ++ LIBCWD_DO_TSD_MEMBER(libcw_do, _off); \ + _private_::no_alloc_ostream_ct no_alloc_ostream(*LIBCWD_DO_TSD_MEMBER(libcw_do, current_oss)); \ + no_alloc_ostream << data; \ + -- LIBCWD_DO_TSD_MEMBER(libcw_do, _off); \ + LIBCWD_DO_TSD(libcw_do).fatal_finish(libcw_do, channel_set LIBCWD_COMMA_TSD); /* Never returns */ \ + LIBCWD_ASSERT( !"Bug in libcwd!" ); \ + } \ + else \ + { \ + DEBUGDEBUG_ELSE_DoutFatalInternal(data) \ + LIBCWD_ASSERT( !"See msg above." ); \ + core_dump(); \ + } \ } while(0) namespace libcw { @@ -399,11 +402,9 @@ // _private_:: bool inside_ios_base_Init_Init(void) // Single Threaded function. { + LIBCWD_TSD_DECLARATION #ifdef DEBUGDEBUGMALLOC - { - LIBCWD_TSD_DECLARATION - LIBCWD_ASSERT( __libcwd_tsd.internal == 0 ); - } + LIBCWD_ASSERT( __libcwd_tsd.internal == 0 ); #endif #ifndef _GLIBCPP_USE_WCHAR_T if (std::cerr.flags() != std::ios_base::unitbuf) // Still didn't reach the end of std::ios_base::Init::Init()? @@ -412,9 +413,9 @@ #endif return true; WST_ios_base_initialized = true; - ++libcw_do._off; + ++LIBCWD_DO_TSD_MEMBER(libcw_do, _off); make_all_allocations_invisible_except(NULL); // Get rid of the <pre ios initialization> allocation list. - --libcw_do._off; + --LIBCWD_DO_TSD_MEMBER(libcw_do, _off); DEBUGDEBUG_CERR( "Standard streams initialized." ); return false; } @@ -1201,7 +1202,7 @@ if (WST_initialization_state <= 0) // Only true prior to initialization of std::ios_base::Init. { #ifdef DEBUGDEBUG - bool continued_debug_output = (__libcwd_tsd.library_call == 0 && libcw_do._off < 0); + bool continued_debug_output = (__libcwd_tsd.library_call == 0 && LIBCWD_DO_TSD_MEMBER(libcw_do, _off) < 0); #endif init_debugmalloc(); #ifdef DEBUGDEBUG @@ -1209,7 +1210,7 @@ // and thus no unfinished debug output was printed before entering this function. // Initialization of libcwd with DEBUGDEBUG defined turns on libcwd_do. In order to balance the // continued stack, we print an unfinished debug message here. - if (continued_debug_output != (__libcwd_tsd.library_call == 0 && libcw_do._off < 0)) + if (continued_debug_output != (__libcwd_tsd.library_call == 0 && LIBCWD_DO_TSD_MEMBER(libcw_do, _off) < 0)) DoutInternal( dc_malloc|continued_cf, "internal_malloc(" << size << ", " << flag << ") = " ); #endif } @@ -1232,10 +1233,10 @@ #ifdef DEBUGUSEBFD if (__libcwd_tsd.library_call++) - ++libcw_do._off; // Otherwise debug output will be generated from bfd.cc (location_ct) + ++LIBCWD_DO_TSD_MEMBER(libcw_do, _off); // Otherwise debug output will be generated from bfd.cc (location_ct) location_ct loc(call_addr LIBCWD_COMMA_TSD); if (--__libcwd_tsd.library_call) - --libcw_do._off; + --LIBCWD_DO_TSD_MEMBER(libcw_do, _off); #endif DEBUGDEBUG_CERR( "internal_malloc: internal == " << __libcwd_tsd.internal << "; setting it to 1." ); @@ -2105,7 +2106,7 @@ // malloc(3) and calloc(3) replacements: // -#if __GNUC__ >= 3 || __GNUC_MINOR__ >= 97 && defined(LIBCWD_THREAD_SAFE) +#if (__GNUC__ >= 3 || __GNUC_MINOR__ >= 97) && defined(LIBCWD_THREAD_SAFE) && defined(DEBUGDEBUG) #define UNLOCK if (locked) _private_::allocator_unlock(); #else #define UNLOCK @@ -2113,7 +2114,7 @@ void* __libcwd_malloc(size_t size) { -#if __GNUC__ >= 3 || __GNUC_MINOR__ >= 97 && defined(LIBCWD_THREAD_SAFE) +#if (__GNUC__ >= 3 || __GNUC_MINOR__ >= 97) && defined(LIBCWD_THREAD_SAFE) && defined(DEBUGDEBUG) bool locked = false; if (_private_::WST_multi_threaded) locked = _private_::allocator_trylock(true); // Fake a std::string (etc) lock. @@ -2458,10 +2459,10 @@ #ifdef DEBUGUSEBFD if (__libcwd_tsd.library_call++) - libcw_do._off++; // Otherwise debug output will be generated from bfd.cc (location_ct) + ++LIBCWD_DO_TSD_MEMBER(libcw_do, _off); // Otherwise debug output will be generated from bfd.cc (location_ct) location_ct loc(reinterpret_cast<char*>(__builtin_return_address(0)) + builtin_return_address_offset LIBCWD_COMMA_TSD); if (--__libcwd_tsd.library_call) - libcw_do._off--; + --LIBCWD_DO_TSD_MEMBER(libcw_do, _off); #endif // Update administration Index: src/libcwd/documentation/tutorial/faq.m4 diff -u src/libcwd/documentation/tutorial/faq.m4:1.2 src/libcwd/documentation/tutorial/faq.m4:1.3 --- src/libcwd/documentation/tutorial/faq.m4:1.2 Sat Dec 29 20:17:49 2001 +++ src/libcwd/documentation/tutorial/faq.m4 Fri Jan 18 21:08:54 2002 @@ -346,7 +346,7 @@ <H3>20. What is the maximum length of a label?</H3> <P>The maximum length of the label of a new Debug Channel is given -by the constant<SPAN class="code"> libcw::debug::max_label_len</SPAN>. +by the constant<SPAN class="code"> libcw::debug::max_label_len_c</SPAN>. At this moment that is 16.</P> <A name="prefix"></A> Index: src/libcwd/include/cwd_debug.h diff -u src/libcwd/include/cwd_debug.h:1.5 src/libcwd/include/cwd_debug.h:1.6 --- src/libcwd/include/cwd_debug.h:1.5 Fri Jan 4 19:55:12 2002 +++ src/libcwd/include/cwd_debug.h Fri Jan 18 21:08:54 2002 @@ -1,5 +1,5 @@ // Generated automatically from sys.ho.in by configure. -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/cwd_debug.h,v 1.5 2002/01/05 03:55:12 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/cwd_debug.h,v 1.6 2002/01/19 05:08:54 libcw Exp $ // // Copyright (C) 2001, by // @@ -93,37 +93,39 @@ return os; } -#define LIBCWD_Dout( cntrl, data ) \ - do \ - { \ - if (libcw_do._off < 0) \ - { \ - bool on; \ - { \ - using namespace channels; \ - on = (libcw_do|cntrl).on; \ - } \ - if (on) \ - { \ - libcw_do.start(LIBCWD_TSD); \ - _private_::no_alloc_ostream_ct no_alloc_ostream(*libcw_do.current_oss); \ - no_alloc_ostream << data; \ - libcw_do.finish(LIBCWD_TSD); \ - } \ - } \ +#define LIBCWD_Dout( cntrl, data ) \ + do \ + { \ + if (LIBCWD_DO_TSD_MEMBER(libcw_do, _off) < 0) \ + { \ + bool on; \ + channel_set_bootstrap_st channel_set(LIBCWD_DO_TSD(libcw_do) LIBCWD_COMMA_TSD); \ + { \ + using namespace channels; \ + on = (channel_set|cntrl).on; \ + } \ + if (on) \ + { \ + LIBCWD_DO_TSD(libcw_do).start(libcw_do, channel_set LIBCWD_COMMA_TSD); \ + _private_::no_alloc_ostream_ct no_alloc_ostream(*LIBCWD_DO_TSD_MEMBER(libcw_do, current_oss)); \ + no_alloc_ostream << data; \ + LIBCWD_DO_TSD(libcw_do).finish(libcw_do, channel_set LIBCWD_COMMA_TSD); \ + } \ + } \ } while(0) -#define LIBCWD_DoutFatal( cntrl, data ) \ - do \ - { \ - { \ - using namespace dc_namespace; \ - libcw_do&cntrl; \ - } \ - libcw_do.start(LIBCWD_TSD); \ - _private_::no_alloc_ostream_ct no_alloc_ostream(*libcw_do.current_oss); \ - no_alloc_ostream << data; \ - libcw_do.fatal_finish(LIBCWD_TSD); \ +#define LIBCWD_DoutFatal( cntrl, data ) \ + do \ + { \ + channel_set_bootstrap_st channel_set(LIBCWD_DO_TSD(libcw_do) LIBCWD_COMMA_TSD); \ + { \ + using namespace dc_namespace; \ + channel_set&cntrl; \ + } \ + LIBCWD_DO_TSD(libcw_do).start(libcw_do, channel_set LIBCWD_COMMA_TSD); \ + _private_::no_alloc_ostream_ct no_alloc_ostream(*LIBCWD_DO_TSD_MEMBER(libcw_do, current_oss)); \ + no_alloc_ostream << data; \ + LIBCWD_DO_TSD(libcw_do).fatal_finish(libcw_do, channel_set LIBCWD_COMMA_TSD); \ } while(0) #ifdef DEBUGDEBUG Index: src/libcwd/include/libcw/Makefile.am diff -u src/libcwd/include/libcw/Makefile.am:1.17 src/libcwd/include/libcw/Makefile.am:1.18 --- src/libcwd/include/libcw/Makefile.am:1.17 Sat Dec 29 20:17:49 2001 +++ src/libcwd/include/libcw/Makefile.am Fri Jan 18 21:08:54 2002 @@ -5,6 +5,7 @@ buf2str.h \ char2str.h \ class_alloc.h \ + class_always_channel.inl \ class_channel.h \ class_channel.inl \ class_channel_set.h \ Index: src/libcwd/include/libcw/class_always_channel.h diff -u /dev/null src/libcwd/include/libcw/class_always_channel.h:1.1 --- /dev/null Fri Jan 18 21:09:04 2002 +++ src/libcwd/include/libcw/class_always_channel.h Fri Jan 18 21:08:54 2002 @@ -0,0 +1,47 @@ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_always_channel.h,v 1.1 2002/01/19 05:08:54 libcw Exp $ +// +// Copyright (C) 2002, by +// +// Carlo Wood, Run on IRC <ca...@al...> +// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt +// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 +// +// This file may be distributed under the terms of the Q Public License +// version 1.0 as appearing in the file LICENSE.QPL included in the +// packaging of this file. +// + +/** \file class_always_channel.h + * Do not include this header file directly, instead include "\ref preparation_step2 "debug.h"". + */ + +#ifndef LIBCW_ALWAYS_CHANNEL_H +#define LIBCW_ALWAYS_CHANNEL_H + +#ifndef LIBCW_DEBUG_CONFIG_H +#include <libcw/debug_config.h> +#endif +#ifndef LIBCW_CONTROL_FLAG_H +#include <libcw/control_flag.h> +#endif + +namespace libcw { + namespace debug { + +//=================================================================================================== +// class always_channel_ct +// +// A debug channel with a special characteristic: It is always turned +// and cannot be turned off. +// + +class always_channel_ct { +public: + static char const label[]; +}; + + } // namespace debug +} // namespace libcw + +#endif // LIBCW_ALWAYS_CHANNEL_H + Index: src/libcwd/include/libcw/class_always_channel.inl diff -u /dev/null src/libcwd/include/libcw/class_always_channel.inl:1.1 --- /dev/null Fri Jan 18 21:09:04 2002 +++ src/libcwd/include/libcw/class_always_channel.inl Fri Jan 18 21:08:54 2002 @@ -0,0 +1,40 @@ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_always_channel.inl,v 1.1 2002/01/19 05:08:54 libcw Exp $ +// +// Copyright (C) 2002, by +// +// Carlo Wood, Run on IRC <ca...@al...> +// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt +// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 +// +// This file may be distributed under the terms of the Q Public License +// version 1.0 as appearing in the file LICENSE.QPL included in the +// packaging of this file. +// + +#ifndef LIBCW_CLASS_ALWAYS_CHANNEL_INL +#define LIBCW_CLASS_ALWAYS_CHANNEL_INL + +#ifndef CLASS_ALWAYS_CHANNEL_H +#include <libcw/class_always_channel.h> +#endif +#ifndef LIBCW_CONTROL_FLAG_H +#include <libcw/control_flag.h> +#endif + +namespace libcw { + namespace debug { + +__inline__ +channel_set_st& +channel_set_bootstrap_st::operator|(always_channel_ct const& adc) +{ + mask = 0; + label = adc.label; + on = true; + return *reinterpret_cast<channel_set_st*>(this); +} + + } // namespace debug +} // namespace libcw + +#endif // LIBCW_CLASS_ALWAYS_CHANNEL_INL Index: src/libcwd/include/libcw/class_channel_set.h diff -u src/libcwd/include/libcw/class_channel_set.h:1.2 src/libcwd/include/libcw/class_channel_set.h:1.3 --- src/libcwd/include/libcw/class_channel_set.h:1.2 Sat Dec 29 20:17:50 2001 +++ src/libcwd/include/libcw/class_channel_set.h Fri Jan 18 21:08:54 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel_set.h,v 1.2 2001/12/30 04:17:50 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel_set.h,v 1.3 2002/01/19 05:08:54 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -24,11 +24,15 @@ #ifndef LIBCW_CONTROL_FLAG_H #include <libcw/control_flag.h> #endif +#ifndef LIBCW_PRIVATE_TSD_H +#include <libcw/private_TSD.h> +#endif namespace libcw { namespace debug { class debug_ct; +struct debug_tsd_st; class channel_ct; class fatal_channel_ct; @@ -48,9 +52,13 @@ bool on; // Set if at least one of the provided channels is turned on. + + debug_tsd_st* do_tsd_ptr; + // Thread specific data of current debug object. - debug_ct* debug_object; - // The owner of this object. +#ifdef DEBUGDEBUG + channel_set_data_st(void) : do_tsd_ptr(NULL) { } +#endif }; //=================================================================================================== @@ -78,6 +86,34 @@ channel_set_st& operator|(channel_ct const& dc); channel_set_st& operator|(fatal_channel_ct const& fdc); continued_channel_set_st& operator|(continued_cf_nt); +}; + +//=================================================================================================== +// struct channel_set_bootstrap_st +// +// The debug output target; a combination of channels and control bits. +// + +class channel_ct; +class fatal_channel_ct; +class continued_channel_ct; +class always_channel_ct; + +struct channel_set_bootstrap_st : public channel_set_data_st { + // Warning: This struct may not have attributes of its own! +public: + channel_set_bootstrap_st(debug_tsd_st& do_tsd LIBCWD_COMMA_TSD_PARAM) { do_tsd_ptr = &do_tsd; } + + //------------------------------------------------------------------------------------------------- + // Operators that combine channels/control bits. + // + + channel_set_st& operator|(channel_ct const& dc); + channel_set_st& operator|(always_channel_ct const& adc); + channel_set_st& operator&(fatal_channel_ct const& fdc); // Using operator& just to detect that we indeed used LibcwDoutFatal! + continued_channel_set_st& operator|(continued_channel_ct const& cdc); + channel_set_st& operator|(fatal_channel_ct const&); + channel_set_st& operator&(channel_ct const&); }; } // namespace debug Index: src/libcwd/include/libcw/class_debug.h diff -u src/libcwd/include/libcw/class_debug.h:1.4 src/libcwd/include/libcw/class_debug.h:1.5 --- src/libcwd/include/libcw/class_debug.h:1.4 Sat Jan 12 07:43:15 2002 +++ src/libcwd/include/libcw/class_debug.h Fri Jan 18 21:08:54 2002 @@ -1,6 +1,6 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.4 2002/01/12 15:43:15 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.5 2002/01/19 05:08:54 libcw Exp $ // -// Copyright (C) 2000 - 2001, by +// Copyright (C) 2000 - 2002, by // // Carlo Wood, Run on IRC <ca...@al...> // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt @@ -24,15 +24,12 @@ #ifndef LIBCW_CLASS_CHANNEL_SET_H #include <libcw/class_channel_set.h> #endif -#ifndef LIBCW_PRIVATE_DEBUG_STACK_H -#include <libcw/private_debug_stack.h> -#endif -#ifndef LIBCW_CLASS_DEBUG_STRING_H -#include <libcw/class_debug_string.h> -#endif #ifndef LIBCW_PRIVATE_TSD_H #include <libcw/private_TSD.h> #endif +#ifndef LIBCW_STRUCT_DEBUG_TSD +#include <libcw/struct_debug_tsd.h> +#endif #ifndef LIBCW_IOSFWD #define LIBCW_IOSFWD #include <iosfwd> @@ -40,15 +37,7 @@ namespace libcw { namespace debug { -#ifdef DEBUGUSEBFD - namespace cwbfd { bool ST_init(void); } -#endif -class channel_ct; -class fatal_channel_ct; -class continued_channel_ct; -class laf_ct; - //=================================================================================================== // class debug_ct // @@ -69,73 +58,49 @@ * See \ref group_debug_object. */ class debug_ct { -#ifdef DOXYGEN + friend void debug_tsd_st::start(debug_ct&, channel_set_data_st& LIBCWD_COMMA_TSD_PARAM); + friend void debug_tsd_st::finish(debug_ct &, channel_set_data_st& LIBCWD_COMMA_TSD_PARAM); +#ifdef LIBCW_DOXYGEN protected: #else -public: // Direct access needed in macro LibcwDout(). Do not write to these. +public: // Only public because macro LibcwDout needs acces, don't access this directly. #endif - int _off; - // Debug output is turned on when this variable is -1, otherwise it is off. - - laf_ct* current; - // Current laf. - - std::ostream* current_oss; - // The stringstream of the current laf. This should *always* be equal to current->oss. - // The reason for keeping this copy is to avoid including <sstream> in debug.h. +#ifndef LIBCWD_THREAD_SAFE + //------------------------------------------------------------------------------------------------- + // Put the otherwise Thread Specific Data of this debug object + // directly into the object when we don't use threads. + // - union { - channel_set_st channel_set; - continued_channel_set_st continued_channel_set; - }; - // Temporary storage for the current (continued) channel set (while being assembled from - // operator| calls). The reason for the union is that the type of this variable is converted - // from channel_set_st to continued_channel_set_st by a reinterpret_cast when a continued_cf, - // dc::continued or dc::finish is detected. This allows us to make compile-time decisions (using - // overloading). + debug_tsd_st tsd; +#else + int WNS_index; +#endif protected: - std::ostream* orig_os; - // The original output ostream (as set with set_ostream() or set_fd()). - - std::ostream* os; - // The current output ostream (may be a temporal stringstream). - - bool start_expected; - // Set to true when start() is expected, otherwise we expect a call to finish(). - - bool unfinished_expected; - // Set to true when start() should cause a <unfinished>. - - _private_::debug_stack_tst<laf_ct*> laf_stack; - // Store for nested debug calls. - - friend continued_channel_set_st& channel_set_st::operator|(continued_cf_nt); - // Needs access to `initialized', `off_count' and `continued_stack'. - - int off_count; - // Number of nested and switched off continued channels till first switched on continued channel. - - _private_::debug_stack_tst<int> continued_stack; - // Stores the number of nested and switched off continued channels. - - debug_string_stack_element_ct* M_margin_stack; - // Pointer to list of pushed margins. + //------------------------------------------------------------------------------------------------- + // Protected attributes. + // - debug_string_stack_element_ct* M_marker_stack; - // Pointer to list of pushed markers. + std::ostream* real_os; + // The original output ostream (as set with set_ostream() or set_fd()). -protected: +private: //------------------------------------------------------------------------------------------------- - // Attributes that determine how the prefix is printed: + // Private attributes: // - unsigned short indent; - // Position at which debug message is printed. - // A value of 0 means directly behind the marker. + bool WNS_initialized; + // Set to true when this object is initialized (by a call to NS_init()). -public: +#ifdef DEBUGDEBUG + long init_magic; + // Used to check if the trick with `WNS_initialized' really works. +#endif + bool interactive; + // Set true if the last or current debug output is to cerr + +public: /** \addtogroup group_formatting */ /** \{ */ @@ -148,7 +113,14 @@ * \sa push_margin() * \n pop_margin() */ +#if defined(LIBCWD_THREAD_SAFE) && !defined(LIBCW_DOXYGEN) + struct TS_margin_st { + __inline__ operator debug_string_ct& (void); + __inline__ operator debug_string_ct const& (void) const; + } margin; +#else debug_string_ct margin; +#endif /** * \brief The marker @@ -159,13 +131,20 ... [truncated message content] |
From: Carlo W. <li...@us...> - 2002-01-20 02:33:48
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-20 02:33:46 UTC Modified files: libcwd/debug.cc libcwd/include/libcw/Makefile.am libcwd/include/libcw/class_debug.inl libcwd/include/libcw/struct_debug_tsd.h Log message: Clean ups. ---------------------- diff included ---------------------- Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.54 src/libcwd/debug.cc:1.55 --- src/libcwd/debug.cc:1.54 Fri Jan 18 21:08:54 2002 +++ src/libcwd/debug.cc Sat Jan 19 18:33:36 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.54 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.55 2002/01/20 02:33:36 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -645,7 +645,7 @@ target_os->write("<unfinished>\n", 13); // Continued debug output should end on a space by itself, // Truncate the buffer to its prefix and append "<continued>" to it already. static_cast<buffer_ct*>(current_oss)->restore_position(); - static_cast<buffer_ct*>(current_oss)->write("<continued> ", 12); // therefore we repeat the space here. + current_oss->write("<continued> ", 12); // therefore we repeat the space here. } // Is this a nested debug output (the first of a series in the middle of another debug output)? @@ -682,9 +682,9 @@ // Handle most common case first: no special flags set if (!(channel_set.mask & (noprefix_cf|nolabel_cf|blank_margin_cf|blank_label_cf|blank_marker_cf))) { - static_cast<buffer_ct*>(current_oss)->write(debug_object.margin.c_str(), debug_object.margin.size()); - static_cast<buffer_ct*>(current_oss)->write(channel_set.label, WST_max_len); - static_cast<buffer_ct*>(current_oss)->write(debug_object.marker.c_str(), debug_object.marker.size()); + current_oss->write(debug_object.margin.c_str(), debug_object.margin.size()); + current_oss->write(channel_set.label, WST_max_len); + current_oss->write(debug_object.marker.c_str(), debug_object.marker.size()); write_whitespace_to(*current_oss, indent); } else if (!(channel_set.mask & noprefix_cf)) @@ -692,7 +692,7 @@ if ((channel_set.mask & blank_margin_cf)) write_whitespace_to(*current_oss, debug_object.margin.size()); else - static_cast<buffer_ct*>(current_oss)->write(debug_object.margin.c_str(), debug_object.margin.size()); + current_oss->write(debug_object.margin.c_str(), debug_object.margin.size()); #ifndef DEBUGDEBUGOUTPUT if (!(channel_set.mask & nolabel_cf)) #endif @@ -700,11 +700,11 @@ if ((channel_set.mask & blank_label_cf)) write_whitespace_to(*current_oss, WST_max_len); else - static_cast<buffer_ct*>(current_oss)->write(channel_set.label, WST_max_len); + current_oss->write(channel_set.label, WST_max_len); if ((channel_set.mask & blank_marker_cf)) write_whitespace_to(*current_oss, debug_object.marker.size()); else - static_cast<buffer_ct*>(current_oss)->write(debug_object.marker.c_str(), debug_object.marker.size()); + current_oss->write(debug_object.marker.c_str(), debug_object.marker.size()); write_whitespace_to(*current_oss, indent); } } @@ -825,8 +825,10 @@ { current = reinterpret_cast<laf_ct*>(_private_::WST_dummy_laf); // Used (MT: read-only!) in next debug_ct::start(). DEBUGDEBUG_CERR( "current = " << (void*)current ); - current_oss = target_os; // Used in start. +#ifdef DEBUGDEBUG + current_oss = NULL; DEBUGDEBUG_CERR( "current_oss = " << (void*)current_oss ); +#endif } start_expected = true; @@ -844,23 +846,6 @@ DoutFatal( dc::core, "Don't use `DoutFatal' together with `continued_cf', use `Dout' instead. (This message can also occur when using DoutFatal correctly but from the constructor of a global object)." ); } - /** - * \brief Set output device. - * \ingroup group_destination - * - * Assign a new \c ostream to this %debug object (default is <CODE>std::cerr</CODE>). - */ - void debug_ct::set_ostream(std::ostream* os) - { - LIBCWD_TSD_DECLARATION -#ifdef DEBUGDEBUG - LIBCWD_ASSERT( LIBCWD_TSD_MEMBER(tsd_initialized) ); -#endif - real_os = os; - if (LIBCWD_TSD_MEMBER(laf_stack).size() == 0) - LIBCWD_TSD_MEMBER(current_oss) = real_os; - } - void debug_ct::NS_init(void) { ST_initialize_globals(); // Because all allocations for global objects are internal these days, we use @@ -952,8 +937,10 @@ // current.mask needs to be 0 to avoid a crash in start(): current = reinterpret_cast<laf_ct*>(_private_::WST_dummy_laf); DEBUGDEBUG_CERR( "current = " << (void*)current ); - current_oss = ¤t->oss; +#ifdef DEBUGDEBUG + current_oss = NULL; DEBUGDEBUG_CERR( "current_oss = " << (void*)current_oss ); +#endif laf_stack.init(); continued_stack.init(); Index: src/libcwd/include/libcw/Makefile.am diff -u src/libcwd/include/libcw/Makefile.am:1.18 src/libcwd/include/libcw/Makefile.am:1.19 --- src/libcwd/include/libcw/Makefile.am:1.18 Fri Jan 18 21:08:54 2002 +++ src/libcwd/include/libcw/Makefile.am Sat Jan 19 18:33:36 2002 @@ -5,6 +5,7 @@ buf2str.h \ char2str.h \ class_alloc.h \ + class_always_channel.h \ class_always_channel.inl \ class_channel.h \ class_channel.inl \ @@ -45,6 +46,7 @@ private_set_alloc_checking.h \ private_threading.h \ strerrno.h \ + struct_debug_tsd.h \ type_info.h BUILT_SOURCES = sysd.ho debug_config.ho Index: src/libcwd/include/libcw/class_debug.inl diff -u src/libcwd/include/libcw/class_debug.inl:1.3 src/libcwd/include/libcw/class_debug.inl:1.4 --- src/libcwd/include/libcw/class_debug.inl:1.3 Fri Jan 18 21:08:54 2002 +++ src/libcwd/include/libcw/class_debug.inl Sat Jan 19 18:33:36 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.inl,v 1.3 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.inl,v 1.4 2002/01/20 02:33:36 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -133,6 +133,25 @@ debug_ct::get_ostream(void) const { return real_os; +} + +/** + * \brief Set output device. + * \ingroup group_destination + * + * Assign a new \c ostream to this %debug object (default is <CODE>std::cerr</CODE>). + */ +__inline__ +void +debug_ct::set_ostream(std::ostream* os) +{ + real_os = os; +#ifdef DEBUGDEBUG + LIBCWD_TSD_DECLARATION + LIBCWD_ASSERT( LIBCWD_TSD_MEMBER(tsd_initialized) ); + if (LIBCWD_TSD_MEMBER(laf_stack).size() == 0) + LIBCWD_TSD_MEMBER(current_oss) = NULL; +#endif } /** \} */ Index: src/libcwd/include/libcw/struct_debug_tsd.h diff -u src/libcwd/include/libcw/struct_debug_tsd.h:1.1 src/libcwd/include/libcw/struct_debug_tsd.h:1.2 --- src/libcwd/include/libcw/struct_debug_tsd.h:1.1 Fri Jan 18 21:08:54 2002 +++ src/libcwd/include/libcw/struct_debug_tsd.h Sat Jan 19 18:33:36 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/struct_debug_tsd.h,v 1.1 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/struct_debug_tsd.h,v 1.2 2002/01/20 02:33:36 libcw Exp $ // // Copyright (C) 2002, by // @@ -45,7 +45,6 @@ class channel_ct; class fatal_channel_ct; class laf_ct; -class buffer_ct; //=================================================================================================== // struct debug_tsd_st ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-20 16:25:23
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-20 16:25:22 UTC Modified files: libcwd/debug.cc libcwd/debugmalloc.cc libcwd/documentation/styles/doxygen.css libcwd/include/libcw/class_channel_set.h libcwd/include/libcw/class_debug.h libcwd/include/libcw/class_debug.inl libcwd/include/libcw/class_debug_string.h libcwd/include/libcw/struct_debug_tsd.h libcwd/testsuite/libcwd.tst/do.cc libcwd/testsuite/libcwd.tst/do.re libcwd/testsuite/libcwd.tst/tst.exp libcwd/utils/exec_prog.cc Log message: Fixed bug in debug_string_ct::prepend, the length was not increased, cutting off the last part of the resulting string. Libcwd now compiles with --enable-libcwd-threading. ---------------------- diff included ---------------------- Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.55 src/libcwd/debug.cc:1.56 --- src/libcwd/debug.cc:1.55 Sat Jan 19 18:33:36 2002 +++ src/libcwd/debug.cc Sun Jan 20 08:25:11 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.55 2002/01/20 02:33:36 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.56 2002/01/20 16:25:11 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -77,9 +77,9 @@ int curlen = rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out) - rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); if (curlen > 512 || !(buf = (char*)alloca(curlen))) { - set_alloc_checking_off(); + set_alloc_checking_off(LIBCWD_TSD); buf = (char*)malloc(curlen); - set_alloc_checking_on(); + set_alloc_checking_on(LIBCWD_TSD); used_malloc = true; } rdbuf()->sgetn(buf, curlen); @@ -98,9 +98,9 @@ #endif if (used_malloc) { - set_alloc_checking_off(); + set_alloc_checking_off(LIBCWD_TSD); free(buf); - set_alloc_checking_on(); + set_alloc_checking_on(LIBCWD_TSD); } } void store_position(void) { @@ -446,13 +446,8 @@ size_t debug_string_ct::calculate_capacity(size_t size) { size_t capacity_plus_one = M_default_capacity + 1; // For the terminating zero. - do - { - if (size < capacity_plus_one) - return capacity_plus_one; + while(size >= capacity_plus_one) capacity_plus_one *= 2; - } - while(1); return capacity_plus_one - 1; } @@ -472,7 +467,7 @@ void debug_string_ct::internal_assign(char const* str, size_t len) { - if (len > M_capacity || (M_capacity >= M_default_capacity && len < M_default_capacity)) + if (len > M_capacity || (M_capacity > M_default_capacity && len < M_default_capacity)) M_str = (char*)realloc(M_str, (M_capacity = calculate_capacity(len)) + 1); strncpy(M_str, str, len); M_size = len; @@ -481,7 +476,7 @@ void debug_string_ct::internal_append(char const* str, size_t len) { - if (M_size + len > M_capacity || (M_capacity >= M_default_capacity && M_size + len < M_default_capacity)) + if (M_size + len > M_capacity || (M_capacity > M_default_capacity && M_size + len < M_default_capacity)) M_str = (char*)realloc(M_str, (M_capacity = calculate_capacity(M_size + len)) + 1); strncpy(M_str + M_size, str, len); M_size += len; @@ -490,10 +485,11 @@ void debug_string_ct::internal_prepend(char const* str, size_t len) { - if (M_size + len > M_capacity || (M_capacity >= M_default_capacity && M_size + len < M_default_capacity)) + if (M_size + len > M_capacity || (M_capacity > M_default_capacity && M_size + len < M_default_capacity)) M_str = (char*)realloc(M_str, (M_capacity = calculate_capacity(M_size + len)) + 1); memmove(M_str + len, M_str, M_size + 1); strncpy(M_str, str, len); + M_size += len; } /** @@ -532,7 +528,7 @@ debug_string_stack_element_ct* current_margin_stack = LIBCWD_TSD_MEMBER(M_margin_stack); set_alloc_checking_off(LIBCWD_TSD); void* new_debug_string = malloc(sizeof(debug_string_stack_element_ct)); - LIBCWD_TSD_MEMBER(M_margin_stack) = new (new_debug_string) debug_string_stack_element_ct(margin); + LIBCWD_TSD_MEMBER(M_margin_stack) = new (new_debug_string) debug_string_stack_element_ct(LIBCWD_TSD_MEMBER(margin)); set_alloc_checking_on(LIBCWD_TSD); LIBCWD_TSD_MEMBER(M_margin_stack)->next = current_margin_stack; } @@ -547,7 +543,7 @@ DoutFatal(dc::core, "Calling `debug_ct::pop_margin' more often than `debug_ct::push_margin'."); debug_string_stack_element_ct* next = LIBCWD_TSD_MEMBER(M_margin_stack)->next; set_alloc_checking_off(LIBCWD_TSD); - margin.internal_swallow(LIBCWD_TSD_MEMBER(M_margin_stack)->debug_string); + LIBCWD_TSD_MEMBER(margin).internal_swallow(LIBCWD_TSD_MEMBER(M_margin_stack)->debug_string); free(LIBCWD_TSD_MEMBER(M_margin_stack)); set_alloc_checking_on(LIBCWD_TSD); LIBCWD_TSD_MEMBER(M_margin_stack) = next; @@ -562,7 +558,7 @@ debug_string_stack_element_ct* current_marker_stack = LIBCWD_TSD_MEMBER(M_marker_stack); set_alloc_checking_off(LIBCWD_TSD); void* new_debug_string = malloc(sizeof(debug_string_stack_element_ct)); - LIBCWD_TSD_MEMBER(M_marker_stack) = new (new_debug_string) debug_string_stack_element_ct(marker); + LIBCWD_TSD_MEMBER(M_marker_stack) = new (new_debug_string) debug_string_stack_element_ct(LIBCWD_TSD_MEMBER(marker)); LIBCWD_TSD_MEMBER(M_marker_stack)->next = current_marker_stack; } @@ -576,7 +572,7 @@ DoutFatal(dc::core, "Calling `debug_ct::pop_marker' more often than `debug_ct::push_marker'."); debug_string_stack_element_ct* next = LIBCWD_TSD_MEMBER(M_marker_stack)->next; set_alloc_checking_off(LIBCWD_TSD); - marker.internal_swallow(LIBCWD_TSD_MEMBER(M_marker_stack)->debug_string); + LIBCWD_TSD_MEMBER(marker).internal_swallow(LIBCWD_TSD_MEMBER(M_marker_stack)->debug_string); free(LIBCWD_TSD_MEMBER(M_marker_stack)); set_alloc_checking_on(LIBCWD_TSD); LIBCWD_TSD_MEMBER(M_marker_stack) = next; @@ -682,17 +678,17 @@ // Handle most common case first: no special flags set if (!(channel_set.mask & (noprefix_cf|nolabel_cf|blank_margin_cf|blank_label_cf|blank_marker_cf))) { - current_oss->write(debug_object.margin.c_str(), debug_object.margin.size()); + current_oss->write(margin.c_str(), margin.size()); current_oss->write(channel_set.label, WST_max_len); - current_oss->write(debug_object.marker.c_str(), debug_object.marker.size()); + current_oss->write(marker.c_str(), marker.size()); write_whitespace_to(*current_oss, indent); } else if (!(channel_set.mask & noprefix_cf)) { if ((channel_set.mask & blank_margin_cf)) - write_whitespace_to(*current_oss, debug_object.margin.size()); + write_whitespace_to(*current_oss, margin.size()); else - current_oss->write(debug_object.margin.c_str(), debug_object.margin.size()); + current_oss->write(margin.c_str(), margin.size()); #ifndef DEBUGDEBUGOUTPUT if (!(channel_set.mask & nolabel_cf)) #endif @@ -702,9 +698,9 @@ else current_oss->write(channel_set.label, WST_max_len); if ((channel_set.mask & blank_marker_cf)) - write_whitespace_to(*current_oss, debug_object.marker.size()); + write_whitespace_to(*current_oss, marker.size()); else - current_oss->write(debug_object.marker.c_str(), debug_object.marker.size()); + current_oss->write(marker.c_str(), marker.size()); write_whitespace_to(*current_oss, indent); } } @@ -876,8 +872,6 @@ #ifndef LIBCWD_THREAD_SAFE tsd.init(); #endif - margin.NS_internal_init("", 0); - marker.NS_internal_init(": ", 2); set_alloc_checking_on(LIBCWD_TSD); // This set current_oss and must be called after tsd.init(). @@ -913,6 +907,10 @@ void debug_tsd_st::init(void) { +#ifdef DEBUGDEBUGMALLOC + LIBCWD_TSD_DECLARATION + LIBCWD_ASSERT( __libcwd_tsd.internal ); +#endif _off = 0; // Turn off all debugging until initialization is completed. DEBUGDEBUG_CERR( "In debug_tsd_st::NS_init(void), _off set to 0" ); @@ -943,6 +941,8 @@ #endif laf_stack.init(); continued_stack.init(); + margin.NS_internal_init("", 0); + marker.NS_internal_init(": ", 2); #ifdef DEBUGDEBUGOUTPUT _off = -1; // Print as much debug output as possible right away. @@ -966,13 +966,11 @@ ++_off; // Turn all debug output premanently off, otherwise we might re-initialize // this object again when we try to write debug output to it! DEBUGDEBUG_CERR( "debug_tsd_st destructed: _off became " << _off ); -#ifdef LIBCWD_THREAD_SAFE LIBCWD_TSD_DECLARATION set_alloc_checking_off(LIBCWD_TSD); marker.ST_internal_deinit(); margin.ST_internal_deinit(); set_alloc_checking_on(LIBCWD_TSD); -#endif tsd_initialized = false; } @@ -987,10 +985,6 @@ #endif LIBCWD_TSD_DECLARATION set_alloc_checking_off(LIBCWD_TSD); -#ifndef LIBCWD_THREAD_SAFE - marker.ST_internal_deinit(); - margin.ST_internal_deinit(); -#endif DEBUG_OBJECTS_ACQUIRE_WRITE_LOCK { _private_::debug_objects_ct::container_type& objects(_private_::debug_objects.write_locked()); @@ -1354,6 +1348,7 @@ void debug_ct::restore(debug_ct::OnOffState const& state) { + LIBCWD_TSD_DECLARATION #ifdef DEBUGDEBUGOUTPUT if (state.first_time != LIBCWD_TSD_MEMBER(first_time)) // state.first_time && !first_time. core_dump(); // on() was called without first a call to off(). Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.74 src/libcwd/debugmalloc.cc:1.75 --- src/libcwd/debugmalloc.cc:1.74 Fri Jan 18 21:08:54 2002 +++ src/libcwd/debugmalloc.cc Sun Jan 20 08:25:11 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.74 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.75 2002/01/20 16:25:11 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -1793,7 +1793,7 @@ if ((*iter).second.a_alloc_node.get()->next_list()) { libcw_do.push_margin(); - libcw_do.margin.append(" * ", 4); + libcw_do.margin().append(" * ", 4); Dout( dc::warning, "Memory leak detected!" ); (*iter).second.a_alloc_node.get()->next_list()->show_alloc_list(1, channels::dc::warning); libcw_do.pop_margin(); Index: src/libcwd/documentation/styles/doxygen.css diff -u src/libcwd/documentation/styles/doxygen.css:1.2 src/libcwd/documentation/styles/doxygen.css:1.3 --- src/libcwd/documentation/styles/doxygen.css:1.2 Sat Dec 29 20:17:48 2001 +++ src/libcwd/documentation/styles/doxygen.css Sun Jan 20 08:25:11 2002 @@ -17,7 +17,7 @@ A.el { text-decoration : none; - font-weight : bold + font-weight : normal; } A.elRef { Index: src/libcwd/include/libcw/class_channel_set.h diff -u src/libcwd/include/libcw/class_channel_set.h:1.3 src/libcwd/include/libcw/class_channel_set.h:1.4 --- src/libcwd/include/libcw/class_channel_set.h:1.3 Fri Jan 18 21:08:54 2002 +++ src/libcwd/include/libcw/class_channel_set.h Sun Jan 20 08:25:11 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel_set.h,v 1.3 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel_set.h,v 1.4 2002/01/20 16:25:11 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -39,7 +39,7 @@ //=================================================================================================== // struct channel_set_data_st // -// The attributes of channel_set_st and continued_channel_set_st +// The attributes of channel_set_bootstrap_st, channel_set_st and continued_channel_set_st // struct channel_set_data_st { @@ -62,21 +62,50 @@ }; //=================================================================================================== -// struct continued_channel_set_st +// struct channel_set_bootstrap_st // -// The debug output target; a combination of channels and control bits. +// This is the left-most type of channel 'control' series +// existing of <channel_set_bootstrap_st>|<one or more channels>|<optional control flags>. +// It is used in macro LibcwdDoutScopeStart. +// +// LibcwDoutFatal uses operator& while LibcwDout uses operator|. +// +// The return type is a cast of this object to +// either a channel_set_st (the normal case) or a +// continued_channel_set_st in the case that the +// special debug channel dc::continued was used. // -struct continued_channel_set_st : public channel_set_data_st { +class channel_ct; +class fatal_channel_ct; +class continued_channel_ct; +class always_channel_ct; +struct channel_set_st; +struct continued_channel_set_st; + +struct channel_set_bootstrap_st : public channel_set_data_st { // Warning: This struct may not have attributes of its own! public: - continued_channel_set_st& operator|(control_flag_t cf); + channel_set_bootstrap_st(debug_tsd_st& do_tsd LIBCWD_COMMA_TSD_PARAM) { do_tsd_ptr = &do_tsd; } + + //------------------------------------------------------------------------------------------------- + // Operators that combine channels/control bits. + // + + channel_set_st& operator|(channel_ct const& dc); + channel_set_st& operator|(always_channel_ct const& adc); + channel_set_st& operator&(fatal_channel_ct const& fdc); // Using operator& just to detect that we indeed used LibcwDoutFatal! + continued_channel_set_st& operator|(continued_channel_ct const& cdc); + channel_set_st& operator|(fatal_channel_ct const&); + channel_set_st& operator&(channel_ct const&); }; //=================================================================================================== // struct channel_set_st // // The debug output target; a combination of channels and control bits. +// The final result of a series of <channel>|<control flag>|... +// is passed to struct_debug_tsd_st::start(). // struct channel_set_st : public channel_set_data_st { @@ -89,31 +118,15 @@ }; //=================================================================================================== -// struct channel_set_bootstrap_st +// struct continued_channel_set_st // -// The debug output target; a combination of channels and control bits. +// The channel set type used for a series that starts with dc::continued. // - -class channel_ct; -class fatal_channel_ct; -class continued_channel_ct; -class always_channel_ct; -struct channel_set_bootstrap_st : public channel_set_data_st { +struct continued_channel_set_st : public channel_set_data_st { // Warning: This struct may not have attributes of its own! public: - channel_set_bootstrap_st(debug_tsd_st& do_tsd LIBCWD_COMMA_TSD_PARAM) { do_tsd_ptr = &do_tsd; } - - //------------------------------------------------------------------------------------------------- - // Operators that combine channels/control bits. - // - - channel_set_st& operator|(channel_ct const& dc); - channel_set_st& operator|(always_channel_ct const& adc); - channel_set_st& operator&(fatal_channel_ct const& fdc); // Using operator& just to detect that we indeed used LibcwDoutFatal! - continued_channel_set_st& operator|(continued_channel_ct const& cdc); - channel_set_st& operator|(fatal_channel_ct const&); - channel_set_st& operator&(channel_ct const&); + continued_channel_set_st& operator|(control_flag_t cf); }; } // namespace debug Index: src/libcwd/include/libcw/class_debug.h diff -u src/libcwd/include/libcw/class_debug.h:1.5 src/libcwd/include/libcw/class_debug.h:1.6 --- src/libcwd/include/libcw/class_debug.h:1.5 Fri Jan 18 21:08:54 2002 +++ src/libcwd/include/libcw/class_debug.h Sun Jan 20 08:25:11 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.5 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.6 2002/01/20 16:25:11 libcw Exp $ // // Copyright (C) 2000 - 2002, by // @@ -113,14 +113,8 @@ * \sa push_margin() * \n pop_margin() */ -#if defined(LIBCWD_THREAD_SAFE) && !defined(LIBCW_DOXYGEN) - struct TS_margin_st { - __inline__ operator debug_string_ct& (void); - __inline__ operator debug_string_ct const& (void) const; - } margin; -#else - debug_string_ct margin; -#endif + debug_string_ct& margin(void); + debug_string_ct const& margin(void) const; /** * \brief The marker @@ -131,14 +125,8 @@ * \sa push_marker() * \n pop_marker() */ -#if defined(LIBCWD_THREAD_SAFE) && !defined(LIBCW_DOXYGEN) - struct TS_marker_st { - __inline__ operator debug_string_ct& (void); - __inline__ operator debug_string_ct const& (void) const; - } marker; -#else - debug_string_ct marker; -#endif + debug_string_ct& marker(void); + debug_string_ct const& marker(void) const; /** \} */ Index: src/libcwd/include/libcw/class_debug.inl diff -u src/libcwd/include/libcw/class_debug.inl:1.4 src/libcwd/include/libcw/class_debug.inl:1.5 --- src/libcwd/include/libcw/class_debug.inl:1.4 Sat Jan 19 18:33:36 2002 +++ src/libcwd/include/libcw/class_debug.inl Sun Jan 20 08:25:11 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.inl,v 1.4 2002/01/20 02:33:36 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.inl,v 1.5 2002/01/20 16:25:11 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -39,22 +39,54 @@ /** \addtogroup group_formatting */ /* \{ */ +__inline__ +debug_string_ct& +debug_ct::margin(void) +{ + LIBCWD_TSD_DECLARATION + return LIBCWD_TSD_MEMBER(margin); +} + +__inline__ +debug_string_ct const& +debug_ct::margin(void) const +{ + LIBCWD_TSD_DECLARATION + return LIBCWD_TSD_MEMBER(margin); +} + +__inline__ +debug_string_ct& +debug_ct::marker(void) +{ + LIBCWD_TSD_DECLARATION + return LIBCWD_TSD_MEMBER(marker); +} + +__inline__ +debug_string_ct const& +debug_ct::marker(void) const +{ + LIBCWD_TSD_DECLARATION + return LIBCWD_TSD_MEMBER(marker); +} + // This is here only for backwards compatibility. -// You should call margin.assign() directly. +// You should call margin().assign(s) directly. __inline__ void debug_ct::set_margin(std::string const& s) { - margin.assign(s); + margin().assign(s); } // This is here only for backwards compatibility. -// You should call marker.assign() directly. +// You should call marker().assign(s) directly. __inline__ void debug_ct::set_marker(std::string const& s) { - marker.assign(s); + marker().assign(s); } /** @@ -108,7 +140,7 @@ std::string debug_ct::get_margin(void) const { - return std::string(margin.c_str(), margin.size()); + return std::string(margin().c_str(), margin().size()); } // This is here only for backwards compatibility. @@ -117,7 +149,7 @@ std::string debug_ct::get_marker(void) const { - return std::string(marker.c_str(), marker.size()); + return std::string(marker().c_str(), marker().size()); } /** \} */ Index: src/libcwd/include/libcw/class_debug_string.h diff -u src/libcwd/include/libcw/class_debug_string.h:1.3 src/libcwd/include/libcw/class_debug_string.h:1.4 --- src/libcwd/include/libcw/class_debug_string.h:1.3 Fri Jan 18 21:08:54 2002 +++ src/libcwd/include/libcw/class_debug_string.h Sun Jan 20 08:25:11 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug_string.h,v 1.3 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug_string.h,v 1.4 2002/01/20 16:25:11 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -47,6 +47,8 @@ * This type is used for the public attributes debug_ct::margin and debug_ct::marker of the %debug object class. */ class debug_string_ct { + friend class debug_ct; // Needs access to the private functions. + friend struct debug_tsd_st; private: char* M_str; // Pointer to malloc-ed (zero terminated) string. size_t M_size; // Size of string (exclusive terminating zero). @@ -61,11 +63,6 @@ void internal_swallow(debug_string_ct const&); private: -#ifdef LIBCWD_THREAD_SAFE - friend struct debug_tsd_st; -#else - friend class debug_ct; -#endif void NS_internal_init(char const* s, size_t l); void ST_internal_deinit(void); debug_string_ct(void) { } Index: src/libcwd/include/libcw/struct_debug_tsd.h diff -u src/libcwd/include/libcw/struct_debug_tsd.h:1.2 src/libcwd/include/libcw/struct_debug_tsd.h:1.3 --- src/libcwd/include/libcw/struct_debug_tsd.h:1.2 Sat Jan 19 18:33:36 2002 +++ src/libcwd/include/libcw/struct_debug_tsd.h Sun Jan 20 08:25:11 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/struct_debug_tsd.h,v 1.2 2002/01/20 02:33:36 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/struct_debug_tsd.h,v 1.3 2002/01/20 16:25:11 libcw Exp $ // // Copyright (C) 2002, by // @@ -86,10 +86,11 @@ _private_::debug_stack_tst<int> continued_stack; // Stores the number of nested and switched off continued channels. -#ifdef LIBCWD_THREAD_SAFE debug_string_ct margin; + // The margin string. + debug_string_ct marker; -#endif + // The marker string. debug_string_stack_element_ct* M_margin_stack; // Pointer to list of pushed margins. Index: src/libcwd/testsuite/libcwd.tst/do.cc diff -u src/libcwd/testsuite/libcwd.tst/do.cc:1.18 src/libcwd/testsuite/libcwd.tst/do.cc:1.19 --- src/libcwd/testsuite/libcwd.tst/do.cc:1.18 Wed Jan 9 21:04:34 2002 +++ src/libcwd/testsuite/libcwd.tst/do.cc Sun Jan 20 08:25:11 2002 @@ -89,13 +89,13 @@ // 1.1.2.2 Setting the prefix formatting attributes - Debug( libcw_do.set_margin("***********libcw_do*") ); - Debug( my_own_do.set_margin("**********my_own_do*") ); - Debug( example::my_own_do.set_margin("*example::my_own_do*") ); - - Debug( libcw_do.set_marker("|marker1|") ); - Debug( my_own_do.set_marker("|marker2|") ); - Debug( example::my_own_do.set_marker("|marker3|") ); + Debug( libcw_do.margin().assign("***********libcw_do*", 20) ); + Debug( my_own_do.margin().assign("**********my_own_do*", 20) ); + Debug( example::my_own_do.margin().assign("*example::my_own_do*", 20) ); + + Debug( libcw_do.marker().assign("|marker1|", 9) ); + Debug( my_own_do.marker().assign("|marker2|", 9) ); + Debug( example::my_own_do.marker().assign("|marker3|", 9) ); Dout(dc::debug, "No indent"); Dout(dc::notice, "No indent"); @@ -107,9 +107,9 @@ // 1.1.2.3 Retrieving the prefix formatting attributes - Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.get_margin() << "\", \"" << libcw::debug::libcw_do.get_marker() << "\"."); - MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.get_margin() << "\", \"" << my_own_do.get_marker() << "\"."); - ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.get_margin() << "\", \"" << example::my_own_do.get_marker() << "\"."); + Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.margin().c_str() << "\", \"" << libcw::debug::libcw_do.marker().c_str() << "\"."); + MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.margin().c_str() << "\", \"" << my_own_do.marker().c_str() << "\"."); + ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.margin().c_str() << "\", \"" << example::my_own_do.marker().c_str() << "\"."); // Manipulating the format strings. @@ -117,75 +117,75 @@ Debug( my_own_do.push_margin() ); Debug( example::my_own_do.push_margin() ); - Debug( libcw_do.margin.append("1Alibcw_do1") ); - Debug( my_own_do.margin.append("1Amy_own_do1") ); - Debug( example::my_own_do.margin.append("1Aexample::my_own_do1") ); - - Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.get_margin() << "\", \"" << libcw::debug::libcw_do.get_marker() << "\"."); - MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.get_margin() << "\", \"" << my_own_do.get_marker() << "\"."); - ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.get_margin() << "\", \"" << example::my_own_do.get_marker() << "\"."); - - Debug( libcw_do.margin.prepend("1Plibcw_do1") ); - Debug( my_own_do.margin.prepend("1Pmy_own_do1") ); - Debug( example::my_own_do.margin.prepend("1Pexample::my_own_do1") ); + Debug( libcw_do.margin().append("1Alibcw_do1", 11) ); + Debug( my_own_do.margin().append("1Amy_own_do1", 12) ); + Debug( example::my_own_do.margin().append("1Aexample::my_own_do1", 21) ); + + Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.margin().c_str() << "\", \"" << libcw::debug::libcw_do.marker().c_str() << "\"."); + MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.margin().c_str() << "\", \"" << my_own_do.marker().c_str() << "\"."); + ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.margin().c_str() << "\", \"" << example::my_own_do.marker().c_str() << "\"."); + + Debug( libcw_do.margin().prepend("1Plibcw_do1", 11) ); + Debug( my_own_do.margin().prepend("1Pmy_own_do1", 12) ); + Debug( example::my_own_do.margin().prepend("1Pexample::my_own_do1", 21) ); Debug( libcw_do.push_margin() ); Debug( my_own_do.push_margin() ); Debug( example::my_own_do.push_margin() ); - Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.get_margin() << "\", \"" << libcw::debug::libcw_do.get_marker() << "\"."); - MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.get_margin() << "\", \"" << my_own_do.get_marker() << "\"."); - ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.get_margin() << "\", \"" << example::my_own_do.get_marker() << "\"."); - - Debug( libcw_do.margin.assign("", 0) ); - Debug( my_own_do.margin.assign("*", 1) ); - Debug( example::my_own_do.margin.assign("XYZ", 3) ); - - Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.get_margin() << "\", \"" << libcw::debug::libcw_do.get_marker() << "\"."); - MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.get_margin() << "\", \"" << my_own_do.get_marker() << "\"."); - ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.get_margin() << "\", \"" << example::my_own_do.get_marker() << "\"."); - - Debug( libcw_do.margin.append("2Alibcw_do2") ); - Debug( my_own_do.margin.append("2Amy_own_do2") ); - Debug( example::my_own_do.margin.append("2Aexample::my_own_do2") ); - - Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.get_margin() << "\", \"" << libcw::debug::libcw_do.get_marker() << "\"."); - MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.get_margin() << "\", \"" << my_own_do.get_marker() << "\"."); - ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.get_margin() << "\", \"" << example::my_own_do.get_marker() << "\"."); + Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.margin().c_str() << "\", \"" << libcw::debug::libcw_do.marker().c_str() << "\"."); + MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.margin().c_str() << "\", \"" << my_own_do.marker().c_str() << "\"."); + ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.margin().c_str() << "\", \"" << example::my_own_do.marker().c_str() << "\"."); + + Debug( libcw_do.margin().assign("", 0) ); + Debug( my_own_do.margin().assign("*", 1) ); + Debug( example::my_own_do.margin().assign("XYZ", 3) ); + + Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.margin().c_str() << "\", \"" << libcw::debug::libcw_do.marker().c_str() << "\"."); + MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.margin().c_str() << "\", \"" << my_own_do.marker().c_str() << "\"."); + ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.margin().c_str() << "\", \"" << example::my_own_do.marker().c_str() << "\"."); + + Debug( libcw_do.margin().append("2Alibcw_do2", 11) ); + Debug( my_own_do.margin().append("2Amy_own_do2", 12) ); + Debug( example::my_own_do.margin().append("2Aexample::my_own_do2", 21) ); + + Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.margin().c_str() << "\", \"" << libcw::debug::libcw_do.marker().c_str() << "\"."); + MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.margin().c_str() << "\", \"" << my_own_do.marker().c_str() << "\"."); + ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.margin().c_str() << "\", \"" << example::my_own_do.marker().c_str() << "\"."); Debug( libcw_do.pop_margin() ); Debug( my_own_do.pop_margin() ); Debug( example::my_own_do.pop_margin() ); - Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.get_margin() << "\", \"" << libcw::debug::libcw_do.get_marker() << "\"."); - MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.get_margin() << "\", \"" << my_own_do.get_marker() << "\"."); - ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.get_margin() << "\", \"" << example::my_own_do.get_marker() << "\"."); - - Debug( libcw_do.margin.append("3Alibcw_do3") ); - Debug( my_own_do.margin.append("3Amy_own_do3") ); - Debug( example::my_own_do.margin.append("3Aexample::my_own_do3") ); - - Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.get_margin() << "\", \"" << libcw::debug::libcw_do.get_marker() << "\"."); - MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.get_margin() << "\", \"" << my_own_do.get_marker() << "\"."); - ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.get_margin() << "\", \"" << example::my_own_do.get_marker() << "\"."); + Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.margin().c_str() << "\", \"" << libcw::debug::libcw_do.marker().c_str() << "\"."); + MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.margin().c_str() << "\", \"" << my_own_do.marker().c_str() << "\"."); + ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.margin().c_str() << "\", \"" << example::my_own_do.marker().c_str() << "\"."); + + Debug( libcw_do.margin().append("3Alibcw_do3", 11) ); + Debug( my_own_do.margin().append("3Amy_own_do3", 12) ); + Debug( example::my_own_do.margin().append("3Aexample::my_own_do3", 21) ); + + Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.margin().c_str() << "\", \"" << libcw::debug::libcw_do.marker().c_str() << "\"."); + MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.margin().c_str() << "\", \"" << my_own_do.marker().c_str() << "\"."); + ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.margin().c_str() << "\", \"" << example::my_own_do.marker().c_str() << "\"."); Debug( libcw_do.pop_margin() ); Debug( my_own_do.pop_margin() ); Debug( example::my_own_do.pop_margin() ); - Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.get_margin() << "\", \"" << libcw::debug::libcw_do.get_marker() << "\"."); - MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.get_margin() << "\", \"" << my_own_do.get_marker() << "\"."); - ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.get_margin() << "\", \"" << example::my_own_do.get_marker() << "\"."); + Dout(dc::warning, "Dout text " << libcw::debug::libcw_do.get_indent() << ", \"" << libcw::debug::libcw_do.margin().c_str() << "\", \"" << libcw::debug::libcw_do.marker().c_str() << "\"."); + MyOwnDout(dc::warning, "MyOwnDout text " << my_own_do.get_indent() << ", \"" << my_own_do.margin().c_str() << "\", \"" << my_own_do.marker().c_str() << "\"."); + ExampleDout(dc::warning, "ExampleDout text " << example::my_own_do.get_indent() << ", \"" << example::my_own_do.margin().c_str() << "\", \"" << example::my_own_do.marker().c_str() << "\"."); // 1.1.2.4 Setting and getting the output stream - Debug( libcw_do.set_margin("> ") ); - Debug( my_own_do.set_margin("* ") ); - Debug( example::my_own_do.set_margin("- ") ); - - Debug( libcw_do.set_marker(": ") ); - Debug( my_own_do.set_marker(": ") ); - Debug( example::my_own_do.set_marker(": ") ); + Debug( libcw_do.margin().assign("> ", 2) ); + Debug( my_own_do.margin().assign("* ", 2) ); + Debug( example::my_own_do.margin().assign("- ", 2) ); + + Debug( libcw_do.marker().assign(": ", 2) ); + Debug( my_own_do.marker().assign(": ", 2) ); + Debug( example::my_own_do.marker().assign(": ", 2) ); Debug( libcw_do.set_indent(0) ); Debug( my_own_do.set_indent(0) ); Index: src/libcwd/testsuite/libcwd.tst/do.re diff -u src/libcwd/testsuite/libcwd.tst/do.re:1.9 src/libcwd/testsuite/libcwd.tst/do.re:1.10 --- src/libcwd/testsuite/libcwd.tst/do.re:1.9 Tue Jan 8 18:20:52 2002 +++ src/libcwd/testsuite/libcwd.tst/do.re Sun Jan 20 08:25:11 2002 @@ -30,21 +30,21 @@ ***********libcw_do*1Alibcw_do1WARNING |marker1| Dout text 8, "***********libcw_do*1Alibcw_do1", "|marker1|". **********my_own_do*1Amy_own_do1WARNING |marker2| MyOwnDout text 11, "**********my_own_do*1Amy_own_do1", "|marker2|". *example::my_own_do*1Aexample::my_own_do1WARNING |marker3| ExampleDout text 13, "*example::my_own_do*1Aexample::my_own_do1", "|marker3|". -1Plibcw_do1***********libcw_do*WARNING |marker1| Dout text 8, "1Plibcw_do1***********libcw_do*", "|marker1|". -1Pmy_own_do1**********my_own_do*WARNING |marker2| MyOwnDout text 11, "1Pmy_own_do1**********my_own_do*", "|marker2|". -1Pexample::my_own_do1*example::my_own_do*WARNING |marker3| ExampleDout text 13, "1Pexample::my_own_do1*example::my_own_do*", "|marker3|". +1Plibcw_do1***********libcw_do*1Alibcw_do1WARNING |marker1| Dout text 8, "1Plibcw_do1***********libcw_do*1Alibcw_do1", "|marker1|". +1Pmy_own_do1**********my_own_do*1Amy_own_do1WARNING |marker2| MyOwnDout text 11, "1Pmy_own_do1**********my_own_do*1Amy_own_do1", "|marker2|". +1Pexample::my_own_do1*example::my_own_do*1Aexample::my_own_do1WARNING |marker3| ExampleDout text 13, "1Pexample::my_own_do1*example::my_own_do*1Aexample::my_own_do1", "|marker3|". WARNING |marker1| Dout text 8, "", "|marker1|". *WARNING |marker2| MyOwnDout text 11, "*", "|marker2|". XYZWARNING |marker3| ExampleDout text 13, "XYZ", "|marker3|". 2Alibcw_do2WARNING |marker1| Dout text 8, "2Alibcw_do2", "|marker1|". *2Amy_own_do2WARNING |marker2| MyOwnDout text 11, "*2Amy_own_do2", "|marker2|". XYZ2Aexample::my_own_do2WARNING |marker3| ExampleDout text 13, "XYZ2Aexample::my_own_do2", "|marker3|". -1Plibcw_do1***********libcw_do*WARNING |marker1| Dout text 8, "1Plibcw_do1***********libcw_do*", "|marker1|". -1Pmy_own_do1**********my_own_do*WARNING |marker2| MyOwnDout text 11, "1Pmy_own_do1**********my_own_do*", "|marker2|". -1Pexample::my_own_do1*example::my_own_do*WARNING |marker3| ExampleDout text 13, "1Pexample::my_own_do1*example::my_own_do*", "|marker3|". -1Plibcw_do1***********libcw_do*3Alibcw_do3WARNING |marker1| Dout text 8, "1Plibcw_do1***********libcw_do*3Alibcw_do3", "|marker1|". -1Pmy_own_do1**********my_own_do*3Amy_own_do3WARNING |marker2| MyOwnDout text 11, "1Pmy_own_do1**********my_own_do*3Amy_own_do3", "|marker2|". -1Pexample::my_own_do1*example::my_own_do*3Aexample::my_own_do3WARNING |marker3| ExampleDout text 13, "1Pexample::my_own_do1*example::my_own_do*3Aexample::my_own_do3", "|marker3|". +1Plibcw_do1***********libcw_do*1Alibcw_do1WARNING |marker1| Dout text 8, "1Plibcw_do1***********libcw_do*1Alibcw_do1", "|marker1|". +1Pmy_own_do1**********my_own_do*1Amy_own_do1WARNING |marker2| MyOwnDout text 11, "1Pmy_own_do1**********my_own_do*1Amy_own_do1", "|marker2|". +1Pexample::my_own_do1*example::my_own_do*1Aexample::my_own_do1WARNING |marker3| ExampleDout text 13, "1Pexample::my_own_do1*example::my_own_do*1Aexample::my_own_do1", "|marker3|". +1Plibcw_do1***********libcw_do*1Alibcw_do13Alibcw_do3WARNING |marker1| Dout text 8, "1Plibcw_do1***********libcw_do*1Alibcw_do13Alibcw_do3", "|marker1|". +1Pmy_own_do1**********my_own_do*1Amy_own_do13Amy_own_do3WARNING |marker2| MyOwnDout text 11, "1Pmy_own_do1**********my_own_do*1Amy_own_do13Amy_own_do3", "|marker2|". +1Pexample::my_own_do1*example::my_own_do*1Aexample::my_own_do13Aexample::my_own_do3WARNING |marker3| ExampleDout text 13, "1Pexample::my_own_do1*example::my_own_do*1Aexample::my_own_do13Aexample::my_own_do3", "|marker3|". ***********libcw_do*WARNING |marker1| Dout text 8, "***********libcw_do*", "|marker1|". **********my_own_do*WARNING |marker2| MyOwnDout text 11, "**********my_own_do*", "|marker2|". *example::my_own_do*WARNING |marker3| ExampleDout text 13, "*example::my_own_do*", "|marker3|". Index: src/libcwd/testsuite/libcwd.tst/tst.exp diff -u src/libcwd/testsuite/libcwd.tst/tst.exp:1.2 src/libcwd/testsuite/libcwd.tst/tst.exp:1.3 --- src/libcwd/testsuite/libcwd.tst/tst.exp:1.2 Fri Jan 18 21:08:54 2002 +++ src/libcwd/testsuite/libcwd.tst/tst.exp Sun Jan 20 08:25:11 2002 @@ -2,7 +2,7 @@ global SHAREDLIBS STATICLIBS catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles -# set srcfiles $srcdir/$subdir/continued.cc +# set srcfiles $srcdir/$subdir/do.cc verbose "srcfiles are $srcfiles" set prefix "" Index: src/libcwd/utils/exec_prog.cc diff -u src/libcwd/utils/exec_prog.cc:1.22 src/libcwd/utils/exec_prog.cc:1.23 --- src/libcwd/utils/exec_prog.cc:1.22 Fri Jan 18 21:08:54 2002 +++ src/libcwd/utils/exec_prog.cc Sun Jan 20 08:25:11 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/utils/exec_prog.cc,v 1.22 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/utils/exec_prog.cc,v 1.23 2002/01/20 16:25:11 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -156,8 +156,8 @@ #else // !__GLIBCPP__ std::ofstream debug_stream(debug_filedes[1]); #endif // !__GLIBCPP__ - Debug( libcw_do.margin.assign(prog_name, strlen(prog_name)) ); - Debug( libcw_do.margin.append(": ", 2) ); + Debug( libcw_do.margin().assign(prog_name, strlen(prog_name)) ); + Debug( libcw_do.margin().append(": ", 2) ); Debug( libcw_do.set_ostream(&debug_stream) ); #endif // CWDEBUG // Child process ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-20 23:31:30
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-20 23:31:28 UTC Modified files: libcwd/debug.cc libcwd/include/libcw/private_TSD.h Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.56 src/libcwd/debug.cc:1.57 --- src/libcwd/debug.cc:1.56 Sun Jan 20 08:25:11 2002 +++ src/libcwd/debug.cc Sun Jan 20 15:31:18 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.56 2002/01/20 16:25:11 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.57 2002/01/20 23:31:18 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -957,6 +957,8 @@ debug_tsd_st::~debug_tsd_st() { + if (!tsd_initialized) // Don't de-initialize when it wasn't initialized. + return; // Sanity checks: if (continued_stack.size()) DoutFatal( dc::core|cerr_cf, "Destructing debug_tsd_st with a non-empty continued_stack (missing dc::finish?)" ); @@ -1320,15 +1322,20 @@ void assert_fail(char const* expr, char const* file, int line, char const* function) { -#ifdef DEBUGDEBUGMALLOC +#ifdef DEBUGDEBUG LIBCWD_TSD_DECLARATION - if (__libcwd_tsd.recursive) + if (__libcwd_tsd.recursive_assert +#ifdef DEBUGDEBUGMALLOC + || __libcwd_tsd.recursive +#endif + ) { set_alloc_checking_off(LIBCWD_TSD); FATALDEBUGDEBUG_CERR(file << ':' << line << ": " << function << ": Assertion `" << expr << "' failed.\n"); set_alloc_checking_on(LIBCWD_TSD); core_dump(); } + __libcwd_tsd.recursive_assert = true; #endif DoutFatal(dc::core, file << ':' << line << ": " << function << ": Assertion `" << expr << "' failed.\n"); } Index: src/libcwd/include/libcw/private_TSD.h diff -u src/libcwd/include/libcw/private_TSD.h:1.5 src/libcwd/include/libcw/private_TSD.h:1.6 --- src/libcwd/include/libcw/private_TSD.h:1.5 Fri Jan 18 21:08:54 2002 +++ src/libcwd/include/libcw/private_TSD.h Sun Jan 20 15:31:18 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_TSD.h,v 1.5 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_TSD.h,v 1.6 2002/01/20 23:31:18 libcw Exp $ // // Copyright (C) 2001, by // @@ -71,13 +71,16 @@ int internal; int library_call; #ifdef DEBUGDEBUGMALLOC - int recursive; // Used for sanity double checks (also used in debug.cc now). int marker; + int recursive; // Used for sanity double checks in debugmalloc.cc. #endif #endif // DEBUGMALLOC - bool recursive_fatal; + bool recursive_fatal; // Detect loop involving dc::fatal or dc::core. +#ifdef DEBUGDEBUG + bool recursive_assert; // Detect loop involving LIBCWD_ASSERT. +#endif #ifdef LIBCWD_THREAD_SAFE // Directly contained in debug_ct when not threaded. - debug_tsd_st do_array[16]; + debug_tsd_st do_array[16]; // Thread Specific Data of Debug Objects. #endif int off_cnt_array[256]; TSD_st(void) { std::memset(this, 0, sizeof(struct TSD_st)); } ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-21 03:20:35
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-21 03:20:34 UTC Modified files: libcwd/debug.cc libcwd/include/libcw/class_debug.h libcwd/include/libcw/private_threading.h libcwd/include/libcw/struct_debug_tsd.h libcwd/tests/threads.cc Log message: debug_ct is now thread-safe. ---------------------- diff included ---------------------- Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.57 src/libcwd/debug.cc:1.58 --- src/libcwd/debug.cc:1.57 Sun Jan 20 15:31:18 2002 +++ src/libcwd/debug.cc Sun Jan 20 19:20:24 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.57 2002/01/20 23:31:18 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.58 2002/01/21 03:20:24 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -263,6 +263,24 @@ #ifdef LIBCWD_THREAD_SAFE _private_::initialize_global_mutexes(); #endif + + // Fatal channels need to be marked fatal, otherwise we get into an endless loop + // when they are used before they are created. + channels::dc::core.NS_initialize("COREDUMP", coredump_maskbit); + channels::dc::fatal.NS_initialize("FATAL", fatal_maskbit); + // Initialize other debug channels that might be used before we reach main(). + channels::dc::debug.NS_initialize("DEBUG"); + channels::dc::malloc.NS_initialize("MALLOC"); + channels::dc::continued.NS_initialize(continued_maskbit); + channels::dc::finish.NS_initialize(finish_maskbit); +#ifdef DEBUGUSEBFD + channels::dc::bfd.NS_initialize("BFD"); +#endif + // What the heck, initialize all other debug channels too + channels::dc::warning.NS_initialize("WARNING"); + channels::dc::notice.NS_initialize("NOTICE"); + channels::dc::system.NS_initialize("SYSTEM"); + libcw_do.NS_init(); // Initialize debug code. #ifdef DEBUGUSEBFD cwbfd::ST_init(); // Initialize BFD code. @@ -842,6 +860,8 @@ DoutFatal( dc::core, "Don't use `DoutFatal' together with `continued_cf', use `Dout' instead. (This message can also occur when using DoutFatal correctly but from the constructor of a global object)." ); } + int debug_ct::S_index_count = 0; + void debug_ct::NS_init(void) { ST_initialize_globals(); // Because all allocations for global objects are internal these days, we use @@ -871,6 +891,9 @@ new (_private_::WST_dummy_laf) laf_ct(0, channels::dc::debug.get_label(), 0); // Leaks 24 bytes of memory #ifndef LIBCWD_THREAD_SAFE tsd.init(); +#else + WNS_index = ++S_index_count; + __libcwd_tsd.do_array[WNS_index].init(); #endif set_alloc_checking_on(LIBCWD_TSD); @@ -905,32 +928,17 @@ #endif } + debug_tsd_st::debug_tsd_st(void) : _off(0), tsd_initialized(false) { } // Turn off all debugging until initialization is completed. + void debug_tsd_st::init(void) { #ifdef DEBUGDEBUGMALLOC LIBCWD_TSD_DECLARATION LIBCWD_ASSERT( __libcwd_tsd.internal ); #endif - _off = 0; // Turn off all debugging until initialization is completed. - DEBUGDEBUG_CERR( "In debug_tsd_st::NS_init(void), _off set to 0" ); + DEBUGDEBUG_CERR( "In debug_tsd_st::init(void), _off set to 0" ); start_expected = true; // Of course, we start with expecting the beginning of a debug output. - // Fatal channels need to be marked fatal, otherwise we get into an endless loop - // when they are used before they are created. - channels::dc::core.NS_initialize("COREDUMP", coredump_maskbit); - channels::dc::fatal.NS_initialize("FATAL", fatal_maskbit); - // Initialize other debug channels that might be used before we reach main(). - channels::dc::debug.NS_initialize("DEBUG"); - channels::dc::malloc.NS_initialize("MALLOC"); - channels::dc::continued.NS_initialize(continued_maskbit); - channels::dc::finish.NS_initialize(finish_maskbit); -#ifdef DEBUGUSEBFD - channels::dc::bfd.NS_initialize("BFD"); -#endif - // What the heck, initialize all other debug channels too - channels::dc::warning.NS_initialize("WARNING"); - channels::dc::notice.NS_initialize("NOTICE"); - channels::dc::system.NS_initialize("SYSTEM"); // `current' needs to be non-zero (saving us a check in start()) and // current.mask needs to be 0 to avoid a crash in start(): current = reinterpret_cast<laf_ct*>(_private_::WST_dummy_laf); @@ -951,10 +959,22 @@ _off = 0; // Don't print debug output till the REAL initialization of the debug system has been performed // (ie, the _application_ start (don't confuse that with the constructor - which does nothing)). #endif - DEBUGDEBUG_CERR( "After debug_tsd_st::NS_init(void), _off set to " << _off ); + DEBUGDEBUG_CERR( "After debug_tsd_st::init(void), _off set to " << _off ); tsd_initialized = true; } + namespace _private_ { + void debug_tsd_init(void) + { + LIBCWD_TSD_DECLARATION + ForAllDebugObjects( + set_alloc_checking_off(LIBCWD_TSD); + LIBCWD_DO_TSD(debugObject).init(); + set_alloc_checking_on(LIBCWD_TSD); + ); + } + } + debug_tsd_st::~debug_tsd_st() { if (!tsd_initialized) // Don't de-initialize when it wasn't initialized. @@ -1083,9 +1103,6 @@ DEBUGDEBUG_CERR( "Entering `channel_ct::NS_initialize(\"" << label << "\")'" ); - // Of course, dc::debug is off - so this won't do anything unless DEBUGDEBUG is #defined. - Dout( dc::debug, "Initializing channel_ct(\"" << label << "\")" ); - size_t label_len = strlen(label); if (label_len > max_label_len_c) // Only happens for customized channels @@ -1162,9 +1179,6 @@ WNS_maskbit = maskbit; DEBUGDEBUG_CERR( "Entering `fatal_channel_ct::NS_initialize(\"" << label << "\")'" ); - - // Of course, dc::debug is off - so this won't do anything unless DEBUGDEBUG is #defined. - Dout( dc::debug, "Initializing fatal_channel_ct(\"" << label << "\")" ); size_t label_len = strlen(label); Index: src/libcwd/include/libcw/class_debug.h diff -u src/libcwd/include/libcw/class_debug.h:1.6 src/libcwd/include/libcw/class_debug.h:1.7 --- src/libcwd/include/libcw/class_debug.h:1.6 Sun Jan 20 08:25:11 2002 +++ src/libcwd/include/libcw/class_debug.h Sun Jan 20 19:20:24 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.6 2002/01/20 16:25:11 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.7 2002/01/21 03:20:24 libcw Exp $ // // Copyright (C) 2000 - 2002, by // @@ -74,6 +74,7 @@ debug_tsd_st tsd; #else int WNS_index; + static int S_index_count; #endif protected: Index: src/libcwd/include/libcw/private_threading.h diff -u src/libcwd/include/libcw/private_threading.h:1.8 src/libcwd/include/libcw/private_threading.h:1.9 --- src/libcwd/include/libcw/private_threading.h:1.8 Fri Jan 18 21:08:54 2002 +++ src/libcwd/include/libcw/private_threading.h Sun Jan 20 19:20:24 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.8 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.9 2002/01/21 03:20:24 libcw Exp $ // // Copyright (C) 2001, by // @@ -24,6 +24,10 @@ #ifndef LIBCW_PRIVATE_SET_ALLOC_CHECKING_H #include <libcw/private_set_alloc_checking.h> #endif +#ifndef LIBCW_CSTRING +#define LIBCW_CSTRING +#include <cstring> // Needed for std::memset and std::memcpy. +#endif #ifdef LIBCWD_HAVE_PTHREAD #include <pthread.h> @@ -51,10 +55,6 @@ namespace debug { namespace _private_ { -//=================================================================================================== -// Thread Specific Data -// - #ifdef DEBUGDEBUG extern bool WST_multi_threaded; #endif @@ -467,6 +467,8 @@ pthread_key_create(&S_key, S_destroy); } +extern void debug_tsd_init(void); + template<class TSD> TSD* thread_specific_data_tct<TSD>::S_initialize(void) throw() { @@ -477,21 +479,24 @@ mutex_tct<tsd_initialization_instance>::unlock(); return S_temporary_instance; } - TSD new_TSD; - S_temporary_instance = &new_TSD; + char new_TSD_space[sizeof(TSD)]; // Allocate space on the stack. + S_temporary_instance = new (new_TSD_space) TSD; // Create a temporary TSD. S_initializing = true; - set_alloc_checking_off(new_TSD); + LIBCWD_TSD_DECLARATION // This will 'return' the temporary TSD if TSD == TSD_st. + set_alloc_checking_off(LIBCWD_TSD); TSD* instance = new TSD; - set_alloc_checking_on(new_TSD); + set_alloc_checking_on(LIBCWD_TSD); pthread_setspecific(S_key, instance); // Because pthread_setspecific calls calloc, it is possible that in // the mean time all of libcwd was initialized. Therefore we need // to copy the temporary TSD to the real TSD because it might // contain relevant information. - *instance = new_TSD; // This will not call malloc() et al, and thus not change new_TSD while we're copying it. + std::memcpy((void*)instance, new_TSD_space, sizeof(TSD)); // Put the temporary TSD in its final place. S_initializing = false; S_WNS_initialized = true; mutex_tct<tsd_initialization_instance>::unlock(); + if (WST_multi_threaded) // Is this a second (or later) thread? + debug_tsd_init(); // Initialize the TSD of existing debug objects. return instance; } #endif // defined(LIBCWD_USE_POSIX_THREADS) || defined(LIBCWD_USE_LINUXTHREADS) Index: src/libcwd/include/libcw/struct_debug_tsd.h diff -u src/libcwd/include/libcw/struct_debug_tsd.h:1.3 src/libcwd/include/libcw/struct_debug_tsd.h:1.4 --- src/libcwd/include/libcw/struct_debug_tsd.h:1.3 Sun Jan 20 08:25:11 2002 +++ src/libcwd/include/libcw/struct_debug_tsd.h Sun Jan 20 19:20:24 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/struct_debug_tsd.h,v 1.3 2002/01/20 16:25:11 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/struct_debug_tsd.h,v 1.4 2002/01/21 03:20:24 libcw Exp $ // // Copyright (C) 2002, by // @@ -58,6 +58,9 @@ int _off; // Debug output is turned on when this variable is -1, otherwise it is off. + bool tsd_initialized; + // Set after initialization is completed. + #ifdef DEBUGDEBUGOUTPUT // Since with DEBUGDEBUG defined we start with _off is -1 instead of 0, // we need to ignore the call to on() the first time it is called. @@ -108,8 +111,8 @@ void fatal_finish(debug_ct&, channel_set_data_st& LIBCWD_COMMA_TSD_PARAM) __attribute__ ((__noreturn__)); // Initialization and de-initialization. - bool tsd_initialized; void init(void); + debug_tsd_st(void); ~debug_tsd_st(); }; Index: src/libcwd/tests/threads.cc diff -u src/libcwd/tests/threads.cc:1.7 src/libcwd/tests/threads.cc:1.8 --- src/libcwd/tests/threads.cc:1.7 Sat Dec 29 20:17:50 2001 +++ src/libcwd/tests/threads.cc Sun Jan 20 19:20:24 2002 @@ -4,7 +4,6 @@ //#include "sys.h" #include "../include/sys.h" #include "threads_debug.h" -#include <libcw/threading.h> #include <vector> #include <iostream> @@ -94,6 +93,8 @@ // Set Thread Specific on/off flags of the debug channels. ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on(); ); + // And for the debug object. + Debug( libcw_do.on() ); // Serialize incrementation. mutex_tct<test_instance0>::lock(); ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-21 03:28:25
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-21 03:28:19 UTC Modified files: libcwd/tests/threads3.cc libcwd/tests/threads4.cc Log message: Fixes. ---------------------- diff included ---------------------- Index: src/libcwd/tests/threads3.cc diff -u src/libcwd/tests/threads3.cc:1.2 src/libcwd/tests/threads3.cc:1.3 --- src/libcwd/tests/threads3.cc:1.2 Sat Dec 29 20:17:50 2001 +++ src/libcwd/tests/threads3.cc Sun Jan 20 19:28:09 2002 @@ -1,6 +1,5 @@ #include "sys.h" #include "threads_debug.h" -#include <libcw/threading.h> #include <iostream> #ifdef CWDEBUG @@ -17,6 +16,8 @@ { // Set Thread Specific on/off flags of the debug channels. ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on(); ); + // And for the debug object. + Debug( libcw_do.on() ); std::cout << "COUT:Entering thread " << pthread_self() << ":COUT\n"; Dout(dc::notice, "Entering thread " << pthread_self()); Index: src/libcwd/tests/threads4.cc diff -u src/libcwd/tests/threads4.cc:1.2 src/libcwd/tests/threads4.cc:1.3 --- src/libcwd/tests/threads4.cc:1.2 Sat Dec 29 20:17:50 2001 +++ src/libcwd/tests/threads4.cc Sun Jan 20 19:28:09 2002 @@ -1,6 +1,5 @@ #include "sys.h" #include "threads_debug.h" -#include <libcw/threading.h> #include <iostream> #include <sstream> @@ -28,6 +27,8 @@ pthread_t thread_id[number_of_threads2]; // Set Thread Specific on/off flags of the debug channels. ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on(); ); + // And for the debug object. + Debug( libcw_do.on() ); std::cout << "COUT:Entering thread " << pthread_self() << ":COUT\n"; Dout(dc::notice, "Entering thread " << pthread_self()); ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-22 03:10:05
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-22 03:10:04 UTC Modified files: libcwd/tests/threads4.cc Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/tests/threads4.cc diff -u src/libcwd/tests/threads4.cc:1.3 src/libcwd/tests/threads4.cc:1.4 --- src/libcwd/tests/threads4.cc:1.3 Sun Jan 20 19:28:09 2002 +++ src/libcwd/tests/threads4.cc Mon Jan 21 19:09:54 2002 @@ -11,11 +11,13 @@ } #endif +int const loopsize = 1000; int const number_of_threads = 4; int const number_of_threads2 = 4; void* thread_function2(void* arguments) { + Debug( libcw_do.on() ); Dout(dc::hello, "THIS SHOULD NOT BE PRINTED! (tf2)"); Debug(dc::hello.on()); @@ -29,30 +31,38 @@ ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on(); ); // And for the debug object. Debug( libcw_do.on() ); + char margin[32]; + sprintf(margin, "%-10lu", pthread_self()); + Debug( libcw_do.margin().assign(margin, 10) ); - std::cout << "COUT:Entering thread " << pthread_self() << ":COUT\n"; Dout(dc::notice, "Entering thread " << pthread_self()); int cnt = 0; //strstream ss; - for (int i = 0; i < 1000; ++i) + for (int i = 0; i < loopsize; ++i) { + Dout(dc::notice, "Thread " << pthread_self() << " now starting loop " << i); Dout(dc::hello, pthread_self() << ':' << cnt++ << "; This should be printed"); Debug(dc::hello.off()); Debug(dc::hello.off()); Debug(dc::hello.on()); for (int j = 0; j < number_of_threads2; ++j) - pthread_create(&thread_id[i], NULL, thread_function2, NULL); - Dout(dc::hello, "THIS SHOULD NOT BE PRINTED!!!" << (cnt += 2000)); + { + Dout(dc::notice|continued_cf, "thread_function: creating thread " << j << ", "); + pthread_create(&thread_id[j], NULL, thread_function2, NULL); + Dout(dc::finish, "id " << thread_id[j] << '.'); + } + Dout(dc::hello, "THIS SHOULD NOT BE PRINTED!!!" << (cnt += loopsize + 1)); Debug(dc::hello.on()); - for (int i = 0; i < number_of_threads; ++i) + for (int j = 0; j < number_of_threads2; ++j) { void* status; - pthread_join(thread_id[i], &status); - Dout(dc::notice, "Thread " << thread_id[i] << " returned with status " << ((bool)status ? "OK" : "ERROR") << '.'); + pthread_join(thread_id[j], &status); + Dout(dc::notice, "thread_function: thread " << j << ", id " << thread_id[j] << ", returned with status " << ((bool)status ? "OK" : "ERROR") << '.'); } } - return (void *)(cnt == 1000); + Dout(dc::notice, "Leaving thread " << pthread_self()); + return (void *)(cnt == loopsize); } int main(void) @@ -63,20 +73,26 @@ #endif Debug( libcw_do.set_ostream(&std::cout) ); Debug( libcw_do.on() ); + Debug( libcw_do.margin().assign("main ", 10) ); ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on(); ); Debug( list_channels_on(libcw_do) ); pthread_t thread_id[number_of_threads]; for (int i = 0; i < number_of_threads; ++i) + { + Dout(dc::notice|continued_cf, "main: creating thread " << i << ", "); pthread_create(&thread_id[i], NULL, thread_function, NULL); + Dout(dc::finish, "id " << thread_id[i] << '.'); + } for (int i = 0; i < number_of_threads; ++i) { void* status; pthread_join(thread_id[i], &status); - Dout(dc::notice, "Thread " << thread_id[i] << " returned with status " << ((bool)status ? "OK" : "ERROR") << '.'); + Dout(dc::notice, "main loop: thread " << i << ", id " << thread_id[i] << ", returned with status " << ((bool)status ? "OK" : "ERROR") << '.'); } - + + Dout(dc::notice, "Exiting from main()"); return 0; } ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-23 04:03:57
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-23 04:03:55 UTC Modified files: libcwd/debugmalloc.cc libcwd/include/Makefile.am libcwd/include/cwd_debug.h libcwd/include/libcw/Makefile.am libcwd/include/libcw/class_channel.h libcwd/include/libcw/class_channel_set.h libcwd/include/libcw/class_debug.h libcwd/include/libcw/class_location.h libcwd/include/libcw/private_set_alloc_checking.h libcwd/include/libcw/private_threading.h libcwd/include/libcw/struct_debug_tsd.h libcwd/tests/threads4.cc Added files: libcwd/include/raw_write.h libcwd/include/raw_write.inl libcwd/include/libcw/private_struct_TSD.h Removed files: libcwd/include/libcw/private_TSD.h Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.75 src/libcwd/debugmalloc.cc:1.76 --- src/libcwd/debugmalloc.cc:1.75 Sun Jan 20 08:25:11 2002 +++ src/libcwd/debugmalloc.cc Tue Jan 22 20:03:44 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.75 2002/01/20 16:25:11 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.76 2002/01/23 04:03:44 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -173,6 +173,7 @@ #ifdef LIBCWD_THREAD_SAFE using libcw::debug::_private_::rwlock_tct; using libcw::debug::_private_::memblk_map_instance; +#define INITIALIZE_RWLOCK rwlock_tct<memblk_map_instance>::initialize(); #define ACQUIRE_WRITE_LOCK rwlock_tct<memblk_map_instance>::wrlock(); #define RELEASE_WRITE_LOCK rwlock_tct<memblk_map_instance>::wrunlock(); #define ACQUIRE_READ_LOCK rwlock_tct<memblk_map_instance>::rdlock(); @@ -180,6 +181,7 @@ #define ACQUIRE_READ2WRITE_LOCK rwlock_tct<memblk_map_instance>::rd2wrlock(); #define ACQUIRE_WRITE2READ_LOCK rwlock_tct<memblk_map_instance>::wr2rdlock(); #else // !LIBCWD_THREAD_SAFE +#define INITIALIZE_RWLOCK #define ACQUIRE_WRITE_LOCK #define RELEASE_WRITE_LOCK #define ACQUIRE_READ_LOCK @@ -1487,6 +1489,7 @@ // This block is Single Threaded. if (WST_initialization_state == 0) // Only true once. { + INITIALIZE_RWLOCK _private_::set_alloc_checking_off(LIBCWD_TSD); memblk_map.MT_unsafe = new memblk_map_ct; // MT-safe: There are no threads created yet when we get here. WST_initialization_state = -1; Index: src/libcwd/include/Makefile.am diff -u src/libcwd/include/Makefile.am:1.4 src/libcwd/include/Makefile.am:1.5 --- src/libcwd/include/Makefile.am:1.4 Sat Dec 29 20:17:49 2001 +++ src/libcwd/include/Makefile.am Tue Jan 22 20:03:44 2002 @@ -1,7 +1,7 @@ SUBDIRS = libcw BUILT_SOURCES =@MAINTAINER_MODE_TRUE@ sys.ho -EXTRA_DIST = sys.ho.in cwd_debug.h ios_base_Init.h elf32.h exec_prog.h private_debug_stack.inl $(BUILT_SOURCES) +EXTRA_DIST = sys.ho.in cwd_debug.h raw_write.h raw_write.inl ios_base_Init.h elf32.h exec_prog.h private_debug_stack.inl $(BUILT_SOURCES) EXTRA_HEADERS = sys.h DISTCLEANFILES = sys.h sys.ho Index: src/libcwd/include/cwd_debug.h diff -u src/libcwd/include/cwd_debug.h:1.6 src/libcwd/include/cwd_debug.h:1.7 --- src/libcwd/include/cwd_debug.h:1.6 Fri Jan 18 21:08:54 2002 +++ src/libcwd/include/cwd_debug.h Tue Jan 22 20:03:44 2002 @@ -1,5 +1,5 @@ // Generated automatically from sys.ho.in by configure. -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/cwd_debug.h,v 1.6 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/cwd_debug.h,v 1.7 2002/01/23 04:03:44 libcw Exp $ // // Copyright (C) 2001, by // @@ -15,14 +15,19 @@ #ifndef DEBUG_H #define DEBUG_H -#include <libcw/debug.h> -#include <libcw/private_internal_string.h> +#ifndef RAW_WRITE_H +#include <raw_write.h> +#endif +#ifndef RAW_WRITE_INL +#include <raw_write.inl> +#endif #include <iostream> +#ifndef LIBCW_PRIVATE_INTERNAL_STRING_H +#include <libcw/private_internal_string.h> +#endif +#include <libcw/debug.h> extern "C" size_t strlen(const char *s) throw(); -#ifdef DEBUGDEBUG -extern "C" ssize_t write(int fd, const void *buf, size_t count) throw(); -#endif namespace libcw { namespace debug { @@ -128,120 +133,7 @@ LIBCWD_DO_TSD(libcw_do).fatal_finish(libcw_do, channel_set LIBCWD_COMMA_TSD); \ } while(0) -#ifdef DEBUGDEBUG -namespace _private_ { - // Dummy type used as fake 'ostream' to write to write(2). - enum raw_write_nt { raw_write }; -} - -inline _private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, char const* data) -{ - write(2, data, strlen(data)); - return raw_write; -} - -inline _private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, void const* data) -{ - size_t dat = (size_t)data; - write(2, "0x", 2); - char c[11]; - char* p = &c[11]; - do - { - int d = (dat % 16); - *--p = ((d < 10) ? '0' : ('a' - 10)) + d; - dat /= 16; - } - while(dat > 0); - write(2, p, &c[11] - p); - return raw_write; -} - -inline _private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, bool data) -{ - if (data) - write(2, "true", 4); - else - write(2, "false", 5); - return raw_write; -} - -inline _private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, char data) -{ - char c[1]; - c[0] = data; - write(2, c, 1); - return raw_write; -} - -inline _private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, unsigned long data) -{ - char c[11]; - char* p = &c[11]; - do - { - *--p = '0' + (data % 10); - data /= 10; - } - while(data > 0); - write(2, p, &c[11] - p); - return raw_write; -} - -inline _private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, long data) -{ - if (data < 0) - { - write(2, "-", 1); - data = -data; - } - return operator<<(raw_write, (unsigned long)data); -} - -inline _private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, int data) -{ - return operator<<(raw_write, (long)data); -} - -inline _private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, unsigned int data) -{ - return operator<<(raw_write, static_cast<unsigned long>(data)); -} - -inline _private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, libcw::debug::_private_::internal_string const& data) -{ - write(2, data.data(), data.size()); - return raw_write; -} - -#endif // DEBUGDEBUG - } // namespace debug } // namespace libcw - -#ifdef DEBUGDEBUG -// The difference between DEBUGDEBUG_CERR and FATALDEBUGDEBUG_CERR is that the latter is not suppressed -// when --disable-libcwd-debug-output is used because a fatal error occured anyway, so this can't -// disturb the testsuite. -#define FATALDEBUGDEBUG_CERR(x) \ - do { \ - if (1/*::libcw::debug::_private_::WST_ios_base_initialized FIXME: uncomment again*/) { \ - ::write(2, "DEBUGDEBUG: ", 12); \ - LIBCWD_TSD_DECLARATION \ - /* __libcwd_lcwc means library_call write counter. Used to avoid the 'scope of for changed' warning. */ \ - for (int __libcwd_lcwc = 0; __libcwd_lcwc < __libcwd_tsd.library_call; ++__libcwd_lcwc) \ - ::write(2, " ", 4); \ - ::libcw::debug::_private_::raw_write << x << '\n'; \ - } \ - } while(0) -#else // !DEBUGDEBUG -#define FATALDEBUGDEBUG_CERR(x) -#endif // !DEBUGDEBUG - -#ifdef DEBUGDEBUGOUTPUT -#define DEBUGDEBUG_CERR(x) FATALDEBUGDEBUG_CERR(x) -#else // !DEBUGDEBUGOUTPUT -#define DEBUGDEBUG_CERR(x) -#endif // !DEBUGDEBUGOUTPUT #endif // DEBUG_H Index: src/libcwd/include/libcw/Makefile.am diff -u src/libcwd/include/libcw/Makefile.am:1.19 src/libcwd/include/libcw/Makefile.am:1.20 --- src/libcwd/include/libcw/Makefile.am:1.19 Sat Jan 19 18:33:36 2002 +++ src/libcwd/include/libcw/Makefile.am Tue Jan 22 20:03:44 2002 @@ -36,7 +36,6 @@ macro_Libcwd_macros.h \ max_label_len.h \ pc_mangled_function_name.h \ - private_TSD.h \ private_allocator.h \ private_assert.h \ private_debug_stack.h \ @@ -44,6 +43,7 @@ private_internal_stringstream.h \ private_internal_vector.h \ private_set_alloc_checking.h \ + private_struct_TSD.h \ private_threading.h \ strerrno.h \ struct_debug_tsd.h \ Index: src/libcwd/include/libcw/class_channel.h diff -u src/libcwd/include/libcw/class_channel.h:1.4 src/libcwd/include/libcw/class_channel.h:1.5 --- src/libcwd/include/libcw/class_channel.h:1.4 Fri Jan 11 18:54:42 2002 +++ src/libcwd/include/libcw/class_channel.h Tue Jan 22 20:03:44 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel.h,v 1.4 2002/01/12 02:54:42 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel.h,v 1.5 2002/01/23 04:03:44 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -27,8 +27,8 @@ #ifndef LIBCW_CONTROL_FLAG_H #include <libcw/control_flag.h> #endif -#ifndef LIBCW_PRIVATE_TSD_H -#include <libcw/private_TSD.h> +#ifndef LIBCW_PRIVATE_STRUCT_TSD_H +#include <libcw/private_struct_TSD.h> #endif namespace libcw { Index: src/libcwd/include/libcw/class_channel_set.h diff -u src/libcwd/include/libcw/class_channel_set.h:1.4 src/libcwd/include/libcw/class_channel_set.h:1.5 --- src/libcwd/include/libcw/class_channel_set.h:1.4 Sun Jan 20 08:25:11 2002 +++ src/libcwd/include/libcw/class_channel_set.h Tue Jan 22 20:03:44 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel_set.h,v 1.4 2002/01/20 16:25:11 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_channel_set.h,v 1.5 2002/01/23 04:03:44 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -24,8 +24,8 @@ #ifndef LIBCW_CONTROL_FLAG_H #include <libcw/control_flag.h> #endif -#ifndef LIBCW_PRIVATE_TSD_H -#include <libcw/private_TSD.h> +#ifndef LIBCW_PRIVATE_STRUCT_TSD_H +#include <libcw/private_struct_TSD.h> #endif namespace libcw { Index: src/libcwd/include/libcw/class_debug.h diff -u src/libcwd/include/libcw/class_debug.h:1.7 src/libcwd/include/libcw/class_debug.h:1.8 --- src/libcwd/include/libcw/class_debug.h:1.7 Sun Jan 20 19:20:24 2002 +++ src/libcwd/include/libcw/class_debug.h Tue Jan 22 20:03:44 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.7 2002/01/21 03:20:24 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_debug.h,v 1.8 2002/01/23 04:03:44 libcw Exp $ // // Copyright (C) 2000 - 2002, by // @@ -24,8 +24,8 @@ #ifndef LIBCW_CLASS_CHANNEL_SET_H #include <libcw/class_channel_set.h> #endif -#ifndef LIBCW_PRIVATE_TSD_H -#include <libcw/private_TSD.h> +#ifndef LIBCW_PRIVATE_STRUCT_TSD_H +#include <libcw/private_struct_TSD.h> #endif #ifndef LIBCW_STRUCT_DEBUG_TSD #include <libcw/struct_debug_tsd.h> Index: src/libcwd/include/libcw/class_location.h diff -u src/libcwd/include/libcw/class_location.h:1.3 src/libcwd/include/libcw/class_location.h:1.4 --- src/libcwd/include/libcw/class_location.h:1.3 Tue Jan 8 15:04:59 2002 +++ src/libcwd/include/libcw/class_location.h Tue Jan 22 20:03:44 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_location.h,v 1.3 2002/01/08 23:04:59 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/class_location.h,v 1.4 2002/01/23 04:03:44 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -21,8 +21,8 @@ #ifndef LIBCW_DEBUG_CONFIG_H #include <libcw/debug_config.h> #endif -#ifndef LIBCW_PRIVATE_TSD_H -#include <libcw/private_TSD.h> +#ifndef LIBCW_PRIVATE_STRUCT_TSD_H +#include <libcw/private_struct_TSD.h> #endif #ifndef LIBCW_STRING #define LIBCW_STRING Index: src/libcwd/include/libcw/private_TSD.h diff -u src/libcwd/include/libcw/private_TSD.h:1.6 src/libcwd/include/libcw/private_TSD.h:removed --- src/libcwd/include/libcw/private_TSD.h:1.6 Sun Jan 20 15:31:18 2002 +++ src/libcwd/include/libcw/private_TSD.h Tue Jan 22 20:03:55 2002 @@ -1,107 +0,0 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/Attic/private_TSD.h,v 1.6 2002/01/20 23:31:18 libcw Exp $ -// -// Copyright (C) 2001, by -// -// Carlo Wood, Run on IRC <ca...@al...> -// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt -// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 -// -// This file may be distributed under the terms of the Q Public License -// version 1.0 as appearing in the file LICENSE.QPL included in the -// packaging of this file. -// - -/** \file libcw/private_TSD.h - * Do not include this header file directly, instead include "\ref preparation_step2 "debug.h"". - */ - -#ifndef LIBCW_TSD_H -#define LIBCW_TSD_H - -#ifndef LIBCW_DEBUG_CONFIG_H -#include <libcw/debug_config.h> -#endif -#ifndef LIBCW_CSTRING -#define LIBCW_CSTRING -#include <cstring> // Needed for std::memset. -#endif - -namespace libcw { - namespace debug { - namespace _private_ { - struct TSD_st; - } - } -} - -// When LIBCWD_THREAD_SAFE is defined then `__libcwd_tsd' is a local variable -// (see LIBCWD_TSD_DECLARATION) or function parameter (LIBCWD_TSD_PARAM and LIBCWD_COMMA_TSD_PARAM). -// This approach means that many function signatures are different because with thread support a -// `__libcwd_tsd' reference needs to be passed. We use several helper macros for this: -#ifdef LIBCWD_THREAD_SAFE - -#define LIBCWD_TSD __libcwd_tsd // Optional `__libcwd_tsd' parameter - // (foo() or foo(__libcwd_tsd)). -#define LIBCWD_COMMA_TSD , LIBCWD_TSD // Idem, but as second or higher parameter. -#define LIBCWD_TSD_PARAM ::libcw::debug::_private_::TSD_st& __libcwd_tsd - // Optional function parameter - // (foo(void) or foo(TSD_st& __libcwd_tsd)). -#define LIBCWD_COMMA_TSD_PARAM , LIBCWD_TSD_PARAM - // Idem, but as second or higher parameter. -#else // !LIBCWD_THREAD_SAFE - -#define LIBCWD_TSD -#define LIBCWD_COMMA_TSD -#define LIBCWD_TSD_PARAM void -#define LIBCWD_COMMA_TSD_PARAM - -#endif // !LIBCWD_THREAD_SAFE - -// This include uses the above macros. -#ifndef LIBCW_STRUCT_DEBUG_TSD -#include <libcw/struct_debug_tsd.h> -#endif - -namespace libcw { - namespace debug { - namespace _private_ { - -struct TSD_st { -#ifdef DEBUGMALLOC - int internal; - int library_call; -#ifdef DEBUGDEBUGMALLOC - int marker; - int recursive; // Used for sanity double checks in debugmalloc.cc. -#endif -#endif // DEBUGMALLOC - bool recursive_fatal; // Detect loop involving dc::fatal or dc::core. -#ifdef DEBUGDEBUG - bool recursive_assert; // Detect loop involving LIBCWD_ASSERT. -#endif -#ifdef LIBCWD_THREAD_SAFE // Directly contained in debug_ct when not threaded. - debug_tsd_st do_array[16]; // Thread Specific Data of Debug Objects. -#endif - int off_cnt_array[256]; - TSD_st(void) { std::memset(this, 0, sizeof(struct TSD_st)); } -}; - -// Thread Specific Data (TSD) is stored in a structure TSD_st -// and is accessed through a reference to `__libcwd_tsd'. -#ifndef LIBCWD_THREAD_SAFE -// When LIBCWD_THREAD_SAFE is not defined then `__libcwd_tsd' is simply a global object in namespace _private_: -extern TSD_st __libcwd_tsd; -#endif -extern int WST_initializing_TSD; - - } // namespace _private_ - } // namespace debug -} // namespace libcw - -#ifndef LIBCWD_THREAD_SAFE -// Put __libcwd_tsd in global namespace because anywhere we always refer to it -// as `__libcwd_tsd' because when LIBCWD_THREAD_SAFE is defined it is local variable. -using ::libcw::debug::_private_::__libcwd_tsd; -#endif - -#endif // LIBCW_TSD_H Index: src/libcwd/include/libcw/private_set_alloc_checking.h diff -u src/libcwd/include/libcw/private_set_alloc_checking.h:1.2 src/libcwd/include/libcw/private_set_alloc_checking.h:1.3 --- src/libcwd/include/libcw/private_set_alloc_checking.h:1.2 Sat Dec 29 20:17:50 2001 +++ src/libcwd/include/libcw/private_set_alloc_checking.h Tue Jan 22 20:03:45 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_set_alloc_checking.h,v 1.2 2001/12/30 04:17:50 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_set_alloc_checking.h,v 1.3 2002/01/23 04:03:45 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -21,8 +21,8 @@ #ifndef LIBCW_DEBUG_CONFIG_H #include <libcw/debug_config.h> #endif -#ifndef LIBCW_PRIVATE_TSD_H -#include <libcw/private_TSD.h> +#ifndef LIBCW_PRIVATE_STRUCT_TSD_H +#include <libcw/private_struct_TSD.h> #endif namespace libcw { Index: src/libcwd/include/libcw/private_struct_TSD.h diff -u /dev/null src/libcwd/include/libcw/private_struct_TSD.h:1.1 --- /dev/null Tue Jan 22 20:03:55 2002 +++ src/libcwd/include/libcw/private_struct_TSD.h Tue Jan 22 20:03:45 2002 @@ -0,0 +1,107 @@ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_struct_TSD.h,v 1.1 2002/01/23 04:03:45 libcw Exp $ +// +// Copyright (C) 2001, by +// +// Carlo Wood, Run on IRC <ca...@al...> +// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt +// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 +// +// This file may be distributed under the terms of the Q Public License +// version 1.0 as appearing in the file LICENSE.QPL included in the +// packaging of this file. +// + +/** \file libcw/private_struct_TSD.h + * Do not include this header file directly, instead include "\ref preparation_step2 "debug.h"". + */ + +#ifndef LIBCW_STRUCT_TSD_H +#define LIBCW_STRUCT_TSD_H + +#ifndef LIBCW_DEBUG_CONFIG_H +#include <libcw/debug_config.h> +#endif +#ifndef LIBCW_CSTRING +#define LIBCW_CSTRING +#include <cstring> // Needed for std::memset. +#endif + +namespace libcw { + namespace debug { + namespace _private_ { + struct TSD_st; + } + } +} + +// When LIBCWD_THREAD_SAFE is defined then `__libcwd_tsd' is a local variable +// (see LIBCWD_TSD_DECLARATION) or function parameter (LIBCWD_TSD_PARAM and LIBCWD_COMMA_TSD_PARAM). +// This approach means that many function signatures are different because with thread support a +// `__libcwd_tsd' reference needs to be passed. We use several helper macros for this: +#ifdef LIBCWD_THREAD_SAFE + +#define LIBCWD_TSD __libcwd_tsd // Optional `__libcwd_tsd' parameter + // (foo() or foo(__libcwd_tsd)). +#define LIBCWD_COMMA_TSD , LIBCWD_TSD // Idem, but as second or higher parameter. +#define LIBCWD_TSD_PARAM ::libcw::debug::_private_::TSD_st& __libcwd_tsd + // Optional function parameter + // (foo(void) or foo(TSD_st& __libcwd_tsd)). +#define LIBCWD_COMMA_TSD_PARAM , LIBCWD_TSD_PARAM + // Idem, but as second or higher parameter. +#else // !LIBCWD_THREAD_SAFE + +#define LIBCWD_TSD +#define LIBCWD_COMMA_TSD +#define LIBCWD_TSD_PARAM void +#define LIBCWD_COMMA_TSD_PARAM + +#endif // !LIBCWD_THREAD_SAFE + +// This include uses the above macros. +#ifndef LIBCW_STRUCT_DEBUG_TSD +#include <libcw/struct_debug_tsd.h> +#endif + +namespace libcw { + namespace debug { + namespace _private_ { + +struct TSD_st { +#ifdef DEBUGMALLOC + int internal; + int library_call; +#ifdef DEBUGDEBUGMALLOC + int marker; + int recursive; // Used for sanity double checks in debugmalloc.cc. +#endif +#endif // DEBUGMALLOC + bool recursive_fatal; // Detect loop involving dc::fatal or dc::core. +#ifdef DEBUGDEBUG + bool recursive_assert; // Detect loop involving LIBCWD_ASSERT. +#endif +#ifdef LIBCWD_THREAD_SAFE // Directly contained in debug_ct when not threaded. + debug_tsd_st do_array[16]; // Thread Specific Data of Debug Objects. +#endif + int off_cnt_array[256]; + TSD_st(void) { std::memset(this, 0, sizeof(struct TSD_st)); } +}; + +// Thread Specific Data (TSD) is stored in a structure TSD_st +// and is accessed through a reference to `__libcwd_tsd'. +#ifndef LIBCWD_THREAD_SAFE +// When LIBCWD_THREAD_SAFE is not defined then `__libcwd_tsd' is simply a global object in namespace _private_: +extern TSD_st __libcwd_tsd; +#endif +extern int WST_initializing_TSD; + + } // namespace _private_ + } // namespace debug +} // namespace libcw + +#ifndef LIBCWD_THREAD_SAFE +// Put __libcwd_tsd in global namespace because anywhere we always refer to it +// as `__libcwd_tsd' because when LIBCWD_THREAD_SAFE is defined it is local variable. +using ::libcw::debug::_private_::__libcwd_tsd; +#endif + +#endif // LIBCW_STRUCT_TSD_H Index: src/libcwd/include/libcw/private_threading.h diff -u src/libcwd/include/libcw/private_threading.h:1.9 src/libcwd/include/libcw/private_threading.h:1.10 --- src/libcwd/include/libcw/private_threading.h:1.9 Sun Jan 20 19:20:24 2002 +++ src/libcwd/include/libcw/private_threading.h Tue Jan 22 20:03:45 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.9 2002/01/21 03:20:24 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.10 2002/01/23 04:03:45 libcw Exp $ // // Copyright (C) 2001, by // @@ -18,12 +18,20 @@ #ifndef LIBCW_PRIVATE_THREADING_H #define LIBCW_PRIVATE_THREADING_H -#ifndef LIBCW_PRIVATE_TSD_H -#include <libcw/private_TSD.h> +#define LIBCWD_NO_INTERNAL_STRING +#include <raw_write.h> +#undef LIBCWD_NO_INTERNAL_STRING + +#ifndef LIBCW_PRIVATE_STRUCT_TSD_H +#include <libcw/private_struct_TSD.h> #endif #ifndef LIBCW_PRIVATE_SET_ALLOC_CHECKING_H #include <libcw/private_set_alloc_checking.h> #endif +#ifndef LIBCW_CASSERT +#define LIBCW_CASSERT +#include <cassert> +#endif #ifndef LIBCW_CSTRING #define LIBCW_CSTRING #include <cstring> // Needed for std::memset and std::memcpy. @@ -31,6 +39,7 @@ #ifdef LIBCWD_HAVE_PTHREAD #include <pthread.h> +#include <semaphore.h> #if defined(PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) && defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP) #define LIBCWD_USE_LINUXTHREADS #else @@ -59,6 +68,33 @@ extern bool WST_multi_threaded; #endif +//=================================================================================================== +// Thread Specific Data. + +#if defined(LIBCWD_USE_POSIX_THREADS) || defined(LIBCWD_USE_LINUXTHREADS) +template<class TSD> + class thread_specific_data_tct { + private: + static pthread_once_t S_key_once; + static pthread_key_t S_key; + static TSD* S_temporary_instance; + static bool S_initializing; + static bool S_WNS_initialized; + static void S_alloc_key(void) throw(); + static TSD* S_initialize(void) throw(); + static void S_destroy(void* tsd_ptr) throw(); + public: + static TSD& instance(void) throw() + { + TSD* instance = reinterpret_cast<TSD*>(pthread_getspecific(S_key)); + if (!instance) + instance = S_initialize(); + return *instance; + } + static bool initialized(void) { return S_WNS_initialized; } + }; +#endif // defined(LIBCWD_USE_POSIX_THREADS) || defined(LIBCWD_USE_LINUXTHREADS) + } // namespace _private_ } // namespace debug } // namespace libcw @@ -137,7 +173,7 @@ debug_channels_instance, // rwlock // Values reserved for read/write locks. reserved_instance_low, - reserved_instance_high = 4 * reserved_instance_low, + reserved_instance_high = 3 * reserved_instance_low, // Values reserved for test executables. test_instance0 = reserved_instance_high, test_instance1, @@ -188,7 +224,15 @@ } static void lock(void) throw() { + if (instance == 22 || instance == 34 || instance == 46) FATALDEBUGDEBUG_CERR(pthread_self() << ": locking mutex " << instance); +#if LIBCWD_DEBUGTHREADS + int res = +#endif pthread_mutex_lock(&S_mutex); +#if LIBCWD_DEBUGTHREADS + assert( res == 0 ); +#endif + if (instance == 22 || instance == 34 || instance == 46) FATALDEBUGDEBUG_CERR(pthread_self() << ": mutex " << instance << " locked"); #ifdef DEBUGDEBUG instance_locked[instance] += 1; #endif @@ -198,7 +242,15 @@ #ifdef DEBUGDEBUG instance_locked[instance] -= 1; #endif + if (instance == 22 || instance == 34 || instance == 46) FATALDEBUGDEBUG_CERR(pthread_self() << ": unlocking mutex " << instance); +#if LIBCWD_DEBUGTHREADS + int res = +#endif pthread_mutex_unlock(&S_mutex); +#if LIBCWD_DEBUGTHREADS + assert( res == 0 ); +#endif + if (instance == 22 || instance == 34 || instance == 46) FATALDEBUGDEBUG_CERR(pthread_self() << ": mutex " << instance << " unlocked"); } }; @@ -280,71 +332,152 @@ class rwlock_tct { private: static int const readers_instance = instance + reserved_instance_low; - static int const writers_instance = instance + 2 * reserved_instance_low; - static int const readers_count_instance = instance + 3 * reserved_instance_low; + static int const readers_count_instance = instance + 2 * reserved_instance_low; + static sem_t S_no_readers_left; // 0: locked, 1: unlocked. static int S_readers_count; static bool S_writer_is_waiting; static pthread_t S_writer_id; + static bool S_WNS_initialized; public: static void initialize(void) throw() { + if (S_WNS_initialized) + return; + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling initialize() instance " << instance); mutex_tct<readers_instance>::initialize(); - mutex_tct<writers_instance>::initialize(); mutex_tct<readers_count_instance>::initialize(); +#if LIBCWD_DEBUGTHREADS + int res = +#endif + sem_init(&S_no_readers_left, 0, 1); + FATALDEBUGDEBUG_CERR("res == " << res << "; &S_no_readers_left = " << (void*)&S_no_readers_left); + int val; + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); + FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); +#if LIBCWD_DEBUGTHREADS + if (res != 0) + FATALDEBUGDEBUG_CERR("res == " << strerror(res) ); + assert( res == 0 ); +#endif + S_WNS_initialized = true; + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving initialize() instance " << instance); } static bool tryrdlock(void) throw() { +#if LIBCWD_DEBUGTHREADS + assert(S_WNS_initialized); +#endif + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::tryrdlock()"); if (instance < end_recursive_types && pthread_equal(S_writer_id, pthread_self())) + { + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); return true; // No error checking is done. + } if (S_writer_is_waiting || !mutex_tct<readers_count_instance>::trylock()) + { + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); return false; - bool success = (++S_readers_count != 1) || mutex_tct<writers_instance>::trylock(); + } + bool success = (++S_readers_count != 1) || (sem_trywait(&S_no_readers_left) == 0); if (!success) S_readers_count = 0; mutex_tct<readers_count_instance>::unlock(); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); return success; } static bool trywrlock(void) throw() { +#if LIBCWD_DEBUGTHREADS + assert(S_WNS_initialized); +#endif + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::trywrlock()"); #ifndef DEBUGDEBUG - return mutex_tct<writers_instance>::trylock(); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()"); + return sem_trywait(&S_no_readers_left) == 0; #else - bool res = mutex_tct<writers_instance>::trylock(); + bool res = (sem_trywait(&S_no_readers_left) == 0); if (res) instance_locked[instance] += 1; + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()"); return res; #endif } static void rdlock(void) throw() { +#if LIBCWD_DEBUGTHREADS + assert(S_WNS_initialized); +#endif + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::rdlock()"); if (instance < end_recursive_types && pthread_equal(S_writer_id, pthread_self())) + { + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdlock() ILLEGAL!"); return; // No error checking is done. + } if (S_writer_is_waiting) { mutex_tct<readers_instance>::lock(); mutex_tct<readers_instance>::unlock(); } mutex_tct<readers_count_instance>::lock(); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Inside readers_count_instance critical area; S_readers_count == " << S_readers_count); if (++S_readers_count == 1) - mutex_tct<writers_instance>::lock(); // Warning: must be done while - // S_readers_count is still locked! + { + int val; + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); + FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait..."); + sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); + } mutex_tct<readers_count_instance>::unlock(); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdlock()"); } static void rdunlock(void) throw() { + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::rdunlock()"); if (instance < end_recursive_types && pthread_equal(S_writer_id, pthread_self())) + { + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdunlock() ILLEGAL!"); return; // No error checking is done. + } mutex_tct<readers_count_instance>::lock(); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Inside readers_count_instance critical area; S_readers_count == " << S_readers_count); if (--S_readers_count == 0) - mutex_tct<writers_instance>::unlock(); + { + int val; + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); + FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_post..."); + sem_post(&S_no_readers_left); + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); + } mutex_tct<readers_count_instance>::unlock(); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdunlock()"); } static void wrlock(void) throw() { +#if LIBCWD_DEBUGTHREADS + assert(S_WNS_initialized); +#endif + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::wrlock()"); mutex_tct<readers_instance>::lock(); // Block new readers, S_writer_is_waiting = true; - mutex_tct<writers_instance>::lock(); // ... while waiting for current readers to - // be finished (if any). + if (1) + { + int val; + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); + FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait..."); + sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); + } if (instance < end_recursive_types) S_writer_id = pthread_self(); S_writer_is_waiting = false; @@ -352,18 +485,32 @@ #ifdef DEBUGDEBUG instance_locked[instance] += 1; #endif + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wrlock()"); } static void wrunlock(void) throw() { + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::wrunlock()"); #ifdef DEBUGDEBUG instance_locked[instance] -= 1; #endif if (instance < end_recursive_types) S_writer_id = 0; - mutex_tct<writers_instance>::unlock(); + if(1) + { + int val; + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); + FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_post..."); + sem_post(&S_no_readers_left); + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); + } + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wrunlock()"); } static void rd2wrlock() throw() { + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::rd2wrlock()"); mutex_tct<readers_count_instance>::lock(); bool inherit_lock = (--S_readers_count == 0); mutex_tct<readers_count_instance>::unlock(); @@ -371,8 +518,17 @@ { mutex_tct<readers_instance>::lock(); // Block new readers, S_writer_is_waiting = true; - mutex_tct<writers_instance>::lock(); // ... while waiting for remaining readers to - // be finished. + if (1) + { + int val; + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); + FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait..."); + sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! + sem_getvalue(&S_no_readers_left, &val); + FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); + } if (instance < end_recursive_types) S_writer_id = pthread_self(); S_writer_is_waiting = false; @@ -381,9 +537,11 @@ #ifdef DEBUGDEBUG instance_locked[instance] += 1; #endif + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rd2wrlock()"); } static void wr2rdlock() throw() { + FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::wr2rdlock()"); #ifdef DEBUGDEBUG instance_locked[instance] -= 1; #endif @@ -392,6 +550,7 @@ S_writer_id = 0; ++S_readers_count; mutex_tct<readers_count_instance>::unlock(); + FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wr2rdlock()"); } }; @@ -404,35 +563,17 @@ template <int instance> pthread_t rwlock_tct<instance>::S_writer_id = 0; +template <int instance> + bool rwlock_tct<instance>::S_WNS_initialized = 0; + +template <int instance> + sem_t rwlock_tct<instance>::S_no_readers_left; + //=================================================================================================== -// -// Thread Specific Data. -// +// Implementation of Thread Specific Data. #if defined(LIBCWD_USE_POSIX_THREADS) || defined(LIBCWD_USE_LINUXTHREADS) template<class TSD> - class thread_specific_data_tct { - private: - static pthread_once_t S_key_once; - static pthread_key_t S_key; - static TSD* S_temporary_instance; - static bool S_initializing; - static bool S_WNS_initialized; - static void S_alloc_key(void) throw(); - static TSD* S_initialize(void) throw(); - static void S_destroy(void* tsd_ptr) throw(); - public: - static TSD& instance(void) throw() - { - TSD* instance = reinterpret_cast<TSD*>(pthread_getspecific(S_key)); - if (!instance) - instance = S_initialize(); - return *instance; - } - static bool initialized(void) { return S_WNS_initialized; } - }; - -template<class TSD> pthread_once_t thread_specific_data_tct<TSD>::S_key_once = PTHREAD_ONCE_INIT; template<class TSD> @@ -500,6 +641,9 @@ return instance; } #endif // defined(LIBCWD_USE_POSIX_THREADS) || defined(LIBCWD_USE_LINUXTHREADS) + +// End of Thread Specific Data +//=================================================================================================== extern void initialize_global_mutexes(void) throw(); Index: src/libcwd/include/libcw/struct_debug_tsd.h diff -u src/libcwd/include/libcw/struct_debug_tsd.h:1.4 src/libcwd/include/libcw/struct_debug_tsd.h:1.5 --- src/libcwd/include/libcw/struct_debug_tsd.h:1.4 Sun Jan 20 19:20:24 2002 +++ src/libcwd/include/libcw/struct_debug_tsd.h Tue Jan 22 20:03:45 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/struct_debug_tsd.h,v 1.4 2002/01/21 03:20:24 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/struct_debug_tsd.h,v 1.5 2002/01/23 04:03:45 libcw Exp $ // // Copyright (C) 2002, by // @@ -26,8 +26,8 @@ #ifndef LIBCW_CLASS_DEBUG_STRING_H #include <libcw/class_debug_string.h> #endif -#ifndef LIBCW_PRIVATE_TSD_H -#include <libcw/private_TSD.h> +#ifndef LIBCW_PRIVATE_STRUCT_TSD_H +#include <libcw/private_struct_TSD.h> #endif #ifndef LIBCW_IOSFWD #define LIBCW_IOSFWD Index: src/libcwd/include/raw_write.h diff -u /dev/null src/libcwd/include/raw_write.h:1.1 --- /dev/null Tue Jan 22 20:03:55 2002 +++ src/libcwd/include/raw_write.h Tue Jan 22 20:03:44 2002 @@ -0,0 +1,90 @@ +// Generated automatically from sys.ho.in by configure. +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/raw_write.h,v 1.1 2002/01/23 04:03:44 libcw Exp $ +// +// Copyright (C) 2001, by +// +// Carlo Wood, Run on IRC <ca...@al...> +// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt +// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 +// +// This file may be distributed under the terms of the Q Public License +// version 1.0 as appearing in the file LICENSE.QPL included in the +// packaging of this file. +// + +#ifndef LIBCW_PRIVATE_THREADING_H +#include <libcw/private_threading.h> +#endif + +#ifndef RAW_WRITE_H +#define RAW_WRITE_H + +#include <libcw/debug_config.h> + +#ifdef DEBUGDEBUG +extern "C" ssize_t write(int fd, const void *buf, size_t count) throw(); + +// The difference between DEBUGDEBUG_CERR and FATALDEBUGDEBUG_CERR is that the latter is not suppressed +// when --disable-libcwd-debug-output is used because a fatal error occured anyway, so this can't +// disturb the testsuite. +#define FATALDEBUGDEBUG_CERR(x) \ + do { \ + if (1/*::libcw::debug::_private_::WST_ios_base_initialized FIXME: uncomment again*/) { \ + ::write(2, "DEBUGDEBUG: ", 12); \ + LIBCWD_TSD_DECLARATION \ + /* __libcwd_lcwc means library_call write counter. Used to avoid the 'scope of for changed' warning. */ \ + for (int __libcwd_lcwc = 0; __libcwd_lcwc < __libcwd_tsd.library_call; ++__libcwd_lcwc) \ + ::write(2, " ", 4); \ + ::libcw::debug::_private_::raw_write << x << '\n'; \ + } \ + } while(0) +#else // !DEBUGDEBUG +#define FATALDEBUGDEBUG_CERR(x) +#endif // !DEBUGDEBUG + +#ifdef DEBUGDEBUGOUTPUT +#define DEBUGDEBUG_CERR(x) FATALDEBUGDEBUG_CERR(x) +#else // !DEBUGDEBUGOUTPUT +#define DEBUGDEBUG_CERR(x) +#endif // !DEBUGDEBUGOUTPUT + +#ifdef DEBUGDEBUG +namespace libcw { + namespace debug { + +namespace _private_ { + // Dummy type used as fake 'ostream' to write to write(2). + enum raw_write_nt { raw_write }; +} + +_private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, char const* data); +_private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, void const* data); +_private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, bool data); +_private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, char data); +_private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, unsigned long data); +_private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, long data); +_private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, int data); +_private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, unsigned int data); + + } // namespace debug +} // namespace libcw +#endif // DEBUGDEBUG + +#endif // RAW_WRITE_H + +#if !defined(LIBCWD_NO_INTERNAL_STRING) && !defined(LIBCWD_RAW_WRITE_INTERNAL_STRING) +#define LIBCWD_RAW_WRITE_INTERNAL_STRING +#ifndef LIBCWD_NO_INTERNAL_STRING +#include <libcw/private_internal_string.h> +#endif +#ifdef DEBUGDEBUG +namespace libcw { + namespace debug { + +_private_::raw_write_nt const& operator<<(_private_::raw_write_nt const& raw_write, libcw::debug::_private_::internal_string const& data); + + } // namespace debug +} // namespace libcw +#endif // DEBUGDEBUG +#endif // !LIBCWD_NO_INTERNAL_STRING + Index: src/libcwd/include/raw_write.inl diff -u /dev/null src/libcwd/include/raw_write.inl:1.1 --- /dev/null Tue Jan 22 20:03:55 2002 +++ src/libcwd/include/raw_write.inl Tue Jan 22 20:03:44 2002 @@ -0,0 +1,125 @@ +// Generated automatically from sys.ho.in by configure. +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/raw_write.inl,v 1.1 2002/01/23 04:03:44 libcw Exp $ +// +// Copyright (C) 2001, by +// +// Carlo Wood, Run on IRC <ca...@al...> +// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt +// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 +// +// This file may be distributed under the terms of the Q Public License +// version 1.0 as appearing in the file LICENSE.QPL included in the +// packaging of this file. +// + +#ifndef RAW_WRITE_INL +#define RAW_WRITE_INL + +#ifdef DEBUGDEBUG + +#ifndef LIBCW_PRIVATE_INTERNAL_STRING_H +#include <libcw/private_internal_string.h> +#endif + +namespace libcw { + namespace debug { + +__inline__ +_private_::raw_write_nt const& +operator<<(_private_::raw_write_nt const& raw_write, char const* data) +{ + write(2, data, strlen(data)); + return raw_write; +} + +__inline__ +_private_::raw_write_nt const& +operator<<(_private_::raw_write_nt const& raw_write, void const* data) +{ + size_t dat = (size_t)data; + write(2, "0x", 2); + char c[11]; + char* p = &c[11]; + do + { + int d = (dat % 16); + *--p = ((d < 10) ? '0' : ('a' - 10)) + d; + dat /= 16; + } + while(dat > 0); + write(2, p, &c[11] - p); + return raw_write; +} + +__inline__ _private_::raw_write_nt const& +operator<<(_private_::raw_write_nt const& raw_write, bool data) +{ + if (data) + write(2, "true", 4); + else + write(2, "false", 5); + return raw_write; +} + +__inline__ _private_::raw_write_nt const& +operator<<(_private_::raw_write_nt const& raw_write, char data) +{ + char c[1]; + c[0] = data; + write(2, c, 1); + return raw_write; +} + +__inline__ _private_::raw_write_nt const& +operator<<(_private_::raw_write_nt const& raw_write, unsigned long data) +{ + char c[11]; + char* p = &c[11]; + do + { + *--p = '0' + (data % 10); + data /= 10; + } + while(data > 0); + write(2, p, &c[11] - p); + return raw_write; +} + +__inline__ +_private_::raw_write_nt const& +operator<<(_private_::raw_write_nt const& raw_write, long data) +{ + if (data < 0) + { + write(2, "-", 1); + data = -data; + } + return operator<<(raw_write, (unsigned long)data); +} + +__inline__ _private_::raw_write_nt const& +operator<<(_private_::raw_write_nt const& raw_write, int data) +{ + return operator<<(raw_write, (long)data); +} + +__inline__ +_private_::raw_write_nt const& +operator<<(_private_::raw_write_nt const& raw_write, unsigned int data) +{ + return operator<<(raw_write, static_cast<unsigned long>(data)); +} + +__inline__ +_private_::raw_write_nt const& +operator<<(_private_::raw_write_nt const& raw_write, libcw::debug::_private_::internal_string const& data) +{ + write(2, data.data(), data.size()); + return raw_write; +} + + } // namespace debug +} // namespace libcw +#endif // DEBUGDEBUG + +#endif // RAW_WRITE_INL Index: src/libcwd/tests/threads4.cc diff -u src/libcwd/tests/threads4.cc:1.4 src/libcwd/tests/threads4.cc:1.5 --- src/libcwd/tests/threads4.cc:1.4 Mon Jan 21 19:09:54 2002 +++ src/libcwd/tests/threads4.cc Tue Jan 22 20:03:45 2002 @@ -12,8 +12,8 @@ #endif int const loopsize = 1000; -int const number_of_threads = 4; -int const number_of_threads2 = 4; +int const number_of_threads = 2; +int const number_of_threads2 = 1; void* thread_function2(void* arguments) { ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-24 05:48:41
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-24 05:48:39 UTC Modified files: libcwd/Makefile.am libcwd/bfd.cc libcwd/include/libcw/Makefile.am libcwd/include/libcw/private_threading.h Added files: libcwd/semwrapper.cc libcwd/include/libcw/semwrapper.h Log message: Work in progress ---------------------- diff included ---------------------- Index: src/libcwd/Makefile.am diff -u src/libcwd/Makefile.am:1.41 src/libcwd/Makefile.am:1.42 --- src/libcwd/Makefile.am:1.41 Tue Jan 8 17:42:21 2002 +++ src/libcwd/Makefile.am Wed Jan 23 21:48:29 2002 @@ -26,6 +26,7 @@ debugmalloc.cc \ demangle.cc \ demangle3.cc \ + semwrapper.cc \ strerrno.cc \ type_info.cc Index: src/libcwd/bfd.cc diff -u src/libcwd/bfd.cc:1.93 src/libcwd/bfd.cc:1.94 --- src/libcwd/bfd.cc:1.93 Fri Jan 18 21:08:54 2002 +++ src/libcwd/bfd.cc Wed Jan 23 21:48:29 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.93 2002/01/19 05:08:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.94 2002/01/24 05:48:29 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -68,6 +68,7 @@ using libcw::debug::_private_::mutex_tct; using libcw::debug::_private_::object_files_instance; using libcw::debug::_private_::dlopen_map_instance; +#define BFD_INITIALIZE_LOCK rwlock_tct<object_files_instance>::initialize(); #define BFD_ACQUIRE_WRITE_LOCK rwlock_tct<object_files_instance>::wrlock(); #define BFD_RELEASE_WRITE_LOCK rwlock_tct<object_files_instance>::wrunlock(); #define BFD_ACQUIRE_READ_LOCK rwlock_tct<object_files_instance>::rdlock(); @@ -77,6 +78,7 @@ #define DLOPEN_MAP_ACQUIRE_LOCK mutex_tct<dlopen_map_instance>::lock(); #define DLOPEN_MAP_RELEASE_LOCK mutex_tct<dlopen_map_instance>::unlock(); #else // !LIBCWD_THREAD_SAFE +#define BFD_INITIALIZE_LOCK #define BFD_ACQUIRE_WRITE_LOCK #define BFD_RELEASE_WRITE_LOCK #define BFD_ACQUIRE_READ_LOCK @@ -1010,6 +1012,7 @@ // but the sanity checks inside the allocators used in load_object_file() // require the lock to be set. Fortunately is therefore also doesn't hurt // that we keep the lock a long time (during the execution of ldd_prog). + BFD_INITIALIZE_LOCK BFD_ACQUIRE_WRITE_LOCK load_object_file(fullpath.value->data(), 0); Index: src/libcwd/include/libcw/Makefile.am diff -u src/libcwd/include/libcw/Makefile.am:1.20 src/libcwd/include/libcw/Makefile.am:1.21 --- src/libcwd/include/libcw/Makefile.am:1.20 Tue Jan 22 20:03:44 2002 +++ src/libcwd/include/libcw/Makefile.am Wed Jan 23 21:48:29 2002 @@ -45,6 +45,7 @@ private_set_alloc_checking.h \ private_struct_TSD.h \ private_threading.h \ + semwrapper.h \ strerrno.h \ struct_debug_tsd.h \ type_info.h Index: src/libcwd/include/libcw/private_threading.h diff -u src/libcwd/include/libcw/private_threading.h:1.10 src/libcwd/include/libcw/private_threading.h:1.11 --- src/libcwd/include/libcw/private_threading.h:1.10 Tue Jan 22 20:03:45 2002 +++ src/libcwd/include/libcw/private_threading.h Wed Jan 23 21:48:29 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.10 2002/01/23 04:03:45 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.11 2002/01/24 05:48:29 libcw Exp $ // // Copyright (C) 2001, by // @@ -39,7 +39,7 @@ #ifdef LIBCWD_HAVE_PTHREAD #include <pthread.h> -#include <semaphore.h> +#include <libcw/semwrapper.h> #if defined(PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) && defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP) #define LIBCWD_USE_LINUXTHREADS #else @@ -60,6 +60,30 @@ #endif #endif +#ifdef LIBCWD_THREAD_SAFE +#define LIBCWD_TSD_INSTANCE ::libcw::debug::_private_::\ + thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::instance() + // For directly passing the `__libcwd_tsd' instance to a function (foo(TSD::instance())). +#define LIBCWD_COMMA_TSD_INSTANCE , LIBCWD_TSD_INSTANCE + // Idem, but as second or higher parameter. +#define LIBCWD_TSD_DECLARATION ::libcw::debug::_private_::\ + TSD_st& __libcwd_tsd(::libcw::debug::_private_::\ + thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::instance()); + // Declaration of local `__libcwd_tsd' structure reference. +#define LIBCWD_DO_TSD(debug_object) (__libcwd_tsd.do_array[(debug_object).WNS_index]) + // For use inside class debug_ct to access member `m'. +#else // !LIBCWD_THREAD_SAFE +#define LIBCWD_TSD_INSTANCE +#define LIBCWD_COMMA_TSD_INSTANCE +#define LIBCWD_TSD_DECLARATION +#define LIBCWD_DO_TSD(debug_object) ((debug_object).tsd) +#endif // !LIBCWD_THREAD_SAFE + +#define LIBCWD_DO_TSD_MEMBER(debug_object, m) (LIBCWD_DO_TSD(debug_object).m) +#define LIBCWD_TSD_MEMBER(m) LIBCWD_DO_TSD_MEMBER(*this, m) + +#ifdef LIBCWD_THREAD_SAFE + namespace libcw { namespace debug { namespace _private_ { @@ -68,9 +92,6 @@ extern bool WST_multi_threaded; #endif -//=================================================================================================== -// Thread Specific Data. - #if defined(LIBCWD_USE_POSIX_THREADS) || defined(LIBCWD_USE_LINUXTHREADS) template<class TSD> class thread_specific_data_tct { @@ -95,42 +116,7 @@ }; #endif // defined(LIBCWD_USE_POSIX_THREADS) || defined(LIBCWD_USE_LINUXTHREADS) - } // namespace _private_ - } // namespace debug -} // namespace libcw - -#ifdef LIBCWD_THREAD_SAFE -#define LIBCWD_TSD_INSTANCE ::libcw::debug::_private_::\ - thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::instance() - // For directly passing the `__libcwd_tsd' instance to a function (foo(TSD::instance())). -#define LIBCWD_COMMA_TSD_INSTANCE , LIBCWD_TSD_INSTANCE - // Idem, but as second or higher parameter. -#define LIBCWD_TSD_DECLARATION ::libcw::debug::_private_::\ - TSD_st& __libcwd_tsd(::libcw::debug::_private_::\ - thread_specific_data_tct< ::libcw::debug::_private_::TSD_st>::instance()); - // Declaration of local `__libcwd_tsd' structure reference. -#define LIBCWD_DO_TSD(debug_object) (__libcwd_tsd.do_array[(debug_object).WNS_index]) - // For use inside class debug_ct to access member `m'. -#else // !LIBCWD_THREAD_SAFE -#define LIBCWD_TSD_INSTANCE -#define LIBCWD_COMMA_TSD_INSTANCE -#define LIBCWD_TSD_DECLARATION -#define LIBCWD_DO_TSD(debug_object) ((debug_object).tsd) -#endif // !LIBCWD_THREAD_SAFE - -#define LIBCWD_DO_TSD_MEMBER(debug_object, m) (LIBCWD_DO_TSD(debug_object).m) -#define LIBCWD_TSD_MEMBER(m) LIBCWD_DO_TSD_MEMBER(*this, m) - -// End of Thread Specific Data //=================================================================================================== - -#ifdef LIBCWD_THREAD_SAFE - -namespace libcw { - namespace debug { - namespace _private_ { - -//=================================================================================================== // // Mutex locking. // @@ -349,10 +335,10 @@ #if LIBCWD_DEBUGTHREADS int res = #endif - sem_init(&S_no_readers_left, 0, 1); + LIBCWD_SEM(init)(&S_no_readers_left, 0, 1); FATALDEBUGDEBUG_CERR("res == " << res << "; &S_no_readers_left = " << (void*)&S_no_readers_left); int val; - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); #if LIBCWD_DEBUGTHREADS @@ -379,7 +365,7 @@ FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); return false; } - bool success = (++S_readers_count != 1) || (sem_trywait(&S_no_readers_left) == 0); + bool success = (++S_readers_count != 1) || (LIBCWD_SEM(trywait)(&S_no_readers_left) == 0); if (!success) S_readers_count = 0; mutex_tct<readers_count_instance>::unlock(); @@ -394,9 +380,9 @@ FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::trywrlock()"); #ifndef DEBUGDEBUG FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()"); - return sem_trywait(&S_no_readers_left) == 0; + return LIBCWD_SEM(trywait)(&S_no_readers_left) == 0; #else - bool res = (sem_trywait(&S_no_readers_left) == 0); + bool res = (LIBCWD_SEM(trywait)(&S_no_readers_left) == 0); if (res) instance_locked[instance] += 1; FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()"); @@ -424,12 +410,12 @@ if (++S_readers_count == 1) { int val; - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait..."); - sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(wait)(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); } mutex_tct<readers_count_instance>::unlock(); @@ -448,12 +434,12 @@ if (--S_readers_count == 0) { int val; - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_post..."); - sem_post(&S_no_readers_left); - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(post)(&S_no_readers_left); + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); } mutex_tct<readers_count_instance>::unlock(); @@ -470,12 +456,12 @@ if (1) { int val; - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait..."); - sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(wait)(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); } if (instance < end_recursive_types) @@ -498,12 +484,12 @@ if(1) { int val; - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_post..."); - sem_post(&S_no_readers_left); - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(post)(&S_no_readers_left); + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); } FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wrunlock()"); @@ -521,12 +507,12 @@ if (1) { int val; - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait..."); - sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! - sem_getvalue(&S_no_readers_left, &val); + LIBCWD_SEM(wait)(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! + LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); } if (instance < end_recursive_types) @@ -650,6 +636,8 @@ } // namespace _private_ } // namespace debug } // namespace libcw + +#undef LIBCWD_SEM #endif // LIBCWD_THREAD_SAFE #endif // LIBCW_PRIVATE_THREADING_H Index: src/libcwd/include/libcw/semwrapper.h diff -u /dev/null src/libcwd/include/libcw/semwrapper.h:1.1 --- /dev/null Wed Jan 23 21:48:39 2002 +++ src/libcwd/include/libcw/semwrapper.h Wed Jan 23 21:48:29 2002 @@ -0,0 +1,53 @@ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/semwrapper.h,v 1.1 2002/01/24 05:48:29 libcw Exp $ +// +// Copyright (C) 2002, by +// +// Carlo Wood, Run on IRC <ca...@al...> +// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt +// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 +// +// This file may be distributed under the terms of the Q Public License +// version 1.0 as appearing in the file LICENSE.QPL included in the +// packaging of this file. +// + +// +// Bug work around. +// See http://sources.redhat.com/ml/binutils/2002-01/msg00???.html +// + +#ifndef LIBCW_SEMWRAPPER_H +#define LIBCW_SEMWRAPPER_H + +#include <semaphore.h> + +namespace libcw { + namespace debug { + namespace _private_ { + +// This bug results in __old_sem_* to be used (in libpthread) +// which can not cause problems as long as we declare enough +// space. +// +// With typedef struct { long int sem_status; int sem_spinlock; } old_sem_t; +// it is garanteed however that sizeof(old_sem_t) <= sizeof(sem_t) and +// thus creating a sem_t variable and passing that to __old_sem_* +// functions can not cause problems. +// +// This wrapper is to make sure that __old_sem_* and __new_sem_* calls +// aren't mixed. + +extern int __libcwd_sem_post_wrapper(sem_t* sem); +extern int __libcwd_sem_init_wrapper(sem_t* sem, int pshared, unsigned int value); +extern int __libcwd_sem_wait_wrapper(sem_t* sem); +extern int __libcwd_sem_trywait_wrapper(sem_t* sem); +extern int __libcwd_sem_getvalue_wrapper(sem_t* __restrict sem, int* __restrict sval); +extern int __libcwd_sem_destroy_wrapper(sem_t* sem); + + } // namespace __private_ + } // namespace debug +} // namespace libcw + +#define LIBCWD_SEM(x) __libcwd_sem_##x##_wrapper + +#endif // LIBCW_SEMWRAPPER_H Index: src/libcwd/semwrapper.cc diff -u /dev/null src/libcwd/semwrapper.cc:1.1 --- /dev/null Wed Jan 23 21:48:39 2002 +++ src/libcwd/semwrapper.cc Wed Jan 23 21:48:29 2002 @@ -0,0 +1,59 @@ +// $Header: /cvsroot/l/li/libcw/src/libcwd/semwrapper.cc,v 1.1 2002/01/24 05:48:29 libcw Exp $ +// +// Copyright (C) 2002, by +// +// Carlo Wood, Run on IRC <ca...@al...> +// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt +// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 +// +// This file may be distributed under the terms of the Q Public License +// version 1.0 as appearing in the file LICENSE.QPL included in the +// packaging of this file. +// + +// +// Bug work around. +// See http://sources.redhat.com/ml/binutils/2002-01/msg00???.html +// + +#include "sys.h" +#include <libcw/semwrapper.h> + +namespace libcw { + namespace debug { + namespace _private_ { + +int __libcwd_sem_post_wrapper(sem_t* sem) +{ + return sem_post(sem); +} + +int __libcwd_sem_init_wrapper(sem_t* sem, int pshared, unsigned int value) +{ + return sem_init(sem, pshared, value); +} + +int __libcwd_sem_wait_wrapper(sem_t* sem) +{ + return sem_wait(sem); +} + +int __libcwd_sem_trywait_wrapper(sem_t* sem) +{ + return sem_trywait(sem); +} + +int __libcwd_sem_getvalue_wrapper(sem_t* __restrict sem, int* __restrict sval) +{ + return sem_getvalue(sem, sval); +} + +int __libcwd_sem_destroy_wrapper(sem_t* sem) +{ + return sem_destroy(sem); +} + + } // namespace __private_ + } // namespace debug +} // namespace libcw + ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-24 21:16:21
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-24 21:16:20 UTC Modified files: libcwd/Makefile.am libcwd/configure.in libcwd/include/libcw/Makefile.am libcwd/include/libcw/private_threading.h libcwd/tests/threads4.cc Removed files: libcwd/semwrapper.cc libcwd/include/libcw/semwrapper.h Log message: Now using a semaphore for rwlock. The problem with __old_sem_post is now solved. We still have dead locks though. ---------------------- diff included ---------------------- Index: src/libcwd/Makefile.am diff -u src/libcwd/Makefile.am:1.42 src/libcwd/Makefile.am:1.43 --- src/libcwd/Makefile.am:1.42 Wed Jan 23 21:48:29 2002 +++ src/libcwd/Makefile.am Thu Jan 24 13:16:09 2002 @@ -26,11 +26,10 @@ debugmalloc.cc \ demangle.cc \ demangle3.cc \ - semwrapper.cc \ strerrno.cc \ type_info.cc -libcwd_la_LDFLAGS = -version-info $(VERSIONINFO) +libcwd_la_LDFLAGS = -version-info $(VERSIONINFO) $(LIB_THREADS_SHARED) libcwd_la_LIBADD = utils/libutils.la Index: src/libcwd/configure.in diff -u src/libcwd/configure.in:1.95 src/libcwd/configure.in:1.96 --- src/libcwd/configure.in:1.95 Fri Jan 11 18:54:42 2002 +++ src/libcwd/configure.in Thu Jan 24 13:16:09 2002 @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_REVISION($Revision: 1.95 $)dnl +AC_REVISION($Revision: 1.96 $)dnl dnl General intialization of `autoconf' varaibles. dnl Ensure that the directory specified with --srcdir was correct @@ -335,6 +335,7 @@ AC_SUBST(CW_CONFIG_HAVE_PTHREADS) CW_CONFIG_HAVE_PTHREADS=undef AC_SUBST(LIB_THREADS) +AC_SUBST(LIB_THREADS_SHARED) if test "$libcwd_config_threading" = yes; then dnl Check if we have POSIX threads @@ -363,6 +364,13 @@ LIBS="$LIBS $LIB_THREADS" AC_CHECK_FUNCS(pthread_kill_other_threads_np) LIBS="$SAVE_LIBS" + + if test "$ac_cv_search_pthread_create" = "none required"; then + dnl Even if nothing is required, we still need to use -lpthread explicitly + dnl while linking a shared library, otherwise the versioning info of + dnl versioned symbols will be missing! This is needed for the sem_* calls. + AC_CHECK_LIB(pthread, pthread_create, [LIB_THREADS_SHARED=-lpthread]) + fi fi dnl This test needs the full set of libraries we just determined. Index: src/libcwd/include/libcw/Makefile.am diff -u src/libcwd/include/libcw/Makefile.am:1.21 src/libcwd/include/libcw/Makefile.am:1.22 --- src/libcwd/include/libcw/Makefile.am:1.21 Wed Jan 23 21:48:29 2002 +++ src/libcwd/include/libcw/Makefile.am Thu Jan 24 13:16:09 2002 @@ -45,7 +45,6 @@ private_set_alloc_checking.h \ private_struct_TSD.h \ private_threading.h \ - semwrapper.h \ strerrno.h \ struct_debug_tsd.h \ type_info.h Index: src/libcwd/include/libcw/private_threading.h diff -u src/libcwd/include/libcw/private_threading.h:1.11 src/libcwd/include/libcw/private_threading.h:1.12 --- src/libcwd/include/libcw/private_threading.h:1.11 Wed Jan 23 21:48:29 2002 +++ src/libcwd/include/libcw/private_threading.h Thu Jan 24 13:16:09 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.11 2002/01/24 05:48:29 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/private_threading.h,v 1.12 2002/01/24 21:16:09 libcw Exp $ // // Copyright (C) 2001, by // @@ -18,9 +18,16 @@ #ifndef LIBCW_PRIVATE_THREADING_H #define LIBCW_PRIVATE_THREADING_H +#define LIBCWD_DEBUGDEBUGRWLOCK 1 + +#if LIBCWD_DEBUGDEBUGRWLOCK #define LIBCWD_NO_INTERNAL_STRING #include <raw_write.h> #undef LIBCWD_NO_INTERNAL_STRING +#define LIBCWD_DEBUGDEBUGRWLOCK_CERR(x) FATALDEBUGDEBUG_CERR(x) +#else +#define LIBCWD_DEBUGDEBUGRWLOCK_CERR(x) +#endif // LIBCWD_DEBUGDEBUGRWLOCK #ifndef LIBCW_PRIVATE_STRUCT_TSD_H #include <libcw/private_struct_TSD.h> @@ -39,7 +46,7 @@ #ifdef LIBCWD_HAVE_PTHREAD #include <pthread.h> -#include <libcw/semwrapper.h> +#include <semaphore.h> #if defined(PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) && defined(PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP) #define LIBCWD_USE_LINUXTHREADS #else @@ -210,7 +217,9 @@ } static void lock(void) throw() { - if (instance == 22 || instance == 34 || instance == 46) FATALDEBUGDEBUG_CERR(pthread_self() << ": locking mutex " << instance); +#if LIBCWD_DEBUGDEBUGRWLOCK + if (instance != tsd_initialization_instance) LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": locking mutex " << instance); +#endif #if LIBCWD_DEBUGTHREADS int res = #endif @@ -218,7 +227,9 @@ #if LIBCWD_DEBUGTHREADS assert( res == 0 ); #endif - if (instance == 22 || instance == 34 || instance == 46) FATALDEBUGDEBUG_CERR(pthread_self() << ": mutex " << instance << " locked"); +#if LIBCWD_DEBUGDEBUGRWLOCK + if (instance != tsd_initialization_instance) LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": mutex " << instance << " locked"); +#endif #ifdef DEBUGDEBUG instance_locked[instance] += 1; #endif @@ -227,8 +238,10 @@ { #ifdef DEBUGDEBUG instance_locked[instance] -= 1; +#endif +#if LIBCWD_DEBUGDEBUGRWLOCK + if (instance != tsd_initialization_instance) LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": unlocking mutex " << instance); #endif - if (instance == 22 || instance == 34 || instance == 46) FATALDEBUGDEBUG_CERR(pthread_self() << ": unlocking mutex " << instance); #if LIBCWD_DEBUGTHREADS int res = #endif @@ -236,7 +249,9 @@ #if LIBCWD_DEBUGTHREADS assert( res == 0 ); #endif - if (instance == 22 || instance == 34 || instance == 46) FATALDEBUGDEBUG_CERR(pthread_self() << ": mutex " << instance << " unlocked"); +#if LIBCWD_DEBUGDEBUGRWLOCK + if (instance != tsd_initialization_instance) LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": mutex " << instance << " unlocked"); +#endif } }; @@ -329,47 +344,48 @@ { if (S_WNS_initialized) return; - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling initialize() instance " << instance); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling initialize() instance " << instance); mutex_tct<readers_instance>::initialize(); mutex_tct<readers_count_instance>::initialize(); #if LIBCWD_DEBUGTHREADS int res = #endif - LIBCWD_SEM(init)(&S_no_readers_left, 0, 1); - FATALDEBUGDEBUG_CERR("res == " << res << "; &S_no_readers_left = " << (void*)&S_no_readers_left); + sem_init(&S_no_readers_left, 0, 1); +#if LIBCWD_DEBUGDEBUGRWLOCK + LIBCWD_DEBUGDEBUGRWLOCK_CERR("res == " << res << "; &S_no_readers_left = " << (void*)&S_no_readers_left); int val; - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); - FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val); +#endif #if LIBCWD_DEBUGTHREADS if (res != 0) - FATALDEBUGDEBUG_CERR("res == " << strerror(res) ); + LIBCWD_DEBUGDEBUGRWLOCK_CERR("res == " << strerror(res) ); assert( res == 0 ); #endif S_WNS_initialized = true; - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving initialize() instance " << instance); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving initialize() instance " << instance); } static bool tryrdlock(void) throw() { #if LIBCWD_DEBUGTHREADS assert(S_WNS_initialized); #endif - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::tryrdlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::tryrdlock()"); if (instance < end_recursive_types && pthread_equal(S_writer_id, pthread_self())) { - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); return true; // No error checking is done. } if (S_writer_is_waiting || !mutex_tct<readers_count_instance>::trylock()) { - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); return false; } - bool success = (++S_readers_count != 1) || (LIBCWD_SEM(trywait)(&S_no_readers_left) == 0); + bool success = (++S_readers_count != 1) || (sem_trywait(&S_no_readers_left) == 0); if (!success) S_readers_count = 0; mutex_tct<readers_count_instance>::unlock(); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::tryrdlock()"); return success; } static bool trywrlock(void) throw() @@ -377,15 +393,15 @@ #if LIBCWD_DEBUGTHREADS assert(S_WNS_initialized); #endif - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::trywrlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::trywrlock()"); #ifndef DEBUGDEBUG - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()"); - return LIBCWD_SEM(trywait)(&S_no_readers_left) == 0; + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()"); + return sem_trywait(&S_no_readers_left) == 0; #else - bool res = (LIBCWD_SEM(trywait)(&S_no_readers_left) == 0); + bool res = (sem_trywait(&S_no_readers_left) == 0); if (res) instance_locked[instance] += 1; - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::trywrlock()"); return res; #endif } @@ -394,10 +410,10 @@ #if LIBCWD_DEBUGTHREADS assert(S_WNS_initialized); #endif - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::rdlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::rdlock()"); if (instance < end_recursive_types && pthread_equal(S_writer_id, pthread_self())) { - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdlock() ILLEGAL!"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdlock() ILLEGAL!"); return; // No error checking is done. } if (S_writer_is_waiting) @@ -406,64 +422,70 @@ mutex_tct<readers_instance>::unlock(); } mutex_tct<readers_count_instance>::lock(); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Inside readers_count_instance critical area; S_readers_count == " << S_readers_count); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Inside readers_count_instance critical area; S_readers_count == " << S_readers_count); if (++S_readers_count == 1) { +#if LIBCWD_DEBUGDEBUGRWLOCK int val; - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); - FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait..."); - LIBCWD_SEM(wait)(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling sem_wait..."); +#endif + sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! +#if LIBCWD_DEBUGDEBUGRWLOCK + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); +#endif } mutex_tct<readers_count_instance>::unlock(); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdlock()"); } static void rdunlock(void) throw() { - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::rdunlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::rdunlock()"); if (instance < end_recursive_types && pthread_equal(S_writer_id, pthread_self())) { - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdunlock() ILLEGAL!"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdunlock() ILLEGAL!"); return; // No error checking is done. } mutex_tct<readers_count_instance>::lock(); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Inside readers_count_instance critical area; S_readers_count == " << S_readers_count); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Inside readers_count_instance critical area; S_readers_count == " << S_readers_count); if (--S_readers_count == 0) { +#if LIBCWD_DEBUGDEBUGRWLOCK int val; - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); - FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_post..."); - LIBCWD_SEM(post)(&S_no_readers_left); - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling sem_post..."); +#endif + sem_post(&S_no_readers_left); +#if LIBCWD_DEBUGDEBUGRWLOCK + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); +#endif } mutex_tct<readers_count_instance>::unlock(); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdunlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rdunlock()"); } static void wrlock(void) throw() { #if LIBCWD_DEBUGTHREADS assert(S_WNS_initialized); #endif - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::wrlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::wrlock()"); mutex_tct<readers_instance>::lock(); // Block new readers, S_writer_is_waiting = true; - if (1) - { - int val; - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); - FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait..."); - LIBCWD_SEM(wait)(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); - } +#if LIBCWD_DEBUGDEBUGRWLOCK + int val; + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling sem_wait..."); +#endif + sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! +#if LIBCWD_DEBUGDEBUGRWLOCK + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); +#endif if (instance < end_recursive_types) S_writer_id = pthread_self(); S_writer_is_waiting = false; @@ -471,11 +493,11 @@ #ifdef DEBUGDEBUG instance_locked[instance] += 1; #endif - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wrlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wrlock()"); } static void wrunlock(void) throw() { - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::wrunlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::wrunlock()"); #ifdef DEBUGDEBUG instance_locked[instance] -= 1; #endif @@ -483,20 +505,23 @@ S_writer_id = 0; if(1) { +#if LIBCWD_DEBUGDEBUGRWLOCK int val; - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); - FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_post..."); - LIBCWD_SEM(post)(&S_no_readers_left); - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling sem_post..."); +#endif + sem_post(&S_no_readers_left); +#if LIBCWD_DEBUGDEBUGRWLOCK + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); +#endif } - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wrunlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wrunlock()"); } static void rd2wrlock() throw() { - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::rd2wrlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::rd2wrlock()"); mutex_tct<readers_count_instance>::lock(); bool inherit_lock = (--S_readers_count == 0); mutex_tct<readers_count_instance>::unlock(); @@ -504,17 +529,17 @@ { mutex_tct<readers_instance>::lock(); // Block new readers, S_writer_is_waiting = true; - if (1) - { - int val; - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val << "; (__sem_value = " << S_no_readers_left.__sem_value << ')'); - FATALDEBUGDEBUG_CERR(pthread_self() << ": S_no_readers_left.__sem_lock: __status = " << S_no_readers_left.__sem_lock.__status << ", __spinlock = " << S_no_readers_left.__sem_lock.__spinlock << ", __sem_waiting = " << S_no_readers_left.__sem_waiting); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling sem_wait..."); - LIBCWD_SEM(wait)(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! - LIBCWD_SEM(getvalue)(&S_no_readers_left, &val); - FATALDEBUGDEBUG_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); - } +#if LIBCWD_DEBUGDEBUGRWLOCK + int val; + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " contains value " << val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling sem_wait..."); +#endif + sem_wait(&S_no_readers_left); // Warning: must be done while S_readers_count is still locked! +#if LIBCWD_DEBUGDEBUGRWLOCK + sem_getvalue(&S_no_readers_left, &val); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": &S_no_readers_left " << &S_no_readers_left << " now contains value " << val); +#endif if (instance < end_recursive_types) S_writer_id = pthread_self(); S_writer_is_waiting = false; @@ -523,11 +548,11 @@ #ifdef DEBUGDEBUG instance_locked[instance] += 1; #endif - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rd2wrlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::rd2wrlock()"); } static void wr2rdlock() throw() { - FATALDEBUGDEBUG_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::wr2rdlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Calling rwlock_tct<" << instance << ">::wr2rdlock()"); #ifdef DEBUGDEBUG instance_locked[instance] -= 1; #endif @@ -536,7 +561,7 @@ S_writer_id = 0; ++S_readers_count; mutex_tct<readers_count_instance>::unlock(); - FATALDEBUGDEBUG_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wr2rdlock()"); + LIBCWD_DEBUGDEBUGRWLOCK_CERR(pthread_self() << ": Leaving rwlock_tct<" << instance << ">::wr2rdlock()"); } }; Index: src/libcwd/include/libcw/semwrapper.h diff -u src/libcwd/include/libcw/semwrapper.h:1.1 src/libcwd/include/libcw/semwrapper.h:removed --- src/libcwd/include/libcw/semwrapper.h:1.1 Wed Jan 23 21:48:29 2002 +++ src/libcwd/include/libcw/semwrapper.h Thu Jan 24 13:16:20 2002 @@ -1,53 +0,0 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/Attic/semwrapper.h,v 1.1 2002/01/24 05:48:29 libcw Exp $ -// -// Copyright (C) 2002, by -// -// Carlo Wood, Run on IRC <ca...@al...> -// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt -// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 -// -// This file may be distributed under the terms of the Q Public License -// version 1.0 as appearing in the file LICENSE.QPL included in the -// packaging of this file. -// - -// -// Bug work around. -// See http://sources.redhat.com/ml/binutils/2002-01/msg00???.html -// - -#ifndef LIBCW_SEMWRAPPER_H -#define LIBCW_SEMWRAPPER_H - -#include <semaphore.h> - -namespace libcw { - namespace debug { - namespace _private_ { - -// This bug results in __old_sem_* to be used (in libpthread) -// which can not cause problems as long as we declare enough -// space. -// -// With typedef struct { long int sem_status; int sem_spinlock; } old_sem_t; -// it is garanteed however that sizeof(old_sem_t) <= sizeof(sem_t) and -// thus creating a sem_t variable and passing that to __old_sem_* -// functions can not cause problems. -// -// This wrapper is to make sure that __old_sem_* and __new_sem_* calls -// aren't mixed. - -extern int __libcwd_sem_post_wrapper(sem_t* sem); -extern int __libcwd_sem_init_wrapper(sem_t* sem, int pshared, unsigned int value); -extern int __libcwd_sem_wait_wrapper(sem_t* sem); -extern int __libcwd_sem_trywait_wrapper(sem_t* sem); -extern int __libcwd_sem_getvalue_wrapper(sem_t* __restrict sem, int* __restrict sval); -extern int __libcwd_sem_destroy_wrapper(sem_t* sem); - - } // namespace __private_ - } // namespace debug -} // namespace libcw - -#define LIBCWD_SEM(x) __libcwd_sem_##x##_wrapper - -#endif // LIBCW_SEMWRAPPER_H Index: src/libcwd/semwrapper.cc diff -u src/libcwd/semwrapper.cc:1.1 src/libcwd/semwrapper.cc:removed --- src/libcwd/semwrapper.cc:1.1 Wed Jan 23 21:48:29 2002 +++ src/libcwd/semwrapper.cc Thu Jan 24 13:16:20 2002 @@ -1,59 +0,0 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/Attic/semwrapper.cc,v 1.1 2002/01/24 05:48:29 libcw Exp $ -// -// Copyright (C) 2002, by -// -// Carlo Wood, Run on IRC <ca...@al...> -// RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt -// Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 -// -// This file may be distributed under the terms of the Q Public License -// version 1.0 as appearing in the file LICENSE.QPL included in the -// packaging of this file. -// - -// -// Bug work around. -// See http://sources.redhat.com/ml/binutils/2002-01/msg00???.html -// - -#include "sys.h" -#include <libcw/semwrapper.h> - -namespace libcw { - namespace debug { - namespace _private_ { - -int __libcwd_sem_post_wrapper(sem_t* sem) -{ - return sem_post(sem); -} - -int __libcwd_sem_init_wrapper(sem_t* sem, int pshared, unsigned int value) -{ - return sem_init(sem, pshared, value); -} - -int __libcwd_sem_wait_wrapper(sem_t* sem) -{ - return sem_wait(sem); -} - -int __libcwd_sem_trywait_wrapper(sem_t* sem) -{ - return sem_trywait(sem); -} - -int __libcwd_sem_getvalue_wrapper(sem_t* __restrict sem, int* __restrict sval) -{ - return sem_getvalue(sem, sval); -} - -int __libcwd_sem_destroy_wrapper(sem_t* sem) -{ - return sem_destroy(sem); -} - - } // namespace __private_ - } // namespace debug -} // namespace libcw - Index: src/libcwd/tests/threads4.cc diff -u src/libcwd/tests/threads4.cc:1.5 src/libcwd/tests/threads4.cc:1.6 --- src/libcwd/tests/threads4.cc:1.5 Tue Jan 22 20:03:45 2002 +++ src/libcwd/tests/threads4.cc Thu Jan 24 13:16:10 2002 @@ -13,7 +13,7 @@ int const loopsize = 1000; int const number_of_threads = 2; -int const number_of_threads2 = 1; +int const number_of_threads2 = 2; void* thread_function2(void* arguments) { ----------------------- End of diff ----------------------- |