OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [doc/] [xml/] [manual/] [debug_mode.xml] - Blame information for rev 833

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
2
         xml:id="manual.ext.debug_mode" xreflabel="Debug Mode">
3
4
 
5
Debug Mode
6
  
7
    
8
      C++
9
    
10
    
11
      library
12
    
13
    
14
      debug
15
    
16
  
17
18
 
19
 
20
 
21
Intro
22
 
23
  
24
    By default, libstdc++ is built with efficiency in mind, and
25
    therefore performs little or no error checking that is not
26
    required by the C++ standard. This means that programs that
27
    incorrectly use the C++ standard library will exhibit behavior
28
    that is not portable and may not even be predictable, because they
29
    tread into implementation-specific or undefined behavior. To
30
    detect some of these errors before they can become problematic,
31
    libstdc++ offers a debug mode that provides additional checking of
32
    library facilities, and will report errors in the use of libstdc++
33
    as soon as they can be detected by emitting a description of the
34
    problem to standard error and aborting the program.  This debug
35
    mode is available with GCC 3.4.0 and later versions.
36
  
37
 
38
  
39
    The libstdc++ debug mode performs checking for many areas of the
40
    C++ standard, but the focus is on checking interactions among
41
    standard iterators, containers, and algorithms, including:
42
  
43
 
44
  
45
    Safe iterators: Iterators keep track of the
46
    container whose elements they reference, so errors such as
47
    incrementing a past-the-end iterator or dereferencing an iterator
48
    that points to a container that has been destructed are diagnosed
49
    immediately.
50
 
51
    Algorithm preconditions: Algorithms attempt to
52
    validate their input parameters to detect errors as early as
53
    possible. For instance, the set_intersection
54
    algorithm requires that its iterator
55
    parameters first1 and last1 form a valid
56
    iterator range, and that the sequence
57
    [first1, last1) is sorted according to
58
    the same predicate that was passed
59
    to set_intersection; the libstdc++ debug mode will
60
    detect an error if the sequence is not sorted or was sorted by a
61
    different predicate.
62
  
63
 
64
65
 
66
Semantics
67
 
68
  
69
  
70
 
71
A program that uses the C++ standard library correctly
72
  will maintain the same semantics under debug mode as it had with
73
  the normal (release) library. All functional and exception-handling
74
  guarantees made by the normal library also hold for the debug mode
75
  library, with one exception: performance guarantees made by the
76
  normal library may not hold in the debug mode library. For
77
  instance, erasing an element in a std::list is a
78
  constant-time operation in normal library, but in debug mode it is
79
  linear in the number of iterators that reference that particular
80
  list. So while your (correct) program won't change its results, it
81
  is likely to execute more slowly.
82
 
83
libstdc++ includes many extensions to the C++ standard library. In
84
  some cases the extensions are obvious, such as the hashed
85
  associative containers, whereas other extensions give predictable
86
  results to behavior that would otherwise be undefined, such as
87
  throwing an exception when a std::basic_string is
88
  constructed from a NULL character pointer. This latter category also
89
  includes implementation-defined and unspecified semantics, such as
90
  the growth rate of a vector. Use of these extensions is not
91
  considered incorrect, so code that relies on them will not be
92
  rejected by debug mode. However, use of these extensions may affect
93
  the portability of code to other implementations of the C++ standard
94
  library, and is therefore somewhat hazardous. For this reason, the
95
  libstdc++ debug mode offers a "pedantic" mode (similar to
96
  GCC's -pedantic compiler flag) that attempts to emulate
97
  the semantics guaranteed by the C++ standard. For
98
  instance, constructing a std::basic_string with a NULL
99
  character pointer would result in an exception under normal mode or
100
  non-pedantic debug mode (this is a libstdc++ extension), whereas
101
  under pedantic debug mode libstdc++ would signal an error. To enable
102
  the pedantic debug mode, compile your program with
103
  both -D_GLIBCXX_DEBUG
104
  and -D_GLIBCXX_DEBUG_PEDANTIC .
105
  (N.B. In GCC 3.4.x and 4.0.0, due to a bug,
106
  -D_GLIBXX_DEBUG_PEDANTIC was also needed. The problem has
107
  been fixed in GCC 4.0.1 and later versions.) 
108
 
109
The following library components provide extra debugging
110
  capabilities in debug mode:
111
112
  std::basic_string (no safe iterators and see note below)
113
  std::bitset
114
  std::deque
115
  std::list
116
  std::map
117
  std::multimap
118
  std::multiset
119
  std::set
120
  std::vector
121
  std::unordered_map
122
  std::unordered_multimap
123
  std::unordered_set
124
  std::unordered_multiset
125
126
 
127
N.B. although there are precondition checks for some string operations,
128
e.g.  operator[],
129
they will not always be run when using the char and
130
wchar_t specialisations (std::string and
131
std::wstring).  This is because libstdc++ uses GCC's
132
extern template extension to provide explicit instantiations
133
of std::string and std::wstring, and those
134
explicit instantiations don't include the debug-mode checks.  If the
135
containing functions are inlined then the checks will run, so compiling
136
with -O1 might be enough to enable them.  Alternatively
137
-D_GLIBCXX_EXTERN_TEMPLATE=0 will suppress the declarations
138
of the explicit instantiations and cause the functions to be instantiated
139
with the debug-mode checks included, but this is unsupported and not
140
guaranteed to work.  For full debug-mode support you can use the
141
__gnu_debug::basic_string debugging container directly,
142
which always works correctly.
143
144
 
145
146
 
147
Using
148
 
149
  
150
  
151
Using the Debug Mode
152
 
153
 
154
To use the libstdc++ debug mode, compile your application with the
155
  compiler flag -D_GLIBCXX_DEBUG. Note that this flag
156
  changes the sizes and behavior of standard class templates such
157
  as std::vector, and therefore you can only link code
158
  compiled with debug mode and code compiled without debug mode if no
159
  instantiation of a container is passed between the two translation
160
  units.
161
 
162
By default, error messages are formatted to fit on lines of about
163
  78 characters.  The environment variable
164
  GLIBCXX_DEBUG_MESSAGE_LENGTH can be used to request a
165
  different length.
166
 
167
168
 
169
Using a Specific Debug Container
170
 
171
When it is not feasible to recompile your entire application, or
172
  only specific containers need checking, debugging containers are
173
  available as GNU extensions. These debugging containers are
174
  functionally equivalent to the standard drop-in containers used in
175
  debug mode, but they are available in a separate namespace as GNU
176
  extensions and may be used in programs compiled with either release
177
  mode or with debug mode. The
178
  following table provides the names and headers of the debugging
179
  containers:
180
181
 
182
183
Debugging Containers
184
 
185
186
187
188
189
190
 
191
192
  
193
    Container
194
    Header
195
    Debug container
196
    Debug header
197
  
198
199
200
  
201
    std::bitset
202
    bitset
203
    __gnu_debug::bitset
204
    <debug/bitset>
205
  
206
  
207
    std::deque
208
    deque
209
    __gnu_debug::deque
210
    <debug/deque>
211
  
212
  
213
    std::list
214
    list
215
    __gnu_debug::list
216
    <debug/list>
217
  
218
  
219
    std::map
220
    map
221
    __gnu_debug::map
222
    <debug/map>
223
  
224
  
225
    std::multimap
226
    map
227
    __gnu_debug::multimap
228
    <debug/map>
229
  
230
  
231
    std::multiset
232
    set
233
    __gnu_debug::multiset
234
    <debug/set>
235
  
236
  
237
    std::set
238
    set
239
    __gnu_debug::set
240
    <debug/set>
241
  
242
  
243
    std::string
244
    string
245
    __gnu_debug::string
246
    <debug/string>
247
  
248
  
249
    std::wstring
250
    string
251
    __gnu_debug::wstring
252
    <debug/string>
253
  
254
  
255
    std::basic_string
256
    string
257
    __gnu_debug::basic_string
258
    <debug/string>
259
  
260
  
261
    std::vector
262
    vector
263
    __gnu_debug::vector
264
    <debug/vector>
265
  
266
267
268
269
 
270
In addition, when compiling in C++11 mode, these additional
271
containers have additional debug capability.
272
273
 
274
275
Debugging Containers C++11
276
 
277
278
279
280
281
282
 
283
284
  
285
    Container
286
    Header
287
    Debug container
288
    Debug header
289
  
290
291
292
    
293
    std::unordered_map
294
    unordered_map
295
    __gnu_debug::unordered_map
296
    <debug/unordered_map>
297
  
298
  
299
    std::unordered_multimap
300
    unordered_map
301
    __gnu_debug::unordered_multimap
302
    <debug/unordered_map>
303
  
304
  
305
    std::unordered_set
306
    unordered_set
307
    __gnu_debug::unordered_set
308
    <debug/unordered_set>
309
  
310
  
311
    std::unordered_multiset
312
    unordered_set
313
    __gnu_debug::unordered_multiset
314
    <debug/unordered_set>
315
  
316
317
318
319
320
321
 
322
Design
323
 
324
  
325
  
326
  
Goals
327
 
328
    
329
    
330
 The libstdc++ debug mode replaces unsafe (but efficient) standard
331
  containers and iterators with semantically equivalent safe standard
332
  containers and iterators to aid in debugging user programs. The
333
  following goals directed the design of the libstdc++ debug mode:
334
 
335
  
336
 
337
    Correctness: the libstdc++ debug mode must not change
338
    the semantics of the standard library for all cases specified in
339
    the ANSI/ISO C++ standard. The essence of this constraint is that
340
    any valid C++ program should behave in the same manner regardless
341
    of whether it is compiled with debug mode or release mode. In
342
    particular, entities that are defined in namespace std in release
343
    mode should remain defined in namespace std in debug mode, so that
344
    legal specializations of namespace std entities will remain
345
    valid. A program that is not valid C++ (e.g., invokes undefined
346
    behavior) is not required to behave similarly, although the debug
347
    mode will abort with a diagnostic when it detects undefined
348
    behavior.
349
 
350
    Performance: the additional of the libstdc++ debug mode
351
    must not affect the performance of the library when it is compiled
352
    in release mode. Performance of the libstdc++ debug mode is
353
    secondary (and, in fact, will be worse than the release
354
    mode).
355
 
356
    Usability: the libstdc++ debug mode should be easy to
357
    use. It should be easily incorporated into the user's development
358
    environment (e.g., by requiring only a single new compiler switch)
359
    and should produce reasonable diagnostics when it detects a
360
    problem with the user program. Usability also involves detection
361
    of errors when using the debug mode incorrectly, e.g., by linking
362
    a release-compiled object against a debug-compiled object if in
363
    fact the resulting program will not run correctly.
364
 
365
    Minimize recompilation: While it is expected that
366
    users recompile at least part of their program to use debug
367
    mode, the amount of recompilation affects the
368
    detect-compile-debug turnaround time. This indirectly affects the
369
    usefulness of the debug mode, because debugging some applications
370
    may require rebuilding a large amount of code, which may not be
371
    feasible when the suspect code may be very localized. There are
372
    several levels of conformance to this requirement, each with its
373
    own usability and implementation characteristics. In general, the
374
    higher-numbered conformance levels are more usable (i.e., require
375
    less recompilation) but are more complicated to implement than
376
    the lower-numbered conformance levels.
377
      
378
        Full recompilation: The user must recompile his or
379
        her entire application and all C++ libraries it depends on,
380
        including the C++ standard library that ships with the
381
        compiler. This must be done even if only a small part of the
382
        program can use debugging features.
383
 
384
        Full user recompilation: The user must recompile
385
        his or her entire application and all C++ libraries it depends
386
        on, but not the C++ standard library itself. This must be done
387
        even if only a small part of the program can use debugging
388
        features. This can be achieved given a full recompilation
389
        system by compiling two versions of the standard library when
390
        the compiler is installed and linking against the appropriate
391
        one, e.g., a multilibs approach.
392
 
393
        Partial recompilation: The user must recompile the
394
        parts of his or her application and the C++ libraries it
395
        depends on that will use the debugging facilities
396
        directly. This means that any code that uses the debuggable
397
        standard containers would need to be recompiled, but code
398
        that does not use them (but may, for instance, use IOStreams)
399
        would not have to be recompiled.
400
 
401
        Per-use recompilation: The user must recompile the
402
        parts of his or her application and the C++ libraries it
403
        depends on where debugging should occur, and any other code
404
        that interacts with those containers. This means that a set of
405
        translation units that accesses a particular standard
406
        container instance may either be compiled in release mode (no
407
        checking) or debug mode (full checking), but must all be
408
        compiled in the same way; a translation unit that does not see
409
        that standard container instance need not be recompiled. This
410
        also means that a translation unit A that contains a
411
        particular instantiation
412
        (say, std::vector<int>) compiled in release
413
        mode can be linked against a translation unit B that
414
        contains the same instantiation compiled in debug mode (a
415
        feature not present with partial recompilation). While this
416
        behavior is technically a violation of the One Definition
417
        Rule, this ability tends to be very important in
418
        practice. The libstdc++ debug mode supports this level of
419
        recompilation. 
420
 
421
        Per-unit recompilation: The user must only
422
        recompile the translation units where checking should occur,
423
        regardless of where debuggable standard containers are
424
        used. This has also been dubbed "-g mode",
425
        because the -g compiler switch works in this way,
426
        emitting debugging information at a per--translation-unit
427
        granularity. We believe that this level of recompilation is in
428
        fact not possible if we intend to supply safe iterators, leave
429
        the program semantics unchanged, and not regress in
430
        performance under release mode because we cannot associate
431
        extra information with an iterator (to form a safe iterator)
432
        without either reserving that space in release mode
433
        (performance regression) or allocating extra memory associated
434
        with each iterator with new (changes the program
435
        semantics).
436
      
437
    
438
  
439
  
440
 
441
  
Methods
442
 
443
    
444
    
445
This section provides an overall view of the design of the
446
  libstdc++ debug mode and details the relationship between design
447
  decisions and the stated design goals.
448
 
449
  
The Wrapper Model
450
 
451
The libstdc++ debug mode uses a wrapper model where the
452
  debugging versions of library components (e.g., iterators and
453
  containers) form a layer on top of the release versions of the
454
  library components. The debugging components first verify that the
455
  operation is correct (aborting with a diagnostic if an error is
456
  found) and will then forward to the underlying release-mode
457
  container that will perform the actual work. This design decision
458
  ensures that we cannot regress release-mode performance (because the
459
  release-mode containers are left untouched) and partially
460
  enables mixing debug and
461
  release code at link time, although that will not be
462
  discussed at this time.
463
 
464
Two types of wrappers are used in the implementation of the debug
465
  mode: container wrappers and iterator wrappers. The two types of
466
  wrappers interact to maintain relationships between iterators and
467
  their associated containers, which are necessary to detect certain
468
  types of standard library usage errors such as dereferencing
469
  past-the-end iterators or inserting into a container using an
470
  iterator from a different container.
471
 
472
  
Safe Iterators
473
 
474
Iterator wrappers provide a debugging layer over any iterator that
475
  is attached to a particular container, and will manage the
476
  information detailing the iterator's state (singular,
477
  dereferenceable, etc.) and tracking the container to which the
478
  iterator is attached. Because iterators have a well-defined, common
479
  interface the iterator wrapper is implemented with the iterator
480
  adaptor class template __gnu_debug::_Safe_iterator,
481
  which takes two template parameters:
482
 
483
484
  Iterator: The underlying iterator type, which must
485
    be either the iterator or const_iterator
486
    typedef from the sequence type this iterator can reference.
487
 
488
  Sequence: The type of sequence that this iterator
489
  references. This sequence must be a safe sequence (discussed below)
490
  whose iterator or const_iterator typedef
491
  is the type of the safe iterator.
492
493
  
494
 
495
  
Safe Sequences (Containers)
496
 
497
 
498
Container wrappers provide a debugging layer over a particular
499
  container type. Because containers vary greatly in the member
500
  functions they support and the semantics of those member functions
501
  (especially in the area of iterator invalidation), container
502
  wrappers are tailored to the container they reference, e.g., the
503
  debugging version of std::list duplicates the entire
504
  interface of std::list, adding additional semantic
505
  checks and then forwarding operations to the
506
  real std::list (a public base class of the debugging
507
  version) as appropriate. However, all safe containers inherit from
508
  the class template __gnu_debug::_Safe_sequence,
509
  instantiated with the type of the safe container itself (an instance
510
  of the curiously recurring template pattern).
511
 
512
The iterators of a container wrapper will be
513
  safe
514
  iterators that reference sequences of this type and wrap the
515
  iterators provided by the release-mode base class. The debugging
516
  container will use only the safe iterators within its own interface
517
  (therefore requiring the user to use safe iterators, although this
518
  does not change correct user code) and will communicate with the
519
  release-mode base class with only the underlying, unsafe,
520
  release-mode iterators that the base class exports.
521
 
522
 The debugging version of std::list will have the
523
  following basic structure:
524
 
525
526
template<typename _Tp, typename _Allocator = allocator<_Tp>
527
  class debug-list :
528
    public release-list<_Tp, _Allocator>,
529
    public __gnu_debug::_Safe_sequence<debug-list<_Tp, _Allocator> >
530
  {
531
    typedef release-list<_Tp, _Allocator> _Base;
532
    typedef debug-list<_Tp, _Allocator>   _Self;
533
 
534
  public:
535
    typedef __gnu_debug::_Safe_iterator<typename _Base::iterator, _Self>       iterator;
536
    typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator, _Self> const_iterator;
537
 
538
    // duplicate std::list interface with debugging semantics
539
  };
540
541
  
542
  
543
 
544
  
Precondition Checking
545
 
546
The debug mode operates primarily by checking the preconditions of
547
  all standard library operations that it supports. Preconditions that
548
  are always checked (regardless of whether or not we are in debug
549
  mode) are checked via the __check_xxx macros defined
550
  and documented in the source
551
  file include/debug/debug.h. Preconditions that may or
552
  may not be checked, depending on the debug-mode
553
  macro _GLIBCXX_DEBUG, are checked via
554
  the __requires_xxx macros defined and documented in the
555
  same source file. Preconditions are validated using any additional
556
  information available at run-time, e.g., the containers that are
557
  associated with a particular iterator, the position of the iterator
558
  within those containers, the distance between two iterators that may
559
  form a valid range, etc. In the absence of suitable information,
560
  e.g., an input iterator that is not a safe iterator, these
561
  precondition checks will silently succeed.
562
 
563
The majority of precondition checks use the aforementioned macros,
564
  which have the secondary benefit of having prewritten debug
565
  messages that use information about the current status of the
566
  objects involved (e.g., whether an iterator is singular or what
567
  sequence it is attached to) along with some static information
568
  (e.g., the names of the function parameters corresponding to the
569
  objects involved). When not using these macros, the debug mode uses
570
  either the debug-mode assertion
571
  macro _GLIBCXX_DEBUG_ASSERT , its pedantic
572
  cousin _GLIBCXX_DEBUG_PEDASSERT, or the assertion
573
  check macro that supports more advance formulation of error
574
  messages, _GLIBCXX_DEBUG_VERIFY. These macros are
575
  documented more thoroughly in the debug mode source code.
576
  
577
 
578
  
Release- and debug-mode coexistence
579
 
580
The libstdc++ debug mode is the first debug mode we know of that
581
  is able to provide the "Per-use recompilation" (4) guarantee, that
582
  allows release-compiled and debug-compiled code to be linked and
583
  executed together without causing unpredictable behavior. This
584
  guarantee minimizes the recompilation that users are required to
585
  perform, shortening the detect-compile-debug bug hunting cycle
586
  and making the debug mode easier to incorporate into development
587
  environments by minimizing dependencies.
588
 
589
Achieving link- and run-time coexistence is not a trivial
590
  implementation task. To achieve this goal we required a small
591
  extension to the GNU C++ compiler (since incorporated into the C++11 language specification, described in the GCC Manual for the C++ language as
592
  namespace
593
  association), and a complex organization of debug- and
594
  release-modes. The end result is that we have achieved per-use
595
  recompilation but have had to give up some checking of the
596
  std::basic_string class template (namely, safe
597
  iterators).
598
599
 
600
 
Compile-time coexistence of release- and debug-mode components
601
 
602
 
603
Both the release-mode components and the debug-mode
604
  components need to exist within a single translation unit so that
605
  the debug versions can wrap the release versions. However, only one
606
  of these components should be user-visible at any particular
607
  time with the standard name, e.g., std::list. 
608
 
609
In release mode, we define only the release-mode version of the
610
  component with its standard name and do not include the debugging
611
  component at all. The release mode version is defined within the
612
  namespace std. Minus the namespace associations, this
613
  method leaves the behavior of release mode completely unchanged from
614
  its behavior prior to the introduction of the libstdc++ debug
615
  mode. Here's an example of what this ends up looking like, in
616
  C++.
617
 
618
619
namespace std
620
{
621
  template<typename _Tp, typename _Alloc = allocator<_Tp> >
622
    class list
623
    {
624
      // ...
625
     };
626
} // namespace std
627
628
 
629
In debug mode we include the release-mode container (which is now
630
defined in the namespace __cxx1998) and also the
631
debug-mode container. The debug-mode container is defined within the
632
namespace __debug, which is associated with namespace
633
std via the C++11 namespace association language feature.  This
634
method allows the debug and release versions of the same component to
635
coexist at compile-time and link-time without causing an unreasonable
636
maintenance burden, while minimizing confusion. Again, this boils down
637
to C++ code as follows:
638
 
639
640
namespace std
641
{
642
  namespace __cxx1998
643
  {
644
    template<typename _Tp, typename _Alloc = allocator<_Tp> >
645
      class list
646
      {
647
        // ...
648
      };
649
  } // namespace __gnu_norm
650
 
651
  namespace __debug
652
  {
653
    template<typename _Tp, typename _Alloc = allocator<_Tp> >
654
      class list
655
      : public __cxx1998::list<_Tp, _Alloc>,
656
        public __gnu_debug::_Safe_sequence<list<_Tp, _Alloc> >
657
      {
658
        // ...
659
      };
660
  } // namespace __cxx1998
661
 
662
  // namespace __debug __attribute__ ((strong));
663
  inline namespace __debug { }
664
}
665
666
 
667
 
668
 
Link- and run-time coexistence of release- and</code></pre></td> </tr> <tr valign="middle"> <td>669</td> <td></td> <td></td> <td class="code"><pre><code> debug-mode components
670
 
671
 
672
Because each component has a distinct and separate release and
673
debug implementation, there is no issue with link-time
674
coexistence: the separate namespaces result in different mangled
675
names, and thus unique linkage.
676
 
677
However, components that are defined and used within the C++
678
standard library itself face additional constraints. For instance,
679
some of the member functions of  std::moneypunct return
680
std::basic_string. Normally, this is not a problem, but
681
with a mixed mode standard library that could be using either
682
debug-mode or release-mode  basic_string objects, things
683
get more complicated.  As the return value of a function is not
684
encoded into the mangled name, there is no way to specify a
685
release-mode or a debug-mode string. In practice, this results in
686
runtime errors. A simplified example of this problem is as follows.
687
688
 
689
 Take this translation unit, compiled in debug-mode: 
690
691
// -D_GLIBCXX_DEBUG
692
#include <string>
693
 
694
std::string test02();
695
 
696
std::string test01()
697
{
698
  return test02();
699
}
700
 
701
int main()
702
{
703
  test01();
704
  return 0;
705
}
706
707
 
708
 ... and linked to this translation unit, compiled in release mode:
709
 
710
711
#include <string>
712
 
713
std::string
714
test02()
715
{
716
  return std::string("toast");
717
}
718
719
 
720
 For this reason we cannot easily provide safe iterators for
721
  the std::basic_string class template, as it is present
722
  throughout the C++ standard library. For instance, locale facets
723
  define typedefs that include basic_string: in a mixed
724
  debug/release program, should that typedef be based on the
725
  debug-mode basic_string or the
726
  release-mode basic_string? While the answer could be
727
  "both", and the difference hidden via renaming a la the
728
  debug/release containers, we must note two things about locale
729
  facets:
730
 
731
732
  They exist as shared state: one can create a facet in one
733
  translation unit and access the facet via the same type name in a
734
  different translation unit. This means that we cannot have two
735
  different versions of locale facets, because the types would not be
736
  the same across debug/release-mode translation unit barriers.
737
 
738
  They have virtual functions returning strings: these functions
739
  mangle in the same way regardless of the mangling of their return
740
  types (see above), and their precise signatures can be relied upon
741
  by users because they may be overridden in derived classes.
742
743
 
744
With the design of libstdc++ debug mode, we cannot effectively hide
745
  the differences between debug and release-mode strings from the
746
  user. Failure to hide the differences may result in unpredictable
747
  behavior, and for this reason we have opted to only
748
  perform basic_string changes that do not require ABI
749
  changes. The effect on users is expected to be minimal, as there are
750
  simple alternatives (e.g., __gnu_debug::basic_string),
751
  and the usability benefit we gain from the ability to mix debug- and
752
  release-compiled translation units is enormous.
753
 
754
 
755
 
Alternatives for Coexistence
756
 
757
 
758
The coexistence scheme above was chosen over many alternatives,
759
  including language-only solutions and solutions that also required
760
  extensions to the C++ front end. The following is a partial list of
761
  solutions, with justifications for our rejection of each.
762
 
763
764
  Completely separate debug/release libraries: This is by
765
  far the simplest implementation option, where we do not allow any
766
  coexistence of debug- and release-compiled translation units in a
767
  program. This solution has an extreme negative affect on usability,
768
  because it is quite likely that some libraries an application
769
  depends on cannot be recompiled easily. This would not meet
770
  our usability or minimize recompilation criteria
771
  well.
772
 
773
  Add a Debug boolean template parameter:
774
  Partial specialization could be used to select the debug
775
  implementation when Debug == true, and the state
776
  of _GLIBCXX_DEBUG could decide whether the
777
  default Debug argument is true
778
  or false. This option would break conformance with the
779
  C++ standard in both debug and release modes. This would
780
  not meet our correctness criteria. 
781
 
782
  Packaging a debug flag in the allocators: We could
783
    reuse the Allocator template parameter of containers
784
    by adding a sentinel wrapper debug<> that
785
    signals the user's intention to use debugging, and pick up
786
    the debug<> allocator wrapper in a partial
787
    specialization. However, this has two drawbacks: first, there is a
788
    conformance issue because the default allocator would not be the
789
    standard-specified std::allocator<T>. Secondly
790
    (and more importantly), users that specify allocators instead of
791
    implicitly using the default allocator would not get debugging
792
    containers. Thus this solution fails the correctness
793
    criteria.
794
 
795
  Define debug containers in another namespace, and employ
796
      a using declaration (or directive): This is an
797
      enticing option, because it would eliminate the need for
798
      the link_name extension by aliasing the
799
      templates. However, there is no true template aliasing mechanism
800
      in C++, because both using directives and using
801
      declarations disallow specialization. This method fails
802
      the correctness criteria.
803
 
804
   Use implementation-specific properties of anonymous
805
    namespaces. 
806
    See  this post
807
    
808
    This method fails the correctness criteria.
809
 
810
  Extension: allow reopening on namespaces: This would
811
    allow the debug mode to effectively alias the
812
    namespace std to an internal namespace, such
813
    as __gnu_std_debug, so that it is completely
814
    separate from the release-mode std namespace. While
815
    this will solve some renaming problems and ensure that
816
    debug- and release-compiled code cannot be mixed unsafely, it ensures that
817
    debug- and release-compiled code cannot be mixed at all. For
818
    instance, the program would have two std::cout
819
    objects! This solution would fails the minimize
820
    recompilation requirement, because we would only be able to
821
    support option (1) or (2).
822
 
823
  Extension: use link name: This option involves
824
    complicated re-naming between debug-mode and release-mode
825
    components at compile time, and then a g++ extension called 
826
    link name  to recover the original names at link time. There
827
    are two drawbacks to this approach. One, it's very verbose,
828
    relying on macro renaming at compile time and several levels of
829
    include ordering. Two, ODR issues remained with container member
830
    functions taking no arguments in mixed-mode settings resulting in
831
    equivalent link names,  vector::push_back()  being
832
    one example.
833
    See link
834
    name 
835
836
 
837
Other options may exist for implementing the debug mode, many of
838
  which have probably been considered and others that may still be
839
  lurking. This list may be expanded over time to include other
840
  options that we could have implemented, but in all cases the full
841
  ramifications of the approach (as measured against the design goals
842
  for a libstdc++ debug mode) should be considered first. The DejaGNU
843
  testsuite includes some testcases that check for known problems with
844
  some solutions (e.g., the using declaration solution
845
  that breaks user specialization), and additional testcases will be
846
  added as we are able to identify other typical problem cases. These
847
  test cases will serve as a benchmark by which we can compare debug
848
  mode implementations.
849
 
850
  
851
  
852
 
853
  
Other Implementations
854
 
855
    
856
    
857
 There are several existing implementations of debug modes for C++
858
  standard library implementations, although none of them directly
859
  supports debugging for programs using libstdc++. The existing
860
  implementations include:
861
862
  SafeSTL:
863
  SafeSTL was the original debugging version of the Standard Template
864
  Library (STL), implemented by Cay S. Horstmann on top of the
865
  Hewlett-Packard STL. Though it inspired much work in this area, it
866
  has not been kept up-to-date for use with modern compilers or C++
867
  standard library implementations.
868
 
869
  STLport: STLport is a free
870
  implementation of the C++ standard library derived from the SGI implementation, and
871
  ported to many other platforms. It includes a debug mode that uses a
872
  wrapper model (that in some ways inspired the libstdc++ debug mode
873
  design), although at the time of this writing the debug mode is
874
  somewhat incomplete and meets only the "Full user recompilation" (2)
875
  recompilation guarantee by requiring the user to link against a
876
  different library in debug mode vs. release mode.
877
 
878
  Metrowerks CodeWarrior: The C++ standard library
879
  that ships with Metrowerks CodeWarrior includes a debug mode. It is
880
  a full debug-mode implementation (including debugging for
881
  CodeWarrior extensions) and is easy to use, although it meets only
882
  the "Full recompilation" (1) recompilation
883
  guarantee.
884
885
 
886
  
887
888
 
889

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.