gcc 7.1.0下gdb无法prinf查看errno解决

gcc 7.1.0下gdb无法prinf查看errno解决

centos7.4 下, gcc 7.1.0, gdb8.1下编译postgresql-10.10源码
编译参数:
./configure --enable-debug --prefix=/home/postgres/pginstall CFLAGS="-DGCC_HASCLASSVISIBILITY -O0 -Wall -W -g3 -gdwarf-2"

// miscinit.c -> CreateDataDirLockFile()
fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
		if (fd >= 0)
			break;				/* Success; exit the retry loop */

		/*
		 * Couldn't create the pid file. Probably it already exists.
		 */
		if ((errno != EEXIST && errno != EACCES) || ntries > 100)
			ereport(FATAL,
					(errcode_for_file_access(),
					 errmsg("could not create lock file \"%s\": %m",
							filename)));

gdb调试上面代码时, 想打印errno的值, 结果报错如下:

(gdb) p errno
'__errno_location' has unknown return type; cast the call to its declared return type

解决如下:

(gdb) p *((int*(*)())__errno_location)()
$13 = 17

在网上查了一下, 理论上"p errno" 就可以查看errno的值, 在gcc7.1.0 和 gdb8.1下,
可能存在Bug或者时某些功能缺失造成的.
解决方法就是:
p *((int*(*)())__errno_location)()

prinf *((int*(*)())__errno_location)()

参考

在这里插入图片描述
https://stackoverflow.com/questions/11495720/why-cant-errnos-value-be-printed

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值