Subversion Repositories HelenOS

Rev

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

Rev 4132 Rev 4137
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 <print.h>
38
#include <print.h>
39
#include <panic.h>
39
#include <panic.h>
40
#include <interrupt.h>
40
#include <interrupt.h>
41
#include <arch/asm.h>
41
#include <arch/asm.h>
42
#include <arch/cpu.h>
42
#include <arch/cpu.h>
43
#include <debug.h>
43
#include <debug.h>
44
#include <func.h>
44
#include <func.h>
45
#include <smp/ipi.h>
45
#include <smp/ipi.h>
46
 
-
 
47
#ifdef CONFIG_SYMTAB
-
 
48
#include <symtab.h>
46
#include <symtab.h>
49
#endif
-
 
50
 
47
 
51
typedef struct  {
48
typedef struct  {
52
    uintptr_t address;      /**< Breakpoint address */
49
    uintptr_t address;      /**< Breakpoint address */
53
    int flags;              /**< Flags regarding breakpoint */
50
    int flags;              /**< Flags regarding breakpoint */
54
    int counter;            /**< How many times the exception occured */
51
    int counter;            /**< How many times the exception occured */
55
} bpinfo_t;
52
} bpinfo_t;
56
 
53
 
57
static bpinfo_t breakpoints[BKPOINTS_MAX];
54
static bpinfo_t breakpoints[BKPOINTS_MAX];
58
SPINLOCK_INITIALIZE(bkpoint_lock);
55
SPINLOCK_INITIALIZE(bkpoint_lock);
59
 
56
 
60
#ifdef CONFIG_KCONSOLE
57
#ifdef CONFIG_KCONSOLE
61
 
58
 
62
static int cmd_print_breakpoints(cmd_arg_t *argv);
59
static int cmd_print_breakpoints(cmd_arg_t *argv);
63
static cmd_info_t bkpts_info = {
60
static cmd_info_t bkpts_info = {
64
    .name = "bkpts",
61
    .name = "bkpts",
65
    .description = "Print breakpoint table.",
62
    .description = "Print breakpoint table.",
66
    .func = cmd_print_breakpoints,
63
    .func = cmd_print_breakpoints,
67
    .argc = 0,
64
    .argc = 0,
68
};
65
};
69
 
66
 
70
static int cmd_del_breakpoint(cmd_arg_t *argv);
67
static int cmd_del_breakpoint(cmd_arg_t *argv);
71
static cmd_arg_t del_argv = {
68
static cmd_arg_t del_argv = {
72
    .type = ARG_TYPE_INT
69
    .type = ARG_TYPE_INT
73
};
70
};
74
static cmd_info_t delbkpt_info = {
71
static cmd_info_t delbkpt_info = {
75
    .name = "delbkpt",
72
    .name = "delbkpt",
76
    .description = "delbkpt <number> - Delete breakpoint.",
73
    .description = "delbkpt <number> - Delete breakpoint.",
77
    .func = cmd_del_breakpoint,
74
    .func = cmd_del_breakpoint,
78
    .argc = 1,
75
    .argc = 1,
79
    .argv = &del_argv
76
    .argv = &del_argv
80
};
77
};
81
 
78
 
82
static int cmd_add_breakpoint(cmd_arg_t *argv);
79
static int cmd_add_breakpoint(cmd_arg_t *argv);
83
static cmd_arg_t add_argv = {
80
static cmd_arg_t add_argv = {
84
    .type = ARG_TYPE_INT
81
    .type = ARG_TYPE_INT
85
};
82
};
86
static cmd_info_t addbkpt_info = {
83
static cmd_info_t addbkpt_info = {
87
    .name = "addbkpt",
84
    .name = "addbkpt",
88
    .description = "addbkpt <&symbol> - new breakpoint.",
85
    .description = "addbkpt <&symbol> - new breakpoint.",
89
    .func = cmd_add_breakpoint,
86
    .func = cmd_add_breakpoint,
90
    .argc = 1,
87
    .argc = 1,
91
    .argv = &add_argv
88
    .argv = &add_argv
92
};
89
};
93
 
90
 
94
static cmd_arg_t addw_argv = {
91
static cmd_arg_t addw_argv = {
95
    .type = ARG_TYPE_INT
92
    .type = ARG_TYPE_INT
96
};
93
};
97
static cmd_info_t addwatchp_info = {
94
static cmd_info_t addwatchp_info = {
98
    .name = "addwatchp",
95
    .name = "addwatchp",
99
    .description = "addbwatchp <&symbol> - new write watchpoint.",
96
    .description = "addbwatchp <&symbol> - new write watchpoint.",
100
    .func = cmd_add_breakpoint,
97
    .func = cmd_add_breakpoint,
101
    .argc = 1,
98
    .argc = 1,
102
    .argv = &addw_argv
99
    .argv = &addw_argv
103
};
100
};
104
 
101
 
105
#endif /* CONFIG_KCONSOLE */
102
#endif /* CONFIG_KCONSOLE */
106
 
103
 
107
/* Setup DR register according to table */
104
/* Setup DR register according to table */
108
static void setup_dr(int curidx)
105
static void setup_dr(int curidx)
109
{
106
{
110
    unative_t dr7;
107
    unative_t dr7;
111
    bpinfo_t *cur = &breakpoints[curidx];
108
    bpinfo_t *cur = &breakpoints[curidx];
112
    int flags = breakpoints[curidx].flags;
109
    int flags = breakpoints[curidx].flags;
113
 
110
 
114
    /* Disable breakpoint in DR7 */
111
    /* Disable breakpoint in DR7 */
115
    dr7 = read_dr7();
112
    dr7 = read_dr7();
116
    dr7 &= ~(0x2 << (curidx*2));
113
    dr7 &= ~(0x2 << (curidx*2));
117
 
114
 
118
    if (cur->address) { /* Setup DR register */
115
    if (cur->address) { /* Setup DR register */
119
        /* Set breakpoint to debug registers */
116
        /* Set breakpoint to debug registers */
120
        switch (curidx) {
117
        switch (curidx) {
121
        case 0:
118
        case 0:
122
            write_dr0(cur->address);
119
            write_dr0(cur->address);
123
            break;
120
            break;
124
        case 1:
121
        case 1:
125
            write_dr1(cur->address);
122
            write_dr1(cur->address);
126
            break;
123
            break;
127
        case 2:
124
        case 2:
128
            write_dr2(cur->address);
125
            write_dr2(cur->address);
129
            break;
126
            break;
130
        case 3:
127
        case 3:
131
            write_dr3(cur->address);
128
            write_dr3(cur->address);
132
            break;
129
            break;
133
        }
130
        }
134
        /* Set type to requested breakpoint & length*/
131
        /* Set type to requested breakpoint & length*/
135
        dr7 &= ~ (0x3 << (16 + 4*curidx));
132
        dr7 &= ~ (0x3 << (16 + 4*curidx));
136
        dr7 &= ~ (0x3 << (18 + 4*curidx));
133
        dr7 &= ~ (0x3 << (18 + 4*curidx));
137
        if ((flags & BKPOINT_INSTR)) {
134
        if ((flags & BKPOINT_INSTR)) {
138
            ;
135
            ;
139
        } else {
136
        } else {
140
       
137
       
141
#ifdef __32_BITS__
138
#ifdef __32_BITS__
142
            dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx);
139
            dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx);
143
#endif
140
#endif
144
 
141
 
145
#ifdef __64_BITS__
142
#ifdef __64_BITS__
146
            dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx);
143
            dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx);
147
#endif
144
#endif
148
           
145
           
149
            if ((flags & BKPOINT_WRITE))
146
            if ((flags & BKPOINT_WRITE))
150
                dr7 |= ((unative_t) 0x1) << (16 + 4 * curidx);
147
                dr7 |= ((unative_t) 0x1) << (16 + 4 * curidx);
151
            else if ((flags & BKPOINT_READ_WRITE))
148
            else if ((flags & BKPOINT_READ_WRITE))
152
                dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx);
149
                dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx);
153
        }
150
        }
154
 
151
 
155
        /* Enable global breakpoint */
152
        /* Enable global breakpoint */
156
        dr7 |= 0x2 << (curidx * 2);
153
        dr7 |= 0x2 << (curidx * 2);
157
 
154
 
158
        write_dr7(dr7);
155
        write_dr7(dr7);
159
       
156
       
160
    }
157
    }
161
}
158
}
162
   
159
   
163
/** Enable hardware breakpoint
160
/** Enable hardware breakpoint
164
 *
161
 *
165
 * @param where Address of HW breakpoint
162
 * @param where Address of HW breakpoint
166
 * @param flags Type of breakpoint (EXECUTE, WRITE)
163
 * @param flags Type of breakpoint (EXECUTE, WRITE)
167
 * @return Debug slot on success, -1 - no available HW breakpoint
164
 * @return Debug slot on success, -1 - no available HW breakpoint
168
 */
165
 */
169
int breakpoint_add(const void *where, const int flags, int curidx)
166
int breakpoint_add(const void *where, const int flags, int curidx)
170
{
167
{
171
    ipl_t ipl;
168
    ipl_t ipl;
172
    int i;
169
    int i;
173
    bpinfo_t *cur;
170
    bpinfo_t *cur;
174
 
171
 
175
    ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
172
    ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
176
 
173
 
177
    ipl = interrupts_disable();
174
    ipl = interrupts_disable();
178
    spinlock_lock(&bkpoint_lock);
175
    spinlock_lock(&bkpoint_lock);
179
   
176
   
180
    if (curidx == -1) {
177
    if (curidx == -1) {
181
        /* Find free space in slots */
178
        /* Find free space in slots */
182
        for (i = 0; i < BKPOINTS_MAX; i++)
179
        for (i = 0; i < BKPOINTS_MAX; i++)
183
            if (!breakpoints[i].address) {
180
            if (!breakpoints[i].address) {
184
                curidx = i;
181
                curidx = i;
185
                break;
182
                break;
186
            }
183
            }
187
        if (curidx == -1) {
184
        if (curidx == -1) {
188
            /* Too many breakpoints */
185
            /* Too many breakpoints */
189
            spinlock_unlock(&bkpoint_lock);
186
            spinlock_unlock(&bkpoint_lock);
190
            interrupts_restore(ipl);
187
            interrupts_restore(ipl);
191
            return -1;
188
            return -1;
192
        }
189
        }
193
    }
190
    }
194
    cur = &breakpoints[curidx];
191
    cur = &breakpoints[curidx];
195
 
192
 
196
    cur->address = (uintptr_t) where;
193
    cur->address = (uintptr_t) where;
197
    cur->flags = flags;
194
    cur->flags = flags;
198
    cur->counter = 0;
195
    cur->counter = 0;
199
 
196
 
200
    setup_dr(curidx);
197
    setup_dr(curidx);
201
 
198
 
202
    spinlock_unlock(&bkpoint_lock);
199
    spinlock_unlock(&bkpoint_lock);
203
    interrupts_restore(ipl);
200
    interrupts_restore(ipl);
204
 
201
 
205
    /* Send IPI */
202
    /* Send IPI */
206
#ifdef CONFIG_SMP
203
#ifdef CONFIG_SMP
207
//  ipi_broadcast(VECTOR_DEBUG_IPI);
204
//  ipi_broadcast(VECTOR_DEBUG_IPI);
208
#endif  
205
#endif  
209
 
206
 
210
    return curidx;
207
    return curidx;
211
}
208
}
212
 
209
 
213
#ifdef __64_BITS__
210
#ifdef __64_BITS__
214
    #define getip(x)  ((x)->rip)
211
    #define getip(x)  ((x)->rip)
215
#else
212
#else
216
    #define getip(x)  ((x)->eip)
213
    #define getip(x)  ((x)->eip)
217
#endif
214
#endif
218
 
215
 
219
static void handle_exception(int slot, istate_t *istate)
216
static void handle_exception(int slot, istate_t *istate)
220
{
217
{
221
    ASSERT(breakpoints[slot].address);
218
    ASSERT(breakpoints[slot].address);
222
 
219
 
223
    /* Handle zero checker */
220
    /* Handle zero checker */
224
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
221
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
225
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
222
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
226
            if (*((unative_t *) breakpoints[slot].address) != 0)
223
            if (*((unative_t *) breakpoints[slot].address) != 0)
227
                return;
224
                return;
228
            printf("*** Found ZERO on address %lx (slot %d) ***\n",
225
            printf("*** Found ZERO on address %lx (slot %d) ***\n",
229
                breakpoints[slot].address, slot);
226
                breakpoints[slot].address, slot);
230
        } else {
227
        } else {
231
            printf("Data watchpoint - new data: %lx\n",
228
            printf("Data watchpoint - new data: %lx\n",
232
                *((unative_t *) breakpoints[slot].address));
229
                *((unative_t *) breakpoints[slot].address));
233
        }
230
        }
234
    }
231
    }
235
 
232
 
236
#ifdef CONFIG_SYMTAB
-
 
237
    printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate),
233
    printf("Reached breakpoint %d:%lx (%s)\n", slot, getip(istate),
238
        get_symtab_entry(getip(istate)));
234
        symtab_fmt_name_lookup(getip(istate)));
239
#else
-
 
240
    printf("Reached breakpoint %d:%lx\n", slot, getip(istate));
-
 
241
#endif
-
 
242
 
235
 
243
#ifdef CONFIG_KCONSOLE
236
#ifdef CONFIG_KCONSOLE
244
    atomic_set(&haltstate, 1);
237
    atomic_set(&haltstate, 1);
245
    kconsole("debug", "Debug console ready.\n", false);
238
    kconsole("debug", "Debug console ready.\n", false);
246
    atomic_set(&haltstate, 0);
239
    atomic_set(&haltstate, 0);
247
#endif
240
#endif
248
}
241
}
249
 
242
 
250
void breakpoint_del(int slot)
243
void breakpoint_del(int slot)
251
{
244
{
252
    bpinfo_t *cur;
245
    bpinfo_t *cur;
253
    ipl_t ipl;
246
    ipl_t ipl;
254
 
247
 
255
    ipl = interrupts_disable();
248
    ipl = interrupts_disable();
256
    spinlock_lock(&bkpoint_lock);
249
    spinlock_lock(&bkpoint_lock);
257
 
250
 
258
    cur = &breakpoints[slot];
251
    cur = &breakpoints[slot];
259
    if (!cur->address) {
252
    if (!cur->address) {
260
        spinlock_unlock(&bkpoint_lock);
253
        spinlock_unlock(&bkpoint_lock);
261
        interrupts_restore(ipl);
254
        interrupts_restore(ipl);
262
        return;
255
        return;
263
    }
256
    }
264
 
257
 
265
    cur->address = NULL;
258
    cur->address = NULL;
266
 
259
 
267
    setup_dr(slot);
260
    setup_dr(slot);
268
 
261
 
269
    spinlock_unlock(&bkpoint_lock);
262
    spinlock_unlock(&bkpoint_lock);
270
    interrupts_restore(ipl);
263
    interrupts_restore(ipl);
271
#ifdef CONFIG_SMP
264
#ifdef CONFIG_SMP
272
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
265
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
273
#endif
266
#endif
274
}
267
}
275
 
268
 
276
 
269
 
277
 
270
 
278
static void debug_exception(int n __attribute__((unused)), istate_t *istate)
271
static void debug_exception(int n __attribute__((unused)), istate_t *istate)
279
{
272
{
280
    unative_t dr6;
273
    unative_t dr6;
281
    int i;
274
    int i;
282
   
275
   
283
    /* Set RF to restart the instruction  */
276
    /* Set RF to restart the instruction  */
284
#ifdef __64_BITS__
277
#ifdef __64_BITS__
285
    istate->rflags |= RFLAGS_RF;
278
    istate->rflags |= RFLAGS_RF;
286
#else
279
#else
287
    istate->eflags |= EFLAGS_RF;
280
    istate->eflags |= EFLAGS_RF;
288
#endif
281
#endif
289
 
282
 
290
    dr6 = read_dr6();
283
    dr6 = read_dr6();
291
    for (i=0; i < BKPOINTS_MAX; i++) {
284
    for (i=0; i < BKPOINTS_MAX; i++) {
292
        if (dr6 & (1 << i)) {
285
        if (dr6 & (1 << i)) {
293
            dr6 &= ~ (1 << i);
286
            dr6 &= ~ (1 << i);
294
            write_dr6(dr6);
287
            write_dr6(dr6);
295
           
288
           
296
            handle_exception(i, istate);
289
            handle_exception(i, istate);
297
        }
290
        }
298
    }
291
    }
299
}
292
}
300
 
293
 
301
#ifdef CONFIG_SMP
294
#ifdef CONFIG_SMP
302
static void
295
static void
303
debug_ipi(int n __attribute__((unused)),
296
debug_ipi(int n __attribute__((unused)),
304
    istate_t *istate __attribute__((unused)))
297
    istate_t *istate __attribute__((unused)))
305
{
298
{
306
    int i;
299
    int i;
307
 
300
 
308
    spinlock_lock(&bkpoint_lock);
301
    spinlock_lock(&bkpoint_lock);
309
    for (i = 0; i < BKPOINTS_MAX; i++)
302
    for (i = 0; i < BKPOINTS_MAX; i++)
310
        setup_dr(i);
303
        setup_dr(i);
311
    spinlock_unlock(&bkpoint_lock);
304
    spinlock_unlock(&bkpoint_lock);
312
}
305
}
313
#endif
306
#endif
314
 
307
 
315
/** Initialize debugger */
308
/** Initialize debugger */
316
void debugger_init()
309
void debugger_init()
317
{
310
{
318
    int i;
311
    int i;
319
 
312
 
320
    for (i = 0; i < BKPOINTS_MAX; i++)
313
    for (i = 0; i < BKPOINTS_MAX; i++)
321
        breakpoints[i].address = NULL;
314
        breakpoints[i].address = NULL;
322
 
315
 
323
#ifdef CONFIG_KCONSOLE
316
#ifdef CONFIG_KCONSOLE
324
    cmd_initialize(&bkpts_info);
317
    cmd_initialize(&bkpts_info);
325
    if (!cmd_register(&bkpts_info))
318
    if (!cmd_register(&bkpts_info))
326
        printf("Cannot register command %s\n", bkpts_info.name);
319
        printf("Cannot register command %s\n", bkpts_info.name);
327
 
320
 
328
    cmd_initialize(&delbkpt_info);
321
    cmd_initialize(&delbkpt_info);
329
    if (!cmd_register(&delbkpt_info))
322
    if (!cmd_register(&delbkpt_info))
330
        printf("Cannot register command %s\n", delbkpt_info.name);
323
        printf("Cannot register command %s\n", delbkpt_info.name);
331
 
324
 
332
    cmd_initialize(&addbkpt_info);
325
    cmd_initialize(&addbkpt_info);
333
    if (!cmd_register(&addbkpt_info))
326
    if (!cmd_register(&addbkpt_info))
334
        printf("Cannot register command %s\n", addbkpt_info.name);
327
        printf("Cannot register command %s\n", addbkpt_info.name);
335
 
328
 
336
    cmd_initialize(&addwatchp_info);
329
    cmd_initialize(&addwatchp_info);
337
    if (!cmd_register(&addwatchp_info))
330
    if (!cmd_register(&addwatchp_info))
338
        printf("Cannot register command %s\n", addwatchp_info.name);
331
        printf("Cannot register command %s\n", addwatchp_info.name);
339
#endif /* CONFIG_KCONSOLE */
332
#endif /* CONFIG_KCONSOLE */
340
   
333
   
341
    exc_register(VECTOR_DEBUG, "debugger", debug_exception);
334
    exc_register(VECTOR_DEBUG, "debugger", debug_exception);
342
#ifdef CONFIG_SMP
335
#ifdef CONFIG_SMP
343
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi);
336
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi);
344
#endif
337
#endif
345
}
338
}
346
 
339
 
347
#ifdef CONFIG_KCONSOLE
340
#ifdef CONFIG_KCONSOLE
348
/** Print table of active breakpoints */
341
/** Print table of active breakpoints */
349
int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
342
int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
350
{
343
{
351
    unsigned int i;
344
    unsigned int i;
352
    char *symbol;
345
    char *symbol;
353
 
346
 
354
#ifdef __32_BITS__
347
#ifdef __32_BITS__
355
    printf("#  Count Address    In symbol\n");
348
    printf("#  Count Address    In symbol\n");
356
    printf("-- ----- ---------- ---------\n");
349
    printf("-- ----- ---------- ---------\n");
357
#endif
350
#endif
358
 
351
 
359
#ifdef __64_BITS__
352
#ifdef __64_BITS__
360
    printf("#  Count Address            In symbol\n");
353
    printf("#  Count Address            In symbol\n");
361
    printf("-- ----- ------------------ ---------\n");
354
    printf("-- ----- ------------------ ---------\n");
362
#endif
355
#endif
363
   
356
   
364
    for (i = 0; i < BKPOINTS_MAX; i++)
357
    for (i = 0; i < BKPOINTS_MAX; i++)
365
        if (breakpoints[i].address) {
358
        if (breakpoints[i].address) {
366
#ifdef CONFIG_SYMTAB
-
 
367
            symbol = get_symtab_entry(breakpoints[i].address);
359
            symbol = symtab_fmt_name_lookup(
368
#else
-
 
369
            symbol = "n/a";
360
                breakpoints[i].address);
370
#endif
-
 
371
 
361
 
372
#ifdef __32_BITS__
362
#ifdef __32_BITS__
373
            printf("%-2u %-5d %#10zx %s\n", i,
363
            printf("%-2u %-5d %#10zx %s\n", i,
374
                breakpoints[i].counter, breakpoints[i].address,
364
                breakpoints[i].counter, breakpoints[i].address,
375
                symbol);
365
                symbol);
376
#endif
366
#endif
377
 
367
 
378
#ifdef __64_BITS__
368
#ifdef __64_BITS__
379
            printf("%-2u %-5d %#18zx %s\n", i,
369
            printf("%-2u %-5d %#18zx %s\n", i,
380
                breakpoints[i].counter, breakpoints[i].address,
370
                breakpoints[i].counter, breakpoints[i].address,
381
                symbol);
371
                symbol);
382
#endif
372
#endif
383
 
373
 
384
        }
374
        }
385
    return 1;
375
    return 1;
386
}
376
}
387
 
377
 
388
/** Remove breakpoint from table */
378
/** Remove breakpoint from table */
389
int cmd_del_breakpoint(cmd_arg_t *argv)
379
int cmd_del_breakpoint(cmd_arg_t *argv)
390
{
380
{
391
    unative_t bpno = argv->intval;
381
    unative_t bpno = argv->intval;
392
    if (bpno > BKPOINTS_MAX) {
382
    if (bpno > BKPOINTS_MAX) {
393
        printf("Invalid breakpoint number.\n");
383
        printf("Invalid breakpoint number.\n");
394
        return 0;
384
        return 0;
395
    }
385
    }
396
    breakpoint_del(argv->intval);
386
    breakpoint_del(argv->intval);
397
    return 1;
387
    return 1;
398
}
388
}
399
 
389
 
400
/** Add new breakpoint to table */
390
/** Add new breakpoint to table */
401
static int cmd_add_breakpoint(cmd_arg_t *argv)
391
static int cmd_add_breakpoint(cmd_arg_t *argv)
402
{
392
{
403
    int flags;
393
    int flags;
404
    int id;
394
    int id;
405
 
395
 
406
    if (argv == &add_argv) {
396
    if (argv == &add_argv) {
407
        flags = BKPOINT_INSTR;
397
        flags = BKPOINT_INSTR;
408
    } else { /* addwatchp */
398
    } else { /* addwatchp */
409
        flags = BKPOINT_WRITE;
399
        flags = BKPOINT_WRITE;
410
    }
400
    }
411
    printf("Adding breakpoint on address: %p\n", argv->intval);
401
    printf("Adding breakpoint on address: %p\n", argv->intval);
412
    id = breakpoint_add((void *)argv->intval, flags, -1);
402
    id = breakpoint_add((void *)argv->intval, flags, -1);
413
    if (id < 0)
403
    if (id < 0)
414
        printf("Add breakpoint failed.\n");
404
        printf("Add breakpoint failed.\n");
415
    else
405
    else
416
        printf("Added breakpoint %d.\n", id);
406
        printf("Added breakpoint %d.\n", id);
417
   
407
   
418
    return 1;
408
    return 1;
419
}
409
}
420
#endif /* CONFIG_KCONSOLE */
410
#endif /* CONFIG_KCONSOLE */
421
 
411
 
422
/** @}
412
/** @}
423
 */
413
 */
424
 
414