Merge remote-tracking branch 'origin/master' into sampling-wip
Change-Id: Iae5c02be5801d75e8adc55222ccb35c559f7ebf4
This commit is contained in:
@ -91,4 +91,5 @@ target_link_libraries(memorymap-test fail-util)
|
||||
add_test(NAME memorymap-test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/testing COMMAND memorymap-test)
|
||||
|
||||
add_executable(sumtree-test testing/SumTreeTest.cc)
|
||||
target_link_libraries(sumtree-test fail-util)
|
||||
add_test(NAME sumtree-test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/testing COMMAND sumtree-test)
|
||||
|
||||
@ -43,8 +43,13 @@ bool CommandLine::parse() {
|
||||
option::Descriptor desc = {0, 0, 0, 0, 0, 0};
|
||||
this->options.push_back(desc);
|
||||
|
||||
// Generate the options stats
|
||||
option::Stats stats(this->options.data(), argv.size(), argv.data());
|
||||
// Copy argv to preserve original argument order
|
||||
// (for proper re-parsing after adding more options)
|
||||
argv_reordered = argv;
|
||||
|
||||
// Generate the options stats (GNU mode)
|
||||
option::Stats stats(true, this->options.data(),
|
||||
argv_reordered.size(), argv_reordered.data());
|
||||
|
||||
if (parsed_options)
|
||||
delete[] parsed_options;
|
||||
@ -56,9 +61,9 @@ bool CommandLine::parse() {
|
||||
parsed_options = new option::Option[stats.options_max];
|
||||
parsed_buffer = new option::Option[stats.buffer_max];
|
||||
|
||||
m_parser = new option::Parser(this->options.data(), argv.size(), argv.data(),
|
||||
parsed_options, parsed_buffer);
|
||||
|
||||
m_parser = new option::Parser(true, this->options.data(),
|
||||
argv_reordered.size(), argv_reordered.data(),
|
||||
parsed_options, parsed_buffer);
|
||||
|
||||
// Pop the terminating entry
|
||||
this->options.pop_back();
|
||||
|
||||
@ -30,7 +30,7 @@ public:
|
||||
private:
|
||||
static CommandLine m_instance;
|
||||
|
||||
std::vector<const char *> argv;
|
||||
std::vector<const char *> argv, argv_reordered;
|
||||
std::vector<option::Descriptor> options;
|
||||
option::Option *parsed_options, *parsed_buffer;
|
||||
option::Parser *m_parser;
|
||||
|
||||
@ -133,9 +133,11 @@ void DatabaseProtobufAdapter::TypeBridge_string::bind(MYSQL_BIND *bind, const go
|
||||
/* Handle the NULL case */
|
||||
if (insert_null(bind, msg)) return;
|
||||
|
||||
buffer = ref->GetString(*msg, desc);
|
||||
|
||||
bind->buffer_type = MYSQL_TYPE_STRING;
|
||||
bind->buffer = (void *) ref->GetString(*msg, desc).c_str();
|
||||
bind->buffer_length = ref->GetString(*msg, desc).length();
|
||||
bind->buffer = (void *) buffer.c_str();
|
||||
bind->buffer_length = buffer.length();
|
||||
}
|
||||
void DatabaseProtobufAdapter::TypeBridge_enum::bind(MYSQL_BIND *bind, const google::protobuf::Message *msg) {
|
||||
const google::protobuf::Reflection *ref = msg->GetReflection();
|
||||
|
||||
@ -80,7 +80,7 @@ class DatabaseProtobufAdapter {
|
||||
TypeBridge_uint32(const google::protobuf::FieldDescriptor *desc)
|
||||
: TypeBridge(desc){};
|
||||
|
||||
virtual std::string sql_type() { return "INT"; };
|
||||
virtual std::string sql_type() { return "INT UNSIGNED"; };
|
||||
virtual int element_size() { return 4; };
|
||||
virtual void copy_to(const google::protobuf::Message *msg, int i, void *);
|
||||
virtual void bind(MYSQL_BIND *bind, const google::protobuf::Message *msg);
|
||||
@ -101,7 +101,7 @@ class DatabaseProtobufAdapter {
|
||||
TypeBridge_uint64(const google::protobuf::FieldDescriptor *desc)
|
||||
: TypeBridge(desc){};
|
||||
|
||||
virtual std::string sql_type() { return "BIGINT"; };
|
||||
virtual std::string sql_type() { return "BIGINT UNSIGNED"; };
|
||||
virtual int element_size() { return 8; };
|
||||
virtual void copy_to(const google::protobuf::Message *msg, int i, void *);
|
||||
virtual void bind(MYSQL_BIND *bind, const google::protobuf::Message *msg);
|
||||
@ -138,6 +138,7 @@ class DatabaseProtobufAdapter {
|
||||
};
|
||||
|
||||
struct TypeBridge_string : TypeBridge {
|
||||
std::string buffer;
|
||||
TypeBridge_string(const google::protobuf::FieldDescriptor *desc)
|
||||
: TypeBridge(desc){};
|
||||
virtual std::string sql_type() { return "TEXT"; };
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <map>
|
||||
|
||||
#include "DwarfReader.hpp"
|
||||
#include "libdwarf.h"
|
||||
@ -128,8 +130,10 @@ bool DwarfReader::read_source_files(const std::string& fileName,std::list<std::s
|
||||
while (dwarf_next_cu_header(dbg,0,0,0,0,&header,0)==DW_DLV_OK) {
|
||||
// Access the die
|
||||
Dwarf_Die die;
|
||||
if (dwarf_siblingof(dbg,0,&die,0)!=DW_DLV_OK)
|
||||
if (dwarf_siblingof(dbg,0,&die,0)!=DW_DLV_OK) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the source lines
|
||||
Dwarf_Line* lineBuffer;
|
||||
@ -140,17 +144,25 @@ bool DwarfReader::read_source_files(const std::string& fileName,std::list<std::s
|
||||
// Store them
|
||||
for (int index=0;index<lineCount;index++) {
|
||||
Dwarf_Unsigned lineNo;
|
||||
if (dwarf_lineno(lineBuffer[index],&lineNo,0)!=DW_DLV_OK)
|
||||
if (dwarf_lineno(lineBuffer[index],&lineNo,0)!=DW_DLV_OK){
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
char* lineSource;
|
||||
if (dwarf_linesrc(lineBuffer[index],&lineSource,0)!=DW_DLV_OK)
|
||||
if (dwarf_linesrc(lineBuffer[index],&lineSource,0)!=DW_DLV_OK){
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
Dwarf_Bool isCode;
|
||||
if (dwarf_linebeginstatement(lineBuffer[index],&isCode,0)!=DW_DLV_OK)
|
||||
if (dwarf_linebeginstatement(lineBuffer[index],&isCode,0)!=DW_DLV_OK){
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
Dwarf_Addr addr;
|
||||
if (dwarf_lineaddr(lineBuffer[index],&addr,0)!=DW_DLV_OK)
|
||||
if (dwarf_lineaddr(lineBuffer[index],&addr,0)!=DW_DLV_OK){
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lineNo&&isCode) {
|
||||
//LOG << "lineNo: " << lineNo << " addr: " << reinterpret_cast<void*>(addr) << " line source:" << normalize(lineSource) << endl;
|
||||
@ -171,14 +183,20 @@ bool DwarfReader::read_source_files(const std::string& fileName,std::list<std::s
|
||||
lines.unique();
|
||||
|
||||
// Shut down libdwarf
|
||||
if (dwarf_finish(dbg,0)!=DW_DLV_OK)
|
||||
if (dwarf_finish(dbg,0)!=DW_DLV_OK) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DwarfReader::read_mapping(std::string fileName, std::list<addrToLine>& addrToLineList) {
|
||||
bool DwarfReader::read_mapping(std::string fileName, std::list<DwarfLineMapping>& lineMapping) {
|
||||
// temporary mapping of instruction address to (file, line)
|
||||
// => static instruction addresses are sorted ascendingly for the whole binary
|
||||
// (i.e. all instructions from all CUs!)
|
||||
std::map<unsigned, SourceLine> instr_to_sourceline;
|
||||
|
||||
// Open The file
|
||||
int fd=open(fileName.c_str(),O_RDONLY);
|
||||
@ -200,10 +218,13 @@ bool DwarfReader::read_mapping(std::string fileName, std::list<addrToLine>& addr
|
||||
|
||||
// Iterator over the headers
|
||||
Dwarf_Unsigned header;
|
||||
// iterate compilation unit headers
|
||||
while (dwarf_next_cu_header(dbg,0,0,0,0,&header,0)==DW_DLV_OK) {
|
||||
// Access the die
|
||||
Dwarf_Die die;
|
||||
// XXX: "if there are no sibling headers, die" | semantics unclear!
|
||||
if (dwarf_siblingof(dbg,0,&die,0)!=DW_DLV_OK) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -211,6 +232,7 @@ bool DwarfReader::read_mapping(std::string fileName, std::list<addrToLine>& addr
|
||||
Dwarf_Line* lineBuffer;
|
||||
Dwarf_Signed lineCount;
|
||||
if (dwarf_srclines(die,&lineBuffer,&lineCount,0)!=DW_DLV_OK) {
|
||||
close(fd);
|
||||
continue; //return false;
|
||||
}
|
||||
|
||||
@ -218,24 +240,30 @@ bool DwarfReader::read_mapping(std::string fileName, std::list<addrToLine>& addr
|
||||
for (int index=0;index<lineCount;index++) {
|
||||
Dwarf_Unsigned lineNo;
|
||||
if (dwarf_lineno(lineBuffer[index],&lineNo,0)!=DW_DLV_OK) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
char* lineSource;
|
||||
if (dwarf_linesrc(lineBuffer[index],&lineSource,0)!=DW_DLV_OK) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
Dwarf_Bool isCode;
|
||||
if (dwarf_linebeginstatement(lineBuffer[index],&isCode,0)!=DW_DLV_OK) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
Dwarf_Addr addr;
|
||||
if (dwarf_lineaddr(lineBuffer[index],&addr,0)!=DW_DLV_OK) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lineNo&&isCode) {
|
||||
struct addrToLine newLine = { (int) addr, (int) lineNo, normalize(lineSource) };
|
||||
addrToLineList.push_back(newLine);
|
||||
// wrap line_number and source_file into an object
|
||||
SourceLine tmp_sl(normalize(lineSource), lineNo);
|
||||
// store SourceLine object with static instr in the map
|
||||
instr_to_sourceline.insert(std::make_pair(addr, tmp_sl));
|
||||
}
|
||||
|
||||
dwarf_dealloc(dbg,lineSource,DW_DLA_STRING);
|
||||
@ -250,9 +278,30 @@ bool DwarfReader::read_mapping(std::string fileName, std::list<addrToLine>& addr
|
||||
|
||||
// Shut down libdwarf
|
||||
if (dwarf_finish(dbg,0)!=DW_DLV_OK) {
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
// iterate instr_to_sourceline to determine the "line_range_size" for mapping
|
||||
std::map<unsigned, SourceLine>::iterator it;
|
||||
for (it = instr_to_sourceline.begin(); it != instr_to_sourceline.end(); it++) {
|
||||
unsigned addr = it->first;
|
||||
SourceLine sl = it->second;
|
||||
|
||||
/* Default the linetable's address range (->"size") to the maximum
|
||||
* possible value. This results in the last linetable entry having
|
||||
* maximum range. This entry will either be a dummy or a function's
|
||||
* epilogue, both of which are irrelevant for our (current) use cases.
|
||||
* All other entries' sizes are set properly. */
|
||||
DwarfLineMapping mapping(addr, (std::numeric_limits<unsigned>::max() - addr),
|
||||
sl.line_number, sl.source_file);
|
||||
if (!lineMapping.empty()) {
|
||||
DwarfLineMapping& back = lineMapping.back();
|
||||
back.line_range_size = addr - back.absolute_addr;
|
||||
}
|
||||
lineMapping.push_back(mapping);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -7,6 +7,26 @@
|
||||
|
||||
namespace fail {
|
||||
|
||||
// temporary wrapper object for (file, linenumber)
|
||||
class SourceLine {
|
||||
public:
|
||||
std::string source_file;
|
||||
unsigned line_number;
|
||||
|
||||
SourceLine(std::string source, unsigned line) : source_file(source), line_number(line) {}
|
||||
};
|
||||
|
||||
// wrapper object for insertion into DB
|
||||
class DwarfLineMapping {
|
||||
public:
|
||||
unsigned absolute_addr;
|
||||
unsigned line_range_size;
|
||||
unsigned line_number;
|
||||
std::string line_source;
|
||||
|
||||
DwarfLineMapping(unsigned addr, unsigned size, unsigned number, std::string src)
|
||||
: absolute_addr(addr), line_range_size(size), line_number(number), line_source(src){}
|
||||
};
|
||||
|
||||
/**
|
||||
* This source code is based on bcov 0.2.
|
||||
@ -15,23 +35,16 @@ namespace fail {
|
||||
* GNU GENERAL PUBLIC LICENSE
|
||||
*/
|
||||
|
||||
struct addrToLine {
|
||||
int absoluteAddr;
|
||||
int lineNumber;
|
||||
std::string lineSource;
|
||||
};
|
||||
|
||||
/**
|
||||
* \class DwarfReader
|
||||
* ToDO
|
||||
*/
|
||||
|
||||
class DwarfReader {
|
||||
/**
|
||||
* \class DwarfReader
|
||||
* ToDO
|
||||
*/
|
||||
class DwarfReader {
|
||||
|
||||
public:
|
||||
|
||||
bool read_source_files(const std::string& fileName, std::list<std::string>& lines);
|
||||
bool read_mapping(std::string fileName, std::list<addrToLine>& addrToLineList);
|
||||
bool read_mapping(std::string fileName, std::list<DwarfLineMapping>& lineMapping);
|
||||
};
|
||||
|
||||
} // end-of-namespace fail
|
||||
|
||||
@ -19,11 +19,15 @@ bool MemoryMap::readFromFile(char const * const filename)
|
||||
unsigned count = 0;
|
||||
|
||||
while (getline(file, buf)) {
|
||||
std::string addr, len;
|
||||
std::stringstream ss(buf, std::ios::in);
|
||||
ss >> guest_addr >> guest_len;
|
||||
ss >> addr >> len;
|
||||
guest_addr = strtoul(addr.c_str(), NULL, 0);
|
||||
guest_len = strtoul(len.c_str(), NULL, 0);
|
||||
add(guest_addr, guest_len);
|
||||
count++;
|
||||
}
|
||||
|
||||
// assertion kept from original code; usually something's fishy if the file
|
||||
// contains no entries
|
||||
assert(count > 0);
|
||||
|
||||
@ -11,8 +11,7 @@ set(SRCS
|
||||
|
||||
include(FindLLVM)
|
||||
|
||||
# compiling without -fno-rtti fails even when LLVM is not built with that flag
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS} -fno-rtti" )
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS}" )
|
||||
|
||||
add_library(fail-llvmdisassembler ${SRCS})
|
||||
target_link_libraries(fail-llvmdisassembler fail-sal)
|
||||
|
||||
@ -49,7 +49,10 @@ LLVMtoFailTranslator* LLVMtoFailTranslator::createFromBinary(const std::string e
|
||||
llvm::InitializeAllDisassemblers();
|
||||
|
||||
OwningPtr<Binary> binary;
|
||||
assert(createBinary(elf_path, binary) == 0);
|
||||
llvm::error_code ret = createBinary(elf_path, binary);
|
||||
assert (ret == 0);
|
||||
(void) ret; // unused in release builds
|
||||
assert (binary.get() != NULL);
|
||||
|
||||
#ifndef __puma
|
||||
LLVMDisassembler disas(dyn_cast<ObjectFile>(binary.get()));
|
||||
@ -57,4 +60,4 @@ LLVMtoFailTranslator* LLVMtoFailTranslator::createFromBinary(const std::string e
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
#ifndef __puma
|
||||
#include "../LLVMDisassembler.hpp"
|
||||
|
||||
using namespace llvm;
|
||||
@ -69,4 +68,3 @@ int main(int argc, char* argv[]) {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
#include "util/SumTree.hpp"
|
||||
#include "util/Logger.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#define LOG std::cerr
|
||||
|
||||
using std::endl;
|
||||
|
||||
fail::Logger LOG("SumTreeTest");
|
||||
|
||||
struct Pilot {
|
||||
uint32_t id;
|
||||
uint32_t instr2;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <stdlib.h>
|
||||
#include "util/MemoryMap.hpp"
|
||||
|
||||
using namespace fail;
|
||||
@ -16,6 +17,7 @@ uint32_t outside[] = { 0, 10, 16, 1, 20, 1, 25, 10 };
|
||||
void test_failed(std::string msg)
|
||||
{
|
||||
cerr << "MemoryMap test failed (" << msg << ")!" << endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
// pass by value intentional
|
||||
@ -98,6 +100,7 @@ int main()
|
||||
char const *filename_tmp = "tmp.memorymap";
|
||||
char const *filename_test1 = "test1.memorymap";
|
||||
char const *filename_test2 = "test2.memorymap";
|
||||
char const *filename_test3 = "test3.memorymap";
|
||||
|
||||
for (unsigned i = 0; i < LEN(inside); i += 2) {
|
||||
mm.add(inside[i], inside[i+1]);
|
||||
@ -125,4 +128,8 @@ int main()
|
||||
mm.clear();
|
||||
mm.readFromFile(filename_test2);
|
||||
test(mm);
|
||||
|
||||
mm.clear();
|
||||
mm.readFromFile(filename_test3);
|
||||
test(mm);
|
||||
}
|
||||
|
||||
3
src/core/util/testing/test3.memorymap
Normal file
3
src/core/util/testing/test3.memorymap
Normal file
@ -0,0 +1,3 @@
|
||||
012 0x6
|
||||
0x11 3
|
||||
21 0x4
|
||||
Reference in New Issue
Block a user