Skip to content

Commit

Permalink
Workaround gdb bug by changing a tempate parameter:
Browse files Browse the repository at this point in the history
There's a bug in gdb where unsigned template parameters cause issues with
RTTI. This patch changes a template parameter from `size_t` to `int` to
workaround this gdb bug.
  • Loading branch information
seelabs committed Nov 4, 2022
1 parent ebbf4b6 commit 1c4ac4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/ripple/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Some fields have a different meaning for their
class STAccount;
class STAmount;
class STBlob;
template <std::size_t>
template <int>
class STBitString;
template <class>
class STInteger;
Expand Down
34 changes: 20 additions & 14 deletions src/ripple/protocol/STBitString.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@

namespace ripple {

template <std::size_t Bits>
// The template parameter could be an unsigned type, however there's a bug in
// gdb (last checked in gdb 12.1) that prevents gdb from finding the RTTI
// information of a template parameterized by an unsigned type. This RTTI
// information is needed to write gdb pretty printers.
template <int Bits>
class STBitString final : public STBase
{
static_assert(Bits > 0, "Number of bits must be positive");

public:
using value_type = base_uint<Bits>;

Expand Down Expand Up @@ -79,36 +85,36 @@ using STUInt128 = STBitString<128>;
using STUInt160 = STBitString<160>;
using STUInt256 = STBitString<256>;

template <std::size_t Bits>
template <int Bits>
inline STBitString<Bits>::STBitString(SField const& n) : STBase(n)
{
}

template <std::size_t Bits>
template <int Bits>
inline STBitString<Bits>::STBitString(const value_type& v) : value_(v)
{
}

template <std::size_t Bits>
template <int Bits>
inline STBitString<Bits>::STBitString(SField const& n, const value_type& v)
: STBase(n), value_(v)
{
}

template <std::size_t Bits>
template <int Bits>
inline STBitString<Bits>::STBitString(SerialIter& sit, SField const& name)
: STBitString(name, sit.getBitString<Bits>())
{
}

template <std::size_t Bits>
template <int Bits>
STBase*
STBitString<Bits>::copy(std::size_t n, void* buf) const
{
return emplace(n, buf, *this);
}

template <std::size_t Bits>
template <int Bits>
STBase*
STBitString<Bits>::move(std::size_t n, void* buf)
{
Expand Down Expand Up @@ -136,22 +142,22 @@ STUInt256::getSType() const
return STI_UINT256;
}

template <std::size_t Bits>
template <int Bits>
std::string
STBitString<Bits>::getText() const
{
return to_string(value_);
}

template <std::size_t Bits>
template <int Bits>
bool
STBitString<Bits>::isEquivalent(const STBase& t) const
{
const STBitString* v = dynamic_cast<const STBitString*>(&t);
return v && (value_ == v->value_);
}

template <std::size_t Bits>
template <int Bits>
void
STBitString<Bits>::add(Serializer& s) const
{
Expand All @@ -160,28 +166,28 @@ STBitString<Bits>::add(Serializer& s) const
s.addBitString<Bits>(value_);
}

template <std::size_t Bits>
template <int Bits>
template <typename Tag>
void
STBitString<Bits>::setValue(base_uint<Bits, Tag> const& v)
{
value_ = v;
}

template <std::size_t Bits>
template <int Bits>
typename STBitString<Bits>::value_type const&
STBitString<Bits>::value() const
{
return value_;
}

template <std::size_t Bits>
template <int Bits>
STBitString<Bits>::operator value_type() const
{
return value_;
}

template <std::size_t Bits>
template <int Bits>
bool
STBitString<Bits>::isDefault() const
{
Expand Down

0 comments on commit 1c4ac4b

Please sign in to comment.