Files
binutils-gdb/gdb/testsuite/gdb.base/shlib-unload.c
Andrew Burgess e9709998ff gdb: restructure disable_breakpoints_in_unloaded_shlib
This commit rewrites disable_breakpoints_in_unloaded_shlib to be more
like disable_breakpoints_in_freed_objfile.  Instead of looping over
all b/p locations, we instead loop over all b/p and then over all
locations for each b/p.

The advantage of doing this is that we can fix the small bug that was
documented in a comment in the code:

  /* This may cause duplicate notifications for the same breakpoint.  */
  notify_breakpoint_modified (b);

By calling notify_breakpoint_modified() as we modify each location we
can potentially send multiple notifications for a single b/p.

Is this a bug?  Maybe not.  After all, at each notification one of the
locations will have changed, so its probably fine.  But it's not
ideal, and we can easily do better, so lets do that.

There's a new test which checks that we only get a single notification
when the shared library is unloaded.  Note that the test is written as
if there are multiple related but different tests within the same test
file ... but there aren't currently!  The next commit will add another
test proc to this test script at which point the comments will make
sense.  I've done this to avoid unnecessary churn in the next commit.

Tested-By: Hannes Domani <ssbssa@yahoo.de>
Approved-By: Tom Tromey <tom@tromey.com>
2025-02-24 10:51:14 +00:00

64 lines
1.5 KiB
C

/* This testcase is part of GDB, the GNU debugger.
Copyright 2024-2025 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
#ifdef __WIN32__
#include <windows.h>
#define dlopen(name, mode) LoadLibrary (TEXT (name))
#ifdef _WIN32_WCE
# define dlsym(handle, func) GetProcAddress (handle, TEXT (func))
#else
# define dlsym(handle, func) GetProcAddress (handle, func)
#endif
#define dlclose(handle) FreeLibrary (handle)
#else
#include <dlfcn.h>
#endif
#include <assert.h>
#include "shlib-unload.h"
int
main (void)
{
int res;
void *handle;
int (*func) (void);
int val = inline_func ();
handle = dlopen (SHLIB_NAME, RTLD_LAZY);
assert (handle != NULL);
func = (int (*)(void)) dlsym (handle, "foo");
assert (func != NULL);
val += func ();
func = (int (*)(void)) dlsym (handle, "bar");
assert (func != NULL);
val += func ();
res = dlclose (handle); /* Break here. */
assert (res == 0);
return val;
}