Skip to content

Commit

Permalink
More comprehensive and deterministic reporting (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterbrereton committed May 14, 2024
1 parent bcda6e1 commit 0c5c524
Show file tree
Hide file tree
Showing 14 changed files with 445 additions and 198 deletions.
2 changes: 2 additions & 0 deletions _orc-config
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ resource_metrics = false
violation_report = [
'class:byte_size',
'member:data_member_location',
'member:alignment',
# 'member:type',
'structure:byte_size',
'subprogram:virtuality',
'subprogram:vtable_elem_location'
Expand Down
31 changes: 31 additions & 0 deletions include/orc/dwarf_structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
#include <array>
#include <cassert>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>

// application
#include "orc/dwarf_constants.hpp"
#include "orc/hash.hpp"
#include "orc/string_pool.hpp"

/**************************************************************************************************/
Expand Down Expand Up @@ -252,6 +254,34 @@ std::ostream& operator<<(std::ostream& s, const attribute_sequence& x);

/**************************************************************************************************/

struct location {
pool_string file;
std::uint64_t loc{0};
};

inline bool operator==(const location& x, const location& y) {
return x.file == y.file && x.loc == y.loc;
}
inline bool operator!=(const location& x, const location& y) {
return !(x == y);
}
inline bool operator<(const location& x, const location& y) {
return x.file.hash() < y.file.hash() || (x.file == y.file && x.loc < y.loc);
}

template <>
struct std::hash<location> {
std::size_t operator()(const location& x) const {
return orc::hash_combine(x.file.hash(), x.loc);
}
};

std::ostream& operator<<(std::ostream&, const location&);

std::optional<location> derive_definition_location(const attribute_sequence& x);

/**************************************************************************************************/

enum class arch : std::uint8_t {
unknown,
x86,
Expand Down Expand Up @@ -320,6 +350,7 @@ struct die {
std::uint32_t _ofd_index{0}; // object file descriptor index
std::size_t _cu_die_address{0}; // address of associated compilation unit die entry
std::uint32_t _debug_info_offset{0}; // relative from top of __debug_info
std::optional<location> _location; // file_decl and file_line, if they exit for the die.
dw::tag _tag{dw::tag::none};
arch _arch{arch::unknown};
bool _has_children{false};
Expand Down
27 changes: 22 additions & 5 deletions include/orc/orc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@
struct odrv_report {
odrv_report(std::string_view symbol, const die* list_head);

std::string category() const;
std::size_t category_count() const { return _conflicting_attributes.size(); }
std::string category(std::size_t n) const;
std::string reporting_categories() const;
std::string filtered_categories() const;

using symbol_instances = std::vector<object_ancestry>;
using symbol_declaration = location;
using symbol_location_map = std::unordered_map<symbol_declaration, symbol_instances>;

struct conflict_details {
const die* _die{nullptr};
dw::tag _tag{dw::tag::none};
attribute_sequence _attributes;
symbol_location_map _locations;
std::size_t _count{0}; // may be different than _locations.size()
};

const auto& conflict_map() const { return _conflict_map; }
Expand All @@ -36,13 +45,13 @@ struct odrv_report {
private:
const die* _list_head{nullptr};
mutable std::map<std::size_t, conflict_details> _conflict_map;
dw::at _name{dw::at::none};
std::vector<dw::at> _conflicting_attributes;
};

std::ostream& operator<<(std::ostream& s, const odrv_report& x);

// Return `true` if an ODRV
bool filter_report(const odrv_report& report);
// Return `true` if the ODRV report is one we should emit
bool emit_report(const odrv_report& report);

/**************************************************************************************************/

Expand All @@ -54,7 +63,15 @@ void orc_reset();
const char* demangle(const char* x);

/**************************************************************************************************/
// TODO: (fosterbrereton) Find a better home for this somewhere?
template <class C>
void sort_unique(C& container) {
std::sort(container.begin(), container.end());
const auto new_end = std::unique(container.begin(), container.end());
container.erase(new_end, container.end());
}

/**************************************************************************************************/

std::mutex& ostream_safe_mutex();

Expand Down

0 comments on commit 0c5c524

Please sign in to comment.