aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authormaksim-kita <maksim-kita@yandex-team.com>2023-11-02 15:15:26 +0300
committermaksim-kita <maksim-kita@yandex-team.com>2023-11-02 16:26:16 +0300
commitd4ec9ad0ad93850fa81d9e78298066d138aba60f (patch)
tree70255a78488d9abdac8cbac0f447356e40249cd2 /library/cpp
parent7bb2ef5057a017f193e0c790e16dac7e78891c26 (diff)
downloadydb-d4ec9ad0ad93850fa81d9e78298066d138aba60f.tar.gz
Stacktraces add line numbers
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/CMakeLists.darwin-x86_64.txt1
-rw-r--r--library/cpp/CMakeLists.linux-aarch64.txt1
-rw-r--r--library/cpp/CMakeLists.linux-x86_64.txt1
-rw-r--r--library/cpp/dwarf_backtrace/CMakeLists.darwin-x86_64.txt18
-rw-r--r--library/cpp/dwarf_backtrace/CMakeLists.linux-aarch64.txt19
-rw-r--r--library/cpp/dwarf_backtrace/CMakeLists.linux-x86_64.txt19
-rw-r--r--library/cpp/dwarf_backtrace/CMakeLists.txt15
-rw-r--r--library/cpp/dwarf_backtrace/registry/set_format_backtrace.cpp18
-rw-r--r--library/cpp/dwarf_backtrace/registry/ya.make15
-rw-r--r--library/cpp/dwarf_backtrace/ut/backtrace_ut.cpp55
-rw-r--r--library/cpp/dwarf_backtrace/ut/ya.make12
11 files changed, 174 insertions, 0 deletions
diff --git a/library/cpp/CMakeLists.darwin-x86_64.txt b/library/cpp/CMakeLists.darwin-x86_64.txt
index 772027a342..0f393b2039 100644
--- a/library/cpp/CMakeLists.darwin-x86_64.txt
+++ b/library/cpp/CMakeLists.darwin-x86_64.txt
@@ -34,6 +34,7 @@ add_subdirectory(diff)
add_subdirectory(digest)
add_subdirectory(disjoint_sets)
add_subdirectory(dns)
+add_subdirectory(dwarf_backtrace)
add_subdirectory(enumbitset)
add_subdirectory(execprofile)
add_subdirectory(getopt)
diff --git a/library/cpp/CMakeLists.linux-aarch64.txt b/library/cpp/CMakeLists.linux-aarch64.txt
index cd50b0e3a4..cf47314f07 100644
--- a/library/cpp/CMakeLists.linux-aarch64.txt
+++ b/library/cpp/CMakeLists.linux-aarch64.txt
@@ -33,6 +33,7 @@ add_subdirectory(diff)
add_subdirectory(digest)
add_subdirectory(disjoint_sets)
add_subdirectory(dns)
+add_subdirectory(dwarf_backtrace)
add_subdirectory(enumbitset)
add_subdirectory(execprofile)
add_subdirectory(getopt)
diff --git a/library/cpp/CMakeLists.linux-x86_64.txt b/library/cpp/CMakeLists.linux-x86_64.txt
index 772027a342..0f393b2039 100644
--- a/library/cpp/CMakeLists.linux-x86_64.txt
+++ b/library/cpp/CMakeLists.linux-x86_64.txt
@@ -34,6 +34,7 @@ add_subdirectory(diff)
add_subdirectory(digest)
add_subdirectory(disjoint_sets)
add_subdirectory(dns)
+add_subdirectory(dwarf_backtrace)
add_subdirectory(enumbitset)
add_subdirectory(execprofile)
add_subdirectory(getopt)
diff --git a/library/cpp/dwarf_backtrace/CMakeLists.darwin-x86_64.txt b/library/cpp/dwarf_backtrace/CMakeLists.darwin-x86_64.txt
new file mode 100644
index 0000000000..3fb6a8f4b9
--- /dev/null
+++ b/library/cpp/dwarf_backtrace/CMakeLists.darwin-x86_64.txt
@@ -0,0 +1,18 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(library-cpp-dwarf_backtrace)
+target_link_libraries(library-cpp-dwarf_backtrace PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ contrib-libs-backtrace
+)
+target_sources(library-cpp-dwarf_backtrace PRIVATE
+ ${CMAKE_SOURCE_DIR}/library/cpp/dwarf_backtrace/backtrace.cpp
+)
diff --git a/library/cpp/dwarf_backtrace/CMakeLists.linux-aarch64.txt b/library/cpp/dwarf_backtrace/CMakeLists.linux-aarch64.txt
new file mode 100644
index 0000000000..fc0672a08c
--- /dev/null
+++ b/library/cpp/dwarf_backtrace/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,19 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(library-cpp-dwarf_backtrace)
+target_link_libraries(library-cpp-dwarf_backtrace PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ contrib-libs-backtrace
+)
+target_sources(library-cpp-dwarf_backtrace PRIVATE
+ ${CMAKE_SOURCE_DIR}/library/cpp/dwarf_backtrace/backtrace.cpp
+)
diff --git a/library/cpp/dwarf_backtrace/CMakeLists.linux-x86_64.txt b/library/cpp/dwarf_backtrace/CMakeLists.linux-x86_64.txt
new file mode 100644
index 0000000000..fc0672a08c
--- /dev/null
+++ b/library/cpp/dwarf_backtrace/CMakeLists.linux-x86_64.txt
@@ -0,0 +1,19 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(library-cpp-dwarf_backtrace)
+target_link_libraries(library-cpp-dwarf_backtrace PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ contrib-libs-backtrace
+)
+target_sources(library-cpp-dwarf_backtrace PRIVATE
+ ${CMAKE_SOURCE_DIR}/library/cpp/dwarf_backtrace/backtrace.cpp
+)
diff --git a/library/cpp/dwarf_backtrace/CMakeLists.txt b/library/cpp/dwarf_backtrace/CMakeLists.txt
new file mode 100644
index 0000000000..606ff46b4b
--- /dev/null
+++ b/library/cpp/dwarf_backtrace/CMakeLists.txt
@@ -0,0 +1,15 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-aarch64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ include(CMakeLists.darwin-x86_64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-x86_64.txt)
+endif()
diff --git a/library/cpp/dwarf_backtrace/registry/set_format_backtrace.cpp b/library/cpp/dwarf_backtrace/registry/set_format_backtrace.cpp
new file mode 100644
index 0000000000..b3e6c3f8d8
--- /dev/null
+++ b/library/cpp/dwarf_backtrace/registry/set_format_backtrace.cpp
@@ -0,0 +1,18 @@
+#include <library/cpp/dwarf_backtrace/backtrace.h>
+#include <util/stream/format.h>
+#include <util/system/backtrace.h>
+
+namespace {
+ void PrintDwarfBacktrace(IOutputStream* out, void* const* backtrace, size_t size) {
+ auto error = NDwarf::ResolveBacktrace({backtrace, size}, [out](const NDwarf::TLineInfo& info) {
+ *out << info.FileName << ":" << info.Line << ":" << info.Col
+ << " in " << info.FunctionName << " (" << Hex(info.Address, HF_ADDX) << ')' << Endl;
+ return NDwarf::EResolving::Continue;
+ });
+ if (error) {
+ *out << "***Cannot get backtrace: " << error->Message << " (" << error->Code << ")***" << Endl;
+ }
+ }
+
+ [[maybe_unused]] auto _ = SetFormatBackTraceFn(&PrintDwarfBacktrace);
+}
diff --git a/library/cpp/dwarf_backtrace/registry/ya.make b/library/cpp/dwarf_backtrace/registry/ya.make
new file mode 100644
index 0000000000..6770671b13
--- /dev/null
+++ b/library/cpp/dwarf_backtrace/registry/ya.make
@@ -0,0 +1,15 @@
+LIBRARY()
+
+IF(OS_LINUX)
+
+ PEERDIR(
+ library/cpp/dwarf_backtrace
+ )
+
+ SRCS(
+ GLOBAL set_format_backtrace.cpp
+ )
+
+ENDIF()
+
+END()
diff --git a/library/cpp/dwarf_backtrace/ut/backtrace_ut.cpp b/library/cpp/dwarf_backtrace/ut/backtrace_ut.cpp
new file mode 100644
index 0000000000..dc271ad513
--- /dev/null
+++ b/library/cpp/dwarf_backtrace/ut/backtrace_ut.cpp
@@ -0,0 +1,55 @@
+#include <library/cpp/testing/gtest/gtest.h>
+#include <util/system/compiler.h>
+#include <util/system/backtrace.h>
+#include <util/stream/str.h>
+
+Y_FORCE_INLINE
+TString InlinedFunction_866a4407b28483588033f95add111d() {
+ TStringStream out;
+ FormatBackTrace(&out);
+ return out.Str();
+}
+
+Y_NO_INLINE
+TString Function_3e15a2d04c8613ae64833c5407dd98() {
+ return InlinedFunction_866a4407b28483588033f95add111d();
+}
+
+Y_NO_INLINE
+TString NotInlinedFunction_3c7dbf1e3b2b71819241cb5ad2b142() {
+ return Function_3e15a2d04c8613ae64833c5407dd98();
+}
+
+namespace NTestNamespace {
+ Y_NO_INLINE
+ TString NamespacedFunction() {
+ return InlinedFunction_866a4407b28483588033f95add111d();
+ }
+}
+
+using namespace ::testing;
+TEST(dwarf_backtrace_should, handle_inlines) {
+ const TString backtrace = NotInlinedFunction_3c7dbf1e3b2b71819241cb5ad2b142();
+
+ EXPECT_THAT(
+ backtrace,
+ HasSubstr("InlinedFunction_866a4407b28483588033f95add111d")
+ );
+
+ EXPECT_THAT(
+ backtrace,
+ HasSubstr("backtrace_ut.cpp:9:0 in InlinedFunction")
+ );
+
+ EXPECT_THAT(
+ backtrace,
+ HasSubstr("Function_3e15a2d04c8613ae64833c5407dd98")
+ );
+}
+
+TEST(dwarf_backtrace_should, handle_namespaces) {
+ EXPECT_THAT(
+ NTestNamespace::NamespacedFunction(),
+ HasSubstr("NTestNamespace::NamespacedFunction")
+ );
+}
diff --git a/library/cpp/dwarf_backtrace/ut/ya.make b/library/cpp/dwarf_backtrace/ut/ya.make
new file mode 100644
index 0000000000..9f23256483
--- /dev/null
+++ b/library/cpp/dwarf_backtrace/ut/ya.make
@@ -0,0 +1,12 @@
+GTEST()
+
+PEERDIR(
+ library/cpp/dwarf_backtrace
+ library/cpp/dwarf_backtrace/registry
+)
+
+SRCS(
+ backtrace_ut.cpp
+)
+
+END()