kdlibcpp

Форк
0
/
processmon.cpp 
925 строк · 26.0 Кб
1
#include "stdafx.h"
2

3
#include <map>
4

5
#include <boost/thread/recursive_mutex.hpp>
6
#include <boost/atomic.hpp>
7

8
#include "processmon.h"
9

10
namespace kdlib
11
{
12

13
///////////////////////////////////////////////////////////////////////////////
14

15
class ProcessInfo;
16
typedef boost::shared_ptr<ProcessInfo>  ProcessInfoPtr;
17

18
///////////////////////////////////////////////////////////////////////////////
19

20
class ProcessInfo {
21

22
public:
23

24
    ModulePtr getModule(MEMOFFSET_64  offset);
25
    void insertModule( ModulePtr& module);
26
    void removeModule(MEMOFFSET_64  offset );
27

28
    TypeInfoPtr getTypeInfo(const std::wstring& name);
29
    void insertTypeInfo(const TypeInfoPtr& typeInfo);
30

31
    void insertBreakpoint(const BreakpointPtr& breakpoint);
32
    void removeBreakpoint(const BreakpointPtr& breakpoint);
33

34
    DebugCallbackResult breakpointHit(BreakpointPtr& breakpoint);
35

36
    void onChangeSymbolPaths();
37

38
private:
39

40
    typedef std::map<MEMOFFSET_64, ModulePtr> ModuleMap;
41
    ModuleMap  m_moduleMap;
42
    boost::recursive_mutex  m_moduleLock;
43

44
    typedef std::map<std::wstring, TypeInfoPtr>  TypeInfoMap;
45
    TypeInfoMap  m_typeInfoMap;
46
    boost::recursive_mutex  m_typeInfoLock;
47
    
48
    typedef std::map<BREAKPOINT_ID, BreakpointPtr>  BreakpointIdMap;
49
    BreakpointIdMap  m_breakpointMap;
50
    boost::recursive_mutex  m_breakpointLock;
51
};
52

53
///////////////////////////////////////////////////////////////////////////////
54

55
class ProcessMonitorImpl {
56

57
public:
58

59
    ProcessMonitorImpl() : m_bpUnique(0x80000000)
60
    {}
61

62
    ~ProcessMonitorImpl()
63
    {}
64

65
public:
66

67
    DebugCallbackResult processStart(PROCESS_DEBUG_ID id);
68
    DebugCallbackResult processStop(PROCESS_DEBUG_ID id, ProcessExitReason reason, unsigned int ExitCode);
69
    void processAllDetach();
70
    void processAllTerminate();
71
    unsigned int getNumberProcesses();
72

73
    DebugCallbackResult createThread();
74
    DebugCallbackResult stopThread();
75

76
    DebugCallbackResult moduleLoad(PROCESS_DEBUG_ID id, MEMOFFSET_64 offset, const std::wstring& moduleName);
77
    DebugCallbackResult moduleUnload(PROCESS_DEBUG_ID id, MEMOFFSET_64  offset, const std::wstring& moduleName);
78
    DebugCallbackResult breakpointHit(PROCESS_DEBUG_ID id, BreakpointPtr& breakpoint);
79
    void currentThreadChange(THREAD_DEBUG_ID threadid);
80
    void executionStatusChange(ExecutionStatus status);
81
    void localScopeChange();
82
    void changeSymbolPaths();
83
    void breakpointsChange(PROCESS_DEBUG_ID id);
84
    DebugCallbackResult  exceptionHit(const ExceptionInfo& excinfo);
85
    void debugOutput(const std::wstring& text, OutputFlag flag);
86
    void startInput();
87
    void stopInput();
88

89
    ModulePtr getModule( MEMOFFSET_64  offset, PROCESS_DEBUG_ID id );
90
    void insertModule( ModulePtr& module, PROCESS_DEBUG_ID id );
91

92
    TypeInfoPtr getTypeInfo(const std::wstring& name, PROCESS_DEBUG_ID id = -1);
93
    void insertTypeInfo(const TypeInfoPtr& typeInfo, PROCESS_DEBUG_ID id = -1);
94

95
    void registerEventsCallback(DebugEventsCallback *callback);
96
    void removeEventsCallback(DebugEventsCallback *callback);
97

98
    void registerBreakpoint( const BreakpointPtr& breakpoint, PROCESS_DEBUG_ID id = -1 );
99
    void removeBreakpoint( const BreakpointPtr& breakpoint, PROCESS_DEBUG_ID id = -1 );
100

101
private:
102

103
    ProcessInfoPtr  getProcess( PROCESS_DEBUG_ID id );
104

105
    boost::recursive_mutex  m_lock;
106

107
    typedef std::map<PROCESS_DEBUG_ID, ProcessInfoPtr>  ProcessMap;
108
    ProcessMap  m_processMap;
109

110
    boost::atomic<unsigned long long>  m_bpUnique;
111

112
private:
113

114
    typedef std::list<DebugEventsCallback*>  EventsCallbackList;
115

116
    boost::recursive_mutex      m_callbacksLock;
117
    EventsCallbackList          m_callbacks;
118
};
119

120
ProcessMonitorImpl*  g_procmon;
121

122
///////////////////////////////////////////////////////////////////////////////
123

124
class CurrentProcessGuard {
125

126
public:
127

128
    CurrentProcessGuard() :
129
        m_procId( getCurrentProcessId() )
130
        {}
131

132
    ~CurrentProcessGuard() {
133
        setCurrentProcessById(m_procId);
134
    }
135

136
private:
137

138
    PROCESS_DEBUG_ID  m_procId;
139
};
140

141
///////////////////////////////////////////////////////////////////////////////
142

143
void ProcessMonitor::init()
144
{
145
    if (!g_procmon)
146
        g_procmon = new ProcessMonitorImpl();
147
}
148

149
///////////////////////////////////////////////////////////////////////////////
150

151
void ProcessMonitor::deinit()
152
{
153
    if (g_procmon)
154
    {
155
        delete  g_procmon;
156
        g_procmon = nullptr;
157
    }
158
}
159

160
/////////////////////////////////////////////////////////////////////////////
161

162
void ProcessMonitor::registerEventsCallback(DebugEventsCallback *callback)
163
{
164
    g_procmon->registerEventsCallback(callback);
165
}
166

167
/////////////////////////////////////////////////////////////////////////////
168

169
void ProcessMonitor::removeEventsCallback(DebugEventsCallback *callback)
170
{
171
    g_procmon->removeEventsCallback(callback);
172
}
173

174
/////////////////////////////////////////////////////////////////////////////
175

176
void ProcessMonitor::registerBreakpoint( const BreakpointPtr& breakpoint, PROCESS_DEBUG_ID id )
177
{
178
    if ( id == -1 )
179
        id = getCurrentProcessId();
180

181
    g_procmon->registerBreakpoint(breakpoint, id);
182
}
183

184

185
/////////////////////////////////////////////////////////////////////////////
186

187
void ProcessMonitor::removeBreakpoint( const BreakpointPtr& breakpoint, PROCESS_DEBUG_ID id )
188
{
189
    if ( id == -1 )
190
        id = getCurrentProcessId();
191

192
    g_procmon->removeBreakpoint(breakpoint, id);
193
}
194

195
/////////////////////////////////////////////////////////////////////////////
196

197
DebugCallbackResult ProcessMonitor::processStart(PROCESS_DEBUG_ID id)
198
{
199
    return g_procmon->processStart(id);
200
}
201

202
/////////////////////////////////////////////////////////////////////////////
203

204
DebugCallbackResult ProcessMonitor::processStop(PROCESS_DEBUG_ID id, ProcessExitReason reason, unsigned int exitCode)
205
{
206
    return g_procmon->processStop(id, reason, exitCode);
207
}
208

209
///////////////////////////////////////////////////////////////////////////////
210

211
DebugCallbackResult ProcessMonitor::createThread()
212
{
213
    return g_procmon->createThread();
214
}
215

216
///////////////////////////////////////////////////////////////////////////////
217

218
DebugCallbackResult ProcessMonitor::stopThread()
219
{
220
    return g_procmon->stopThread();
221
}
222

223
///////////////////////////////////////////////////////////////////////////////
224

225
void ProcessMonitor::processAllTerminate()
226
{
227
    g_procmon->processAllTerminate();
228
}
229

230
///////////////////////////////////////////////////////////////////////////////
231

232
void ProcessMonitor::processAllDetach()
233
{
234
    g_procmon->processAllDetach();
235
}
236

237
///////////////////////////////////////////////////////////////////////////////
238

239
unsigned int ProcessMonitor::getNumberProcesses()
240
{
241
    return g_procmon->getNumberProcesses();
242
}
243

244
///////////////////////////////////////////////////////////////////////////////
245

246
DebugCallbackResult ProcessMonitor::moduleLoad(PROCESS_DEBUG_ID id, MEMOFFSET_64 offset, const std::wstring& moduleName)
247
{
248
    return g_procmon->moduleLoad(id, offset, moduleName);
249
}
250

251
///////////////////////////////////////////////////////////////////////////////
252

253
DebugCallbackResult ProcessMonitor::moduleUnload(PROCESS_DEBUG_ID id, MEMOFFSET_64  offset, const std::wstring& moduleName)
254
{
255
    return g_procmon->moduleUnload(id, offset, moduleName);
256
}
257

258
///////////////////////////////////////////////////////////////////////////////
259

260
DebugCallbackResult ProcessMonitor::breakpointHit(PROCESS_DEBUG_ID id, BreakpointPtr& breakpoint)
261
{
262
    return g_procmon->breakpointHit(id, breakpoint);
263
}
264

265
///////////////////////////////////////////////////////////////////////////////
266

267
void ProcessMonitor::currentThreadChange(THREAD_DEBUG_ID id)
268
{
269
    g_procmon->currentThreadChange(id);
270
}
271

272
///////////////////////////////////////////////////////////////////////////////
273

274
void ProcessMonitor::executionStatusChange(ExecutionStatus status)
275
{
276
    g_procmon->executionStatusChange(status);
277
}
278

279
///////////////////////////////////////////////////////////////////////////////
280

281
void ProcessMonitor::localScopeChange()
282
{
283
    g_procmon->localScopeChange();
284
}
285

286
///////////////////////////////////////////////////////////////////////////////
287

288
void ProcessMonitor::changeSymbolPaths()
289
{
290
    g_procmon->changeSymbolPaths();
291
}
292

293
///////////////////////////////////////////////////////////////////////////////
294

295
void ProcessMonitor::breakpointsChange(PROCESS_DEBUG_ID id)
296
{
297
    g_procmon->breakpointsChange(id);
298
}
299

300
///////////////////////////////////////////////////////////////////////////////
301

302
DebugCallbackResult ProcessMonitor::exceptionHit(const ExceptionInfo& excinfo)
303
{
304
    return g_procmon->exceptionHit(excinfo);
305
}
306

307
///////////////////////////////////////////////////////////////////////////////
308

309
void ProcessMonitor::debugOutput(const std::wstring& text, OutputFlag flag)
310
{
311
    g_procmon->debugOutput(text, flag);
312
}
313

314
///////////////////////////////////////////////////////////////////////////////
315

316
void ProcessMonitor::startInput()
317
{
318
    g_procmon->startInput();
319
}
320

321
///////////////////////////////////////////////////////////////////////////////
322

323
void ProcessMonitor::stopInput()
324
{
325
    g_procmon->stopInput();
326
}
327

328
///////////////////////////////////////////////////////////////////////////////
329

330
ModulePtr ProcessMonitor::getModule( MEMOFFSET_64  offset, PROCESS_DEBUG_ID id )
331
{
332
    if ( id == -1 )
333
        id = getCurrentProcessId();
334

335
    return g_procmon->getModule(offset,id);
336
}
337

338
///////////////////////////////////////////////////////////////////////////////
339

340
void ProcessMonitor::insertModule( ModulePtr& module, PROCESS_DEBUG_ID id )
341
{
342
    if ( id == -1 )
343
        id = getCurrentProcessId();
344

345
    return g_procmon->insertModule(module, id);
346
}
347

348
///////////////////////////////////////////////////////////////////////////////
349

350
TypeInfoPtr ProcessMonitor::getTypeInfo(const std::wstring& name, PROCESS_DEBUG_ID id)
351
{
352
    if (id == -1)
353
        id = getCurrentProcessId();
354

355
    return g_procmon->getTypeInfo(name, id);
356
}
357

358
///////////////////////////////////////////////////////////////////////////////
359

360
void ProcessMonitor::insertTypeInfo(const TypeInfoPtr& typeInfo, PROCESS_DEBUG_ID id)
361
{
362
    if (id == -1)
363
        id = getCurrentProcessId();
364

365
    return g_procmon->insertTypeInfo(typeInfo, id);
366
}
367

368
///////////////////////////////////////////////////////////////////////////////
369

370
DebugCallbackResult ProcessMonitorImpl::processStart(PROCESS_DEBUG_ID id)
371
{
372
    {
373
        ProcessInfoPtr  proc = ProcessInfoPtr(new ProcessInfo());
374
        boost::recursive_mutex::scoped_lock l(m_lock);
375
        m_processMap[id] = proc;
376
    }
377

378
    DebugCallbackResult  result = DebugCallbackNoChange;
379

380
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
381

382
    EventsCallbackList::iterator  it = m_callbacks.begin();
383

384
    for (; it != m_callbacks.end(); ++it)
385
    {
386
        DebugCallbackResult  ret = (*it)->onProcessStart(id);
387
        result = ret != DebugCallbackNoChange ? ret : result;
388
    }
389

390
    return result;
391
}
392

393

394
///////////////////////////////////////////////////////////////////////////////
395

396
DebugCallbackResult ProcessMonitorImpl::processStop(PROCESS_DEBUG_ID id, ProcessExitReason reason, unsigned int exitCode)
397
{
398
    {
399
        boost::recursive_mutex::scoped_lock l(m_lock);
400
        m_processMap.erase(id);
401
    }
402

403
    DebugCallbackResult  result = DebugCallbackNoChange;
404

405
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
406

407
    EventsCallbackList::iterator  it = m_callbacks.begin();
408

409
    for (; it != m_callbacks.end(); ++it)
410
    {
411
        DebugCallbackResult  ret = (*it)->onProcessExit(id, reason, exitCode);
412
        result = ret != DebugCallbackNoChange ? ret : result;
413
    }
414

415
    return result;
416
}
417

418
///////////////////////////////////////////////////////////////////////////////
419

420
DebugCallbackResult ProcessMonitorImpl::createThread()
421
{
422
    DebugCallbackResult  result = DebugCallbackNoChange;
423

424
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
425

426
    EventsCallbackList::iterator  it = m_callbacks.begin();
427

428
    for (; it != m_callbacks.end(); ++it)
429
    {
430
        DebugCallbackResult  ret = (*it)->onThreadStart();
431
        result = ret != DebugCallbackNoChange ? ret : result;
432
    }
433

434
    return result;
435
}
436

437
///////////////////////////////////////////////////////////////////////////////
438

439
DebugCallbackResult ProcessMonitorImpl::stopThread()
440
{
441
    DebugCallbackResult  result = DebugCallbackNoChange;
442

443
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
444

445
    EventsCallbackList::iterator  it = m_callbacks.begin();
446

447
    for (; it != m_callbacks.end(); ++it)
448
    {
449
        DebugCallbackResult  ret = (*it)->onThreadStop();
450
        result = ret != DebugCallbackNoChange ? ret : result;
451
    }
452

453
    return result;
454
}
455

456
///////////////////////////////////////////////////////////////////////////////
457

458
void ProcessMonitorImpl::processAllTerminate()
459
{
460
    while (!m_processMap.empty())
461
    {
462
        PROCESS_DEBUG_ID id = m_processMap.begin()->first;
463
        processStop(id, ProcessTerminate, 0);
464
    }
465
}
466

467
///////////////////////////////////////////////////////////////////////////////
468

469
void ProcessMonitorImpl::processAllDetach()
470
{
471
    while (!m_processMap.empty())
472
    {
473
        PROCESS_DEBUG_ID id = m_processMap.begin()->first;
474
        processStop(id, ProcessDetach, 0);
475
    }
476
}
477

478
///////////////////////////////////////////////////////////////////////////////
479

480
unsigned int ProcessMonitorImpl::getNumberProcesses()
481
{
482
    boost::recursive_mutex::scoped_lock l(m_lock);
483
    return static_cast<unsigned int>(m_processMap.size());
484
}
485

486
///////////////////////////////////////////////////////////////////////////////
487

488
ModulePtr ProcessMonitorImpl::getModule( MEMOFFSET_64  offset, PROCESS_DEBUG_ID id )
489
{
490
    ProcessInfoPtr  processInfo = getProcess(id);
491

492
    ModulePtr  module;
493

494
    if ( processInfo )
495
        module = processInfo->getModule(offset);
496

497
    return module;
498
}
499

500
///////////////////////////////////////////////////////////////////////////////
501

502
DebugCallbackResult ProcessMonitorImpl::moduleLoad(PROCESS_DEBUG_ID id, MEMOFFSET_64 offset, const std::wstring& moduleName)
503
{
504
    DebugCallbackResult  result = DebugCallbackNoChange;
505

506
    ProcessInfoPtr  processInfo = getProcess(id);
507

508
    if ( processInfo )
509
    {
510
        processInfo->removeModule( offset );
511
        loadModule(offset);
512
    }
513

514
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
515

516
    EventsCallbackList::iterator  it;
517
    for (it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
518
    {
519
        DebugCallbackResult  ret = (*it)->onModuleLoad(offset, moduleName);
520
        result = ret != DebugCallbackNoChange ? ret : result;
521
    }
522

523
    return result;
524
}
525

526
///////////////////////////////////////////////////////////////////////////////
527

528
DebugCallbackResult ProcessMonitorImpl::moduleUnload(PROCESS_DEBUG_ID id, MEMOFFSET_64  offset, const std::wstring &moduleName)
529
{
530
    DebugCallbackResult  result = DebugCallbackNoChange;
531

532
    ProcessInfoPtr  processInfo = getProcess(id);
533

534
    if ( processInfo )
535
        processInfo->removeModule( offset );
536

537
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
538

539
    EventsCallbackList::iterator  it;
540
    for ( it = m_callbacks.begin(); it != m_callbacks.end(); ++it )
541
    {
542
        DebugCallbackResult  ret = (*it)->onModuleUnload(offset, moduleName );
543
        result = ret != DebugCallbackNoChange ? ret : result;
544
    }
545

546
    return result;
547
}
548

549
///////////////////////////////////////////////////////////////////////////////
550

551
DebugCallbackResult ProcessMonitorImpl::breakpointHit(PROCESS_DEBUG_ID id, BreakpointPtr& breakpoint)
552
{
553
    DebugCallbackResult  result = DebugCallbackNoChange;
554

555
    ProcessInfoPtr  processInfo = getProcess(id);
556
    if ( processInfo )
557
        result = processInfo->breakpointHit(breakpoint);
558

559
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
560

561
    EventsCallbackList::iterator  it;
562
    for (it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
563
    {
564
        DebugCallbackResult  ret = (*it)->onBreakpoint(breakpoint->getId());
565
        result = ret != DebugCallbackNoChange ? ret : result;
566
    }
567

568
    return result;
569
}
570

571
///////////////////////////////////////////////////////////////////////////////
572

573
void ProcessMonitorImpl::currentThreadChange(THREAD_DEBUG_ID threadid)
574
{
575
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
576

577
    EventsCallbackList::iterator  it = m_callbacks.begin();
578

579
    for (; it != m_callbacks.end(); ++it)
580
    {
581
        (*it)->onCurrentThreadChange(threadid);
582
    }
583
}
584

585
///////////////////////////////////////////////////////////////////////////////
586

587
void ProcessMonitorImpl::executionStatusChange(ExecutionStatus status)
588
{
589
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
590

591
    EventsCallbackList::iterator  it = m_callbacks.begin();
592

593
    for (; it != m_callbacks.end(); ++it)
594
    {
595
        (*it)->onExecutionStatusChange(status);
596
    }
597
}
598

599
///////////////////////////////////////////////////////////////////////////////
600

601
void ProcessMonitorImpl::localScopeChange()
602
{
603
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
604

605
    EventsCallbackList::iterator  it = m_callbacks.begin();
606

607
    for (; it != m_callbacks.end(); ++it)
608
    {
609
        (*it)->onChangeLocalScope();
610
    }
611
}
612

613
///////////////////////////////////////////////////////////////////////////////
614

615
void ProcessMonitorImpl::changeSymbolPaths()
616
{
617

618
    {
619
        boost::recursive_mutex::scoped_lock l(m_lock);
620

621
        for ( ProcessMap::iterator  it = m_processMap.begin(); it != m_processMap.end(); ++it)
622
           it->second->onChangeSymbolPaths();
623
    }
624

625
    {
626
        boost::recursive_mutex::scoped_lock l(m_callbacksLock);
627

628
        EventsCallbackList::iterator  it = m_callbacks.begin();
629

630
        for (; it != m_callbacks.end(); ++it)
631
        {
632
            (*it)->onChangeSymbolPaths();
633
        }
634
    }
635
}
636

637
///////////////////////////////////////////////////////////////////////////////
638

639
void ProcessMonitorImpl::breakpointsChange(PROCESS_DEBUG_ID id)
640
{
641
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
642

643
    EventsCallbackList::iterator  it = m_callbacks.begin();
644

645
    for (; it != m_callbacks.end(); ++it)
646
    {
647
        (*it)->onChangeBreakpoints();
648
    }
649
}
650

651
///////////////////////////////////////////////////////////////////////////////
652

653
DebugCallbackResult  ProcessMonitorImpl::exceptionHit(const ExceptionInfo& excinfo)
654
{
655
    DebugCallbackResult  result = DebugCallbackNoChange;
656

657
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
658

659
    EventsCallbackList::iterator  it;
660
    for (it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
661
    {
662
        DebugCallbackResult  ret = (*it)->onException(excinfo);
663
        result = ret != DebugCallbackNoChange ? ret : result;
664
    }
665

666
    return result;
667
}
668

669
///////////////////////////////////////////////////////////////////////////////
670

671
void ProcessMonitorImpl::debugOutput(const std::wstring& text, OutputFlag flag)
672
{
673
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
674

675
    EventsCallbackList::iterator  it;
676
    for (it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
677
    {
678
        (*it)->onDebugOutput(text, flag);
679
    }
680
}
681

682
///////////////////////////////////////////////////////////////////////////////
683

684
void ProcessMonitorImpl::startInput()
685
{
686
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
687

688
    EventsCallbackList::iterator  it;
689
    for (it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
690
    {
691
        (*it)->onStartInput();
692
    }
693
}
694

695
///////////////////////////////////////////////////////////////////////////////
696

697
void ProcessMonitorImpl::stopInput()
698
{
699
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
700

701
    EventsCallbackList::iterator  it;
702
    for (it = m_callbacks.begin(); it != m_callbacks.end(); ++it)
703
    {
704
        (*it)->onStopInput();
705
    }
706
}
707

708
///////////////////////////////////////////////////////////////////////////////
709

710
void ProcessMonitorImpl::insertModule( ModulePtr& module, PROCESS_DEBUG_ID id )
711
{
712
    ProcessInfoPtr  processInfo = getProcess(id);
713
    if ( processInfo )
714
        return processInfo->insertModule(module);
715
}
716

717
///////////////////////////////////////////////////////////////////////////////
718

719
TypeInfoPtr ProcessMonitorImpl::getTypeInfo(const std::wstring& name, PROCESS_DEBUG_ID id)
720
{
721
    ProcessInfoPtr  processInfo = getProcess(id);
722
    if ( processInfo )
723
        return processInfo->getTypeInfo(name);
724

725
    return TypeInfoPtr();
726
}
727

728
///////////////////////////////////////////////////////////////////////////////
729

730
void ProcessMonitorImpl::insertTypeInfo(const TypeInfoPtr& typeInfo, PROCESS_DEBUG_ID id)
731
{
732
    ProcessInfoPtr  processInfo = getProcess(id);
733
    if (processInfo)
734
        return processInfo->insertTypeInfo(typeInfo);
735
}
736

737
///////////////////////////////////////////////////////////////////////////////
738

739
ProcessInfoPtr ProcessMonitorImpl::getProcess( PROCESS_DEBUG_ID id )
740
{
741
    boost::recursive_mutex::scoped_lock l(m_lock);
742

743
    ProcessMap::iterator  it  = m_processMap.find(id);
744

745
    if ( it != m_processMap.end() )
746
        return it->second;
747

748
    ProcessInfoPtr  proc = ProcessInfoPtr( new ProcessInfo() );
749
    m_processMap[id] = proc;
750

751
    return proc;
752
}
753

754

755
///////////////////////////////////////////////////////////////////////////////
756

757
void ProcessMonitorImpl::registerEventsCallback(DebugEventsCallback *callback)
758
{
759
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
760
    m_callbacks.push_back(callback);
761
}
762

763
///////////////////////////////////////////////////////////////////////////////
764

765
void ProcessMonitorImpl::removeEventsCallback(DebugEventsCallback *callback)
766
{
767
    boost::recursive_mutex::scoped_lock l(m_callbacksLock);
768
    m_callbacks.remove(callback);
769
}
770

771
///////////////////////////////////////////////////////////////////////////////
772

773
void ProcessMonitorImpl::registerBreakpoint( const BreakpointPtr& breakpoint, PROCESS_DEBUG_ID id )
774
{
775
    ProcessInfoPtr  processInfo = getProcess(id);
776

777
    if ( processInfo )
778
    {
779
        processInfo->insertBreakpoint(breakpoint);
780
    }
781
}
782

783
///////////////////////////////////////////////////////////////////////////////
784

785
void ProcessMonitorImpl::removeBreakpoint( const BreakpointPtr& breakpoint, PROCESS_DEBUG_ID id )
786
{
787
    ProcessInfoPtr  processInfo = getProcess(id);
788

789
    if ( processInfo )
790
    {
791
        processInfo->removeBreakpoint(breakpoint);
792
    }
793
}
794

795
///////////////////////////////////////////////////////////////////////////////
796

797
ModulePtr ProcessInfo::getModule(MEMOFFSET_64  offset)
798
{
799
    boost::recursive_mutex::scoped_lock l(m_moduleLock);
800

801
    ModuleMap::iterator it = m_moduleMap.find(offset);
802

803
    if ( it != m_moduleMap.end() )
804
        return it->second;
805

806
    for ( ModuleMap::iterator it = m_moduleMap.begin(); it != m_moduleMap.end(); ++it )
807
    {
808
        if ( it->second->getBase() <= offset && offset < it->second->getEnd() )
809
        {
810
           return it->second;
811
        }
812
    }
813

814
    return ModulePtr();
815
}
816

817
///////////////////////////////////////////////////////////////////////////////
818

819
void ProcessInfo::insertModule( ModulePtr& module)
820
{
821
    boost::recursive_mutex::scoped_lock l(m_moduleLock);
822
    m_moduleMap[ module->getBase() ] = module;
823
}
824

825
///////////////////////////////////////////////////////////////////////////////
826

827
void ProcessInfo::removeModule(MEMOFFSET_64  offset )
828
{
829
    boost::recursive_mutex::scoped_lock l(m_moduleLock);
830
    m_moduleMap.erase(offset);
831
}
832

833
///////////////////////////////////////////////////////////////////////////////
834

835
TypeInfoPtr ProcessInfo::getTypeInfo(const std::wstring& name)
836
{
837
    boost::recursive_mutex::scoped_lock l(m_typeInfoLock);
838

839
    TypeInfoMap::iterator  it = m_typeInfoMap.find(name);
840

841
    if (it != m_typeInfoMap.end())
842
        return it->second;
843

844
    return TypeInfoPtr();
845
}
846

847
///////////////////////////////////////////////////////////////////////////////
848

849
void ProcessInfo::insertTypeInfo(const TypeInfoPtr& typeInfo)
850
{
851
    boost::recursive_mutex::scoped_lock l(m_typeInfoLock);
852

853
    m_typeInfoMap.insert(std::make_pair(typeInfo->getName(), typeInfo));
854
}
855

856
///////////////////////////////////////////////////////////////////////////////
857

858
void ProcessInfo::insertBreakpoint(const BreakpointPtr& breakpoint)
859
{
860
    boost::recursive_mutex::scoped_lock l(m_breakpointLock);
861
    
862
    m_breakpointMap[breakpoint->getId()] = breakpoint;
863
}
864

865
///////////////////////////////////////////////////////////////////////////////
866

867
void ProcessInfo::removeBreakpoint(const BreakpointPtr& breakpoint)
868
{
869
    BreakpointPtr origbp;
870

871
    {
872
        boost::recursive_mutex::scoped_lock l(m_breakpointLock);
873

874
        BreakpointIdMap::iterator   it = m_breakpointMap.find(breakpoint->getId());
875
        if (it == m_breakpointMap.end() )
876
            return;
877

878
        origbp = it->second;
879

880
        m_breakpointMap.erase(it);
881
    }
882

883
    BreakpointCallback*  callback = origbp->getCallback();
884
    if ( callback != 0 )
885
        callback->onRemove();
886

887
}
888

889

890
///////////////////////////////////////////////////////////////////////////////
891

892
DebugCallbackResult ProcessInfo::breakpointHit(BreakpointPtr& breakpoint)
893
{
894
    boost::recursive_mutex::scoped_lock l(m_breakpointLock);
895
    
896
    BreakpointIdMap::iterator  it =  m_breakpointMap.find( breakpoint->getId() );
897

898
    if ( it == m_breakpointMap.end() )
899
        return DebugCallbackNoChange;
900

901
    BreakpointPtr  origBp = it->second;
902

903
    BreakpointCallback*  callback = origBp->getCallback();
904
    if ( callback == 0 )
905
        return DebugCallbackBreak;
906

907
    return callback->onHit();
908
}
909

910
/////////////////////////////////////////////////////////////////////////////
911

912
void ProcessInfo::onChangeSymbolPaths()
913
{
914
    boost::recursive_mutex::scoped_lock l(m_moduleLock);
915

916
    for ( ModuleMap::iterator it = m_moduleMap.begin(); it != m_moduleMap.end(); ++it)
917
    {
918
        if ( !it->second->isSymbolLoaded() )
919
            it->second->resetSymbols();
920
    }
921
}
922

923
/////////////////////////////////////////////////////////////////////////////
924

925
} //namesapce kdlib
926

927

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.