aboutsummaryrefslogtreecommitdiffstats
path: root/xen/common/debug.c
blob: b17748a864b70f21fe52f12098e84573d558027c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * debug.c
 *
 * xen pervasive debugger
 */

#include <xen/config.h>
#include <xen/types.h>
#include <xen/lib.h>
#include <hypervisor-ifs/dom0_ops.h>
#include <xen/sched.h>
#include <xen/event.h>
#include <asm/page.h>
#include <asm/pdb.h>
#include <asm/shadow.h>

#undef DEBUG_TRACE
#ifdef DEBUG_TRACE
#define TRC(_x) _x
#else
#define TRC(_x)
#endif

/****************************************************************************/

extern u_char pdb_linux_get_value(int pid, unsigned long cr3, 
				  unsigned long addr);

/*
 * interactively call pervasive debugger from a privileged domain
 */
void pdb_do_debug (dom0_op_t *op)
{
    op->u.debug.status = 0;

    TRC(printk("PDB: op:%c, dom:%llu, in1:%x, in2:%x, in3:%x, in4:%x\n",
	       op->u.debug.opcode, op->u.debug.domain,
	       op->u.debug.in1, op->u.debug.in2,
	       op->u.debug.in3, op->u.debug.in4));

    /* NOT NOW
    if (op->u.debug.domain == 0)
    {
        op->u.debug.status = 1;
	return;
    }
    */

    switch (op->u.debug.opcode)
    {
        case 'c' :
	{
	    struct domain *d = find_domain_by_id(op->u.debug.domain);
	    if ( d != NULL )
	    {
                domain_unpause_by_systemcontroller(d);
		put_domain(d);
	    }
	    else
	    {
	        op->u.debug.status = 2;                    /* invalid domain */
	    }
	    break;
	}
        case 'r' :
        {
            int loop;
            u_char x;
	    unsigned long cr3;
	    struct domain *d;

	    d = find_domain_by_id(op->u.debug.domain);
	    if ( shadow_mode(d) )
	      cr3 = pagetable_val(d->mm.shadow_table);
	    else
	      cr3 = pagetable_val(d->mm.pagetable);

            for (loop = 0; loop < op->u.debug.in2; loop++)         /* length */
            { 
                if (loop % 8 == 0)
                {
                    printk ("\n%08x ", op->u.debug.in1 + loop);
                }
                x = pdb_linux_get_value(op->u.debug.in3,
					cr3, op->u.debug.in1 + loop);
                printk (" %02x", x);
            }
            printk ("\n");
	    put_domain(d);
            break;
        }
        case 's' :
	{
	    struct domain *d = find_domain_by_id(op->u.debug.domain);

	    if ( d != NULL )
	    {
                domain_pause_by_systemcontroller(d);
		put_domain(d);
	    }
	    else
	    {
	        op->u.debug.status = 2;                    /* invalid domain */
	    }
	    break;
	}
        default :
	{
	    printk("PDB error: unknown debug opcode %c (0x%x)\n",
		   op->u.debug.opcode, op->u.debug.opcode);
	}
    }
}