利用DebugView调试Windows程序

调试程序时,普遍采用的方式是打印日志文字到文件。
利用DebugView调试Windows程序, 更方便查看动态信息。

DebugView

Introduction

DebugView is an application that lets you monitor debug output on your local system, or any computer on the network that you can reach via TCP/IP. It is capable of displaying both kernel-mode and Win32 debug output, so you don't need a debugger to catch the debug output your applications or device drivers generate, nor do you need to modify your applications or drivers to use non-standard debug output APIs.
下载地址:https://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

基本配置
Capture
Options
清空信息 按钮
设置时间格式 按钮

时间格式主要有以下两种:

  • 时间格式1


    时间格式1
  • 时间格式2


    时间格式2
过滤 按钮

点过滤按钮可设置对指定进程或含指定文字的信息进行高亮显示。

如何在程序中打印信息到DebugView

在程序中用OutputDebugString即可将信息输出到DebugView
举例:

OutputDebugStringA("Hello World!!");
重要前提

在集成开发环境(如VS)直接运行程序,DebugView是捕获不到的,因为OutputDebugString提前被控制台捕获了,显示在控制台上了。
所以应该直接运行Debug或者Release的程序。

Win7下DebugView无法捕获信息

有时发现DebugView在Win7中无法查看OutputDebugString所抛出的消息,这可能是微软为了安全原因考虑,所以把此功能给关闭。
解决方法:

1.打开注册表
run -> regedit
2.打开
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager]
3.建立[Debug Print Filter]这个新键
4.新增加一个“DEFAULT”的DWORD值,将其内容设置0x0f
5.重启OS后生效。

或者将以下文字拷贝到SetDebugPrintFilter.reg, 然后运行,重启OS后生效

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session Manager/Debug Print Filter] 
"DEFAULT"=dword:0000000f
将指定键值加入到注册表
如何过滤指定进程或字符串

to Highlight "Hello" and include all of the other input as well you would:
Set Include to "*".
Then in the Higlight section where you see the color (Red for Filter 1) - Click in the red color drop down area and add the text "Hello"
This will show you all of your output in DebugView and highlight "Hello" in red.

  • 过滤指定进程


    过滤指定进程

    过滤效果
  • 过滤指定文字

过滤包含`TCPListener的消息`
过滤指定文件的结果

DebugView ++

DebugView++ is a free viewer for Windows OutputDebugString() based logging in the style of Sysinternals DebugView.

DebugView ++

下载地址: https://debugviewpp.wordpress.com/

高亮指定进程

选中指定进程,点右键。


选中指定进程进行高亮
高亮结果
查找指定文字并高亮

查找指定文字并高亮

点击NextPrevious可跳转到下一个或上一个符合条件的消息。

手动设置过滤条件
过滤 按钮
快捷键
  • 清空日志
Ctrl + X
  • Clock Time
Ctrl + T
  • Save View
Ctrl + S

References:

https://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
https://social.microsoft.com/Forums/en-US/f9c88f4a-7fc1-44e0-8f4a-e27491516f91/how-to-use-debugview-highlighting-filter?forum=Offtopic
https://debugviewpp.wordpress.com/

你可能感兴趣的:(利用DebugView调试Windows程序)