In Windbg, how can I list enumeration values ​​during debugging?

Typically, enum values ​​are simple values ​​added to the compiler, or are set directly to an integral literal, so the values ​​can be easily displayed or seen directly by looking at the source file.

However, sometimes enum values ​​are used to set a constant in a class equal to a value defined elsewhere, or to the result of a compile-time expression that is not easily duplicated.

Is there a way to get Windbg to show me the actual value of each enum member for these more complex cases?

+6
source share
1 answer

Consider this small structure:

 struct foo { enum enum1 { enum1_val1_ = 5, enum1_val2_, }; enum enum2 { enum2_val1_ = 0x0001, enum2_val2_ = 0x0010, }; enum { // assume these come from complicated compile-time expressions some_class_constant_ = 86, another_one_ = 99, }; }; 

The fastest way is to use the dt command with the -r switches (recurse that you need to specify for enum members) and -v (verbose you need to list enum in all):

 0:000> dt -r -v foo LangTestingD!foo struct foo, 3 elements, 0x1 bytes Enum enum1, 2 total enums enum1_val1_ = 0n5 enum1_val2_ = 0n6 Enum enum2, 2 total enums enum2_val1_ = 0n1 enum2_val2_ = 0n16 Enum <unnamed-tag>, 2 total enums some_class_constant_ = 0n86 another_one_ = 0n99 

You can see that it lists the values ​​of each enumeration, even an unnamed one. All unnamed listings will be listed correctly.

The problem with dt -r -v foo is that it lists each member of foo : all data members, all members of a function, all enumerations, and which it tries to overwrite in each of them, and lists its members. If foo is a complex class that is fairly easy to get with inheritance, the output will be huge and it will be difficult to find the one enum you are looking for.

So, the next parameter is to specify the dt you want to list, in particular:

 0:000> dt foo::enum1 LangTestingD!foo::enum1 enum1_val1_ = 0n5 enum1_val2_ = 0n6 

Good Excellent! But what about this unnamed listing? Well, you say, check the output above where it uses the <unnamed-tag> . Perhaps we can use it.

 0:000> dt foo::<unnamed-tag> Couldn't resolve error at 'foo::<unnamed-tag>' 

This will actually work, but you need to use a few extra switches. When you combine -n (the next parameter is the name) and -y (matches the next parameter as the name prefix), it seems to work:

 0:000> dt -n -y foo::<unnamed-tag> LangTestingD!foo::<unnamed-tag> some_class_constant_ = 0n86 

However, only the first value is indicated. Even worse, if there are several unnamed enumerations, then only the first value of the first is displayed. Often this will be enough, since a few unnamed enumerations are not too common, but if you absolutely need them, you will have to use -r -v and just find them in the output.

+9
source

Source: https://habr.com/ru/post/946608/


All Articles