كيفية الحصول على تتبع المكدس من ملف تفريغ برمجيا على ويندوز

StackOverflow https://stackoverflow.com/questions/838947

  •  22-07-2019
  •  | 
  •  

سؤال

وأريد أن استرداد تتبع المكدس من ملف تفريغ مستخدم برمجيا. يوجد هذا تفريغ مستخدم في موقع معروف وأريد أن استخراج فقط تتبع المكدس خروج منه، ووضع ذلك في ملف نص عادي - هل هناك طريقة للقيام بذلك؟

ملحوظة: لا أستطيع القيام بذلك يدويا - افتح WinDbg و نوع "ك" القيادة - ولكن وكما ذكرت سابقا أنا أريد أن أفعل هذا برمجيا.

والشكر

هل كانت مفيدة؟

المحلول

ويجب عليك التحقق من windbg SDK فرعي مع أمثلة على كيفية dbgeng.dll يمكن استخدامها برمجيا.
نموذج التعليمات البرمجية:

 PSTR g_DumpFile;
 PSTR g_ImagePath;
 PSTR g_SymbolPath;

 ULONG64 g_TraceFrom[3];

 IDebugClient* g_Client;
 IDebugControl* g_Control;
 IDebugSymbols* g_Symbols;

  void CreateInterfaces(void)
  {
    HRESULT Status;

    // Start things off by getting an initial interface from
    // the engine.  This can be any engine interface but is
    // generally IDebugClient as the client interface is
    // where sessions are started.
    if ((Status = DebugCreate(__uuidof(IDebugClient),
                              (void**)&g_Client)) != S_OK)
    {
        Exit(1, "DebugCreate failed, 0x%X\n", Status);
    }

    // Query for some other interfaces that we'll need.
    if ((Status = g_Client->QueryInterface(__uuidof(IDebugControl),
                                           (void**)&g_Control)) != S_OK ||
        (Status = g_Client->QueryInterface(__uuidof(IDebugSymbols),
                                           (void**)&g_Symbols)) != S_OK)
    {
        Exit(1, "QueryInterface failed, 0x%X\n", Status);
    }
 }

 void
 DumpStack(void)
 {
    HRESULT Status;
    PDEBUG_STACK_FRAME Frames = NULL;
    int Count = 50;

    printf("\nFirst %d frames of the call stack:\n", Count);

    if (g_TraceFrom[0] || g_TraceFrom[1] || g_TraceFrom[2])
    {
        ULONG Filled;

        Frames = new DEBUG_STACK_FRAME[Count];
        if (Frames == NULL)
        {
            Exit(1, "Unable to allocate stack frames\n");
        }

        if ((Status = g_Control->
             GetStackTrace(g_TraceFrom[0], g_TraceFrom[1], g_TraceFrom[2],
                           Frames, Count, &Filled)) != S_OK)
        {
            Exit(1, "GetStackTrace failed, 0x%X\n", Status);
        }

        Count = Filled;
    }

    // Print the call stack.
    if ((Status = g_Control->
         OutputStackTrace(DEBUG_OUTCTL_ALL_CLIENTS, Frames,
                          Count, DEBUG_STACK_SOURCE_LINE |
                          DEBUG_STACK_FRAME_ADDRESSES |
                          DEBUG_STACK_COLUMN_NAMES |
                          DEBUG_STACK_FRAME_NUMBERS)) != S_OK)
    {
        Exit(1, "OutputStackTrace failed, 0x%X\n", Status);
    }

    delete[] Frames;
 }


 void __cdecl main(int Argc, __in_ecount(Argc) char** Argv)
 {
    CreateInterfaces();

    ParseCommandLine(Argc, Argv);

    ApplyCommandLineArguments();

    DumpStack();

    Exit(0, NULL);
 }

نصائح أخرى

ولقد كتبت مقالة عن تفريغ المكدس في C / C ++ مع ويندوز ويونيكس / لينكس في DDJ قبل بضع سنوات. فإنه لا يستخدم cordump، لكنه يكتب إطارات كومة إلى ملف السجل، على الأخطاء الداخلية، أو عندما يحدد نظام التشغيل خطأ تطبيق.

وربما يساعدك:

http://www.ddj.com/architect/185300443

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top