求助,Windows服务调试遇到的问题

wxh200707020140 2018-08-22 08:03:24
最近写一个项目,要做成Windows服务,在服务启动后会调用一个第三方的dll文件,在某些特定的情况调用dll某个函数dll会崩溃,会导致服务莫名其妙的停止,通过宏定义开关把它改成Win32控制台程序,调用dll这个函数又可以正常工作,现在不知道是dll的问题还是Windows服务没写好,求给一个确定问题的方法,谢谢啦。
...全文
178 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxh200707020140 2018-08-23
  • 打赏
  • 举报
回复
尝试过用WinDbg调试,但是工作电脑没办法联网,只能下载Symbols文件,但是调试的时候依旧出现部分Symbols文件找不到,电脑系统Win7 旗舰版,ServicePack 1 64位操作系统,用的vs2010,不知道该去哪里下载合适的Symbols文件
赵4老师 2018-08-23
  • 打赏
  • 举报
回复
用调试器(OD,WINDBG等)调试服务程序
To debug the initialization code of a service application, the debugger must be attached when the service is started. This is accomplished by creating a registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\ProgramName


The ProgramName is the image file for the service application you are debugging. Do not specify a path. For example, the ProgramName might look like MyService.exe.

Under this key create a string data value called Debugger. The value of this string should be set to the full path of the debugger that will be used. For example,

c:\Debuggers\windbg.exe



In addition to setting this registry key, the service application must be marked as "interactive". This allows your service to interact with the desktop, and allows the debugger window to appear on your desktop.

This again requires modifying a registry key: you must bitwise-or the type entry for your service with 0x100 (this is the value for SERVICE_INTERACTIVE_PROCESS according to Winnt.h). The exact location and name of this registry entry varies. For example:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyServiceKey


Finally, you need to adjust the service application timeout. Otherwise, the service application will kill the debugger within 20 seconds after starting. Adjusting the timeout involves setting an entry in the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control


Under this key, create a DWORD data value called ServicesPipeTimeout. Set this entry to the amount of time in milliseconds that you want the service to wait before timing out. For example, 60,000 is one minute, while 86,400,000 is 24 hours.

设置ServicesPipeTimeout后需要重启系统才生效

Now, when the service is started, the debugger will also start. When the debugger starts, it will stop at the initial process breakpoint, before the service has begun running. This allows you to set breakpoints or otherwise configure your debugging session to let you monitor the startup of your service. Another option is to place calls to the DebugBreak function in your service from the point at which you would like to break into the debugger. (For more information, see DebugBreak in the Platform SDK documentation.)

If your service is running with other services in a Service Host Process, you may need to isolate the service into its own Service Host Process.
wxh200707020140 2018-08-23
  • 打赏
  • 举报
回复
求各位走过路过的大爷们,帮帮忙
cjzzmdn 2018-08-23
  • 打赏
  • 举报
回复
vs调试菜单有个附加到进程按钮
赵4老师 2018-08-23
  • 打赏
  • 举报
回复
http://blog.csdn.net/zhao4zhong1/article/details/53078924 老司机找bug的十年心路历程
sghcpt 2018-08-23
  • 打赏
  • 举报
回复
楼主,如果你想判断是否服务代码问题还是第三方dll文件,可以不调用第三方的dll接口函数,换成别的其它函数试试就知道是否是第三方dll哪个接口的接口问题吧。。

楼主既然在那边电脑中不能联网,那么可以试试在服务代码中添加崩溃捕捉代码,即崩溃的时候,生成dump文件, 然后再把dump文件拿到你可以联网的电脑中使用windbg调试或者直接使用vs调试了吧。。

dump文件的生成可以在网上搜索“c++ 生成dump”相关字眼或者"生成dump文件"字眼。。记住调试时,需要你之前编译时生成的.pdb文件一起调试的。

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧