dll.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Copyright (C) 2002-2022 Free Software Foundation, Inc.
  2. This file is part of GDB.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include "server.h"
  14. #include "dll.h"
  15. #include <algorithm>
  16. /* An "unspecified" CORE_ADDR, for match_dll. */
  17. #define UNSPECIFIED_CORE_ADDR (~(CORE_ADDR) 0)
  18. /* Record a newly loaded DLL at BASE_ADDR for the current process. */
  19. void
  20. loaded_dll (const char *name, CORE_ADDR base_addr)
  21. {
  22. loaded_dll (current_process (), name, base_addr);
  23. }
  24. /* Record a newly loaded DLL at BASE_ADDR for PROC. */
  25. void
  26. loaded_dll (process_info *proc, const char *name, CORE_ADDR base_addr)
  27. {
  28. gdb_assert (proc != nullptr);
  29. proc->all_dlls.emplace_back (name != nullptr ? name : "", base_addr);
  30. proc->dlls_changed = true;
  31. }
  32. /* Record that the DLL with NAME and BASE_ADDR has been unloaded
  33. from the current process. */
  34. void
  35. unloaded_dll (const char *name, CORE_ADDR base_addr)
  36. {
  37. unloaded_dll (current_process (), name, base_addr);
  38. }
  39. /* Record that the DLL with NAME and BASE_ADDR has been unloaded
  40. from PROC. */
  41. void
  42. unloaded_dll (process_info *proc, const char *name, CORE_ADDR base_addr)
  43. {
  44. gdb_assert (proc != nullptr);
  45. auto pred = [&] (const dll_info &dll)
  46. {
  47. if (base_addr != UNSPECIFIED_CORE_ADDR
  48. && base_addr == dll.base_addr)
  49. return true;
  50. if (name != NULL && dll.name == name)
  51. return true;
  52. return false;
  53. };
  54. auto iter = std::find_if (proc->all_dlls.begin (), proc->all_dlls.end (),
  55. pred);
  56. if (iter == proc->all_dlls.end ())
  57. /* For some inferiors we might get unloaded_dll events without having
  58. a corresponding loaded_dll. In that case, the dll cannot be found
  59. in ALL_DLL, and there is nothing further for us to do.
  60. This has been observed when running 32bit executables on Windows64
  61. (i.e. through WOW64, the interface between the 32bits and 64bits
  62. worlds). In that case, the inferior always does some strange
  63. unloading of unnamed dll. */
  64. return;
  65. else
  66. {
  67. /* DLL has been found so remove the entry and free associated
  68. resources. */
  69. proc->all_dlls.erase (iter);
  70. proc->dlls_changed = true;
  71. }
  72. }
  73. void
  74. clear_dlls (void)
  75. {
  76. for_each_process ([] (process_info *proc)
  77. {
  78. proc->all_dlls.clear ();
  79. });
  80. }