Program Error Debugger
groups to diagnose a program error for a computer running Windows. A text file (Drwtsn32.log) is created whenever an error is detected, and can be delivered to support personnel by the method they prefer. You also have the option of creating a crash dump file, which is a binary file that a programmer can load into a debugger. If a program error occurs, Dr. Watson will start automatically. To start Dr. Watson, click Start, click Run, and then type drwtsn32. To start Dr. Watson from a command prompt, change to the root directory, and then type drwtsn32.Setting up Dr. WatsonUsing the Dr. Watson log fileWorking with Dr. WatsonUsing Dr. WatsonTop of pageManage Your Profile |Legal |Contact Us© 2016 Microsoft Corporation. All rights reserved.Contact Us |Terms of Use |Trademarks |Privacy & Cookies
computer software that has been planned carefully and written well may not always work correctly. Mysterious creatures called bugs may creep in and wreak havoc, leaving the programmer to clean up the mess. Some have theorized that a program fails only because its author made a mistake, but experienced computer programmers know that bugs are always to blame. This is why the task of fixing broken computer software is called debugging. It is impossible to https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/drwatson_overview.mspx prove the correctness of any non-trivial program; hence the Cynic's First Law of Debugging: Programs don't become more reliable as they are debugged; the bugs just get harder to find. Scheme is equipped with a variety of special software for finding and removing bugs. The debugging tools include facilities for tracing a program's use of specified procedures, for examining https://groups.csail.mit.edu/mac/ftpdir/scheme-7.4/doc-html/user_6.html Scheme environments, and for setting breakpoints, places where the program will pause for inspection. Many bugs are detected when programs try to do something that is impossible, like adding a number to a symbol, or using a variable that does not exist; this type of mistake is called an error. Whenever an error occurs, Scheme prints an error message and starts a new REPL. For example, using a nonexistent variable foo will cause Scheme to respond 1 ]=> foo ;Unbound variable: foo ;To continue, call RESTART with an option number: ; (RESTART 3) => Specify a value to use instead of foo. ; (RESTART 2) => Define foo to a given value. ; (RESTART 1) => Return to read-eval-print level 1. 2 error> Sometimes, a bug will never cause an error, but will still cause the program to operate incorrectly. For instance, (prime? 7) => #f In this situation, Scheme does not know that the program is misbehaving. The programmer must notice the problem and, if necessary, start the debugging tools manually. Ther
part of programming. If you run upon errors, you need to know how to find the issue, and resolve it. If you’re missing a semi-colon, http://www.cplusplus.com/forum/articles/28767/ you shouldn’t have to make a post to figure that out. Please keep in mind that this isn’t specifically how you should debug. It isn’t a set of rules, it’s a set of https://www.cs.rochester.edu/u/nelson/courses/csc_173/review/gdb.html recommendations. My recommendations may not necessarily be proper practice. If anything incorrect is found in this article please post so I can fix it. I don’t like to spread false knowledge. Anyway, we’ll start program error basic, from acknowledging and understanding a compiler error, to single-stepping through a program with your IDE’s debugger. Please note: I’m referencing C++ for Dummies 5th Edition by Stephen Randy Davis, pages 139-155. Identifying An Error Often times your program doesn’t work as planned, and won’t compile properly. Even the best programmers make mistakes, being able to identify what you did wrong is essential. There are two types program error debugger of errors that exist; those that the C++ compiler can catch on its own, and those that the compiler can’t catch. Errors that C++ can catch are known as compiler-time errors. Compiler-time errors should be relatively easy to fix, because the compiler points you to where the problem is. All that garbage that’s spit out by the compiler has some use. Here’s an example. I forgot to put a semicolon after my return statement. 1
2
3
4
int main() { return 0 } Your compiler should generate an error something like… \main.cpp(4) : error C2143: syntax error : missing ';' before '}' Compiler errors differ from compiler to compiler, but its all going to generally be the same. In my case, I’m using Visual Studio 2008, but if you’re using Dev-C++, or G++, the same thing applies. Now lets take this compiler error apart. The first part of it \main.cpp(4) says that the error is in the file main.cpp, on line 4. After that is error C2143: That’s the compiler specific error code. If you’re using Visual Studio, you can easily look up the error code on MSDN if you need to. After that the error states syntax error : W
option >g++ -g -o gdbprog gdbprog.cc Load executable into gdb >gdb gdbprog GDB is free software and you are welcome to distribute copies of it under certain conditions; type "show copying" to see the conditions. There is absolutely no warranty for GDB; type "show warranty" for details. GDB 4.12 (sparc-sun-sunos4.1.3C), Copyright 1994 Free Software Foundation, Inc... Use help to get information about available commands. Run program with run command (gdb) run Starting program: gdbprog Program received signal SIGSEGV, Segmentation fault. 0x2350 in DoOperation (ptrs=0x18bc0) at gdbprog.cc:24 24 sum += *ptrs[i]; Program will run until termination, a break point is reached, or an error occurs You can find out where the program is, i.e. where the segmentation fault occurred, using the where command. This gives a function call trace of how you got to this point and shows line numbers inside files. (gdb) where #0 0x2350 in DoOperation (ptrs=0x18bc0) at gdbprog.cc:24 #1 0x24b0 in main () at gdbprog.cc:45 list shows surrounding code (gdb) list 19 { 20 int sum = 0; 21 int i; 22 23 for(i = 0;i < 10;i++) 24 sum += *ptrs[i]; 25 } 26 27 28 void PrintArray() print allows you to display variables or any language expression. You may need a cast to display value correctly. (gdb) print i $1 = 1 (gdb) print ptrs[i] $2 = (int *) 0x0 (gdb) print (int* [10])*ptrs $3 = {0x18be8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} break sets breakpoints at places where you want the debugger to stop. break function-name will set a breakpoint at the start of the function. You can set multiple breakpoints. (gdb) break InitArrays Breakpoint 1 at 0x2298: file gdbprog.cc, line 10. run will restart the program when stopped in mid-execution (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starti