Marvee Amasi
Marvee Amasi
DIIDevHeads IoT Integration Server
Created by Marvee Amasi on 8/29/2024 in #code-review
Segmentation Fault with GCC and Gcov on Instrumented C++ Program
I'm to instrument GCC and Gcov to collect execution sequence information. While my approach works well for c programs on x86 and x86_64, I'm encountering a segmentation fault when attempting to instrument a C++ program on x86_64.
C++
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
vector<int> numbers = {1, 2, 3, 4, 5};

sort(numbers.begin(), numbers.end(), greater<int>());

for (int num : numbers) {
cout << num << " ";
}
cout << endl;

return 0;
}
C++
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
vector<int> numbers = {1, 2, 3, 4, 5};

sort(numbers.begin(), numbers.end(), greater<int>());

for (int num : numbers) {
cout << num << " ";
}
cout << endl;

return 0;
}
When I compile this program with GCC and Gcov on a 64-bit Intel processor x86_64 and attempt to run it, I encounter a segmentation fault. I'm using GCC version 3.4.5 on CentOS 6.4. My instrumentation code is being inserted correctly and there are no other obvious issues in the code. Does anyone have experience with similar issues or suggestions for troubleshooting?
3 replies