├── .bazelci └── presubmit.yml ├── .clang-format ├── .clang-tidy ├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ ├── android.yml │ ├── cifuzz.yml │ ├── emscripten.yml │ ├── linux.yml │ ├── macos.yml │ └── windows.yml ├── .gitignore ├── AUTHORS ├── BUILD.bazel ├── CMakeLists.txt ├── CONTRIBUTORS ├── ChangeLog ├── LICENSE.md ├── MODULE.bazel ├── README.rst ├── WORKSPACE.bazel ├── bazel ├── example │ ├── BUILD.bazel │ └── main.cc └── glog.bzl ├── cmake ├── DetermineGflagsNamespace.cmake ├── FindUnwind.cmake ├── GetCacheVariables.cmake ├── RunCleanerTest1.cmake ├── RunCleanerTest2.cmake ├── RunCleanerTest3.cmake ├── TestInitPackageConfig.cmake └── TestPackageConfig.cmake ├── codecov.yml ├── docs ├── build.md ├── contribute.md ├── failures.md ├── flags.md ├── index.md ├── license.md ├── log_cleaner.md ├── log_stripping.md ├── logging.md ├── overrides │ └── main.html ├── packages.md ├── requirements.txt ├── sinks.md ├── unwinder.md ├── usage.md └── windows.md ├── examples └── custom_sink.cc ├── gcovr.cfg ├── glog-config.cmake.in ├── glog-modules.cmake.in ├── libglog.pc.in ├── mkdocs.yml └── src ├── base ├── commandlineflags.h └── googleinit.h ├── cleanup_immediately_unittest.cc ├── cleanup_with_absolute_prefix_unittest.cc ├── cleanup_with_relative_prefix_unittest.cc ├── config.h.cmake.in ├── dcheck_unittest ├── CMakeLists.txt └── glog_dcheck.cc ├── demangle.cc ├── demangle.h ├── demangle_unittest.cc ├── demangle_unittest.sh ├── demangle_unittest.txt ├── flags.cc ├── fuzz_demangle.cc ├── glog ├── flags.h ├── log_severity.h ├── logging.h ├── platform.h ├── raw_logging.h ├── stl_logging.h ├── types.h └── vlog_is_on.h ├── googletest.h ├── includes_unittest ├── CMakeLists.txt ├── glog_includes_logging.cc ├── glog_includes_raw_logging.cc ├── glog_includes_stl_logging.cc └── glog_includes_vlog_is_on.cc ├── log_severity_unittest ├── CMakeLists.txt ├── glog_log_severity_constants.cc └── glog_log_severity_conversion.cc ├── logging.cc ├── logging_striplog_test.sh ├── logging_unittest.cc ├── logging_unittest.err ├── logging_unittest.out ├── mock-log.h ├── mock-log_unittest.cc ├── package_config_unittest └── working_config │ ├── CMakeLists.txt │ └── glog_package_config.cc ├── raw_logging.cc ├── signalhandler.cc ├── signalhandler_unittest.cc ├── signalhandler_unittest.sh ├── stacktrace.cc ├── stacktrace.h ├── stacktrace_generic-inl.h ├── stacktrace_libunwind-inl.h ├── stacktrace_powerpc-inl.h ├── stacktrace_unittest.cc ├── stacktrace_unwind-inl.h ├── stacktrace_windows-inl.h ├── stacktrace_x86-inl.h ├── stl_logging_unittest.cc ├── striplog_unittest.cc ├── symbolize.cc ├── symbolize.h ├── symbolize_unittest.cc ├── utilities.cc ├── utilities.h ├── utilities_unittest.cc ├── vlog_is_on.cc └── windows ├── dirent.h ├── port.cc └── port.h /.bazelci/presubmit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tasks: 3 | ubuntu1804: 4 | name: "Ubuntu 22.04" 5 | platform: ubuntu2204 6 | build_flags: 7 | - "--features=layering_check" 8 | - "--copt=-Werror" 9 | build_targets: 10 | - "//..." 11 | test_flags: 12 | - "--features=layering_check" 13 | - "--copt=-Werror" 14 | test_targets: 15 | - "//..." 16 | macos: 17 | name: "macOS: latest Xcode" 18 | platform: macos 19 | build_flags: 20 | - "--features=layering_check" 21 | - "--copt=-Werror" 22 | build_targets: 23 | - "//..." 24 | test_flags: 25 | - "--features=layering_check" 26 | - "--copt=-Werror" 27 | test_targets: 28 | - "//..." 29 | windows-msvc: 30 | name: "Windows: MSVC 2017" 31 | platform: windows 32 | environment: 33 | BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC" 34 | build_flags: 35 | - "--features=layering_check" 36 | - "--copt=/WX" 37 | build_targets: 38 | - "//..." 39 | test_flags: 40 | - "--features=layering_check" 41 | - "--copt=/WX" 42 | test_targets: 43 | - "//..." 44 | windows-clang-cl: 45 | name: "Windows: Clang" 46 | platform: windows 47 | environment: 48 | BAZEL_VC: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC" 49 | build_flags: 50 | - "--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl" 51 | - "--extra_execution_platforms=//:x64_windows-clang-cl" 52 | - "--compiler=clang-cl" 53 | - "--features=layering_check" 54 | build_targets: 55 | - "//..." 56 | test_flags: 57 | - "--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl" 58 | - "--extra_execution_platforms=//:x64_windows-clang-cl" 59 | - "--compiler=clang-cl" 60 | - "--features=layering_check" 61 | test_targets: 62 | - "//..." 63 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: Google 4 | AccessModifierOffset: -1 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveMacros: false 7 | AlignConsecutiveAssignments: false 8 | AlignConsecutiveDeclarations: false 9 | AlignEscapedNewlines: Left 10 | AlignOperands: true 11 | AlignTrailingComments: true 12 | AllowAllArgumentsOnNextLine: true 13 | AllowAllConstructorInitializersOnNextLine: true 14 | AllowAllParametersOfDeclarationOnNextLine: true 15 | AllowShortBlocksOnASingleLine: Never 16 | AllowShortCaseLabelsOnASingleLine: false 17 | AllowShortFunctionsOnASingleLine: All 18 | AllowShortLambdasOnASingleLine: All 19 | AllowShortIfStatementsOnASingleLine: WithoutElse 20 | AllowShortLoopsOnASingleLine: true 21 | AlwaysBreakAfterDefinitionReturnType: None 22 | AlwaysBreakAfterReturnType: None 23 | AlwaysBreakBeforeMultilineStrings: true 24 | AlwaysBreakTemplateDeclarations: Yes 25 | BinPackArguments: true 26 | BinPackParameters: true 27 | BraceWrapping: 28 | AfterCaseLabel: false 29 | AfterClass: false 30 | AfterControlStatement: false 31 | AfterEnum: false 32 | AfterFunction: false 33 | AfterNamespace: false 34 | AfterObjCDeclaration: false 35 | AfterStruct: false 36 | AfterUnion: false 37 | AfterExternBlock: false 38 | BeforeCatch: false 39 | BeforeElse: false 40 | IndentBraces: false 41 | SplitEmptyFunction: true 42 | SplitEmptyRecord: true 43 | SplitEmptyNamespace: true 44 | BreakBeforeBinaryOperators: None 45 | BreakBeforeBraces: Attach 46 | BreakBeforeInheritanceComma: false 47 | BreakInheritanceList: BeforeColon 48 | BreakBeforeTernaryOperators: true 49 | BreakConstructorInitializersBeforeComma: false 50 | BreakConstructorInitializers: BeforeColon 51 | BreakAfterJavaFieldAnnotations: false 52 | BreakStringLiterals: true 53 | ColumnLimit: 80 54 | CommentPragmas: '^ IWYU pragma:' 55 | CompactNamespaces: false 56 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 57 | ConstructorInitializerIndentWidth: 4 58 | ContinuationIndentWidth: 4 59 | Cpp11BracedListStyle: true 60 | DeriveLineEnding: true 61 | DerivePointerAlignment: false 62 | DisableFormat: false 63 | ExperimentalAutoDetectBinPacking: false 64 | FixNamespaceComments: true 65 | ForEachMacros: 66 | - foreach 67 | - Q_FOREACH 68 | - BOOST_FOREACH 69 | IncludeBlocks: Regroup 70 | IncludeCategories: 71 | - Regex: '^' 72 | Priority: 2 73 | SortPriority: 0 74 | - Regex: '^<.*\.h>' 75 | Priority: 1 76 | SortPriority: 0 77 | - Regex: '^<.*' 78 | Priority: 2 79 | SortPriority: 0 80 | - Regex: '.*' 81 | Priority: 3 82 | SortPriority: 0 83 | IncludeIsMainRegex: '([-_](test|unittest))?$' 84 | IncludeIsMainSourceRegex: '' 85 | IndentCaseLabels: true 86 | IndentGotoLabels: true 87 | IndentPPDirectives: AfterHash 88 | IndentWidth: 2 89 | IndentWrappedFunctionNames: false 90 | JavaScriptQuotes: Leave 91 | JavaScriptWrapImports: true 92 | KeepEmptyLinesAtTheStartOfBlocks: false 93 | MacroBlockBegin: '' 94 | MacroBlockEnd: '' 95 | MaxEmptyLinesToKeep: 1 96 | NamespaceIndentation: None 97 | ObjCBinPackProtocolList: Never 98 | ObjCBlockIndentWidth: 2 99 | ObjCSpaceAfterProperty: false 100 | ObjCSpaceBeforeProtocolList: true 101 | PenaltyBreakAssignment: 2 102 | PenaltyBreakBeforeFirstCallParameter: 1 103 | PenaltyBreakComment: 300 104 | PenaltyBreakFirstLessLess: 120 105 | PenaltyBreakString: 1000 106 | PenaltyBreakTemplateDeclaration: 10 107 | PenaltyExcessCharacter: 1000000 108 | PenaltyReturnTypeOnItsOwnLine: 200 109 | PointerAlignment: Left 110 | RawStringFormats: 111 | - Language: Cpp 112 | Delimiters: 113 | - cc 114 | - CC 115 | - cpp 116 | - Cpp 117 | - CPP 118 | - 'c++' 119 | - 'C++' 120 | CanonicalDelimiter: '' 121 | BasedOnStyle: google 122 | - Language: TextProto 123 | Delimiters: 124 | - pb 125 | - PB 126 | - proto 127 | - PROTO 128 | EnclosingFunctions: 129 | - EqualsProto 130 | - EquivToProto 131 | - PARSE_PARTIAL_TEXT_PROTO 132 | - PARSE_TEST_PROTO 133 | - PARSE_TEXT_PROTO 134 | - ParseTextOrDie 135 | - ParseTextProtoOrDie 136 | CanonicalDelimiter: '' 137 | BasedOnStyle: google 138 | ReflowComments: true 139 | SortIncludes: true 140 | SortUsingDeclarations: true 141 | SpaceAfterCStyleCast: false 142 | SpaceAfterLogicalNot: false 143 | SpaceAfterTemplateKeyword: true 144 | SpaceBeforeAssignmentOperators: true 145 | SpaceBeforeCpp11BracedList: false 146 | SpaceBeforeCtorInitializerColon: true 147 | SpaceBeforeInheritanceColon: true 148 | SpaceBeforeParens: ControlStatements 149 | SpaceBeforeRangeBasedForLoopColon: true 150 | SpaceInEmptyBlock: false 151 | SpaceInEmptyParentheses: false 152 | SpacesBeforeTrailingComments: 2 153 | SpacesInAngles: false 154 | SpacesInConditionalStatement: false 155 | SpacesInContainerLiterals: true 156 | SpacesInCStyleCastParentheses: false 157 | SpacesInParentheses: false 158 | SpacesInSquareBrackets: false 159 | SpaceBeforeSquareBrackets: false 160 | Standard: c++14 161 | StatementMacros: 162 | - Q_UNUSED 163 | - QT_REQUIRE_VERSION 164 | TabWidth: 8 165 | UseCRLF: false 166 | UseTab: Never 167 | ... 168 | 169 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: 'clang-diagnostic-*,clang-analyzer-*,google-*,modernize-*,-modernize-use-trailing-return-type,readability-*,portability-*,performance-*,bugprone-*,android-*,darwin-*,clang-analyzer-*' 3 | WarningsAsErrors: '' 4 | HeaderFilterRegex: '' 5 | FormatStyle: file 6 | CheckOptions: 7 | - key: cert-dcl16-c.NewSuffixes 8 | value: 'L;LL;LU;LLU' 9 | - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField 10 | value: '0' 11 | - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors 12 | value: '1' 13 | - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic 14 | value: '1' 15 | - key: google-build-namespaces.HeaderFileExtensions 16 | value: ',h,hh,hpp,hxx' 17 | - key: google-global-names-in-headers.HeaderFileExtensions 18 | value: ',h,hh,hpp,hxx' 19 | - key: google-readability-braces-around-statements.ShortStatementLines 20 | value: '1' 21 | - key: google-readability-function-size.BranchThreshold 22 | value: '4294967295' 23 | - key: google-readability-function-size.LineThreshold 24 | value: '4294967295' 25 | - key: google-readability-function-size.NestingThreshold 26 | value: '4294967295' 27 | - key: google-readability-function-size.ParameterThreshold 28 | value: '4294967295' 29 | - key: google-readability-function-size.StatementThreshold 30 | value: '800' 31 | - key: google-readability-function-size.VariableThreshold 32 | value: '4294967295' 33 | - key: google-readability-namespace-comments.ShortNamespaceLines 34 | value: '10' 35 | - key: google-readability-namespace-comments.SpacesBeforeComments 36 | value: '2' 37 | - key: google-runtime-int.SignedTypePrefix 38 | value: int 39 | - key: google-runtime-int.TypeSuffix 40 | value: '' 41 | - key: google-runtime-int.UnsignedTypePrefix 42 | value: uint 43 | - key: google-runtime-references.WhiteListTypes 44 | value: '' 45 | - key: modernize-loop-convert.MaxCopySize 46 | value: '16' 47 | - key: modernize-loop-convert.MinConfidence 48 | value: reasonable 49 | - key: modernize-loop-convert.NamingStyle 50 | value: CamelCase 51 | - key: modernize-pass-by-value.IncludeStyle 52 | value: llvm 53 | - key: modernize-replace-auto-ptr.IncludeStyle 54 | value: llvm 55 | - key: modernize-use-nullptr.NullMacros 56 | value: 'NULL' 57 | ... 58 | 59 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.h linguist-language=C++ 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Set update schedule for GitHub Actions 2 | 3 | version: 2 4 | updates: 5 | 6 | - package-ecosystem: "github-actions" 7 | directory: "/" 8 | schedule: 9 | # Check for updates to GitHub Actions every week 10 | interval: "weekly" 11 | -------------------------------------------------------------------------------- /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build-android: 7 | name: NDK-C++${{matrix.std}}-${{matrix.abi}}-${{matrix.build_type}} 8 | runs-on: ubuntu-22.04 9 | permissions: 10 | actions: read 11 | contents: read 12 | security-events: write 13 | defaults: 14 | run: 15 | shell: bash 16 | env: 17 | NDK_VERSION: 26.0.10792818 18 | strategy: 19 | fail-fast: true 20 | matrix: 21 | std: [14, 17, 20] 22 | abi: [arm64-v8a, armeabi-v7a, x86_64, x86] 23 | build_type: [Debug, Release] 24 | 25 | steps: 26 | - uses: actions/checkout@v4 27 | 28 | - name: Initialize CodeQL 29 | uses: github/codeql-action/init@v3 30 | with: 31 | languages: cpp 32 | 33 | - name: Setup Dependencies 34 | run: | 35 | sudo apt-get update 36 | DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \ 37 | cmake \ 38 | ninja-build 39 | 40 | - name: Setup NDK 41 | env: 42 | ANDROID_SDK_ROOT: /usr/local/lib/android/sdk 43 | run: | 44 | echo 'y' | ${{env.ANDROID_SDK_ROOT}}/cmdline-tools/latest/bin/sdkmanager --install 'ndk;${{env.NDK_VERSION}}' 45 | 46 | - name: Configure 47 | env: 48 | CXXFLAGS: -Wall -Wextra -Wpedantic -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}} 49 | run: | 50 | cmake -S . -B build_${{matrix.abi}} \ 51 | -DCMAKE_ANDROID_API=28 \ 52 | -DCMAKE_ANDROID_ARCH_ABI=${{matrix.abi}} \ 53 | -DCMAKE_ANDROID_NDK=/usr/local/lib/android/sdk/ndk/${{env.NDK_VERSION}} \ 54 | -DCMAKE_ANDROID_STL_TYPE=c++_shared \ 55 | -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ 56 | -DCMAKE_CXX_EXTENSIONS=OFF \ 57 | -DCMAKE_CXX_STANDARD=${{matrix.std}} \ 58 | -DCMAKE_CXX_STANDARD_REQUIRED=ON \ 59 | -DCMAKE_SYSTEM_NAME=Android \ 60 | -G Ninja \ 61 | -Werror 62 | 63 | - name: Build 64 | run: | 65 | cmake --build build_${{matrix.abi}} \ 66 | --config ${{matrix.build_type}} 67 | 68 | - name: Perform CodeQL Analysis 69 | uses: github/codeql-action/analyze@v3 70 | -------------------------------------------------------------------------------- /.github/workflows/cifuzz.yml: -------------------------------------------------------------------------------- 1 | name: CIFuzz 2 | on: [pull_request] 3 | jobs: 4 | Fuzzing: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Build Fuzzers 8 | id: build 9 | uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master 10 | with: 11 | oss-fuzz-project-name: 'glog' 12 | dry-run: false 13 | language: c++ 14 | - name: Run Fuzzers 15 | uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master 16 | with: 17 | oss-fuzz-project-name: 'glog' 18 | fuzz-seconds: 60 19 | dry-run: false 20 | language: c++ 21 | - name: Upload Crash 22 | uses: actions/upload-artifact@v4 23 | if: failure() && steps.build.outcome == 'success' 24 | with: 25 | name: artifacts 26 | path: ./out/artifacts 27 | -------------------------------------------------------------------------------- /.github/workflows/emscripten.yml: -------------------------------------------------------------------------------- 1 | name: Emscripten 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build-linux: 7 | defaults: 8 | run: 9 | shell: bash 10 | name: Emscripten-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}} 11 | runs-on: ubuntu-22.04 12 | permissions: 13 | actions: read 14 | contents: read 15 | security-events: write 16 | container: emscripten/emsdk 17 | strategy: 18 | fail-fast: true 19 | matrix: 20 | build_type: [Release, Debug] 21 | lib: [static] 22 | std: [14, 17, 20, 23] 23 | 24 | steps: 25 | - uses: actions/checkout@v4 26 | 27 | - name: Initialize CodeQL 28 | uses: github/codeql-action/init@v3 29 | with: 30 | languages: cpp 31 | 32 | - name: Setup Dependencies 33 | run: | 34 | sudo apt-get update 35 | DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \ 36 | cmake \ 37 | ninja-build 38 | 39 | - name: Configure 40 | env: 41 | CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror -Wno-error=wasm-exception-spec ${{env.CXXFLAGS}} 42 | run: | 43 | emcmake cmake -S . -B build_${{matrix.build_type}} \ 44 | -DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} \ 45 | -DCMAKE_CXX_STANDARD=${{matrix.std}} \ 46 | -DCMAKE_CXX_STANDARD_REQUIRED=ON \ 47 | -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \ 48 | -G Ninja \ 49 | -Werror 50 | 51 | - name: Build 52 | run: | 53 | cmake --build build_${{matrix.build_type}} \ 54 | --config ${{matrix.build_type}} 55 | 56 | - name: Perform CodeQL Analysis 57 | uses: github/codeql-action/analyze@v3 58 | -------------------------------------------------------------------------------- /.github/workflows/linux.yml: -------------------------------------------------------------------------------- 1 | name: Linux 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build-linux: 7 | defaults: 8 | run: 9 | shell: bash 10 | name: GCC-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}} 11 | runs-on: ubuntu-22.04 12 | permissions: 13 | actions: read 14 | contents: read 15 | security-events: write 16 | strategy: 17 | fail-fast: true 18 | matrix: 19 | build_type: [Release, Debug] 20 | lib: [shared, static] 21 | std: [14, 17, 20, 23] 22 | 23 | steps: 24 | - uses: actions/checkout@v4 25 | 26 | - name: Initialize CodeQL 27 | uses: github/codeql-action/init@v3 28 | with: 29 | languages: cpp 30 | 31 | - name: Setup Dependencies 32 | run: | 33 | sudo apt-get update 34 | DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-suggests --no-install-recommends \ 35 | g++ \ 36 | cmake \ 37 | gcovr \ 38 | libgflags-dev \ 39 | libgmock-dev \ 40 | libgtest-dev \ 41 | libunwind-dev \ 42 | ninja-build 43 | 44 | - name: Setup Environment 45 | if: matrix.build_type == 'Debug' 46 | run: | 47 | echo 'CXXFLAGS=--coverage' >> $GITHUB_ENV 48 | 49 | - name: Configure 50 | env: 51 | CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror ${{env.CXXFLAGS}} 52 | run: | 53 | cmake -S . -B build_${{matrix.build_type}} \ 54 | -DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} \ 55 | -DCMAKE_CXX_STANDARD=${{matrix.std}} \ 56 | -DCMAKE_CXX_STANDARD_REQUIRED=ON \ 57 | -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \ 58 | -G Ninja \ 59 | -Werror 60 | 61 | - name: Build 62 | run: | 63 | cmake --build build_${{matrix.build_type}} \ 64 | --config ${{matrix.build_type}} 65 | 66 | - name: Install 67 | run: | 68 | cmake --build build_${{matrix.build_type}} \ 69 | --config ${{matrix.build_type}} \ 70 | --target install 71 | 72 | cmake build_${{matrix.build_type}} \ 73 | -DCMAKE_INSTALL_INCLUDEDIR=${{runner.workspace}}/foo/include \ 74 | -DCMAKE_INSTALL_LIBDIR=${{runner.workspace}}/foo/lib \ 75 | -DCMAKE_INSTALL_DATAROOTDIR=${{runner.workspace}}/foo/share 76 | cmake --build build_${{matrix.build_type}} \ 77 | --config ${{matrix.build_type}} \ 78 | --target install 79 | 80 | - name: Test CMake Package (relative GNUInstallDirs) 81 | run: | 82 | cmake -S src/package_config_unittest/working_config \ 83 | -B build_${{matrix.build_type}}_package \ 84 | -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ 85 | -DCMAKE_PREFIX_PATH=${{github.workspace}}/install \ 86 | -G Ninja 87 | cmake --build build_${{matrix.build_type}}_package \ 88 | --config ${{matrix.build_type}} 89 | 90 | - name: Test CMake Package (absolute GNUInstallDirs) 91 | run: | 92 | cmake -S src/package_config_unittest/working_config \ 93 | -B build_${{matrix.build_type}}_package_foo \ 94 | -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ 95 | -DCMAKE_PREFIX_PATH=${{runner.workspace}}/foo \ 96 | -G Ninja 97 | cmake --build build_${{matrix.build_type}}_package_foo \ 98 | --config ${{matrix.build_type}} 99 | 100 | - name: Test 101 | run: | 102 | ctest --test-dir build_${{matrix.build_type}} -j$(nproc) --output-on-failure 103 | 104 | - name: Generate Coverage 105 | if: matrix.build_type == 'Debug' 106 | run: | 107 | cd build_${{matrix.build_type}} 108 | gcovr -r .. . -s --xml coverage.xml 109 | 110 | - name: Upload Coverage to Codecov 111 | if: matrix.build_type == 'Debug' 112 | uses: codecov/codecov-action@v5 113 | with: 114 | token: ${{ secrets.CODECOV_TOKEN }} 115 | files: build_${{matrix.build_type}}/coverage.xml 116 | fail_ci_if_error: true 117 | verbose: true 118 | 119 | - name: Perform CodeQL Analysis 120 | uses: github/codeql-action/analyze@v3 121 | -------------------------------------------------------------------------------- /.github/workflows/macos.yml: -------------------------------------------------------------------------------- 1 | name: macOS 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build-macos: 7 | name: AppleClang-C++${{matrix.std}}-${{matrix.build_type}} 8 | runs-on: macos-12 9 | permissions: 10 | actions: read 11 | contents: read 12 | security-events: write 13 | strategy: 14 | fail-fast: true 15 | matrix: 16 | std: [14, 17, 20, 23] 17 | include: 18 | - generator: Xcode 19 | - build_type: Debug 20 | 21 | steps: 22 | - uses: actions/checkout@v4 23 | 24 | - name: Setup Dependencies 25 | run: | 26 | brew install ninja 27 | 28 | - name: Setup Coverage Dependencies 29 | if: matrix.build_type == 'Debug' 30 | run: | 31 | brew install gcovr 32 | 33 | - name: Setup Environment 34 | if: matrix.build_type == 'Debug' 35 | run: | 36 | echo 'CXXFLAGS=--coverage' >> $GITHUB_ENV 37 | echo 'LDFLAGS=--coverage' >> $GITHUB_ENV 38 | 39 | - name: Configure 40 | shell: bash 41 | env: 42 | CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror -pedantic-errors ${{env.CXXFLAGS}} 43 | run: | 44 | cmake -S . -B build_${{matrix.build_type}} \ 45 | -DCMAKE_CXX_EXTENSIONS=OFF \ 46 | -DCMAKE_CXX_STANDARD=${{matrix.std}} \ 47 | -DCMAKE_CXX_STANDARD_REQUIRED=ON \ 48 | -G "${{matrix.generator}}" \ 49 | -Werror 50 | 51 | - name: Build 52 | run: | 53 | cmake --build build_${{matrix.build_type}} \ 54 | --config ${{matrix.build_type}} 55 | 56 | - name: Test 57 | run: | 58 | ctest --test-dir build_${{matrix.build_type}} \ 59 | --build-config ${{matrix.build_type}} \ 60 | --output-on-failure 61 | 62 | - name: Generate Coverage 63 | if: matrix.build_type == 'Debug' 64 | run: | 65 | cd build_${{matrix.build_type}} 66 | rm -r Tests/ 67 | gcovr -r .. . -s --cobertura coverage.xml 68 | 69 | - name: Upload Coverage to Codecov 70 | if: matrix.build_type == 'Debug' 71 | uses: codecov/codecov-action@v5 72 | with: 73 | token: ${{ secrets.CODECOV_TOKEN }} 74 | files: build_${{matrix.build_type}}/coverage.xml 75 | fail_ci_if_error: true 76 | verbose: true 77 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.orig 2 | /build*/ 3 | /site/ 4 | bazel-* 5 | # Bzlmod lockfile 6 | /MODULE.bazel.lock 7 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of glog authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | # 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | # 9 | # Please keep the list sorted. 10 | 11 | Abhishek Dasgupta 12 | Abhishek Parmar 13 | Andrew Schwartzmeyer 14 | Andy Ying 15 | Brian Silverman 16 | Dmitriy Arbitman 17 | Google Inc. 18 | Guillaume Dumont 19 | LingBin 20 | Marco Wang 21 | Michael Tanner 22 | MiniLight 23 | romange 24 | Roman Perepelitsa 25 | Sergiu Deitsch 26 | tbennun 27 | Teddy Reed 28 | Vijaymahantesh Sattigeri 29 | Zhongming Qu 30 | Zhuoran Shen 31 | -------------------------------------------------------------------------------- /BUILD.bazel: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | exports_files(["COPYING"]) 4 | 5 | load(":bazel/glog.bzl", "glog_library") 6 | 7 | glog_library() 8 | 9 | # platform() to build with clang-cl on Bazel CI. This is enabled with 10 | # the flags in .bazelci/presubmit.yml: 11 | # 12 | # --incompatible_enable_cc_toolchain_resolution 13 | # --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl 14 | # --extra_execution_platforms=//:x64_windows-clang-cl 15 | platform( 16 | name = "x64_windows-clang-cl", 17 | constraint_values = [ 18 | "@platforms//cpu:x86_64", 19 | "@platforms//os:windows", 20 | "@rules_cc//cc/private/toolchain:clang-cl", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # People who have agreed to one of the CLAs and can contribute patches. 2 | # The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Google employees are listed here 4 | # but not in AUTHORS, because Google holds the copyright. 5 | # 6 | # Names should be added to this file only after verifying that 7 | # the individual or the individual's organization has agreed to 8 | # the appropriate Contributor License Agreement, found here: 9 | # 10 | # https://developers.google.com/open-source/cla/individual 11 | # https://developers.google.com/open-source/cla/corporate 12 | # 13 | # The agreement for individuals can be filled out on the web. 14 | # 15 | # When adding J Random Contributor's name to this file, 16 | # either J's name or J's organization's name should be 17 | # added to the AUTHORS file, depending on whether the 18 | # individual or corporate CLA was used. 19 | # 20 | # Names should be added to this file as: 21 | # Name 22 | # 23 | # Please keep the list sorted. 24 | 25 | Abhishek Dasgupta 26 | Abhishek Parmar 27 | Andrew Schwartzmeyer 28 | Andy Ying 29 | Bret McKee 30 | Brian Silverman 31 | Dmitriy Arbitman 32 | Eric Kilmer 33 | Fumitoshi Ukai 34 | Guillaume Dumont 35 | Håkan L. S. Younes 36 | Ivan Penkov 37 | Jacob Trimble 38 | Jim Ray 39 | LingBin 40 | Marco Wang 41 | Michael Darr 42 | Michael Tanner 43 | MiniLight 44 | Peter Collingbourne 45 | Rodrigo Queiro 46 | romange 47 | Roman Perepelitsa 48 | Sergiu Deitsch 49 | Shinichiro Hamaji 50 | tbennun 51 | Teddy Reed 52 | Vijaymahantesh Sattigeri 53 | Zhongming Qu 54 | Zhuoran Shen 55 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2024-06-08 Google Inc. 2 | 3 | * google-glog: version 0.7.1. 4 | * See git log for the details. 5 | 6 | 2024-02-17 Google Inc. 7 | 8 | * google-glog: version 0.7.0. 9 | * See git log for the details. 10 | 11 | 2022-04-05 Google Inc. 12 | 13 | * google-glog: version 0.6.0. 14 | * See git log for the details. 15 | 16 | 2021-05-08 Google Inc. 17 | 18 | * google-glog: version 0.5.0. 19 | * See git log for the details. 20 | 21 | 2019-01-22 Google Inc. 22 | 23 | * google-glog: version 0.4.0. 24 | * See git log for the details. 25 | 26 | 2017-05-09 Google Inc. 27 | 28 | * google-glog: version 0.3.5 29 | * See git log for the details. 30 | 31 | 2015-03-09 Google Inc. 32 | 33 | * google-glog: version 0.3.4 34 | * See git log for the details. 35 | 36 | 2013-02-01 Google Inc. 37 | 38 | * google-glog: version 0.3.3 39 | * Add --disable-rtti option for configure. 40 | * Visual Studio build and test fix. 41 | * QNX build fix (thanks vanuan). 42 | * Reduce warnings. 43 | * Fixed LOG_SYSRESULT (thanks ukai). 44 | * FreeBSD build fix (thanks yyanagisawa). 45 | * Clang build fix. 46 | * Now users can re-initialize glog after ShutdownGoogleLogging. 47 | * Color output support by GLOG_colorlogtostderr (thanks alexs). 48 | * Now glog's ABI around flags are compatible with gflags. 49 | * Document mentions how to modify flags from user programs. 50 | 51 | 2012-01-12 Google Inc. 52 | 53 | * google-glog: version 0.3.2 54 | * Clang support. 55 | * Demangler and stacktrace improvement for newer GCCs. 56 | * Now fork(2) doesn't mess up log files. 57 | * Make valgrind happier. 58 | * Reduce warnings for more -W options. 59 | * Provide a workaround for ERROR defined by windows.h. 60 | 61 | 2010-06-15 Google Inc. 62 | 63 | * google-glog: version 0.3.1 64 | * GLOG_* environment variables now work even when gflags is installed. 65 | * Snow leopard support. 66 | * Now we can build and test from out side tree. 67 | * Add DCHECK_NOTNULL. 68 | * Add ShutdownGoogleLogging to close syslog (thanks DGunchev) 69 | * Fix --enable-frame-pointers option (thanks kazuki.ohta) 70 | * Fix libunwind detection (thanks giantchen) 71 | 72 | 2009-07-30 Google Inc. 73 | 74 | * google-glog: version 0.3.0 75 | * Fix a deadlock happened when user uses glog with recent gflags. 76 | * Suppress several unnecessary warnings (thanks keir). 77 | * NetBSD and OpenBSD support. 78 | * Use Win32API GetComputeNameA properly (thanks magila). 79 | * Fix user name detection for Windows (thanks ademin). 80 | * Fix several minor bugs. 81 | 82 | 2009-04-10 Google Inc. 83 | * google-glog: version 0.2.1 84 | * Fix timestamps of VC++ version. 85 | * Add pkg-config support (thanks Tomasz) 86 | * Fix build problem when building with gtest (thanks Michael) 87 | * Add --with-gflags option for configure (thanks Michael) 88 | * Fixes for GCC 4.4 (thanks John) 89 | 90 | 2009-01-23 Google Inc. 91 | * google-glog: version 0.2 92 | * Add initial Windows VC++ support. 93 | * Google testing/mocking frameworks integration. 94 | * Link pthread library automatically. 95 | * Flush logs in signal handlers. 96 | * Add macros LOG_TO_STRING, LOG_AT_LEVEL, DVLOG, and LOG_TO_SINK_ONLY. 97 | * Log microseconds. 98 | * Add --log_backtrace_at option. 99 | * Fix some minor bugs. 100 | 101 | 2008-11-18 Google Inc. 102 | * google-glog: version 0.1.2 103 | * Add InstallFailureSignalHandler(). (satorux) 104 | * Re-organize the way to produce stacktraces. 105 | * Don't define unnecessary macro DISALLOW_EVIL_CONSTRUCTORS. 106 | 107 | 2008-10-15 Google Inc. 108 | * google-glog: version 0.1.1 109 | * Support symbolize for MacOSX 10.5. 110 | * BUG FIX: --vmodule didn't work with gflags. 111 | * BUG FIX: symbolize_unittest failed with GCC 4.3. 112 | * Several fixes on the document. 113 | 114 | 2008-10-07 Google Inc. 115 | 116 | * google-glog: initial release: 117 | The glog package contains a library that implements application-level 118 | logging. This library provides logging APIs based on C++-style 119 | streams and various helper macros. 120 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright © 2024, Google Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | * Neither the name of Google Inc. nor the names of its contributors may be used 14 | to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | module( 2 | name = "glog", 3 | compatibility_level = 1, 4 | ) 5 | 6 | bazel_dep(name = "gflags", version = "2.2.2") 7 | bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True) 8 | bazel_dep(name = "platforms", version = "0.0.10") 9 | bazel_dep(name = "rules_cc", version = "0.0.12") 10 | 11 | # Required for Windows clang-cl build: --extra_toolchains=@local_config_cc//:cc-toolchain-arm64_windows 12 | cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension") 13 | use_repo(cc_configure, "local_config_cc") 14 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Google Logging Library 2 | ====================== 3 | 4 | **Deprecation notice**: This project is no longer maintained and will be archived on 2025-06-30. 5 | Consider using 6 | `ng-log `_ (API-compatible, 7 | community-maintained, 8 | `migration instructions `_) 9 | or 10 | `Abseil Logging `_ 11 | (Google-maintained) instead. Thank you for all the contributions! 12 | 13 | Google Logging (glog) was a C++14 library that implements application-level 14 | logging. The library provided logging APIs based on C++-style streams and 15 | various helper macros. 16 | 17 | Getting Started 18 | --------------- 19 | 20 | Please refer to project's `documentation `_. 21 | -------------------------------------------------------------------------------- /WORKSPACE.bazel: -------------------------------------------------------------------------------- 1 | # WORKSPACE marker file needed by Bazel 2 | -------------------------------------------------------------------------------- /bazel/example/BUILD.bazel: -------------------------------------------------------------------------------- 1 | cc_test( 2 | name = "main", 3 | size = "small", 4 | srcs = ["main.cc"], 5 | deps = [ 6 | "//:glog", 7 | "@gflags//:gflags", 8 | ], 9 | ) 10 | -------------------------------------------------------------------------------- /bazel/example/main.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) { 6 | // Initialize Google's logging library. 7 | google::InitGoogleLogging(argv[0]); 8 | 9 | // Optional: parse command line flags 10 | gflags::ParseCommandLineFlags(&argc, &argv, true); 11 | 12 | LOG(INFO) << "Hello, world!"; 13 | 14 | // glog/stl_logging.h allows logging STL containers. 15 | std::vector x; 16 | x.push_back(1); 17 | x.push_back(2); 18 | x.push_back(3); 19 | LOG(INFO) << "ABC, it's easy as " << x; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /cmake/DetermineGflagsNamespace.cmake: -------------------------------------------------------------------------------- 1 | macro(determine_gflags_namespace VARIABLE) 2 | if (NOT DEFINED "${VARIABLE}") 3 | if (CMAKE_REQUIRED_INCLUDES) 4 | set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}") 5 | else () 6 | set (CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS) 7 | endif () 8 | 9 | set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS}) 10 | 11 | set(_NAMESPACES gflags google) 12 | set(_check_code 13 | " 14 | #include 15 | 16 | int main(int argc, char**argv) 17 | { 18 | GLOG_GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); 19 | } 20 | ") 21 | if (NOT CMAKE_REQUIRED_QUIET) 22 | message (STATUS "Looking for gflags namespace") 23 | endif () 24 | if (${ARGC} EQUAL 3) 25 | set (CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS}) 26 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}") 27 | endif () 28 | 29 | set (_check_file 30 | ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/DetermineGflagsNamespace.cxx) 31 | 32 | foreach (_namespace ${_NAMESPACES}) 33 | file (WRITE "${_check_file}" "${_check_code}") 34 | try_compile (${VARIABLE} 35 | "${CMAKE_BINARY_DIR}" "${_check_file}" 36 | COMPILE_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}" -DGLOG_GFLAGS_NAMESPACE=${_namespace} 37 | LINK_LIBRARIES gflags 38 | CMAKE_FLAGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 39 | OUTPUT_VARIABLE OUTPUT) 40 | 41 | if (${VARIABLE}) 42 | set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace" FORCE) 43 | break () 44 | else () 45 | file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 46 | "Determining the gflags namespace ${_namespace} failed with the following output:\n" 47 | "${OUTPUT}\n\n") 48 | endif () 49 | endforeach (_namespace) 50 | 51 | if (${ARGC} EQUAL 3) 52 | set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE}) 53 | endif () 54 | 55 | if (${VARIABLE}) 56 | if (NOT CMAKE_REQUIRED_QUIET) 57 | message (STATUS "Looking for gflags namespace - ${${VARIABLE}}") 58 | endif () 59 | file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 60 | "Determining the gflags namespace passed with the following output:\n" 61 | "${OUTPUT}\n\n") 62 | else () 63 | if (NOT CMAKE_REQUIRED_QUIET) 64 | message (STATUS "Looking for gflags namespace - failed") 65 | endif () 66 | set (${VARIABLE} ${_namespace} CACHE INTERNAL "gflags namespace") 67 | endif () 68 | endif () 69 | endmacro () 70 | -------------------------------------------------------------------------------- /cmake/FindUnwind.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find libunwind 2 | # Once done this will define 3 | # 4 | # Unwind_FOUND - system has libunwind 5 | # unwind::unwind - cmake target for libunwind 6 | 7 | include (FindPackageHandleStandardArgs) 8 | 9 | find_path (Unwind_INCLUDE_DIR NAMES unwind.h libunwind.h DOC "unwind include directory") 10 | find_library (Unwind_LIBRARY NAMES unwind DOC "unwind library") 11 | 12 | mark_as_advanced (Unwind_INCLUDE_DIR Unwind_LIBRARY) 13 | 14 | # Extract version information 15 | if (Unwind_LIBRARY) 16 | set (_Unwind_VERSION_HEADER ${Unwind_INCLUDE_DIR}/libunwind-common.h) 17 | 18 | if (EXISTS ${_Unwind_VERSION_HEADER}) 19 | file (READ ${_Unwind_VERSION_HEADER} _Unwind_VERSION_CONTENTS) 20 | 21 | string (REGEX REPLACE ".*#define UNW_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" 22 | Unwind_VERSION_MAJOR "${_Unwind_VERSION_CONTENTS}") 23 | string (REGEX REPLACE ".*#define UNW_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" 24 | Unwind_VERSION_MINOR "${_Unwind_VERSION_CONTENTS}") 25 | string (REGEX REPLACE ".*#define UNW_VERSION_EXTRA[ \t]+([0-9]+).*" "\\1" 26 | Unwind_VERSION_PATCH "${_Unwind_VERSION_CONTENTS}") 27 | 28 | set (Unwind_VERSION ${Unwind_VERSION_MAJOR}.${Unwind_VERSION_MINOR}) 29 | 30 | if (CMAKE_MATCH_0) 31 | # Third version component may be empty 32 | set (Unwind_VERSION ${Unwind_VERSION}.${Unwind_VERSION_PATCH}) 33 | set (Unwind_VERSION_COMPONENTS 3) 34 | else (CMAKE_MATCH_0) 35 | set (Unwind_VERSION_COMPONENTS 2) 36 | endif (CMAKE_MATCH_0) 37 | endif (EXISTS ${_Unwind_VERSION_HEADER}) 38 | endif (Unwind_LIBRARY) 39 | 40 | # handle the QUIETLY and REQUIRED arguments and set Unwind_FOUND to TRUE 41 | # if all listed variables are TRUE 42 | find_package_handle_standard_args (Unwind 43 | REQUIRED_VARS Unwind_INCLUDE_DIR Unwind_LIBRARY 44 | VERSION_VAR Unwind_VERSION 45 | ) 46 | 47 | if (Unwind_FOUND) 48 | if (NOT TARGET unwind::unwind) 49 | add_library (unwind::unwind INTERFACE IMPORTED) 50 | 51 | set_property (TARGET unwind::unwind PROPERTY 52 | INTERFACE_INCLUDE_DIRECTORIES ${Unwind_INCLUDE_DIR} 53 | ) 54 | set_property (TARGET unwind::unwind PROPERTY 55 | INTERFACE_LINK_LIBRARIES ${Unwind_LIBRARY} 56 | ) 57 | set_property (TARGET unwind::unwind PROPERTY 58 | IMPORTED_CONFIGURATIONS RELEASE 59 | ) 60 | endif (NOT TARGET unwind::unwind) 61 | endif (Unwind_FOUND) 62 | -------------------------------------------------------------------------------- /cmake/GetCacheVariables.cmake: -------------------------------------------------------------------------------- 1 | cmake_policy (PUSH) 2 | cmake_policy (VERSION 3.16...3.27) 3 | 4 | include (CMakeParseArguments) 5 | 6 | function (get_cache_variables _CACHEVARS) 7 | set (_SINGLE) 8 | set (_MULTI EXCLUDE) 9 | set (_OPTIONS) 10 | 11 | cmake_parse_arguments (_ARGS "${_OPTIONS}" "${_SINGLE}" "${_MULTI}" ${ARGS} ${ARGN}) 12 | 13 | get_cmake_property (_VARIABLES VARIABLES) 14 | 15 | set (CACHEVARS) 16 | 17 | foreach (_VAR ${_VARIABLES}) 18 | if (DEFINED _ARGS_EXCLUDE) 19 | if ("${_VAR}" IN_LIST _ARGS_EXCLUDE) 20 | continue () 21 | endif ("${_VAR}" IN_LIST _ARGS_EXCLUDE) 22 | endif (DEFINED _ARGS_EXCLUDE) 23 | 24 | get_property (_CACHEVARTYPE CACHE ${_VAR} PROPERTY TYPE) 25 | 26 | if ("${_CACHEVARTYPE}" STREQUAL INTERNAL OR 27 | "${_CACHEVARTYPE}" STREQUAL STATIC OR 28 | "${_CACHEVARTYPE}" STREQUAL UNINITIALIZED) 29 | continue () 30 | endif ("${_CACHEVARTYPE}" STREQUAL INTERNAL OR 31 | "${_CACHEVARTYPE}" STREQUAL STATIC OR 32 | "${_CACHEVARTYPE}" STREQUAL UNINITIALIZED) 33 | 34 | get_property (_CACHEVARVAL CACHE ${_VAR} PROPERTY VALUE) 35 | 36 | if ("${_CACHEVARVAL}" STREQUAL "") 37 | continue () 38 | endif ("${_CACHEVARVAL}" STREQUAL "") 39 | 40 | get_property (_CACHEVARDOC CACHE ${_VAR} PROPERTY HELPSTRING) 41 | 42 | # Escape " in values 43 | string (REPLACE "\"" "\\\"" _CACHEVARVAL "${_CACHEVARVAL}") 44 | # Escape " in help strings 45 | string (REPLACE "\"" "\\\"" _CACHEVARDOC "${_CACHEVARDOC}") 46 | # Escape ; in values 47 | string (REPLACE ";" "\\\;" _CACHEVARVAL "${_CACHEVARVAL}") 48 | # Escape ; in help strings 49 | string (REPLACE ";" "\\\;" _CACHEVARDOC "${_CACHEVARDOC}") 50 | # Escape backslashes in values except those that are followed by a 51 | # quote. 52 | string (REGEX REPLACE "\\\\([^\"])" "\\\\\\1" _CACHEVARVAL "${_CACHEVARVAL}") 53 | # Escape backslashes in values that are followed by a letter to avoid 54 | # invalid escape sequence errors. 55 | string (REGEX REPLACE "\\\\([a-zA-Z])" "\\\\\\\\1" _CACHEVARVAL "${_CACHEVARVAL}") 56 | string (REPLACE "\\\\" "\\\\\\\\" _CACHEVARDOC "${_CACHEVARDOC}") 57 | 58 | if (NOT "${_CACHEVARTYPE}" STREQUAL BOOL) 59 | set (_CACHEVARVAL "\"${_CACHEVARVAL}\"") 60 | endif (NOT "${_CACHEVARTYPE}" STREQUAL BOOL) 61 | 62 | if (NOT "${_CACHEVARTYPE}" STREQUAL "" AND NOT "${_CACHEVARVAL}" STREQUAL "") 63 | set (CACHEVARS "${CACHEVARS}set (${_VAR} ${_CACHEVARVAL} CACHE ${_CACHEVARTYPE} \"${_CACHEVARDOC}\")\n") 64 | endif (NOT "${_CACHEVARTYPE}" STREQUAL "" AND NOT "${_CACHEVARVAL}" STREQUAL "") 65 | endforeach (_VAR) 66 | 67 | set (${_CACHEVARS} ${CACHEVARS} PARENT_SCOPE) 68 | endfunction (get_cache_variables) 69 | 70 | cmake_policy (POP) 71 | -------------------------------------------------------------------------------- /cmake/RunCleanerTest1.cmake: -------------------------------------------------------------------------------- 1 | set (RUNS 3) 2 | 3 | foreach (iter RANGE 1 ${RUNS}) 4 | set (ENV{GOOGLE_LOG_DIR} ${TEST_DIR}) 5 | execute_process (COMMAND ${LOGCLEANUP} RESULT_VARIABLE _RESULT) 6 | 7 | if (NOT _RESULT EQUAL 0) 8 | message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})") 9 | endif (NOT _RESULT EQUAL 0) 10 | endforeach (iter) 11 | 12 | file (GLOB LOG_FILES ${TEST_DIR}/*.foobar) 13 | list (LENGTH LOG_FILES NUM_FILES) 14 | 15 | if (WIN32) 16 | # On Windows open files cannot be removed and will result in a permission 17 | # denied error while unlinking such file. Therefore, the last file will be 18 | # retained. 19 | set (_expected 1) 20 | else (WIN32) 21 | set (_expected 0) 22 | endif (WIN32) 23 | 24 | if (NOT NUM_FILES EQUAL _expected) 25 | message (SEND_ERROR "Expected ${_expected} log file in log directory but found ${NUM_FILES}") 26 | endif (NOT NUM_FILES EQUAL _expected) 27 | -------------------------------------------------------------------------------- /cmake/RunCleanerTest2.cmake: -------------------------------------------------------------------------------- 1 | set (RUNS 3) 2 | 3 | foreach (iter RANGE 1 ${RUNS}) 4 | execute_process (COMMAND ${LOGCLEANUP} -log_dir=${TEST_DIR} 5 | RESULT_VARIABLE _RESULT) 6 | 7 | if (NOT _RESULT EQUAL 0) 8 | message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})") 9 | endif (NOT _RESULT EQUAL 0) 10 | endforeach (iter) 11 | 12 | file (GLOB LOG_FILES ${TEST_DIR}/test_cleanup_*.barfoo) 13 | list (LENGTH LOG_FILES NUM_FILES) 14 | 15 | if (WIN32) 16 | # On Windows open files cannot be removed and will result in a permission 17 | # denied error while unlinking such file. Therefore, the last file will be 18 | # retained. 19 | set (_expected 1) 20 | else (WIN32) 21 | set (_expected 0) 22 | endif (WIN32) 23 | 24 | if (NOT NUM_FILES EQUAL _expected) 25 | message (SEND_ERROR "Expected ${_expected} log file in log directory but found ${NUM_FILES}") 26 | endif (NOT NUM_FILES EQUAL _expected) 27 | -------------------------------------------------------------------------------- /cmake/RunCleanerTest3.cmake: -------------------------------------------------------------------------------- 1 | set (RUNS 3) 2 | 3 | # Create the subdirectory required by this unit test. 4 | file (MAKE_DIRECTORY ${TEST_DIR}/${TEST_SUBDIR}) 5 | 6 | foreach (iter RANGE 1 ${RUNS}) 7 | execute_process (COMMAND ${LOGCLEANUP} -log_dir=${TEST_DIR} 8 | RESULT_VARIABLE _RESULT) 9 | 10 | if (NOT _RESULT EQUAL 0) 11 | message (FATAL_ERROR "Failed to run logcleanup_unittest (error: ${_RESULT})") 12 | endif (NOT _RESULT EQUAL 0) 13 | endforeach (iter) 14 | 15 | file (GLOB LOG_FILES ${TEST_DIR}/${TEST_SUBDIR}/test_cleanup_*.relativefoo) 16 | list (LENGTH LOG_FILES NUM_FILES) 17 | 18 | if (WIN32) 19 | # On Windows open files cannot be removed and will result in a permission 20 | # denied error while unlinking such file. Therefore, the last file will be 21 | # retained. 22 | set (_expected 1) 23 | else (WIN32) 24 | set (_expected 0) 25 | endif (WIN32) 26 | 27 | if (NOT NUM_FILES EQUAL _expected) 28 | message (SEND_ERROR "Expected ${_expected} log file in build directory ${TEST_DIR}${TEST_SUBDIR} but found ${NUM_FILES}") 29 | endif (NOT NUM_FILES EQUAL _expected) 30 | 31 | # Remove the subdirectory required by this unit test. 32 | file (REMOVE_RECURSE ${TEST_DIR}/${TEST_SUBDIR}) 33 | -------------------------------------------------------------------------------- /cmake/TestInitPackageConfig.cmake: -------------------------------------------------------------------------------- 1 | # Create the build directory 2 | execute_process ( 3 | COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR} 4 | RESULT_VARIABLE _DIRECTORY_CREATED_SUCCEEDED 5 | ) 6 | 7 | if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) 8 | message (FATAL_ERROR "Failed to create build directory") 9 | endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) 10 | 11 | file (WRITE ${INITIAL_CACHE} "${CACHEVARS}") 12 | -------------------------------------------------------------------------------- /cmake/TestPackageConfig.cmake: -------------------------------------------------------------------------------- 1 | if (GENERATOR_TOOLSET) 2 | list (APPEND _ADDITIONAL_ARGS -T ${GENERATOR_TOOLSET}) 3 | endif (GENERATOR_TOOLSET) 4 | 5 | if (GENERATOR_PLATFORM) 6 | list (APPEND _ADDITIONAL_ARGS -A ${GENERATOR_PLATFORM}) 7 | endif (GENERATOR_PLATFORM) 8 | 9 | # Run CMake 10 | execute_process ( 11 | # Capture the PATH environment variable content set during project generation 12 | # stage. This is required because later during the build stage the PATH is 13 | # modified again (e.g., for MinGW AppVeyor CI builds) by adding back the 14 | # directory containing git.exe. Incidentally, the Git installation directory 15 | # also contains sh.exe which causes MinGW Makefile generation to fail. 16 | COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH} 17 | ${CMAKE_COMMAND} -C ${INITIAL_CACHE} 18 | -G ${GENERATOR} 19 | ${_ADDITIONAL_ARGS} 20 | -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON 21 | -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON 22 | -Dglog_ROOT=${PACKAGE_DIR} 23 | -S ${SOURCE_DIR} 24 | -B ${TEST_BINARY_DIR} 25 | RESULT_VARIABLE _GENERATE_SUCCEEDED 26 | ) 27 | 28 | if (NOT _GENERATE_SUCCEEDED EQUAL 0) 29 | message (FATAL_ERROR "Failed to generate project files using CMake") 30 | endif (NOT _GENERATE_SUCCEEDED EQUAL 0) 31 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: 2 | layout: "diff, flags, files" 3 | behavior: default 4 | require_changes: false 5 | require_base: false 6 | require_head: true 7 | ignore: 8 | - "**/*_unittest.cc" 9 | - "src/*_unittest/**" 10 | - "src/googletest.h" 11 | - "src/mock-log.h" 12 | -------------------------------------------------------------------------------- /docs/build.md: -------------------------------------------------------------------------------- 1 | # Building from Source 2 | 3 | ## Bazel 4 | 5 | To use glog within a project which uses the [Bazel](https://bazel.build/) build 6 | tool, add the following lines to your `MODULE.bazel` file: 7 | 8 | ``` bazel title="MODULE.bazel" 9 | bazel_dep(name = "glog") 10 | 11 | archive_override( 12 | module_name = "glog", 13 | urls = "https://github.com/google/glog/archive/cc0de6c200375b33d907ee7632eee2f173b33a09.tar.gz", 14 | strip_prefix = "glog-cc0de6c200375b33d907ee7632eee2f173b33a09", # Latest commit as of 2024-06-08. 15 | integrity = "sha256-rUrv4EBkdc+4Wbhfxp+KoRstlj2Iw842/OpLfDq0ivg=", 16 | ) 17 | ``` 18 | 19 | You can then add `@glog//:glog` to 20 | the deps section of a `cc_binary` or 21 | `cc_library` rule, and `#!cpp #include ` to 22 | include it in your source code. 23 | 24 | !!! example "Using glog in a Bazel project" 25 | ``` bazel 26 | cc_binary( 27 | name = "main", 28 | srcs = ["main.cc"], 29 | deps = ["@glog//:glog"], 30 | ) 31 | ``` 32 | 33 | ## CMake 34 | 35 | glog can be compiled using [CMake](http://www.cmake.org) on a wide range of 36 | platforms. The typical workflow for building glog on a Unix-like system with GNU 37 | Make as build tool is as follows: 38 | 39 | 1. Clone the repository and change into source directory. 40 | ``` bash 41 | git clone https://github.com/google/glog.git 42 | cd glog 43 | ``` 44 | 2. Run CMake to configure the build tree. 45 | ``` bash 46 | cmake -S . -B build -G "Unix Makefiles" 47 | ``` 48 | CMake provides different generators, and by default will pick the most 49 | relevant one to your environment. If you need a specific version of Visual 50 | Studio, use `#!bash cmake . -G `, and see `#!bash cmake 51 | --help` for the available generators. Also see `-T `, which can 52 | be used to request the native x64 toolchain with `-T host=x64`. 53 | 3. Afterwards, generated files can be used to compile the project. 54 | ``` bash 55 | cmake --build build 56 | ``` 57 | 4. Test the build software (optional). 58 | ``` bash 59 | cmake --build build --target test 60 | ``` 61 | 5. Install the built files (optional). 62 | ``` bash 63 | cmake --build build --target install 64 | ``` 65 | 66 | Once successfully built, glog can be [integrated into own projects](usage.md). 67 | -------------------------------------------------------------------------------- /docs/contribute.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. 4 | There are a just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement (CLA) 7 | 8 | Contributions to any Google project must be accompanied by a Contributor 9 | License Agreement. This is not a copyright **assignment**, it simply 10 | gives Google permission to use and redistribute your contributions as 11 | part of the project. 12 | 13 | - If you are an individual writing original source code and you're 14 | sure you own the intellectual property, then you'll need to sign an 15 | [individual 16 | CLA](https://developers.google.com/open-source/cla/individual). 17 | - If you work for a company that wants to allow you to contribute your 18 | work, then you'll need to sign a [corporate 19 | CLA](https://developers.google.com/open-source/cla/corporate). 20 | 21 | You generally only need to submit a CLA once, so if you've already 22 | submitted one (even if it was for a different project), you probably 23 | don't need to do it again. 24 | 25 | Once your CLA is submitted (or if you already submitted one for another Google 26 | project), make a commit adding yourself to the 27 | [AUTHORS](https://github.com/google/glog/blob/master/AUTHORS) and 28 | [CONTRIBUTORS](https://github.com/google/glog/blob/master/CONTRIBUTORS) files. 29 | This commit can be part of your first [pull 30 | request](https://help.github.com/articles/creating-a-pull-request). 31 | 32 | ## Submitting a Patch 33 | 34 | 1. It's generally best to start by opening a new issue describing the 35 | bug or feature you're intending to fix. Even if you think it's 36 | relatively minor, it's helpful to know what people are working on. 37 | Mention in the initial issue that you are planning to work on that 38 | bug or feature so that it can be assigned to you. 39 | 2. Follow the normal process of 40 | [forking](https://help.github.com/articles/fork-a-repo) the project, 41 | and setup a new branch to work in. It's important that each group of 42 | changes be done in separate branches in order to ensure that a pull 43 | request only includes the commits related to that bug or feature. 44 | 3. Do your best to have [well-formed commit 45 | messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) 46 | for each change. This provides consistency throughout the project, 47 | and ensures that commit messages are able to be formatted properly 48 | by various git tools. 49 | 4. Finally, push the commits to your fork and submit a [pull 50 | request](https://help.github.com/articles/creating-a-pull-request). 51 | -------------------------------------------------------------------------------- /docs/failures.md: -------------------------------------------------------------------------------- 1 | # Failure Signal Handler 2 | 3 | ## Stacktrace as Default Failure Handler 4 | 5 | The library provides a convenient signal handler that will dump useful 6 | information when the program crashes on certain signals such as `SIGSEGV`. The 7 | signal handler can be installed by `#!cpp 8 | google::InstallFailureSignalHandler()`. The following is an example of output 9 | from the signal handler. 10 | 11 | *** Aborted at 1225095260 (unix time) try "date -d @1225095260" if you are using GNU date *** 12 | *** SIGSEGV (@0x0) received by PID 17711 (TID 0x7f893090a6f0) from PID 0; stack trace: *** 13 | PC: @ 0x412eb1 TestWaitingLogSink::send() 14 | @ 0x7f892fb417d0 (unknown) 15 | @ 0x412eb1 TestWaitingLogSink::send() 16 | @ 0x7f89304f7f06 google::LogMessage::SendToLog() 17 | @ 0x7f89304f35af google::LogMessage::Flush() 18 | @ 0x7f89304f3739 google::LogMessage::~LogMessage() 19 | @ 0x408cf4 TestLogSinkWaitTillSent() 20 | @ 0x4115de main 21 | @ 0x7f892f7ef1c4 (unknown) 22 | @ 0x4046f9 (unknown) 23 | 24 | 25 | ## Customizing Handler Output 26 | 27 | By default, the signal handler writes the failure dump to the standard error. 28 | However, it is possible to customize the destination by installing a callback 29 | using the `#!cpp google::InstallFailureWriter()` function. The function expects 30 | a pointer to a function with the following signature: 31 | 32 | ``` cpp 33 | void YourFailureWriter(const char* message/* (1)! */, std::size_t length/* (2)! */); 34 | ``` 35 | 36 | 1. The pointer references the start of the failure message. 37 | 38 | !!! danger 39 | The string is **not null-terminated**. 40 | 41 | 2. The message length in characters. 42 | 43 | !!! warning "Possible overflow errors" 44 | Users should not expect the `message` string to be null-terminated. 45 | 46 | ## User-defined Failure Function 47 | 48 | `FATAL` severity level messages or unsatisfied `CHECK` condition 49 | terminate your program. You can change the behavior of the termination 50 | by `google::InstallFailureFunction`. 51 | 52 | ``` cpp 53 | void YourFailureFunction() { 54 | // Reports something... 55 | exit(EXIT_FAILURE); 56 | } 57 | 58 | int main(int argc, char* argv[]) { 59 | google::InstallFailureFunction(&YourFailureFunction); 60 | } 61 | ``` 62 | 63 | By default, glog tries to dump the stacktrace and calls `#!cpp std::abort`. The 64 | stacktrace is generated only when running the application on a system 65 | supported[^1] by glog. 66 | 67 | [^1]: To extract the stack trace, glog currently supports the following targets: 68 | 69 | * x86, x86_64, 70 | * PowerPC architectures, 71 | * `libunwind`, 72 | * and the Debug Help Library (`dbghelp`) on Windows. 73 | 74 | -------------------------------------------------------------------------------- /docs/flags.md: -------------------------------------------------------------------------------- 1 | # Adjusting Output 2 | 3 | Several flags influence glog's output behavior. 4 | 5 | ## Using Command-line Parameters and Environment Variables 6 | 7 | If the [Google gflags 8 | library](https://github.com/gflags/gflags) is installed on your machine, 9 | the build system will automatically detect and use it, allowing you to 10 | pass flags on the command line. 11 | 12 | !!! example "Activate `--logtostderr` in an application from the command line" 13 | A binary `you_application` that uses glog can be started using 14 | ``` bash 15 | ./your_application --logtostderr=1 16 | ``` 17 | to log to `stderr` instead of writing the output to a log file. 18 | 19 | !!! tip 20 | You can set boolean flags to `true` by specifying `1`, `true`, or `yes`. To 21 | set boolean flags to `false`, specify `0`, `false`, or `no`. In either case 22 | the spelling is case-insensitive. 23 | 24 | 25 | If the Google gflags library isn't installed, you set flags via 26 | environment variables, prefixing the flag name with `GLOG_`, e.g., 27 | 28 | !!! example "Activate `logtostderr` without gflags" 29 | ``` bash 30 | GLOG_logtostderr=1 ./your_application 31 | ``` 32 | 33 | The following flags are most commonly used: 34 | 35 | `logtostderr` (`bool`, default=`false`) 36 | 37 | : Log messages to `stderr` instead of logfiles. 38 | 39 | `stderrthreshold` (`int`, default=2, which is `ERROR`) 40 | 41 | : Copy log messages at or above this level to `stderr` in addition to 42 | logfiles. The numbers of severity levels `INFO`, `WARNING`, `ERROR`, 43 | and `FATAL` are 0, 1, 2, and 3, respectively. 44 | 45 | `minloglevel` (`int`, default=0, which is `INFO`) 46 | 47 | : Log messages at or above this level. Again, the numbers of severity 48 | levels `INFO`, `WARNING`, `ERROR`, and `FATAL` are 0, 1, 2, and 3, 49 | respectively. 50 | 51 | `log_dir` (`string`, default="") 52 | 53 | : If specified, logfiles are written into this directory instead of 54 | the default logging directory. 55 | 56 | `v` (`int`, default=0) 57 | 58 | : Show all `#!cpp VLOG(m)` messages for `m` less or equal the value of this 59 | flag. Overridable by `#!bash --vmodule`. Refer to [verbose 60 | logging](logging.md#verbose-logging) for more detail. 61 | 62 | `vmodule` (`string`, default="") 63 | 64 | : Per-module verbose level. The argument has to contain a 65 | comma-separated list of `=`. `` is a 66 | glob pattern (e.g., `gfs*` for all modules whose name starts with "gfs"), 67 | matched against the filename base (that is, name ignoring .cc/.h./-inl.h). 68 | `` overrides any value given by `--v`. See also [verbose 69 | logging](logging.md#verbose-logging) for more details. 70 | 71 | Additional flags are defined in 72 | [flags.cc](https://github.com/google/glog/blob/master/src/flags.cc). Please see 73 | the source for their complete list. 74 | 75 | ## Modifying Flags Programmatically 76 | 77 | You can also modify flag values in your program by modifying global variables 78 | `FLAGS_*`. Most settings start working immediately after you update `FLAGS_*`. 79 | The exceptions are the flags related to destination files. For instance, you 80 | might want to set `FLAGS_log_dir` before calling `google::InitGoogleLogging`. 81 | 82 | !!! example "Setting `log_dir` at runtime" 83 | ``` cpp 84 | LOG(INFO) << "file"; 85 | // Most flags work immediately after updating values. 86 | FLAGS_logtostderr = 1; 87 | LOG(INFO) << "stderr"; 88 | FLAGS_logtostderr = 0; 89 | // This won’t change the log destination. If you want to set this 90 | // value, you should do this before google::InitGoogleLogging . 91 | FLAGS_log_dir = "/some/log/directory"; 92 | LOG(INFO) << "the same file"; 93 | ``` 94 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Google Logging Library 2 | 3 | Google Logging (glog) is a C++14 library that implements application-level 4 | logging. The library provides logging APIs based on C++-style streams and 5 | various helper macros. 6 | 7 | # How to Use 8 | 9 | You can log a message by simply streaming things to `LOG`(), e.g., 11 | 12 | ``` cpp title="main.cpp" 13 | #include 14 | 15 | int main(int argc, char* argv[]) { 16 | google::InitGoogleLogging(argv[0]); // (1)! 17 | LOG(INFO) << "Found " << num_cookies << " cookies"; // (2)! 18 | } 19 | ``` 20 | 21 | 1. Initialize the Google Logging Library 22 | 2. Log a message with informational severity 23 | 24 | The library can be installed using various [package managers](packages.md) or 25 | compiled [from source](build.md). For a detailed overview of glog features and 26 | their usage, please refer to the [user guide](logging.md). 27 | 28 | !!! warning 29 | The above example requires further [Bazel](build.md#bazel) or 30 | [CMake](usage.md) setup for use in own projects. 31 | -------------------------------------------------------------------------------- /docs/license.md: -------------------------------------------------------------------------------- 1 | # The 3-Clause BSD License 2 | 3 | --8<-- "LICENSE.md" 4 | -------------------------------------------------------------------------------- /docs/log_cleaner.md: -------------------------------------------------------------------------------- 1 | # Automatically Remove Old Logs 2 | 3 | To enable the log cleaner: 4 | 5 | ``` cpp 6 | using namespace std::chrono_literals; 7 | google::EnableLogCleaner(24h * 3); // keep your logs for 3 days 8 | ``` 9 | 10 | In C++20 (and later) this can be shortened to: 11 | 12 | ``` cpp 13 | using namespace std::chrono_literals; 14 | google::EnableLogCleaner(3d); // keep your logs for 3 days 15 | ``` 16 | 17 | And then glog will check if there are overdue logs whenever a flush is 18 | performed. In this example, any log file from your project whose last 19 | modified time is greater than 3 days will be `unlink`()ed. 20 | 21 | This feature can be disabled at any time (if it has been enabled) using 22 | ``` cpp 23 | google::DisableLogCleaner(); 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/log_stripping.md: -------------------------------------------------------------------------------- 1 | # Strip Logging Messages 2 | 3 | Strings used in log messages can increase the size of your binary and 4 | present a privacy concern. You can therefore instruct glog to remove all 5 | strings which fall below a certain severity level by using the 6 | `GOOGLE_STRIP_LOG` macro: 7 | 8 | If your application has code like this: 9 | 10 | ``` cpp 11 | #define GOOGLE_STRIP_LOG 1 // this must go before the #include! 12 | #include 13 | ``` 14 | 15 | The compiler will remove the log messages whose severities are less than 16 | the specified integer value. Since `VLOG` logs at the severity level 17 | `INFO` (numeric value `0`), setting `GOOGLE_STRIP_LOG` to 1 or greater 18 | removes all log messages associated with `VLOG`s as well as `INFO` log 19 | statements. 20 | 21 | -------------------------------------------------------------------------------- /docs/overrides/main.html: -------------------------------------------------------------------------------- 1 | {% extends "base.html" %} 2 | 3 | {% block outdated %} 4 | You're not viewing the latest version. 5 | 6 | Click here to go to latest. 7 | 8 | {% endblock %} 9 | -------------------------------------------------------------------------------- /docs/packages.md: -------------------------------------------------------------------------------- 1 | # Installation using Package Managers 2 | 3 | ## conan 4 | 5 | You can download and install glog using the [conan](https://conan.io) 6 | package manager: 7 | 8 | ``` bash 9 | pip install conan 10 | conan install -r conancenter glog/@ 11 | ``` 12 | 13 | The glog recipe in conan center is kept up to date by conan center index 14 | community contributors. If the version is out of date, please create an 15 | issue or pull request on the 16 | [conan-center-index](https://github.com/conan-io/conan-center-index) 17 | repository. 18 | 19 | ## vcpkg 20 | 21 | You can download and install glog using the 22 | [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager: 23 | 24 | ``` bash 25 | git clone https://github.com/Microsoft/vcpkg.git 26 | cd vcpkg 27 | ./bootstrap-vcpkg.sh 28 | ./vcpkg integrate install 29 | ./vcpkg install glog 30 | ``` 31 | 32 | The glog port in vcpkg is kept up to date by Microsoft team members and 33 | community contributors. If the version is out of date, please create an 34 | issue or pull request on the vcpkg repository. 35 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | mike>=2.1.1 2 | mkdocs-git-committers-plugin-2>=2.3.0 3 | mkdocs-git-revision-date-localized-plugin>=1.2.6 4 | mkdocs-material-extensions>=1.3.1 5 | mkdocs-material>=9.5.26 6 | mkdocs>=1.6.0 7 | -------------------------------------------------------------------------------- /docs/sinks.md: -------------------------------------------------------------------------------- 1 | # Custom Sinks 2 | 3 | Under certain circumstances, it is useful to send the log output to a 4 | destination other than a file, `stderr` and/or `stdout`. In case, the library 5 | provides the `#!cpp google::LogSink` interface whose implementations can be used 6 | to write the log output to arbitrary locations. 7 | 8 | ## Basic Interface 9 | 10 | The sink interface is defined as follows: 11 | 12 | ``` cpp 13 | class LogSink { 14 | public: 15 | virtual void send(LogSeverity severity, const char* full_filename, 16 | const char* base_filename, int line, 17 | const LogMessageTime& time, const char* message, 18 | size_t message_len); 19 | }; 20 | ``` 21 | 22 | The user must implement `#!cpp google::LogSink::send`, which is called by the 23 | library every time a message is logged. 24 | 25 | !!! warning "Possible deadlock due to nested logging" 26 | This method can't use `LOG()` or `CHECK()` as logging system mutex(s) are 27 | held during this call. 28 | 29 | ## Registering Log Sinks 30 | 31 | To use the custom sink and instance of the above interface implementation must 32 | be registered using `google::AddLogSink` which expects a pointer to the 33 | `google::LogSink` instance. To unregister use `google::RemoveLogSink`. Both 34 | functions are thread-safe. 35 | 36 | !!! danger "`LogSink` ownership" 37 | The `google::LogSink` instance must not be destroyed until the referencing 38 | pointer is unregistered. 39 | 40 | ## Direct Logging 41 | 42 | Instead of registering the sink, we can directly use to log messages. While `#! 43 | LOG_TO_SINK(sink, severity)` allows to log both to the sink and to a global log 44 | registry, e.g., a file, `#!cpp LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity)` 45 | will avoid the latter. 46 | 47 | !!! example "Using a custom sink" 48 | ``` cpp title="custom_sink.cc" 49 | -8<- "examples/custom_sink.cc:33:" 50 | ``` 51 | 52 | 1. `MySink` implements a custom sink that sends log messages to `std::cout`. 53 | 2. The custom sink must be registered to for use with existing logging 54 | macros. 55 | 3. Once the custom sink is no longer needed we remove it from the registry. 56 | 4. A sink does not need to be registered globally. However, then, messages 57 | must be logged using dedicated macros. 58 | 59 | Running the above example as `#!bash GLOG_log_dir=. ./custom_sink_example` 60 | will produce 61 | 62 |
63 | 64 | ``` title="Custom sink output" 65 | INFO custom_sink.cc:63 logging to MySink 66 | INFO custom_sink.cc:68 direct logging 67 | INFO custom_sink.cc:69 direct logging but not to file (1) 68 | ``` 69 | 70 |
71 | 72 | 1. This line is not present in the log file because we used 73 | `LOG_TO_SINK_BUT_NOT_TO_LOGFILE` to log the message. 74 | 75 | and the corresponding log file will contain 76 | 77 | ``` title="Log file generated with the custom sink" 78 | Log file created at: 2024/06/11 13:24:27 79 | Running on machine: pc 80 | Running duration (h:mm:ss): 0:00:00 81 | Log line format: [IWEF]yyyymmdd hh:mm:ss.uuuuuu threadid file:line] msg 82 | I20240611 13:24:27.476620 126237946035776 custom_sink.cc:63] logging to MySink 83 | I20240611 13:24:27.476796 126237946035776 custom_sink.cc:68] direct logging 84 | ``` 85 | -------------------------------------------------------------------------------- /docs/unwinder.md: -------------------------------------------------------------------------------- 1 | # Installation Notes for 64-bit Linux Systems 2 | 3 | !!! note 4 | The description on this page is possibly not up-to-date. 5 | 6 | The [glibc built-in stack-unwinder](#glibc-built-in-stack-unwinder) on 64-bit 7 | systems has some problems with glog. In particular, if you are using 8 | [`InstallFailureSignalHandler()`](failures.md), the signal may be raised in the 9 | middle of `malloc`, holding some `malloc`-related locks when they invoke the 10 | stack unwinder. The built-in stack unwinder may call `malloc` recursively, which 11 | may require the thread to acquire a lock it already holds resulting in a 12 | deadlock. 13 | 14 | ## Recommended Approach: `libunwind` 15 | 16 | For above reason, if you use a 64-bit system and you need 17 | `InstallFailureSignalHandler()`, we strongly recommend you install `libunwind` 18 | before trying to configure or install google glog. libunwind can be found 19 | [here](http://download.savannah.nongnu.org/releases/libunwind/libunwind-snap-070410.tar.gz). 20 | 21 | Even if you already have `libunwind` installed, you will probably still need to 22 | install from the snapshot to get the latest version. 23 | 24 | !!! warning 25 | If you install libunwind from the URL above, be aware that you may have 26 | trouble if you try to statically link your binary with glog: that is, if you 27 | link with `gcc -static -lgcc_eh ...`. This is because both `libunwind` and 28 | `libgcc` implement the same C++ exception handling APIs, but they implement 29 | them differently on some platforms. This is not likely to be a problem on 30 | ia64, but may be on x86-64. 31 | 32 | Also, if you link binaries statically, make sure that you add 33 | `-Wl,--eh-frame-hdr` to your linker options. This is required so that 34 | `libunwind` can find the information generated by the compiler required for 35 | stack unwinding. 36 | 37 | Using `-static` is rare, though, so unless you know this will affect you it 38 | probably won't. 39 | 40 | ## Alternative Stack-unwinder 41 | 42 | If you cannot or do not wish to install `libunwind`, you can still try to use 43 | two kinds of stack-unwinder: 44 | 45 | ### glibc Built-in Stack-unwinder 46 | 47 | As we already mentioned, glibc's unwinder has a deadlock issue. However, if you 48 | don't use `InstallFailureSignalHandler()` or you don't worry about the rare 49 | possibilities of deadlocks, you can use this stack-unwinder. If you specify no 50 | options and `libunwind` isn't detected on your system, the configure script 51 | chooses this unwinder by default. 52 | 53 | ### Frame Pointer based Stack-unwinder 54 | 55 | The frame pointer based stack unwinder requires that your application, the glog 56 | library, and system libraries like libc, all be compiled with a frame pointer. 57 | This is *not* the default for x86-64. 58 | -------------------------------------------------------------------------------- /docs/usage.md: -------------------------------------------------------------------------------- 1 | # Using glog in a CMake Project 2 | 3 | Assuming that glog was previously [built using CMake](build.md#cmake) or 4 | installed using a package manager, you can use the CMake command `#!cmake 5 | find_package` to build against glog in your CMake project as follows: 6 | 7 | ``` cmake title="CMakeLists.txt" 8 | cmake_minimum_required (VERSION 3.16) 9 | project (myproj VERSION 1.0) 10 | 11 | find_package (glog 0.8.0 REQUIRED) 12 | 13 | add_executable (myapp main.cpp) 14 | target_link_libraries (myapp glog::glog) 15 | ``` 16 | 17 | Compile definitions and options will be added automatically to your target as 18 | needed. 19 | 20 | Alternatively, glog can be incorporated into using the CMake command `#!cmake 21 | add_subdirectory` to include glog directly from a subdirectory of your project 22 | by replacing the `#!cmake find_package` call from the previous snippet by 23 | `add_subdirectory`. The `#!cmake glog::glog` target is in this case an `#!cmake 24 | ALIAS` library target for the `glog` library target. 25 | -------------------------------------------------------------------------------- /docs/windows.md: -------------------------------------------------------------------------------- 1 | # Notes for Windows Users 2 | 3 | glog defines the severity level `ERROR`, which is also defined by `windows.h`. 4 | You can make glog not define `INFO`, `WARNING`, `ERROR`, and `FATAL` by defining 5 | `GLOG_NO_ABBREVIATED_SEVERITIES` before including `glog/logging.h`. Even with 6 | this macro, you can still use the iostream like logging facilities: 7 | 8 | ``` cpp 9 | #define GLOG_NO_ABBREVIATED_SEVERITIES 10 | #include 11 | #include 12 | 13 | // ... 14 | 15 | LOG(ERROR) << "This should work"; 16 | LOG_IF(ERROR, x > y) << "This should be also OK"; 17 | ``` 18 | 19 | However, you cannot use `INFO`, `WARNING`, `ERROR`, and `FATAL` anymore for 20 | functions defined in `glog/logging.h`. 21 | 22 | ``` cpp 23 | #define GLOG_NO_ABBREVIATED_SEVERITIES 24 | #include 25 | #include 26 | 27 | // ... 28 | 29 | // This won’t work. 30 | // google::FlushLogFiles(google::ERROR); 31 | 32 | // Use this instead. 33 | google::FlushLogFiles(google::GLOG_ERROR); 34 | ``` 35 | 36 | If you don't need `ERROR` defined by `windows.h`, there are a couple of more 37 | workarounds which sometimes don't work[^1]: 38 | 39 | - `#!cpp #define WIN32_LEAN_AND_MEAN` or `NOGDI` **before** 40 | `#!cpp #include `. 41 | - `#!cpp #undef ERROR` **after** `#!cpp #include `. 42 | 43 | [^1]: For more information refer to [this 44 | issue](http://code.google.com/p/google-glog/issues/detail?id=33). 45 | -------------------------------------------------------------------------------- /examples/custom_sink.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Sergiu Deitsch 31 | // 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | namespace { 41 | 42 | struct MyLogSink : google::LogSink { // (1)! 43 | void send(google::LogSeverity severity, const char* /*full_filename*/, 44 | const char* base_filename, int line, 45 | const google::LogMessageTime& /*time*/, const char* message, 46 | std::size_t message_len) override { 47 | std::cout << google::GetLogSeverityName(severity) << ' ' << base_filename 48 | << ':' << line << ' '; 49 | std::copy_n(message, message_len, 50 | std::ostreambuf_iterator{std::cout}); 51 | std::cout << '\n'; 52 | } 53 | }; 54 | 55 | } // namespace 56 | 57 | int main(int /*argc*/, char** argv) { 58 | google::InitGoogleLogging(argv[0]); 59 | 60 | MyLogSink sink; 61 | google::AddLogSink(&sink); // (2)! 62 | 63 | LOG(INFO) << "logging to MySink"; 64 | 65 | google::RemoveLogSink(&sink); // (3)! 66 | 67 | // We can directly log to a sink without registering it 68 | LOG_TO_SINK(&sink, INFO) << "direct logging"; // (4)! 69 | LOG_TO_SINK_BUT_NOT_TO_LOGFILE(&sink, INFO) 70 | << "direct logging but not to file"; 71 | } 72 | -------------------------------------------------------------------------------- /gcovr.cfg: -------------------------------------------------------------------------------- 1 | exclude = src/.*_unittest\.cc 2 | exclude = src/googletest\.h 3 | exclude = src/mock-log\.h 4 | exclude-directories = Tests/ 5 | exclude-throw-branches = yes 6 | exclude-unreachable-branches = yes 7 | filter = .*/glog/.*\.h 8 | filter = src/ 9 | -------------------------------------------------------------------------------- /glog-config.cmake.in: -------------------------------------------------------------------------------- 1 | if (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@) 2 | message (FATAL_ERROR "CMake >= @glog_CMake_VERSION@ required") 3 | endif (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@) 4 | 5 | @PACKAGE_INIT@ 6 | 7 | include (CMakeFindDependencyMacro) 8 | include (${CMAKE_CURRENT_LIST_DIR}/glog-modules.cmake) 9 | 10 | find_dependency (Threads) 11 | 12 | @gflags_DEPENDENCY@ 13 | @Unwind_DEPENDENCY@ 14 | 15 | include (${CMAKE_CURRENT_LIST_DIR}/glog-targets.cmake) 16 | -------------------------------------------------------------------------------- /glog-modules.cmake.in: -------------------------------------------------------------------------------- 1 | cmake_policy (PUSH) 2 | cmake_policy (SET CMP0057 NEW) 3 | 4 | if (CMAKE_VERSION VERSION_LESS 3.3) 5 | message (FATAL_ERROR "glog-modules.cmake requires the consumer " 6 | "to use CMake 3.3 (or newer)") 7 | endif (CMAKE_VERSION VERSION_LESS 3.3) 8 | 9 | set (glog_MODULE_PATH "@glog_FULL_CMake_DATADIR@") 10 | list (APPEND CMAKE_MODULE_PATH ${glog_MODULE_PATH}) 11 | 12 | if (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH) 13 | message (FATAL_ERROR "Cannot add '${glog_MODULE_PATH}' to " 14 | "CMAKE_MODULE_PATH. This will cause glog-config.cmake to fail at " 15 | "locating required find modules. Make sure CMAKE_MODULE_PATH is not a cache variable.") 16 | endif (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH) 17 | 18 | cmake_policy (POP) 19 | -------------------------------------------------------------------------------- /libglog.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libglog 7 | Description: Google Log (glog) C++ logging framework 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lglog 10 | Libs.private: @glog_libraries_options_for_static_linking@ 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | --- 2 | site_name: Google Logging Library 3 | site_url: https://google.github.io/glog/ 4 | repo_url: https://github.com/google/glog 5 | repo_name: google/glog 6 | edit_uri: edit/master/docs/ 7 | copyright: Copyright © 2024 Google Inc. & contributors - Change cookie settings 8 | markdown_extensions: 9 | - admonition 10 | - attr_list 11 | - def_list 12 | - footnotes 13 | - md_in_html 14 | - pymdownx.details 15 | - pymdownx.highlight: 16 | anchor_linenums: true 17 | line_spans: __span 18 | pygments_lang_class: true 19 | - pymdownx.inlinehilite 20 | - pymdownx.snippets: 21 | base_path: 22 | - '.' 23 | check_paths: true 24 | - pymdownx.superfences 25 | - tables 26 | - toc: 27 | permalink: true 28 | theme: 29 | name: material 30 | custom_dir: docs/overrides 31 | icon: 32 | annotation: material/chevron-right-circle 33 | edit: material/pencil 34 | repo: fontawesome/brands/git-alt 35 | view: material/eye 36 | language: en 37 | features: 38 | - content.action.edit 39 | - content.code.annotate 40 | - content.code.copy 41 | - content.code.select 42 | - header.autohide 43 | - navigation.expand 44 | - navigation.instant.preview 45 | - navigation.instant.progress 46 | - navigation.prune 47 | - navigation.indexes 48 | - toc.follow 49 | - navigation.top 50 | - navigation.path 51 | # - navigation.sections 52 | # - navigation.tabs 53 | # - navigation.tabs.sticky 54 | - navigation.tracking 55 | - search.highlight 56 | - search.share 57 | - search.suggest 58 | palette: 59 | # Palette toggle for automatic mode 60 | - media: "(prefers-color-scheme)" 61 | toggle: 62 | icon: material/brightness-auto 63 | name: Switch to light mode 64 | # Palette toggle for light mode 65 | - media: "(prefers-color-scheme: light)" 66 | scheme: default 67 | primary: teal 68 | accent: green 69 | toggle: 70 | icon: material/brightness-7 71 | name: Switch to dark mode 72 | # Palette toggle for dark mode 73 | - media: "(prefers-color-scheme: dark)" 74 | scheme: slate 75 | primary: black 76 | toggle: 77 | icon: material/brightness-4 78 | name: Switch to system preference 79 | plugins: 80 | - git-revision-date-localized: 81 | enable_creation_date: true 82 | - git-committers: 83 | repository: google/glog 84 | branch: master 85 | - privacy 86 | - search 87 | - tags 88 | extra: 89 | version: 90 | alias: true 91 | default: 92 | - dev 93 | - stable 94 | provider: mike 95 | consent: 96 | actions: 97 | - manage 98 | - accept 99 | - reject 100 | title: Cookie consent 101 | description: >- 102 | We use cookies to recognize your repeated visits and preferences, as well 103 | as to measure the effectiveness of our documentation and whether users 104 | find what they're searching for. With your consent, you're helping us to 105 | make our documentation better. 106 | nav: 107 | - Getting Started: 108 | - Overview: index.md 109 | - Usage in CMake Projects: usage.md 110 | - Building from Source: build.md 111 | - Installation using Package Managers: packages.md 112 | - User Guide: 113 | - Logging: logging.md 114 | - Adjusting Output: flags.md 115 | - Custom Sinks: sinks.md 116 | - Failure Handler: failures.md 117 | - Log Removal: log_cleaner.md 118 | - Stripping Log Messages: log_stripping.md 119 | - System-specific Considerations: 120 | - Usage on Windows: windows.md 121 | - Linux Unwinder: unwinder.md 122 | - Contributing: contribute.md 123 | - License: license.md 124 | -------------------------------------------------------------------------------- /src/base/googleinit.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // --- 31 | // Author: Jacob Hoffman-Andrews 32 | 33 | #ifndef _GOOGLEINIT_H 34 | #define _GOOGLEINIT_H 35 | 36 | class GoogleInitializer { 37 | public: 38 | using void_function = void (*)(); 39 | GoogleInitializer(const char*, void_function f) { f(); } 40 | }; 41 | 42 | #define REGISTER_MODULE_INITIALIZER(name, body) \ 43 | namespace { \ 44 | static void google_init_module_##name() { body; } \ 45 | GoogleInitializer google_initializer_module_##name( \ 46 | #name, google_init_module_##name); \ 47 | } 48 | 49 | #endif /* _GOOGLEINIT_H */ 50 | -------------------------------------------------------------------------------- /src/cleanup_immediately_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "base/commandlineflags.h" 31 | #include "glog/logging.h" 32 | #include "glog/raw_logging.h" 33 | #include "googletest.h" 34 | 35 | #ifdef GLOG_USE_GFLAGS 36 | # include 37 | using namespace GFLAGS_NAMESPACE; 38 | #endif 39 | 40 | #ifdef HAVE_LIB_GMOCK 41 | # include 42 | 43 | # include "mock-log.h" 44 | // Introduce several symbols from gmock. 45 | using google::glog_testing::ScopedMockLog; 46 | using testing::_; 47 | using testing::AllOf; 48 | using testing::AnyNumber; 49 | using testing::HasSubstr; 50 | using testing::InitGoogleMock; 51 | using testing::StrictMock; 52 | using testing::StrNe; 53 | #endif 54 | 55 | using namespace google; 56 | 57 | TEST(CleanImmediately, logging) { 58 | using namespace std::chrono_literals; 59 | google::SetLogFilenameExtension(".foobar"); 60 | google::EnableLogCleaner(0h); 61 | 62 | for (unsigned i = 0; i < 1000; ++i) { 63 | LOG(INFO) << "cleanup test"; 64 | } 65 | 66 | google::DisableLogCleaner(); 67 | } 68 | 69 | int main(int argc, char** argv) { 70 | FLAGS_colorlogtostderr = false; 71 | FLAGS_timestamp_in_logfile_name = true; 72 | #ifdef GLOG_USE_GFLAGS 73 | ParseCommandLineFlags(&argc, &argv, true); 74 | #endif 75 | // Make sure stderr is not buffered as stderr seems to be buffered 76 | // on recent windows. 77 | setbuf(stderr, nullptr); 78 | 79 | // Test some basics before InitGoogleLogging: 80 | CaptureTestStderr(); 81 | const string early_stderr = GetCapturedTestStderr(); 82 | 83 | EXPECT_FALSE(IsGoogleLoggingInitialized()); 84 | 85 | InitGoogleLogging(argv[0]); 86 | 87 | EXPECT_TRUE(IsGoogleLoggingInitialized()); 88 | 89 | InitGoogleTest(&argc, argv); 90 | #ifdef HAVE_LIB_GMOCK 91 | InitGoogleMock(&argc, argv); 92 | #endif 93 | 94 | // so that death tests run before we use threads 95 | CHECK_EQ(RUN_ALL_TESTS(), 0); 96 | } 97 | -------------------------------------------------------------------------------- /src/cleanup_with_absolute_prefix_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "base/commandlineflags.h" 31 | #include "glog/logging.h" 32 | #include "glog/raw_logging.h" 33 | #include "googletest.h" 34 | 35 | #ifdef GLOG_USE_GFLAGS 36 | # include 37 | using namespace GFLAGS_NAMESPACE; 38 | #endif 39 | 40 | #ifdef HAVE_LIB_GMOCK 41 | # include 42 | 43 | # include "mock-log.h" 44 | // Introduce several symbols from gmock. 45 | using google::glog_testing::ScopedMockLog; 46 | using testing::_; 47 | using testing::AllOf; 48 | using testing::AnyNumber; 49 | using testing::HasSubstr; 50 | using testing::InitGoogleMock; 51 | using testing::StrictMock; 52 | using testing::StrNe; 53 | #endif 54 | 55 | using namespace google; 56 | 57 | TEST(CleanImmediatelyWithAbsolutePrefix, logging) { 58 | using namespace std::chrono_literals; 59 | google::EnableLogCleaner(0h); 60 | google::SetLogFilenameExtension(".barfoo"); 61 | google::SetLogDestination(GLOG_INFO, "test_cleanup_"); 62 | 63 | for (unsigned i = 0; i < 1000; ++i) { 64 | LOG(INFO) << "cleanup test"; 65 | } 66 | 67 | for (unsigned i = 0; i < 10; ++i) { 68 | LOG(ERROR) << "cleanup test"; 69 | } 70 | 71 | google::DisableLogCleaner(); 72 | } 73 | 74 | int main(int argc, char** argv) { 75 | FLAGS_colorlogtostderr = false; 76 | FLAGS_timestamp_in_logfile_name = true; 77 | #ifdef GLOG_USE_GFLAGS 78 | ParseCommandLineFlags(&argc, &argv, true); 79 | #endif 80 | // Make sure stderr is not buffered as stderr seems to be buffered 81 | // on recent windows. 82 | setbuf(stderr, nullptr); 83 | 84 | // Test some basics before InitGoogleLogging: 85 | CaptureTestStderr(); 86 | const string early_stderr = GetCapturedTestStderr(); 87 | 88 | EXPECT_FALSE(IsGoogleLoggingInitialized()); 89 | 90 | InitGoogleLogging(argv[0]); 91 | 92 | EXPECT_TRUE(IsGoogleLoggingInitialized()); 93 | 94 | InitGoogleTest(&argc, argv); 95 | #ifdef HAVE_LIB_GMOCK 96 | InitGoogleMock(&argc, argv); 97 | #endif 98 | 99 | // so that death tests run before we use threads 100 | CHECK_EQ(RUN_ALL_TESTS(), 0); 101 | } 102 | -------------------------------------------------------------------------------- /src/cleanup_with_relative_prefix_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "base/commandlineflags.h" 31 | #include "glog/logging.h" 32 | #include "glog/raw_logging.h" 33 | #include "googletest.h" 34 | 35 | #ifdef GLOG_USE_GFLAGS 36 | # include 37 | using namespace GFLAGS_NAMESPACE; 38 | #endif 39 | 40 | #ifdef HAVE_LIB_GMOCK 41 | # include 42 | 43 | # include "mock-log.h" 44 | // Introduce several symbols from gmock. 45 | using google::glog_testing::ScopedMockLog; 46 | using testing::_; 47 | using testing::AllOf; 48 | using testing::AnyNumber; 49 | using testing::HasSubstr; 50 | using testing::InitGoogleMock; 51 | using testing::StrictMock; 52 | using testing::StrNe; 53 | #endif 54 | 55 | using namespace google; 56 | 57 | TEST(CleanImmediatelyWithRelativePrefix, logging) { 58 | using namespace std::chrono_literals; 59 | google::EnableLogCleaner(0h); 60 | google::SetLogFilenameExtension(".relativefoo"); 61 | google::SetLogDestination(GLOG_INFO, "test_subdir/test_cleanup_"); 62 | 63 | for (unsigned i = 0; i < 1000; ++i) { 64 | LOG(INFO) << "cleanup test"; 65 | } 66 | 67 | google::DisableLogCleaner(); 68 | } 69 | 70 | int main(int argc, char** argv) { 71 | FLAGS_colorlogtostderr = false; 72 | FLAGS_timestamp_in_logfile_name = true; 73 | #ifdef GLOG_USE_GFLAGS 74 | ParseCommandLineFlags(&argc, &argv, true); 75 | #endif 76 | // Make sure stderr is not buffered as stderr seems to be buffered 77 | // on recent windows. 78 | setbuf(stderr, nullptr); 79 | 80 | // Test some basics before InitGoogleLogging: 81 | CaptureTestStderr(); 82 | const string early_stderr = GetCapturedTestStderr(); 83 | 84 | EXPECT_FALSE(IsGoogleLoggingInitialized()); 85 | 86 | InitGoogleLogging(argv[0]); 87 | 88 | EXPECT_TRUE(IsGoogleLoggingInitialized()); 89 | 90 | InitGoogleTest(&argc, argv); 91 | #ifdef HAVE_LIB_GMOCK 92 | InitGoogleMock(&argc, argv); 93 | #endif 94 | 95 | // so that death tests run before we use threads 96 | CHECK_EQ(RUN_ALL_TESTS(), 0); 97 | } 98 | -------------------------------------------------------------------------------- /src/config.h.cmake.in: -------------------------------------------------------------------------------- 1 | #ifndef GLOG_CONFIG_H 2 | #define GLOG_CONFIG_H 3 | 4 | /* Define if you have the `dladdr' function */ 5 | #cmakedefine HAVE_DLADDR 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #cmakedefine HAVE_DLFCN_H 9 | 10 | /* Define if you have the `backtrace' function in */ 11 | #cmakedefine HAVE_EXECINFO_BACKTRACE 12 | 13 | /* Define if you have the `backtrace_symbols' function in */ 14 | #cmakedefine HAVE_EXECINFO_BACKTRACE_SYMBOLS 15 | 16 | /* Define if you have the `fcntl' function */ 17 | #cmakedefine HAVE_FCNTL 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #cmakedefine HAVE_GLOB_H 21 | 22 | /* define if you have google gmock library */ 23 | #cmakedefine HAVE_LIB_GMOCK 24 | 25 | /* define if you have google gtest library */ 26 | #cmakedefine HAVE_LIB_GTEST 27 | 28 | /* define if you have dbghelp library */ 29 | #cmakedefine HAVE_DBGHELP 30 | 31 | /* Define if you have the 'pread' function */ 32 | #cmakedefine HAVE_PREAD 33 | 34 | /* Define if you have the 'posix_fadvise' function in */ 35 | #cmakedefine HAVE_POSIX_FADVISE 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #cmakedefine HAVE_PWD_H 39 | 40 | /* Define if you have the 'pwrite' function */ 41 | #cmakedefine HAVE_PWRITE 42 | 43 | /* Define if you have the 'sigaction' function */ 44 | #cmakedefine HAVE_SIGACTION 45 | 46 | /* Define if you have the `sigaltstack' function */ 47 | #cmakedefine HAVE_SIGALTSTACK 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #cmakedefine HAVE_SYSCALL_H 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #cmakedefine HAVE_SYSLOG_H 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #cmakedefine HAVE_ELF_H 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #cmakedefine HAVE_SYS_EXEC_ELF_H 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #cmakedefine HAVE_LINK_H 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #cmakedefine HAVE_SYS_SYSCALL_H 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #cmakedefine HAVE_SYS_TIME_H 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #cmakedefine HAVE_SYS_TYPES_H 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #cmakedefine HAVE_SYS_UCONTEXT_H 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #cmakedefine HAVE_SYS_UTSNAME_H 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #cmakedefine HAVE_SYS_WAIT_H 81 | 82 | /* Define to 1 if you have the header file. */ 83 | #cmakedefine HAVE_UCONTEXT_H 84 | 85 | /* Define to 1 if you have the header file. */ 86 | #cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H} 87 | 88 | /* define if you have unwind */ 89 | #cmakedefine HAVE_UNWIND 90 | 91 | /* define if you have libunwind */ 92 | #cmakedefine HAVE_LIBUNWIND 93 | 94 | /* define if symbolize support is available */ 95 | #cmakedefine HAVE_SYMBOLIZE 96 | 97 | /* define if localtime_r is available in time.h */ 98 | #cmakedefine HAVE_LOCALTIME_R 99 | 100 | /* define if gmtime_r is available in time.h */ 101 | #cmakedefine HAVE_GMTIME_R 102 | 103 | /* define if _chsize_s is available in io.h */ 104 | #cmakedefine HAVE__CHSIZE_S 105 | 106 | /* define if ssize_t is defined */ 107 | #cmakedefine HAVE_SSIZE_T 108 | 109 | /* define if mode_t is defined */ 110 | #cmakedefine HAVE_MODE_T 111 | 112 | /* How to access the PC from a struct ucontext */ 113 | #cmakedefine PC_FROM_UCONTEXT ${PC_FROM_UCONTEXT} 114 | 115 | /* define if we should print file offsets in traces instead of symbolizing. */ 116 | #cmakedefine PRINT_UNSYMBOLIZED_STACK_TRACES 117 | 118 | /* The size of `void *', as computed by sizeof. */ 119 | #cmakedefine SIZEOF_VOID_P ${SIZEOF_VOID_P} 120 | 121 | /* location of source code */ 122 | #cmakedefine TEST_SRC_DIR ${TEST_SRC_DIR} 123 | 124 | /* Define if thread-local storage is enabled. */ 125 | #cmakedefine GLOG_THREAD_LOCAL_STORAGE 126 | 127 | /* define if abi::__cxa_demangle is available in cxxabi.h */ 128 | #cmakedefine HAVE___CXA_DEMANGLE 129 | 130 | /* define if __argv is available in cstdlib */ 131 | #cmakedefine HAVE___ARGV 132 | 133 | /* define if __progname is available */ 134 | #cmakedefine HAVE___PROGNAME 135 | 136 | /* define if getprogname is available in cstdlib */ 137 | #cmakedefine HAVE_GETPROGNAME 138 | 139 | /* define if program_invocation_short_name is available in cerrno */ 140 | #cmakedefine HAVE_PROGRAM_INVOCATION_SHORT_NAME 141 | 142 | #endif // GLOG_CONFIG_H 143 | -------------------------------------------------------------------------------- /src/dcheck_unittest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | project (glog_log_severity LANGUAGES CXX) 3 | 4 | find_package (glog REQUIRED NO_MODULE) 5 | 6 | add_executable (glog_dcheck glog_dcheck.cc) 7 | target_link_libraries (glog_dcheck PRIVATE glog::glog) 8 | -------------------------------------------------------------------------------- /src/dcheck_unittest/glog_dcheck.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Sergiu Deitsch 31 | 32 | #include 33 | 34 | int main(int /*argc*/, char** argv) { 35 | google::InitGoogleLogging(argv[0]); 36 | google::InstallFailureSignalHandler(); 37 | 38 | #if defined(_MSC_VER) 39 | // Avoid presenting an interactive dialog that will cause the test to time 40 | // out. 41 | _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); 42 | #endif // defined(_MSC_VER) 43 | 44 | DLOG(INFO) << "no output"; 45 | DLOG(WARNING) << "no output"; 46 | DLOG(ERROR) << "no output"; 47 | 48 | // Must not fail in release build 49 | DLOG_ASSERT(false); 50 | 51 | // Must be the last expression 52 | DLOG(FATAL) << "no output"; 53 | } 54 | -------------------------------------------------------------------------------- /src/demangle.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Satoru Takabayashi 31 | // 32 | // An async-signal-safe and thread-safe demangler for Itanium C++ ABI 33 | // (aka G++ V3 ABI). 34 | 35 | // The demangler is implemented to be used in async signal handlers to 36 | // symbolize stack traces. We cannot use libstdc++'s 37 | // abi::__cxa_demangle() in such signal handlers since it's not async 38 | // signal safe (it uses malloc() internally). 39 | // 40 | // Note that this demangler doesn't support full demangling. More 41 | // specifically, it doesn't print types of function parameters and 42 | // types of template arguments. It just skips them. However, it's 43 | // still very useful to extract basic information such as class, 44 | // function, constructor, destructor, and operator names. 45 | // 46 | // See the implementation note in demangle.cc if you are interested. 47 | // 48 | // Example: 49 | // 50 | // | Mangled Name | The Demangler | abi::__cxa_demangle() 51 | // |---------------|---------------|----------------------- 52 | // | _Z1fv | f() | f() 53 | // | _Z1fi | f() | f(int) 54 | // | _Z3foo3bar | foo() | foo(bar) 55 | // | _Z1fIiEvi | f<>() | void f(int) 56 | // | _ZN1N1fE | N::f | N::f 57 | // | _ZN3Foo3BarEv | Foo::Bar() | Foo::Bar() 58 | // | _Zrm1XS_" | operator%() | operator%(X, X) 59 | // | _ZN3FooC1Ev | Foo::Foo() | Foo::Foo() 60 | // | _Z1fSs | f() | f(std::basic_string, 62 | // | | | std::allocator >) 63 | // 64 | // See the unit test for more examples. 65 | // 66 | // Note: we might want to write demanglers for ABIs other than Itanium 67 | // C++ ABI in the future. 68 | // 69 | 70 | #ifndef GLOG_INTERNAL_DEMANGLE_H 71 | #define GLOG_INTERNAL_DEMANGLE_H 72 | 73 | #include 74 | 75 | #if defined(GLOG_USE_GLOG_EXPORT) 76 | # include "glog/export.h" 77 | #endif 78 | 79 | #if !defined(GLOG_NO_EXPORT) 80 | # error "demangle.h" was not included correctly. 81 | #endif 82 | 83 | namespace google { 84 | inline namespace glog_internal_namespace_ { 85 | 86 | // Demangle "mangled". On success, return true and write the 87 | // demangled symbol name to "out". Otherwise, return false. 88 | // "out" is modified even if demangling is unsuccessful. 89 | bool GLOG_NO_EXPORT Demangle(const char* mangled, char* out, size_t out_size); 90 | 91 | } // namespace glog_internal_namespace_ 92 | } // namespace google 93 | 94 | #endif // GLOG_INTERNAL_DEMANGLE_H 95 | -------------------------------------------------------------------------------- /src/demangle_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Satoru Takabayashi 31 | // 32 | // Unit tests for functions in demangle.c. 33 | 34 | #include "demangle.h" 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "config.h" 41 | #include "glog/logging.h" 42 | #include "googletest.h" 43 | #include "utilities.h" 44 | 45 | #ifdef GLOG_USE_GFLAGS 46 | # include 47 | using namespace GFLAGS_NAMESPACE; 48 | #endif 49 | 50 | GLOG_DEFINE_bool(demangle_filter, false, 51 | "Run demangle_unittest in filter mode"); 52 | 53 | using namespace std; 54 | using namespace google; 55 | 56 | // A wrapper function for Demangle() to make the unit test simple. 57 | static const char* DemangleIt(const char* const mangled) { 58 | static char demangled[4096]; 59 | if (Demangle(mangled, demangled, sizeof(demangled))) { 60 | return demangled; 61 | } else { 62 | return mangled; 63 | } 64 | } 65 | 66 | #if defined(GLOG_OS_WINDOWS) 67 | 68 | # if defined(HAVE_DBGHELP) && !defined(NDEBUG) 69 | TEST(Demangle, Windows) { 70 | EXPECT_STREQ("public: static void __cdecl Foo::func(int)", 71 | DemangleIt("?func@Foo@@SAXH@Z")); 72 | EXPECT_STREQ("public: static void __cdecl Foo::func(int)", 73 | DemangleIt("@ILT+1105(?func@Foo@@SAXH@Z)")); 74 | EXPECT_STREQ("int __cdecl foobarArray(int * const)", 75 | DemangleIt("?foobarArray@@YAHQAH@Z")); 76 | } 77 | # endif 78 | 79 | #else 80 | 81 | // Test corner cases of boundary conditions. 82 | TEST(Demangle, CornerCases) { 83 | const size_t size = 10; 84 | char tmp[size] = {0}; 85 | const char* demangled = "foobar()"; 86 | const char* mangled = "_Z6foobarv"; 87 | EXPECT_TRUE(Demangle(mangled, tmp, sizeof(tmp))); 88 | // sizeof("foobar()") == size - 1 89 | EXPECT_STREQ(demangled, tmp); 90 | EXPECT_TRUE(Demangle(mangled, tmp, size - 1)); 91 | EXPECT_STREQ(demangled, tmp); 92 | EXPECT_FALSE(Demangle(mangled, tmp, size - 2)); // Not enough. 93 | EXPECT_FALSE(Demangle(mangled, tmp, 1)); 94 | EXPECT_FALSE(Demangle(mangled, tmp, 0)); 95 | EXPECT_FALSE(Demangle(mangled, nullptr, 0)); // Should not cause SEGV. 96 | } 97 | 98 | // Test handling of functions suffixed with .clone.N, which is used by GCC 99 | // 4.5.x, and .constprop.N and .isra.N, which are used by GCC 4.6.x. These 100 | // suffixes are used to indicate functions which have been cloned during 101 | // optimization. We ignore these suffixes. 102 | TEST(Demangle, Clones) { 103 | char tmp[20]; 104 | EXPECT_TRUE(Demangle("_ZL3Foov", tmp, sizeof(tmp))); 105 | EXPECT_STREQ("Foo()", tmp); 106 | EXPECT_TRUE(Demangle("_ZL3Foov.clone.3", tmp, sizeof(tmp))); 107 | EXPECT_STREQ("Foo()", tmp); 108 | EXPECT_TRUE(Demangle("_ZL3Foov.constprop.80", tmp, sizeof(tmp))); 109 | EXPECT_STREQ("Foo()", tmp); 110 | EXPECT_TRUE(Demangle("_ZL3Foov.isra.18", tmp, sizeof(tmp))); 111 | EXPECT_STREQ("Foo()", tmp); 112 | EXPECT_TRUE(Demangle("_ZL3Foov.isra.2.constprop.18", tmp, sizeof(tmp))); 113 | EXPECT_STREQ("Foo()", tmp); 114 | // Invalid (truncated), should not demangle. 115 | EXPECT_FALSE(Demangle("_ZL3Foov.clo", tmp, sizeof(tmp))); 116 | // Invalid (.clone. not followed by number), should not demangle. 117 | EXPECT_FALSE(Demangle("_ZL3Foov.clone.", tmp, sizeof(tmp))); 118 | // Invalid (.clone. followed by non-number), should not demangle. 119 | EXPECT_FALSE(Demangle("_ZL3Foov.clone.foo", tmp, sizeof(tmp))); 120 | // Invalid (.constprop. not followed by number), should not demangle. 121 | EXPECT_FALSE(Demangle("_ZL3Foov.isra.2.constprop.", tmp, sizeof(tmp))); 122 | } 123 | 124 | TEST(Demangle, FromFile) { 125 | string test_file = FLAGS_test_srcdir + "/src/demangle_unittest.txt"; 126 | ifstream f(test_file.c_str()); // The file should exist. 127 | EXPECT_FALSE(f.fail()); 128 | 129 | string line; 130 | while (getline(f, line)) { 131 | // Lines start with '#' are considered as comments. 132 | if (line.empty() || line[0] == '#') { 133 | continue; 134 | } 135 | // Each line should contain a mangled name and a demangled name 136 | // separated by '\t'. Example: "_Z3foo\tfoo" 137 | string::size_type tab_pos = line.find('\t'); 138 | EXPECT_NE(string::npos, tab_pos); 139 | string mangled = line.substr(0, tab_pos); 140 | string demangled = line.substr(tab_pos + 1); 141 | EXPECT_EQ(demangled, DemangleIt(mangled.c_str())); 142 | } 143 | } 144 | 145 | #endif 146 | 147 | int main(int argc, char** argv) { 148 | InitGoogleTest(&argc, argv); 149 | #ifdef GLOG_USE_GFLAGS 150 | ParseCommandLineFlags(&argc, &argv, true); 151 | #endif 152 | 153 | FLAGS_logtostderr = true; 154 | InitGoogleLogging(argv[0]); 155 | if (FLAGS_demangle_filter) { 156 | // Read from cin and write to cout. 157 | string line; 158 | while (getline(cin, line, '\n')) { 159 | cout << DemangleIt(line.c_str()) << endl; 160 | } 161 | return 0; 162 | } else if (argc > 1) { 163 | cout << DemangleIt(argv[1]) << endl; 164 | return 0; 165 | } else { 166 | return RUN_ALL_TESTS(); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /src/demangle_unittest.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Copyright (c) 2006, Google Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | # 32 | # Author: Satoru Takabayashi 33 | # 34 | # Unit tests for demangle.c with a real binary. 35 | 36 | set -e 37 | 38 | die () { 39 | echo $1 40 | exit 1 41 | } 42 | 43 | BINDIR=".libs" 44 | LIBGLOG="$BINDIR/libglog.so" 45 | 46 | DEMANGLER="$BINDIR/demangle_unittest" 47 | 48 | if test -e "$DEMANGLER"; then 49 | # We need shared object. 50 | export LD_LIBRARY_PATH=$BINDIR 51 | export DYLD_LIBRARY_PATH=$BINDIR 52 | else 53 | # For windows 54 | DEMANGLER="./demangle_unittest.exe" 55 | if ! test -e "$DEMANGLER"; then 56 | echo "We coundn't find demangle_unittest binary." 57 | exit 1 58 | fi 59 | fi 60 | 61 | # Extract C++ mangled symbols from libbase.so. 62 | NM_OUTPUT="demangle.nm" 63 | nm "$LIBGLOG" | perl -nle 'print $1 if /\s(_Z\S+$)/' > "$NM_OUTPUT" 64 | 65 | # Check if mangled symbols exist. If there are none, we quit. 66 | # The binary is more likely compiled with GCC 2.95 or something old. 67 | if ! grep --quiet '^_Z' "$NM_OUTPUT"; then 68 | echo "PASS" 69 | exit 0 70 | fi 71 | 72 | # Demangle the symbols using our demangler. 73 | DM_OUTPUT="demangle.dm" 74 | GLOG_demangle_filter=1 "$DEMANGLER" --demangle_filter < "$NM_OUTPUT" > "$DM_OUTPUT" 75 | 76 | # Calculate the numbers of lines. 77 | NM_LINES=`wc -l "$NM_OUTPUT" | awk '{ print $1 }'` 78 | DM_LINES=`wc -l "$DM_OUTPUT" | awk '{ print $1 }'` 79 | 80 | # Compare the numbers of lines. They must be the same. 81 | if test "$NM_LINES" != "$DM_LINES"; then 82 | die "$NM_OUTPUT and $DM_OUTPUT don't have the same numbers of lines" 83 | fi 84 | 85 | # Check if mangled symbols exist. They must not exist. 86 | if grep --quiet '^_Z' "$DM_OUTPUT"; then 87 | MANGLED=`grep '^_Z' "$DM_OUTPUT" | wc -l | awk '{ print \$1 }'` 88 | echo "Mangled symbols ($MANGLED out of $NM_LINES) found in $DM_OUTPUT:" 89 | grep '^_Z' "$DM_OUTPUT" 90 | die "Mangled symbols ($MANGLED out of $NM_LINES) found in $DM_OUTPUT" 91 | fi 92 | 93 | # All C++ symbols are demangled successfully. 94 | echo "PASS" 95 | exit 0 96 | -------------------------------------------------------------------------------- /src/demangle_unittest.txt: -------------------------------------------------------------------------------- 1 | # Test caces for demangle_unittest. Each line consists of a 2 | # tab-separated pair of mangled and demangled symbol names. 3 | 4 | # Constructors and destructors. 5 | _ZN3FooC1Ev Foo::Foo() 6 | _ZN3FooD1Ev Foo::~Foo() 7 | _ZNSoD0Ev std::ostream::~ostream() 8 | 9 | # G++ extensions. 10 | _ZTCN10LogMessage9LogStreamE0_So LogMessage::LogStream 11 | _ZTv0_n12_N10LogMessage9LogStreamD0Ev LogMessage::LogStream::~LogStream() 12 | _ZThn4_N7icu_3_410UnicodeSetD0Ev icu_3_4::UnicodeSet::~UnicodeSet() 13 | 14 | # A bug in g++'s C++ ABI version 2 (-fabi-version=2). 15 | _ZN7NSSInfoI5groupjjXadL_Z10getgrgid_rEELZ19nss_getgrgid_r_nameEEC1Ei NSSInfo<>::NSSInfo() 16 | 17 | # C linkage symbol names. Should keep them untouched. 18 | main main 19 | Demangle Demangle 20 | _ZERO _ZERO 21 | 22 | # Cast operator. 23 | _Zcviv operator int() 24 | _ZN3foocviEv foo::operator int() 25 | 26 | # Versioned symbols. 27 | _Z3Foo@GLIBCXX_3.4 Foo@GLIBCXX_3.4 28 | _Z3Foo@@GLIBCXX_3.4 Foo@@GLIBCXX_3.4 29 | 30 | # Abbreviations. 31 | _ZNSaE std::allocator 32 | _ZNSbE std::basic_string 33 | _ZNSdE std::iostream 34 | _ZNSiE std::istream 35 | _ZNSoE std::ostream 36 | _ZNSsE std::string 37 | 38 | # Substitutions. We just replace them with ?. 39 | _ZN3fooS_E foo::? 40 | _ZN3foo3barS0_E foo::bar::? 41 | _ZNcvT_IiEEv operator ?<>() 42 | 43 | # "<< <" case. 44 | _ZlsI3fooE operator<< <> 45 | 46 | # ABI tags. 47 | _Z1AB3barB3foo A 48 | _ZN3fooL3barB5cxx11E foo::bar 49 | 50 | # Random things we found interesting. 51 | _ZN3FooISt6vectorISsSaISsEEEclEv Foo<>::operator()() 52 | _ZTI9Callback1IiE Callback1<> 53 | _ZN7icu_3_47UMemorynwEj icu_3_4::UMemory::operator new() 54 | _ZNSt6vectorIbE9push_backE std::vector<>::push_back 55 | _ZNSt6vectorIbSaIbEE9push_backEb std::vector<>::push_back() 56 | _ZlsRSoRK15PRIVATE_Counter operator<<() 57 | _ZSt6fill_nIPPN9__gnu_cxx15_Hashtable_nodeISt4pairIKPKcjEEEjS8_ET_SA_T0_RKT1_ std::fill_n<>() 58 | _ZZ3FoovE3Bar Foo()::Bar 59 | _ZGVZ7UpTimervE8up_timer UpTimer()::up_timer 60 | 61 | # Test cases from gcc-4.1.0/libstdc++-v3/testsuite/demangle. 62 | # Collected by: 63 | # % grep verify_demangle **/*.cc | perl -nle 'print $1 if /"(_Z.*?)"/' | 64 | # sort | uniq 65 | # 66 | # Note that the following symbols are invalid. 67 | # That's why they are not demangled. 68 | # - _ZNZN1N1fEiE1X1gE 69 | # - _ZNZN1N1fEiE1X1gEv 70 | # - _Z1xINiEE 71 | _Z1fA37_iPS_ f() 72 | _Z1fAszL_ZZNK1N1A1fEvE3foo_0E_i f() 73 | _Z1fI1APS0_PKS0_EvT_T0_T1_PA4_S3_M1CS8_ f<>() 74 | _Z1fI1XENT_1tES2_ f<>() 75 | _Z1fI1XEvPVN1AIT_E1TE f<>() 76 | _Z1fILi1ELc120EEv1AIXplT_cviLd4028ae147ae147aeEEE f<>() 77 | _Z1fILi1ELc120EEv1AIXplT_cviLf3f800000EEE f<>() 78 | _Z1fILi5E1AEvN1CIXqugtT_Li0ELi1ELi2EEE1qE f<>() 79 | _Z1fILi5E1AEvN1CIXstN1T1tEEXszsrS2_1tEE1qE f<>() 80 | _Z1fILi5EEvN1AIXcvimlT_Li22EEE1qE f<>() 81 | _Z1fIiEvi f<>() 82 | _Z1fKPFiiE f() 83 | _Z1fM1AFivEPS0_ f() 84 | _Z1fM1AKFivE f() 85 | _Z1fM1AKFvvE f() 86 | _Z1fPFPA1_ivE f() 87 | _Z1fPFYPFiiEiE f() 88 | _Z1fPFvvEM1SFvvE f() 89 | _Z1fPKM1AFivE f() 90 | _Z1fi f() 91 | _Z1fv f() 92 | _Z1jM1AFivEPS1_ j() 93 | _Z1rM1GFivEMS_KFivES_M1HFivES1_4whatIKS_E5what2IS8_ES3_ r() 94 | _Z1sPA37_iPS0_ s() 95 | _Z1xINiEE _Z1xINiEE 96 | _Z3absILi11EEvv abs<>() 97 | _Z3foo3bar foo() 98 | _Z3foo5Hello5WorldS0_S_ foo() 99 | _Z3fooA30_A_i foo() 100 | _Z3fooIA6_KiEvA9_KT_rVPrS4_ foo<>() 101 | _Z3fooILi2EEvRAplT_Li1E_i foo<>() 102 | _Z3fooIiFvdEiEvv foo<>() 103 | _Z3fooPM2ABi foo() 104 | _Z3fooc foo() 105 | _Z3fooiPiPS_PS0_PS1_PS2_PS3_PS4_PS5_PS6_PS7_PS8_PS9_PSA_PSB_PSC_ foo() 106 | _Z3kooPA28_A30_i koo() 107 | _Z4makeI7FactoryiET_IT0_Ev make<>() 108 | _Z5firstI3DuoEvS0_ first<>() 109 | _Z5firstI3DuoEvT_ first<>() 110 | _Z9hairyfuncM1YKFPVPFrPA2_PM1XKFKPA3_ilEPcEiE hairyfunc() 111 | _ZGVN5libcw24_GLOBAL__N_cbll.cc0ZhUKa23compiler_bug_workaroundISt6vectorINS_13omanip_id_tctINS_5debug32memblk_types_manipulator_data_ctEEESaIS6_EEE3idsE libcw::(anonymous namespace)::compiler_bug_workaround<>::ids 112 | _ZN12libcw_app_ct10add_optionIS_EEvMT_FvPKcES3_cS3_S3_ libcw_app_ct::add_option<>() 113 | _ZN1AIfEcvT_IiEEv A<>::operator ?<>() 114 | _ZN1N1TIiiE2mfES0_IddE N::T<>::mf() 115 | _ZN1N1fE N::f 116 | _ZN1f1fE f::f 117 | _ZN3FooIA4_iE3barE Foo<>::bar 118 | _ZN5Arena5levelE Arena::level 119 | _ZN5StackIiiE5levelE Stack<>::level 120 | _ZN5libcw5debug13cwprint_usingINS_9_private_12GlobalObjectEEENS0_17cwprint_using_tctIT_EERKS5_MS5_KFvRSt7ostreamE libcw::debug::cwprint_using<>() 121 | _ZN6System5Sound4beepEv System::Sound::beep() 122 | _ZNKSt14priority_queueIP27timer_event_request_base_ctSt5dequeIS1_SaIS1_EE13timer_greaterE3topEv std::priority_queue<>::top() 123 | _ZNKSt15_Deque_iteratorIP15memory_block_stRKS1_PS2_EeqERKS5_ std::_Deque_iterator<>::operator==() 124 | _ZNKSt17__normal_iteratorIPK6optionSt6vectorIS0_SaIS0_EEEmiERKS6_ std::__normal_iterator<>::operator-() 125 | _ZNSbIcSt11char_traitsIcEN5libcw5debug27no_alloc_checking_allocatorEE12_S_constructIPcEES6_T_S7_RKS3_ std::basic_string<>::_S_construct<>() 126 | _ZNSt13_Alloc_traitsISbIcSt18string_char_traitsIcEN5libcw5debug9_private_17allocator_adaptorIcSt24__default_alloc_templateILb0ELi327664EELb1EEEENS5_IS9_S7_Lb1EEEE15_S_instancelessE std::_Alloc_traits<>::_S_instanceless 127 | _ZNSt3_In4wardE std::_In::ward 128 | _ZNZN1N1fEiE1X1gE _ZNZN1N1fEiE1X1gE 129 | _ZNZN1N1fEiE1X1gEv _ZNZN1N1fEiE1X1gEv 130 | _ZSt1BISt1DIP1ARKS2_PS3_ES0_IS2_RS2_PS2_ES2_ET0_T_SB_SA_PT1_ std::B<>() 131 | _ZSt5state std::state 132 | _ZTI7a_class a_class 133 | _ZZN1N1fEiE1p N::f()::p 134 | _ZZN1N1fEiEs N::f() 135 | _ZlsRK1XS1_ operator<<() 136 | _ZlsRKU3fooU4bart1XS0_ operator<<() 137 | _ZlsRKU3fooU4bart1XS2_ operator<<() 138 | _ZlsRSoRKSs operator<<() 139 | _ZngILi42EEvN1AIXplT_Li2EEE1TE operator-<>() 140 | _ZplR1XS0_ operator+() 141 | _Zrm1XS_ operator%() 142 | 143 | # Template argument packs can start with I or J. 144 | _Z3addIIiEEvDpT_ add<>() 145 | _Z3addIJiEEvDpT_ add<>() 146 | 147 | # Nested templates with pack expansion 148 | _ZSt13__invoke_implIvPFvPiEJDnEET_St14__invoke_otherOT0_DpOT1_ std::__invoke_impl<>() 149 | _ZSt8__invokeIPFvPiEJDnEENSt15__invoke_resultIT_JDpT0_EE4typeEOS4_DpOS5_ std::__invoke<>() 150 | _ZNSt6thread8_InvokerISt5tupleIJPFvPiEDnEEE9_M_invokeIJLm0ELm1EEEEvSt12_Index_tupleIJXspT_EEE std::thread::_Invoker<>::_M_invoke<>() 151 | _ZNSt6thread8_InvokerISt5tupleIJPFvPiEDnEEEclEv std::thread::_Invoker<>::operator()() 152 | _ZNSt6thread11_State_implINS_8_InvokerISt5tupleIJPFvPiEDnEEEEE6_M_runEv std::thread::_State_impl<>::_M_run() 153 | -------------------------------------------------------------------------------- /src/fuzz_demangle.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2023 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //////////////////////////////////////////////////////////////////////////////// 16 | 17 | #include 18 | 19 | #include "demangle.h" 20 | 21 | extern "C" int LLVMFuzzerTestOneInput(const unsigned char* Data, 22 | unsigned Size) { 23 | if (Size >= 4095) { 24 | return 0; 25 | } 26 | char Buffer[Size + 1]; 27 | std::memcpy(Buffer, Data, Size); 28 | Buffer[Size] = 0; 29 | char demangled[4096]; 30 | google::Demangle(Buffer, demangled, Size); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/glog/log_severity.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef BASE_LOG_SEVERITY_H__ 31 | #define BASE_LOG_SEVERITY_H__ 32 | 33 | #if defined(GLOG_USE_GLOG_EXPORT) 34 | # include "glog/export.h" 35 | #endif 36 | 37 | #if !defined(GLOG_EXPORT) 38 | # error was not included correctly. See the documentation for how to consume the library. 39 | #endif 40 | 41 | namespace google { 42 | 43 | // The recommended semantics of the log levels are as follows: 44 | // 45 | // INFO: 46 | // Use for state changes or other major events, or to aid debugging. 47 | // WARNING: 48 | // Use for undesired but relatively expected events, which may indicate a 49 | // problem 50 | // ERROR: 51 | // Use for undesired and unexpected events that the program can recover from. 52 | // All ERRORs should be actionable - it should be appropriate to file a bug 53 | // whenever an ERROR occurs in production. 54 | // FATAL: 55 | // Use for undesired and unexpected events that the program cannot recover 56 | // from. 57 | 58 | // Variables of type LogSeverity are widely taken to lie in the range 59 | // [0, NUM_SEVERITIES-1]. Be careful to preserve this assumption if 60 | // you ever need to change their values or add a new severity. 61 | 62 | enum LogSeverity { 63 | GLOG_INFO = 0, 64 | GLOG_WARNING = 1, 65 | GLOG_ERROR = 2, 66 | GLOG_FATAL = 3, 67 | #ifndef GLOG_NO_ABBREVIATED_SEVERITIES 68 | # ifdef ERROR 69 | # error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail. 70 | # endif 71 | INFO = GLOG_INFO, 72 | WARNING = GLOG_WARNING, 73 | ERROR = GLOG_ERROR, 74 | FATAL = GLOG_FATAL 75 | #endif 76 | }; 77 | 78 | #if defined(__cpp_inline_variables) 79 | # if (__cpp_inline_variables >= 201606L) 80 | # define GLOG_INLINE_VARIABLE inline 81 | # endif // (__cpp_inline_variables >= 201606L) 82 | #endif // defined(__cpp_inline_variables) 83 | 84 | #if !defined(GLOG_INLINE_VARIABLE) 85 | # define GLOG_INLINE_VARIABLE 86 | #endif // !defined(GLOG_INLINE_VARIABLE) 87 | 88 | GLOG_INLINE_VARIABLE 89 | constexpr int NUM_SEVERITIES = 4; 90 | 91 | // DFATAL is FATAL in debug mode, ERROR in normal mode 92 | #ifdef NDEBUG 93 | # define DFATAL_LEVEL ERROR 94 | #else 95 | # define DFATAL_LEVEL FATAL 96 | #endif 97 | 98 | // NDEBUG usage helpers related to (RAW_)DCHECK: 99 | // 100 | // DEBUG_MODE is for small !NDEBUG uses like 101 | // if (DEBUG_MODE) foo.CheckThatFoo(); 102 | // instead of substantially more verbose 103 | // #ifndef NDEBUG 104 | // foo.CheckThatFoo(); 105 | // #endif 106 | // 107 | // IF_DEBUG_MODE is for small !NDEBUG uses like 108 | // IF_DEBUG_MODE( string error; ) 109 | // DCHECK(Foo(&error)) << error; 110 | // instead of substantially more verbose 111 | // #ifndef NDEBUG 112 | // string error; 113 | // DCHECK(Foo(&error)) << error; 114 | // #endif 115 | // 116 | #ifdef NDEBUG 117 | enum { DEBUG_MODE = 0 }; 118 | # define IF_DEBUG_MODE(x) 119 | #else 120 | enum { DEBUG_MODE = 1 }; 121 | # define IF_DEBUG_MODE(x) x 122 | #endif 123 | 124 | } // namespace google 125 | 126 | #endif // BASE_LOG_SEVERITY_H__ 127 | -------------------------------------------------------------------------------- /src/glog/platform.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Shinichiro Hamaji 31 | // 32 | // Detect supported platforms. 33 | 34 | #ifndef GLOG_PLATFORM_H 35 | #define GLOG_PLATFORM_H 36 | 37 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) 38 | # define GLOG_OS_WINDOWS 39 | #elif defined(__CYGWIN__) || defined(__CYGWIN32__) 40 | # define GLOG_OS_CYGWIN 41 | #elif defined(linux) || defined(__linux) || defined(__linux__) 42 | # define GLOG_OS_LINUX 43 | # if defined(__ANDROID__) 44 | # define GLOG_OS_ANDROID 45 | # endif 46 | #elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) 47 | # define GLOG_OS_MACOSX 48 | #elif defined(__FreeBSD__) 49 | # define GLOG_OS_FREEBSD 50 | #elif defined(__NetBSD__) 51 | # define GLOG_OS_NETBSD 52 | #elif defined(__OpenBSD__) 53 | # define GLOG_OS_OPENBSD 54 | #elif defined(__EMSCRIPTEN__) 55 | # define GLOG_OS_EMSCRIPTEN 56 | #else 57 | // TODO(hamaji): Add other platforms. 58 | #error Platform not supported by glog. Please consider to contribute platform information by submitting a pull request on Github. 59 | #endif 60 | 61 | #endif // GLOG_PLATFORM_H 62 | -------------------------------------------------------------------------------- /src/glog/types.h: -------------------------------------------------------------------------------- 1 | 2 | // Copyright (c) 2024, Google Inc. 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // 31 | 32 | #ifndef GLOG_TYPES_H 33 | #define GLOG_TYPES_H 34 | 35 | #include 36 | #include 37 | 38 | namespace google { 39 | 40 | using int32 = std::int32_t; 41 | using uint32 = std::uint32_t; 42 | using int64 = std::int64_t; 43 | using uint64 = std::uint64_t; 44 | 45 | } // namespace google 46 | 47 | #if defined(__has_feature) 48 | # if __has_feature(thread_sanitizer) 49 | # define GLOG_SANITIZE_THREAD 1 50 | # endif 51 | #endif 52 | 53 | #if !defined(GLOG_SANITIZE_THREAD) && defined(__SANITIZE_THREAD__) && \ 54 | __SANITIZE_THREAD__ 55 | # define GLOG_SANITIZE_THREAD 1 56 | #endif 57 | 58 | #if defined(GLOG_SANITIZE_THREAD) 59 | # define GLOG_IFDEF_THREAD_SANITIZER(X) X 60 | #else 61 | # define GLOG_IFDEF_THREAD_SANITIZER(X) 62 | #endif 63 | 64 | #if defined(_MSC_VER) 65 | # define GLOG_MSVC_PUSH_DISABLE_WARNING(n) \ 66 | __pragma(warning(push)) __pragma(warning(disable : n)) 67 | # define GLOG_MSVC_POP_WARNING() __pragma(warning(pop)) 68 | #else 69 | # define GLOG_MSVC_PUSH_DISABLE_WARNING(n) 70 | # define GLOG_MSVC_POP_WARNING() 71 | #endif 72 | 73 | #if defined(GLOG_SANITIZE_THREAD) 74 | // We need to identify the static variables as "benign" races 75 | // to avoid noisy reports from TSAN. 76 | extern "C" void AnnotateBenignRaceSized(const char* file, int line, 77 | const volatile void* mem, size_t size, 78 | const char* description); 79 | #endif // defined(GLOG_SANITIZE_THREAD) 80 | 81 | #endif // GLOG_TYPES_H 82 | -------------------------------------------------------------------------------- /src/glog/vlog_is_on.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Ray Sidney and many others 31 | // 32 | // Defines the VLOG_IS_ON macro that controls the variable-verbosity 33 | // conditional logging. 34 | // 35 | // It's used by VLOG and VLOG_IF in logging.h 36 | // and by RAW_VLOG in raw_logging.h to trigger the logging. 37 | // 38 | // It can also be used directly e.g. like this: 39 | // if (VLOG_IS_ON(2)) { 40 | // // do some logging preparation and logging 41 | // // that can't be accomplished e.g. via just VLOG(2) << ...; 42 | // } 43 | // 44 | // The truth value that VLOG_IS_ON(level) returns is determined by 45 | // the three verbosity level flags: 46 | // --v= Gives the default maximal active V-logging level; 47 | // 0 is the default. 48 | // Normally positive values are used for V-logging levels. 49 | // --vmodule= Gives the per-module maximal V-logging levels to override 50 | // the value given by --v. 51 | // E.g. "my_module=2,foo*=3" would change the logging level 52 | // for all code in source files "my_module.*" and "foo*.*" 53 | // ("-inl" suffixes are also disregarded for this matching). 54 | // 55 | // SetVLOGLevel helper function is provided to do limited dynamic control over 56 | // V-logging by overriding the per-module settings given via --vmodule flag. 57 | // 58 | // CAVEAT: --vmodule functionality is not available in non gcc compilers. 59 | // 60 | 61 | #ifndef GLOG_VLOG_IS_ON_H 62 | #define GLOG_VLOG_IS_ON_H 63 | 64 | #include 65 | 66 | #if defined(GLOG_USE_GLOG_EXPORT) 67 | # include "glog/export.h" 68 | #endif 69 | 70 | #if !defined(GLOG_EXPORT) 71 | # error was not included correctly. See the documentation for how to consume the library. 72 | #endif 73 | 74 | #include "glog/flags.h" 75 | #include "glog/types.h" 76 | 77 | #if defined(__GNUC__) 78 | // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site. 79 | // (Normally) the first time every VLOG_IS_ON(n) site is hit, 80 | // we determine what variable will dynamically control logging at this site: 81 | // it's either FLAGS_v or an appropriate internal variable 82 | // matching the current source file that represents results of 83 | // parsing of --vmodule flag and/or SetVLOGLevel calls. 84 | # define VLOG_IS_ON(verboselevel) \ 85 | __extension__({ \ 86 | static google::SiteFlag vlocal__ = {nullptr, nullptr, 0, nullptr}; \ 87 | GLOG_IFDEF_THREAD_SANITIZER(AnnotateBenignRaceSized( \ 88 | __FILE__, __LINE__, &vlocal__, sizeof(google::SiteFlag), "")); \ 89 | google::int32 verbose_level__ = (verboselevel); \ 90 | (vlocal__.level == nullptr \ 91 | ? google::InitVLOG3__(&vlocal__, &FLAGS_v, __FILE__, \ 92 | verbose_level__) \ 93 | : *vlocal__.level >= verbose_level__); \ 94 | }) 95 | #else 96 | // GNU extensions not available, so we do not support --vmodule. 97 | // Dynamic value of FLAGS_v always controls the logging level. 98 | # define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel)) 99 | #endif 100 | 101 | namespace google { 102 | 103 | // Set VLOG(_IS_ON) level for module_pattern to log_level. 104 | // This lets us dynamically control what is normally set by the --vmodule flag. 105 | // Returns the level that previously applied to module_pattern. 106 | // NOTE: To change the log level for VLOG(_IS_ON) sites 107 | // that have already executed after/during InitGoogleLogging, 108 | // one needs to supply the exact --vmodule pattern that applied to them. 109 | // (If no --vmodule pattern applied to them 110 | // the value of FLAGS_v will continue to control them.) 111 | extern GLOG_EXPORT int SetVLOGLevel(const char* module_pattern, int log_level); 112 | 113 | // Various declarations needed for VLOG_IS_ON above: ========================= 114 | 115 | struct SiteFlag { 116 | int32* level; 117 | const char* base_name; 118 | std::size_t base_len; 119 | SiteFlag* next; 120 | }; 121 | 122 | // Helper routine which determines the logging info for a particular VLOG site. 123 | // site_flag is the address of the site-local pointer to the controlling 124 | // verbosity level 125 | // site_default is the default to use for *site_flag 126 | // fname is the current source file name 127 | // verbose_level is the argument to VLOG_IS_ON 128 | // We will return the return value for VLOG_IS_ON 129 | // and if possible set *site_flag appropriately. 130 | extern GLOG_EXPORT bool InitVLOG3__(SiteFlag* site_flag, 131 | int32* site_default, 132 | const char* fname, 133 | int32 verbose_level); 134 | } // namespace google 135 | 136 | #endif // GLOG_VLOG_IS_ON_H 137 | -------------------------------------------------------------------------------- /src/includes_unittest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | project (glog_includes LANGUAGES CXX) 3 | 4 | find_package (glog REQUIRED NO_MODULE) 5 | 6 | add_executable (glog_includes_logging glog_includes_logging.cc) 7 | target_link_libraries (glog_includes_logging PRIVATE glog::glog) 8 | 9 | add_executable (glog_includes_vlog_is_on glog_includes_vlog_is_on.cc) 10 | target_link_libraries (glog_includes_vlog_is_on PRIVATE glog::glog) 11 | 12 | add_executable (glog_includes_raw_logging glog_includes_raw_logging.cc) 13 | target_link_libraries (glog_includes_raw_logging PRIVATE glog::glog) 14 | 15 | add_executable (glog_includes_stl_logging glog_includes_stl_logging.cc) 16 | target_link_libraries (glog_includes_stl_logging PRIVATE glog::glog) 17 | -------------------------------------------------------------------------------- /src/includes_unittest/glog_includes_logging.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Sergiu Deitsch 31 | 32 | #include 33 | 34 | int main() { 35 | LOG(INFO) << "info"; 36 | LOG(WARNING) << "warning"; 37 | LOG(ERROR) << "error"; 38 | LOG(FATAL) << "fatal"; 39 | } 40 | -------------------------------------------------------------------------------- /src/includes_unittest/glog_includes_raw_logging.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Sergiu Deitsch 31 | 32 | #include 33 | 34 | int main() { 35 | RAW_LOG(INFO, "info"); 36 | RAW_LOG(WARNING, "warning"); 37 | RAW_LOG(ERROR, "error"); 38 | RAW_LOG(FATAL, "fatal"); 39 | } 40 | -------------------------------------------------------------------------------- /src/includes_unittest/glog_includes_stl_logging.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Sergiu Deitsch 31 | 32 | #include 33 | 34 | int main() {} 35 | -------------------------------------------------------------------------------- /src/includes_unittest/glog_includes_vlog_is_on.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Sergiu Deitsch 31 | 32 | #include 33 | 34 | int main() { VLOG_IS_ON(0); } 35 | -------------------------------------------------------------------------------- /src/log_severity_unittest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | project (glog_log_severity LANGUAGES CXX) 3 | 4 | find_package (glog REQUIRED NO_MODULE) 5 | 6 | add_executable (glog_log_severity_constants glog_log_severity_constants.cc) 7 | target_link_libraries (glog_log_severity_constants PRIVATE glog::glog) 8 | 9 | add_executable (glog_log_severity_conversion glog_log_severity_conversion.cc) 10 | target_link_libraries (glog_log_severity_conversion PRIVATE glog::glog) 11 | -------------------------------------------------------------------------------- /src/log_severity_unittest/glog_log_severity_constants.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Sergiu Deitsch 31 | 32 | #include 33 | 34 | int main() { 35 | // Must not compile 36 | LOG(0) << "type unsafe info"; 37 | LOG(1) << "type unsafe info"; 38 | LOG(2) << "type unsafe info"; 39 | LOG(3) << "type unsafe info"; 40 | } 41 | -------------------------------------------------------------------------------- /src/log_severity_unittest/glog_log_severity_conversion.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Sergiu Deitsch 31 | 32 | #include 33 | 34 | int main() { 35 | // Must not compile 36 | google::LogMessage{__FILE__, __LINE__, -1}; 37 | // Cast to int to avoid implicit conversoin to nullptr 38 | google::LogMessage{__FILE__, __LINE__, static_cast(0)}; 39 | google::LogMessage{__FILE__, __LINE__, 1}; 40 | google::LogMessage{__FILE__, __LINE__, 2}; 41 | google::LogMessage{__FILE__, __LINE__, 3}; 42 | } 43 | -------------------------------------------------------------------------------- /src/logging_striplog_test.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Copyright (c) 2023, Google Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | # 32 | # Author: Sergey Ioffe 33 | 34 | get_strings () { 35 | if test -e "$1"; then 36 | binary="$1" 37 | elif test -e "$1.exe"; then 38 | binary="$1.exe" 39 | else 40 | echo "We coundn't find $1 binary." 41 | exit 1 42 | fi 43 | 44 | strings -n 10 $binary | sort | awk '/TESTMESSAGE/ {printf "%s ", $2}' 45 | } 46 | 47 | # Die if "$1" != "$2", print $3 as death reason 48 | check_eq () { 49 | if [ "$1" != "$2" ]; then 50 | echo "Check failed: '$1' == '$2' ${3:+ ($3)}" 51 | exit 1 52 | fi 53 | } 54 | 55 | die () { 56 | echo $1 57 | exit 1 58 | } 59 | 60 | # Check that the string literals are appropriately stripped. This will 61 | # not be the case in debug mode. 62 | 63 | mode=`GLOG_check_mode=1 ./striplog0_unittest 2> /dev/null` 64 | echo $mode 65 | if [ "$mode" = "opt" ]; 66 | then 67 | echo "In OPT mode" 68 | check_eq "`get_strings striplog0_unittest`" "COND ERROR FATAL INFO WARNING " 69 | check_eq "`get_strings striplog2_unittest`" "COND ERROR FATAL " 70 | check_eq "`get_strings striplog10_unittest`" "" 71 | else 72 | echo "In DBG mode; not checking strings" 73 | fi 74 | 75 | # Check that LOG(FATAL) aborts even for large STRIP_LOG 76 | 77 | ./striplog2_unittest 2>/dev/null && die "Did not abort for STRIP_LOG=2" 78 | ./striplog10_unittest 2>/dev/null && die "Did not abort for STRIP_LOG=10" 79 | 80 | echo "PASS" 81 | -------------------------------------------------------------------------------- /src/mock-log_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Zhanyong Wan 31 | 32 | // Tests the ScopedMockLog class. 33 | 34 | #include "mock-log.h" 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | 41 | namespace { 42 | 43 | using google::GLOG_ERROR; 44 | using google::GLOG_INFO; 45 | using google::GLOG_WARNING; 46 | using google::glog_testing::ScopedMockLog; 47 | using std::string; 48 | using testing::_; 49 | using testing::EndsWith; 50 | using testing::InSequence; 51 | using testing::InvokeWithoutArgs; 52 | 53 | // Tests that ScopedMockLog intercepts LOG()s when it's alive. 54 | TEST(ScopedMockLogTest, InterceptsLog) { 55 | ScopedMockLog log; 56 | 57 | InSequence s; 58 | EXPECT_CALL(log, 59 | Log(GLOG_WARNING, EndsWith("mock-log_unittest.cc"), "Fishy.")); 60 | EXPECT_CALL(log, Log(GLOG_INFO, _, "Working...")).Times(2); 61 | EXPECT_CALL(log, Log(GLOG_ERROR, _, "Bad!!")); 62 | 63 | LOG(WARNING) << "Fishy."; 64 | LOG(INFO) << "Working..."; 65 | LOG(INFO) << "Working..."; 66 | LOG(ERROR) << "Bad!!"; 67 | } 68 | 69 | void LogBranch() { LOG(INFO) << "Logging a branch..."; } 70 | 71 | void LogTree() { LOG(INFO) << "Logging the whole tree..."; } 72 | 73 | void LogForest() { 74 | LOG(INFO) << "Logging the entire forest."; 75 | LOG(INFO) << "Logging the entire forest.."; 76 | LOG(INFO) << "Logging the entire forest..."; 77 | } 78 | 79 | // The purpose of the following test is to verify that intercepting logging 80 | // continues to work properly if a LOG statement is executed within the scope 81 | // of a mocked call. 82 | TEST(ScopedMockLogTest, LogDuringIntercept) { 83 | ScopedMockLog log; 84 | InSequence s; 85 | EXPECT_CALL(log, Log(GLOG_INFO, __FILE__, "Logging a branch...")) 86 | .WillOnce(InvokeWithoutArgs(LogTree)); 87 | EXPECT_CALL(log, Log(GLOG_INFO, __FILE__, "Logging the whole tree...")) 88 | .WillOnce(InvokeWithoutArgs(LogForest)); 89 | EXPECT_CALL(log, Log(GLOG_INFO, __FILE__, "Logging the entire forest.")); 90 | EXPECT_CALL(log, Log(GLOG_INFO, __FILE__, "Logging the entire forest..")); 91 | EXPECT_CALL(log, Log(GLOG_INFO, __FILE__, "Logging the entire forest...")); 92 | LogBranch(); 93 | } 94 | 95 | } // namespace 96 | 97 | int main(int argc, char** argv) { 98 | google::InitGoogleLogging(argv[0]); 99 | testing::InitGoogleTest(&argc, argv); 100 | testing::InitGoogleMock(&argc, argv); 101 | 102 | return RUN_ALL_TESTS(); 103 | } 104 | -------------------------------------------------------------------------------- /src/package_config_unittest/working_config/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.16) 2 | project (glog_package_config LANGUAGES CXX) 3 | 4 | find_package (glog REQUIRED NO_MODULE) 5 | 6 | add_executable (glog_package_config glog_package_config.cc) 7 | 8 | target_link_libraries (glog_package_config PRIVATE glog::glog) 9 | -------------------------------------------------------------------------------- /src/package_config_unittest/working_config/glog_package_config.cc: -------------------------------------------------------------------------------- 1 | #include "glog/logging.h" 2 | 3 | int main(int /*argc*/, char** argv) { google::InitGoogleLogging(argv[0]); } 4 | -------------------------------------------------------------------------------- /src/signalhandler_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Satoru Takabayashi 31 | // 32 | // This is a helper binary for testing signalhandler.cc. The actual test 33 | // is done in signalhandler_unittest.sh. 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "config.h" 43 | #include "glog/logging.h" 44 | #include "stacktrace.h" 45 | #include "symbolize.h" 46 | 47 | #if defined(HAVE_UNISTD_H) 48 | # include 49 | #endif 50 | #ifdef GLOG_USE_GFLAGS 51 | # include 52 | using namespace GFLAGS_NAMESPACE; 53 | #endif 54 | #if defined(_MSC_VER) 55 | # include // write 56 | #endif 57 | 58 | using namespace google; 59 | 60 | static void DieInThread(int* a) { 61 | std::ostringstream oss; 62 | oss << std::showbase << std::hex << std::this_thread::get_id(); 63 | 64 | fprintf(stderr, "%s is dying\n", oss.str().c_str()); 65 | int b = 1 / *a; 66 | fprintf(stderr, "We should have died: b=%d\n", b); 67 | } 68 | 69 | static void WriteToStdout(const char* data, size_t size) { 70 | if (write(fileno(stdout), data, size) < 0) { 71 | // Ignore errors. 72 | } 73 | } 74 | 75 | int main(int argc, char** argv) { 76 | #if defined(HAVE_STACKTRACE) && defined(HAVE_SYMBOLIZE) 77 | InitGoogleLogging(argv[0]); 78 | # ifdef GLOG_USE_GFLAGS 79 | ParseCommandLineFlags(&argc, &argv, true); 80 | # endif 81 | InstallFailureSignalHandler(); 82 | const std::string command = argc > 1 ? argv[1] : "none"; 83 | if (command == "segv") { 84 | // We'll check if this is outputted. 85 | LOG(INFO) << "create the log file"; 86 | LOG(INFO) << "a message before segv"; 87 | // We assume 0xDEAD is not writable. 88 | int* a = (int*)0xDEAD; 89 | *a = 0; 90 | } else if (command == "loop") { 91 | fprintf(stderr, "looping\n"); 92 | while (true) 93 | ; 94 | } else if (command == "die_in_thread") { 95 | std::thread t{&DieInThread, nullptr}; 96 | t.join(); 97 | } else if (command == "dump_to_stdout") { 98 | InstallFailureWriter(WriteToStdout); 99 | abort(); 100 | } else if (command == "installed") { 101 | fprintf(stderr, "signal handler installed: %s\n", 102 | IsFailureSignalHandlerInstalled() ? "true" : "false"); 103 | } else { 104 | // Tell the shell script 105 | puts("OK"); 106 | } 107 | #endif 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /src/signalhandler_unittest.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Copyright (c) 2008, Google Inc. 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are 8 | # met: 9 | # 10 | # * Redistributions of source code must retain the above copyright 11 | # notice, this list of conditions and the following disclaimer. 12 | # * Redistributions in binary form must reproduce the above 13 | # copyright notice, this list of conditions and the following disclaimer 14 | # in the documentation and/or other materials provided with the 15 | # distribution. 16 | # * Neither the name of Google Inc. nor the names of its 17 | # contributors may be used to endorse or promote products derived from 18 | # this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | # 32 | # Author: Satoru Takabayashi 33 | # 34 | # Unit tests for signalhandler.cc. 35 | 36 | die () { 37 | echo $1 38 | exit 1 39 | } 40 | 41 | BINDIR=".libs" 42 | LIBGLOG="$BINDIR/libglog.so" 43 | 44 | BINARY="$BINDIR/signalhandler_unittest" 45 | LOG_INFO="./signalhandler_unittest.INFO" 46 | 47 | # Remove temporary files. 48 | rm -f signalhandler.out* 49 | 50 | if test -e "$BINARY"; then 51 | # We need shared object. 52 | export LD_LIBRARY_PATH=$BINDIR 53 | export DYLD_LIBRARY_PATH=$BINDIR 54 | else 55 | # For windows 56 | BINARY="./signalhandler_unittest.exe" 57 | if ! test -e "$BINARY"; then 58 | echo "We coundn't find demangle_unittest binary." 59 | exit 1 60 | fi 61 | fi 62 | 63 | if [ x`$BINARY` != 'xOK' ]; then 64 | echo "PASS (No stacktrace support. We don't run this test.)" 65 | exit 0 66 | fi 67 | 68 | # The PC cannot be obtained in signal handlers on PowerPC correctly. 69 | # We just skip the test for PowerPC. 70 | if [ x`uname -p` = x"powerpc" ]; then 71 | echo "PASS (We don't test the signal handler on PowerPC.)" 72 | exit 0 73 | fi 74 | 75 | # Test for a case the program kills itself by SIGSEGV. 76 | GOOGLE_LOG_DIR=. $BINARY segv 2> signalhandler.out1 77 | for pattern in SIGSEGV 0xdead main "Aborted at [0-9]"; do 78 | if ! grep --quiet "$pattern" signalhandler.out1; then 79 | die "'$pattern' should appear in the output" 80 | fi 81 | done 82 | if ! grep --quiet "a message before segv" $LOG_INFO; then 83 | die "'a message before segv' should appear in the INFO log" 84 | fi 85 | rm -f $LOG_INFO 86 | 87 | # Test for a case the program is killed by this shell script. 88 | # $! = the process id of the last command run in the background. 89 | # $$ = the process id of this shell. 90 | $BINARY loop 2> signalhandler.out2 & 91 | # Wait until "looping" is written in the file. This indicates the program 92 | # is ready to accept signals. 93 | while true; do 94 | if grep --quiet looping signalhandler.out2; then 95 | break 96 | fi 97 | done 98 | kill -TERM $! 99 | wait $! 100 | 101 | from_pid='' 102 | # Only linux has the process ID of the signal sender. 103 | if [ x`uname` = "xLinux" ]; then 104 | from_pid="from PID $$" 105 | fi 106 | for pattern in SIGTERM "by PID $!" "$from_pid" main "Aborted at [0-9]"; do 107 | if ! grep --quiet "$pattern" signalhandler.out2; then 108 | die "'$pattern' should appear in the output" 109 | fi 110 | done 111 | 112 | # Test for a case the program dies in a non-main thread. 113 | $BINARY die_in_thread 2> signalhandler.out3 114 | EXPECTED_TID="`sed 's/ .*//; q' signalhandler.out3`" 115 | 116 | for pattern in SIGFPE DieInThread "TID $EXPECTED_TID" "Aborted at [0-9]"; do 117 | if ! grep --quiet "$pattern" signalhandler.out3; then 118 | die "'$pattern' should appear in the output" 119 | fi 120 | done 121 | 122 | # Test for a case the program installs a custom failure writer that writes 123 | # stuff to stdout instead of stderr. 124 | $BINARY dump_to_stdout 1> signalhandler.out4 125 | for pattern in SIGABRT main "Aborted at [0-9]"; do 126 | if ! grep --quiet "$pattern" signalhandler.out4; then 127 | die "'$pattern' should appear in the output" 128 | fi 129 | done 130 | 131 | echo PASS 132 | -------------------------------------------------------------------------------- /src/stacktrace.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Routines to extract the current stack trace. These functions are 31 | // thread-safe. 32 | 33 | #include "stacktrace.h" 34 | 35 | // Make an implementation of stacktrace compiled. 36 | #if defined(STACKTRACE_H) 37 | # include STACKTRACE_H 38 | #endif 39 | -------------------------------------------------------------------------------- /src/stacktrace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Routines to extract the current stack trace. These functions are 31 | // thread-safe. 32 | 33 | #ifndef GLOG_INTERNAL_STACKTRACE_H 34 | #define GLOG_INTERNAL_STACKTRACE_H 35 | 36 | #include "glog/platform.h" 37 | 38 | #if defined(GLOG_USE_GLOG_EXPORT) 39 | # include "glog/export.h" 40 | #endif 41 | 42 | #if !defined(GLOG_NO_EXPORT) 43 | # error "stacktrace.h" was not included correctly. 44 | #endif 45 | 46 | #include "config.h" 47 | #if defined(HAVE_LIBUNWIND) 48 | # define STACKTRACE_H "stacktrace_libunwind-inl.h" 49 | #elif defined(HAVE_UNWIND) 50 | # define STACKTRACE_H "stacktrace_unwind-inl.h" 51 | #elif !defined(NO_FRAME_POINTER) 52 | # if defined(__i386__) && __GNUC__ >= 2 53 | # define STACKTRACE_H "stacktrace_x86-inl.h" 54 | # elif (defined(__ppc__) || defined(__PPC__)) && __GNUC__ >= 2 55 | # define STACKTRACE_H "stacktrace_powerpc-inl.h" 56 | # elif defined(GLOG_OS_WINDOWS) 57 | # define STACKTRACE_H "stacktrace_windows-inl.h" 58 | # endif 59 | #endif 60 | 61 | #if !defined(STACKTRACE_H) && defined(HAVE_EXECINFO_BACKTRACE) 62 | # define STACKTRACE_H "stacktrace_generic-inl.h" 63 | #endif 64 | 65 | #if defined(STACKTRACE_H) 66 | # define HAVE_STACKTRACE 67 | #endif 68 | 69 | namespace google { 70 | inline namespace glog_internal_namespace_ { 71 | 72 | #if defined(HAVE_STACKTRACE) 73 | 74 | // This is similar to the GetStackFrames routine, except that it returns 75 | // the stack trace only, and not the stack frame sizes as well. 76 | // Example: 77 | // main() { foo(); } 78 | // foo() { bar(); } 79 | // bar() { 80 | // void* result[10]; 81 | // int depth = GetStackFrames(result, 10, 1); 82 | // } 83 | // 84 | // This produces: 85 | // result[0] foo 86 | // result[1] main 87 | // .... ... 88 | // 89 | // "result" must not be nullptr. 90 | GLOG_NO_EXPORT int GetStackTrace(void** result, int max_depth, int skip_count); 91 | 92 | #endif // defined(HAVE_STACKTRACE) 93 | 94 | } // namespace glog_internal_namespace_ 95 | } // namespace google 96 | 97 | #endif // GLOG_INTERNAL_STACKTRACE_H 98 | -------------------------------------------------------------------------------- /src/stacktrace_generic-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2000 - 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Portable implementation - just use glibc 31 | // 32 | // Note: The glibc implementation may cause a call to malloc. 33 | // This can cause a deadlock in HeapProfiler. 34 | #include 35 | 36 | #include 37 | 38 | #include "stacktrace.h" 39 | 40 | namespace google { 41 | inline namespace glog_internal_namespace_ { 42 | 43 | // If you change this function, also change GetStackFrames below. 44 | int GetStackTrace(void** result, int max_depth, int skip_count) { 45 | static const int kStackLength = 64; 46 | void* stack[kStackLength]; 47 | int size; 48 | 49 | size = backtrace(stack, kStackLength); 50 | skip_count++; // we want to skip the current frame as well 51 | int result_count = size - skip_count; 52 | if (result_count < 0) { 53 | result_count = 0; 54 | } 55 | if (result_count > max_depth) { 56 | result_count = max_depth; 57 | } 58 | for (int i = 0; i < result_count; i++) { 59 | result[i] = stack[i + skip_count]; 60 | } 61 | 62 | return result_count; 63 | } 64 | 65 | } // namespace glog_internal_namespace_ 66 | } // namespace google 67 | -------------------------------------------------------------------------------- /src/stacktrace_libunwind-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2005 - 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Arun Sharma 31 | // 32 | // Produce stack trace using libunwind 33 | 34 | #include "utilities.h" 35 | 36 | extern "C" { 37 | #define UNW_LOCAL_ONLY 38 | #include 39 | } 40 | #include "glog/raw_logging.h" 41 | #include "stacktrace.h" 42 | 43 | namespace google { 44 | inline namespace glog_internal_namespace_ { 45 | 46 | // Sometimes, we can try to get a stack trace from within a stack 47 | // trace, because libunwind can call mmap (maybe indirectly via an 48 | // internal mmap based memory allocator), and that mmap gets trapped 49 | // and causes a stack-trace request. If were to try to honor that 50 | // recursive request, we'd end up with infinite recursion or deadlock. 51 | // Luckily, it's safe to ignore those subsequent traces. In such 52 | // cases, we return 0 to indicate the situation. 53 | // We can use the GCC __thread syntax here since libunwind is not supported on 54 | // Windows. 55 | static __thread bool g_tl_entered; // Initialized to false. 56 | 57 | // If you change this function, also change GetStackFrames below. 58 | int GetStackTrace(void** result, int max_depth, int skip_count) { 59 | void* ip; 60 | int n = 0; 61 | unw_cursor_t cursor; 62 | unw_context_t uc; 63 | 64 | if (g_tl_entered) { 65 | return 0; 66 | } 67 | g_tl_entered = true; 68 | 69 | unw_getcontext(&uc); 70 | RAW_CHECK(unw_init_local(&cursor, &uc) >= 0, "unw_init_local failed"); 71 | skip_count++; // Do not include the "GetStackTrace" frame 72 | 73 | while (n < max_depth) { 74 | int ret = 75 | unw_get_reg(&cursor, UNW_REG_IP, reinterpret_cast(&ip)); 76 | if (ret < 0) { 77 | break; 78 | } 79 | if (skip_count > 0) { 80 | skip_count--; 81 | } else { 82 | result[n++] = ip; 83 | } 84 | ret = unw_step(&cursor); 85 | if (ret <= 0) { 86 | break; 87 | } 88 | } 89 | 90 | g_tl_entered = false; 91 | return n; 92 | } 93 | 94 | } // namespace glog_internal_namespace_ 95 | } // namespace google 96 | -------------------------------------------------------------------------------- /src/stacktrace_powerpc-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Craig Silverstein 31 | // 32 | // Produce stack trace. I'm guessing (hoping!) the code is much like 33 | // for x86. For apple machines, at least, it seems to be; see 34 | // http://developer.apple.com/documentation/mac/runtimehtml/RTArch-59.html 35 | // http://www.linux-foundation.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html#STACK 36 | // Linux has similar code: http://patchwork.ozlabs.org/linuxppc/patch?id=8882 37 | 38 | #include // for uintptr_t 39 | #include 40 | 41 | #include "stacktrace.h" 42 | 43 | namespace google { 44 | inline namespace glog_internal_namespace_ { 45 | 46 | // Given a pointer to a stack frame, locate and return the calling 47 | // stackframe, or return nullptr if no stackframe can be found. Perform sanity 48 | // checks (the strictness of which is controlled by the boolean parameter 49 | // "STRICT_UNWINDING") to reduce the chance that a bad pointer is returned. 50 | template 51 | static void** NextStackFrame(void** old_sp) { 52 | void** new_sp = static_cast(*old_sp); 53 | 54 | // Check that the transition from frame pointer old_sp to frame 55 | // pointer new_sp isn't clearly bogus 56 | if (STRICT_UNWINDING) { 57 | // With the stack growing downwards, older stack frame must be 58 | // at a greater address that the current one. 59 | if (new_sp <= old_sp) return nullptr; 60 | // Assume stack frames larger than 100,000 bytes are bogus. 61 | if ((uintptr_t)new_sp - (uintptr_t)old_sp > 100000) return nullptr; 62 | } else { 63 | // In the non-strict mode, allow discontiguous stack frames. 64 | // (alternate-signal-stacks for example). 65 | if (new_sp == old_sp) return nullptr; 66 | // And allow frames upto about 1MB. 67 | if ((new_sp > old_sp) && 68 | ((uintptr_t)new_sp - (uintptr_t)old_sp > 1000000)) { 69 | return nullptr; 70 | } 71 | } 72 | if ((uintptr_t)new_sp & (sizeof(void*) - 1)) return nullptr; 73 | return new_sp; 74 | } 75 | 76 | // This ensures that GetStackTrace stes up the Link Register properly. 77 | void StacktracePowerPCDummyFunction() __attribute__((noinline)); 78 | void StacktracePowerPCDummyFunction() { __asm__ volatile(""); } 79 | 80 | // If you change this function, also change GetStackFrames below. 81 | int GetStackTrace(void** result, int max_depth, int skip_count) { 82 | void** sp; 83 | // Apple OS X uses an old version of gnu as -- both Darwin 7.9.0 (Panther) 84 | // and Darwin 8.8.1 (Tiger) use as 1.38. This means we have to use a 85 | // different asm syntax. I don't know quite the best way to discriminate 86 | // systems using the old as from the new one; I've gone with __APPLE__. 87 | #ifdef __APPLE__ 88 | __asm__ volatile("mr %0,r1" : "=r"(sp)); 89 | #else 90 | __asm__ volatile("mr %0,1" : "=r"(sp)); 91 | #endif 92 | 93 | // On PowerPC, the "Link Register" or "Link Record" (LR), is a stack 94 | // entry that holds the return address of the subroutine call (what 95 | // instruction we run after our function finishes). This is the 96 | // same as the stack-pointer of our parent routine, which is what we 97 | // want here. While the compiler will always(?) set up LR for 98 | // subroutine calls, it may not for leaf functions (such as this one). 99 | // This routine forces the compiler (at least gcc) to push it anyway. 100 | StacktracePowerPCDummyFunction(); 101 | 102 | // The LR save area is used by the callee, so the top entry is bogus. 103 | skip_count++; 104 | 105 | int n = 0; 106 | while (sp && n < max_depth) { 107 | if (skip_count > 0) { 108 | skip_count--; 109 | } else { 110 | // PowerPC has 3 main ABIs, which say where in the stack the 111 | // Link Register is. For DARWIN and AIX (used by apple and 112 | // linux ppc64), it's in sp[2]. For SYSV (used by linux ppc), 113 | // it's in sp[1]. 114 | #if defined(_CALL_AIX) || defined(_CALL_DARWIN) 115 | result[n++] = *(sp + 2); 116 | #elif defined(_CALL_SYSV) 117 | result[n++] = *(sp + 1); 118 | #elif defined(__APPLE__) || \ 119 | ((defined(__linux) || defined(__linux__)) && defined(__PPC64__)) 120 | // This check is in case the compiler doesn't define _CALL_AIX/etc. 121 | result[n++] = *(sp + 2); 122 | #elif defined(__linux) || defined(__OpenBSD__) 123 | // This check is in case the compiler doesn't define _CALL_SYSV. 124 | result[n++] = *(sp + 1); 125 | #else 126 | # error Need to specify the PPC ABI for your architecture. 127 | #endif 128 | } 129 | // Use strict unwinding rules. 130 | sp = NextStackFrame(sp); 131 | } 132 | return n; 133 | } 134 | 135 | } // namespace glog_internal_namespace_ 136 | } // namespace google 137 | -------------------------------------------------------------------------------- /src/stacktrace_unwind-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Arun Sharma 31 | // 32 | // Produce stack trace using libgcc 33 | 34 | #include // ABI defined unwinder 35 | 36 | #include "stacktrace.h" 37 | 38 | namespace google { 39 | inline namespace glog_internal_namespace_ { 40 | 41 | struct trace_arg_t { 42 | void** result; 43 | int max_depth; 44 | int skip_count; 45 | int count; 46 | }; 47 | 48 | // Workaround for the malloc() in _Unwind_Backtrace() issue. 49 | static _Unwind_Reason_Code nop_backtrace(struct _Unwind_Context* /*uc*/, 50 | void* /*opq*/) { 51 | return _URC_NO_REASON; 52 | } 53 | 54 | // This code is not considered ready to run until 55 | // static initializers run so that we are guaranteed 56 | // that any malloc-related initialization is done. 57 | static bool ready_to_run = false; 58 | class StackTraceInit { 59 | public: 60 | StackTraceInit() { 61 | // Extra call to force initialization 62 | _Unwind_Backtrace(nop_backtrace, nullptr); 63 | ready_to_run = true; 64 | } 65 | }; 66 | 67 | static StackTraceInit module_initializer; // Force initialization 68 | 69 | static _Unwind_Reason_Code GetOneFrame(struct _Unwind_Context* uc, void* opq) { 70 | auto* targ = static_cast(opq); 71 | 72 | if (targ->skip_count > 0) { 73 | targ->skip_count--; 74 | } else { 75 | targ->result[targ->count++] = reinterpret_cast(_Unwind_GetIP(uc)); 76 | } 77 | 78 | if (targ->count == targ->max_depth) { 79 | return _URC_END_OF_STACK; 80 | } 81 | 82 | return _URC_NO_REASON; 83 | } 84 | 85 | // If you change this function, also change GetStackFrames below. 86 | int GetStackTrace(void** result, int max_depth, int skip_count) { 87 | if (!ready_to_run) { 88 | return 0; 89 | } 90 | 91 | trace_arg_t targ; 92 | 93 | skip_count += 1; // Do not include the "GetStackTrace" frame 94 | 95 | targ.result = result; 96 | targ.max_depth = max_depth; 97 | targ.skip_count = skip_count; 98 | targ.count = 0; 99 | 100 | _Unwind_Backtrace(GetOneFrame, &targ); 101 | 102 | return targ.count; 103 | } 104 | 105 | } // namespace glog_internal_namespace_ 106 | } // namespace google 107 | -------------------------------------------------------------------------------- /src/stacktrace_windows-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2000 - 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Andrew Schwartzmeyer 31 | // 32 | // Windows implementation - just use CaptureStackBackTrace 33 | 34 | // clang-format off 35 | #include // Must come before 36 | #include 37 | // clang-format on 38 | 39 | namespace google { 40 | inline namespace glog_internal_namespace_ { 41 | 42 | int GetStackTrace(void** result, int max_depth, int skip_count) { 43 | if (max_depth > 64) { 44 | max_depth = 64; 45 | } 46 | skip_count++; // we want to skip the current frame as well 47 | // This API is thread-safe (moreover it walks only the current thread). 48 | return CaptureStackBackTrace(static_cast(skip_count), 49 | static_cast(max_depth), result, nullptr); 50 | } 51 | 52 | } // namespace glog_internal_namespace_ 53 | } // namespace google 54 | -------------------------------------------------------------------------------- /src/stacktrace_x86-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2000 - 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Produce stack trace 31 | 32 | #include // for uintptr_t 33 | 34 | #include "utilities.h" // for OS_* macros 35 | 36 | #if !defined(GLOG_OS_WINDOWS) 37 | # include 38 | # include 39 | #endif 40 | 41 | #include // for nullptr 42 | 43 | #include "stacktrace.h" 44 | 45 | namespace google { 46 | inline namespace glog_internal_namespace_ { 47 | 48 | // Given a pointer to a stack frame, locate and return the calling 49 | // stackframe, or return nullptr if no stackframe can be found. Perform sanity 50 | // checks (the strictness of which is controlled by the boolean parameter 51 | // "STRICT_UNWINDING") to reduce the chance that a bad pointer is returned. 52 | template 53 | static void** NextStackFrame(void** old_sp) { 54 | void** new_sp = static_cast(*old_sp); 55 | 56 | // Check that the transition from frame pointer old_sp to frame 57 | // pointer new_sp isn't clearly bogus 58 | if (STRICT_UNWINDING) { 59 | // With the stack growing downwards, older stack frame must be 60 | // at a greater address that the current one. 61 | if (new_sp <= old_sp) return nullptr; 62 | // Assume stack frames larger than 100,000 bytes are bogus. 63 | if (reinterpret_cast(new_sp) - 64 | reinterpret_cast(old_sp) > 65 | 100000) { 66 | return nullptr; 67 | } 68 | } else { 69 | // In the non-strict mode, allow discontiguous stack frames. 70 | // (alternate-signal-stacks for example). 71 | if (new_sp == old_sp) return nullptr; 72 | // And allow frames upto about 1MB. 73 | if ((new_sp > old_sp) && (reinterpret_cast(new_sp) - 74 | reinterpret_cast(old_sp) > 75 | 1000000)) { 76 | return nullptr; 77 | } 78 | } 79 | if (reinterpret_cast(new_sp) & (sizeof(void*) - 1)) { 80 | return nullptr; 81 | } 82 | #ifdef __i386__ 83 | // On 64-bit machines, the stack pointer can be very close to 84 | // 0xffffffff, so we explicitly check for a pointer into the 85 | // last two pages in the address space 86 | if ((uintptr_t)new_sp >= 0xffffe000) return nullptr; 87 | #endif 88 | #if !defined(GLOG_OS_WINDOWS) 89 | if (!STRICT_UNWINDING) { 90 | // Lax sanity checks cause a crash in 32-bit tcmalloc/crash_reason_test 91 | // on AMD-based machines with VDSO-enabled kernels. 92 | // Make an extra sanity check to insure new_sp is readable. 93 | // Note: NextStackFrame() is only called while the program 94 | // is already on its last leg, so it's ok to be slow here. 95 | static int page_size = getpagesize(); 96 | void* new_sp_aligned = 97 | reinterpret_cast(reinterpret_cast(new_sp) & 98 | static_cast(~(page_size - 1))); 99 | if (msync(new_sp_aligned, static_cast(page_size), MS_ASYNC) == -1) { 100 | return nullptr; 101 | } 102 | } 103 | #endif 104 | return new_sp; 105 | } 106 | 107 | // If you change this function, also change GetStackFrames below. 108 | int GetStackTrace(void** result, int max_depth, int skip_count) { 109 | void** sp; 110 | 111 | #ifdef __GNUC__ 112 | # if __GNUC__ * 100 + __GNUC_MINOR__ >= 402 113 | # define USE_BUILTIN_FRAME_ADDRESS 114 | # endif 115 | #endif 116 | 117 | #ifdef USE_BUILTIN_FRAME_ADDRESS 118 | sp = reinterpret_cast(__builtin_frame_address(0)); 119 | #elif defined(__i386__) 120 | // Stack frame format: 121 | // sp[0] pointer to previous frame 122 | // sp[1] caller address 123 | // sp[2] first argument 124 | // ... 125 | sp = (void**)&result - 2; 126 | #elif defined(__x86_64__) 127 | // __builtin_frame_address(0) can return the wrong address on gcc-4.1.0-k8 128 | unsigned long rbp; 129 | // Move the value of the register %rbp into the local variable rbp. 130 | // We need 'volatile' to prevent this instruction from getting moved 131 | // around during optimization to before function prologue is done. 132 | // An alternative way to achieve this 133 | // would be (before this __asm__ instruction) to call Noop() defined as 134 | // static void Noop() __attribute__ ((noinline)); // prevent inlining 135 | // static void Noop() { asm(""); } // prevent optimizing-away 136 | __asm__ volatile("mov %%rbp, %0" : "=r"(rbp)); 137 | // Arguments are passed in registers on x86-64, so we can't just 138 | // offset from &result 139 | sp = (void**)rbp; 140 | #endif 141 | 142 | int n = 0; 143 | while (sp && n < max_depth) { 144 | if (*(sp + 1) == nullptr) { 145 | // In 64-bit code, we often see a frame that 146 | // points to itself and has a return address of 0. 147 | break; 148 | } 149 | if (skip_count > 0) { 150 | skip_count--; 151 | } else { 152 | result[n++] = *(sp + 1); 153 | } 154 | // Use strict unwinding rules. 155 | sp = NextStackFrame(sp); 156 | } 157 | return n; 158 | } 159 | } // namespace glog_internal_namespace_ 160 | } // namespace google 161 | -------------------------------------------------------------------------------- /src/stl_logging_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "glog/stl_logging.h" 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "config.h" 40 | #include "glog/logging.h" 41 | #include "googletest.h" 42 | 43 | using namespace std; 44 | 45 | struct user_hash { 46 | size_t operator()(int x) const { return static_cast(x); } 47 | }; 48 | 49 | static void TestSTLLogging() { 50 | { 51 | // Test a sequence. 52 | vector v; 53 | v.push_back(10); 54 | v.push_back(20); 55 | v.push_back(30); 56 | ostringstream ss; 57 | ss << v; 58 | EXPECT_EQ(ss.str(), "10 20 30"); 59 | vector copied_v(v); 60 | CHECK_EQ(v, copied_v); // This must compile. 61 | } 62 | 63 | { 64 | // Test a sorted pair associative container. 65 | map m; 66 | m[20] = "twenty"; 67 | m[10] = "ten"; 68 | m[30] = "thirty"; 69 | ostringstream ss; 70 | ss << m; 71 | EXPECT_EQ(ss.str(), "(10, ten) (20, twenty) (30, thirty)"); 72 | map copied_m(m); 73 | CHECK_EQ(m, copied_m); // This must compile. 74 | } 75 | 76 | { 77 | // Test a long sequence. 78 | vector v; 79 | string expected; 80 | for (int i = 0; i < 100; i++) { 81 | v.push_back(i); 82 | if (i > 0) expected += ' '; 83 | const size_t buf_size = 256; 84 | char buf[buf_size]; 85 | std::snprintf(buf, buf_size, "%d", i); 86 | expected += buf; 87 | } 88 | v.push_back(100); 89 | expected += " ..."; 90 | ostringstream ss; 91 | ss << v; 92 | CHECK_EQ(ss.str(), expected.c_str()); 93 | } 94 | 95 | { 96 | // Test a sorted pair associative container. 97 | // Use a non-default comparison functor. 98 | map> m; 99 | m[20] = "twenty"; 100 | m[10] = "ten"; 101 | m[30] = "thirty"; 102 | ostringstream ss; 103 | ss << m; 104 | EXPECT_EQ(ss.str(), "(30, thirty) (20, twenty) (10, ten)"); 105 | map> copied_m(m); 106 | CHECK_EQ(m, copied_m); // This must compile. 107 | } 108 | } 109 | 110 | int main(int, char**) { 111 | TestSTLLogging(); 112 | std::cout << "PASS\n"; 113 | return 0; 114 | } 115 | -------------------------------------------------------------------------------- /src/striplog_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Sergey Ioffe 31 | 32 | // The common part of the striplog tests. 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "base/commandlineflags.h" 41 | #include "config.h" 42 | #include "glog/logging.h" 43 | 44 | GLOG_DEFINE_bool(check_mode, false, "Prints 'opt' or 'dbg'"); 45 | 46 | using std::string; 47 | using namespace google; 48 | 49 | int CheckNoReturn(bool b) { 50 | string s; 51 | if (b) { 52 | LOG(FATAL) << "Fatal"; 53 | return 0; // Workaround for MSVC warning C4715 54 | } else { 55 | return 0; 56 | } 57 | } 58 | 59 | struct A {}; 60 | std::ostream& operator<<(std::ostream& str, const A&) { return str; } 61 | 62 | namespace { 63 | void handle_abort(int /*code*/) { std::exit(EXIT_FAILURE); } 64 | } // namespace 65 | 66 | int main(int, char* argv[]) { 67 | #if defined(_MSC_VER) 68 | // Avoid presenting an interactive dialog that will cause the test to time 69 | // out. 70 | _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); 71 | #endif // defined(_MSC_VER) 72 | std::signal(SIGABRT, handle_abort); 73 | 74 | FLAGS_logtostderr = true; 75 | InitGoogleLogging(argv[0]); 76 | if (FLAGS_check_mode) { 77 | printf("%s\n", DEBUG_MODE ? "dbg" : "opt"); 78 | return 0; 79 | } 80 | LOG(INFO) << "TESTMESSAGE INFO"; 81 | LOG(WARNING) << 2 << "something" 82 | << "TESTMESSAGE WARNING" << 1 << 'c' << A() << std::endl; 83 | LOG(ERROR) << "TESTMESSAGE ERROR"; 84 | bool flag = true; 85 | (flag ? LOG(INFO) : LOG(ERROR)) << "TESTMESSAGE COND"; 86 | LOG(FATAL) << "TESTMESSAGE FATAL"; 87 | } 88 | -------------------------------------------------------------------------------- /src/utilities_unittest.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Shinichiro Hamaji 31 | #include "utilities.h" 32 | 33 | #include "glog/logging.h" 34 | #include "googletest.h" 35 | 36 | #ifdef GLOG_USE_GFLAGS 37 | # include 38 | using namespace GFLAGS_NAMESPACE; 39 | #endif 40 | 41 | using namespace google; 42 | 43 | TEST(utilities, InitGoogleLoggingDeathTest) { 44 | ASSERT_DEATH(InitGoogleLogging("foobar"), ""); 45 | } 46 | 47 | int main(int argc, char** argv) { 48 | InitGoogleLogging(argv[0]); 49 | InitGoogleTest(&argc, argv); 50 | 51 | CHECK_EQ(RUN_ALL_TESTS(), 0); 52 | } 53 | -------------------------------------------------------------------------------- /src/windows/port.cc: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2023, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * --- 31 | * Author: Craig Silverstein 32 | * Copied from google-perftools and modified by Shinichiro Hamaji 33 | */ 34 | 35 | #ifndef _WIN32 36 | # error You should only be including windows/port.cc in a windows environment! 37 | #endif 38 | 39 | #include "port.h" 40 | 41 | #include 42 | 43 | #include "config.h" 44 | 45 | namespace google { 46 | inline namespace glog_internal_namespace_ { 47 | 48 | #ifndef HAVE_LOCALTIME_R 49 | struct tm* localtime_r(const std::time_t* timep, std::tm* result) { 50 | localtime_s(result, timep); 51 | return result; 52 | } 53 | #endif // not HAVE_LOCALTIME_R 54 | #ifndef HAVE_GMTIME_R 55 | struct tm* gmtime_r(const std::time_t* timep, std::tm* result) { 56 | gmtime_s(result, timep); 57 | return result; 58 | } 59 | #endif // not HAVE_GMTIME_R 60 | 61 | } // namespace glog_internal_namespace_ 62 | } // namespace google 63 | -------------------------------------------------------------------------------- /src/windows/port.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2023, Google Inc. 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are 6 | * met: 7 | * 8 | * * Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above 11 | * copyright notice, this list of conditions and the following disclaimer 12 | * in the documentation and/or other materials provided with the 13 | * distribution. 14 | * * Neither the name of Google Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * --- 31 | * Author: Craig Silverstein 32 | * Copied from google-perftools and modified by Shinichiro Hamaji 33 | * 34 | * These are some portability typedefs and defines to make it a bit 35 | * easier to compile this code under VC++. 36 | * 37 | * Several of these are taken from glib: 38 | * http://developer.gnome.org/doc/API/glib/glib-windows-compatability-functions.html 39 | */ 40 | 41 | #ifndef CTEMPLATE_WINDOWS_PORT_H_ 42 | #define CTEMPLATE_WINDOWS_PORT_H_ 43 | 44 | #include "config.h" 45 | 46 | #if defined(GLOG_USE_GLOG_EXPORT) 47 | # include "glog/export.h" 48 | #endif 49 | 50 | #if !defined(GLOG_EXPORT) 51 | # error "port.h" was not included correctly. 52 | #endif 53 | 54 | #ifdef _WIN32 55 | 56 | # ifndef WIN32_LEAN_AND_MEAN 57 | # define WIN32_LEAN_AND_MEAN /* We always want minimal includes */ 58 | # endif 59 | 60 | # include /* for _getcwd() */ 61 | # include /* because we so often use open/close/etc */ 62 | # include /* for _getpid() */ 63 | # include 64 | # include /* for gethostname */ 65 | 66 | # include /* template_dictionary.cc uses va_copy */ 67 | # include /* for _strnicmp(), strerror_s() */ 68 | # include /* for localtime_s() */ 69 | /* Note: the C++ #includes are all together at the bottom. This file is 70 | * used by both C and C++ code, so we put all the C++ together. 71 | */ 72 | 73 | # ifdef _MSC_VER 74 | 75 | /* 4244: otherwise we get problems when substracting two size_t's to an int 76 | * 4251: it's complaining about a private struct I've chosen not to dllexport 77 | * 4355: we use this in a constructor, but we do it safely 78 | * 4715: for some reason VC++ stopped realizing you can't return after abort() 79 | * 4800: we know we're casting ints/char*'s to bools, and we're ok with that 80 | * 4996: Yes, we're ok using "unsafe" functions like fopen() and strerror() 81 | * 4312: Converting uint32_t to a pointer when testing %p 82 | * 4267: also subtracting two size_t to int 83 | * 4722: Destructor never returns due to abort() 84 | */ 85 | # pragma warning(disable : 4244 4251 4355 4715 4800 4996 4267 4312 4722) 86 | 87 | /* file I/O */ 88 | # define PATH_MAX 1024 89 | # define popen _popen 90 | # define pclose _pclose 91 | # define R_OK 04 /* read-only (for access()) */ 92 | # define S_ISDIR(m) (((m)&_S_IFMT) == _S_IFDIR) 93 | 94 | # define O_WRONLY _O_WRONLY 95 | # define O_CREAT _O_CREAT 96 | # define O_EXCL _O_EXCL 97 | 98 | # define S_IRUSR S_IREAD 99 | # define S_IWUSR S_IWRITE 100 | 101 | /* Not quite as lightweight as a hard-link, but more than good enough for us. */ 102 | # define link(oldpath, newpath) CopyFileA(oldpath, newpath, false) 103 | 104 | # define strcasecmp _stricmp 105 | # define strncasecmp _strnicmp 106 | 107 | /* In windows-land, hash<> is called hash_compare<> (from xhash.h) */ 108 | /* VC11 provides std::hash */ 109 | # if defined(_MSC_VER) && (_MSC_VER < 1700) 110 | # define hash hash_compare 111 | # endif 112 | 113 | /* Windows doesn't support specifying the number of buckets as a 114 | * hash_map constructor arg, so we leave this blank. 115 | */ 116 | # define CTEMPLATE_SMALL_HASHTABLE 117 | 118 | # define DEFAULT_TEMPLATE_ROOTDIR ".." 119 | 120 | # endif // _MSC_VER 121 | 122 | namespace google { 123 | inline namespace glog_internal_namespace_ { 124 | # ifndef HAVE_LOCALTIME_R 125 | GLOG_NO_EXPORT std::tm* localtime_r(const std::time_t* timep, std::tm* result); 126 | # endif // not HAVE_LOCALTIME_R 127 | 128 | # ifndef HAVE_GMTIME_R 129 | GLOG_NO_EXPORT std::tm* gmtime_r(const std::time_t* timep, std::tm* result); 130 | # endif // not HAVE_GMTIME_R 131 | 132 | GLOG_NO_EXPORT 133 | inline char* strerror_r(int errnum, char* buf, std::size_t buflen) { 134 | strerror_s(buf, buflen, errnum); 135 | return buf; 136 | } 137 | } // namespace glog_internal_namespace_ 138 | } // namespace google 139 | 140 | #endif /* _WIN32 */ 141 | 142 | #endif /* CTEMPLATE_WINDOWS_PORT_H_ */ 143 | --------------------------------------------------------------------------------