The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/ddb/db_break.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: db_break.c,v 1.18 2003/04/29 17:06:03 scw Exp $        */
    2 
    3 /*
    4  * Mach Operating System
    5  * Copyright (c) 1991,1990 Carnegie Mellon University
    6  * All Rights Reserved.
    7  *
    8  * Permission to use, copy, modify and distribute this software and its
    9  * documentation is hereby granted, provided that both the copyright
   10  * notice and this permission notice appear in all copies of the
   11  * software, derivative works or modified versions, and any portions
   12  * thereof, and that both notices appear in supporting documentation.
   13  *
   14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   16  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   17  *
   18  * Carnegie Mellon requests users of this software to return to
   19  *
   20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   21  *  School of Computer Science
   22  *  Carnegie Mellon University
   23  *  Pittsburgh PA 15213-3890
   24  *
   25  * any improvements or extensions that they make and grant Carnegie the
   26  * rights to redistribute these changes.
   27  *
   28  *      Author: David B. Golub, Carnegie Mellon University
   29  *      Date:   7/90
   30  */
   31 
   32 /*
   33  * Breakpoints.
   34  */
   35 
   36 #include <sys/cdefs.h>
   37 __KERNEL_RCSID(0, "$NetBSD: db_break.c,v 1.18 2003/04/29 17:06:03 scw Exp $");
   38 
   39 #include <sys/param.h>
   40 #include <sys/proc.h>
   41 
   42 #include <machine/db_machdep.h>         /* type definitions */
   43 
   44 #include <ddb/db_lex.h>
   45 #include <ddb/db_access.h>
   46 #include <ddb/db_sym.h>
   47 #include <ddb/db_break.h>
   48 #include <ddb/db_output.h>
   49 
   50 #define NBREAKPOINTS    100
   51 static struct db_breakpoint     db_break_table[NBREAKPOINTS];
   52 static db_breakpoint_t          db_next_free_breakpoint = &db_break_table[0];
   53 static db_breakpoint_t          db_free_breakpoints = 0;
   54 static db_breakpoint_t          db_breakpoint_list = 0;
   55 
   56 static db_breakpoint_t  db_breakpoint_alloc(void);
   57 static void             db_breakpoint_free(db_breakpoint_t);
   58 static void             db_delete_breakpoint(struct vm_map *, db_addr_t);
   59 static db_breakpoint_t  db_find_breakpoint(struct vm_map *, db_addr_t);
   60 static void             db_list_breakpoints(void);
   61 static void             db_set_breakpoint(struct vm_map *, db_addr_t, int);
   62 
   63 static db_breakpoint_t
   64 db_breakpoint_alloc(void)
   65 {
   66         db_breakpoint_t bkpt;
   67 
   68         if ((bkpt = db_free_breakpoints) != 0) {
   69                 db_free_breakpoints = bkpt->link;
   70                 return (bkpt);
   71         }
   72         if (db_next_free_breakpoint == &db_break_table[NBREAKPOINTS]) {
   73                 db_printf("All breakpoints used.\n");
   74                 return (0);
   75         }
   76         bkpt = db_next_free_breakpoint;
   77         db_next_free_breakpoint++;
   78 
   79         return (bkpt);
   80 }
   81 
   82 static void
   83 db_breakpoint_free(db_breakpoint_t bkpt)
   84 {
   85         bkpt->link = db_free_breakpoints;
   86         db_free_breakpoints = bkpt;
   87 }
   88 
   89 void
   90 db_set_breakpoint(struct vm_map *map, db_addr_t addr, int count)
   91 {
   92         db_breakpoint_t bkpt;
   93 
   94         if (db_find_breakpoint(map, addr)) {
   95                 db_printf("Already set.\n");
   96                 return;
   97         }
   98 
   99         bkpt = db_breakpoint_alloc();
  100         if (bkpt == 0) {
  101                 db_printf("Too many breakpoints.\n");
  102                 return;
  103         }
  104 
  105         bkpt->map = map;
  106         bkpt->address = BKPT_ADDR(addr);
  107         bkpt->flags = 0;
  108         bkpt->init_count = count;
  109         bkpt->count = count;
  110 
  111         bkpt->link = db_breakpoint_list;
  112         db_breakpoint_list = bkpt;
  113 }
  114 
  115 static void
  116 db_delete_breakpoint(struct vm_map *map, db_addr_t addr)
  117 {
  118         db_breakpoint_t bkpt;
  119         db_breakpoint_t *prev;
  120 
  121         for (prev = &db_breakpoint_list;
  122              (bkpt = *prev) != 0;
  123              prev = &bkpt->link) {
  124                 if (db_map_equal(bkpt->map, map) &&
  125                     (bkpt->address == BKPT_ADDR(addr))) {
  126                         *prev = bkpt->link;
  127                         break;
  128                 }
  129         }
  130         if (bkpt == 0) {
  131                 db_printf("Not set.\n");
  132                 return;
  133         }
  134 
  135         db_breakpoint_free(bkpt);
  136 }
  137 
  138 db_breakpoint_t
  139 db_find_breakpoint(struct vm_map *map, db_addr_t addr)
  140 {
  141         db_breakpoint_t bkpt;
  142 
  143         for (bkpt = db_breakpoint_list;
  144              bkpt != 0;
  145              bkpt = bkpt->link)
  146                 if (db_map_equal(bkpt->map, map) &&
  147                     (bkpt->address == BKPT_ADDR(addr)))
  148                         return (bkpt);
  149 
  150         return (0);
  151 }
  152 
  153 db_breakpoint_t
  154 db_find_breakpoint_here(db_addr_t addr)
  155 {
  156         return db_find_breakpoint(db_map_addr(addr), addr);
  157 }
  158 
  159 static boolean_t db_breakpoints_inserted = TRUE;
  160 
  161 void
  162 db_set_breakpoints(void)
  163 {
  164         db_breakpoint_t bkpt;
  165 
  166         if (!db_breakpoints_inserted) {
  167 
  168                 for (bkpt = db_breakpoint_list;
  169                      bkpt != 0;
  170                      bkpt = bkpt->link)
  171                         if (db_map_current(bkpt->map)) {
  172                                 bkpt->bkpt_inst = db_get_value(bkpt->address,
  173                                     BKPT_SIZE, FALSE);
  174                                 db_put_value(bkpt->address,
  175                                     BKPT_SIZE, BKPT_SET(bkpt->bkpt_inst));
  176                         }
  177                 db_breakpoints_inserted = TRUE;
  178         }
  179 }
  180 
  181 void
  182 db_clear_breakpoints(void)
  183 {
  184         db_breakpoint_t bkpt;
  185 
  186         if (db_breakpoints_inserted) {
  187 
  188                 for (bkpt = db_breakpoint_list;
  189                      bkpt != 0;
  190                      bkpt = bkpt->link)
  191                         if (db_map_current(bkpt->map))
  192                             db_put_value(bkpt->address, BKPT_SIZE,
  193                                 bkpt->bkpt_inst);
  194                 db_breakpoints_inserted = FALSE;
  195         }
  196 }
  197 
  198 /*
  199  * List breakpoints.
  200  */
  201 void
  202 db_list_breakpoints(void)
  203 {
  204         db_breakpoint_t bkpt;
  205 
  206         if (db_breakpoint_list == 0) {
  207                 db_printf("No breakpoints set\n");
  208                 return;
  209         }
  210 
  211         db_printf(" Map      Count    Address\n");
  212         for (bkpt = db_breakpoint_list;
  213              bkpt != 0;
  214              bkpt = bkpt->link) {
  215                 db_printf("%s%p %5d    ",
  216                     db_map_current(bkpt->map) ? "*" : " ",
  217                     bkpt->map, bkpt->init_count);
  218                 db_printsym(bkpt->address, DB_STGY_PROC, db_printf);
  219                 db_printf("\n");
  220         }
  221 }
  222 
  223 /* Delete breakpoint */
  224 /*ARGSUSED*/
  225 void
  226 db_delete_cmd(db_expr_t addr, int have_addr, db_expr_t count, char * modif)
  227 {
  228 
  229         db_delete_breakpoint(db_map_addr(addr), (db_addr_t)addr);
  230 }
  231 
  232 /* Set breakpoint with skip count */
  233 /*ARGSUSED*/
  234 void
  235 db_breakpoint_cmd(db_expr_t addr, int have_addr, db_expr_t count, char * modif)
  236 {
  237 
  238         if (count == -1)
  239                 count = 1;
  240 
  241         db_set_breakpoint(db_map_addr(addr), (db_addr_t)addr, count);
  242 }
  243 
  244 /* list breakpoints */
  245 /*ARGSUSED*/
  246 void
  247 db_listbreak_cmd(db_expr_t addr, int have_addr, db_expr_t count, char * modif)
  248 {
  249 
  250         db_list_breakpoints();
  251 }
  252 
  253 #include <uvm/uvm_extern.h>
  254 
  255 /*
  256  *      We want ddb to be usable before most of the kernel has been
  257  *      initialized.  In particular, current_thread() or kernel_map
  258  *      (or both) may be null.
  259  */
  260 
  261 boolean_t
  262 db_map_equal(struct vm_map *map1, struct vm_map *map2)
  263 {
  264 
  265         return ((map1 == map2) ||
  266                 ((map1 == NULL) && (map2 == kernel_map)) ||
  267                 ((map1 == kernel_map) && (map2 == NULL)));
  268 }
  269 
  270 boolean_t
  271 db_map_current(struct vm_map *map)
  272 {
  273 #if 0
  274         thread_t        thread;
  275 
  276         return ((map == NULL) ||
  277                 (map == kernel_map) ||
  278                 (((thread = current_thread()) != NULL) &&
  279                  (map == thread->task->map)));
  280 #else
  281 
  282         return (1);
  283 #endif
  284 }
  285 
  286 struct vm_map *
  287 db_map_addr(vaddr_t addr)
  288 {
  289 #if 0
  290         thread_t        thread;
  291 
  292         /*
  293          *      We want to return kernel_map for all
  294          *      non-user addresses, even when debugging
  295          *      kernel tasks with their own maps.
  296          */
  297 
  298         if ((VM_MIN_ADDRESS <= addr) && (addr < VM_MAX_ADDRESS) &&
  299             ((thread = current_thread()) != NULL))
  300                 return thread->task->map;
  301         else
  302 #endif
  303                 return kernel_map;
  304 }

Cache object: e3de21db992b8b5d8b4e240e111fea13


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.