chromium 44 如何在 release 版本打印 Debug 日志

在某些特殊情况下,可能需要在release版本中打印出 Debug 版本的日志(DLOG/DVLOG系列)。可以在编译时,指定 dcheck_always_on="true"

根据以下4个文件,可知 dcheck_always_on="true"

src\base\logging.h 中的

// ...
#if DCHECK_IS_ON()

#define DLOG_IS_ON(severity) LOG_IS_ON(severity)
#define DLOG_IF(severity, condition) LOG_IF(severity, condition)
#define DLOG_ASSERT(condition) LOG_ASSERT(condition)
#define DPLOG_IF(severity, condition) PLOG_IF(severity, condition)
#define DVLOG_IF(verboselevel, condition) VLOG_IF(verboselevel, condition)
#define DVPLOG_IF(verboselevel, condition) VPLOG_IF(verboselevel, condition)

#else  // DCHECK_IS_ON()

// If !DCHECK_IS_ON(), we want to avoid emitting any references to |condition|
// (which may reference a variable defined only if DCHECK_IS_ON()).
// Contrast this with DCHECK et al., which has different behavior.

#define DLOG_IS_ON(severity) false
#define DLOG_IF(severity, condition) EAT_STREAM_PARAMETERS
#define DLOG_ASSERT(condition) EAT_STREAM_PARAMETERS
#define DPLOG_IF(severity, condition) EAT_STREAM_PARAMETERS
#define DVLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS
#define DVPLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS

#endif  // DCHECK_IS_ON()
// ...

src\base\dcheck_is_on.h

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_DCHECK_IS_ON_H_
#define BASE_DCHECK_IS_ON_H_

#include "base/debug/debugging_buildflags.h"

#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
#define DCHECK_IS_ON() false
#else
#define DCHECK_IS_ON() true
#endif

#if BUILDFLAG(EXPENSIVE_DCHECKS_ARE_ON)
#define EXPENSIVE_DCHECKS_ARE_ON() true
#else
#define EXPENSIVE_DCHECKS_ARE_ON() false
#endif

#endif  // BASE_DCHECK_IS_ON_H_

src\build\config\BUILD.gn

#...
  if (dcheck_always_on) {
    defines += [ "DCHECK_ALWAYS_ON=1" ]
    if (dcheck_is_configurable) {
      defines += [ "DCHECK_IS_CONFIGURABLE" ]
    }
  }
#...

src\build\config\dcheck_always_on.gni

# Copyright (c) 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# TODO(crbug.com/1233050): Until the bug is resolved we need to include
# gclient_args for the definition of build_with_chromium and build_overrides
# for client overrides of that flag. The latter should go away.
import("//build/config/gclient_args.gni")
import("//build_overrides/build.gni")
declare_args() {
  # Enables DCHECKs to be built-in, but to default to being non-fatal/log-only.
  # DCHECKS can then be set as fatal/non-fatal via the "DcheckIsFatal" feature.
  # See https://bit.ly/dcheck-albatross for details on how this is used.
  dcheck_is_configurable = false
}

declare_args() {
  # Set to false to disable DCHECK in Release builds. This is enabled by default
  # for non-official builds on the below platforms.
  # This default only affects Chromium as indicated by build_with_chromium.
  # Other clients typically set this to false. If another client wants to use
  # the same default value as Chromium, we'd need to add a separate gclient
  # variable to replace build_with_chromium here.
  # Note: If you are here to revert because DCHECKs are failing on a specific OS
  # please prefer excluding OSes rather than reverting . I.e. if Mac builds
  # break badly but other platforms are reasonably stable, add "&& !is_mac"
  # instead of reverting.
  dcheck_always_on =
      (build_with_chromium && !is_official_build) || dcheck_is_configurable
}

declare_args() {
  # Set to false to disable EXPENSIVE_DCHECK()s.
  # TODO(crbug.com/1225701): Hash out whether expensive DCHECKs need to be
  # disabled for developers by default. There's concern that disabling these
  # globally by default effectively reduces them to zero coverage. This is
  # in place so that you can disable expensive DCHECKs while retaining some
  # DCHECK coverage, which is especially important in user-facing builds.
  enable_expensive_dchecks = is_debug || dcheck_always_on
}

可以在 release 版本增加 编译参数 dcheck_always_on="true"

也就是生成的 args.gn 带参数 dcheck_always_on = true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值