少年修仙传客户端基础资源
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
#include "il2cpp-config.h"
 
#if IL2CPP_MONO_DEBUGGER
 
#include "il2cpp-class-internals.h"
#include "il2cpp-object-internals.h"
#include "Debugger.h"
#include "os/Thread.h"
#include "os/c-api/Allocator.h"
#include "os/SocketBridge.h"
 
#include "vm/Assembly.h"
#include "vm/Image.h"
#include "vm/MetadataCache.h"
#include "vm/Method.h"
#include "vm/StackTrace.h"
#include "vm/Thread.h"
#include "utils/Environment.h"
#include "utils/dynamic_array.h"
#include "utils/StringUtils.h"
#include "utils/StringViewUtils.h"
#include "utils/Il2CppHashMap.h"
#include "utils/HashUtils.h"
 
#include "VmStringUtils.h"
 
#include <deque>
#include <string>
#include <algorithm>
 
il2cpp::os::ThreadLocalValue s_ExecutionContexts; // Il2CppThreadUnwindState*
 
struct MonoDebuggerRuntimeCallbacks
{
    void(*il2cpp_debugger_save_thread_context)(Il2CppThreadUnwindState* context, int frameCountAdjust);
    void(*il2cpp_debugger_free_thread_context)(Il2CppThreadUnwindState* context);
};
 
struct DebuggerTransport
{
    const char *name;
    void(*connect) (const char *address);
    int (*wait_for_attach) (void);
    void(*close1) (void);
    void(*close2) (void);
    int (*send) (void *buf, int len);
    int(*recv) (void *buf, int len);
};
 
struct MonoContext;
extern "C"
{
    void mono_debugger_agent_parse_options(const char *options);
    void mono_debugger_agent_init();
    void mono_debugger_run_debugger_thread_func(void* arg);
    void debugger_agent_single_step_from_context(MonoContext *ctx, Il2CppSequencePoint* sequencePoint);
    void mono_debugger_il2cpp_init();
    void unity_debugger_agent_breakpoint(Il2CppSequencePoint* sequencePoint);
    void unity_debugger_agent_pausepoint();
    void mono_debugger_install_runtime_callbacks(MonoDebuggerRuntimeCallbacks* cbs);
    int32_t unity_debugger_agent_is_global_breakpoint_active();
    int32_t unity_debugger_agent_is_single_stepping();
    void unity_debugger_agent_handle_exception(Il2CppException *exc);
    int32_t il2cpp_mono_methods_match(const MethodInfo* left, const MethodInfo* right);
    void mono_debugger_agent_user_break();
    int32_t mono_debugger_agent_debug_log_is_enabled();
    void mono_debugger_agent_debug_log(int level, Il2CppString *category, Il2CppString *message);
    int32_t unity_pause_point_active();
    void il2cpp_save_current_thread_context_func_exit();
    void mono_debugger_agent_register_transport(DebuggerTransport *trans);
 
    void* il2cpp_malloc(size_t size)
    {
        return IL2CPP_MALLOC(size);
    }
}
 
static const Il2CppDebuggerMetadataRegistration *g_metadata;
 
namespace il2cpp
{
namespace utils
{
    static os::Thread* s_DebuggerThread;
    static bool s_IsDebuggerAttached = false;
    static bool s_IsDebuggerInitialized = false;
    static std::string s_AgentOptions;
 
    typedef dynamic_array<Il2CppSequencePoint*> SequencePointList;
    typedef Il2CppHashMap<const MethodInfo*, SequencePointList*, il2cpp::utils::PointerHash<MethodInfo> > MethodToSequencePointsMap;
    static MethodToSequencePointsMap s_methodToSequencePoints;
 
    typedef dynamic_array<Il2CppCatchPoint*> CatchPointList;
    typedef Il2CppHashMap<const MethodInfo*, CatchPointList*, il2cpp::utils::PointerHash<MethodInfo> > MethodToCatchPointsMap;
    static MethodToCatchPointsMap s_methodToCatchPoints;
 
    typedef Il2CppHashMap<const MethodInfo*, const MethodInfo*, il2cpp::utils::PointerHash<MethodInfo> > MethodToMethodMap;
    static MethodToMethodMap s_uninflatedMethodToInflated;
    SequencePointList s_sequencePoints;
 
    typedef dynamic_array<const char*> FileNameList;
    typedef Il2CppHashMap<const Il2CppClass*, FileNameList, il2cpp::utils::PointerHash<Il2CppClass> > TypeSourceFileMap;
    static TypeSourceFileMap *s_typeSourceFiles;
 
    static MethodToSequencePointsMap::const_iterator GetMethodSequencePointIterator(const MethodInfo *method);
 
 
    void Debugger::RegisterMetadata(const Il2CppDebuggerMetadataRegistration *data)
    {
        g_metadata = data;
    }
 
#if defined(RUNTIME_IL2CPP)
    void breakpoint_callback(Il2CppSequencePoint* sequencePoint)
    {
        unity_debugger_agent_breakpoint(sequencePoint);
    }
 
    void pausepoint_callback()
    {
        unity_debugger_agent_pausepoint();
    }
 
#endif
 
    static void InitializeMonoSoftDebugger(const char* options)
    {
#if defined(RUNTIME_IL2CPP)
 
        os::SocketBridge::WaitForInitialization();
 
        mono_debugger_il2cpp_init();
        mono_debugger_agent_parse_options(options);
        mono_debugger_agent_init();
 
        s_typeSourceFiles = new TypeSourceFileMap();
 
        MonoDebuggerRuntimeCallbacks cbs;
        cbs.il2cpp_debugger_save_thread_context = Debugger::SaveThreadContext;
        cbs.il2cpp_debugger_free_thread_context = Debugger::FreeThreadContext;
        mono_debugger_install_runtime_callbacks(&cbs);
 
        il2cpp::utils::Debugger::RegisterCallbacks(breakpoint_callback, pausepoint_callback);
 
        register_allocator(il2cpp_malloc);
 
        s_IsDebuggerInitialized = true;
#else
        IL2CPP_ASSERT(0 && "The managed debugger is only supported for the libil2cpp runtime backend.");
#endif
    }
 
    void Debugger::SetAgentOptions(const char* options)
    {
        s_AgentOptions = options;
    }
 
    void Debugger::RegisterTransport(const Il2CppDebuggerTransport* transport)
    {
#if defined(RUNTIME_IL2CPP)
        DebuggerTransport mono_transport;
        mono_transport.name = transport->name;
        mono_transport.connect = transport->connect;
        mono_transport.wait_for_attach = transport->wait_for_attach;
        mono_transport.close1 = transport->close1;
        mono_transport.close2 = transport->close2;
        mono_transport.send = transport->send;
        mono_transport.recv = transport->recv;
        mono_debugger_agent_register_transport(&mono_transport);
#endif
    }
 
    void Debugger::InitializeTypeSourceFileMap()
    {
        int lastTypeIndex = -1;
        Il2CppClass *klass = NULL;
        FileNameList files;
 
        vm::AssemblyVector* assemblies = vm::Assembly::GetAllAssemblies();
        for (vm::AssemblyVector::const_iterator  iter = assemblies->begin(); iter != assemblies->end(); ++iter)
        {
            const Il2CppDebuggerMetadataRegistration* debuggerMetadata = vm::Assembly::GetImage(*iter)->codeGenModule->debuggerMetadata;
            for (int i = 0; i < debuggerMetadata->numTypeSourceFileEntries; ++i)
            {
                Il2CppTypeSourceFilePair& pair = debuggerMetadata->typeSourceFiles[i];
                const char *file = debuggerMetadata->sequencePointSourceFiles[pair.sourceFileIndex].file;
                if (pair.klassIndex != lastTypeIndex)
                {
                    if (klass)
                        s_typeSourceFiles->add(klass, files);
 
                    klass = il2cpp::vm::MetadataCache::GetTypeInfoFromTypeDefinitionIndex(pair.klassIndex);
                    lastTypeIndex = pair.klassIndex;
                    files.clear();
                }
 
                files.push_back(file);
            }
        }
 
        if (files.size() > 0)
            s_typeSourceFiles->add(klass, files);
    }
 
    void Debugger::Start()
    {
        if (s_IsDebuggerInitialized)
        {
            vm::MetadataCache::InitializeAllMethodMetadata();
            InitializeTypeSourceFileMap();
            InitializeMethodToSequencePointMap();
            InitializeMethodToCatchPointMap();
            Debugger::StartDebuggerThread();
        }
    }
 
    static bool TryInitializeDebugger(const std::string& options)
    {
        if (StringUtils::StartsWith(STRING_TO_STRINGVIEW(options), "--debugger-agent"))
        {
            InitializeMonoSoftDebugger(options.c_str() + options.find("=") + 1);
            return true;
        }
 
        return false;
    }
 
    void Debugger::Init()
    {
        if (!s_AgentOptions.empty())
        {
            TryInitializeDebugger(s_AgentOptions);
        }
        else
        {
            const std::vector<UTF16String>& args = Environment::GetMainArgs();
            for (std::vector<UTF16String>::const_iterator arg = args.begin(); arg != args.end(); ++arg)
            {
                std::string argument = StringUtils::Utf16ToUtf8(*arg);
                if (TryInitializeDebugger(argument))
                    break;
            }
        }
    }
 
    static Debugger::OnBreakPointHitCallback s_BreakCallback;
    static Debugger::OnPausePointHitCallback s_PauseCallback;
    void Debugger::RegisterCallbacks(OnBreakPointHitCallback breakCallback, OnPausePointHitCallback pauseCallback)
    {
        s_BreakCallback = breakCallback;
        s_PauseCallback = pauseCallback;
    }
 
    void Debugger::StartDebuggerThread()
    {
#if defined(RUNTIME_IL2CPP)
        s_DebuggerThread = new os::Thread();
        s_DebuggerThread->Run(mono_debugger_run_debugger_thread_func, NULL);
#else
        IL2CPP_ASSERT(0 && "The managed debugger is only supported for the libil2cpp runtime backend.");
#endif
    }
 
    Il2CppThreadUnwindState* Debugger::GetThreadStatePointer()
    {
        if (!s_IsDebuggerInitialized)
            return NULL;
 
        Il2CppThreadUnwindState* unwindState;
        s_ExecutionContexts.GetValue(reinterpret_cast<void**>(&unwindState));
 
        return unwindState;
    }
 
    void Debugger::SaveThreadContext(Il2CppThreadUnwindState* context, int frameCountAdjust)
    {
        if (!s_IsDebuggerInitialized)
            return;
 
        IL2CPP_ASSERT(!IsDebuggerThread(os::Thread::GetCurrentThread()));
    }
 
    void Debugger::FreeThreadContext(Il2CppThreadUnwindState* context)
    {
        if (!s_IsDebuggerInitialized)
            return;
 
        IL2CPP_ASSERT(!IsDebuggerThread(os::Thread::GetCurrentThread()));
    }
 
    void Debugger::OnBreakPointHit(Il2CppSequencePoint *sequencePoint)
    {
#if defined(RUNTIME_IL2CPP)
        if (IsGlobalBreakpointActive() || unity_debugger_agent_is_single_stepping())
        {
            debugger_agent_single_step_from_context(NULL, sequencePoint);
        }
        else if (s_BreakCallback)
        {
            s_BreakCallback(sequencePoint);
        }
        else
            IL2CPP_DEBUG_BREAK();
#else
        IL2CPP_ASSERT(0 && "The managed debugger is only supported for the libil2cpp runtime backend.");
#endif
    }
 
    void Debugger::OnPausePointHit()
    {
#if defined(RUNTIME_IL2CPP)
        if (s_PauseCallback)
            s_PauseCallback();
#else
        IL2CPP_ASSERT(0 && "The managed debugger is only supported for the libil2cpp runtime backend.");
#endif
    }
 
    bool Debugger::IsGlobalBreakpointActive()
    {
        if (!Debugger::GetIsDebuggerAttached())
            return false;
#if defined(RUNTIME_IL2CPP)
        return unity_debugger_agent_is_global_breakpoint_active();
#else
        IL2CPP_ASSERT(0 && "The managed debugger is only supported for the libil2cpp runtime backend.");
        return false;
#endif
    }
 
    bool Debugger::GetIsDebuggerAttached()
    {
        return s_IsDebuggerAttached;
    }
 
    void Debugger::SetIsDebuggerAttached(bool attached)
    {
        s_IsDebuggerAttached = attached;
    }
 
    bool Debugger::IsDebuggerThread(os::Thread* thread)
    {
        return thread == s_DebuggerThread;
    }
 
    void Debugger::AllocateThreadLocalData()
    {
        Il2CppThreadUnwindState* unwindState;
        s_ExecutionContexts.GetValue(reinterpret_cast<void**>(&unwindState));
        if (unwindState == NULL)
        {
            unwindState = (Il2CppThreadUnwindState*)calloc(1, sizeof(Il2CppThreadUnwindState));
            unwindState->frameCapacity = 512;
            unwindState->executionContexts = (Il2CppSequencePointExecutionContext**)calloc(512, sizeof(Il2CppSequencePointExecutionContext*));
            s_ExecutionContexts.SetValue(unwindState);
        }
    }
 
    void Debugger::FreeThreadLocalData()
    {
        if (s_IsDebuggerInitialized)
        {
            Il2CppThreadUnwindState* unwindState;
            s_ExecutionContexts.GetValue(reinterpret_cast<void**>(&unwindState));
            s_ExecutionContexts.SetValue(NULL);
            free(unwindState);
        }
    }
 
    Il2CppSequencePoint* Debugger::GetSequencePoint(const Il2CppImage* image, size_t id)
    {
        if (image->codeGenModule->debuggerMetadata->numSequencePoints == 0)
            return NULL;
 
        return &image->codeGenModule->debuggerMetadata->sequencePoints[id];
    }
 
    struct SeqPointIter
    {
        SequencePointList::iterator iter, end;
    };
 
    Il2CppSequencePoint* Debugger::GetSequencePoints(const MethodInfo* method, void** iter)
    {
        if (!iter)
            return NULL;
 
        SeqPointIter *pIter = NULL;
 
        if (!*iter)
        {
            MethodToSequencePointsMap::const_iterator entry = GetMethodSequencePointIterator(method);
            if (entry == s_methodToSequencePoints.end())
                return NULL;
 
            pIter = new SeqPointIter();
            *iter = pIter;
            pIter->iter = entry->second->begin();
            pIter->end = entry->second->end();
            return *(pIter->iter);
        }
 
        pIter = (SeqPointIter*)*iter;
        pIter->iter++;
        if (pIter->iter != pIter->end)
        {
            return *(pIter->iter);
        }
        else
        {
            delete pIter;
            *iter = NULL;
        }
 
        return NULL;
    }
 
    Il2CppSequencePoint* Debugger::GetAllSequencePoints(void* *iter)
    {
        size_t index = (size_t)(intptr_t)*iter;
 
        if (index >= s_sequencePoints.size())
            return NULL;
 
        Il2CppSequencePoint* retVal = s_sequencePoints[index];
        *iter = (void*)(intptr_t)(index + 1);
        return retVal;
    }
 
    MethodToSequencePointsMap::const_iterator GetMethodSequencePointIterator(const MethodInfo *method)
    {
        if (method->is_inflated)
            method = method->genericMethod->methodDefinition;
 
        MethodToSequencePointsMap::const_iterator entry = s_methodToSequencePoints.find(method);
        if (entry == s_methodToSequencePoints.end())
        {
            //the sequence point map doesn't have uninflated methods, need to map the incoming method to
            //an inflated method.  il2cpp_mono_methods_match has a case for this.
            MethodToMethodMap::const_iterator inflated = s_uninflatedMethodToInflated.find(method);
            if (inflated != s_uninflatedMethodToInflated.end())
            {
                method = inflated->second;
            }
            else
            {
                for (MethodToSequencePointsMap::iterator mapIter = s_methodToSequencePoints.begin(); mapIter != s_methodToSequencePoints.end(); ++mapIter)
                {
                    if (il2cpp_mono_methods_match(method, mapIter->first))
                    {
                        s_uninflatedMethodToInflated.add(method, mapIter->first);
                        method = mapIter->first;
                        break;
                    }
                }
            }
 
            return s_methodToSequencePoints.find(method);
        }
 
        return entry;
    }
 
    Il2CppSequencePoint* Debugger::GetSequencePoint(Il2CppCatchPoint* cp)
    {
        const MethodInfo *method = GetCatchPointMethod(cp);
 
        MethodToSequencePointsMap::const_iterator entry = GetMethodSequencePointIterator(method);
        if (entry == s_methodToSequencePoints.end())
            return NULL;
 
        SequencePointList::iterator iter = entry->second->begin();
        while (iter != entry->second->end())
        {
            if ((*iter)->ilOffset >= cp->ilOffset)
                return *iter;
 
            ++iter;
        }
 
        return NULL;
    }
 
    struct CatchPointIter
    {
        CatchPointList::iterator iter, end;
    };
 
    Il2CppCatchPoint* Debugger::GetCatchPoints(const MethodInfo* method, void** iter)
    {
        if (!iter)
            return NULL;
 
        CatchPointIter *pIter = NULL;
 
        if (!*iter)
        {
            MethodToCatchPointsMap::const_iterator entry = s_methodToCatchPoints.find(method);
            if (entry == s_methodToCatchPoints.end())
                return NULL;
 
            pIter = new CatchPointIter();
            *iter = pIter;
            pIter->iter = entry->second->begin();
            pIter->end = entry->second->end();
            return *(pIter->iter);
        }
 
        pIter = (CatchPointIter*)*iter;
        pIter->iter++;
        if (pIter->iter != pIter->end)
        {
            return *(pIter->iter);
        }
        else
        {
            delete pIter;
            *iter = NULL;
        }
 
        return NULL;
    }
 
    void Debugger::HandleException(Il2CppException *exc)
    {
        if (s_IsDebuggerInitialized)
            unity_debugger_agent_handle_exception(exc);
    }
 
    bool SequencePointOffsetLess(const Il2CppSequencePoint *s1, const Il2CppSequencePoint *s2)
    {
        return s1->ilOffset < s2->ilOffset;
    }
 
    bool CatchPointOffsetLess(const Il2CppCatchPoint *c1, const Il2CppCatchPoint *c2)
    {
        return c1->ilOffset < c2->ilOffset;
    }
 
    void Debugger::InitializeMethodToSequencePointMap()
    {
        size_t count = 0;
        vm::AssemblyVector* assemblies = vm::Assembly::GetAllAssemblies();
        for (vm::AssemblyVector::const_iterator iter = assemblies->begin(); iter != assemblies->end(); ++iter)
        {
            const Il2CppDebuggerMetadataRegistration* debuggerMetadata = vm::Assembly::GetImage(*iter)->codeGenModule->debuggerMetadata;
            for (int i = 0; i < debuggerMetadata->numSequencePoints; ++i)
            {
                Il2CppSequencePoint& seqPoint = debuggerMetadata->sequencePoints[i];
                const MethodInfo *method = GetSequencePointMethod(&seqPoint);
 
                if (method != NULL)
                {
                    IL2CPP_ASSERT(!method->is_inflated && "Only open generic methods should have sequence points");
 
                    SequencePointList* list;
                    MethodToSequencePointsMap::iterator existingList = s_methodToSequencePoints.find(method);
                    if (existingList == s_methodToSequencePoints.end())
                    {
                        list = new SequencePointList();
                        s_methodToSequencePoints.add(method, list);
                    }
                    else
                    {
                        list = existingList->second;
                    }
                    list->push_back(&seqPoint);
                    count++;
                }
            }
        }
 
        s_sequencePoints.reserve(count);
 
        for (MethodToSequencePointsMap::iterator methods = s_methodToSequencePoints.begin(); methods != s_methodToSequencePoints.end(); ++methods)
        {
            SequencePointList *seqPoints = methods->second;
            std::sort(seqPoints->begin(), seqPoints->end(), SequencePointOffsetLess);
            s_sequencePoints.insert(s_sequencePoints.end(), seqPoints->begin(), seqPoints->end());
        }
    }
 
    void Debugger::InitializeMethodToCatchPointMap()
    {
        vm::AssemblyVector* assemblies = vm::Assembly::GetAllAssemblies();
        for (vm::AssemblyVector::const_iterator iter = assemblies->begin(); iter != assemblies->end(); ++iter)
        {
            const Il2CppDebuggerMetadataRegistration* debuggerMetadata = vm::Assembly::GetImage(*iter)->codeGenModule->debuggerMetadata;
            for (int i = 0; i < debuggerMetadata->numCatchPoints; ++i)
            {
                Il2CppCatchPoint& catchPoint = debuggerMetadata->catchPoints[i];
                const MethodInfo *method = GetCatchPointMethod(&catchPoint);
 
                if (method != NULL)
                {
                    CatchPointList* list;
                    MethodToCatchPointsMap::iterator existingList = s_methodToCatchPoints.find(method);
                    if (existingList == s_methodToCatchPoints.end())
                    {
                        list = new CatchPointList();
                        s_methodToCatchPoints.add(method, list);
                    }
                    else
                    {
                        list = existingList->second;
                    }
                    list->push_back(&catchPoint);
                }
            }
        }
 
        for (MethodToCatchPointsMap::iterator methods = s_methodToCatchPoints.begin(); methods != s_methodToCatchPoints.end(); ++methods)
        {
            CatchPointList *catchPoints = methods->second;
            std::sort(catchPoints->begin(), catchPoints->end(), CatchPointOffsetLess);
        }
    }
 
    const char** Debugger::GetTypeSourceFiles(const Il2CppClass *klass, int& count)
    {
        TypeSourceFileMap::iterator it = s_typeSourceFiles->find(klass);
        if (it == s_typeSourceFiles->end())
        {
            count = 0;
            return NULL;
        }
 
        count = (int)it->second.size();
        return it->second.data();
    }
 
    void Debugger::UserBreak()
    {
        if (s_IsDebuggerAttached)
            mono_debugger_agent_user_break();
    }
 
    bool Debugger::IsLoggingEnabled()
    {
        return mono_debugger_agent_debug_log_is_enabled();
    }
 
    void Debugger::Log(int level, Il2CppString *category, Il2CppString *message)
    {
        if (s_IsDebuggerAttached)
            mono_debugger_agent_debug_log(level, category, message);
    }
 
    bool Debugger::IsPausePointActive()
    {
        return unity_pause_point_active();
    }
 
    void Debugger::CheckPausePoint()
    {
        if (il2cpp::utils::Debugger::IsPausePointActive())
            il2cpp::utils::Debugger::OnPausePointHit();
    }
 
    const MethodInfo* Debugger::GetSequencePointMethod(Il2CppSequencePoint *seqPoint)
    {
        if (seqPoint == NULL)
            return NULL;
 
        return il2cpp::vm::MetadataCache::GetMethodInfoFromMethodDefinitionIndex(seqPoint->methodDefinitionIndex);
    }
 
    const MethodInfo* Debugger::GetCatchPointMethod(Il2CppCatchPoint *catchPoint)
    {
        if (catchPoint == NULL)
            return NULL;
 
        return il2cpp::vm::MetadataCache::GetMethodInfoFromMethodDefinitionIndex(catchPoint->methodDefinitionIndex);
    }
 
    const char* Debugger::GetLocalName(const MethodInfo* method, int32_t index)
    {
        const Il2CppDebuggerMetadataRegistration* debuggerMetadata = method->klass->image->codeGenModule->debuggerMetadata;
        return debuggerMetadata->methodExecutionContextInfoStrings[index];
    }
 
    const Il2CppMethodScope* Debugger::GetLocalScope(const MethodInfo* method, int32_t index)
    {
        const Il2CppDebuggerMetadataRegistration* debuggerMetadata = method->klass->image->codeGenModule->debuggerMetadata;
        return &debuggerMetadata->methodScopes[index];
    }
 
    void Debugger::GetMethodExecutionContextInfo(const MethodInfo* method, uint32_t* executionContextInfoCount, const Il2CppMethodExecutionContextInfo **executionContextInfo, const Il2CppMethodHeaderInfo **headerInfo, const Il2CppMethodScope **scopes)
    {
        if (il2cpp::vm::Method::IsInflated(method))
            method = il2cpp::vm::MetadataCache::GetGenericMethodDefinition(method);
        int methodIndex = il2cpp::vm::MetadataCache::GetIndexForMethodDefinition(method);
        const Il2CppDebuggerMetadataRegistration* debuggerMetadata = method->klass->image->codeGenModule->debuggerMetadata;
 
        Il2CppMethodExecutionContextInfoIndex *index = &debuggerMetadata->methodExecutionContextInfoIndexes[GetTokenRowId(method->token) - 1];
        if (index->count != -1)
        {
            *executionContextInfoCount = index->count;
            *executionContextInfo = &debuggerMetadata->methodExecutionContextInfos[index->startIndex];
        }
        else
        {
            *executionContextInfoCount = 0;
            *executionContextInfo = NULL;
        }
        *headerInfo = &debuggerMetadata->methodHeaderInfos[GetTokenRowId(method->token) - 1];
        *scopes = &debuggerMetadata->methodScopes[(*headerInfo)->startScope];
    }
 
    void Debugger::GetStackFrames(void* context)
    {
        il2cpp::vm::StackFrames* stackFrames = static_cast<il2cpp::vm::StackFrames*>(context);
 
        Il2CppThreadUnwindState* unwindState = GetThreadStatePointer();
        if (unwindState == NULL)
            return; // There might not be any managed code executing yet.
 
        for (uint32_t i = 0; i < unwindState->frameCount; ++i)
        {
            const MethodInfo* method = unwindState->executionContexts[i]->method;
            if (method != NULL)
            {
                Il2CppStackFrameInfo frameInfo = { 0 };
                frameInfo.method = method;
                stackFrames->push_back(frameInfo);
            }
        }
    }
}
}
 
#else
 
#include "Debugger.h"
#include "os/Debug.h"
 
namespace il2cpp
{
namespace utils
{
    bool Debugger::GetIsDebuggerAttached()
    {
        return os::Debug::IsDebuggerPresent();
    }
}
}
 
#endif // IL2CPP_MONO_DEBUGGER