db_trap.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* $OpenBSD: db_trap.c,v 1.19 2015/03/14 03:38:46 jsg Exp $ */
  2. /* $NetBSD: db_trap.c,v 1.9 1996/02/05 01:57:18 christos Exp $ */
  3. /*
  4. * Mach Operating System
  5. * Copyright (c) 1993,1992,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 Mellon
  26. * the rights to redistribute these changes.
  27. *
  28. * Author: David B. Golub, Carnegie Mellon University
  29. * Date: 7/90
  30. */
  31. /*
  32. * Trap entry point to kernel debugger.
  33. */
  34. #include <sys/param.h>
  35. #include <sys/systm.h>
  36. #include <machine/db_machdep.h>
  37. #include <ddb/db_run.h>
  38. #include <ddb/db_command.h>
  39. #include <ddb/db_output.h>
  40. #include <ddb/db_sym.h>
  41. #include <ddb/db_extern.h>
  42. #include <ddb/db_interface.h>
  43. #include <ddb/db_var.h>
  44. void
  45. db_trap(int type, int code)
  46. {
  47. boolean_t bkpt;
  48. boolean_t watchpt;
  49. db_is_active = 1;
  50. bkpt = IS_BREAKPOINT_TRAP(type, code);
  51. watchpt = IS_WATCHPOINT_TRAP(type, code);
  52. if (db_stop_at_pc(DDB_REGS, &bkpt)) {
  53. if (db_inst_count) {
  54. db_printf("After %d instructions\n", db_inst_count);
  55. }
  56. if (bkpt)
  57. db_printf("Breakpoint at\t");
  58. else if (watchpt)
  59. db_printf("Watchpoint at\t");
  60. else
  61. db_printf("Stopped at\t");
  62. db_dot = PC_REGS(DDB_REGS);
  63. db_print_loc_and_inst(db_dot);
  64. /*
  65. * Just in case we do not have any usable console driver,
  66. * give the user a traceback.
  67. */
  68. if (cold) {
  69. db_stack_trace_print(db_dot, 0, 10 /* arbitrary */, "",
  70. db_printf);
  71. }
  72. if (panicstr != NULL) {
  73. if (db_print_position() != 0)
  74. db_printf("\n");
  75. db_printf("RUN AT LEAST 'trace' AND 'ps' AND INCLUDE "
  76. "OUTPUT WHEN REPORTING THIS PANIC!\n");
  77. #ifdef MULTIPROCESSOR
  78. db_printf("IF RUNNING SMP, USE 'mach ddbcpu <#>' AND "
  79. "'trace' ON OTHER PROCESSORS, TOO.\n");
  80. #endif
  81. db_printf("DO NOT EVEN BOTHER REPORTING THIS WITHOUT "
  82. "INCLUDING THAT INFORMATION!\n");
  83. }
  84. db_command_loop();
  85. }
  86. db_restart_at_pc(DDB_REGS, watchpt);
  87. db_is_active = 0;
  88. }