comparison host/infra/assert.cxx @ 283:f58bc1b2c2bc

Reorganization of the host-side autoconfiscation support, and a couple of minor bug fixes. The main goal is to support per-package host-side software in addition to the generic host-side tools. For example, the synthetic target HAL and device driver packages can now have host subdirectories with support code.
author bartv
date Sun, 11 Aug 2002 21:40:50 +0000
parents e2d866e32dac
children 938a6182d15f
comparison
equal deleted inserted replaced
282:a29ee6c2dd3c 283:f58bc1b2c2bc
8 // 8 //
9 //============================================================================ 9 //============================================================================
10 //####COPYRIGHTBEGIN#### 10 //####COPYRIGHTBEGIN####
11 // 11 //
12 // ---------------------------------------------------------------------------- 12 // ----------------------------------------------------------------------------
13 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. 13 // Copyright (C) 2002 Bart Veer
14 // Copyright (C) 1998, 1999, 2000, 2001 Red Hat, Inc.
14 // 15 //
15 // This file is part of the eCos host tools. 16 // This file is part of the eCos host tools.
16 // 17 //
17 // This program is free software; you can redistribute it and/or modify it 18 // This program is free software; you can redistribute it and/or modify it
18 // under the terms of the GNU General Public License as published by the Free 19 // under the terms of the GNU General Public License as published by the Free
161 // 162 //
162 // First some initial diagnostics are output immediately, in case 163 // First some initial diagnostics are output immediately, in case
163 // subsequent attempts to output more data cause additional failures. It 164 // subsequent attempts to output more data cause additional failures. It
164 // is worthwhile detecting recursive assertion failures. 165 // is worthwhile detecting recursive assertion failures.
165 // 166 //
166 // Assuming the table of callbacks is not empty it is possible to output 167 // Assuming the table of callbacks is not empty it is possible to
167 // some more data to a file. The tmpnam() function is used to get a filename. 168 // output some more data to a file. If possible mkstemp() is used to
168 // The file is opened and the callbacks are invoked. Three utilities have to 169 // create this file. If mkstemp() is not available then tmpnam() is
169 // be provided to do the real work, and a static is used to keep track of the 170 // used instead. That function has security problems, albeit not ones
170 // FILE * pointer. 171 // likely to affect dump files. Once the file is opened the callbacks
172 // are invoked. Three utilities have to be provided to do the real
173 // work, and a static is used to keep track of the FILE * pointer.
171 // 174 //
172 // The testcase tassert8, and in particular the associated Tcl proc 175 // The testcase tassert8, and in particular the associated Tcl proc
173 // tassert8_filter in testsuite/cyginfra/assert.exp, has detailed 176 // tassert8_filter in testsuite/cyginfra/assert.exp, has detailed
174 // knowledge of the output format. Any changes here may need to be 177 // knowledge of the output format. Any changes here may need to be
175 // reflected in that test case. There are also support routines in 178 // reflected in that test case. There are also support routines in
239 if (0 != fn) 242 if (0 != fn)
240 fprintf(stderr, "Function %s\n", fn); 243 fprintf(stderr, "Function %s\n", fn);
241 244
242 // Only create a logfile if more information is available. 245 // Only create a logfile if more information is available.
243 if (0 != callbacks.size() ) { 246 if (0 != callbacks.size() ) {
247
248 // Use mkstemp() if possible, but only when running on a platform where /tmp
249 // is likely to be available.
250 #if defined(HAVE_MKSTEMP) && !defined(_MSC_VER)
251 char filename[32];
252 int fd;
253 strcpy(filename, "/tmp/ecosdump.XXXXXX");
254 fd = mkstemp(filename);
255 if (-1 == fd) {
256 fprintf(stderr, "Unable to create a suitable output file for additional data.\n");
257 } else {
258 default_handler_output_file = fdopen(fd, "w");
259 if (0 == default_handler_output_file) {
260 close(fd);
261 }
262 }
263 #else
244 char filename[L_tmpnam]; 264 char filename[L_tmpnam];
245 if (0 == tmpnam(filename)) { 265 if (0 == tmpnam(filename)) {
246 fprintf(stderr, "Unable to create a suitable output file for additional data.\n"); 266 fprintf(stderr, "Unable to create a suitable output file for additional data.\n");
247 } else { 267 } else {
248 268
249 // No attempt is made to ensure that the file does not already 269 // No attempt is made to ensure that the file does not already
250 // exist. This would require POSIX calls rather than ISO C ones. 270 // exist. This would require POSIX calls rather than ISO C ones.
251 // The probability of a problem is considered to be too small 271 // The probability of a problem is considered to be too small
252 // to worry about. 272 // to worry about.
253 default_handler_output_file = fopen(filename, "w"); 273 default_handler_output_file = fopen(filename, "w");
254 if (0 == default_handler_output_file) { 274 }
255 fprintf(stderr, "Unable to open output file %s\n", filename); 275 #endif
256 fputs("No further assertion information is available.\n", stderr); 276 if (0 == default_handler_output_file) {
257 } else { 277 fprintf(stderr, "Unable to open output file %s\n", filename);
258 fprintf(stderr, "Writing additional output to %s\n", filename); 278 fputs("No further assertion information is available.\n", stderr);
279 } else {
280 fprintf(stderr, "Writing additional output to %s\n", filename);
259 281
260 // Repeat the information about the assertion itself. 282 // Repeat the information about the assertion itself.
261 fprintf(default_handler_output_file, "Assertion failure: %s\n", msg); 283 fprintf(default_handler_output_file, "Assertion failure: %s\n", msg);
262 fprintf(default_handler_output_file, "File %s, line number %lu\n", file, (unsigned long) lineno); 284 fprintf(default_handler_output_file, "File %s, line number %lu\n", file, (unsigned long) lineno);
263 if (0 != fn) 285 if (0 != fn)
264 fprintf(default_handler_output_file, "Function %s\n", fn); 286 fprintf(default_handler_output_file, "Function %s\n", fn);
265 fputs("\n", default_handler_output_file); 287 fputs("\n", default_handler_output_file);
266 288
267 // Now for the various callbacks. 289 // Now for the various callbacks.
268 cyg_assert_failure_invoke_callbacks( &default_handler_first_fn, 290 cyg_assert_failure_invoke_callbacks( &default_handler_first_fn,
269 &default_handler_second_fn, &default_handler_final_fn ); 291 &default_handler_second_fn, &default_handler_final_fn );
270 292
271 // And close the file. 293 // And close the file.
272 fputs("\nEnd of assertion data.\n", default_handler_output_file); 294 fputs("\nEnd of assertion data.\n", default_handler_output_file);
273 fclose(default_handler_output_file); 295 fclose(default_handler_output_file);
274 }
275 } 296 }
276 } 297 }
277 fflush(stderr); 298 fflush(stderr);
278 } 299 }
279 300