/* * Helping functions */ void surf_parse_error(const char *fmt, ...) { va_list va; va_start(va,fmt); char *msg = bvprintf(fmt,va); va_end(va); xbt_die("Parse error at %s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg); }
void surf_parse_warn(const char *fmt, ...) { va_list va; va_start(va,fmt); char *msg = bvprintf(fmt,va); va_end(va); XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg); free(msg); }
static int __cdecl bprintf(BPRINT_BUFFER & bp, LPCTSTR pszFormat, ...) { va_list va; va_start(va, pszFormat); int cch = bvprintf(bp, pszFormat, va); va_end(va); return cch; }
static void __cdecl bprintfl(BPRINT_BUFFER & bp, LPCTSTR pszFormat, ...) { va_list va; va_start(va, pszFormat); int cch = bvprintf(bp, pszFormat, va); va_end(va); bprint_EndLine(bp); }
char *bprintf(const char *fmt, ...) { va_list ap; va_start(ap, fmt); char *res = bvprintf(fmt, ap); va_end(ap); return res; }
void surf_parse_error(const char *fmt, ...) { va_list va; va_start(va,fmt); int lineno = surf_parse_lineno; char *msg = bvprintf(fmt,va); va_end(va); cleanup(); XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg); surf_exit(); xbt_die("Exiting now"); }
void printf(const char *fmt, ...) { ASSERT32FLAT(); va_list args; va_start(args, fmt); bvprintf(&screeninfo, fmt, args); va_end(args); if (ScreenAndDebug) debug_serial_flush(); }
void panic(const char *fmt, ...) { if (CONFIG_DEBUG_LEVEL) { va_list args; va_start(args, fmt); bvprintf(&debuginfo, fmt, args); va_end(args); debug_serial_flush(); } // XXX - use PANIC PORT. irq_disable(); for (;;) hlt(); }
static int __cdecl dprintf(int flags, LPCTSTR pszFormat, ...) { if (!(DebugFlags & flags)) return 0; va_list va; va_start(va, pszFormat); int cch = bvprintf(g_bprint, pszFormat, va); va_end(va); // if this string ended in \n, flush the bprint buffer. if (g_bprint.cch > 0 && g_bprint.psz[g_bprint.cch-1] == _UT('\n')) bprint_Write(); return cch; }
void __dprintf(const char *fmt, ...) { if (!MODESEGMENT && CONFIG_THREADS && CONFIG_DEBUG_LEVEL >= DEBUG_thread && *fmt != '\\' && *fmt != '/') { struct thread_info *cur = getCurThread(); if (cur != &MainThread) { // Show "thread id" for this debug message. putc_debug(&debuginfo, '|'); puthex(&debuginfo, (u32)cur, 8); putc_debug(&debuginfo, '|'); putc_debug(&debuginfo, ' '); } } va_list args; va_start(args, fmt); bvprintf(&debuginfo, fmt, args); va_end(args); debug_serial_flush(); }
static void xbt_log_layout_format_dynamic(xbt_log_layout_t l, xbt_log_event_t ev, const char *fmt, xbt_log_appender_t app) { xbt_strbuff_t buff = xbt_strbuff_new(); char tmpfmt[50]; int precision = -1; int length = -1; char *q = l->data; char *tmp; char *tmp2; while (*q != '\0') { if (*q == '%') { q++; handle_modifier: switch (*q) { case '\0': fprintf(stderr, "Layout format (%s) ending with %%\n", (char *) l->data); abort(); case '%': xbt_strbuff_append(buff, "%"); break; case 'n': /* platform-dependant line separator (LOG4J compliant) */ xbt_strbuff_append(buff, "\n"); break; case 'e': /* plain space (SimGrid extension) */ xbt_strbuff_append(buff, " "); break; case '.': /* precision specifyier */ q++; sscanf(q, "%d", &precision); q += (precision>9?2:1); goto handle_modifier; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* length modifier */ sscanf(q, "%d", &length); q += (length>9?2:1); goto handle_modifier; case 'c': /* category name; LOG4J compliant should accept a precision postfix to show the hierarchy */ append_string(ev->cat->name); break; case 'p': /* priority name; LOG4J compliant */ append_string(xbt_log_priority_names[ev->priority]); break; case 'h': /* host name; SimGrid extension */ append_string(gras_os_myname()); break; case 't': /* thread name; LOG4J compliant */ append_string(xbt_thread_self_name()); break; case 'P': /* process name; SimGrid extension */ append_string(xbt_procname()); break; case 'i': /* process PID name; SimGrid extension */ append_int((*xbt_getpid) ()); break; case 'F': /* file name; LOG4J compliant */ append_string(ev->fileName); break; case 'l': /* location; LOG4J compliant */ append2("%s:%d", ev->fileName, ev->lineNum); precision = -1; /* Ignored */ break; case 'L': /* line number; LOG4J compliant */ append_int(ev->lineNum); break; case 'M': /* method (ie, function) name; LOG4J compliant */ append_string(ev->functionName); break; case 'b': /* backtrace; called %throwable in LOG4J */ case 'B': /* short backtrace; called %throwable{short} in LOG4J */ #if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE) { xbt_ex_t e; int i; e.used = backtrace((void **) e.bt, XBT_BACKTRACE_SIZE); e.bt_strings = NULL; e.msg = NULL; e.remote = 0; xbt_backtrace_current(&e); if (*q == 'B') { append_string(e.bt_strings[2] + 8); } else { for (i = 2; i < e.used; i++) { append_string(e.bt_strings[i] + 8); xbt_strbuff_append(buff, "\n"); } } xbt_ex_free(e); } #else append_string("(no backtrace on this arch)"); #endif break; case 'd': /* date; LOG4J compliant */ append_double(gras_os_time()); break; case 'r': /* application age; LOG4J compliant */ append_double(gras_os_time() - format_begin_of_time); break; case 'm': /* user-provided message; LOG4J compliant */ tmp2 = bvprintf(fmt, ev->ap_copy); append_string(tmp2); free(tmp2); break; default: fprintf(stderr, ERRMSG, *q, (char *) l->data); abort(); } q++; } else { char tmp2[2]; tmp2[0] = *(q++); tmp2[1] = '\0'; xbt_strbuff_append(buff, tmp2); } } app->do_append(app, buff->data); xbt_strbuff_free(buff); }