Bug 257829 - lldb crashes with asio acceptor::accept
Summary: lldb crashes with asio acceptor::accept
Status: Closed DUPLICATE of bug 253881
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-RELEASE
Hardware: i386 Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-14 05:06 UTC by ota
Modified: 2021-12-25 11:57 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ota 2021-08-14 05:06:29 UTC
lldb crashes with the following program.
I have FreeBSD 13.0-RELEASE on i386 so far.
I also included gdb101's output for a comparison.

Please note that I run the program 2 times and lldb crashes with 2nd time when the port# is already taken by the 1st run.

% cat asio_accept.cpp 
// c++ -g -std=c++03 -I/usr/local/include asio_accept.cpp -L/usr/local/lib -lboost_system -lpthread

#include <boost/asio.hpp>

int main()
{
    using boost::asio::ip::tcp;

    boost::asio::io_service io_service;
    tcp::acceptor acceptor( io_service, tcp::endpoint( tcp::v4(), 1111 ) );
    tcp::socket socket( io_service );

    acceptor.accept( socket );
}

% c++ -g -std=c++03 -I/usr/local/include asio_accept.cpp -L/usr/local/lib -lboost_system -lpthread
% ./a.out &
% lldb ./a.out
(lldb) target create "./a.out"
Current executable set to '/export/home/hiro/a.out' (i386).
(lldb) run
Process 84554 launching
Process 84554 launched: '/export/home/hiro/a.out' (i386)
Program aborted due to an unhandled Error:
Error value was Success. (Note: Success values must still be checked prior to being destroyed).
PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace.
#0 0x03874b54 PrintStackTrace /usr/src/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:564:13
#1 0x03874f5e /usr/src/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:624:3
#2 0x03872e6e RunSignalHandlers /usr/src/contrib/llvm-project/llvm/lib/Support/Signals.cpp:67:5
#3 0x0387508c SignalHandler /usr/src/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:0:3
#4 0x24a46319 handle_signal /usr/src/lib/libthr/thread/thr_sig.c:303:3
Abort


% gdb101 ./a.out 
GNU gdb (GDB) 10.1 [GDB v10.1 for FreeBSD]
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "i386-portbld-freebsd13.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...
(gdb) run
Starting program: /export/home/hiro/a.out

Program received signal SIGABRT, Aborted.
thr_kill () at thr_kill.S:4
4       thr_kill.S: No such file or directory.
(gdb) bt
#0  thr_kill () at thr_kill.S:4
#1  0x20646e1b in __raise (s=6) at /usr/src/lib/libc/gen/raise.c:52
#2  0x206f233b in abort () at /usr/src/lib/libc/stdlib/abort.c:67
#3  0x2055ddc6 in std::terminate ()
    at /usr/src/contrib/libcxxrt/exception.cc:1495
#4  0x2055e7ce in report_failure (err=<optimized out>,
    thrown_exception=thrown_exception@entry=0x207bd000)
    at /usr/src/contrib/libcxxrt/exception.cc:719
#5  0x2055e324 in throw_exception (ex=0x207bd000)
    at /usr/src/contrib/libcxxrt/exception.cc:778
#6  __cxa_throw (thrown_exception=0x207bd044,
    tinfo=0x402034 <typeinfo for boost::wrapexcept<boost::system::system_error>>,
    dest=0x40e240 <boost::wrapexcept<boost::system::system_error>::~wrapexcept()>)
    at /usr/src/contrib/libcxxrt/exception.cc:801
#7  0x0040e0c1 in boost::throw_exception<boost::system::system_error> (e=...)
    at /usr/local/include/boost/throw_exception.hpp:70
#8  0x0040df9c in boost::asio::detail::do_throw_error (err=...,
    location=0x401ada "bind")
    at /usr/local/include/boost/asio/detail/impl/throw_error.ipp:38
#9  0x0040df08 in boost::asio::detail::throw_error (err=...,
    location=0x401ada "bind")
    at /usr/local/include/boost/asio/detail/throw_error.hpp:42
--Type <RET> for more, q to quit, c to continue without paging--
#10 0x0040c59a in boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::executor>::basic_socket_acceptor<boost::asio::io_context> (
    this=0xffbfe768, context=..., endpoint=..., reuse_addr=true)
    at /usr/local/include/boost/asio/basic_socket_acceptor.hpp:285
#11 0x0040baac in main () at asio_accept.cpp:10
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2021-08-14 11:37:35 UTC
Similar to in bug 253881, somehow this works perfectly fine for me: 

(lldb) target create "./a.out"
Current executable set to '/share/dim/src/llvm/bugs/bug257829/a.out' (x86_64).
(lldb) r
Process 1220 launched: '/share/dim/src/llvm/bugs/bug257829/a.out' (x86_64)
This version of LLDB has no plugin for the mipsassem language. Inspection of frame variables will be limited.
Process 1220 stopped
* thread #1, name = 'a.out', stop reason = signal SIGABRT
    frame #0: 0x0000000800519eea libc.so.7`__sys_thr_kill at thr_kill.S:4
(lldb) bt
* thread #1, name = 'a.out', stop reason = signal SIGABRT
  * frame #0: 0x0000000800519eea libc.so.7`__sys_thr_kill at thr_kill.S:4
    frame #1: 0x000000080048efc4 libc.so.7`__raise(s=6) at raise.c:52:10
    frame #2: 0x00000008005438e9 libc.so.7`abort at abort.c:67:8
    frame #3: 0x0000000800380ae9 libcxxrt.so.1`report_failure(err=<unavailable>, thrown_exception=0x0000000800a2d008) at exception.cc:719:5
    frame #4: 0x000000000020ea74 a.out`void boost::throw_exception<boost::system::system_error>(e=0x00007fffffffe268) at throw_exception.hpp:70:5
    frame #5: 0x000000000020e960 a.out`boost::asio::detail::do_throw_error(err=0x00007fffffffe3d8, location="bind") at throw_error.ipp:38:3
    frame #6: 0x000000000020e8e0 a.out`boost::asio::detail::throw_error(err=0x00007fffffffe3d8, location="bind") at throw_error.hpp:42:5
    frame #7: 0x000000000020d07d a.out`boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::executor>::basic_socket_acceptor<boost::asio::io_context>(this=0x00007fffffffe4a0, context=0x00007fffffffe4d0, endpoint=0x00007fffffffe480, reuse_addr=true, (null)=0x0000000000000000) at basic_socket_acceptor.hpp:285:5
    frame #8: 0x000000000020c5e1 a.out`main at asio_accept.cpp:10:19
    frame #9: 0x000000000020c310 a.out`_start(ap=<unavailable>, cleanup=<unavailable>) at crt1_c.c:73:7
(lldb) f 7
frame #7: 0x000000000020d07d a.out`boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::executor>::basic_socket_acceptor<boost::asio::io_context>(this=0x00007fffffffe4a0, context=0x00007fffffffe4d0, endpoint=0x00007fffffffe480, reuse_addr=true, (null)=0x0000000000000000) at basic_socket_acceptor.hpp:285:5
   282        boost::asio::detail::throw_error(ec, "set_option");
   283      }
   284      impl_.get_service().bind(impl_.get_implementation(), endpoint, ec);
-> 285      boost::asio::detail::throw_error(ec, "bind");
   286      impl_.get_service().listen(impl_.get_implementation(),
   287          socket_base::max_listen_connections, ec);
   288      boost::asio::detail::throw_error(ec, "listen");

I think there must be something different in our environment(s) that causes the error for you, and not me.
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2021-08-15 17:43:28 UTC

*** This bug has been marked as a duplicate of bug 253881 ***
Comment 3 commit-hook freebsd_committer freebsd_triage 2021-08-16 17:02:18 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c1a540709a83f810aa47380b946552ab20020374

commit c1a540709a83f810aa47380b946552ab20020374
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-08-16 16:56:41 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-08-16 16:57:24 +0000

    Apply upstream lldb fix for unhandled Error causing abort

    Merge commit 5033f0793fe6 from llvm git (by Dimitry Andric):

      [lldb] Avoid unhandled Error in TypeSystemMap::GetTypeSystemForLanguage

      When assertions are turned off, the `llvm::Error` value created at the
      start of this function is overwritten using the move-assignment
      operator, but the success value is never checked. Whenever a TypeSystem
      cannot be found or created, this can lead to lldb core dumping with:

          Program aborted due to an unhandled Error:
          Error value was Success. (Note: Success values must still be checked prior to being destroyed).

      Fix this by not creating a `llvm::Error` value in advance, and directly
      returning the result of `llvm::make_error` instead, whenever an error is
      encountered.

      See also: <https://bugs.freebsd.org/253881> and
      <https://bugs.freebsd.org/257829>.

      Reviewed By: teemperor

      Differential Revision: https://reviews.llvm.org/D108088

    Reported by:    dmgk, ota@j.email.ne.jp
    PR:             253881, 257829
    MFC after:      3 days

 .../llvm-project/lldb/source/Symbol/TypeSystem.cpp | 90 +++++++++-------------
 1 file changed, 38 insertions(+), 52 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2021-08-20 16:22:39 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a949c6a0d6c83994471e33c8ea60f1509e691f6c

commit a949c6a0d6c83994471e33c8ea60f1509e691f6c
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-08-16 16:56:41 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-08-20 16:21:46 +0000

    Apply upstream lldb fix for unhandled Error causing abort

    Merge commit 5033f0793fe6 from llvm git (by Dimitry Andric):

      [lldb] Avoid unhandled Error in TypeSystemMap::GetTypeSystemForLanguage

      When assertions are turned off, the `llvm::Error` value created at the
      start of this function is overwritten using the move-assignment
      operator, but the success value is never checked. Whenever a TypeSystem
      cannot be found or created, this can lead to lldb core dumping with:

          Program aborted due to an unhandled Error:
          Error value was Success. (Note: Success values must still be checked prior to being destroyed).

      Fix this by not creating a `llvm::Error` value in advance, and directly
      returning the result of `llvm::make_error` instead, whenever an error is
      encountered.

      See also: <https://bugs.freebsd.org/253881> and
      <https://bugs.freebsd.org/257829>.

      Reviewed By: teemperor

      Differential Revision: https://reviews.llvm.org/D108088

    Reported by:    dmgk, ota@j.email.ne.jp
    PR:             253881, 257829

    (cherry picked from commit c1a540709a83f810aa47380b946552ab20020374)

 .../llvm-project/lldb/source/Symbol/TypeSystem.cpp | 90 +++++++++-------------
 1 file changed, 38 insertions(+), 52 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2021-12-25 11:57:56 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=456e2b149ecb1ea5f9e81b9b0733c7ec9526b8c2

commit 456e2b149ecb1ea5f9e81b9b0733c7ec9526b8c2
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-08-16 16:56:41 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-12-25 11:51:16 +0000

    Apply upstream lldb fix for unhandled Error causing abort

    Merge commit 5033f0793fe6 from llvm git (by Dimitry Andric):

      [lldb] Avoid unhandled Error in TypeSystemMap::GetTypeSystemForLanguage

      When assertions are turned off, the `llvm::Error` value created at the
      start of this function is overwritten using the move-assignment
      operator, but the success value is never checked. Whenever a TypeSystem
      cannot be found or created, this can lead to lldb core dumping with:

          Program aborted due to an unhandled Error:
          Error value was Success. (Note: Success values must still be checked prior to being destroyed).

      Fix this by not creating a `llvm::Error` value in advance, and directly
      returning the result of `llvm::make_error` instead, whenever an error is
      encountered.

      See also: <https://bugs.freebsd.org/253881> and
      <https://bugs.freebsd.org/257829>.

      Reviewed By: teemperor

      Differential Revision: https://reviews.llvm.org/D108088

    Reported by:    dmgk, ota@j.email.ne.jp
    PR:             253881, 257829
    MFC after:      3 days

    (cherry picked from commit c1a540709a83f810aa47380b946552ab20020374)

 .../llvm-project/lldb/source/Symbol/TypeSystem.cpp | 90 +++++++++-------------
 1 file changed, 38 insertions(+), 52 deletions(-)