チェンジセット 1529 (default)
- 日時:
- 2021/11/19 0:00:17 (3年前)
- 場所:
- framework/trunk
- ファイル:
-
- 2個の更新
凡例:
- 未変更
- 追加
- 削除
-
framework/trunk/CoreTest/Sources/Diagnostics/NativeExceptionHandlerTest.cs
r1124 r1529 10 10 // you may not use this file except in compliance with the License. You 11 11 // may obtain a copy of the License at 12 // 12 // 13 13 // http://www.apache.org/licenses/LICENSE-2.0 14 // 14 // 15 15 // Unless required by applicable law or agreed to in writing, software 16 16 // distributed under the License is distributed on an "AS IS" BASIS, … … 20 20 // </license> 21 21 // ---------------------------------------------------------------------------- 22 // ReSharper disable ExceptionNotDocumented 22 23 namespace FCSoft.SilverFrost.Framework.Diagnostics 23 24 { … … 64 65 /// </summary> 65 66 [Test] 67 [Explicit("Cannot stop")] 66 68 public void TestSetDumpDirectoryAndThrowAccessViolation() 67 69 { … … 78 80 ZeroMemory(IntPtr.Zero, 1); 79 81 }, 80 Throws.InstanceOf< AccessViolationException>());82 Throws.InstanceOf<Exception>()); 81 83 82 84 string[] files = Directory.GetFiles(temporaryDirectory.Path); … … 85 87 86 88 FileInfo fileInfo = new FileInfo(files[0]); 89 Assert.That(fileInfo.Name, Does.EndWith("-" + Process.GetCurrentProcess().Id + @"-0x00000005.dmp"), "Name"); 87 90 Assert.That(fileInfo.Length, Is.GreaterThan(1024 * 128), "FileLength"); 88 91 } … … 95 98 96 99 /// <summary> 97 /// ダンプの種類を設定して例外を発生させ、 100 /// ダンプの出力先のディレクトリを設定してソフトウェア例外を発生させ、 101 /// そのディレクトリにダンプファイルが作成されるかをテストします。 102 /// </summary> 103 [Test] 104 public void TestSetDumpDirectoryAndRaiseException() 105 { 106 using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) 107 { 108 Assert.That(NativeExceptionHandler.RegisterExceptionHandler(), Is.True, "RegisterExceptionHandler"); 109 try 110 { 111 NativeExceptionHandler.DumpDirectory = temporaryDirectory.Path; 112 113 Assert.That( 114 delegate 115 { 116 RaiseException(0xA, 1, 0, IntPtr.Zero); 117 }, 118 Throws.InstanceOf<Exception>()); 119 120 string[] files = Directory.GetFiles(temporaryDirectory.Path); 121 DumpFiles(files); 122 Assert.That(files.Length, Is.EqualTo(1), "Dump file count"); 123 124 FileInfo fileInfo = new FileInfo(files[0]); 125 Assert.That(fileInfo.Name, Does.EndWith("-" + Process.GetCurrentProcess().Id + @"-0x0000000A.dmp"), "Name"); 126 Assert.That(fileInfo.Length, Is.GreaterThan(1024 * 128), "FileLength"); 127 } 128 finally 129 { 130 Assert.That(NativeExceptionHandler.UnregisterExceptionHandler(), Is.True, "UnregisterExceptionHandler"); 131 } 132 } 133 } 134 135 /// <summary> 136 /// ダンプの種類を設定してソフトウェア例外を発生させ、 98 137 /// 正しい種類のダンプファイルが作成されるかをテストします。 99 138 /// </summary> 100 139 [Test] 101 public void TestSetDumpTypeAnd ThrowAccessViolation()140 public void TestSetDumpTypeAndRaiseException() 102 141 { 103 142 using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) … … 112 151 delegate 113 152 { 114 ZeroMemory(IntPtr.Zero, 1);115 }, 116 Throws.InstanceOf< AccessViolationException>());153 RaiseException(0xA, 1, 0, IntPtr.Zero); 154 }, 155 Throws.InstanceOf<Exception>()); 117 156 118 157 string[] files = Directory.GetFiles(temporaryDirectory.Path); … … 121 160 122 161 FileInfo fileInfo = new FileInfo(files[0]); 162 Assert.That(fileInfo.Name, Does.EndWith("-" + Process.GetCurrentProcess().Id + @"-0x0000000A.dmp"), "Name"); 123 163 Assert.That(fileInfo.Length, Is.GreaterThan(1024 * 1024 * 16), "FileLength"); 124 164 } … … 131 171 132 172 /// <summary> 133 /// ログのの出力先ファイルを設定して 例外を発生させ、173 /// ログのの出力先ファイルを設定してソフトウェア例外を発生させ、 134 174 /// そのファイルにログが出力されるかをテストします。 135 175 /// </summary> 136 176 [Test] 137 public void TestSetLogFileAnd ThrowAccessViolation()177 public void TestSetLogFileAndRaiseException() 138 178 { 139 179 using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) … … 150 190 delegate 151 191 { 152 ZeroMemory(IntPtr.Zero, 1);192 RaiseException(0xA, 1, 0, IntPtr.Zero); 153 193 }, 154 Throws.InstanceOf< AccessViolationException>());194 Throws.InstanceOf<Exception>()); 155 195 156 196 Assert.That( 157 197 delegate 158 198 { 159 ZeroMemory(IntPtr.Zero, 1);199 RaiseException(0xA, 1, 0, IntPtr.Zero); 160 200 }, 161 Throws.InstanceOf< AccessViolationException>());201 Throws.InstanceOf<Exception>()); 162 202 163 203 string[] files = Directory.GetFiles(temporaryDirectory.Path); … … 217 257 218 258 Assert.That( 219 (TestDelegate)ThrowApplicationException, 259 delegate 260 { 261 throw new ApplicationException(); 262 }, 220 263 Throws.InstanceOf<ApplicationException>()); 264 265 string[] files = Directory.GetFiles(temporaryDirectory.Path); 266 DumpFiles(files); 267 Assert.That(files.Length, Is.EqualTo(0), "Dump file count"); 268 } 269 finally 270 { 271 Assert.That(NativeExceptionHandler.UnregisterExceptionHandler(), Is.True, "UnregisterExceptionHandler"); 272 } 273 } 274 } 275 276 /// <summary> 277 /// ダンプの出力先のディレクトリを設定してコードから <see cref="ArgumentNullException"/> 例外を発生させ、 278 /// そのディレクトリにダンプファイルが作成されないかをテストします。 279 /// </summary> 280 [Test] 281 public void TestThrowManualArgumentNullException() 282 { 283 using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) 284 { 285 Assert.That(NativeExceptionHandler.RegisterExceptionHandler(), Is.True, "RegisterExceptionHandler"); 286 try 287 { 288 NativeExceptionHandler.DumpDirectory = temporaryDirectory.Path; 289 290 Assert.That( 291 delegate 292 { 293 throw new ArgumentNullException(); 294 }, 295 Throws.InstanceOf<ArgumentNullException>()); 296 297 string[] files = Directory.GetFiles(temporaryDirectory.Path); 298 DumpFiles(files); 299 Assert.That(files.Length, Is.EqualTo(0), "Dump file count"); 300 } 301 finally 302 { 303 Assert.That(NativeExceptionHandler.UnregisterExceptionHandler(), Is.True, "UnregisterExceptionHandler"); 304 } 305 } 306 } 307 308 /// <summary> 309 /// ダンプの出力先のディレクトリを設定してコードから <see cref="NullReferenceException"/> 例外を発生させ、 310 /// そのディレクトリにダンプファイルが作成されないかをテストします。 311 /// </summary> 312 [Test] 313 public void TestThrowManualNullReferenceException() 314 { 315 using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) 316 { 317 Assert.That(NativeExceptionHandler.RegisterExceptionHandler(), Is.True, "RegisterExceptionHandler"); 318 try 319 { 320 NativeExceptionHandler.DumpDirectory = temporaryDirectory.Path; 321 322 Assert.That( 323 delegate 324 { 325 throw new NullReferenceException(); 326 }, 327 Throws.InstanceOf<NullReferenceException>()); 221 328 222 329 string[] files = Directory.GetFiles(temporaryDirectory.Path); … … 339 446 340 447 /// <summary> 448 /// ソフトウェア例外を発生します。 449 /// </summary> 450 /// <param name="exceptionCode">例外コード。</param> 451 /// <param name="exceptionFlags">継続不能な場合は <c>1</c>。継続可能な場合は <c>0</c>。</param> 452 /// <param name="numberOfArguments"><paramref name="arguments"/> の配列数。</param> 453 /// <param name="arguments">引数の配列。</param> 454 [DllImport("kernel32.dll", SetLastError = false)] 455 private static extern void RaiseException(int exceptionCode, int exceptionFlags, int numberOfArguments, IntPtr arguments); 456 457 /// <summary> 341 458 /// 再帰的に呼び出すメソッドです。 342 459 /// </summary> … … 353 470 354 471 /// <summary> 355 /// <see cref="ApplicationException"/> 例外を発生させます。356 /// </summary>357 /// <exception cref="ApplicationException">358 /// 必ず発生します。359 /// </exception>360 private static void ThrowApplicationException()361 {362 throw new ApplicationException();363 }364 365 /// <summary>366 472 /// ファイルの一覧をダンプします。 367 473 /// </summary> … … 369 475 private static void DumpFiles(string[] files) 370 476 { 477 Trace.WriteLine("### Files: " + files.Length); 478 371 479 for (int i = 0; i < files.Length; i++) 372 480 { -
framework/trunk/NativeLibrary/Sources/ExceptionHandler.cpp
r1441 r1529 10 10 // you may not use this file except in compliance with the License. You 11 11 // may obtain a copy of the License at 12 // 12 // 13 13 // http://www.apache.org/licenses/LICENSE-2.0 14 // 14 // 15 15 // Unless required by applicable law or agreed to in writing, software 16 16 // distributed under the License is distributed on an "AS IS" BASIS, … … 395 395 case STATUS_INTEGER_DIVIDE_BY_ZERO: // 0xC0000094L 396 396 case STATUS_STACK_OVERFLOW: // 0xC00000FDL 397 case 0xC06D7363L: // EXCEPTION_MSVC exception inserted by Visual C++, often used for SEH398 case 0xC0524F54L: // EXCEPTION_COMPLUS EXCEPTION_COMPLUS (ROT)399 case 0xC0434352L: // EXCEPTION_COMPLUS EXCEPTION_COMPLUS (CCR)400 case 0xC0434F4DL: // EXCEPTION_COMPLUS EXCEPTION_COMPLUS (COM)401 case 0xC0434F4EL: // EXCEPTION_HIJACK Resuming thread after garbage collection.402 case 0xC053534FL: // EXCEPTION_SOFTSO CLR X^bNI[o[t[403 case 0xC0455858L: // EXCEPTION_EXX SetupThread PInvoke failure.404 case 0xE0434F4DL: // EXCEPTION_CLR CLR áOÌX[405 case 0xE0434F4EL: // EXCEPTION_HIJACK COM+ exceptions OR .NET Remoting n?406 case 0xE06D7363L: // EXCEPTION_OVERFLOW CLR OverflowException ÌX[407 case 0x406D1388L: // ? XPECLib ©çÀs³êé408 397 case 0x00000005L: // ? rpcrt4!NdrSendReceive ©çX[ 409 398 case 0x00000006L: // SERVICE_CONTROL_PARAMCHANGE? Windows XP ÌT[rXRg[àŶ 410 399 case 0x02345678L: // ? jit!Compiler ©çX[ (x86 Àè?) 400 case 0x406D1388L: // ? XPECLib ©çÀs³êé 401 402 //// ÈºÍ 0xC Æ 0xE ð¼ûè`·é 403 case 0xC06D7363L: // EXCEPTION_MSVC exception inserted by Visual C++, often used for SEH 404 case 0xE06D7363L: // EXCEPTION_OVERFLOW CLR OverflowException ÌX[ 405 406 case 0xC0524F54L: // EXCEPTION_COMPLUS EXCEPTION_COMPLUS (ROT) 407 case 0xE0524F54L: // ? (O̽ßÉè`) 408 409 case 0xC0434352L: // EXCEPTION_COMPLUS EXCEPTION_COMPLUS (CCR) 410 case 0xE0434352L: // EXCEPTION_COMPLUS EXCEPTION_COMPLUS (CCR), .NET 4 nÈ~Ì CLR áO? 411 412 case 0xC053534FL: // EXCEPTION_SOFTSO CLR X^bNI[o[t[ 413 case 0xE053534FL: // ? (O̽ßÉè`) 414 415 case 0xC0455858L: // EXCEPTION_EXX SetupThread PInvoke failure. 416 case 0xE0455858L: // ? (O̽ßÉè`) 417 418 case 0xC0434F4DL: // EXCEPTION_COMPLUS EXCEPTION_COMPLUS (COM) 419 case 0xE0434F4DL: // EXCEPTION_CLR CLR áOÌX[ 420 421 case 0xC0434F4EL: // EXCEPTION_HIJACK Resuming thread after garbage collection. 422 case 0xE0434F4EL: // EXCEPTION_HIJACK COM+ exceptions OR .NET Remoting n? 411 423 return EXCEPTION_CONTINUE_SEARCH; 412 424 default:
※ 詳しい使い方は
TracChangeset を参照してください。