diff options
author | Alex White <alex.white@oarcorp.com> | 2021-04-30 14:34:18 -0500 |
---|---|---|
committer | Joel Sherrill <joel@rtems.org> | 2021-06-17 16:00:08 -0500 |
commit | ac56fce7c17e40c6ecd7980fa828a76550bbacb3 (patch) | |
tree | e59a7e98baa63d8ac08a9265f5b8c9dd6d58efde /tester/covoar/AddressToLineMapper.cc | |
parent | covoar: Store only the file name in ExecutableInfo (diff) | |
download | rtems-tools-ac56fce7c17e40c6ecd7980fa828a76550bbacb3.tar.bz2 |
covoar: Store address-to-line info outside of DWARF
This adds the AddressToLineMapper class and supporting classes to
assume responsibility of tracking address-to-line information.
This allows the DWARF library to properly cleanup all of its resources
and leads to significant memory savings.
Closes #4383
Diffstat (limited to 'tester/covoar/AddressToLineMapper.cc')
-rw-r--r-- | tester/covoar/AddressToLineMapper.cc | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/tester/covoar/AddressToLineMapper.cc b/tester/covoar/AddressToLineMapper.cc new file mode 100644 index 0000000..c305e3b --- /dev/null +++ b/tester/covoar/AddressToLineMapper.cc @@ -0,0 +1,104 @@ +/*! @file AddressToLineMapper.cc + * @brief AddressToLineMapper Implementation + * + * This file contains the implementation of the functionality + * of the AddressToLineMapper class. + */ + +#include "AddressToLineMapper.h" + +namespace Coverage { + + uint64_t SourceLine::location() const + { + return address; + } + + bool SourceLine::is_an_end_sequence() const + { + return is_end_sequence; + } + + const std::string& SourceLine::path() const + { + return path_; + } + + int SourceLine::line() const + { + return line_num; + } + + void AddressLineRange::addSourceLine(const rld::dwarf::address& address) + { + auto insertResult = sourcePaths.insert(address.path()); + + sourceLines.emplace_back( + SourceLine ( + address.location(), + *insertResult.first, + address.line(), + address.is_an_end_sequence() + ) + ); + } + + const SourceLine& AddressLineRange::getSourceLine(uint32_t address) const + { + if (address < lowAddress || address > highAddress) { + throw SourceNotFoundError(std::to_string(address)); + } + + const SourceLine* last_line = nullptr; + for (const auto &line : sourceLines) { + if (address <= line.location()) + { + if (address == line.location()) + last_line = &line; + break; + } + last_line = &line; + } + + if (last_line == nullptr) { + throw SourceNotFoundError(std::to_string(address)); + } + + return *last_line; + } + + void AddressToLineMapper::getSource( + uint32_t address, + std::string& sourceFile, + int& sourceLine + ) const { + const SourceLine default_sourceline = SourceLine(); + const SourceLine* match = &default_sourceline; + + for (const auto &range : addressLineRanges) { + try { + const SourceLine& potential_match = range.getSourceLine(address); + + if (match->is_an_end_sequence() || !potential_match.is_an_end_sequence()) { + match = &potential_match; + } + } catch (const AddressLineRange::SourceNotFoundError&) {} + } + + sourceFile = match->path(); + sourceLine = match->line(); + } + + AddressLineRange& AddressToLineMapper::makeRange( + uint32_t low, + uint32_t high + ) + { + addressLineRanges.emplace_back( + AddressLineRange(low, high) + ); + + return addressLineRanges.back(); + } + +} |