本文整理汇总了C++中Trace类的典型用法代码示例。如果您正苦于以下问题:C++ Trace类的具体用法?C++ Trace怎么用?C++ Trace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Trace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EndAnalyze
void CfdAnalyzer::Analyze(Trace &trace, const std::string &detType,
const std::string &detSubtype,
const std::map<std::string, int> & tagMap) {
TraceAnalyzer::Analyze(trace, detType, detSubtype, tagMap);
Globals *globals = Globals::get();
unsigned int saturation = (unsigned int)trace.GetValue("saturation");
if(saturation > 0) {
EndAnalyze();
return;
}
double aveBaseline = trace.GetValue("baseline");
unsigned int maxPos = (unsigned int)trace.GetValue("maxpos");
pair<unsigned int, unsigned int> range = globals->waveformRange("default");
unsigned int waveformLow = range.first;
unsigned int waveformHigh = range.second;
unsigned int delay = 2;
double fraction = 0.25;
vector<double> cfd;
Trace::iterator cfdStart = trace.begin();
advance(cfdStart, (int)(maxPos - waveformLow - 2));
Trace::iterator cfdStop = trace.begin();
advance(cfdStop, (int)(maxPos + waveformHigh));
for(Trace::iterator it = cfdStart; it != cfdStop; it++) {
Trace::iterator it0 = it;
advance(it0, delay);
double origVal = *it;
double transVal = *it0;
cfd.insert(cfd.end(), fraction *
(origVal - transVal - aveBaseline));
}
vector<double>::iterator cfdMax =
max_element(cfd.begin(), cfd.end());
vector<double> fitY;
fitY.insert(fitY.end(), cfd.begin(), cfdMax);
fitY.insert(fitY.end(), *cfdMax);
vector<double>fitX;
for(unsigned int i = 0; i < fitY.size(); i++)
fitX.insert(fitX.end(), i);
double num = fitY.size();
double sumXSq = 0, sumX = 0, sumXY = 0, sumY = 0;
for(unsigned int i = 0; i < num; i++) {
sumXSq += fitX.at(i)*fitX.at(i);
sumX += fitX.at(i);
sumY += fitY.at(i);
sumXY += fitX.at(i)*fitY.at(i);
}
double deltaPrime = num*sumXSq - sumX*sumX;
double intercept =
(1/deltaPrime)*(sumXSq*sumY - sumX*sumXY);
double slope =
(1/deltaPrime)*(num*sumXY - sumX*sumY);
trace.InsertValue("phase", (-intercept/slope)+maxPos);
EndAnalyze();
}
示例2: phaseTrace
void MissionPhase::phaseTrace(double time, Trace& trace, int maxDepth) const {
if (maxDepth == 0) {
return;
}
for (const MissionPhase& phase : _subphases) {
if (phase.timeRange().includes(time)) {
trace.push_back(phase);
phase.phaseTrace(time, trace, maxDepth - 1);
return;
}
else if (phase.timeRange().start > time) {
// Since time ranges are sorted we can do early termination
return;
}
}
}
示例3: Trace
/** get the current tracer.
* Call with 'true' when you want to change the tracer
* and with 'false' when you want to use it.
*
* If the current tracer has been used, it's not modified; instead, it is
* passed to Layer3 (which will deallocate it when it ends) and copied to
* a new instance.
*/
Trace *tracer(bool modify = false)
{
if (modify && trace_used)
{
Trace *tr = new Trace(*t);
l3()->registerTracer(t);
t = tr;
trace_used = false;
}
else if (! t)
{
t = new Trace();
trace_used = !modify;
t->SetErrorLevel (LEVEL_WARNING); // default
}
else if (!modify)
trace_used = true;
return t;
}
示例4: main
int main(int argc, char** argv){
HWND hwnd;
hwnd = GetConsoleWindow();
Painter pen(hwnd);
system("color 3e");
Trace t;
t.add_point(0, 0);
t.add_point(20, 200);
t.add_point(200, 200);
t.drawbezier(pen);
printf("len is %f", t.bezier_len());
getchar();
return 0;
}
示例5: fprintf
Trace * Trace::load_project_file(const char * filename)
{
XMLBZIP2_reader reader;
xmlDocPtr doc = reader.xmlReadDoc(filename);
if (doc == NULL) {
fprintf(stderr, "Failed to parse %s\n", filename);
return NULL;
}
// Todo - make it actually load the architecture on demand
Trace * t = new Trace(new ARMArchitecture());
xmlNodePtr root_element = xmlDocGetRootElement(doc);
xmlNodePtr memories_n = findChild(root_element, "memblocks");
if (!memories_n)
{
printf("could not find memblocks section, aborting!\n");
return NULL;
}
xmlNodePtr memory_n = findChild(memories_n, "memory");
if (!memory_n)
{
printf("could not load memory, aborting!\n");
return NULL;
}
xmlNodePtr memory_base_n = findChild(memory_n, "base");
if (!memory_base_n)
{
printf("could not find memory base address, aborting!\n");
return NULL;
}
address_t base_addr = strtoul((char *) xmlNodeGetContent(memory_base_n), NULL, 16);
xmlNodePtr memory_data_n = findChild(memory_n, "data");
if (!memory_n)
{
printf("could not find memory data, aborting!\n");
return NULL;
}
char * base64_content = (char*)xmlNodeGetContent(memory_data_n);
int base64_len = strlen(base64_content);
char * code_buf;
size_t code_len;
bool ok = base64_decode_alloc (base64_content, base64_len, &code_buf, &code_len);
xmlFree(base64_content);
if (!ok)
{
printf("could not parse memory data, aborting!\n");
return NULL;
}
MemSegment * m = new MemSegment(base_addr, code_len, code_buf);
t->addSegment(m);
free(code_buf);
xmlNodePtr instructions_n = findChild(root_element, "instructions");
if (instructions_n)
for(xmlNodePtr node_a = instructions_n->children; node_a != NULL; node_a = node_a->next) {
u32 addr;
u32 opcode;
bool good = false;
bool opcodeset = false;
//printf("node %s\n", node_a->name);
for(xmlNodePtr node_b = node_a->children; node_b != NULL; node_b = node_b->next) {
char * content = (char *) xmlNodeGetContent(node_b);
if (!content)
continue;
if (xmlStrcmp(node_b->name, BAD_CAST "addr") == 0)
{
good = true;
addr = strtoul(content, NULL, 16);
}
else if (xmlStrcmp(node_b->name, BAD_CAST "opcode") == 0)
{
opcode = strtoul(content, NULL, 16);
opcodeset = true;
}
xmlFree(content);
}
if (!opcodeset)
opcode = t->ldw(addr);
if (good)
{
// fixme
Instruction * inst = t->m_arch->create_instruction(t, addr);//new Instruction(t, addr, opcode);
t->insert_memlocd(inst);
//.........这里部分代码省略.........
示例6: predict
void predict(Options::PredictEnum mode, ReportWriter *writer, const RomAccessor &rom, Trace &trace, const AnnotationResolver &annotations) {
if (mode == Options::PRD_NEVER)
return;
bool limit_to_functions = mode == Options::PRD_FUNCTIONS;
Profile profile("Predict", true);
struct PredictBranch {
const Annotation *annotation;
Pointer from_pc;
Pointer pc;
uint16_t DP, P;
uint8_t DB;
};
std::vector<PredictBranch> predict_brances;
LargeBitfield has_op(256*64*1024);
LargeBitfield inside_op(256 * 64 * 1024);
for (auto opsit : trace.ops) {
const Pointer pc = opsit.first;
const Trace::OpVariantLookup &vl = opsit.second;
const OpInfo &example = trace.variant(vl, 0);
const uint8_t* data = rom.evalPtr(pc);
const uint8_t opcode = data[0];
uint32_t op_size = instruction_size(opcode, is_memory_accumulator_wide(example.P), is_index_wide(example.P));
for (uint32_t i = 0; i < op_size; ++i) {
has_op.set_bit(bank_add(pc, i));
if (i!=0) inside_op.set_bit(bank_add(pc, i));
}
StringBuilder sb;
Pointer target_jump, target_no_jump;
bool branch_or_jump = decode_static_jump(opcode, rom, pc, &target_jump, &target_no_jump);
const Hint *hint = annotations.hint(pc);
if (hint && hint->has_hint(Hint::BRANCH_ALWAYS)) {
target_no_jump = INVALID_POINTER;
}
if (hint && hint->has_hint(Hint::BRANCH_NEVER)) {
target_jump = INVALID_POINTER;
}
if (!branch_or_jump)
continue;
const Annotation *source_annotation = nullptr, *target_annotation = nullptr;
annotations.resolve_annotation(pc, &source_annotation);
if (target_jump != INVALID_POINTER) {
trace.labels.set_bit(target_jump);
annotations.resolve_annotation(target_jump, &target_annotation);
}
if (source_annotation || !limit_to_functions) {
PredictBranch p;
p.annotation = source_annotation;
p.from_pc = pc;
p.DB = example.DB;
p.DP = example.DP;
p.P = example.P;
if (target_jump != INVALID_POINTER && (target_annotation == source_annotation || !limit_to_functions)) {
p.pc = target_jump;
CUSTOM_ASSERT(target_jump != INVALID_POINTER);
predict_brances.push_back(p);
}
if (target_no_jump != INVALID_POINTER && (!limit_to_functions || (target_no_jump >= source_annotation->startOfRange && target_no_jump <= source_annotation->endOfRange))) {
// BRA,BRL and the jumps always branches/jumps
p.pc = target_no_jump;
CUSTOM_ASSERT(target_no_jump != INVALID_POINTER);
predict_brances.push_back(p);
}
}
}
StringBuilder sb;
sb.clear();
if (writer)
writer->writeSeperator("Prediction diagnostics");
for (int pbi=0; pbi<(int)predict_brances.size(); ++pbi) {
const PredictBranch pb = predict_brances[pbi];
Pointer pc = pb.pc;
Pointer r0 = limit_to_functions ? pb.annotation->startOfRange : 0, r1 = limit_to_functions ? pb.annotation->endOfRange : 0xFFFFFF;
uint16_t P = pb.P, DP = pb.DP;
uint8_t DB = pb.DB;
bool P_unknown = false;
if (inside_op[pc]) {
if (writer) {
//.........这里部分代码省略.........
示例7:
Event *headEvent(Trace *trace){
return trace->getHead();
}
示例8: main
int main (int argn, char** argv) {
// 1. parse cmd
parse_cmd_line(argn, argv);
// 2. input DNA sequence file
int numSeq = 0;
SequenceSet allSeqs (0, Sequence());
parse_seqs_file(allSeqs, numSeq, trainFname);
vector<int> lenSeqs (numSeq, 0);
for (int n = 0; n < numSeq; n ++)
lenSeqs[n] = allSeqs[n].size();
// pre-info
cout << "#########################################################" << endl;
cout << "ScoreMatch: " << C_M;
cout << ", ScoreInsertion: " << C_I;
cout << ", ScoreDeletion: " << C_D;
cout << ", ScoreMismatch: " << C_MM << endl;
for (int n = 0; n < numSeq; n ++)
sequence_dump(allSeqs, n);
// 3. relaxed convex program: ADMM-based algorithm
string dir_path = string(trainFname)+".trace/";
//system((string("rm -rf ")+dir_path).c_str());
//system((string("mkdir ")+dir_path).c_str());
// omp_set_num_threads(NUM_THREADS);
int T2 = get_init_model_length (lenSeqs) + LENGTH_OFFSET; // model_seq_length
time_t begin = time(NULL);
vector<Tensor4D> W = CVX_ADMM_MSA (allSeqs, lenSeqs, T2, dir_path);
time_t end = time(NULL);
// 4. output the result
// a. tuple view
cout << ">>>>>>>>>>>>>>>>>>>>>>>TupleView<<<<<<<<<<<<<<<<<<<<<<<<" << endl;
for (int n = 0; n < numSeq; n ++) {
cout << "n = " << n << endl;
tensor4D_dump(W[n]);
}
// b. sequence view
cout << ">>>>>>>>>>>>>>>>>>>>>>>SequenceView<<<<<<<<<<<<<<<<<<<<<<<<" << endl;
int T2m = T2;
Tensor tensor (T2m, Matrix (NUM_DNA_TYPE, vector<double>(NUM_DNA_TYPE, 0.0)));
Matrix mat_insertion (T2m, vector<double> (NUM_DNA_TYPE, 0.0));
for (int n = 0; n < numSeq; n ++) {
int T1 = W[n].size();
for (int i = 0; i < T1; i ++) {
for (int j = 0; j < T2m; j ++) {
for (int d = 0; d < NUM_DNA_TYPE; d ++) {
for (int m = 0; m < NUM_MOVEMENT; m ++) {
if (m == DELETION_A or m == MATCH_A)
tensor[j][d][dna2T3idx('A')] += max(0.0, W[n][i][j][d][m]);
else if (m == DELETION_T or m == MATCH_T)
tensor[j][d][dna2T3idx('T')] += max(0.0, W[n][i][j][d][m]);
else if (m == DELETION_C or m == MATCH_C)
tensor[j][d][dna2T3idx('C')] += max(0.0, W[n][i][j][d][m]);
else if (m == DELETION_G or m == MATCH_G)
tensor[j][d][dna2T3idx('G')] += max(0.0, W[n][i][j][d][m]);
else if (m == DELETION_START or m == MATCH_START)
tensor[j][d][dna2T3idx('*')] += max(0.0, W[n][i][j][d][m]);
else if (m == DELETION_END or m == MATCH_END)
tensor[j][d][dna2T3idx('#')] += max(0.0, W[n][i][j][d][m]);
else if (m == INSERTION)
mat_insertion[j][d] += max(0.0, W[n][i][j][d][m]);
}
}
}
}
}
Trace trace (0, Cell(2)); // 1d: j, 2d: ATCG
refined_viterbi_algo (trace, tensor, mat_insertion);
// for (int i = 0; i < trace.size(); i ++)
// cout << trace[i].toString() << endl;
for (int n = 0; n < numSeq; n ++) {
char buffer [50];
sprintf (buffer, "Seq%5d", n);
cout << buffer << ": ";
for (int j = 0; j < allSeqs[n].size(); j ++)
cout << allSeqs[n][j];
cout << endl;
}
Sequence recSeq;
cout << "SeqRecov: ";
for (int i = 0; i < trace.size(); i ++)
if (trace[i].action != INSERTION) {
cout << trace[i].acidB;
recSeq.push_back(trace[i].acidB);
if (trace[i].acidB == '#') break;
}
cout << endl;
cout << ">>>>>>>>>>>>>>>>>>>>>>>MatchingView<<<<<<<<<<<<<<<<<<<<<<<<" << endl;
// NOTE: rounding scheme
SequenceSet allModelSeqs, allDataSeqs;
for (int n = 0; n < numSeq; n ++) {
Sequence model_seq = recSeq, data_seq = allSeqs[n];
data_seq.erase(data_seq.begin());
model_seq.erase(model_seq.begin());
data_seq.erase(data_seq.end()-1);
model_seq.erase(model_seq.end()-1);
// align sequences locally
//.........这里部分代码省略.........
示例9: second_subproblem
/* We resolve the second subproblem through sky-plane projection */
Sequence second_subproblem (Tensor5D& W_1, Tensor5D& W_2, Tensor5D& Y, double& mu, SequenceSet& allSeqs, vector<int> lenSeqs) {
/*{{{*/
int numSeq = allSeqs.size();
int T2 = W_2[0][0].size();
// reinitialize W_2 to all-zero matrix
for (int n = 0; REINIT_W_ZERO_TOGGLE and n < numSeq; n ++) {
int T1 = W_2[n].size();
for (int i = 0; i < T1; i ++)
for (int j = 0; j < T2; j ++)
for (int d = 0; d < NUM_DNA_TYPE; d ++)
for (int m = 0; m < NUM_MOVEMENT; m ++)
W_2[n][i][j][d][m] = 0.0;
}
vector<Tensor4D> delta (numSeq, Tensor4D(0, Tensor(T2, Matrix(NUM_DNA_TYPE,
vector<double>(NUM_MOVEMENT, 0.0)))));
tensor5D_init (delta, allSeqs, lenSeqs, T2);
Tensor tensor (T2, Matrix (NUM_DNA_TYPE, vector<double>(NUM_DNA_TYPE, 0.0)));
Matrix mat_insertion (T2, vector<double>(NUM_DNA_TYPE, 0.0));
Trace trace (0, Cell(2)); // 1d: j, 2d: ATCG
int fw_iter = -1;
while (fw_iter < MAX_2nd_FW_ITER) {
fw_iter ++;
// 1. compute delta
#ifdef PARRALLEL_COMPUTING
//#pragma omp parallel for
#endif
for (int n = 0; n < numSeq; n ++) {
int T1 = W_2[n].size();
for (int i = 0; i < T1; i ++) {
for (int j = 0; j < T2; j ++)
for (int d = 0; d < NUM_DNA_TYPE; d ++)
for (int m = 0; m < NUM_MOVEMENT; m ++) {
delta[n][i][j][d][m] = -1.0* mu * (W_2[n][i][j][d][m] - W_1[n][i][j][d][m]) + Y[n][i][j][d][m];
#ifdef SECOND_SUBPROBLEM_DEBUG
if (delta[n][i][j][d][m] > 0)
cout <<"delta: " << n << "," << i << "," << j << "," << d << "," << m << ": "
<< delta[n][i][j][d][m] << endl;
#endif
if (m == DELETION_A or m == MATCH_A)
tensor[j][d][dna2T3idx('A')] += max(0.0, delta[n][i][j][d][m]);
else if (m == DELETION_T or m == MATCH_T)
tensor[j][d][dna2T3idx('T')] += max(0.0, delta[n][i][j][d][m]);
else if (m == DELETION_C or m == MATCH_C)
tensor[j][d][dna2T3idx('C')] += max(0.0, delta[n][i][j][d][m]);
else if (m == DELETION_G or m == MATCH_G)
tensor[j][d][dna2T3idx('G')] += max(0.0, delta[n][i][j][d][m]);
else if (m == DELETION_START or m == MATCH_START)
tensor[j][d][dna2T3idx('*')] += max(0.0, delta[n][i][j][d][m]);
else if (m == DELETION_END or m == MATCH_END)
tensor[j][d][dna2T3idx('#')] += max(0.0, delta[n][i][j][d][m]);
else if (m == INSERTION) {
mat_insertion[j][d] += max(0.0, delta[n][i][j][d][m]);
}
}
}
}
#ifdef SECOND_SUBPROBLEM_DEBUG
cout << "tensor transition input list:" << endl;
for (int j = 0; j < T2; j ++)
for (int d = 0; d < NUM_DNA_TYPE; d ++)
for (int k = 0; k < NUM_DNA_TYPE; k ++) {
if (tensor[j][d][k] > 0)
cout << "(" << j << ", " << d << ", " << k << ")=" << tensor[j][d][k] << endl;
}
#endif
double delta_square = 0.0;
for (int n = 0; n < numSeq; n ++)
delta_square += tensor4D_frob_prod (delta[n], delta[n]);
//cout << "delta_square: " << delta_square << endl;
if ( delta_square < 1e-12 ) {
//cout << "small delta. early stop." << endl;
break;
}
// 2. determine the trace: run viterbi algorithm
trace.clear();
refined_viterbi_algo (trace, tensor, mat_insertion);
Tensor5D S (numSeq, Tensor4D(0, Tensor(T2, Matrix(NUM_DNA_TYPE, vector<double>(NUM_MOVEMENT, 0.0)))));
tensor5D_init (S, allSeqs, lenSeqs, T2);
// 3. recover values for S
// 3b. set a number of selected elements to 1
for (int t = 0; t < trace.size(); t++) {
int sj = trace[t].location[0];
int sd = trace[t].location[1];
int sm = dna2T3idx(trace[t].acidB);
// cout << trace[t].acidB;
for (int n = 0; n < numSeq; n ++) {
int T1 = S[n].size();
for (int i = 0; i < T1; i ++) {
for (int m = 0; m < NUM_MOVEMENT; m ++)
if (delta[n][i][sj][sd][m] > 0.0) {
if (m == DEL_BASE_IDX + sm or m == MTH_BASE_IDX + sm)
S[n][i][sj][sd][m] = 1.0;
else if (m == INSERTION and trace[t].action == INSERTION) {
S[n][i][sj][sd][m] = 1.0;
//.........这里部分代码省略.........
示例10: pushTimestep
void pushTimestep(OracleType oPoint, SideChannelType scPoint) {
oracleTrace.push(oPoint);
sideChannelTrace.push(scPoint);
}
示例11: main
int
main (int ac, char *ag[])
{
int index;
Queue < Server * >server;
Server *s;
Layer2Interface *l2;
Layer3 *l3;
#ifdef HAVE_EIBNETIPSERVER
EIBnetServer *serv = 0;
#endif
memset (&arg, 0, sizeof (arg));
arg.addr = 0x0001;
arg.errorlevel = LEVEL_WARNING;
argp_parse (&argp, ac, ag, 0, &index, &arg);
if (index > ac - 1)
die ("url expected");
if (index < ac - 1)
die ("unexpected parameter");
if (arg.port == 0 && arg.name == 0 && arg.serverip == 0)
die ("No listen-address given");
signal (SIGPIPE, SIG_IGN);
pth_init ();
Trace t;
t.SetTraceLevel (arg.tracelevel);
t.SetErrorLevel (arg.errorlevel);
/*
if (getuid () == 0)
ERRORPRINTF (&t, 0x37000001, 0, "EIBD should not run as root");
*/
if(arg.eibnetname)
{
if(arg.eibnetname[0] == '=')
arg.eibnetname++;
if(strlen(arg.eibnetname) >= 30)
die("EIBnetServer/IP name can't be longer then 30 char");
}
if (arg.daemon)
{
int fd = open (arg.daemon, O_WRONLY | O_APPEND | O_CREAT, FILE_MODE);
if (fd == -1)
die ("Can not open file %s", arg.daemon);
int i = fork ();
if (i < 0)
die ("fork failed");
if (i > 0)
exit (0);
close (1);
close (2);
close (0);
dup2 (fd, 1);
dup2 (fd, 2);
close (fd);
setsid ();
}
FILE *pidf;
if (arg.pidfile)
if ((pidf = fopen (arg.pidfile, "w")) != NULL)
{
fprintf (pidf, "%d", getpid ());
fclose (pidf);
}
l2 = Create (ag[index], arg.backendflags, &t);
if (!l2 || !l2->init ())
die ("initialisation of the backend failed");
l3 = new Layer3 (l2, &t);
if (arg.port)
{
s = new InetServer (l3, &t, arg.port);
if (!s->init ())
die ("initialisation of the knxd inet protocol failed");
server.put (s);
}
if (arg.name)
{
s = new LocalServer (l3, &t, arg.name);
if (!s->init ())
die ("initialisation of the knxd unix protocol failed");
server.put (s);
}
#ifdef HAVE_EIBNETIPSERVER
serv = startServer (l3, &t, arg.eibnetname);
#endif
#ifdef HAVE_GROUPCACHE
if (!CreateGroupCache (l3, &t, arg.groupcache))
die ("initialisation of the group cache failed");
#endif
signal (SIGINT, SIG_IGN);
//.........这里部分代码省略.........
示例12: read_trace_from_file
bap_blocks_t * read_trace_from_file(const string &filename,
uint64_t offset,
uint64_t numisns,
bool print,
bool atts,
bool pintrace)
{
// a block to accumulate the lifted traces
bap_blocks_t * result = new bap_blocks_t;
uint64_t counter = 0LL;
pintrace::TraceReader tr;
//cerr << "reading from offset " << offset << endl;
if(pintrace) {
try {
tr.open(filename.c_str());
}
catch (pintrace::TraceExn& e) {
cerr << "Trace exception: " << e.msg << endl;
throw e;
}
// FIXME: Currently only x86
VexArch arch = VexArchX86;
bfd_architecture bfd_arch = bfd_arch_i386;
asm_program_t * prog = asmir_trace_asmp_for_arch(bfd_arch);
assert(prog);
assert(prog->abfd);
// Initializations
translate_init();
// cerr << "plz seek to " << offset << " of " << tr.count() << endl;
if (!tr.seek(offset)) {
/* Couldn't seek there! */
return NULL;
}
while(
(tr.pos() < tr.count()) && // Don't go past the end of the trace
((numisns == 0) ? true : counter < numisns) // Count numisns
) {
// Reading each instruction
pintrace::Frame *f = tr.next();
assert(f);
counter += 1;
// cerr << "pos " << tr.pos() << " of " << tr.count() << endl;
switch(f->type) {
case pintrace::FRM_STD: // TODO: We should consider key frame
{
assert(false);
break;
}
case pintrace::FRM_STD2: // TODO: We should consider key frame
{
//static int num = 0;
//cerr << "Raising frame " << num++ << endl;
pintrace::StdFrame2 *cur_frm = (pintrace::StdFrame2 *) f;
/* Set up the trace_read_memory function so the
* disassembler is happy. */
set_trace_bytes(cur_frm->rawbytes, cur_frm->insn_length,
cur_frm->addr);
bap_block_t *bblock = new bap_block_t;
bblock->bap_ir = new vector<Stmt *>();
bblock->inst = cur_frm->addr;
bblock->vex_ir =
translate_insn(arch,
(unsigned char *)cur_frm->rawbytes,
cur_frm->addr);
// prog = byte_insn_to_asmp(bfd_arch,
// cur_frm->addr,
// (unsigned char *)cur_frm->rawbytes,
// MAX_INSN_BYTES);
generate_bap_ir_block(prog, bblock);
// free internal VEX memory...
// XXX Not necessary(?) as asmir_close will do this too
vx_FreeAll();
string assembly(asmir_string_of_insn(prog,
(bfd_vma)(cur_frm->addr)));
////string assembly("ed has disabled this; fix it");
bblock->bap_ir->front()->assembly = assembly;
if (atts)
bblock->bap_ir->front()->attributes.cv =
cur_frm->getOperands() ;
bblock->bap_ir->front()->attributes.tid = cur_frm->tid;
result->push_back(bblock);
//for (int i = 0 ; i < bblock->bap_ir->size() ; i ++)
//.........这里部分代码省略.........
示例13: main
int
main(int argc, char *argv[]) {
ROSE_INITIALIZE;
Diagnostics::initAndRegister(&mlog, "tool");
// Parse the command-line to configure the partitioner engine, obtain the executable and its arguments, and generate a man
// page, adjust global settings, etc. This demo tool has no switches of its own, which makes this even easier. For a
// production tool, it's probably better to obtain the parser and register only those switches we need (e.g., no need for
// AST generation switches since we skip that step), to set it up to use our own diagnostic stream instead of exceptions,
// and to adjust this tool's synopsis in the documentation. Examples of all of these can be found in other demos.
P2::Engine engine;
engine.doingPostAnalysis(false); // no need for any post-analysis phases (user can override on cmdline)
std::vector<std::string> command;
try {
command = engine.parseCommandLine(argc, argv, purpose, description).unreachedArgs();
} catch (const std::runtime_error &e) {
mlog[FATAL] <<"invalid command-line: " <<e.what() <<"\n";
exit(1);
}
if (command.empty()) {
mlog[FATAL] <<"no executable specified\n";
exit(1);
}
// Since we'll be tracing this program's execution, we might as well disassemble the process's memory directly. That way we
// don't have to worry about ROSE mapping the specimen to the same virtual address as the kernel (which might be using
// address randomization). We can stop short of generating the AST because we won't need it.
BinaryAnalysis::BinaryDebugger debugger(command);
std::string specimenResourceName = "proc:noattach:" + StringUtility::numberToString(debugger.isAttached());
P2::Partitioner partitioner = engine.partition(specimenResourceName);
partitioner.memoryMap()->dump(std::cerr); // show the memory map as a debugging aid
// Create a global control flow graph whose vertices are instructions from a global CFG whose verts are mostly basic
// blocks.
InsnCfg insnCfg;
const P2::ControlFlowGraph &bbCfg = partitioner.cfg();
BOOST_FOREACH (const P2::ControlFlowGraph::Vertex &bbVert, bbCfg.vertices()) {
if (P2::BasicBlock::Ptr bb = isBasicBlock(bbVert)) {
const std::vector<SgAsmInstruction*> &insns = bb->instructions();
// Each basic block has one or more instructions that need to be inserted into our instruction control flow graph
// with edges from each instruction to the next. The insertEdgeWithVertices automatically inserts missing
// vertices, and doesn't insert vertices that already exist, making it convenient for this type of construction.
for (size_t i=1; i<insns.size(); ++i)
insnCfg.insertEdgeWithVertices(insns[i-1], insns[i]);
// The final instruction of this block needs to flow into each of the initial instructions of the successor basic
// blocks. Be careful that the successors are actually existing basic blocks. Note that in ROSE's global CFG, a
// function call has at least two successors: the function being called (normal edges), and the address to which
// the function returns ("callret" edges). There are other types of edges too, but we want only the normal edges.
BOOST_FOREACH (const P2::ControlFlowGraph::Edge &bbEdge, bbVert.outEdges()) {
if (bbEdge.value().type() == P2::E_NORMAL) {
if (P2::BasicBlock::Ptr target = isBasicBlock(*bbEdge.target()))
insnCfg.insertEdgeWithVertices(insns.back(), target->instructions()[0]);
}
}
}
}
mlog[INFO] <<"block CFG: "
<<StringUtility::plural(bbCfg.nVertices(), "vertices", "vertex") <<", "
<<StringUtility::plural(bbCfg.nEdges(), "edges") <<"\n";
mlog[INFO] <<"insn CFG: "
<<StringUtility::plural(insnCfg.nVertices(), "vertices", "vertex") <<", "
<<StringUtility::plural(insnCfg.nEdges(), "edges") <<"\n";
// Run the executable to obtain a trace. We use the instruction pointer to look up a SgAsmInstruction in the insnCfg and
// thus map the trace onto the instruction CFG.
mlog[INFO] <<"running subordinate to obtain trace: " <<boost::join(command, " ") <<"\n";
std::set<rose_addr_t> missingAddresses;
Trace trace;
while (!debugger.isTerminated()) {
// Find the instruction CFG vertex corresponding to the current execution address. It could be that the execution
// address doesn't exist in the CFG, and this can be caused by a number of things including failure of ROSE to
// statically find the address, dynamic libraries that weren't loaded statically, etc.
rose_addr_t va = debugger.executionAddress();
InsnCfg::ConstVertexIterator vertex = insnCfg.findVertexKey(va);
if (!insnCfg.isValidVertex(vertex)) {
missingAddresses.insert(va);
} else {
trace.append(vertex->id());
}
debugger.singleStep();
}
mlog[INFO] <<"subordinate " <<debugger.howTerminated() <<"\n";
mlog[INFO] <<"trace length: " <<StringUtility::plural(trace.size(), "instructions") <<"\n";
Diagnostics::mfprintf(mlog[INFO])("overall burstiness: %6.2f%%\n", 100.0 * trace.burstiness());
mlog[INFO] <<"distinct executed addresses missing from CFG: " <<missingAddresses.size() <<"\n";
// Print a list of CFG vertices that were never reached. We use std::cout rather than diagnostics because this is one of
// the main outputs of this demo. The "if" condition is constant time.
BOOST_FOREACH (const InsnCfg::Vertex &vertex, insnCfg.vertices()) {
if (!trace.exists(vertex.id()))
std::cout <<"not executed: " <<unparseInstructionWithAddress(vertex.value()) <<"\n";
}
// Print list of addresses that were executed but did not appear in the CFG
BOOST_FOREACH (rose_addr_t va, missingAddresses)
std::cout <<"missing address: " <<StringUtility::addrToString(va) <<"\n";
// Print those branch instructions that were executed by the trace but always took the same branch. Just to mix things up,
//.........这里部分代码省略.........
示例14: Analyze
void FittingAnalyzer::Analyze(Trace &trace, const std::string &detType,
const std::string &detSubtype,
const std::map<std::string, int> & tagMap) {
TraceAnalyzer::Analyze(trace, detType, detSubtype, tagMap);
if(trace.HasValue("saturation") || trace.empty() ||
trace.GetWaveform().size() == 0) {
EndAnalyze();
return;
}
Globals *globals = Globals::get();
const double sigmaBaseline = trace.GetValue("sigmaBaseline");
const double maxVal = trace.GetValue("maxval");
const double qdc = trace.GetValue("qdc");
const double maxPos = trace.GetValue("maxpos");
const vector<double> waveform = trace.GetWaveform();
bool isDblBeta = detType == "beta" && detSubtype == "double";
bool isDblBetaT = isDblBeta && tagMap.find("timing") != tagMap.end();
trace.plot(D_SIGMA, sigmaBaseline*100);
if(!isDblBetaT) {
if(sigmaBaseline > globals->sigmaBaselineThresh()) {
EndAnalyze();
return;
}
} else {
if(sigmaBaseline > globals->siPmtSigmaBaselineThresh()) {
EndAnalyze();
return;
}
}
pair<double,double> pars = globals->fitPars(detType+":"+detSubtype);
if(isDblBetaT)
pars = globals->fitPars(detType+":"+detSubtype+":timing");
FitDriver *driver;
switch(fitterType_) {
case FitDriver::GSL:
driver = new GslFitter(isDblBetaT);
break;
case FitDriver::UNKNOWN:
default:
EndAnalyze();
return;
}
driver->PerformFit(waveform, pars, sigmaBaseline, qdc);
trace.InsertValue("phase", driver->GetPhase()+maxPos);
trace.plot(DD_AMP, driver->GetAmplitude(), maxVal);
trace.plot(D_PHASE, driver->GetPhase()*1000+100);
trace.plot(D_CHISQPERDOF, driver->GetChiSqPerDof());
delete(driver);
EndAnalyze();
}
示例15: TraceDiffExecute
/**
Executes the trace difference algorithm optionally followed by the
mutation detection algorithm.
*/
mutlib_result_t TraceDiffExecute( tracediff_t* td, tracediff_algorithm_t a )
{
enum { STATE_INITIALISE, STATE_VALIDATE_INPUT, STATE_TRACE_ALIGN,
STATE_TRACE_DIFFERENCE, STATE_MUTATION_ANALYSIS, STATE_EXIT };
int n;
mutlib_strand_t Strand = MUTLIB_STRAND_FORWARD;
TraceDiffParameters Parameter;
Trace AlignedTrace[2];
int AlignedTraceClipL[2];
int AlignedTraceClipR[2];
List<MutTag> DiffTagList;
Trace* DiffTrace = 0;
bool Done = false;
int State = STATE_INITIALISE;
assert(td != NULL);
try
{
while(!Done)
{
switch(State)
{
case STATE_INITIALISE:
// Destroy old results
TraceDiffDestroyResults( td );
Strand = td->Alignment.Input.Strand;
State = STATE_VALIDATE_INPUT;
break;
case STATE_VALIDATE_INPUT:
// Check input values
State = STATE_EXIT;
for( n=0; n<TRACEDIFF_PARAMETERS; n++ )
Parameter[n].Value( td->Parameter[n] );
if( TraceDiffValidateParameters(td,Parameter) != MUTLIB_RESULT_SUCCESS )
break;
if( TraceAlignValidateInput(&td->Alignment) != MUTLIB_RESULT_SUCCESS )
{
td->ResultCode = td->Alignment.ResultCode;
std::strcpy( td->ResultString, td->Alignment.ResultString );
break;
}
State = STATE_TRACE_ALIGN;
break;
case STATE_TRACE_ALIGN:
// Align the reference and input traces
if( TraceAlignExecute(&td->Alignment) != MUTLIB_RESULT_SUCCESS )
{
td->ResultCode = TraceAlignGetResultCode( &td->Alignment );
std::strcpy( td->ResultString, TraceAlignGetResultString(&td->Alignment) );
State = STATE_EXIT;
break;
}
for( int n=0; n<2; n++ )
AlignedTrace[n].Wrap(TraceAlignGetAlignment(&td->Alignment,static_cast<mutlib_input_t>(n),&AlignedTraceClipL[n],&AlignedTraceClipR[n]),false);
State = STATE_TRACE_DIFFERENCE;
break;
case STATE_TRACE_DIFFERENCE: {
// Scale & Subtract the two traces to obtain the difference trace
State = (a&TRACEDIFF_ALGORITHM_DEFAULT_DIFFERENCE_ONLY) ? STATE_EXIT : STATE_MUTATION_ANALYSIS;
if( Parameter[TRACEDIFF_PARAMETER_YSCALE].Value() > 0.0 )
AlignedTrace[MUTLIB_INPUT].ScaleTo( AlignedTrace[MUTLIB_INPUT_REFERENCE] );
DiffTrace = AlignedTrace[MUTLIB_INPUT].Subtract( AlignedTrace[MUTLIB_INPUT_REFERENCE] );
if( !DiffTrace )
throw std::bad_alloc();
DiffTrace->AutoDestroy( false );
td->Difference = DiffTrace->Raw();
td->DifferenceLeft = AlignedTraceClipL[MUTLIB_INPUT];
td->DifferenceRight = AlignedTraceClipR[MUTLIB_INPUT];
break; }
case STATE_MUTATION_ANALYSIS:
// Analyse the difference trace for possible mutations
TraceDiffScanForMutations( *DiffTrace, Strand, DiffTrace->IntervalMode(),
AlignedTraceClipL[MUTLIB_INPUT], Parameter, DiffTagList );
if( DiffTagList.Count() > 0 )
{
// Construct output mutation tag list
TagArray OutTags;
bool bComplementBases = Parameter[TRACEDIFF_PARAMETER_COMPLEMENT_TAGS].Value()>0.0 ? true : false;
OutTags.Create( DiffTagList.Count() );
OutTags.ReadTags( DiffTagList, 1, bComplementBases );
OutTags.AutoDestroy( false );
td->Tag = OutTags.Raw();
td->TagCount = DiffTagList.Count();
}
State = STATE_EXIT;
//.........这里部分代码省略.........