Commit 0108702b authored by williangaspar's avatar williangaspar
parent 84030219
......@@ -303,13 +303,20 @@ void CodegenLLVM::visit(Call &call)
b_.CreateProbeReadStr(buf, call.type.size, expr_);
expr_ = buf;
}
else if (call.func == "kaddr")
else if (call.func == "kaddr")
{
uint64_t addr;
auto &name = static_cast<String&>(*call.vargs->at(0)).str;
addr = bpftrace_.resolve_kname(name.c_str());
expr_ = b_.getInt64(addr);
}
else if (call.func == "uaddr")
{
uint64_t addr;
auto &name = static_cast<String&>(*call.vargs->at(0)).str;
addr = bpftrace_.resolve_uname(name.c_str());
expr_ = b_.getInt64(addr);
}
else if (call.func == "join")
{
call.vargs->front()->accept(*this);
......
......@@ -209,7 +209,7 @@ void SemanticAnalyser::visit(Call &call)
call.type = SizedType(Type::integer, 8);
}
else if (call.func == "kaddr") {
else if (call.func == "kaddr" || call.func == "uaddr") {
if (check_nargs(call, 1)) {
if (check_arg(call, Type::string, 0, true)) {
;
......
......@@ -1145,8 +1145,7 @@ uint64_t BPFtrace::resolve_kname(const char *name)
if (found)
{
std::string first_word = line.substr(0, line.find(" "));
addr = std::stoull(first_word, 0, 16);
addr = read_address_from_output(line);
}
}
......@@ -1155,6 +1154,38 @@ uint64_t BPFtrace::resolve_kname(const char *name)
return addr;
}
uint64_t BPFtrace::resolve_uname(const char *name)
{
uint64_t addr = 0;
std::string call_str = "objdump -tT /bin/bash | grep ";
call_str += name;
const char *call = call_str.c_str();
auto result = exec_system(call);
addr = read_address_from_output(result);
return addr;
}
std::string BPFtrace::exec_system(const char* cmd)
{
std::array<char, 128> buffer;
std::string result;
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
if (!pipe) throw std::runtime_error("popen() failed!");
while (!feof(pipe.get())) {
if (fgets(buffer.data(), 128, pipe.get()) != nullptr)
result += buffer.data();
}
return result;
}
uint64_t BPFtrace::read_address_from_output(std::string output)
{
std::string first_word = output.substr(0, output.find(" "));
return std::stoull(first_word, 0, 16);
}
std::string BPFtrace::resolve_usym(uintptr_t addr, int pid, bool show_offset)
{
struct bcc_symbol sym;
......
......@@ -38,6 +38,7 @@ public:
std::string resolve_sym(uintptr_t addr, bool show_offset=false);
std::string resolve_usym(uintptr_t addr, int pid, bool show_offset=false);
uint64_t resolve_kname(const char *name);
uint64_t resolve_uname(const char *name);
std::string resolve_name(uint64_t name_id);
int pid_;
......@@ -82,6 +83,8 @@ private:
static uint64_t reduce_value(const std::vector<uint8_t> &value, int ncpus);
static uint64_t min_value(const std::vector<uint8_t> &value, int ncpus);
static uint64_t max_value(const std::vector<uint8_t> &value, int ncpus);
static uint64_t read_address_from_output(std::string output);
static std::string exec_system(const char* cmd);
static std::string hist_index_label(int power);
static std::string lhist_index_label(int number);
std::vector<uint8_t> find_empty_key(IMap &map, size_t size) const;
......
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