Commit 298f2928 authored by Alastair Robertson's avatar Alastair Robertson

Codegen: Fix calls to bpf_map_update_elem

parent 130b26ae
...@@ -26,8 +26,8 @@ AttachedProbe::AttachedProbe(Probe &probe, std::tuple<uint8_t *, uintptr_t> &fun ...@@ -26,8 +26,8 @@ AttachedProbe::AttachedProbe(Probe &probe, std::tuple<uint8_t *, uintptr_t> &fun
AttachedProbe::~AttachedProbe() AttachedProbe::~AttachedProbe()
{ {
perf_reader_free(perf_reader_);
close(progfd_); close(progfd_);
perf_reader_free(perf_reader_);
int err = 0; int err = 0;
switch (probe_.type) switch (probe_.type)
{ {
......
...@@ -81,5 +81,21 @@ int BPFtrace::run() ...@@ -81,5 +81,21 @@ int BPFtrace::run()
return 0; return 0;
} }
int BPFtrace::print_maps()
{
for(auto &mapmap : maps_)
{
Map &map = *mapmap.second.get();
uint64_t key = 0;
uint64_t next_key = 99;
uint64_t value;
int ret;
ret = bpf_get_next_key(map.mapfd_, &key, &next_key);
std::cout << ret << map.name_ << ":" << key << ":" << next_key << std::endl;
ret = bpf_lookup_elem(map.mapfd_, &key, &value);
std::cout << ret << map.name_ << ":" << key << ":" << value << std::endl;
}
}
} // namespace bpftrace } // namespace bpftrace
} // namespace ebpf } // namespace ebpf
...@@ -43,6 +43,7 @@ public: ...@@ -43,6 +43,7 @@ public:
virtual ~BPFtrace() { } virtual ~BPFtrace() { }
virtual int add_probe(ast::Probe &p); virtual int add_probe(ast::Probe &p);
int run(); int run();
int print_maps();
std::map<std::string, Type> map_val_; std::map<std::string, Type> map_val_;
std::map<std::string, std::vector<Type>> map_args_; std::map<std::string, std::vector<Type>> map_args_;
......
...@@ -113,14 +113,13 @@ void CodegenLLVM::visit(AssignMapStatement &assignment) ...@@ -113,14 +113,13 @@ void CodegenLLVM::visit(AssignMapStatement &assignment)
Function *pseudo_func = module_->getFunction("llvm.bpf.pseudo"); Function *pseudo_func = module_->getFunction("llvm.bpf.pseudo");
Value *map_ptr = b_.CreateCall(pseudo_func, Value *map_ptr = b_.CreateCall(pseudo_func,
{b_.getInt64(BPF_PSEUDO_MAP_FD), b_.getInt64(mapfd)}); {b_.getInt64(BPF_PSEUDO_MAP_FD), b_.getInt64(mapfd)});
AllocaInst *key = createAllocaBPF(b_.getInt8PtrTy()); AllocaInst *key = createAllocaBPF(b_.getInt64Ty());
AllocaInst *val = createAllocaBPF(b_.getInt8PtrTy()); AllocaInst *val = createAllocaBPF(b_.getInt64Ty());
AllocaInst *flags = createAllocaBPF(b_.getInt8PtrTy()); Value *flags = b_.getInt64(0);
b_.CreateStore(b_.getInt64(0), key); // TODO variable key b_.CreateStore(b_.getInt64(0), key); // TODO variable key
assignment.expr->accept(*this); assignment.expr->accept(*this);
b_.CreateStore(expr_, val); b_.CreateStore(expr_, val);
b_.CreateStore(b_.getInt64(0), flags); // TODO set flags
// int map_update_elem(&map, &key, &value, flags) // int map_update_elem(&map, &key, &value, flags)
FunctionType *update_func_type = FunctionType::get( FunctionType *update_func_type = FunctionType::get(
......
...@@ -89,7 +89,9 @@ int main(int argc, char *argv[]) ...@@ -89,7 +89,9 @@ int main(int argc, char *argv[])
if (err) if (err)
return err; return err;
// TODO print results err = bpftrace.print_maps();
if (err)
return err;
return 0; return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment