How to stop program in gdb at writing to a particular file known by its name

前端 未结 1 496
夕颜
夕颜 2020-12-11 06:42

How can I set a breakpoint in gdb to stop program at every write to a particular file known by its name?

相关标签:
1条回答
  • 2020-12-11 07:01

    You can get GDB to stop on every write system call with catch syscall write.

    Since write operates on file descriptors, and not on named files, you can't make this breakpoint conditional on the name; you'll have to find out the file descriptor that corresponds to your "interesting" file first.

    On Linux, you can look at ls -l /proc/<pid>/fd/* to associate file descriptors with names.

    Other systems may have lsof, or other system-specific mechanisms for doing the same.

    Once you have the file descriptor, you can make the catch conditional (so GDB stops only when that particular file is written). The exact details of how to do that differ between operating systems and processors, and you didn't supply either.

    0 讨论(0)
提交回复
热议问题