summaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorbabenko <[email protected]>2025-02-01 22:00:57 +0300
committerbabenko <[email protected]>2025-02-01 22:16:41 +0300
commita0eafa50f69b88e2c366b50bc97196686ec4d8e8 (patch)
treef0e83688395774d6f0b940d346e815d248258ab0 /library/cpp
parent8cb823cc499768ee83daaba6fb81de16054071ad (diff)
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
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/backtrace/symbolizers/dummy/dummy_symbolizer.cpp4
-rw-r--r--library/cpp/yt/backtrace/symbolizers/dynload/dynload_symbolizer.cpp4
-rw-r--r--library/cpp/yt/string/raw_formatter.h27
3 files changed, 10 insertions, 25 deletions
diff --git a/library/cpp/yt/backtrace/symbolizers/dummy/dummy_symbolizer.cpp b/library/cpp/yt/backtrace/symbolizers/dummy/dummy_symbolizer.cpp
index 19cb41e7951..3b1d37aa028 100644
--- a/library/cpp/yt/backtrace/symbolizers/dummy/dummy_symbolizer.cpp
+++ b/library/cpp/yt/backtrace/symbolizers/dummy/dummy_symbolizer.cpp
@@ -13,8 +13,8 @@ void SymbolizeBacktrace(
for (int index = 0; index < std::ssize(backtrace); ++index) {
TRawFormatter<1024> formatter;
formatter.AppendNumber(index + 1, 10, 2);
- formatter.AppendString(". ");
- formatter.AppendNumberAsHexWithPadding(reinterpret_cast<uintptr_t>(backtrace[index]), 12);
+ formatter.AppendString(". 0x");
+ formatter.AppendNumber(reinterpret_cast<uintptr_t>(backtrace[index]), /*radix*/ 16, /*width*/ 12);
formatter.AppendString("\n");
frameCallback(formatter.GetBuffer());
}
diff --git a/library/cpp/yt/backtrace/symbolizers/dynload/dynload_symbolizer.cpp b/library/cpp/yt/backtrace/symbolizers/dynload/dynload_symbolizer.cpp
index 37ebda8e488..ca4b157045b 100644
--- a/library/cpp/yt/backtrace/symbolizers/dynload/dynload_symbolizer.cpp
+++ b/library/cpp/yt/backtrace/symbolizers/dynload/dynload_symbolizer.cpp
@@ -75,10 +75,10 @@ int GetSymbolInfo(const void* pc, char* buffer, int length)
void DumpStackFrameInfo(TBaseFormatter* formatter, const void* pc)
{
- formatter->AppendString("@ ");
+ formatter->AppendString("@ 0x");
const int width = (sizeof(void*) == 8 ? 12 : 8) + 2;
// +2 for "0x"; 12 for x86_64 because higher bits are always zeroed.
- formatter->AppendNumberAsHexWithPadding(reinterpret_cast<uintptr_t>(pc), width);
+ formatter->AppendNumber(reinterpret_cast<uintptr_t>(pc), 16, width);
formatter->AppendString(" ");
// Get the symbol from the previous address of PC,
// because PC may be in the next function.
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 <size_t N>
@@ -203,7 +189,6 @@ public:
private:
char Buffer_[N];
-
};
////////////////////////////////////////////////////////////////////////////////