void symex_slicet::slice(symex_target_equationt::SSA_stept &SSA_step) { get_symbols(SSA_step.guard_expr); switch(SSA_step.type) { case goto_trace_stept::ASSERT: get_symbols(SSA_step.cond_expr); break; case goto_trace_stept::ASSUME: get_symbols(SSA_step.cond_expr); break; case goto_trace_stept::LOCATION: // ignore break; case goto_trace_stept::ASSIGNMENT: slice_assignment(SSA_step); break; case goto_trace_stept::OUTPUT: break; default: assert(false); } }
void symex_slicet::get_symbols(const exprt &expr) { get_symbols(expr.type()); forall_operands(it, expr) get_symbols(*it); if(expr.id()==ID_symbol) depends.insert(to_symbol_expr(expr).get_identifier()); }
void symex_slicet::slice(symex_target_equationt::SSA_stept &SSA_step) { get_symbols(SSA_step.guard); switch(SSA_step.type) { case goto_trace_stept::ASSERT: get_symbols(SSA_step.cond_expr); break; case goto_trace_stept::ASSUME: get_symbols(SSA_step.cond_expr); break; case goto_trace_stept::LOCATION: // ignore break; case goto_trace_stept::ASSIGNMENT: slice_assignment(SSA_step); break; case goto_trace_stept::DECL: slice_decl(SSA_step); break; case goto_trace_stept::OUTPUT: case goto_trace_stept::INPUT: break; case goto_trace_stept::DEAD: // ignore for now break; case goto_trace_stept::CONSTRAINT: case goto_trace_stept::SHARED_READ: case goto_trace_stept::SHARED_WRITE: case goto_trace_stept::ATOMIC_BEGIN: case goto_trace_stept::ATOMIC_END: case goto_trace_stept::SPAWN: case goto_trace_stept::MEMORY_BARRIER: // ignore for now break; case goto_trace_stept::FUNCTION_CALL: case goto_trace_stept::FUNCTION_RETURN: // ignore for now break; default: assert(false); } }
test_data_generator::test_data_generator() : symbols_(get_symbols()), gen_((std::random_device())()), sym_distr_(0, symbols_.size() - 1), size_distr_(10, 100) { }
void symex_slicet::collect_open_variables( const symex_target_equationt &equation, symbol_sett &open_variables) { symbol_sett lhs; for(symex_target_equationt::SSA_stepst::const_iterator it=equation.SSA_steps.begin(); it!=equation.SSA_steps.end(); it++) { const symex_target_equationt::SSA_stept &SSA_step=*it; get_symbols(SSA_step.guard_expr); switch(SSA_step.type) { case goto_trace_stept::ASSERT: get_symbols(SSA_step.cond_expr); break; case goto_trace_stept::ASSUME: get_symbols(SSA_step.cond_expr); break; case goto_trace_stept::LOCATION: // ignore break; case goto_trace_stept::ASSIGNMENT: get_symbols(SSA_step.rhs); lhs.insert(SSA_step.lhs.get(ID_identifier)); break; case goto_trace_stept::OUTPUT: break; default: assert(false); } } open_variables=depends; // remove the ones that are defined open_variables.erase(lhs.begin(), lhs.end()); }
bool cbmc_dimacst::write_dimacs(std::ostream &out) { dynamic_cast<dimacs_cnft&>(prop).write_dimacs_cnf(out); // we dump the mapping variable<->literals for(bv_cbmct::symbolst::const_iterator s_it=get_symbols().begin(); s_it!=get_symbols().end(); s_it++) { if(s_it->second.is_constant()) out << "c " << (s_it->second.is_true()?"TRUE":"FALSE") << " " << s_it->first << "\n"; else out << "c " << s_it->second.dimacs() << " " << s_it->first << "\n"; } // dump mapping for selected bit-vectors const boolbv_mapt &boolbv_map=get_map(); for(boolbv_mapt::mappingt::const_iterator m_it=boolbv_map.mapping.begin(); m_it!=boolbv_map.mapping.end(); m_it++) { if(m_it->second.bvtype==IS_SIGNED || m_it->second.bvtype==IS_UNSIGNED) { const boolbv_mapt::literal_mapt &literal_map=m_it->second.literal_map; out << "c " << m_it->first; for(unsigned i=0; i<literal_map.size(); i++) if(!literal_map[i].is_set) out << " " << "?"; else if(literal_map[i].l.is_constant()) out << " " << (literal_map[i].l.is_true()?"TRUE":"FALSE"); else out << " " << literal_map[i].l.dimacs(); out << "\n"; } } return false; }
void symex_slicet::slice( symex_target_equationt &equation, const expr_listt &exprs) { // collect dependencies forall_expr_list(expr_it, exprs) get_symbols(*expr_it); slice(equation); }
void path_slicert::get_symbols(const exprt &expr, string_sett &s) { if(expr.id()==ID_symbol) { s.insert(to_symbol_expr(expr).get_identifier()); } else if(expr.id()==ID_index) { assert(expr.operands().size()==2); string_sett tmp; get_symbols(expr.op0(), tmp); get_symbols(expr.op1(), s); for(string_sett::const_iterator it=tmp.begin(); it!=tmp.end(); it++) s.insert(id2string(*it)+"[]"); } else if(expr.id()==ID_member) { assert(expr.operands().size()==1); string_sett tmp; get_symbols(expr.op0(), tmp); std::string suffix="."+expr.get_string(ID_component_name); for(string_sett::const_iterator it=tmp.begin(); it!=tmp.end(); it++) s.insert(id2string(*it)+suffix); } else forall_operands(it, expr) get_symbols(*it, s); }
static void get_months(const UDateFormat *fmt, UChar *months [], UBool useLongNames, UErrorCode *status) { UDateFormatSymbolType monthType = (useLongNames ? UDAT_MONTHS : UDAT_SHORT_MONTHS); if(U_FAILURE(*status)) return; get_symbols(fmt, monthType, months, MONTH_COUNT - 1, 0, 0, status); /* some locales have 13 months, no idea why */ }
void symex_slicet::slice_assignment( symex_target_equationt::SSA_stept &SSA_step) { assert(SSA_step.lhs.id()==ID_symbol); const irep_idt &id=SSA_step.lhs.get(ID_identifier); if(depends.find(id)==depends.end()) { // we don't really need it SSA_step.ignore=true; } else get_symbols(SSA_step.rhs); }
void reflectable_descriptor::write_value(const void* source_ptr, symbol& target_symbol) const { // ensure target is a symbols value if (!is_symbols(target_symbol)) target_symbol = symbols({}); // get type to write VAR& symbols = get_symbols(target_symbol); VAL* reflectable_ptr = static_cast<const reflectable*>(source_ptr); VAL& reflectable = *reflectable_ptr; VAL& type = get_type(reflectable); // write values write_value_internal(type, reflectable, symbols); }
int get_args(char* filename, args_t* args) { FILE* fp; int ret = 0; if ((fp = fopen(filename, "r")) != NULL) { ret = get_mode(fp, args) && get_states(fp, args) && get_symbols(fp, args) && get_transitions(fp, args); fclose(fp); } return ret; }
static void get_days(const UDateFormat *fmt, UChar *days [], UBool useLongNames, int32_t fdow, UErrorCode *status) { UDateFormatSymbolType dayType = (useLongNames ? UDAT_WEEKDAYS : UDAT_SHORT_WEEKDAYS); if(U_FAILURE(*status)) return; /* fdow is 1-based */ --fdow; get_symbols(fmt, dayType, days, DAY_COUNT, 1, fdow, status); }
int _bmlw_setup (BMLDebugLogger logger) { ldt_fs = Setup_LDT_Keeper (); TRACE (" wrapper initialized: 0x%p\n", ldt_fs); //Check_FS_Segment(ldt_fs); if (!(emu_dll = LoadDLL ("BuzzMachineLoader.dll"))) { TRACE (" failed to load window bml\n"); return FALSE; } TRACE (" windows bml loaded\n"); if (!get_symbols (emu_dll, api, sizeof (api) / sizeof (api[0]))) { return FALSE; } TRACE (" symbols connected\n"); BMLX (bmlw_set_logger (logger)); return TRUE; }
bool path_slicert::depends_lhs_rec( const exprt &expr, const string_sett &suffixes_r, const string_sett &suffixes_w, string_sett &dependencies, string_sett &new_dependencies) { if(expr.id()==ID_symbol) { string_sett tmp_r, tmp_w; const irep_idt &id=to_symbol_expr(expr).get_identifier(); for(string_sett::const_iterator it=suffixes_w.begin(); it!=suffixes_w.end(); it++) tmp_w.insert(id2string(id)+id2string(*it)); for(string_sett::const_iterator it=suffixes_r.begin(); it!=suffixes_r.end(); it++) { tmp_r.insert(id2string(id)+id2string(*it)); #ifdef DEBUG std::cout << "tmp_r: " << id2string(id)+id2string(*it) << std::endl; #endif } // do we depend on it? if(!depends(tmp_r, dependencies)) { #ifdef DEBUG std::cout << "NO DEPN\n"; #endif return false; // no! } #ifdef DEBUG std::cout << "DEP!\n"; #endif // yes! but we no longer do. for(string_sett::const_iterator it=tmp_w.begin(); it!=tmp_w.end(); it++) dependencies.erase(*it); } else if(expr.id()==ID_index) { assert(expr.operands().size()==2); get_symbols(expr.op0(), new_dependencies); get_symbols(expr.op1(), new_dependencies); string_sett tmp_r, tmp_w; for(string_sett::const_iterator it=suffixes_r.begin(); it!=suffixes_r.end(); it++) { tmp_r.insert(*it); tmp_r.insert("[]"+id2string(*it)); } // can't get rid of array depenencies // thus, tmp_w stays empty return depends_lhs_rec(expr.op0(), tmp_r, tmp_w, dependencies, new_dependencies); } else if(expr.id()==ID_member) { assert(expr.operands().size()==1); string_sett tmp_r, tmp_w; for(string_sett::const_iterator it=suffixes_r.begin(); it!=suffixes_r.end(); it++) { tmp_r.insert(*it); tmp_r.insert("."+expr.get_string("component_name")+id2string(*it)); } for(string_sett::const_iterator it=suffixes_w.begin(); it!=suffixes_w.end(); it++) { tmp_w.insert("."+expr.get_string("component_name")+id2string(*it)); } return depends_lhs_rec(expr.op0(), tmp_r, tmp_w, dependencies, new_dependencies); } return true; }
static enum ld_plugin_status get_symbols_v2 (const void *handle, int nsyms, struct ld_plugin_symbol *syms) { return get_symbols (handle, nsyms, syms, LDPR_PREVAILING_DEF_IRONLY_EXP); }
void do_ranlib (const char *archive) { FILE *infp; if (NULL == (infp = fopen (archive, "rb"))) { fprintf (stderr, "pBlazRanLib: %s: ", archive); perror (NULL); exit (1); } if (!get_symbols (infp)) { fprintf (stderr, "pBlazRanLib: %s: Malformed archive\n", archive); fclose (infp); exit (1); } else if (!list && !print_index) { FILE *outfp; struct symbol_s *symp; char buf[4]; int str_length; int pad; int nsym; int symtab_size; char tmpfile[] = "arXXXXXX"; struct stat stat_buf; int can_stat; #ifdef _WIN32 if (NULL == _mktemp (tmpfile) || NULL == (outfp = fopen (tmpfile, "wb"))) { fclose (infp); fprintf (stderr, "pBlazRanLib: %s: ", tmpfile); perror (NULL); exit (1); } #else if ((pad = mkstemp (tmpfile)) < 0) { fclose (infp); fprintf (stderr, "pBlazRanLib: %s: ", tmpfile); perror (NULL); exit (1); } if (NULL == (outfp = fdopen (pad, "wb"))) { close (pad); fclose (infp); perror ("pBlazRanLib"); exit (1); } #endif /* calculate the size of symbol table */ for (str_length = 0, nsym = 0, symp = symlist; symp; ++nsym, symp = symp->next) { str_length += strlen (symp->name) + 1; } symtab_size = 4 + 4 * nsym + str_length; fprintf (outfp, ARMAG AR_SYMBOL_TABLE_NAME "%-12d%-6d%-6d%-8d%-10d" ARFMAG, (int) time (NULL), 0, 0, 0, symtab_size); if (symtab_size & 1) { pad = 1; ++symtab_size; } else pad = 0; symtab_size += SARMAG + ARHDR_LEN; sputl (nsym, buf); fwrite (buf, 1, sizeof (buf), outfp); for (symp = symlist; symp; symp = symp->next) { sputl (symp->offset + symtab_size, buf); fwrite (buf, 1, sizeof (buf), outfp); } for (symp = symlist; symp; symp = symp->next) { fputs (symp->name, outfp); putc ('\0', outfp); } if (pad) putc ('\n', outfp); fseek (infp, first_member_offset, SEEK_SET); while (EOF != (pad = getc (infp))) putc (pad, outfp); fclose (outfp); if (0 != fstat(fileno(infp), &stat_buf)) { fprintf (stderr, "pBlazRanLib: can't stat %s: ", archive); perror (NULL); fclose (infp); can_stat = 0; } else can_stat = 1; fclose (infp); if (0 != remove (archive)) { fprintf (stderr, "pBlazRanLib: can't remove %s: ", archive); perror (NULL); } else if (0 != rename (tmpfile, archive)) { fprintf (stderr, "pBlazRanLib: can't rename %s to %s: ", tmpfile, archive); perror (NULL); } else if (!can_stat || 0 != chmod (archive, stat_buf.st_mode)) { fprintf (stderr, "pBlazRanLib: can't chmod %s: ", archive); perror (NULL); } } else fclose (infp); }
void add_dependencies(const exprt &expr, string_sett &dest) { get_symbols(expr, dest); }
int main(int argc, char **argv, char **envp) { bfd *bf; int out_fd = 0; /* Get the input arguments */ parse_args(argc, argv); /* Make sure that we can option the BFD file */ dbg("Opening BFD file: %s\n", bfd_filename); if (!(bf = bfd_openr(bfd_filename, 0))) { fprintf(stderr, "Failed to open BFD file: %s, errno=%d\n", bfd_filename, errno); exit(2); } dbg("Checking format\n"); if (bfd_check_format(bf, bfd_object) == 0) { fprintf(stderr, "BFD file %s is not an object file\n", bfd_filename); exit(3); } dbg("Loading symbol table from BFD file %s\n", bfd_filename); symbol_table = get_symbols(bf, &number_of_symbols); /* Count the number of undefined function symbols */ (void)traverse_undefined_functions(NULL, count_undefined); /* Check if the module calls any non-returning functions (like exit). These * will require some additional setup. */ check_for_nonreturning_functions(); /* Make sure that we can open the output file if one is specified. If no * out_filename is specified, we'll use stdout. */ if (out_filename) { out_fd = open(out_filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (out_fd < 0) { fprintf(stderr, "Failed to open output file: %s, errno=%d\n", out_filename, errno); exit(4); } } /* Output the thunk file in three pieces: 1. The constant file prologue 2. * Library path information (if any) 3. Library file name information (if * any) 4. Exported symbole information (if any) 5. Imported symbole * information (if any) 6. The constant file epilogue. */ put_file_prologue(out_fd); put_import_name_strtab(out_fd); put_all_nxflat_import(out_fd); put_file_epilogue(out_fd); if (out_fd > 0) close(out_fd); exit(0); }
/* archive file (*.a) loading test */ int main() { int ret; int symnum; bfd* abfd; asymbol** syms; int symbol_pos, symbol_size; int index; #ifndef OBJ_TEST const char* file = "foo.a"; #else const char* file = "hello.o"; #endif unsigned char* file_o; file_o = load_file(file); abfd = bfd_openr(file, NULL); assert(abfd); ret = bfd_check_format(abfd, bfd_archive); //ret = bfd_check_format(abfd, bfd_object); assert(ret); #ifndef OBJ_TEST bfd* b = NULL; #else bfd* b = abfd;//NULL; #endif link_list_t* bfds = NULL; STEP_LOG("create function map\n"); #ifndef OBJ_TEST while(NULL != (b = bfd_openr_next_archived_file(abfd, b))) #endif { ret = bfd_check_format(b, bfd_object); assert(ret); // STEP_LOG("next\n"); if (!(bfd_get_file_flags(b) & HAS_SYMS)) { assert(bfd_get_error() == bfd_error_no_error); /* no symbol */ bfd_close(abfd); return 1; } if (NULL == bfds) { LOG("Add first:0x%08X\n", (int)b); bfds = add_item(bfds, &b, sizeof(b)); } else { LOG("Add bfd:0x%08X\n", (int)b); add_item(bfds, &b, sizeof(b)); } get_symbols(&syms, &symnum, b); create_symbol_function_pos(file_o, b, syms, symnum); } STEP_LOG("relocate function addresses\n"); link_list_t* list = bfds; while(NULL != list) { b = *(bfd**)(list->item); get_symbols(&syms, &symnum, b); reloc_file(file_o, b, syms); list = list->next; } STEP_LOG("try to get function addressses\n"); int (*func)(); void (*func1)(const char*); func = NULL; func1 = NULL; list = bfds; while(NULL != list) { b = *(bfd**)(list->item); LOG("bfd:0x%08X\n", (int)b); LOG("call goodby...."); get_symbols(&syms, &symnum, b); symbol_pos = get_symbol_pos("goodby", b, syms, symnum, file_o); if (0 != symbol_pos) { func = (int (*) ())(get_function(symbol_pos)); } LOG("call hello_someone...."); symbol_pos = get_symbol_pos("hello_someone", b, syms, symnum, file_o); if (0 != symbol_pos) { func1 = (void (*) (const char*))(get_function(symbol_pos)); } if (NULL != func && NULL != func1) break; list = list->next; } STEP_LOG("try to call functions\n"); if (NULL != func) { func(); } else { LOG("failed to call func\n"); } if (NULL != func1) { func1("WORLD!"); } else { LOG("failed to call func\n"); } delete_all_items(bfds); free(syms); bfd_close(abfd); free(file_o); return 0; }
static bool depends(const exprt &expr, const string_sett &dependencies) { string_sett tmp; get_symbols(expr, tmp); return depends(tmp, dependencies); }
void init_game() { struct array_mem_small *msmall; struct array_mem_mid *mmid; struct array_mem_norm *mlarge; struct Process *proc; struct instruction_node *in; struct process_thread *pthread; struct process_task *ptask; int next_offs,proc_offs,pos; double xx,lato_x,lato_y; if(arena_mem_type==MEM_TYPE_ONE) { msmall=(struct array_mem_small*)malloc(sizeof(struct array_mem_small)*size_arena); if(msmall==NULL) die("error malloking small array mem"); bzero(msmall,sizeof(struct array_mem_small)*size_arena); arena=msmall; } if(arena_mem_type==MEM_TYPE_TWO) { mmid=(struct array_mem_mid*)malloc(sizeof(struct array_mem_mid)*size_arena); if(mmid==NULL) die("error malloking mid array mem"); bzero(mmid,sizeof(struct array_mem_mid)*size_arena); arena=mmid; } if(arena_mem_type==MEM_TYPE_FOUR) { mlarge=(struct array_mem_norm*)malloc(sizeof(struct array_mem_norm)*size_arena); if(mlarge==NULL) die("error malloking large array mem"); bzero(mlarge,sizeof(struct array_mem_norm)*size_arena); arena=mlarge; } next_offs=0; for(proc=proc_primo;proc;proc=proc->next) { //calc offset in mem proc_offs=(next_offs+(rand()%min_distance))%size_arena; //put in mem pos=proc_offs; for(in=proc->pc->first;in;in=in->next) { putcode(pos++,proc->processID,in->code); } //create pt pthread=(struct process_thread*)malloc(sizeof(struct process_thread)); if(pthread==NULL) die("error alloking new thread"); pthread->IP=proc_offs+(atoi(proc->pc->org)); pthread->communication_in_a=0; pthread->communication_out_a=0; pthread->communication_in_b=0; pthread->communication_out_b=0; pthread->prev=NULL; pthread->next=NULL; pthread->ptask=NULL; ptask=(struct process_task*)malloc(sizeof(struct process_task)); if(ptask==NULL) die("error alloking new task"); ptask->ID=proc->processID; ptask->n_threads=1; ptask->prev=NULL; ptask->next=NULL; ptask->primo_thread=NULL; ptask->ultimo_thread=NULL; ptask->cur_thread=pthread; ptask->communication_in_a=0; ptask->communication_out_a=0; ptask->communication_in_b=0; ptask->communication_out_b=0; get_symbols(&ptask->out_symbol,&ptask->out_color); //add pt add_thread(pthread,ptask); add_task(ptask); //recalc next_offs next_offs+=proc_offs+proc->pc->len; //free proc&pc in=proc->pc->first; do{ if(in->left) free_expr(in->left); if(in->right) free_expr(in->right); if(in->code) free(in->code); if(in->next) {in=in->next;free(in->prev);} else {free(in);in=NULL;} }while(in!=NULL); } xx=sqrt(size_arena); lato_y=rint(xx); lato_x=ceil(xx); max_x=(int)lato_x; max_y=(int)lato_y; if(output_mode>=OUTPUT_DEBUG) { sprintf(out_str,"max_x=%d max_y=%d\n",max_x,max_y); fputs(out_str,fpout); } //init_graph if(vo_mode==VO_FRAMEBUFFER) init_txt(); if(vo_mode==VO_X11) init_x11(); }
void symex_slicet::collect_open_variables( const symex_target_equationt &equation, symbol_sett &open_variables) { symbol_sett lhs; for(symex_target_equationt::SSA_stepst::const_iterator it=equation.SSA_steps.begin(); it!=equation.SSA_steps.end(); it++) { const symex_target_equationt::SSA_stept &SSA_step=*it; get_symbols(SSA_step.guard); switch(SSA_step.type) { case goto_trace_stept::ASSERT: get_symbols(SSA_step.cond_expr); break; case goto_trace_stept::ASSUME: get_symbols(SSA_step.cond_expr); break; case goto_trace_stept::LOCATION: // ignore break; case goto_trace_stept::ASSIGNMENT: get_symbols(SSA_step.ssa_rhs); lhs.insert(SSA_step.ssa_lhs.get_identifier()); break; case goto_trace_stept::OUTPUT: case goto_trace_stept::INPUT: case goto_trace_stept::DEAD: case goto_trace_stept::NONE: break; case goto_trace_stept::DECL: case goto_trace_stept::FUNCTION_CALL: case goto_trace_stept::FUNCTION_RETURN: case goto_trace_stept::CONSTRAINT: case goto_trace_stept::SHARED_READ: case goto_trace_stept::SHARED_WRITE: case goto_trace_stept::ATOMIC_BEGIN: case goto_trace_stept::ATOMIC_END: case goto_trace_stept::SPAWN: case goto_trace_stept::MEMORY_BARRIER: // ignore for now break; default: assert(false); } } open_variables=depends; // remove the ones that are defined open_variables.erase(lhs.begin(), lhs.end()); }