Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Can-visualc++;2013 Purify和Quantify做什么?_C++_Visual Studio 2013_Purify_Quantify - Fatal编程技术网

C++ Can-visualc++;2013 Purify和Quantify做什么?

C++ Can-visualc++;2013 Purify和Quantify做什么?,c++,visual-studio-2013,purify,quantify,C++,Visual Studio 2013,Purify,Quantify,我们使用VC6.0、Purify、PClint和Quantify在WindowsXP上开发了一个控制台应用程序。VC6无法在Windows 7和8上工作。如果我们要升级到Windows 8,我已经研究了我们的开发环境选项。我们的应用程序是标准C++控制台应用程序。实际上,我们所有的用户都在Linux上。有没有经验丰富的VC++ + PRO 2013或2012跨平台的C++开发?具体来说,它可以进行内存边界检查、内存泄漏检查和代码性能分析(每个函数需要多少时间) 嗯,这并不是说“一个人能做另一个

我们使用VC6.0、Purify、PClint和Quantify在WindowsXP上开发了一个控制台应用程序。VC6无法在Windows 7和8上工作。如果我们要升级到Windows 8,我已经研究了我们的开发环境选项。我们的应用程序是标准C++控制台应用程序。实际上,我们所有的用户都在Linux上。有没有经验丰富的VC++ + PRO 2013或2012跨平台的C++开发?具体来说,它可以进行内存边界检查、内存泄漏检查和代码性能分析(每个函数需要多少时间)

嗯,这并不是说“一个人能做另一个人能做的一切”。它更像是一个十字路口,利用它们来获得最大的覆盖率

Purify是一个运行时检查器,因此它的性能通常优于VisualStudio的内置内存检查功能。但是Purify不做静态分析,所以您需要使用VisualStudio。这是一个巨大的合作关系


我已经研究了开发环境的选项 ... 我们的应用是[跨平台]标准的C++控制台应用程序。 自行车开始脱落。。。这是一个很好的机会,因为您正在编写可移植代码。许多人编写在一个平台上运行的代码,他们从其他平台上的其他工具中解放了诊断功能

下面的所有内容都是免费的(VisualStudioEnterprise下的企业代码分析除外),如果您能够干净地完成此过程,那么您将拥有相当可靠的代码

窗口

使用Visual Studio(任何版本)并显示警告。它们包括
/WAll
/W4
。如果您有Visual Studio Enterprise,请确保添加企业代码分析或添加/analyze开关

您可以在VisualStudio中进行基本内存检查。我不知道最新的纯度如何与之配合。(我不使用它,因为我编写跨平台代码并使用Linux进行重载内存检查)

对于Windows平台,您还应该做其他事情。您可以在OWASP上找到关于开发工具链的讨论

Linux

确保支持GCC、Clang和ICC。使用它们时,请确保启动警告,包括
-Wall
-Wextra
-Wconversion
。GCC是主流,您的代码可能在其上运行良好。ICC是英特尔的编译器,它无情地删除未定义的行为。如果您的代码在ICC下中断,可能是因为编译器/优化器删除了一些未定义的行为(请参阅下面的Clang's undefined sanitizer,了解如何查找违规代码)

Clang3.3的清洁剂真的很好(Clang3.2及以下版本没有)。确保使用
-fsanize=address
-fsanize=undefined
运行。清理程序添加运行时检查程序,并在执行期间查找冲突。自我测试越多越好。一份完整的消毒剂清单可以在网上找到

下面是铿锵3.3的食谱。它们包括如何获取叮当声,如何构建叮当声,以及如何使用santizers执行测试

使用GCC、Clang和ICC完成编译后,在Valgrind下运行程序。Valgrind是另一个动态内存检查器

对于Linux平台,您还应该做其他事情。您可以在OWASP上找到关于开发工具链的讨论


要下载并使用最新版本构建Clang 3.3,请执行以下操作:

wget http://llvm.org/releases/3.3/llvm-3.3.src.tar.gz
wget http://llvm.org/releases/3.3/cfe-3.3.src.tar.gz
wget http://llvm.org/releases/3.3/compiler-rt-3.3.src.tar.gz
# wget http://llvm.org/releases/3.3/lldb-3.3.src.tar.gz
tar xvf llvm-3.3.src.tar.gz
cd llvm-3.3.src/tools
tar xvf ../../cfe-3.3.src.tar.gz
mv cfe-3.3.src clang
# tar xvf ../../lldb-3.3.src.tar.gz
# mv lldb-3.3.src/ lldb
cd ..
cd projects
tar xvf ../../compiler-rt-3.3.src.tar.gz
mv compiler-rt-3.3.src/ compiler-rt
cd ..
./configure --enable-optimized --prefix=/usr/local
make -j4

# Pause to wait for the password prompt
read -p "Press [Enter] key to install..."

# Begin install
sudo make install

# Install does not copy asan_symbolize.py
sudo cp projects/compiler-rt/lib/asan/scripts/asan_symbolize.py /usr/local/bin

# Install does not install scan-build and scan-view
# Perform the copy, and/or put them on-path
sudo mkdir /usr/local/bin/scan-build
sudo cp -r tools/clang/tools/scan-build /usr/local/bin
sudo mkdir /usr/local/bin/scan-view
sudo cp -r tools/clang/tools/scan-view /usr/local/bin

要使用叮当声:

export CC=/usr/local/bin/clang
export CXX=/usr/local/bin/clang++
export CFLAGS="-g3 -fsanitize=undefined"
export CXXFLAGS="-g3 -fsanitize=undefined -fno-sanitize=vptr"

./configure

make

make check | /usr/local/bin/asan_symbolize.py
如果出现任何内存问题,它将类似于以下内容(摘自):

以下是未定义的行为和非法转移的情况(摘自Postgres:


如果你在英特尔的ICC下失败了,那么一定要用
-fsanitize=undefined
在叮当声下运行它,因为ICC会默默地删除任何有问题的代码。这是我发现的最容易找到有问题的代码的方法。

奇怪的是,由于使用unix,你不使用Purify,因为我过去作为C程序员的大部分时间Purify只在unix上运行,而even当它被用于窗户时,它就没有那么好了。
==76794==ERROR: AddressSanitizer: global-buffer-overflow on address
0x000105ad50d2 at pc 0x105a364ab bp 0x7fff5a23f720 sp 0x7fff5a23f718
READ of size 19 at 0x000105ad50d2 thread T0
    #0 0x105a364aa in MemBuf::append MemBuf.cc:248
    #1 0x105a4ef57 in testHttpReply::testSanityCheckFirstLine
testHttpReply.cc:197
    #2 0x1068d71d1 in CppUnit::TestCaseMethodFunctor::operator()() const (in
libcppunit-1.12.1.dylib) + 33
    #3 0x1068cd9a3 in CppUnit::DefaultProtector::protect(CppUnit::Functor
const&, CppUnit::ProtectorContext const&) (in libcppunit-1.12.1.dylib) + 35
    #4 0x1068d4d88 in CppUnit::ProtectorChain::ProtectFunctor::operator()()
const (in libcppunit-1.12.1.dylib) + 24
    #5 0x1068d45e8 in CppUnit::ProtectorChain::protect(CppUnit::Functor const&,
CppUnit::ProtectorContext const&) (in libcppunit-1.12.1.dylib) + 456
    #6 0x1068dcf78 in CppUnit::TestResult::protect(CppUnit::Functor const&,
CppUnit::Test*, std::string const&) (in libcppunit-1.12.1.dylib) + 56
    #7 0x1068d6d1d in CppUnit::TestCase::run(CppUnit::TestResult*) (in
libcppunit-1.12.1.dylib) + 285
    #8 0x1068d77b6 in
CppUnit::TestComposite::doRunChildTests(CppUnit::TestResult*) (in
libcppunit-1.12.1.dylib) + 54
    #9 0x1068d76be in CppUnit::TestComposite::run(CppUnit::TestResult*) (in
libcppunit-1.12.1.dylib) + 30
    #10 0x1068d77b6 in
CppUnit::TestComposite::doRunChildTests(CppUnit::TestResult*) (in
libcppunit-1.12.1.dylib) + 54
    #11 0x1068d76be in CppUnit::TestComposite::run(CppUnit::TestResult*) (in
libcppunit-1.12.1.dylib) + 30
    #12 0x1068dcde1 in CppUnit::TestResult::runTest(CppUnit::Test*) (in
libcppunit-1.12.1.dylib) + 33
    #13 0x1068de9a5 in CppUnit::TestRunner::run(CppUnit::TestResult&,
std::string const&) (in libcppunit-1.12.1.dylib) + 53
    #14 0x105a55a97 in main testMain.cc:31
    #15 0x7fff90af07e0 in start (in libdyld.dylib) + 0
    #16 0x0
0x000105ad50d2 is located 46 bytes to the left of global variable '.str28' from
'tests/testHttpReply.cc' (0x105ad5100) of size 16
  '.str28' is ascii string 'HTTP/1.1 -000

0x000105ad50d2 is located 0 bytes to the right of global variable '.str27' from
'tests/testHttpReply.cc' (0x105ad50c0) of size 18
  '.str27' is ascii string 'HTTP/1.10 Okay
make check
...

vacuuming database template1 ... localtime.c:127:20: runtime error:
left shift of negative value -1
pg_lzcompress.c:601:5: runtime error: left shift of negative value -68
pg_lzcompress.c:601:5: runtime error: left shift of negative value -68
pg_lzcompress.c:385:16: runtime error: left shift of negative value -68
pg_lzcompress.c:615:4: runtime error: left shift of negative value -68