Re: CpuWhere 蓝屏问题

WinDbg

CpuWhere 蓝屏问题


Blade 2013-08-30, 14:25 下午

我在看软件调试的时候 看到CpuWhere程序这一部分, 然后我的电脑上(XP3) Fetch Records 的时候就会蓝屏, 后来我安装了WDK ,  安装网上的教程, 用VS2005 重新编译了一下 bts工程, 生成了一个CpuWhere.sys, 把这个文件放到C:/windows/system32/drivers/ 下(不放到这里, 就不能Load, 为啥?), 但是还是蓝屏, 我看了一下代码中 一些寄存器位, 和我的CPU正好一致, 应该不需要修改。 我想调试一下驱动程序, 然后网上说要用虚拟机, 然后我就重启切到 我平时用的WIN7系统, 里面装了一下虚拟机, 确定可以进入调试模式, 不过还没有去装VS之类的, 不过我想看下虚拟机能不能读写寄存器, 然后就把我以前学习LBR.dll 扩展的时候, 改写的可以正常在我的环境下运行的LBR.DLL 拷过来用, 然后运行的时候,发现读到的全是 0, 应该是不能使用, 所以我想问下, 虚拟机中运行的系统是不是不能读写寄存器, 还是说因为虚拟机的宿主系统WIN7系统导致的? 因为安装VS, 和 安装虚拟XP系统等等, 都要花时间, 而且我的XP系统速度比较慢, 在运行虚拟机可能更慢, 所以想偷个懒, 事先请教一下张老师和各位牛人。 我把我的问题整理一下。

1 驱动程序一定要放到C:/windows/system32/drivers/ 吗?

2 调试驱动程序用虚拟机比较好吗?(源码级调试, 类似于用VS断点调试应用程序)

3 虚拟机中运行的系统能读写MSR吗? 是和宿主系统有关吗?

 

Re: CpuWhere 蓝屏问题


格蠹老雷 2013-08-30, 21:20 下午

最近正在为《软件调试》第二版更新这个程序。第一版是有两个今日看来比较明显的限制的,一个是不支持64位,第二个是不支持多CPU。

对于第二个问题,有个workaround是,启动CpuWhere程序后,在任务管理器中Set Affinity,让其只在一个CPU上运行。

因为这个程序需要CPU的硬件支持,虚拟机里的CPU一般没有这个功能...

Re: CpuWhere 蓝屏问题


Blade 2013-09-08, 00:10 上午

有段时间没心思看书, 所以也一直没回复,不好意思了, 今天我看了一下, 按照老师的设置单核CPU下运行这个程序, 确实没有不会蓝屏了, 但是还是抓不到记录, 我折腾了好一会,好像没法调试, 因为虚拟机没法调, 我也没有双机。。。, 那个DbgPrint也不能打印到windbg里面的样子(我是attach cpuwhere.exe), 求支招

下面是我的cpuwhere打印的信息

   
Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.


Connected to Windows XP 2600 x86 compatible target at (Sat Sep  7 23:30:52.296 2013 (GMT+8)), ptr64 FALSE

Symbol search path is:
*** Invalid ***

****************************************************************************
* Symbol loading may be unreliable without a symbol search path.           *
* Use .symfix to have the debugger choose a symbol path.                   *
* After setting your symbol path, use .reload to refresh symbol locations. *
****************************************************************************

Executable search path is:

*********************************************************************

* Symbols can not be loaded because symbol path is not initialized. *

*                                                                   *

* The Symbol Path can be set by:                                    *

*   using the _NT_SYMBOL_PATH environment variable.                 *

*   using the -y <symbol_path> argument when starting the debugger. *

*   using .sympath and .sympath+                                    *

*********************************************************************

*** ERROR: Symbol file could not be found.  Defaulted to export symbols for
ntkrpamp.exe
 -

*******************************************************************************

WARNING: Local kernel debugging requires booting with kernel
debugging support (/debug or bcdedit -debug on) to work optimally.

*******************************************************************************

Windows XP Kernel
Version 2600
 (Service Pack 3)
 MP
(4 procs)
Free x86 compatible

Product:
WinNt
, suite:
 TerminalServer
 SingleUserTS


Built by: 2600.xpsp_sp3_qfe.130704-0421

Machine Name:


Kernel base = 0x80800000 PsLoadedModuleList = 0x80886720

Debug session time: Sat Sep  7 23:30:52.328 2013 (GMT+8)

System Uptime: 0 days 0:35:15.872


Got 0 bytes (0 records) from driver

Re: CpuWhere 蓝屏问题


Blade 2013-09-08, 00:12 上午
哦, 我看到了, 之前用dbgview也看不到, 现在看到了, 因为要用debugview的内核模式, 我之前不知道, 刚才查资料的时候注意到了

Re: CpuWhere 蓝屏问题


格蠹老雷 2013-09-08, 10:32 上午
不错,将DbgView中cpuwhere驱动打印的信息贴出来,看看

Re: CpuWhere 蓝屏问题


Blade 2013-09-08, 11:40 上午
[CpuWhere_1010]
CpuWhere.SYS: entering DriverEntry
 
[CpuWhere_1010]
CpuWhere: IRP_MJ_CREATE
 
[CpuWhere_1010]
 User mode buddy is active: 1
 
[CpuWhere_1010]
CPUWHERE_START
 
[CpuWhere_1010]
CPU Signature is 206a7,family 6.
 
[CpuWhere_1010]
g_bIsPentium4=0
 
[CpuWhere_1010]
DS is setup at 8728fe30: base 871e2000, index 871e2000, max 871f0a60, int 871f0a6c
 
[CpuWhere_1010]
Old IA32_DEBUGCTL=00000000:00000000
 
[CpuWhere_1010]
Current IA32_DEBUGCTL=00000000:000000c0
 
[CpuWhere_1010]
StartTracing exits with 0
 
[CpuWhere_1010]
Old IA32_DEBUGCTL=00000000:000000c0
 
[CpuWhere_1010]
Current IA32_DEBUGCTL=00000000:00000000
 
[CpuWhere_1010]
Starting to read from 871e1ff4 while index is 871e2000
 
[CpuWhere_1010]
ulRecordMax =5000, pBtsRecord=871e1ff4, g_pDebug->dwBtsBase=871e2000
 
[CpuWhere_1010]
0 records read from 871e2000 to 871e1ff4, bReadAll=0
 
[CpuWhere_1010]
0 BTS records returned, bReadAll=1, index reset to 871e2000.
 
[CpuWhere_1010]
Old IA32_DEBUGCTL=00000000:00000000
 
[CpuWhere_1010]
Current IA32_DEBUGCTL=00000000:000000c0
 
红色的地方是我添加的日志, 读取Record的while循环根本没进去, index 和 base 是相等的,都是871e2000,缓冲器一条记录都没有的意思? pBtsRecord  >= g_pDebug->dwBtsBased的条件不成立,所以没读取记录。

Re: CpuWhere 蓝屏问题


Blade 2013-09-08, 12:04 下午

我的操作过程是先Load 然后  Start Recording 之后FetchRecords, 因为担心我操作的方式不对....所以先说明一下。

另外我比较困惑的是g_pDebugStore 通过ExAllocatePoolWithTag 分配后, 进行了一些初始化, 之后在GetBtsRecords之前就再也没有任何对 g_pDebugStore这一块内存进行写操作的过程,计算机为什么知道需要将g_pDebugStore中的信息进行更新呢? 从日志上来看, 从SetUpDSArea 初始化之后到 GetBtsReords时, g_pDebugStore的 Index都没有变化, 和 Base是相同的。

Re: CpuWhere 蓝屏问题


格蠹老雷 2013-09-08, 12:22 下午

日志信息看起来很正常,设置到MSR寄存器后,CPU会自动更新Index字段。你用的是什么CPU?

Re: CpuWhere 蓝屏问题


Blade 2013-09-08, 12:43 下午

我的CPU是 i5-2450M.  

有哪个地方将g_pDebugStore设置到MSR寄存器中吗? 我没注意到有这句代码。

Re: CpuWhere 蓝屏问题


Blade 2013-09-08, 15:28 下午

哦, 注意到了, 之前没看到....

 

   dwEDX=0;
   dwEAX=bEnable?(DWORD)g_pDebugStore:0;

   WriteMSR(IA32_DS_AREA, dwEDX,dwEAX);

Powered by Community Server Powered by CnForums.Net