Skip to content

Commit

Permalink
Use debug info for func args (#1183)
Browse files Browse the repository at this point in the history
* frontend: llvm: catch arg names using debug info

The current way we extract function names from arguments in LLVM is
rarely successful. This is because the names attached to the LLVM
Argument objects are empty, likely removed during the compilation
process. This adds an option for looking at debug information to spot
the right argument name.

Ref: ossf/fuzz-introspector#1175

Signed-off-by: David Korczynski <[email protected]>

* nit

Signed-off-by: David Korczynski <[email protected]>

* output argNames to summary.json

Signed-off-by: David Korczynski <[email protected]>

---------

Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
shovon58 committed Aug 3, 2023
1 parent 3f79aa7 commit e090804
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1067,9 +1067,37 @@ FuzzerFunctionWrapper FuzzIntrospector::wrapFunction(Function *F) {
FuncWrap.ReturnType = resolveTypeName(F->getReturnType());

// Arguments
// errs() << "Function:\n";
// errs() << FuncWrap.FunctionName << "\n";
for (auto &A : F->args()) {
FuncWrap.ArgTypes.push_back(resolveTypeName(A.getType()));
FuncWrap.ArgNames.push_back(A.getName().str());
//FuncWrap.ArgNames.push_back(A.getName().str());
if (A.getName().str().empty()) {
const DILocalVariable* Var = NULL;
bool FoundArg = false;
for (auto &BB : *F) {
for (auto &I : BB) {
if (const DbgDeclareInst* DbgDeclare = dyn_cast<DbgDeclareInst>(&I)) {
if (auto DLV = dyn_cast<DILocalVariable>(DbgDeclare->getVariable())) {
if ( DLV->getArg() == A.getArgNo() + 1 &&
!DLV->getName().empty() &&
DLV->getScope()->getSubprogram() == F->getSubprogram()) {
//errs() << "--" << DLV->getName().str() << "\n";
FuncWrap.ArgNames.push_back(DLV->getName().str());
FoundArg = true;
}
}
}
}
}
if (FoundArg == false) {
FuncWrap.ArgNames.push_back("");
}
}
else {
// It's non empty, we just push that.
FuncWrap.ArgNames.push_back(A.getName().str());
}
}

// Log the amount of basic blocks, instruction count and cyclomatic
Expand Down
1 change: 1 addition & 0 deletions src/fuzz_introspector/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def create_all_function_table(
json_copy = row_element.copy()
json_copy['Func name'] = demangled_func_name
json_copy['Args'] = str(fd.arg_types)
json_copy['ArgNames'] = fd.arg_names
json_copy['Reached by Fuzzers'] = fd.reached_by_fuzzers
json_copy['return_type'] = fd.return_type
json_copy['raw-function-name'] = fd.raw_function_name
Expand Down

0 comments on commit e090804

Please sign in to comment.