Page MenuHomePhabricator

[LLDB] [PECOFF] Fix error handling for executables that object::createBinary error out on

Authored by mstorsjo on Oct 30 2019, 3:23 PM.



llvm::object::createBinary returns an Expected<>, which requires not only checking the object for success, but also requires consuming the Error, if one was set.

Use LLDB_LOG_ERROR for this case, and change an existing similar log statement to use it as well, to make sure the Error is consumed even if the log channel is disabled.

Diff Detail

Event Timeline

mstorsjo created this revision.Oct 30 2019, 3:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 30 2019, 3:23 PM
amccarth accepted this revision.Oct 30 2019, 4:22 PM
This revision is now accepted and ready to land.Oct 30 2019, 4:22 PM
labath accepted this revision.Oct 31 2019, 1:34 AM
labath added inline comments.

There's an LLDB_LOG_ERROR macro, which makes sure to "handle" the error even if logging is disabled. It also handles all the .c_str() stuff *and* is able to prepend the name of the caller to the log message (if one requests that when enabling logging). So, overall, this could just be:
LLDB_LOG_ERROR(log, binary.takeError(), "Failed to create binary for file ({1}): {0}", file)

mstorsjo marked an inline comment as done.Oct 31 2019, 1:41 AM
mstorsjo added inline comments.

Oh, awesome, that's much neater.

mstorsjo updated this revision to Diff 227236.Oct 31 2019, 1:48 AM
mstorsjo edited the summary of this revision. (Show Details)

Using LLDB_LOG_ERROR instead of formatting the error to a string before invoking logging macros.

This revision was automatically updated to reflect the committed changes.