这是Valgrind调试结果:
valgrind --leak-check=yes --track-origins=yes ./ns-server
==43648== Memcheck, a memory error detector
==43648== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==43648== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==43648== Command: ./ns-server
==43648==
--43648-- ./ns-server:
--43648-- dSYM directory is missing; consider using --dsymutil=yes
111111111111222222222222first get nextlen 564
nextlen is 564
i am here decry
==43648== Thread 2:
==43648== Invalid read of size 1
==43648== at 0x6C49: strlen (vg_replace_strmem.c:427)
==43648== by 0x100133F4F: StringBuffer::setString(char const*) (in ./ns-server)
==43648== by 0x100158B2F: XString::setFromAnsi(char const*) (in ./ns-server)
==43648== by 0x100024476: CkRsa::DecryptStringENC(char const*, bool, CkString&) (in ./ns-server)
==43648== by 0x10002452A: CkRsa::decryptStringENC(char const*, bool) (in ./ns-server)
==43648== by 0x10001222A: My_RSA::MyDecryption(char*) (in ./ns-server)
==43648== by 0x1000013FA: Server::Register(char*, int, char*) (in ./ns-server)
==43648== by 0x100001114: Server::Evaluate_MSG(void*) (in ./ns-server)
==43648== by 0x409898: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib)
==43648== by 0x409729: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
==43648== by 0x40DFC8: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
==43648== Address 0x100476730 is 0 bytes after a block of size 128 alloc'd
==43648== at 0x47E1: malloc (vg_replace_malloc.c:300)
==43648== by 0x100001334: Server::Register(char*, int, char*) (in ./ns-server)
==43648== by 0x100001114: Server::Evaluate_MSG(void*) (in ./ns-server)
==43648== by 0x409898: _pthread_body (in /usr/lib/system/libsystem_pthread.dylib)
==43648== by 0x409729: _pthread_start (in /usr/lib/system/libsystem_pthread.dylib)
==43648== by 0x40DFC8: thread_start (in /usr/lib/system/libsystem_pthread.dylib)
==43648==
这个结果只是告诉我错误发生在哪个文件中,但是没有告诉我它的行号,它的确切位置。我的文件包含数千行代码,如何为Valgrind设置选项,以便我可以获得错误发生的确切行数?
我的makefile:
LIBS = libStatic/libchilkat_i386.a libStatic/libchilkat_x86_64.a -lpthread
GPP = g++
TARGET = -o ns-server
CPP = main.cpp Server.cpp TCPConnect.cpp RSAsample.cpp
all:
$(GPP) $(TARGET) $(CPP) $(LIBS)
clean:
rm ns-server
答案 0 :(得分:1)
如果没有二进制文件中的调试符号,valgrind将无法显示文件名和行号信息。要将调试信息放入二进制文件中,需要在编译语句中添加-g
选项和gcc
。
有关详细信息,请参阅在线valgrind manual。