Skip to content

Commit e564a15

Browse files
committed
Try without any fixes
1 parent 0a54df7 commit e564a15

7 files changed

Lines changed: 32 additions & 18 deletions

File tree

BUILDME

Whitespace-only changes.

build/cmake/FindLibunwind.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SET(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/libunwind-prefix/src/libunw
44

55
ExternalProject_Add(libunwind
66
GIT_REPOSITORY https://github.com/DataDog/libunwind.git
7-
GIT_TAG gleocadie/v1.8.1-custom-3
7+
GIT_TAG kevin/v1.8.1-custom-2
88
GIT_PROGRESS true
99
INSTALL_COMMAND ""
1010
UPDATE_COMMAND ""

profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/HybridUnwinder.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,17 @@ std::int32_t HybridUnwinder::Unwind(void* ctx, std::uintptr_t* buffer, std::size
8686
return i;
8787
}
8888

89-
if (_codeCache->IsManaged(ip))
89+
auto isManaged = _codeCache->IsManaged(ip);
90+
// No value means that the managed code cache was not capable of
91+
// determining if the frame is managed or not (failed to acquire the lock).
92+
// This is temporary to avoid having libunwind failing.
93+
if (!isManaged.has_value())
94+
{
95+
if (tracer) tracer->RecordFinish(0, FinishReason::UnknownFrameType);
96+
return i;
97+
}
98+
99+
if (isManaged.value())
90100
{
91101
if (tracer)
92102
{
@@ -101,8 +111,7 @@ std::int32_t HybridUnwinder::Unwind(void* ctx, std::uintptr_t* buffer, std::size
101111
{
102112
unw_word_t sp = 0;
103113
unw_word_t nativeFp = 0;
104-
unw_get_reg(&cursor, UNW_AARCH64_SP, &sp);
105-
unw_get_reg(&cursor, UNW_REG_FP, &nativeFp);
114+
106115
tracer->Record(EventType::NativeFrame, ip, nativeFp, sp);
107116
}
108117

@@ -194,7 +203,8 @@ std::int32_t HybridUnwinder::Unwind(void* ctx, std::uintptr_t* buffer, std::size
194203

195204
if (tracer) tracer->Record(EventType::FrameChainStep, ip, fp);
196205

197-
if (_codeCache->IsManaged(ip))
206+
// Here we do a best effort, just try fp-chain + fp sanity check.
207+
if (isManaged.has_value() && isManaged.value())
198208
{
199209
if (i >= bufferSize)
200210
{

profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/UnwinderTracer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static const char* FinishReasonName(FinishReason r)
3535
case FinishReason::InvalidFp: return "InvalidFp";
3636
case FinishReason::TooManyNativeFrames: return "TooManyNativeFrames";
3737
case FinishReason::InvalidIp: return "InvalidIp";
38+
case FinishReason::UnknownFrameType: return "UnknownFrameType";
3839
default: return "Unknown";
3940
}
4041
}

profiler/src/ProfilerEngine/Datadog.Profiler.Native.Linux/UnwinderTracer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ enum class FinishReason : std::uint8_t
128128
InvalidFp = 7,
129129
TooManyNativeFrames = 8,
130130
InvalidIp = 9,
131+
UnknownFrameType = 10,
131132
};
132133

133134
// ---------------------------------------------------------------------------

profiler/src/ProfilerEngine/Datadog.Profiler.Native/ManagedCodeCache.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bool ManagedCodeCache::Initialize()
6969
return false;
7070
}
7171

72-
bool ManagedCodeCache::IsCodeInR2RModule(std::uintptr_t ip, bool signalSafe) const noexcept
72+
std::optional<bool> ManagedCodeCache::IsCodeInR2RModule(std::uintptr_t ip, bool signalSafe) const noexcept
7373
{
7474
// IsCodeInR2RModule can be called in a signal handler or not.
7575
// If it's called in a signal handler, we need to use a shared lock with try_to_lock.
@@ -84,23 +84,25 @@ bool ManagedCodeCache::IsCodeInR2RModule(std::uintptr_t ip, bool signalSafe) con
8484

8585
if (!moduleLock.owns_lock())
8686
{
87-
return false;
87+
return std::nullopt;
8888
}
8989

9090
auto moduleCodeRange = FindRange(_modulesCodeRanges, ip);
9191
if (!moduleCodeRange.has_value())
9292
{
93-
return false;
93+
return {false};
9494
}
9595

9696
if (moduleCodeRange->isRemoved)
9797
{
9898
// No print, can be called in a signal handler
9999
// LogOnce(Debug, "ManagedCodeCache::IsCodeInR2RModule: Module code range was removed for ip: 0x", std::hex, ip);
100-
return false;
100+
// This could happen only from the SamplesCollector thread (native).
101+
//
102+
return std::nullopt;
101103
}
102104

103-
return moduleCodeRange->contains(ip);
105+
return {moduleCodeRange->contains(ip)};
104106
}
105107

106108
// must not be called in a signal handler (GetFunctionFromIP is not signal-safe)
@@ -114,8 +116,8 @@ std::optional<FunctionID> ManagedCodeCache::GetFunctionId(std::uintptr_t ip) noe
114116
}
115117

116118
// Level 2: Check if the IP is within a module code range
117-
118-
if (IsCodeInR2RModule(ip, false))
119+
auto isCodeInR2RModule = IsCodeInR2RModule(ip, false);
120+
if (isCodeInR2RModule.has_value() && isCodeInR2RModule.value())
119121
{
120122
auto functionId = GetFunctionFromIP_Original(ip);
121123
if (functionId.has_value()) {
@@ -188,7 +190,7 @@ std::optional<FunctionID> ManagedCodeCache::GetFunctionIdImpl(std::uintptr_t ip)
188190
}
189191

190192
// can be called in a signal handler
191-
bool ManagedCodeCache::IsManaged(std::uintptr_t ip) const noexcept
193+
std::optional<bool> ManagedCodeCache::IsManaged(std::uintptr_t ip) const noexcept
192194
{
193195
uint64_t page = GetPageNumber(static_cast<UINT_PTR>(ip));
194196

@@ -197,7 +199,7 @@ bool ManagedCodeCache::IsManaged(std::uintptr_t ip) const noexcept
197199
std::shared_lock<std::shared_mutex> mapLock(_pagesMutex, std::try_to_lock);
198200
if (!mapLock.owns_lock())
199201
{
200-
return false;
202+
return std::nullopt;
201203
}
202204
auto pageIt = _pagesMap.find(page);
203205
if (pageIt != _pagesMap.end())
@@ -206,12 +208,12 @@ bool ManagedCodeCache::IsManaged(std::uintptr_t ip) const noexcept
206208
std::shared_lock<std::shared_mutex> pageLock(pageIt->second.lock, std::try_to_lock);
207209
if (!pageLock.owns_lock())
208210
{
209-
return false;
211+
return std::nullopt;
210212
}
211213
auto range = FindRange(pageIt->second.ranges, static_cast<UINT_PTR>(ip));
212214
if (range.has_value())
213215
{
214-
return true;
216+
return {true};
215217
}
216218
}
217219
}

profiler/src/ProfilerEngine/Datadog.Profiler.Native/ManagedCodeCache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ManagedCodeCache {
8484
~ManagedCodeCache();
8585

8686
// Signal-safe lookup methods (no allocation)
87-
[[nodiscard]] bool IsManaged(std::uintptr_t ip) const noexcept;
87+
[[nodiscard]] std::optional<bool> IsManaged(std::uintptr_t ip) const noexcept;
8888

8989
// Not signal-safe
9090
[[nodiscard]] std::optional<FunctionID> GetFunctionId(std::uintptr_t ip) noexcept;
@@ -173,7 +173,7 @@ class ManagedCodeCache {
173173
template<typename WorkType>
174174
void EnqueueWork(WorkType work);
175175
std::optional<FunctionID> GetFunctionIdImpl(std::uintptr_t ip) const noexcept;
176-
bool IsCodeInR2RModule(std::uintptr_t ip, bool signalSafe) const noexcept;
176+
std::optional<bool> IsCodeInR2RModule(std::uintptr_t ip, bool signalSafe) const noexcept;
177177
std::optional<FunctionID> GetFunctionFromIP_Original(std::uintptr_t ip) noexcept;
178178
void AddFunctionImpl(FunctionID functionId, bool isAsync);
179179

0 commit comments

Comments
 (0)