locked
troubleshooting application startup process RRS feed

  • Question

  • I have windows application. I need to troubleshoot application start up process. How can I troubleshoot and what are the tools can be used to troubleshoot.

    Can anybody guide on this ?

    Mrutyunjaya

    • Moved by Baron Bi Tuesday, July 3, 2018 7:29 AM Not about c++ development
    Thursday, June 7, 2018 10:42 AM

Answers

  • Hi,

    thanks for posting here.

    This forum is about c++ development issues. For your case, I suggest you post on desktop forum for better support.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by MRUTYUNJAYA.M Monday, August 27, 2018 6:38 PM
    Tuesday, July 3, 2018 7:28 AM

All replies

  • The obvious starting point would be to use WinDbg or the Visual Studio debugger.

    But this question is extremely vague.  Exactly what problem are you trying to diagnose/solve?

    Thursday, June 7, 2018 10:52 AM
  • Thanks for your prompt reply. I am trying to diagnose and get complete path of startup process.

    Mrutyunjaya

    Thursday, June 7, 2018 11:55 AM
  • I am trying to diagnose and get complete path of startup process.

    Hello,

    use GetCurrentDirectory(): https://msdn.microsoft.com/en-us/library/windows/desktop/aa364934(v=vs.85).aspx

    Regards, Guido

    Thursday, June 7, 2018 12:05 PM
  • Thanks for your prompt reply. I am trying to diagnose and get complete path of startup process.

    What do you mean by "startup process"?  I still have no idea what you want to do.

    If you want your process to retrieve the fully qualified path to its .exe file it can call GetModuleFileName functon

    Better explanations of what you are trying to achieve will enable the community to provide better advice.

    Thursday, June 7, 2018 12:07 PM
  • get complete path of startup process

    I also am not sure what you mean. In this context, you probably mean that you want to know what executes during the startup process. I believe that the relevant source code for the C RunTime (CRT) is available in your system, you can study that. There is probably a way to use the debugger to step through it.


    Sam Hobbs
    SimpleSamples.Info

    Thursday, June 7, 2018 7:07 PM
  • Exactly, I want to know what executes from user space to kernel space internally during the startup process. What are the debuggers to step through it ?

    Mrutyunjaya

    Friday, June 8, 2018 5:11 AM
  • Are you doing this for a specific program you wrote or is this a question about the startup code for all C++ projects? Do you suspect a bug in the Microsoft code or is the Microsoft code causing a problem in a program of yours?

    I searched for debug crt startup and found the following that might help.



    Sam Hobbs
    SimpleSamples.Info

    Friday, June 8, 2018 6:51 AM
  • For background
    https://blogs.msdn.microsoft.com/microsoft_press/2012/04/16/sample-chapters-windows-internals-sixth-edition-part-1/
    where 'Process Monitor' is used to get an overview about Process Startup.
    For debugging get windbg
    https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools
    where, e.g. when in user-mode, you can break as early as CreateProcessEvent.
    Windbg is also a Kernel-Debugger, works great with Virtual Machines (Hyper-V needs Windows Prof).  
     
    With kind regards

    Friday, June 8, 2018 7:31 AM
  • I have windows application. I need to troubleshoot application start up process. How can I troubleshoot and what are the tools can be used to troubleshoot.

    Can anybody guide on this ?

    Mrutyunjaya

    First thing you need to specify are you the one who is starting this process by using CreateProcess() or ShellExecute() . If yes then GetLastError() is your friend. Something from MSDN

    If the function succeeds, the return value is nonzero.
    
    If the function fails, the return value is zero. To get extended error information, call GetLastError.
    
    Note that the function returns before the process has finished initialization. If a required DLL cannot be located or fails to initialize, the process is terminated. To get the termination status of a process, call GetExitCodeProcess.

    Or if you are just trying to run an application by clicking on it and it is not working then you need to see 

    1) whether it is showing any error or message , if yes look for it and find out the meaning of error.

    2) If it is getting closed silently then you can need to find out whether  any dependencies is missing or not.

    3) If it is crashing you can generate dmp file and can send to corresponding app ppl who can perform analysis on it.

    Thanks


    Rupesh Shukla

    Saturday, June 9, 2018 12:50 PM
  • Exactly, I want to know what executes from user space to kernel space internally during the startup process. What are the debuggers to step through it ?

    Mrutyunjaya

    The following assumes that you are asking about Window desktop application.  First, change the entry point of your program so that you can begin debugging the process before the CRT is initialized.  You can do this by setting the entry point as described at WinMain is just the conventional name for the Win32 process entry point

    Using either the visual studio debugger or WinDbg set a breakpoint in the raw entry point function.  You can then debug the entire startup process, including the initialization of the CRT.  In your raw entry point function you would pass control to startup the CRT by calling one if the CRT entry points shown in https://docs.microsoft.com/en-gb/cpp/build/reference/entry-entry-point-symbol



    • Edited by RLWA32 Saturday, June 9, 2018 2:07 PM
    • Proposed as answer by Baron Bi Wednesday, June 20, 2018 8:15 AM
    Saturday, June 9, 2018 1:24 PM
  • If what you mean by startup process is what the process does prior to when it calls main, then the question is how far do you want to trace things.

    If you only want the user mode calls, then Visual Studio or WinDbg will be enough, and it is easy enough to get the earliest point that execution starts in a process by using the call stack. For example, Desktop application call stack is:

    This means that RtlUserThreadStart in ntdll.dll is the earliest user mode point that you can get, so if you use a user mode debugger, then this is the earliest you can debug from.

    If you want to get at an even earlier point than this, you are going to have to use the kernel mode debugger from WinDbg.

    This is the only debugger that will allow the kernel mode debugging that you need to trace the startup.

    While I'm not going to try to stop you, the process startup is quite boring. First the process object is created, then the first thread is created. This then loads kernel32.dll (this pulls in ntdll.dll since this is required for any process, and kernelbase.dll since kernel32.dll depends on it), the executable is then loaded and all dependent libraries are loaded, as each library is loaded the DllMain is called with DLL_PROCESS_ATTACH. Finally it jumps into the RtlUserThreadStart function which calls the executable entrypoint function.

    If anything, the WoW64 process startup is more interesting since it has to load the WoW layer libraries, the 64 bit ntdll.dll, and the 32 bit required libraries (ntdll.dll, kernel32.dll and kernelbase.dll). It also has to do the processor mode switch too.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    • Proposed as answer by Baron Bi Wednesday, June 20, 2018 8:14 AM
    Saturday, June 9, 2018 3:21 PM
  • Very interesting.  But I wonder why anyone would need to diagnose a user-mode startup problem by going to these lengths (including my own suggestion).

    • Edited by RLWA32 Saturday, June 9, 2018 4:06 PM
    Saturday, June 9, 2018 4:03 PM
  • The two most obvious would be a DllMain problem or a global problem.

    But I agree, just putting a breakpoint on the DllMain or the constructor for the global variable should be enough.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Saturday, June 9, 2018 4:53 PM
  • Hi,

    thanks for posting here.

    This forum is about c++ development issues. For your case, I suggest you post on desktop forum for better support.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by MRUTYUNJAYA.M Monday, August 27, 2018 6:38 PM
    Tuesday, July 3, 2018 7:28 AM