【发布时间】:2017-03-30 09:36:52
【问题描述】:
(gdb) print* data_out_file[0]
$1 = {_flags = -1, _IO_read_ptr = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_read_end = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_read_base = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_write_base = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_write_ptr = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_write_end = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_buf_base = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_buf_end = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_save_base = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_backup_base = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>,
_IO_save_end = 0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>, _markers = 0xffffffffffffffff, _chain = 0x11004147ffffffff,
_fileno = 498074112, _flags2 = 12648704, _old_offset = 135392766359363840, _cur_column = 240, _vtable_offset = 66 'B', _shortbuf = "á",
_lock = 0xecfc392019202004, _offset = -35, __pad1 = 0xffffffffffffffff, __pad2 = 0xffffffffffffffff, __pad3 = 0xffffffffffffffff,
__pad4 = 0xffffffffffffffff, __pad5 = 18446744073709551615, _mode = -1, _unused2 = 'ÿ' <repeats 20 times>}
在 GDB 中,如果我们打印文件指针,我们会得到描述符。 只是想知道我们如何在像 printf 这样的 C 代码中做到这一点?
【问题讨论】:
-
文件描述符是一个整数。我不知道 that 是什么,因为您没有显示声明、类型或...除了无效指针的集合之外的任何内容,但它不是文件描述符。
-
如果你试图找出一个能打印所有信息的神奇格式说明符,你就走错了路。否则,您可以使用正确的格式打印每个成员。
-
这不是一个文件描述符,而是一个 dereferenced 文件指针。
_fileno = 498074112包含底层文件描述符。 (但整个结构内容对我来说看起来无效) -
您不会打印 FILE* 描述符,它是指向完全依赖于实现的不透明数据的指针。
-
Linux 下,需要打印文件描述符的各个成员。例如你有一个文件指针
FILE *fp来打印_flag使用fp->_flag。