How to set a watchpoint at a file in GDB to break whenever the file is modified?

Viewed 874

While debugging my program I want to observe changes which the program is making to files and I want debugger to tell me when that happens

I am debugging a program which either creates or modifies certain files (let's say text files). A file can be modified from multiple places in the program and it can be modified a multiple number of times. The sequence of modification is important. I am looking for a way to set a watchpoint on the file just like we set on variables. Basically I want the program to break whenever the file is modified so that I can analyze the file content and observe the program further. Is there a way to achieve this?

2 Answers
Related