std::string CompilerFactory::findNativeTool(const std::string &profile_tool_name,const Argv & _args) { FUNCTION_TRACE; Argv arg(_args); bool tool_found=false; std::string file; struct stat info_me; std::string exe_param=System::appendExecSuffix(arg[0]); std::string appli=application_path(exe_param); DEBUG3("exe_param %s -> %s\n",exe_param.c_str(),appli.c_str()); if (profile_tool_name.empty()) { file=appli; } else { if (stat(appli.c_str(),&info_me)!=0) FATAL2("Could not get information from %s\n",appli.c_str()); exe_param=System::appendExecSuffix(profile_tool_name); int index=-1; file=application_path(exe_param); while (!file.empty()) { struct stat info; DEBUG2("Tool: %s\n",file.c_str()); char file_abs[MAX_PATH]; if (realPath(file.c_str(),file_abs)!=NULL) { DEBUG2("Tool abs: %s\n",file_abs); if (stat(file_abs,&info)==0) { if ( ! (info.st_ctime==info_me.st_ctime && info.st_size==info_me.st_size) ) { // tool found tool_found=true; DEBUG2("Tool found: %s\n",file.c_str()); break; } else { // suppress path entry #if SUPPRESS_PATH_ENTRY suppressPathEntry(file.c_str()); #endif setenv("COVERAGESCANNER_ARGS","",1); } } } index++; file=findFileInPath(exe_param,index); } if (!tool_found) FATAL2("Could not find application: %s\n",exe_param.c_str()); } return file; }
/*========================================== * is_key_in_use -- Return TRUE if a live record *========================================*/ BOOLEAN is_key_in_use (CNSTRING key) { DELETESET set=0; INT keynum=0; char ktype=0; CNSTRING barekey=0; BOOLEAN result=FALSE; if (!parse_key(key, &ktype, &keynum)) { char msg[512]; snprintf(msg, sizeof(msg)/sizeof(msg[0]), "Bad key passed to is_key_in_use: %s", key); FATAL2(msg); } set = get_deleteset_from_type(ktype); ASSERT(keynum>0); result = xref_isvalid_impl(set, keynum); strfree((STRING *)&barekey); return result; }
void revert_command (Widget w, XtPointer client_data, XtPointer call_data) { char_type *c; font_type *f = (font_type *) client_data; charcode_type code = FONT_CURRENT_CHARCODE (*f); char_type *original = FONT_CHAR (*f, code); /* Set the pointer in the font structure to null, so `read_char' will have to reread the character. */ FONT_CHAR (*f, code) = NULL; /* Reread the character. */ c = read_char (*f, code); if (c == NULL) FATAL2 ("xbfe: Character %d has somehow been deleted from `%s'", FONT_CURRENT_CHARCODE (*f), FONT_NAME (*f)); show_char (XtParent (w), f, c); /* Release the storage the current character is using. We must do this after rereading the character from the font, so that the same memory is not used. If that happens, `bitmap_set_values' thinks nothing has changed. */ free_bitmap (&BCHAR_BITMAP (*original)); free (original); }
/*============================================== * failreport -- Report fatal error via FATAL *============================================*/ static void failreport (CNSTRING msg, INT level, CNSTRING key, CNSTRING scope) { char buffer[512]; snprintf(buffer, 512, "(%s:%s level %ld) %s", scope, key, level, msg); FATAL2(buffer); }
/*================================================= * llassert -- Implement assertion * (for rbtree module, which does not include lifelines headers) *===============================================*/ static void llassert (int assertion, const char* error) { if (assertion) return; FATAL2(error); }
/*===================================== * add_xref_to_set_impl -- Add deleted key to xrefs. * generic for all types *===================================*/ static BOOLEAN add_xref_to_set_impl (INT keynum, DELETESET set, DUPS dups) { INT lo, i; if (keynum <= 0 || !xreffp || (set->n) < 1) { char msg[128]; snprintf(msg, sizeof(msg)/sizeof(msg[0]) , _("Corrupt DELETESET %c"), set->ctype); FATAL2(msg); } /* special case simplification if deleting last record */ if (keynum+1 == set->recs[0]) { /* just bump the 'next free' indicator down to return this keynum next, and we don't even have to add this to the list */ --set->recs[0]; ASSERT(writexrefs()); return TRUE; } if (set->n >= set->max) growxrefs(set); ASSERT(set->n < set->max); lo = find_slot(keynum, set); if (lo < set->n && (set->recs)[lo] == keynum) { /* key is already free */ char msg[96]; if (dups==DUPSOK) return FALSE; snprintf(msg, sizeof(msg)/sizeof(msg[0]) , _("Tried to add already-deleted record (%ld) to xref (%c)!") , keynum, set->ctype); FATAL2(msg); /* deleting a deleted record! */ } /* key replaces xrefs[lo] - push lo+ up */ for (i=set->n-1; i>=lo; --i) (set->recs)[i+1] = (set->recs)[i]; (set->recs)[lo] = keynum; (set->n)++; ASSERT(writexrefs()); maxkeynum=-1; return TRUE; }
/*=================================================== * addxref_impl -- Mark key free (accepts string key, any type) * key: [IN] key to delete (add to free set) * silent: [IN] if FALSE, ASSERT if record is already free *=================================================*/ static BOOLEAN addxref_impl (CNSTRING key, DUPS dups) { char ktype=0; INT keynum=0; if (!parse_key(key, &ktype, &keynum)) { char msg[512]; snprintf(msg, sizeof(msg)/sizeof(msg[0]), "Bad key passed to addxref_impl: %s", key); FATAL2(msg); } switch(ktype) { case 'I': return addixref_impl(keynum, dups); case 'F': return addfxref_impl(keynum, dups); case 'S': return addsxref_impl(keynum, dups); case 'E': return addexref_impl(keynum, dups); case 'X': return addxxref_impl(keynum, dups); default: ASSERT(0); return FALSE; } }
bitmap_type * pbm_get_block (unsigned height) { static int image_format; static int image_height; static int image_width = -1; static unsigned scanline_count = 0; static one_byte *saved_scanline = NULL; dimensions_type d; unsigned row; boolean row_has_black; bitmap_type *b = XTALLOC (1, bitmap_type); boolean found_black = false; int c = getc (pbm_input_file); if (c == EOF) return NULL; ungetc (c, pbm_input_file); if (image_width == -1) pbm_readpbminit (pbm_input_file, &image_width, &image_height, &image_format); DIMENSIONS_WIDTH (d) = image_width; DIMENSIONS_HEIGHT (d) = height; *b = new_bitmap (d); for (row = 0; row < height; row += found_black) { if (scanline_count == image_height) FATAL2 ("%s: Tried to read image row %d", pbm_input_filename, scanline_count); if (saved_scanline) { memcpy (BITMAP_ROW (*b, row), saved_scanline, image_width); saved_scanline = NULL; } else { pbm_readpbmrow (pbm_input_file, BITMAP_ROW (*b, row), image_width, image_format); scanline_count++; if (trace_scanlines) { printf ("%5d:", scanline_count); for (c = 0; c < image_width; c++) putchar (BITMAP_ROW (*b, row)[c] ? '*' : ' '); putchar ('\n'); } } /* Ignore this row if it was all-white and we haven't seen any black ones yet. */ row_has_black = memchr (BITMAP_ROW (*b, row), BLACK, image_width) != NULL; if (!found_black && row_has_black) { /* Our first non-blank row. */ found_black = true; } if (row >= height - BLANK_COUNT && row_has_black) { /* We've hit a nonblank row where we shouldn't have. Save this row and return. */ saved_scanline = BITMAP_ROW (*b, row); break; } } BITMAP_HEIGHT (*b) = height - BLANK_COUNT; return b; }
/*=========================== * lextok -- lex the next token *=========================*/ static int lextok (PACTX pactx, YYSTYPE * lvalp, INT c, INT t) { INT retval, mul; extern INT Yival; extern FLOAT Yfval; static char tokbuf[512]; /* token buffer */ STRING p = tokbuf; if (t == LETTER) { p = tokbuf; while (is_iden_char(c, t)) { if (p-tokbuf < (int)sizeof(tokbuf) - 3) { *p++ = c; } else { /* token overlong -- ignore end of it */ /* TODO: How can we force a parse error from here ? */ } t = chartype(c = inchar(pactx)); } *p = 0; unreadchar(pactx, c); if (reserved(tokbuf, &retval)) return retval; /* IDEN values have to be passed from yacc.y to free_iden */ *lvalp = (PNODE) strsave(tokbuf); return IDEN; } if (t == '-' || t == DIGIT || t == '.') { BOOLEAN whole = FALSE; BOOLEAN frac = FALSE; FLOAT fdiv; mul = 1; if (t == '-') { t = chartype(c = inchar(pactx)); if (t != '.' && t != DIGIT) { unreadchar(pactx, c); return '-'; } mul = -1; } Yival = 0; while (t == DIGIT) { whole = TRUE; Yival = Yival*10 + c - '0'; t = chartype(c = inchar(pactx)); } if (t != '.') { unreadchar(pactx, c); Yival *= mul; *lvalp = NULL; return ICONS; } t = chartype(c = inchar(pactx)); Yfval = 0.0; fdiv = 1.0; while (t == DIGIT) { frac = TRUE; Yfval = Yfval*10 + c - '0'; fdiv *= 10.; t = chartype(c = inchar(pactx)); } unreadchar(pactx, c); if (!whole && !frac) { unreadchar(pactx, c); if (mul == -1) { unreadchar(pactx, '.'); return '-'; } else return '.'; } Yfval = mul*(Yival + Yfval/fdiv); *lvalp = NULL; return FCONS; } if (c == '"') { INT start_line = pactx->lineno; p = tokbuf; while (TRUE) { while ((c = inchar(pactx)) != EOF && c != '"' && c != '\\') { if (p-tokbuf > sizeof(tokbuf)/sizeof(tokbuf[0]) - 3) { /* Overflowing tokbuf buffer */ /* TODO: (Perry, 2006-06-30) I don't know how to fail gracefully from here inside parser */ char msg[512]; snprintf(msg, sizeof(msg)/sizeof(msg[0]) , _("String constant overflowing internal buffer tokbuf len=%d, file: %s, start line: %ld") , sizeof(tokbuf)/sizeof(tokbuf[0]) , pactx->fullpath , start_line + 1 ); FATAL2(msg); *p = c = 0; } *p++ = c; } if (c == 0 || c == '"') { *p = 0; *lvalp = make_internal_string_node(pactx, tokbuf); return SCONS; } switch (c = inchar(pactx)) { case 'n': *p++ = '\n'; break; case 't': *p++ = '\t'; break; case 'v': *p++ = '\v'; break; case 'r': *p++ = '\r'; break; case 'b': *p++ = '\b'; break; case 'f': *p++ = '\f'; break; case '"': *p++ = '"'; break; case '\\': *p++ = '\\'; break; case EOF: *p = 0; *lvalp = make_internal_string_node(pactx, tokbuf); return SCONS; default: *p++ = c; break; } } } if (c == EOF) return 0; return c; }
void CsLibGen::save_source(const char *filename, const CompilerInterface &compiler_wrapper,const char *default_csexe,bool lock_csexe) { FUNCTION_TRACE; int i; FILE *f; char signature_str[CHAINE_LEN]; char tmp[CHAINE_LEN]; char indexstr[CHAINE_LEN]; char *default_csexe_escaped=NULL; if (default_csexe) { default_csexe_escaped = (char*)MALLOC(strlen(default_csexe)*2+1) ; escape(default_csexe,default_csexe_escaped); } DEBUG1("==== begin generating __cs_libgen.cs source code ====\n"); if (filename==NULL) f=stdout; else f=fopen(filename,"w"); if (f==NULL) { FATAL2("Could not open %s with write access\n",filename); } if (nb_data==0) { WARNING1("No object files compiled with code coverage support\n"); } fputs_trace("#pragma warning disable\n",f); fputs_trace("using System;\n",f); fputs_trace("using System.IO;\n",f); fputs_trace("using System.Text;\n",f); if (compiler_wrapper.setupMS()) fputs_trace("using System.Runtime.InteropServices;\n",f); fputs_trace("class CoverageScanner\n",f); fputs_trace("{\n",f); if (lock_csexe) { fputs_trace("const int CS_TIMEOUT=3000;\n",f); } fputs_trace("static string __cs_appname=\"",f); fputs_trace(default_csexe_escaped,f); fputs_trace(".csexe\";\n",f); fputs_trace("static System.IO.Stream __fopenread(string name) { return new FileStream(name,FileMode.Create,FileAccess.Read); }\n",f); fputs_trace("static System.IO.Stream __fopenappend(string name) { return new FileStream(name,FileMode.Append,FileAccess.Write); }\n",f); fputs_trace("static System.IO.Stream __fopenwrite(string name) { return new FileStream(name,FileMode.Create,FileAccess.Write); }\n",f); fputs_trace("static void __remove(string name) { System.IO.File.Delete(name); }\n",f); fputs_trace("static void __fputs(string data,System.IO.Stream stream) { System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();stream.Write(encoding.GetBytes(data),0,data.Length); }\n",f); fputs_trace("static string __fgets(System.IO.Stream stream) \n",f); fputs_trace(" { byte[] bytes= new byte[1024]; int numBytesToRead=1024; int numBytesRead=0; int n=stream.Read(bytes,numBytesRead,numBytesToRead); return Encoding.ASCII.GetString(bytes,0,n);}\n",f); fputs_trace("static void __fclose(System.IO.Stream stream) { stream.Close(); }\n",f); fputs_trace("static string __cs_testname=\"\";\n",f); fputs_trace("static string __cs_teststate=\"\";\n",f); /* Custom IO delegates */ fputs_trace("public delegate string __cs_fgets_delegate(System.IO.Stream stream);\n",f); fputs_trace("public delegate void __cs_fputs_delegate(string s, System.IO.Stream stream);\n",f); fputs_trace("public delegate System.IO.Stream __cs_fopenappend_delegate(string path);\n",f); fputs_trace("public delegate System.IO.Stream __cs_fopenread_delegate(string path);\n",f); fputs_trace("public delegate System.IO.Stream __cs_fopenwrite_delegate(string path);\n",f); fputs_trace("public delegate void __cs_fclose_delegate(System.IO.Stream fp);\n",f); fputs_trace("public delegate void __cs_remove_delegate(string n);\n",f); /* Custom IO */ fputs_trace("static __cs_fgets_delegate __cs_fgets = new __cs_fgets_delegate(__fgets);\n",f); fputs_trace("static __cs_fputs_delegate __cs_fputs = new __cs_fputs_delegate(__fputs);\n",f); fputs_trace("static __cs_fopenappend_delegate __cs_fopenappend = new __cs_fopenappend_delegate(__fopenappend);\n",f); fputs_trace("static __cs_fopenread_delegate __cs_fopenread = new __cs_fopenread_delegate(__fopenread);\n",f); fputs_trace("static __cs_fopenwrite_delegate __cs_fopenwrite = new __cs_fopenwrite_delegate(__fopenwrite);\n",f); fputs_trace("static __cs_fclose_delegate __cs_fclose = new __cs_fclose_delegate(__fclose);\n",f); fputs_trace("static __cs_remove_delegate __cs_remove = new __cs_remove_delegate(__remove);\n",f); fputs_trace("static string __out_buffer=\"\";\n",f); fputs_trace("static string cs_fgets(System.IO.Stream stream)\n",f); fputs_trace("{\n",f); fputs_trace(" return __cs_fgets(stream);\n",f); fputs_trace("}\n",f); fputs_trace("static void cs_fputs(string s, System.IO.Stream stream)\n",f); fputs_trace("{\n",f); fputs_trace(" const int max_lg=1024;\n",f); fputs_trace(" int lg=s.Length;\n",f); fputs_trace(" int __out_buffer_lg=__out_buffer.Length;\n",f); fputs_trace(" if (lg+__out_buffer_lg>=max_lg)\n",f); fputs_trace(" {\n",f); fputs_trace(" if (__out_buffer_lg>0) __cs_fputs(__out_buffer,stream);\n",f); fputs_trace(" __out_buffer=\"\";\n",f); fputs_trace(" }\n",f); fputs_trace(" if (lg>=max_lg)\n",f); fputs_trace(" {\n",f); fputs_trace(" __cs_fputs(s,stream);\n",f); fputs_trace(" return ;\n",f); fputs_trace(" }\n",f); fputs_trace(" __out_buffer+=s;\n",f); fputs_trace("}\n",f); fputs_trace("static System.IO.Stream cs_fopenappend(string path)\n",f); fputs_trace("{\n",f); fputs_trace(" __out_buffer=\"\";\n",f); fputs_trace(" return __cs_fopenappend(path);\n",f); fputs_trace("}\n",f); fputs_trace("static System.IO.Stream cs_fopenread(string path)\n",f); fputs_trace("{\n",f); fputs_trace(" __out_buffer=\"\";\n",f); fputs_trace(" return __cs_fopenread(path);\n",f); fputs_trace("}\n",f); fputs_trace("static System.IO.Stream cs_fopenwrite(string path)\n",f); fputs_trace("{\n",f); fputs_trace(" __out_buffer=\"\";\n",f); fputs_trace(" return __cs_fopenwrite(path);\n",f); fputs_trace("}\n",f); fputs_trace("static void cs_fclose(System.IO.Stream fp)\n",f); fputs_trace("{\n",f); fputs_trace(" if (__out_buffer.Length!=0) __cs_fputs(__out_buffer,fp);\n",f); fputs_trace(" __out_buffer=\"\";\n",f); fputs_trace(" __cs_fclose(fp);\n",f); fputs_trace("}\n",f); fputs_trace("public static \n",f); fputs_trace("void ",f); fputs_trace(" __coveragescanner_set_custom_io(",f); fputs_trace("__cs_fgets_delegate cs_fgets,\n",f); fputs_trace("__cs_fputs_delegate cs_fputs,\n",f); fputs_trace("__cs_fopenappend_delegate cs_fopenappend,\n",f); fputs_trace("__cs_fopenread_delegate cs_fopenread,\n",f); fputs_trace("__cs_fopenwrite_delegate cs_fopenwrite,\n",f); fputs_trace("__cs_fclose_delegate cs_fclose,\n",f); fputs_trace("__cs_remove_delegate cs_remove\n",f); fputs_trace(")\n",f); fputs_trace("{\n",f); fputs_trace(" __cs_fgets=cs_fgets;\n",f); fputs_trace(" __cs_fputs=cs_fputs;\n",f); fputs_trace(" __cs_fopenappend=cs_fopenappend;\n",f); fputs_trace(" __cs_fopenread=cs_fopenread;\n",f); fputs_trace(" __cs_fopenwrite=cs_fopenwrite;\n",f); fputs_trace(" __cs_fclose=cs_fclose;\n",f); fputs_trace(" __cs_remove=cs_remove;\n",f); fputs_trace("}\n",f); fputs_trace("struct __cs_exec_t { public int size; public int signature; public string name;public int []values;} ;\n",f); fputs_trace("static __cs_exec_t []__cs_exec= null;\n",f); /* Checksum for lockfile */ fputs_trace("static int __checksum_over_coverage()\n",f); fputs_trace("{\n",f); fputs_trace(" int i,item;\n",f); fputs_trace(" int chksum=0;\n",f); fputs_trace(" for (item=0;__cs_exec[item].name!=null;item++)\n",f); fputs_trace(" {\n",f); fputs_trace(" for (i=0;i<__cs_exec[item].size;i++)\n",f); fputs_trace(" {\n",f); fputs_trace(" chksum += __cs_exec[item].values[i];\n",f); fputs_trace(" }\n",f); fputs_trace(" }\n",f); fputs_trace(" return chksum;\n",f); fputs_trace("}\n",f); fputs_trace("\n",f); /* init function of the table */ fputs_trace("static string __cs_int2hex(int v)\n",f); fputs_trace("{\n",f); fputs_trace(" string h=\"\";\n",f); fputs_trace(" int i;\n",f); fputs_trace(" for (i=0;i<8;i++)\n",f); fputs_trace(" {\n",f); fputs_trace(" char c;\n",f); fputs_trace(" c=(char)((v>>(4*(7-i))) & 0xF);\n",f); fputs_trace(" if (c<=9)\n",f); fputs_trace(" c+='0';\n",f); fputs_trace(" else\n",f); fputs_trace(" c+=(char)('A'-10);\n",f); fputs_trace(" h+=c;\n",f); fputs_trace(" }\n",f); fputs_trace(" return h;\n",f); fputs_trace("}\n",f); fputs_trace("static void __cs_sem_init()\n",f); fputs_trace("{\n",f); fputs_trace("}\n",f); fputs_trace("static int __cs_sem_lock()\n",f); fputs_trace("{\n",f); if (lock_csexe) { fputs_trace(" System.DateTime start_time=System.DateTime.Now;\n",f); fputs_trace(" System.DateTime end_time;\n",f); fputs_trace(" string lockfile;\n",f); fputs_trace(" string str;\n",f); fputs_trace(" string str2;\n",f); fputs_trace(" System.IO.Stream f=null;\n\n",f); fputs_trace(" if (__cs_fgets==null) return 1;\n",f); fputs_trace(" str=\"cs:\";\n",f); fputs_trace(" str+=__cs_int2hex(System.Diagnostics.Process.GetCurrentProcess().Id);\n",f); fputs_trace(" str+=\":\";\n",f); fputs_trace(" str+=__cs_int2hex(start_time.Second*1000+start_time.Minute*60000+start_time.Millisecond);\n",f); fputs_trace(" str+=\":\";\n",f); fputs_trace(" str+=__cs_int2hex(__checksum_over_coverage());\n",f); fputs_trace(" lockfile=__cs_appname;\n",f); fputs_trace(" lockfile+=\".lck\";\n",f); fputs_trace(" start_time=System.DateTime.Now;\n",f); fputs_trace(" for (end_time=start_time;(end_time-start_time).Seconds<CS_TIMEOUT;end_time=System.DateTime.Now)\n",f); fputs_trace(" {\n",f); fputs_trace(" int canlock=0;\n",f); fputs_trace(" try {\n",f); fputs_trace(" f=cs_fopenread(lockfile);\n",f); fputs_trace(" } \n",f); fputs_trace(" catch \n",f); fputs_trace(" {\n",f); fputs_trace(" canlock=1;\n",f); fputs_trace(" f=null;\n",f); fputs_trace(" }\n",f); fputs_trace(" if (f!=null)\n",f); fputs_trace(" {\n",f); fputs_trace(" try {\n",f); fputs_trace(" f=cs_fopenread(lockfile);\n",f); fputs_trace(" str2=cs_fgets(f); \n",f); fputs_trace(" cs_fclose(f);\n",f); fputs_trace(" if (str2==\"\")\n",f); fputs_trace(" canlock=1;\n",f); fputs_trace(" } catch {}\n",f); fputs_trace(" } \n",f); fputs_trace(" if (canlock==1)\n",f); fputs_trace(" {\n",f); fputs_trace(" try \n",f); fputs_trace(" {\n",f); fputs_trace(" f=cs_fopenwrite(lockfile); \n",f); fputs_trace(" cs_fputs(str,f); \n",f); fputs_trace(" cs_fclose(f);\n",f); fputs_trace(" f=cs_fopenread(lockfile); \n",f); fputs_trace(" str2=cs_fgets(f); \n",f); fputs_trace(" cs_fclose(f);\n",f); fputs_trace(" if (str2==str)\n",f); fputs_trace(" return 1;\n",f); fputs_trace(" } catch {}\n",f); fputs_trace(" }\n",f); fputs_trace(" }\n",f); fputs_trace(" return 0;\n",f); } else fputs_trace(" return 1;\n",f); fputs_trace("}\n",f); fputs_trace("static void __cs_sem_unlock()\n",f); fputs_trace("{\n",f); if (lock_csexe) { fputs_trace("try \n",f); fputs_trace("{\n",f); fputs_trace(" string lockfile;\n",f); fputs_trace(" if (__cs_fgets==null) return ;\n",f); fputs_trace(" lockfile=__cs_appname;\n",f); fputs_trace(" lockfile+=\".lck\";\n",f); fputs_trace(" if (__cs_remove!=null)\n",f); fputs_trace(" __cs_remove(lockfile);\n",f); fputs_trace(" else\n",f); fputs_trace(" {\n",f); fputs_trace(" System.IO.Stream f;\n\n",f); fputs_trace(" f=cs_fopenwrite(lockfile); \n",f); fputs_trace(" cs_fclose(f);\n",f); fputs_trace(" }\n",f); fputs_trace("} catch {}\n",f); } fputs_trace("}\n",f); fputs_trace("static void __cs_exec_init()\n",f); fputs_trace("{\n",f); fputs_trace("try \n",f); fputs_trace("{\n",f); fputs_trace(" if (__cs_exec!=null) return ;\n\n",f); fputs_trace(" __cs_exec_t []exectab = new __cs_exec_t[",f); sprintf(tmp,"%lu",nb_data+1); fputs_trace(tmp,f); fputs_trace(" ];\n\n",f); fputs_trace(" __cs_exec=exectab;\n\n",f); for (i=0;i<nb_data;i++) { char table_name[INSTRUMENTATION_CODE_MAX_LENGTH] ; char filename_abs[MAX_PATH]; realPath(datas[i].filename,filename_abs); Source::instrumentation_table(filename_abs,table_name); fputs_trace(" /* ",f); fputs_trace(filename_abs,f); fputs_trace(" */\n",f); sprintf(indexstr,"%i",i); sprintf(tmp," __cs_exec[%i]",i); fputs_trace(tmp,f); fputs_trace(".signature=",f); sprintf(signature_str,"%lu",datas[i].signature); fputs_trace(signature_str,f); fputs_trace(";\n",f); fputs_trace(tmp,f); fputs_trace(".name=",f); fputs_trace("\"",f); { char table_name[INSTRUMENTATION_CODE_MAX_LENGTH] ; char filename_abs_escape[MAX_PATH*2]; char filename_abs[MAX_PATH]; realPath(datas[i].filename,filename_abs); Source::instrumentation_table(filename_abs,table_name); escape(filename_abs,filename_abs_escape); fputs_trace(filename_abs_escape,f); } fputs_trace("\";\n",f); fputs_trace(tmp,f); fputs_trace(".values=",f); fputs_trace(table_name,f); fputs_trace(".val;\n",f); fputs_trace(tmp,f); fputs_trace(".size=",f); fputs_trace(table_name,f); fputs_trace(".nb;\n",f); } sprintf(tmp," __cs_exec[%i]",i); fputs_trace(tmp,f); fputs_trace(".signature=0;\n",f); fputs_trace(tmp,f); fputs_trace(".name=null;\n",f); fputs_trace(tmp,f); fputs_trace(".values=null;\n",f); fputs_trace(tmp,f); fputs_trace(".size=0;\n",f); fputs_trace("} catch {}\n",f); fputs_trace("}\n",f); /* __coveragescanner_save */ fputs_trace("public static \n",f); fputs_trace("void ",f); fputs_trace(" __coveragescanner_save()\n",f); fputs_trace("{\n",f); fputs_trace("try \n",f); fputs_trace("{\n",f); fputs_trace(" int i,item;\n",f); fputs_trace(" System.IO.Stream f;\n\n",f); fputs_trace(" __cs_sem_init();\n",f); fputs_trace(" __cs_exec_init();\n",f); fputs_trace(" if (__cs_sem_lock()==0) return ;\n",f); fputs_trace(" f=cs_fopenappend(__cs_appname);\n",f); fputs_trace(" if (f==null) return ;\n",f); fputs_trace(" try {\n",f); fputs_trace(" if (__cs_testname!=\"\") {\n",f); fputs_trace(" cs_fputs(\"*\",f);\n",f); fputs_trace(" cs_fputs(__cs_testname,f);\n",f); fputs_trace(" cs_fputs(\"\\n\",f);\n",f); fputs_trace(" }\n",f); fputs_trace(" cs_fputs(\"# Measurements\\n\",f);\n",f); /* Recording code */ fputs_trace(" for (item=0;__cs_exec[item].name!=null;item++)\n",f); fputs_trace(" {\n",f); fputs_trace(" if (__cs_exec[item].size==0) continue;\n",f); fputs_trace(" bool empty=true;\n",f); fputs_trace(" for (i=0;i<__cs_exec[item].size;i++)\n",f); fputs_trace(" {\n",f); fputs_trace(" if (__cs_exec[item].values[i]!=0)\n",f); fputs_trace(" empty=false;\n",f); fputs_trace(" }\n",f); fputs_trace(" if (empty) continue;\n",f); fputs_trace(" cs_fputs(\"/\",f);\n",f); fputs_trace(" cs_fputs(Convert.ToString(__cs_exec[item].size),f);\n",f); fputs_trace(" cs_fputs(\":\",f);\n",f); fputs_trace(" cs_fputs(Convert.ToString(__cs_exec[item].signature),f);\n",f); fputs_trace(" cs_fputs(\":\",f);\n",f); fputs_trace(" cs_fputs(__cs_exec[item].name,f);\n",f); fputs_trace(" cs_fputs(\"\\n\",f);\n",f); fputs_trace(" cs_fputs(\"\\\\\",f);\n",f); fputs_trace(" for (i=0;i<__cs_exec[item].size;i++)\n",f); fputs_trace(" {\n",f); fputs_trace(" {\n",f); fputs_trace(" switch (__cs_exec[item].values[i])\n",f); fputs_trace(" {\n",f); fputs_trace(" case 1:\n",f); fputs_trace(" cs_fputs(\"+\",f);\n",f); fputs_trace(" break;\n",f); fputs_trace(" case 0:\n",f); fputs_trace(" cs_fputs(\"-\",f);\n",f); fputs_trace(" break;\n",f); fputs_trace(" default:\n",f); fputs_trace(" cs_fputs(__cs_int2hex(__cs_exec[item].values[i]),f);\n",f); fputs_trace(" break;\n",f); fputs_trace(" }\n",f); fputs_trace(" }\n",f); fputs_trace(" __cs_exec[item].values[i]=0;\n",f); fputs_trace(" }\n",f); fputs_trace(" cs_fputs(\"\\n\",f);\n",f); fputs_trace(" }\n",f); /* saving the execution statue */ fputs_trace(" if (__cs_teststate!=\"\") {\n",f); fputs_trace(" cs_fputs(\"!\",f);\n",f); fputs_trace(" cs_fputs(__cs_teststate,f);\n",f); fputs_trace(" cs_fputs(\"\\n\",f);\n",f); fputs_trace(" __cs_teststate=\"\";\n",f); fputs_trace(" }\n",f); fputs_trace(" cs_fclose(f);\n",f); fputs_trace(" } catch { cs_fclose(f); }\n",f); fputs_trace(" __cs_sem_unlock();\n",f); fputs_trace("} catch {}\n",f); fputs_trace("}\n",f); fputs_trace("\n",f); /* __coveragescanner_testname */ fputs_trace("public static \n",f); fputs_trace("void ",f); fputs_trace(" __coveragescanner_testname(string name)\n",f); fputs_trace("{\n",f); fputs_trace(" __cs_testname=name;\n",f); fputs_trace("}\n",f); /* __coveragescanner_filename */ fputs_trace("public static \n",f); fputs_trace("void ",f); fputs_trace(" __coveragescanner_filename(string name)\n",f); fputs_trace("{\n",f); fputs_trace("try \n",f); fputs_trace("{\n",f); fputs_trace(" __cs_appname=name;\n",f); fputs_trace(" __cs_appname+=\".csexe\";\n",f); fputs_trace("} catch {}\n",f); fputs_trace("}\n",f); /* __coveragescanner_clear */ fputs_trace("public static \n",f); fputs_trace("void ",f); fputs_trace(" __coveragescanner_clear()\n",f); fputs_trace("{\n",f); fputs_trace("try \n",f); fputs_trace("{\n",f); fputs_trace(" int i,item;\n",f); fputs_trace(" __cs_sem_init();\n",f); fputs_trace(" __cs_exec_init();\n",f); fputs_trace(" for (item=0;__cs_exec[item].values!=null;item++)\n",f); fputs_trace(" for (i=0;i<__cs_exec[item].size;i++)\n",f); fputs_trace(" __cs_exec[item].values[i]=0;\n",f); fputs_trace("} catch {}\n",f); fputs_trace("}\n",f); fputs_trace("\n",f); /* __coveragescanner_teststate */ fputs_trace("public static \n",f); fputs_trace("void ",f); fputs_trace(" __coveragescanner_teststate(string state)\n",f); fputs_trace("{\n",f); fputs_trace(" __cs_teststate=state;\n",f); fputs_trace("}\n",f); if (!compiler_wrapper.customSetup()) { fputs_trace("static bool __cs_default_exit=true;\n",f); fputs_trace("static void __cs_exit()\n",f); fputs_trace("{\n",f); fputs_trace(" __coveragescanner_save();\n",f); fputs_trace("}\n",f); fputs_trace("static void __cs_exit_default()\n",f); fputs_trace("{\n",f); fputs_trace(" if (__cs_default_exit)\n",f); fputs_trace(" __cs_exit();\n",f); fputs_trace("}\n",f); fputs_trace("static void __cs_init()\n",f); fputs_trace("{\n",f); fputs_trace(" try {\n",f); fputs_trace(" __coveragescanner_filename(System.Environment.GetCommandLineArgs()[0]);\n",f); fputs_trace(" } catch\n",f); fputs_trace(" {__coveragescanner_filename(\"",f); fputs_trace(default_csexe_escaped,f); fputs_trace("\");}\n",f); fputs_trace("}\n",f); } fputs_trace("public class __cs_lib_t {\n",f); fputs_trace(" public",f); fputs_trace(" __cs_lib_t()\n",f); fputs_trace(" {\n",f); if (!compiler_wrapper.customSetup()) fputs_trace(" CoverageScanner.__cs_init();\n",f); fputs_trace(" }\n",f); if (!compiler_wrapper.customSetup()) { fputs_trace(" ~__cs_lib_t()\n",f); fputs_trace(" {\n",f); fputs_trace(" CoverageScanner.__cs_exit();\n",f); fputs_trace(" }\n",f); } fputs_trace("};\n",f); fputs_trace("}\n",f); if (filename!=NULL) fclose(f); DEBUG1("==== end generating __cs_libgen.cs source code ====\n"); FREE(default_csexe_escaped); }
static string maketex P2C(kpse_file_format_type, format, string*, args) { /* New implementation, use fork/exec pair instead of popen, since * the latter is virtually impossible to make safe. */ unsigned len; string *s; string ret; string fn; if (!kpse_make_tex_discard_errors) { fprintf (stderr, "kpathsea: Running"); for (s = &args[0]; *s != NULL; s++) fprintf (stderr, " %s", *s); fputc('\n', stderr); } #if defined (AMIGA) /* Amiga has a different interface. */ { string cmd; string newcmd; cmd = xstrdup(args[0]); for (s = &args[1]; *s != NULL; s++) { newcmd = concat(cmd, *s); free (cmd); cmd = newcmd; } ret = system(cmd) == 0 ? getenv ("LAST_FONT_CREATED"): NULL; free (cmd); } #elif defined (MSDOS) #error Implement new MSDOS mktex call interface here #elif defined (WIN32) /* We would vastly prefer to link directly with mktex.c here. Unfortunately, it is not quite possible because kpathsea is not reentrant. The progname is expected to be set in mktex.c and various initialisations occur. So to be safe, we implement a call sequence equivalent to the Unix one. */ { STARTUPINFO si; PROCESS_INFORMATION pi; HANDLE child_in, child_out, child_err; HANDLE father_in, father_out_dup; HANDLE current_pid; SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; string new_cmd = NULL, app_name = NULL; char buf[1024+1]; int num; extern char *quote_args(char **argv); if (look_for_cmd(args[0], &app_name) == FALSE) { ret = NULL; goto error_exit; } /* Compute the command line */ new_cmd = quote_args(args); /* We need this handle to duplicate other handles */ current_pid = GetCurrentProcess(); ZeroMemory( &si, sizeof(STARTUPINFO) ); si.cb = sizeof(STARTUPINFO); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW ; si.wShowWindow = /* 0 */ SW_HIDE ; /* Child stdin */ child_in = CreateFile("nul", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, /* non inheritable */ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); si.hStdInput = child_in; if (CreatePipe(&father_in, &child_out, NULL, 0) == FALSE) { fprintf(stderr, "popen: error CreatePipe\n"); goto error_exit; } if (DuplicateHandle(current_pid, child_out, current_pid, &father_out_dup, 0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) { fprintf(stderr, "popen: error DuplicateHandle father_in\n"); CloseHandle(father_in); CloseHandle(child_out); goto error_exit; } CloseHandle(child_out); si.hStdOutput = father_out_dup; /* Child stderr */ if (kpse_make_tex_discard_errors) { child_err = CreateFile("nul", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, /* non inheritable */ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); } else { DuplicateHandle(current_pid, GetStdHandle(STD_ERROR_HANDLE), current_pid, &child_err, 0, TRUE, DUPLICATE_SAME_ACCESS); } si.hStdError = child_err; /* creating child process */ if (CreateProcess(app_name, /* pointer to name of executable module */ new_cmd, /* pointer to command line string */ NULL, /* pointer to process security attributes */ NULL, /* pointer to thread security attributes */ TRUE, /* handle inheritance flag */ 0, /* creation flags */ NULL, /* pointer to environment */ NULL, /* pointer to current directory */ &si, /* pointer to STARTUPINFO */ &pi /* pointer to PROCESS_INFORMATION */ ) == 0) { FATAL2("kpathsea: CreateProcess() failed for `%s' (Error %x)\n", new_cmd, GetLastError()); } CloseHandle(child_in); CloseHandle(father_out_dup); CloseHandle(child_err); /* Only the process handle is needed */ CloseHandle(pi.hThread); /* Get stdout of child from the pipe. */ fn = xstrdup(""); while (ReadFile(father_in,buf,sizeof(buf)-1, &num, NULL) != 0 && num > 0) { if (num <= 0) { if (GetLastError() != ERROR_BROKEN_PIPE) { FATAL1("kpathsea: read() error code for `%s' (Error %d)", GetLastError()); break; } } else { string newfn; buf[num] = '\0'; newfn = concat(fn, buf); free(fn); fn = newfn; } } /* End of file on pipe, child should have exited at this point. */ CloseHandle(father_in); if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_OBJECT_0) { WARNING2("kpathsea: failed to wait for process termination: %s (Error %d)\n", new_cmd, GetLastError()); } CloseHandle(pi.hProcess); if (new_cmd) free(new_cmd); if (app_name) free(app_name); if (fn) { len = strlen(fn); /* Remove trailing newlines and returns. */ while (len && (fn[len - 1] == '\n' || fn[len - 1] == '\r')) { fn[len - 1] = '\0'; len--; } ret = len == 0 ? NULL : kpse_readable_file (fn); if (!ret && len > 1) { WARNING1 ("kpathsea: mktexpk output `%s' instead of a filename", fn); } /* Free the name if we're not returning it. */ if (fn != ret) free (fn); } error_exit: ; } #else { /* Standard input for the child. Set to /dev/null */ int childin; /* Standard output for the child, what we're interested in. */ int childout[2]; /* Standard error for the child, same as parent or /dev/null */ int childerr; /* Child pid. */ pid_t childpid; /* Open the channels that the child will use. */ /* A fairly horrible uses of gotos for here for the error case. */ if ((childin = open("/dev/null", O_RDONLY)) < 0) { perror("kpathsea: open(\"/dev/null\", O_RDONLY)"); goto error_childin; } if (pipe(childout) < 0) { perror("kpathsea: pipe()"); goto error_childout; } if ((childerr = open("/dev/null", O_WRONLY)) < 0) { perror("kpathsea: open(\"/dev/null\", O_WRONLY)"); goto error_childerr; } if ((childpid = fork()) < 0) { perror("kpathsea: fork()"); close(childerr); error_childerr: close(childout[0]); close(childout[1]); error_childout: close(childin); error_childin: fn = NULL; } else if (childpid == 0) { /* Child * * We can use vfork, provided we're careful about what we * do here: do not return from this function, do not modify * variables, call _exit if there is a problem. * * Complete setting up the file descriptors. * We use dup(2) so the order in which we do this matters. */ close(childout[0]); /* stdin -- the child will not receive input from this */ if (childin != 0) { close(0); dup(childin); close(childin); } /* stdout -- the output of the child's action */ if (childout[1] != 1) { close(1); dup(childout[1]); close(childout[1]); } /* stderr -- use /dev/null if we discard errors */ if (childerr != 2) { if (kpse_make_tex_discard_errors) { close(2); dup(childerr); } close(childerr); } /* FIXME: We could/should close all other file descriptors as well. */ /* exec -- on failure a call of _exit(2) it is the only option */ if (execvp(args[0], args)) perror(args[0]); _exit(1); } else { /* Parent */ char buf[1024+1]; int num; int status; /* Clean up child file descriptors that we won't use anyway. */ close(childin); close(childout[1]); close(childerr); /* Get stdout of child from the pipe. */ fn = xstrdup(""); while ((num = read(childout[0],buf,sizeof(buf)-1)) != 0) { if (num == -1) { if (errno != EINTR) { perror("kpathsea: read()"); break; } } else { string newfn; buf[num] = '\0'; newfn = concat(fn, buf); free(fn); fn = newfn; } } /* End of file on pipe, child should have exited at this point. */ close(childout[0]); /* We don't really care about the exit status at this point. */ wait(NULL); } if (fn) { len = strlen(fn); /* Remove trailing newlines and returns. */ while (len && (fn[len - 1] == '\n' || fn[len - 1] == '\r')) { fn[len - 1] = '\0'; len--; } ret = len == 0 ? NULL : kpse_readable_file (fn); if (!ret && len > 1) { WARNING1 ("kpathsea: mktexpk output `%s' instead of a filename", fn); } /* Free the name if we're not returning it. */ if (fn != ret) free (fn); } else { ret = NULL; } } #endif if (ret == NULL) misstex (format, args); else kpse_db_insert (ret); return ret; }
int coveragescanner(int argc,char **argv) { #ifdef __COVERAGESCANNER__ __coveragescanner_install(argv[0]); #endif #if LOG signal(SIGABRT,sighandler); signal(SIGTERM,sighandler); signal(SIGFPE,sighandler); signal(SIGILL,sighandler); signal(SIGINT,sighandler); signal(SIGSEGV,sighandler); signal(SIGTERM,sighandler); #endif #ifdef SEFLTEST setenv("EF_PROTECT_FREE","1",0); setenv("EF_FREE_WIPE","1",0); #endif #if 0 if (strcmp(argv[0],"link.exe")==0) DebugBreak(); #endif #if LOG OPEN_LOG(); DEBUG5("TestCocoon v%i.%i.%i date:%s\n",(TESTCOCOON_VERSION>>16),(TESTCOCOON_VERSION>>8)&0xFF, TESTCOCOON_VERSION&0xFF ,__DATE__); std::string cmd; for (int i=0;i<argc;i++) { cmd+=" "; cmd+=System::quoteArgument(argv[i]); } DEBUG2("cmd=%s\n",cmd.c_str()); for (int ilog=0;ilog<argc;ilog++) { DEBUG3("Argv[%i]=%s\n",ilog,argv[ilog]); } #endif bool coveragescanner_disable_env=CompilerInterface::isCoverageScannerDisabledPerEnvironmentVariable(); if (coveragescanner_disable_env) { DEBUG1("COVERAGESCANNER_DISABLE is set\n"); } Option option(argc,argv); CompilerInterface::disableCoverageScannerPerEnvironmentVariable(); if (coveragescanner_disable_env || option.isInactive()) { DEBUG1("Do not instrument source file, call the native tool.\n"); DEBUG3("call_native_tool(%s,%s)\n",option.profileToolName().c_str(),option.param_args()[0]); CompilerInterface *compiler_p=CompilerFactory::create(option); if (compiler_p==NULL) { FATAL1("Could not find CoverageScanner profile!"); } int ret = compiler_p->callNativeTool(); TmpFile::object().deleteFiles(); return ret; } //DebugBreak(); #if defined(LOG) || !defined(NO_DEBUG) fprintf(stderr,"CoverageScanner (\"%s\") is build in debug mode.\n",argv[0]); #endif DEBUG1("Instrument source file, not calling the native tool.\n"); Compiler compiler(option); if (!compiler.generate()) { FATAL2("Error:%s\n",compiler.error()); } MEMORY_REPORT; return (0); }