more DEBUGF

This commit is contained in:
van Hauser
2020-11-30 21:54:18 +01:00
parent 1b75cc9f74
commit e769102491
7 changed files with 60 additions and 61 deletions

View File

@ -270,6 +270,16 @@
\ \
} while (0) } while (0)
/* Show a prefixed debug output. */
#define DEBUGF(x...) \
do { \
\
SAYF(cMGN "[D] " cBRI "DEBUG: " cRST x); \
SAYF(cRST ""); \
\
} while (0)
/* Error-checking versions of read() and write() that call RPFATAL() as /* Error-checking versions of read() and write() that call RPFATAL() as
appropriate. */ appropriate. */

View File

@ -268,8 +268,8 @@ struct InsTrim : public ModulePass {
for (auto &BB : F) for (auto &BB : F)
if (BB.size() > 0) ++bb_cnt; if (BB.size() > 0) ++bb_cnt;
SAYF(cMGN "[D] " cRST "Function %s size %zu %u\n", DEBUGF("Function %s size %zu %u\n", F.getName().str().c_str(), F.size(),
F.getName().str().c_str(), F.size(), bb_cnt); bb_cnt);
} }

View File

@ -627,9 +627,8 @@ struct afl_pass : gimple_opt_pass {
} }
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF("loaded allowlist with %zu file and %zu function entries\n",
"loaded allowlist with %zu file and %zu function entries\n", allowListFiles.size(), allowListFunctions.size());
allowListFiles.size(), allowListFunctions.size());
} }
@ -702,9 +701,8 @@ struct afl_pass : gimple_opt_pass {
} }
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF("loaded denylist with %zu file and %zu function entries\n",
"loaded denylist with %zu file and %zu function entries\n", denyListFiles.size(), denyListFunctions.size());
denyListFiles.size(), denyListFunctions.size());
} }
@ -745,10 +743,10 @@ struct afl_pass : gimple_opt_pass {
if (fnmatch(("*" + *it).c_str(), instFunction.c_str(), 0) == 0) { if (fnmatch(("*" + *it).c_str(), instFunction.c_str(), 0) == 0) {
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF(
"Function %s is in the deny function list, " "Function %s is in the deny function list, not "
"not instrumenting ... \n", "instrumenting ... \n",
instFunction.c_str()); instFunction.c_str());
return false; return false;
} }
@ -825,10 +823,10 @@ struct afl_pass : gimple_opt_pass {
if (fnmatch(("*" + *it).c_str(), instFunction.c_str(), 0) == 0) { if (fnmatch(("*" + *it).c_str(), instFunction.c_str(), 0) == 0) {
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF(
"Function %s is in the allow function list, " "Function %s is in the allow function list, instrumenting "
"instrumenting ... \n", "... \n",
instFunction.c_str()); instFunction.c_str());
return true; return true;
} }
@ -859,11 +857,11 @@ struct afl_pass : gimple_opt_pass {
if (fnmatch(("*" + *it).c_str(), source_file.c_str(), 0) == 0) { if (fnmatch(("*" + *it).c_str(), source_file.c_str(), 0) == 0) {
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF(
"Function %s is in the allowlist (%s), " "Function %s is in the allowlist (%s), instrumenting ... "
"instrumenting ... \n", "\n",
IDENTIFIER_POINTER(DECL_NAME(F->decl)), IDENTIFIER_POINTER(DECL_NAME(F->decl)),
source_file.c_str()); source_file.c_str());
return true; return true;
} }

View File

@ -173,9 +173,8 @@ void initInstrumentList() {
} }
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF("loaded allowlist with %zu file and %zu function entries\n",
"loaded allowlist with %zu file and %zu function entries\n", allowListFiles.size(), allowListFunctions.size());
allowListFiles.size(), allowListFunctions.size());
} }
@ -248,9 +247,8 @@ void initInstrumentList() {
} }
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF("loaded denylist with %zu file and %zu function entries\n",
"loaded denylist with %zu file and %zu function entries\n", denyListFiles.size(), denyListFunctions.size());
denyListFiles.size(), denyListFunctions.size());
} }
@ -409,10 +407,10 @@ bool isInInstrumentList(llvm::Function *F) {
if (fnmatch(("*" + *it).c_str(), instFunction.c_str(), 0) == 0) { if (fnmatch(("*" + *it).c_str(), instFunction.c_str(), 0) == 0) {
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF(
"Function %s is in the deny function list, " "Function %s is in the deny function list, not instrumenting "
"not instrumenting ... \n", "... \n",
instFunction.c_str()); instFunction.c_str());
return false; return false;
} }
@ -489,10 +487,10 @@ bool isInInstrumentList(llvm::Function *F) {
if (fnmatch(("*" + *it).c_str(), instFunction.c_str(), 0) == 0) { if (fnmatch(("*" + *it).c_str(), instFunction.c_str(), 0) == 0) {
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF(
"Function %s is in the allow function list, " "Function %s is in the allow function list, instrumenting "
"instrumenting ... \n", "... \n",
instFunction.c_str()); instFunction.c_str());
return true; return true;
} }
@ -523,10 +521,10 @@ bool isInInstrumentList(llvm::Function *F) {
if (fnmatch(("*" + *it).c_str(), source_file.c_str(), 0) == 0) { if (fnmatch(("*" + *it).c_str(), source_file.c_str(), 0) == 0) {
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF(
"Function %s is in the allowlist (%s), " "Function %s is in the allowlist (%s), instrumenting ... "
"instrumenting ... \n", "\n",
F->getName().str().c_str(), source_file.c_str()); F->getName().str().c_str(), source_file.c_str());
return true; return true;
} }

View File

@ -105,15 +105,14 @@ bool AFLcheckIfInstrument::runOnModule(Module &M) {
if (isInInstrumentList(&F)) { if (isInInstrumentList(&F)) {
if (debug) if (debug)
SAYF(cMGN "[D] " cRST "function %s is in the instrument file list\n", DEBUGF("function %s is in the instrument file list\n",
F.getName().str().c_str()); F.getName().str().c_str());
} else { } else {
if (debug) if (debug)
SAYF(cMGN "[D] " cRST DEBUGF("function %s is NOT in the instrument file list\n",
"function %s is NOT in the instrument file list\n", F.getName().str().c_str());
F.getName().str().c_str());
auto & Ctx = F.getContext(); auto & Ctx = F.getContext();
AttributeList Attrs = F.getAttributes(); AttributeList Attrs = F.getAttributes();

View File

@ -354,11 +354,8 @@ static void edit_params(u32 argc, char **argv, char **envp) {
cc_params[cc_par_cnt++] = "-B"; cc_params[cc_par_cnt++] = "-B";
cc_params[cc_par_cnt++] = obj_path; cc_params[cc_par_cnt++] = obj_path;
if (clang_mode) { if (clang_mode) { cc_params[cc_par_cnt++] = "-no-integrated-as"; }
cc_params[cc_par_cnt++] = "-no-integrated-as";
}
} }
if (compiler_mode == GCC_PLUGIN) { if (compiler_mode == GCC_PLUGIN) {
@ -708,7 +705,8 @@ static void edit_params(u32 argc, char **argv, char **envp) {
} }
if (getenv("AFL_NO_BUILTIN") || getenv("AFL_LLVM_LAF_TRANSFORM_COMPARES") || if (getenv("AFL_NO_BUILTIN") || getenv("AFL_LLVM_LAF_TRANSFORM_COMPARES") ||
getenv("LAF_TRANSFORM_COMPARES") || getenv("AFL_LLVM_LAF_ALL") || lto_mode) { getenv("LAF_TRANSFORM_COMPARES") || getenv("AFL_LLVM_LAF_ALL") ||
lto_mode) {
cc_params[cc_par_cnt++] = "-fno-builtin-strcmp"; cc_params[cc_par_cnt++] = "-fno-builtin-strcmp";
cc_params[cc_par_cnt++] = "-fno-builtin-strncmp"; cc_params[cc_par_cnt++] = "-fno-builtin-strncmp";
@ -1002,16 +1000,11 @@ int main(int argc, char **argv, char **envp) {
} }
if (strncmp(callname, "afl-clang", 9) == 0) { if (strncmp(callname, "afl-clang", 9) == 0) {
clang_mode = 1; clang_mode = 1;
if (strncmp(callname, "afl-clang++", 11) == 0) { if (strncmp(callname, "afl-clang++", 11) == 0) { plusplus_mode = 1; }
plusplus_mode = 1;
}
} }
@ -1085,8 +1078,7 @@ int main(int argc, char **argv, char **envp) {
if (instrument_mode == 0) if (instrument_mode == 0)
instrument_mode = INSTRUMENT_CFG; instrument_mode = INSTRUMENT_CFG;
else if (instrument_mode != INSTRUMENT_CFG) else if (instrument_mode != INSTRUMENT_CFG)
FATAL( FATAL("you cannot set AFL_LLVM_INSTRUMENT and AFL_LLVM_INSTRIM together");
"you cannot set AFL_LLVM_INSTRUMENT and AFL_LLVM_INSTRIM together");
} }

View File

@ -182,10 +182,12 @@ static void edit_params(int argc, char **argv) {
instrim = 1; instrim = 1;
if (debug) if (debug)
DEBUGF("passthrough=%s instrim=%d, gold_pos=%d, gold_present=%s inst_present=%s rt_present=%s rt_lto_present=%s\n", DEBUGF(
passthrough ? "true" : "false", instrim, gold_pos, "passthrough=%s instrim=%d, gold_pos=%d, gold_present=%s "
gold_present ? "true" : "false", inst_present ? "true" : "false", "inst_present=%s rt_present=%s rt_lto_present=%s\n",
rt_present ? "true" : "false", rt_lto_present ? "true" : "false"); passthrough ? "true" : "false", instrim, gold_pos,
gold_present ? "true" : "false", inst_present ? "true" : "false",
rt_present ? "true" : "false", rt_lto_present ? "true" : "false");
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {