如何在写入以其名称已知的特定文件时停止gdb中的程序 [英] How to stop program in gdb at writing to a particular file known by its name
问题描述
如何在 gdb 中设置断点以在每次写入以文件名已知的特定文件时停止程序?
How can I set a breakpoint in gdb to stop program at every write to a particular file known by its name?
推荐答案
您可以使用 catch syscall write
让 GDB 在每次 write
系统调用时停止.
You can get GDB to stop on every write
system call with catch syscall write
.
由于 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.
在 Linux 上,您可以查看 ls -l/proc/<pid>/fd/*
以将文件描述符与名称相关联.
On Linux, you can look at ls -l /proc/<pid>/fd/*
to associate file descriptors with names.
其他系统可能有 lsof
或其他系统特定的机制来做同样的事情.
Other systems may have lsof
, or other system-specific mechanisms for doing the same.
一旦你有了文件描述符,你就可以使 catch
有条件(因此 GDB 仅在写入该特定文件时停止).具体操作方法因操作系统和处理器而异,您也没有提供.
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.
这篇关于如何在写入以其名称已知的特定文件时停止gdb中的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!