网站怎么做短信接口,长沙景点预约攻略,做AMC12的题的网站,wordpress opml问题记录#xff1a; 在刚完成mymuduo库之后#xff0c;写了一个简单的测试服务器#xff0c; 但是在服务器运行后直接报错#xff1a; cherryhcss-ecs-4995:~/mymuduo/example$ ./testserver
Segmentation fault (core dumped)出现多错误这通常意味着程序试图访问其内存空… 问题记录 在刚完成mymuduo库之后写了一个简单的测试服务器 但是在服务器运行后直接报错 cherryhcss-ecs-4995:~/mymuduo/example$ ./testserver
Segmentation fault (core dumped)出现多错误这通常意味着程序试图访问其内存空间中未分配或不允许的部分。
所以我决定先使用gdb进行一下简单的调试
gdb ./testserver把程序跑起来之后马上定位到了报错位置
Program received signal SIGSEGV, Segmentation fault.
EventLoop::updateChannel (this0x7fffffffdd60, channel0x555555572eb0) at /home/cherry/mymuduo/EventLoop.cc:126
126 poller_-updateChannel(channel);我再查看代码
125 void EventLoop::updateChannel(Channel *channel) {
126 poller_-updateChannel(channel);
127 }既然是段错误说明我们访问了不被允许访问的内存或者操作了不被允许操作的内存。 接下来我们有以下三个主要的思路
(gdb) print poller_ #poller是否是空
(gdb) print channel #channel是否为空
(gdb) print *channel #如果channel不是空那么它是否指向了有效对象该对象状态是否正常
(gdb) backtrace #如果都正常查看调用栈是哪里调用了 EventLoop::updateChannel 方法但是比较悲剧的是我直接 print poller_ 就发现我们重要的poller对象竟然是空
所以我马上去看了一下构造函数代码是否正常
EventLoop::EventLoop(): looping_(false), quit_(false), callingPendingFunctors_(false), threadId_(CurrentThread::tid()), poller_(Poller::newDefaultPoller(this)), wakeupFd_(createEventfd()), wakeupChannel_(new Channel(this, wakeupFd_)) 在构造函数中 poller_的初始化是通过newDefaultPoller来完成的那么去看看它是否正常工作
Poller* Poller::newDefaultPoller(EventLoop *loop) {if (::getenv(MUDUO_USE_POLL)) {return nullptr; // 生成poll的实例} else {return nullptr; // 生成epoll的实例}
}好巧不巧我们竟然在生成epoll实例的地方返回了一个空之前在写这个代码的时候还没有完成EpollPoller.h文件的书写为了防止部分编译报错所以先写成空了。
更改代码如下
#include EpollPoller.h
return new EPollPoller(loop);