Improve debugging

This commit is contained in:
Gioacchino Mazzurco 2020-03-25 00:02:09 +01:00
parent cdafb7e27f
commit a0da5a3120
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
3 changed files with 38 additions and 19 deletions

View File

@ -55,6 +55,8 @@ RsFileTree::fromBase64(const std::string& base64)
const auto failure = [](std::error_condition ec)
{ return std::make_tuple(nullptr, ec); };
if(base64.empty()) return failure(std::errc::invalid_argument);
std::error_condition ec;
std::vector<uint8_t> mem;
if( (ec = RsBase64::decode(base64, mem)) ) return failure(ec);

View File

@ -1037,8 +1037,6 @@ protected:
VLQ_deserialize(
const uint8_t data[], uint32_t size, uint32_t& offset, T& member )
{
uint32_t backupOffset = offset;
member = 0;
uint32_t offsetBackup = offset;
@ -1048,14 +1046,14 @@ protected:
for (size_t i = 0; offset < size && i <= sizeof(T); ++i)
{
member |= (data[offset] & 127) << (7 * i);
// If the next-byte flag is not set, ++ is after on purpose
// If the next-byte flag is not set. ++ is after on purpose
if(!(data[offset++] & 128))
{
RsDbg() << __PRETTY_FUNCTION__
<< " size: " << size
<< " backupOffset " << backupOffset
<< " offset: " << offset
<< " member " << member << std::endl;
Dbg2() << __PRETTY_FUNCTION__
<< " size: " << size
<< " backupOffset " << offsetBackup
<< " offset: " << offset
<< " member " << member << std::endl;
return true;
}
}
@ -1064,13 +1062,14 @@ protected:
* ended before we encountered the end of the number, or the number
* is VLQ encoded improperly */
RsErr() << __PRETTY_FUNCTION__ << std::errc::illegal_byte_sequence
<< " size: " << size
<< " offsetBackup: " << offsetBackup
<< " offset: " << offset << " bytes: ";
for(; offsetBackup < offset; ++offsetBackup)
std::cerr << " " << std::bitset<8>(data[offsetBackup]);
std::cerr << std::endl;
RsErr().uStream() << " " << std::bitset<8>(data[offsetBackup]);
RsErr().uStream() << std::endl;
print_stacktrace();
return false;
}

View File

@ -46,7 +46,10 @@ struct t_RsLogger
{
inline t_RsLogger() = default;
typedef t_RsLogger stream_type;
/** On other platforms expose the type of underlying stream.
* On Android it cannot work like that so return the class type itself
* just for code compatibility with other platforms */
using stream_type = t_RsLogger;
template<typename T>
inline stream_type& operator<<(const T& val)
@ -68,6 +71,11 @@ struct t_RsLogger
return *this;
}
/** On other platforms return underlying stream to write avoiding additional
* prefixes. On Android it cannot work like that so return the object itself
* just for code compatibility with other platforms */
inline stream_type& uStream() { return *this; }
private:
std::ostringstream ostr;
};
@ -92,7 +100,8 @@ struct t_RsLogger
{
inline t_RsLogger() = default;
typedef decltype(std::cerr) stream_type;
/// Expose the type of underlying stream
using stream_type = decltype(std::cerr);
template<typename T>
inline stream_type& operator<<(const T& val)
@ -111,6 +120,9 @@ struct t_RsLogger
/// needed for manipulators and things like std::endl
stream_type& operator<<(std::ostream& (*pf)(std::ostream&))
{ return std::cerr << pf; }
/// Return underlying stream to write avoiding additional prefixes
inline stream_type& uStream() const { return std::cerr; }
};
#endif // def __ANDROID__
@ -176,16 +188,22 @@ struct RsNoDbg
{
inline RsNoDbg() = default;
/**
* This match most of the types, but might be not enough for templated
* types
*/
/** Defined as the type itself just for code compatibility with other
* logging classes */
using stream_type = RsNoDbg;
/** This match most of the types, but might be not enough for templated
* types */
template<typename T>
inline RsNoDbg& operator<<(const T&) { return *this; }
inline stream_type& operator<<(const T&) { return *this; }
/// needed for manipulators and things like std::endl
inline RsNoDbg& operator<<(std::ostream& (*/*pf*/)(std::ostream&))
inline stream_type& operator<<(std::ostream& (*/*pf*/)(std::ostream&))
{ return *this; }
/** Return the object itself just for code compatibility with other
* logging classes */
inline stream_type& uStream() { return *this; }
};
/**