2012-03-13 8 views
0

サンプルコードの使用を開始するには、C++/CLI Win32 debugger library for x86でプロセス例外を監視してください。デバッグAPIによるプロセス例外の監視

私が作ったいくつかのコードは次のとおりです。

 
using System; 
using DebugLibrary; 

namespace DebugTeste01 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      DebugUtil.DebugActiveProcess(4932); 
      DebugEvent de = new DebugEvent(); 
      ThreadContext tc = new ThreadContext(); 
      LDTEntry ldte = new LDTEntry(); 

      do 
      { 
       debug_evt = DebugUtil.WaitForDebugEvent(0xffffffff); 

       de = (DebugEvent)debug_evt; 
       Process proc = Process.GetProcessById(de.processId); 

       object meminfo = DebugUtil.GetMemoryInfo(proc.Handle); 
       //... 
       object modinf = DebugUtil.GetModuleInfo(proc.Handle); 
       //... 

       switch (debug_evt.GetType().ToString()) 
       { 
        case "DebugLibrary.DebugEvent_CreateProcess": 
         { 
          DebugEvent_CreateProcess decp = (DebugEvent_CreateProcess)debug_evt; 
          //some action, logging, etc. 
         } 
         break; 
        case "DebugLibrary.DebugEvent_LoadDll": 
         { 
          DebugEvent_LoadDll dect = (DebugEvent_LoadDll)debug_evt; 
          //some action, logging, etc. 
         } 
         break; 
        case "DebugLibrary.DebugEvent_CreateThread": 
         { 
          DebugEvent_CreateThread dect = (DebugEvent_CreateThread)debug_evt; 
          //some action, logging, etc. 
         } 
         break; 
        case "DebugLibrary.DebugEvent_ExitThread": 
         { 
          DebugEvent_ExitThread dect = (DebugEvent_ExitThread)debug_evt; 
          //some action, logging, etc. 
         } 
         break; 
        case "DebugLibrary.DebugEvent_Exception": 
         { 
          DebugEvent_Exception dect = (DebugEvent_Exception)debug_evt; 

          ExceptionRecord exbp = dect.exceptionRecord; 

          switch (exbp.GetType().ToString()) 
          { 
           case "Breakpoint": 
            { 
             //some action, logging, etc. 
             exbp = null; 
            } 
            break; 
           case "AccessViolation": 
            { 
             //some action, logging, etc. 
             exbp = null; 
            } 
            break; 
           //more case 
          } 
         } 
         break; 
        default: 
         { 
          //some action, logging, etc. 
          debug_evt = null; 
         } 
         break; 
       } 

       try 
       { 
        DebugUtil.ContinueDebugEvent(de.processId, de.threadId, false); 
       } 
       catch 
       { 
        break; 
       } 
      } 
      while (true); 
     } 
    } 
} 

[EDIT] 2012年3月14日
良い記事:Using the Windows Debugging API
[EDIT] 2012年3月14日
実装の改善。
これは、最終的なアプリケーション用の初期スケルトン構成を持っています。

答えて

1

私はあなたに理解のためにデバッガライティングのリソースを教えてくれているようです。その場合は、あなたの最善の場所はMSDNです。これはどのように扱うべきかの基礎を示します。そこから実際にアプリケーションと環境まで、例外をどのように処理するのかを示します。

実際のコードに対するコメントとして、プロセス名を使用する代わりに、PIDへのハードコーディングを避けてください。

+0

コードの目的はAPIの使い方を示すことですが、まずどのように動作するのか理解しておく必要があります。 – lsalamon

関連する問題