Subversion Repositories HelenOS

Rev

Rev 3343 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3343 Rev 3742
1
/*
1
/*
2
 * Copyright (c) 2006 Ondrej Palkovsky
2
 * Copyright (c) 2006 Ondrej Palkovsky
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup amd64debug
29
/** @addtogroup amd64debug
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch/debugger.h>
35
#include <arch/debugger.h>
36
#include <console/kconsole.h>
36
#include <console/kconsole.h>
37
#include <console/cmd.h>
37
#include <console/cmd.h>
38
#include <symtab.h>
38
#include <symtab.h>
39
#include <print.h>
39
#include <print.h>
40
#include <panic.h>
40
#include <panic.h>
41
#include <interrupt.h>
41
#include <interrupt.h>
42
#include <arch/asm.h>
42
#include <arch/asm.h>
43
#include <arch/cpu.h>
43
#include <arch/cpu.h>
44
#include <debug.h>
44
#include <debug.h>
45
#include <func.h>
45
#include <func.h>
46
#include <smp/ipi.h>
46
#include <smp/ipi.h>
47
 
47
 
48
typedef struct  {
48
typedef struct  {
49
    uintptr_t address;      /**< Breakpoint address */
49
    uintptr_t address;      /**< Breakpoint address */
50
    int flags;              /**< Flags regarding breakpoint */
50
    int flags;              /**< Flags regarding breakpoint */
51
    int counter;            /**< How many times the exception occured */
51
    int counter;            /**< How many times the exception occured */
52
} bpinfo_t;
52
} bpinfo_t;
53
 
53
 
54
static bpinfo_t breakpoints[BKPOINTS_MAX];
54
static bpinfo_t breakpoints[BKPOINTS_MAX];
55
SPINLOCK_INITIALIZE(bkpoint_lock);
55
SPINLOCK_INITIALIZE(bkpoint_lock);
56
 
56
 
-
 
57
#ifdef CONFIG_KCONSOLE
-
 
58
 
57
static int cmd_print_breakpoints(cmd_arg_t *argv);
59
static int cmd_print_breakpoints(cmd_arg_t *argv);
58
static cmd_info_t bkpts_info = {
60
static cmd_info_t bkpts_info = {
59
    .name = "bkpts",
61
    .name = "bkpts",
60
    .description = "Print breakpoint table.",
62
    .description = "Print breakpoint table.",
61
    .func = cmd_print_breakpoints,
63
    .func = cmd_print_breakpoints,
62
    .argc = 0,
64
    .argc = 0,
63
};
65
};
64
 
66
 
65
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
67
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
66
 
68
 
67
static int cmd_del_breakpoint(cmd_arg_t *argv);
69
static int cmd_del_breakpoint(cmd_arg_t *argv);
68
static cmd_arg_t del_argv = {
70
static cmd_arg_t del_argv = {
69
    .type = ARG_TYPE_INT
71
    .type = ARG_TYPE_INT
70
};
72
};
71
static cmd_info_t delbkpt_info = {
73
static cmd_info_t delbkpt_info = {
72
    .name = "delbkpt",
74
    .name = "delbkpt",
73
    .description = "delbkpt <number> - Delete breakpoint.",
75
    .description = "delbkpt <number> - Delete breakpoint.",
74
    .func = cmd_del_breakpoint,
76
    .func = cmd_del_breakpoint,
75
    .argc = 1,
77
    .argc = 1,
76
    .argv = &del_argv
78
    .argv = &del_argv
77
};
79
};
78
 
80
 
79
static int cmd_add_breakpoint(cmd_arg_t *argv);
81
static int cmd_add_breakpoint(cmd_arg_t *argv);
80
static cmd_arg_t add_argv = {
82
static cmd_arg_t add_argv = {
81
    .type = ARG_TYPE_INT
83
    .type = ARG_TYPE_INT
82
};
84
};
83
static cmd_info_t addbkpt_info = {
85
static cmd_info_t addbkpt_info = {
84
    .name = "addbkpt",
86
    .name = "addbkpt",
85
    .description = "addbkpt <&symbol> - new breakpoint.",
87
    .description = "addbkpt <&symbol> - new breakpoint.",
86
    .func = cmd_add_breakpoint,
88
    .func = cmd_add_breakpoint,
87
    .argc = 1,
89
    .argc = 1,
88
    .argv = &add_argv
90
    .argv = &add_argv
89
};
91
};
90
 
92
 
91
static cmd_arg_t addw_argv = {
93
static cmd_arg_t addw_argv = {
92
    .type = ARG_TYPE_INT
94
    .type = ARG_TYPE_INT
93
};
95
};
94
static cmd_info_t addwatchp_info = {
96
static cmd_info_t addwatchp_info = {
95
    .name = "addwatchp",
97
    .name = "addwatchp",
96
    .description = "addbwatchp <&symbol> - new write watchpoint.",
98
    .description = "addbwatchp <&symbol> - new write watchpoint.",
97
    .func = cmd_add_breakpoint,
99
    .func = cmd_add_breakpoint,
98
    .argc = 1,
100
    .argc = 1,
99
    .argv = &addw_argv
101
    .argv = &addw_argv
100
};
102
};
101
 
103
 
102
#endif
-
 
103
 
-
 
104
/** Print table of active breakpoints */
104
#endif /* CONFIG_DEBUG_AS_WATCHPOINT */
105
int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
-
 
106
{
-
 
107
    unsigned int i;
-
 
108
    char *symbol;
-
 
109
 
-
 
110
#ifdef __32_BITS__  
105
#endif /* CONFIG_KCONSOLE */
111
    printf("#  Count Address    In symbol\n");
-
 
112
    printf("-- ----- ---------- ---------\n");
-
 
113
#endif
-
 
114
 
-
 
115
#ifdef __64_BITS__
-
 
116
    printf("#  Count Address            In symbol\n");
-
 
117
    printf("-- ----- ------------------ ---------\n");
-
 
118
#endif
-
 
119
   
-
 
120
    for (i = 0; i < BKPOINTS_MAX; i++)
-
 
121
        if (breakpoints[i].address) {
-
 
122
            symbol = get_symtab_entry(breakpoints[i].address);
-
 
123
 
-
 
124
#ifdef __32_BITS__
-
 
125
            printf("%-2u %-5d %#10zx %s\n", i,
-
 
126
                breakpoints[i].counter, breakpoints[i].address,
-
 
127
                symbol);
-
 
128
#endif
-
 
129
 
-
 
130
#ifdef __64_BITS__
-
 
131
            printf("%-2u %-5d %#18zx %s\n", i,
-
 
132
                breakpoints[i].counter, breakpoints[i].address,
-
 
133
                symbol);
-
 
134
#endif
-
 
135
 
-
 
136
        }
-
 
137
    return 1;
-
 
138
}
-
 
139
 
106
 
140
/* Setup DR register according to table */
107
/* Setup DR register according to table */
141
static void setup_dr(int curidx)
108
static void setup_dr(int curidx)
142
{
109
{
143
    unative_t dr7;
110
    unative_t dr7;
144
    bpinfo_t *cur = &breakpoints[curidx];
111
    bpinfo_t *cur = &breakpoints[curidx];
145
    int flags = breakpoints[curidx].flags;
112
    int flags = breakpoints[curidx].flags;
146
 
113
 
147
    /* Disable breakpoint in DR7 */
114
    /* Disable breakpoint in DR7 */
148
    dr7 = read_dr7();
115
    dr7 = read_dr7();
149
    dr7 &= ~(0x2 << (curidx*2));
116
    dr7 &= ~(0x2 << (curidx*2));
150
 
117
 
151
    if (cur->address) { /* Setup DR register */
118
    if (cur->address) { /* Setup DR register */
152
        /* Set breakpoint to debug registers */
119
        /* Set breakpoint to debug registers */
153
        switch (curidx) {
120
        switch (curidx) {
154
        case 0:
121
        case 0:
155
            write_dr0(cur->address);
122
            write_dr0(cur->address);
156
            break;
123
            break;
157
        case 1:
124
        case 1:
158
            write_dr1(cur->address);
125
            write_dr1(cur->address);
159
            break;
126
            break;
160
        case 2:
127
        case 2:
161
            write_dr2(cur->address);
128
            write_dr2(cur->address);
162
            break;
129
            break;
163
        case 3:
130
        case 3:
164
            write_dr3(cur->address);
131
            write_dr3(cur->address);
165
            break;
132
            break;
166
        }
133
        }
167
        /* Set type to requested breakpoint & length*/
134
        /* Set type to requested breakpoint & length*/
168
        dr7 &= ~ (0x3 << (16 + 4*curidx));
135
        dr7 &= ~ (0x3 << (16 + 4*curidx));
169
        dr7 &= ~ (0x3 << (18 + 4*curidx));
136
        dr7 &= ~ (0x3 << (18 + 4*curidx));
170
        if ((flags & BKPOINT_INSTR)) {
137
        if ((flags & BKPOINT_INSTR)) {
171
            ;
138
            ;
172
        } else {
139
        } else {
173
       
140
       
174
#ifdef __32_BITS__
141
#ifdef __32_BITS__
175
            dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx);
142
            dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx);
176
#endif
143
#endif
177
 
144
 
178
#ifdef __64_BITS__
145
#ifdef __64_BITS__
179
            dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx);
146
            dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx);
180
#endif
147
#endif
181
           
148
           
182
            if ((flags & BKPOINT_WRITE))
149
            if ((flags & BKPOINT_WRITE))
183
                dr7 |= ((unative_t) 0x1) << (16 + 4 * curidx);
150
                dr7 |= ((unative_t) 0x1) << (16 + 4 * curidx);
184
            else if ((flags & BKPOINT_READ_WRITE))
151
            else if ((flags & BKPOINT_READ_WRITE))
185
                dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx);
152
                dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx);
186
        }
153
        }
187
 
154
 
188
        /* Enable global breakpoint */
155
        /* Enable global breakpoint */
189
        dr7 |= 0x2 << (curidx * 2);
156
        dr7 |= 0x2 << (curidx * 2);
190
 
157
 
191
        write_dr7(dr7);
158
        write_dr7(dr7);
192
       
159
       
193
    }
160
    }
194
}
161
}
195
   
162
   
196
/** Enable hardware breakpoint
163
/** Enable hardware breakpoint
197
 *
164
 *
198
 * @param where Address of HW breakpoint
165
 * @param where Address of HW breakpoint
199
 * @param flags Type of breakpoint (EXECUTE, WRITE)
166
 * @param flags Type of breakpoint (EXECUTE, WRITE)
200
 * @return Debug slot on success, -1 - no available HW breakpoint
167
 * @return Debug slot on success, -1 - no available HW breakpoint
201
 */
168
 */
202
int breakpoint_add(const void *where, const int flags, int curidx)
169
int breakpoint_add(const void *where, const int flags, int curidx)
203
{
170
{
204
    ipl_t ipl;
171
    ipl_t ipl;
205
    int i;
172
    int i;
206
    bpinfo_t *cur;
173
    bpinfo_t *cur;
207
 
174
 
208
    ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
175
    ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
209
 
176
 
210
    ipl = interrupts_disable();
177
    ipl = interrupts_disable();
211
    spinlock_lock(&bkpoint_lock);
178
    spinlock_lock(&bkpoint_lock);
212
   
179
   
213
    if (curidx == -1) {
180
    if (curidx == -1) {
214
        /* Find free space in slots */
181
        /* Find free space in slots */
215
        for (i = 0; i < BKPOINTS_MAX; i++)
182
        for (i = 0; i < BKPOINTS_MAX; i++)
216
            if (!breakpoints[i].address) {
183
            if (!breakpoints[i].address) {
217
                curidx = i;
184
                curidx = i;
218
                break;
185
                break;
219
            }
186
            }
220
        if (curidx == -1) {
187
        if (curidx == -1) {
221
            /* Too many breakpoints */
188
            /* Too many breakpoints */
222
            spinlock_unlock(&bkpoint_lock);
189
            spinlock_unlock(&bkpoint_lock);
223
            interrupts_restore(ipl);
190
            interrupts_restore(ipl);
224
            return -1;
191
            return -1;
225
        }
192
        }
226
    }
193
    }
227
    cur = &breakpoints[curidx];
194
    cur = &breakpoints[curidx];
228
 
195
 
229
    cur->address = (uintptr_t) where;
196
    cur->address = (uintptr_t) where;
230
    cur->flags = flags;
197
    cur->flags = flags;
231
    cur->counter = 0;
198
    cur->counter = 0;
232
 
199
 
233
    setup_dr(curidx);
200
    setup_dr(curidx);
234
 
201
 
235
    spinlock_unlock(&bkpoint_lock);
202
    spinlock_unlock(&bkpoint_lock);
236
    interrupts_restore(ipl);
203
    interrupts_restore(ipl);
237
 
204
 
238
    /* Send IPI */
205
    /* Send IPI */
239
#ifdef CONFIG_SMP
206
#ifdef CONFIG_SMP
240
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
207
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
241
#endif  
208
#endif  
242
 
209
 
243
    return curidx;
210
    return curidx;
244
}
211
}
245
 
212
 
246
#ifdef amd64
213
#ifdef amd64
247
#   define getip(x) ((x)->rip)
214
#   define getip(x) ((x)->rip)
248
#else
215
#else
249
#   define getip(x) ((x)->eip)
216
#   define getip(x) ((x)->eip)
250
#endif
217
#endif
251
 
218
 
252
static void handle_exception(int slot, istate_t *istate)
219
static void handle_exception(int slot, istate_t *istate)
253
{
220
{
254
    ASSERT(breakpoints[slot].address);
221
    ASSERT(breakpoints[slot].address);
255
 
222
 
256
    /* Handle zero checker */
223
    /* Handle zero checker */
257
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
224
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
258
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
225
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
259
            if (*((unative_t *) breakpoints[slot].address) != 0)
226
            if (*((unative_t *) breakpoints[slot].address) != 0)
260
                return;
227
                return;
261
            printf("*** Found ZERO on address %lx (slot %d) ***\n",
228
            printf("*** Found ZERO on address %lx (slot %d) ***\n",
262
                breakpoints[slot].address, slot);
229
                breakpoints[slot].address, slot);
263
        } else {
230
        } else {
264
            printf("Data watchpoint - new data: %lx\n",
231
            printf("Data watchpoint - new data: %lx\n",
265
                *((unative_t *) breakpoints[slot].address));
232
                *((unative_t *) breakpoints[slot].address));
266
        }
233
        }
267
    }
234
    }
268
    printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate),
235
    printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate),
269
        get_symtab_entry(getip(istate)));
236
        get_symtab_entry(getip(istate)));
-
 
237
 
270
    printf("***Type 'exit' to exit kconsole.\n");
238
#ifdef CONFIG_KCONSOLE
271
    atomic_set(&haltstate,1);
239
    atomic_set(&haltstate, 1);
272
    kconsole((void *) "debug");
240
    kconsole("debug", "Debug console ready (type 'exit' to continue)\n", false);
273
    atomic_set(&haltstate,0);
241
    atomic_set(&haltstate, 0);
-
 
242
#endif
274
}
243
}
275
 
244
 
276
void breakpoint_del(int slot)
245
void breakpoint_del(int slot)
277
{
246
{
278
    bpinfo_t *cur;
247
    bpinfo_t *cur;
279
    ipl_t ipl;
248
    ipl_t ipl;
280
 
249
 
281
    ipl = interrupts_disable();
250
    ipl = interrupts_disable();
282
    spinlock_lock(&bkpoint_lock);
251
    spinlock_lock(&bkpoint_lock);
283
 
252
 
284
    cur = &breakpoints[slot];
253
    cur = &breakpoints[slot];
285
    if (!cur->address) {
254
    if (!cur->address) {
286
        spinlock_unlock(&bkpoint_lock);
255
        spinlock_unlock(&bkpoint_lock);
287
        interrupts_restore(ipl);
256
        interrupts_restore(ipl);
288
        return;
257
        return;
289
    }
258
    }
290
 
259
 
291
    cur->address = NULL;
260
    cur->address = NULL;
292
 
261
 
293
    setup_dr(slot);
262
    setup_dr(slot);
294
 
263
 
295
    spinlock_unlock(&bkpoint_lock);
264
    spinlock_unlock(&bkpoint_lock);
296
    interrupts_restore(ipl);
265
    interrupts_restore(ipl);
297
#ifdef CONFIG_SMP
266
#ifdef CONFIG_SMP
298
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
267
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
299
#endif
268
#endif
300
}
269
}
301
 
270
 
302
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
-
 
303
 
271
 
304
/** Remove breakpoint from table */
-
 
305
int cmd_del_breakpoint(cmd_arg_t *argv)
-
 
306
{
-
 
307
    unative_t bpno = argv->intval;
-
 
308
    if (bpno > BKPOINTS_MAX) {
-
 
309
        printf("Invalid breakpoint number.\n");
-
 
310
        return 0;
-
 
311
    }
-
 
312
    breakpoint_del(argv->intval);
-
 
313
    return 1;
-
 
314
}
-
 
315
 
-
 
316
/** Add new breakpoint to table */
-
 
317
static int cmd_add_breakpoint(cmd_arg_t *argv)
-
 
318
{
-
 
319
    int flags;
-
 
320
    int id;
-
 
321
 
-
 
322
    if (argv == &add_argv) {
-
 
323
        flags = BKPOINT_INSTR;
-
 
324
    } else { /* addwatchp */
-
 
325
        flags = BKPOINT_WRITE;
-
 
326
    }
-
 
327
    printf("Adding breakpoint on address: %p\n", argv->intval);
-
 
328
    id = breakpoint_add((void *)argv->intval, flags, -1);
-
 
329
    if (id < 0)
-
 
330
        printf("Add breakpoint failed.\n");
-
 
331
    else
-
 
332
        printf("Added breakpoint %d.\n", id);
-
 
333
   
-
 
334
    return 1;
-
 
335
}
-
 
336
#endif
-
 
337
 
272
 
338
static void debug_exception(int n __attribute__((unused)), istate_t *istate)
273
static void debug_exception(int n __attribute__((unused)), istate_t *istate)
339
{
274
{
340
    unative_t dr6;
275
    unative_t dr6;
341
    int i;
276
    int i;
342
   
277
   
343
    /* Set RF to restart the instruction  */
278
    /* Set RF to restart the instruction  */
344
#ifdef amd64       
279
#ifdef amd64       
345
    istate->rflags |= RFLAGS_RF;
280
    istate->rflags |= RFLAGS_RF;
346
#else
281
#else
347
    istate->eflags |= EFLAGS_RF;
282
    istate->eflags |= EFLAGS_RF;
348
#endif
283
#endif
349
 
284
 
350
    dr6 = read_dr6();
285
    dr6 = read_dr6();
351
    for (i=0; i < BKPOINTS_MAX; i++) {
286
    for (i=0; i < BKPOINTS_MAX; i++) {
352
        if (dr6 & (1 << i)) {
287
        if (dr6 & (1 << i)) {
353
            dr6 &= ~ (1 << i);
288
            dr6 &= ~ (1 << i);
354
            write_dr6(dr6);
289
            write_dr6(dr6);
355
           
290
           
356
            handle_exception(i, istate);
291
            handle_exception(i, istate);
357
        }
292
        }
358
    }
293
    }
359
}
294
}
360
 
295
 
361
#ifdef CONFIG_SMP
296
#ifdef CONFIG_SMP
362
static void
297
static void
363
debug_ipi(int n __attribute__((unused)),
298
debug_ipi(int n __attribute__((unused)),
364
    istate_t *istate __attribute__((unused)))
299
    istate_t *istate __attribute__((unused)))
365
{
300
{
366
    int i;
301
    int i;
367
 
302
 
368
    spinlock_lock(&bkpoint_lock);
303
    spinlock_lock(&bkpoint_lock);
369
    for (i = 0; i < BKPOINTS_MAX; i++)
304
    for (i = 0; i < BKPOINTS_MAX; i++)
370
        setup_dr(i);
305
        setup_dr(i);
371
    spinlock_unlock(&bkpoint_lock);
306
    spinlock_unlock(&bkpoint_lock);
372
}
307
}
373
#endif
308
#endif
374
 
309
 
375
/** Initialize debugger */
310
/** Initialize debugger */
376
void debugger_init()
311
void debugger_init()
377
{
312
{
378
    int i;
313
    int i;
379
 
314
 
380
    for (i = 0; i < BKPOINTS_MAX; i++)
315
    for (i = 0; i < BKPOINTS_MAX; i++)
381
        breakpoints[i].address = NULL;
316
        breakpoints[i].address = NULL;
382
   
317
 
-
 
318
#ifdef CONFIG_KCONSOLE
383
    cmd_initialize(&bkpts_info);
319
    cmd_initialize(&bkpts_info);
384
    if (!cmd_register(&bkpts_info))
320
    if (!cmd_register(&bkpts_info))
385
        panic("could not register command %s\n", bkpts_info.name);
321
        printf("Cannot register command %s\n", bkpts_info.name);
386
 
322
 
387
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
323
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
388
    cmd_initialize(&delbkpt_info);
324
    cmd_initialize(&delbkpt_info);
389
    if (!cmd_register(&delbkpt_info))
325
    if (!cmd_register(&delbkpt_info))
390
        panic("could not register command %s\n", delbkpt_info.name);
326
        printf("Cannot register command %s\n", delbkpt_info.name);
391
 
327
 
392
    cmd_initialize(&addbkpt_info);
328
    cmd_initialize(&addbkpt_info);
393
    if (!cmd_register(&addbkpt_info))
329
    if (!cmd_register(&addbkpt_info))
394
        panic("could not register command %s\n", addbkpt_info.name);
330
        printf("Cannot register command %s\n", addbkpt_info.name);
395
 
331
 
396
    cmd_initialize(&addwatchp_info);
332
    cmd_initialize(&addwatchp_info);
397
    if (!cmd_register(&addwatchp_info))
333
    if (!cmd_register(&addwatchp_info))
398
        panic("could not register command %s\n", addwatchp_info.name);
334
        printf("Cannot register command %s\n", addwatchp_info.name);
-
 
335
#endif /* CONFIG_DEBUG_AS_WATCHPOINT */
399
#endif
336
#endif /* CONFIG_KCONSOLE */
400
   
337
   
401
    exc_register(VECTOR_DEBUG, "debugger", debug_exception);
338
    exc_register(VECTOR_DEBUG, "debugger", debug_exception);
402
#ifdef CONFIG_SMP
339
#ifdef CONFIG_SMP
403
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi);
340
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi);
404
#endif
341
#endif
405
}
342
}
406
 
343
 
-
 
344
#ifdef CONFIG_KCONSOLE
-
 
345
/** Print table of active breakpoints */
-
 
346
int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
-
 
347
{
-
 
348
    unsigned int i;
-
 
349
    char *symbol;
-
 
350
 
-
 
351
#ifdef __32_BITS__  
-
 
352
    printf("#  Count Address    In symbol\n");
-
 
353
    printf("-- ----- ---------- ---------\n");
-
 
354
#endif
-
 
355
 
-
 
356
#ifdef __64_BITS__
-
 
357
    printf("#  Count Address            In symbol\n");
-
 
358
    printf("-- ----- ------------------ ---------\n");
-
 
359
#endif
-
 
360
   
-
 
361
    for (i = 0; i < BKPOINTS_MAX; i++)
-
 
362
        if (breakpoints[i].address) {
-
 
363
            symbol = get_symtab_entry(breakpoints[i].address);
-
 
364
 
-
 
365
#ifdef __32_BITS__
-
 
366
            printf("%-2u %-5d %#10zx %s\n", i,
-
 
367
                breakpoints[i].counter, breakpoints[i].address,
-
 
368
                symbol);
-
 
369
#endif
-
 
370
 
-
 
371
#ifdef __64_BITS__
-
 
372
            printf("%-2u %-5d %#18zx %s\n", i,
-
 
373
                breakpoints[i].counter, breakpoints[i].address,
-
 
374
                symbol);
-
 
375
#endif
-
 
376
 
-
 
377
        }
-
 
378
    return 1;
-
 
379
}
-
 
380
 
-
 
381
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
-
 
382
 
-
 
383
/** Remove breakpoint from table */
-
 
384
int cmd_del_breakpoint(cmd_arg_t *argv)
-
 
385
{
-
 
386
    unative_t bpno = argv->intval;
-
 
387
    if (bpno > BKPOINTS_MAX) {
-
 
388
        printf("Invalid breakpoint number.\n");
-
 
389
        return 0;
-
 
390
    }
-
 
391
    breakpoint_del(argv->intval);
-
 
392
    return 1;
-
 
393
}
-
 
394
 
-
 
395
/** Add new breakpoint to table */
-
 
396
static int cmd_add_breakpoint(cmd_arg_t *argv)
-
 
397
{
-
 
398
    int flags;
-
 
399
    int id;
-
 
400
 
-
 
401
    if (argv == &add_argv) {
-
 
402
        flags = BKPOINT_INSTR;
-
 
403
    } else { /* addwatchp */
-
 
404
        flags = BKPOINT_WRITE;
-
 
405
    }
-
 
406
    printf("Adding breakpoint on address: %p\n", argv->intval);
-
 
407
    id = breakpoint_add((void *)argv->intval, flags, -1);
-
 
408
    if (id < 0)
-
 
409
        printf("Add breakpoint failed.\n");
-
 
410
    else
-
 
411
        printf("Added breakpoint %d.\n", id);
-
 
412
   
-
 
413
    return 1;
-
 
414
}
-
 
415
#endif /* CONFIG_DEBUG_AS_WATCHPOINT */
-
 
416
#endif /* CONFIG_KCONSOLE */
-
 
417
 
407
/** @}
418
/** @}
408
 */
419
 */
409
 
420