Output error text when event information retrieval fails

In some cases Event Monitor reported blank event text. I am suspecting
the TdhGetEventInformation() fails for some reason resulting in a silent
failure to return event text.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-06-23 13:04:46 +02:00
parent d113388a69
commit dd9cd83400

View File

@ -608,33 +608,34 @@ wxString wxETWListCtrl::OnGetItemText(const winstd::event_rec &rec, long column)
// Get event meta-info. // Get event meta-info.
unique_ptr<TRACE_EVENT_INFO> info; unique_ptr<TRACE_EVENT_INFO> info;
ULONG ulResult; ULONG ulResult;
if ((ulResult = TdhGetEventInformation((PEVENT_RECORD)&rec, 0, NULL, info)) == ERROR_SUCCESS) { if ((ulResult = TdhGetEventInformation((PEVENT_RECORD)&rec, 0, NULL, info)) != ERROR_SUCCESS)
if (info->DecodingSource != DecodingSourceWPP) { return tstring_printf(_T("(Error getting event information (error %u))"), ulResult).c_str();
if (rec.EventHeader.Flags & EVENT_HEADER_FLAG_STRING_ONLY) {
// This is a string-only event. Print it.
return reinterpret_cast<LPCWSTR>(rec.UserData);
} else {
// This is not a string-only event. Prepare parameters.
BYTE nPtrSize = (rec.EventHeader.Flags & EVENT_HEADER_FLAG_32_BIT_HEADER) ? 4 : 8; if (info->DecodingSource != DecodingSourceWPP) {
vector<tstring> props; if (rec.EventHeader.Flags & EVENT_HEADER_FLAG_STRING_ONLY) {
vector<DWORD_PTR> props_msg; // This is a string-only event. Print it.
props.reserve(info->TopLevelPropertyCount); return reinterpret_cast<LPCWSTR>(rec.UserData);
props_msg.reserve(info->TopLevelPropertyCount); } else {
for (ULONG i = 0; i < info->TopLevelPropertyCount; i++) { // This is not a string-only event. Prepare parameters.
props.push_back(std::move(PropertyToString((PEVENT_RECORD)&rec, info.get(), i, NULL, 0, nPtrSize)));
props_msg.push_back((DWORD_PTR)props[i].c_str());
}
if (info->EventMessageOffset) { BYTE nPtrSize = (rec.EventHeader.Flags & EVENT_HEADER_FLAG_32_BIT_HEADER) ? 4 : 8;
// Format the message. vector<tstring> props;
return wstring_msg(0, reinterpret_cast<LPCTSTR>(reinterpret_cast<LPCBYTE>(info.get()) + info->EventMessageOffset), props_msg.data()).c_str(); vector<DWORD_PTR> props_msg;
} props.reserve(info->TopLevelPropertyCount);
props_msg.reserve(info->TopLevelPropertyCount);
for (ULONG i = 0; i < info->TopLevelPropertyCount; i++) {
props.push_back(std::move(PropertyToString((PEVENT_RECORD)&rec, info.get(), i, NULL, 0, nPtrSize)));
props_msg.push_back((DWORD_PTR)props[i].c_str());
}
if (info->EventMessageOffset) {
// Format the message.
return wstring_msg(0, reinterpret_cast<LPCTSTR>(reinterpret_cast<LPCBYTE>(info.get()) + info->EventMessageOffset), props_msg.data()).c_str();
} }
} else if (info->EventMessageOffset) {
// This is a WPP event.
return reinterpret_cast<LPCWSTR>(reinterpret_cast<LPCBYTE>(info.get()) + info->EventMessageOffset);
} }
} else if (info->EventMessageOffset) {
// This is a WPP event.
return reinterpret_cast<LPCWSTR>(reinterpret_cast<LPCBYTE>(info.get()) + info->EventMessageOffset);
} }
} }
} }
@ -1059,7 +1060,7 @@ static tstring PropertyToString(PEVENT_RECORD pEvent, PTRACE_EVENT_INFO pInfo, U
// Get the size of the array if the property is an array. // Get the size of the array if the property is an array.
ULONG ulArraySize = 0; ULONG ulArraySize = 0;
if ((ulResult = GetArraySize(pEvent, pInfo, ulPropIndex, &ulArraySize)) != ERROR_SUCCESS) if ((ulResult = GetArraySize(pEvent, pInfo, ulPropIndex, &ulArraySize)) != ERROR_SUCCESS)
return tstring_printf(_T("(Error getting array size (error %u))"), ulResult);; return tstring_printf(_T("(Error getting array size (error %u))"), ulResult);
tstring out; tstring out;
bool out_nonfirst = false; bool out_nonfirst = false;