【问题标题】:lldb shows wierd std::strings (macOS)lldb 显示奇怪的 std::strings (macOS)
【发布时间】:2018-01-13 14:24:26
【问题描述】:

我遇到了一些麻烦 lldb 在我的CEF FileHandler 中显示正确的字符串输出

当我调试这个应用程序构建时 clang-5.0.1(llvm 使用 brew 安装) 使用调试器 lldb:

[ 96%] Building CXX object gui/executionGraphGui/CMakeFiles/ExecutionGraphGUI.dir/cefapp/FileSchemeHandlerFactory.cpp.o
/usr/local/opt/llvm/bin/clang++   -I/Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui -I/Users/gabrielnuetzi/Desktop/ExecutionGraph/include -I/Users/gabrielnuetzi/Desktop/ExecutionGraph/build/include -I/usr/local/include/eigen3 -I/Users/gabrielnuetzi/Desktop/ExecutionGraph/build/src/meta/include -I/Users/gabrielnuetzi/Desktop/ExecutionGraph/build/external/args-src -I/Users/gabrielnuetzi/Desktop/ExecutionGraph/build/external/cefbinaries-src -I/Users/gabrielnuetzi/Desktop/ExecutionGraph/build/external/cefbinaries-src/include  -g -arch x86_64 -mmacosx-version-min=10.9   -std=c++14 -lc++experimental -ferror-limit=50 -Werror=return-type -g -g3 -fno-omit-frame-pointer -Weverything -Wpedantic -Wno-deprecated-register -Wno-documentation -Wno-old-style-cast -Wno-comment -Wno-float-equal -Wno-deprecated -Wno-c++98-compat-pedantic -Wno-undef -Wno-unused-macros -fsanitize=leak -fsanitize=address -o CMakeFiles/ExecutionGraphGUI.dir/cefapp/FileSchemeHandlerFactory.cpp.o -c /Users/gabrielnuetzi/Desktop/ExecutionGraph/gui/executionGraphGui/cefapp/FileSchemeHandlerFactory.cpp

来源是:

std::string t = "client://executionGraph/index.html";
std::string temp = CefString(urlParts.path.str).ToString();

我只看到非常奇怪的输出,例如:

Process 3741 stopped
* thread #22, name = 'Chrome_IOThread', stop reason = breakpoint 1.1
    frame #0: 0x000000010011eb09 ExecutionGraphGUI`FileSchemeHandlerFactory::Create(this=0x00006060000dc340, scheme_name=0x0000700007ac9c18, request=(ptr_ = 0x0000700007ac9c10)) at FileSchemeHandlerFactory.cpp:37
   34           ...
-> 37           std::string t = "client://executionGraph/index.html";
   38           ...

Process 3741 launched: '/Users/gabrielnuetzi/Desktop/ExecutionGraph/build/gui/executionGraphGui/Debug/ExecutionGraphGUI.app/Contents/MacOS/ExecutionGraphGUI' (x86_64)
(lldb) fr v t
(std::__1::string) t = "\x85\xac\a\0p\0\0\x10\x85\xac\a\0p\0\0�\a\0p\0\0\xa0\x83\xac\a\0p\0\0`\x83\xac\a\0p\0\0@"

为什么会出现这种行为?或者问题出在哪里,错误的格式化程序?我很难弄清楚为什么我无法在我的应用程序中成功调试这些字符串。 上面的示例是通过从终端启动 lldb 来完成的。在像here 这样的普通 main.cpp 应用程序中, 一切正常,字符串格式正常。

同时加载formatter code type summary add -P std::__1::string 无济于事!

非常欢迎任何帮助!

fr v -R t的输出

(lldb) fr v -R t
(std::__1::string) t = {
  __r_ = {
    std::__1::__compressed_pair_elem<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__rep, 0, false> = {
      __value_ = {
         = {
          __l = {
            __cap_ = 123145431056880
            __size_ = 123145431056816
            __data_ = 0x0000700007ac8080
          }
          __s = {
             = {
              __size_ = '\xf0'
              __lx = '\xf0'
            }
            __data_ = {
              [0] = '\x81'
              [1] = '\xac'
              [2] = '\a'
              [3] = '\0'
              [4] = 'p'
              [5] = '\0'
              [6] = '\0'
              [7] = '\xb0'
              [8] = '\x81'
              [9] = '\xac'
              [10] = '\a'
              [11] = '\0'
              [12] = 'p'
              [13] = '\0'
              [14] = '\0'
              [15] = '\x80'
              [16] = '\x80'
              [17] = '\xac'
              [18] = '\a'
              [19] = '\0'
              [20] = 'p'
              [21] = '\0'
              [22] = '\0'
            }
          }
          __r = {
            __words = {
              [0] = 123145431056880
              [1] = 123145431056816
              [2] = 123145431056512
            }
          }
        }
      }
    }
  }
}

【问题讨论】:

  • 你可以试试fr v -R(禁用格式化程序) - 如果它是一个短字符串,你会在__data_ 数组中看到它,如果它是一个更长的字符串,试试 x/s temp 之类的东西。 __r_.__first_.__r.__words[2]。不是一种解决方法,而是一种查看对象中内容的方法。
  • 输出完全相同,当我输出 for(auto c : t) { std::cout &lt;&lt; c &lt;&lt; "," } 时,字符串看起来正确 (??):client://executionGraph/index.html
  • 它与-fsanitize=leak -fsanitize=address 相关。但是为什么呢??

标签: c++ macos debugging c++14 lldb


【解决方案1】:

经过一些调试,我发现 -fsanitize=address 导致此问题:没有这些,调试按预期进行。这是一种解决方法,但我不明白如何使它与消毒剂一起使用...?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多