void v4pDisplayDebug(char *formatString, ...) { va_list args ; char text[0x100] ; va_start(args, formatString) ; vprintf(formatString, args) ; va_end(args); }
static int __show_message(enum msg_type flag, const char *string, va_list ap) { // _ShowMessage MUST be used instead of printf as of 10/24/2004. // Return: 0 = Successful, 1 = Failed. // int ret = 0; char prefix[40]; if (!string || strlen(string) <= 0) { printf("Empty string passed to _ShowMessage().\n"); return 1; } switch (flag) { case MSG_NONE: // direct printf replacement break; case MSG_STATUS: //Bright Green (To inform about good things) strcpy(prefix,CL_GREEN"[Status]"CL_RESET":"); break; case MSG_SQL: //Bright Violet (For dumping out anything related with SQL) strcpy(prefix,CL_MAGENTA"[SQL]"CL_RESET":"); break; case MSG_FATAL: //Bright Red (Fatal errors, abort(); if possible) strcpy(prefix,CL_RED"[Fatal Error]"CL_RESET":"); break; case MSG_ERROR: //Bright Red (Regular errors) strcpy(prefix,CL_RED"[Error]"CL_RESET":"); break; case MSG_WARN: //Bright Yellow strcpy(prefix,CL_YELLOW"[Warning]"CL_RESET":"); break; case MSG_NOTICE: //Bright White (Less than a warning) strcpy(prefix,CL_WHITE"[Notice]"CL_RESET":"); break; case MSG_INFO: //Bright White (Variable information) strcpy(prefix,CL_WHITE"[Info]"CL_RESET":"); break; case MSG_DEBUG: //Bright Cyan, important stuff! strcpy(prefix,CL_CYAN"[Debug]"CL_RESET":"); break; default: printf("In function _ShowMessage() -> Invalid flag passed.\n"); return 1; } if (flag <= msglevel) { if (flag != MSG_NONE) printf ("%s ", prefix); vprintf (string, ap); fflush (stdout); } va_end(ap); /* if ((core_config.debug_output_level > -1) && (flag >= core_config.debug_output_level)) { FILE *fp; fp=fopen(OUTPUT_MESSAGES_LOG,"a"); if (fp == NULL) { printf(CL_RED"[Error]"CL_RESET": Could not open '"CL_WHITE"%s"CL_RESET"', file not found.\n",OUTPUT_MESSAGES_LOG); fflush(stdout); return; } StripColor(output); strcpy(output,"\r"); fwrite(output,strlen(output),1,fp); fclose(fp); } */ return 0; }
void mk_utils_trace(const char *component, int color, const char *function, char *file, int line, const char* format, ...) { va_list args; char *color_function = NULL; char *color_fileline = NULL; char *color_component = NULL; char *reset_color = ANSI_RESET; char *magenta_color = ANSI_RESET ANSI_BOLD_MAGENTA; char *red_color = ANSI_RESET ANSI_BOLD_RED; char *cyan_color = ANSI_RESET ANSI_CYAN; struct timeval tv; struct timezone tz; if (env_trace_filter) { if (!strstr(env_trace_filter, file)) { return; } } /* Mutex lock */ pthread_mutex_lock(&mutex_trace); gettimeofday(&tv, &tz); /* Switch message color */ char* bgcolortype = mk_utils_getenv("MK_TRACE_BACKGROUND"); if (!bgcolortype) { bgcolortype = "dark"; } if (!strcmp(bgcolortype, "light")) { switch(color) { case MK_TRACE_CORE: color_component = ANSI_BOLD_GREEN; color_function = ANSI_BOLD_MAGENTA; color_fileline = ANSI_GREEN; break; case MK_TRACE_PLUGIN: color_component = ANSI_BOLD_GREEN; color_function = ANSI_BLUE; color_fileline = ANSI_GREEN; break; } } else { /* covering 'dark' and garbage values defaulting to 'dark' cases */ switch(color) { case MK_TRACE_CORE: color_component = ANSI_BOLD_GREEN; color_function = ANSI_YELLOW; color_fileline = ANSI_BOLD_WHITE; break; case MK_TRACE_PLUGIN: color_component = ANSI_BOLD_BLUE; color_function = ANSI_BLUE; color_fileline = ANSI_BOLD_WHITE; break; } } /* Only print colors to a terminal */ if (!isatty(STDOUT_FILENO)) { color_function = ""; color_fileline = ""; reset_color = ""; magenta_color = ""; red_color = ""; cyan_color = ""; } va_start( args, format ); printf("~ %s%2lu.%lu%s %s[%s%s%s|%s:%-3i%s] %s%s()%s ", cyan_color, (tv.tv_sec - monkey_init_time), tv.tv_usec, reset_color, magenta_color, color_component, component, color_fileline, file, line, magenta_color, color_function, function, red_color); vprintf(format, args ); va_end(args); printf("%s\n", reset_color); fflush(stdout); /* Mutex unlock */ pthread_mutex_unlock(&mutex_trace); }
static void conf_default_message_callback(const char *fmt, va_list ap) { printf("#\n# "); vprintf(fmt, ap); printf("\n#\n"); }
static void vsim_info_cont(const char fmt[], va_list ap) { if (verbose < 1) return; fgreen(); vprintf(fmt, ap); fbreset(); }
void Sys_VPrintf(const char *msg, va_list arg) { tty_Hide(); vprintf(msg, arg); tty_Show(); }
void setLogFile(const char *fileName) { if (fileName == NULL) { return; } if (strlen(fileName) == 0) { return; } if (strlen(fileName) > MAX_LOG_FILE_NAME_LEN - 1) { printf("too long file name:%d\n",strlen(fileName)); return; } { FILE *f = NULL; #if __IS_WIN__ if ((fopen_s(&f,fileName,"rw")) != 0) { #else if ((f = fopen(fileName,"rw")) == NULL) { #endif printf("open log file [%s] error\n",fileName); return; } fclose(f); #if __IS_WIN__ strncpy_s(logFileName,MAX_LOG_FILE_NAME_LEN,fileName,strlen(fileName)); #else strncpy(logFileName,fileName,MAX_LOG_FILE_NAME_LEN); #endif } } void printLog(char* sModule, int nLogLevel, char *sFile,int nLine,char *fmt, ...) { struct tm newTimeST; #if __IS_WIN__ DWORD nThreadID; #else unsigned int nThreadID; #endif struct tm *newtime = &newTimeST; time_t aclock; FILE *logFile = NULL; va_list ap1, ap2;; if (nLogLevel < 1 || nLogLevel > COUNT_ERROR_LEVEL) { printf("error log level:%d\n",nLogLevel); return; } if (nLogLevel > logLevel) { return; } time( &aclock ); #if __IS_WIN__ localtime_s(newtime, &aclock ); nThreadID = GetCurrentProcessId(); nThreadID = (nThreadID << 16) + GetCurrentThreadId(); #else newtime = localtime( &aclock ); nThreadID = getpid(); nThreadID = (nThreadID << 16) + pthread_self(); #endif if (strlen(logFileName) > 0) { #if __IS_WIN__ if ((fopen_s(&logFile,logFileName,"rb+")) != 0) { #else if ((logFile = fopen(logFileName,"rb+")) == NULL) { #endif printf("open log file [%s] error\n",logFileName); } } printf("\n[%4d-%02d-%02d %02d:%02d:%02d][%s][%ud][%s:%d][%s] ", newtime->tm_year+1900,newtime->tm_mon+1,newtime->tm_mday,newtime->tm_hour, newtime->tm_min,newtime->tm_sec,sModule,nThreadID,sFile,nLine,errorLevel[nLogLevel-1]); va_start(ap1, fmt); if (logFile != NULL) { #if __IS_WIN__ ap2 = ap1; #else va_copy(ap2, ap1); #endif vfprintf(logFile,fmt,ap2); } vprintf(fmt,ap1); if (logFile != NULL) { va_end(ap2); } va_end(ap1); } int errorReturn(int errorCode,char *tag,char *msg) { LOG_WITH_TAG(LEVEL_ERROR,tag,errorCode,msg); return errorCode; }
void ath_hal_vprintf(struct ath_hal *ah, const char* fmt, va_list ap) { vprintf(fmt, ap); }
int printf(const char *format, ...) { va_list va; va_start(va, format); return vprintf(format, va); }
/* * for GalUtil_PInfo1, GalUtil_PInfo2, GalUtil_Debug1, GalUtil_Debug2 */ static void printf_info(const char *format, va_list args, void *client_data) { vprintf(format, args); fflush(stdout); }
void VFLogv(const char* format, va_list args) { vprintf(format, args); }
void LocalConsole::Write(const char * Format, ...) { va_list ap; va_start(ap, Format); vprintf(Format, ap); }
void nandsim_log(struct nandsim_chip *chip, int level, const char *fmt, ...) { char hdr[TIME_STR_SIZE]; char tmp[NANDSIM_ENTRY_SIZE]; struct nandsim_softc *sc; struct timeval currtime; va_list ap; int hdr_len, len, rest; if (nandsim_log_output == NANDSIM_OUTPUT_NONE) return; if (chip == NULL) return; sc = chip->sc; if (!sc->alq && nandsim_log_output == NANDSIM_OUTPUT_FILE) return; if (level <= nandsim_log_level) { microtime(&currtime); hdr_len = sprintf(hdr, "%08jd.%08li [chip:%d, ctrl:%d]: ", (intmax_t)currtime.tv_sec, currtime.tv_usec, chip->chip_num, chip->ctrl_num); switch(nandsim_log_output) { case NANDSIM_OUTPUT_CONSOLE: printf("%s", hdr); va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); break; case NANDSIM_OUTPUT_RAM: va_start(ap, fmt); len = vsnprintf(tmp, NANDSIM_ENTRY_SIZE - 1, fmt, ap); tmp[NANDSIM_ENTRY_SIZE - 1] = 0; va_end(ap); rest = log_size - sc->log_idx - 1; if (rest >= hdr_len) { bcopy(hdr, &sc->log_buff[sc->log_idx], hdr_len); sc->log_idx += hdr_len; sc->log_buff[sc->log_idx] = 0; } else { bcopy(hdr, &sc->log_buff[sc->log_idx], rest); bcopy(&hdr[rest], sc->log_buff, hdr_len - rest); sc->log_idx = hdr_len - rest; sc->log_buff[sc->log_idx] = 0; } rest = log_size - sc->log_idx - 1; if (rest >= len) { bcopy(tmp, &sc->log_buff[sc->log_idx], len); sc->log_idx += len; sc->log_buff[sc->log_idx] = 0; } else { bcopy(tmp, &sc->log_buff[sc->log_idx], rest); bcopy(&tmp[rest], sc->log_buff, len - rest); sc->log_idx = len - rest; sc->log_buff[sc->log_idx] = 0; } break; case NANDSIM_OUTPUT_FILE: va_start(ap, fmt); len = vsnprintf(tmp, NANDSIM_ENTRY_SIZE - 1, fmt, ap); tmp[NANDSIM_ENTRY_SIZE - 1] = 0; va_end(ap); rest = NANDSIM_ENTRY_SIZE - str_index; if (rest >= hdr_len) { strcat(string, hdr); str_index += hdr_len; } else { strlcat(string, hdr, NANDSIM_ENTRY_SIZE + 1); alq_write(sc->alq, (void *) string, ALQ_NOWAIT); strcpy(string, &hdr[rest]); str_index = hdr_len - rest; } rest = NANDSIM_ENTRY_SIZE - str_index; if (rest >= len) { strcat(string, tmp); str_index += len; } else { strlcat(string, tmp, NANDSIM_ENTRY_SIZE + 1); alq_write(sc->alq, (void *) string, ALQ_NOWAIT); strcpy(string, &tmp[rest]); str_index = len - rest; } break; default: break; } } }
void panicsys(const char *format, va_list alist, struct regs *rp, int on_panic_stack) { int s = spl8(); kthread_t *t = curthread; cpu_t *cp = CPU; caddr_t intr_stack = NULL; uint_t intr_actv; ushort_t schedflag = t->t_schedflag; cpu_t *bound_cpu = t->t_bound_cpu; char preempt = t->t_preempt; (void) setjmp(&t->t_pcb); t->t_flag |= T_PANIC; t->t_schedflag |= TS_DONT_SWAP; t->t_bound_cpu = cp; t->t_preempt++; /* * Switch lbolt to event driven mode. */ lbolt_hybrid = lbolt_event_driven; panic_enter_hw(s); /* * If we're on the interrupt stack and an interrupt thread is available * in this CPU's pool, preserve the interrupt stack by detaching an * interrupt thread and making its stack the intr_stack. */ if (CPU_ON_INTR(cp) && cp->cpu_intr_thread != NULL) { kthread_t *it = cp->cpu_intr_thread; intr_stack = cp->cpu_intr_stack; intr_actv = cp->cpu_intr_actv; cp->cpu_intr_stack = thread_stk_init(it->t_stk); cp->cpu_intr_thread = it->t_link; /* * Clear only the high level bits of cpu_intr_actv. * We want to indicate that high-level interrupts are * not active without destroying the low-level interrupt * information stored there. */ cp->cpu_intr_actv &= ((1 << (LOCK_LEVEL + 1)) - 1); } /* * Record one-time panic information and quiesce the other CPUs. * Then print out the panic message and stack trace. */ if (on_panic_stack) { panic_data_t *pdp = (panic_data_t *)panicbuf; pdp->pd_version = PANICBUFVERS; pdp->pd_msgoff = sizeof (panic_data_t) - sizeof (panic_nv_t); if (t->t_panic_trap != NULL) panic_savetrap(pdp, t->t_panic_trap); else panic_saveregs(pdp, rp); (void) vsnprintf(&panicbuf[pdp->pd_msgoff], PANICBUFSIZE - pdp->pd_msgoff, format, alist); /* * Call into the platform code to stop the other CPUs. * We currently have all interrupts blocked, and expect that * the platform code will lower ipl only as far as needed to * perform cross-calls, and will acquire as *few* locks as is * possible -- panicstr is not set so we can still deadlock. */ panic_stopcpus(cp, t, s); panicstr = (char *)format; va_copy(panicargs, alist); panic_lbolt = LBOLT_NO_ACCOUNT; panic_lbolt64 = LBOLT_NO_ACCOUNT64; panic_hrestime = hrestime; panic_hrtime = gethrtime_waitfree(); panic_thread = t; panic_regs = t->t_pcb; panic_reg = rp; panic_cpu = *cp; panic_ipl = spltoipl(s); panic_schedflag = schedflag; panic_bound_cpu = bound_cpu; panic_preempt = preempt; if (intr_stack != NULL) { panic_cpu.cpu_intr_stack = intr_stack; panic_cpu.cpu_intr_actv = intr_actv; } /* * Lower ipl to 10 to keep clock() from running, but allow * keyboard interrupts to enter the debugger. These callbacks * are executed with panicstr set so they can bypass locks. */ splx(ipltospl(CLOCK_LEVEL)); panic_quiesce_hw(pdp); (void) FTRACE_STOP(); (void) callb_execute_class(CB_CL_PANIC, NULL); if (log_intrq != NULL) log_flushq(log_intrq); /* * If log_consq has been initialized and syslogd has started, * print any messages in log_consq that haven't been consumed. */ if (log_consq != NULL && log_consq != log_backlogq) log_printq(log_consq); fm_banner(); #if defined(__x86) /* * A hypervisor panic originates outside of Solaris, so we * don't want to prepend the panic message with misleading * pointers from within Solaris. */ if (!IN_XPV_PANIC()) #endif printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id, (void *)t); vprintf(format, alist); printf("\n\n"); if (t->t_panic_trap != NULL) { panic_showtrap(t->t_panic_trap); printf("\n"); } traceregs(rp); printf("\n"); if (((boothowto & RB_DEBUG) || obpdebug) && !nopanicdebug && !panic_forced) { if (dumpvp != NULL) { debug_enter("panic: entering debugger " "(continue to save dump)"); } else { debug_enter("panic: entering debugger " "(no dump device, continue to reboot)"); } } } else if (panic_dump != 0 || panic_sync != 0 || panicstr != NULL) { printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id, (void *)t); vprintf(format, alist); printf("\n"); } else goto spin; /* * Prior to performing sync or dump, we make sure that do_polled_io is * set, but we'll leave ipl at 10; deadman(), a CY_HIGH_LEVEL cyclic, * will re-enter panic if we are not making progress with sync or dump. */ /* * Sync the filesystems. Reset t_cred if not set because much of * the filesystem code depends on CRED() being valid. */ if (!in_sync && panic_trigger(&panic_sync)) { if (t->t_cred == NULL) t->t_cred = kcred; splx(ipltospl(CLOCK_LEVEL)); do_polled_io = 1; vfs_syncall(); } /* * Take the crash dump. If the dump trigger is already set, try to * enter the debugger again before rebooting the system. */ if (panic_trigger(&panic_dump)) { panic_dump_hw(s); splx(ipltospl(CLOCK_LEVEL)); errorq_panic(); do_polled_io = 1; dumpsys(); } else if (((boothowto & RB_DEBUG) || obpdebug) && !nopanicdebug) { debug_enter("panic: entering debugger (continue to reboot)"); } else printf("dump aborted: please record the above information!\n"); if (halt_on_panic) mdboot(A_REBOOT, AD_HALT, NULL, B_FALSE); else mdboot(A_REBOOT, panic_bootfcn, panic_bootstr, B_FALSE); spin: /* * Restore ipl to at most CLOCK_LEVEL so we don't end up spinning * and unable to jump into the debugger. */ splx(MIN(s, ipltospl(CLOCK_LEVEL))); for (;;) ; }
/* * Initialize a symbol table from a file */ void initsymtable(char *filename) { char *base; long tblsize; struct entry *ep; struct entry *baseep, *lep; struct symtableheader hdr; struct stat stbuf; long i; int fd; vprintf(stdout, "Initialize symbol table.\n"); if (filename == NULL) { entrytblsize = maxino / HASHFACTOR; entry = (struct entry **) calloc((unsigned)entrytblsize, sizeof(struct entry *)); if (entry == (struct entry **)NULL) panic("no memory for entry table\n"); ep = addentry(".", ROOTINO, NODE); ep->e_flags |= NEW; return; } if ((fd = open(filename, O_RDONLY, 0)) < 0) { fprintf(stderr, "open: %s\n", strerror(errno)); panic("cannot open symbol table file %s\n", filename); } if (fstat(fd, &stbuf) < 0) { fprintf(stderr, "stat: %s\n", strerror(errno)); panic("cannot stat symbol table file %s\n", filename); } tblsize = stbuf.st_size - sizeof(struct symtableheader); base = calloc(sizeof(char), (unsigned)tblsize); if (base == NULL) panic("cannot allocate space for symbol table\n"); if (read(fd, base, (int)tblsize) < 0 || read(fd, (char *)&hdr, sizeof(struct symtableheader)) < 0) { fprintf(stderr, "read: %s\n", strerror(errno)); panic("cannot read symbol table file %s\n", filename); } switch (command) { case 'r': /* * For normal continuation, insure that we are using * the next incremental tape */ if (hdr.dumpdate != dumptime) { if (hdr.dumpdate < dumptime) fprintf(stderr, "Incremental tape too low\n"); else fprintf(stderr, "Incremental tape too high\n"); done(1); } break; case 'R': /* * For restart, insure that we are using the same tape */ curfile.action = SKIP; dumptime = hdr.dumptime; dumpdate = hdr.dumpdate; if (!bflag) newtapebuf(hdr.ntrec); getvol(hdr.volno); break; default: panic("initsymtable called from command %c\n", command); break; } maxino = hdr.maxino; entrytblsize = hdr.entrytblsize; entry = (struct entry **) (base + tblsize - (entrytblsize * sizeof(struct entry *))); baseep = (struct entry *)(base + hdr.stringsize - sizeof(struct entry)); lep = (struct entry *)entry; for (i = 0; i < entrytblsize; i++) { if (entry[i] == NULL) continue; entry[i] = &baseep[(long)entry[i]]; } for (ep = &baseep[1]; ep < lep; ep++) { ep->e_name = base + (long)ep->e_name; ep->e_parent = &baseep[(long)ep->e_parent]; if (ep->e_sibling != NULL) ep->e_sibling = &baseep[(long)ep->e_sibling]; if (ep->e_links != NULL) ep->e_links = &baseep[(long)ep->e_links]; if (ep->e_entries != NULL) ep->e_entries = &baseep[(long)ep->e_entries]; if (ep->e_next != NULL) ep->e_next = &baseep[(long)ep->e_next]; } }
/* * Logs the given message to stdout (if print is true) while prefixing the * current time to it. Additionally, the message will be saved in the i3 SHM * log if enabled. * This is to be called by *LOG() which includes filename/linenumber/function. * */ static void vlog(const bool print, const char *fmt, va_list args) { /* Precisely one page to not consume too much memory but to hold enough * data to be useful. */ static char message[4096]; static struct tm result; static time_t t; static struct tm *tmp; static size_t len; /* Get current time */ t = time(NULL); /* Convert time to local time (determined by the locale) */ tmp = localtime_r(&t, &result); /* Generate time prefix */ len = strftime(message, sizeof(message), "%x %X - ", tmp); /* * logbuffer print * ---------------- * true true format message, save, print * true false format message, save * false true print message only * false false INVALID, never called */ if (!logbuffer) { #ifdef DEBUG_TIMING struct timeval tv; gettimeofday(&tv, NULL); printf("%s%d.%d - ", message, tv.tv_sec, tv.tv_usec); #else printf("%s", message); #endif vprintf(fmt, args); } else { len += vsnprintf(message + len, sizeof(message) - len, fmt, args); if (len >= sizeof(message)) { fprintf(stderr, "BUG: single log message > 4k\n"); /* vsnprintf returns the number of bytes that *would have been written*, * not the actual amount written. Thus, limit len to sizeof(message) to avoid * memory corruption and outputting garbage later. */ len = sizeof(message); /* Punch in a newline so the next log message is not dangling at * the end of the truncated message. */ message[len - 2] = '\n'; } /* If there is no space for the current message in the ringbuffer, we * need to wrap and write to the beginning again. */ if (len >= (size_t)(logbuffer_size - (logwalk - logbuffer))) { loglastwrap = logwalk; logwalk = logbuffer + sizeof(i3_shmlog_header); store_log_markers(); header->wrap_count++; } /* Copy the buffer, move the write pointer to the byte after our * current message. */ strncpy(logwalk, message, len); logwalk += len; store_log_markers(); #if !defined(__OpenBSD__) /* Wake up all (i3-dump-log) processes waiting for condvar. */ pthread_cond_broadcast(&(header->condvar)); #endif if (print) fwrite(message, len, 1, stdout); } }
void Sys_DebugVPrintf( const char *fmt, va_list arg ) { tty_Hide(); vprintf( fmt, arg ); tty_Show(); }
void msg(const char *fmt, ...) { va_list va; va_start(va, fmt); vprintf(fmt, va); va_end(va); }
void printf_wrapper(void *env, const char *fmt, ...) { va_list args; va_start(args, fmt); vprintf(fmt, args); va_end(args); }
void test1(va_list args) { vprintf("%d %f %ld %c %s %% %x %X %i\n", args); }
void vpanic(const char *fmt, va_list ap) { #ifdef SMP cpuset_t other_cpus; #endif struct thread *td = curthread; int bootopt, newpanic; static char buf[256]; spinlock_enter(); #ifdef SMP /* * stop_cpus_hard(other_cpus) should prevent multiple CPUs from * concurrently entering panic. Only the winner will proceed * further. */ if (panicstr == NULL && !kdb_active) { other_cpus = all_cpus; CPU_CLR(PCPU_GET(cpuid), &other_cpus); stop_cpus_hard(other_cpus); } /* * Ensure that the scheduler is stopped while panicking, even if panic * has been entered from kdb. */ td->td_stopsched = 1; #endif bootopt = RB_AUTOBOOT; newpanic = 0; if (panicstr) bootopt |= RB_NOSYNC; else { bootopt |= RB_DUMP; panicstr = fmt; newpanic = 1; } if (newpanic) { (void)vsnprintf(buf, sizeof(buf), fmt, ap); panicstr = buf; cngrab(); printf("panic: %s\n", buf); } else { printf("panic: "); vprintf(fmt, ap); printf("\n"); } #ifdef SMP printf("cpuid = %d\n", PCPU_GET(cpuid)); #endif #ifdef KDB if (newpanic && trace_on_panic) kdb_backtrace(); if (debugger_on_panic) kdb_enter(KDB_WHY_PANIC, "panic"); #endif /*thread_lock(td); */ td->td_flags |= TDF_INPANIC; /* thread_unlock(td); */ if (!sync_on_panic) bootopt |= RB_NOSYNC; kern_reboot(bootopt); }
void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap) { #if TARGET_OS_IPHONE static int asl_initialized = 0; #if !TARGET_IPHONE_SIMULATOR static aslclient asl_client; #endif #else FILE *fp = NULL; (void)fp; #endif if (!verbosity_is_enabled()) return; #if TARGET_OS_IPHONE #if TARGET_IPHONE_SIMULATOR vprintf(fmt, ap); #else if (!asl_initialized) { asl_client = asl_open(file_path_str(FILE_PATH_PROGRAM_NAME), "com.apple.console", ASL_OPT_STDERR | ASL_OPT_NO_DELAY); asl_initialized = 1; } aslmsg msg = asl_new(ASL_TYPE_MSG); asl_set(msg, ASL_KEY_READ_UID, "-1"); if (tag) asl_log(asl_client, msg, ASL_LEVEL_NOTICE, "%s", tag); asl_vlog(asl_client, msg, ASL_LEVEL_NOTICE, fmt, ap); asl_free(msg); #endif #elif defined(_XBOX1) /* FIXME: Using arbitrary string as fmt argument is unsafe. */ char msg_new[1024]; char buffer[1024]; msg_new[0] = buffer[0] = '\0'; snprintf(msg_new, sizeof(msg_new), "%s: %s %s", file_path_str(FILE_PATH_PROGRAM_NAME), tag ? tag : "", fmt); wvsprintf(buffer, msg_new, ap); OutputDebugStringA(buffer); #elif defined(ANDROID) int prio = ANDROID_LOG_INFO; if (tag) { if (string_is_equal(file_path_str(FILE_PATH_LOG_WARN), tag)) prio = ANDROID_LOG_WARN; else if (string_is_equal(file_path_str(FILE_PATH_LOG_ERROR), tag)) prio = ANDROID_LOG_ERROR; } __android_log_vprint(prio, file_path_str(FILE_PATH_PROGRAM_NAME), fmt, ap); #else #ifdef HAVE_FILE_LOGGER fp = (FILE*)retro_main_log_file(); #else fp = stderr; #endif fprintf(fp, "%s %s :: ", file_path_str(FILE_PATH_PROGRAM_NAME), tag ? tag : file_path_str(FILE_PATH_LOG_INFO)); vfprintf(fp, fmt, ap); fflush(fp); #endif }
void info (const char*fmt, ...) { va_list ap; va_start(ap,fmt); printf("[INFO]: "); vprintf(fmt,ap); }
void fatal(char* s,...) { va_list p; va_start(p,s); vprintf(s,p); va_end(p); err_print(""); /* print reason and location of fatal stop */ history=fatal_message; wrap_up(); }
/** Tracer */ void auto_trace(char *format, ...) { va_list args; va_start(args, format); vprintf(format, args); va_end(args); }
void print(char* s,...) { va_list p; va_start(p,s); if (term_line_empty && *s=='\n') ++s; /* avoid printing empty line */ vprintf(s,p); va_end(p); /* print formatted value */ term_line_empty= s[strlen(s)-1]=='\n'; update_terminal(); }
int test_ok(int passed, const char *description, const char *directive, const char *reason, const char *file, unsigned line, const char *fmt, ...) { int is_todo = !passed && directive && !strcmp(directive, "TODO"); int is_setup = directive && !is_todo && !strcmp(directive, "SETUP"); if (is_setup) { if (!passed) { fflush(stdout); fprintf(stderr, "# SETUP not ok%s%s%s%s\n", description ? " - " : "", description ? description : "", reason ? " - " : "", reason ? reason : ""); } } else { if (!test_cases) { atexit(test_plan_exit); fprintf(stderr, "You tried to run a test without a plan! " "Gotta have a plan. at %s line %u\n", file, line); fflush(stderr); exit(255); } ++test_num; if (test_num > test_cases || (!passed && !is_todo)) ++test_fails; /* We dont need to print this unless we want to */ #if 0 fprintf(stderr, "%s:%u: note: %sok %d%s%s%s%s%s%s\n", file, line, passed ? "" : "not ", test_num, description ? " - " : "", description ? description : "", directive ? " # " : "", directive ? directive : "", reason ? " " : "", reason ? reason : ""); #endif } if (passed) fflush(stdout); else { va_list args; va_start(args, fmt); if (is_todo) { /* Enable this to output TODO as warning */ #if 0 printf("%s:%d: warning: Failed (TODO) test\n", file, line); if (fmt) vprintf(fmt, args); #endif fflush(stdout); } else { fflush(stdout); fprintf(stderr, "%s:%d: error: Failed test\n", file, line); if (fmt) vfprintf(stderr, fmt, args); fflush(stderr); } va_end(args); } return passed; }
/* * dump a snapshot of the symbol table */ void dumpsymtable(char *filename, long checkpt) { struct entry *ep, *tep; ino_t i; struct entry temp, *tentry; long mynum = 1, stroff = 0; FILE *fd; struct symtableheader hdr; vprintf(stdout, "Checkpointing the restore\n"); if (Nflag) return; if ((fd = fopen(filename, "w")) == NULL) { fprintf(stderr, "fopen: %s\n", strerror(errno)); panic("cannot create save file %s for symbol table\n", filename); done(1); } clearerr(fd); /* * Assign indices to each entry * Write out the string entries */ for (i = WINO; i <= maxino; i++) { for (ep = lookupino(i); ep != NULL; ep = ep->e_links) { ep->e_index = mynum++; (void) fwrite(ep->e_name, sizeof(char), (int)allocsize(ep->e_namlen), fd); } } /* * Convert pointers to indexes, and output */ tep = &temp; stroff = 0; for (i = WINO; i <= maxino; i++) { for (ep = lookupino(i); ep != NULL; ep = ep->e_links) { memmove(tep, ep, (long)sizeof(struct entry)); tep->e_name = (char *)stroff; stroff += allocsize(ep->e_namlen); tep->e_parent = (struct entry *)ep->e_parent->e_index; if (ep->e_links != NULL) tep->e_links = (struct entry *)ep->e_links->e_index; if (ep->e_sibling != NULL) tep->e_sibling = (struct entry *)ep->e_sibling->e_index; if (ep->e_entries != NULL) tep->e_entries = (struct entry *)ep->e_entries->e_index; if (ep->e_next != NULL) tep->e_next = (struct entry *)ep->e_next->e_index; (void) fwrite((char *)tep, sizeof(struct entry), 1, fd); } } /* * Convert entry pointers to indexes, and output */ for (i = 0; i < entrytblsize; i++) { if (entry[i] == NULL) tentry = NULL; else tentry = (struct entry *)entry[i]->e_index; (void) fwrite((char *)&tentry, sizeof(struct entry *), 1, fd); } hdr.volno = checkpt; hdr.maxino = maxino; hdr.entrytblsize = entrytblsize; hdr.stringsize = stroff; hdr.dumptime = dumptime; hdr.dumpdate = dumpdate; hdr.ntrec = ntrec; (void) fwrite((char *)&hdr, sizeof(struct symtableheader), 1, fd); if (ferror(fd)) { fprintf(stderr, "fwrite: %s\n", strerror(errno)); panic("output error to file %s writing symbol table\n", filename); } (void) fclose(fd); }
void mk_print(int type, const char *format, ...) { time_t now; struct tm *current; const char *header_color = NULL; const char *header_title = NULL; const char *bold_color = ANSI_BOLD; const char *reset_color = ANSI_RESET; const char *white_color = ANSI_WHITE; va_list args; va_start(args, format); switch (type) { case MK_INFO: header_title = "Info"; header_color = ANSI_GREEN; break; case MK_ERR: header_title = "Error"; header_color = ANSI_RED; break; case MK_WARN: header_title = "Warning"; header_color = ANSI_YELLOW; break; case MK_BUG: #ifdef DEBUG mk_utils_stacktrace(); #endif header_title = " BUG !"; header_color = ANSI_BOLD ANSI_RED; break; } /* Only print colors to a terminal */ if (!isatty(STDOUT_FILENO)) { header_color = ""; bold_color = ""; reset_color = ""; white_color = ""; } now = time(NULL); struct tm result; current = localtime_r(&now, &result); printf("%s[%s%i/%02i/%02i %02i:%02i:%02i%s]%s ", bold_color, reset_color, current->tm_year + 1900, current->tm_mon + 1, current->tm_mday, current->tm_hour, current->tm_min, current->tm_sec, bold_color, reset_color); printf("%s[%s%7s%s]%s ", bold_color, header_color, header_title, white_color, reset_color); vprintf(format, args); va_end(args); printf("%s\n", reset_color); fflush(stdout); }
UInt VG_(message)(VgMsgKind kind, const HChar* format, ...) { UInt ret; va_list vargs; va_start(vargs, format); ret = vprintf(format, vargs); va_end(vargs); printf("\n"); return ret; }