| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file defines dynamic annotations for use with dynamic analysis | 5 // This file defines dynamic annotations for use with dynamic analysis |
| 6 // tool such as valgrind, PIN, etc. | 6 // tool such as valgrind, PIN, etc. |
| 7 // | 7 // |
| 8 // Dynamic annotation is a source code annotation that affects | 8 // Dynamic annotation is a source code annotation that affects |
| 9 // the generated code (that is, the annotation is not a comment). | 9 // the generated code (that is, the annotation is not a comment). |
| 10 // Each such annotation is attached to a particular | 10 // Each such annotation is attached to a particular |
| 11 // instruction and/or to a particular object (address) in the program. | 11 // instruction and/or to a particular object (address) in the program. |
| 12 // | 12 // |
| 13 // The annotations that should be used by users are macros in all upper-case | 13 // The annotations that should be used by users are macros in all upper-case |
| 14 // (e.g., ANNOTATE_NEW_MEMORY). | 14 // (e.g., ANNOTATE_NEW_MEMORY). |
| 15 // | 15 // |
| 16 // Actual implementation of these macros may differ depending on the | 16 // Actual implementation of these macros may differ depending on the |
| 17 // dynamic analysis tool being used. | 17 // dynamic analysis tool being used. |
| 18 // | 18 // |
| 19 // This file supports the following dynamic analysis tools: | 19 // This file supports the following dynamic analysis tools: |
| 20 // - None (NDEBUG is defined). | 20 // - None (NVALGRIND is defined). |
| 21 // Macros are defined empty. | 21 // Macros are defined empty. |
| 22 // - ThreadSanitizer (NDEBUG is not defined). | 22 // - ThreadSanitizer (NVALGRIND is not defined). |
| 23 // Macros are defined as calls to non-inlinable empty functions | 23 // Macros are defined as calls to non-inlinable empty functions |
| 24 // that are intercepted by ThreadSanitizer. | 24 // that are intercepted by ThreadSanitizer. |
| 25 // | 25 // |
| 26 #ifndef BASE_DYNAMIC_ANNOTATIONS_H_ | 26 #ifndef BASE_DYNAMIC_ANNOTATIONS_H_ |
| 27 #define BASE_DYNAMIC_ANNOTATIONS_H_ | 27 #define BASE_DYNAMIC_ANNOTATIONS_H_ |
| 28 | 28 |
| 29 // All the annotation macros are in effect only in debug mode. | 29 #include "base/third_party/valgrind/valgrind.h" |
| 30 #ifndef NDEBUG | |
| 31 // Debug build. | |
| 32 | 30 |
| 31 #ifndef NVALGRIND |
| 33 // ------------------------------------------------------------- | 32 // ------------------------------------------------------------- |
| 34 // Annotations useful when implementing condition variables such as CondVar, | 33 // Annotations useful when implementing condition variables such as CondVar, |
| 35 // using conditional critical sections (Await/LockWhen) and when constructing | 34 // using conditional critical sections (Await/LockWhen) and when constructing |
| 36 // user-defined synchronization mechanisms. | 35 // user-defined synchronization mechanisms. |
| 37 // | 36 // |
| 38 // The annotations ANNOTATE_HAPPENS_BEFORE() and ANNOTATE_HAPPENS_AFTER() can | 37 // The annotations ANNOTATE_HAPPENS_BEFORE() and ANNOTATE_HAPPENS_AFTER() can |
| 39 // be used to define happens-before arcs in user-defined synchronization | 38 // be used to define happens-before arcs in user-defined synchronization |
| 40 // mechanisms: the race detector will infer an arc from the former to the | 39 // mechanisms: the race detector will infer an arc from the former to the |
| 41 // latter when they share the same argument pointer. | 40 // latter when they share the same argument pointer. |
| 42 // | 41 // |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 class static_var ## _annotator { \ | 301 class static_var ## _annotator { \ |
| 303 public: \ | 302 public: \ |
| 304 static_var ## _annotator() { \ | 303 static_var ## _annotator() { \ |
| 305 ANNOTATE_BENIGN_RACE(&static_var, \ | 304 ANNOTATE_BENIGN_RACE(&static_var, \ |
| 306 # static_var ": " description); \ | 305 # static_var ": " description); \ |
| 307 } \ | 306 } \ |
| 308 }; \ | 307 }; \ |
| 309 static static_var ## _annotator the ## static_var ## _annotator;\ | 308 static static_var ## _annotator the ## static_var ## _annotator;\ |
| 310 } | 309 } |
| 311 | 310 |
| 312 #else // NDEBUG is defined | 311 #else |
| 313 // Release build, empty macros. | 312 // NVALGRIND is defined, empty macros. |
| 314 | 313 |
| 315 #define ANNOTATE_RWLOCK_CREATE(lock) // empty | 314 #define ANNOTATE_RWLOCK_CREATE(lock) // empty |
| 316 #define ANNOTATE_RWLOCK_DESTROY(lock) // empty | 315 #define ANNOTATE_RWLOCK_DESTROY(lock) // empty |
| 317 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) // empty | 316 #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) // empty |
| 318 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) // empty | 317 #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) // empty |
| 319 #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) // empty | 318 #define ANNOTATE_CONDVAR_LOCK_WAIT(cv, lock) // empty |
| 320 #define ANNOTATE_CONDVAR_WAIT(cv) // empty | 319 #define ANNOTATE_CONDVAR_WAIT(cv) // empty |
| 321 #define ANNOTATE_CONDVAR_SIGNAL(cv) // empty | 320 #define ANNOTATE_CONDVAR_SIGNAL(cv) // empty |
| 322 #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) // empty | 321 #define ANNOTATE_CONDVAR_SIGNAL_ALL(cv) // empty |
| 323 #define ANNOTATE_HAPPENS_BEFORE(obj) // empty | 322 #define ANNOTATE_HAPPENS_BEFORE(obj) // empty |
| (...skipping 13 matching lines...) Expand all Loading... |
| 337 #define ANNOTATE_IGNORE_READS_BEGIN() // empty | 336 #define ANNOTATE_IGNORE_READS_BEGIN() // empty |
| 338 #define ANNOTATE_IGNORE_READS_END() // empty | 337 #define ANNOTATE_IGNORE_READS_END() // empty |
| 339 #define ANNOTATE_IGNORE_WRITES_BEGIN() // empty | 338 #define ANNOTATE_IGNORE_WRITES_BEGIN() // empty |
| 340 #define ANNOTATE_IGNORE_WRITES_END() // empty | 339 #define ANNOTATE_IGNORE_WRITES_END() // empty |
| 341 #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() // empty | 340 #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() // empty |
| 342 #define ANNOTATE_IGNORE_READS_AND_WRITES_END() // empty | 341 #define ANNOTATE_IGNORE_READS_AND_WRITES_END() // empty |
| 343 #define ANNOTATE_NO_OP(arg) // empty | 342 #define ANNOTATE_NO_OP(arg) // empty |
| 344 #define ANNOTATE_UNPROTECTED_READ(x) (x) | 343 #define ANNOTATE_UNPROTECTED_READ(x) (x) |
| 345 #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) // empty | 344 #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) // empty |
| 346 | 345 |
| 347 #endif // NDEBUG | 346 #endif // NVALGRIND |
| 348 | 347 |
| 349 // Return non-zero value if running under valgrind. | 348 // Return non-zero value if running under valgrind. |
| 350 extern "C" int RunningOnValgrind(); | 349 extern "C" int RunningOnValgrind(); |
| 351 | 350 |
| 352 #endif // BASE_DYNAMIC_ANNOTATIONS_H_ | 351 #endif // BASE_DYNAMIC_ANNOTATIONS_H_ |
| OLD | NEW |