public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Lancelot SIX <lsix@lancelotsix.com>
To: Tom Tromey <tromey@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Add gdb.free_objfile event registry
Date: Mon, 20 Jun 2022 18:36:32 +0000	[thread overview]
Message-ID: <20220620183612.px4ct47mq36tyqfo@ubuntu.lan> (raw)
In-Reply-To: <20220620173622.2711270-1-tromey@adacore.com>

Hi,

I have minor remarks / questions down below.

> diff --git a/gdb/testsuite/gdb.python/py-event-load.c b/gdb/testsuite/gdb.python/py-event-load.c
> new file mode 100644
> index 00000000000..515b4b0be08
> --- /dev/null
> +++ b/gdb/testsuite/gdb.python/py-event-load.c
> @@ -0,0 +1,42 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> +   Copyright 2010-2022 Free Software Foundation, Inc.

Is the 2010 intentional?  It looks that this file is copied from
gdb.base/catch-load.c which is marked 2012-2022.

> +
> +   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 <unistd.h>
> +
> +#ifdef __WIN32__
> +#include <windows.h>
> +#define dlopen(name, mode) LoadLibrary (TEXT (name))
> +#define dlclose(handle) FreeLibrary (handle)
> +#else
> +#include <dlfcn.h>
> +#endif
> +
> +/* This is updated by the .exp file.  */
> +char *libname = "catch-load-so.so";

To be "consistent" with other files which uses this pattern, shouldn't
the default libname reflect the test name? Something like
py-event-load-so.so I guess.  Later in the test you use
"py-events-shlib.so" as actual libname.

> +
> +int
> +main ()
> +{
> +  void *h;
> +
> +  h = dlopen (libname, RTLD_LAZY);
> +
> +  dlclose (h);
> +
> +  h = NULL;			/* final breakpoint here */
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.python/py-event-load.exp b/gdb/testsuite/gdb.python/py-event-load.exp
> new file mode 100644
> index 00000000000..f7aeb5f33fb
> --- /dev/null
> +++ b/gdb/testsuite/gdb.python/py-event-load.exp
> @@ -0,0 +1,67 @@
> +# Copyright 2022 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/>.
> +#
> +
> +# Test the Python free_objfile event.
> +
> +load_lib gdb-python.exp
> +
> +if {[skip_shlib_tests]} {
> +    untested "skipping shared library tests"
> +    return -1
> +}
> +
> +if {[get_compiler_info]} {
> +    warning "Could not get compiler info"
> +    untested "no compiler info"
> +    return -1
> +}
> +
> +standard_testfile .c
> +if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
> +	 executable {debug shlib_load}] != ""} {
> +    untested "failed to compile"
> +    return -1
> +}
> +
> +set testfile2 py-events-shlib
> +set srcfile2 ${testfile2}.c
> +set binfile2 [standard_output_file ${testfile2}.so]
> +set binfile2_dlopen [shlib_target_file ${testfile2}.so]
> +if {[gdb_compile_shlib "${srcdir}/${subdir}/${srcfile2}" \
> +	 ${binfile2} {debug}] != ""} {
> +    untested "failed to compile shared library"
> +    return -1
> +}
> +
> +clean_restart $testfile
> +
> +if {![runto_main]} {
> +    return
> +}
> +
> +if { [skip_python_tests] } { return }

I guess that this skip check can be moved above (together with the
skip_shlib_tests), so on target which skip python tests we do not bother
compiling the test program.  WDYT?

Best,
Lancelot.

> +
> +gdb_test_no_output "set var libname = \"$binfile2_dlopen\""
> +
> +set pyfile [gdb_remote_download host ${srcdir}/${subdir}/py-event-load.py]
> +gdb_test_no_output "source ${pyfile}" "load python file"
> +
> +gdb_breakpoint [gdb_get_line_number "final breakpoint here"]
> +
> +gdb_continue_to_breakpoint "run to final breakpoint"
> +
> +gdb_test "python print(freed_objfile)" [string_to_regexp $binfile2_dlopen] \
> +    "print name of unloaded objfile"
> diff --git a/gdb/testsuite/gdb.python/py-event-load.py b/gdb/testsuite/gdb.python/py-event-load.py
> new file mode 100644
> index 00000000000..9cf56115205
> --- /dev/null
> +++ b/gdb/testsuite/gdb.python/py-event-load.py
> @@ -0,0 +1,30 @@
> +# Copyright (C) 2022 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/>.
> +
> +# Test Python free_objfile event.
> +
> +import gdb
> +
> +
> +freed_objfile = None
> +
> +
> +def free_objfile_handler(event):
> +    assert isinstance(event, gdb.FreeObjFileEvent)
> +    global freed_objfile
> +    freed_objfile = event.objfile.username
> +
> +
> +gdb.events.free_objfile.connect(free_objfile_handler)
> -- 
> 2.34.1
> 

  parent reply	other threads:[~2022-06-20 18:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 17:36 Tom Tromey
2022-06-20 18:21 ` Eli Zaretskii
2022-06-20 18:36 ` Lancelot SIX [this message]
2022-07-18 17:25   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220620183612.px4ct47mq36tyqfo@ubuntu.lan \
    --to=lsix@lancelotsix.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).