[lldb][DataFormatters] Support pretty printing std::string when built with -funsigned...
authorJordan Rupprecht <rupprecht@google.com>
Fri, 22 Nov 2019 18:25:03 +0000 (10:25 -0800)
committerJordan Rupprecht <rupprecht@google.com>
Fri, 22 Nov 2019 18:25:03 +0000 (10:25 -0800)
commit506144da04b94d7d492ad34f7d3d81e8368677bb
treeace042b23006324b6c5fe3fdc251f12dcd22744c
parent8b40bdbd7edc4cbd6c906911be0329b0900e0486
[lldb][DataFormatters] Support pretty printing std::string when built with -funsigned-char.

Summary:
When built w/ `-funsigned-char`, `std::string` becomes equivalent to `std::basic_string<unsigned char>`, causing these formatters to not match. This patch adds overloads for both libstdc++ and libc++ string formatters that accepts unsigned char.

Motivated by the following example:

```
$ cat pretty_print.cc

template <typename T>
void print_val(T s) {
  std::cerr << s << '\n';  // Set a breakpoint here!
}

int main() {
  std::string val = "hello";
  print_val(val);
  return 0;
}
$ clang++ -stdlib=libc++ -funsigned-char -fstandalone-debug -g pretty_print.cc
$ lldb ./a.out -b -o 'b pretty_print.cc:6' -o r -o 'fr v'
...
(lldb) fr v
(std::__1::basic_string<unsigned char, std::__1::char_traits<unsigned char>, std::__1::allocator<unsigned char> >) s = {
  __r_ = {
    std::__1::__compressed_pair_elem<std::__1::basic_string<unsigned char, std::__1::char_traits<unsigned char>, std::__1::allocator<unsigned char> >::__rep, 0, false> = {
      __value_ = {
         = {
          __l = (__cap_ = 122511465736202, __size_ = 0, __data_ = 0x0000000000000000)
          __s = {
             = (__size_ = '\n', __lx = '\n')
            __data_ = {
              [0] = 'h'
              [1] = 'e'
              [2] = 'l'
              [3] = 'l'
              [4] = 'o'
              [5] = '\0'
...
```

Reviewers: labath, JDevlieghere, shafik

Subscribers: christof, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70517
lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/TestDataFormatterLibcxxString.py
lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/string/main.cpp
lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/TestDataFormatterStdString.py
lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libstdcpp/string/main.cpp
lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp