Skip to content

Commit 14e4664

Browse files
committed
fix
1 parent 6fc0f47 commit 14e4664

File tree

10 files changed

+57
-63
lines changed

10 files changed

+57
-63
lines changed

ydb/library/yql/utils/backtrace/backtrace.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "backtrace.h"
22

3-
#include <ydb/library/yql/utils/backtrace/libbacktrace/backtrace.h>
4-
#include <ydb/library/yql/utils/backtrace/libbacktrace/symbolizer.h>
3+
#include "backtrace_lib.h"
4+
#include "symbolizer.h"
55

66
#include <library/cpp/deprecated/atomic/atomic.h>
77
#include <library/cpp/malloc/api/malloc.h>
@@ -78,6 +78,8 @@ void SetFatalSignalAction(void (*sigaction)(int, siginfo_t*, void*))
7878
namespace {
7979
std::vector<std::function<void(int)>> Before, After;
8080
bool KikimrSymbolize = false;
81+
const int Limit = 400;
82+
NYql::NBacktrace::TCollectedFrame Frames[Limit];
8183

8284
void CallCallbacks(decltype(Before)& where, int signum) {
8385
for (const auto &fn: where) {
@@ -87,14 +89,16 @@ namespace {
8789
}
8890
}
8991

90-
void PrintFrames(IOutputStream* out, const TVector<NYql::NBacktrace::TCollectedFrame>& frames);
92+
void PrintFrames(IOutputStream* out, const NYql::NBacktrace::TCollectedFrame* frames, size_t cnt);
9193

9294
void DoBacktrace(IOutputStream* out, void* data) {
93-
PrintFrames(out, NYql::NBacktrace::CollectFrames(data));
95+
auto cnt = NYql::NBacktrace::CollectFrames(Frames, data);
96+
PrintFrames(out, Frames, cnt);
9497
}
9598

9699
void DoBacktrace(IOutputStream* out, void** stack, size_t cnt) {
97-
PrintFrames(out, NYql::NBacktrace::CollectFrames(stack, cnt));
100+
Y_UNUSED(NYql::NBacktrace::CollectFrames(Frames, stack, cnt));
101+
PrintFrames(out, Frames, cnt);
98102
}
99103

100104

@@ -185,11 +189,11 @@ void EnableKikimrBacktraceFormat() {
185189
}
186190

187191
namespace {
188-
void PrintFrames(IOutputStream* out, const TVector<NYql::NBacktrace::TCollectedFrame>& frames) {
192+
void PrintFrames(IOutputStream* out, const NYql::NBacktrace::TCollectedFrame* frames, size_t count) {
189193
auto& outp = *out;
190194
if (KikimrSymbolize) {
191-
TVector<NYql::NBacktrace::TStackFrame> sFrames(frames.size());
192-
for (size_t i = 0; i < frames.size(); ++i) {
195+
TVector<NYql::NBacktrace::TStackFrame> sFrames(count);
196+
for (size_t i = 0; i < count; ++i) {
193197
sFrames[i] = NYql::NBacktrace::TStackFrame{frames[i].File, frames[i].Address};
194198
}
195199
auto symbolized = NYql::NBacktrace::Symbolize(sFrames);
@@ -198,10 +202,11 @@ namespace {
198202
}
199203
return;
200204
}
201-
outp << "StackFrames: " << frames.size() << "\n";
202-
for (auto &frame: frames) {
205+
outp << "StackFrames: " << count << "\n";
206+
for (size_t i = 0; i < count; ++i) {
207+
auto& frame = frames[i];
203208
auto fileName = frame.File;
204-
if (fileName == "/proc/self/exe") {
209+
if (!strcmp(fileName, "/proc/self/exe")) {
205210
fileName = "EXE";
206211
}
207212
auto it = NYql::NBacktrace::Mapping.find(fileName);

ydb/library/yql/utils/backtrace/libbacktrace/backtrace_dummy.cpp renamed to ydb/library/yql/utils/backtrace/backtrace_dummy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "backtrace.h"
1+
#include "backtrace_lib.h"
22

33
#include <util/system/backtrace.h>
44

ydb/library/yql/utils/backtrace/libbacktrace/backtrace.cpp renamed to ydb/library/yql/utils/backtrace/backtrace_lib.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "backtrace.h"
1+
#include "backtrace_lib.h"
22

33
#include <util/generic/hash.h>
44
#include <util/system/execpath.h>
@@ -34,7 +34,7 @@ namespace {
3434
namespace NYql {
3535
namespace NBacktrace {
3636
TCollectedFrame::TCollectedFrame(uintptr_t addr) {
37-
File = GetPersistentExecPath();
37+
File = GetPersistentExecPath().c_str();
3838
Address = addr;
3939
#if defined(_linux_) && defined(_x86_64_)
4040
Dl_info dlInfo;
@@ -51,22 +51,20 @@ namespace NYql {
5151
#endif
5252
}
5353

54-
TVector<TCollectedFrame> CollectFrames(void* data) {
54+
size_t CollectFrames(TCollectedFrame* frames, void* data) {
5555
#if defined(_linux_) && defined(_x86_64_)
5656
DLLs.clear();
5757
dl_iterate_phdr(DlIterCallback, &DLLs);
5858
#endif
5959
size_t cnt = CollectBacktrace(Stack, Limit, data);
60-
return CollectFrames(Stack, cnt);
60+
return CollectFrames(frames, Stack, cnt);
6161
}
6262

63-
TVector<TCollectedFrame> CollectFrames(void** stack, size_t cnt) {
64-
TVector<TCollectedFrame> result;
65-
result.reserve(cnt);
63+
size_t CollectFrames(TCollectedFrame* frames, void** stack, size_t cnt) {
6664
for (size_t i = 0; i < cnt; ++i) {
67-
result.emplace_back(reinterpret_cast<uintptr_t>(stack[i]));
65+
new (frames + i)TCollectedFrame(reinterpret_cast<uintptr_t>(stack[i]));
6866
}
69-
return result;
67+
return cnt;
7068
}
7169
}
7270
}

ydb/library/yql/utils/backtrace/libbacktrace/backtrace.h renamed to ydb/library/yql/utils/backtrace/backtrace_lib.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ namespace NYql {
88
size_t CollectBacktrace(void** addresses, size_t limit, void* data);
99
struct TCollectedFrame {
1010
TCollectedFrame(uintptr_t addr);
11-
TString File;
11+
TCollectedFrame() = default;
12+
const char* File;
1213
size_t Address;
1314
};
14-
TVector<TCollectedFrame> CollectFrames(void* data);
15-
TVector<TCollectedFrame> CollectFrames(void** stack, size_t cnt);
15+
size_t CollectFrames(TCollectedFrame* frames, void* data);
16+
size_t CollectFrames(TCollectedFrame* frames, void** stack, size_t cnt);
1617
}
1718
}

ydb/library/yql/utils/backtrace/libbacktrace/backtrace_linux.cpp renamed to ydb/library/yql/utils/backtrace/backtrace_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "backtrace.h"
1+
#include "backtrace_lib.h"
22

33
#include <libunwind.h>
44
#include <signal.h>

ydb/library/yql/utils/backtrace/libbacktrace/ya.make

Lines changed: 0 additions & 30 deletions
This file was deleted.

ydb/library/yql/utils/backtrace/symbolize.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "backtrace.h"
22

3-
#include <ydb/library/yql/utils/backtrace/libbacktrace/symbolizer.h>
3+
#include "symbolizer.h"
44

55
#include <util/string/split.h>
66
#include <util/stream/str.h>
@@ -10,6 +10,7 @@ namespace NYql {
1010
namespace NBacktrace {
1111

1212
TString Symbolize(const TString& input, const THashMap<TString, TString>& mapping) {
13+
#if defined(__linux__) && defined(__x86_64__)
1314
TString output;
1415
TStringOutput out(output);
1516

@@ -28,14 +29,16 @@ namespace NYql {
2829
Split(TString(line), " ", parts);
2930
TString modulePath;
3031
ui64 address;
31-
if (parts.size() > 2) {
32+
ui64 offset;
33+
if (parts.size() > 3) {
3234
modulePath = parts[1];
3335
TryFromString<ui64>(parts[2], address);
36+
TryFromString<ui64>(parts[3], offset);
3437
auto it = mapping.find(modulePath);
3538
if (it != mapping.end()) {
3639
modulePath = it->second;
3740
}
38-
frames.emplace_back(TStackFrame{modulePath, address});
41+
frames.emplace_back(TStackFrame{modulePath, address - offset});
3942
}
4043
} else {
4144
out << line << "\n";
@@ -49,6 +52,9 @@ namespace NYql {
4952
out << e << "\n";
5053
}
5154
return output;
55+
#else
56+
return input;
57+
#endif
5258
}
5359

5460
} /* namespace NBacktrace */

ydb/library/yql/utils/backtrace/ya.make

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,31 @@ LIBRARY()
22

33
SRCS(
44
backtrace.cpp
5+
backtrace_lib.cpp
56
symbolize.cpp
67
)
78

89
PEERDIR(
910
library/cpp/deprecated/atomic
10-
ydb/library/yql/utils/backtrace/libbacktrace
1111
)
1212

13-
END()
1413

15-
RECURSE_FOR_TESTS(
16-
ut
17-
)
14+
IF (OS_LINUX AND ARCH_X86_64)
15+
SRCS(
16+
backtrace_linux.cpp
17+
symbolizer_linux.cpp
18+
)
19+
20+
PEERDIR(
21+
contrib/libs/backtrace
22+
contrib/libs/libunwind
23+
)
24+
ADDINCL(contrib/libs/libunwind/include)
25+
26+
ELSE()
27+
SRCS(
28+
backtrace_dummy.cpp
29+
)
30+
ENDIF()
1831

32+
END()

0 commit comments

Comments
 (0)