Thread: [libcw-cvs] [CVS] Module src (Page 2)
Abandoned project
Status: Beta
Brought to you by:
libcw
From: Carlo W. <li...@us...> - 2001-12-27 05:17:46
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-27 05:17:46 UTC Modified files: Tag: branch-threading libcwd/debug.cc libcwd/debugmalloc.cc libcwd/elf32.cc Log message: Fix compilation when configured with --disable-libcwd-location ---------------------- diff included ---------------------- Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.46.2.41 src/libcwd/debug.cc:1.46.2.42 --- src/libcwd/debug.cc:1.46.2.41 Fri Dec 7 18:06:22 2001 +++ src/libcwd/debug.cc Wed Dec 26 21:17:35 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.46.2.41 2001/12/08 02:06:22 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.46.2.42 2001/12/27 05:17:35 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -899,7 +899,9 @@ 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"); @@ -1292,14 +1294,24 @@ channel_set_st& debug_ct::operator|(fatal_channel_ct const&) { +#ifdef DEBUGUSEBFD DoutFatal(dc::fatal, location_ct((char*)__builtin_return_address(0) + libcw::debug::builtin_return_address_offset) << " : Don't use Dout together with dc::core or dc::fatal! Use DoutFatal instead."); +#else + DoutFatal(dc::core, + "Don't use Dout together with dc::core or dc::fatal! Use DoutFatal instead."); +#endif } channel_set_st& debug_ct::operator&(channel_ct const&) { +#ifdef DEBUGUSEBFD DoutFatal(dc::fatal, location_ct((char*)__builtin_return_address(0) + libcw::debug::builtin_return_address_offset) << - " : Use dc::core or dc::fatal together with DoutFatal."); + " : Use dc::core or dc::fatal together with DoutFatal."); +#else + DoutFatal(dc::core, + "Use dc::core or dc::fatal together with DoutFatal."); +#endif } namespace _private_ { Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.61.2.47 src/libcwd/debugmalloc.cc:1.61.2.48 --- src/libcwd/debugmalloc.cc:1.61.2.47 Fri Dec 7 18:06:22 2001 +++ src/libcwd/debugmalloc.cc Wed Dec 26 21:17:35 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.61.2.47 2001/12/08 02:06:22 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.61.2.48 2001/12/27 05:17:35 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -839,6 +839,7 @@ extern void demangle_symbol(char const* in, _private_::internal_string& out); +#ifdef DEBUGUSEBFD struct dm_location_ct : public location_ct { void print_on(std::ostream& os) const; friend _private_::no_alloc_ostream_ct& operator<<(_private_::no_alloc_ostream_ct& os, dm_location_ct const& data); @@ -846,9 +847,11 @@ friend _private_::non_allocating_fake_ostream_using_write_ct const& operator<<(_private_::non_allocating_fake_ostream_using_write_ct const& os, dm_location_ct const& data); #endif }; +#endif // DEBUGUSEBFD static char const* const twentyfive_spaces_c = " "; +#ifdef DEBUGUSEBFD _private_::no_alloc_ostream_ct& operator<<(_private_::no_alloc_ostream_ct& os, dm_location_ct const& data) { size_t len = strlen(data.M_filename); @@ -887,7 +890,8 @@ write(2, twentyfive_spaces_c, cnt); return raw_write; } -#endif +#endif // DEBUGDEBUGOUTPUT +#endif // DEBUGUSEBFD void dm_alloc_ct::print_description(LIBCWD_TSD_PARAM) const { Index: src/libcwd/elf32.cc diff -u src/libcwd/elf32.cc:1.20.2.21 src/libcwd/elf32.cc:1.20.2.22 --- src/libcwd/elf32.cc:1.20.2.21 Wed Dec 5 22:01:15 2001 +++ src/libcwd/elf32.cc Wed Dec 26 21:17:35 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.20.2.21 2001/12/06 06:01:15 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.20.2.22 2001/12/27 05:17:35 libcw Exp $ // // Copyright (C) 2001, by // @@ -18,7 +18,7 @@ #include <libcw/debug_config.h> -#ifndef DEBUGUSEGNULIBBFD +#if defined(DEBUGUSEBFD) && !defined(DEBUGUSEGNULIBBFD) #include "sys.h" #include <inttypes.h> // ISO C99 header, needed for int32_t etc. @@ -1890,4 +1890,4 @@ } // namespace debug } // namespace libcw -#endif // !DEBUGUSEGNULIBBFD +#endif // DEBUGUSEBFD && !DEBUGUSEGNULIBBFD ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-27 05:24:58
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-27 05:24:57 UTC Modified files: libcwd/debug.cc libcwd/elf32.cc Log message: Fix compilation when configured with --disable-libcwd-location ---------------------- diff included ---------------------- Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.47 src/libcwd/debug.cc:1.48 --- src/libcwd/debug.cc:1.47 Sat Sep 22 21:13:50 2001 +++ src/libcwd/debug.cc Wed Dec 26 21:24:47 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.47 2001/09/23 04:13:50 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.48 2001/12/27 05:24:47 libcw Exp $ // // Copyright (C) 2000, by // @@ -29,7 +29,7 @@ #endif #endif // CWDEBUG -RCSTAG_CC("$Id: debug.cc,v 1.47 2001/09/23 04:13:50 libcw Exp $") +RCSTAG_CC("$Id: debug.cc,v 1.48 2001/12/27 05:24:47 libcw Exp $") using namespace std; @@ -500,7 +500,9 @@ channels::dc::malloc.initialize("MALLOC"); channels::dc::continued.initialize(continued_maskbit); channels::dc::finish.initialize(finish_maskbit); +#ifdef DEBUGUSEBFD channels::dc::bfd.initialize("BFD"); +#endif // What the heck, initialize all other debug channels too channels::dc::warning.initialize("WARNING"); channels::dc::notice.initialize("NOTICE"); @@ -786,14 +788,24 @@ channel_set_st& debug_ct::operator|(fatal_channel_ct const&) { +#ifdef DEBUGUSEBFD DoutFatal(dc::fatal, location_ct((char*)__builtin_return_address(0) + libcw::debug::builtin_return_address_offset) << " : Don't use Dout together with dc::core or dc::fatal! Use DoutFatal instead."); +#else + DoutFatal(dc::core, + "Don't use Dout together with dc::core or dc::fatal! Use DoutFatal instead."); +#endif } channel_set_st& debug_ct::operator&(channel_ct const&) { +#ifdef DEBUGUSEBFD DoutFatal(dc::fatal, location_ct((char*)__builtin_return_address(0) + libcw::debug::builtin_return_address_offset) << - " : Use dc::core or dc::fatal together with DoutFatal."); + " : Use dc::core or dc::fatal together with DoutFatal."); +#else + DoutFatal(dc::core, + "Use dc::core or dc::fatal together with DoutFatal."); +#endif } void buf_st::init(char const* s, size_t l, bool first_time) Index: src/libcwd/elf32.cc diff -u src/libcwd/elf32.cc:1.26 src/libcwd/elf32.cc:1.27 --- src/libcwd/elf32.cc:1.26 Sat Sep 22 22:01:08 2001 +++ src/libcwd/elf32.cc Wed Dec 26 21:24:47 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.26 2001/09/23 05:01:08 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.27 2001/12/27 05:24:47 libcw Exp $ // // Copyright (C) 2001, by // @@ -18,7 +18,7 @@ #include <libcw/debug_config.h> -#ifndef DEBUGUSEGNULIBBFD +#if defined(DEBUGUSEBFD) && !defined(DEBUGUSEGNULIBBFD) #include "sys.h" #include <inttypes.h> // ISO C99 header, needed for int32_t etc. @@ -33,7 +33,7 @@ #include <libcw/debug.h> #include <libcw/elf32.h> -RCSTAG_CC("$Id: elf32.cc,v 1.26 2001/09/23 05:01:08 libcw Exp $") +RCSTAG_CC("$Id: elf32.cc,v 1.27 2001/12/27 05:24:47 libcw Exp $") #define DEBUGELF32 0 #define DEBUGSTABS 0 @@ -1845,4 +1845,4 @@ } // namespace debug } // namespace libcw -#endif // !DEBUGUSEGNULIBBFD +#endif // DEBUGUSEBFD && !DEBUGUSEGNULIBBFD ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-28 04:12:11
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-28 04:12:10 UTC Modified files: Tag: branch-threading libcwd/documentation/Makefile libcwd/documentation/magic.dox Added files: Tag: branch-threading libcwd/documentation/images/libcw_magic.png libcwd/documentation/images/toc.png libcwd/documentation/images/wink.gif libcwd/documentation/images/buttons/lr_index.png libcwd/documentation/images/buttons/lr_next.png libcwd/documentation/images/buttons/lr_prev.png libcwd/documentation/images/lines/cat.png libcwd/documentation/images/lines/caterpil.png libcwd/documentation/images/lines/ghost.png libcwd/documentation/images/lines/hippo.png libcwd/documentation/images/lines/mouse.png libcwd/documentation/images/lines/owl.png libcwd/documentation/images/lines/snail.png libcwd/documentation/tutorial/.cvsignore libcwd/documentation/tutorial/Makefile libcwd/documentation/tutorial/channel.cc libcwd/documentation/tutorial/faq.m4 libcwd/documentation/tutorial/hello_world.cc libcwd/documentation/tutorial/index.m4 libcwd/documentation/tutorial/intro.m4 libcwd/documentation/tutorial/log_file.cc libcwd/documentation/tutorial/tut1.m4 libcwd/documentation/tutorial/tut2.m4 libcwd/documentation/tutorial/tut3.m4 libcwd/documentation/tutorial/tut4.m4 libcwd/documentation/tutorial/tut5.m4 libcwd/documentation/tutorial/tut6.m4 libcwd/documentation/tutorial/tut7.m4 libcwd/documentation/tutorial/examples5/Makedefs.h libcwd/documentation/tutorial/examples5/Makefile libcwd/documentation/tutorial/examples5/README libcwd/documentation/tutorial/examples5/sysinclude/README libcwd/documentation/tutorial/examples5/sysinclude/libbooster/debug.h libcwd/documentation/tutorial/examples5/sysinclude/libturbo/debug.h libcwd/documentation/tutorial/examples5/tut5.1/.cvsignore libcwd/documentation/tutorial/examples5/tut5.1/Makefile libcwd/documentation/tutorial/examples5/tut5.2/.cvsignore libcwd/documentation/tutorial/examples5/tut5.3/.cvsignore libcwd/documentation/tutorial/examples5/tut5.3/Makefile libcwd/documentation/tutorial/examples5/tut5.4/.cvsignore libcwd/documentation/tutorial/examples5/tut5.4/Makefile libcwd/documentation/tutorial/examples7/Makedefs.h libcwd/documentation/tutorial/examples7/Makefile libcwd/documentation/tutorial/examples7/debug.h libcwd/documentation/tutorial/examples7/sys.h libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore libcwd/documentation/tutorial/examples7/tut7.1/Makefile libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore libcwd/documentation/tutorial/examples7/tut7.2/Makefile libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore libcwd/documentation/tutorial/examples7/tut7.3/Makefile Log message: Added tutorial to the cvs. Using .png instead of .gif where possible. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/Makefile diff -u src/libcwd/documentation/Makefile:1.1.2.3 src/libcwd/documentation/Makefile:1.1.2.4 --- src/libcwd/documentation/Makefile:1.1.2.3 Wed Dec 26 21:13:21 2001 +++ src/libcwd/documentation/Makefile Thu Dec 27 20:11:58 2001 @@ -4,7 +4,9 @@ .PHONY: html external styles tutorial -html: external styles tutorial +all: html tutorial + +html: styles external rm -rf html doxygen doxygen.config mv html/preparation.html html/preparation.tmp Index: src/libcwd/documentation/images/buttons/lr_index.png Index: src/libcwd/documentation/images/buttons/lr_next.png Index: src/libcwd/documentation/images/buttons/lr_prev.png Index: src/libcwd/documentation/images/libcw_magic.png Index: src/libcwd/documentation/images/lines/cat.png Index: src/libcwd/documentation/images/lines/caterpil.png Index: src/libcwd/documentation/images/lines/ghost.png Index: src/libcwd/documentation/images/lines/hippo.png Index: src/libcwd/documentation/images/lines/mouse.png Index: src/libcwd/documentation/images/lines/owl.png Index: src/libcwd/documentation/images/lines/snail.png Index: src/libcwd/documentation/images/toc.png Index: src/libcwd/documentation/images/wink.gif Index: src/libcwd/documentation/magic.dox diff -u src/libcwd/documentation/magic.dox:1.1.2.3 src/libcwd/documentation/magic.dox:1.1.2.4 --- src/libcwd/documentation/magic.dox:1.1.2.3 Wed Dec 26 21:13:21 2001 +++ src/libcwd/documentation/magic.dox Thu Dec 27 20:11:58 2001 @@ -23,7 +23,7 @@ \htmlonly <p STYLE="margin-left: 1.27cm"> <br> -<img width=340 height=165 src="../images/libcw_magic.gif" alt="Memory layout of magic numbers" border=0> +<img width=340 height=165 src="../images/libcw_magic.png" alt="Memory layout of magic numbers" border=0> <br CLEAR=ALL> <br> Figure 1. Memory layout of an allocated memory block with <CODE>DEBUGMAGICMALLOC</CODE> defined. \endhtmlonly Index: src/libcwd/documentation/tutorial/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/.cvsignore:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/.cvsignore Thu Dec 27 20:11:59 2001 @@ -0,0 +1,7 @@ +hello_world +channel +log_file +turn_on +amo.cc +amo +*.html Index: src/libcwd/documentation/tutorial/Makefile diff -u /dev/null src/libcwd/documentation/tutorial/Makefile:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/Makefile Thu Dec 27 20:11:59 2001 @@ -0,0 +1,40 @@ +.SUFFIXES: +.PHONY: examples html + +FILES5:=$(shell grep 'START CODE' tut5.m4 | cut -d \ -f4) +FILES7:=$(shell grep 'START CODE' tut7.m4 | cut -d \ -f4) + +all: examples html + +examples: $(FILES5) $(FILES7) +html: index.html faq.html intro.html tut1.html tut2.html tut3.html tut4.html tut5.html tut6.html tut7.html + +%.html: %.m4 ../definitions.m4 + m4 -D__TUTORIAL=1 -I.. $< > $@ + +$(FILES5): tut5.m4 ../../.libs/libcwd.so + @$(MAKE) $@-x + +$(FILES7): tut7.m4 ../../.libs/libcwd.so + @$(MAKE) -s $@-x + +%-x: + @IN=`echo $* | sed -e 's/examples\([57]\).*/tut\1.m4/'`; \ + grep -A1000 "START CODE $*" $$IN |\ + grep -B1000 "END CODE $*" |\ + egrep -v "(START|END) CODE $*" |\ + sed -e 's/</</g' -e 's/>/>/g' -e 's/&/\&/g' -e 's/"/"/g' -e 's/§/§/g' \ + -e 's/<SPAN.[^>]*>//g' -e 's/<\/SPAN>//g' > $*.tmp; \ + if (test ! -f $* || ! cmp -s $* $*.tmp); then \ + echo "Extracting $* from $$IN."; \ + mv $*.tmp $*; \ + else \ + echo "$* wasn't changed."; \ + touch $*; \ + rm $*.tmp; \ + fi; \ + OUT=`echo $(*F) | sed -e 's/\.[ch]*$$//'`; \ + if test "$$OUT" != "debug"; then \ + $(MAKE) -C $(*D) $$OUT; \ + fi + Index: src/libcwd/documentation/tutorial/channel.cc diff -u /dev/null src/libcwd/documentation/tutorial/channel.cc:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/channel.cc Thu Dec 27 20:11:59 2001 @@ -0,0 +1,26 @@ +// Compile as: g++ -g -DCWDEBUG channel.cc -lcwd [-lbfd -liberty [-ldl]] +// Please see the "example-project" in the source distribution of libcwd +// for a better Real Life example. + +#include <libcw/sysd.h> +#define DEBUGCHANNELS ::example // Where we'll put our namespace dc +#include <libcw/debug.h> + +#ifdef CWDEBUG +namespace example { // namespace dc cannot be put in :: + namespace dc { + libcw::debug::channel_ct ghost("GHOST"); // Create our own Debug Channel + } +} +#endif + +int main(void) +{ + Debug( dc::ghost.on() ); // Remember: don't forget to turn + Debug( libcw_do.on() ); // the debug Channel and Object on! + + for (int i = 0; i < 4; ++i) + Dout( dc::ghost, "i = " << i ); // We can write more than just + // "Hello World" to the ostream :) + return 0; +} Index: src/libcwd/documentation/tutorial/examples5/Makedefs.h diff -u /dev/null src/libcwd/documentation/tutorial/examples5/Makedefs.h:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/Makedefs.h Thu Dec 27 20:11:59 2001 @@ -0,0 +1,107 @@ +# This file contains the Project specific variables. +# +# Extra parameters can be added to the following variables: +# +# CFLAGS, CXXFLAGS, INCLUDEFLAGS, SYSTEMINCLUDEFLAGS, LDFLAGS. +# +# Always use a += for these variables to *add* parameters rather +# than overriding them! + +# +# CFLAGS / CXXFLAGS +# +# Project specific compiler flags. +# +# Use this when profiling: + +##CFLAGS=-pg -O6 -pipe +##CXXFLAGS=-pg -O6 -pipe -fno-exceptions +##LDFLAGS=-pg + +# Add extra, project specific, defines here, etc. + +##CFLAGS+=-D__MYCLIB__ +CXXFLAGS+=-DCWDEBUG + +# +# INCLUDEFLAGS +# +# Project specific "include" flags. +# +# These directories are searched when you use an #include "foobar.h" +# in your source code. +# +# The given directories will be relative to the directory from which +# the compiler is started, which is the directory that the source +# file being compiled is in. Therefore always use -I$(BASEDIR) as +# a prefix (BASEDIR is the directory this file is in). +# +# Note: If you want to add an include directory that is specific for +# only one executable or library, you might want to add this -I flag +# to the Makefile for that executable or library respectively instead. + +INCLUDEFLAGS+=-I$(BASEDIR)/tut5.2 + +# +# SYSTEMINCLUDEFLAGS +# +# Project specific system <include> flags. +# +# These directories are searched when you use a #include <foobar.h> +# in your source code. +# +# Note: If you are writting a library, then you want to use +# #include <yourlib/foobar.h> in your headerfiles, because later on +# these header files are installed in /usr/local/include for instance. +# In that case you need to add -I$(BASEDIR)/include *here* instead +# to in INCLUDEFLAGS above. +# + +SYSTEMINCLUDEFLAGS+=-I$(BASEDIR)/sysinclude -I$(BASEDIR)/../../../include + +# +# LDFLAGS +# +# Project specific linker flags (Overridden flags: -s or -pg ...) +# +# These flags are passed to the compiler at link time, these flags +# are given a default value in $(PROTODIR)/Makedefs.h. You can +# override them here. +# + +LIBPATH:=$(shell (cd $(BASEDIR)/../../../.libs; pwd)) +LDFLAGS=-Wl,-rpath,$(LIBPATH) + +# +# LIBFLAGS +# +# Project specific linker flags (Persistent flags: -L and -Wl,...) +# +# If you want to link your (test) executables with the latest version of +# your project library instead of the version that was actually installed +# in /usr/local (for example), then you need to add -L$(BASEDIR)/lib to +# LIBFLAGS. + +LIBFLAGS+=-L$(BASEDIR)/../../../.libs + +# +# DFLAGS +# +# Extra flags for generating dependencies. +# The default is -MM, only including "local" headers. +# Use this if you need dependencies on <system> headers, +# (for example when you are writing a library and are using <headers> +# with angle brackets yourself). + +##DFLAGS=-M + +# +# CPPEXT +# +# The C++ extension that is used in this project. Correct this! + +CPPEXT=.cc + +# Speed up +.SUFFIXES: + Index: src/libcwd/documentation/tutorial/examples5/Makefile diff -u /dev/null src/libcwd/documentation/tutorial/examples5/Makefile:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/Makefile Thu Dec 27 20:11:59 2001 @@ -0,0 +1,14 @@ +# List of subdirectories (automatically updated by `makeproto'): +SUBDIRS=tut5.1 tut5.3 tut5.4 + +#----------------------------------------------------------------------------- + +include $(PROTODIR)/base/PTMakefile + +# Add here project specific additions: + +#build:: +#depend:: +clean:: + rm -rf tut5.2/debug.o example-* +#real-clean:: Index: src/libcwd/documentation/tutorial/examples5/README diff -u /dev/null src/libcwd/documentation/tutorial/examples5/README:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/README Thu Dec 27 20:11:59 2001 @@ -0,0 +1,10 @@ +In order to compile this you will need to have `prototype' installed. +You can download `prototype' from http://www.xs4all.nl/~carlo17/prototype/ + + +Compile by typing: + +make + +This will create all executables from tutorial 5 in the current directory. + Index: src/libcwd/documentation/tutorial/examples5/sysinclude/README diff -u /dev/null src/libcwd/documentation/tutorial/examples5/sysinclude/README:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/sysinclude/README Thu Dec 27 20:11:59 2001 @@ -0,0 +1,3 @@ +The header files in this directory are NOT examples of how +to write correctly a library headerfile. They are only +included to be able to test the rest. Index: src/libcwd/documentation/tutorial/examples5/sysinclude/libbooster/debug.h diff -u /dev/null src/libcwd/documentation/tutorial/examples5/sysinclude/libbooster/debug.h:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/sysinclude/libbooster/debug.h Thu Dec 27 20:11:59 2001 @@ -0,0 +1,14 @@ +#include <libcw/debug.h> + +namespace booster { + namespace debug { + namespace channels { + namespace dc { + using namespace libcw::debug; + using namespace libcw::debug::channels::dc; + extern channel_ct booster; + extern channel_ct foobar; + } + } + } +} Index: src/libcwd/documentation/tutorial/examples5/sysinclude/libturbo/debug.h diff -u /dev/null src/libcwd/documentation/tutorial/examples5/sysinclude/libturbo/debug.h:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/sysinclude/libturbo/debug.h Thu Dec 27 20:11:59 2001 @@ -0,0 +1,20 @@ +#include <libcw/debug.h> + +namespace turbo { + namespace debug { + namespace channels { + namespace dc { + using namespace libcw::debug; + using namespace libcw::debug::channels::dc; + extern channel_ct turbo; + extern channel_ct foobar; + } + } + } +} + +namespace libcw { + namespace debug { + using namespace turbo::debug; + } +} Index: src/libcwd/documentation/tutorial/examples5/tut5.1/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/examples5/tut5.1/.cvsignore:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/tut5.1/.cvsignore Thu Dec 27 20:11:59 2001 @@ -0,0 +1,2 @@ +turn_on.cc +turn_on Index: src/libcwd/documentation/tutorial/examples5/tut5.1/Makefile diff -u /dev/null src/libcwd/documentation/tutorial/examples5/tut5.1/Makefile:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/tut5.1/Makefile Thu Dec 27 20:11:59 2001 @@ -0,0 +1,30 @@ +# Directory where the base Makefile resides: +BASEDIR=.. + +# List of source files (one per executable): +CSRC= +CXXSRC=turn_on.cc + +# List of subdirectories: +SUBDIRS= + +# Extra static libraries to link with: +STATICLIBS= + +# Extra shared libraries to link with: +SHAREDLIBS=-lcwd + +# Put here extra -L... flags +LIBFLAGS= + +# Extra *.o files that need to be linked: +EXTRA_OBJS= + +#----------------------------------------------------------------------------- + +include $(PROTODIR)/test/PTMakefile + +build:: + ln -f turn_on ../example-5.1 +#clean:: +#depend:: Index: src/libcwd/documentation/tutorial/examples5/tut5.2/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/examples5/tut5.2/.cvsignore:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/tut5.2/.cvsignore Thu Dec 27 20:11:59 2001 @@ -0,0 +1,3 @@ +debug.h +debug.cc +sys.h Index: src/libcwd/documentation/tutorial/examples5/tut5.3/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/examples5/tut5.3/.cvsignore:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/tut5.3/.cvsignore Thu Dec 27 20:11:59 2001 @@ -0,0 +1,4 @@ +test1.cc +test2.cc +test1 +test2 Index: src/libcwd/documentation/tutorial/examples5/tut5.3/Makefile diff -u /dev/null src/libcwd/documentation/tutorial/examples5/tut5.3/Makefile:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/tut5.3/Makefile Thu Dec 27 20:11:59 2001 @@ -0,0 +1,31 @@ +# Directory where the base Makefile resides: +BASEDIR=.. + +# List of source files (one per executable): +CSRC= +CXXSRC=test1.cc test2.cc + +# List of subdirectories: +SUBDIRS= + +# Extra static libraries to link with: +STATICLIBS= + +# Extra shared libraries to link with: +SHAREDLIBS=-lcwd + +# Put here extra -L... flags +LIBFLAGS= + +# Extra *.o files that need to be linked: +EXTRA_OBJS=$(BASEDIR)/tut5.2/debug.o + +#----------------------------------------------------------------------------- + +include $(PROTODIR)/test/PTMakefile + +build:: + ln -f test1 ../example-5.3.1 + ln -f test2 ../example-5.3.2 +#clean:: +#depend:: Index: src/libcwd/documentation/tutorial/examples5/tut5.4/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/examples5/tut5.4/.cvsignore:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/tut5.4/.cvsignore Thu Dec 27 20:11:59 2001 @@ -0,0 +1,16 @@ +test1.cc +test2.cc +test3.cc +test4.cc +test5.cc +test6.cc +test7.cc +test8.cc +test1 +test2 +test3 +test4 +test5 +test6 +test7 +test8 Index: src/libcwd/documentation/tutorial/examples5/tut5.4/Makefile diff -u /dev/null src/libcwd/documentation/tutorial/examples5/tut5.4/Makefile:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples5/tut5.4/Makefile Thu Dec 27 20:11:59 2001 @@ -0,0 +1,36 @@ +# Directory where the base Makefile resides: +BASEDIR=.. + +# List of source files (one per executable): +CSRC= +CXXSRC=test3.cc test4.cc test5.cc test6.cc test7.cc test8.cc + +# List of sub directories: +SUBDIRS= + +# Extra static libraries to link with: +STATICLIBS= + +# Extra shared libraries to link with: +SHAREDLIBS=-lcwd + +# Put here extra -L... flags +LIBFLAGS= + +# Extra *.o files that need to be linked: +EXTRA_OBJS=$(BASEDIR)/tut5.2/debug.o + +#----------------------------------------------------------------------------- + +include $(PROTODIR)/test/PTMakefile + +build:: + ln -f test3 ../example-5.4.1 + ln -f test4 ../example-5.4.2 + ln -f test5 ../example-5.4.3 + ln -f test6 ../example-5.4.4 + ln -f test7 ../example-5.4.5 + ln -f test8 ../example-5.4.6 + +#clean:: +#depend:: Index: src/libcwd/documentation/tutorial/examples7/Makedefs.h diff -u /dev/null src/libcwd/documentation/tutorial/examples7/Makedefs.h:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/Makedefs.h Thu Dec 27 20:12:00 2001 @@ -0,0 +1,103 @@ +# This file contains the Project specific variables. +# +# Extra parameters can be added to the following variables: +# +# CFLAGS, CXXFLAGS, INCLUDEFLAGS, SYSTEMINCLUDEFLAGS, LDFLAGS. +# +# Always use a += for these variables to *add* parameters rather +# than overriding them! + +# +# CFLAGS / CXXFLAGS +# +# Project specific compiler flags. +# +# Use this when profiling: + +##CFLAGS=-pg -O6 -pipe +##CXXFLAGS=-pg -O6 -pipe -fno-exceptions +##LDFLAGS=-pg + +# Add extra, project specific, defines here, etc. + +##CFLAGS+=-D__MYCLIB__ +CXXFLAGS+=-DCWDEBUG + +# +# INCLUDEFLAGS +# +# Project specific "include" flags. +# +# These directories are searched when you use an #include "foobar.h" +# in your source code. +# +# The given directories will be relative to the directory from which +# the compiler is started, which is the directory that the source +# file being compiled is in. Therefore always use -I$(BASEDIR) as +# a prefix (BASEDIR is the directory this file is in). +# +# Note: If you want to add an include directory that is specific for +# only one executable or library, you might want to add this -I flag +# to the Makefile for that executable or library respectively instead. + +INCLUDEFLAGS+=-I$(BASEDIR) + +# +# SYSTEMINCLUDEFLAGS +# +# Project specific system <include> flags. +# +# These directories are searched when you use a #include <foobar.h> +# in your source code. +# +# Note: If you are writting a library, then you want to use +# #include <yourlib/foobar.h> in your headerfiles, because later on +# these header files are installed in /usr/local/include for instance. +# In that case you need to add -I$(BASEDIR)/include *here* instead +# to in INCLUDEFLAGS above. +# + +SYSTEMINCLUDEFLAGS+=-I$(BASEDIR)/sysinclude -I$(BASEDIR)/../../../include + +# +# LDFLAGS +# +# Project specific linker flags (Overridden flags: -s or -pg ...) +# +# These flags are passed to the compiler at link time, these flags +# are given a default value in $(PROTODIR)/Makedefs.h. You can +# override them here. +# + +LIBPATH:=$(shell (cd $(BASEDIR)/../../../.libs; pwd)) +LDFLAGS=-Wl,-rpath,$(LIBPATH) + +# +# LIBFLAGS +# +# Project specific linker flags (Persistent flags: -L and -Wl,...) +# +# If you want to link your (test) executables with the latest version of +# your project library instead of the version that was actually installed +# in /usr/local (for example), then you need to add -L$(BASEDIR)/lib to +# LIBFLAGS. + +LIBFLAGS+=-L$(BASEDIR)/../../../.libs + +# +# DFLAGS +# +# Extra flags for generating dependencies. +# The default is -MM, only including "local" headers. +# Use this if you need dependencies on <system> headers, +# (for example when you are writing a library and are using <headers> +# with angle brackets yourself). + +##DFLAGS=-M + +# +# CPPEXT +# +# The C++ extension that is used in this project. Correct this! + +CPPEXT=.cc Index: src/libcwd/documentation/tutorial/examples7/Makefile diff -u /dev/null src/libcwd/documentation/tutorial/examples7/Makefile:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/Makefile Thu Dec 27 20:12:00 2001 @@ -0,0 +1,13 @@ +# List of subdirectories (automatically updated by `makeproto'): +SUBDIRS=tut7.1 tut7.2 tut7.3 + +#----------------------------------------------------------------------------- + +include $(PROTODIR)/base/PTMakefile + +# Add here project specific additions: + +#build:: +#depend:: +#clean:: +#real-clean:: Index: src/libcwd/documentation/tutorial/examples7/debug.h diff -u /dev/null src/libcwd/documentation/tutorial/examples7/debug.h:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/debug.h Thu Dec 27 20:12:00 2001 @@ -0,0 +1,25 @@ +#ifndef DEBUG_H +#define DEBUG_H + +#ifndef CWDEBUG +#define AllocTag1(p) +#define AllocTag2(p, desc) +#define AllocTag_dynamic_description(p, x) +#define AllocTag(p, x) +#define ASSERT(x) +#define Debug(x) +#define Dout(a, b) +#define DoutFatal(a, b) LibcwDoutFatal(::std, , a, b) +#define ForAllDebugChannels(STATEMENT) +#define ForAllDebugObjects(STATEMENT) +#define LibcwDebug(dc_namespace, x) +#define LibcwDout(a, b, c, d) +#define LibcwDoutFatal(a, b, c, d) do { ::std::cerr << d << ::std::endl; exit(-1); } while(1) +#define NEW(x) new x +#define set_alloc_checking_off() +#define set_alloc_checking_on() +#else +#include <libcw/debug.h> +#endif + +#endif Index: src/libcwd/documentation/tutorial/examples7/sys.h diff -u /dev/null src/libcwd/documentation/tutorial/examples7/sys.h:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/sys.h Thu Dec 27 20:12:00 2001 @@ -0,0 +1,13 @@ +// Bug workaround for libstdc++, avoid warnings like +// /usr/include/g++-3/iostream.h:253:5: "_G_CLOG_CONFLICT" is not defined +#include <_G_config.h> +#ifndef _G_CLOG_CONFLICT +#define _G_CLOG_CONFLICT 0 +#endif +#ifndef _G_HAS_LABS +#define _G_HAS_LABS 1 +#endif + +#ifdef CWDEBUG +#include <libcw/sysd.h> +#endif Index: src/libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore Thu Dec 27 20:12:00 2001 @@ -0,0 +1,6 @@ +invisible.cc +test_delete.cc +coredump.cc +invisible +test_delete +coredump Index: src/libcwd/documentation/tutorial/examples7/tut7.1/Makefile diff -u /dev/null src/libcwd/documentation/tutorial/examples7/tut7.1/Makefile:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.1/Makefile Thu Dec 27 20:12:00 2001 @@ -0,0 +1,33 @@ +# Directory where the base Makefile resides: +BASEDIR=.. + +# List of source files (one per executable): +CSRC= +CXXSRC=invisible.cc coredump.cc test_delete.cc + +# List of sub directories: +SUBDIRS= + +# Extra static libraries to link with: +STATICLIBS= + +# Extra shared libraries to link with: +SHAREDLIBS=-lcwd + +# Put here extra -L... flags +LIBFLAGS= + +# Extra *.o files that need to be linked: +EXTRA_OBJS= + +#----------------------------------------------------------------------------- + +include $(PROTODIR)/test/PTMakefile + +build:: + ln -f invisible ../example-7.1.1 + ln -f coredump ../example-7.1.2 + ln -f test_delete ../example-7.1.3 + +#clean:: +#depend:: Index: src/libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore Thu Dec 27 20:12:00 2001 @@ -0,0 +1,2 @@ +find_alloc.cc +find_alloc Index: src/libcwd/documentation/tutorial/examples7/tut7.2/Makefile diff -u /dev/null src/libcwd/documentation/tutorial/examples7/tut7.2/Makefile:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.2/Makefile Thu Dec 27 20:12:00 2001 @@ -0,0 +1,31 @@ +# Directory where the base Makefile resides: +BASEDIR=.. + +# List of source files (one per executable): +CSRC= +CXXSRC=find_alloc.cc + +# List of sub directories: +SUBDIRS= + +# Extra static libraries to link with: +STATICLIBS= + +# Extra shared libraries to link with: +SHAREDLIBS=-lcwd + +# Put here extra -L... flags +LIBFLAGS= + +# Extra *.o files that need to be linked: +EXTRA_OBJS= + +#----------------------------------------------------------------------------- + +include $(PROTODIR)/test/PTMakefile + +build:: + ln -f find_alloc ../example-7.2 + +#clean:: +#depend:: Index: src/libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore Thu Dec 27 20:12:00 2001 @@ -0,0 +1,10 @@ +total_alloc.cc +memleak.cc +memleak2.cc +marker.cc +marker2.cc +total_alloc +memleak +memleak2 +marker +marker2 Index: src/libcwd/documentation/tutorial/examples7/tut7.3/Makefile diff -u /dev/null src/libcwd/documentation/tutorial/examples7/tut7.3/Makefile:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.3/Makefile Thu Dec 27 20:12:00 2001 @@ -0,0 +1,35 @@ +# Directory where the base Makefile resides: +BASEDIR=.. + +# List of source files (one per executable): +CSRC= +CXXSRC=total_alloc.cc marker.cc marker2.cc memleak.cc memleak2.cc + +# List of sub directories: +SUBDIRS= + +# Extra static libraries to link with: +STATICLIBS= + +# Extra shared libraries to link with: +SHAREDLIBS=-lcwd + +# Put here extra -L... flags +LIBFLAGS= + +# Extra *.o files that need to be linked: +EXTRA_OBJS= + +#----------------------------------------------------------------------------- + +include $(PROTODIR)/test/PTMakefile + +build:: + ln -f total_alloc ../example-7.3.1 + ln -f marker.cc ../example-7.3.2 + ln -f marker2.cc ../example-7.3.3 + ln -f memleak.cc ../example-7.3.4 + ln -f memleak2.cc ../example-7.3.5 + +#clean:: +#depend:: Index: src/libcwd/documentation/tutorial/faq.m4 diff -u /dev/null src/libcwd/documentation/tutorial/faq.m4:1.1.2.1 --- /dev/null Thu Dec 27 20:12:10 2001 +++ src/libcwd/documentation/tutorial/faq.m4 Thu Dec 27 20:11:59 2001 @@ -0,0 +1,440 @@ +include(definitions.m4)dnl +__HTMLHEADER +__PAGEHEADER +__PAGESTART + +<H1>FAQ</H1> + +<P>Warning: The ammount of information included in this FAQ is exhaustive. +Do NOT read it except as a replacement for self-torture. Instead read the +<A HREF="index.html">tutorial</A> and skip all the references to +this FAQ unless you find yourself banging your head into the wall asking yourself +the same question as is listed in the tutorial. In that case a link will +bring you here to read just that one question.</P> + +<HR SIZE=1 NOSHADE> + +<A name="sysd.h"></A> +<H3>1. Why do I have to include "libcw/sysd.h" as first header file?</H3> + +<P>This header file is used to fix operating systems bugs, including bugs +in the system header files. The only way it can do this is when it +is included before <EM>any</EM> other header file, including system header +files.</P> + +<P>This header file defines also a few very important operating system +dependend macros like the ones used for inclusion of the ident string. +Therefore <EM>nothing</EM> will compile without this header file. +Because it must be included in <EM>every</EM> source file as very first +header file, it would make no sense to include it also in another +header file; so it isn't. As a result, forgetting this header file +or including any other libcw header file before including libcw/sysd.h, +will definitely lead to compile errors in that header file. </P> + +<A name="libcwd"></A> +<H3>2. What is this <SPAN class="H3code">libcw</SPAN> talk? +Aren't you forgetting the <U><SPAN class="H3code">d</SPAN></U> of +<SPAN class="H3code">libcw<U>d</U></SPAN>?</H3> + +<P>Libcwd is a spin off of the larger libcw project. +The header files of both are put in the same directory, +called <SPAN class="filename">libcw </SPAN>(for example, +<SPAN class="filename">/usr/include/libcw</SPAN>).</P> + +<P>The <U><SPAN class="code">d</SPAN></U> in +<SPAN class="code">libcw<U>d</U></SPAN> stands for <U>D</U>ebugging. +The <U><SPAN class="code">cw</SPAN></U> in +<SPAN class="code">lib<U>cw</U></SPAN> stand for the initials of +the designer/developer of this life-span project [but I suppose you already +guessed that ;) ].</P> + +<A name="dir"></A> +<H3>3. Why do I need to type "<SPAN class="H3code">libcw/sysd.h</SPAN>" +and not just "<SPAN class="H3code">sysd.h</SPAN>"?</H3> + +<P>The header file names of libcw are not unique. In order to uniquely +identify which header file needs to be included the "libcw/" part +is needed.</P> + +<P>Never use the compiler option <SPAN class="code"><SPAN class="command-line-parameter">-I</SPAN> +<SPAN class="command-line-variable">/usr/include/libcw</SPAN></SPAN> so you can skip +the "libcw/" part in your <SPAN class="code">#include</SPAN> +directives. There is no garantee that there isn't a header file name +collision in that case.</P> + +<A name="debug.h"></A> +<H3>4. What is defined <EM>exactly</EM> in <SPAN class="H3code">libcw/debug.h</SPAN>?</H3> + +<P>Everything. +Go and read the <A HREF="../html/reference.html>Reference Manual</A> to get <EM>all</EM> gory details if you dare.</P> + +<A name="macros"></A> +<H3>5. Why are you using macros for <SPAN class="H3code">Debug</SPAN> and <SPAN class="H3code">Dout</SPAN>?</H3> + +<P>Because it is the only way to easy remove debugging code from an application as function of a macro +and because it allows for the fastest possible code even without optimisation, which is often the case +while debugging. A more detailed explanation is given in the <A HREF="../html/page_why_macro.html">Reference Manual</A>.</P> + +<A name="Debug"></A> +<H3>6. Why do I need to type the <SPAN class="H3code">Debug( )</SPAN> around it?</H3> + +<P>The macro <SPAN class="code">Debug()</SPAN> is used for two things. 1) The code inside it is only included +when the macro <SPAN class="code">CWDEBUG</SPAN> is defined. 2) It includes the namespace <SPAN class="code">libcw::debug</SPAN>.</P> + +<P>As a result, you don't have to add <SPAN class="code">#ifdef CWDEBUG ... #endif</SPAN> around the code and +in most cases you don't have to type <SPAN class="code">libcw::debug</SPAN>. +The expression <SPAN class="code">Debug( STATEMENT );</SPAN> is equivalent with:</P> + +<PRE class="code"> +#ifdef CWDEBUG + do { + using namespace ::libcw::debug; + using namespace DEBUGCHANNELS; + { STATEMENT; } + } while(0); +#endif +</PRE> + +<P>Please note that definitions within a <SPAN class="code">Debug()</SPAN> statement will be +restricted to their own scope. +Please read the <A HREF="../html/group__chapter__custom__debug__h.html">Reference Manual</A> for an +explanation of <SPAN class="code">DEBUGCHANNELS</SPAN>.</P> + +<A name="DebugChannels"></A> +<H3>7. Which Debug Channels exist? Can I make my own?</H3> + +<P>This question is covered in chapter +<A HREF="../html/group__group__debug__channels.html">Controlling The Output Level (Debug Channels)</A> +of the Reference Manual. +As is described there, creating your own debug channels is best done by writing your own <SPAN class="code">debug.h</SPAN> +header file. The following template is a good start for such a <SPAN class="code">debug.h</SPAN> for an end application +(a library needs more work):</P> + +<PRE class="code"> +#ifndef MY_DEBUG_H +#define MY_DEBUG_H + +#define DEBUGCHANNELS ::myapplication::debug::channels +#include <libcw/debug.h> + +namespace myapplication { + namespace debug { + namespace channels { + namespace dc { + using namespace ::libcw::debug::channels::dc; + extern ::libcw::debug::channel_ct mychannel; + // ... more channels here + } + } + } +} + +#endif // MY_DEBUG_H +</PRE> + +<P>Replace «<SPAN class="code">MY_DEBUG_H</SPAN>», +«<SPAN class="code">myapplication::debug</SPAN>» and «<SPAN class="code">mychannel</SPAN>» with your own names. + +<P>See the <SPAN class="filename">example-project</SPAN> that comes +with the source distribution of libcwd for a Real Life example.</P> + +<A name="recursive"></A> +<H3>8. Can I turn Debug Channels off again? Can I do that recursively?</H3> + +<P>Debug channels can be switched on and off at any time. At the start of your program you should +turn on the channels of your choice by calling <SPAN class="code">Debug(dc::<EM>channel</EM>.on())</SPAN> +<EM>once</EM>. Sometimes you want to temporally turn off certain channels: you want to make +sure that no debug output is written to that particular debug channel, at that moment. This can be +achieved by calling the methods <SPAN class="code">off()</SPAN> and <SPAN class="code">on()</SPAN> in +<EM>pairs</EM> and in that order. For example:</P> + +<PRE class="code"> + // Make sure no allocation debug output is generated: + Debug( dc::malloc.off() ); + char* temporal_buffer = new char [1024]; + // ... do stuff ... + delete [] temporal_buffer; + Debug( dc::malloc.on() ); +</PRE> + +<P>This will work even when `do stuff' calls a function that also turns <SPAN class="code">dc::malloc</SPAN> off and on: +after the call to <SPAN class="code">on()</SPAN> the debug channel can still be off: it is restored to the on/off state +that it was in before the corresponding call to <SPAN class="code">off()</SPAN>. In fact, the calls to +<SPAN class="code">off()</SPAN> and <SPAN class="code">on()</SPAN> only respectively increment and decrement a counter.</P> + +<A name="Channel"></A> +<H3>9. Why do you call it a Debug <EM>Channel</EM>? What <EM>is</EM> a Debug Channel?</H3> + +<P>A Debug Channel is a fictious "news channel". It should contain information of a certain kind that is +interesting or not interesting as a whole. A Debug Channel is not a device or stream, a single debug channel is best +viewed upon as a single bit in a bitmask. Every time you write debug output you have to specify a "bitmask" +which specifies when that message is written; like when you are cross posting to usenet news groups, specifying multiple +news groups for a single message. When any of the specified Debug Channels is turned on, then the message is written +to the output stream of the underlaying debug object.</P> + +<A name="OwnDebugObject"></A> +<H3>10. Can I make my own Debug Object?</H3> + +<P><A HREF="../html/group__chapter__custom__do.html">Yes</A>, you can make as many debug objects as you like. +Each debug object is associated with one ostream. However, the default debug output macros <CODE>Dout</CODE> and +<CODE>DoutFatal</CODE> use the default debug object <CODE>libcw_do</CODE>. +It isn't hard at all to define your own macros though; for example add something like the following to +<A HREF="../html/group__chapter__custom__debug__h.html">your own "debug.h"</A> file:</P> + +<PRE class="code"> +#ifdef CWDEBUG +extern libcw::debug::debug_ct <SPAN class="highlight">my_debug_object</SPAN>; +#define <SPAN class="highlight">MyDout</SPAN>(cntrl, data) LibcwDout(DEBUGCHANNELS, <SPAN class="highlight">my_debug_object</SPAN>, cntrl, data) +#define <SPAN class="highlight">MyDoutFatal</SPAN>(cntrl, data) LibcwDoutFatal(DEBUGCHANNELS, <SPAN class="highlight">my_debug_object</SPAN>, cntrl, data) +#else // !CWDEBUG +#define <SPAN class="highlight">MyDout</SPAN>(a, b) +#define <SPAN class="highlight">MyDoutFatal</SPAN>(a, b) LibcwDoutFatal(::std, /*nothing*/, a, b) +#endif // !CWDEBUG +</PRE> + +<A name="recursive2"></A> +<H3>11. Can I turn Debug Objects off again? Can I do that recursively?</H3> + +<P>Debug objects can be switched on and off at any time. At the start of your program you should +turn on the debug object(s) by calling <SPAN class="code">Debug(<EM>debugobject</EM>.on())</SPAN> +<EM>once</EM>. Sometimes you want to temporally turn off all debug output. +This can be achieved by calling the methods <SPAN class="code">off()</SPAN> and <SPAN class="code">on()</SPAN> in +<EM>pairs</EM> and in that order. For example:</P> + +<PRE class="code"> + // Disable all debug output to `libcw_do': + Debug( libcw_do.off() ); + // ... do stuff ... + Debug( libcw_do.on() ); +</PRE> + +<P>This will work even when `do stuff' calls a function that also turns <SPAN class="code">libcw_do</SPAN> off and on: +after the call to <SPAN class="code">on()</SPAN> the debug object can still be off: it is restored to the on/off state +that it was in before the corresponding call to <SPAN class="code">off()</SPAN>. In fact, the calls to +<SPAN class="code">off()</SPAN> and <SPAN class="code">on()</SPAN> only respectively increment and decrement a counter.</P> + +<A name="SetOstream"></A> +<H3>12. How do I set a new <SPAN class="H3code">ostream</SPAN> for a given Debug Object?</H3> + +<P>You can change the <SPAN class="code">ostream</SPAN> that is associated with a Debug Object at any time. +For example, changing the <SPAN class="code">ostream</SPAN> of <SPAN class="code">libcw_do</SPAN> from the +default <SPAN class="code">cerr</SPAN> to <SPAN class="code">cout</SPAN>:</P> + +<PRE class="code"> + Debug( libcw_do.set_ostream(&cout) ); +</PRE> + +<P>See also <A HREF="tut3.html">tutorial 3</A>.</P> + +<A name="WhyOff"></A> +<H3>13. Why are Debug Objects turned off at creation?</H3> + +<P>The Debug Objects and Debug Channels are global objects. Because libcwd could not be +dependant of libcw, they do not use libcw's <CODE>Global<></CODE> template. +As a result, the order in which the debug channels and objects are initialized is +unknown; moreover, other global objects whose constructors might try to write debug output could +be constructed before the debug objects are initialized! The debug objects are therefore +designed in a way that independent of there internal state of initialisation they function without +crashing. It should be obvious that the only way this could be achieved was by creating them +in the state <EM>off</EM>.</P> + +<A name="Order"></A> +<H3>14. Why do you turn on the debug object after you enable a debug channel, why not the other way around?</H3> + +<P>The order in which Debug Channels and Debug Objects are turned on does not matter at all. +At most, when you think about the Debug Object as the «main switch» then it seems to make +sense to first play with the little channel switches before finally activating the complete Debug +machinery. Others might think more in the lines of: lets start with setting the debug object +<EM>on</EM> before I forget it. That is a bit <EM>too</EM> fuzzy (logic) for me though ;)</P> + +<A name="Object"></A> +<H3>15. Why do you call it a Debug <EM>Object</EM>? What <EM>is</EM> a Debug Object?</H3> + +<P>Good question. It can't be because I wasn't creative, I am very creative. +Note that I didn't think of <EM>Object</EM> as in OOP (<EM>that</EM> would be uncreative) +but more along the lines of an <EM>object</EM>, like in science fiction stories -- objects +you can't get around. The monolith of <A HREF="http://uk.imdb.com/Title?0062622" target="_blank">2001: A Space Odyssey</A> +is a good example I guess.</P> + +<P>Unlike the monolith however, a Debug Object is not mysterious at all. Basically it +is a pointer to an <SPAN class="code">ostream</SPAN> with a few extra attributes added to +give it an internal state for 'on' (pass output on) and 'off' (don't pass output on) as well +as some formatting information of how to write the data that is passed on to its +<SPAN class="code">ostream</SPAN>.</P> + +<A name="semicolon"></A> +<H3>16. Do I need to type that semi-colon after the macro? Why isn't it part of the macro?</H3> + +<P>Yes, that colon needs to be there. +It was chosen not to include the semi-colon in the macro because this way it looks +a bit like a function call which feels more natural.</P> + +<P>The code <SPAN class="code">Dout(dc::notice, "Hello World");</SPAN> is definitely +a <EM>statement</EM> and therefore needs to end on a semi-colon (after expansion). When the +macro <SPAN class="code">CWDEBUG</SPAN> is not defined, the macro is replaced with +whitespace but still has to be a statement: it must be a single semi-colon then.</P> + +<P>For example,</P> + +<PRE class="code"> + if (error) + Dout(dc::notice, "An error occured"); + + exit(0); + cerr << "We should never reach this\n"; +</PRE> + +<P>If the complete line <SPAN class="code">Dout(dc::notice, "An error occured");</SPAN>, +including semi-colon is removed (replaced with whitespace), then the line +<SPAN class="code">exit(0);</SPAN> would be executed only when <SPAN class="code">error</SPAN> +is <SPAN class="code">true</SPAN>! And when the semi-colon would be included in +the macro then people could easily be tempted to add a semi-colon anyway (because it +looks so much better), which would break code like:</P> + +<PRE class="code"> + if (error) + Dout(dc::notice, "An error occured"); + else + cout << "Everything is ok\n"; +</PRE> + +<P>because after macro expansion that would become:</P> + +<PRE class="code"> + if (error) + ; + ; + else // <-- syntax error + cout << "Everything is ok\n"; +</PRE> + +<A name="LibcwDout"></A> +<H3>17. I made my own Debug Object, can I still use <SPAN class="H3code">Dout</SPAN>?</H3> + +<P>No, macro <SPAN class="code">Dout</SPAN> et al. use exclusively the debug object that +comes with libcwd. It is easy to define your own macros however (see <A HREF="#OwnDebugObject">above</A>). +You are free to <EM>redefine</EM> the <SPAN class="code">Dout</SPAN> macros however, just realize that libcwd +will continue to use its own debug object (<SPAN class="code">libcw_do</SPAN>), debug output written by libcwd +in its header files do not use the <SPAN class="code">Dout</SPAN> macro (especially in order to allow you +to redefine it).</P> + +<A name="evaluation"></A> +<H3>18. Is the second field of the macro still evaluated when the Debug Channel and/or Debug Object are turned off?</H3> + +<P>No! And that is a direct result of the fact that <SPAN class="code">Dout</SPAN> et al. are <EM>macros</EM>. +Indeed this fact could therefore be a little confusing. +In pseudo-code the macro expansion looks something like</P> + +<PRE class="code"> + if (debug object and any of the debug channels are turned on) + the_ostream << your message; +</PRE> + +<P>and so, "your message" is <EM>not</EM> evaluated when it isn't also +actually written. This fact is also covered in the +<A HREF="../html/classlibcw_1_1debug_1_1debug__ct.html#eval_example">Reference Manual</A>.</P> + +<P>Note that debug code should never have an effect on any of your variables (and thus on the application) anyway. +In the production version of your application all debug code will be removed and you don't want it to behave differently then!</P> + +<A name="suppress"></A> +<H3>19. Can I suppress that new-line character?</H3> + +<P>Yes, and a lot more. See <A HREF="tut5.html#Formatting">tutorial 5.4</A>.</P> + +<A name="label"></A> +<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>. +At this moment that is 16.</P> + +<A name="prefix"></A> +<H3>21. Why do I have to use the <SPAN class="H3code">dc::</SPAN> prefix?</H3> + +<P>This is a complex reason. Basically because of a flaw in the design of namespaces in C++. +Namespaces have been introduced in order to avoid name collisions, which was a good thing. +It doesn't make much sense if you constantly have to type <SPAN class="code">::somelibrary::debug::channel::notice</SPAN> +of course, then you could as well have avoided the name space problem by using +<SPAN class="code">somelibrary_debug_channel_notice</SPAN> right? +Therefore you don't have to type the name of the namespace that is "current". +There can be only <EM>one</EM> namespace current at a time however. The result is that +this can not be used to solve our problem: We want to avoid both, name collisions between debug channels +and any other variable or function name, but <EM>also</EM> between debug channels defined in +different libraries. That means we need more than one namespace: A namespace for each of +the libraries. We can not make all of them current however. Worse, we can not +make any namespace current because it must be possible to add code that writes debug output +<EM>everywhere</EM>. We can only use the <SPAN class="code">using namespace</SPAN> +directive. Now here is the real flaw: A <SPAN class="code">using namespace</SPAN> directive +gives no priority whatsoever to names when resolving them, for example, you can't do this:</P> + +<PRE class="code"> +namespace base { + int base1; + int base2; +} + +namespace derived { + using namespace base; + int derived1; + char base1; +} + + // ... + using namespace derived; + base1 = 'a'; +</PRE> + +<P>because C++ will make absolutely no difference between variables defined in +<SPAN class="code">derived</SPAN> and variables defined in <SPAN class="code">base</SPAN> +but will complain that <SPAN class="code">base1</SPAN> is ambigious.</P> + +<P>The only opening that the ANSI/ISO C++ Standard allows us here is in the +following phrase:</P> + +<QUOTE> +Given <SPAN class="code">X::m</SPAN> (where <SPAN class="code">X</SPAN> is a user-declared namespace), +or given <SPAN class="code">::m</SPAN> (where <SPAN class="code">X</SPAN> is the global namespace), +let <SPAN class="code">S</SPAN> be the set of all declarations of <SPAN class="code">m</SPAN> in <SPAN class="code">X</SPAN> +and in the transitive closure of all namespaces nominated by <I>using-directive</I>s in X and its used namespaces, +except that <I>using-directive</I>s are ignored in any namespace, including <SPAN class="code">X</SPAN>, +directly containing one or more declarations of <SPAN class="code">m</SPAN>. +No namespace is searched more than once in the lookup of a name. If <SPAN class="code">S</SPAN> is the empty set, +the program is ill-formed. Otherwise, if <SPAN class="code">S</SPAN> has exactly one member, +or if the context of the reference is a using-declaration, <SPAN class="code">S</SPAN> is +the required set of declarations of <SPAN class="code">m</SPAN>. +Otherwise if the use of <SPAN class="code">m</SPAN> is not one that allows a unique +declaration to be chosen from <SPAN class="code">S</SPAN>, the program is ill-formed. +</QUOTE> + +<P>Replace <SPAN class="code">X</SPAN> with <SPAN class="code">dc::</SPAN> +(obviously we don't want to put the debug channels in global namespace) +and we can use this rule to at least select a specific channel by using +the trick that the used <SPAN class="code">dc</SPAN> namespace is <EM>not the same</EM> +namespace for the different libraries. Then we can use debug channels with +the same name in <SPAN class="code">dc</SPAN> namespaces in <EM>different</EM> +namespaces in different libraries and use the namespaces of <EM>one</EM> library +at a time to select the current <SPAN class="code">dc</SPAN> namespace.</P> + +<P>If this is over your head then that is probably because I can't explain :). +Don't worry however, you only need to know <EM>how</EM> to introduce new debug +channels and not understand how it works. The correct procedure is described +in the <A HREF="../html/group__group__debug__channels.html">Reference Manual</A>.</P> + +<A name="ownnamespace"></A> +<H3>22. Can I put my debug channels in my own name space?</H3> + +<P>Yes. How, is described in the <A HREF="../html/group__group__debug__channels.html">Reference Manual</A>. +For some background information on why this has to be so complex, please read the <A HREF="#prefix">previous question</A>.</P> + +<A name="labelwidth"></A> +<H3>23. Why does it print spaces between the label and the colon? How is the field width of the label determined?</H3> + +<P>The colon is indented so it ends up in the same column for all existing debug channels. +Hence, the longest label of all existing/created debug channels determines the number of spaces. +This value can be less than the <A HREF="#label">maximum allowed label size</A> of course.</P> + +__PAGEEND +__PAGEFOOTER +__HTMLFOOTER + Index: src/libcwd/documentation/tutorial/hello_world.cc diff -u /dev/null src/libcwd/documentation/tutorial/hello_world.cc:1.1.2.1 --- /dev/null Thu Dec 27 20:12:11 2001 +++ src/libcwd/documentation/tutorial/hello_world.cc Thu Dec 27 20:11:59 2001 @@ -0,0 +1,13 @@ +#include <libcw/sysd.h> // This must be the first header file +#include <libcw/debug.h> + +int main(void) +{ + Debug( dc::notice.on() ); // Turn on the NOTICE Debug Channel + Debug( libcw_do.on() ); // Turn the default Debug Object on + + Dout( dc::notice, "Hello World" ); + + return 0; +} + Index: src/libcwd/documentation/tutorial/index.m4 diff -u /dev/null src/libcwd/documentation/tutorial/index.m4:1.1.2.1 --- /dev/null Thu Dec 27 20:12:11 2001 +++ src/libcwd/documentation/tutorial/index.m4 Thu Dec 27 20:11:59 2001 @@ -0,0 +1,87 @@ +include(definitions.m4)dnl +define(__TOC_START, [[ +</DIV> +<TABLE border=0 cellpadding=0 cellspacing=10> + +<TR> +<TD WIDTH=15 valign=center> + <IMG width=34 height=34 src="../images/toc.png" alt="Main index" align=top border=0> +</TD> +<TD valign=center><DIV class="toc-header1"> + <A class="toc1" href="../html/index.html" target="_top"> + Back to main index + </A></DIV> +</TD> +</TR> +]])dnl +define(__TOC_END, [[ +</TABLE> +<DIV class="normal"> +]])dnl +define(__PAGE, [[<!-- -Page $1---------------------------------------------------- --> + +<TR> +<TD WIDTH=15 valign=center> + <IMG width=34 height=34 src="../images/toc.png" align=top border=0> +</TD> +<TD valign=center><DIV class="toc-header1"> + <A class="toc1" href="$3"> + $2 + </A></DIV> +</TD> +</TR>]])dnl +define(__PAGE_START, [[ +<TR> +<TD WIDTH=15></TD> +<TD> + <TABLE border=0 cellpadding=0 cellspacing=0>]])dnl +define(__PAGE_END, [[ + </TABLE> +</TD> +</TR>]])dnl +define(__PARAGRAPH, [[ +<TR> +<TD WIDTH=50><DIV class="toc-number$1"> + $2 +</DIV></TD> +<TD><DIV class="toc-header$1"> + <A class="toc" HREF="$4"> + $3 + </A></DIV> +</TD> +</TR>]])dnl +dnl# +dnl# Start of document +dnl# +__HTMLHEADER +__PAGEHEADER +__PAGESTART +<P>Welcome to the tutorial of libcwd, an Object Oriented debugging support library for C++ developers.</P> + +<H1>Table of Contents</H1> +__TOC_START +__PAGE(1, [[Introduction]], intro.html) +__PAGE(2, [[Tutorial 1 : Hello World]], tut1.html) +__PAGE(3, [[Tutorial 2 : Creating your own Debug Channels]], tut2.html) +__PAGE(4, [[Tutorial 3 : Setting the <CODE>ostream</CODE>]], tut3.html) +__PAGE(5, [[Tutorial 4 : Management of <CODE>CWDEBUG</CODE>]], tut4.html) +__PAGE(6, [[Tutorial 5 : Advanced examples]], tut5.html) +__PAGE_START +__PARAGRAPH(2f, 5.1, [[Running over all Debug Channels]], [[tut5.html#Running]]) +__PARAGRAPH(2, 5.2, [[Debug Channels and name spaces]], [[tut5.html#Debug]]) +__PARAGRAPH(2, 5.3, [[Combining channels]], [[tut5.html#Combining]]) +__PARAGRAPH(2, 5.4, [[Formatting debug output]], [[tut5.html#Formatting]]) +__PARAGRAPH(3, 5.4.1, [[Control flags]], [[tut5.html#Control]]) +__PARAGRAPH(3, 5.4.2, [[Methods of the debug object]], [[tut5.html#Methods]]) +__PAGE_END +__PAGE(7, [[Tutorial 6 : The debugging of dynamic memory allocations]], tut6.html) +__PAGE(8, [[Tutorial 7 : Advanced examples]], tut7.html) +__PAGE_START +__PARAGRAPH(2f, 7.1, [[Removing allocations from the Allocated memory Overview]], [[tut7.html#Removing]]) +__PARAGRAPH(2, 7.2, [[Retrieving information about memory allocations]], [[tut7.html#Retrieving]]) +__PARAGRAPH(2, 7.3, [[Memory leak detection]], [[tut7.html#Memory]]) +__PAGE_END +__TOC_END +__PAGEEND +__PAGEFOOTER +__HTMLFOOTER Index: src/libcwd/documentation/tutorial/intro.m4 diff -u /dev/null src/libcwd/documentation/tutorial/intro.m4:1.1.2.1 --- /dev/null Thu Dec 27 20:12:11 2001 +++ src/libcwd/documentation/tutorial/intro.m4 Thu Dec 27 20:11:59 2001 @@ -0,0 +1,32 @@ +include(definitions.m4)dnl +__HTMLHEADER +__PAGEHEADER +__PAGESTART + +<H1>Tutorial</H1> + +<P><FONT class="hello">Hello</FONT>, +my name is <A HREF="http://www.xs4all.nl/~carlo17/" TARGET="_blank">Carlo Wood</A> +and I will guide you through a few example programs in order to help familiarize you +with <code>libcwd</code>.</P> + +<P class="line"><IMG class="line" width=870 height=34 src="../images/lines/mouse.png"></P> + +<P>Hopefully you have already installed the library and the header files. +If not, then do so now - see the <A HREF="../external/INSTALL">INSTALL</A> file in the +<A HREF="http://sourceforge.net/project/showfiles.php?group_id=354" TARGET="_blank">distribution package</A> +for detailed instructions.</P> + +<P>This tutorial is mixed with a lot of FAQ-style questions, which are linked to a more detailed explanation. +For a correct understanding of the tutorial it is <EM>not</EM> needed to read these FAQs; they are only provided for your +convenience, only read if you really want to know the answer.</P> + +__PAGEEND +<P class="line"><IMG width=870 height=18 src="../images/lines/cat.png"></P> +<DIV class="buttons"> +<A HREF="index.html"><IMG width=64 height=32 src="../images/buttons/lr_index.png" border="0"></A> +<A HREF="tut1.html"><IMG width=64 height=32 src="../images/buttons/lr_next.png" border="0"></A> +</DIV> +__PAGEFOOTER +__HTMLFOOTER + Index: src/libcwd/documentation/tutorial/log_file.cc diff -u /dev/null src/libcwd/documentation/tutorial/log_file.cc:1.1.2.1 --- /dev/null Thu Dec 27 20:12:11 2001 +++ src/libcwd/documentation/tutorial/log_file.cc Thu Dec 27 20:11:59 2001 @@ -0,0 +1,21 @@ +#include <libcw/sysd.h> +#include <fstream> +#include <libcw/debug.h> + +int main(void) +{ + Debug( dc::notice.on() ); + Debug( libcw_do.on() ); + +#ifdef CWDEBUG + ofstream file; + file.open("log"); +#endif + + // Set the ostream related with libcw_do to `file': + Debug( libcw_do.set_ostream(&file) ); + + Dout( dc::notice, "Hippopotamus are heavy" ); + + return 0; +} Index: src/libcwd/documentation/tutorial/tut1.m4 diff -u /dev/null src/libcwd/documentation/tutorial/tut1.m4:1.1.2.1 --- /dev/null Thu Dec 27 20:12:11 2001 +++ src/libcwd/documentation/tutorial/tut1.m4 Thu Dec 27 20:11:59 2001 @@ -0,0 +1,119 @@ +include(definitions.m4)dnl +__HTMLHEADER +__PAGEHEADER +__PAGESTART + +<H2>Tutorial 1: Hello World</H2> + +<P>The smallest C++ program that prints «<SPAN class="output">Hello World</SPAN>» as <I>debug output</I> +to <CODE>cerr</CODE> is:</P> + +<P class="download">[<A HREF="hello_world.cc">download</A>]</P> + +<P>Compile as: <SPAN class="shell-command">g++ -g -DCWDEBUG hello_world.cc -lcwd -o hello_world</SPAN></P> + +<PRE> +#include <libcw/sysd.h> // This must be the first header file +#include <libcw/debug.h> + +int main(void) +{ + Debug( dc::notice.on() ); // Turn on the NOTICE Debug Channel + Debug( libcw_do.on() ); // Turn on the default Debug Object + + Dout( dc::notice, "Hello World" ); + + return 0; +} +</PRE> + +<P>Each of the lines of code in this first example program are explained below:</P> + +<H3><CODE>#include <libcw/sysd.h></CODE></H3> + +<P>This must be the very first header file that is included; even before system header files. +Every source file that includes other libcw headers must include it.</P> + +<DIV class="faq-frame"><H4>FAQ</H4><UL class="faq"> +<LI><A HREF="faq.html#sysd.h">Why?</A></LI> +<LI><A HREF="faq.html#libcwd">What is this <TT>libcw</TT> talk? +Aren't you forgetting the <U><TT>d</TT></U> of +<TT>libcw<U>d</U></TT>?</A></LI> +<LI><A HREF="faq.html#dir">Why do I need to type "<CODE>libcw/sysd.h</CODE>" +and not just "<CODE>sysd.h</CODE>"?</LI></A> +</UL></DIV> + +<H3><CODE>#include <libcw/debug.h></CODE></H3> + +<P>This header file contains all definitions and declarations that are needed for debug output. +For example, it defines the macros <CODE>Debug</CODE> and <CODE>Dout</CODE> and declares +the debug object <CODE>libcw_do</CODE> and the debug channel <CODE>dc::notice</CODE>.</P> + +<DIV class="faq-frame"><H4>FAQ</H4><UL class="faq"> +<LI><A HREF="faq.html#debug.h">What is defined <EM>exactly</EM> in <CODE>libcw/debug.h</CODE>?</A></LI> +<LI><A HREF="faq.html#macros">Why are you using macros for <CODE>Debug</CODE> and <CODE>Dout</CODE>?</A></LI> +</UL></DIV> + +<A NAME="turn_on_channel"></A> +<H3></CODE>Debug( dc::notice.on() );</CODE></H3> + +<P>This turns on the <I><U>D</U>ebug <U>C</U>hannel</I> <CODE> <U>dc</U>::notice</CODE>. +Without this line, the code <CODE>Dout( dc::notice, "Hello World" )</CODE> would output +nothing: all <I>Debug Channels</I> are <EM>off</EM> by default, at start up.</P> + +<DIV class="faq-frame"><H4>FAQ</H4><UL class="faq"> +<LI><A HREF="faq.html#Debug">Why do I need to type the <CODE>Debug( )</CODE> around it?</A></LI> +<LI><A HREF="faq.html#DebugChannels">Which Debug Channels exist? Can I make my own?</A></LI> +<LI><A HREF="faq.html#recursive">Can I turn Debug Channels off again? Can I do that recursively?</A></LI> +<LI><A HREF="faq.html#Channel">Why do you call it a Debug <EM>Channel</EM>? What <EM>is</EM> a Debug Channel?</A></LI> +</UL></DIV> + +<H3><CODE>Debug( libcw_do.on() );</CODE></H3> + +<P>This turns on the <I><U>D</U>ebug <U>O</U>bject</I> <CODE>libcw_<U>do</U></CODE>. +Without this line, the code <CODE>Dout( dc::notice, "Hello World" )</CODE> would output +nothing: all <I>Debug Objects</I> are <EM>off</EM> by default, at start up.</P> + +<P>A <I>Debug Object</I> is related to exactly one <CODE>ostream</CODE>. +<CODE>Libcwd</CODE> defines only one <I>Debug Object</I> by itself (being <CODE>libcw_do</CODE>), +this is enough for most applications. +The default ostream is <CODE>cerr</CODE>. +Using the macro <CODE>Dout</CODE> causes debug output to be written to <CODE>libcw_do</CODE>.</P> + +<DIV class="faq-frame"><H4>FAQ</H4><UL class="faq"> +<LI><A HREF="faq.html#Debug">Why do I need to type the <CODE>Debug( )</CODE> around it?</A></LI> +<LI><A HREF="faq.html#OwnDebugObject">Can I make my own Debug Object?</A></LI> +<LI><A HREF="faq.html#recursive2">Can I turn Debug Objects off again? Can I do that recursively?</A></LI> +<LI><A HREF="faq.html#SetOstream">How do I set a new <CODE>ostream</CODE> for a give... [truncated message content] |
From: Carlo W. <li...@us...> - 2001-12-28 05:15:29
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-28 05:15:28 UTC Modified files: Tag: branch-threading libcwd/.cvsignore libcwd/Makefile.am libcwd/NEWS libcwd/acinclude.m4 libcwd/configure.in Log message: Now works with automake-1.5. A few build bug fixes. ---------------------- diff included ---------------------- Index: src/libcwd/.cvsignore diff -u src/libcwd/.cvsignore:1.14.2.3 src/libcwd/.cvsignore:1.14.2.4 --- src/libcwd/.cvsignore:1.14.2.3 Sun Oct 21 16:29:28 2001 +++ src/libcwd/.cvsignore Thu Dec 27 21:15:17 2001 @@ -11,6 +11,8 @@ config.sub ltconfig ltmain.sh +depcomp +stamp-h1 config.h.in config.h stamp-h.in Index: src/libcwd/Makefile.am diff -u src/libcwd/Makefile.am:1.30.2.14 src/libcwd/Makefile.am:1.30.2.15 --- src/libcwd/Makefile.am:1.30.2.14 Sun Dec 9 15:52:46 2001 +++ src/libcwd/Makefile.am Thu Dec 27 21:15:17 2001 @@ -53,6 +53,7 @@ rm -rf rpm MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure stamp-h.in Makefile.in \ - install-sh missing mkinstalldirs config.guess config.sub ltmain.sh ltconfig + install-sh missing mkinstalldirs config.guess config.sub ltmain.sh ltconfig \ + config.cache config.log config.status depcomp @MAINTAINER_MODE_TRUE@include maintMakefile Index: src/libcwd/NEWS diff -u src/libcwd/NEWS:1.45.2.9 src/libcwd/NEWS:1.45.2.10 --- src/libcwd/NEWS:1.45.2.9 Sat Dec 1 17:01:30 2001 +++ src/libcwd/NEWS Thu Dec 27 21:15:17 2001 @@ -9,6 +9,10 @@ allow the use of the testsuite together with --enable-libcwd-debug. (You shouldn't use either unless you are hacking libcwd itself). + Miscellaneous: + - The configuration option --disable-libcwd-location is fixed. + - Automake-1.5 now works. + API changes: IMPORTANT: Debug channels have globally been renamed to Debug Index: src/libcwd/acinclude.m4 diff -u src/libcwd/acinclude.m4:1.41.2.8 src/libcwd/acinclude.m4:1.41.2.9 --- src/libcwd/acinclude.m4:1.41.2.8 Tue Nov 13 19:01:06 2001 +++ src/libcwd/acinclude.m4 Thu Dec 27 21:15:17 2001 @@ -148,7 +148,7 @@ fi done fi] -dnl `automake' looks for AC_OUTPUT and thinks `$1.in' etc. +dnl `automake' looks for AC_OUTPUT and thinks `$1' etc. dnl is a literally required file unless we fool it a bit here: [AC_OUTPUT]([$1], [$2], [$3])) @@ -517,9 +517,8 @@ dnl Like AC_PROG_CXX, except that it demands that GNU g++-2.95.1 dnl or higher is available. AC_DEFUN(CW_PROG_CXX, -[AC_BEFORE([$0], [AC_PROG_CXXCPP])dnl -AC_CHECK_PROGS(CXX, g++ c++) -AC_PROG_CXX_WORKS +[AC_BEFORE([$0], [CW_PROG_CXXCPP]) +AC_REQUIRE([AC_PROG_CXX]) AC_CACHE_CHECK(whether we are using GNU C++ version 2.95.1 or later, ac_cv_prog_gxx_version, [dnl The semicolon is to pacify NeXT's syntax-checking cpp. cat > conftest.C <<EOF @@ -555,7 +554,9 @@ dnl dnl Like AC_PROG_CXXCPP but with bug work around that allows user to override CXXCPP. AC_DEFUN(CW_PROG_CXXCPP, -[dnl This triggers the bug: +[AC_BEFORE([$0], [AC_PROG_CXXCPP]) +AC_REQUIRE([CW_PROG_CXX]) +dnl This triggers the bug: if test -n "$CXXCPP"; then dnl Work around: unset ac_cv_prog_CXXCPP @@ -572,7 +573,7 @@ dnl dnl Extract finger prints of C++ compiler and preprocessor and C compiler which is used for linking. AC_DEFUN(CW_PROG_CXX_FINGER_PRINTS, -[AC_REQUIRE([CW_PROG_CXX]) +[AC_REQUIRE([AC_PROG_CXX]) AC_REQUIRE([CW_PROG_CXXCPP]) AC_REQUIRE([AC_PROG_CC]) cw_prog_cxx_finger_print="`$CXX -v 2>&1 | grep version | head -n 1`" @@ -820,9 +821,7 @@ dnl CW_SETUP_RPM_DIRS dnl Set up rpm directory when on linux and in maintainer-mode AC_DEFUN(CW_SETUP_RPM_DIRS, -[SPECCHANGELOG=spec.changelog -if test "$USE_MAINTAINER_MODE" = yes; then - AC_SUBST_FILE(SPECCHANGELOG) +[if test "$USE_MAINTAINER_MODE" = yes; then LSMFILE="$PACKAGE.lsm" AC_SUBST(LSMFILE) SPECFILE="$PACKAGE.spec" Index: src/libcwd/configure.in diff -u src/libcwd/configure.in:1.81.2.12 src/libcwd/configure.in:1.81.2.13 --- src/libcwd/configure.in:1.81.2.12 Tue Nov 13 19:01:06 2001 +++ src/libcwd/configure.in Thu Dec 27 21:15:17 2001 @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_REVISION($Revision: 1.81.2.12 $)dnl +AC_REVISION($Revision: 1.81.2.13 $)dnl dnl General intialization of `autoconf' varaibles. dnl Ensure that the directory specified with --srcdir was correct @@ -111,6 +111,7 @@ unset ac_cv_prog_CC fi AC_PROG_CC +AC_PROG_CXX CW_PROG_CXX CW_PROG_CXXCPP @@ -138,8 +139,8 @@ dnl We need to use these options for the tests too CXXFLAGS="$DEBUGOPTS $EXTRAOPTS" -dnl This block cannot be replaced by a macro because the DISABLE_* and -dnl PROG_LIBTOOL macros need to be in configure.in itself for some reason. +dnl This block cannot be replaced by a macro because the DISABLE_* and the +dnl AM_PROG_LIBTOOL macro need to be in configure.in itself for some reason. dnl This block is also present in src/libcw/configure.in! dnl Generate libtool (also checks shared/static prerequisites) if expr "$host" : ".*openbsd.*" >/dev/null; then @@ -152,7 +153,7 @@ test -n "$enable_shared" || enable_shared=yes test -n "$enable_static" || enable_static=yes dnl Note: due to a bug in libtool-1.3c, the language must be C at this point! -AC_PROG_LIBTOOL +AM_PROG_LIBTOOL 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=//'` @@ -446,8 +447,8 @@ cd .. ]) -CW_OUTPUT(Makefile maintMakefile include/Makefile include/libcw/Makefile utils/Makefile tests/Makefile testsuite/Makefile include/libcw/debug_config.ho include/libcw/sysd.ho include/sys.ho) +CW_OUTPUT(Makefile maintMakefile include/Makefile include/libcw/Makefile utils/Makefile tests/Makefile testsuite/Makefile include/libcw/debug_config.ho include/libcw/sysd.ho include/sys.ho libcwd.spec) exit 0 dnl Keep automake happy -AC_OUTPUT(Makefile maintMakefile include/Makefile include/libcw/Makefile utils/Makefile tests/Makefile testsuite/Makefile include/libcw/debug_config.ho include/libcw/sysd.ho include/sys.ho) +AC_OUTPUT(Makefile maintMakefile include/Makefile include/libcw/Makefile utils/Makefile tests/Makefile testsuite/Makefile include/libcw/debug_config.ho include/libcw/sysd.ho include/sys.ho libcwd.spec) ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-28 05:25:37
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-28 05:25:37 UTC Modified files: libcwd/.cvsignore libcwd/Makefile.am libcwd/NEWS libcwd/acinclude.m4 libcwd/configure.in Log message: Fix for automake 1.5. ---------------------- diff included ---------------------- Index: src/libcwd/.cvsignore diff -u src/libcwd/.cvsignore:1.15 src/libcwd/.cvsignore:1.16 --- src/libcwd/.cvsignore:1.15 Mon Aug 27 05:46:26 2001 +++ src/libcwd/.cvsignore Thu Dec 27 21:25:27 2001 @@ -11,6 +11,8 @@ config.sub ltconfig ltmain.sh +depcomp +stamp-h1 config.h.in config.h stamp-h.in Index: src/libcwd/Makefile.am diff -u src/libcwd/Makefile.am:1.33 src/libcwd/Makefile.am:1.34 --- src/libcwd/Makefile.am:1.33 Sat Sep 22 22:01:08 2001 +++ src/libcwd/Makefile.am Thu Dec 27 21:25:27 2001 @@ -47,6 +47,7 @@ rm -rf rpm MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure stamp-h.in Makefile.in \ - install-sh missing mkinstalldirs config.guess config.sub ltmain.sh ltconfig + install-sh missing mkinstalldirs config.guess config.sub ltmain.sh ltconfig \ + config.cache config.log config.status depcomp @MAINTAINER_MODE_TRUE@include maintMakefile Index: src/libcwd/NEWS diff -u src/libcwd/NEWS:1.60 src/libcwd/NEWS:1.61 --- src/libcwd/NEWS:1.60 Sat Sep 22 22:01:08 2001 +++ src/libcwd/NEWS Thu Dec 27 21:25:27 2001 @@ -3,6 +3,10 @@ libcwd now works with (single threaded) qt applications. A few major bugs have been fixed. + Miscellaneous: + - The configuration option --disable-libcwd-location is fixed. + - Automake-1.5 now works. + API changes: You now MUST use CWDEBUG, defining DEBUG will no longer work; it was Index: src/libcwd/acinclude.m4 diff -u src/libcwd/acinclude.m4:1.42 src/libcwd/acinclude.m4:1.43 --- src/libcwd/acinclude.m4:1.42 Wed Sep 19 16:34:49 2001 +++ src/libcwd/acinclude.m4 Thu Dec 27 21:25:27 2001 @@ -148,7 +148,7 @@ fi done fi] -dnl `automake' looks for AC_OUTPUT and thinks `$1.in' etc. +dnl `automake' looks for AC_OUTPUT and thinks `$1' etc. dnl is a literally required file unless we fool it a bit here: [AC_OUTPUT]([$1], [$2], [$3])) @@ -512,9 +512,8 @@ dnl Like AC_PROG_CXX, except that it demands that GNU g++-2.95.1 dnl or higher is available. AC_DEFUN(CW_PROG_CXX, -[AC_BEFORE([$0], [AC_PROG_CXXCPP])dnl -AC_CHECK_PROGS(CXX, g++ c++) -AC_PROG_CXX_WORKS +[AC_BEFORE([$0], [CW_PROG_CXXCPP]) +AC_REQUIRE([AC_PROG_CXX]) AC_CACHE_CHECK(whether we are using GNU C++ version 2.95.1 or later, ac_cv_prog_gxx_version, [dnl The semicolon is to pacify NeXT's syntax-checking cpp. cat > conftest.C <<EOF @@ -550,7 +549,9 @@ dnl dnl Like AC_PROG_CXXCPP but with bug work around that allows user to override CXXCPP. AC_DEFUN(CW_PROG_CXXCPP, -[dnl This triggers the bug: +[AC_BEFORE([$0], [AC_PROG_CXXCPP]) +AC_REQUIRE([CW_PROG_CXX]) +dnl This triggers the bug: if test -n "$CXXCPP"; then dnl Work around: unset ac_cv_prog_CXXCPP @@ -567,7 +568,7 @@ dnl dnl Extract finger prints of C++ compiler and preprocessor and C compiler which is used for linking. AC_DEFUN(CW_PROG_CXX_FINGER_PRINTS, -[AC_REQUIRE([CW_PROG_CXX]) +[AC_REQUIRE([AC_PROG_CXX]) AC_REQUIRE([CW_PROG_CXXCPP]) AC_REQUIRE([AC_PROG_CC]) cw_prog_cxx_finger_print="`$CXX -v 2>&1 | grep version | head -n 1`" Index: src/libcwd/configure.in diff -u src/libcwd/configure.in:1.84 src/libcwd/configure.in:1.85 --- src/libcwd/configure.in:1.84 Sat Sep 22 22:01:08 2001 +++ src/libcwd/configure.in Thu Dec 27 21:25:27 2001 @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_REVISION($Revision: 1.84 $)dnl +AC_REVISION($Revision: 1.85 $)dnl dnl General intialization of `autoconf' varaibles. dnl Ensure that the directory specified with --srcdir was correct @@ -100,12 +100,13 @@ CW_ENVIRONMENT dnl Check for compiler and preprocessor +AC_PROG_CC +AC_PROG_CXX CW_PROG_CXX CW_PROG_CXXCPP if test -n "$CC"; then unset ac_cv_prog_CC fi -AC_PROG_CC dnl Check if C compiler and C++ compiler versions match. CW_COMPILER_VERSIONS @@ -128,8 +129,8 @@ dnl We need to use these options for the tests too CXXFLAGS="$DEBUGOPTS $EXTRAOPTS" -dnl This block cannot be replaced by a macro because the DISABLE_* and -dnl PROG_LIBTOOL macros need to be in configure.in itself for some reason. +dnl This block cannot be replaced by a macro because the DISABLE_* and the +dnl AM_PROG_LIBTOOL macro need to be in configure.in itself for some reason. dnl This block is also present in src/libcw/configure.in! dnl Generate libtool (also checks shared/static prerequisites) if expr "$host" : ".*openbsd.*" >/dev/null; then @@ -142,7 +143,7 @@ test -n "$enable_shared" || enable_shared=yes test -n "$enable_static" || enable_static=yes dnl Note: due to a bug in libtool-1.3c, the language must be C at this point! -AC_PROG_LIBTOOL +AM_PROG_LIBTOOL 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=//'` ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-29 23:59:26
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-29 23:59:25 UTC Added files: libcwd/documentation/tutorial/examples5/sysinclude/libbooster/debug.h libcwd/documentation/tutorial/examples5/sysinclude/libturbo/debug.h Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/tutorial/examples5/sysinclude/libbooster/debug.h diff -u /dev/null src/libcwd/documentation/tutorial/examples5/sysinclude/libbooster/debug.h:1.2 --- /dev/null Sat Dec 29 15:59:25 2001 +++ src/libcwd/documentation/tutorial/examples5/sysinclude/libbooster/debug.h Sat Dec 29 15:59:14 2001 @@ -0,0 +1,14 @@ +#include <libcw/debug.h> + +namespace booster { + namespace debug { + namespace channels { + namespace dc { + using namespace libcw::debug; + using namespace libcw::debug::channels::dc; + extern channel_ct booster; + extern channel_ct foobar; + } + } + } +} Index: src/libcwd/documentation/tutorial/examples5/sysinclude/libturbo/debug.h diff -u /dev/null src/libcwd/documentation/tutorial/examples5/sysinclude/libturbo/debug.h:1.2 --- /dev/null Sat Dec 29 15:59:25 2001 +++ src/libcwd/documentation/tutorial/examples5/sysinclude/libturbo/debug.h Sat Dec 29 15:59:14 2001 @@ -0,0 +1,20 @@ +#include <libcw/debug.h> + +namespace turbo { + namespace debug { + namespace channels { + namespace dc { + using namespace libcw::debug; + using namespace libcw::debug::channels::dc; + extern channel_ct turbo; + extern channel_ct foobar; + } + } + } +} + +namespace libcw { + namespace debug { + using namespace turbo::debug; + } +} ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 00:53:22
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-30 00:53:20 UTC Removed files: Tag: branch-threading libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore libcwd/documentation/tutorial/examples7/tut7.1/Makefile libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore libcwd/documentation/tutorial/examples7/tut7.2/Makefile libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore libcwd/documentation/tutorial/examples7/tut7.3/Makefile Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore diff -u src/libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore:1.1.2.1 src/libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore:removed --- src/libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore:1.1.2.1 Thu Dec 27 20:12:00 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.1/.cvsignore Sat Dec 29 16:53:20 2001 @@ -1,6 +0,0 @@ -invisible.cc -test_delete.cc -coredump.cc -invisible -test_delete -coredump Index: src/libcwd/documentation/tutorial/examples7/tut7.1/Makefile diff -u src/libcwd/documentation/tutorial/examples7/tut7.1/Makefile:1.1.2.1 src/libcwd/documentation/tutorial/examples7/tut7.1/Makefile:removed --- src/libcwd/documentation/tutorial/examples7/tut7.1/Makefile:1.1.2.1 Thu Dec 27 20:12:00 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.1/Makefile Sat Dec 29 16:53:20 2001 @@ -1,33 +0,0 @@ -# Directory where the base Makefile resides: -BASEDIR=.. - -# List of source files (one per executable): -CSRC= -CXXSRC=invisible.cc coredump.cc test_delete.cc - -# List of sub directories: -SUBDIRS= - -# Extra static libraries to link with: -STATICLIBS= - -# Extra shared libraries to link with: -SHAREDLIBS=-lcwd - -# Put here extra -L... flags -LIBFLAGS= - -# Extra *.o files that need to be linked: -EXTRA_OBJS= - -#----------------------------------------------------------------------------- - -include $(PROTODIR)/test/PTMakefile - -build:: - ln -f invisible ../example-7.1.1 - ln -f coredump ../example-7.1.2 - ln -f test_delete ../example-7.1.3 - -#clean:: -#depend:: Index: src/libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore diff -u src/libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore:1.1.2.1 src/libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore:removed --- src/libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore:1.1.2.1 Thu Dec 27 20:12:00 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.2/.cvsignore Sat Dec 29 16:53:20 2001 @@ -1,2 +0,0 @@ -find_alloc.cc -find_alloc Index: src/libcwd/documentation/tutorial/examples7/tut7.2/Makefile diff -u src/libcwd/documentation/tutorial/examples7/tut7.2/Makefile:1.1.2.1 src/libcwd/documentation/tutorial/examples7/tut7.2/Makefile:removed --- src/libcwd/documentation/tutorial/examples7/tut7.2/Makefile:1.1.2.1 Thu Dec 27 20:12:00 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.2/Makefile Sat Dec 29 16:53:20 2001 @@ -1,31 +0,0 @@ -# Directory where the base Makefile resides: -BASEDIR=.. - -# List of source files (one per executable): -CSRC= -CXXSRC=find_alloc.cc - -# List of sub directories: -SUBDIRS= - -# Extra static libraries to link with: -STATICLIBS= - -# Extra shared libraries to link with: -SHAREDLIBS=-lcwd - -# Put here extra -L... flags -LIBFLAGS= - -# Extra *.o files that need to be linked: -EXTRA_OBJS= - -#----------------------------------------------------------------------------- - -include $(PROTODIR)/test/PTMakefile - -build:: - ln -f find_alloc ../example-7.2 - -#clean:: -#depend:: Index: src/libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore diff -u src/libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore:1.1.2.1 src/libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore:removed --- src/libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore:1.1.2.1 Thu Dec 27 20:12:00 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.3/.cvsignore Sat Dec 29 16:53:20 2001 @@ -1,10 +0,0 @@ -total_alloc.cc -memleak.cc -memleak2.cc -marker.cc -marker2.cc -total_alloc -memleak -memleak2 -marker -marker2 Index: src/libcwd/documentation/tutorial/examples7/tut7.3/Makefile diff -u src/libcwd/documentation/tutorial/examples7/tut7.3/Makefile:1.1.2.1 src/libcwd/documentation/tutorial/examples7/tut7.3/Makefile:removed --- src/libcwd/documentation/tutorial/examples7/tut7.3/Makefile:1.1.2.1 Thu Dec 27 20:12:00 2001 +++ src/libcwd/documentation/tutorial/examples7/tut7.3/Makefile Sat Dec 29 16:53:20 2001 @@ -1,35 +0,0 @@ -# Directory where the base Makefile resides: -BASEDIR=.. - -# List of source files (one per executable): -CSRC= -CXXSRC=total_alloc.cc marker.cc marker2.cc memleak.cc memleak2.cc - -# List of sub directories: -SUBDIRS= - -# Extra static libraries to link with: -STATICLIBS= - -# Extra shared libraries to link with: -SHAREDLIBS=-lcwd - -# Put here extra -L... flags -LIBFLAGS= - -# Extra *.o files that need to be linked: -EXTRA_OBJS= - -#----------------------------------------------------------------------------- - -include $(PROTODIR)/test/PTMakefile - -build:: - ln -f total_alloc ../example-7.3.1 - ln -f marker.cc ../example-7.3.2 - ln -f marker2.cc ../example-7.3.3 - ln -f memleak.cc ../example-7.3.4 - ln -f memleak2.cc ../example-7.3.5 - -#clean:: -#depend:: ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 00:55:15
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-30 00:55:14 UTC Removed files: Tag: branch-threading libcwd/documentation/tutorial/examples7/Makedefs.h libcwd/documentation/tutorial/examples7/Makefile Log message: Work in progress. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/tutorial/examples7/Makedefs.h diff -u src/libcwd/documentation/tutorial/examples7/Makedefs.h:1.1.2.1 src/libcwd/documentation/tutorial/examples7/Makedefs.h:removed --- src/libcwd/documentation/tutorial/examples7/Makedefs.h:1.1.2.1 Thu Dec 27 20:12:00 2001 +++ src/libcwd/documentation/tutorial/examples7/Makedefs.h Sat Dec 29 16:55:14 2001 @@ -1,103 +0,0 @@ -# This file contains the Project specific variables. -# -# Extra parameters can be added to the following variables: -# -# CFLAGS, CXXFLAGS, INCLUDEFLAGS, SYSTEMINCLUDEFLAGS, LDFLAGS. -# -# Always use a += for these variables to *add* parameters rather -# than overriding them! - -# -# CFLAGS / CXXFLAGS -# -# Project specific compiler flags. -# -# Use this when profiling: - -##CFLAGS=-pg -O6 -pipe -##CXXFLAGS=-pg -O6 -pipe -fno-exceptions -##LDFLAGS=-pg - -# Add extra, project specific, defines here, etc. - -##CFLAGS+=-D__MYCLIB__ -CXXFLAGS+=-DCWDEBUG - -# -# INCLUDEFLAGS -# -# Project specific "include" flags. -# -# These directories are searched when you use an #include "foobar.h" -# in your source code. -# -# The given directories will be relative to the directory from which -# the compiler is started, which is the directory that the source -# file being compiled is in. Therefore always use -I$(BASEDIR) as -# a prefix (BASEDIR is the directory this file is in). -# -# Note: If you want to add an include directory that is specific for -# only one executable or library, you might want to add this -I flag -# to the Makefile for that executable or library respectively instead. - -INCLUDEFLAGS+=-I$(BASEDIR) - -# -# SYSTEMINCLUDEFLAGS -# -# Project specific system <include> flags. -# -# These directories are searched when you use a #include <foobar.h> -# in your source code. -# -# Note: If you are writting a library, then you want to use -# #include <yourlib/foobar.h> in your headerfiles, because later on -# these header files are installed in /usr/local/include for instance. -# In that case you need to add -I$(BASEDIR)/include *here* instead -# to in INCLUDEFLAGS above. -# - -SYSTEMINCLUDEFLAGS+=-I$(BASEDIR)/sysinclude -I$(BASEDIR)/../../../include - -# -# LDFLAGS -# -# Project specific linker flags (Overridden flags: -s or -pg ...) -# -# These flags are passed to the compiler at link time, these flags -# are given a default value in $(PROTODIR)/Makedefs.h. You can -# override them here. -# - -LIBPATH:=$(shell (cd $(BASEDIR)/../../../.libs; pwd)) -LDFLAGS=-Wl,-rpath,$(LIBPATH) - -# -# LIBFLAGS -# -# Project specific linker flags (Persistent flags: -L and -Wl,...) -# -# If you want to link your (test) executables with the latest version of -# your project library instead of the version that was actually installed -# in /usr/local (for example), then you need to add -L$(BASEDIR)/lib to -# LIBFLAGS. - -LIBFLAGS+=-L$(BASEDIR)/../../../.libs - -# -# DFLAGS -# -# Extra flags for generating dependencies. -# The default is -MM, only including "local" headers. -# Use this if you need dependencies on <system> headers, -# (for example when you are writing a library and are using <headers> -# with angle brackets yourself). - -##DFLAGS=-M - -# -# CPPEXT -# -# The C++ extension that is used in this project. Correct this! - -CPPEXT=.cc Index: src/libcwd/documentation/tutorial/examples7/Makefile diff -u src/libcwd/documentation/tutorial/examples7/Makefile:1.1.2.1 src/libcwd/documentation/tutorial/examples7/Makefile:removed --- src/libcwd/documentation/tutorial/examples7/Makefile:1.1.2.1 Thu Dec 27 20:12:00 2001 +++ src/libcwd/documentation/tutorial/examples7/Makefile Sat Dec 29 16:55:14 2001 @@ -1,13 +0,0 @@ -# List of subdirectories (automatically updated by `makeproto'): -SUBDIRS=tut7.1 tut7.2 tut7.3 - -#----------------------------------------------------------------------------- - -include $(PROTODIR)/base/PTMakefile - -# Add here project specific additions: - -#build:: -#depend:: -#clean:: -#real-clean:: ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 01:22:21
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-30 01:22:19 UTC Modified files: Tag: branch-threading libcwd/documentation/tutorial/Makefile Added files: libcwd/documentation/tutorial/examples5/.cvsignore libcwd/documentation/tutorial/examples5/sys.h Tag: branch-threading libcwd/documentation/tutorial/moo.awk libcwd/documentation/tutorial/tut5.in libcwd/documentation/tutorial/tut7.in Removed files: Tag: branch-threading libcwd/documentation/tutorial/tut5.m4 libcwd/documentation/tutorial/tut7.m4 Log message: Improvement of build system for tutorial. Now it should build only what is necessary, using the Makefile dependency rules. Got rid of 'prototype'. Some dependency rules are still missing. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/tutorial/Makefile diff -u src/libcwd/documentation/tutorial/Makefile:1.1.2.1 src/libcwd/documentation/tutorial/Makefile:1.1.2.2 --- src/libcwd/documentation/tutorial/Makefile:1.1.2.1 Thu Dec 27 20:11:59 2001 +++ src/libcwd/documentation/tutorial/Makefile Sat Dec 29 17:22:09 2001 @@ -1,40 +1,63 @@ .SUFFIXES: .PHONY: examples html -FILES5:=$(shell grep 'START CODE' tut5.m4 | cut -d \ -f4) -FILES7:=$(shell grep 'START CODE' tut7.m4 | cut -d \ -f4) +SOURCES5:=$(shell grep 'START CODE' tut5.in | cut -d \ -f4) +SOURCES7:=$(shell grep 'START CODE' tut7.in | cut -d \ -f4) +AOUT5:=$(shell grep 'START OUTPUT' tut5.in | cut -d \ -f4) +AOUT7:=$(shell grep 'START OUTPUT' tut7.in | cut -d \ -f4) all: examples html -examples: $(FILES5) $(FILES7) +examples: $(SOURCES5) $(SOURCES7) html: index.html faq.html intro.html tut1.html tut2.html tut3.html tut4.html tut5.html tut6.html tut7.html %.html: %.m4 ../definitions.m4 m4 -D__TUTORIAL=1 -I.. $< > $@ -$(FILES5): tut5.m4 ../../.libs/libcwd.so - @$(MAKE) $@-x +tut5.m4: tut5.in $(AOUT5) + awk -f moo.awk $< > $@ -$(FILES7): tut7.m4 ../../.libs/libcwd.so - @$(MAKE) -s $@-x - -%-x: - @IN=`echo $* | sed -e 's/examples\([57]\).*/tut\1.m4/'`; \ - grep -A1000 "START CODE $*" $$IN |\ - grep -B1000 "END CODE $*" |\ - egrep -v "(START|END) CODE $*" |\ - sed -e 's/</</g' -e 's/>/>/g' -e 's/&/\&/g' -e 's/"/"/g' -e 's/§/§/g' \ - -e 's/<SPAN.[^>]*>//g' -e 's/<\/SPAN>//g' > $*.tmp; \ - if (test ! -f $* || ! cmp -s $* $*.tmp); then \ - echo "Extracting $* from $$IN."; \ - mv $*.tmp $*; \ +tut7.m4: tut7.in $(AOUT7) + awk -f moo.awk $< > $@ + +$(SOURCES5): tut5.in ../../.libs/libcwd.so + @$(MAKE) -s $@-cc + +$(SOURCES7): tut7.in ../../.libs/libcwd.so + @$(MAKE) -s $@-cc + +%-cc: + @IN=`echo $* | sed -e 's/examples\([57]\).*/tut\1.in/'`; \ + if grep "END CODE $*" $$IN >/dev/null; then \ + grep -A1000 "START CODE $*" $$IN |\ + grep -B1000 "END CODE $*" |\ + egrep -v "(START|END) CODE $*" |\ + sed -e 's/</</g' -e 's/>/>/g' -e 's/&/\&/g' -e 's/"/"/g' -e 's/§/§/g' \ + -e 's/<SPAN.[^>]*>//g' -e 's/<\/SPAN>//g' > $*.tmp; \ + if (test ! -f $* || ! cmp -s $* $*.tmp); then \ + echo "Extracting $* from $$IN."; \ + mv $*.tmp $*; \ + else \ + echo "$* wasn't changed."; \ + touch $*; \ + rm $*.tmp; \ + fi; \ else \ - echo "$* wasn't changed."; \ - touch $*; \ - rm $*.tmp; \ - fi; \ - OUT=`echo $(*F) | sed -e 's/\.[ch]*$$//'`; \ - if test "$$OUT" != "debug"; then \ - $(MAKE) -C $(*D) $$OUT; \ + echo "No line with \"END CODE $*\" in $$IN!"; \ + exit 1; \ fi + +examples5/%-bin: %.cc examples5/debug.o examples5/sys.h + $(CXX) -g -pipe -DCWDEBUG -Iexamples5 -I- -Iexamples5/sysinclude -I../../include \ + $< examples5/debug.o -L../../.libs/libcwd.so -Wl,-rpath,$(shell (../../.libs; pwd)) -lcwd -o $@ + +examples5/debug.o: examples5/debug.cc + $(CXX) -g -pipe -DCWDEBUG -Iexamples5 -Iexamples5/sysinclude -I../../include -c $< -o $@ + +examples7/%-bin: %.cc examples7/sys.h examples7/debug.h + $(CXX) -g -pipe -DCWDEBUG -Iexamples7 -I- -I../../include \ + $< -L../../.libs/libcwd.so -Wl,-rpath,$(shell (../../.libs; pwd)) -lcwd -o $@ + +maintainer-clean: + rm -f examples5/debug.* examples5/test* core examples7/test* tut5.m4 tut7.m4 *.html Index: src/libcwd/documentation/tutorial/examples5/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/examples5/.cvsignore:1.1 --- /dev/null Sat Dec 29 17:22:20 2001 +++ src/libcwd/documentation/tutorial/examples5/.cvsignore Sat Dec 29 17:22:09 2001 @@ -0,0 +1,5 @@ +debug.cc +debug.h +sys.h +test* + Index: src/libcwd/documentation/tutorial/examples5/sys.h diff -u /dev/null src/libcwd/documentation/tutorial/examples5/sys.h:1.1 --- /dev/null Sat Dec 29 17:22:20 2001 +++ src/libcwd/documentation/tutorial/examples5/sys.h Sat Dec 29 17:22:09 2001 @@ -0,0 +1,6 @@ +#ifdef HAVE_CONFIG_H // This is just an example of what you could do +#include "config.h" // when using autoconf for your project. +#endif +#ifdef CWDEBUG // This is needed so that others can compile +#include <libcw/sysd.h> // your application without having libcwd installed. +#endif Index: src/libcwd/documentation/tutorial/moo.awk diff -u /dev/null src/libcwd/documentation/tutorial/moo.awk:1.1.2.1 --- /dev/null Sat Dec 29 17:22:20 2001 +++ src/libcwd/documentation/tutorial/moo.awk Sat Dec 29 17:22:09 2001 @@ -0,0 +1,12 @@ +/^<\!-- START OUTPUT .* -->$/ { + print; + sub(/^<\!-- START OUTPUT /,"",$0); + sub(/ -->$/,"",$0); + cmd=sprintf("%s 2>&1 | sed -e 's/&/\\&/g' -e 's/</\\</g' -e 's/>/\\>/g' -e 's/\"/\\"/g' -e 's/§/\\§/g'", $0); + system(cmd); + next; +} + +{ + print; +} Index: src/libcwd/documentation/tutorial/tut5.in diff -u /dev/null src/libcwd/documentation/tutorial/tut5.in:1.1.2.1 --- /dev/null Sat Dec 29 17:22:20 2001 +++ src/libcwd/documentation/tutorial/tut5.in Sat Dec 29 17:22:09 2001 @@ -0,0 +1,587 @@ +include(definitions.m4)dnl +__HTMLHEADER +__PAGEHEADER +__PAGESTART + +<H2>Tutorial 5: Advanced examples</H2> + +<P>In this tutorial you will learn how to list all debugging channels +and how to write a loop that runs over all existing debug channels. +You will make four debug channels in their own namespace and write debug output to a combination of them. +You will also learn how to add an error message after a debug message, how to format a debug message, +how to supress the label and how to supress the newline at the end. +Finally you will learn how to write interrupted debug output +in an example that prints the call to a system call and the result of that.</P> + +<A NAME="Running"></A> +<H3>5.1 Running over all Debug Channels</H3> + +<P>In <A HREF="tut2.html">tutorial 2</A> you have learned how to create new Debug Channels. +Each new Debug Channel is stored in an internal list, allowing +you to loop over all debug channels without knowing exactly which ones exist. +For example, the following code will <A HREF="tut1.html#turn_on_channel">turn on</A> all +debug channels. It is not allowed to call <CODE>on()</CODE> +for a Debug Channel that is already <I>on</I>: that will result in a runtime error.</P> + +<P>A special shortcut function is provided to list all debug channels, +the following code prints a list of all channels after they have been turned on.</P> + +<P>Compile as: <SPAN class="shell-command">g++ -g -DCWDEBUG test5.1.1.cc -lcwd -o turn_on</SPAN></P> +<P class="download">[<A HREF="examples5/test5.1.1.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/test5.1.1.cc --> +#include "sys.h" // See tutorial 2 +#include <libcw/debug.h> + +int main(void) +{ + // Turn on debug object `libcw_do'. + Debug( libcw_do.on() ); + + // Turn on all debug channels that are off. + <SPAN class="highlight">ForAllDebugChannels(</SPAN> + if (!<SPAN class="highlight">debugChannel</SPAN>.is_on()) + <SPAN class="highlight">debugChannel</SPAN>.on(); + <SPAN class="highlight">);</SPAN> + + // Print a listing of all debug channels to debug object `libcw_do'. + Debug( <SPAN class="highlight">list_channels_on(</SPAN>libcw_do<SPAN class="highlight">)</SPAN> ); + + return 0; +} +<!-- END CODE examples5/test5.1.1.cc --> +</PRE> + +<P>This program outputs:</P> + +<PRE class="output"> +<!-- START OUTPUT examples5/test5.1.1-bin --> +</PRE> + +<A NAME="Debug"></A> +<H3>5.2 Debug Channels and name spaces</H3> + +<P>The custom debug channel <CODE>dc::ghost</CODE> that you created +in <A HREF="tut2.html">tutorial 2</A> was put in <CODE>namespace debug_channels</CODE>. +The debug channels of libcw are put in namespace <CODE>libcw::debug::channels</CODE>. +Nevertheless, it is not necessary to type</P> + +<PRE>Dout( libcw::debug::channels::dc::notice, "Hello World" );</PRE> + +<P>By default, the macro <CODE>Dout</CODE> et al. automatically include a<CODE> using namespace libcw::debug::channels</CODE>. +It is possible to change this default namespace by defining <CODE>DEBUGCHANNELS</CODE> +<EM>before</EM> including the header file <CODE>libcw/debug.h</CODE>. +This is will be shown below.</P> + +<P>Of course, you can put your own debug channels also in namespace<CODE> libcw::debug::channels</CODE> +but that wouldn't garantee not to collide with a new debug channel added to libcw in the future, or +with debug channels of other libraries that would do the same.</P> + +<A NAME="debug.h"></A> +<P>In the following example we will define four new debug channels in their own +name space<CODE> example::debug::channels </CODE> by creating a project specific header file "debug.h" +which needs to be included instead of the debug.h from libcw.</P> + +<P>The example application below uses the fictitious libraries <SPAN STYLE="font-family: courier">libbooster</SPAN> +and <SPAN STYLE="font-family: courier">libturbo</SPAN>, both of which use libcwd themselfs and declare their own debug +channel namespaces <CODE>booster::debug::channels</CODE> and <CODE>turbo::debug::channels</CODE> according to +the rules as mentioned in the <A HREF="../html/group__chapter__custom__debug__h.html#libraries">reference manual</A>.</P> + +<P>The project header file "debug.h":</P> +<P class="download">[<A HREF="examples5/debug.h">download</A>]</P> +<PRE> +<!-- START CODE examples5/debug.h --> +#ifndef EXAMPLE_DEBUG_H +#define EXAMPLE_DEBUG_H + +#ifdef CWDEBUG + +#ifndef DEBUGCHANNELS // This test is only necessary in libraries +#define DEBUGCHANNELS ::example::debug::channels +#endif +#include <libbooster/debug.h> // Note that these will include +#include <libturbo/debug.h> // libcw/debug.h for us. + +namespace example { + namespace debug { + namespace channels { + namespace dc { + using namespace libcw::debug; // For class channel_ct + + // The list of debug channel namespaces of the libraries that we use: + // (These two already include libcw::debug::channels::dc) + using namespace ::booster::debug::channels::dc; + using namespace ::turbo::debug::channels::dc; + + // Our own debug channels: + extern channel_ct elephant; + extern channel_ct cat; + extern channel_ct mouse; + extern channel_ct owl; + + // When the libraries use the same name for any debug channels, + // then here is the place to `hide' these channels by redefining them. + // For example, if `libbooster' defined `notice' too (as does libcw) + // then we have to redefine it again: + static channel_ct& notice(libcw::debug::channels::dc::notice) + __attribute__ ((unused)); + + } // namespace dc + } // namespace channels + } // namespace debug +} // namespace example + +// The following is only necessary for libraries. +// Libraries should not use Dout() et al. in their own header files, +// instead we define our own macros here for use in those header files: +#define MyLibHeaderDout(cntrl, data) \ + LibcwDout(::example::debug::channels, ::libcw::debug::libcw_do, cntrl, data) +#define MyLibHeaderDoutFatal(cntrl, data) \ + LibcwDoutFatal(::example::debug::channels, ::libcw::debug::libcw_do, cntrl, data) + +#else // !CWDEBUG + +// This is needed so people who don't have libcwd installed can still compile it. +// The file "nodebug.h" is provided in the libcwd and needs to be included in your +// own package. +#include "nodebug.h" +#define MyLibHeaderDout(cntrl, data) +#define MyLibHeaderDoutFatal(cntrl, data) LibcwDoutFatal(::std, /*nothing*/, cntrl, data) + +#endif // !CWDEBUG + +#endif // EXAMPLE_DEBUG_H +<!-- END CODE examples5/debug.h --> +</PRE> + +<P>The source file "debug.cc":</P> +<P class="download">[<A HREF="examples5/debug.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/debug.cc --> +#include "sys.h" // See tutorial 2 +#include "debug.h" + +#ifdef CWDEBUG +using namespace libcw::debug; + +namespace example { + namespace debug { + namespace channels { + namespace dc { + channel_ct elephant("DUMBO"); + channel_ct cat("FELIX"); + channel_ct mouse("HILDAGO"); + channel_ct owl("EINSTEIN"); + } + } + } +} +#endif +<!-- END CODE examples5/debug.cc --> +</PRE> + +<A NAME="Combining"></A> +<H3>5.3 Combining channels</H3> + +<P>Debug channels can be on or off and they have a label. +Sometimes you might want to write certain debug output to a +debug object when <EM>any</EM> of a given list of debug channels is turned on. +The syntax to do that is based on the fact that debug channels can be viewed upon as a bit mask: +using <CODE>operator|</CODE>. +In the following example we will write debug output to several different combinations +of the custom debug channels that we defined in the previous paragraph.</P> + +<P>The source file "test5.3.1.cc":</P> +<P class="download">[<A HREF="examples5/test5.3.1.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/test5.3.1.cc --> +#include "sys.h" // See § 2 +#include "debug.h" // See § 5.2 + +int main(void) +{ + // Start with everything turned on: + Debug( libcw_do.on() ); + ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on() ); + + Dout( dc::elephant|dc::owl, "The elephant is called Dumbo, the owl is called Einstein." ); + + return 0; +} +<!-- END CODE examples5/test5.3.1.cc --> +</PRE> + +<P>This program outputs:</P> + +<PRE class="output"> +<!-- START OUTPUT examples5/test5.3.1-bin --> +</PRE> + +<P>using the label of the left most channel that is turned on.</P> + +<P>If we turn off <CODE>dc::elephant</CODE>:</P> + +<P class="download">[<A HREF="examples5/test5.3.2.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/test5.3.2.cc --> +#include "sys.h" +#include "debug.h" + +int main(void) +{ + // Start with everything turned on: + Debug( libcw_do.on() ); + ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on() ); + + <SPAN class="highlight">Debug( dc::elephant.off() );</SPAN> + Dout( dc::elephant|dc::owl, "The elephant is called Dumbo, the owl is called Einstein." ); + + return 0; +} +<!-- END CODE examples5/test5.3.2.cc --> +</PRE> + +<P>Then the program outputs</P> + +<PRE class="output"> +<!-- START OUTPUT examples5/test5.3.2-bin --> +</PRE> + +<A NAME="Formatting"></A> +<H3>5.4 Formatting debug output</H3> + +<P>It is possible to control the format of debug output in two different ways:</P> +<OL TYPE=1> +<LI>Per call to Dout, using control flags. +<LI>Persistantly per debug object, using methods of the debug object. +</OL> + +<A NAME="Control"></A> +<H4>5.4.1 Control flags</H4> + +<P>Control flags are unsigned integer bit-masks and are passed along to +<CODE>Dout</CODE> together with the debug channel(s). +For example, in the following code the newline that is normally printed after +each output is suppressed in the first call:</P> + +<P class="download">[<A HREF="examples5/test5.4.1.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/test5.4.1.cc --> +#include "sys.h" +#include "debug.h" + +int main(void) +{ + Debug( libcw_do.on() ); + Debug( dc::notice.on() ); + + Dout( dc::notice|nonewline_cf, "Hello, " ); + Dout( dc::notice, "World" ); + + return 0; +} +<!-- END CODE examples5/test5.4.1.cc --> +</PRE> + +<P>This program outputs:</P> + +<PRE class="output"> +<!-- START OUTPUT examples5/test5.4.1-bin --> +</PRE> + +<P>In order to supress the <EM>prefix</EM> in the second call we use +<CODE>noprefix_cf</CODE>:</P> + +<P class="download">[<A HREF="examples5/test5.4.2.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/test5.4.2.cc --> +#include "sys.h" +#include "debug.h" + +int main(void) +{ + Debug( libcw_do.on() ); + Debug( dc::notice.on() ); + + Dout( dc::notice|nonewline_cf, "Hello, " ); + Dout( dc::notice|<SPAN class="highlight">noprefix_cf</SPAN>, "World" ); + + return 0; +} +<!-- END CODE examples5/test5.4.2.cc --> +</PRE> + +<P>Now the output is</P> + +<PRE class="output"> +<!-- START OUTPUT examples5/test5.4.2-bin --> +</PRE> + +<P>There are in total eleven <EM>control flags</EM>, +see the <A HREF="../html/reference.html">Reference Manual</A> +for an <A HREF="../html/group__group__control__flags.html">overview</A>.</P> + +<P>Lets get a little bit more practical now. +In the next example we perform a system call and write this fact to <CODE>dc::notice</CODE> +in the same way as <SPAN class="filename">strace(1)</SPAN> would do; the fact that the call is made +is printed first. After the call returns we print the results.</P> + +<P class="download">[<A HREF="examples5/test5.4.3.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/test5.4.3.cc --> +#include "sys.h" +#include "debug.h" +#include <sys/stat.h> +#include <unistd.h> + +std::ostream& operator<<(std::ostream& os, struct stat const buf) +{ + os << "inode:" << buf.st_ino << "; " << "size:" << buf.st_size; + return os; +} + +std::ostream& operator<<(std::ostream& os, struct stat const* bufp) +{ + os << "{ " << *bufp << " }"; + return os; +} + +int main(int argc, char* argv[]) +{ + Debug( libcw_do.on() ); + Debug( dc::notice.on() ); + + if (argc != 2) + { + std::cerr << "Usage: " << argv[0] << " <file_name>\n"; + exit(-1); + } + + char const* file_name = argv[1]; + struct stat buf; + + // Warning: this is NOT the correct way to do this (see below) + Dout( dc::notice|nonewline_cf, + "stat(\"" << file_name << "\", " ); + + int ret = stat(file_name, &buf); + + Dout( dc::notice|noprefix_cf|cond_error_cf(ret != 0), + &buf << ") = " << ret ); + + return 0; +} +<!-- END CODE examples5/test5.4.3.cc --> +</PRE> + +<P>Note the use of <CODE>cond_error_cf(<EM>condition</EM>)</CODE> which is equal to +<CODE>error_cf</CODE> if the condition passed is true, or zero otherwise. +The result of <CODE>error_cf</CODE> is that an error message is printed +after the debug output according to the current value of <CODE>errno</CODE>. +When we run this program with parameter "/bin/ls" we get something like:</P> + +<PRE class="output"> +<!-- START OUTPUT examples5/test5.4.3-bin /bin/ls --> +</PRE> + +<P>And when we use a file that doesn't exist, we get something like:</P> + +<PRE class="output"> +NOTICE : stat("foobar", { inode:134572072; size:1 }) = -1: ENOENT (No such file or directory) +</PRE> + +<P>As you already might have noticed from the comment in the program, this is not +the correct way to do this. The reason that it is wrong is because the call +to <CODE>stat</CODE> could cause debug output itself. Well, it +couldn't in this case, but in a more general case it could :).</P> + +<P>Let us replace the call to <CODE>stat</CODE> by a function of +ourselfs that allocates memory (as certain system calls could do too!):</P> + +<P class="download">[<A HREF="examples5/test5.4.4.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/test5.4.4.cc --> +#include "sys.h" +#include "debug.h" +#include <sys/stat.h> +#include <unistd.h> + +std::ostream& operator<<(std::ostream& os, struct stat const buf) +{ + os << "inode:" << buf.st_ino << "; " << "size:" << buf.st_size; + return os; +} + +std::ostream& operator<<(std::ostream& os, struct stat const* bufp) +{ + os << "{ " << *bufp << " }"; + return os; +} + +// We only use this function to show what happens with the debug output, +// you shouldn't do anything like this in a real program. +int stat_with_buf_alloc(char const* file_name, struct stat*& bufp) +{ + bufp = new struct stat; + return stat(file_name, bufp); +} + +int main(int argc, char* argv[]) +{ + Debug( libcw_do.on() ); + Debug( dc::notice.on() ); + <SPAN class="highlight">Debug( dc::malloc.on() );</SPAN> + + if (argc != 2) + { + std::cerr << "Usage: " << argv[0] << " <file_name>\n"; + exit(-1); + } + + char const* file_name = argv[1]; + struct stat<SPAN class="highlight">*</SPAN> buf<SPAN class="highlight">p</SPAN>; + + // This is NOT the correct way to do this. + Dout( dc::notice|nonewline_cf, + "stat_with_buf_alloc(\"" << file_name << "\", " ); + + int ret = stat<SPAN class="highlight">_with_buf_alloc</SPAN>(file_name, buf<SPAN class="highlight">p</SPAN>); + + Dout( dc::notice|noprefix_cf|cond_error_cf(ret != 0), + bufp << ") = " << ret ); + + <SPAN class="highlight"> + Debug( dc::malloc.off() ); + delete bufp;</SPAN> + return 0; +} +<!-- END CODE examples5/test5.4.4.cc --> +</PRE> + +<P>Now the call (to <CODE>stat_with_buf_alloc</CODE>) writes debug output +itself which is completely messing up our beautiful attempt to look like the +output of <SPAN class="filename">strace(1)</SPAN>:</P> + +<PRE class="output"> +<!-- START OUTPUT examples5/test5.4.4-bin /bin/ls --> +</PRE> + +<A NAME="interrupted"></A> +<P>Therefore it isn't a good idea to use <CODE>nonewline_cf</CODE> and <CODE>noprefix_cf</CODE> like this. +Use instead <CODE>continued_cf</CODE>, <CODE>dc::continued</CODE> and <CODE>dc::finish</CODE> +which are designed especially for <EM>interrupted debug output</EM>:</P> + +<P class="download">[<A HREF="examples5/test5.4.5.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/test5.4.5.cc --> +#include "sys.h" +#include "debug.h" +#include <sys/stat.h> +#include <unistd.h> + +std::ostream& operator<<(std::ostream& os, struct stat const buf) +{ + os << "inode:" << buf.st_ino << "; " << "size:" << buf.st_size; + return os; +} + +std::ostream& operator<<(std::ostream& os, struct stat const* bufp) +{ + os << "{ " << *bufp << " }"; + return os; +} + +// We only use this function to show what happens with the debug output, +// you shouldn't do anything like this in a real program. +int stat_with_buf_alloc(char const* file_name, struct stat*& bufp) +{ + bufp = new struct stat; + return stat(file_name, bufp); +} + +int main(int argc, char* argv[]) +{ + Debug( libcw_do.on() ); + Debug( dc::notice.on() ); + Debug( dc::malloc.on() ); + + if (argc != 2) + { + std::cerr << "Usage: " << argv[0] << " <file_name>\n"; + exit(-1); + } + + char const* file_name = argv[1]; + struct stat* bufp; + + Dout( dc::notice|<SPAN class="highlight">continued_cf</SPAN>, + "stat_with_buf_alloc(\"" << file_name << "\", " ); + + int ret = stat_with_buf_alloc(file_name, bufp); + + Dout( <SPAN class="highlight">dc::finish</SPAN>|cond_error_cf(ret != 0), + bufp << ") = " << ret ); + + Debug( dc::malloc.off() ); + delete bufp; + return 0; +} +<!-- END CODE examples5/test5.4.5.cc --> +</PRE> + +<P>Now the output looks like</P> + +<PRE class="output"> +<!-- START OUTPUT examples5/test5.4.5-bin /bin/ls --> +</PRE> + +<A NAME="Methods"></A> +<H4>5.4.2 Methods of the debug object</H4> + +<P>You can also change the format of debug output by calling methods of the debug object. +Consider the following example:</P> + +<P class="download">[<A HREF="examples5/test5.4.6.cc">download</A>]</P> +<PRE> +<!-- START CODE examples5/test5.4.6.cc --> +#include "sys.h" +#include "debug.h" + +int main(void) +{ + Debug( libcw_do.on() ); + ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on() ); + + Debug( libcw_do.<SPAN class="highlight">set_margin</SPAN>("<-- margin -->") ); + Debug( libcw_do.<SPAN class="highlight">set_marker</SPAN>("<-- marker -->") ); + Dout( dc::cat|dc::mouse, "The cat chases the mouse." ); + Dout( dc::mouse|dc::elephant, "The mouse chases the elephant." ); + Dout( dc::notice|<SPAN class="highlight">nolabel_cf</SPAN>, "Setting indentation to 8 spaces:" ); + Dout( dc::notice|<SPAN class="highlight">blank_label_cf</SPAN>, "<------>" ); + Debug( libcw_do.<SPAN class="highlight">set_indent(8)</SPAN> ); + Dout( dc::cat, "The cat sleeps." ); + Dout( dc::elephant, "The elephant looks around:" ); + Dout( dc::elephant|<SPAN class="highlight">blank_label_cf|blank_marker_cf</SPAN>, "where did the mouse go?" ); + + return 0; +} +<!-- END CODE examples5/test5.4.6.cc --> +</PRE> + +<P>This program outputs:</P> +<PRE class="output"> +<!-- START OUTPUT examples5/test5.4.6-bin --> +</PRE> + +<P>This concludes the first part of this tutorial about debug output. +The following chapters handle the memory allocation debugging support of libcwd.</P> + +__PAGEEND +<P class="line"><IMG width=870 height=25 src="../images/lines/owl.png"></P> +<DIV class="buttons"> +<A HREF="tut4.html"><IMG width=64 height=32 src="../images/buttons/lr_prev.png" border="0"></A> +<A HREF="index.html"><IMG width=64 height=32 src="../images/buttons/lr_index.png" border="0"></A> +<A HREF="tut6.html"><IMG width=64 height=32 src="../images/buttons/lr_next.png" border="0"></A> +</DIV> +__PAGEFOOTER +__HTMLFOOTER Index: src/libcwd/documentation/tutorial/tut5.m4 diff -u src/libcwd/documentation/tutorial/tut5.m4:1.1.2.1 src/libcwd/documentation/tutorial/tut5.m4:removed --- src/libcwd/documentation/tutorial/tut5.m4:1.1.2.1 Thu Dec 27 20:11:59 2001 +++ src/libcwd/documentation/tutorial/tut5.m4 Sat Dec 29 17:22:20 2001 @@ -1,682 +0,0 @@ -include(definitions.m4)dnl -__HTMLHEADER -__PAGEHEADER -__PAGESTART - -<H2>Tutorial 5: Advanced examples</H2> - -<P>In this tutorial you will learn how to list all debugging channels -and how to write a loop that runs over all existing debug channels. -You will make four debug channels in their own namespace and write debug output to a combination of them. -You will also learn how to add an error message after a debug message, how to format a debug message, -how to supress the label and how to supress the newline at the end. -Finally you will learn how to write interrupted debug output -in an example that prints the call to a system call and the result of that.</P> - -<A NAME="Running"></A> -<H3>5.1 Running over all Debug Channels</H3> - -<P>In <A HREF="tut2.html">tutorial 2</A> you have learned how to create new Debug Channels. -Each new Debug Channel is stored in an internal list, allowing -you to loop over all debug channels without knowing exactly which ones exist. -For example, the following code will <A HREF="tut1.html#turn_on_channel">turn on</A> all -debug channels. It is not allowed to call <CODE>on()</CODE> -for a Debug Channel that is already <I>on</I>: that will result in a runtime error.</P> - -<P>A special shortcut function is provided to list all debug channels, -the following code prints a list of all channels after they have been turned on.</P> - -<P>Compile as: <SPAN class="shell-command">g++ -g -DCWDEBUG turn_on.cc -lcwd -o turn_on</SPAN></P> -<P class="download">[<A HREF="examples5/tut5.1/turn_on.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.1/turn_on.cc --> -#include "sys.h" // See tutorial 2 -#include <libcw/debug.h> - -int main(void) -{ - // Turn on debug object `libcw_do'. - Debug( libcw_do.on() ); - - // Turn on all debug channels that are off. - <SPAN class="highlight">ForAllDebugChannels(</SPAN> - if (!<SPAN class="highlight">debugChannel</SPAN>.is_on()) - <SPAN class="highlight">debugChannel</SPAN>.on(); - <SPAN class="highlight">);</SPAN> - - // Print a listing of all debug channels to debug object `libcw_do'. - Debug( <SPAN class="highlight">list_channels_on(</SPAN>libcw_do<SPAN class="highlight">)</SPAN> ); - - return 0; -} -<!-- END CODE examples5/tut5.1/turn_on.cc --> -</PRE> - -<P>This program outputs:</P> - -<PRE class="output"> -<!-- START OUTPUT examples5/tut5.1/turn_on.cc turn_on --> -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/documentation/tutorial/examples5/tut5.1/turn_on... done (71 symbols) -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/.libs/libcwd.so.0 (0x40018000) ... done (854 symbols) -BFD : Loading debug info from /usr/lib/libstdc++-libc6.2-2.so.3 (0x40069000) ... done (1602 symbols) -BFD : Loading debug info from /lib/i686/libm.so.6 (0x400ab000) ... done (1430 symbols) -BFD : Loading debug info from /lib/i686/libc.so.6 (0x400ce000) ... done (4189 symbols) -BFD : Loading debug info from /lib/libdl.so.2 (0x40208000) ... done (52 symbols) -BFD : Loading debug info from /lib/ld-linux.so.2 (0x40000000) ... done (281 symbols) -BFD : Enabled -DEBUG : Enabled -MALLOC : Enabled -NOTICE : Enabled -SYSTEM : Enabled -WARNING : Enabled -<!-- END OUTPUT examples5/tut5.1/turn_on.cc --> -</PRE> - -<A NAME="Debug"></A> -<H3>5.2 Debug Channels and name spaces</H3> - -<P>The custom debug channel <CODE>dc::ghost</CODE> that you created -in <A HREF="tut2.html">tutorial 2</A> was put in <CODE>namespace debug_channels</CODE>. -The debug channels of libcw are put in namespace <CODE>libcw::debug::channels</CODE>. -Nevertheless, it is not necessary to type</P> - -<PRE>Dout( libcw::debug::channels::dc::notice, "Hello World" );</PRE> - -<P>By default, the macro <CODE>Dout</CODE> et al. automatically include a<CODE> using namespace libcw::debug::channels</CODE>. -It is possible to change this default namespace by defining <CODE>DEBUGCHANNELS</CODE> -<EM>before</EM> including the header file <CODE>libcw/debug.h</CODE>. -This is will be shown below.</P> - -<P>Of course, you can put your own debug channels also in namespace<CODE> libcw::debug::channels</CODE> -but that wouldn't garantee not to collide with a new debug channel added to libcw in the future, or -with debug channels of other libraries that would do the same.</P> - -<A NAME="debug.h"></A> -<P>In the following example we will define four new debug channels in their own -name space<CODE> example::debug::channels </CODE> by creating a project specific header file "debug.h" -which needs to be included instead of the debug.h from libcw.</P> - -<P>The example application below uses the fictitious libraries <SPAN STYLE="font-family: courier">libbooster</SPAN> -and <SPAN STYLE="font-family: courier">libturbo</SPAN>, both of which use libcwd themselfs and declare their own debug -channel namespaces <CODE>booster::debug::channels</CODE> and <CODE>turbo::debug::channels</CODE> according to -the rules as mentioned in the <A HREF="../html/group__chapter__custom__debug__h.html#libraries">reference manual</A>.</P> - -<P>The project header file "debug.h":</P> -<P class="download">[<A HREF="examples5/tut5.2/debug.h">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.2/debug.h --> -#ifndef EXAMPLE_DEBUG_H -#define EXAMPLE_DEBUG_H - -#ifdef CWDEBUG - -#ifndef DEBUGCHANNELS // This test is only necessary in libraries -#define DEBUGCHANNELS ::example::debug::channels -#endif -#include <libbooster/debug.h> // Note that these will include -#include <libturbo/debug.h> // libcw/debug.h for us. - -namespace example { - namespace debug { - namespace channels { - namespace dc { - using namespace libcw::debug; // For class channel_ct - - // The list of debug channel namespaces of the libraries that we use: - // (These two already include libcw::debug::channels::dc) - using namespace ::booster::debug::channels::dc; - using namespace ::turbo::debug::channels::dc; - - // Our own debug channels: - extern channel_ct elephant; - extern channel_ct cat; - extern channel_ct mouse; - extern channel_ct owl; - - // When the libraries use the same name for any debug channels, - // then here is the place to `hide' these channels by redefining them. - // For example, if `libbooster' defined `notice' too (as does libcw) - // then we have to redefine it again: - static channel_ct& notice(libcw::debug::channels::dc::notice) - __attribute__ ((unused)); - - } // namespace dc - } // namespace channels - } // namespace debug -} // namespace example - -// The following is only necessary for libraries. -// Libraries should not use Dout() et al. in their own header files, -// instead we define our own macros here for use in those header files: -#define MyLibHeaderDout(cntrl, data) \ - LibcwDout(::example::debug::channels, ::libcw::debug::libcw_do, cntrl, data) -#define MyLibHeaderDoutFatal(cntrl, data) \ - LibcwDoutFatal(::example::debug::channels, ::libcw::debug::libcw_do, cntrl, data) - -#else // !CWDEBUG - -// This is needed so people who don't have libcwd installed can still compile it. -// The file "nodebug.h" is provided in the libcwd and needs to be included in your -// own package. -#include "nodebug.h" -#define MyLibHeaderDout(cntrl, data) -#define MyLibHeaderDoutFatal(cntrl, data) LibcwDoutFatal(::std, /*nothing*/, cntrl, data) - -#endif // !CWDEBUG - -#endif // EXAMPLE_DEBUG_H -<!-- END CODE examples5/tut5.2/debug.h --> -</PRE> - -<P>The source file "debug.cc":</P> -<P class="download">[<A HREF="examples5/tut5.2/debug.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.2/debug.cc --> -#include "sys.h" // See tutorial 2 -#include "debug.h" - -#ifdef CWDEBUG -using namespace libcw::debug; - -namespace example { - namespace debug { - namespace channels { - namespace dc { - channel_ct elephant("DUMBO"); - channel_ct cat("FELIX"); - channel_ct mouse("HILDAGO"); - channel_ct owl("EINSTEIN"); - } - } - } -} -#endif -<!-- END CODE examples5/tut5.2/debug.cc --> -</PRE> - -<A NAME="Combining"></A> -<H3>5.3 Combining channels</H3> - -<P>Debug channels can be on or off and they have a label. -Sometimes you might want to write certain debug output to a -debug object when <EM>any</EM> of a given list of debug channels is turned on. -The syntax to do that is based on the fact that debug channels can be viewed upon as a bit mask: -using <CODE>operator|</CODE>. -In the following example we will write debug output to several different combinations -of the custom debug channels that we defined in the previous paragraph.</P> - -<P>The source file "test1.cc":</P> -<P class="download">[<A HREF="examples5/tut5.3/test1.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.3/test1.cc --> -#include "sys.h" // See § 2 -#include "debug.h" // See § 5.2 - -int main(void) -{ - // Start with everything turned on: - Debug( libcw_do.on() ); - ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on() ); - - Dout( dc::elephant|dc::owl, "The elephant is called Dumbo, the owl is called Einstein." ); - - return 0; -} -<!-- END CODE examples5/tut5.3/test1.cc --> -</PRE> - -<P>This program outputs:</P> - -<PRE class="output"> -<!-- START OUTPUT examples5/tut5.3/test1.cc test1 --> -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/documentation/tutorial/examples5/tut5.3/test1... done (109 symbols) -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/.libs/libcwd.so.0 (0x40018000) ... done (854 symbols) -BFD : Loading debug info from /usr/lib/libstdc++-libc6.2-2.so.3 (0x40069000) ... done (1602 symbols) -BFD : Loading debug info from /lib/i686/libm.so.6 (0x400ab000) ... done (1430 symbols) -BFD : Loading debug info from /lib/i686/libc.so.6 (0x400ce000) ... done (4189 symbols) -BFD : Loading debug info from /lib/libdl.so.2 (0x40208000) ... done (52 symbols) -BFD : Loading debug info from /lib/ld-linux.so.2 (0x40000000) ... done (281 symbols) -DUMBO : The elephant is called Dumbo, the owl is called Einstein. -<!-- END OUTPUT examples5/tut5.3/test1.cc --> -</PRE> - -<P>using the label of the left most channel that is turned on.</P> - -<P>If we turn off <CODE>dc::elephant</CODE>:</P> - -<P class="download">[<A HREF="examples5/tut5.3/test2.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.3/test2.cc --> -#include "sys.h" -#include "debug.h" - -int main(void) -{ - // Start with everything turned on: - Debug( libcw_do.on() ); - ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on() ); - - <SPAN class="highlight">Debug( dc::elephant.off() );</SPAN> - Dout( dc::elephant|dc::owl, "The elephant is called Dumbo, the owl is called Einstein." ); - - return 0; -} -<!-- END CODE examples5/tut5.3/test2.cc --> -</PRE> - -<P>Then the program outputs</P> - -<PRE class="output"> -<!-- START OUTPUT examples5/tut5.3/test2.cc test2 --> -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/documentation/tutorial/examples5/tut5.3/test2... done (109 symbols) -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/.libs/libcwd.so.0 (0x40018000) ... done (854 symbols) -BFD : Loading debug info from /usr/lib/libstdc++-libc6.2-2.so.3 (0x40069000) ... done (1602 symbols) -BFD : Loading debug info from /lib/i686/libm.so.6 (0x400ab000) ... done (1430 symbols) -BFD : Loading debug info from /lib/i686/libc.so.6 (0x400ce000) ... done (4189 symbols) -BFD : Loading debug info from /lib/libdl.so.2 (0x40208000) ... done (52 symbols) -BFD : Loading debug info from /lib/ld-linux.so.2 (0x40000000) ... done (281 symbols) -EINSTEIN: The elephant is called Dumbo, the owl is called Einstein. -<!-- END OUTPUT examples5/tut5.3/test2.cc --> -</PRE> - -<A NAME="Formatting"></A> -<H3>5.4 Formatting debug output</H3> - -<P>It is possible to control the format of debug output in two different ways:</P> -<OL TYPE=1> -<LI>Per call to Dout, using control flags. -<LI>Persistantly per debug object, using methods of the debug object. -</OL> - -<A NAME="Control"></A> -<H4>5.4.1 Control flags</H4> - -<P>Control flags are unsigned integer bit-masks and are passed along to -<CODE>Dout</CODE> together with the debug channel(s). -For example, in the following code the newline that is normally printed after -each output is suppressed in the first call:</P> - -<P class="download">[<A HREF="examples5/tut5.4/test3.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.4/test3.cc --> -#include "sys.h" -#include "debug.h" - -int main(void) -{ - Debug( libcw_do.on() ); - Debug( dc::notice.on() ); - - Dout( dc::notice|nonewline_cf, "Hello, " ); - Dout( dc::notice, "World" ); - - return 0; -} -<!-- END CODE examples5/tut5.4/test3.cc --> -</PRE> - -<P>This program outputs:</P> - -<PRE class="output"> -<!-- START OUTPUT examples5/tut5.4/test3.cc test3 --> -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/documentation/tutorial/examples5/tut5.4/test3... done (105 symbols) -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/.libs/libcwd.so.0 (0x40018000) ... done (854 symbols) -BFD : Loading debug info from /usr/lib/libstdc++-libc6.2-2.so.3 (0x40069000) ... done (1602 symbols) -BFD : Loading debug info from /lib/i686/libm.so.6 (0x400ab000) ... done (1430 symbols) -BFD : Loading debug info from /lib/i686/libc.so.6 (0x400ce000) ... done (4189 symbols) -BFD : Loading debug info from /lib/libdl.so.2 (0x40208000) ... done (52 symbols) -BFD : Loading debug info from /lib/ld-linux.so.2 (0x40000000) ... done (281 symbols) -NOTICE : Hello, NOTICE : World -<!-- END OUTPUT examples5/tut5.4/test3.cc --> -</PRE> - -<P>In order to supress the <EM>prefix</EM> in the second call we use -<CODE>noprefix_cf</CODE>:</P> - -<P class="download">[<A HREF="examples5/tut5.4/test4.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.4/test4.cc --> -#include "sys.h" -#include "debug.h" - -int main(void) -{ - Debug( libcw_do.on() ); - Debug( dc::notice.on() ); - - Dout( dc::notice|nonewline_cf, "Hello, " ); - Dout( dc::notice|<SPAN class="highlight">noprefix_cf</SPAN>, "World" ); - - return 0; -} -<!-- END CODE examples5/tut5.4/test4.cc --> -</PRE> - -<P>Now the output is</P> - -<PRE class="output"> -<!-- START OUTPUT examples5/tut5.4/test4.cc test4 --> -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/documentation/tutorial/examples5/tut5.4/test4... done (105 symbols) -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/.libs/libcwd.so.0 (0x40018000) ... done (854 symbols) -BFD : Loading debug info from /usr/lib/libstdc++-libc6.2-2.so.3 (0x40069000) ... done (1602 symbols) -BFD : Loading debug info from /lib/i686/libm.so.6 (0x400ab000) ... done (1430 symbols) -BFD : Loading debug info from /lib/i686/libc.so.6 (0x400ce000) ... done (4189 symbols) -BFD : Loading debug info from /lib/libdl.so.2 (0x40208000) ... done (52 symbols) -BFD : Loading debug info from /lib/ld-linux.so.2 (0x40000000) ... done (281 symbols) -NOTICE : Hello, World -<!-- END OUTPUT examples5/tut5.4/test4.cc --> -</PRE> - -<P>There are in total eleven <EM>control flags</EM>, -see the <A HREF="../html/reference.html">Reference Manual</A> -for an <A HREF="../html/group__group__control__flags.html">overview</A>.</P> - -<P>Lets get a little bit more practical now. -In the next example we perform a system call and write this fact to <CODE>dc::notice</CODE> -in the same way as <SPAN class="filename">strace(1)</SPAN> would do; the fact that the call is made -is printed first. After the call returns we print the results.</P> - -<P class="download">[<A HREF="examples5/tut5.4/test5.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.4/test5.cc --> -#include "sys.h" -#include "debug.h" -#include <sys/stat.h> -#include <unistd.h> - -std::ostream& operator<<(std::ostream& os, struct stat const buf) -{ - os << "inode:" << buf.st_ino << "; " << "size:" << buf.st_size; - return os; -} - -std::ostream& operator<<(std::ostream& os, struct stat const* bufp) -{ - os << "{ " << *bufp << " }"; - return os; -} - -int main(int argc, char* argv[]) -{ - Debug( libcw_do.on() ); - Debug( dc::notice.on() ); - - if (argc != 2) - { - std::cerr << "Usage: " << argv[0] << " <file_name>\n"; - exit(-1); - } - - char const* file_name = argv[1]; - struct stat buf; - - // Warning: this is NOT the correct way to do this (see below) - Dout( dc::notice|nonewline_cf, - "stat(\"" << file_name << "\", " ); - - int ret = stat(file_name, &buf); - - Dout( dc::notice|noprefix_cf|cond_error_cf(ret != 0), - &buf << ") = " << ret ); - - return 0; -} -<!-- END CODE examples5/tut5.4/test5.cc --> -</PRE> - -<P>Note the use of <CODE>cond_error_cf(<EM>condition</EM>)</CODE> which is equal to -<CODE>error_cf</CODE> if the condition passed is true, or zero otherwise. -The result of <CODE>error_cf</CODE> is that an error message is printed -after the debug output according to the current value of <CODE>errno</CODE>. -When we run this program with parameter "/bin/ls" we get something like:</P> - -<PRE class="output"> -<!-- START OUTPUT examples5/tut5.4/test5.cc test5 /bin/ls --> -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/documentation/tutorial/examples5/tut5.4/test5... done (110 symbols) -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/.libs/libcwd.so.0 (0x40018000) ... done (854 symbols) -BFD : Loading debug info from /usr/lib/libstdc++-libc6.2-2.so.3 (0x40069000) ... done (1602 symbols) -BFD : Loading debug info from /lib/i686/libm.so.6 (0x400ab000) ... done (1430 symbols) -BFD : Loading debug info from /lib/i686/libc.so.6 (0x400ce000) ... done (4189 symbols) -BFD : Loading debug info from /lib/libdl.so.2 (0x40208000) ... done (52 symbols) -BFD : Loading debug info from /lib/ld-linux.so.2 (0x40000000) ... done (281 symbols) -NOTICE : stat("/bin/ls", { inode:10065; size:43740 }) = 0 -<!-- END OUTPUT examples5/tut5.4/test5.cc --> -</PRE> - -<P>And when we use a file that doesn't exist, we get something like:</P> - -<PRE class="output"> -NOTICE : stat("foobar", { inode:134572072; size:1 }) = -1: ENOENT (No such file or directory) -</PRE> - -<P>As you already might have noticed from the comment in the program, this is not -the correct way to do this. The reason that it is wrong is because the call -to <CODE>stat</CODE> could cause debug output itself. Well, it -couldn't in this case, but in a more general case it could :).</P> - -<P>Let us replace the call to <CODE>stat</CODE> by a function of -ourselfs that allocates memory (as certain system calls could do too!):</P> - -<P class="download">[<A HREF="examples5/tut5.4/test6.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.4/test6.cc --> -#include "sys.h" -#include "debug.h" -#include <sys/stat.h> -#include <unistd.h> - -std::ostream& operator<<(std::ostream& os, struct stat const buf) -{ - os << "inode:" << buf.st_ino << "; " << "size:" << buf.st_size; - return os; -} - -std::ostream& operator<<(std::ostream& os, struct stat const* bufp) -{ - os << "{ " << *bufp << " }"; - return os; -} - -// We only use this function to show what happens with the debug output, -// you shouldn't do anything like this in a real program. -int stat_with_buf_alloc(char const* file_name, struct stat*& bufp) -{ - bufp = new struct stat; - return stat(file_name, bufp); -} - -int main(int argc, char* argv[]) -{ - Debug( libcw_do.on() ); - Debug( dc::notice.on() ); - <SPAN class="highlight">Debug( dc::malloc.on() );</SPAN> - - if (argc != 2) - { - std::cerr << "Usage: " << argv[0] << " <file_name>\n"; - exit(-1); - } - - char const* file_name = argv[1]; - struct stat<SPAN class="highlight">*</SPAN> buf<SPAN class="highlight">p</SPAN>; - - // This is NOT the correct way to do this. - Dout( dc::notice|nonewline_cf, - "stat_with_buf_alloc(\"" << file_name << "\", " ); - - int ret = stat<SPAN class="highlight">_with_buf_alloc</SPAN>(file_name, buf<SPAN class="highlight">p</SPAN>); - - Dout( dc::notice|noprefix_cf|cond_error_cf(ret != 0), - bufp << ") = " << ret ); - - <SPAN class="highlight"> - Debug( dc::malloc.off() ); - delete bufp;</SPAN> - return 0; -} -<!-- END CODE examples5/tut5.4/test6.cc --> -</PRE> - -<P>Now the call (to <CODE>stat_with_buf_alloc</CODE>) writes debug output -itself which is completely messing up our beautiful attempt to look like the -output of <SPAN class="filename">strace(1)</SPAN>:</P> - -<PRE class="output"> -<!-- START OUTPUT examples5/tut5.4/test6.cc test6 /bin/ls --> -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/documentation/tutorial/examples5/tut5.4/test6... done (112 symbols) -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/.libs/libcwd.so.0 (0x40018000) ... done (854 symbols) -BFD : Loading debug info from /usr/lib/libstdc++-libc6.2-2.so.3 (0x40069000) ... done (1602 symbols) -BFD : Loading debug info from /lib/i686/libm.so.6 (0x400ab000) ... done (1430 symbols) -BFD : Loading debug info from /lib/i686/libc.so.6 (0x400ce000) ... done (4189 symbols) -BFD : Loading debug info from /lib/libdl.so.2 (0x40208000) ... done (52 symbols) -BFD : Loading debug info from /lib/ld-linux.so.2 (0x40000000) ... done (281 symbols) -NOTICE : stat_with_buf_alloc("/bin/ls", MALLOC : operator new (size = 88) = 0x8168b18 -{ inode:10065; size:43740 }) = 0 -<!-- END OUTPUT examples5/tut5.4/test6.cc --> -</PRE> - -<A NAME="interrupted"></A> -<P>Therefore it isn't a good idea to use <CODE>nonewline_cf</CODE> and <CODE>noprefix_cf</CODE> like this. -Use instead <CODE>continued_cf</CODE>, <CODE>dc::continued</CODE> and <CODE>dc::finish</CODE> -which are designed especially for <EM>interrupted debug output</EM>:</P> - -<P class="download">[<A HREF="examples5/tut5.4/test7.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.4/test7.cc --> -#include "sys.h" -#include "debug.h" -#include <sys/stat.h> -#include <unistd.h> - -std::ostream& operator<<(std::ostream& os, struct stat const buf) -{ - os << "inode:" << buf.st_ino << "; " << "size:" << buf.st_size; - return os; -} - -std::ostream& operator<<(std::ostream& os, struct stat const* bufp) -{ - os << "{ " << *bufp << " }"; - return os; -} - -// We only use this function to show what happens with the debug output, -// you shouldn't do anything like this in a real program. -int stat_with_buf_alloc(char const* file_name, struct stat*& bufp) -{ - bufp = new struct stat; - return stat(file_name, bufp); -} - -int main(int argc, char* argv[]) -{ - Debug( libcw_do.on() ); - Debug( dc::notice.on() ); - Debug( dc::malloc.on() ); - - if (argc != 2) - { - std::cerr << "Usage: " << argv[0] << " <file_name>\n"; - exit(-1); - } - - char const* file_name = argv[1]; - struct stat* bufp; - - Dout( dc::notice|<SPAN class="highlight">continued_cf</SPAN>, - "stat_with_buf_alloc(\"" << file_name << "\", " ); - - int ret = stat_with_buf_alloc(file_name, bufp); - - Dout( <SPAN class="highlight">dc::finish</SPAN>|cond_error_cf(ret != 0), - bufp << ") = " << ret ); - - Debug( dc::malloc.off() ); - delete bufp; - return 0; -} -<!-- END CODE examples5/tut5.4/test7.cc --> -</PRE> - -<P>Now the output looks like</P> - -<PRE class="output"> -<!-- START OUTPUT examples5/tut5.4/test7.cc test7 /bin/ls --> -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/documentation/tutorial/examples5/tut5.4/test7... done (113 symbols) -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/.libs/libcwd.so.0 (0x40018000) ... done (854 symbols) -BFD : Loading debug info from /usr/lib/libstdc++-libc6.2-2.so.3 (0x40069000) ... done (1602 symbols) -BFD : Loading debug info from /lib/i686/libm.so.6 (0x400ab000) ... done (1430 symbols) -BFD : Loading debug info from /lib/i686/libc.so.6 (0x400ce000) ... done (4189 symbols) -BFD : Loading debug info from /lib/libdl.so.2 (0x40208000) ... done (52 symbols) -BFD : Loading debug info from /lib/ld-linux.so.2 (0x40000000) ... done (281 symbols) -NOTICE : stat_with_buf_alloc("/bin/ls", <unfinished> -MALLOC : operator new (size = 88) = 0x8168fc0 -NOTICE : <continued> { inode:10065; size:43740 }) = 0 -<!-- END OUTPUT examples5/tut5.4/test7.cc --> -</PRE> - -<A NAME="Methods"></A> -<H4>5.4.2 Methods of the debug object</H4> - -<P>You can also change the format of debug output by calling methods of the debug object. -Consider the following example:</P> - -<P class="download">[<A HREF="examples5/tut5.4/test8.cc">download</A>]</P> -<PRE> -<!-- START CODE examples5/tut5.4/test8.cc --> -#include "sys.h" -#include "debug.h" - -int main(void) -{ - Debug( libcw_do.on() ); - ForAllDebugChannels( if (!debugChannel.is_on()) debugChannel.on() ); - - Debug( libcw_do.<SPAN class="highlight">set_margin</SPAN>("<-- margin -->") ); - Debug( libcw_do.<SPAN class="highlight">set_marker</SPAN>("<-- marker -->") ); - Dout( dc::cat|dc::mouse, "The cat chases the mouse." ); - Dout( dc::mouse|dc::elephant, "The mouse chases the elephant." ); - Dout( dc::notice|<SPAN class="highlight">nolabel_cf</SPAN>, "Setting indentation to 8 spaces:" ); - Dout( dc::notice|<SPAN class="highlight">blank_label_cf</SPAN>, "<------>" ); - Debug( libcw_do.<SPAN class="highlight">set_indent(8)</SPAN> ); - Dout( dc::cat, "The cat sleeps." ); - Dout( dc::elephant, "The elephant looks around:" ); - Dout( dc::elephant|<SPAN class="highlight">blank_label_cf|blank_marker_cf</SPAN>, "where did the mouse go?" ); - - return 0; -} -<!-- END CODE examples5/tut5.4/test8.cc --> -</PRE> - -<P>This program outputs:</P> -<PRE class="output"> -<!-- START OUTPUT examples5/tut5.4/test8.cc test8 --> -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/documentation/tutorial/examples5/tut5.4/test8... done (155 symbols) -BFD : Loading debug info from /home/carlo/c++/libcw_branch-threading/src/libcwd/.libs/libcwd.so.0 (0x40018000) ... done (854 symbols) -BFD : Loading debug info from /usr/lib/libstdc++-libc6.2-2.so.3 (0x40069000) ... done (1602 symbols) -BFD : Loading debug info from /lib/i686/libm.so.6 (0x400ab000) ... done (1430 symbols) -BFD : Loading debug info from /lib/i686/libc.so.6 (0x400ce000) ... done (4189 symbols) -BFD : Loading debug info from /lib/libdl.so.2 (0x40208000) ... done (52 symbols) -BFD : Loading debug info from /lib/ld-linux.so.2 (0x40000000) ... done (281 symbols) -<-- margin -->FELIX <-- marker -->The cat chases the mouse. -<-- margin -->HILDAGO <-- marker -->The mouse chases the elephant. -<-- margin -->Setting indentation to 8 spaces: -<-- margin --> <-- marker --><------> -<-- margin -->FELIX <-- marker --> The cat sleeps. -<-- margin -->DUMBO <-- marker --> The elephant looks around: -<-- margin --> where did the mouse go? -<!-- END OUTPUT examples5/tut5.4/test8.cc --> -</PRE> - -<P>This concludes the first part of this tutorial about debug output. -The following chapters handle the memory allocation debugging support of libcwd.</P> - -__PAGEEND -<P class="line"><IMG width=870 height=25 src="../images/lines/owl.png"></P> -<DIV class="buttons"> -<A HREF="tut4.html"><IMG width=64 height=32 src="../images/buttons/lr_prev.png" border="0"></A> -<A HREF="index.html"><IMG width=64 height=32 src="../images/buttons/lr_index.png" border="0"></A> -<A HREF="tut6.html"><IMG width=64 height=32 src="../images/buttons/lr_next.png" border="0"></A> -</DIV> -__PAGEFOOTER -__HTMLFOOTER Index: src/libcwd/documentation/tutorial/tut7.in diff -u /dev/null src/libcwd/documentation/tutorial/tut7.in:1.1.2.1 --- /dev/null Sat Dec 29 17:22:20 2001 +++ src/libcwd/documentation/tutorial/tut7.in Sat Dec 29 17:22:09 2001 @@ -0,0 +1,508 @@ +include(definitions.m4)dnl +__HTMLHEADER +__PAGEHEADER +__PAGESTART + +<H2>Tutorial 7: Advanced examples</H2> + +<P>In this tutorial you will learn how to make memory allocations +«invisible» so that they will not show up in the +Allocated memory Overview, how to find information about an +allocated memory block given an arbitrary pointer pointing +inside it and how to write simple memory-leak detection code.</P> + +<A NAME="Removing"></A> +<H3>7.1 Removing allocations from the Allocated memory Overview</H3> + +<P>Sometimes a program can allocate a very large number of memory blocks. +Having all of those in the Allocated memory Overview could make it +impractically large. Therefore it is possible to remove items from this list.</P> + +<P>In the following example we make one allocation invisible by +using the function <CODE>make_invisible()</CODE>:</P> + +<P>Compile as: <CODE>g++ -g -DCWDEBUG test7.1.1.cc -lcwd -o invisible</CODE></P> +<P class="download">[<A HREF="examples7/test7.1.1.cc">download</A>]</P> +<PRE> +<!-- START CODE examples7/test7.1.1.cc --> +#include "sys.h" +#include "debug.h" + +int main(void) +{ + Debug( libcw_do.on() ); + Debug( dc::malloc.on() ); + + int* first = new int; + AllocTag2(first, "first"); + + int* second = new int; + AllocTag2(second, "second"); + + Debug( list_allocations_on(libcw_do) ); + + Debug( <SPAN class="highlight">make_invisible(</SPAN>first<SPAN class="highlight">)</SPAN> ); + + Debug( list_allocations_on(libcw_do) ); + + delete second; + delete first; + + return 0; +} +<!-- END CODE examples7/test7.1.1.cc --> +</PRE> + +<P>The output of this program is</P> + +<PRE class="output"> +<!-- START OUTPUT examples7/test7.1.1-bin --> +</PRE> + +<P>As you can see, the first allocation at line 9 disappeared from the +overview after it was made invisible.</P> + +<P>Pointer validation at de-allocation is still performed however. +For instance, when we make a mistake when freeing the first <CODE>int</CODE>:</P> + +<P>Compile as: <CODE>g++ -g -DCWDEBUG test7.1.2.cc -lcwd -o coredump</CODE></P> +<P class="download">[<A HREF="examples7/test7.1.2.cc">download</A>]</P> +<PRE> +<!-- START CODE examples7/test7.1.2.cc --> +#include "sys.h" +#include "debug.h" + +int main(void) +{ + Debug( libcw_do.on() ); + Debug( dc::malloc.on() ); + + int* first = new int; + AllocTag2(first, "first"); + + int* second = new int; + AllocTag2(second, "second"); + + Debug( list_allocations_on(libcw_do) ); + + Debug( make_invisible(first) ); + + Debug( list_allocations_on(libcw_do) ); + + delete second; + delete <SPAN class="highlight">[]</SPAN> first; // Make a deliberate error + + return 0; +} +<!-- END CODE examples7/test7.1.2.cc --> +</PRE> + +<P>then the output becomes</P> + +<PRE class="output"> +<!-- START OUTPUT examples7/test7.1.2-bin --> +</PRE> + +<P>Also the function <CODE>test_delete()</CODE> still works:</P> + +<P>Compile as: <CODE>g++ -g -DCWDEBUG test7.1.3.cc -lcwd -o test_delete</CODE></P> +<P class="download">[<A HREF="examples7/test7.1.3.cc">download</A>]</P> +<PRE> +<!-- START CODE examples7/test7.1.3.cc --> +#include "sys.h" +#include "debug.h" + +int main(void) +{ + Debug( libcw_do.on() ); + Debug( dc::malloc.on() ); + Debug( dc::notice.on() ); + + void* p = malloc(3000); + + Debug( make_invisible(p) ); + Debug( list_allocations_on(libcw_do) ); + + Dout(dc::notice, "test_delete(" << p << ") = " << <SPAN class="highlight">test_delete(</SPAN>p<SPAN class="highlight">)</SPAN>); + free(p); + Dout(dc::notice, "test_delete(" << p << ") = " << <SPAN class="highlight">test_delete(</SPAN>p<SPAN class="highlight">)</SPAN>); + + return 0; +} +<!-- END CODE examples7/test7.1.3.cc --> +</PRE> + +<P>results in</P> + +<PRE class="output"> +<!-- START OUTPUT examples7/test7.1.3-bin --> +</PRE> + +<P>However, <CODE>find_alloc()</CODE>, the function that is explained in the next paragraph, +will <EM>fail</EM> to find an «invisible» block (it will return <CODE>NULL</CODE>).</P> + +<A NAME="Retrieving"></A> +<H3>7.2 Retrieving information about memory allocations</H3> + +<P>Libcwd allows the developer to generate powerful debugging output; aside from being able to test +if a given pointer points to the start of an allocated memory block, using <CODE>test_delete()</CODE>, +it is even possible to find all information about an allocated memory block that is also shown in the Allocated memory O... [truncated message content] |
From: Carlo W. <li...@us...> - 2001-12-30 02:05:37
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-30 02:05:36 UTC Modified files: Tag: branch-threading libcwd/documentation/tutorial/Makefile Log message: Bug fixes, better dependencies and more bug fixes. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/tutorial/Makefile diff -u src/libcwd/documentation/tutorial/Makefile:1.1.2.2 src/libcwd/documentation/tutorial/Makefile:1.1.2.3 --- src/libcwd/documentation/tutorial/Makefile:1.1.2.2 Sat Dec 29 17:22:09 2001 +++ src/libcwd/documentation/tutorial/Makefile Sat Dec 29 18:05:26 2001 @@ -20,10 +20,10 @@ tut7.m4: tut7.in $(AOUT7) awk -f moo.awk $< > $@ -$(SOURCES5): tut5.in ../../.libs/libcwd.so +$(SOURCES5): tut5.in @$(MAKE) -s $@-cc -$(SOURCES7): tut7.in ../../.libs/libcwd.so +$(SOURCES7): tut7.in @$(MAKE) -s $@-cc %-cc: @@ -47,16 +47,16 @@ exit 1; \ fi -examples5/%-bin: %.cc examples5/debug.o examples5/sys.h +examples5/%-bin: examples5/%.cc examples5/debug.o examples5/debug.h examples5/sys.h examples5/sysinclude/libbooster/debug.h examples5/sysinclude/libturbo/debug.h ../../.libs/libcwd.so $(CXX) -g -pipe -DCWDEBUG -Iexamples5 -I- -Iexamples5/sysinclude -I../../include \ - $< examples5/debug.o -L../../.libs/libcwd.so -Wl,-rpath,$(shell (../../.libs; pwd)) -lcwd -o $@ + $< examples5/debug.o -L../../.libs -Wl,-rpath,$(shell (cd ../../.libs; pwd)) -lcwd -o $@ -examples5/debug.o: examples5/debug.cc +examples5/debug.o: examples5/debug.cc examples5/debug.h examples5/sys.h examples5/sysinclude/libbooster/debug.h examples5/sysinclude/libturbo/debug.h $(CXX) -g -pipe -DCWDEBUG -Iexamples5 -Iexamples5/sysinclude -I../../include -c $< -o $@ -examples7/%-bin: %.cc examples7/sys.h examples7/debug.h +examples7/%-bin: examples7/%.cc examples7/sys.h examples7/debug.h ../../.libs/libcwd.so $(CXX) -g -pipe -DCWDEBUG -Iexamples7 -I- -I../../include \ - $< -L../../.libs/libcwd.so -Wl,-rpath,$(shell (../../.libs; pwd)) -lcwd -o $@ + $< -L../../.libs -Wl,-rpath,$(shell (cd ../../.libs; pwd)) -lcwd -o $@ maintainer-clean: rm -f examples5/debug.* examples5/test* core examples7/test* tut5.m4 tut7.m4 *.html ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 02:07:28
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-30 02:07:27 UTC Modified files: Tag: branch-threading libcwd/documentation/tutorial/.cvsignore libcwd/documentation/tutorial/Makefile Added files: Tag: branch-threading libcwd/documentation/tutorial/examples7/.cvsignore Log message: Build system now works. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/tutorial/.cvsignore diff -u src/libcwd/documentation/tutorial/.cvsignore:1.1.2.1 src/libcwd/documentation/tutorial/.cvsignore:1.1.2.2 --- src/libcwd/documentation/tutorial/.cvsignore:1.1.2.1 Thu Dec 27 20:11:59 2001 +++ src/libcwd/documentation/tutorial/.cvsignore Sat Dec 29 18:07:17 2001 @@ -1,7 +1,6 @@ hello_world channel log_file -turn_on -amo.cc -amo *.html +tut5.m4 +tut7.m4 Index: src/libcwd/documentation/tutorial/Makefile diff -u src/libcwd/documentation/tutorial/Makefile:1.1.2.3 src/libcwd/documentation/tutorial/Makefile:1.1.2.4 --- src/libcwd/documentation/tutorial/Makefile:1.1.2.3 Sat Dec 29 18:05:26 2001 +++ src/libcwd/documentation/tutorial/Makefile Sat Dec 29 18:07:17 2001 @@ -22,6 +22,7 @@ $(SOURCES5): tut5.in @$(MAKE) -s $@-cc + @rm -f core $(SOURCES7): tut7.in @$(MAKE) -s $@-cc Index: src/libcwd/documentation/tutorial/examples7/.cvsignore diff -u /dev/null src/libcwd/documentation/tutorial/examples7/.cvsignore:1.1.2.1 --- /dev/null Sat Dec 29 18:07:27 2001 +++ src/libcwd/documentation/tutorial/examples7/.cvsignore Sat Dec 29 18:07:17 2001 @@ -0,0 +1 @@ +test* ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 02:18:33
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-30 02:18:33 UTC Modified files: Tag: branch-threading libcwd/documentation/tutorial/Makefile libcwd/documentation/tutorial/tut5.in Log message: Removed a 'touch'. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/tutorial/Makefile diff -u src/libcwd/documentation/tutorial/Makefile:1.1.2.4 src/libcwd/documentation/tutorial/Makefile:1.1.2.5 --- src/libcwd/documentation/tutorial/Makefile:1.1.2.4 Sat Dec 29 18:07:17 2001 +++ src/libcwd/documentation/tutorial/Makefile Sat Dec 29 18:18:23 2001 @@ -40,7 +40,6 @@ mv $*.tmp $*; \ else \ echo "$* wasn't changed."; \ - touch $*; \ rm $*.tmp; \ fi; \ else \ Index: src/libcwd/documentation/tutorial/tut5.in diff -u src/libcwd/documentation/tutorial/tut5.in:1.1.2.1 src/libcwd/documentation/tutorial/tut5.in:1.1.2.2 --- src/libcwd/documentation/tutorial/tut5.in:1.1.2.1 Sat Dec 29 17:22:09 2001 +++ src/libcwd/documentation/tutorial/tut5.in Sat Dec 29 18:18:23 2001 @@ -491,8 +491,8 @@ return os; } -// We only use this function to show what happens with the debug output, -// you shouldn't do anything like this in a real program. +// We only use this function to show what happens with the debug output. +// You shouldn't do anything like this in a real program. int stat_with_buf_alloc(char const* file_name, struct stat*& bufp) { bufp = new struct stat; ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 02:37:32
|
CVSROOT : /cvsroot/libcw Module : src Branch tags: branch-threading Commit time: 2001-11-30 02:37:30 UTC Modified files: Tag: branch-threading libcwd/documentation/Makefile libcwd/documentation/styles/tutorial.css Log message: Removed TODO file. ---------------------- diff included ---------------------- Index: src/libcwd/documentation/Makefile diff -u src/libcwd/documentation/Makefile:1.1.2.4 src/libcwd/documentation/Makefile:1.1.2.5 --- src/libcwd/documentation/Makefile:1.1.2.4 Thu Dec 27 20:11:58 2001 +++ src/libcwd/documentation/Makefile Sat Dec 29 18:37:20 2001 @@ -35,5 +35,5 @@ $(MAKE) -C styles tutorial: - $(MAKE) -C tutorial + $(MAKE) -s -C tutorial Index: src/libcwd/documentation/styles/tutorial.css diff -u src/libcwd/documentation/styles/tutorial.css:1.1.2.1 src/libcwd/documentation/styles/tutorial.css:1.1.2.2 --- src/libcwd/documentation/styles/tutorial.css:1.1.2.1 Wed Dec 26 21:12:10 2001 +++ src/libcwd/documentation/styles/tutorial.css Sat Dec 29 18:37:20 2001 @@ -5,7 +5,7 @@ */ DIV.body { - margin-left : 2cm; + margin-left : 1cm; margin-right : 0; } ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 04:18:06
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-30 04:18:01 UTC Modified files: libcwd/INSTALL libcwd/Makefile.am libcwd/NEWS libcwd/README libcwd/acinclude.m4 libcwd/bfd.cc libcwd/configure.in libcwd/debug.cc libcwd/debugmalloc.cc libcwd/demangle.cc libcwd/demangle3.cc libcwd/elf32.cc libcwd/libcwd.spec.in libcwd/maintMakefile.in libcwd/strerrno.cc libcwd/type_info.cc libcwd/example-project/.cvsignore libcwd/example-project/Makefile.am libcwd/example-project/configure.in libcwd/example-project/debug.cc libcwd/example-project/macrotest.cc libcwd/example-project/program.cc libcwd/example-project/sys.h libcwd/include/Makefile.am libcwd/include/sys.ho.in libcwd/include/libcw/Makefile.am libcwd/include/libcw/bfd.h libcwd/include/libcw/buf2str.h libcwd/include/libcw/char2str.h libcwd/include/libcw/cwprint.h libcwd/include/libcw/debug.h libcwd/include/libcw/debug_config.ho.in libcwd/include/libcw/debugmalloc.h libcwd/include/libcw/demangle.h libcwd/include/libcw/lockable_auto_ptr.h libcwd/include/libcw/strerrno.h libcwd/include/libcw/sysd.ho.in libcwd/include/libcw/type_info.h libcwd/tests/.cvsignore libcwd/tests/Makefile.am libcwd/tests/dout_alloc.cc libcwd/tests/hello_world.cc libcwd/tests/hello_world_debug.h libcwd/tests/initbug.cc libcwd/tests/syslog.cc libcwd/tests/syslog_debug.h libcwd/testsuite/Makefile.in libcwd/testsuite/module.cc libcwd/testsuite/libcwd.tst/alloctag.cc libcwd/testsuite/libcwd.tst/alloctag.re libcwd/testsuite/libcwd.tst/bfd.cc libcwd/testsuite/libcwd.tst/bfd.re libcwd/testsuite/libcwd.tst/cf.cc libcwd/testsuite/libcwd.tst/continued.cc libcwd/testsuite/libcwd.tst/dc.cc libcwd/testsuite/libcwd.tst/debug.h libcwd/testsuite/libcwd.tst/demangler.cc libcwd/testsuite/libcwd.tst/demangler.re libcwd/testsuite/libcwd.tst/dlopen.cc libcwd/testsuite/libcwd.tst/dlopen.re libcwd/testsuite/libcwd.tst/do.cc libcwd/testsuite/libcwd.tst/do.re libcwd/testsuite/libcwd.tst/flush.cc libcwd/testsuite/libcwd.tst/leak.cc libcwd/testsuite/libcwd.tst/leak.re libcwd/testsuite/libcwd.tst/lockable_auto_ptr.cc libcwd/testsuite/libcwd.tst/magic.cc libcwd/testsuite/libcwd.tst/marker.cc libcwd/testsuite/libcwd.tst/test.exp libcwd/testsuite/libcwd.tst/test_delete.cc libcwd/testsuite/libcwd.tst/test_delete.re libcwd/testsuite/libcwd.tst/type_info.cc libcwd/utils/Makefile.am libcwd/utils/buf2str.cc libcwd/utils/char2str.cc libcwd/utils/exec_prog.cc Added files: libcwd/threading.cc libcwd/documentation/.cvsignore libcwd/documentation/Makefile libcwd/documentation/README libcwd/documentation/alloc_intro.dox libcwd/documentation/allocated_memory_overview.dox libcwd/documentation/control_flags.dox libcwd/documentation/custom-debug.h.dox libcwd/documentation/custom_do.dox libcwd/documentation/deallocation_pointer_validation.dox libcwd/documentation/debug_channels.dox libcwd/documentation/debug_object.dox libcwd/documentation/definitions.m4 libcwd/documentation/destination.dox libcwd/documentation/downloading.dox libcwd/documentation/doxygen.config libcwd/documentation/fatal_output.dox libcwd/documentation/finding.dox libcwd/documentation/formatting.dox libcwd/documentation/html.footer libcwd/documentation/html.header libcwd/documentation/invisible.dox libcwd/documentation/location.dox libcwd/documentation/locations.dox libcwd/documentation/magic.dox libcwd/documentation/mainpage.dox libcwd/documentation/memory_leak_checking.dox libcwd/documentation/modules.dox libcwd/documentation/namespaces.dox libcwd/documentation/nested.dox libcwd/documentation/preparation.dox libcwd/documentation/reference.dox libcwd/documentation/special.dox libcwd/documentation/symbols_intro.dox libcwd/documentation/type_info.dox libcwd/documentation/why_macro.dox libcwd/documentation/writing_intro.dox libcwd/documentation/doxygen-examples/markers.cc libcwd/documentation/external/.cvsignore libcwd/documentation/images/libcw_magic.png libcwd/documentation/images/libcwd_logo.png libcwd/documentation/images/toc.png libcwd/documentation/images/wink.gif libcwd/documentation/images/buttons/lr_index.png libcwd/documentation/images/buttons/lr_next.png libcwd/documentation/images/buttons/lr_prev.png libcwd/documentation/images/lines/cat.png libcwd/documentation/images/lines/caterpil.png libcwd/documentation/images/lines/ghost.png libcwd/documentation/images/lines/hippo.png libcwd/documentation/images/lines/mouse.png libcwd/documentation/images/lines/owl.png libcwd/documentation/images/lines/snail.png libcwd/documentation/scripts/break_out_of_frame.js libcwd/documentation/scripts/detect_browser.js libcwd/documentation/scripts/load_style_sheets.js libcwd/documentation/styles/.cvsignore libcwd/documentation/styles/Makefile libcwd/documentation/styles/defines.h libcwd/documentation/styles/doxygen.css libcwd/documentation/styles/main.css libcwd/documentation/styles/test.m4 libcwd/documentation/styles/tutorial.css libcwd/documentation/styles/ie/.cvsignore libcwd/documentation/styles/konqueror/.cvsignore libcwd/documentation/styles/mozilla/.cvsignore libcwd/documentation/styles/netscape4/.cvsignore libcwd/documentation/styles/netscape6/.cvsignore libcwd/documentation/tutorial/.cvsignore libcwd/documentation/tutorial/Makefile libcwd/documentation/tutorial/channel.cc libcwd/documentation/tutorial/faq.m4 libcwd/documentation/tutorial/hello_world.cc libcwd/documentation/tutorial/index.m4 libcwd/documentation/tutorial/intro.m4 libcwd/documentation/tutorial/log_file.cc libcwd/documentation/tutorial/moo.awk libcwd/documentation/tutorial/tut1.m4 libcwd/documentation/tutorial/tut2.m4 libcwd/documentation/tutorial/tut3.m4 libcwd/documentation/tutorial/tut4.m4 libcwd/documentation/tutorial/tut5.in libcwd/documentation/tutorial/tut6.m4 libcwd/documentation/tutorial/tut7.in libcwd/documentation/tutorial/examples7/.cvsignore libcwd/documentation/tutorial/examples7/debug.h libcwd/documentation/tutorial/examples7/sys.h libcwd/example-project/acconfig.h libcwd/example-project/debug.h.maintainer libcwd/include/cwd_debug.h libcwd/include/elf32.h libcwd/include/exec_prog.h libcwd/include/ios_base_Init.h libcwd/include/private_debug_stack.inl libcwd/include/libcw/class_alloc.h libcwd/include/libcw/class_channel.h libcwd/include/libcw/class_channel.inl libcwd/include/libcw/class_channel_set.h libcwd/include/libcw/class_channel_set.inl libcwd/include/libcw/class_continued_channel.h libcwd/include/libcw/class_continued_channel.inl libcwd/include/libcw/class_debug.h libcwd/include/libcw/class_debug.inl libcwd/include/libcw/class_debug_string.h libcwd/include/libcw/class_debug_string.inl libcwd/include/libcw/class_fatal_channel.h libcwd/include/libcw/class_fatal_channel.inl libcwd/include/libcw/class_location.h libcwd/include/libcw/class_location.inl libcwd/include/libcw/class_marker.h libcwd/include/libcw/control_flag.h libcwd/include/libcw/core_dump.h libcwd/include/libcw/enum_memblk_types.h libcwd/include/libcw/macro_AllocTag.h libcwd/include/libcw/macro_ForAllDebugChannels.h libcwd/include/libcw/macro_ForAllDebugObjects.h libcwd/include/libcw/macro_Libcwd_macros.h libcwd/include/libcw/max_label_len.h libcwd/include/libcw/pc_mangled_function_name.h libcwd/include/libcw/private_TSD.h libcwd/include/libcw/private_allocator.h libcwd/include/libcw/private_assert.h libcwd/include/libcw/private_debug_stack.h libcwd/include/libcw/private_internal_string.h libcwd/include/libcw/private_internal_stringstream.h libcwd/include/libcw/private_internal_vector.h libcwd/include/libcw/private_set_alloc_checking.h libcwd/include/libcw/private_threading.h libcwd/tests/allocator.cc libcwd/tests/stabs.cc libcwd/tests/threads.cc libcwd/tests/threads2.cc libcwd/tests/threads3.cc libcwd/tests/threads4.cc libcwd/tests/threads_debug.h libcwd/testsuite/libcwd.tst/sys.h Removed files: libcwd/README.nodebug.h libcwd/cwprint.cc libcwd/debugdebugcheckpoint.cc libcwd/no_alloc_checking_stringstream.cc libcwd/example-project/debug.h libcwd/example-project/maintMakefile.in libcwd/include/libcw/bcd2str.h libcwd/include/libcw/debugdebugcheckpoint.h libcwd/include/libcw/elf32.h libcwd/include/libcw/exec_prog.h libcwd/include/libcw/iomanip.h libcwd/include/libcw/no_alloc_checking_stringstream.h libcwd/include/libcw/perf.h libcwd/testsuite/libcwd.tst/undef.cc libcwd/testsuite/libcwd.tst/undef.re libcwd/utils/bcd2str.cc libcwd/utils/perf.cc Log message: Merge from branch-threading. ---------------------- diff included ---------------------- Index: src/libcwd/INSTALL diff -u src/libcwd/INSTALL:1.21 src/libcwd/INSTALL:1.22 --- src/libcwd/INSTALL:1.21 Sat Sep 22 22:01:08 2001 +++ src/libcwd/INSTALL Sat Dec 29 20:17:46 2001 @@ -3,6 +3,7 @@ ./configure --prefix=/usr make +su make install If that doesn't work, mail me: li...@al... @@ -14,101 +15,109 @@ Check if you have all GNU tools/libraries/packages that libcwd depends on: - Primary site: - ftp://ftp.gnu.org/gnu/ +Primary site: +ftp://ftp.gnu.org/gnu/ - List of mirrors: - http://www.gnu.org/order/ftp.html +List of mirrors: +http://www.gnu.org/order/ftp.html - Packages/versions needed - ------------------------ +Packages/versions needed +------------------------ - i) The GNU compiler, version 2.95.1 or higher. - - Location: gnu/gcc/ - Current version: 3.0 - - Alternatively you can install only - ia) gnu/gcc/gcc-core-<version>.tar.gz and - ib) gnu/gcc/gcc-g++-<version>.tar.gz - - Note: It is very unlikely that you want to install - the source tree of gcc/g++. Please try to upgrade your - compiler the usual way if needed. - If you are using rpm's then you will need to - install/upgrade the following: - gcc (2.95.1 or higher), - gcc-c++ (of same version), - libstdc++ (of same version) and - cpp (of same version). - Check your installation on RedHat with: - rpm -qa | egrep '(gcc|libstdc|cpp)' - - Note: If you don't use rpm's but are using tar balls, - then you do NOT need to download gnu/libstdc++/* because - gcc-2.95 and higher comes with libstdc++ included. - The gnu/libstdc++/ directory on GNU ftp sites are - for older compilers or to be used as source drop-in - when you compile g++ (replacing the normal stdc++ with - an alpha version). You also don't need libg++. - Don't delete those libraries if you have them though - since existing binaries might need to link with them. - - libcwd-0.99.15 was tested with gcc-2.95.x, gcc-2.96-97 (RedHat), - gcc-3.0 and gcc-3.0.1. - - Packages needed to run the testsuite - ------------------------------------ - - If you want to run the testsuite then you will have to install - dejagnu-1.4.1 which can be downloaded from ftp://ftp.gnu.org/gnu/dejagnu/, - or your local GNU mirror. However, this version still contains a bug - and you'll have to apply the following patch: edit /usr/share/dejagnu/target.exp - line 275 and remove the newline at the end (so that the word "text" on line - 276 is added at the end of line 275: - regsub -all ".*: warning: -f(pic|PIC) ignored for target .*" $text "" text - - Alternatively, you can get dejagnu directly from the cvs repository - at http://www.gnu.org/software/dejagnu/ where this bug already has been - fixed (as it will be in any version *after* 1.4.1). - - You will also need expect-5.32.2 (and tcl/tk 8.3.3?). At least, expect 5.31.2 - is known to hang. - - Packages/versions needed as maintainer or when using CVS - -------------------------------------------------------- - - If you want to generate maintainer files (and you need that when - you get this package via CVS) then you also need to have the - following tools: - - iii) GNU make - iv) GNU m4 - v) GNU which version 2.x - vi) autoconf version 2.13 (2.52 seems to have problems) - vii) automake version 1.4pl1 or higher - viii) libtool version 1.4 or higher +i) The GNU compiler, version 2.95.1 or higher. + + Location: gnu/gcc/ + Current version: 3.0.2 + +Alternatively you can install only +ia) gnu/gcc/gcc-core-<version>.tar.gz and +ib) gnu/gcc/gcc-g++-<version>.tar.gz + +Note: It is very unlikely that you want to install +the source tree of gcc/g++. Please try to upgrade your +compiler the usual way if needed. +If you are using rpm's then you will need to +install/upgrade the following: + gcc (2.95.1 or higher), + gcc-c++ (of same version), + libstdc++ (of same version) and + cpp (of same version). +Check your installation on RedHat with: + rpm -qa | egrep '(gcc|libstdc|cpp)' + +Note: If you don't use rpm's but are using tar balls, +then you do NOT need to download gnu/libstdc++/* because +gcc-2.95 and higher comes with libstdc++ included. +The gnu/libstdc++/ directory on GNU ftp sites are +for older compilers or to be used as source drop-in +when you compile g++ (replacing the normal stdc++ with +an alpha version). You also don't need libg++. +Don't delete those libraries if you have them though +since existing binaries might need to link with them. + +libcwd-0.99.16 was tested with gcc-2.95.x, gcc-2.96-97 (RedHat) +and gcc-3.0.x. + +Packages needed to run the testsuite +------------------------------------ + +ii) If you want to run the testsuite then you will have to install +dejagnu-1.4.1 which can be downloaded from ftp://ftp.gnu.org/gnu/dejagnu/, +or your local GNU mirror. However, this version still contains a bug +and you'll have to apply the following patch: edit /usr/share/dejagnu/target.exp +line 275 and remove the newline at the end (so that the word "text" on line +276 is added at the end of line 275: +regsub -all ".*: warning: -f(pic|PIC) ignored for target .*" $text "" text + +Alternatively, you can get dejagnu directly from the cvs repository +at http://www.gnu.org/software/dejagnu/ where this bug already has been +fixed (as it will be in any version *after* 1.4.1). + +You will also need expect-5.32.2 (and tcl/tk 8.3.3?). At least, expect 5.31.2 +is known to hang. + +Packages/versions needed as maintainer or when using CVS +-------------------------------------------------------- + +If you want to generate maintainer files (and you need that when you +get this package via CVS; in that case you also need to configure using +--enable-maintainer-mode) then you also need to have the following tools: + +iii) GNU make +iv) GNU m4 +v) GNU which version 2.x +vi) autoconf version 2.13 (2.52 seems to have problems) +vii) automake version 1.4pl1 or higher +viii) libtool version 1.4 or higher + +Each of those can be downloaded from your local GNU site. + +Moreover, in order to generate the documentation, you need to +have the following installed: + +ix) GNU grep version 2.4.2 is known to work. +x) doxygen version 1.2.12 or higher (http://www.doxygen.org/) +xi) graphviz http://www.research.att.com/sw/tools/graphviz/ - Each of those can be downloaded from your local GNU site. Hackers info ============ -=i=- -`configure' has a few interesting options. You can list them by issuing: +'configure' has a few interesting options. You can list them by issuing: ./configure --help There is no reason to use libcwd's feature options (--disable-libcwd-alloc, --disable-libcwd-magic, --disable-libcwd-marker and --disable-libcwd-location). -Actually, I forgot why they are there :). You can read more about what -they do in Chapter 4 "Debugging compile options" here: -http://libcw.sourceforge.net/templates/index.html?debugging -If you want to change Makefile.am files and the-like then you'll need to +Actually, I forgot why they are there :). You can read more about the +configuration options and what they do in include/libcw/debug_config.h. + +If you want to change Makefile.am files and the like then you'll need to use --enable-maintainer-mode. If you enable maintainer-mode then you -will need GNU make, other make won't work (you also need a lot of other -extra tools installed on your system). +will need GNU make, other make won't work (you also need a LOT of other +extra tools installed on your system, only for the brave thus). -=ii=- @@ -124,7 +133,7 @@ -=iii=- If you don't have an ELF32 system and therefore need to link with libbfd, then you -can configure using --enable-libcwd-bfd. If libiberty.a or libbfd.so are in an +can configure using --enable-libcwd-libbfd. If libiberty.a or libbfd.so are in an unusual directory, then you will have to set LDFLAGS prior to running ./configure: LDFLAGS="-L/usr/gnu/lib" CPPFLAGS="-I/usr/gnu/include" ./configure @@ -132,15 +141,15 @@ Please note that the libbfd that comes with binutils-2.11.x is not compatible with the libiberty that comes with with gcc-2.95.x. --=iii=- +-=iv=- -You can install libcwd in a `staging' directory by issuing +You can install libcwd in a 'staging' directory by issuing make DESTDIR=/tmp/staging install this can come in handy when you want to build an rpm for instance. --=iv=- +-=v=- The Makefile has the following targets: @@ -150,22 +159,29 @@ make clean make distclean -If you feel brave you might even want to try +If you configured with --enable-maintainer-mode then the following +targets exist as well: -make dist -make maintainer-clean +make dist // Create tar ball +make maintainer-clean // Erase everything that was generated somehow +make check // Run test suite +make tar // Create tar ball +make rpm // Create rpms +make ChangeLog // Generate ChangeLog from cvs database +make CC="gcc-3.0.2" CXX="g++-3.0.2" reconfig // Switch compilers keeping the same configuration +make full-check // Iterate over all configurations and all compiler versions -well, ... heh. Look in the Makefile for more targets ;) +It is not garanteed that these work on another machine than mine however. --=v=- +-=vi=- Finally, you can also build libcwd in a different directory than the source tree is in: -tar xzf libcwd-0.99.15.tar.gz +tar xzf libcwd-0.99.16.tar.gz mkdir libcwd-objdir cd libcwd-objdir -../libcwd-0.99.15/configure --prefix=/usr +../libcwd-0.99.16/configure --prefix=/usr make su make install Index: src/libcwd/Makefile.am diff -u src/libcwd/Makefile.am:1.34 src/libcwd/Makefile.am:1.35 --- src/libcwd/Makefile.am:1.34 Thu Dec 27 21:25:27 2001 +++ src/libcwd/Makefile.am Sat Dec 29 20:17:46 2001 @@ -4,8 +4,8 @@ SUBDIRS = include utils . tests testsuite -BUILT_SOURCES =@MAINTAINER_MODE_TRUE@ libcwd.lsm libcwd.spec nodebug.h -EXTRA_DIST = LICENSE.QPL README.FreeBSD README.openbsd README.nodebug.h debian $(BUILT_SOURCES) +BUILT_SOURCES =@MAINTAINER_MODE_TRUE@ libcwd.lsm libcwd.spec +EXTRA_DIST = LICENSE.QPL README.FreeBSD README.openbsd nodebug.h $(BUILT_SOURCES) DISTCLEANFILES = libcwd-@VERSION@.tar.gz VERSIONINFO=@VERSIONINFO@ @@ -18,17 +18,15 @@ lib_LTLIBRARIES = libcwd.la libcwd_la_SOURCES = \ + threading.cc \ elf32.cc \ bfd.cc \ debug.cc \ - debugdebugcheckpoint.cc \ debugmalloc.cc \ demangle.cc \ demangle3.cc \ - cwprint.cc \ strerrno.cc \ - type_info.cc \ - no_alloc_checking_stringstream.cc + type_info.cc libcwd_la_LDFLAGS = -version-info $(VERSIONINFO) @@ -36,12 +34,20 @@ # --------------- Maintainer's Section -dist-hook: +dist-hook: example-project/debug.h documentation + cp -pr $(srcdir)/documentation $(distdir)/documentation + find $(distdir)/documentation -name CVS -print | xargs rm -rf mkdir $(distdir)/example-project for i in `grep '^/' $(srcdir)/example-project/CVS/Entries | cut -d/ -f2`; do \ cp -p $(srcdir)/example-project/$$i $(distdir)/example-project; \ done + rm $(distdir)/example-project/debug.h.maintainer $(distdir)/example-project/macrotest.cc + cp -p $(srcdir)/example-project/debug.h $(distdir)/example-project chmod +x $(distdir)/install-sh + mkdir $(distdir)/debian + for i in `grep '^/' $(srcdir)/debian/CVS/Entries | cut -d/ -f2`; do \ + cp -p $(srcdir)/debian/$$i $(distdir)/debian; \ + done distclean-local: rm -rf rpm Index: src/libcwd/NEWS diff -u src/libcwd/NEWS:1.61 src/libcwd/NEWS:1.62 --- src/libcwd/NEWS:1.61 Thu Dec 27 21:25:27 2001 +++ src/libcwd/NEWS Sat Dec 29 20:17:46 2001 @@ -1,7 +1,13 @@ -libcwd-0.99.15 +libcwd-0.99.16 - libcwd now works with (single threaded) qt applications. A few major - bugs have been fixed. + libcwd is now thread-safe. + + The source file line number lookup was improved for optimized code with + inlined functions (-O). + + New configuration option --disable-libcwd-debug-output was added to + allow the use of the testsuite together with --enable-libcwd-debug. + (You shouldn't use either unless you are hacking libcwd itself). Miscellaneous: - The configuration option --disable-libcwd-location is fixed. @@ -9,6 +15,70 @@ API changes: + IMPORTANT: Debug channels have globally been renamed to Debug + selectors. The word 'channel' had too much association with output + destinations (streams). + + IMPORTANT: 'channel_ct const' -> 'selector_ct'. + Debug selectors (previously channels) should no longer be declared + constant. Declarations like + libcw::debug::channel_ct const my_channel("FOO"); + will have to be changed to + libcw::debug::selector_ct my_channel("FOO"); + + `long memblks()' has been renamed to `unsigned long mem_blocks()'. + + In debug_ct, set_margin, get_margin, set_marker and get_marker are + a bit slow for heavy swapping of the margin and marker (std::string + is 'slow'); therefore (using internal allocations, which is not + possible with std::string (see bug fixes below)) public access + to members debug_ct::margin and debug_ct::marker is now granted, + providing the following methods of the returned object: size(), + c_str() (the terminating zero is already there, this just returns + an internal pointer), reserve(), capacity(), append(), prepend() + and assign() - all with meanings borrowed from std::string. + For example, when capacity() returns a value larger or equal to + the length of a string that would result from a call to append(), + then calling append is garanteed not to invalidate the pointer + returned by c_str(). The default capacity can be set with `reserve'. + append/prepend/assign accept both a std::string reference or a + char*/size_t pair. + Finally, the following methods are added to debug_ct directly: + `push_margin', `pop_margin', `push_marker' and `pop_marker'. + These functions can be used to quickly store and restore the + respective formatting strings. + + A debug function for internal use (by the maintainers): + `debugdebugcheckpoint()' has been removed. If you need a user + function to be called every Dout() then can define your own Dout + macro's, that makes more sense then recompiling libcwd. + + CWASSERT was renamed to LIBCWD_ASSERT; Note that all macros that start + with LIBCWD_ should NOT be used by the user, they are for internal use + by libcwd. + + Bug fixes: + + When using .stabs, each first line of code after a source file scope change + as a result of an inlined function resulted in a location lookup failure + ("No line number"). + + The default std::allocator implementation uses static pointers to keep + a private free list, allocating memory with malloc() in large chunks. + The sharing of this memory pool with all STL containers, including + std::string and std::stringstreams - and even the buffers of std::cout + and std::cerr - caused `internal' allocations being mixed with `userspace' + allocations and thus an incorrect error detection. + Libcwd now uses its own allocators, with their own memory pool, for + variables that need internal allocations. + +libcwd-0.99.15 + + libcwd now works with (single threaded) qt applications. A few major + bugs have been fixed. + + API changes: + You now MUST use CWDEBUG, defining DEBUG will no longer work; it was incompatible with qt-2.2.4. @@ -39,18 +109,10 @@ On systems where a 'char' is unsigned, the line number lookup of DWARF failed. - - Some systems (I had this on a powerpc-unknown-linux-gnu) and/or with - old binutils produce incorrect .stabs N_FUN entries, causing the line - number lookup of stabs to fail. Libcwd now detects this and then uses - an alternative way to determining the start of a function (as a result - libcwd now succeeds where libbfd fails). - - Added a workaround for a bug in libtools so that executables in the - tests/ directory no longer can accidently link with an old installed - version of libcwd. - Several fixes in the build system (all related to the testsuite). + Systems with old binutils produce incorrect .stabs entries, causing + the line number lookup of stabs to fail. Libcwd now detects this and + then aborts. libcwd-0.99.13 Index: src/libcwd/README diff -u src/libcwd/README:1.8 src/libcwd/README:1.9 --- src/libcwd/README:1.8 Mon Jul 30 21:10:04 2001 +++ src/libcwd/README Sat Dec 29 20:17:46 2001 @@ -37,44 +37,6 @@ 2) Support for memory allocation debugging. -Documentation -------------- - -You can find extensive documentation online at -http://libcw.sourceforge.net/debugging/. There you will find -a reference manual, a tutorial and many examples. - -It is highly recommended that you download and install the html -files locally for greater speed. At the moment you can only -download the documentation by using `cvs': - -Install cvs (after all, you are a developer) and issue the -following command once: - -cvs -d:pserver:ano...@cv...:/cvsroot/libcw login - -When prompted for a password for anonymous, simply press the -Enter key. Next download the documentation with the following -commandline: - -cvs -z3 -d:pserver:ano...@cv...:/cvsroot/libcw co www - -At any later time you can update the documentation by changing -directory into the www directory and issuing: - -cvs update -d - -A European mirror has been setup in Amsterdam (the Netherlands) at -http://www.alinoe.com/. This is my home PC (cable, 128cps) and -therefore only contains the front page, using www.xs4all.nl -(my other provider) for all the rest of the pages and images. -Feel free to try this when sourceforge is too slow. - -Note that the documentation includes documentation of libcw -(without a `d' at the end), libcw is not released to the public -yet. You can ignore everything not in the debugging/ directory. - - Anonymous CVS Access -------------------- Index: src/libcwd/README.nodebug.h diff -u src/libcwd/README.nodebug.h:1.1 src/libcwd/README.nodebug.h:removed --- src/libcwd/README.nodebug.h:1.1 Wed Jul 25 19:10:39 2001 +++ src/libcwd/README.nodebug.h Sat Dec 29 20:18:01 2001 @@ -1,7 +0,0 @@ -In order to make it possible that others compile your application without -having libcwd installed, the file nodebug.h must be part of the distribution -of your application and should be included instead of <libcw/debug.h> -when CWDEBUG is not defined. - -For an example of how to do this, see the example-project directory. - Index: src/libcwd/acinclude.m4 diff -u src/libcwd/acinclude.m4:1.43 src/libcwd/acinclude.m4:1.44 --- src/libcwd/acinclude.m4:1.43 Thu Dec 27 21:25:27 2001 +++ src/libcwd/acinclude.m4 Sat Dec 29 20:17:46 2001 @@ -161,12 +161,11 @@ dnl CW_DEFINE_TYPE(NEWTYPE, OLDTYPE) dnl -dnl Add `typedef OLDTYPE NEWTYPE' to the output variable CW_TYPEDEFS +dnl Add `typedef OLDTYPE NEWTYPE;' to the output variable CW_TYPEDEFS dnl AC_DEFUN(CW_DEFINE_TYPE, [AC_REQUIRE([CW_DEFINE_TYPE_INITIALIZATION]) -CW_TYPEDEFS="$CW_TYPEDEFS\\ -typedef $2 $1;" +CW_TYPEDEFS="typedef $2 $1; $CW_TYPEDEFS" ]) dnl CW_TYPE_EXTRACT_FROM(FUNCTION, INIT, ARGUMENTS, ARGUMENT) @@ -334,6 +333,7 @@ AC_DEFUN(CW_MALLOC_OVERHEAD, [AC_CACHE_CHECK(malloc overhead in bytes, cw_cv_system_mallocoverhead, [CW_TRY_RUN([#include <cstddef> +#include <cstdlib> bool bulk_alloc(size_t malloc_overhead_attempt, size_t size) { @@ -377,12 +377,17 @@ AC_DEFUN(CW_NEED_WORD_ALIGNMENT, [AC_CACHE_CHECK(if machine needs word alignment, cw_cv_system_needwordalignment, [CW_TRY_RUN([#include <cstddef> +#include <cstdlib> int main(void) { size_t* p = reinterpret_cast<size_t*>((char*)malloc(5) + 1); *p = 0x12345678; +#ifdef __alpha__ // Works, but still should use alignment. + exit(-1); +#else exit ((((unsigned long)p & 1UL) && *p == 0x12345678) ? 0 : -1); +#endif }], cw_cv_system_needwordalignment=no, cw_cv_system_needwordalignment=yes, @@ -816,9 +821,7 @@ dnl CW_SETUP_RPM_DIRS dnl Set up rpm directory when on linux and in maintainer-mode AC_DEFUN(CW_SETUP_RPM_DIRS, -[SPECCHANGELOG=spec.changelog -if test "$USE_MAINTAINER_MODE" = yes; then - AC_SUBST_FILE(SPECCHANGELOG) +[if test "$USE_MAINTAINER_MODE" = yes; then LSMFILE="$PACKAGE.lsm" AC_SUBST(LSMFILE) SPECFILE="$PACKAGE.spec" @@ -886,7 +889,13 @@ AC_DEFUN(CW_DO_OPTIONS, [dnl dnl Choose warning options to use if test "$USE_MAINTAINER_MODE" = yes; then -WARNOPTS="-Wall -Woverloaded-virtual -Wundef -Wpointer-arith -Winline -Wwrite-strings -Werror" +AC_EGREP_CPP(Winline-broken, +[#if __GNUC__ < 3 +Winline-broken +#endif +], +WARNOPTS="-Wall -Woverloaded-virtual -Wundef -Wpointer-arith -Wwrite-strings -Werror", +WARNOPTS="-Wall -Woverloaded-virtual -Wundef -Wpointer-arith -Wwrite-strings -Werror -Winline") else WARNOPTS= fi @@ -904,7 +913,11 @@ AC_SUBST(DEBUGOPTS) dnl Other options -EXTRAOPTS="" +if test "$USE_MAINTAINER_MODE" = yes; then +EXTRAOPTS="-O" +else +EXTRAOPTS="-O" +fi AC_SUBST(EXTRAOPTS) dnl Test options @@ -929,6 +942,14 @@ unset ac_cv_prog_cxx_works unset ac_cv_prog_gxx unset ac_cv_prog_gxx_version +fi +if test x"$CC" != "x" -o x"$CPP" != "x"; then + unset ac_cv_prog_CC + unset ac_cv_prog_CPP + unset ac_cv_prog_cc_cross + unset ac_cv_prog_g + unset ac_cv_prog_cc_works + unset ac_cv_prog_gcc fi ]) Index: src/libcwd/bfd.cc diff -u src/libcwd/bfd.cc:1.87 src/libcwd/bfd.cc:1.88 --- src/libcwd/bfd.cc:1.87 Sat Sep 22 21:13:50 2001 +++ src/libcwd/bfd.cc Sat Dec 29 20:17:46 2001 @@ -1,6 +1,6 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.87 2001/09/23 04:13:50 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.88 2001/12/30 04:17:46 libcw Exp $ // -// Copyright (C) 2000, by +// Copyright (C) 2000 - 2001, by // // Carlo Wood, Run on IRC <ca...@al...> // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt @@ -45,15 +45,13 @@ #endif #include <cstdio> // Needed for vsnprintf. #include <algorithm> -#include <libcw/debug.h> -#include <libcw/bfd.h> +#include "cwd_debug.h" +#include "ios_base_Init.h" #ifdef CWDEBUG_DLOPEN_DEFINED #undef dlopen #undef dlclose #endif -#include <libcw/exec_prog.h> -#include <libcw/cwprint.h> -#include <libcw/demangle.h> +#include "exec_prog.h" #ifdef DEBUGUSEGNULIBBFD #if defined(BFD64) && !BFD_HOST_64BIT_LONG && defined(__GLIBCPP__) && !defined(_GLIBCPP_USE_LONG_LONG) // libbfd is compiled with 64bit support on a 32bit host, but libstdc++ is not compiled with support @@ -62,29 +60,60 @@ #error "Incompatible libbfd and libstdc++ (see comments in source code)." #endif #else // !DEBUGUSEGNULIBBFD -#include <libcw/elf32.h> +#include "elf32.h" #endif // !DEBUGUSEGNULIBBFD -#ifdef DEBUGDEBUGBFD -#include <iomanip> -#endif - -RCSTAG_CC("$Id: bfd.cc,v 1.87 2001/09/23 04:13:50 libcw Exp $") +#ifdef LIBCWD_THREAD_SAFE +using libcw::debug::_private_::rwlock_tct; +using libcw::debug::_private_::mutex_tct; +using libcw::debug::_private_::object_files_instance; +using libcw::debug::_private_::dlopen_map_instance; +#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(); +#define BFD_RELEASE_READ_LOCK rwlock_tct<object_files_instance>::rdunlock(); +#define BFD_ACQUIRE_READ2WRITE_LOCK rwlock_tct<object_files_instance>::rd2wrlock(); +#define BFD_ACQUIRE_WRITE2READ_LOCK rwlock_tct<object_files_instance>::wr2rdlock(); +#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_ACQUIRE_WRITE_LOCK +#define BFD_RELEASE_WRITE_LOCK +#define BFD_ACQUIRE_READ_LOCK +#define BFD_RELEASE_READ_LOCK +#define BFD_ACQUIRE_READ2WRITE_LOCK +#define BFD_ACQUIRE_WRITE2READ_LOCK +#define DLOPEN_MAP_ACQUIRE_LOCK +#define DLOPEN_MAP_RELEASE_LOCK +#endif // !LIBCWD_THREAD_SAFE -using namespace std; - extern char** environ; namespace libcw { namespace debug { + extern void demangle_symbol(char const* in, _private_::internal_string& out); + // New debug channel namespace channels { namespace dc { - channel_ct const bfd("BFD"); + /** \addtogroup group_default_dc */ + /* \{ */ + + /** The BFD channel. */ + channel_ct bfd +#ifndef HIDE_FROM_DOXYGEN + ("BFD") +#endif + ; + + /** \} */ } } + using _private_::set_alloc_checking_on; + using _private_::set_alloc_checking_off; + // Local stuff namespace cwbfd { @@ -111,7 +140,7 @@ inline uint32_t bfd_get_file_flags(bfd const* abfd) { return abfd->has_syms() ? HAS_SYMS : 0; } inline long bfd_get_symtab_upper_bound(bfd* abfd) { return abfd->get_symtab_upper_bound(); } inline long bfd_canonicalize_symtab(bfd* abfd, asymbol** symbol_table) { return abfd->canonicalize_symtab(symbol_table); } -inline bool bfd_is_abs_section(asection const* sect) { return (sect == elf32::absolute_section); } +inline bool bfd_is_abs_section(asection const* sect) { return (sect == elf32::absolute_section_c); } inline bool bfd_is_com_section(asection const* sect) { return false; } inline bool bfd_is_ind_section(asection const* sect) { return false; } inline bool bfd_is_und_section(asection const* sect) { return false; } @@ -131,14 +160,15 @@ va_end(vl); if (len >= buf_size) { - set_alloc_checking_off(); + LIBCWD_TSD_DECLARATION + set_alloc_checking_off(LIBCWD_TSD); char* bufp = new char[len + 1]; - set_alloc_checking_on(); + set_alloc_checking_on(LIBCWD_TSD); vsnprintf(bufp, sizeof(buf), format, vl); Dout(dc::bfd, buf); - set_alloc_checking_off(); + set_alloc_checking_off(LIBCWD_TSD); delete [] bufp; - set_alloc_checking_on(); + set_alloc_checking_on(LIBCWD_TSD); } else Dout(dc::bfd, buf); @@ -163,11 +193,17 @@ bool operator()(symbol_ct const& a, symbol_ct const& b) const; }; + // cwbfd:: + typedef std::set<symbol_ct, symbol_key_greater, _private_::object_files_allocator::rebind<symbol_ct>::other> function_symbols_ct; + + // cwbfd:: + class object_file_ct; + // cwbfd:: - typedef set<symbol_ct, symbol_key_greater> function_symbols_ct; + typedef std::list<object_file_ct*, _private_::object_files_allocator> object_files_ct; // cwbfd:: - class object_file_ct { + class object_file_ct { // All allocations related to object_file_ct must be `internal'. private: bfd* abfd; void* lbase; @@ -187,6 +223,10 @@ long get_number_of_symbols(void) const { return number_of_symbols; } function_symbols_ct& get_function_symbols(void) { return function_symbols; } function_symbols_ct const& get_function_symbols(void) const { return function_symbols; } + private: + friend object_files_ct const& NEEDS_READ_LOCK_object_files(void); // Need access to `ST_list_instance'. + friend object_files_ct& NEEDS_WRITE_LOCK_object_files(void); // Need access to `ST_list_instance'. + static char ST_list_instance[sizeof(object_files_ct)]; }; // cwbfd:: @@ -225,77 +265,86 @@ return symbol_start_addr(a.symbol) >= reinterpret_cast<char const*>(symbol_start_addr(b.symbol)) + symbol_size(b.symbol); } - // Global object (but libcwd must stay independent of stuff in libcw/kernel, so we don't use Global<>) // cwbfd:: - typedef list<object_file_ct*> object_files_ct; + char object_file_ct::ST_list_instance[sizeof(object_files_ct)] __attribute__((__aligned__)); + // cwbfd:: - static char object_files_instance_[sizeof(object_files_ct)] __attribute__((__aligned__)); + inline object_files_ct const& NEEDS_READ_LOCK_object_files(void) + { + return *reinterpret_cast<object_files_ct const*>(object_file_ct::ST_list_instance); + } + // cwbfd:: - object_files_ct& object_files(void) { return *reinterpret_cast<object_files_ct*>(object_files_instance_); } + inline object_files_ct& NEEDS_WRITE_LOCK_object_files(void) + { + return *reinterpret_cast<object_files_ct*>(object_file_ct::ST_list_instance); + } // cwbfd:: - object_file_ct* find_object_file(void const* addr) + object_file_ct* NEEDS_READ_LOCK_find_object_file(void const* addr) { - object_files_ct::iterator i(object_files().begin()); - for(; i != object_files().end(); ++i) + object_files_ct::const_iterator i(NEEDS_READ_LOCK_object_files().begin()); + for(; i != NEEDS_READ_LOCK_object_files().end(); ++i) if ((*i)->get_lbase() < addr && (char*)(*i)->get_lbase() + (*i)->size() > addr) break; - return (i != object_files().end()) ? (*i) : NULL; + return (i != NEEDS_READ_LOCK_object_files().end()) ? (*i) : NULL; } // cwbfd:: - object_file_ct* find_object_file(bfd const* abfd) + object_file_ct* NEEDS_READ_LOCK_find_object_file(bfd const* abfd) { - object_files_ct::iterator i(object_files().begin()); - for(; i != object_files().end(); ++i) + object_files_ct::const_iterator i(NEEDS_READ_LOCK_object_files().begin()); + for(; i != NEEDS_READ_LOCK_object_files().end(); ++i) if ((*i)->get_bfd() == abfd) break; - return (i != object_files().end()) ? (*i) : NULL; + return (i != NEEDS_READ_LOCK_object_files().end()) ? (*i) : NULL; } // cwbfd:: struct symbol_less { - bool operator()(asymbol const* a, asymbol const* b) const - { - if (a == b) - return false; - if (bfd_get_section(a)->vma + a->value < bfd_get_section(b)->vma + b->value) - return true; - else if (bfd_get_section(a)->vma + a->value > bfd_get_section(b)->vma + b->value) - return false; - else if (!(a->flags & BSF_FUNCTION) && (b->flags & BSF_FUNCTION)) - return true; - else if ((a->flags & BSF_FUNCTION) && !(b->flags & BSF_FUNCTION)) - return false; - else if (*a->name == '.') - return true; - else if (*b->name == '.') - return false; - else if (!strcmp(a->name, "gcc2_compiled.")) - return true; - else if (!strcmp(b->name, "gcc2_compiled.")) - return false; - else if (!strcmp(a->name, "force_to_data")) - return true; - else if (!strcmp(b->name, "force_to_data")) - return false; - else if (!(a->flags & BSF_GLOBAL) && (b->flags & BSF_GLOBAL)) - return true; - else if ((a->flags & BSF_GLOBAL) && !(b->flags & BSF_GLOBAL)) - return false; - else if (!(a->flags & BSF_LOCAL) && (b->flags & BSF_LOCAL)) - return true; - else if ((a->flags & BSF_LOCAL) && !(b->flags & BSF_LOCAL)) - return false; - else if (!(a->flags & BSF_OBJECT) && (b->flags & BSF_OBJECT)) - return true; - else if ((a->flags & BSF_OBJECT) && !(b->flags & BSF_OBJECT)) - return false; - // Lets hope that IF it matters, that a long name is more important ;) - return (strlen(a->name) < strlen(b->name)); - } + bool operator()(asymbol const* a, asymbol const* b) const; }; + bool symbol_less::operator()(asymbol const* a, asymbol const* b) const + { + if (a == b) + return false; + if (bfd_get_section(a)->vma + a->value < bfd_get_section(b)->vma + b->value) + return true; + else if (bfd_get_section(a)->vma + a->value > bfd_get_section(b)->vma + b->value) + return false; + else if (!(a->flags & BSF_FUNCTION) && (b->flags & BSF_FUNCTION)) + return true; + else if ((a->flags & BSF_FUNCTION) && !(b->flags & BSF_FUNCTION)) + return false; + else if (*a->name == '.') + return true; + else if (*b->name == '.') + return false; + else if (!strcmp(a->name, "gcc2_compiled.")) + return true; + else if (!strcmp(b->name, "gcc2_compiled.")) + return false; + else if (!strcmp(a->name, "force_to_data")) + return true; + else if (!strcmp(b->name, "force_to_data")) + return false; + else if (!(a->flags & BSF_GLOBAL) && (b->flags & BSF_GLOBAL)) + return true; + else if ((a->flags & BSF_GLOBAL) && !(b->flags & BSF_GLOBAL)) + return false; + else if (!(a->flags & BSF_LOCAL) && (b->flags & BSF_LOCAL)) + return true; + else if ((a->flags & BSF_LOCAL) && !(b->flags & BSF_LOCAL)) + return false; + else if (!(a->flags & BSF_OBJECT) && (b->flags & BSF_OBJECT)) + return true; + else if ((a->flags & BSF_OBJECT) && !(b->flags & BSF_OBJECT)) + return false; + // Lets hope that IF it matters, that a long name is more important ;) + return (strlen(a->name) < strlen(b->name)); + } + // cwbfd:: void* const unknown_l_addr = (void*)-1; @@ -303,7 +352,10 @@ object_file_ct::object_file_ct(char const* filename, void* base) : lbase(base) { #ifdef DEBUGDEBUGMALLOC - CWASSERT( libcw::debug::_internal_::internal ); + { + LIBCWD_TSD_DECLARATION + LIBCWD_ASSERT( __libcwd_tsd.internal ); + } #endif abfd = bfd_openr(filename, NULL); @@ -362,7 +414,6 @@ #endif symbol_table = (asymbol**) malloc(storage_needed); - AllocTag_dynamic_description(symbol_table, "symbols of " << filename); number_of_symbols = bfd_canonicalize_symtab(abfd, symbol_table); #ifdef DEBUGUSEGNULIBBFD @@ -412,7 +463,9 @@ if (lbase == unknown_l_addr) { #ifdef HAVE_DLOPEN - libcw::debug::_internal_::internal = false; + LIBCWD_TSD_DECLARATION + int saved_internal = __libcwd_tsd.internal; + __libcwd_tsd.internal = 0; void* handle = ::dlopen(filename, RTLD_LAZY); if (!handle) { @@ -422,13 +475,13 @@ char* val; if (s_end_vma && (val = (char*)dlsym(handle, "_end"))) // dlsym will fail when _end is a local symbol. { - libcw::debug::_internal_::internal = true; + __libcwd_tsd.internal = saved_internal; lbase = val - s_end_vma; } else #ifdef HAVE_LINK_H { - libcw::debug::_internal_::internal = true; + __libcwd_tsd.internal = saved_internal; for(link_map* p = _dl_loaded; p; p = p->l_next) if (!strcmp(p->l_name, filename)) { @@ -438,9 +491,10 @@ } #else // !HAVE_LINK_H { - libcw::debug::_internal_::internal = true; + __libcwd_tsd.internal = saved_internal; // The following code uses a heuristic approach to guess the start of an object file. - map<void*, unsigned int> start_values; + typedef std::map<void*, unsigned int, std::less<void*>, _private_::internal_allocator::rebind<void*>::other> start_values_map_ct; + start_values_map_ct start_values; unsigned int best_count = 0; void* best_start = 0; for (asymbol** s = symbol_table; s <= &symbol_table[number_of_symbols - 1]; ++s) @@ -450,13 +504,13 @@ asection const* sect = bfd_get_section(*s); if (sect->name[1] == 't' && !strcmp(sect->name, ".text")) { - libcw::debug::_internal_::internal = false; + __libcwd_tsd.internal = 0; void* val = dlsym(handle, (*s)->name); if (dlerror() == NULL) { - libcw::debug::_internal_::internal = true; + __libcwd_tsd.internal = saved_internal; void* start = reinterpret_cast<char*>(val) - (*s)->value - sect->vma; - pair<map<void*, unsigned int>::iterator, bool> p = start_values.insert(pair<void* const, unsigned int>(start, 0)); + std::pair<start_values_map_ct::iterator, bool> p = start_values.insert(std::pair<void* const, unsigned int>(start, 0)); if (++(*(p.first)).second > best_count) { best_start = start; @@ -465,7 +519,7 @@ } } else - libcw::debug::_internal_::internal = true; + __libcwd_tsd.internal = saved_internal; } } if (best_count < 3) @@ -475,17 +529,17 @@ symbol_table = NULL; bfd_close(abfd); number_of_symbols = 0; - libcw::debug::_internal_::internal = false; + __libcwd_tsd.internal = 0; ::dlclose(handle); - libcw::debug::_internal_::internal = true; + __libcwd_tsd.internal = saved_internal; return; } lbase = best_start; } #endif // !HAVE_LINK_H - libcw::debug::_internal_::internal = false; + __libcwd_tsd.internal = 0; ::dlclose(handle); - libcw::debug::_internal_::internal = true; + __libcwd_tsd.internal = saved_internal; Dout(dc::continued, '(' << lbase << ") ... "); #else // !HAVE_DLOPEN DoutFatal(dc::fatal, "Can't determine start of shared library: you will need libdl to be detected by configure."); @@ -506,7 +560,7 @@ } // Sort the symbol table in order of start address. - sort(symbol_table, &symbol_table[number_of_symbols], symbol_less()); + std::sort(symbol_table, &symbol_table[number_of_symbols], symbol_less()); // Calculate sizes for every symbol for (int i = 0; i < number_of_symbols - 1; ++i) @@ -545,15 +599,18 @@ } if (number_of_symbols > 0) - object_files().push_back(this); + NEEDS_WRITE_LOCK_object_files().push_back(this); } // cwbfd:: object_file_ct::~object_file_ct() { - list<object_file_ct*>::iterator iter(find(object_files().begin(), object_files().end(), this)); - if (iter != object_files().end()) - object_files().erase(iter); +#if defined(LIBCWD_THREAD_SAFE) && defined(DEBUGDEBUG) + LIBCWD_ASSERT( _private_::is_locked(object_files_instance) ); +#endif + object_files_ct::iterator iter(find(NEEDS_WRITE_LOCK_object_files().begin(), NEEDS_WRITE_LOCK_object_files().end(), this)); + if (iter != NEEDS_WRITE_LOCK_object_files().end()) + NEEDS_WRITE_LOCK_object_files().erase(iter); } // cwbfd:: @@ -596,12 +653,12 @@ } // cwbfd:: - string* argv0_ptr; + _private_::ST_internal_string* ST_argv0_ptr; // MT: Set in `ST_get_full_path_to_executable', used in `ST_decode_ps'. // cwbfd:: - string const* pidstr_ptr; + _private_::ST_internal_string const* ST_pidstr_ptr; // MT: Set in `ST_get_full_path_to_executable', used in `ST_decode_ps'. // cwbfd:: - int decode_ps(char const* buf, size_t len) + int ST_decode_ps(char const* buf, size_t len) // MT: Single Threaded function. { static int pid_token = 0; static int command_token = 0; @@ -610,7 +667,7 @@ bool found_PID = false; bool eating_token = false; size_t current_column = 1; - string token; + _private_::ST_internal_string token; for (char const* p = buf; p < &buf[len]; ++p, ++current_column) { @@ -632,11 +689,11 @@ { if (*p == ' ' || *p == '\t' || *p == '\n') { - if (pid_token == current_token && token == *pidstr_ptr) + if (pid_token == current_token && token == *ST_pidstr_ptr) found_PID = true; else if (found_PID && (command_token == current_token || current_column >= command_column)) { - *argv0_ptr = token + '\0'; + *ST_argv0_ptr = token + '\0'; return 0; } else if (pid_token == 0 && token == "PID") @@ -673,9 +730,9 @@ // program. // // cwbfd:: - void get_full_path_to_executable(string& result) + void ST_get_full_path_to_executable(_private_::ST_internal_string& result) { - string argv0; // Like main()s argv[0], thus must be zero terminated. + _private_::ST_internal_string argv0; // Like main()s argv[0], thus must be zero terminated. char buf[6]; char* p = &buf[5]; *p = 0; @@ -686,7 +743,7 @@ strcpy(proc_path, "/proc/"); strcpy(proc_path + 6, p); strcat(proc_path, "/cmdline"); - ifstream proc_file(proc_path); + std::ifstream proc_file(proc_path); if (proc_file) { @@ -695,7 +752,7 @@ } else { - string pidstr; + _private_::ST_internal_string pidstr; size_t const max_pidstr = sizeof("65535\0"); char pidstr_buf[max_pidstr]; @@ -714,19 +771,19 @@ argv[2] = p; argv[3] = NULL; - argv0_ptr = &argv0; // Ugly way to pass these strings to decode_ps: - pidstr_ptr = &pidstr; // pidstr is input, argv0 is output. + ST_argv0_ptr = &argv0; // Ugly way to pass these ST_internal_strings to ST_decode_ps: + ST_pidstr_ptr = &pidstr; // pidstr is input, argv0 is output. - if (exec_prog(ps_prog, argv, environ, decode_ps) == -1 || argv0.empty()) + if (ST_exec_prog(ps_prog, argv, environ, ST_decode_ps) == -1 || argv0.empty()) DoutFatal(dc::fatal|error_cf, "Failed to execute \"" << ps_prog << "\""); } - if (argv0.find('/') == string::npos) + if (argv0.find('/') == _private_::ST_internal_string::npos) { - string prog_name(argv0); - string path_list(getenv("PATH")); - string::size_type start_pos = 0, end_pos; - string path; + _private_::ST_internal_string prog_name(argv0); + _private_::ST_internal_string path_list(getenv("PATH")); + _private_::ST_internal_string::size_type start_pos = 0, end_pos; + _private_::ST_internal_string path; struct stat finfo; prog_name += '\0'; for (;;) @@ -745,7 +802,7 @@ break; } } - if (end_pos == string::npos) + if (end_pos == _private_::ST_internal_string::npos) break; start_pos = end_pos + 1; } @@ -758,11 +815,11 @@ DoutFatal(dc::fatal|error_cf, "realpath(\"" << argv0.data() << "\", full_path_buf)"); Dout(dc::debug, "Full path to executable is \"" << full_path << "\"."); - result = full_path; + result.assign(full_path); } // cwbfd:: - static bool initialized = false; + static bool WST_initialized = false; // MT: Set here to false, set to `true' once in `cwbfd::ST_init'. // cwbfd:: struct my_link_map { @@ -778,10 +835,12 @@ }; // cwbfd:: - vector<my_link_map> shared_libs; + typedef _private_::internal_vector<my_link_map> 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'. // cwbfd:: - int decode(char const* buf, size_t len) + int ST_decode_ldd(char const* buf, size_t len) { for (char const* p = buf; p < &buf[len]; ++p) if (p[0] == '=' && p[1] == '>' && p[2] == ' ' || p[2] == '\t') @@ -795,7 +854,7 @@ for (q = p; q < &buf[len] && *q > ' '; ++q); if (*q == '\n') // This ldd doesn't return an offset (ie, on solaris). { - shared_libs.push_back(my_link_map(p, q - p, unknown_l_addr)); + ST_shared_libs.push_back(my_link_map(p, q - p, unknown_l_addr)); break; } for (char const* r = q; r < &buf[len]; ++r) @@ -803,7 +862,7 @@ { char* s; void* addr = reinterpret_cast<void*>(strtol(++r, &s, 0)); - shared_libs.push_back(my_link_map(p, q - p, addr)); + ST_shared_libs.push_back(my_link_map(p, q - p, addr)); break; } break; @@ -837,7 +896,10 @@ // cwbfd:: object_file_ct* load_object_file(char const* name, void* l_addr) { - CWASSERT( libcw::debug::_internal_::internal ); + { + LIBCWD_TSD_DECLARATION + LIBCWD_ASSERT( __libcwd_tsd.internal ); + } if (l_addr == unknown_l_addr) Dout(dc::bfd|continued_cf|flush_cf, "Loading debug info from " << name << ' '); else if (l_addr == 0) @@ -847,7 +909,7 @@ object_file_ct* object_file = new object_file_ct(name, l_addr); if (object_file->get_number_of_symbols() > 0) { - Dout(dc::finish, "done (" << dec << object_file->get_number_of_symbols() << " symbols)"); + Dout(dc::finish, "done (" << std::dec << object_file->get_number_of_symbols() << " symbols)"); #ifdef DEBUGDEBUGBFD dump_object_file_symbols(object_file); #endif @@ -862,18 +924,22 @@ } // cwbfd:: - int init(void) + bool ST_init(void) { - static bool being_initialized = false; + static bool WST_being_initialized = false; // This should catch it when we call new or malloc while 'internal'. - if (being_initialized) - { -#ifdef DEBUGMALLOC - libcw::debug::_internal_::internal = false; + if (WST_being_initialized) + return false; + WST_being_initialized = true; + + // MT: We assume this is called before reaching main(). + // Therefore, no synchronisation is required. +#if defined(DEBUGDEBUG) && defined(LIBCWD_THREAD_SAFE) + if (_private_::WST_multi_threaded) + core_dump(); #endif - DoutFatal(dc::core, "Bug in libcwd: libcw_bfd_init() called twice or recursively entering itself! Please submit a full bug report to li...@al...."); - } - being_initialized = true; + + LIBCWD_TSD_DECLARATION #if defined(DEBUGDEBUG) && defined(DEBUGMALLOC) // First time we get here, this string is intialized - this must be with `internal' off! @@ -881,13 +947,13 @@ if (!second_time) { second_time = true; - CWASSERT( !libcw::debug::_internal_::internal ); + LIBCWD_ASSERT( !__libcwd_tsd.internal ); } #endif // **************************************************************************** // Start INTERNAL! - set_alloc_checking_off(); + set_alloc_checking_off(LIBCWD_TSD); #ifdef DEBUGMALLOC // Initialize the malloc library if not done yet. @@ -910,22 +976,38 @@ Debug( dc::bfd.on() ); #endif - // Initialize object files list - new (object_files_instance_) object_files_ct; + // Initialize object files list, we don't really need the + // write lock because this function is Single Threaded. + new (&NEEDS_WRITE_LOCK_object_files()) object_files_ct; #ifdef DEBUGUSEGNULIBBFD bfd_init(); #endif // Get the full path and name of executable - struct non_alloc_checking_string_st { - string* value; - non_alloc_checking_string_st(void) { value = new string; } // alloc checking already off. - ~non_alloc_checking_string_st() { set_alloc_checking_off(); delete value; set_alloc_checking_on(); } + struct static_internal_string { + _private_::ST_internal_string* value; + static_internal_string(void) + { + value = new _private_::ST_internal_string; // alloc checking already off. + } + ~static_internal_string() + { + LIBCWD_TSD_DECLARATION + set_alloc_checking_off(LIBCWD_TSD); +#if defined(DEBUGDEBUG) && defined(LIBCWD_THREAD_SAFE) + _private_::WST_multi_threaded = false; // `fullpath' is static and will only be destroyed from exit(). +#endif + delete value; +#if defined(DEBUGDEBUG) && defined(LIBCWD_THREAD_SAFE) + _private_::WST_multi_threaded = true; // Make sure we catch other global strings (in order to avoid a static destructor ordering fiasco). +#endif + set_alloc_checking_on(LIBCWD_TSD); + } }; - static non_alloc_checking_string_st fullpath; // Must be static because bfd keeps a pointer to its data() - get_full_path_to_executable(*fullpath.value); - *fullpath.value += '\0'; // Make string null terminated so we can use data(). + static static_internal_string fullpath; // Must be static because bfd keeps a pointer to its data() + ST_get_full_path_to_executable(*fullpath.value); + *fullpath.value += '\0'; // Make string null terminated so we can use data(). #ifdef DEBUGUSEGNULIBBFD bfd_set_error_program_name(fullpath.value->data() + fullpath.value->find_last_of('/') + 1); @@ -933,6 +1015,11 @@ #endif // Load executable + // No write lock is really needed because this is a Single Threaded function, + // 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_ACQUIRE_WRITE_LOCK load_object_file(fullpath.value->data(), 0); // Load all shared objects @@ -944,9 +1031,9 @@ argv[0] = "ldd"; argv[1] = fullpath.value->data(); argv[2] = NULL; - exec_prog(ldd_prog, argv, environ, decode); + ST_exec_prog(ldd_prog, argv, environ, ST_decode_ldd); - for(vector<my_link_map>::iterator iter = shared_libs.begin(); iter != shared_libs.end(); ++iter) + for(ST_shared_libs_vector_ct::iterator iter = ST_shared_libs.begin(); iter != ST_shared_libs.end(); ++iter) { my_link_map* l = &(*iter); #else @@ -956,7 +1043,8 @@ if (l->l_addr) load_object_file(l->l_name, reinterpret_cast<void*>(l->l_addr)); } - object_files().sort(object_file_greater()); + NEEDS_WRITE_LOCK_object_files().sort(object_file_greater()); + BFD_RELEASE_WRITE_LOCK #ifdef ALWAYS_PRINT_LOADING if (libcwd_was_off) @@ -965,9 +1053,9 @@ Debug( dc::bfd.off() ); #endif - initialized = true; + WST_initialized = true; // MT: Safe, this function is Single Threaded. - set_alloc_checking_on(); + set_alloc_checking_on(LIBCWD_TSD); // End INTERNAL! // **************************************************************************** @@ -977,19 +1065,21 @@ dump_object_file_symbols(*i); #endif - return 0; + return true; } // cwbfd:: symbol_ct const* pc_symbol(bfd_vma addr, object_file_ct* object_file) { - static asymbol dummy_symbol; - static asection dummy_section; if (object_file) { - // Make symbol_start_addr(&dummy_symbol) and symbol_size(&dummy_symbol) return the correct value + asymbol dummy_symbol; // A dummy symbol with size 1 and start `addr', + asection dummy_section; + + // Make symbol_start_addr(&dummy_symbol) and symbol_size(&dummy_symbol) return the correct value: bfd_asymbol_bfd(&dummy_symbol) = object_file->get_bfd(); - dummy_symbol.section = &dummy_section; // Has dummy_section.vma == 0. Use dummy_symbol.value to store (value + vma): + dummy_section.vma = 0; // Use a vma of 0 and + dummy_symbol.section = &dummy_section; // use dummy_symbol.value to store (value + vma): dummy_symbol.value = reinterpret_cast<char const*>(addr) - reinterpret_cast<char const*>(object_file->get_lbase()); symbol_size(&dummy_symbol) = 1; function_symbols_ct::iterator i(object_file->get_function_symbols().find(symbol_ct(&dummy_symbol, true))); @@ -1008,19 +1098,28 @@ } // namespace cwbfd + /** \addtogroup group_locations */ + /** \{ */ + char const* const unknown_function_c = "<unknown function>"; - // - // Find the mangled function name of the address `addr'. - // + /** + * \brief Find the mangled function name of the address \a addr. + * + * \returns the same pointer that is returned by location_ct::mangled_function_name() on success, + * otherwise \ref unknown_function_c is returned. + */ char const* pc_mangled_function_name(void const* addr) { using namespace cwbfd; - if (!initialized) - init(); + if (!WST_initialized // `WST_initialized' is only false when we are still Single Threaded. + && !ST_init()) + return unknown_function_c; - symbol_ct const* symbol = pc_symbol((bfd_vma)(size_t)addr, find_object_file(addr)); + BFD_ACQUIRE_READ_LOCK; + symbol_ct const* symbol = pc_symbol((bfd_vma)(size_t)addr, NEEDS_READ_LOCK_find_object_file(addr)); + BFD_RELEASE_READ_LOCK; if (!symbol) return unknown_function_c; @@ -1028,6 +1127,21 @@ return symbol->get_symbol()->name; } + /** \} */ // End of group 'group_locations'. + + struct bfd_location_ct : public location_ct { + friend _private_::no_alloc_ostream_ct& operator<<(_private_::no_alloc_ostream_ct& os, bfd_location_ct const& data); + }; + + _private_::no_alloc_ostream_ct& operator<<(_private_::no_alloc_ostream_ct& os, bfd_location_ct const& location) + { + if (location.M_filepath) + os << location.M_filename << ':' << location.M_line; + else + os << "<unknown ... [truncated message content] |
From: Carlo W. <li...@us...> - 2001-12-30 20:00:14
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-30 20:00:12 UTC Modified files: libcwd/Makefile.am libcwd/maintMakefile.in Log message: Make example-project/debug.h dependant of documentation directly. ---------------------- diff included ---------------------- Index: src/libcwd/Makefile.am diff -u src/libcwd/Makefile.am:1.35 src/libcwd/Makefile.am:1.36 --- src/libcwd/Makefile.am:1.35 Sat Dec 29 20:17:46 2001 +++ src/libcwd/Makefile.am Sun Dec 30 12:00:01 2001 @@ -34,7 +34,7 @@ # --------------- Maintainer's Section -dist-hook: example-project/debug.h documentation +dist-hook: documentation cp -pr $(srcdir)/documentation $(distdir)/documentation find $(distdir)/documentation -name CVS -print | xargs rm -rf mkdir $(distdir)/example-project Index: src/libcwd/maintMakefile.in diff -u src/libcwd/maintMakefile.in:1.14 src/libcwd/maintMakefile.in:1.15 --- src/libcwd/maintMakefile.in:1.14 Sat Dec 29 20:17:47 2001 +++ src/libcwd/maintMakefile.in Sun Dec 30 12:00:01 2001 @@ -148,5 +148,5 @@ done; \ ) -documentation: +documentation: example-project/debug.h $(MAKE) -C documentation ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 20:00:54
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-30 20:00:54 UTC Modified files: libcwd/example-project/.cvsignore Log message: Needed ignore for automake 1.5. ---------------------- diff included ---------------------- Index: src/libcwd/example-project/.cvsignore diff -u src/libcwd/example-project/.cvsignore:1.3 src/libcwd/example-project/.cvsignore:1.4 --- src/libcwd/example-project/.cvsignore:1.3 Sat Dec 29 20:17:49 2001 +++ src/libcwd/example-project/.cvsignore Sun Dec 30 12:00:43 2001 @@ -14,3 +14,4 @@ debug.h program confdefs.h +stamp-h1 ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 20:05:53
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-30 20:05:51 UTC Modified files: libcwd/README.FreeBSD libcwd/include/sys.ho.in Log message: Work in progress on port to FreeBSD. ---------------------- diff included ---------------------- Index: src/libcwd/README.FreeBSD diff -u src/libcwd/README.FreeBSD:1.7 src/libcwd/README.FreeBSD:1.8 --- src/libcwd/README.FreeBSD:1.7 Mon Jul 30 21:10:04 2001 +++ src/libcwd/README.FreeBSD Sun Dec 30 12:05:41 2001 @@ -1,3 +1,12 @@ +30 December 2001 + + FreeBSD now compiles with g++-2.95.3. + It doesn't work however because _dl_loaded doesn't exist, which I need + to get a list of currently loaded dynamic libraries. All in all, + you should use linux as developers platform: _dl_loaded doesn't exist, + __libc_malloc et al don't exist... Of course you need to use gmake. + No idea why GNU make isn't the default :/ + 31 Juli 2001 FreeBSD fails to compile libcwd when using g++-2.95.3 (internal compiler error). Index: src/libcwd/include/sys.ho.in diff -u src/libcwd/include/sys.ho.in:1.3 src/libcwd/include/sys.ho.in:1.4 --- src/libcwd/include/sys.ho.in:1.3 Sat Dec 29 20:17:49 2001 +++ src/libcwd/include/sys.ho.in Sun Dec 30 12:05:41 2001 @@ -1,5 +1,5 @@ // @configure_input@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/sys.ho.in,v 1.3 2001/12/30 04:17:49 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/sys.ho.in,v 1.4 2001/12/30 20:05:41 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -45,6 +45,7 @@ // Word around (if any): @CW_REDEFINES_FIX@ +#ifdef HAVE__G_CONFIG_H // This is to avoid warnings like: // /usr/include/g++-3/iostream.h:253:5: "_G_CLOG_CONFLICT" is not defined #@CW_CONFIG_G_CONFIG_H_MACROS@ NEED_G_CONFIG_H_MACROS @@ -56,7 +57,8 @@ #ifndef _G_HAS_LABS #define _G_HAS_LABS @CW_HAVE_LABS@ #endif -#endif +#endif // NEED_G_CONFIG_H_MACROS +#endif // HAVE__G_CONFIG_H // Fixes for gcc-2.96 and earlier. ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 20:55:53
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-30 20:55:52 UTC Modified files: libcwd/debug.cc Log message: FreeBSD bug fix. ---------------------- diff included ---------------------- Index: src/libcwd/debug.cc diff -u src/libcwd/debug.cc:1.49 src/libcwd/debug.cc:1.50 --- src/libcwd/debug.cc:1.49 Sat Dec 29 20:17:46 2001 +++ src/libcwd/debug.cc Sun Dec 30 12:55:42 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.49 2001/12/30 04:17:46 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debug.cc,v 1.50 2001/12/30 20:55:42 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -951,7 +951,9 @@ if (corelim.rlim_max != RLIM_INFINITY) { _off = -1; - Dout(dc::warning, "core size is limited (hard limit: " << (corelim.rlim_max / 1024) << " kb). Core dumps might be truncated!"); + // 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 _off = 0; #endif ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 21:18:28
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-30 21:18:26 UTC Modified files: libcwd/bfd.cc libcwd/configure.in Log message: FreeBSD port: check for _dl_loaded directly instead of just link.h ---------------------- diff included ---------------------- Index: src/libcwd/bfd.cc diff -u src/libcwd/bfd.cc:1.88 src/libcwd/bfd.cc:1.89 --- src/libcwd/bfd.cc:1.88 Sat Dec 29 20:17:46 2001 +++ src/libcwd/bfd.cc Sun Dec 30 13:18:16 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.88 2001/12/30 04:17:46 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.89 2001/12/30 21:18:16 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -39,7 +39,7 @@ #include <cstring> #include <cstdlib> #endif -#ifdef HAVE_LINK_H +#ifdef HAVE__DL_LOADED #include <link.h> extern link_map* _dl_loaded; #endif @@ -479,7 +479,7 @@ lbase = val - s_end_vma; } else -#ifdef HAVE_LINK_H +#ifdef HAVE__DL_LOADED { __libcwd_tsd.internal = saved_internal; for(link_map* p = _dl_loaded; p; p = p->l_next) @@ -1023,7 +1023,7 @@ load_object_file(fullpath.value->data(), 0); // Load all shared objects -#ifndef HAVE_LINK_H +#ifndef HAVE__DL_LOADED // Path to `ldd' char const ldd_prog[] = "/usr/bin/ldd"; @@ -1184,7 +1184,7 @@ BFD_ACQUIRE_READ_LOCK; object_file_ct* object_file = NEEDS_READ_LOCK_find_object_file(addr); -#ifdef HAVE_LINK_H +#ifdef HAVE__DL_LOADED if (!object_file) { set_alloc_checking_off(LIBCWD_TSD); Index: src/libcwd/configure.in diff -u src/libcwd/configure.in:1.86 src/libcwd/configure.in:1.87 --- src/libcwd/configure.in:1.86 Sat Dec 29 20:17:46 2001 +++ src/libcwd/configure.in Sun Dec 30 13:18:16 2001 @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_REVISION($Revision: 1.86 $)dnl +AC_REVISION($Revision: 1.87 $)dnl dnl General intialization of `autoconf' varaibles. dnl Ensure that the directory specified with --srcdir was correct @@ -384,6 +384,11 @@ dnl Checks for header files. AC_HEADER_STAT AC_CHECK_HEADERS(_G_config.h link.h) + +dnl Check for global variable. +if test "$ac_cv_header_link_h" = yes; then + AC_CHECK_FUNCS(_dl_loaded) +fi dnl Check for typedefs. AC_TYPE_UID_T ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 21:26:42
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-30 21:26:41 UTC Modified files: libcwd/testsuite/libcwd.tst/sys.h Log message: Also use HAVE__G_CONFIG_H in testsuite ---------------------- diff included ---------------------- Index: src/libcwd/testsuite/libcwd.tst/sys.h diff -u src/libcwd/testsuite/libcwd.tst/sys.h:1.2 src/libcwd/testsuite/libcwd.tst/sys.h:1.3 --- src/libcwd/testsuite/libcwd.tst/sys.h:1.2 Sat Dec 29 20:17:51 2001 +++ src/libcwd/testsuite/libcwd.tst/sys.h Sun Dec 30 13:26:31 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/testsuite/libcwd.tst/sys.h,v 1.2 2001/12/30 04:17:51 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/testsuite/libcwd.tst/sys.h,v 1.3 2001/12/30 21:26:31 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -14,8 +14,8 @@ #ifndef TESTSUITE_SYS_H #define TESTSUITE_SYS_H -#define NEED_G_CONFIG_H_MACROS -#ifdef NEED_G_CONFIG_H_MACROS +#include "../../config.h" +#ifdef HAVE__G_CONFIG_H #include <_G_config.h> #ifndef _G_CLOG_CONFLICT #define _G_CLOG_CONFLICT 0 @@ -23,7 +23,7 @@ #ifndef _G_HAS_LABS #define _G_HAS_LABS 1 #endif -#endif +#endif // HAVE__G_CONFIG_H #include <libcw/sysd.h> ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-30 21:33:11
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-30 21:33:11 UTC Modified files: libcwd/testsuite/libcwd.tst/dlopen.cc Log message: Bug fix ---------------------- diff included ---------------------- Index: src/libcwd/testsuite/libcwd.tst/dlopen.cc diff -u src/libcwd/testsuite/libcwd.tst/dlopen.cc:1.6 src/libcwd/testsuite/libcwd.tst/dlopen.cc:1.7 --- src/libcwd/testsuite/libcwd.tst/dlopen.cc:1.6 Sat Dec 29 20:17:51 2001 +++ src/libcwd/testsuite/libcwd.tst/dlopen.cc Sun Dec 30 13:33:00 2001 @@ -23,7 +23,7 @@ if (!handle) { - char* error_str = dlerror(); + char const* error_str = dlerror(); DoutFatal(dc::fatal, "Failed to load \"./module.so\": " << error_str); } @@ -36,7 +36,7 @@ if (!f) { - char* error_str = dlerror(); + char const* error_str = dlerror(); DoutFatal(dc::fatal, "Failed find function \"" << sym << "\": " << error_str); } ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-31 01:04:06
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-31 01:04:04 UTC Modified files: libcwd/debugmalloc.cc libcwd/include/libcw/macro_Libcwd_macros.h Log message: Bug fixes. ---------------------- diff included ---------------------- Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.64 src/libcwd/debugmalloc.cc:1.65 --- src/libcwd/debugmalloc.cc:1.64 Sat Dec 29 20:17:46 2001 +++ src/libcwd/debugmalloc.cc Sun Dec 30 17:03:54 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.64 2001/12/30 04:17:46 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.65 2001/12/31 01:03:54 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -1196,41 +1196,18 @@ { if (WST_initialization_state <= 0) // Only true prior to initialization of std::ios_base::Init. { - // This block is Single Threaded. - if (WST_initialization_state == 0) // Only true once. - { - __libcwd_tsd.internal = 1; - memblk_map.MT_unsafe = new memblk_map_ct; // MT-safe: There are no threads created yet when we get here. - WST_initialization_state = -1; - __libcwd_tsd.internal = 0; - } -#ifdef __GLIBCPP__ - // "ios_base" is always initialized for libstdc++ version 2. - if (!_private_::WST_ios_base_initialized && !_private_::inside_ios_base_Init_Init()) -#endif // __GLIBCPP__ - { - WST_initialization_state = 1; // ST_initialize_globals() calls malloc again of course. -#ifdef DEBUGDEBUGMALLOC - --__libcwd_tsd.recursive; // Allow that. -#endif #ifdef DEBUGDEBUG - bool continued_debug_output = (__libcwd_tsd.library_call == 0 && libcw_do._off < 0); -#endif - libcw::debug::ST_initialize_globals(); // This doesn't belong in the malloc department at all, but malloc() happens - // to be a function that is called _very_ early - and hence this is a good moment - // to initialize ALL of libcwd. -#ifdef DEBUGDEBUGMALLOC - ++__libcwd_tsd.recursive; + bool continued_debug_output = (__libcwd_tsd.library_call == 0 && libcw_do._off < 0); #endif + init_debugmalloc(); #ifdef DEBUGDEBUG - // It is possible that libcwd is not initialized at this point, libcw_do._off == 0 (turned off) - // 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)) - DoutInternal( dc_malloc|continued_cf, "internal_malloc(" << size << ", " << flag << ") = " ); + // It is possible that libcwd is not initialized at this point, libcw_do._off == 0 (turned off) + // 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)) + DoutInternal( dc_malloc|continued_cf, "internal_malloc(" << size << ", " << flag << ") = " ); #endif - } } register void* mptr; @@ -1299,7 +1276,7 @@ ++__libcwd_tsd.recursive; #endif #if defined(DEBUGDEBUGMALLOC) && defined(__GLIBCPP__) && !defined(DEBUGMALLOCEXTERNALCLINKAGE) - LIBCWD_ASSERT( _private_::WST_ios_base_initialized ); + LIBCWD_ASSERT( _private_::WST_ios_base_initialized || __libcwd_tsd.internal ); #endif if (__libcwd_tsd.internal) { @@ -1499,13 +1476,33 @@ void init_debugmalloc(void) { - if (WST_initialization_state == 0) + if (WST_initialization_state <= 0) { LIBCWD_TSD_DECLARATION - _private_::set_alloc_checking_off(LIBCWD_TSD); - memblk_map.MT_unsafe = new memblk_map_ct; // MT-safe: `init_debugmalloc' is called before any threads are created. - WST_initialization_state = -1; - _private_::set_alloc_checking_on(LIBCWD_TSD); + // This block is Single Threaded. + if (WST_initialization_state == 0) // Only true once. + { + _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; + _private_::set_alloc_checking_on(LIBCWD_TSD); + } +#ifdef __GLIBCPP__ + // "ios_base" is always initialized for libstdc++ version 2. + if (!_private_::WST_ios_base_initialized && !_private_::inside_ios_base_Init_Init()) +#endif // __GLIBCPP__ + { + WST_initialization_state = 1; // ST_initialize_globals() calls malloc again of course. +#ifdef DEBUGDEBUGMALLOC + --__libcwd_tsd.recursive; // Allow that. +#endif + libcw::debug::ST_initialize_globals(); // This doesn't belong in the malloc department at all, but malloc() happens + // to be a function that is called _very_ early - and hence this is a good moment + // to initialize ALL of libcwd. +#ifdef DEBUGDEBUGMALLOC + ++__libcwd_tsd.recursive; +#endif + } } } @@ -2118,7 +2115,7 @@ #endif #endif #if defined(DEBUGDEBUGMALLOC) && defined(__GLIBCPP__) && !defined(DEBUGMALLOCEXTERNALCLINKAGE) - LIBCWD_ASSERT( _private_::WST_ios_base_initialized ); + LIBCWD_ASSERT( _private_::WST_ios_base_initialized || __libcwd_tsd.internal ); #endif if (__libcwd_tsd.internal) { @@ -2195,7 +2192,7 @@ #endif #endif #if defined(DEBUGDEBUGMALLOC) && defined(__GLIBCPP__) && !defined(DEBUGMALLOCEXTERNALCLINKAGE) - LIBCWD_ASSERT( _private_::WST_ios_base_initialized ); + LIBCWD_ASSERT( _private_::WST_ios_base_initialized || __libcwd_tsd.internal ); #endif if (__libcwd_tsd.internal) { @@ -2283,7 +2280,7 @@ #endif #endif #if defined(DEBUGDEBUGMALLOC) && defined(__GLIBCPP__) && !defined(DEBUGMALLOCEXTERNALCLINKAGE) - LIBCWD_ASSERT( _private_::WST_ios_base_initialized ); + LIBCWD_ASSERT( _private_::WST_ios_base_initialized || __libcwd_tsd.internal ); #endif if (__libcwd_tsd.internal) { @@ -2647,7 +2644,7 @@ ++__libcwd_tsd.recursive; #endif #if defined(DEBUGDEBUGMALLOC) && defined(__GLIBCPP__) && !defined(DEBUGMALLOCEXTERNALCLINKAGE) - LIBCWD_ASSERT( _private_::WST_ios_base_initialized ); + LIBCWD_ASSERT( _private_::WST_ios_base_initialized || __libcwd_tsd.internal ); #endif #ifdef DEBUGDEBUGMALLOC --__libcwd_tsd.recursive; @@ -2668,7 +2665,7 @@ ++__libcwd_tsd.recursive; #endif #if defined(DEBUGDEBUGMALLOC) && defined(__GLIBCPP__) && !defined(DEBUGMALLOCEXTERNALCLINKAGE) - LIBCWD_ASSERT( _private_::WST_ios_base_initialized ); + LIBCWD_ASSERT( _private_::WST_ios_base_initialized || __libcwd_tsd.internal ); #endif #ifdef DEBUGDEBUGMALLOC --__libcwd_tsd.recursive; Index: src/libcwd/include/libcw/macro_Libcwd_macros.h diff -u src/libcwd/include/libcw/macro_Libcwd_macros.h:1.2 src/libcwd/include/libcw/macro_Libcwd_macros.h:1.3 --- src/libcwd/include/libcw/macro_Libcwd_macros.h:1.2 Sat Dec 29 20:17:50 2001 +++ src/libcwd/include/libcw/macro_Libcwd_macros.h Sun Dec 30 17:03:54 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/macro_Libcwd_macros.h,v 1.2 2001/12/30 04:17:50 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/include/libcw/macro_Libcwd_macros.h,v 1.3 2001/12/31 01:03:54 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -57,7 +57,7 @@ #define LIBCWD_STR1(x) #x #define LIBCWD_STR2(x) LIBCWD_STR1(x) #define LIBCWD_STR3 "LibcwDout at " __FILE__ ":" LIBCWD_STR2(__LINE__) "\n" -#define DEBUGDEBUGLIBCWDOUTMARKER ::write(2, LIBCWD_STR3, sizeof(LIBCWD_STR3)); +#define DEBUGDEBUGLIBCWDOUTMARKER ::write(2, LIBCWD_STR3, sizeof(LIBCWD_STR3) - 1); #else // !DEBUGDEBUGOUTPUT #define DEBUGDEBUGLIBCWDOUTMARKER #endif // !DEBUGDEBUGOUTPUT @@ -100,7 +100,7 @@ #ifndef DEBUGDEBUGLIBCWDOUTFATALMARKER #ifdef DEBUGDEBUGOUTPUT #define LIBCWD_STR4 "LibcwDoutFatal at " __FILE__ ":" LIBCWD_STR2(__LINE__) "\n" -#define DEBUGDEBUGLIBCWDOUTFATALMARKER ::write(2, LIBCWD_STR4, sizeof(LIBCWD_STR4)); +#define DEBUGDEBUGLIBCWDOUTFATALMARKER ::write(2, LIBCWD_STR4, sizeof(LIBCWD_STR4) - 1); #else #define DEBUGDEBUGLIBCWDOUTFATALMARKER #endif ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2001-12-31 05:01:35
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2001-11-31 05:01:34 UTC Modified files: libcwd/bfd.cc Log message: Don't start ST_exec_prog with 'internal' on. ---------------------- diff included ---------------------- Index: src/libcwd/bfd.cc diff -u src/libcwd/bfd.cc:1.89 src/libcwd/bfd.cc:1.90 --- src/libcwd/bfd.cc:1.89 Sun Dec 30 13:18:16 2001 +++ src/libcwd/bfd.cc Sun Dec 30 21:01:23 2001 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.89 2001/12/30 21:18:16 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/bfd.cc,v 1.90 2001/12/31 05:01:23 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -835,7 +835,7 @@ }; // cwbfd:: - typedef _private_::internal_vector<my_link_map> ST_shared_libs_vector_ct; + typedef std::vector<my_link_map> 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'. @@ -942,13 +942,7 @@ LIBCWD_TSD_DECLARATION #if defined(DEBUGDEBUG) && defined(DEBUGMALLOC) - // First time we get here, this string is intialized - this must be with `internal' off! - static bool second_time = false; - if (!second_time) - { - second_time = true; - LIBCWD_ASSERT( !__libcwd_tsd.internal ); - } + LIBCWD_ASSERT( !__libcwd_tsd.internal ); #endif // **************************************************************************** @@ -1031,13 +1025,15 @@ argv[0] = "ldd"; argv[1] = fullpath.value->data(); argv[2] = NULL; + set_alloc_checking_on(LIBCWD_TSD); ST_exec_prog(ldd_prog, argv, environ, ST_decode_ldd); + set_alloc_checking_off(LIBCWD_TSD); - for(ST_shared_libs_vector_ct::iterator iter = ST_shared_libs.begin(); iter != ST_shared_libs.end(); ++iter) + for(ST_shared_libs_vector_ct::const_iterator iter = ST_shared_libs.begin(); iter != ST_shared_libs.end(); ++iter) { - my_link_map* l = &(*iter); + my_link_map const* l = &(*iter); #else - for(link_map* l = _dl_loaded; l; l = l->l_next) + for(link_map const* l = _dl_loaded; l; l = l->l_next) { #endif if (l->l_addr) ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-01 04:43:16
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-01 04:43:15 UTC Modified files: libcwd/testsuite/libcwd.tst/dlopen.re libcwd/testsuite/libcwd.tst/test.exp Log message: On FreeBSD, which doesn't have _dl_loaded, less allocations are done. As a result, the variations in the debug output of this test vary too much: just test the relevant part and skip "anything" before it. ---------------------- diff included ---------------------- Index: src/libcwd/testsuite/libcwd.tst/dlopen.re diff -u src/libcwd/testsuite/libcwd.tst/dlopen.re:1.8 src/libcwd/testsuite/libcwd.tst/dlopen.re:1.9 --- src/libcwd/testsuite/libcwd.tst/dlopen.re:1.8 Sat Dec 29 20:17:51 2001 +++ src/libcwd/testsuite/libcwd.tst/dlopen.re Mon Dec 31 20:43:04 2001 @@ -1,20 +1,11 @@ -// input lines 3 -// output till ^MALLOC -((WARNING : core size is limited.* -)*BFD : Loading debug info from.* +// input lines 2 +// output till Loading debug info from +(.* )* -// input lines 4 -// output till ^BFD : Loading -(MALLOC : (malloc\([0-9]*\)|calloc\([0-9]*, [0-9]*\)) = <unfinished> -BFD : address 0x[0-9a-f]* corresponds to (dl-[a-z]*\.c|specific\.c|dlerror\.c):[0-9]* -MALLOC : <continued> 0x[0-9a-f]* -)+ -BFD : Loading debug info from \./module\.so \(0x[0-9a-f]*\) \.\.\. done \([0-9]* symbols\) -// input lines 4 +BFD : Loading debug info from \./module\.so \(0x[a-f0-9]*\) \.\.\. done \([0-9]* symbols\) +// input lines 2 // output till malloc\(310\) -(MALLOC : malloc\(28\) = <unfinished> -BFD : address 0x[0-9a-f]* corresponds to stl_alloc.h:[0-9]* -MALLOC : <continued> 0x[0-9a-f]* +(.* )* MALLOC : malloc\(310\) = <unfinished> BFD : address 0x[0-9a-f]* corresponds to module.cc:16 @@ -28,5 +19,5 @@ // input lines 2 // output till ^NOTICE (malloc 0x[0-9a-f]* *(dl-[a-z]*\.c|stl_alloc\.h|specific\.c|dlerror\.c):[0-9]* *<unknown type>; \(sz = [0-9]*\) -)+ +)* NOTICE : Finished Index: src/libcwd/testsuite/libcwd.tst/test.exp diff -u src/libcwd/testsuite/libcwd.tst/test.exp:1.6 src/libcwd/testsuite/libcwd.tst/test.exp:1.7 --- src/libcwd/testsuite/libcwd.tst/test.exp:1.6 Sat Dec 29 20:17:51 2001 +++ src/libcwd/testsuite/libcwd.tst/test.exp Mon Dec 31 20:43:05 2001 @@ -2,7 +2,7 @@ global SHAREDLIBS STATICLIBS catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles -# set srcfiles $srcdir/$subdir/alloctag.cc +# set srcfiles $srcdir/$subdir/dlopen.cc verbose "srcfiles are $srcfiles" set prefix "" ----------------------- End of diff ----------------------- |
From: Carlo W. <li...@us...> - 2002-01-04 04:22:45
|
CVSROOT : /cvsroot/libcw Module : src Commit time: 2002-00-04 04:22:43 UTC Modified files: libcwd/debugmalloc.cc libcwd/elf32.cc libcwd/testsuite/lib/libcwd.exp libcwd/testsuite/libcwd.tst/test.exp Log message: Bug fixes. Improvement of line number lookup for dwarf-2. ---------------------- diff included ---------------------- Index: src/libcwd/debugmalloc.cc diff -u src/libcwd/debugmalloc.cc:1.65 src/libcwd/debugmalloc.cc:1.66 --- src/libcwd/debugmalloc.cc:1.65 Sun Dec 30 17:03:54 2001 +++ src/libcwd/debugmalloc.cc Thu Jan 3 20:22:33 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.65 2001/12/31 01:03:54 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/debugmalloc.cc,v 1.66 2002/01/04 04:22:33 libcw Exp $ // // Copyright (C) 2000 - 2001, by // @@ -945,7 +945,9 @@ _private_::no_alloc_print_int_to(buf, a_size / type_info_ptr->ref_size(), false); buf->put(']'); } +#ifdef LIBCWD_USE_STRSTREAM buf->put('\0'); +#endif DoutInternal( dc::continued, buf->str() ); #ifdef LIBCWD_USE_STRSTREAM buf->freeze(0); Index: src/libcwd/elf32.cc diff -u src/libcwd/elf32.cc:1.28 src/libcwd/elf32.cc:1.29 --- src/libcwd/elf32.cc:1.28 Sat Dec 29 20:17:46 2001 +++ src/libcwd/elf32.cc Thu Jan 3 20:22:33 2002 @@ -1,4 +1,4 @@ -// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.28 2001/12/30 04:17:46 libcw Exp $ +// $Header: /cvsroot/l/li/libcw/src/libcwd/elf32.cc,v 1.29 2002/01/04 04:22:33 libcw Exp $ // // Copyright (C) 2001, by // @@ -599,22 +599,128 @@ typedef std::set<object_files_string, std::less<object_files_string>, _private_::object_files_allocator::rebind<object_files_string>::other> object_files_string_set_ct; //========================================================================================================================================== -// struct location_st +// struct location_ct // // Internal representation for locations. // -struct location_st { - object_files_string_set_ct::iterator source_iter; - Elf32_Half line; - object_files_string_set_ct::iterator func_iter; -}; - struct range_st { Elf32_Addr start; size_t size; }; +struct location_st { + object_files_string_set_ct::iterator M_func_iter; + object_files_string_set_ct::iterator M_source_iter; + Elf32_Half M_line; + + friend std::ostream& operator<<(std::ostream& os, location_st const& loc); +}; + +class object_file_ct; + +class location_ct : private location_st { +private: + location_st M_prev_location; + Elf32_Addr M_address; + range_st M_range; + int M_flags; + bool M_used; + object_file_ct* M_object_file; + +public: + location_ct(object_file_ct* object_file) : M_address(0), M_flags(0), M_object_file(object_file) { M_line = 0; M_range.start = 0; } + + void invalidate(void) { + M_flags = 0; + DoutDwarf(dc::bfd, "--> location invalidated."); + } + void set_line(Elf32_Half line) { + if (!(M_flags & 1) || M_line != line) + M_used = false; + M_flags |= 1; + M_line = line; + DoutDwarf(dc::bfd, "--> location.M_line = " << M_line); + if (is_valid()) + { + DoutDwarf(dc::bfd, "--> location now valid."); + M_store(); + } + } + void set_address(Elf32_Addr address) { + if (M_address != address) + M_used = false; + M_flags |= 2; + M_address = address; + DoutDwarf(dc::bfd, "--> location.M_address = 0x" << std::hex << address); + if (is_valid()) + { + DoutDwarf(dc::bfd, "--> location now valid."); + M_store(); + } + } + void copy(void) + { + if (is_valid()) + M_store(); + } + void set_source_iter(object_files_string_set_ct::iterator const& iter) { M_source_iter = iter; M_used = false; } + void set_func_iter(object_files_string_set_ct::iterator const& iter) { M_func_iter = iter; } + // load_stabs doesn't use out M_address. + bool is_valid_stabs(void) const { return (M_flags == 1); } + void increment_line(int increment) { + if (increment != 0) + M_used = false; +#if DEBUGDWARF + bool was_not_valid = !(M_flags & 1); +#endif + M_flags |= 1; + M_line += increment; + DoutDwarf(dc::bfd, "--> location.M_line = " << M_line); + if (is_valid()) + { +#if DEBUGDWARF + if (was_not_valid) + DoutDwarf(dc::bfd, "--> location now valid."); +#endif + M_store(); + } + } + void increment_address(unsigned int increment) { + if (increment > 0) + M_used = false; + M_address += increment; + DoutDwarf(dc::bfd, "--> location.M_address = 0x" << std::hex << M_address); +#if DEBUGDWARF + bool was_not_valid = !(M_flags & 2); +#endif + M_flags |= 2; + if (is_valid()) + { +#if DEBUGDWARF + if (was_not_valid) + DoutDwarf(dc::bfd, "--> location now valid."); +#endif + M_store(); + } + } + void sequence_end(void) { + DoutDwarf(dc::bfd, "--> Sequence end."); + if (is_valid()) + M_store(); + } + + Elf32_Half get_line(void) const { LIBCWD_ASSERT( (M_flags & 1) ); return M_line; } + object_files_string_set_ct::iterator get_source_iter(void) const { return M_source_iter; } + Elf32_Addr get_address(void) const { return M_address; } + + void stabs_range(range_st const& range) const; + +private: + bool is_valid(void) const { return (M_flags == 3); } + void M_store(void); +}; + bool operator==(range_st const& range1, range_st const& range2) { DoutFatal(dc::core, "Calling operator==(range_st const& range1, range_st const& range2)"); @@ -627,10 +733,15 @@ return os; } +std::ostream& operator<<(std::ostream& os, location_st const& loc) +{ + os << (*loc.M_source_iter).data() << ':' << std::dec << loc.M_line << " : \"" << (*loc.M_func_iter).data() << "\"."; + return os; +} + std::ostream& operator<<(std::ostream& os, std::pair<range_st const, location_st> const& p) { - os << std::hex << p.first.start << " - " << p.first.start + p.first.size - << "; " << (*p.second.source_iter).data() << ':' << std::dec << p.second.line << " : \"" << (*p.second.func_iter).data() << "\"."; + os << std::hex << p.first.start << " - " << p.first.start + p.first.size << "; " << p.second << '.'; return os; } #endif @@ -654,8 +765,6 @@ Elf32_Shdr const& section_header(void) const { return M_section_header; } }; -class object_file_ct; - struct hash_list_st { char const* name; Elf32_Addr addr; @@ -703,6 +812,8 @@ virtual void find_nearest_line(asymbol_st const*, Elf32_Addr, char const**, char const**, unsigned int*); private: char* allocate_and_read_section(int i); + friend void location_ct::M_store(void); + friend void location_ct::stabs_range(range_st const& range) const; void register_range(location_st const& location, range_st const& range); void load_stabs(void); void load_dwarf(void); @@ -712,6 +823,48 @@ }; //------------------------------------------------------------------------------------------------------------------------------------------- + +void location_ct::M_store(void) +{ + if (M_used) + { + DoutDwarf(dc::bfd, "Skipping M_store: M_used is set."); + return; + } + if (M_prev_location.M_source_iter == M_source_iter && M_prev_location.M_line == M_line) + { + DoutDwarf(dc::bfd, "Skipping M_store: location didn't change."); + M_used = true; + return; + } + if (M_range.start == M_address) + { + DoutDwarf(dc::bfd, "Skipping M_store: address range is zero."); + return; + } + if (M_range.start) + { + DoutDwarf(dc::bfd, "M_store(): Registering new range."); + M_range.size = M_address - M_range.start; + M_object_file->register_range(M_prev_location, M_range); + } +#if DEBUGDWARF + else + DoutDwarf(dc::bfd, "M_store(): M_range.start was 0."); +#endif + M_range.start = M_address; + M_prev_location.M_func_iter = M_func_iter; + M_prev_location.M_source_iter = M_source_iter; + M_prev_location.M_line = M_line; + M_used = true; +} + +inline void location_ct::stabs_range(range_st const& range) const +{ + M_object_file->register_range(*this, range); +} + +//------------------------------------------------------------------------------------------------------------------------------------------- // Implementation static asection_st const abs_section_c = { 0, "*ABS*" }; @@ -1157,7 +1310,7 @@ debug_info_ptr += 4; break; case DW_FORM_data8: - DoutDwarf(dc::finish, *reinterpret_cast<unsigned long long const*>(debug_info_ptr)); + // DoutDwarf(dc::finish, *reinterpret_cast<unsigned long long const*>(debug_info_ptr)); debug_info_ptr += 8; break; case DW_FORM_indirect: @@ -1181,7 +1334,7 @@ debug_info_ptr += 4; break; case DW_FORM_ref8: - DoutDwarf(dc::finish, *reinterpret_cast<unsigned long long const*>(debug_info_ptr)); + // DoutDwarf(dc::finish, *reinterpret_cast<unsigned long long const*>(debug_info_ptr)); debug_info_ptr += 8; break; case DW_FORM_ref_udata: @@ -1264,12 +1417,8 @@ // State machine. // See paragraph 6.2 of "DWARF Debugging Information Format" document. - Elf32_Addr address; // The program-counter value corresponding to a machine instruction generated by the compiler. uLEB128_t file; // An unsigned integer indicating the identity of the source file corresponding to a machine // instruction. - unsigned int line; // An unsigned integer indicating a source line number. Lines are numbered beginning at 1. - // The compiler may emit the value 0 in cases where an instruction cannot be attributed to - // any source line. uLEB128_t column; // An unsigned integer indicating a column number within a source line. Columns are numbered // beginning at 1. The value 0 is reserved to indicate that a statement begins at the left // edge of the line. @@ -1329,29 +1478,25 @@ object_files_string cur_dir; object_files_string cur_source; - location_st location; - range_st range; + location_ct location(this); object_files_string cur_func("-DWARF symbol\0"); // We don't add function names - this is used to see we're // doing DWARF in find_nearest_line(). - location.func_iter = M_function_names.insert(cur_func).first; + location.set_func_iter(M_function_names.insert(cur_func).first); do { - address = 0; file = 0; // One less than the `file' mentioned in the documentation. - line = 1; column = 0; is_stmt = default_is_stmt; basic_block = false; end_sequence = false; - - location.line = 0; - range.start = 0; - cur_dir = default_dir; cur_source = cur_dir + default_source; - location.source_iter = M_source_files.insert(cur_source).first; + + location.invalidate(); + location.set_source_iter(M_source_files.insert(cur_source).first); + location.set_line(1); while(!end_sequence) { @@ -1368,25 +1513,25 @@ LIBCWD_ASSERT( size > 0 ); uLEB128_t extended_opcode; dwarf_read(debug_line_ptr, extended_opcode); - LIBCWD_ASSERT( extended_opcode < 0x80 ); // Then it's size is one: + LIBCWD_ASSERT( extended_opcode < 0x80 ); // Then it's size is one: --size; switch(extended_opcode) { case DW_LNE_end_sequence: LIBCWD_ASSERT( size == 0 ); end_sequence = true; - DoutDwarf(dc::bfd, "DW_LNE_end_sequence: Address: 0x" << std::hex << address); - range.size = address - range.start; - if (location.line) - register_range(location, range); + DoutDwarf(dc::bfd, "DW_LNE_end_sequence: Address: 0x" << std::hex << location.get_address()); + location.sequence_end(); break; case DW_LNE_set_address: + { + Elf32_Addr address; LIBCWD_ASSERT( size == sizeof(address) ); dwarf_read(debug_line_ptr, address); DoutDwarf(dc::bfd, "DW_LNE_set_address: 0x" << std::hex << address); - if (!range.start) - range.start = address; + location.set_address(address); break; + } case DW_LNE_define_file: { unsigned char const* end = debug_line_ptr + size; @@ -1411,38 +1556,31 @@ break; } case DW_LNS_copy: - DoutDwarf(dc::bfd, "DW_LNS_copy: Address/Line: 0x" << std::hex << address << ", " << std::dec << line); - if (location.line && location.line != line) - { - range.size = address - range.start; - register_range(location, range); - range.start = address; - } - location.line = line; + DoutDwarf(dc::bfd, "DW_LNS_copy"); + location.copy(); basic_block = false; break; case DW_LNS_advance_pc: { uLEB128_t address_increment; dwarf_read(debug_line_ptr, address_increment); - address += minimum_instruction_length * address_increment; - DoutDwarf(dc::bfd, "DW_LNS_advance_pc: 0x" << std::hex << address); - if (!range.start) - range.start = address; + DoutDwarf(dc::bfd, "DW_LNS_advance_pc: " << std::hex << address_increment); + location.increment_address(minimum_instruction_length * address_increment); break; } case DW_LNS_advance_line: { LEB128_t line_increment; dwarf_read(debug_line_ptr, line_increment); - line += line_increment; - DoutDwarf(dc::bfd, "DW_LNS_advance_line: " << line); + DoutDwarf(dc::bfd, "DW_LNS_advance_line: " << line_increment); + location.increment_line(line_increment); break; } case DW_LNS_set_file: dwarf_read(debug_line_ptr, file); --file; DoutDwarf(dc::bfd, "DW_LNS_set_file: \"" << file_names[file].name << '"'); + location.invalidate(); if (*file_names[file].name == '/') cur_source.assign(file_names[file].name); else @@ -1458,8 +1596,7 @@ cur_source.append(file_names[file].name); } cur_source += '\0'; - location.source_iter = M_source_files.insert(cur_source).first; - location.line = 0; + location.set_source_iter(M_source_files.insert(cur_source).first); break; case DW_LNS_set_column: dwarf_read(debug_line_ptr, column); @@ -1475,21 +1612,17 @@ break; case DW_LNS_const_add_pc: { + DoutDwarf(dc::bfd, "DW_LNS_const_add_pc"); unsigned int address_increment = (255 - opcode_base) / line_range; - address += minimum_instruction_length * address_increment; - DoutDwarf(dc::bfd, "DW_LNS_const_add_pc: 0x" << std::hex << address); - if (!range.start) - range.start = address; + location.increment_address(minimum_instruction_length * address_increment); break; } case DW_LNS_fixed_advance_pc: { + DoutDwarf(dc::bfd, "DW_LNS_fixed_advance_pc"); unsigned short int address_increment; dwarf_read(debug_line_ptr, address_increment); - address += minimum_instruction_length * address_increment; - DoutDwarf(dc::bfd, "DW_LNS_fixed_advance_pc: 0x" << std::hex << address); - if (!range.start) - range.start = address; + location.increment_address(minimum_instruction_length * address_increment); break; } default: @@ -1506,17 +1639,12 @@ { // Special opcode. int line_increment = line_base + ((opcode - opcode_base) % line_range); - line += line_increment; unsigned int address_increment = (opcode - opcode_base) / line_range; - address += minimum_instruction_length * address_increment; - DoutDwarf(dc::bfd, "Special opcode. Address/Line: 0x" << std::hex << address << ", " << std::dec << line); - if (location.line && location.line != line) // Catenate ranges with same location. - { - range.size = address - range.start; - register_range(location, range); - range.start = address; - } - location.line = line; + DoutDwarf(dc::bfd, "Special opcode. Address/Line increments: 0x" << + std::hex << address_increment << ", " << std::dec << line_increment); + location.invalidate(); // Make sure we won't add a new range until after also line was incremented. + location.increment_address(minimum_instruction_length * address_increment); + location.increment_line(line_increment); basic_block = false; } } @@ -1582,7 +1710,7 @@ object_files_string cur_dir; object_files_string cur_source; object_files_string cur_func; - location_st location; + location_ct location(this); range_st range; bool skip_function = false; bool source_file_changed_and_we_didnt_copy_it_yet = true; @@ -1630,7 +1758,7 @@ Dout(dc::bfd, "N_FUN: " << "end at " << std::hex << stabs[j].n_value << '.'); range.size = func_addr + stabs[j].n_value - range.start; if (!skip_function) - register_range(location, range); + location.stabs_range(range); skip_function = false; } else @@ -1646,7 +1774,7 @@ range.start = func_addr = stabs[j].n_value; if (DEBUGSTABS) Dout(dc::bfd, "N_FUN: " << std::hex << func_addr << " : \"" << &stabs_string_table[stabs[j].n_strx] << "\"."); - if (func_addr == 0 && location.line) + if (func_addr == 0 && location.is_valid_stabs()) { // Start of function is not given (bug in assembler?), try to find it by name: uint32_t hash = elf_hash(reinterpret_cast<unsigned char const*>(fn), (unsigned char)':'); @@ -1667,7 +1795,7 @@ // the dynamic linker has put it in the 'undefined' section and no // address is known even though there is still this N_FUN entry. skip_function = true; - location.line = 0; + location.invalidate(); break; } else if (DEBUGSTABS) @@ -1691,8 +1819,8 @@ LIBCWD_ASSERT( func_addr_test == func_addr ); } #endif - location.func_iter = M_function_names.insert(cur_func).first; - location.line = 0; // See N_SLINE + location.set_func_iter(M_function_names.insert(cur_func).first); + location.invalidate(); // See N_SLINE } break; } @@ -1701,9 +1829,9 @@ Dout(dc::bfd, "N_SLINE: " << stabs[j].n_desc << " at " << std::hex << stabs[j].n_value << '.'); if (stabs[j].n_value != 0) { - // Always false when function was changed since last line because location.line is set to 0 in that case. + // Always false when function was changed since last line because location.invalidate() was called in that case. // Catenate ranges with same location. - if (!source_file_changed_and_we_didnt_copy_it_yet && stabs[j].n_desc == location.line) + if (!source_file_changed_and_we_didnt_copy_it_yet && location.is_valid_stabs() && stabs[j].n_desc == location.get_line()) break; range.size = func_addr + stabs[j].n_value - range.start; // Delay one source/line change when there was no code since last source file change. @@ -1714,12 +1842,12 @@ break; } if (!skip_function) - register_range(location, range); + location.stabs_range(range); range.start += range.size; } // Store the source/line for the next range. - location.source_iter = last_source_iter; - location.line = stabs[j].n_desc; + location.set_source_iter(last_source_iter); + location.set_line(stabs[j].n_desc); source_file_changed_and_we_didnt_copy_it_yet = false; source_file_changed_but_line_number_not_yet = false; break; @@ -1754,7 +1882,7 @@ range.start = offset; range.size = 1; object_files_range_location_map_ct::const_iterator i(M_ranges.find(static_cast<range_st const>(range))); - if (i == M_ranges.end() || (*(*(*i).second.func_iter).data() != '-' && strcmp((*(*i).second.func_iter).data(), symbol->name))) + if (i == M_ranges.end() || (*(*(*i).second.M_func_iter).data() != '-' && strcmp((*(*i).second.M_func_iter).data(), symbol->name))) { *file = NULL; *func = symbol->name; @@ -1762,12 +1890,12 @@ } else { - *file = (*(*i).second.source_iter).data(); - if (*(*(*i).second.func_iter).data() != '-') // '-' is used for DWARF symbols by load_dwarf() (see above). - *func = (*(*i).second.func_iter).data(); + *file = (*(*i).second.M_source_iter).data(); + if (*(*(*i).second.M_func_iter).data() != '-') // '-' is used for DWARF symbols by load_dwarf() (see above). + *func = (*(*i).second.M_func_iter).data(); else *func = symbol->name; - *line = (*i).second.line; + *line = (*i).second.M_line; } return; } @@ -1784,9 +1912,7 @@ { 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.source_iter).data() << ':' << std::dec << location.line << " : \"" - << (*location.func_iter).data() << "\"."); + 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 @@ -1798,7 +1924,7 @@ #if DEBUGSTABS || DEBUGDWARF if (!p.second) { - if ((*p.first).second.func_iter != location.func_iter) + if ((*p.first).second.M_func_iter != location.M_func_iter) Dout(dc::bfd, "WARNING: Collision between different functions (" << *p.first << ")!?"); else { @@ -1806,9 +1932,9 @@ Dout(dc::bfd, "WARNING: Different start for same function (" << *p.first << ")!?"); if ((*p.first).first.size != range.size) Dout(dc::bfd, "WARNING: Different sizes for same function. Not sure what .stabs entry to use."); - if ((*p.first).second.line != location.line) + if ((*p.first).second.M_line != location.M_line) Dout(dc::bfd, "WARNING: Different line numbers for overlapping range (" << *p.first << ")!?"); - if ((*p.first).second.source_iter != location.source_iter) + if ((*p.first).second.M_source_iter != location.M_source_iter) Dout(dc::bfd, "Collision with " << *p.first << "."); } } Index: src/libcwd/testsuite/lib/libcwd.exp diff -u src/libcwd/testsuite/lib/libcwd.exp:1.8 src/libcwd/testsuite/lib/libcwd.exp:1.9 --- src/libcwd/testsuite/lib/libcwd.exp:1.8 Sat Feb 24 19:47:38 2001 +++ src/libcwd/testsuite/lib/libcwd.exp Thu Jan 3 20:22:33 2002 @@ -43,7 +43,7 @@ verbose " out = \"$out\"" if { [regexp -- "nodebug" $options] } { - regsub -- "-g\[a-z0-9\]*" "$OPTIONS" "" compiler_options + regsub -- "-g\[-a-z0-9\]*" "$OPTIONS" "" compiler_options } else { set compiler_options "$OPTIONS" } Index: src/libcwd/testsuite/libcwd.tst/test.exp diff -u src/libcwd/testsuite/libcwd.tst/test.exp:1.7 src/libcwd/testsuite/libcwd.tst/test.exp:1.8 --- src/libcwd/testsuite/libcwd.tst/test.exp:1.7 Mon Dec 31 20:43:05 2001 +++ src/libcwd/testsuite/libcwd.tst/test.exp Thu Jan 3 20:22:33 2002 @@ -2,7 +2,7 @@ global SHAREDLIBS STATICLIBS catch "glob -nocomplain $srcdir/$subdir/*.cc" srcfiles -# set srcfiles $srcdir/$subdir/dlopen.cc +# set srcfiles $srcdir/$subdir/leak.cc verbose "srcfiles are $srcfiles" set prefix "" ----------------------- End of diff ----------------------- |