- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编辑:
似乎有一些东西不受 valgrind 和 alpine ditrib 的支持。使用像这样的简单 main :
#include <iostream>
int main() {return 0;}
valgrind 返回泄漏:
==8== Memcheck, a memory error detector
==8== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==8== Using Valgrind-3.19.0-8d3c8034b8-20220411 and LibVEX; rerun with -h for copyright info
==8== Command: ./toto
==8== Parent PID: 1
==8==
--8--
--8-- Valgrind options:
--8-- --track-origins=yes
--8-- --keep-debuginfo=yes
--8-- --read-inline-info=yes
--8-- --error-exitcode=1
--8-- --leak-check=full
--8-- --errors-for-leak-kinds=all
--8-- --show-leak-kinds=all
--8-- --verbose
--8-- --sigill-diagnostics=no
--8-- --log-file=valgrind-out.txt
--8-- Contents of /proc/version:
--8-- Linux version 5.10.16.3-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Fri Apr 2 22:23:49 UTC 2021
--8--
--8-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3-avx-avx2-bmi-f16c-rdrand-rdseed
--8-- Page sizes: currently 4096, max supported 4096
--8-- Valgrind library directory: /usr/libexec/valgrind
--8-- Reading syms from /src/toto
--8-- Reading syms from /lib/ld-musl-x86_64.so.1
--8-- object doesn't have a symbol table
--8-- Reading syms from /usr/libexec/valgrind/memcheck-amd64-linux
--8-- object doesn't have a dynamic symbol table
--8-- Scheduler: using generic scheduler lock implementation.
--8-- Reading suppressions file: /usr/libexec/valgrind/default.supp
==8== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-8-by-???-on-0d65120c6746
==8== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-8-by-???-on-0d65120c6746
==8== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-8-by-???-on-0d65120c6746
==8==
==8== TO CONTROL THIS PROCESS USING vgdb (which you probably
==8== don't want to do, unless you know exactly what you're doing,
==8== or are doing some strange experiment):
==8== /usr/libexec/valgrind/../../bin/vgdb --pid=8 ...command...
==8==
==8== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==8== /path/to/gdb ./toto
==8== and then give GDB the following command
==8== target remote | /usr/libexec/valgrind/../../bin/vgdb --pid=8
==8== --pid is optional if only one valgrind process is running
==8==
--8-- Reading syms from /usr/libexec/valgrind/vgpreload_core-amd64-linux.so
--8-- object doesn't have a symbol table
--8-- Reading syms from /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so
--8-- object doesn't have a symbol table
--8-- REDIR: 0x405082f (libc.musl-x86_64.so.1:strlen) redirected to 0x48a7b10 (strlen)
--8-- REDIR: 0x40505f1 (libc.musl-x86_64.so.1:strcpy) redirected to 0x48a7b72 (strcpy)
--8-- REDIR: 0x4050534 (libc.musl-x86_64.so.1:strchr) redirected to 0x48a787c (strchr)
--8-- REDIR: 0x4050935 (libc.musl-x86_64.so.1:strncmp) redirected to 0x48a7f6a (strncmp)
--8-- REDIR: 0x40509bd (libc.musl-x86_64.so.1:strnlen) redirected to 0x48a7aea (strnlen)
--8-- REDIR: 0x4050a80 (libc.musl-x86_64.so.1:strspn) redirected to 0x48ab61a (strspn)
--8-- REDIR: 0x4050601 (libc.musl-x86_64.so.1:strcspn) redirected to 0x48ab5ba (strcspn)
--8-- Reading syms from /usr/lib/libstdc++.so.6.0.29
--8-- object doesn't have a symbol table
--8-- REDIR: 0x40509f9 (libc.musl-x86_64.so.1:strrchr) redirected to 0x48a77e9 (strrchr)
--8-- Reading syms from /usr/lib/libgcc_s.so.1
--8-- object doesn't have a symbol table
--8-- REDIR: 0x4023529 (libc.musl-x86_64.so.1:malloc) redirected to 0x48a2650 (malloc)
--8-- REDIR: 0x40505d9 (libc.musl-x86_64.so.1:strcmp) redirected to 0x48a847c (strcmp)
==8==
==8== HEAP SUMMARY:
==8== in use at exit: 72,704 bytes in 1 blocks
==8== total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated
==8==
==8== Searching for pointers to 1 not-freed blocks
==8== Checked 51,200 bytes
==8==
==8== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
==8== at 0x48A26D5: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==8== by 0x4974557: ??? (in /usr/lib/libstdc++.so.6.0.29)
==8== by 0x4059482: ??? (in /lib/ld-musl-x86_64.so.1)
==8== by 0x409693F: ???
==8== by 0x4A7651F: ??? (in /usr/lib/libstdc++.so.6.0.29)
==8== by 0x1FFF000CFF: ???
==8== by 0xB907FED: ???
==8== by 0x5C1A2: ???
==8== by 0xCE9F: ???
==8== by 0x1CEAEF: ???
==8==
==8== LEAK SUMMARY:
==8== definitely lost: 0 bytes in 0 blocks
==8== indirectly lost: 0 bytes in 0 blocks
==8== possibly lost: 0 bytes in 0 blocks
==8== still reachable: 72,704 bytes in 1 blocks
==8== suppressed: 0 bytes in 0 blocks
==8==
==8== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
为了便于复制,您可以使用这样的 docker 文件:
FROM alpine
RUN apk update && apk add libstdc++ g++ make linux-headers valgrind
WORKDIR /src
CMD ["make"]
用这个makefile
MAKEFLAGS += --no-print-directory
CC=g++
CFLAGS=-W -Wall -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wno-missing-braces -ansi -pedantic -std=c++20 -I/usr/local/include
LDFLAGS=-L /usr/lib/openssl/lib -L /usr/lib
EXEC_DEBUG=toto
DEBOBJDIR=./obj/debug
SRCDIR=.
SRC_FILES=$(wildcard $(SRCDIR)/*/*/*.cpp $(SRCDIR)/*/*.cpp $(SRCDIR)/*.cpp)
DEBOBJ= $(SRC_FILES:%.cpp=$(DEBOBJDIR)/%.o)
DEPS= $(DEBOBJ:.o=.d)
MEMORYCHECKER=valgrind
MEMORY_RESULT_FILE=valgrind-out.txt
VALGRIND_FLAGS=--error-exitcode=1 --leak-check=full --errors-for-leak-kinds=all --show-leak-kinds=all --verbose --sigill-diagnostics=no --log-file=$(MEMORY_RESULT_FILE)
VALGRIND_FULL_FLAGS=--track-origins=yes --keep-debuginfo=yes --read-inline-info=yes
.PHONY: all clear
all: $(EXEC_DEBUG) fullMemoryCheck
-include $(DEPS)
$(EXEC_DEBUG): $(DEBOBJ)
$(CC) -o $@ $^ $(LDFLAGS)
$(DEBOBJDIR)/%.o : %.cpp makefile
@mkdir -p $(dir $@)
$(CC) -o $@ -MP -MMD -c $< $(CFLAGS) -g
clean:
find $(DEBOBJDIR) -name "*.o" -type f -delete
find $(DEBOBJDIR) -name "*.d" -type f -delete
clear: clean
rm -rf $(EXEC) $(EXEC_DEBUG)
fullMemoryCheck: $(EXEC_DEBUG)
@export GLIBCXX_FORCE_NEW
$(MEMORYCHECKER) $(VALGRIND_FULL_FLAGS) $(VALGRIND_FLAGS) ./$(EXEC_DEBUG)
正如@Paul Floyd 提到的那样,这里声明了一个现有的错误:https://bugs.kde.org/show_bug.cgi?id=426751但没有已知问题。所以我用我的例子来帮助找到 alpine (lib musl libc) 中不支持的内容。
PS:问题出在iostream,因为如果我评论include,它就会消失。
旧版本:
经过大量搜索后,我找不到一种方法来查看代码中“泄漏”(仍可访问)的堆栈跟踪。正如我在文档中看到的那样,我向 valgrind 添加了一些选项“--track-origins=yes --keep-debuginfo=yes --read-inline-info=yes”,但这对我没有帮助。
我的编译行看起来像这样(使用 -g3):
g++ -o obj/debug/./src/file1.o -MP -MMD -c src/file1.cpp -W -Wall -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wno-missing-braces -ansi -pedantic -std=c++20 -I/usr/local/include -DRAPIDJSON_HAS_STDSTRING -g3
g++ -o obj/debug/./src/file2.o -MP -MMD -c src/file2.cpp -W -Wall -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wno-missing-braces -ansi -pedantic -std=c++20 -I/usr/local/include -DRAPIDJSON_HAS_STDSTRING -g3
g++ -o obj/debug/./src/file3.o -MP -MMD -c src/file3.cpp -W -Wall -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wno-missing-braces -ansi -pedantic -std=c++20 -I/usr/local/include -DRAPIDJSON_HAS_STDSTRING -g3
...
g++ -o obj/debug/./src/fileX.o -MP -MMD -c src/fileX.cpp -W -Wall -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wno-missing-braces -ansi -pedantic -std=c++20 -I/usr/local/include -DRAPIDJSON_HAS_STDSTRING -g3
g++ -o obj/debug/./src/main.o -MP -MMD -c src/main.cpp -W -Wall -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wno-missing-braces -ansi -pedantic -std=c++20 -I/usr/local/include -DRAPIDJSON_HAS_STDSTRING -g3
g++ -o botsd obj/debug/./src/file1.o obj/debug/./src/file2.o obj/debug/./src/file3.o obj/debug/./src/fileX.o obj/debug/./src/main.o -L /usr/lib/openssl/lib -L /usr/lib -llog4cplus -lpthread -lssl -lcrypto -lcurl
g++ -c -g3 -I. -I.. -std=c++20 -I/usr/include -I./cxxtest-4.4/ -DCXXTEST_RUNNING -DRAPIDJSON_HAS_STDSTRING -o output/OutputTrace.o ../src/cmdLine/OutputTrace.cpp
python3 cxxtest-4.4/bin/cxxtestgen -o output/testMemory.cpp --error-printer testFile1.h testFile2.h testFile3.h ... testFileX.h
g++ -c -g3 -I. -I.. -std=c++20 -I/usr/include -I./cxxtest-4.4/ -DCXXTEST_RUNNING -DRAPIDJSON_HAS_STDSTRING output/testMemory.cpp -o output/testMemory.o
g++ -Wall -g3 -I. -I.. output/testMemory.o ../obj/debug/src/file1.o ../obj/debug/src/file2.o ../obj/debug/src/file3.o ... ../obj/debug/src/fileX.o -L /usr/lib/openssl/lib -L /usr/lib -llog4cplus -lpthread -lssl -lcrypto -lcurl -o output/testMemory
从我的主要 makefile 中提取:
MAKEFLAGS += --no-print-directory
CC=g++
CPPCHECK=cppcheck
CFLAGS=-W -Wall -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wno-missing-braces -ansi -pedantic -std=c++20 -I/usr/local/include -DRAPIDJSON_HAS_STDSTRING
LDFLAGS=-L /usr/lib/openssl/lib -L /usr/lib -llog4cplus -lpthread -lssl -lcrypto -lcurl
EXEC_DEBUG=test
DEBOBJDIR=./obj/debug
SRCDIR=./src
TESTDIR=./tests
SRC=$(wildcard $(SRCDIR)/*/*/*.cpp $(SRCDIR)/*/*.cpp $(SRCDIR)/*.cpp)
DEBOBJ= $(SRC:%.cpp=$(DEBOBJDIR)/%.o)
DEPS= $(DEBOBJ:.o=.d)
.PHONY: all clean clear
all: $(EXEC_DEBUG) run-tests
-include $(DEPS)
$(EXEC_DEBUG): $(DEBOBJ)
$(CC) -o $@ $^ $(LDFLAGS)
$(DEBOBJDIR)/%.o : %.cpp makefile
@mkdir -p $(dir $@)
$(CC) -o $@ -MP -MMD -c $< $(CFLAGS) -g3
test-clean:
+@cd $(TESTDIR) && make clean
clean: test-clean
find $(DEBOBJDIR) -name "*.o" -type f -delete
find $(DEBOBJDIR) -name "*.d" -type f -delete
clear: clean
rm -rf $(EXEC_DEBUG)
run-tests: $(EXEC_DEBUG)
+@cd $(TESTDIR) && make
fullMemoryCheck: $(EXEC_DEBUG)
+@cd $(TESTDIR) && make fullMemoryCheck
然后我像这样启动 Valgrind(我认为 GLIBCXX_FORCE_NEW 没用,但我尝试了很多东西:))
export GLIBCXX_FORCE_NEW
valgrind --track-origins=yes --keep-debuginfo=yes --read-inline-info=yes --error-exitcode=1 --leak-check=full --errors-for-leak-kinds=all --show-leak-kinds=all --verbose --sigill-diagnostics=no --log-file=valgrind-out.txt ./output/testMemory
从我的辅助(测试)makefile 中查看:
CXXC = g++ -Wall -g3 -I. -I..
CC = g++ -c -g3 -I. -I.. -std=c++20 -I/usr/include -I./cxxtest-4.4/ -DCXXTEST_RUNNING -DRAPIDJSON_HAS_STDSTRING
LDFLAGS=-L /usr/lib/openssl/lib -L /usr/lib -llog4cplus -lpthread -lssl -lcrypto -lcurl
TESTGEN=cxxtest-4.4/bin/cxxtestgen
MEMORYCHECKER=valgrind
MEMORY_RESULT_FILE=valgrind-out.txt
VALGRIND_FLAGS=--error-exitcode=1 --leak-check=full --errors-for-leak-kinds=all --show-leak-kinds=all --verbose --sigill-diagnostics=no --log-file=$(MEMORY_RESULT_FILE)
VALGRIND_FULL_FLAGS=--track-origins=yes --keep-debuginfo=yes --read-inline-info=yes
TARGETS=error_printer
VALGRIND_TARGET=testMemory
OUTDIR=output
OBJDIR=../obj/debug/src
TST_FILES=$(wildcard */*/*.h */*.h)
TSTFILES= $(filter-out $(wildcard cxxtest*/*/*), $(TST_FILES))
NOPERFFILES= $(filter-out $(wildcard */Perf*.h), $(TSTFILES))
NO_PERF_FILES= $(filter-out $(wildcard */*/Perf*.h), $(NOPERFFILES))
OBJ_FILES=$(wildcard $(OBJDIR)/*/*/*.o $(OBJDIR)/*/*.o)
ADDITIONNAL_SRC=../src/cmdLine/OutputTrace.cpp
EXCLUDE_OBJ=$(subst ../,../obj/debug/,$(ADDITIONNAL_SRC:%.cpp=%.o))
ADDITIONNAL_OBJ=$(OUTDIR)/$(addsuffix .o,$(basename $(notdir $(ADDITIONNAL_SRC))))
FINAL_OBJ=$(filter-out $(EXCLUDE_OBJ), $(OBJ_FILES))
.PHONY: all clean distclean fullMemoryCheck
all: run memoryCheck
clean:
rm -f $(OUTDIR)/*
distclean: clean
rm -f Makefile
memoryCheck: $(VALGRIND_TARGET)
@export GLIBCXX_FORCE_NEW
@if $(MEMORYCHECKER) $(VALGRIND_FLAGS) ./$(OUTDIR)/$(VALGRIND_TARGET); then \
echo " Memory is clear!"; \
else \
cat $(MEMORY_RESULT_FILE); \
exit "Memory problems found"; \
fi
fullMemoryCheck: $(VALGRIND_TARGET)
@export GLIBCXX_FORCE_NEW
$(MEMORYCHECKER) $(VALGRIND_FULL_FLAGS) $(VALGRIND_FLAGS) ./$(OUTDIR)/$(VALGRIND_TARGET)
run: $(TARGETS)
@./$(OUTDIR)/$(TARGETS)
$(ADDITIONNAL_OBJ): $(ADDITIONNAL_SRC)
@mkdir -p $(dir $@)
$(CC) -o $@ $<
$(TARGETS).cpp: $(TSTFILES)
python3 $(TESTGEN) -o $(OUTDIR)/$@ --error-printer $(TSTFILES)
$(TARGETS).o: $(TARGETS).cpp
$(CC) $(OUTDIR)/$(TARGETS).cpp -o $(OUTDIR)/$(TARGETS).o
$(TARGETS): $(ADDITIONNAL_OBJ) $(TARGETS).o
$(CXXC) $(OUTDIR)/$(TARGETS).o $(ADDITIONNAL_OBJ) $(FINAL_OBJ) $(LDFLAGS) -o $(OUTDIR)/$(TARGETS)
$(VALGRIND_TARGET).cpp: $(NO_PERF_FILES)
python3 $(TESTGEN) -o $(OUTDIR)/$@ --error-printer $(NO_PERF_FILES)
$(VALGRIND_TARGET).o: $(VALGRIND_TARGET).cpp
$(CC) $(OUTDIR)/$(VALGRIND_TARGET).cpp -o $(OUTDIR)/$(VALGRIND_TARGET).o
$(VALGRIND_TARGET): $(ADDITIONNAL_OBJ) $(VALGRIND_TARGET).o
$(CXXC) $(OUTDIR)/$(VALGRIND_TARGET).o $(ADDITIONNAL_OBJ) $(FINAL_OBJ) $(LDFLAGS) -o $(OUTDIR)/$(VALGRIND_TARGET)
我必须添加 --sigill-diagnostics=no 以避免使用 SIGKILL 的 openSSL 出现错误(参见 https://bugzilla.redhat.com/show_bug.cgi?id=1495320 )
现在输出只是一个“泄漏”:
==255== Memcheck, a memory error detector
==255== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==255== Using Valgrind-3.19.0-8d3c8034b8-20220411 and LibVEX; rerun with -h for copyright info
==255== Command: ./output/testMemory
==255== Parent PID: 246
==255==
--255--
--255-- Valgrind options:
--255-- --track-origins=yes
--255-- --keep-debuginfo=yes
--255-- --read-inline-info=yes
--255-- --error-exitcode=1
--255-- --leak-check=full
--255-- --errors-for-leak-kinds=all
--255-- --show-leak-kinds=all
--255-- --verbose
--255-- --sigill-diagnostics=no
--255-- --log-file=valgrind-out.txt
--255-- Contents of /proc/version:
--255-- Linux version 5.10.16.3-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Fri Apr 2 22:23:49 UTC 2021
--255--
--255-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3-avx-avx2-bmi-f16c-rdrand-rdseed
--255-- Page sizes: currently 4096, max supported 4096
--255-- Valgrind library directory: /usr/libexec/valgrind
--255-- Reading syms from /src/tests/output/testMemory
--255-- Reading syms from /lib/ld-musl-x86_64.so.1
--255-- object doesn't have a symbol table
--255-- Reading syms from /usr/libexec/valgrind/memcheck-amd64-linux
--255-- object doesn't have a dynamic symbol table
--255-- Scheduler: using generic scheduler lock implementation.
--255-- Reading suppressions file: /usr/libexec/valgrind/default.supp
==255== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-255-by-???-on-91ae10bb5054
==255== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-255-by-???-on-91ae10bb5054
==255== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-255-by-???-on-91ae10bb5054
==255==
==255== TO CONTROL THIS PROCESS USING vgdb (which you probably
==255== don't want to do, unless you know exactly what you're doing,
==255== or are doing some strange experiment):
==255== /usr/libexec/valgrind/../../bin/vgdb --pid=255 ...command...
==255==
==255== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==255== /path/to/gdb ./output/testMemory
==255== and then give GDB the following command
==255== target remote | /usr/libexec/valgrind/../../bin/vgdb --pid=255
==255== --pid is optional if only one valgrind process is running
==255==
--255-- Reading syms from /usr/libexec/valgrind/vgpreload_core-amd64-linux.so
--255-- object doesn't have a symbol table
--255-- Reading syms from /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so
--255-- object doesn't have a symbol table
--255-- REDIR: 0x405082f (libc.musl-x86_64.so.1:strlen) redirected to 0x48a7b10 (strlen)
--255-- REDIR: 0x40505f1 (libc.musl-x86_64.so.1:strcpy) redirected to 0x48a7b72 (strcpy)
--255-- REDIR: 0x4050534 (libc.musl-x86_64.so.1:strchr) redirected to 0x48a787c (strchr)
--255-- REDIR: 0x4050935 (libc.musl-x86_64.so.1:strncmp) redirected to 0x48a7f6a (strncmp)
--255-- REDIR: 0x4050a80 (libc.musl-x86_64.so.1:strspn) redirected to 0x48ab61a (strspn)
--255-- REDIR: 0x4050601 (libc.musl-x86_64.so.1:strcspn) redirected to 0x48ab5ba (strcspn)
--255-- REDIR: 0x40509bd (libc.musl-x86_64.so.1:strnlen) redirected to 0x48a7aea (strnlen)
--255-- Reading syms from /usr/lib/liblog4cplus-2.0.so.3.4.6
--255-- object doesn't have a symbol table
--255-- REDIR: 0x40509f9 (libc.musl-x86_64.so.1:strrchr) redirected to 0x48a77e9 (strrchr)
--255-- Reading syms from /usr/lib/openssl/lib/libcrypto.so.3
--255-- Reading syms from /usr/local/lib/librestclient-cpp.so.1.1.1
--255-- Reading syms from /usr/lib/libstdc++.so.6.0.29
--255-- object doesn't have a symbol table
--255-- Reading syms from /usr/lib/libgcc_s.so.1
--255-- object doesn't have a symbol table
--255-- Reading syms from /usr/local/lib/libcurl.so.4.8.0
--255-- Reading syms from /usr/lib/openssl/lib/libssl.so.3
--255-- REDIR: 0x4023529 (libc.musl-x86_64.so.1:malloc) redirected to 0x48a2650 (malloc)
--255-- REDIR: 0x4e5c68e (libstdc++.so.6:operator new(unsigned long)) redirected to 0x48a2de0 (operator new(unsigned long))
--255-- REDIR: 0x40505d9 (libc.musl-x86_64.so.1:strcmp) redirected to 0x48a847c (strcmp)
--255-- REDIR: 0x404ff8d (libc.musl-x86_64.so.1:memcmp) redirected to 0x48a9ff3 (memcmp)
--255-- REDIR: 0x4050544 (libc.musl-x86_64.so.1:strchrnul) redirected to 0x48aaf8d (strchrnul)
--255-- REDIR: 0x4e5ae18 (libstdc++.so.6:operator delete(void*, unsigned long)) redirected to 0x48a51f4 (operator delete(void*, unsigned long))
--255-- REDIR: 0x4e5c70e (libstdc++.so.6:operator new[](unsigned long)) redirected to 0x48a3dc4 (operator new[](unsigned long))
--255-- REDIR: 0x404fefe (libc.musl-x86_64.so.1:memchr) redirected to 0x48a8542 (memchr)
--255-- REDIR: 0x4e5ae2a (libstdc++.so.6:operator delete[](void*)) redirected to 0x48a5e80 (operator delete[](void*))
--255-- REDIR: 0x4023460 (libc.musl-x86_64.so.1:free) redirected to 0x48a4a8a (free)
--255-- REDIR: 0x402519f (libc.musl-x86_64.so.1:realloc) redirected to 0x48a6e29 (realloc)
--255-- REDIR: 0x40233a1 (libc.musl-x86_64.so.1:calloc) redirected to 0x48a6b5a (calloc)
--255-- REDIR: 0x4e5ae0f (libstdc++.so.6:operator delete(void*)) redirected to 0x48a4fac (operator delete(void*))
--255-- REDIR: 0x4050d40 (libc.musl-x86_64.so.1:strstr) redirected to 0x48ab4a4 (strstr)
--255-- REDIR: 0x4050972 (libc.musl-x86_64.so.1:strncpy) redirected to 0x48a7cae (strncpy)
--255-- memcheck GC: 1000 nodes, 315 survivors (31.5%)
--255-- memcheck GC: 1014 new table size (driftup)
==255==
==255== HEAP SUMMARY:
==255== in use at exit: 72,704 bytes in 1 blocks
==255== total heap usage: 9,136,810 allocs, 9,136,809 frees, 369,272,065 bytes allocated
==255==
==255== Searching for pointers to 1 not-freed blocks
==255== Checked 134,080 bytes
==255==
==255== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
==255== at 0x48A26D5: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==255== by 0x4E59557: ??? (in /usr/lib/libstdc++.so.6.0.29)
==255== by 0x4059D8A: ??? (in /lib/ld-musl-x86_64.so.1)
==255== by 0x409693F: ???
==255== by 0x4F5B51F: ??? (in /usr/lib/libstdc++.so.6.0.29)
==255== by 0xB907FED: ???
==255== by 0x5C1A2: ???
==255== by 0xCE9F: ???
==255== by 0x1CEAEF: ??? (in /src/tests/output/testMemory)
==255==
==255== LEAK SUMMARY:
==255== definitely lost: 0 bytes in 0 blocks
==255== indirectly lost: 0 bytes in 0 blocks
==255== possibly lost: 0 bytes in 0 blocks
==255== still reachable: 72,704 bytes in 1 blocks
==255== suppressed: 0 bytes in 0 blocks
==255==
==255== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
我可以补充一点,我在基于 alpine 3.16.2(使用 valgrind、g++ 等...)的 docker 容器中运行它
对于了解它的人来说,这是一个使用 cxxtest (v4.4) 运行的程序。但它不应该影响,因为所有源文件都像我一样编译并且在我的程序文件夹中。所以 valgrind 应该找到符号(有部分 lotOfFiles.h 和 lotOfFiles.cpp)
所以我的问题是:我可以添加什么来帮助 valgrind 查找符号? (显然我不想要 libstdc++ 的细节,而只是我代码中的一个线索)
最佳答案
--track-origins=yes
不会因泄漏而改变任何内容。就是为了追溯内存分配,比如未初始化的内存。
--keep-debuginfo=yes
仅当您的应用程序使用 dlopen 和 dlclose 时才需要。它告诉 Valgrind 在任何 dlcloses 后保留调试信息。
Alpine Linux。恐怕 musl libc 对 Valgrind 没有最好的支持。如果您可以使用另一个更主流的发行版,它可能会有所帮助。
最后,我建议您尝试使用一个简单的示例让事情正常运行,然后逐步构建您的完整测试系统。
例如,您能否仅通过以下方式获得“仍然可达”:
#include <stdlib.h>
int main()
{
int* pi = malloc(3456);
}
编辑:this 看起来相关吗?
关于c++ - valgrind 不会显示堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74390792/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!