Hex Artifact Content
Not logged in

Artifact f18562976753621a5cc5ea63bc453ba19dd7b917:


0000: 49 20 77 72 6f 74 65 20 61 20 73 6d 61 6c 6c 20  I wrote a small 
0010: 70 69 65 63 65 20 6f 66 20 73 6f 75 72 63 65 63  piece of sourcec
0020: 6f 64 65 20 74 68 61 74 20 67 65 6e 65 72 61 74  ode that generat
0030: 65 73 20 73 74 61 63 6b 74 72 61 63 65 73 20 69  es stacktraces i
0040: 6e 20 44 20 32 2e 30 20 75 6e 64 65 72 20 77 69  n D 2.0 under wi
0050: 6e 64 6f 77 73 2e 20 49 74 20 77 6f 72 6b 73 20  ndows. It works 
0060: 62 6f 74 68 20 77 69 74 68 20 74 68 65 20 70 64  both with the pd
0070: 62 20 61 6e 64 20 63 76 20 64 65 62 75 67 20 73  b and cv debug s
0080: 79 6d 62 6f 6c 20 66 6f 72 6d 61 74 2e 20 46 6f  ymbol format. Fo
0090: 72 20 45 78 63 65 70 74 69 6f 6e 73 20 74 68 61  r Exceptions tha
00a0: 74 20 61 72 65 20 64 65 72 69 76 65 64 20 66 72  t are derived fr
00b0: 6f 6d 20 74 68 65 20 45 72 72 6f 72 20 63 6c 61  om the Error cla
00c0: 73 73 20 74 68 65 20 74 72 61 63 65 20 69 6e 66  ss the trace inf
00d0: 6f 72 6d 61 74 69 6f 6e 20 69 73 20 61 75 74 6f  ormation is auto
00e0: 6d 61 74 69 63 61 6c 6c 79 20 61 70 70 65 6e 64  matically append
00f0: 65 64 2c 20 74 68 69 73 20 63 61 75 73 65 73 20  ed, this causes 
0100: 61 6c 6c 20 62 75 69 6c 74 69 6e 20 44 20 65 72  all builtin D er
0110: 72 6f 72 73 20 74 6f 20 67 65 74 20 61 20 73 74  rors to get a st
0120: 61 63 6b 74 72 61 63 65 20 69 6e 66 6f 72 6d 61  acktrace informa
0130: 74 69 6f 6e 2e 20 54 68 65 20 6f 6e 6c 79 20 70  tion. The only p
0140: 6f 69 6e 74 20 77 68 65 72 65 20 74 68 69 73 20  oint where this 
0150: 64 6f 65 73 20 6e 6f 74 20 77 6f 72 6b 20 69 73  does not work is
0160: 20 74 68 65 20 41 63 63 65 73 73 20 56 69 6f 61   the Access Vioa
0170: 6c 74 69 6f 6e 20 65 72 72 6f 72 2c 20 61 73 20  ltion error, as 
0180: 69 74 20 64 6f 65 73 20 6e 6f 74 20 63 61 6c 6c  it does not call
0190: 20 74 68 65 20 73 74 61 63 6b 74 72 61 63 65 20   the stacktrace 
01a0: 63 61 6c 6c 62 61 63 6b 20 66 75 6e 63 74 69 6f  callback functio
01b0: 6e 20 66 6f 72 20 73 6f 6d 65 20 72 65 61 73 6f  n for some reaso
01c0: 6e 2e 0d 0a 0d 0a 0d 0a 49 74 20 69 73 20 76 65  n.......It is ve
01d0: 72 79 20 65 61 73 79 20 74 6f 20 75 73 65 2c 20  ry easy to use, 
01e0: 6a 75 73 74 20 63 6f 70 79 20 74 68 65 20 74 77  just copy the tw
01f0: 6f 20 66 69 6c 65 73 20 66 72 6f 6d 20 74 68 65  o files from the
0200: 20 7a 69 70 20 61 72 63 68 69 76 65 20 74 6f 20   zip archive to 
0210: 79 6f 75 72 20 72 6f 6f 74 20 73 6f 75 72 63 65  your root source
0220: 20 64 69 72 65 63 74 6f 72 79 20 61 6e 64 20 69   directory and i
0230: 6d 70 6f 72 74 20 74 68 65 20 73 74 61 63 6b 74  mport the stackt
0240: 72 61 63 65 20 6d 6f 64 75 6c 65 20 69 6e 73 69  race module insi
0250: 64 65 20 79 6f 75 72 20 6d 61 69 6e 20 66 69 6c  de your main fil
0260: 65 2e 0d 0a 0d 0a 69 6d 70 6f 72 74 20 73 74 61  e.....import sta
0270: 63 6b 74 72 61 63 65 3b 0d 0a 0d 0a 76 6f 69 64  cktrace;....void
0280: 20 6d 61 69 6e 28 73 74 72 69 6e 67 5b 5d 20 61   main(string[] a
0290: 72 67 76 29 7b 0d 0a 2e 2e 2e 0d 0a 7d 0d 0a 0d  rgv){.......}...
02a0: 0a 4e 6f 77 20 61 6c 6c 20 45 72 72 6f 72 73 20  .Now all Errors 
02b0: 77 69 6c 6c 20 67 65 74 20 74 72 61 63 65 20 69  will get trace i
02c0: 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0d 0a 49 66 20  nformation...If 
02d0: 79 6f 75 20 6e 65 65 64 20 61 20 62 61 63 6b 74  you need a backt
02e0: 72 61 63 65 20 61 74 20 61 20 63 65 72 74 61 69  race at a certai
02f0: 6e 20 70 6f 69 6e 74 20 69 6e 20 79 6f 75 72 20  n point in your 
0300: 63 6f 64 65 20 6a 75 73 74 20 64 6f 20 74 68 65  code just do the
0310: 20 66 6f 6c 6c 6f 77 69 6e 67 3a 0d 0a 0d 0a 6d   following:....m
0320: 6f 64 75 6c 65 20 66 6f 6f 3b 0d 0a 0d 0a 69 6d  odule foo;....im
0330: 70 6f 72 74 20 73 74 61 63 6b 74 72 61 63 65 3b  port stacktrace;
0340: 0d 0a 0d 0a 76 6f 69 64 20 62 6c 75 70 28 29 7b  ....void blup(){
0350: 0d 0a 2e 2e 2e 0d 0a 53 74 61 63 6b 54 72 61 63  .......StackTrac
0360: 65 20 74 72 61 63 65 20 3d 20 6e 65 77 20 53 74  e trace = new St
0370: 61 63 6b 54 72 61 63 65 28 29 3b 0d 0a 61 75 74  ackTrace();..aut
0380: 6f 20 73 74 61 63 6b 20 3d 20 74 72 61 63 65 2e  o stack = trace.
0390: 47 65 74 43 61 6c 6c 73 74 61 63 6b 28 29 3b 0d  GetCallstack();.
03a0: 0a 66 6f 72 65 61 63 68 28 63 68 61 72 5b 5d 20  .foreach(char[] 
03b0: 73 3b 73 74 61 63 6b 29 0d 0a 77 72 69 74 65 66  s;stack)..writef
03c0: 6c 6e 28 22 25 73 22 2c 73 29 3b 0d 0a 2e 2e 2e  ln("%s",s);.....
03d0: 0d 0a 7d 0d 0a 0d 0a 49 74 20 69 73 20 72 65 6c  ..}....It is rel
03e0: 65 61 73 65 64 20 75 6e 64 65 72 20 74 68 65 20  eased under the 
03f0: 42 53 44 20 6c 69 63 65 6e 73 65 2e 20 49 66 20  BSD license. If 
0400: 74 68 69 73 20 6c 69 63 65 6e 63 65 20 63 61 75  this licence cau
0410: 73 65 73 20 61 6e 79 20 70 72 6f 62 6c 65 6d 73  ses any problems
0420: 20 66 6f 72 20 79 6f 75 2c 20 66 65 65 6c 20 66   for you, feel f
0430: 72 65 65 20 74 6f 20 63 6f 6e 74 61 63 74 20 6d  ree to contact m
0440: 65 20 61 6e 64 20 77 65 20 77 69 6c 6c 20 66 69  e and we will fi
0450: 78 20 74 68 65 20 70 72 6f 62 6c 65 6d 2e 0d 0a  x the problem...
0460: 0d 0a 58 50 20 55 73 65 72 73 3a 0d 0a 49 66 20  ..XP Users:..If 
0470: 79 6f 75 20 67 65 74 20 61 20 73 74 61 63 6b 74  you get a stackt
0480: 72 61 63 65 20 77 69 74 68 20 6e 75 6d 62 65 72  race with number
0490: 73 20 6f 6e 6c 79 20 64 6f 77 6e 6c 6f 61 64 20  s only download 
04a0: 61 20 6e 65 77 20 76 65 72 73 69 6f 6e 20 6f 66  a new version of
04b0: 20 64 62 67 68 65 6c 70 2e 64 6c 6c 20 61 6e 64   dbghelp.dll and
04c0: 20 70 75 74 20 69 74 20 69 6e 74 6f 20 79 6f 75   put it into you
04d0: 72 20 70 72 6f 6a 65 63 74 20 72 6f 6f 74 20 64  r project root d
04e0: 69 72 65 63 74 6f 72 79 2e 20 54 68 61 74 20 73  irectory. That s
04f0: 68 6f 75 6c 64 20 66 69 78 20 69 74 2e           hould fix it.