博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
16.windbg-.frame、dt(切换局部上下文、查找结构体)
阅读量:2394 次
发布时间:2019-05-10

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

原文地址:

这里使用一个debug程序:

.frame

.frame命令指定使用哪个局部上下文(作用域)来解析局部变量,或者显示当前的局部上下文

帧序号(frame number)是堆栈帧在堆栈回溯中的位置。可以使用命令或者查看堆栈回溯。第一行 (当前帧) 的帧序号是0。后面的行分别是1、2、3等等。

[cpp]
  1. 0:000> kn  
  2.  # ChildEBP RetAddr    
  3. 00 0012f78c 7c92daea ntdll!KiFastSystemCallRet  
  4. 01 0012f790 7c932298 ntdll!ZwRequestWaitReplyPort+0xc  
  5. 02 0012f7b0 7c872a51 ntdll!CsrClientCallServer+0x8c  
  6. 03 0012f8ac 7c872b98 kernel32!ReadConsoleInternal+0x1be  
  7. 04 0012f934 7c8018b7 kernel32!ReadConsoleA+0x3b  
  8. 05 0012f98c 102c207c kernel32!ReadFile+0x64  
  9. 06 0012fa20 102c19c9 MSVCR90D!_read_nolock+0x62c [f:\dd\vctools\crt_bld\self_x86\crt\src\read.c @ 233]  
  10. 07 0012fa70 10253e43 MSVCR90D!_read+0x219 [f:\dd\vctools\crt_bld\self_x86\crt\src\read.c @ 93]  
  11. 08 0012fa98 102523e8 MSVCR90D!_filbuf+0x113 [f:\dd\vctools\crt_bld\self_x86\crt\src\_filbuf.c @ 136]  
  12. 09 0012faf0 10252440 MSVCR90D!getc+0x208 [f:\dd\vctools\crt_bld\self_x86\crt\src\fgetc.c @ 76]  
  13. 0a 0012fafc 1025245a MSVCR90D!_fgetchar+0x10 [f:\dd\vctools\crt_bld\self_x86\crt\src\fgetchar.c @ 37]  
  14. 0b 0012fb04 0041160b MSVCR90D!getchar+0xa [f:\dd\vctools\crt_bld\self_x86\crt\src\fgetchar.c @ 47]  
  15. 0c 0012fbe4 004114b2 test2!MyCls::hold+0x2b [d:\project1\test2\test2\test2.cpp @ 28]  
  16. 0d 0012fcec 0041167a test2!foo1+0xa2 [d:\project1\test2\test2\test2.cpp @ 39]  
  17. 0e 0012fdc0 004116ea test2!foo2+0x3a [d:\project1\test2\test2\test2.cpp @ 45]  
  18. 0f 0012fe94 00411743 test2!foo3+0x3a [d:\project1\test2\test2\test2.cpp @ 51]  
  19. 10 0012ff68 00411ce8 test2!main+0x23 [d:\project1\test2\test2\test2.cpp @ 56]  
  20. 11 0012ffb8 00411b2f test2!__tmainCRTStartup+0x1a8 [f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 586]  
  21. 12 0012ffc0 7c817077 test2!mainCRTStartup+0xf [f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c @ 403]  
  22. 13 0012fff0 00000000 kernel32!BaseProcessStart+0x23  
  23. 0:000> .frame d  
  24. 0d 0012fcec 0041167a test2!foo1+0xa2 [d:\project1\test2\test2\test2.cpp @ 39]  
  25. 0:000> x  
  26. 0012fce4 pcls = 0x00392a28  
  27. 0012fcd8 rawptr = 0x00392a28  

.frame 帧号,之后跟x,可以显示当前这个函数里面的局部变量

对应d帧的代码:

[cpp]
  1. void foo1()  
  2. {  
  3.     MyCls *pcls=new MyCls();  
  4.     void *rawptr=pcls;  
  5.     pcls->set("abcd");  
  6.     pcls->output();  
  7.     pcls->hold();  
  8. };  

x显示的是pcls和rawptr

dt

dt命令显示局部变量、全局变量或数据类型的信息。它也可以仅显示数据类型。即结构和联合(union)的信息

dt最方便处是查找结构体,查找结构体一定要使用dt,不要使用x

[cpp]
  1. 0:000:x86> dt *!*IMAGE_DOS*  
  2.           test1!IMAGE_DOS_HEADER  
  3.           test1!PIMAGE_DOS_HEADER  
  4.           test1!_IMAGE_DOS_HEADER  
  5.           ntdll!_IMAGE_DOS_HEADER  
  6.           ntdll32!_IMAGE_DOS_HEADER  
  7.           MSVCR90D!IMAGE_DOS_HEADER  
  8.           MSVCR90D!PIMAGE_DOS_HEADER  
  9.           MSVCR90D!_IMAGE_DOS_HEADER  

dt -b this可以打印this指针,只在类中起作用

[cpp]
  1. 0:000:x86> dt -b this  
  2. Local var @ 0x1cfd00 Type CLook*  
  3. 0x00683488   
  4.    +0x000 m_i              : 0n1524615000  
  5.    +0x004 m_j              : 37 'Unknown format character  

如果只想显示某个字段,可以用-ny 加上搜索选项,如:

[html]
  1. 0:000> dt -v ntdll!_PEB -ny BeingDebugged @$peb  
  2. struct _PEB, 91 elements, 0x248 bytes  
  3.    +0x002 BeingDebugged : 0x1 ''  

-v是详细输出。这会输出结构的总大小和字段数量这样的附加信息

也可以直接这样看大小:

[cpp]
  1. 0:000:x86> ?? sizeof(IMAGE_DOS_HEADER)  
  2. unsigned int 0x40  

也可以用-y 来连接通配符,如:

[html]
  1. 0:000> dt -v ntdll!_PEB -y B* @$peb  
  2. struct _PEB, 91 elements, 0x248 bytes  
  3.    +0x002 BeingDebugged : 0x1 ''  
  4.    +0x003 BitField : 0x8 ''  
[cpp]
  1. 0:000> dt pcls  
  2. Local var @ 0x12fce4 Type MyCls*  
  3. 0x00392a28   
  4.    +0x000 str              : 0x00415800  "abcd"  
  5.    +0x004 inobj            : innner  
  6. 0:000> dt rawptr  
  7. Local var @ 0x12fcd8 Type void*  
  8. 0x00392a28   
  9.   
  10. 0:000> dt -b-r pcls  
  11. Local var @ 0x12fce4 Type MyCls*  
  12. 0x00392a28   
  13.    +0x000 str              : 0x00415800  "abcd"  
  14.    +0x004 inobj            : innner  
  15.       +0x000 arr              :  "abcd"  
  16.        [00] 97 'a'  
  17.        [01] 98 'b'  
  18.        [02] 99 'c'  
  19.        [03] 100 'd'  
  20.        [04] 0 ''  
  21.        [05] 0 ''  
  22.        [06] 0 ''  
  23.        [07] 0 ''  
  24.        [08] 0 ''  
  25.        [09] 0 '' 

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

你可能感兴趣的文章
Eclipse LUNA配置TomCat(非j2ee版本)
查看>>
树莓派安装mysql-srver报错 404 not found!
查看>>
Ubuntu 14.04LTS 下安装.net框架
查看>>
Eclipse 配置Groovy语言环境 && Java工程运行Groovy
查看>>
(九)以交易为生:风险管理
查看>>
c# 中的继承操作
查看>>
LeetCode 1470. 重新排列数组
查看>>
1486. 数组异或操作
查看>>
1450. 在既定时间做作业的学生人数
查看>>
股票指标库 TA-Lib 安装方法
查看>>
python调试神器:icecream
查看>>
TensorFlow学习系列(一):初识TensorFlow
查看>>
TensorFlow学习系列(二):形状和动态维度
查看>>
TensorFlow学习系列(三):保存/恢复和混合多个模型
查看>>
TensorFlow学习系列(四):利用神经网络实现泛逼近器(universal approximator)
查看>>
TensorFlow学习系列(五):如何使用队列和多线程优化输入管道
查看>>
TensorFlow学习系列(六):变量更新和控制依赖
查看>>
TensorFlow 变量管理
查看>>
并查集分析
查看>>
最新的二十个有趣的深度学习数据集
查看>>