I'm trying to print the reference value of std::optional which is from the following type:
boost::beast::ssl_stream<boost::beast::basic_stream<boost::asio::ip::tcp,
boost::asio::any_io_executor, boost::beast::unlimited_rate_policy>
I can print the optional wrapper
(lldb) p ssl_stream_
(std::optional<boost::beast::ssl_stream<boost::beast::basic_stream<boost::asio::ip::tcp, boost::asio::any_io_executor, boost::beast::unlimited_rate_policy> > >) $6 = Has Value=true {
Value = {
p_ = boost::beast::flat_stream<boost::asio::ssl::stream<boost::beast::basic_stream<boost::asio::ip::tcp, boost::asio::any_io_executor, boost::beast::unlimited_rate_policy> > > @ 0x0000000103a04080 {
__value_ = 0x0000000103a04080
}
}
}
However, I cannot dump the object itself (boost type) :
(lldb) p ssl_stream_.value()
error: expression failed to parse:
error: <user expression 12>:1:13: call to member function 'value' is ambiguous
ssl_stream_.value()
~~~~~~~~~~~~^~~~~
note: candidate function
note: candidate function
(lldb) p *ssl_stream_
error: expression failed to parse:
error: <user expression 13>:1:1: use of overloaded operator '*' is ambiguous (operand type 'std::optional<boost::beast::ssl_stream<boost::beast::basic_stream<boost::asio::ip::tcp, boost::asio::any_io_executor, boost::beast::unlimited_rate_policy>>>')
*ssl_stream_
^~~~~~~~~~~~
note: candidate function
note: candidate function
Any idea how to print it in the debugger ?
CodePudding user response:
While I commend that you're trying to debug your own issue... Easiest is: don't. What are you expecting to find there? It's all implementation details. Also, why is it an optional anyways?
I'm going by my own extrapolation of the code from your previous question.
For me lldb just segfaults trying to p ssl_stream_
. That is, if it can even resolve the symbol, which it cannot e.g. within the coroutine scope.
Using gdb works "normal":
(gdb) p ssl_stream_
$1 = std::optional<boost::beast::ssl_stream<boost::beast::basic_stream<boost::asio::ip::tcp, boost::asio::any_io_executor, boost::beast::unlimited_rate_policy> >> = {
[contained value] = {<boost::asio::ssl::stream_base> = {<No data fields>},
p_ = std::unique_ptr<boost::beast::flat_stream<boost::asio::ssl::stream<boost::beast::basic_stream<boost::asio::ip::tcp, boost::asio::any_io_executor, boost::beast::unlimited_rate_policy> > >> = {get() = 0x555555fea000}}}
However, the value()
function is inlined:
(gdb) p ssl_stream_.value()
Cannot evaluate function -- may be inlined
So there is no way to get the behaviour without (a) spelling out the implementation details (b) compiling with optimizations (or at least inlining) disabled.
Indeed recompiling without optimization:
(gdb) p ssl_stream_.value()
$2 = (boost::beast::ssl_stream<boost::beast::basic_stream<boost::asio::ip::tcp, boost::asio::any_io_executor, boost::beast::unlimited_rate_policy> > &) @0x7fffffffd948: {<boost::asio::ssl::stream_base> = {<No data fields>},
p_ = std::unique_ptr<boost::beast::flat_stream<boost::asio::ssl::stream<boost::beast::basic_stream<boost::asio::ip::tcp, boost::asio::any_io_executor, boost::beast::unlimited_rate_policy> > >> = {get() = 0x555556120000}}
As predicted, this doesn't tell you anything. There's nothing I can think of you would want to find there. If you want death by information:
p *ssl_stream_.value().p_
The only interesting bit would be the underlying native handles, perhaps, which you can get using accessor functions. If you tell us what you're debugging and why, I might have better ideas.