📄 bug_conf.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/bug_conf.c,v 1.3 2003/01/15 14:04:30 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** * Copyright 1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* Run-time configuration of the BUG() macro and friends. *//* * $Log: bug_conf.c,v $ * Revision 1.3 2003/01/15 14:04:30 josh * directory structure shifting * * Revision 1.2 2001/11/08 15:56:20 tneale * Updated for newest file layout * * Revision 1.1.1.1 2001/11/05 17:48:41 tneale * Tornado shuffle * * Revision 1.21 2001/01/19 22:23:39 paul * Update copyright. * * Revision 1.20 2000/10/16 19:21:49 paul * Restore sockets and mempool code. * * Revision 1.19 2000/03/17 00:12:37 meister * Update copyright message * * Revision 1.18 2000/03/13 21:22:04 paul * Removed some code that we are no longer working on. * * Revision 1.17 1999/04/26 19:04:59 sra * Fix a few minor warnings, fix a few Solaris-specific problems in the * demo code. * * Revision 1.16 1999/02/19 22:16:52 wes * Silence a format warning * * Revision 1.15 1999/02/18 04:41:32 wes * Sockets merge: Everything Else * - memory pools * - thread support * - port-specific headers * * Revision 1.14.8.4 1999/01/04 20:54:32 wes * Use reentrant localtime_r if threaded on UNIX * * Revision 1.14.8.3 1998/11/13 18:17:23 wes * Make SNARK_*LOCK*() calls into the "real" attache global lock * ATTACHE_*LOCK*() and make it live in attache-land, not snark-land. * * Revision 1.14.8.2 1998/10/01 21:45:22 wes * sockets port: add new configurable bug action: yield the processor * * Revision 1.14.8.1 1998/09/23 19:17:17 wes * Merge socket-branch-1 changes to socket-branch-2 * * Revision 1.14.6.1 1998/08/19 13:26:25 wes * Merge sockets-pthreads work to shared branch * * Revision 1.14.2.1 1998/08/05 20:48:49 wes * XXX: Deal with mit-pthreads header file dane brammage * * Revision 1.14 1998/07/02 06:55:35 sra * Make Snark restartable under pSOS, and other minor cleanups. * * Revision 1.13 1998/02/25 15:21:47 sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 1.12 1998/02/25 04:57:23 sra * Update copyrights. * * Revision 1.11 1997/05/15 07:54:06 sra * Add IDENT option. * * Revision 1.10 1997/04/15 06:05:31 sra * Fix bug_timestamp(). * * Revision 1.9 1997/03/20 06:52:50 sra * DFARS-safe copyright text. Zap! * * Revision 1.8 1997/03/19 22:05:28 sra * Perhaps we should include install.h before testing install options? * * Revision 1.7 1997/03/19 20:20:06 sra * Remove gratuitous Attache dependencies. * * Revision 1.6 1997/03/19 04:47:35 sra * Get rid of some gratuitous historical dependencies on Attache. * * Revision 1.5 1997/03/19 04:11:35 sra * BUG() now common to all products, so move the associated .h files. * * Revision 1.4 1997/03/09 18:38:00 sra * Track changes in keyword module. * * Revision 1.3 1997/02/25 08:14:25 sra * Fiddle bug_timestamp(). * * Revision 1.2 1997/02/24 00:56:59 sra * Support for run-time configuration of BUG() macros. * * Revision 1.1 1997/02/23 21:56:22 sra * Initial revision * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*/#include <stdio.h>#include <stddef.h>#include <stdlib.h>#include <wrn/wm/common/install.h>#if INSTALL_ATTACHE_THREADS#include <wrn/wm/attache/attthd.h>#endif#include <wrn/wm/demo/snarklib.h>#include <wrn/wm/demo/read_ini.h>static struct bug_table { char *name; enum bug_codes code;} bugtab[] = {#define BUGDEF(x) { #x , x },#include <wrn/wm/common/bugdef.h>#undef BUGDEF};static struct keyword_table bug_keywords;unsigned bug_flags[sizeof(bugtab)/sizeof(*bugtab)]; int bug_breakpoint(enum bug_codes code, void *cookie, int fatal){ return fatal;}/* * This really ought to use the Attache time service * and POSIX functions, but it's a pain to do right * and this is just noncritical debugging code anyway. * Fix later. */#ifdef INSTALL_on_unix#include <time.h>#include <sys/time.h>#if defined(__NetBSD__) && defined(INSTALL_ATTACHE_THREADS)/* !!! mit_pthreads strftime() prototype is inexplicably commented out */size_t strftime __P((char *, size_t, const char *, const struct tm *));#endifvoid bug_timestamp(struct sty *sty){ char ts[30]; struct timeval tv; struct tm *tm;#if INSTALL_ATTACHE_THREADS struct tm tms;#endif /* * time-related functions appear to have races on Solaris. */ gettimeofday(&tv, 0);#if INSTALL_ATTACHE_THREADS tm = localtime_r(&tv.tv_sec, &tms);#else tm = localtime(&tv.tv_sec);#endif strftime(ts, sizeof(ts), "%H:%M:%S", tm); sty_printf(sty, "%s.%06lu: ", ts, (unsigned long)tv.tv_usec);}#else /* INSTALL_on_unix */void bug_timestamp(struct sty *sty){ unsigned long now = GLUE_NOW(); /* sic */ sty_printf(sty, "%lu.%03lu: ", now / 1000, now % 1000);}#endif /* INSTALL_on_unix */void bug_yield(enum bug_codes code, char *file, int line){#if INSTALL_ATTACHE_THREADS ETC_THD_YIELD();#endif }static void bug_config_1(struct ini_handle *ini_handle, char *name, unsigned flag){ static char snark_section[] = "etc snark bug"; struct bug_table *t; char *s; int i; for (s = ini_iter_start(ini_handle, snark_section, name); s; s = ini_iter_next(ini_handle)) if (s[0] == '*' && s[1] == '\0') for (i = 0; i < sizeof(bugtab)/sizeof(*bugtab); i++) bug_flags[i] ^= flag; else if ((t = keyword_find(&bug_keywords, s)) != 0) bug_flags[(int) (t->code)] ^= flag; else fprintf(stderr, "%% [%s] %s: Unknown bug name \"%s\"\n", snark_section, name, s);}void bug_config(void){ struct ini_handle *ini_handle = ini_open(256); KEYWORD_INIT(&bug_keywords, bugtab); bug_config_1(ini_handle, "print", BUG_FLAG_PRINT); bug_config_1(ini_handle, "break", BUG_FLAG_BREAK); bug_config_1(ini_handle, "fatal", BUG_FLAG_FATAL); bug_config_1(ini_handle, "ident", BUG_FLAG_IDENT); bug_config_1(ini_handle, "yield", BUG_FLAG_YIELD); ini_close(ini_handle);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -