From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78063 invoked by alias); 22 Apr 2019 13:40:50 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 78049 invoked by uid 89); 22 Apr 2019 13:40:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=territory, aborts, observed, UD:event-loop.c X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 22 Apr 2019 13:40:48 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 323613092655; Mon, 22 Apr 2019 13:40:47 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 482435D71D; Mon, 22 Apr 2019 13:40:46 +0000 (UTC) Subject: Re: [PATCH] Fix "nosharedlibrary + continue + shared lib event" crash To: Simon Marchi , gdb-patches@sourceware.org References: <20190409131410.10205-1-palves@redhat.com> From: Pedro Alves Message-ID: <78ded5a2-c60e-c7b4-692f-8329801c13c0@redhat.com> Date: Mon, 22 Apr 2019 13:40:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-04/txt/msg00418.txt.bz2 On 4/11/19 3:49 AM, Simon Marchi wrote: > On 2019-04-09 9:14 a.m., Pedro Alves wrote: >> GDB misbehaves if you run the "nosharelibrary" command, continue >> execution, and then the program hits the shared library event >> breakpoint. On my system it aborts like this: >> >> (gdb) nosharedlibrary >> (gdb) c >> Continuing. >> pure virtual method called >> terminate called without an active exception >> Aborted (core dumped) >> >> Though it's really undefined behavior territory, caused by deferencing >> a dangling solib event probe pointer. >> >> I've observed this by running "nosharedlibrary" when stopped at the >> entry point, but it should happen at any other point, if the program >> does a dlopen/dlclose after. >> >> The fix is to discard an objfile's probes from the svr4 probes table >> when an objfile is about to be released. >> >> New test included, works with both native and gdbserver testing. >> >> Valgrind log: >> >> (gdb) starti >> (gdb) nosharedlibrary >> (gdb) c >> Continuing. >> ==24895== Invalid read of size 8 >> ==24895== at 0x89E5FB: solib_event_probe_action(probe_and_action*) (solib-svr4.c:1735) >> ==24895== by 0x89E95A: svr4_handle_solib_event() (solib-svr4.c:1872) >> ==24895== by 0x8A7198: handle_solib_event() (solib.c:1274) >> ==24895== by 0x4E3407: bpstat_stop_status(address_space const*, unsigned long, thread_info*, target_waitstatus const*, bpstats*) (breakpoint.c:5407) >> ==24895== by 0x721F41: handle_signal_stop(execution_control_state*) (infrun.c:5685) >> ==24895== by 0x720B11: handle_inferior_event(execution_control_state*) (infrun.c:5129) >> ==24895== by 0x71DD93: fetch_inferior_event(void*) (infrun.c:3748) >> ==24895== by 0x7059C3: inferior_event_handler(inferior_event_type, void*) (inf-loop.c:43) >> ==24895== by 0x874DF0: remote_async_serial_handler(serial*, void*) (remote.c:14039) >> ==24895== by 0x894101: run_async_handler_and_reschedule(serial*) (ser-base.c:137) >> ==24895== by 0x8941E6: fd_event(int, void*) (ser-base.c:188) >> ==24895== by 0x67AFEF: handle_file_event(file_handler*, int) (event-loop.c:732) >> ==24895== Address 0x18b63860 is 0 bytes inside a block of size 136 free'd >> ==24895== at 0x4C2E616: operator delete(void*, unsigned long) (vg_replace_malloc.c:585) >> ==24895== by 0x8C6A12: stap_probe::~stap_probe() (stap-probe.c:124) >> ==24895== by 0x66F7DB: probe_key_free(bfd*, void*) (elfread.c:1382) >> ==24895== by 0x69B705: bfdregistry_callback_adaptor(void (*)(registry_container*, void*), registry_container*, void*) (gdb_bfd.c:131) >> ==24895== by 0x855A57: registry_clear_data(registry_data_registry*, void (*)(void (*)(registry_container*, void*), registry_container*, void*), registry_container*, registry_fields*) (registry.c:79) >> ==24895== by 0x855B01: registry_container_free_data(registry_data_registry*, void (*)(void (*)(registry_container*, void*), registry_container*, void*), registry_container*, registry_fields*) (registry.c:92) >> ==24895== by 0x69B783: bfd_free_data(bfd*) (gdb_bfd.c:131) >> ==24895== by 0x69C4BA: gdb_bfd_unref(bfd*) (gdb_bfd.c:609) >> ==24895== by 0x7CC33F: objfile::~objfile() (objfiles.c:651) >> ==24895== by 0x7CD559: objfile_purge_solibs() (objfiles.c:1021) >> ==24895== by 0x8A7132: no_shared_libraries(char const*, int) (solib.c:1252) >> ==24895== by 0x548E3D: do_const_cfunc(cmd_list_element*, char const*, int) (cli-decode.c:106) >> ==24895== Block was alloc'd at >> ==24895== at 0x4C2D42A: operator new(unsigned long) (vg_replace_malloc.c:334) >> ==24895== by 0x8C527C: handle_stap_probe(objfile*, sdt_note*, std::vector >*, unsigned long) (stap-probe.c:1561) >> ==24895== by 0x8C5535: stap_static_probe_ops::get_probes(std::vector >*, objfile*) const (stap-probe.c:1656) >> ==24895== by 0x66F71B: elf_get_probes(objfile*) (elfread.c:1365) >> ==24895== by 0x7EDD85: find_probes_in_objfile(objfile*, char const*, char const*) (probe.c:227) >> ==24895== by 0x4DF382: create_longjmp_master_breakpoint() (breakpoint.c:3275) >> ==24895== by 0x4F6562: breakpoint_re_set() (breakpoint.c:13828) >> ==24895== by 0x8A66AA: solib_add(char const*, int, int) (solib.c:1010) >> ==24895== by 0x89F7C6: enable_break(svr4_info*, int) (solib-svr4.c:2360) >> ==24895== by 0x8A104C: svr4_solib_create_inferior_hook(int) (solib-svr4.c:2992) >> ==24895== by 0x8A70B9: solib_create_inferior_hook(int) (solib.c:1215) >> ==24895== by 0x70C073: post_create_inferior(target_ops*, int) (infcmd.c:467) >> ==24895== >> pure virtual method called >> terminate called without an active exception >> ==24895== >> ==24895== Process terminating with default action of signal 6 (SIGABRT): dumping core >> ==24895== at 0x7CF3750: raise (raise.c:51) >> ==24895== by 0x7CF4D30: abort (abort.c:79) >> ==24895== by 0xB008F4: __gnu_cxx::__verbose_terminate_handler() (in build/gdb/gdb) >> ==24895== by 0xAFF845: __cxxabiv1::__terminate(void (*)()) (in build/gdb/gdb) >> ==24895== by 0xAFF890: std::terminate() (in build/gdb/gdb) >> ==24895== by 0xAFF95E: __cxa_pure_virtual (in build/gdb/gdb) >> ==24895== by 0x89E610: solib_event_probe_action(probe_and_action*) (solib-svr4.c:1735) >> ==24895== by 0x89E95A: svr4_handle_solib_event() (solib-svr4.c:1872) >> ==24895== by 0x8A7198: handle_solib_event() (solib.c:1274) >> ==24895== by 0x4E3407: bpstat_stop_status(address_space const*, unsigned long, thread_info*, target_waitstatus const*, bpstats*) (breakpoint.c:5407) >> ==24895== by 0x721F41: handle_signal_stop(execution_control_state*) (infrun.c:5685) >> ==24895== by 0x720B11: handle_inferior_event(execution_control_state*) (infrun.c:5129) >> ==24895== >> >> Note, this little bit in the patch is just a cleanup that I noticed: >> >> - lookup.prob = prob; >> lookup.address = address; >> >> That line isn't necessary because hashing/comparison only looks at the >> address. > > I am not able to reproduce the problem, and the test doesn't fail here, without > the rest of the patch applied. I think it's because on my system gdb doesn't use > the probe based interface. > > Anyhow, the fix makes sense. Since the probe is deleted on objfile destruction, the > corresponding probe_and_action structures should too. Thanks for the review. I've pushed it in now, with an additional "On systems that use the probes-based solib interface, " at the beginning of the commit log. Thanks, Pedro Alves