windbg的ah系列命令如何使用?

问题描述 投票:0回答:1

我不知道ah系列命令的Address参数是什么。


这是ah系列命令的msdn。

https://learn.microsoft.com/en-us/windows-hardware/drivers/debuggercmds/ah--assertion-handling-

ahb [地址]

ahi [地址]

ahd [地址]

地址

指定正在设置断言处理状态的指令的地址。如果省略此参数,调试器将使用当前程序计数器。


它表示正在设置断言处理状态的指令。

这是否意味着存在设置断言处理状态的汇编指令?

实际上,程序执行比较指令,并根据比较结果决定是否执行断言函数。

所以我找不到设置断言处理状态的汇编指令。


我写了一个测试程序。

程序在主函数中触发断言。

我使用 ahb 或 ahi 指令设置主函数的每个汇编指令。

但是这些指令并没有改变断言的处理方式,程序总是弹出窗口。

windbg
1个回答
0
投票

据我所知,

ah
命令仅适用于生成
int 0x2c
的断言。

这是一个非常简单的例子:

#include <Windows.h> // needed for DbgRaiseAssertionFailure
#include <assert.h>  // needed for _ASSERT
#include <stdio.h>

int main(int argc, char** argv)
{
    // generates an int3 (software BP)
    // _ASSERT(argc == 2);

    // generates an int 0x2c
    if (argc != 2)
        DbgRaiseAssertionFailure();


    printf("Ok!\n");

    return 0;
}

这是调试模式下的主要功能(注意

00007ff6debe2b1c
处的中断):

0:000> u Test!main L 15
Test!main [G:\Appdata\CPP\Test\Test.cpp @ 333]:
00007ff6`debe2af0 4889542410      mov     qword ptr [rsp+10h],rdx
00007ff6`debe2af5 894c2408        mov     dword ptr [rsp+8],ecx
00007ff6`debe2af9 55              push    rbp
00007ff6`debe2afa 57              push    rdi
00007ff6`debe2afb 4881ece8000000  sub     rsp,0E8h
00007ff6`debe2b02 488d6c2420      lea     rbp,[rsp+20h]
00007ff6`debe2b07 488d0dace50000  lea     rcx,[Test!_NULL_IMPORT_DESCRIPTOR <PERF> (Test+0x210ba) (00007ff6`debf10ba)]
00007ff6`debe2b0e e853e8ffff      call    Test!ILT+865(__CheckForDebuggerJustMyCode) (00007ff6`debe1366)
00007ff6`debe2b13 83bde000000002  cmp     dword ptr [rbp+0E0h],2
00007ff6`debe2b1a 7402            je      Test!main+0x2e (00007ff6`debe2b1e)
00007ff6`debe2b1c cd2c            int     2Ch
00007ff6`debe2b1e ba80030000      mov     edx,380h
00007ff6`debe2b23 488d0de6700000  lea     rcx,[Test!`string' (00007ff6`debe9c10)]
00007ff6`debe2b2a e861e6ffff      call    Test!ILT+395(printf) (00007ff6`debe1190)
00007ff6`debe2b2f 33c0            xor     eax,eax
00007ff6`debe2b31 488da5c8000000  lea     rsp,[rbp+0C8h]
00007ff6`debe2b38 5f              pop     rdi
00007ff6`debe2b39 5d              pop     rbp
00007ff6`debe2b3a c3              ret
00007ff6`debe2b3b cc              int     3
00007ff6`debe2b3c cc              int     3  

如果我正常运行程序,调试器会在此处中断:

Test!main+0x2c:
00007ff6`debe2b1c cd2c            int     2Ch

如果我输入(在运行程序之前):

0:000> ahi 00007ff6`debe2b1c
Test!main+0x2c (00007ff6`debe2b1c) [G:\CPP\Test\Test.cpp @ 336]- ignore

0:000> ah
Test!main+0x2c (00007ff6`debe2b1c) [G:\CPP\Test\Test.cpp @ 336]- ignore

然后断言完全被忽略,程序正常运行,而不会中断调试器。

请注意,

DbgRaiseAssertionFailure
记录在此处,它唯一的工作是发出一个 int 0x2c:

#define DbgRaiseAssertionFailure() __int2c()

此中断的向量如下:

0: kd> !idt 0x2c

Dumping IDT: fffff8074d3c6000

2c:     fffff80750a16dc0 nt!KiRaiseAssertionShadow

我真正不知道的是,对于用户模式,是否还有其他宏与“标准”断言(打印或生成带有文件、行号和消息的消息框)一样有用,但使用整数0x2C。

在内核模式下,标准方法是使用

NT_ASSERT
宏,它也会生成 int 0x2c。请注意,该宏的文档还引用了
ah
命令,这往往证实了
ah
仅适用于 int 0x2c。

© www.soinside.com 2019 - 2024. All rights reserved.