microsoft / krabsetw

KrabsETW provides a modern C++ wrapper and a .NET wrapper around the low-level ETW trace consumption functions.
Other
610 stars 149 forks source link

parse<boolean> is identified as UINT8 #177

Open Gabriele91 opened 3 years ago

Gabriele91 commented 3 years ago

Hi there,

I have a problem regarding parse for boolean type. Indeed it is identified as UINT8 instead of BOOLEAN (or BOOL), thus throw_if_invalid raises an exception: image

I guess it happens because in c++ boolean is an unsigned char instead of int (it is also true for bool). I think could be nice a specialized template for the boolean type, in order to avoid this problem.

Gabriele91 commented 3 years ago

Update, It is also true for the BOOL type, which is classified as INT32 instead of BOOLEAN: image I guess a workaround is a struct krabs::boolean like the krabs::hex32/64 ones.

Gabriele91 commented 3 years ago

This is my workaround and it works fine, for me.

namespace krabs
{
    struct boolean
    {
        int value;
    };

    namespace debug
    {
        template <>
        inline void assert_valid_assignment<boolean>(const std::wstring&, const property_info& info)
        {
            auto actual = (_TDH_IN_TYPE)info.pEventPropertyInfo_->nonStructType.InType;
            if (actual != TDH_INTYPE_BOOLEAN) {
                throw std::runtime_error("Requested a boolean value from non-boolean property");
            }
        }
    }
}
Gabriele91 commented 3 years ago

Nope, the issue is visible in the first image, the specialized template classifies it as UINT8 instead of boolean (TDH_INTYPE_BOOLEAN). This raises the exception.

swannman commented 3 years ago

@Gabriele91 nice find! #148 added support for boolean including an appropriate assert_valid_assignment specialization, but it's possible that we missed something. Would you be willing to share a minimal repro that I can test with?