Windows XP에서 VC 6.0, Purify, PC-Lint 및 Quantify를 사용하여 콘솔 응용 프로그램을 개발합니다. VC6은 Windows 7 및 8에서 작동하지 않습니다. Windows 8로 업그레이드하려면 개발 환경에 대한 옵션을 살펴 보았습니다. 우리의 응용 프로그램은 표준 C++ 콘솔 응용 프로그램입니다. 거의 모든 사용자는 Linux를 사용합니다. 누구든지 크로스 플랫폼 C++ 개발을 위해 VC++ Pro 2013 또는 2012에 대한 경험이 있습니까? 특히, 메모리 경계 검사, 메모리 누수 검사 및 코드 성능 분석 (각 기능이 소요되는 시간)을 수행 할 수 있습니까?Visual C++ 2013에서 Purify 및 Quntify가 수행 할 수 있습니까?
답변
Visual C++ 2013에서는 Purify와 Quantify가하는 일을 할 수 있습니까?
글쎄, 그다지 "다른 사람이하는 모든 일을 할 수 있지 않습니까?" 그것의 더 많은 교차로처럼, 그리고 그들을 모두 사용하여 가장 범위를 얻을.
Purify는 런타임 검사기이므로 일반적으로 Visual Studio의 내장 메모리 검사 기능을 능가합니다. 그러나 Purify는 정적 분석을 수행하지 않으므로 Visual Studio를 사용해야합니다. 그것의 큰 파트너쉽.
나는 우리의 응용 프로그램은 [크로스 플랫폼] 표준 C++ 콘솔 응용 프로그램입니다 ... 개발 환경 에 대한 우리의 옵션을 살펴 보았다.
자전거 흘리기 시작 ... 이것은 휴대용 코드를 작성하기 때문에 좋은 기회입니다. 많은 사람들이 하나의 플랫폼에서 실행되는 코드를 작성하고 다른 플랫폼의 다른 도구에서 진단을 풀어냅니다.
아래의 내용은 모두 무료입니다 (Visual Studio Enterprise의 Enterprise Code Analysis 제외). 프로세스가 정상적으로 진행될 수 있다면 상당히 견고한 코드를 얻을 수 있습니다.
윈도우
를 사용하여 비주얼 스튜디오 (모든 버전) 및 경고를 켜십시오. 여기에는 /WAll
및 /W4
이 포함됩니다. Visual Studio Enterprise를 사용하는 경우 엔터프라이즈 코드 분석을 추가하거나 /analyze
스위치를 추가해야합니다.
Visual Studio에서 기본 메모리 검사를받습니다. 최신 순도가 어떻게 작동하는지 모르겠습니다. (크로스 플랫폼 코드를 작성하고 중대한 메모리 검사를 위해 Linux를 사용하기 때문에 사용하지 않습니다.)
Windows 플랫폼에서해야 할 다른 사항이 있습니다. OWASP의 C-Based Toolchain Hardening에서 개발 툴 체인에 대한 설명을 찾을 수 있습니다.
리눅스
GCC, 연타, 및 ICC를 지원해야합니다. 경고문을 사용하려면 -Wall
, -Wextra
및 -Wconversion
을 포함하여 경고를 불러 오십시오. GCC가 주류이며 코드가 잘 작동 할 것입니다. ICC는 인텔의 컴파일러이며 정의되지 않은 동작을 제거하는 데 무자비합니다. 코드가 ICC에서 깨진다면 아마도 컴파일러/최적화 기가 정의되지 않은 동작을 제거했기 때문일 것입니다 (문제의 코드를 찾는 방법은 Clang의 정의되지 않은 새니 타이 져 참조).
Clang 3.3은 위생 도구 (Clang 3.2 이하에는 포함되지 않음)로 정말 빛납니다. -fsanitize=address
및 -fsanitize=undefined
으로 실행하십시오.위생 처리 프로그램은 런타임 체커를 추가하고 실행 중 위반을 찾습니다. 자신감이 많을수록 좋습니다. 소독제의 전체 목록은 Clang's Controlling Code Generation입니다.
Clang 3.3 요리법은 다음과 같습니다. 여기에는 Clang을 가져 오는 방법, Clang을 만드는 방법, 그리고 santizers를 사용하여 테스트를 수행하는 방법이 포함됩니다.
GCC, Clang 및 ICC로 편집을 완료 한 후 Valgrind에서 프로그램을 실행하십시오. Valgrind는 또 다른 동적 메모리 검사기입니다.
Linux 플랫폼에서해야 할 다른 사항이 있습니다. OWASP의 C-Based Toolchain Hardening에서 개발 툴 체인에 대한 설명을 찾을 수 있습니다.
최신으로 연타 3.3을 다운로드하고 빌드하려면 : 당신이 어떤 메모리 문제가 유사합니다 얻는 경우에
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
:
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
가 연타를 사용하려면 다음 (Squid 3.3.9 Self Test Failures on Mac OS X 10.8에서 가져옴) :
==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
그리고 여기에 무슨 정의되지 않은 동작입니다 및 불법 변화는 포스트 그레스의 Clang 3.3 findings and Illegal Shifts)에서 가져온 (처럼 보이는 : 당신이 인텔의 ICC에서 실패하는 경우, 다음 -fsanitize=undefined
와 연타에서 실행해야
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
ICC 것 때문에 문제가되는 코드를 자동으로 제거하십시오. 내가 위반 한 코드를 찾은 가장 쉬운 방법입니다.