コード例 #1
0
/* Dump the events to stdout, if verbose is set. */
static void
dump_pass_data (void)
{
  size_t i, j;

  for (i = 0; i < NR_TEST_PASSES; ++i) {
    printf ("pass %zu\n", pass_data[i].pass);
    printf ("    number of events collected %zu\n", pass_data[i].nr_events);
    printf ("    elapsed time %" PRIi64 " ns\n", pass_data[i].elapsed_ns);
    for (j = 0; j < pass_data[i].nr_events; ++j) {
      int64_t ns, diff_ns;
      CLEANUP_FREE char *source_str = NULL;

      ns = timespec_diff (&pass_data[i].start_t, &pass_data[i].events[j].t);
      source_str = source_to_string (pass_data[i].events[j].source);
      printf ("    %.1fms ", ns / 1000000.0);
      if (j > 0) {
	diff_ns = timespec_diff (&pass_data[i].events[j-1].t,
				 &pass_data[i].events[j].t);
	printf ("(+%.1f) ", diff_ns / 1000000.0);
      }
      printf ("[%s] \"", source_str);
      print_escaped_string (pass_data[i].events[j].message);
      printf ("\"\n");
    }
  }

  fflush (stdout);
}
コード例 #2
0
ファイル: exec.cpp プロジェクト: TimePath/gmqcc
static void trace_print_global(qc_program_t *prog, unsigned int glob, int vtype) {
    static char spaces[28+1] = "                            ";
    prog_section_def_t *def;
    qcany_t    *value;
    int       len;

    if (!glob) {
        if ((len = printf("<null>,")) == -1)
            len = 0;

        goto done;
    }

    def = prog_getdef(prog, glob);
    value = (qcany_t*)(&prog->globals[glob]);

    len = printf("[@%u] ", glob);
    if (def) {
        const char *name = prog_getstring(prog, def->name);
        if (name[0] == '#')
            len += printf("$");
        else
            len += printf("%s ", name);
        vtype = def->type & DEF_TYPEMASK;
    }

    switch (vtype) {
        case TYPE_VOID:
        case TYPE_ENTITY:
        case TYPE_FIELD:
        case TYPE_FUNCTION:
        case TYPE_POINTER:
            len += printf("(%i),", value->_int);
            break;
        case TYPE_VECTOR:
            len += printf("'%g %g %g',", value->vector[0],
                                         value->vector[1],
                                         value->vector[2]);
            break;
        case TYPE_STRING:
            if (value->string)
                len += print_escaped_string(prog_getstring(prog, value->string), sizeof(spaces)-len-5);
            else
                len += printf("(null)");
            len += printf(",");
            /* len += printf("\"%s\",", prog_getstring(prog, value->string)); */
            break;
        case TYPE_FLOAT:
        default:
            len += printf("%g,", value->_float);
            break;
    }
done:
    if (len < (int)sizeof(spaces)-1) {
        spaces[sizeof(spaces)-1-len] = 0;
        fputs(spaces, stdout);
        spaces[sizeof(spaces)-1-len] = ' ';
    }
}
コード例 #3
0
static void
print_activity (struct activity *activity)
{
  if (activity->warning) ansi_red (); else ansi_green ();
  print_escaped_string (activity->name);
  ansi_restore ();
  printf (" %.1fms ±%.1fms ",
          activity->mean / 1000000, activity->sd / 1000000);
  if (activity->warning) ansi_red (); else ansi_green ();
  printf ("(%.1f%%) ", activity->percent);
  ansi_restore ();
}
コード例 #4
0
ファイル: utils.cpp プロジェクト: albertng/SmithWaterman
void print_token(std::ostream &stream, int token) {
  stream << token_to_string(token);

  switch(token) {
    case TINTCONST :
      stream << " = " << yylval.int_const;
      break;

    case TBOOLCONST :
      stream << " = " << (yylval.bool_const ? "true" : "false");
      break;

    case TIDENTIFIER :
      stream << " = " << *(yylval.id_name);
      break;

    case TERROR :
      stream << " = ";
      print_escaped_string(stream, *(yylval.error_msg));
      break;
  } 
}
コード例 #5
0
ファイル: comp_err.c プロジェクト: leafji/MYSQL_5.7
static int create_header_files(struct errors *error_head)
{
    FILE *er_definef, *sql_statef, *er_namef;
    struct errors *tmp_error;
    struct message *er_msg;
    const char *er_text;

    DBUG_ENTER("create_header_files");

    if (!(er_definef= my_fopen(HEADERFILE, O_WRONLY, MYF(MY_WME))))
    {
        DBUG_RETURN(1);
    }
    if (!(sql_statef= my_fopen(STATEFILE, O_WRONLY, MYF(MY_WME))))
    {
        my_fclose(er_definef, MYF(0));
        DBUG_RETURN(1);
    }
    if (!(er_namef= my_fopen(NAMEFILE, O_WRONLY, MYF(MY_WME))))
    {
        my_fclose(er_definef, MYF(0));
        my_fclose(sql_statef, MYF(0));
        DBUG_RETURN(1);
    }

    fprintf(er_definef, "/* Autogenerated file, please don't edit */\n\n");
    fprintf(sql_statef, "/* Autogenerated file, please don't edit */\n\n");
    fprintf(er_namef, "/* Autogenerated file, please don't edit */\n\n");

    fprintf(er_definef, "#ifndef MYSQLD_ERROR_INCLUDED\n");
    fprintf(er_definef, "#define MYSQLD_ERROR_INCLUDED\n\n");

    /*
      Find out how many sections of error messages we have, what the first
      number in each section is and the number of messages in each section.
    */
    {
        int error_code= error_head->d_code;
        int section_size[100]; /* Assume that 100 sections is enough. */
        int current_section= 0;
        int section_nr;
        section_size[0]= 0;
        fprintf(er_definef,
                "static const int errmsg_section_start[] = { %d", error_code);
        for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
        {
            if (tmp_error->d_code != error_code) /* Starting new section? */
            {
                fprintf(er_definef, ", %d", tmp_error->d_code);
                error_code= tmp_error->d_code;
                section_size[++current_section]= 0;
            }
            error_code++;
            section_size[current_section]++;
        }
        fprintf(er_definef, " };\n");

        fprintf(er_definef,
                "static const int errmsg_section_size[] = { %d", section_size[0]);
        for (section_nr= 1; section_nr <= current_section; section_nr++)
            fprintf(er_definef, ", %d", section_size[section_nr]);
        fprintf(er_definef, " };\n\n");
    }

    for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
    {
        /*
           generating mysqld_error.h
           fprintf() will automatically add \r on windows
        */
        fprintf(er_definef, "#define %s %d\n", tmp_error->er_name,
                tmp_error->d_code);

        /* generating sql_state.h file */
        if (tmp_error->sql_code1[0] || tmp_error->sql_code2[0])
            fprintf(sql_statef,
                    "{ %-40s,\"%s\", \"%s\" },\n", tmp_error->er_name,
                    tmp_error->sql_code1, tmp_error->sql_code2);
        /*generating er_name file */
        er_msg= find_message(tmp_error, default_language, 0);
        er_text = (er_msg ? er_msg->text : "");
        fprintf(er_namef, "{ \"%s\", %d, \"", tmp_error->er_name,
                tmp_error->d_code);
        print_escaped_string(er_namef, er_text);
        fprintf(er_namef, "\" },\n");
    }
    /* finishing off with mysqld_error.h */
    fprintf(er_definef, "#endif\n");
    my_fclose(er_definef, MYF(0));
    my_fclose(sql_statef, MYF(0));
    my_fclose(er_namef, MYF(0));
    DBUG_RETURN(0);
}
コード例 #6
0
ファイル: comp_err.c プロジェクト: hobbytp/percona-xtrabackup
static int create_header_files(struct errors *error_head)
{
  uint er_last= 0;
  FILE *er_definef, *sql_statef, *er_namef;
  struct errors *tmp_error;
  struct message *er_msg;
  const char *er_text;

  DBUG_ENTER("create_header_files");

  if (!(er_definef= my_fopen(HEADERFILE, O_WRONLY, MYF(MY_WME))))
  {
    DBUG_RETURN(1);
  }
  if (!(sql_statef= my_fopen(STATEFILE, O_WRONLY, MYF(MY_WME))))
  {
    my_fclose(er_definef, MYF(0));
    DBUG_RETURN(1);
  }
  if (!(er_namef= my_fopen(NAMEFILE, O_WRONLY, MYF(MY_WME))))
  {
    my_fclose(er_definef, MYF(0));
    my_fclose(sql_statef, MYF(0));
    DBUG_RETURN(1);
  }

  fprintf(er_definef, "/* Autogenerated file, please don't edit */\n\n");
  fprintf(sql_statef, "/* Autogenerated file, please don't edit */\n\n");
  fprintf(er_namef, "/* Autogenerated file, please don't edit */\n\n");

  fprintf(er_definef, "#define ER_ERROR_FIRST %d\n", error_head->d_code);

  for (tmp_error= error_head; tmp_error; tmp_error= tmp_error->next_error)
  {
    /*
       generating mysqld_error.h
       fprintf() will automatically add \r on windows
    */
    fprintf(er_definef, "#define %s %d\n", tmp_error->er_name,
	    tmp_error->d_code);
    er_last= tmp_error->d_code;

    /* generating sql_state.h file */
    if (tmp_error->sql_code1[0] || tmp_error->sql_code2[0])
      fprintf(sql_statef,
	      "{ %-40s,\"%s\", \"%s\" },\n", tmp_error->er_name,
	      tmp_error->sql_code1, tmp_error->sql_code2);
    /*generating er_name file */
    er_msg= find_message(tmp_error, default_language, 0);
    er_text = (er_msg ? er_msg->text : "");
    fprintf(er_namef, "{ \"%s\", %d, \"", tmp_error->er_name,
            tmp_error->d_code);
    print_escaped_string(er_namef, er_text);
    fprintf(er_namef, "\" },\n");
  }
  /* finishing off with mysqld_error.h */
  fprintf(er_definef, "#define ER_ERROR_LAST %d\n", er_last);
  my_fclose(er_definef, MYF(0));
  my_fclose(sql_statef, MYF(0));
  my_fclose(er_namef, MYF(0));
  DBUG_RETURN(0);
}
コード例 #7
0
ファイル: exec.cpp プロジェクト: TimePath/gmqcc
int main(int argc, char **argv) {
    size_t      i;
    qcint_t       fnmain = -1;
    qc_program_t *prog;
    size_t      xflags = VMXF_DEFAULT;
    bool        opts_printfields = false;
    bool        opts_printdefs   = false;
    bool        opts_printfuns   = false;
    bool        opts_disasm      = false;
    bool        opts_info        = false;
    bool        noexec           = false;
    const char *progsfile        = nullptr;
    const char **dis_list        = nullptr;
    int         opts_v           = 0;

    arg0 = argv[0];

    if (argc < 2) {
        usage();
        exit(EXIT_FAILURE);
    }

    while (argc > 1) {
        if (!strcmp(argv[1], "-h") ||
            !strcmp(argv[1], "-help") ||
            !strcmp(argv[1], "--help"))
        {
            usage();
            exit(EXIT_SUCCESS);
        }
        else if (!strcmp(argv[1], "-v")) {
            ++opts_v;
            --argc;
            ++argv;
        }
        else if (!strncmp(argv[1], "-vv", 3)) {
            const char *av = argv[1]+1;
            for (; *av; ++av) {
                if (*av == 'v')
                    ++opts_v;
                else {
                    usage();
                    exit(EXIT_FAILURE);
                }
            }
            --argc;
            ++argv;
        }
        else if (!strcmp(argv[1], "-version") ||
                 !strcmp(argv[1], "--version"))
        {
            version();
            exit(EXIT_SUCCESS);
        }
        else if (!strcmp(argv[1], "-trace")) {
            --argc;
            ++argv;
            xflags |= VMXF_TRACE;
        }
        else if (!strcmp(argv[1], "-profile")) {
            --argc;
            ++argv;
            xflags |= VMXF_PROFILE;
        }
        else if (!strcmp(argv[1], "-info")) {
            --argc;
            ++argv;
            opts_info = true;
            noexec = true;
        }
        else if (!strcmp(argv[1], "-disasm")) {
            --argc;
            ++argv;
            opts_disasm = true;
            noexec = true;
        }
        else if (!strcmp(argv[1], "-disasm-func")) {
            --argc;
            ++argv;
            if (argc <= 1) {
                usage();
                exit(EXIT_FAILURE);
            }
            vec_push(dis_list, argv[1]);
            --argc;
            ++argv;
            noexec = true;
        }
        else if (!strcmp(argv[1], "-printdefs")) {
            --argc;
            ++argv;
            opts_printdefs = true;
            noexec = true;
        }
        else if (!strcmp(argv[1], "-printfuns")) {
            --argc;
            ++argv;
            opts_printfuns = true;
            noexec = true;
        }
        else if (!strcmp(argv[1], "-printfields")) {
            --argc;
            ++argv;
            opts_printfields = true;
            noexec = true;
        }
        else if (!strcmp(argv[1], "-vector") ||
                 !strcmp(argv[1], "-string") ||
                 !strcmp(argv[1], "-float") )
        {
            qcvm_parameter p;
            if (argv[1][1] == 'f')
                p.vtype = TYPE_FLOAT;
            else if (argv[1][1] == 's')
                p.vtype = TYPE_STRING;
            else if (argv[1][1] == 'v')
                p.vtype = TYPE_VECTOR;
            else
                p.vtype = TYPE_VOID;

            --argc;
            ++argv;
            if (argc < 2) {
                usage();
                exit(EXIT_FAILURE);
            }
            p.value = argv[1];

            vec_push(main_params, p);
            --argc;
            ++argv;
        }
        else if (!strcmp(argv[1], "--")) {
            --argc;
            ++argv;
            break;
        }
        else if (argv[1][0] != '-') {
            if (progsfile) {
                fprintf(stderr, "only 1 program file may be specified\n");
                usage();
                exit(EXIT_FAILURE);
            }
            progsfile = argv[1];
            --argc;
            ++argv;
        }
        else
        {
            fprintf(stderr, "unknown parameter: %s\n", argv[1]);
            usage();
            exit(EXIT_FAILURE);
        }
    }

    if (argc == 2 && !progsfile) {
        progsfile = argv[1];
        --argc;
        ++argv;
    }

    if (!progsfile) {
        fprintf(stderr, "must specify a program to execute\n");
        usage();
        exit(EXIT_FAILURE);
    }

    prog = prog_load(progsfile, noexec);
    if (!prog) {
        fprintf(stderr, "failed to load program '%s'\n", progsfile);
        exit(EXIT_FAILURE);
    }

    prog->builtins       = qc_builtins;
    prog->builtins_count = GMQCC_ARRAY_COUNT(qc_builtins);

    if (opts_info) {
        printf("Program's system-checksum = 0x%04x\n", (unsigned int)prog->crc16);
        printf("Entity field space: %u\n", (unsigned int)prog->entityfields);
        printf("Globals: %zu\n", prog->globals.size());
        printf("Counts:\n"
               "      code: %zu\n"
               "      defs: %zu\n"
               "    fields: %zu\n"
               " functions: %zu\n"
               "   strings: %zu\n",
               prog->code.size(),
               prog->defs.size(),
               prog->fields.size(),
               prog->functions.size(),
               prog->strings.size());
    }

    if (opts_info) {
        prog_delete(prog);
        return 0;
    }
    for (i = 0; i < vec_size(dis_list); ++i) {
        size_t k;
        printf("Looking for `%s`\n", dis_list[i]);
        for (k = 1; k < prog->functions.size(); ++k) {
            const char *name = prog_getstring(prog, prog->functions[k].name);
            if (!strcmp(name, dis_list[i])) {
                prog_disasm_function(prog, k);
                break;
            }
        }
    }
    if (opts_disasm) {
        for (i = 1; i < prog->functions.size(); ++i)
            prog_disasm_function(prog, i);
        return 0;
    }
    if (opts_printdefs) {
        const char *getstring = nullptr;
        for (auto &it : prog->defs) {
            printf("Global: %8s %-16s at %u%s",
                   type_name[it.type & DEF_TYPEMASK],
                   prog_getstring(prog, it.name),
                   (unsigned int)it.offset,
                   ((it.type & DEF_SAVEGLOBAL) ? " [SAVE]" : ""));
            if (opts_v) {
                switch (it.type & DEF_TYPEMASK) {
                    case TYPE_FLOAT:
                        printf(" [init: %g]", ((qcany_t*)(&prog->globals[0] + it.offset))->_float);
                        break;
                    case TYPE_INTEGER:
                        printf(" [init: %i]", (int)( ((qcany_t*)(&prog->globals[0] + it.offset))->_int ));
                        break;
                    case TYPE_ENTITY:
                    case TYPE_FUNCTION:
                    case TYPE_FIELD:
                    case TYPE_POINTER:
                        printf(" [init: %u]", (unsigned)( ((qcany_t*)(&prog->globals[0] + it.offset))->_int ));
                        break;
                    case TYPE_STRING:
                        getstring = prog_getstring(prog, ((qcany_t*)(&prog->globals[0] + it.offset))->string);
                        printf(" [init: `");
                        print_escaped_string(getstring, strlen(getstring));
                        printf("`]\n");
                        break;
                    default:
                        break;
                }
            }
            printf("\n");
        }
    }
    if (opts_printfields) {
        for (auto &it : prog->fields) {
            printf("Field: %8s %-16s at %d%s\n",
                   type_name[it.type],
                   prog_getstring(prog, it.name),
                   it.offset,
                   ((it.type & DEF_SAVEGLOBAL) ? " [SAVE]" : ""));
        }
    }
    if (opts_printfuns) {
        for (auto &it : prog->functions) {
            int32_t a;
            printf("Function: %-16s taking %u parameters:(",
                   prog_getstring(prog, it.name),
                   (unsigned int)it.nargs);
            for (a = 0; a < it.nargs; ++a) {
                printf(" %i", it.argsize[a]);
            }
            if (opts_v > 1) {
                int32_t start = it.entry;
                if (start < 0)
                    printf(") builtin %i\n", (int)-start);
                else {
                    size_t funsize = 0;
                    prog_section_statement_t *st = &prog->code[0] + start;
                    for (;st->opcode != INSTR_DONE; ++st)
                        ++funsize;
                    printf(") - %zu instructions", funsize);
                    if (opts_v > 2) {
                        printf(" - locals: %i + %i\n",
                               it.firstlocal,
                               it.locals);
                    }
                    else
                        printf("\n");
                }
            }
            else if (opts_v) {
                printf(") locals: %i + %i\n",
                       it.firstlocal,
                       it.locals);
            }
            else
                printf(")\n");
        }
    }
    if (!noexec) {
        for (i = 1; i < prog->functions.size(); ++i) {
            const char *name = prog_getstring(prog, prog->functions[i].name);
            if (!strcmp(name, "main"))
                fnmain = (qcint_t)i;
        }
        if (fnmain > 0)
        {
            prog_main_setparams(prog);
            prog_exec(prog, &prog->functions[fnmain], xflags, VM_JUMPS_DEFAULT);
        }
        else
            fprintf(stderr, "No main function found\n");
    }

    prog_delete(prog);
    return 0;
}