Skip to content

Commit

Permalink
Check a return value of dpath helper
Browse files Browse the repository at this point in the history
Signed-off-by: Masanori Misono <m.misono760@gmail.com>
  • Loading branch information
mmisono authored and fbs committed Oct 14, 2020
1 parent 71de09a commit 688cab9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ast/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ void CodegenLLVM::visit(Call &call)
AllocaInst *buf = b_.CreateAllocaBPF(bpftrace_.strlen_, "path");
b_.CREATE_MEMSET(buf, b_.getInt8(0), bpftrace_.strlen_, 1);
call.vargs->front()->accept(*this);
b_.CreatePath(buf, expr_);
b_.CreatePath(ctx_, buf, expr_, call.loc);
expr_ = buf;
expr_deleter_ = [this, buf]() { b_.CreateLifetimeEnd(buf); };
}
Expand Down
10 changes: 8 additions & 2 deletions src/ast/irbuilderbpf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,10 @@ void IRBuilderBPF::CreateHelperErrorCond(Value *ctx,
SetInsertPoint(helper_merge_block);
}

void IRBuilderBPF::CreatePath(AllocaInst *buf, Value *path)
void IRBuilderBPF::CreatePath(Value *ctx,
AllocaInst *buf,
Value *path,
const location &loc)
{
// int bpf_d_path(struct path *path, char *buf, u32 sz)
// Return: 0 or error
Expand All @@ -1158,7 +1161,10 @@ void IRBuilderBPF::CreatePath(AllocaInst *buf, Value *path)
getInt64(
libbpf::BPF_FUNC_d_path),
d_path_func_ptr_type);
createCall(d_path_func, { path, buf, getInt32(bpftrace_.strlen_) }, "d_path");
CallInst *call = createCall(d_path_func,
{ path, buf, getInt32(bpftrace_.strlen_) },
"d_path");
CreateHelperErrorCond(ctx, call, libbpf::BPF_FUNC_d_path, loc);
}

} // namespace ast
Expand Down
5 changes: 4 additions & 1 deletion src/ast/irbuilderbpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ class IRBuilderBPF : public IRBuilder<>
StructType *GetStructType(std::string name, const std::vector<llvm::Type *> & elements, bool packed = false);
AllocaInst *CreateUSym(llvm::Value *val);
Value *CreatKFuncArg(Value *ctx, SizedType& type, std::string& name);
void CreatePath(AllocaInst *buf, Value *path);
void CreatePath(Value *ctx,
AllocaInst *buf,
Value *path,
const location &loc);
int helper_error_id_ = 0;

private:
Expand Down

0 comments on commit 688cab9

Please sign in to comment.