libcwd: The C++ Debugging Support Library - Reference Manual
Author: Carlo Wood
Description: C++ debugging support library with ostream debug output
Keywords: libcwd, debug output, debug facility, debug channel, object orientation, OO, C++, nested debug output, ostream, memory allocation, debugging, source file and line number

Main Page Reference Manual Namespace List Compound List Namespace Members Compound Members File Members

# libcwd/class_location.h

Go to the documentation of this file.

    00001 // $Header$
    00002 //
    00003 // Copyright (C) 2000 - 2004, by
    00004 //
    00005 // Carlo Wood, Run on IRC <carlo@alinoe.com>
    00006 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
    00007 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
    00008 //
    00009 // This file may be distributed under the terms of the Q Public License
    00010 // version 1.0 as appearing in the file LICENSE.QPL included in the
    00011 // packaging of this file.
    00012 //
    00013
    00018 #ifndef LIBCWD_CLASS_LOCATION_H
    00019 #define LIBCWD_CLASS_LOCATION_H
    00020
    00021 #ifndef LIBCWD_CONFIG_H
    00022 #include <libcwd/config.h>
    00023 #endif
    00024
    00025 #if CWDEBUG_LOCATION
    00026
    00027 #ifndef LIBCWD_PRIVATE_STRUCT_TSD_H
    00028 #include <libcwd/private_struct_TSD.h>
    00029 #endif
    00030 #ifndef LIBCWD_CLASS_OBJECT_FILE_H
    00031 #include <libcwd/class_object_file.h>
    00032 #endif
    00033 #ifndef LIBCW_LOCKABLE_AUTO_PTR_H
    00034 #include <libcwd/lockable_auto_ptr.h>
    00035 #endif
    00036 #ifndef LIBCW_STRING
    00037 #define LIBCW_STRING
    00038 #include <string>
    00039 #endif
    00040 #ifndef LIBCW_IOSFWD
    00041 #define LIBCW_IOSFWD
    00042 #include <iosfwd>
    00043 #endif
    00044
    00045 namespace libcwd {
    00046
    00047 // Forward declaration.
    00048 class location_ct;
    00049
    00050   namespace _private_ {
    00051
    00052 enum hidden_st {
    00053   filtered_location,
    00054   unfiltered_location,
    00055   new_location
    00056 };
    00057
    00058 // Forward declaration.
    00059 template<class OSTREAM>
    00060   void print_location_on(OSTREAM& os, location_ct const& location);
    00061
    00062   } // namespace _private_
    00063 } // namespace libcwd
    00064
    00065 // This header file uses hidden_st
    00066 #ifndef LIBCWD_CLASS_ALLOC_FILTER_H
    00067 #include <libcwd/class_alloc_filter.h>
    00068 #endif
    00069
    00070 namespace libcwd {
    00071
    00076 extern char const* const unknown_function_c;
    00077
    00088 class location_ct {
    00089 protected:
    00090   lockable_auto_ptr<char, true> M_filepath;
    00091   union {
    00092     char* M_filename;
    00093     void const* M_initialization_delayed;
    00094     void const* M_unknown_pc;
    00095   };
    00096   unsigned int M_line;
    00097   char const* M_func;
    00098   object_file_ct const* M_object_file;
    00099   bool M_known;
    00100 private:
    00101 #if CWDEBUG_ALLOC
    00102   friend class alloc_filter_ct;
    00103   mutable _private_::hidden_st M_hide;          // Indicates if this location is filtered by the current filter.
    00104 #endif
    00105
    00106 protected:
    00107   // M_func can point to one of these constants, or to libcwd::unknown_function_c
    00108   // or to a static string with the mangled function name.
    00109   static char const* const S_uninitialized_location_ct_c;
    00110   static char const* const S_pre_ios_initialization_c;
    00111   static char const* const S_pre_libcwd_initialization_c;
    00112   static char const* const S_cleared_location_ct_c;
    00113
    00114 public:
    00115   explicit location_ct(void const* addr);
    00116       // Construct a location object for address `addr'.
    00117 #if LIBCWD_THREAD_SAFE
    00118   explicit location_ct(void const* addr LIBCWD_COMMA_TSD_PARAM);
    00119       // Idem, but with passing the TSD.
    00120 #endif
    00121   ~location_ct();
    00122
    00129   location_ct(void);
    00130
    00140   location_ct(location_ct const& location);
    00141
    00151   location_ct& operator=(location_ct const& location);          // Assignment operator
    00152
    00160   void lock_ownership(void) { if (M_known) M_filepath.lock(); }
    00161
    00165   void pc_location(void const* pc);
    00166
    00167   // Only public because libcwd calls it directly.
    00168   void M_pc_location(void const* addr LIBCWD_COMMA_TSD_PARAM);
    00169
    00173   void clear(void);
    00174
    00175 public:
    00176   // Accessors
    00181   bool is_known(void) const;
    00182
    00189   std::string file(void) const;
    00190
    00192   unsigned int line(void) const;
    00193
    00200   char const* mangled_function_name(void) const;
    00201
    00203   size_t filename_length(void) const { return M_known ? strlen(M_filename) : 0; }
    00205   size_t filepath_length(void) const { return M_known ? strlen(M_filepath.get()) : 0; }
    00206
    00212   object_file_ct const* object_file(void) const { return M_object_file; }
    00213
    00214   // Printing
    00216   void print_filepath_on(std::ostream& os) const;
    00218   void print_filename_on(std::ostream& os) const;
    00219   template<class OSTREAM>
    00220     friend void _private_::print_location_on(OSTREAM& os, location_ct const& location);
    00221 #if (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
    00222   // This doesn't need to be a friend, but g++ 3.3.x and lower are broken.
    00223   // We need to declare an operator<< this way as a workaround.
    00224   friend std::ostream&
    00225   operator<<(std::ostream& os, location_ct const& location)
    00226   {
    00227     _private_::print_location_on(os, location);
    00228     return os;
    00229   }
    00230 #endif
    00231
    00232   // This is used in list_allocations_on.
    00233   bool initialization_delayed(void) const { return (!M_object_file && (M_func == S_pre_ios_initialization_c || M_func == S_pre_libcwd_initialization_c)); }
    00234   void const* unknown_pc(void) const { return (!M_object_file && M_func == unknown_function_c) ? M_unknown_pc : initialization_delayed() ? M_initialization_delayed : 0; }
    00235 #if CWDEBUG_ALLOC
    00236   void handle_delayed_initialization(alloc_filter_ct const& filter);
    00237   bool hide_from_alloc_list(void) const { return M_hide == _private_::filtered_location; }
    00238   bool new_location(void) const { return M_hide == _private_::new_location; }
    00239   void synchronize_with(alloc_filter_ct const&) const;
    00240 #endif
    00241 };
    00242
    00256 location_format_t location_format(location_format_t format);
    00257  // End of group 'group_locations'
    00259
    00260 } // namespace libcwd
    00261
    00262 #endif // CWDEBUG_LOCATION
    00263 #endif // LIBCWD_CLASS_LOCATION_H