Debian Codegraph @

tests/stub-tool/stub-ext/stubext.h

raw symbols SCIP
1 #ifndef STUBEXT_H
2 #define STUBEXT_H
3 /*
4 * Author: Zhang Yu <[email protected]>
5 * Maintainer: Zhang Yu <[email protected]>
6 *
7 * MIT License
8 *
9 * Copyright (c) 2020 Zhang Yu
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in all
19 * copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
30 //需修改Stub的私用成员函数和成员变量为保护类型
31 #include <stub-tool/cpp-stub/stub.h>
32 #include "stub-shadow.h"
33
34 #define VADDR(CLASS_NAME,MEMBER_NAME) (typename stub_ext::VFLocator<decltype(&CLASS_NAME::MEMBER_NAME)>::Func)(&CLASS_NAME::MEMBER_NAME)
35
36 namespace stub_ext {
37
38 class StubExt : public Stub
39 {
40 public:
41 StubExt() : Stub() {}
42
43 template<typename T, class Lamda>
44 void set_lamda(T addr, Lamda lamda)
45 {
46 Wrapper *wrapper = nullptr;
47 auto addr_stub = depictShadow(&wrapper,addr,lamda);
48 set(addr, addr_stub);
49 char *fn = addrof(addr);
50 auto iter = m_result.find(fn);
51 if (iter != m_result.end()) {
52 m_wrappers.insert(std::make_pair(fn,wrapper));
53 } else {
54 freeWrapper(wrapper);
55 }
56 }
57
58 template<typename T>
59 void reset(T addr)
60 {
61 Stub::reset(addr);
62 char *fn = addrof(addr);
63 auto iter = m_wrappers.find(fn);
64 if (iter != m_wrappers.end()) {
65 freeWrapper(iter->second);
66 m_wrappers.erase(iter);
67 }
68 }
69
70 ~StubExt()
71 {
72 for (auto iter = m_wrappers.begin(); iter != m_wrappers.end(); ++iter) {
73 freeWrapper(iter->second);
74 }
75 }
76 protected:
77 std::map<char*, Wrapper*> m_wrappers;
78 };
79
80 }
81
82 #endif // STUBEXT_H