This is an archive of the discontinued LLVM Phabricator instance.

[ObjectYAML][DWARF] Collect diagnostic message when YAMLParser fails.
ClosedPublic

Authored by Higuoxing on Jun 26 2020, 1:49 AM.

Details

Summary

Before this patch, the diagnostic message is printed to errs() directly, which makes it difficult to use FailedWithMessage() in unit testing.
In this patch, we add a custom error handler for YAMLParser, which helps collect diagnostic messages and make it easy to use FailedWithMessage() to check error messages.

Diff Detail

Event Timeline

Higuoxing created this revision.Jun 26 2020, 1:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2020, 1:49 AM
Higuoxing edited the summary of this revision. (Show Details)Jun 26 2020, 1:54 AM

Thanks for this! I just want to make sure that the normal error message hasn't degraded as a result. Does yaml2obj produce the same full error message as before?

Thanks for this! I just want to make sure that the normal error message hasn't degraded as a result. Does yaml2obj produce the same full error message as before?

DWARFYAML::emitDebugSections() isn't used in yaml2obj. It's only used in unit testing. Hence, this patch doesn't affect yaml2obj.

jhenderson accepted this revision.Jun 26 2020, 4:32 AM

Great, LGTM, with one nit.

llvm/unittests/ObjectYAML/DWARFYAMLTest.cpp
24

Since you don't do anything with the expected after this, this can just be EXPECT_THAT_EXPECTED - ASSERT_THAT_EXPECTED terminates the current test rather than allowing it to continue. This isn't relevant currently, but might be important should the test be extended to check the values that have been parsed. I don't think testing the values needs doing in this patch though, since this patch is about error handling.

This revision is now accepted and ready to land.Jun 26 2020, 4:32 AM
MaskRay accepted this revision.Jun 28 2020, 11:57 AM

Thanks!

llvm/lib/ObjectYAML/DWARFEmitter.cpp
476

*static_cast<SMDiagnostic *>(DiagContext) = Diag;

Higuoxing updated this revision to Diff 274005.Jun 29 2020, 1:08 AM
Higuoxing marked 2 inline comments as done.

Address comments.

Thanks for reviewing!

This revision was automatically updated to reflect the committed changes.