ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

TestDebug.c
Go to the documentation of this file.
00001 #define NATIVE 0
00002 
00003 #if NATIVE
00004 #define _X86_
00005 #include "ntndk.h"
00006 #else
00007 #include "stdio.h"
00008 #include "windows.h"
00009 #endif
00010 
00011 VOID
00012 Main(VOID)
00013 {
00014 #if NATIVE
00015     NTSTATUS Status;
00016     OBJECT_ATTRIBUTES ObjectAttributes;
00017     CLIENT_ID ClientId;
00018     DBGUI_WAIT_STATE_CHANGE State;
00019 #else
00020     DWORD Error, BytesRead;
00021     DEBUG_EVENT DebugEvent;
00022     WCHAR ImageName[MAX_PATH];
00023 #endif
00024     HANDLE hProcess;
00025     BOOLEAN Alive = TRUE;
00026 
00027 #if NATIVE
00028     printf("*** Native (DbgUi) Debugging Test Application\n");
00029     printf("Press any key to connect to Dbgk...");
00030     getchar();
00031 
00032     Status = DbgUiConnectToDbg();
00033     printf(" Connection Established. Status: %lx\n", Status);
00034     printf("Debug Object Handle: %lx\n", NtCurrentTeb()->DbgSsReserved[1]);
00035     printf("Press any key to debug services.exe...");
00036 #else
00037     printf("*** Win32 (Debug) Debugging Test Application\n");
00038     printf("Press any key to debug services.exe...");
00039 #endif
00040     getchar();
00041 
00042 #if NATIVE
00043     InitializeObjectAttributes(&ObjectAttributes, NULL, 0, 0, 0);
00044     ClientId.UniqueThread = 0;
00045     ClientId.UniqueProcess = UlongToHandle(168);
00046     Status = NtOpenProcess(&hProcess,
00047                            PROCESS_ALL_ACCESS,
00048                            &ObjectAttributes,
00049                            &ClientId);
00050     Status = DbgUiDebugActiveProcess(hProcess);
00051 #else
00052     Error = DebugActiveProcess(168);
00053 #endif
00054 
00055 #if NATIVE
00056     printf(" Debugger Attached. Status: %lx\n", Status);
00057 #else
00058     printf(" Debugger Attached. Error: %lx\n", Error);
00059 #endif
00060     printf("Press any key to get first debug event... ");
00061     getchar();
00062 
00063     while (Alive)
00064     {
00065 #if NATIVE
00066         Status = DbgUiWaitStateChange(&State, NULL);
00067         printf(" Event Received. Status: %lx\n", Status);
00068         printf("New State: %lx. Application Client ID: %lx/%lx\n",
00069                State.NewState,
00070                State.AppClientId.UniqueProcess, State.AppClientId.UniqueThread);
00071 #else
00072         Error = WaitForDebugEvent(&DebugEvent, -1);
00073         printf(" Event Received. Error: %lx\n", Error);
00074         printf("New State: %lx. Application Client ID: %lx/%lx\n",
00075                DebugEvent.dwDebugEventCode,
00076                DebugEvent.dwProcessId, DebugEvent.dwThreadId);
00077 #endif
00078 
00079 #if NATIVE
00080         switch (State.NewState)
00081 #else
00082         switch (DebugEvent.dwDebugEventCode)
00083 #endif
00084         {
00085 #if NATIVE
00086             case DbgCreateProcessStateChange:
00087                 printf("Process Handle: %lx. Thread Handle: %lx\n",
00088                     State.StateInfo.CreateProcessInfo.HandleToProcess,
00089                     State.StateInfo.CreateProcessInfo.HandleToThread);
00090                 printf("Process image handle: %lx\n",
00091                     State.StateInfo.CreateProcessInfo.NewProcess.FileHandle);
00092                 printf("Process image base: %lx\n",
00093                     State.StateInfo.CreateProcessInfo.NewProcess.BaseOfImage);
00094 #else
00095             case CREATE_PROCESS_DEBUG_EVENT:
00096                 printf("Process Handle: %lx. Thread Handle: %lx\n",
00097                         DebugEvent.u.CreateProcessInfo.hProcess,
00098                         DebugEvent.u.CreateProcessInfo.hThread);
00099                 printf("Process image handle: %lx\n",
00100                         DebugEvent.u.CreateProcessInfo.hFile);
00101                 printf("Process image base: %lx\n",
00102                         DebugEvent.u.CreateProcessInfo.lpBaseOfImage);
00103                 hProcess = DebugEvent.u.CreateProcessInfo.hProcess;
00104 #endif
00105                 break;
00106 
00107 #if NATIVE
00108             case DbgCreateThreadStateChange:
00109                 printf("New thread: %lx\n", State.StateInfo.CreateThread.HandleToThread);
00110                 printf("Thread Start Address: %p\n", State.StateInfo.CreateThread.NewThread.StartAddress);
00111 #else
00112             case CREATE_THREAD_DEBUG_EVENT:
00113                 printf("New thread: %lx\n", DebugEvent.u.CreateThread.hThread);
00114                 printf("Thread Start Address: %p\n",
00115                         DebugEvent.u.CreateThread.lpStartAddress);
00116 #endif
00117                 break;
00118 
00119 #if NATIVE
00120             case DbgLoadDllStateChange:
00121                 printf("New DLL: %lx\n", State.StateInfo.LoadDll.FileHandle);
00122                 printf("DLL LoadAddress: %p\n", State.StateInfo.LoadDll.BaseOfDll);
00123 #else
00124             case LOAD_DLL_DEBUG_EVENT:
00125                 printf("New DLL: %lx\n", DebugEvent.u.LoadDll.hFile);
00126                 printf("DLL LoadAddress: %p\n", DebugEvent.u.LoadDll.lpBaseOfDll);
00127                 Error = ReadProcessMemory(hProcess,
00128                                           DebugEvent.u.LoadDll.lpImageName,
00129                                           &DebugEvent.u.LoadDll.lpImageName,
00130                                           sizeof(DebugEvent.u.LoadDll.lpImageName),
00131                                           &BytesRead);
00132                 if (DebugEvent.u.LoadDll.lpImageName)
00133                 {
00134                     Error = ReadProcessMemory(hProcess,
00135                                               DebugEvent.u.LoadDll.lpImageName,
00136                                               ImageName,
00137                                               sizeof(ImageName),
00138                                               &BytesRead);
00139                     printf("DLL Name: %S\n", ImageName);
00140                 }
00141 #endif
00142                 break;
00143 
00144 #if NATIVE
00145             case DbgBreakpointStateChange:
00146                 printf("Initial breakpoint hit at: %p!\n",
00147                        State.StateInfo.Exception.ExceptionRecord.ExceptionAddress);
00148 #else
00149 
00150 #endif
00151                 break;
00152 
00153 #if NATIVE
00154             case DbgExitThreadStateChange:
00155                 printf("Thread exited: %lx\n", State.StateInfo.ExitThread.ExitStatus);
00156 #else
00157 
00158 #endif
00159                 break;
00160 
00161 #if NATIVE
00162             case DbgExitProcessStateChange:
00163                 printf("Process exited: %lx\n", State.StateInfo.ExitProcess.ExitStatus);
00164                 Alive = FALSE;
00165 #else
00166 
00167 #endif
00168                 break;
00169         }
00170 
00171         printf("Press any key to continue debuggee...");
00172         getchar();
00173 
00174 #if NATIVE
00175         ClientId.UniqueProcess = State.AppClientId.UniqueProcess;
00176         ClientId.UniqueThread = State.AppClientId.UniqueThread;
00177         Status = DbgUiContinue(&ClientId, DBG_CONTINUE);
00178         printf(" Debuggee Resumed. Status: %lx\n", Status);
00179 #else
00180         Error = ContinueDebugEvent(DebugEvent.dwProcessId,
00181                                    DebugEvent.dwThreadId,
00182                                    DBG_CONTINUE);
00183         printf(" Debuggee Resumed. Error: %lx\n", Error);
00184 #endif
00185 
00186         printf("Press any key to get next debug event... ");
00187         getchar();
00188     };
00189     printf("*** End of test\n");
00190     getchar();
00191 }

Generated on Sun May 27 2012 04:37:41 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.