Subversion Repositories HelenOS

Rev

Rev 4101 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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