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

class_location.h
Go to the documentation of this file.
1 // $Header$
2 //
3 // Copyright (C) 2000 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
18 #ifndef LIBCWD_CLASS_LOCATION_H
19 #define LIBCWD_CLASS_LOCATION_H
20 
21 #ifndef LIBCWD_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #if CWDEBUG_LOCATION
26 
27 #ifndef LIBCWD_PRIVATE_STRUCT_TSD_H
28 #include "private_struct_TSD.h"
29 #endif
30 #ifndef LIBCWD_CLASS_OBJECT_FILE_H
31 #include "class_object_file.h"
32 #endif
33 #ifndef LIBCW_LOCKABLE_AUTO_PTR_H
34 #include "lockable_auto_ptr.h"
35 #endif
36 #ifndef LIBCW_STRING
37 #define LIBCW_STRING
38 #include <string>
39 #endif
40 #ifndef LIBCW_IOSFWD
41 #define LIBCW_IOSFWD
42 #include <iosfwd>
43 #endif
44 
45 namespace libcwd {
46 
47 // Forward declaration.
48 class location_ct;
49 
50  namespace _private_ {
51 
52 enum hidden_st {
53  filtered_location,
54  unfiltered_location,
55  new_location
56 };
57 
58 // Forward declaration.
59 template<class OSTREAM>
60  void print_location_on(OSTREAM& os, location_ct const& location);
61 
62  } // namespace _private_
63 } // namespace libcwd
64 
65 // This header file uses hidden_st
66 #ifndef LIBCWD_CLASS_ALLOC_FILTER_H
67 #include "class_alloc_filter.h"
68 #endif
69 
70 namespace libcwd {
71 
76 extern char const* const unknown_function_c;
77 
88 class location_ct {
89 protected:
90  lockable_auto_ptr<char, true> M_filepath;
91  union {
92  char* M_filename;
93  void const* M_initialization_delayed;
94  void const* M_unknown_pc;
95  };
96  unsigned int M_line;
97  char const* M_func;
98  object_file_ct const* M_object_file;
99  bool M_known;
100 private:
101 #if CWDEBUG_ALLOC
102  friend class alloc_filter_ct;
103  mutable _private_::hidden_st M_hide; // Indicates if this location is filtered by the current filter.
104 #endif
105 
106 protected:
107  // M_func can point to one of these constants, or to libcwd::unknown_function_c
108  // or to a static string with the mangled function name.
109  static char const* const S_uninitialized_location_ct_c;
110  static char const* const S_pre_ios_initialization_c;
111  static char const* const S_pre_libcwd_initialization_c;
112  static char const* const S_cleared_location_ct_c;
113 
114 public:
115  explicit location_ct(void const* addr);
116  // Construct a location object for address `addr'.
117 #if LIBCWD_THREAD_SAFE
118  explicit location_ct(void const* addr LIBCWD_COMMA_TSD_PARAM);
119  // Idem, but with passing the TSD.
120 #endif
121  ~location_ct();
122 
129  location_ct();
130 
140  location_ct(location_ct const& location);
141 
151  location_ct& operator=(location_ct const& location); // Assignment operator
152 
160  void lock_ownership() { if (M_known) M_filepath.lock(); }
161 
165  void pc_location(void const* pc);
166 
167  // Only public because libcwd calls it directly.
168  void M_pc_location(void const* addr LIBCWD_COMMA_TSD_PARAM);
169 
173  void clear();
174 
175 public:
176  // Accessors
181  bool is_known() const;
182 
189  std::string file() const;
190 
192  unsigned int line() const;
193 
200  char const* mangled_function_name() const;
201 
203  size_t filename_length() const { return M_known ? strlen(M_filename) : 0; }
205  size_t filepath_length() const { return M_known ? strlen(M_filepath.get()) : 0; }
206 
212  object_file_ct const* object_file() const { return M_object_file; }
213 
214  // Printing
216  void print_filepath_on(std::ostream& os) const;
218  void print_filename_on(std::ostream& os) const;
219  template<class OSTREAM>
220  friend void _private_::print_location_on(OSTREAM& os, location_ct const& location);
221 #if (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
222  // This doesn't need to be a friend, but g++ 3.3.x and lower are broken.
223  // We need to declare an operator<< this way as a workaround.
224  friend std::ostream&
225  operator<<(std::ostream& os, location_ct const& location)
226  {
227  _private_::print_location_on(os, location);
228  return os;
229  }
230 #endif
231 
232  // This is used in list_allocations_on.
233  bool initialization_delayed() const { return (!M_object_file && (M_func == S_pre_ios_initialization_c || M_func == S_pre_libcwd_initialization_c)); }
234  void const* unknown_pc() const { return (!M_object_file && M_func == unknown_function_c) ? M_unknown_pc : initialization_delayed() ? M_initialization_delayed : 0; }
235 #if CWDEBUG_LOCATION
236  void handle_delayed_initialization(alloc_filter_ct const& filter);
237  bool hide_from_alloc_list() const { return M_hide == _private_::filtered_location; }
238  bool new_location() const { return M_hide == _private_::new_location; }
239  void synchronize_with(alloc_filter_ct const&) const;
240 #endif
241 };
242 
243 //#if (__GNUC__ > 3 || __GNUC_MINOR__ >= 4)
244 //extern std::ostream& operator<<(std::ostream& os, location_ct const& location);
245 //#endif
246 
260 location_format_t location_format(location_format_t format);
261  // End of group 'group_locations'
263 
264 } // namespace libcwd
265 
266 #endif // CWDEBUG_LOCATION
267 #endif // LIBCWD_CLASS_LOCATION_H
namespace for libcwd.
Definition: debug.cc:87
std::ostream & operator<<(std::ostream &os, memblk_types_nt memblk_type)
Allow writing a memblk_types_nt directly to an ostream.
Definition: debugmalloc.cc:688
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.