00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
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
00059 template<class OSTREAM>
00060 void print_location_on(OSTREAM& os, location_ct const& location);
00061
00062 }
00063 }
00064
00065
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;
00104 #endif
00105
00106 protected:
00107
00108
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
00117 #if LIBCWD_THREAD_SAFE
00118 explicit location_ct(void const* addr LIBCWD_COMMA_TSD_PARAM);
00119
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);
00152
00160 void lock_ownership(void) { if (M_known) M_filepath.lock(); }
00161
00165 void pc_location(void const* pc);
00166
00167
00168 void M_pc_location(void const* addr LIBCWD_COMMA_TSD_PARAM);
00169
00173 void clear(void);
00174
00175 public:
00176
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
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
00223
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
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
00259
00260 }
00261
00262 #endif // CWDEBUG_LOCATION
00263 #endif // LIBCWD_CLASS_LOCATION_H