博客
关于我
libevent学习之六:VS2013调试libevent源码
阅读量:587 次
发布时间:2019-03-09

本文共 4091 字,大约阅读时间需要 13 分钟。

今天就介绍一下vs2013 下面调试libevent源码。不需要创建sln解决方案,只需要创建工程,包含

源码目录即可源码调试。 

1、手工添加test/print-winsocke-errors.c文件,不然nmake编译的时候会报错。

print-winsock-errors.c源代码程序:

#include 
#include
#include
#include
#include "event2/event.h"#include "event2/util.h"#include "event2/thread.h"#define E(x) printf (#x " -> \"%s\"\n", evutil_socket_error_to_string (x));int main (int argc, char **argv){ int i, j; const char *s1, *s2;#ifdef EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED evthread_use_windows_threads ();#endif s1 = evutil_socket_error_to_string (WSAEINTR); for (i = 0; i < 3; i++) { printf ("\niteration %d:\n\n", i); E(WSAEINTR); E(WSAEACCES); E(WSAEFAULT); E(WSAEINVAL); E(WSAEMFILE); E(WSAEWOULDBLOCK); E(WSAEINPROGRESS); E(WSAEALREADY); E(WSAENOTSOCK); E(WSAEDESTADDRREQ); E(WSAEMSGSIZE); E(WSAEPROTOTYPE); E(WSAENOPROTOOPT); E(WSAEPROTONOSUPPORT); E(WSAESOCKTNOSUPPORT); E(WSAEOPNOTSUPP); E(WSAEPFNOSUPPORT); E(WSAEAFNOSUPPORT); E(WSAEADDRINUSE); E(WSAEADDRNOTAVAIL); E(WSAENETDOWN); E(WSAENETUNREACH); E(WSAENETRESET); E(WSAECONNABORTED); E(WSAECONNRESET); E(WSAENOBUFS); E(WSAEISCONN); E(WSAENOTCONN); E(WSAESHUTDOWN); E(WSAETIMEDOUT); E(WSAECONNREFUSED); E(WSAEHOSTDOWN); E(WSAEHOSTUNREACH); E(WSAEPROCLIM); E(WSASYSNOTREADY); E(WSAVERNOTSUPPORTED); E(WSANOTINITIALISED); E(WSAEDISCON); E(WSATYPE_NOT_FOUND); E(WSAHOST_NOT_FOUND); E(WSATRY_AGAIN); E(WSANO_RECOVERY); E(WSANO_DATA); E(0xdeadbeef); /* test the case where no message is available */ /* fill up the hash table a bit to make sure it grows properly */ for (j = 0; j < 50; j++) { int err; evutil_secure_rng_get_bytes(&err, sizeof(err)); evutil_socket_error_to_string(err); } } s2 = evutil_socket_error_to_string (WSAEINTR); if (s1 != s2) printf ("caching failed!\n"); libevent_global_shutdown (); return EXIT_SUCCESS;}

2、修改Makefile.nmake 

将 

CFLAGS=$(CFLAGS) /Ox /W3 /wd4996 /nologo

改为 

CFLAGS=$(CFLAGS) /Od /W3 /wd4996 /nologo /Zi

使用/Od禁止优化,使用/Zi 生成调试信息。

3、vs2013命令行编译:nmake /f Makefile.nmake

编译生成:

4、新建工程,附加源码调试

解决方案包含源代码目录:

 

  以上三个目录添加到VC的附加库目录。

    lib包含目录添加刚才生成的

  所在目录

5、源码跟踪调试

F11跳入源码调试:

附上测试代码:
// libevent-test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#pragma comment(lib,"ws2_32.lib")#pragma comment(lib,"wsock32.lib")#pragma comment(lib,"libevent.lib")#pragma comment(lib,"libevent_core.lib")#pragma comment(lib,"libevent_extras.lib")#include 
#include
#include
#ifndef _WIN32#include
#include
#endif#include
#ifdef EVENT__HAVE_SYS_TIME_H#include
#endif#include
#include
#include
#include
#include
#include
#include
#include
#ifdef _WIN32#include
#endifstruct timeval lasttime;int event_is_persistent;static voidtimeout_cb(evutil_socket_t fd, short event, void *arg){ struct timeval newtime, difference; struct event *timeout = (struct event *)arg; double elapsed; evutil_gettimeofday(&newtime, NULL); evutil_timersub(&newtime, &lasttime, &difference); elapsed = difference.tv_sec + (difference.tv_usec / 1.0e6); printf("timeout_cb called at %d: %.3f seconds elapsed.\n", (int)newtime.tv_sec, elapsed); lasttime = newtime; if (!event_is_persistent) { struct timeval tv; evutil_timerclear(&tv); tv.tv_sec = 2; event_add(timeout, &tv); }}intmain(int argc, char **argv){ struct event timeout; struct timeval tv; struct event_base *base; int flags;#ifdef _WIN32 WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 2); (void)WSAStartup(wVersionRequested, &wsaData);#endif if (argc == 2 && !strcmp(argv[1], "-p")) { event_is_persistent = 1; flags = EV_PERSIST; } else { event_is_persistent = 0; flags = 0; } /* Initalize the event library */ base = event_base_new(); /* Initalize one event */ event_assign(&timeout, base, -1, flags, timeout_cb, (void*)&timeout); evutil_timerclear(&tv); tv.tv_sec = 2; event_add(&timeout, &tv); evutil_gettimeofday(&lasttime, NULL); event_base_dispatch(base); return (0);}

原文链接:

转载地址:http://jtfsz.baihongyu.com/

你可能感兴趣的文章
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>