Пример #1
0
 void DisassemblerContext::print_exists(const ValuePtr<Exists>& term, bool bracket) {
   if (bracket)
     *m_output << '(';
   *m_output << "exists (";
   
   unsigned n_parameters = term->parameter_types().size();
   unsigned parameter_name_base = m_parameter_name_index;
   m_parameter_name_index += n_parameters;
   
   boost::format name_formatter("%%%s");
   
   m_parameter_names.push_back(ParameterNameList::value_type());
   ParameterNameList::value_type& name_list = m_parameter_names.back();
   for (unsigned ii = 0; ii != n_parameters; ++ii) {
     if (ii)
       *m_output << ", ";
     
     std::string name = str(name_formatter % (parameter_name_base + ii));
     *m_output << name << " : ";
     print_term(term->parameter_types()[ii], false);
     
     name_list.push_back(name);
   }
   
   *m_output << ") > ";
   
   print_term(term->result(), true);
   
   m_parameter_names.pop_back();
   m_parameter_name_index = parameter_name_base;
   
   if (bracket)
     *m_output << ')';
 }
Пример #2
0
void print_term(int address)
{
	int i;
	switch(HEAP[address].s1.kind)
	{
		case REF:
			if(HEAP[address].s1.addr == address)
				printf("_%d", address);
			else
				print_term(HEAP[address].s1.addr);
			break;
		case STR:
			address = HEAP[address].s1.addr;
			printf("%s", HEAP[address].s2.name);
			if(HEAP[address].s2.arity > 0)
			{
				printf("(");
				for(i=0; i<HEAP[address].s2.arity; i++)
				{
					print_term(address+1+i);
					if(i<HEAP[address].s2.arity-1)
						printf(", ");
				}
				printf(")");
			}
	}
}
Пример #3
0
static int term_test(IC_Env *env)
{
    ETERM *ti, *to, *tr;

    ti = erl_format("[{hej, 1, 23}, \"string\", {1.23, 45}]");

    fprintf(stdout, "\n======== m_i_term test ======\n\n");
    tr = m_i_term_test(NULL, ti, &to, env);
    CHECK_EXCEPTION(env);
    RETURN_IF_OK(erl_match(ti, to) && erl_match(ti, tr));
    if (!erl_match(ti, to)) {
	fprintf(stdout, " out parameter error, sent:\n");
	print_term(ti);
	fprintf(stdout, "got:\n");
	print_term(to);
    }
    if (!erl_match(ti, tr)) {
	fprintf(stdout, " result error, sent:\n");
	print_term(ti);
	fprintf(stdout, "got:\n");
	print_term(tr);
    }
    erl_free_term(ti);
    erl_free_term(to);
    erl_free_term(tr);
    return -1;
}
Пример #4
0
static int typedef_test(IC_Env *env)
{
    m_banan mbi, mbo;		/* erlang_port */
    m_apa mai;			/* ETERM* */
    m_apa mao = NULL;
    long tl;

    strcpy(mbi.node,"node");
    mbi.id = 15;
    mbi.creation = 1;

    fprintf(stdout, "\n======== m_i_typedef test ======\n\n");
    mai = erl_format("[{hej, 1, 23}, \"string\", {1.23, 45}]");
    tl = m_i_typedef_test(NULL, mai, &mbi, &mao, &mbo, env);
    CHECK_EXCEPTION(env);
    RETURN_IF_OK(erl_match(mai, mao) && cmp_port(&mbi, &mbo) && tl == 4711);
    if (!erl_match(mai, mao)) {
	fprintf(stdout, " out parameter error (term), sent:\n");
	print_term(mai);
	fprintf(stdout, "got:\n");
	print_term(mao);
    }
    if (!cmp_port(&mbi, &mbo)) {
	fprintf(stdout, " out parameter error (port), sent:\n");
	print_port(&mbi);
	fprintf(stdout, "got:\n");
	print_port(&mbo);
    }
    if (tl != 4711) {
	fprintf(stdout, " result error, sent: 4711, got %ld\n", tl);
    }
    erl_free_term(mai);
    erl_free_term(mao);
    return -1;
} 
Пример #5
0
    void DisassemblerContext::print_function_type_term(const ValuePtr<FunctionType>& term, bool bracket, const ValuePtr<Function>& use_names) {
      PSI_ASSERT(!use_names || (term->parameter_types().size() == use_names->parameters().size()));
      
      if (bracket)
        *m_output << '(';

      *m_output << "function";
      switch (term->calling_convention()) {
      case cconv_c: break;
      case cconv_x86_stdcall: *m_output << " cc_x86_stdcall";
      case cconv_x86_thiscall: *m_output << " cc_x86_thiscall";
      case cconv_x86_fastcall: *m_output << " cc_x86_fastcall";
      default: PSI_FAIL("Unknown calling convention in disassembler");
      }
      if (term->sret())
        *m_output << " sret";
      *m_output << " (";
      
      unsigned n_parameters = term->parameter_types().size();
      unsigned parameter_name_base = m_parameter_name_index;
      m_parameter_name_index += n_parameters;
      
      boost::format name_formatter("%%%s");
      
      m_parameter_names.push_back(ParameterNameList::value_type());
      ParameterNameList::value_type& name_list = m_parameter_names.back();
      for (unsigned ii = 0; ii != n_parameters; ++ii) {
        if (ii)
          *m_output << ", ";
        
        std::string name;
        if (use_names) {
          *m_output << TermNamePrinter(&m_names.find(use_names->parameters().at(ii))->second->name);
        } else {
          *m_output << name_formatter % (parameter_name_base + ii);
        }
        
        const ParameterType& ty = term->parameter_types()[ii];
        *m_output << " :";
        print_parameter_attributes(ty.attributes);
        *m_output << ' ';
        print_term(ty.value, false);
        
        name_list.push_back(name);
      }
      
      *m_output << ") >";
      print_parameter_attributes(term->result_type().attributes);
      *m_output << ' ';
      print_term(term->result_type().value, true);
      
      m_parameter_names.pop_back();
      m_parameter_name_index = parameter_name_base;
      
      if (bracket)
        *m_output << ')';
    }
Пример #6
0
 void DisassemblerContext::print_apply_term(const ValuePtr<ApplyType>& apply, bool bracket) {
   if (bracket)
     *m_output << '(';
   
   *m_output << "apply ";
   print_term(apply->recursive(), true);
   for (std::vector<ValuePtr<> >::const_iterator ii = apply->parameters().begin(), ie = apply->parameters().end(); ii != ie; ++ii) {
     *m_output << ' ';
     print_term(*ii, true);
   }
     
   if (bracket)
     *m_output << ')';
 }
static void
print_variable(Variable *var)
{
    GList *itr;

    printf("= Variable: %s =\n", var->name);

    printf("struct sml_object Variable: %p\n", var->sml_var);
    printf("Range %f - %f\n", var->min, var->max);
    printf("Current value: %f\n", var->cur_value);
    printf("Guess value: %f\n", var->guess_value);
    printf("Last event: %p\n", var->last_event);

    printf("Terms:\n");
    for (itr = var->terms; itr; itr = itr->next) {
        print_term(itr->data);
    }

    printf("Events:\n");
    for (itr = var->events; itr; itr = itr->next)
        print_event(itr->data);

    printf("Status Events:\n");
    for (itr = var->status_events; itr; itr = itr->next)
        print_status_event(itr->data);

    printf("====================\n");
}
Пример #8
0
void add_stuff(term *t, environment *env)
{
    if(t->kind == DEF){
        add_environment(env, t);
    }
    if(t->kind == IND){
        term **constructors = t->cases;
        t->cases = 0;
        int n = t->n;

        add_environment(env, t);
        int i;
        for (i = 0; i < n; ++i) {
            term *cons = constructors[i];
            evaluate_term(cons, env);
            add_environment(env, cons);
        }

        term *elim = make_eliminator(t, constructors, n);
        elim->annotation = type_infer(elim, 0, 0);
        printf("Automatically adding %s: ", elim->name);
        print_term(elim->annotation);
        printf("\n");
        add_environment(env, elim);
        for (i = 0; i < n; ++i) {
            free_term(constructors[i]);
        }
        free(constructors);
        free_term(elim);
    }
}
Пример #9
0
 void DisassemblerContext::print_phi_term(const ValuePtr<Phi>& term) {
   *m_output << "phi ";
   print_term(term->type(), true);
   *m_output << ": ";
   const std::vector<PhiEdge>& edges = term->edges();
   bool first = true;
   for (std::vector<PhiEdge>::const_iterator ii = edges.begin(), ie = edges.end(); ii != ie; ++ii) {
     if (first)
       first = false;
     else
       *m_output << ", ";
     *m_output << name(ii->block) << " > ";
     print_term(ii->value, true);
   }
   *m_output << ";\n";
 }
Пример #10
0
void dump_parse_post_compile(Term* term)
{
    std::cout << "dump_parse " << global_id(term) << ": ";
    for (int i=0; i < term->numInputs(); i++) {
        if (i != 0) std::cout << ", ";
        print_term(term->input(0), std::cout);
    }
    std::cout << std::endl;
}
Пример #11
0
void blazeit(FILE *input, environment *env)
{
    while(1){
        if(debug){
            printf("~ ");
            fflush(stdout);
        }
        char *line = fgetl(input);
        if(!line){
            printf("EOF\n");
            break;
        }
        term *t = parse_string(line);
        if (!t) continue;
        if (debug){
            printf("Input: ");
            print_term(t);
            printf("\n");
        }
        term *type = type_infer(t, env, 0);
        if (debug){
            printf("Type Check: ");
            print_term(type);
            printf("\n");
        }

        if(!type) fprintf(stderr, "Didn't Type Check!\n");
        evaluate_term(t, env);

        add_stuff(t, env);

        if(debug){
            printf("Output: ");
            print_term(t);
            printf("\n");
        }
        free_term(type);
        free_term(t);
        free(line);
    }
}
Пример #12
0
bool command::process(term & t)
{
	bool ret = false;
	term resp;
#ifdef PRINTCMD
	char * tmpbuf = print_term(command);
	REMOTE_LOG(DBG, "========================================\nCOMMAND : %s %s\n========================================\n",
		CMD_NAME_STR(ERL_INT_VALUE(cmd)),
		tmpbuf);
	delete tmpbuf;
#endif

	if(t.is_tuple() && t[1].is_integer()) {
        int cmd = t[1].v.i;
		resp.tuple();
		resp.add(t[0]);
		resp.insert().integer(cmd);
        if((t.length() - 1) != (size_t)CMD_ARGS_COUNT(cmd)) {
			term & _t = resp.insert().tuple();
	    	_t.insert().atom("error");
	    	_t.insert().atom("badarg");
	    	if(resp.is_undef())
                REMOTE_LOG(ERR, "ERROR badarg %s expected %d, got %d\n", CMD_NAME_STR(cmd)
                    , CMD_ARGS_COUNT(cmd), (t.length() - 1));
	        if(resp.is_undef()) REMOTE_LOG(CRT, "driver error: no resp generated, shutting down port\n");
            vector<unsigned char> respv = tc.encode(resp);
            p.write_cmd(respv);
	    } else {
		    switch(cmd) {
            case RMOTE_MSG:	ret = change_log_flag(t, resp);	break;
            case GET_SESSN:	ret = get_session(t, resp);		break;
            case PUT_SESSN:	ret = release_conn(t, resp);	break;
		    case CMT_SESSN:	ret = commit(t, resp);			break;
            case RBK_SESSN:	ret = rollback(t, resp);		break;
            case CMD_DSCRB:	ret = describe(t, resp);		break;
            case PREP_STMT:	ret = prep_sql(t, resp);		break;
            case BIND_ARGS:	ret = bind_args(t, resp);		break;
            case EXEC_STMT:	ret = exec_stmt(t, resp);		break;
            case FTCH_ROWS:	ret = fetch_rows(t, resp);		break;
            case CLSE_STMT:	ret = close_stmt(t, resp);		break;
            case GET_LOBDA:	ret = get_lob_data(t, resp);	break;
            case CMD_ECHOT:	ret = echo(t, resp);			break;
		    case SESN_PING:	ret = ping(t, resp);			break;
            default:
		    	ret = true;
                break;
            }
        }
    }

	return ret;
}
Пример #13
0
 void DisassemblerContext::print_recursive(const ValuePtr<RecursiveType>& term) {
   *m_output << "recursive (";
   
   boost::format name_formatter("%%%s");
   
   for (RecursiveType::ParameterList::const_iterator ib = term->parameters().begin(), ii = term->parameters().begin(), ie = term->parameters().end(); ii != ie; ++ii) {
     if (ii != ib)
       *m_output << ", ";
     
     *m_output << name(*ii) << " : ";
     print_term((*ii)->type(), false);
   }
   
   *m_output << ") > ";
   
   if (term->result())
     print_term(term->result(), true);
   else
     *m_output << "NULL";
   
   *m_output << ";\n";
 }
Пример #14
0
void log_domain_print_message(const gchar *domain, gchar *buf)
{
	gchar *buf_nl;
	regex_t regex;
	gint ret_comp, ret_exec;

	buf_nl = g_strconcat(buf, "\n", NULL);

	if (regexp && command_line)
		{
			ret_comp = regcomp(&regex, regexp, 0);
			if (!ret_comp)
				{
				ret_exec = regexec(&regex, buf_nl, 0, NULL, 0);

				if (!ret_exec)
					{
					print_term(FALSE, buf_nl);
					if (strcmp(domain, DOMAIN_INFO) == 0)
						g_idle_add(log_normal_cb, buf_nl);
					else
						g_idle_add(log_msg_cb, buf_nl);
					}
				regfree(&regex);
				}
		}
	else
		{
		print_term(FALSE, buf_nl);
		if (strcmp(domain, DOMAIN_INFO) == 0)
			g_idle_add(log_normal_cb, buf_nl);
		else
			g_idle_add(log_msg_cb, buf_nl);
		}
	g_free(buf);
}
Пример #15
0
int ei_s_print_term(char** s, const char* buf, int* index)
{
    int r;
    ei_x_buff x;
    if (*s != NULL) {
	x.buff = *s;
	x.index = 0;
	x.buffsz = BUFSIZ;
    } else {
	ei_x_new(&x);
    }
    r = print_term(NULL, &x, buf, index);
    ei_x_append_buf(&x, "", 1); /* append '\0' */
    *s = x.buff;
    return r;
}
Пример #16
0
// not used anymore
static void print_benchmark(FILE *f, smt_benchmark_t *bench) {
  uint32_t i, n;

  n = bench->nformulas;
  fprintf(f, "Benchmark %s\n", bench->name);
  fprintf(f, "Logic: %s\n", bench->logic_name);
  fprintf(f, "Parameter: %"PRId32"\n", bench->logic_parameter);
  fprintf(f, "Status: %s\n", status2string[bench->status]);
  fprintf(f, "Number of formulas or assumptions: %"PRIu32"\n", n);

  for (i=0; i<n; i++) {
    fprintf(f, "\n---- Assertion %"PRIu32" ----\n", i);
    print_term(f, bench->formulas[i]);
    fprintf(f, "\n");
  }
}
Пример #17
0
int ei_print_term(FILE *fp, const char* buf, int* index)
{
    return print_term(fp, NULL, buf, index);
}
Пример #18
0
static int print_term(FILE* fp, ei_x_buff* x,
			       const char* buf, int* index)
{
    int i, doquote, n, m, ty, r;
    char a[MAXATOMLEN], *p;
    int ch_written = 0;		/* counter of written chars */
    erlang_pid pid;
    erlang_port port;
    erlang_ref ref;
    double d;
    long l;

    int tindex = *index;

    /* use temporary index for multiple (and failable) decodes */

    if (fp == NULL && x == NULL) return -1;

    doquote = 0;
    ei_get_type_internal(buf, index, &ty, &n);
    switch (ty) {
    case ERL_ATOM_EXT:   
    case ERL_ATOM_UTF8_EXT:
    case ERL_SMALL_ATOM_EXT:
    case ERL_SMALL_ATOM_UTF8_EXT:
	if (ei_decode_atom(buf, index, a) < 0)
	   goto err;
	doquote = !islower((int)a[0]);
	for (p = a; !doquote && *p != '\0'; ++p)
	    doquote = !(isalnum((int)*p) || *p == '_' || *p == '@');
	if (doquote) {
	    xputc('\'', fp, x); ++ch_written; 
	}
	xputs(a, fp, x); ch_written += strlen(a);
	if (doquote) {
	    xputc('\'', fp, x); ++ch_written;
	}
	break;
    case ERL_PID_EXT:
    case ERL_NEW_PID_EXT:
	if (ei_decode_pid(buf, index, &pid) < 0) goto err;
	ch_written += xprintf(fp, x, "<%s.%d.%d>", pid.node,
			      pid.num, pid.serial);
	break;
    case ERL_PORT_EXT:
    case ERL_NEW_PORT_EXT:
	if (ei_decode_port(buf, index, &port) < 0) goto err;
	ch_written += xprintf(fp, x, "#Port<%d.%d>", port.id, port.creation);
	break;
    case ERL_NEW_REFERENCE_EXT:
    case ERL_NEWER_REFERENCE_EXT:
    case ERL_REFERENCE_EXT:
	if (ei_decode_ref(buf, index, &ref) < 0) goto err;
	ch_written += xprintf(fp, x, "#Ref<");
	for (i = 0; i < ref.len; ++i) {
	    ch_written += xprintf(fp, x, "%d", ref.n[i]);
	    if (i < ref.len - 1) {
		xputc('.', fp, x); ++ch_written;
	    }
	}
	xputc('>', fp, x); ++ch_written;
	break;
    case ERL_NIL_EXT:
	if (ei_decode_list_header(buf, index, &n) < 0) goto err;
	ch_written += xprintf(fp, x, "[]");
	break;
    case ERL_LIST_EXT:
	if (ei_decode_list_header(buf, &tindex, &n) < 0) goto err;
	xputc('[', fp, x); ch_written++;
	for (i = 0; i < n; ++i) {
	    r = print_term(fp, x, buf, &tindex);
	    if (r < 0) goto err;
	    ch_written += r;
	    if (i < n - 1) {
		xputs(", ", fp, x); ch_written += 2;
	    }
	}
	if (ei_get_type_internal(buf, &tindex, &ty, &n) < 0) goto err;
	if (ty != ERL_NIL_EXT) {
	    xputs(" | ", fp, x); ch_written += 3;
	    r = print_term(fp, x, buf, &tindex);
	    if (r < 0) goto err;
	    ch_written += r;
	} else {
	    if (ei_decode_list_header(buf, &tindex, &n) < 0) goto err;
	}
	xputc(']', fp, x); ch_written++;
	*index = tindex;
	break;
    case ERL_STRING_EXT:
	p = ei_malloc(n+1);
	if (p == NULL) goto err;
	if (ei_decode_string(buf, index, p) < 0) {
	    ei_free(p);
	    goto err;
	}
	ch_written += print_string(fp, x, p, n);
	ei_free(p);
	break;
    case ERL_SMALL_TUPLE_EXT:
    case ERL_LARGE_TUPLE_EXT:
	if (ei_decode_tuple_header(buf, &tindex, &n) < 0) goto err;
	xputc('{', fp, x); ch_written++;

	for (i = 0; i < n; ++i) {
	    r = print_term(fp, x, buf, &tindex);
	    if (r < 0) goto err;
	    ch_written += r;
	    if (i < n-1) {
		xputs(", ", fp, x); ch_written += 2;
	    }
	}
	*index = tindex;
	xputc('}', fp, x); ch_written++;
	break;
    case ERL_BINARY_EXT:
	p = ei_malloc(n);
	if (p == NULL) goto err;
	if (ei_decode_binary(buf, index, p, &l) < 0) {
	    ei_free(p);
	    goto err;
	}
	ch_written += xprintf(fp, x, "#Bin<");
	if (l > BINPRINTSIZE)
	    m = BINPRINTSIZE;
	else
	    m = l;
	--m;
	for (i = 0; i < m; ++i) {
	    ch_written += xprintf(fp, x, "%d,", p[i]);
	}
	ch_written += xprintf(fp, x, "%d", p[i]);
	if (l > BINPRINTSIZE)
	    ch_written += xprintf(fp, x, ",...");
	xputc('>', fp, x); ++ch_written;
	ei_free(p);
	break;
    case ERL_SMALL_INTEGER_EXT:
    case ERL_INTEGER_EXT:
	if (ei_decode_long(buf, index, &l) < 0) goto err;
	ch_written += xprintf(fp, x, "%ld", l);
	break;
    case ERL_SMALL_BIG_EXT:
    case ERL_LARGE_BIG_EXT:
        {
            erlang_big *b;
            char *ds;

            if ( (b = ei_alloc_big(n)) == NULL) goto err;

            if (ei_decode_big(buf, index, b) < 0) {
                ei_free_big(b);
                goto err;
            }
            
            if ( (ds = ei_big_to_str(b)) == NULL ) {
                ei_free_big(b);
                goto err;
            }
            
            ch_written += xprintf(fp, x, ds);
            free(ds);
            ei_free_big(b);
            
        }
        break;

    case ERL_FLOAT_EXT:
    case NEW_FLOAT_EXT:
	if (ei_decode_double(buf, index, &d) < 0) goto err;
	ch_written += xprintf(fp, x, "%f", d);
	break;
    default:
	goto err;
    }
    return ch_written;
 err:
    return -1;
}
Пример #19
0
void dump(Term* term)
{
    Value str;
    print_term(term, &str);
    std::cout << as_cstring(&str);
}
Пример #20
0
static void eval_mem_rules(double interval)
{
	long cmmpages_size, cmm_inc, cmm_dec, cmm_new;
	double free_memory, swaprate, apcr;
	char *procinfo_current, *procinfo_prev;

	procinfo_current = meminfo + history_current * meminfo_size;
	free_memory = get_proc_value(procinfo_current, "MemFree", ':');

	procinfo_current = vmstat + history_current * vmstat_size;
	procinfo_prev = vmstat + history_prev * vmstat_size;
	swaprate = (get_proc_value(procinfo_current, "pswpin", ' ') +
		    get_proc_value(procinfo_current, "pswpout", ' ') -
		    get_proc_value(procinfo_prev, "pswpin", ' ') -
		    get_proc_value(procinfo_prev, "pswpout", ' ')) /
		    interval;
	apcr = (get_proc_value(procinfo_current, "pgpgin", ' ') +
		get_proc_value(procinfo_current, "pgpgout", ' ') -
		get_proc_value(procinfo_prev, "pgpgin", ' ') -
		get_proc_value(procinfo_prev, "pgpgout", ' ')) /
		interval;

	cmmpages_size = get_cmmpages_size();
	symbols.apcr = apcr;			// apcr in 512 byte blocks / sec
	symbols.swaprate = swaprate;		// swaprate in 4K pages / sec
	symbols.freemem = free_memory / 1024;	// freemem in MB

	cmm_inc = eval_double(cfg.cmm_inc, &symbols);
	/* cmm_dec is optional */
	if (cfg.cmm_dec)
		cmm_dec = eval_double(cfg.cmm_dec, &symbols);
	else
		cmm_dec = cmm_inc;

	/* only use this for development and testing */
	if (debug && foreground == 1) {
		printf("------------------- Memory ------------------\n");
		printf("cmm_min: %ld\n", cfg.cmm_min);
		printf("cmm_max: %ld\n", cfg.cmm_max);
		printf("swaprate: %f\n", symbols.swaprate);
		printf("apcr: %f\n", symbols.apcr);
		printf("cmm_inc: %ld = ", cmm_inc);
		print_term(cfg.cmm_inc);
		printf("\n");
		printf("cmm_dec: %ld = ", cmm_dec);
		if (cfg.cmm_dec)
			print_term(cfg.cmm_dec);
		else
			print_term(cfg.cmm_inc);
		printf("\n");
		printf("free memory: %f MB\n", symbols.freemem);
		printf("---------------------------------------------\n");
		printf("cmm_pages: %ld\n", cmmpages_size);
		printf("---------------------------------------------\n");
		printf("memplug: ");
		print_term(cfg.memplug);
		printf("\n");
		printf("memunplug: ");
		print_term(cfg.memunplug);
		printf("\n");
		printf("---------------------------------------------\n");
	}

	cmm_new = cmmpages_size;
	/* Evaluate the memplug rule */
	if (eval_term(cfg.memplug, &symbols)) {
		if (cmm_dec < 0) {
			cpuplugd_error("cmm_dec went negative (%ld), set it "
				       "to 0.\n", cmm_dec);
			cmm_dec = 0;
		}
		cmm_new -= cmm_dec;
	/* Evaluate the memunplug rule only if memplug did not match */
	} else if (eval_term(cfg.memunplug, &symbols)) {
		if (cmm_inc < 0) {
			cpuplugd_error("cmm_inc went negative (%ld), set it "
				       "to 0.\n", cmm_inc);
			cmm_inc = 0;
		}
		cmm_new += cmm_inc;
	}
	if (cmm_new < cfg.cmm_min) {
		cpuplugd_debug("minimum memory limit is reached\n");
		cmm_new = cfg.cmm_min;
	}
	if (cmm_new > cfg.cmm_max) {
		cpuplugd_debug("maximum memory limit is reached\n");
		cmm_new = cfg.cmm_max;
	}
	if (cmm_new != cmmpages_size)
		set_cmm_pages(cmm_new);
}
Пример #21
0
static void eval_cpu_rules(void)
{
	double diffs[CPUSTATS], diffs_total, percent_factor;
	char *procinfo_current, *procinfo_prev;
	int cpu, nr_cpus, on_off;

	nr_cpus = get_numcpus();
	procinfo_current = cpustat + history_current * cpustat_size;
	procinfo_prev = cpustat + history_prev * cpustat_size;

	diffs[0] = get_proc_value(procinfo_current, "user", ' ') -
		   get_proc_value(procinfo_prev, "user", ' ');
	diffs[1] = get_proc_value(procinfo_current, "nice", ' ') -
		   get_proc_value(procinfo_prev, "nice", ' ');
	diffs[2] = get_proc_value(procinfo_current, "system", ' ') -
		   get_proc_value(procinfo_prev, "system", ' ');
	diffs[3] = get_proc_value(procinfo_current, "idle", ' ') -
		   get_proc_value(procinfo_prev, "idle", ' ');
	diffs[4] = get_proc_value(procinfo_current, "iowait", ' ') -
		   get_proc_value(procinfo_prev, "iowait", ' ');
	diffs[5] = get_proc_value(procinfo_current, "irq", ' ') -
		   get_proc_value(procinfo_prev, "irq", ' ');
	diffs[6] = get_proc_value(procinfo_current, "softirq", ' ') -
		   get_proc_value(procinfo_prev, "softirq", ' ');
	diffs[7] = get_proc_value(procinfo_current, "steal", ' ') -
		   get_proc_value(procinfo_prev, "steal", ' ');
	diffs[8] = get_proc_value(procinfo_current, "guest", ' ') -
		   get_proc_value(procinfo_prev, "guest", ' ');
	diffs[9] = get_proc_value(procinfo_current, "guest_nice", ' ') -
		   get_proc_value(procinfo_prev, "guest_nice", ' ');

	diffs_total = get_proc_value(procinfo_current, "total_ticks", ' ') -
		      get_proc_value(procinfo_prev, "total_ticks", ' ');
	if (diffs_total == 0)
		diffs_total = 1;

	symbols.loadavg = get_proc_value(procinfo_current, "loadavg", ' ');
	symbols.runnable_proc = get_proc_value(procinfo_current,
					       "runnable_proc", ' ');
	symbols.onumcpus = get_proc_value(procinfo_current, "onumcpus", ' ');

	percent_factor = 100 * symbols.onumcpus;
	symbols.user = (diffs[0] / diffs_total) * percent_factor;
	symbols.nice = (diffs[1] / diffs_total) * percent_factor;
	symbols.system = (diffs[2] / diffs_total) * percent_factor;
	symbols.idle = (diffs[3] / diffs_total) * percent_factor;
	symbols.iowait = (diffs[4] / diffs_total) * percent_factor;
	symbols.irq = (diffs[5] / diffs_total) * percent_factor;
	symbols.softirq = (diffs[6] / diffs_total) * percent_factor;
	symbols.steal = (diffs[7] / diffs_total) * percent_factor;
	symbols.guest = (diffs[8] / diffs_total) * percent_factor;
	symbols.guest_nice = (diffs[9] / diffs_total) * percent_factor;

	/* only use this for development and testing */
	cpuplugd_debug("cpustat values:\n%s", cpustat + history_current *
		       cpustat_size);
	if (debug && foreground == 1) {
		printf("-------------------- CPU --------------------\n");
		printf("cpu_min: %ld\n", cfg.cpu_min);
		printf("cpu_max: %ld\n", cfg.cpu_max);
		printf("loadavg: %f \n", symbols.loadavg);
		printf("user percent = %f\n", symbols.user);
		printf("nice percent = %f\n", symbols.nice);
		printf("system percent = %f\n", symbols.system);
		printf("idle percent = %f\n", symbols.idle);
		printf("iowait percent = %f\n", symbols.iowait);
		printf("irq percent = %f\n", symbols.irq);
		printf("softirq percent = %f\n", symbols.softirq);
		printf("steal percent = %f\n", symbols.steal);
		printf("guest percent = %f\n", symbols.guest);
		printf("guest_nice percent = %f\n", symbols.guest_nice);
		printf("numcpus %d\n", nr_cpus);
		printf("runnable_proc: %d\n", (int) symbols.runnable_proc);
		printf("---------------------------------------------\n");
		printf("onumcpus:   %d\n", (int) symbols.onumcpus);
		printf("---------------------------------------------\n");
		printf("hotplug: ");
		print_term(cfg.hotplug);
		printf("\n");
		printf("hotunplug: ");
		print_term(cfg.hotunplug);
		printf("\n");
		printf("---------------------------------------------\n");
	}

	on_off = 0;
	/* Evaluate the hotplug rule */
	if (eval_term(cfg.hotplug, &symbols))
		on_off++;
	/* Evaluate the hotunplug rule only if hotplug did not match */
	else if (eval_term(cfg.hotunplug, &symbols))
		on_off--;
	if (on_off > 0) {
		/* check the cpu nr limit */
		if (symbols.onumcpus + 1 > cfg.cpu_max) {
			/* cpu limit reached */
			cpuplugd_debug("maximum cpu limit is reached\n");
			return;
		}
		/* try to find a offline cpu */
		for (cpu = 0; cpu < nr_cpus; cpu++)
			if (is_online(cpu) == 0 && cpu_is_configured(cpu) != 0)
				break;
		if (cpu < nr_cpus) {
			cpuplugd_debug("cpu with id %d is currently offline "
				       "and will be enabled\n", cpu);
			if (hotplug(cpu) == -1)
				cpuplugd_debug("unable to find a cpu which "
					       "can be enabled\n");
		} else {
			/*
			 * In case we tried to enable a cpu but this failed.
			 * This is the case if a cpu is deconfigured
			 */
			cpuplugd_debug("unable to find a cpu which can "
				       "be enabled\n");
		}
	} else if (on_off < 0) {
		/* check cpu nr limit */
		if (symbols.onumcpus <= cfg.cpu_min) {
			cpuplugd_debug("minimum cpu limit is reached\n");
			return;
		}
		/* try to find a online cpu */
		for (cpu = get_numcpus() - 1; cpu >= 0; cpu--) {
			if (is_online(cpu) != 0)
				break;
		}
		if (cpu > 0) {
			cpuplugd_debug("cpu with id %d is currently online "
				       "and will be disabled\n", cpu);
			hotunplug(cpu);
		}
	}
}
Пример #22
0
int main() {

	int choice, len;
	int *p;
	char buf[2];
	char first_array[] = "first";
	char second_array[] = "second";
/*
	print_term("Rogue test\n\n");
	print_term("0 - End test\n");
	print_term("1 - NULL pointer dereference\n");
	print_term("2 - Access memory in Kseg0\n");
	print_term("3 - Operate a semaphore not in Useg3\n");
	print_term("4 - Request to delay for < 0 seconds\n");
	print_term("5 - Write to .text section\n");
	print_term("6 - Buffer overflow!\n");
*/
	do {
	  print_term("\nEnter your choice: ");
    len = read_term(buf);
		if (len > 2) len = 2;
		buf[1] = '\0';
		choice = to_num(buf);
	} while((choice < 0) || (choice > 6));

	switch (choice) {
    case 0:
		  print_term("Terminating gracefully...\n");
		  return 0;
		  break;

		case 1:
		  p = NULL;
			*p = 10;  /* Should kill the process */
			print_term("Should not get here!\n");
		  break;

		case 2:
		  p = (int *)(SEG1 + 4);
			*p = 10;
			print_term("Should not get here!\n");
		  break;

		case 3:
		  p = (int *)(SEG2 + (20 * PAGE_SIZE));
			*p = 0;  /* Should succeed */
			print_term("Set the semaphore to 0...\n");
			V(p, 1);    /* Should fail */
			print_term("Should not get here!\n");
		  break;

		case 4:
		  delay(-6);
			print_term("Should not get here!\n");
      break;

    case 5:
		  p = (int *)(SEG2 + 10);  /* This is in the .text section */
			*p = 42;
			print_term("Should not get here!\n");
			break;

    case 6:
		  print_term("\nfirst_array[] is ");
			print_term(first_array);
			print_term("\nsecond_array[] is ");
			print_term(second_array);

			print_term("\nnow enter a string longer than 6 characters...");
			read_term(first_array);

			print_term("\nnow first_array[] is ");
			print_term(first_array);
			print_term("\nand second_array[] is ");
			print_term(second_array);

      return 0;

		default:
      print_term("Should not get here...\n");
		  break;
	}

	print_term("Houston, we have a problem...\n");
	return 0;
}
Пример #23
0
 void DisassemblerContext::print_term_definition(const ValuePtr<>& term, bool global) {
   *m_output << name(term) << " = ";
   
   switch (term->term_type()) {
   case term_functional: {
     if (global)
       *m_output << "define ";
     print_functional_term(value_cast<FunctionalValue>(term), false);
     *m_output << ";\n";
     break;
   }
   
   case term_function_type: {
     if (global)
       *m_output << "define ";
     print_function_type_term(value_cast<FunctionType>(term), false);
     *m_output << ";\n";
     break;
   }
   
   case term_instruction: {
     print_instruction_term(value_cast<Instruction>(term));
     break;
   }
   
   case term_phi: {
     print_phi_term(value_cast<Phi>(term));
     break;
   }
   
   case term_global_variable: {
     ValuePtr<GlobalVariable> gvar = value_cast<GlobalVariable>(term);
     *m_output << "global ";
     if (gvar->constant())
       *m_output << "const ";
     print_term(gvar->value_type(), true);
     if (gvar->value()) {
       *m_output << ' ';
       print_term(gvar->value(), true);
     }
     *m_output << ";\n";
     return;
   }
   
   case term_function: {
     print_function(value_cast<Function>(term));
     return;
   }
   
   case term_function_parameter: {
     ValuePtr<FunctionParameter> parameter = value_cast<FunctionParameter>(term);
     ValuePtr<Function> function = parameter->function();
     unsigned n = 0;
     for (Function::ParameterList::const_iterator ii = function->parameters().begin(), ie = function->parameters().end(); ii != ie; ++ii, ++n) {
       if (parameter == *ii) {
         *m_output << "[function parameter " << n << "]\n";
         return;
       }
     }
     *m_output << "[invalid function parameter]\n";
     return;
   }
   
   case term_apply: {
     if (global)
       *m_output << "define ";
     print_apply_term(value_cast<ApplyType>(term), false);
     *m_output << ";\n";
     return;
   }
   
   case term_exists: {
     if (global)
       *m_output << "define ";
     print_exists(value_cast<Exists>(term), false);
     *m_output << ";\n";
     return;
   }
   
   case term_recursive: {
     print_recursive(value_cast<RecursiveType>(term));
     return;
   }
   
   case term_recursive_parameter: *m_output << "[recursive parameter]\n"; return;
   case term_parameter_placeholder: *m_output << "[parameter placeholder]\n"; return;
   case term_upref_null: *m_output << "upref_null\n"; return;
     
   default:
     PSI_FAIL("unexpected term type - cannot print a definition");
   }
 }
Пример #24
0
int print_term_and_free(FILE* stream, term* t) {
  int ans = print_term(stream, t);
  free_term(t);
  return ans;
}
Пример #25
0
void print_register(int i)
{
	printf("X%d = ", i);
	print_term(X[i].s1.addr);
	printf("\n");
}
Пример #26
0
void dump(Term* term)
{
    print_term(term, std::cout);
}
Пример #27
0
 void DisassemblerContext::print_functional_term(const ValuePtr<FunctionalValue>& term, bool bracket) {
   if (ValuePtr<BooleanValue> bool_value = dyn_cast<BooleanValue>(term)) {
     *m_output << (bool_value->value() ? "true" : "false");
   } else if (ValuePtr<IntegerType> int_type = dyn_cast<IntegerType>(term)) {
     if (!int_type->is_signed())
       *m_output << 'u';
     *m_output << 'i';
     const char *width;
     switch (int_type->width()) {
     case IntegerType::i8: width = "8"; break;
     case IntegerType::i16: width = "16"; break;
     case IntegerType::i32: width = "32"; break;
     case IntegerType::i64: width = "64"; break;
     case IntegerType::i128: width = "128"; break;
     case IntegerType::iptr: width = "ptr"; break;
     default: PSI_FAIL("unknown integer width");
     }
     *m_output << width;
   } else if (ValuePtr<IntegerValue> int_value = dyn_cast<IntegerValue>(term)) {
     ValuePtr<IntegerType> type = int_value->type();
     *m_output << '#';
     if (!type->is_signed())
       *m_output << 'u';
     char width;
     switch (type->width()) {
     case IntegerType::i8: width = 'b'; break;
     case IntegerType::i16: width = 's'; break;
     case IntegerType::i32: width = 'i'; break;
     case IntegerType::i64: width = 'l'; break;
     case IntegerType::i128: width = 'q'; break;
     case IntegerType::iptr: width = 'p'; break;
     default: PSI_FAIL("unknown integer width");
     }
     *m_output << width;
     int_value->value().print(error_context().bind(term->location()), *m_output, type->is_signed());
   } else if (ValuePtr<FloatType> float_type = dyn_cast<FloatType>(term)) {
     const char *width;
     switch (float_type->width()) {
     case FloatType::fp32: width = "fp32"; break;
     case FloatType::fp64: width = "fp64"; break;
     case FloatType::fp128: width = "fp128"; break;
     case FloatType::fp_x86_80: width = "fp-x86-80"; break;
     case FloatType::fp_ppc_128: width = "fp-ppc-128"; break;
     default: PSI_FAIL("unknown integer width");
     }
     *m_output << width;
   } else if (ValuePtr<ResolvedParameter> resolved_param = dyn_cast<ResolvedParameter>(term)) {
     ParameterNameList::reverse_iterator it = m_parameter_names.rbegin();
     if (resolved_param->depth() < m_parameter_names.size()) {
       std::advance(it, resolved_param->depth());
       PSI_ASSERT(resolved_param->index() < it->size());
       *m_output << (*it)[resolved_param->index()];
     } else {
       *m_output << "[unknown parameter : ";
       print_term(resolved_param->type(), false);
       *m_output << "]";
     }
   } else if (ValuePtr<UnwrapParameter> unwrap_param = dyn_cast<UnwrapParameter>(term)) {
     *m_output << "unwrap_param ";
     print_term(unwrap_param->value(), true);
     *m_output << " " << unwrap_param->index();
   } else {
     class MyVisitor : public FunctionalValueVisitor {
       DisassemblerContext *m_self;
       const char *m_operation;
       bool m_bracket;
       bool m_first;
       
     public:
       MyVisitor(DisassemblerContext *self, const char *operation, bool bracket)
       : m_self(self), m_operation(operation), m_bracket(bracket), m_first(true) {}
       
       virtual void next(const ValuePtr<>& ptr) {
         if (m_first) {
           if (m_bracket)
             *m_self->m_output << '(';
           *m_self->m_output << m_operation;
           m_first = false;
         }
         
         *m_self->m_output << ' ';
         m_self->print_term(ptr, true);
       }
       
       bool empty() const {return m_first;}
     };
     
     MyVisitor my_visitor(this, term->operation_name(), bracket);
     term->functional_visit(my_visitor);
     
     if (my_visitor.empty()) {
       *m_output << term->operation_name();
     } else if (bracket) {
       *m_output << ')';
     }
   }
 }