Valgrind表演???尽管-g标志用于行号

时间:2019-04-20 04:47:31

标签: g++ valgrind

main.cpp

import numpy as np

n_strings = 3
len_strings = 3

ordered_sum_matrix = np.zeros((len_strings,len_strings))

for s in range(0, int(n_strings)):
    binary_string = np.random.binomial(1, 0.5, len_strings)
    for i in range(0, len(binary_string)):
        for j in range(0, len(binary_string)):
            if i == j:
                continue
            ordered_sum_matrix[i,j] = ordered_sum_matrix[i,j] + (binary_string[i] * binary_string[j])

命令行:

#include <iostream>

int main() {
  int* x = new int;
  std::cout << x[3] << std::endl;
  return 0;
}

valgrind输出

$ g++ -g main.cpp -o main
$ valgrind ./main

如果运行==27732== Memcheck, a memory error detector ==27732== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==27732== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==27732== Command: ./main ==27732== ==27732== Invalid read of size 4 ==27732== at 0x1091A3: ??? (in /home/rofl/test_program/main) ==27732== by 0x57FDE76: (below main) (libc-start.c:308) ==27732== Address 0x5bb7c8c is 8 bytes after a block of size 4 alloc'd ==27732== at 0x4C2F4FF: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==27732== by 0x109196: ??? (in /home/rofl/test_program/main) ==27732== by 0x57FDE76: (below main) (libc-start.c:308) ==27732== 0 ==27732== ==27732== HEAP SUMMARY: ==27732== in use at exit: 4 bytes in 1 blocks ==27732== total heap usage: 3 allocs, 2 frees, 73,732 bytes allocated ==27732== ==27732== LEAK SUMMARY: ==27732== definitely lost: 4 bytes in 1 blocks ==27732== indirectly lost: 0 bytes in 0 blocks ==27732== possibly lost: 0 bytes in 0 blocks ==27732== still reachable: 0 bytes in 0 blocks ==27732== suppressed: 0 bytes in 0 blocks ==27732== Rerun with --leak-check=full to see details of leaked memory ==27732== ==27732== For counts of detected and suppressed errors, rerun with: -v ==27732== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) ,我可以中断main函数并一步一步地进行操作,因此我很确定二进制文件中包含调试符号。


使用gdb ./maing++ -fno-omit-frame-pointer

valgrind -v

Valgrind输出:

g++ -g -fno-omit-frame-pointer main.cpp -o main
valgrind -v ./main

1 个答案:

答案 0 :(得分:1)

在阅读调试信息https://bugs.kde.org/show_bug.cgi?id=395682时,这很可能已经解决了Valgrind错误。根据{{​​3}},该修补程序自3.14版本开始可用。