This is an archive of the discontinued LLVM Phabricator instance.

[libFuzzer] Add unstable function printing to print_unstable_stats flag
ClosedPublic

Authored by kevinwkt on Aug 3 2018, 10:54 AM.

Details

Summary

There may be cases in which a user wants to know which part of their code is unstable.
We use ObservedFuncs and UnstableCounters to print at exit which of the ObservedFunctions
are unstable under the -print_unstable_stats flag.

Patch by Kyungtak Woo (@kevinwkt).

Diff Detail

Event Timeline

kevinwkt created this revision.Aug 3 2018, 10:54 AM
kevinwkt retitled this revision from Print Unstable Functions to [libFuzzer] Add print unstable function flag.
kevinwkt added reviewers: Dor1s, metzman.
Dor1s added a comment.Aug 3 2018, 12:32 PM

Very nice!

lib/fuzzer/FuzzerFlags.def
105 ↗(On Diff #159045)

Let's re-phrase a bit, maybe: "If 1, at exit print functions that have unstable coverage edges. Requires -handle_unstable!=0"

Still sounds bad to me though, hopefully Jonathan can help :)

lib/fuzzer/FuzzerLoop.cpp
361 ↗(On Diff #159045)

but we need some assertion mechanism to make sure it's not possible to use -print_unstable_funcs without -handle_unstable.

Another idea I have: can we re-use PrintUnstableStats flag for that? I think it doesn't need handle_unstable. Let's just print functions under that flag as well.

test/fuzzer/print-unstable-funcs.test
1 ↗(On Diff #159045)

It would be nice if we could have at least one function with arguments, just to make sure it also gets printed properly.

metzman added inline comments.Aug 3 2018, 12:36 PM
lib/fuzzer/FuzzerFlags.def
105 ↗(On Diff #159045)

Sounds pretty good actually. I would just change the ordering slightly:
"If 1, print functions that have unstable coverage edges at exit. Requires -handle_unstable = 1 or 2".
Will it work with print_unstable_stats?
I think an option that depends on another is bad, we should avoid this.

kevinwkt updated this revision to Diff 159106.EditedAug 3 2018, 3:22 PM

PTAL
Merged -print_unstable_stats with -print_unstable_funcs.
Added better test cases with arguments.

kevinwkt marked an inline comment as done.Aug 3 2018, 3:22 PM
Dor1s added a comment.Aug 6 2018, 9:20 AM

Please update the CL summary and description. LGTM, otherwise.

metzman accepted this revision.Aug 6 2018, 9:22 AM

LGTM with Max's suggested fix.

This revision is now accepted and ready to land.Aug 6 2018, 9:22 AM
kevinwkt retitled this revision from [libFuzzer] Add print unstable function flag to [libFuzzer] Add unstable function printing to print_unstable_stats flag.Aug 6 2018, 9:26 AM
kevinwkt edited the summary of this revision. (Show Details)
morehouse added inline comments.Aug 6 2018, 11:10 AM
lib/fuzzer/FuzzerTracePC.cpp
358

Since we always print this along with PrintUnstableStats, let's move the implementation there.

test/fuzzer/PrintUnstableStatsTest.cpp
26

Why are these changes necessary?

test/fuzzer/print_unstable_stats.test
6

I thought IsUnstable is set if there's any mismatch at all. Which would mean the ini functions should have IsUnstable set.

20

Are these {{^}} and {{$}} necessary?

kevinwkt updated this revision to Diff 159342.Aug 6 2018, 11:30 AM
kevinwkt marked 3 inline comments as done.
morehouse added inline comments.Aug 6 2018, 11:48 AM
lib/fuzzer/FuzzerTracePC.cpp
384

Can we put the counter increment inside this lambda as well?

test/fuzzer/PrintUnstableStatsTest.cpp
26

Why are these changes necessary?

test/fuzzer/print_unstable_stats.test
6

I thought IsUnstable is set if there's any mismatch at all. Which would mean the ini functions should have IsUnstable set.

kevinwkt added inline comments.Aug 6 2018, 12:48 PM
test/fuzzer/PrintUnstableStatsTest.cpp
26

These changes were requested by Max so that we could verify that a function with parameters will be printed correctly. We can revert if needed.

test/fuzzer/print_unstable_stats.test
6

IsUnstable is set but because the hit count for ini functions are set to 0, they are not picked up for ObservedFunctions. Because those functions were technically "not observed", they are not printed. Basically, this would only print unstable functions that are not caused by "initialization".

20

During fuzzing libFuzzer prints information containing function names such as:
#11 NEW cov: 18 ft: 19 corp: 5/6b lim: 4 exec/s: 0 rss: 28Mb L: 1/2 MS: 1 ChangeBit-
NEW_FUNC[1/1]: 0x584710 in t3() /.../llvm2/projects/compiler-rt/test/fuzzer/PrintUnstableStatsTest.cpp:24
#48 NEW cov: 20 ft: 21 corp: 6/8b lim: 4 exec/s: 0 rss: 28Mb L: 2/2 MS: 2 EraseBytes-CrossOver-

I wanted to make sure it was getting the functions I was checking for and not for the examples above.

kevinwkt updated this revision to Diff 159374.EditedAug 6 2018, 1:09 PM
kevinwkt marked an inline comment as done.

ptal
Included counter increase for stability stats within the lambda.

morehouse added inline comments.Aug 6 2018, 1:38 PM
test/fuzzer/print_unstable_stats.test
20

The check for UNSTABLE_FUNCTIONS: ensures any following matches will come after the UNSTABLE_FUNCTIONS: line, so there shouldn't be any other output from libFuzzer that will match.

kevinwkt updated this revision to Diff 159382.EditedAug 6 2018, 1:44 PM
kevinwkt marked 7 inline comments as done.

ptal
Fixed print_unstable_stats tests to simplify regex.

test/fuzzer/print_unstable_stats.test
20

Yeah, you're right. Will take out.

morehouse accepted this revision.Aug 6 2018, 1:46 PM
Dor1s accepted this revision.Aug 6 2018, 3:40 PM

LGTM, will land soon

Dor1s edited the summary of this revision. (Show Details)Aug 6 2018, 4:00 PM
Dor1s added subscribers: kcc, llvm-commits.
Dor1s updated this revision to Diff 159428.Aug 6 2018, 4:14 PM

rebase and getting ready to land

Herald added subscribers: Restricted Project, delcypher. · View Herald TranscriptAug 6 2018, 4:14 PM
This revision was automatically updated to reflect the committed changes.