-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[analyzer] Collect CTU-involved files in the report directory #3029
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -444,6 +444,30 @@ def __cleanup_timeout(): | |
return __cleanup_timeout | ||
|
||
|
||
def collect_ctu_involved_files(result_handler, source_analyzer, output_dir): | ||
""" | ||
This function collects the list of source files involved by CTU analysis. | ||
The list of files are written to output_dir. | ||
""" | ||
if source_analyzer.ANALYZER_NAME != ClangSA.ANALYZER_NAME: | ||
return | ||
|
||
involved_files = set() | ||
|
||
involved_files.update(source_analyzer.get_analyzer_mentioned_files( | ||
result_handler.analyzer_stdout)) | ||
involved_files.update(source_analyzer.get_analyzer_mentioned_files( | ||
result_handler.analyzer_stderr)) | ||
|
||
out = os.path.join(output_dir, result_handler.analyzer_action_str) | ||
|
||
if involved_files: | ||
with open(out, 'w', encoding='utf-8', errors='ignore') as f: | ||
f.write('\n'.join(involved_files)) | ||
elif os.path.exists(out): | ||
os.remove(out) | ||
|
||
|
||
def check(check_data): | ||
""" | ||
Invoke clang with an action which called by processes. | ||
|
@@ -627,6 +651,9 @@ def __create_timeout(analyzer_process): | |
handle_failure(source_analyzer, rh, zip_file, | ||
result_base, actions_map) | ||
|
||
collect_ctu_involved_files(rh, source_analyzer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want this collection even if the analysis was successful? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we do. These files have to be used for replicating false-positive reports. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, please add a comment here why the collection is done even if the analysis was successful. |
||
output_dirs['ctu_connections']) | ||
|
||
if skip_handler and os.path.exists(result_file): | ||
# We need to check the plist content because skipping | ||
# reports in headers can be done only this way. | ||
|
@@ -702,19 +729,24 @@ def signal_handler(signum, frame): | |
initargs=(checked_var, | ||
actions_num)) | ||
|
||
failed_dir = os.path.join(output_path, "failed") | ||
# If the analysis has failed, we help debugging. | ||
failed_dir = os.path.join(output_path, "failed") | ||
if not os.path.exists(failed_dir): | ||
os.makedirs(failed_dir) | ||
|
||
success_dir = os.path.join(output_path, "success") | ||
|
||
# Analysis was successful processing results. | ||
success_dir = os.path.join(output_path, "success") | ||
if not os.path.exists(success_dir): | ||
os.makedirs(success_dir) | ||
|
||
# Collect what other TUs were involved during CTU analysis. | ||
ctu_connections_dir = os.path.join(output_path, "ctu_connections") | ||
if not os.path.exists(ctu_connections_dir): | ||
os.makedirs(ctu_connections_dir) | ||
|
||
output_dirs = {'success': success_dir, | ||
'failed': failed_dir} | ||
'failed': failed_dir, | ||
'ctu_connections': ctu_connections_dir} | ||
|
||
# Construct analyzer env. | ||
analyzer_environment = env.extend(context.path_env_extra, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "zero.h" | ||
|
||
int main() | ||
{ | ||
int i = 1 / zero(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include <vector> | ||
int zero() { return 0; } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
int zero(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible that previously this set wasn't empty, so we created an involved file, but the next time it was empty, so we do nothing. Do not we need to remove the previous file? So something similar to this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comment. This directory contains generated files for for those TUs which involve some other source files during CTU analysis. It doesn't matter if there were files here with the same name because those will be rewritten. The content of this directory behaves the same way as
failed
directory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bruntib Okay, I try to explain my problem again. Lets assume that you analyzed the same TU two times. The first time the
involved_files
variable contains some file (lib.cpp
) so you will create a file (result_handler.analyzer_action_str
) which will contain the involved files (lib.cpp
). If you change something in your code, you analyze your TU again and theinvolved_files
set is empty you will do nothing. But in theoutput_dir
there will be a file for this TU (result_handler.analyzer_action_str
) which will contain thelib.cpp
involved file from the previous analysis.My question was that in this case don't we need to remove this file if it's exist and the
involved_files
set is empty?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it doesn't cause any problem if those files are not removed. This is in analogy with failed ZIPs and .plist files: those are also not removed when you have lass analyzed TUs. Though we can remove these and the failed ZIPs if we want to gain some free space, though it's not that significant I think. But I'll check it and do this removal for failed ZIPs accordingly in a next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I did it.