Пример #1
0
/* Read suppressions from the file specified in VG_(clo_suppressions)
   and place them in the suppressions list.  If there's any difficulty
   doing this, just give up -- there's no point in trying to recover.  
*/
static void load_one_suppressions_file ( Char* filename )
{
#  define N_BUF 200
   SysRes sres;
   Int    fd, i;
   Bool   eof;
   Char   buf[N_BUF+1];
   Char*  tool_names;
   Char*  supp_name;
   Char*  err_str = NULL;
   SuppLoc tmp_callers[VG_MAX_SUPP_CALLERS];

   fd   = -1;
   sres = VG_(open)( filename, VKI_O_RDONLY, 0 );
   if (sres.isError) {
      if (VG_(clo_xml))
         VG_(message)(Vg_UserMsg, "</valgrindoutput>\n");
      VG_(message)(Vg_UserMsg, "FATAL: can't open suppressions file '%s'", 
                   filename );
      VG_(exit)(1);
   }
   fd = sres.res;

#  define BOMB(S)  { err_str = S;  goto syntax_error; }

   while (True) {
      /* Assign and initialise the two suppression halves (core and tool) */
      Supp* supp;
      supp        = VG_(arena_malloc)(VG_AR_CORE, sizeof(Supp));
      supp->count = 0;

      // Initialise temporary reading-in buffer.
      for (i = 0; i < VG_MAX_SUPP_CALLERS; i++) {
         tmp_callers[i].ty   = NoName;
         tmp_callers[i].name = NULL;
      }

      supp->string = supp->extra = NULL;

      eof = VG_(get_line) ( fd, buf, N_BUF );
      if (eof) break;

      if (!VG_STREQ(buf, "{")) BOMB("expected '{' or end-of-file");
      
      eof = VG_(get_line) ( fd, buf, N_BUF );

      if (eof || VG_STREQ(buf, "}")) BOMB("unexpected '}'");

      supp->sname = VG_(arena_strdup)(VG_AR_CORE, buf);

      eof = VG_(get_line) ( fd, buf, N_BUF );

      if (eof) BOMB("unexpected end-of-file");

      /* Check it has the "tool1,tool2,...:supp" form (look for ':') */
      i = 0;
      while (True) {
         if (buf[i] == ':')  break;
         if (buf[i] == '\0') BOMB("malformed 'tool1,tool2,...:supp' line");
         i++;
      }
      buf[i]    = '\0';    /* Replace ':', splitting into two strings */

      tool_names = & buf[0];
      supp_name  = & buf[i+1];

      if (VG_(needs).core_errors && tool_name_present("core", tool_names))
      {
         // A core suppression
         //(example code, see comment on CoreSuppKind above)
         //if (VG_STREQ(supp_name, "Thread"))
         //   supp->skind = ThreadSupp;
         //else
            BOMB("unknown core suppression type");
      }
      else if (VG_(needs).tool_errors && 
               tool_name_present(VG_(details).name, tool_names))
      {
         // A tool suppression
         if (VG_TDICT_CALL(tool_recognised_suppression, supp_name, supp)) {
            /* Do nothing, function fills in supp->skind */
         } else {
            BOMB("unknown tool suppression type");
         }
      }
      else {
         // Ignore rest of suppression
         while (True) {
            eof = VG_(get_line) ( fd, buf, N_BUF );
            if (eof) BOMB("unexpected end-of-file");
            if (VG_STREQ(buf, "}"))
               break;
         }
         continue;
      }

      if (VG_(needs).tool_errors && 
          !VG_TDICT_CALL(tool_read_extra_suppression_info, fd, buf, N_BUF, supp))
      {
         BOMB("bad or missing extra suppression info");
      }

      i = 0;
      while (True) {
         eof = VG_(get_line) ( fd, buf, N_BUF );
         if (eof)
            BOMB("unexpected end-of-file");
         if (VG_STREQ(buf, "}")) {
            if (i > 0) {
               break;
            } else {
               BOMB("missing stack trace");
            }
         }
         if (i == VG_MAX_SUPP_CALLERS)
            BOMB("too many callers in stack trace");
         if (i > 0 && i >= VG_(clo_backtrace_size)) 
            break;
         tmp_callers[i].name = VG_(arena_strdup)(VG_AR_CORE, buf);
         if (!setLocationTy(&(tmp_callers[i])))
            BOMB("location should start with 'fun:' or 'obj:'");
         i++;
      }

      // If the num callers is >= VG_(clo_backtrace_size), ignore any extra
      // lines and grab the '}'.
      if (!VG_STREQ(buf, "}")) {
         do {
            eof = VG_(get_line) ( fd, buf, N_BUF );
         } while (!eof && !VG_STREQ(buf, "}"));
      }

      // Copy tmp_callers[] into supp->callers[]
      supp->n_callers = i;
      supp->callers = VG_(arena_malloc)(VG_AR_CORE, i*sizeof(SuppLoc));
      for (i = 0; i < supp->n_callers; i++) {
         supp->callers[i] = tmp_callers[i];
      }

      supp->next = suppressions;
      suppressions = supp;
   }
   VG_(close)(fd);
   return;

  syntax_error:
   if (VG_(clo_xml))
      VG_(message)(Vg_UserMsg, "</valgrindoutput>\n");
   VG_(message)(Vg_UserMsg, 
                "FATAL: in suppressions file '%s': %s", filename, err_str );
   
   VG_(close)(fd);
   VG_(message)(Vg_UserMsg, "exiting now.");
   VG_(exit)(1);

#  undef BOMB
#  undef N_BUF   
}
Пример #2
0
int jadvacOpenFile_cue(jadvacContext* ctx)
{
	Blob* currBlob = NULL;
	int retval = JAD_ERROR;
	int c = 0, ret, digits;
	int pregap_lba = -1;
	CueLexer _L = {0}, *L = &_L;
	struct {
		StringBuffer performer, songwriter, title, catalog, isrc, cdtextfile;
	} meta;

	//this might be getting a little large for a stack so...
	TrackInfo* tracks = ctx->allocator->alloc(ctx->allocator,sizeof(TrackInfo)*100);
	int tracknum = -1;

	L->allocator = ctx->allocator;
	L->lastc = '\n';
	L->stream = ctx->stream;
	sb_init(L,&L->buffer);

	sb_init(L,&meta.performer);
	sb_init(L,&meta.songwriter);
	sb_init(L,&meta.title);
	sb_init(L,&meta.catalog);
	sb_init(L,&meta.isrc);
	sb_init(L,&meta.cdtextfile);

	memset(tracks,0,sizeof(struct TrackInfo)*100);


LOOP:
	READ();
	READTOKEN();

	//commands that dont matter much
	if(CHECKTOKEN("PERFORMER")) {
		READSTRING();
		sb_clone(L, &L->buffer, &meta.performer);
		goto ENDLINE;
	}
	if(CHECKTOKEN("SONGWRITER")) { READSTRING(); sb_clone(L, &L->buffer, &meta.songwriter); goto ENDLINE; }
	if(CHECKTOKEN("TITLE")) { READSTRING(); sb_clone(L, &L->buffer, &meta.title); goto ENDLINE; }
	if(CHECKTOKEN("CATALOG")) { READSTRING(); sb_clone(L, &L->buffer, &meta.catalog); goto ENDLINE; }
	if(CHECKTOKEN("ISRC")) { READSTRING(); sb_clone(L, &L->buffer, &meta.isrc); goto ENDLINE; }
	if(CHECKTOKEN("CDTEXTFILE")) { READSTRING(); sb_clone(L, &L->buffer, &meta.cdtextfile); goto ENDLINE; }
	if(CHECKTOKEN("REM")) { READLINE(); goto LOOP; }

	if(CHECKTOKEN("FILE"))
	{
		jadStream stream;

		READSTRING();
		ret = ctx->fs->open(ctx->fs,&stream,L->buffer.buf);
		if(ret) { retval = ret; goto EXIT; }
		READTOKEN(); //file type
		if(CHECKTOKEN("BINARY")) {}
		else BOMB("Invalid file type");

		//currently only binary files are allowed, since we don't have the audio decoding framework in

		//ok, startup the new file
		currBlob = blob_alloc(ctx->allocator);
		currBlob->stream = stream;
		currBlob->type = FileType_Binary;

		goto ENDLINE;
	}

	if(CHECKTOKEN("PREGAP"))
	{
		int m, s, f;
		if(tracknum == -1) BOMB("Invalid INDEX command\n");
		READMSF();
		tracks[tracknum].pregap = m*60*75+s*75+f;
	}
	if(CHECKTOKEN("POSTGAP"))
	{
		int m, s, f;
		if(tracknum == -1) BOMB("Invalid INDEX command\n");
		READMSF();
		tracks[tracknum].postgap = m*60*75+s*75+f;
	}

	if(CHECKTOKEN("INDEX"))
	{
		int indexnum, m, s, f;
		if(tracknum == -1) BOMB("Invalid INDEX command\n");
		READDIGITS();
		indexnum = digits;
		READMSF();
		tracks[tracknum].indexes[indexnum].exists = 1;
		tracks[tracknum].lba = m*60*75+s*75+f;
	}

	if(CHECKTOKEN("TRACK"))
	{
		READDIGITS();
		tracknum = digits;
		READTOKEN(); //track type
		if(CHECKTOKEN("AUDIO")) tracks[tracknum].type = TrackType_Audio;
		else if(CHECKTOKEN("MODE1/2352")) tracks[tracknum].type = TrackType_Mode1_2352;
		else BOMB("Invalid track type");

		//if we have an unassociated blob, now's the time to associte it
		tracks[tracknum].newBlob = currBlob;
		currBlob = NULL;

		goto ENDLINE;
	}

ENDLINE:
	READLINE();
	goto LOOP;

	retval = JAD_OK;

EXIT:
	//todo: unassociated blob
	sb_finalize(L,&meta.performer);
	sb_finalize(L,&meta.songwriter);
	sb_finalize(L,&meta.title);
	sb_finalize(L,&meta.catalog);
	sb_finalize(L,&meta.isrc);
	sb_finalize(L,&meta.cdtextfile);
	sb_finalize(L,&L->buffer);
	ctx->allocator->free(ctx->allocator,tracks);
	return retval;

ERROR:
	retval = JAD_ERROR;
	goto EXIT;
}