Ejemplo n.º 1
0
	Inst *getInst(WorkSpace *ws, otawa::address_t address, Inst *source = 0) {
		try {
			Inst *inst = ws->findInstAt(address);
			if(!inst) {
				if(!source)
					cerr << "ERROR: unconsistant binary: no code segment at " << address << " from symbol\n";
				if(source->topAddress() == address)
					cerr << "ERROR: unconsistant binary: no code segment at " << address << " after instruction at " << source->address() << io::endl;
				else
					cerr << "ERROR: unconsistant binary: no code segment at " << address << "  target of branch at " << source->address() << io::endl;
				return 0;
			}
			else if(inst->isUnknown()) {
				cerr << "ERROR: ERROR: unknown instruction at " << address << ": ";
				int cnt = ws->process()->instSize();
				if(!cnt)
					cnt = 4;
				writeBytes(cerr, address, cnt);
				cerr << io::endl;
				return 0;
			}
			else
				return inst;
		}
		catch(otawa::DecodingException& e) {
			cerr << "ERROR: " << e.message()<< io::endl;
			return 0;
		}
	}
Ejemplo n.º 2
0
	virtual void work(PropList &props) throw (elm::Exception) {
		WorkSpace *ws = workspace();
		cerr << "DEBUG: verbose = " << isVerbose() << "\n";

		// put the symbols
		for(Process::FileIter file(workspace()->process()); file; file++)
			for(File::SymIter sym(file); sym; sym++) {
				if(sym->kind() == Symbol::FUNCTION || sym->kind() == Symbol::LABEL) {
					cerr << "DEBUG: code symbol: " << sym->name() << " (" << sym->address() << ")\n";
					Inst *inst = workspace()->findInstAt(sym->address());
					if(inst) {
						Symbol::ID(inst).add(*sym);
						switch(sym->kind()) {
						case Symbol::FUNCTION:
							FUNCTION_LABEL(inst).add(sym->name());
							break;
						case Symbol::LABEL:
							LABEL(inst).add(sym->name());
							break;
						default:
							break;
						}
					}
				}
			}
		cerr << "DEBUG: here\n";

		// Look the _start
		Inst *start = ws->start();
		if(start) {
			if(isVerbose())
				cerr << "ENTRY: processing entry at " << start->address() << io::endl;
			processEntry(ws, start->address());
		}
		else if(isVerbose())
			cerr << "no entry to process\n";

		// Look the function symbols
		for(Process::FileIter file(ws->process()); file; file++)
			for(File::SymIter sym(file); sym; sym++)
				if(sym->kind() == Symbol::FUNCTION) {
					if(IGNORE_ENTRY(sym))
						cerr << "\n\nINFO: ignoring function symbol \"" << sym->name() << "\"\n";
					else {
						cerr << "\n\nENTRY: processing function \"" << sym->name() << " at " << sym->address() << io::endl;
						Inst *inst = ws->findInstAt(sym->address());
						if(inst)
							processEntry(ws, sym->address());
						else
							cerr << "bad function symbol \"" << sym->name()
								   << "\" no code segment at " << sym->address() << io::endl;
					}
				}

		// dump the instructions
		for(Process::FileIter file(workspace()->process()); file; file++) {
			cout << "FILE: " << file->name() << io::endl;
			for(File::SegIter seg(file); seg; seg++) {
				cout << "SEGMENT: " << seg->name() << io::endl;
				for(Segment::ItemIter item(seg); item; item++) {
					Inst *inst = item->toInst();
					if(inst) {
						if(MARKER(inst))
							cout << io::endl;
						for(Identifier<Symbol *>::Getter sym(inst, Symbol::ID); sym; sym++)
							cout << "\t" << sym->name() << ":\n";
						cout << "\t\t" << inst->address() << "  ";
						if(inst->isUnknown()) {
							cout << "<unknown>:";
							writeBytes(cout, inst->address(), inst->size());
						}
						else
							cout << inst;
						if(MARKER(inst)) {
							bool fst = true;
							for(Identifier<Inst *>::Getter from(inst, FROM); from; from++) {
								cout << (fst ? "\tfrom " : ", ");
								fst = false;
								cout << from->address();
							}
						}
						cout << io::endl;
					}
				}
			}
			cout << "\n";
		}
	}