Commit d93213d0 authored by Jason Hiser's avatar Jason Hiser 🚜

code cleanup for release

parent 28a98ebc
Pipeline #2525 failed with stages
in 1 minute and 28 seconds
This diff is collapsed.
......@@ -25,78 +25,86 @@
#include <irdb-transform>
#include <memory>
using namespace IRDB_SDK;
namespace Stamper
{
using namespace std;
using namespace IRDB_SDK;
typedef unsigned int StampValue_t;
using StampValue_t = unsigned int;
class StackStamp_t : public Transform
{
public:
StackStamp_t(IRDB_SDK::FileIR_t *p_variantIR, StampValue_t sv, bool p_verbose);
int execute();
private: // methods
bool can_stamp(Function_t* f);
// stamp a function
void stamp(Function_t* f);
// update the function's EH info to reflect the stamp
void eh_update(Function_t* f);
// after all eh-pgm re-use has happened, clean stuff up
void cleanup_eh_pgms();
// stamp an instruction in a function
Instruction_t* stamp(Function_t* f, Instruction_t* i);
StampValue_t get_stamp(Function_t* f);
private: // data
struct EhProgramPlaceHolder_t
{
uint8_t caf;
int8_t daf;
int8_t rr;
uint8_t ptrsize; // needed for interpreting programs
IRDB_SDK::EhProgramListing_t cie_program;
IRDB_SDK::EhProgramListing_t fde_program;
IRDB_SDK::RelocationSet_t relocs;
IRDB_SDK::EhProgramListing_t& getCIEProgram() { return cie_program; }
IRDB_SDK::EhProgramListing_t& getFDEProgram() { return fde_program; }
uint8_t getCodeAlignmentFactor() const { return caf; }
int8_t getDataAlignmentFactor() const { return daf; }
int8_t getReturnRegNumber() const { return rr; }
uint8_t getPointerSize() const { return ptrsize; }
EhProgramPlaceHolder_t(const IRDB_SDK::EhProgram_t* orig)
:
caf(orig->getCodeAlignmentFactor()),
daf(orig->getDataAlignmentFactor()),
rr(orig->getReturnRegNumber()),
ptrsize(orig->getPointerSize()),
cie_program(orig->getCIEProgram()),
fde_program(orig->getFDEProgram()),
relocs(orig->getRelocations())
{
}
class StackStamp_t : public Transform
{
public:
StackStamp_t(FileIR_t *p_variantIR, StampValue_t sv, bool p_verbose);
int execute();
};
private: // methods
bool can_stamp(Function_t* f);
// stamp a function
void stamp(Function_t* f);
StampValue_t stamp_value;
int instructions_added;
bool verbose;
std::map<EhProgramPlaceHolder_t, IRDB_SDK::EhProgram_t*> all_eh_pgms;
int functionsTransformed;
int functionsNotTransformed;
// update the function's EH info to reflect the stamp
void eh_update(Function_t* f);
// after all eh-pgm re-use has happened, clean stuff up
void cleanup_eh_pgms();
friend bool operator<(const EhProgramPlaceHolder_t &a, const EhProgramPlaceHolder_t& b) ;
// stamp an instruction in a function
Instruction_t* stamp(Function_t* f, Instruction_t* i);
};
bool operator<(const StackStamp_t::EhProgramPlaceHolder_t &a, const StackStamp_t::EhProgramPlaceHolder_t& b);
// jdh: ???
StampValue_t get_stamp(Function_t* f);
private: // data
struct EhProgramPlaceHolder_t
{
uint8_t caf;
int8_t daf;
int8_t rr;
uint8_t ptrsize; // needed for interpreting programs
EhProgramListing_t cie_program;
EhProgramListing_t fde_program;
RelocationSet_t relocs;
EhProgramListing_t& getCIEProgram() { return cie_program; }
EhProgramListing_t& getFDEProgram() { return fde_program; }
uint8_t getCodeAlignmentFactor() const { return caf; }
int8_t getDataAlignmentFactor() const { return daf; }
int8_t getReturnRegNumber() const { return rr; }
uint8_t getPointerSize() const { return ptrsize; }
EhProgramPlaceHolder_t(const IRDB_SDK::EhProgram_t* orig)
:
caf(orig->getCodeAlignmentFactor()),
daf(orig->getDataAlignmentFactor()),
rr(orig->getReturnRegNumber()),
ptrsize(orig->getPointerSize()),
cie_program(orig->getCIEProgram()),
fde_program(orig->getFDEProgram()),
relocs(orig->getRelocations())
{
}
};
StampValue_t stamp_value = (StampValue_t)0;
bool verbose = false;
int instructions_added = 0;
int functionsTransformed = 0;
int functionsNotTransformed = 0;
map<EhProgramPlaceHolder_t, EhProgram_t*> all_eh_pgms;
friend bool operator<(const EhProgramPlaceHolder_t &a, const EhProgramPlaceHolder_t& b) ;
};
bool operator<(const StackStamp_t::EhProgramPlaceHolder_t &a, const StackStamp_t::EhProgramPlaceHolder_t& b);
}
#endif
......@@ -37,143 +37,121 @@ using namespace IRDB_SDK;
class StackStampDriver_t : public IRDB_SDK::TransformStep_t
{
private:
const string programName=string("libstack_stamp.so");
int variantID = BaseObj_t::NOT_IN_DATABASE;
bool verbose=false;
Stamper::StampValue_t stamp_value=-1;
public:
public:
void usage(const string& name)
{
cerr<<"Usage: "<<name<<" <variant_id>\n";
cerr<<"\t--stamp-value <value> Set the stamp value that will be used. "<<endl;
cerr<<"\t-s <value> (as parsed by by strtoul) "<<endl;
cerr<<"\t--verbose Verbose mode. "<<endl;
cerr<<"\t-v "<<endl;
cerr<<"--help,--usage,-?,-h Display this message "<<endl;
}
string programName="libstack_stamp.so";
int variantID = BaseObj_t::NOT_IN_DATABASE;
bool verbose=false;
StampValue_t stamp_value=-1;
int parseArgs(const vector<string> step_args)
{
auto argv = vector<char*>();
transform(ALLOF(step_args), back_inserter(argv), [](const string &s) -> char* { return const_cast<char*>(s.c_str()); } );
const auto argc=step_args.size();
variantID = atoi(argv[0]);
srand(getpid()+time(NULL));
stamp_value=rand();
if(argc < 1)
{
usage(programName);
return 1;
}
// Parse some options for the transform
static struct option long_options[] = {
{"stamp-value", required_argument, 0, 's'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"usage", no_argument, 0, '?'},
{0,0,0,0}
};
const char* short_opts="s:v?h";
while(true)
{
int index = 0;
int c = getopt_long(argc, &argv[0],short_opts, long_options, &index);
if(c == -1)
break;
switch(c)
void usage(const string& name)
{
case 's':
stamp_value=strtoul(optarg,NULL,0);
break;
case 'v':
verbose=true;
break;
case '?':
case 'h':
usage(argv[0]);
return 1;
break;
default:
break;
cerr<<"Usage: "<<name<<" <variant_id>\n";
cerr<<"\t--stamp-value <value> Set the stamp value that will be used. "<<endl;
cerr<<"\t-s <value> (as parsed by by strtoul) "<<endl;
cerr<<"\t--verbose Verbose mode. "<<endl;
cerr<<"\t-v "<<endl;
cerr<<"--help,--usage,-?,-h Display this message "<<endl;
}
}
cout<<"Stamp value is set to:"<<hex<<stamp_value<<endl;
return 0;
}
int executeStep(IRDBObjects_t *const irdb_objects)
{
int parseArgs(const vector<string> step_args)
{
/* convert to argv format for esay parsing wth getopts */
auto argv = vector<char*>();
transform(ALLOF(step_args), back_inserter(argv), [](const string &s) -> char* { return const_cast<char*>(s.c_str()); } );
const auto argc=step_args.size();
variantID = atoi(argv[0]);
srand(getpid()+time(NULL));
stamp_value=rand();
/* setup the interface to the sql server */
pqxxDB_t &pqxx_interface=*irdb_objects->getDBInterface();;
BaseObj_t::setInterface(&pqxx_interface);
if(argc < 1)
{
usage(programName);
return 1;
}
const auto pidp = irdb_objects->addVariant(variantID);
assert(pidp->isRegistered()==true);
// declare getopts values
const auto short_opts="s:v?h";
struct option long_options[] = {
{"stamp-value", required_argument, 0, 's'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"usage", no_argument, 0, '?'},
{0,0,0,0}
};
// Parse options for the transform
while(true)
{
auto index = 0;
auto c = getopt_long(argc, &argv[0],short_opts, long_options, &index);
if(c == -1)
break;
switch(c)
{
case 's':
stamp_value=strtoul(optarg,NULL,0);
break;
case 'v':
verbose=true;
break;
case '?':
case 'h':
usage(argv[0]);
return 1;
break;
default:
break;
}
}
bool one_success = false;
for(auto this_file : pidp->getFiles())
{
auto firp = irdb_objects->addFileIR(variantID, this_file->getBaseID());
cout<<"Stamp value is set to:"<<hex<<stamp_value<<endl;
return 0;
}
int executeStep(IRDBObjects_t *const irdb_objects)
{
cout<<"Transforming "<<this_file->getURL()<<endl;
assert(firp && pidp);
/* setup the interface to the sql server */
auto &pqxx_interface=*irdb_objects->getDBInterface();;
BaseObj_t::setInterface(&pqxx_interface);
try
{
StackStamp_t ss(firp, stamp_value, verbose);
const auto pidp = irdb_objects->addVariant(variantID);
assert(pidp->isRegistered()==true);
auto success = false;
auto this_file=pidp->getMainFile();
auto firp = irdb_objects->addFileIR(variantID, this_file->getBaseID());
int success=ss.execute();
cout<<"Transforming "<<this_file->getURL()<<endl;
if (success)
{
cout<<"Writing changes for "<<this_file->getURL()<<endl;
one_success = true;
// firp->writeToDB();
}
else
try
{
cout<<"Skipping (no changes) "<<this_file->getURL()<<endl;
Stamper::StackStamp_t ss(firp, stamp_value, verbose);
success=ss.execute();
}
catch (DatabaseError_t pnide)
{
cerr << programName << ": Unexpected database error: " << pnide << "file url: " << this_file->getURL() << endl;
}
catch (...)
{
cerr << programName << ": Unexpected error file url: " << this_file->getURL() << endl;
}
}
catch (DatabaseError_t pnide)
{
cerr << programName << ": Unexpected database error: " << pnide << "file url: " << this_file->getURL() << endl;
}
catch (...)
{
cerr << programName << ": Unexpected error file url: " << this_file->getURL() << endl;
}
} // end file iterator
// if any integer transforms for any files succeeded, we commit
if (one_success)
{
cout<<"Commiting changes...\n";
}
return 0;
}
std::string getStepName(void) const override
{
return std::string("stack_stamp");
}
return success ? 0 : 2;
}
string getStepName(void) const override
{
return string("stack_stamp");
}
};
extern "C"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment