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: /cvsroot/libcwd/libcwd/include/libcwd/class_location.h,v 1.7 2004/05/27 03:03:51 libcw Exp $
00002 //
00003 // Copyright (C) 2000 - 2003, 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     namespace _private_ {
00048 
00049 enum hidden_st {
00050   filtered_location,
00051   unfiltered_location,
00052   new_location
00053 };
00054 
00055     } // namespace _private_
00056 
00061 extern char const* const unknown_function_c;
00062 
00073 class location_ct {
00074 protected:
00075   lockable_auto_ptr<char, true> M_filepath;     
00076   union {
00077     char* M_filename;                           
00078     void const* M_initialization_delayed;       
00079   };
00080   unsigned int M_line;                          
00081   char const* M_func;                           
00082   object_file_ct const* M_object_file;          
00083   bool M_known;                                 
00084 private:
00085 #if CWDEBUG_ALLOC
00086   friend class ooam_filter_ct;
00087   mutable _private_::hidden_st M_hide;          // Indicates if this location is filtered by the current filter.
00088 #endif
00089 
00090 protected:
00091   // M_func can point to one of these constants, or to libcwd::unknown_function_c
00092   // or to a static string with the mangled function name.
00093   static char const* const S_uninitialized_location_ct_c;
00094   static char const* const S_pre_ios_initialization_c;
00095   static char const* const S_pre_libcwd_initialization_c;
00096   static char const* const S_cleared_location_ct_c;
00097 
00098 public:
00099   location_ct(void const* addr);
00100       // Construct a location object for address `addr'.
00101 #if LIBCWD_THREAD_SAFE
00102   location_ct(void const* addr LIBCWD_COMMA_TSD_PARAM);
00103       // Idem, but with passing the TSD.
00104 #endif
00105   ~location_ct();
00106 
00113   location_ct(void);
00114 
00124   location_ct(location_ct const& location);
00125 
00135   location_ct& operator=(location_ct const& location);          // Assignment operator
00136 
00144   void lock_ownership(void) { if (M_known) M_filepath.lock(); }
00145 
00149   void pc_location(void const* pc);
00150 
00151   // Only public because libcwd calls it directly.
00152   void M_pc_location(void const* addr LIBCWD_COMMA_TSD_PARAM);
00153 
00157   void clear(void);
00158 
00159 public:
00160   // Accessors
00165   bool is_known(void) const;
00166 
00173   std::string file(void) const;
00174 
00176   unsigned int line(void) const;
00177 
00184   char const* mangled_function_name(void) const;
00185 
00187   size_t filename_length(void) const { return M_known ? strlen(M_filename) : 0; }
00189   size_t filepath_length(void) const { return M_known ? strlen(M_filepath.get()) : 0; }
00190 
00196   object_file_ct const* object_file(void) const { return M_object_file; }
00197 
00198   // Printing
00200   void print_filepath_on(std::ostream& os) const;
00202   void print_filename_on(std::ostream& os) const;
00203   friend std::ostream& operator<<(std::ostream& os, location_ct const& location);
00204       // Prints a default "M_filename:M_line".
00205 
00206   // This is used in list_allocations_on.
00207   bool initialization_delayed(void) const { return (!M_object_file && (M_func == S_pre_ios_initialization_c || M_func == S_pre_libcwd_initialization_c)); }
00208 #if CWDEBUG_ALLOC
00209   void handle_delayed_initialization(ooam_filter_ct const& filter);
00210   bool hide_from_alloc_list(void) const { return M_hide == _private_::filtered_location; }
00211   bool new_location(void) const { return M_hide == _private_::new_location; }
00212   void synchronize_with(ooam_filter_ct const&) const;
00213 #endif
00214 };
00215  // End of group 'group_locations'
00217 
00218 } // namespace libcwd
00219 
00220 #endif // CWDEBUG_LOCATION
00221 #endif // LIBCWD_CLASS_LOCATION_H
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.