1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | // This file contains functions used by both request.cpp and request_svr.cpp |
6 | // to communicate with the debuggee's GC. |
7 | |
8 | #ifndef _REQUEST_COMMON_H_ |
9 | #define _REQUEST_COMMON_H_ |
10 | |
11 | // Indexes into an array of elements of type T, where the size of type |
12 | // T is not (or may not be) known at compile-time. |
13 | // Returns a DPTR to the requested element (the element at the given index). |
14 | template<typename T> |
15 | DPTR(T) TableIndex(DPTR(T) base, size_t index, size_t t_size) |
16 | { |
17 | TADDR base_addr = base.GetAddr(); |
18 | TADDR element_addr = DacTAddrOffset(base_addr, index, t_size); |
19 | return __DPtr<T>(element_addr); |
20 | } |
21 | |
22 | // Dereferences a DPTR(T*), yielding a DPTR(T). |
23 | template<typename T> |
24 | DPTR(T) Dereference(DPTR(T*) ptr) |
25 | { |
26 | TADDR ptr_base = (TADDR)*ptr; |
27 | return __DPtr<T>(ptr_base); |
28 | } |
29 | |
30 | // Indexes into a given generation table, returning a DPTR to the |
31 | // requested element (the element at the given index) of the table. |
32 | inline DPTR(dac_generation) |
33 | GenerationTableIndex(DPTR(dac_generation) base, size_t index) |
34 | { |
35 | return TableIndex(base, index, g_gcDacGlobals->generation_size); |
36 | } |
37 | |
38 | // Indexes into a heap's generation table, given the heap instance |
39 | // and the desired index. Returns a DPTR to the requested element. |
40 | inline DPTR(dac_generation) |
41 | ServerGenerationTableIndex(DPTR(dac_gc_heap) heap, size_t index) |
42 | { |
43 | TADDR base_addr = dac_cast<TADDR>(heap) + offsetof(dac_gc_heap, generation_table); |
44 | DPTR(dac_generation) base = __DPtr<dac_generation>(base_addr); |
45 | return TableIndex(base, index, g_gcDacGlobals->generation_size); |
46 | } |
47 | |
48 | // Indexes into the global heap table, returning a DPTR to the requested |
49 | // heap instance. |
50 | inline DPTR(dac_gc_heap) |
51 | HeapTableIndex(DPTR(dac_gc_heap**) heaps, size_t index) |
52 | { |
53 | DPTR(dac_gc_heap*) heap_table = Dereference(heaps); |
54 | DPTR(dac_gc_heap*) ptr = TableIndex(heap_table, index, sizeof(dac_gc_heap*)); |
55 | return Dereference(ptr); |
56 | } |
57 | |
58 | #endif // _REQUEST_COMMON_H_ |
59 | |