I have a large code and it is not obvious when it is creating an output file. Is there a way in gdb to put a breakpoint when a new ofstream
is created? Or when a file is written to?
I've tried things like
(gdb) b ofstream
Function "ofstream" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) b std::ofstream
Function "std::ofstream" not defined.
Make breakpoint pending on future shared library load? (y or [n]) n
I want to do this so that I can get a backtrace to find out which functions are creating this file.
I also tried
(gdb) catch syscall write
This works except it also catches the output to the screen (and the output to stdout
is verbose), when really I want to catch the output to a file.
EDIT: Here is a minimal working example.
#include <iostream>
#include <fstream>
using namespace std;
int main () {
cout << "hello world\n" ;
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}