Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LLDB gives "use of undeclared identifier" error for local variable

Tags:

c++

xcode

lldb

In the following function I am unable to see 'recordMap' in LLDB. The for loop prints the keys, recordType is set correctly, but 'p recordMap' gives the error "use of undeclared identifier". I can see the variable 'recordType' fine in LLDB, so I'm in the right scope. When I'm typing 'recordMap' in LLDB it autocompletes as if it's there.

I have optimization set to "none" for both debug and release. What could this possibly be!?

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 );
}

Below is the result of 'image lookup -va $pc' in lldb:

      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
like image 277
Paul Slocum Avatar asked Oct 30 '22 10:10

Paul Slocum


1 Answers

The variable "recordMap" is not listed in the 'image lookup' output; that means it is actually not available to LLDB given your current location

This is usually an issue with debug information generated by the compiler where it leaves variables out. When the debugger is not told about a variable, or about the location in memory of that variable, unfortunately there's not much it can do.

As a workaround, you could manually print the key/value bindings (which I see you're already doing for the key), but I would file a bug report with the clang compiler about the missing variable

like image 132
Enrico Granata Avatar answered Nov 15 '22 06:11

Enrico Granata