windbg

windbg: Is it possible to embed Windgb engine in my own program?

不打扰是莪最后的温柔 提交于 2019-11-30 15:59:16
I'd like to write a debugging/diagnostic tool which can call Windbg functions to examine a dump file, instead of writing a windbg extension. Is this possible and any references? Thanks a lot. Rather than WinDbg, you can use the Debugging API which is implemented in dbghelp.dll. It's documented on MSDN . That reference documentation is rather dry, but it should give you an idea of the capabilities of the API. For example, MiniDumpReadDumpStream is the gateway to examining dump files. In addition to the existing answers, WinDBG is a GUI front end for the DbgEng API. You can use this API to write

How to get the debuggee's command line in WinDbg?

佐手、 提交于 2019-11-30 15:08:22
Is there any extension command could to do so? I just want to the the whole command line including all parameters. Jason Evans Information like the command line args are stored in the PEB (Process Environment Block). You can find a list of common commands here. !peb will display the PEB. try vercommand it's a lot simpler than !peb this is a good place to get you started: http://windbg.info/doc/1-common-cmds.html#2_general_cmds 来源: https://stackoverflow.com/questions/6224834/how-to-get-the-debuggees-command-line-in-windbg

How to find all instances of types that implement a given interface during debugging

雨燕双飞 提交于 2019-11-30 11:50:42
I am looking for a way to locate all current instances on the heap of types that implement a given interface (during WinDbg debugging that is). As interfaces are not types in the sense that you can create instances of an interface, they obviously do not show up when inspecting the heap. I.e. !dumpheap is of little help here. However, !dumpmt -md on a given MT lists the number of IFaces in IFaceMap . As far as I can tell this number seems to indicate if the type implements one or more interfaces or not. When using the -md flag methods on the type are also listed. Unfortunately the !dumpmd doesn

[调试]_[初级]_[Windbg使用教程-2]

笑着哭i 提交于 2019-11-30 10:20:38
场景 1.我们开发C++程序时, 发布给客户用的是Release模式, 并添加崩溃报告,在程序崩溃退出时,可以通过使用WinDbg来调试崩溃产生的dmp文件. 2.我们也可以用来调试程序, 加断点, 看局部变量,只是这里主要还是讲调试dmp的. 说明 1.Windbg并不是系统标配的, 需要通过SDK下载安装. Debugging Tools for Windows . WinDbg, 一个独立的图形Debug工具, 可以调试用户模式和内核模式. 相当于vs的调试器独立版本,或者说是linux里的gdb. 如果配合Windows SDK的C++编译工具, 甚至不需要VS都可以用SDK自带的编译工具和WinDbg开发程序. 2.获取Windows dll pdb文件可以通过两种方式: – 方式1: 启动windbg后,在[Symbol Search Path] 对话框中加入下面的路径: srv*D:\SystemSymbols*http://msdl.microsoft.com/download/symbols 这种方式就是在调试过程中,windbg调试器会从符号表服务器自动下载调试所需的PDB文件. – 方式2: 预先下载PDB文件,这样能减少调试的等待时间. "C: \Program Files \Debugging Tools for Windows (x86) \symchk

windbg 脚本编写 -- 条件断点

馋奶兔 提交于 2019-11-30 10:20:11
先来解释一下,Windbg的脚本是什么?你可以理解为脚本就是一种语言,就像c或者汇编,但是他不需要编译器将其编译为可执行文件,而是由解释器将其内容翻译为对应的动作。而Windbg的脚本就是利用Windbg作为解释器,将脚本内容翻译为实际的动作。也许这个解释还是有些晦涩,那让我们跳过这些晦涩的概念,来一个简单的例子: .echo "hello world!" 这条命令会显示“ hello world! ”这个字符串,把它保存到c:\1.txt文件,然后在Windbg的命令窗口里输入:$$><c:\1.txt回车,看看屏幕上出现了什么?没错,Windbg将1.txt里的内容当做一条Windbg的命令执行了。这就是一个简单的脚本。 也许有人说,这确实是一个脚本,但是他太弱了,只能打印字符串而已。别急,饭要一口一口吃,脚本要一点一点扩展。先来看看这个$$><,根据前面的例子,很容易看出他的作用是将脚本文件交给Windbg解释,由他完成了将一个txt变成Windbg命令的关键转换。其实你知道了这个,Windbg脚本就算入门了,因为你可以把很多命令写在这个文件里,然后用$$><装载执行。这应该能完成一些功能,不过,这样的用法充其量应该叫做batch,而不是script,因为他只能批量执行命令。那么怎么才能升级到script呢?接下来我们一步一步分解,不过在此之前,还是先把$$><了解透彻。$$

Windbg调试----多线程控制调试

ε祈祈猫儿з 提交于 2019-11-30 10:19:42
在调试程序的时候,可能经常会有这样的需求,让一个线程在特定的时候才让其开始执行或者暂停执行。比如复杂的多线程导致死锁的问题,又或者多线程中的Race Condition 导致程序执行异常等。 很多时候,我们可以借助编写调试代码来达到多线程的调试,可是有些情况下调试的执行粒度是指令级别的,那么这个时候我们得借助调试利器Windbg了。本文我们将以 《C/C++编程教训—-函数内静态类对象初始化非线程安全(C++11之前)》 为调试例子 (没看过的同学,可以先看一下这篇博文)。个人觉得这个例子不错,这个调试的执行力度是指令级别的,因为其存在的线程安全问题的代码是编译器生成的,并不是程序员自己的代码。 测试代码 以下这段代码,创建两个线程,这两个线程等待主线程触发的event,然后打印 TestFunction 返回的对象的成员变量 m_iVal 。**正常情况下,两个线程的打印的 m_iVal 都为4。可是在之前博客有提到过, TestFunction() 是非线程安全的,而我们也无法通过增加调试代码来触发这个非线程安全的问题。那么下一章节,我们将通过Windbg来控制线程的执行来触发这个非线程安全的问题。 TestObject TestFunction() { static TestObject obj; return obj; } HANDLE hEvent = NULL ;

WinDbg命令详解--内存操作

懵懂的女人 提交于 2019-11-30 10:19:31
分配内存指令:.dvalloc .dvalloc指令类似与VirtualAlloc函数。可以指定分配的大小、类型(MEM_RESERVE | MEM_COMMIT)(加上参数 / r,申请的内存类型为MEM_RESERVE。默认为MEM_COMMIT)、起始地址(加上参数 / b) 使用.dvalloc分配的内存都是PAGE_EXECUTE_READWRITE属性 释放内存指令 : .dvfree 有分配就有释放.dvfree指令类似VirtualFree 函数。 内存属性查看指令:!vprot !vprot指令类似与VirtualQuery 函数。可以获取一个内存块的各种属性。 内存地址命令:!address !address命令可以按照性质(image or stack or heap or filemap...)、类型(MEM_IMAGE or MEM_MAPPED or MEM_PRIVATE) 、状态(MEM_COMMIT or MEM_FREE or MEM_RESERVE)、保护属性(PAGE_NOACCESS or PAGE_READONLY ...)等组合查询某一组内存列表。 从文件中读入数据到内存指令 : .readmem Dump内存指令:.writemem 我们经常会存在如下需求:有一个程序是压缩壳,需要把解压后的代码Dump出来;为了分析某些数据

windbg调试-----基本调试方法

雨燕双飞 提交于 2019-11-30 10:19:09
基本语法: User-Mode ! analyze [ - v] [ - f | - hang] [ - D BucketID] ! analyze - c [ - load KnownIssuesFile | - unload | - help ] -v 显示详细信息 -hang -show BugCheckCode 显示bugcheckid的相关信息 Kernel-Mode ! analyze [ - v] [ - f | - hang] [ - D BucketID] ! analyze - c [ - load KnownIssuesFile | - unload | - help ] ! analyze - show BugCheckCode [BugParameters] 用法和显示信息的解释: 第一部分:FAULTING_IP: 显示的是出错时候的指令: 例如: FAULTING_IP: MSVCR80D ! strcat + 93 [F:RTMvctoolscrt_bldSELF_X86crtsrcintelstrcat.asm @ 182 ] 102aecf3 8b01 mov eax,dword ptr [ecx] 第二部分: EXCEPTION_RECORD 显示的是代码崩溃的异常信息,可以用 .exr -1 显示 例如: EXCEPTION_RECORD:

windbg调试-----断点设置

≯℡__Kan透↙ 提交于 2019-11-30 10:18:56
几个基本概念: 1:windbg中的符号和语句命令 ; 命令分隔符 {} 表达式块 $$ 命令中的注释,已 “;”代表注释结束 .catch 当程序错误的时候,防止程序终止 .if .do .while .break .for .else 和C语言中的关键字类似 几个命令: c命令:比较内存 例如: 考虑如下程序 void main() { char rgBuf1[ 100 ]; char rgBuf2[ 100 ]; memset(rgBuf1, 0xCC , sizeof (rgBuf1)); memset(rgBuf2, 0xCC , sizeof (rgBuf2)); rgBuf1[ 42 ] = 0xFF ; } 比较rgBuf1和rgBuf2内存内容可以使用如下命令: 0 : 000 > c rgBuf1 (rgBuf1 + 100 ) rgBuf2 或者 0 : 000 > c rgBuf1 L 100 rgBuf2 线程控制命令: 断点设置命令: 变量显示命令: 调试分析命令: 用户空间: 用户空间即用户模式的应用程序运行的空间,他的虚拟地址由0x00000000 到0x7FFFFFFF 设置断点只是针对某个线程空间,所以如果需要队某个线程使用bp 虚拟内存地址形式的断点的话,需要使用.process [process Number]切换到线程空间 设置断点:

如何写windbg高级脚本---以访问文件的windbg脚本为例说明

无人久伴 提交于 2019-11-30 10:18:39
标 题: 如何写windbg高级脚本---以访问文件的windbg脚本为例说明 作 者: 悠扬笛曲 时 间: 2009-03-17 10:27 链 接: http://bbs.pediy.com/showthread.php?t=83946 最近需要在访问指定文件时中断下来,但不知道如何下断,在网上搜索了一番无果,只好自己摸索了。听大侠说windbg的条件断点功能异常强大,可以实现,不禁心痒,特尝试一番,顺便熟悉一下windbg的脚本语法。 先来了解简单的,得到当前访问的文件名 先写段C代码,创建C:\a.txt并往文件中写任意几个字符,代码如下: HANDLE hFile=CreateFile("C:\\a.txt", GENERIC_WRITE|GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { return ; } char Buffer[]={"abcdefghijklemn"}; DWORD dwReturn; WriteFile(hFile,Buffer,strlen(Buffer),&dwReturn,NULL); CloseHandle(hFile); 把以上代码放到对话框的按钮点击响应事件中去