gdb/gdbserver/dll.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* Copyright (C) 2002-2015 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. #define get_dll(inf) ((struct dll_info *)(inf))

  16. /* An "unspecified" CORE_ADDR, for match_dll.  */
  17. #define UNSPECIFIED_CORE_ADDR (~(CORE_ADDR) 0)

  18. struct inferior_list all_dlls;
  19. int dlls_changed;

  20. static void
  21. free_one_dll (struct inferior_list_entry *inf)
  22. {
  23.   struct dll_info *dll = get_dll (inf);
  24.   if (dll->name != NULL)
  25.     free (dll->name);
  26.   free (dll);
  27. }

  28. /* Find a DLL with the same name and/or base addressA NULL name in
  29.    the key is ignored; so is an all-ones base address.  */

  30. static int
  31. match_dll (struct inferior_list_entry *inf, void *arg)
  32. {
  33.   struct dll_info *iter = (void *) inf;
  34.   struct dll_info *key = arg;

  35.   if (key->base_addr != UNSPECIFIED_CORE_ADDR
  36.       && iter->base_addr == key->base_addr)
  37.     return 1;
  38.   else if (key->name != NULL
  39.            && iter->name != NULL
  40.            && strcmp (key->name, iter->name) == 0)
  41.     return 1;

  42.   return 0;
  43. }

  44. /* Record a newly loaded DLL at BASE_ADDR.  */

  45. void
  46. loaded_dll (const char *name, CORE_ADDR base_addr)
  47. {
  48.   struct dll_info *new_dll = xmalloc (sizeof (*new_dll));
  49.   memset (new_dll, 0, sizeof (*new_dll));

  50.   new_dll->entry.id = minus_one_ptid;

  51.   new_dll->name = xstrdup (name);
  52.   new_dll->base_addr = base_addr;

  53.   add_inferior_to_list (&all_dlls, &new_dll->entry);
  54.   dlls_changed = 1;
  55. }

  56. /* Record that the DLL with NAME and BASE_ADDR has been unloaded.  */

  57. void
  58. unloaded_dll (const char *name, CORE_ADDR base_addr)
  59. {
  60.   struct dll_info *dll;
  61.   struct dll_info key_dll;

  62.   /* Be careful not to put the key DLL in any list.  */
  63.   key_dll.name = (char *) name;
  64.   key_dll.base_addr = base_addr;

  65.   dll = (void *) find_inferior (&all_dlls, match_dll, &key_dll);

  66.   if (dll == NULL)
  67.     /* For some inferiors we might get unloaded_dll events without having
  68.        a corresponding loaded_dll.  In that case, the dll cannot be found
  69.        in ALL_DLL, and there is nothing further for us to do.

  70.        This has been observed when running 32bit executables on Windows64
  71.        (i.e. through WOW64, the interface between the 32bits and 64bits
  72.        worlds).  In that case, the inferior always does some strange
  73.        unloading of unnamed dll.  */
  74.     return;
  75.   else
  76.     {
  77.       /* DLL has been found so remove the entry and free associated
  78.          resources.  */
  79.       remove_inferior (&all_dlls, &dll->entry);
  80.       free_one_dll (&dll->entry);
  81.       dlls_changed = 1;
  82.     }
  83. }

  84. void
  85. clear_dlls (void)
  86. {
  87.   for_each_inferior (&all_dlls, free_one_dll);
  88.   clear_inferior_list (&all_dlls);
  89. }