From a0eafa50f69b88e2c366b50bc97196686ec4d8e8 Mon Sep 17 00:00:00 2001 From: babenko Date: Sat, 1 Feb 2025 22:00:57 +0300 Subject: Refactor and improve crash handler stderr dumps 1. Prevent concurrent crashes to interleave in stderr 2. Cleaner and more compact formatting of registers dump 3. Omit `OLDMASK` (nobody seems to know what is it for) 4. Don't print the top backtrace frame twice 5. Code cosmetics commit_hash:f7a4c960b3400d6dfb0f8f60317aa524611d2fd0 --- library/cpp/yt/string/raw_formatter.h | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'library/cpp/yt/string') diff --git a/library/cpp/yt/string/raw_formatter.h b/library/cpp/yt/string/raw_formatter.h index 6956330883b..23ea7f9af08 100644 --- a/library/cpp/yt/string/raw_formatter.h +++ b/library/cpp/yt/string/raw_formatter.h @@ -84,11 +84,12 @@ public: } } - //! Appends a single character and updates the internal cursor. - void AppendChar(char ch) + //! Appends a single character given number of times and updates the internal cursor. + void AppendChar(char ch, int count = 1) { - if (Cursor_ < End_) { + while (Cursor_ < End_ && count > 0) { *Cursor_++ = ch; + count--; } } @@ -97,6 +98,8 @@ public: { int digits = 0; + width = std::min(width, GetBytesRemaining()); + if (radix == 16) { // Optimize output of hex numbers. @@ -140,22 +143,6 @@ public: } } - //! Formats |number| as hexadecimal number and updates the internal cursor. - //! Padding will be added in front if needed. - void AppendNumberAsHexWithPadding(uintptr_t number, int width) - { - char* begin = Cursor_; - AppendString("0x"); - AppendNumber(number, 16); - // Move to right and add padding in front if needed. - if (Cursor_ < begin + width) { - auto delta = begin + width - Cursor_; - std::copy(begin, Cursor_, begin + delta); - std::fill(begin, begin + delta, ' '); - Cursor_ = begin + width; - } - } - //! Formats |guid| and updates the internal cursor. void AppendGuid(TGuid guid) { @@ -185,7 +172,6 @@ private: char* const Begin_; char* Cursor_; char* const End_; - }; template @@ -203,7 +189,6 @@ public: private: char Buffer_[N]; - }; //////////////////////////////////////////////////////////////////////////////// -- cgit v1.3