bfd-target.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Very simple "bfd" target, for GDB, the GNU debugger.
  2. Copyright (C) 2003-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "target.h"
  16. #include "bfd-target.h"
  17. #include "exec.h"
  18. #include "gdb_bfd.h"
  19. /* A target that wraps a BFD. */
  20. static const target_info target_bfd_target_info = {
  21. "bfd",
  22. N_("BFD backed target"),
  23. N_("You should never see this")
  24. };
  25. class target_bfd : public target_ops
  26. {
  27. public:
  28. explicit target_bfd (const gdb_bfd_ref_ptr &bfd);
  29. const target_info &info () const override
  30. { return target_bfd_target_info; }
  31. strata stratum () const override { return file_stratum; }
  32. void close () override;
  33. target_xfer_status
  34. xfer_partial (target_object object,
  35. const char *annex, gdb_byte *readbuf,
  36. const gdb_byte *writebuf,
  37. ULONGEST offset, ULONGEST len,
  38. ULONGEST *xfered_len) override;
  39. const target_section_table *get_section_table () override;
  40. private:
  41. /* The BFD we're wrapping. */
  42. gdb_bfd_ref_ptr m_bfd;
  43. /* The section table build from the ALLOC sections in BFD. Note
  44. that we can't rely on extracting the BFD from a random section in
  45. the table, since the table can be legitimately empty. */
  46. target_section_table m_table;
  47. };
  48. target_xfer_status
  49. target_bfd::xfer_partial (target_object object,
  50. const char *annex, gdb_byte *readbuf,
  51. const gdb_byte *writebuf,
  52. ULONGEST offset, ULONGEST len,
  53. ULONGEST *xfered_len)
  54. {
  55. switch (object)
  56. {
  57. case TARGET_OBJECT_MEMORY:
  58. {
  59. return section_table_xfer_memory_partial (readbuf, writebuf,
  60. offset, len, xfered_len,
  61. m_table);
  62. }
  63. default:
  64. return TARGET_XFER_E_IO;
  65. }
  66. }
  67. const target_section_table *
  68. target_bfd::get_section_table ()
  69. {
  70. return &m_table;
  71. }
  72. target_bfd::target_bfd (const gdb_bfd_ref_ptr &abfd)
  73. : m_bfd (abfd),
  74. m_table (build_section_table (abfd.get ()))
  75. {
  76. }
  77. target_ops *
  78. target_bfd_reopen (const gdb_bfd_ref_ptr &abfd)
  79. {
  80. return new target_bfd (abfd);
  81. }
  82. void
  83. target_bfd::close ()
  84. {
  85. delete this;
  86. }