Skip to content
Snippets Groups Projects
Commit 13e3bf25 authored by clc5q's avatar clc5q
Browse files

Code cleanup to compile on Visual Studio.

parent 5850c5a3
No related branches found
No related tags found
No related merge requests found
#include <cstdlib>
#include "ProfilerInformation.h"
#define qfeof feof
/*
* ascii-to-longlong conversion; Visual Studio 2005 lacks atoll() library func
*
* no error checking; assumes decimal digits
*
* efficient conversion:
* start with value = 0
* then, starting at first character, repeat the following
* until the end of the string:
*
* new value = (10 * (old value)) + decimal value of next character
*
*/
long long my_atoll(char *instr) {
long long retval = 0;
for (; *instr; ++instr) {
retval = 10*retval + (*instr - '0');
}
return retval;
}
#ifdef WIN32
#define atoll my_atoll
#endif
ProfilerInformation::ProfilerInformation(const char* fn)
: filename(std::string(fn))
{
FILE* fin;
int addr;
union { int size, type;} size_type_u;
union {int size, type;} size_type_u;
char type[200];
char scope[200];
char remainder[2000];
int line=0;
if(fn[0]==0)
if (fn[0]==0)
return;
fin=qfopen(fn, "r");
fin = qfopen(fn, "r");
if(!fin)
if (!fin)
{
msg("Cannot open strata annotation file %s\n", fn);
return;
......@@ -36,26 +62,26 @@ ProfilerInformation::ProfilerInformation(const char* fn)
{
qfscanf(fin, "%x %d\n", &addr, &size_type_u);
if(qfeof(fin)) // deal with blank lines at the EOF
if (qfeof(fin)) // deal with blank lines at the EOF
break;
qfscanf(fin, "%s%s", type,scope);
/* if the size > 0, then this is a declaration of a variable */
if(strcmp(type,"FUNC")==0)
if (strcmp(type,"FUNC") == 0)
{
// no useful info for the SA.
; // no useful info for the SA.
}
else if(strcmp(type,"MEMORYHOLE")==0)
else if (strcmp(type,"MEMORYHOLE") == 0)
{
// no useful info for the SA.
}
else if(strcmp(type,"INSTR")==0)
else if (strcmp(type,"INSTR") == 0)
{
// no useful info for the SA.
}
else if(strcmp(type,"PTRIMMEDEBP")==0 ||
else if (strcmp(type,"PTRIMMEDEBP")==0 ||
strcmp(type,"PTRIMMEDESP")==0 ||
strcmp(type,"PTRIMMEDESP2")==0 ||
strcmp(type,"PTRIMMEDABSOLUTE")==0
......@@ -64,25 +90,24 @@ ProfilerInformation::ProfilerInformation(const char* fn)
int the_const;
int real_const=0;
char field[100];
assert(strcmp(scope,"STACK")==0 || strcmp(scope,"GLOBAL")==0);
assert(strcmp(scope,"STACK") == 0 || strcmp(scope,"GLOBAL") == 0);
/* remaining params are <const> <field> <real_const_if_global> <comment> */
qfscanf(fin, "%d %s", &the_const, field);
if( strcmp(type,"PTRIMMEDESP2")==0 ||
strcmp(type,"PTRIMMEDABSOLUTE")==0
)
if (strcmp(type,"PTRIMMEDESP2") == 0 ||
strcmp(type,"PTRIMMEDABSOLUTE") == 0)
qfscanf(fin, "%x", &real_const);
else
real_const=the_const;
// successfully read in, but, ignoring for now.
if(strcmp(type,"PTRIMMEDESP2")==0 || strcmp(type,"PTRIMMEDABSOLUTE")==0 )
if (strcmp(type,"PTRIMMEDESP2")==0 || strcmp(type,"PTRIMMEDABSOLUTE")==0 )
{
profileAddressingInformation(addr,size_type_u.size,type, scope,the_const,field,real_const);
}
}
else if(strcmp(type,"DATAREF")==0)
else if (strcmp(type,"DATAREF")==0)
{
// no useful info for the SA.
......@@ -93,17 +118,17 @@ ProfilerInformation::ProfilerInformation(const char* fn)
assert(strcmp(scope,"STACK")==0);
/* remaining params: comment */
}
else if(strcmp(type,"PROFILEDNUMERIC")==0)
else if (strcmp(type,"PROFILEDNUMERIC")==0)
{
/* profiler generated information */
addProfileInformation(addr,atoll(scope),0,0);
}
else if(strcmp(type,"PROFILEDPOINTER")==0 )
else if (strcmp(type,"PROFILEDPOINTER")==0 )
{
/* profiler generated information */
addProfileInformation(addr,0,atoll(scope),0);
}
else if(strcmp(type,"PROFILEDOTHER")==0 )
else if (strcmp(type,"PROFILEDOTHER")==0 )
{
/* profiler generated information */
addProfileInformation(addr,0,0,atoll(scope));
......@@ -115,23 +140,21 @@ ProfilerInformation::ProfilerInformation(const char* fn)
qfgets(remainder, sizeof(remainder), fin);
line++;
} while(!qfeof(fin));
} while (!qfeof(fin));
qfclose(fin);
msg("Successfully loaded annotation file %s\n", fn);
}
ProfilerInformation::~ProfilerInformation()
{
FILE* fout=qfopen(filename.c_str(), "a+");
ProfilerInformation::~ProfilerInformation() {
FILE* fout = qfopen(filename.c_str(), "a+");
if(!fout)
{
if (!fout) {
msg("Cannot open annotations file (%s) for output\n", filename.c_str());
assert(0);
assert(fout);
}
for( std::set<std::string>::iterator iter=constant_info.begin();
for (std::set<std::string>::iterator iter=constant_info.begin();
iter != constant_info.end();
++iter
)
......@@ -139,27 +162,27 @@ ProfilerInformation::~ProfilerInformation()
qfprintf(fout, "%s", (*iter).c_str());
}
for( std::map<ea_t,InstructionInformation*>::iterator iter=the_map.begin();
for (std::map<ea_t,InstructionInformation*>::iterator iter = the_map.begin();
iter != the_map.end();
++iter
)
{
ea_t addr=(*iter).first;
InstructionInformation *ii=(*iter).second;
if(ii)
if (ii)
{
if(ii->getNumericCount())
if (ii->getNumericCount())
{
qfprintf(fout, "%x %d %s %d Profiler generated, summarized by idal\n",
addr, 0, "PROFILEDNUMERIC", ii->getNumericCount());
}
if(ii->getPointerCount())
if (ii->getPointerCount())
{
qfprintf(fout, "%x %d %s %d Profiler generated, summarized by idal\n",
addr, 0, "PROFILEDPOINTER", ii->getPointerCount());
}
if(ii->getOtherCount())
if (ii->getOtherCount())
{
qfprintf(fout, "%x %d %s %d Profiler generated, summarized by idal\n",
addr, 0, "PROFILEDOTHER", ii->getOtherCount());
......@@ -172,22 +195,20 @@ ProfilerInformation::~ProfilerInformation()
}
void ProfilerInformation::addProfileInformation(ea_t addr, long long nc, long long pc, long long oc)
{
InstructionInformation *ii=GetInfo(addr);
void ProfilerInformation::addProfileInformation(ea_t addr, long long nc, long long pc, long long oc) {
InstructionInformation *ii = GetInfo(addr);
if(!ii)
{
if (!ii) {
ii = new InstructionInformation;
SetInfo(addr,ii);
SetInfo(addr, ii);
}
if(nc)
ii->setNumericCount(nc);
if(pc)
ii->setPointerCount(pc);
if(oc)
ii->setOtherCount(oc);
if (nc)
ii->setNumericCount((int) nc);
if (pc)
ii->setPointerCount((int) pc);
if (oc)
ii->setOtherCount((int) oc);
// msg("Profiled %x to be nc:%lld pc:%lld oc:%lld\n", addr,
// ii->getNumericCount(),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment