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