errno 5追踪.
----------------------------------------
author:hjjdebug
date: 2023年 06月 29日 星期四 14:32:02 CST
----------------------------------------
调试一个ffmpeg 程序,当调用av_read_frame()函数时,返回了-5, 这是什么意思?
-5, 这种小号的错误值是ffmpeg 把系统错误号取反形成的,
#define AVERROR(e) (-(e)) ///< Returns a negative error code from a POSIX error code, to return from library functions.
马上查找一下系统错误号为5是什么意思?
书写如下代码: 可起名为simple.c
#include <errno.h>
int main(void)
{ return 0;}
使用我喜欢的vim编辑器,打开errno.h文件 /usr/include/errno.h
里面浏览了一下,没有直接的内容,有3个包含文件,浏览一下,其中有用的是 <bits/errno.h> ->/usr/include/bits/errno.h
打开<bits/errno.h>,我们看到了错误号125 - 133的定义, 还有一个包含文件<linux/errno.h> -> /usr/include/linux/errno.h
打开<linux/errno.h>文件,只包含一行代码: #include <asm/errno.h> -> /usr/include/asm/errno.h
再打开<asm/errno.h>文件,只包含一行代码 #include <asm-generic/errno.h> -> /usr/include/asm-generic/errno.h
再打开<asm-generic/errno.h>文件,看到了35到133的错误号定义,它包含了一个文件 #include <asm-generic/errno-base.h> -> /usr/include/asm-generic/errno-base.h
再打开<asm-generic/errno-base.h>文件,看到了1到34的错误号定义,
错误号为5, 表示是一种IO 错误.
#define EIO 5 /* I/O error */
是的,在播放码流时,我中断了发送的码流,引起了av_read_frame读不到数据产生 EIO 错误, 追踪结束.完美解决问题.
有没有更快,更有效的手段呢? 有, 把哪个简单的代码预处理一下,直接看输出,搜索结果,就不用一个一个打开文件了.
gcc -E -dD simple.c
它会对simple.c预处理并包含宏定义.将输出重定向到文件可以慢慢观察.
顺便copy 一下基础错误号定义吧, 是ubuntu20 系统
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */