Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7694845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:24:40+00:00 2026-05-31T21:24:40+00:00

I have created my own debugger application. It attaches to a process and creates

  • 0

I have created my own debugger application. It attaches to a process and creates a crash dump file. That works most of the time. The problem I have is that it will not work when the application being debugged is waiting for a mutex object (and this is the very problem that I want to debug).

Furthermore, I have created a simple test.exe application that just loops around and calls Sleep(100) but my debugger fails when it calls MiniDumpWriteDump on this application every time.

What am I doing wrong?

The error code I get returned from the code below is 2147942699 (0x8007012b)

void WriteCrashDump( EXCEPTION_DEBUG_INFO *pExceptionInfo )
{
  CONTEXT c;

  memset( &c, 0, sizeof( c ) );

  GetThreadContext( hThread, &c );

  EXCEPTION_POINTERS ep;

  memset( &ep, 0, sizeof( ep ) );

  ep.ContextRecord   = &c;
  ep.ExceptionRecord = &pExceptionInfo->ExceptionRecord;

    MINIDUMP_EXCEPTION_INFORMATION minidump_exception;

  memset( &minidump_exception, 0, sizeof( minidump_exception ) );

    minidump_exception .ThreadId          = dwThreadId;
    minidump_exception.ExceptionPointers = &ep;
    minidump_exception.ClientPointers    = true;

  char txDumpPath[ MAX_PATH + 1 ];

  sprintf( txDumpPath, "%s.dmp", txProcess );

    HANDLE hFile = CreateFile( txDumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );

  if( hFile )
  {
    BOOL  fSuccess;


    SetLastError( 0L );

    int nDumpOptions =

    MiniDumpNormal
|    MiniDumpWithDataSegs                  
|    MiniDumpWithFullMemory                
|    MiniDumpWithHandleData                
|    MiniDumpFilterMemory                  
|    MiniDumpScanMemory                    
|    MiniDumpWithUnloadedModules           
|    MiniDumpWithIndirectlyReferencedMemory
|    MiniDumpFilterModulePaths             
|    MiniDumpWithProcessThreadData         
|    MiniDumpWithPrivateReadWriteMemory    
|    MiniDumpWithoutOptionalData           
    ;

    fSuccess = MiniDumpWriteDump( hProcess,
                                  dwProcessId,
                                  hFile,
                                  (MINIDUMP_TYPE) nDumpOptions,
                                  &minidump_exception,
                                  NULL,
                                  NULL );

    DWORD dwErr = GetLastError();

    if( ! fSuccess )
            printf( "MiniDumpWriteDump -FAILED (LastError:%u)\n", dwErr );

        CloseHandle( hFile );
    }
}

I have also tried increasing the privileges with the following code snippet which I borrowed from somebody else who seemed to have a similar problem:

BOOL SetDumpPrivileges()
{
    BOOL       fSuccess  = FALSE;
    HANDLE      TokenHandle = NULL;
    TOKEN_PRIVILEGES TokenPrivileges;

    if (!OpenProcessToken(GetCurrentProcess(),
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
        &TokenHandle))
    {
        printf("Could not get the process token");
        goto Cleanup;
    }

    TokenPrivileges.PrivilegeCount = 1;

    if (!LookupPrivilegeValue(NULL,
        SE_DEBUG_NAME,
        &TokenPrivileges.Privileges[0].Luid))
    {
        printf("Couldn't lookup SeDebugPrivilege name");
        goto Cleanup;
    }

    TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

    //Add privileges here.
    if (!AdjustTokenPrivileges(TokenHandle,
        FALSE,
        &TokenPrivileges,
        sizeof(TokenPrivileges),
        NULL,
        NULL))
    {
        printf("Could not revoke the debug privilege");
        goto Cleanup;
    }

    fSuccess = TRUE;

Cleanup:

    if (TokenHandle)
    {
        CloseHandle(TokenHandle);
    }

    return fSuccess;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:24:41+00:00Added an answer on May 31, 2026 at 9:24 pm

    I posted a question on MSDN and somebody kindly provided me the answer to my problem. Here’s the link to the discussion, and the working code snippet I’ve copied below.

    void WriteCrashDump( EXCEPTION_DEBUG_INFO *pExceptionInfo )
    {
      CONTEXT c;
    
      memset( &c, 0, sizeof( c ) );
    
      HANDLE hThread;
      c.ContextFlags = CONTEXT_FULL;
      hThread = _OpenThread( THREAD_ALL_ACCESS, FALSE, dwThreadId );
    
      GetThreadContext( hThread, &c );
    
      EXCEPTION_POINTERS ep;
    
      memset( &ep, 0, sizeof( ep ) );
    
      ep.ContextRecord   = &c;
      ep.ExceptionRecord = &pExceptionInfo->ExceptionRecord;
    
      MINIDUMP_EXCEPTION_INFORMATION minidump_exception;
    
      memset( &minidump_exception, 0, sizeof( minidump_exception ) );
    
      minidump_exception.ThreadId          = dwThreadId;
      minidump_exception.ExceptionPointers = &ep;
      minidump_exception.ExceptionPointers->ContextRecord = &c;
      minidump_exception.ClientPointers    = false;
    
      char txDumpPath[ MAX_PATH + 1 ];
    
      time_t tNow = time( NULL );
      struct tm *pTm = localtime( &tNow );
    
      sprintf( txDumpPath, "%s.%02d%02d%04d_%02d%02d%02d.dmp", 
               txProcess,
               pTm->tm_mday,
               pTm->tm_mon,
               pTm->tm_year,
               pTm->tm_hour, 
               pTm->tm_min, 
               pTm->tm_sec );
    
        HANDLE hFile = CreateFile( txDumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
    
      if( hFile != INVALID_HANDLE_VALUE ) 
      {
        BOOL  fSuccess;
    
        printf( "hProcess   : %d (0x%x)\n", hProcess, hProcess );
        printf( "dwProcessId: %u (0x%lx)\n", dwProcessId, dwProcessId );
        printf( "dwThreadId : %u (0x%lx)\n", dwThreadId,  dwThreadId );
    
        SetLastError( 0L );
    
        fSuccess = MiniDumpWriteDump( hProcess, 
                                      dwProcessId, 
                                      hFile, 
                                      MiniDumpNormal,
                                      &minidump_exception, 
                                      NULL, 
                                      NULL );
    
        DWORD dwErr = GetLastError();
    
        if( ! fSuccess )
        {
          printf( "MiniDumpWriteDump -FAILED (LastError:%u)\n", dwErr );
    
          LPVOID lpMsgBuf;
    
          FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                         NULL,
                         dwErr,
                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                         (LPTSTR) &lpMsgBuf,
                         0,
                         NULL );
    
          // Display the string.
          printf( "%s\n", (LPCTSTR)lpMsgBuf );
    
          // Free the buffer.
          LocalFree( lpMsgBuf );
        }
      } 
    
      if( hThread )
        CloseHandle( hThread );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created my own ExtendedTabControl to totally change it's apperance. It works ok.
I have created my own light box, the problem is that it shows centered
I have created my own class that extends CountDownTimer. Since I use it often,
I have created my own Role Provider because I found the one that ASP.Net
I have created my own XML-file on my Android phone, which looks similar to
I have created my own maps of US states that I want to use
I have created my own Perl module. I reference it from file Config.pm. When
I have created my own keyboard and I want to open that in place
I have created my own class that derives from QTableView, the associated model is
I have created my own Tree implementation for various reasons and have come up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.