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 committed Oct 2, 2020
1 parent 1dd42a2 commit bddb3c2
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 @@ -602,7 +602,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 @@ -1142,7 +1142,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 @@ -1153,7 +1156,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,

This comment has been minimized.

Copy link
@olsajiri

olsajiri Oct 5, 2020

createCall instead?

This comment has been minimized.

Copy link
@mmisono

mmisono Oct 5, 2020

Author Owner

oops, yes, should use createCall here.

{ 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 bddb3c2

Please sign in to comment.