1*3ac0a46fSAndroid Build Coastguard Worker // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file. 4*3ac0a46fSAndroid Build Coastguard Worker 5*3ac0a46fSAndroid Build Coastguard Worker #ifndef THIRD_PARTY_BASE_DEBUG_ALIAS_H_ 6*3ac0a46fSAndroid Build Coastguard Worker #define THIRD_PARTY_BASE_DEBUG_ALIAS_H_ 7*3ac0a46fSAndroid Build Coastguard Worker 8*3ac0a46fSAndroid Build Coastguard Worker namespace pdfium { 9*3ac0a46fSAndroid Build Coastguard Worker namespace base { 10*3ac0a46fSAndroid Build Coastguard Worker namespace debug { 11*3ac0a46fSAndroid Build Coastguard Worker 12*3ac0a46fSAndroid Build Coastguard Worker // Make the optimizer think that var is aliased. This is to prevent it from 13*3ac0a46fSAndroid Build Coastguard Worker // optimizing out local variables that would not otherwise be live at the point 14*3ac0a46fSAndroid Build Coastguard Worker // of a potential crash. 15*3ac0a46fSAndroid Build Coastguard Worker // base::debug::Alias should only be used for local variables, not globals, 16*3ac0a46fSAndroid Build Coastguard Worker // object members, or function return values - these must be copied to locals if 17*3ac0a46fSAndroid Build Coastguard Worker // you want to ensure they are recorded in crash dumps. 18*3ac0a46fSAndroid Build Coastguard Worker // Note that if the local variable is a pointer then its value will be retained 19*3ac0a46fSAndroid Build Coastguard Worker // but the memory that it points to will probably not be saved in the crash 20*3ac0a46fSAndroid Build Coastguard Worker // dump - by default only stack memory is saved. Therefore the aliasing 21*3ac0a46fSAndroid Build Coastguard Worker // technique is usually only worthwhile with non-pointer variables. If you have 22*3ac0a46fSAndroid Build Coastguard Worker // a pointer to an object and you want to retain the object's state you need to 23*3ac0a46fSAndroid Build Coastguard Worker // copy the object or its fields to local variables. Example usage: 24*3ac0a46fSAndroid Build Coastguard Worker // int last_error = err_; 25*3ac0a46fSAndroid Build Coastguard Worker // base::debug::Alias(&last_error); 26*3ac0a46fSAndroid Build Coastguard Worker // DEBUG_ALIAS_FOR_CSTR(name_copy, p->name, 16); 27*3ac0a46fSAndroid Build Coastguard Worker // CHECK(false); 28*3ac0a46fSAndroid Build Coastguard Worker void Alias(const void* var); 29*3ac0a46fSAndroid Build Coastguard Worker 30*3ac0a46fSAndroid Build Coastguard Worker } // namespace debug 31*3ac0a46fSAndroid Build Coastguard Worker } // namespace base 32*3ac0a46fSAndroid Build Coastguard Worker } // namespace pdfium 33*3ac0a46fSAndroid Build Coastguard Worker 34*3ac0a46fSAndroid Build Coastguard Worker #endif // THIRD_PARTY_BASE_DEBUG_ALIAS_H_ 35