From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix "nosharedlibrary + continue + shared lib event" crash
Date: Mon, 22 Apr 2019 13:40:00 -0000 [thread overview]
Message-ID: <78ded5a2-c60e-c7b4-692f-8329801c13c0@redhat.com> (raw)
In-Reply-To: <eb02a588-ecd2-1731-bdcc-d929f96994c4@simark.ca>
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<probe*, std::allocator<probe*> >*, unsigned long) (stap-probe.c:1561)
>> ==24895== by 0x8C5535: stap_static_probe_ops::get_probes(std::vector<probe*, std::allocator<probe*> >*, 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
prev parent reply other threads:[~2019-04-22 13:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190409131410.10205-1-palves@redhat.com>
2019-04-11 2:49 ` Simon Marchi
2019-04-19 15:03 ` [PATCH] solib-svr4: Pass down svr4_info as much as possible (was: [PATCH] Fix "nosharedlibrary + continue + shared lib event" crash) Simon Marchi
2019-04-19 15:05 ` [PATCH] solib-svr4: Pass down svr4_info as much as possible Simon Marchi
2019-04-19 20:03 ` Tom Tromey
2019-04-19 23:16 ` Simon Marchi
2019-04-22 13:57 ` Pedro Alves
2019-04-22 18:22 ` Simon Marchi
2019-04-22 13:40 ` Pedro Alves [this message]
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=78ded5a2-c60e-c7b4-692f-8329801c13c0@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
/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