]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/fault_handlers/debugger.cc
update
[l4.git] / l4 / pkg / plr / server / src / fault_handlers / debugger.cc
1 /*
2  * debugger.cc --
3  *
4  *     Implementation of a tiny debugger without any GDB features.
5  *
6  *     Currently this debugger allows to configure an address in the Romain ini file,
7  *     (simplegdb:singlestep). It will then place a breakpoint (0xCC) on this address
8  *     and once this BP is hit, start single-stepping from this point on.
9  *
10  * (c) 2011-2013 Björn Döbel <doebel@os.inf.tu-dresden.de>,
11  *     economic rights: Technische Universität Dresden (Germany)
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  */
16
17 #include "../log"
18 #include "../app_loading"
19 #include "../emulation"
20 #include "../configuration"
21
22 #include "debugging.h"
23 #include "observers.h"
24
25 Romain::SimpleDebugObserver::SimpleDebugObserver()
26         : _int1_seen(0)
27 {
28         _bp = new Breakpoint(determine_address());
29 }
30
31 /*****************************************************************
32  *                      Debugging stuff                          *
33  *****************************************************************/
34 void Romain::SimpleDebugObserver::startup_notify(Romain::App_instance *i,
35                                                  Romain::App_thread *,
36                                                  Romain::Thread_group *,
37                                                  Romain::App_model *am)
38 {
39         if (_bp->address() != ~0UL) {
40                 _bp->activate(i, am);
41                 DEBUG() << "Activated breakpoint in instance " << i->id()
42                                 << " @ address " << std::hex << _bp->address();
43                 enter_kdebug();
44         }
45 }
46
47
48 void Romain::SimpleDebugObserver::status() const { }
49
50 Romain::Observer::ObserverReturnVal
51 Romain::SimpleDebugObserver::notify(Romain::App_instance *i,
52                                     Romain::App_thread *t,
53                                     Romain::Thread_group *,
54                                     Romain::App_model *am)
55 {
56         switch(t->vcpu()->r()->trapno) {
57                 case 1:
58                         Romain::InstructionPrinter(am->rm()->remote_to_local(t->vcpu()->r()->ip, 0),
59                                                    t->vcpu()->r()->ip);
60                         ++_int1_seen;
61                         t->vcpu()->print_state();
62                         INFO() << "INT1 seen: " << _int1_seen;
63                         enter_kdebug("single step exception");
64                         break;
65                 case 3:
66                         DEBUG() << "INT3 @ " << std::hex << t->vcpu()->r()->ip
67                                     << " addr = " << _bp->address();
68                         if (_bp->was_hit(t)) {
69                                 DEBUG() << "refs: " << _bp->refs();
70                                 t->vcpu()->r()->ip -= 1; // revert int3
71                                 t->vcpu()->r()->flags |= TrapFlag;
72                                 _bp->deactivate(i, am);
73                                 if (_bp->refs() == 0)
74                                         delete _bp;
75                         }
76                         break;
77                 default:
78                         break;
79         }
80
81         return Romain::Observer::Continue;
82 }