]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/fault_handlers/debugging.h
update
[l4.git] / l4 / pkg / plr / server / src / fault_handlers / debugging.h
1 #pragma once
2 /*
3  * debugging.h --
4  *
5  *     Debugging interface
6  *
7  * (c) 2011-2013 Björn Döbel <doebel@os.inf.tu-dresden.de>,
8  *     economic rights: Technische Universität Dresden (Germany)
9  * This file is part of TUD:OS and distributed under the terms of the
10  * GNU General Public License 2.
11  * Please see the COPYING-GPL-2 file for details.
12  */
13
14
15 #include "../log"
16 #include "../manager"
17 #include "../app_loading"
18
19 class Breakpoint
20 {
21         enum {
22                 BREAK_INSTRUCTION = 0xCC,
23         };
24
25         l4_addr_t   _address;
26         l4_umword_t _orig_code;
27         unsigned    _refcnt;
28
29         public:
30                 Breakpoint(l4_addr_t addr)
31                         : _address(addr), _orig_code(0), _refcnt(0)
32                 { }
33
34
35                 ~Breakpoint()
36                 { }
37
38
39                 void activate(Romain::App_instance *i, Romain::App_model *m)
40                 {
41                         ++_refcnt;
42                         l4_addr_t local = m->rm()->remote_to_local(address(), i->id());
43                         DEBUG() << "Setting BP @ 0x" << std::hex << address()
44                                 << " -> local 0x" << local;
45                         _orig_code = *(l4_umword_t*)local;
46                         *(unsigned char*)local = BREAK_INSTRUCTION;
47                         DEBUG() << "addr @ " << std::hex << &_address;
48                 }
49
50
51                 void deactivate(Romain::App_instance *i, Romain::App_model *m)
52                 {
53                         --_refcnt;
54                         DEBUG() << "Deactivating bp @ " << std::hex << address()
55                                 << " in instance " << i->id();
56                         DEBUG() << "(addr == " << &_address << ")";
57                         l4_addr_t local = m->rm()->remote_to_local(address(), i->id());
58                         *(l4_umword_t*)local = _orig_code;
59                 }
60
61
62                 l4_addr_t address() { return _address; }
63                 l4_umword_t orig()  { return _orig_code; }
64                 unsigned refs() const { return _refcnt; }
65
66                 bool was_hit(Romain::App_thread *t)
67                 {
68                         return (t->vcpu()->r()->ip - 1) == _address;
69                 }
70 };