Reputation: 3082
I have the following code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s{"qwe"};
while (true){} // in order to attach
cout << s << endl;
}
I run gdbserver
with the command:
sudo gdbserver --attach localhost:2345 `pidof my_proj`
Then I run gdb
and attach to gdbserver
:
gdb
(gdb) target remote localhost:2345
As expected, it freezes on while (true){}
, and when I'm trying to read the s
variable I get the following output:
(gdb) print s
$1 = {
_M_dataplus = {<std::allocator<char>> = {<std::__new_allocator<char>> = {<No data fields>}, <No data fields>}, _M_p = 0x7ffea7445190 "qwe"},
_M_string_length = 3, {_M_local_buf = "qwe", '\000' <repeats 12 times>,
_M_allocated_capacity = 6649713}}
It's not as pretty as I'd like it to be. But when I attach to my program directly with gdb
and print the same variable, it looks quite pretty:
gdb -p `pidof my_proj`
(gdb) print s
$1 = "qwe"
What is the reason of such a behavior and how can I make the pretty printing work with gdbserver
?
Upvotes: 1
Views: 75