Merge changes I7fe63611,I84ebbb50

* changes:
  util/DwarfReader, ElfImporter: import address ranges
  util/DwarfReader, ElfImporter: use unsigned addresses
This commit is contained in:
Michael Lenz
2014-10-23 07:53:46 +02:00
committed by Gerrit Code Review
3 changed files with 46 additions and 26 deletions

View File

@ -1,4 +1,5 @@
#include <fstream>
#include <limits>
#include <fcntl.h>
#include <unistd.h>
@ -178,7 +179,7 @@ bool DwarfReader::read_source_files(const std::string& fileName,std::list<std::s
return true;
}
bool DwarfReader::read_mapping(std::string fileName, std::list<addrToLine>& addrToLineList) {
bool DwarfReader::read_mapping(std::string fileName, std::list<DwarfLineMapping>& lineMapping) {
// Open The file
int fd=open(fileName.c_str(),O_RDONLY);
@ -200,9 +201,11 @@ 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) {
return false;
}
@ -234,8 +237,21 @@ bool DwarfReader::read_mapping(std::string fileName, std::list<addrToLine>& addr
}
if (lineNo&&isCode) {
struct addrToLine newLine = { (int) addr, (int) lineNo, normalize(lineSource) };
addrToLineList.push_back(newLine);
/* default the linetable's address range (->size) to the maximum
* possible range. this results in the last linetable entry having
* maximum range. as this always (?) is a function epilogue, its
* irrelevant for our use-case. */
// TODO: properly determine the last interval's range, e.g. via __TEXT_END
DwarfLineMapping mapping(addr, (std::numeric_limits<unsigned>::max() - addr),
lineNo, lineSource);
// the address range for the previous line ends with the current line's address
if (!lineMapping.empty()) {
DwarfLineMapping& back = lineMapping.back();
// update the previous lineRangeSize appropriately
back.line_range_size = (addr - back.absolute_addr);
}
lineMapping.push_back(mapping);
}
dwarf_dealloc(dbg,lineSource,DW_DLA_STRING);

View File

@ -7,6 +7,16 @@
namespace fail {
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 +25,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