Newer
Older
/*
* SMPProgram.h - <see below>.
*
* Copyright (c) 2000, 2001, 2010 - University of Virginia
*
* This file is part of the Memory Error Detection System (MEDS) infrastructure.
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from the University
* of Virginia.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: University of Virginia
* e-mail: jwd@virginia.com
* URL : http://www.cs.virginia.edu/
*
* Additional copyrights 2010, 2011 by Zephyr Software LLC
* e-mail: {clc,jwd}@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
#ifndef SMPPROGRAM_H
#define SMPPROGRAM_H 1
// SMPProgram.h
//
// This header defines the interfaces needed for analyzing whole programs.
clc5q
committed
#include <string>
#include <utility>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <cstddef>
#include <pro.h>
#include <ida.hpp>
#include <ua.hpp>
#include "SMPDataFlowAnalysis.h"
#include "SMPInstr.h"
#include "SMPBasicBlock.h"
#include "SMPFunction.h"
using namespace std;
clc5q
committed
class ProfilerInformation;
extern ea_t LowestGlobalVarAddress;
extern ea_t HighestGlobalVarAddress;
extern ea_t LowestCodeAddress;
extern ea_t HighestCodeAddress;
inline bool IsImmedGlobalAddress(ea_t ImmedValue) {
return ((ImmedValue >= LowestGlobalVarAddress) && (ImmedValue <= HighestGlobalVarAddress));
}
// NOTE: Change this when we do targets with data (ither than switch tables) in code
inline bool IsImmedCodeAddress(ea_t ImmedValue) {
return ((ImmedValue >= LowestCodeAddress) && (ImmedValue <= HighestCodeAddress));
}
inline bool IsImmedNumeric(ea_t ImmedValue) {
return (!(IsImmedGlobalAddress(ImmedValue) || IsImmedCodeAddress(ImmedValue)));
}
clc5q
committed
class LessOff {
public:
bool operator()(const pair<size_t, bool> &Off1, const pair<size_t, bool> &Off2) const {
return (Off1.first < Off2.first);
} // end operator
}; // end class LessOff
clc5q
committed
bool IndexedAccess;
clc5q
committed
set<pair<size_t, bool>, LessOff> FieldOffsets; // bool = accessed through index register by any instruction?
clc5q
committed
class LtStr {
public:
bool operator() (const char* c1, const char* c2) const {
return strcmp(c1, c2) < 0;
}
};
// Class encapsulating all that the SMP static analyzer cares to know
// about a whole program.
class SMPProgram {
public:
// Constructors
SMPProgram(void); // Default constructor
~SMPProgram(void); // Destructor
// Get methods
clc5q
committed
inline map<string, ea_t>::iterator FindGlobalName(string Name) {
return GlobalNameMap.find(Name);
}
inline map<string, ea_t>::iterator GetLastGlobalName(void) {
return GlobalNameMap.end();
}
inline ProfilerInformation *GetProfInfo(void) { return ProfInfo; };
void ProfGranularityFinished(FILE *AnnotFile, FILE *InfoAnnotFile); // notification from ProfilerInformation
// Query methods
// Printing methods
void Dump(void); // debug dump
// Analysis methods
clc5q
committed
void AnalyzeData(void); // Analyze static data in the program.
void Analyze(ProfilerInformation* pi); // Analyze all functions in the program
void EmitDataAnnotations(FILE *AnnotFile, FILE *InfoAnnotFile); // Emit annotations for global data
void EmitAnnotations(FILE *AnnotFile, FILE *InfoAnnotFile); // Emit annotations for all functions
SMPFunction* FindFunction(ea_t addr) { return FuncMap[addr]; }
bool ProfilerGranularityComplete; // Profiler-based granularity inference complete
FILE *AnnotationFile; // need to store temporarily to pass to EmitDataAnnotations
FILE *InfoAnnotationFile; // need to store temporarily to pass to EmitDataAnnotations
map<ea_t, SMPFunction *> FuncMap; // all functions in the program
map<ea_t, struct GlobalVar> GlobalVarTable; // all global static variables
clc5q
committed
map<string, ea_t> GlobalNameMap; // map global name to address
set<const char*, LtStr> FuncNameSet;
// Methods
void InitStaticDataTable(void); // Gather info about global static data locations
void ComputeGlobalFieldOffsets(struct GlobalVar &CurrGlobal);
clc5q
committed
void ComputeGlobalSets(void); // LiveIn, LiveOut, VarKill for each func
FuncType RecurseAndMarkRetAdd(SMPFunction *);