db_write_cmd.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* $OpenBSD: db_write_cmd.c,v 1.14 2015/03/14 03:38:46 jsg Exp $ */
  2. /* $NetBSD: db_write_cmd.c,v 1.6 1996/02/05 01:57:25 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. #include <sys/param.h>
  32. #include <sys/systm.h>
  33. #include <machine/db_machdep.h>
  34. #include <ddb/db_access.h>
  35. #include <ddb/db_command.h>
  36. #include <ddb/db_sym.h>
  37. #include <ddb/db_extern.h>
  38. #include <ddb/db_output.h>
  39. /*
  40. * Write to file.
  41. */
  42. /*ARGSUSED*/
  43. void
  44. db_write_cmd(db_expr_t address, boolean_t have_addr, db_expr_t count,
  45. char *modif)
  46. {
  47. db_addr_t addr;
  48. db_expr_t old_value;
  49. db_expr_t new_value;
  50. int size;
  51. boolean_t wrote_one = FALSE;
  52. char tmpfmt[28];
  53. addr = (db_addr_t) address;
  54. switch (modif[0]) {
  55. case 'b':
  56. size = 1;
  57. break;
  58. case 'h':
  59. size = 2;
  60. break;
  61. case 'l':
  62. case '\0':
  63. size = 4;
  64. break;
  65. #ifdef __LP64__
  66. case 'q':
  67. size = 8;
  68. break;
  69. #endif
  70. default:
  71. size = -1;
  72. db_error("Unknown size\n");
  73. /*NOTREACHED*/
  74. }
  75. while (db_expression(&new_value)) {
  76. old_value = db_get_value(addr, size, FALSE);
  77. db_printsym(addr, DB_STGY_ANY, db_printf);
  78. db_printf("\t\t%s\t", db_format(tmpfmt, sizeof tmpfmt,
  79. old_value, DB_FORMAT_N, 0, 8));
  80. db_printf("=\t%s\n", db_format(tmpfmt, sizeof tmpfmt,
  81. new_value, DB_FORMAT_N, 0, 8));
  82. db_put_value(addr, size, new_value);
  83. addr += size;
  84. wrote_one = TRUE;
  85. }
  86. if (!wrote_one) {
  87. db_error("Nothing written.\n");
  88. /*NOTREACHED*/
  89. }
  90. db_next = addr;
  91. db_prev = addr - size;
  92. db_skip_to_eol();
  93. }