Subversion Repositories HelenOS

Rev

Rev 3022 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4055
Line 52... Line 52...
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
-
 
66
 
-
 
67
static int cmd_del_breakpoint(cmd_arg_t *argv);
67
static int cmd_del_breakpoint(cmd_arg_t *argv);
68
static cmd_arg_t del_argv = {
68
static cmd_arg_t del_argv = {
69
    .type = ARG_TYPE_INT
69
    .type = ARG_TYPE_INT
70
};
70
};
71
static cmd_info_t delbkpt_info = {
71
static cmd_info_t delbkpt_info = {
Line 97... Line 97...
97
    .func = cmd_add_breakpoint,
97
    .func = cmd_add_breakpoint,
98
    .argc = 1,
98
    .argc = 1,
99
    .argv = &addw_argv
99
    .argv = &addw_argv
100
};
100
};
101
 
101
 
102
#endif
-
 
103
 
-
 
104
/** Print table of active breakpoints */
-
 
105
int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
-
 
106
{
-
 
107
    unsigned int i;
-
 
108
    char *symbol;
-
 
109
   
-
 
110
    if (sizeof(void *) == 4) {
-
 
111
        printf("#  Count Address    In symbol\n");
-
 
112
        printf("-- ----- ---------- ---------\n");
-
 
113
    } else {
-
 
114
        printf("#  Count Address            In symbol\n");
-
 
115
        printf("-- ----- ------------------ ---------\n");
-
 
116
    }
-
 
117
   
-
 
118
    for (i = 0; i < BKPOINTS_MAX; i++)
-
 
119
        if (breakpoints[i].address) {
-
 
120
            symbol = get_symtab_entry(breakpoints[i].address);
-
 
121
           
-
 
122
            if (sizeof(void *) == 4)
102
#endif /* CONFIG_KCONSOLE */
123
                printf("%-2u %-5d %#10zx %s\n", i, breakpoints[i].counter,
-
 
124
                    breakpoints[i].address, symbol);
-
 
125
            else
-
 
126
                printf("%-2u %-5d %#18zx %s\n", i, breakpoints[i].counter,
-
 
127
                    breakpoints[i].address, symbol);
-
 
128
        }
-
 
129
    return 1;
-
 
130
}
-
 
131
 
103
 
132
/* Setup DR register according to table */
104
/* Setup DR register according to table */
133
static void setup_dr(int curidx)
105
static void setup_dr(int curidx)
134
{
106
{
135
    unative_t dr7;
107
    unative_t dr7;
Line 160... Line 132...
160
        dr7 &= ~ (0x3 << (16 + 4*curidx));
132
        dr7 &= ~ (0x3 << (16 + 4*curidx));
161
        dr7 &= ~ (0x3 << (18 + 4*curidx));
133
        dr7 &= ~ (0x3 << (18 + 4*curidx));
162
        if ((flags & BKPOINT_INSTR)) {
134
        if ((flags & BKPOINT_INSTR)) {
163
            ;
135
            ;
164
        } else {
136
        } else {
-
 
137
       
165
            if (sizeof(int) == 4)
138
#ifdef __32_BITS__
166
                dr7 |= ((unative_t) 0x3) << (18 + 4*curidx);
139
            dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx);
-
 
140
#endif
-
 
141
 
167
            else /* 8 */
142
#ifdef __64_BITS__
168
                dr7 |= ((unative_t) 0x2) << (18 + 4*curidx);
143
            dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx);
-
 
144
#endif
169
           
145
           
170
            if ((flags & BKPOINT_WRITE))
146
            if ((flags & BKPOINT_WRITE))
171
                dr7 |= ((unative_t) 0x1) << (16 + 4*curidx);
147
                dr7 |= ((unative_t) 0x1) << (16 + 4 * curidx);
172
            else if ((flags & BKPOINT_READ_WRITE))
148
            else if ((flags & BKPOINT_READ_WRITE))
173
                dr7 |= ((unative_t) 0x3) << (16 + 4*curidx);
149
                dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx);
174
        }
150
        }
175
 
151
 
176
        /* Enable global breakpoint */
152
        /* Enable global breakpoint */
177
        dr7 |= 0x2 << (curidx*2);
153
        dr7 |= 0x2 << (curidx * 2);
178
 
154
 
179
        write_dr7(dr7);
155
        write_dr7(dr7);
180
       
156
       
181
    }
157
    }
182
}
158
}
Line 223... Line 199...
223
    spinlock_unlock(&bkpoint_lock);
199
    spinlock_unlock(&bkpoint_lock);
224
    interrupts_restore(ipl);
200
    interrupts_restore(ipl);
225
 
201
 
226
    /* Send IPI */
202
    /* Send IPI */
227
#ifdef CONFIG_SMP
203
#ifdef CONFIG_SMP
228
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
204
//  ipi_broadcast(VECTOR_DEBUG_IPI);
229
#endif  
205
#endif  
230
 
206
 
231
    return curidx;
207
    return curidx;
232
}
208
}
233
 
209
 
234
#ifdef amd64
210
#ifdef __64_BITS__
235
#   define getip(x) ((x)->rip)
211
    #define getip(x)  ((x)->rip)
236
#else
212
#else
237
#   define getip(x) ((x)->eip)
213
    #define getip(x)  ((x)->eip)
238
#endif
214
#endif
239
 
215
 
240
static void handle_exception(int slot, istate_t *istate)
216
static void handle_exception(int slot, istate_t *istate)
241
{
217
{
242
    ASSERT(breakpoints[slot].address);
218
    ASSERT(breakpoints[slot].address);
Line 244... Line 220...
244
    /* Handle zero checker */
220
    /* Handle zero checker */
245
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
221
    if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
246
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
222
        if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
247
            if (*((unative_t *) breakpoints[slot].address) != 0)
223
            if (*((unative_t *) breakpoints[slot].address) != 0)
248
                return;
224
                return;
249
            printf("**** Found ZERO on address %lx (slot %d) ****\n",
225
            printf("*** Found ZERO on address %lx (slot %d) ***\n",
250
                breakpoints[slot].address, slot);
226
                breakpoints[slot].address, slot);
251
        } else {
227
        } else {
252
            printf("Data watchpoint - new data: %lx\n",
228
            printf("Data watchpoint - new data: %lx\n",
253
                   *((unative_t *) breakpoints[slot].address));
229
                *((unative_t *) breakpoints[slot].address));
254
        }
230
        }
255
    }
231
    }
256
    printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate),
232
    printf("Reached breakpoint %d:%lx(%s)\n", slot, getip(istate),
257
           get_symtab_entry(getip(istate)));
233
        get_symtab_entry(getip(istate)));
-
 
234
 
258
    printf("***Type 'exit' to exit kconsole.\n");
235
#ifdef CONFIG_KCONSOLE
259
    atomic_set(&haltstate,1);
236
    atomic_set(&haltstate, 1);
260
    kconsole((void *) "debug");
237
    kconsole("debug", "Debug console ready (type 'exit' to continue)\n", false);
261
    atomic_set(&haltstate,0);
238
    atomic_set(&haltstate, 0);
-
 
239
#endif
262
}
240
}
263
 
241
 
264
void breakpoint_del(int slot)
242
void breakpoint_del(int slot)
265
{
243
{
266
    bpinfo_t *cur;
244
    bpinfo_t *cur;
Line 285... Line 263...
285
#ifdef CONFIG_SMP
263
#ifdef CONFIG_SMP
286
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
264
//  ipi_broadcast(VECTOR_DEBUG_IPI);    
287
#endif
265
#endif
288
}
266
}
289
 
267
 
290
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
-
 
291
 
268
 
292
/** Remove breakpoint from table */
-
 
293
int cmd_del_breakpoint(cmd_arg_t *argv)
-
 
294
{
-
 
295
    unative_t bpno = argv->intval;
-
 
296
    if (bpno > BKPOINTS_MAX) {
-
 
297
        printf("Invalid breakpoint number.\n");
-
 
298
        return 0;
-
 
299
    }
-
 
300
    breakpoint_del(argv->intval);
-
 
301
    return 1;
-
 
302
}
-
 
303
 
-
 
304
/** Add new breakpoint to table */
-
 
305
static int cmd_add_breakpoint(cmd_arg_t *argv)
-
 
306
{
-
 
307
    int flags;
-
 
308
    int id;
-
 
309
 
-
 
310
    if (argv == &add_argv) {
-
 
311
        flags = BKPOINT_INSTR;
-
 
312
    } else { /* addwatchp */
-
 
313
        flags = BKPOINT_WRITE;
-
 
314
    }
-
 
315
    printf("Adding breakpoint on address: %p\n", argv->intval);
-
 
316
    id = breakpoint_add((void *)argv->intval, flags, -1);
-
 
317
    if (id < 0)
-
 
318
        printf("Add breakpoint failed.\n");
-
 
319
    else
-
 
320
        printf("Added breakpoint %d.\n", id);
-
 
321
   
-
 
322
    return 1;
-
 
323
}
-
 
324
#endif
-
 
325
 
269
 
326
static void debug_exception(int n __attribute__((unused)), istate_t *istate)
270
static void debug_exception(int n __attribute__((unused)), istate_t *istate)
327
{
271
{
328
    unative_t dr6;
272
    unative_t dr6;
329
    int i;
273
    int i;
330
   
274
   
331
    /* Set RF to restart the instruction  */
275
    /* Set RF to restart the instruction  */
332
#ifdef amd64       
276
#ifdef __64_BITS__
333
    istate->rflags |= RFLAGS_RF;
277
    istate->rflags |= RFLAGS_RF;
334
#else
278
#else
335
    istate->eflags |= EFLAGS_RF;
279
    istate->eflags |= EFLAGS_RF;
336
#endif
280
#endif
337
 
281
 
Line 345... Line 289...
345
        }
289
        }
346
    }
290
    }
347
}
291
}
348
 
292
 
349
#ifdef CONFIG_SMP
293
#ifdef CONFIG_SMP
-
 
294
static void
-
 
295
debug_ipi(int n __attribute__((unused)),
350
static void debug_ipi(int n __attribute__((unused)), istate_t *istate __attribute__((unused)))
296
    istate_t *istate __attribute__((unused)))
351
{
297
{
352
    int i;
298
    int i;
353
 
299
 
354
    spinlock_lock(&bkpoint_lock);
300
    spinlock_lock(&bkpoint_lock);
355
    for (i = 0; i < BKPOINTS_MAX; i++)
301
    for (i = 0; i < BKPOINTS_MAX; i++)
Line 361... Line 307...
361
/** Initialize debugger */
307
/** Initialize debugger */
362
void debugger_init()
308
void debugger_init()
363
{
309
{
364
    int i;
310
    int i;
365
 
311
 
366
    for (i=0; i<BKPOINTS_MAX; i++)
312
    for (i = 0; i < BKPOINTS_MAX; i++)
367
        breakpoints[i].address = NULL;
313
        breakpoints[i].address = NULL;
368
   
314
 
-
 
315
#ifdef CONFIG_KCONSOLE
369
    cmd_initialize(&bkpts_info);
316
    cmd_initialize(&bkpts_info);
370
    if (!cmd_register(&bkpts_info))
317
    if (!cmd_register(&bkpts_info))
371
        panic("could not register command %s\n", bkpts_info.name);
318
        printf("Cannot register command %s\n", bkpts_info.name);
372
 
319
 
373
#ifndef CONFIG_DEBUG_AS_WATCHPOINT
-
 
374
    cmd_initialize(&delbkpt_info);
320
    cmd_initialize(&delbkpt_info);
375
    if (!cmd_register(&delbkpt_info))
321
    if (!cmd_register(&delbkpt_info))
376
        panic("could not register command %s\n", delbkpt_info.name);
322
        printf("Cannot register command %s\n", delbkpt_info.name);
377
 
323
 
378
    cmd_initialize(&addbkpt_info);
324
    cmd_initialize(&addbkpt_info);
379
    if (!cmd_register(&addbkpt_info))
325
    if (!cmd_register(&addbkpt_info))
380
        panic("could not register command %s\n", addbkpt_info.name);
326
        printf("Cannot register command %s\n", addbkpt_info.name);
381
 
327
 
382
    cmd_initialize(&addwatchp_info);
328
    cmd_initialize(&addwatchp_info);
383
    if (!cmd_register(&addwatchp_info))
329
    if (!cmd_register(&addwatchp_info))
384
        panic("could not register command %s\n", addwatchp_info.name);
330
        printf("Cannot register command %s\n", addwatchp_info.name);
385
#endif
331
#endif /* CONFIG_KCONSOLE */
386
   
332
   
387
    exc_register(VECTOR_DEBUG, "debugger",
333
    exc_register(VECTOR_DEBUG, "debugger", debug_exception);
388
             debug_exception);
-
 
389
#ifdef CONFIG_SMP
334
#ifdef CONFIG_SMP
390
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp",
335
    exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi);
-
 
336
#endif
-
 
337
}
-
 
338
 
-
 
339
#ifdef CONFIG_KCONSOLE
-
 
340
/** Print table of active breakpoints */
-
 
341
int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
-
 
342
{
391
             debug_ipi);
343
    unsigned int i;
-
 
344
    char *symbol;
-
 
345
 
-
 
346
#ifdef __32_BITS__
-
 
347
    printf("#  Count Address    In symbol\n");
-
 
348
    printf("-- ----- ---------- ---------\n");
-
 
349
#endif
-
 
350
 
-
 
351
#ifdef __64_BITS__
-
 
352
    printf("#  Count Address            In symbol\n");
-
 
353
    printf("-- ----- ------------------ ---------\n");
392
#endif
354
#endif
-
 
355
   
-
 
356
    for (i = 0; i < BKPOINTS_MAX; i++)
-
 
357
        if (breakpoints[i].address) {
-
 
358
            symbol = get_symtab_entry(breakpoints[i].address);
-
 
359
 
-
 
360
#ifdef __32_BITS__
-
 
361
            printf("%-2u %-5d %#10zx %s\n", i,
-
 
362
                breakpoints[i].counter, breakpoints[i].address,
-
 
363
                symbol);
-
 
364
#endif
-
 
365
 
-
 
366
#ifdef __64_BITS__
-
 
367
            printf("%-2u %-5d %#18zx %s\n", i,
-
 
368
                breakpoints[i].counter, breakpoints[i].address,
-
 
369
                symbol);
-
 
370
#endif
-
 
371
 
-
 
372
        }
-
 
373
    return 1;
-
 
374
}
-
 
375
 
-
 
376
/** Remove breakpoint from table */
-
 
377
int cmd_del_breakpoint(cmd_arg_t *argv)
-
 
378
{
-
 
379
    unative_t bpno = argv->intval;
-
 
380
    if (bpno > BKPOINTS_MAX) {
-
 
381
        printf("Invalid breakpoint number.\n");
-
 
382
        return 0;
-
 
383
    }
-
 
384
    breakpoint_del(argv->intval);
-
 
385
    return 1;
-
 
386
}
-
 
387
 
-
 
388
/** Add new breakpoint to table */
-
 
389
static int cmd_add_breakpoint(cmd_arg_t *argv)
-
 
390
{
-
 
391
    int flags;
-
 
392
    int id;
-
 
393
 
-
 
394
    if (argv == &add_argv) {
-
 
395
        flags = BKPOINT_INSTR;
-
 
396
    } else { /* addwatchp */
-
 
397
        flags = BKPOINT_WRITE;
-
 
398
    }
-
 
399
    printf("Adding breakpoint on address: %p\n", argv->intval);
-
 
400
    id = breakpoint_add((void *)argv->intval, flags, -1);
-
 
401
    if (id < 0)
-
 
402
        printf("Add breakpoint failed.\n");
-
 
403
    else
-
 
404
        printf("Added breakpoint %d.\n", id);
-
 
405
   
-
 
406
    return 1;
393
}
407
}
-
 
408
#endif /* CONFIG_KCONSOLE */
394
 
409
 
395
/** @}
410
/** @}
396
 */
411
 */