c – LLDB为局部变量提供“使用未声明的标识符”错误

在以下函数中,我无法在LLDB中看到“recordMap”. for循环打印键,recordType设置正确,但’p recordMap’给出错误“使用未声明的标识符”.我可以在LLDB中看到变量’recordType’很好,所以我在正确的范围内.当我在LLDB中输入’recordMap’时,它会自动完成,就好像它在那里一样.

对于调试和发布,我将优化设置为“none”.这可能是什么!?

void MezNetworkController::showRecord( std::map<string, MezSQLData*> recordMap ) {

    for( auto item : recordMap )
        printf( " KEY: %s\n", item.first.c_str() );

    int recordType = (int) recordMap["messageType"]->intValue();
    printf( recordType );
}

以下是lldb中’image lookup -va $pc’的结果:

      Address: Mezmo[0x00015ed0] (Mezmo.__TEXT.__text + 45272)
      Summary: Mezmo`MezNetworkController::showRecord(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, MezSQLData*, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, MezSQLData*> > >) + 780 at MezNetworkController.cpp:774
       Module: file = "/Users/paulslocum/Dropbox/_iOS/_414 Messenger_/DerivedData/414 Messenger/Build/Products/Debug-iphoneos/Mezmo.app/Mezmo", arch = "armv7"
  CompileUnit: id = {0x00000000}, file = "/Users/paulslocum/Dropbox/_iOS/_414 Messenger_/414 Messenger/MezNetworkController.cpp", language = "ISO C++:1998"
     Function: id = {0x400015fa2}, name = "showRecord", range = [0x000c2bc4-0x000c42a6)
     FuncType: id = {0x400015fa2}, decl = MezNetworkController.hpp:60, clang_type = "void (void)"
       Blocks: id = {0x400015fa2}, range = [0x000c2bc4-0x000c42a6)
    LineEntry: [0x000c2ed0-0x000c2ee6): /Users/paulslocum/Dropbox/_iOS/_414 Messenger_/414 Messenger/MezNetworkController.cpp:774:38
       Symbol: id = {0x000001f8}, range = [0x000c2bc4-0x000c42a8), name="MezNetworkController::showRecord(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, MezSQLData*, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, MezSQLData*> > >)", mangled="_ZN20MezNetworkController10showRecordENSt3__13mapINS0_12basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEP10MezSQLDataNS0_4lessIS7_EENS5_INS0_4pairIKS7_S9_EEEEEE"
     Variable: id = {0x400015fb6}, name = "this", type = "MezNetworkController *", location =  [sp+1068], decl = 
     Variable: id = {0x400015fc5}, name = "recordType", type = "int", location =  [sp+1028], decl = MezNetworkController.cpp:774

最佳答案 变量“recordMap”未在“图像查找”输出中列出;这意味着,鉴于您当前的位置,LLDB实际上无法使用它

这通常是编译器生成的调试信息的问题,它会将变量排除在外.当调试器没有被告知变量,或者关于该变量的内存中的位置时,遗憾的是它没有多少可以做到.

作为一种解决方法,您可以手动打印键/值绑定(我看到您已经为键执行了操作),但我会向clang编译器提交有关丢失变量的错误报告

点赞