diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-18 06:30:32 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-18 06:30:32 +0000 |
commit | 25ee97fe8ada76755c8bd1087fac9cc3cd03b28c (patch) | |
tree | 7eb8ac2d90d4635d1c727ebd835c7aa4c90d290b /lib/ubsan/ubsan_type_hash.h | |
parent | 01e9a38b8cfe8967efb259978b754c3a9f0c380c (diff) |
ubsan: When diagnosing something wrong somewhere in memory, emit a note
pointing at the bad location and a snippet of nearby memory values. This is
strictly best-effort; reading these bytes to display the note could lead to a
seg fault, and that's explicitly OK.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@170415 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ubsan/ubsan_type_hash.h')
-rw-r--r-- | lib/ubsan/ubsan_type_hash.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/ubsan/ubsan_type_hash.h b/lib/ubsan/ubsan_type_hash.h index ac1be4944..dfaf32752 100644 --- a/lib/ubsan/ubsan_type_hash.h +++ b/lib/ubsan/ubsan_type_hash.h @@ -19,6 +19,27 @@ namespace __ubsan { typedef uptr HashValue; +/// \brief Information about the dynamic type of an object (extracted from its +/// vptr). +class DynamicTypeInfo { + const char *MostDerivedTypeName; + sptr Offset; + +public: + DynamicTypeInfo(const char *MDTN, sptr Offset) + : MostDerivedTypeName(MDTN), Offset(Offset) {} + + /// Determine whether the object had a valid dynamic type. + bool isValid() const { return MostDerivedTypeName; } + /// Get the name of the most-derived type of the object. + const char *getMostDerivedTypeName() const { return MostDerivedTypeName; } + /// Get the offset from the most-derived type to this base class. + sptr getOffset() const { return Offset; } +}; + +/// \brief Get information about the dynamic type of an object. +DynamicTypeInfo getDynamicTypeInfo(void *Object); + /// \brief Check whether the dynamic type of \p Object has a \p Type subobject /// at offset 0. /// \return \c true if the type matches, \c false if not. |