From: huangliang <lh...@se...> - 2003-12-31 09:51:59
|
SGkgYWxsLiBJIHdyaXRlIGEgcHJvZ3JhbSB3aGljaCBvcGVucyBtYW55IHRleHQgZmlsZXMsIGRv IHNvbWUgb3BlcmF0aW9ucyBhbmQgdGhlbiBjbG9zZSB0aGVtLiBFYWNoIHRpbWUgdGhlIHByb2dy YW0gb3BlbnMgb25lIGZpbGUsIHJlYWRzIGl0cyBjb250ZW50cyBhbmQgdGhlbiBjbG9zZXMgaXQu IEkgdXNlIGEgbG9vcCB0byBkZWFsIHdpdGggYWxsIGZpbGVzLiBCdXQgZXZlcnkgdGltZSBJIHJ1 biBpdCwgdGhlIHByb2dyYW0gd2lsbCB0ZXJtaW5hdGUgYWZ0ZXIgaXQgaGFzIHByb2Nlc3NlZCBh IG51bWJlciBvZiAoZm9yIGV4YW1wbGUgNjQxKSBmaWxlcyB0aHJvd2luZyB0aGUgZXJyb3IgbWVz c2FnZSAiYWJub3JtYWwgcHJvZ3JhbSB0ZXJtaW5hdGlvbiIuIEkgYW0gc3VyZSBJIGhhdmUgY2xv c2VkIHRoZSBvcGVuZWQgZmlsZSBhZnRlciBoYXZpbmcgcmVhZCBpdC4gV2hvIGNhbiB0ZWxsIHdo YXQncyB3cm9uZyB3aXRoIGl0Pw0K |
From: Greg C. <chi...@mi...> - 2003-12-31 15:13:31
|
huangliang wrote: > > Hi all. I write a program which opens many text files, do some > operations and then close them. Each time the program opens one > file, reads its contents and then closes it. I use a loop to deal > with all files. But every time I run it, the program will terminate > after it has processed a number of (for example 641) files throwing > the error message "abnormal program termination". I am sure I have > closed the opened file after having read it. Who can tell what's > wrong with it? To find out what's wrong, use standard debugging techniques such as: 1. Add statements to your program to print the values of variables as your program runs. Make sure you flush each print statement, because abnormal termination may prevent the system from doing that for you (use something like fflush() or std::endl). The output will show the state of your program right before it terminates. 2. Remove statements from your program until it does not terminate abnormally. If it looks like for(int j = 0; j < 1000; ++j) { // (a) open a file // (b) read file contents into a variable // (c) perform some operation that changes that variable // (d) store that changed variable somewhere } then remove first (d), then (c), then (b), then (a). The last statement you had to remove may be the problem. 3. Follow the advice Alberto Luaces <al...@na...> gave in his 27 Dec 2003 13:52:17 +0100 reply to your other message: | Hello, what information does the debugger provides? (Compile with | '-g' option, run 'gdb your_exe.exe', type 'run' command and wait | until it crashes; then type 'bt' to inspect the stack frame and | know what function is the culprit). 4. I suspect it doesn't actually crash: the message abnormal program termination could come from a function such as abort(), as in this program: #include <cstdlib> void bar() {std::abort();} void foo() {bar();} int main() {foo();} Still, Alberto's advice helps you: C:/tmp[0]$/MinGW/bin/g++ -ggdb -O0 abnormal.cpp C:/tmp[0]$/gdb/bin/gdb.exe --quiet a.exe (gdb) break 'abort' Breakpoint 1 at 0x401800 (gdb) r Starting program: C:\tmp/a.exe Breakpoint 1, 0x00401800 in abort () (gdb) bt #0 0x00401800 in abort () #1 0x004012db in bar() () at abnormal.cpp:2 #2 0x004012e9 in foo() () at abnormal.cpp:3 #3 0x0040130f in main () at abnormal.cpp:4 Of course, you probably don't call abort() explicitly, but it may be called by some library routine that you use, such as assert(). You may need to set breakpoints on similar functions like std::terminate(). |