lldb doesn't have any special capabilities regarding printing enum names. I think what you're seeing is the result of the enum values being recorded in the debug info (or not). For instance,
enum myenums {a = 0, b, c};
int main ()
{
enum myenums var = b;
return (int) var; // break here
}
% xcrun clang -g a.c
% xcrun lldb a.out
(lldb) br s -p break
Breakpoint 1: where = a.out`main + 18 at a.c:5, address = 0x0000000100000f92
(lldb) r
[...]
-> 5 return (int) var; // break here
6 }
(lldb) p var
(myenums) $0 = b
(lldb) p (myenums) 0
(myenums) $1 = a
(lldb)
If you look at the debug info for this binary (dwarfdump a.out.dSYM
) you'll see that the variable var
's type is myenums
and the debug information includes the values of those enumerated types:
0x0000005a: TAG_enumeration_type [5] *
AT_name( "myenums" )
AT_byte_size( 0x04 )
AT_decl_file( "/private/tmp/a.c" )
AT_decl_line( 1 )
0x00000062: TAG_enumerator [6]
AT_name( "a" )
AT_const_value( 0x0000000000000000 )
0x00000068: TAG_enumerator [6]
AT_name( "b" )
AT_const_value( 0x0000000000000001 )
0x0000006e: TAG_enumerator [6]
AT_name( "c" )
AT_const_value( 0x0000000000000002 )
If I add another enum to my sample file which isn't used anywhere,
enum myenums {a = 0, b, c};
enum otherenums {d = 0, e, f}; // unused in this CU
int main ()
{
enum myenums var = b;
return (int) var; // break here
}
re-compile and look at the DWARF again via dwarfdump
, I won't find any debug info describing otherenums
- it is unused (in this compilation unit) and so it is elided.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…