【问题标题】:remove debug strings in release build在发布版本中删除调试字符串
【发布时间】:2017-11-03 04:22:34
【问题描述】:

我使用LOG_DEBUG 函数将调试信息打印到屏幕上。我使用#define _DEBUG 通过在编译时(发布时)定义_DEBUG FLAG 来禁用LOG_DEBUG 功能。但是发布构建应用程序的 linux strings 命令仍然显示已编译应用程序中存在的调试字符串。那么消除LOG_DEBUG的参数的替代方法是什么?

#ifdef _DEBUG
#define LOG_DEBUG(fmt, ...) printf("[D][%s:%d %s]", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#else
#define LOG_DEBUG(fmt, ...)
#endif


LOG_DEBUG("this is a debug string");     // "this is a debug string" exists in app release build yet

我使用的编译器:ARM/Thumb C/C++ Compiler, RVCT3.1 [Build 569]

优化:-O3

【问题讨论】:

  • 请编辑您的问题以包含编译器名称和版本。您是否尝试过更改优化设置?
  • 我猜一种方法是用#ifdef包围每个调试,但我假设你不想这样做; )
  • 函数调用量很大,我正在寻找更简洁的方法
  • @Manidevs 因此眨眼的脸:D
  • 您目前正在做的是处理这种情况的标准方法。在不包含 _DEBUG 的构建中,该字符串应该消失。为什么不生成 .i 文件,看看那里是否存在字符串。

标签: c debugging release armcc rvds


【解决方案1】:

你可以试试stringification:

#include <stdio.h>

#define _DEBUG

#ifdef _DEBUG
#define LOG_DEBUG(str) do { printf("[D][%s:%d %s] ", \
                               __FILE__, \
                               __LINE__, \
                               __FUNCTION__); \
                            puts(#str); } while(0)
#else
#define LOG_DEBUG(str)
#endif

int main() {
  LOG_DEBUG(this is a debug string);
  return 0;
}

注意:我在 clang 中对此进行了测试,没有表现出您描述的行为。

【讨论】:

  • 也许这只是一个 armcc 问题
猜你喜欢
  • 2012-11-13
  • 2010-10-27
  • 2020-08-02
  • 1970-01-01
  • 2019-12-13
  • 1970-01-01
  • 2014-12-24
相关资源
最近更新 更多