首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >windows -如何访问“用户模式堆栈跟踪数据库(Ust)”?

windows -如何访问“用户模式堆栈跟踪数据库(Ust)”?
EN

Stack Overflow用户
提问于 2018-04-11 03:18:15
回答 2查看 1K关注 0票数 1

如何访问由"gflags.exe“(如sql )创建的”用户模式堆栈跟踪数据库“?否则,你能告诉我一些关于ust的API文档吗?

我使用"gflags.exe“对+ust标志进行了调整,这样我就可以获得堆栈跟踪,从而创建一个内存块。

但是我想通过调用堆栈(比如umdh或leakdiag)编译统计数据内存分配组,以供学习。我想有一些查询ust DB的接口,但是我找不到..有什么方法可以查询或枚举ust DB吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-04-11 20:00:23

使用UMDH作为API。UMDH使用文本文件存储其数据:

代码语言:javascript
复制
umdh -pn:Program.exe -f:before.txt
// do something
umdh -pn:Program.exe -f:after.txt

您甚至可以重复这些步骤以获得更多的文本文件。然后,您可以解析n个文本文件(这是您的“数据库”)(您必须用一些编程语言(如C#或Python)编写查询)并进行分析。

有一些工具已经像这样工作了。在我以前的公司里,我们使用的是UMDHGrapher (不是公开的),还有UmdhVizUmdh可视化,它们都是这样做的。

票数 2
EN

Stack Overflow用户

发布于 2018-04-12 20:02:15

看看avrfsdk.h,它公开了一些可以使用Stack_trace_database的接口

下面显示了演示如何获得分配堆栈跟踪的示例代码

编译而不进行优化

(cl /Zi /W4 /analyze /Od foo.cpp /link / release)

启用页堆并在已编译的exe上收集堆栈跟踪

/i foo.exe +ust +hpa

运行它以获取allocme()中单个malloc()的堆栈跟踪

代码语言:javascript
复制
#include <windows.h>
#include <stdio.h>
#include <avrfsdk.h>
#include <intrin.h>
#define ALLOCSIZ 0x1337
typedef ULONG(WINAPI * VerifierEnumResource)(HANDLE Process, ULONG  Flags,
    ULONG  ResourceType, AVRF_RESOURCE_ENUMERATE_CALLBACK ResourceCallback,
    PVOID  EnumerationContext
    );
ULONG WINAPI HeapAllocCallback(PAVRF_HEAP_ALLOCATION HeapAllocation, PVOID, PULONG) {
    if (HeapAllocation->UserAllocationSize == ALLOCSIZ) {
        printf("Index=%x\tDepth=%x\n", HeapAllocation->BackTraceInformation->Index,
            HeapAllocation->BackTraceInformation->Depth);
        for (ULONG i = 0; i < HeapAllocation->BackTraceInformation->Depth; i++) {
            printf("%I64x\n", HeapAllocation->BackTraceInformation->ReturnAddresses[i]);
        }
    }return 0;
}
char * allocme() { printf("%p\n", _ReturnAddress()); return (char *)malloc(ALLOCSIZ); }
int main(void) {
    char *foo = allocme();
    if (foo) {
        memcpy(foo, "VerifierEnumerateResource\0", 26);
        HMODULE hMod;
        if ((hMod = LoadLibraryA("verifier.dll")) == NULL) { return 0; }
        VerifierEnumResource VerEnuRes;
        if ((*(FARPROC *)&VerEnuRes = GetProcAddress(hMod, foo)) == NULL) {
            return 0;
        };
        HANDLE hProcess = GetCurrentProcess();
        VerEnuRes(hProcess, 0, AvrfResourceHeapAllocation,
            (AVRF_RESOURCE_ENUMERATE_CALLBACK)HeapAllocCallback, NULL);
    }return getchar();
}

执行结果

代码语言:javascript
复制
:>ls
dbstk.cpp

:>cl /nologo /Zi /W4 /analyze /Od dbstk.cpp /link /nologo /release
dbstk.cpp

:>gflags /i dbstk.exe +ust +hpa
Current Registry Settings for dbstk.exe executable are: 02001000
    ust - Create user mode stack trace database
    hpa - Enable page heap
:>dbstk.exe
008710CB <<<<<<<<<<<<<<<<<<<<<<<<<< 
Index=0 Depth=b
10c38e89
77105ede
770ca40a
77095ae0
890e7d
8710ae
8710cb <<<<<<<<<<<<<<<<<<<<<<<<<<<
871390
76c4ed6c
770a37eb
770a37be
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49765945

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档