This is an archive of the discontinued LLVM Phabricator instance.

Add format_provider for lldb::StateType
ClosedPublic

Authored by labath on Jan 23 2017, 9:35 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Jan 23 2017, 9:35 AM
clayborg requested changes to this revision.Jan 23 2017, 9:43 AM

Very close, just add a test for a bad value since someone can have code like:

StateType state;
llvm::formatv("{0}", state);

Just to make sure we don't crash during logging. Can remember what lldb_private::StateAsCString(...) returns, but I am guessing it is NULL for a bad state, so we need to make sure the logging won't crash with that.

This revision now requires changes to proceed.Jan 23 2017, 9:43 AM
clayborg added inline comments.Jan 23 2017, 9:45 AM
unittests/Core/StateTest.cpp
19 ↗(On Diff #85415)

Add a test like:

EXPECT_EQ("(null)", llvm::formatv("{0}", static_cast<StateType>(-1)).str());
labath updated this revision to Diff 85419.Jan 23 2017, 10:03 AM
labath edited edge metadata.

In this case, StateAsCString was returning a pointer to a static buffer in a
scarily non-thread-safe way. I've changed it to print "unknown" instead and test
for that.

clayborg accepted this revision.Jan 23 2017, 11:11 AM

Looks good as long as the test suite is happy.

This revision is now accepted and ready to land.Jan 23 2017, 11:11 AM
This revision was automatically updated to reflect the committed changes.