2

我正在编译农场的 GCC119 上工作。该机器是 AIX 7.1、POWER8 和 IBM XLC 13.1。我正在尝试使用调试堆:

gcc119$ cat test.cxx
#include <altivec.h>
#undef vector
#undef pixel
#undef bool

#include <cstdlib>

int main(int argc, char* argv[])
{
  unsigned char x[32];
  std::memset(x, 0x00, 32);

  return 0;
}

编译结果:

gcc119$ xlC -DDEBUG -g3 -O0 -qheapdebug -qro test.cxx -o test.exe
"test.cxx", line 11.3: 1540-0130 (S) "std::_debug_memset" is not declared.

两者都<cstring>导致<string.h>错误。我也尝试包含<cstdlib>and <stdlib.h>,它们导致了同样的错误。

优化和编程指南手册对调试内存函数进行了很好的讨论,但处理方法仅限于 C。它似乎不处理 C++。

如何在 C++ 程序中使用调试堆?


gcc119$ oslevel -s
7200-00-01-1543

gcc119$ xlC -qversion
IBM XL C/C++ for AIX, V13.1.3 (5725-C72, 5765-J07)
Version: 13.01.0003.0004
4

2 回答 2

1

根据@user10688376 的观察,这就是我想出的。我认为这在技术上是未定义的行为,因为我不允许在命名空间中放置像_debug_memsetand这样的符号。在这一点上,潜在的 UB 比编译失败且没有测试要好。_debug_memcpystd

#if defined(_AIX) && (defined(__xlc__) || defined(__xlC__) || defined(__ibmxl__))
# if defined(__DEBUG_ALLOC__)
namespace std {
  using ::_debug_memset;
  using ::_debug_memcpy;
}
# endif
#endif

_AIX使用它是因为它标识了操作系统。调试堆在 Linux 设备上不可用。(一些 IBM XLC 编译器也在 Linux 上运行)。

__xlc____xlC__用于检测 IBM XLC 编译器 13.0 及更早版本。该编译器完全由 IBM 构建。

__ibmxl__用于检测 IBM XLC 编译器 13.1 及更高版本。此编译器使用 Clang 前端和 IBM 后端。我认为这是LLVM Review 21078中提到的“LLC”编译器。

__DEBUG_ALLOC__之所以使用是因为编译器将其设置为-qheapdebug.

于 2018-11-22T10:13:56.850 回答
1

您应该尝试包含<string.h>并使用 unqualified memset。根据IBM XL C/C++ Programming Guide_debug_memset生活在string.h. 所以问题就变成了,不应该<cstring>通过 提供它std::吗?在IBM XL C/C++ 标准库参考中,它显示了所有 using 声明,并且没有调试函数。

namespace std
{
using ::size_t; using ::memcmp; using ::memcpy; using ::memmove;
using ::memset; using ::strcat; using ::strcmp; using ::strcoll;
using ::strcpy; using ::strcspn; using ::strerror; using ::strlen;
using ::strncat; using ::strncmp; using ::strncpy; using ::strspn;
using ::strtok; using ::strxfrm;
}
于 2018-11-21T23:35:11.880 回答