少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "il2cpp-config.h"
 
#if IL2CPP_TARGET_POSIX && !IL2CPP_TARGET_JAVASCRIPT && !IL2CPP_TARGET_ANDROID && !IL2CPP_TARGET_PS4  && !IL2CPP_TARGET_LUMIN
 
#include "os/StackTrace.h"
#include <execinfo.h>
#include <stdio.h>
#include <cxxabi.h>
#include <dlfcn.h>
 
 
namespace il2cpp
{
namespace os
{
    const int kMaxStackFrames = 128;
 
    void StackTrace::WalkStackNative(WalkStackCallback callback, void* context, WalkOrder walkOrder)
    {
        void* callstack[kMaxStackFrames];
        int frames = backtrace(callstack, kMaxStackFrames);
 
        if (walkOrder == kFirstCalledToLastCalled)
        {
            for (int i = frames - 1; i >= 0; i--)
            {
                if (!callback(reinterpret_cast<Il2CppMethodPointer>(callstack[i]), context))
                    break;
            }
        }
        else
        {
            for (size_t i = 0; i < frames; i++)
            {
                if (!callback(reinterpret_cast<Il2CppMethodPointer>(callstack[i]), context))
                    break;
            }
        }
    }
 
    std::string StackTrace::NativeStackTrace()
    {
        void* callstack[kMaxStackFrames];
        int frames = backtrace(callstack, kMaxStackFrames);
        char **symbols = backtrace_symbols(callstack, frames);
 
        std::string stackTrace;
        if (symbols != NULL)
        {
            for (int i = 0; i < frames; ++i)
            {
                stackTrace += symbols[i];
                stackTrace += "\n";
            }
 
            free(symbols);
        }
 
        return stackTrace;
    }
 
    const void* StackTrace::GetStackPointer()
    {
        // TODO implement to avoid extra WalkStack calls
        return nullptr;
    }
}
}
 
#endif