Commit 1a2ddac2 authored by Vicent Marti's avatar Vicent Marti

cc: Style fixes

parent 051d3e95
...@@ -205,7 +205,7 @@ struct mod_st { ...@@ -205,7 +205,7 @@ struct mod_st {
}; };
static int _find_module(const char *modname, uint64_t start, uint64_t end, static int _find_module(const char *modname, uint64_t start, uint64_t end,
void *p) { void *p) {
struct mod_st *mod = (struct mod_st *)p; struct mod_st *mod = (struct mod_st *)p;
if (!strcmp(modname, mod->name)) { if (!strcmp(modname, mod->name)) {
mod->start = start; mod->start = start;
...@@ -215,7 +215,7 @@ static int _find_module(const char *modname, uint64_t start, uint64_t end, ...@@ -215,7 +215,7 @@ static int _find_module(const char *modname, uint64_t start, uint64_t end,
} }
int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address, int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address,
uint64_t *global) { uint64_t *global) {
struct mod_st mod = {module, 0x0}; struct mod_st mod = {module, 0x0};
if (bcc_procutils_each_module(pid, _find_module, &mod) < 0 || if (bcc_procutils_each_module(pid, _find_module, &mod) < 0 ||
mod.start == 0x0) mod.start == 0x0)
......
...@@ -34,7 +34,7 @@ int bcc_symcache_resolve_name(void *resolver, const char *name, uint64_t *addr); ...@@ -34,7 +34,7 @@ int bcc_symcache_resolve_name(void *resolver, const char *name, uint64_t *addr);
void bcc_symcache_refresh(void *resolver); void bcc_symcache_refresh(void *resolver);
int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address, int bcc_resolve_global_addr(int pid, const char *module, const uint64_t address,
uint64_t *global); uint64_t *global);
int bcc_find_symbol_addr(struct bcc_symbol *sym); int bcc_find_symbol_addr(struct bcc_symbol *sym);
int bcc_resolve_symname(const char *module, const char *symname, int bcc_resolve_symname(const char *module, const char *symname,
const uint64_t addr, struct bcc_symbol *sym); const uint64_t addr, struct bcc_symbol *sym);
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <sstream>
#include <cstring> #include <cstring>
#include <sstream>
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -50,10 +50,12 @@ bool Probe::in_shared_object() { ...@@ -50,10 +50,12 @@ bool Probe::in_shared_object() {
return in_shared_object_.value(); return in_shared_object_.value();
} }
bool Probe::resolve_global_address(uint64_t *global, const uint64_t addr, optional<int> pid) { bool Probe::resolve_global_address(uint64_t *global, const uint64_t addr,
optional<int> pid) {
if (in_shared_object()) { if (in_shared_object()) {
return (pid && return (pid &&
bcc_resolve_global_addr(*pid, bin_path_.c_str(), addr, global) == 0); bcc_resolve_global_addr(*pid, bin_path_.c_str(), addr, global) ==
0);
} }
*global = addr; *global = addr;
...@@ -144,8 +146,7 @@ bool Probe::usdt_cases(std::ostream &stream, const optional<int> &pid) { ...@@ -144,8 +146,7 @@ bool Probe::usdt_cases(std::ostream &stream, const optional<int> &pid) {
const size_t arg_count = locations_[0].arguments_.size(); const size_t arg_count = locations_[0].arguments_.size();
for (size_t arg_n = 0; arg_n < arg_count; ++arg_n) { for (size_t arg_n = 0; arg_n < arg_count; ++arg_n) {
tfm::format(stream, "%s arg%d = 0;\n", tfm::format(stream, "%s arg%d = 0;\n", largest_arg_type(arg_n), arg_n + 1);
largest_arg_type(arg_n), arg_n + 1);
} }
for (size_t loc_n = 0; loc_n < locations_.size(); ++loc_n) { for (size_t loc_n = 0; loc_n < locations_.size(); ++loc_n) {
...@@ -155,7 +156,7 @@ bool Probe::usdt_cases(std::ostream &stream, const optional<int> &pid) { ...@@ -155,7 +156,7 @@ bool Probe::usdt_cases(std::ostream &stream, const optional<int> &pid) {
for (size_t arg_n = 0; arg_n < location.arguments_.size(); ++arg_n) { for (size_t arg_n = 0; arg_n < location.arguments_.size(); ++arg_n) {
Argument &arg = location.arguments_[arg_n]; Argument &arg = location.arguments_[arg_n];
if (!arg.assign_to_local(stream, tfm::format("arg%d", arg_n + 1), if (!arg.assign_to_local(stream, tfm::format("arg%d", arg_n + 1),
bin_path_, pid)) bin_path_, pid))
return false; return false;
} }
stream << "}\n"; stream << "}\n";
...@@ -168,7 +169,7 @@ std::string Probe::largest_arg_type(size_t arg_n) { ...@@ -168,7 +169,7 @@ std::string Probe::largest_arg_type(size_t arg_n) {
for (Location &location : locations_) { for (Location &location : locations_) {
Argument *candidate = &location.arguments_[arg_n]; Argument *candidate = &location.arguments_[arg_n];
if (!largest || if (!largest ||
std::abs(candidate->arg_size()) > std::abs(largest->arg_size())) std::abs(candidate->arg_size()) > std::abs(largest->arg_size()))
largest = candidate; largest = candidate;
} }
...@@ -185,31 +186,31 @@ bool Probe::usdt_getarg(std::ostream &stream, const optional<int> &pid) { ...@@ -185,31 +186,31 @@ bool Probe::usdt_getarg(std::ostream &stream, const optional<int> &pid) {
for (size_t arg_n = 0; arg_n < arg_count; ++arg_n) { for (size_t arg_n = 0; arg_n < arg_count; ++arg_n) {
std::string ctype = largest_arg_type(arg_n); std::string ctype = largest_arg_type(arg_n);
tfm::format(stream, tfm::format(stream,
"static inline %s _bpf_readarg_%s_%d(struct pt_regs *ctx) {\n" "static inline %s _bpf_readarg_%s_%d(struct pt_regs *ctx) {\n"
" %s result = 0x0;\n", " %s result = 0x0;\n",
ctype, name_, arg_n + 1, ctype); ctype, name_, arg_n + 1, ctype);
if (locations_.size() == 1) { if (locations_.size() == 1) {
Location &location = locations_.front(); Location &location = locations_.front();
stream << " "; stream << " ";
if (!location.arguments_[arg_n].assign_to_local( if (!location.arguments_[arg_n].assign_to_local(stream, "result",
stream, "result", bin_path_, pid)) bin_path_, pid))
return false; return false;
stream << "\n"; stream << "\n";
} else { } else {
stream << " switch(ctx->ip) {\n"; stream << " switch(ctx->ip) {\n";
for (Location &location : locations_) { for (Location &location : locations_) {
uint64_t global_address; uint64_t global_address;
if (!resolve_global_address(&global_address, location.address_, pid)) if (!resolve_global_address(&global_address, location.address_, pid))
return false; return false;
tfm::format(stream, " case 0x%xULL: ", global_address); tfm::format(stream, " case 0x%xULL: ", global_address);
if (!location.arguments_[arg_n].assign_to_local( if (!location.arguments_[arg_n].assign_to_local(stream, "result",
stream, "result", bin_path_, pid)) bin_path_, pid))
return false; return false;
stream << " break;\n"; stream << " break;\n";
} }
stream << " }\n"; stream << " }\n";
} }
...@@ -282,7 +283,8 @@ bool Context::generate_usdt_args(std::ostream &stream) { ...@@ -282,7 +283,8 @@ bool Context::generate_usdt_args(std::ostream &stream) {
return true; return true;
} }
bool Context::enable_probe(const std::string &probe_name, const std::string &fn_name) { bool Context::enable_probe(const std::string &probe_name,
const std::string &fn_name) {
Probe *p = get(probe_name); Probe *p = get(probe_name);
if (!p) if (!p)
return false; return false;
...@@ -299,11 +301,8 @@ bool Context::enable_probe(const std::string &probe_name, const std::string &fn_ ...@@ -299,11 +301,8 @@ bool Context::enable_probe(const std::string &probe_name, const std::string &fn_
void Context::each_uprobe(each_uprobe_cb callback) { void Context::each_uprobe(each_uprobe_cb callback) {
for (auto &p : uprobes_) { for (auto &p : uprobes_) {
for (Probe::Location &loc : p.first->locations_) { for (Probe::Location &loc : p.first->locations_) {
callback( callback(p.first->bin_path_.c_str(), p.second.c_str(), loc.address_,
p.first->bin_path_.c_str(), pid_.value_or(-1));
p.second.c_str(),
loc.address_,
pid_.value_or(-1));
} }
} }
} }
...@@ -328,7 +327,6 @@ Context::~Context() { ...@@ -328,7 +327,6 @@ Context::~Context() {
delete p; delete p;
} }
} }
} }
extern "C" { extern "C" {
...@@ -357,7 +355,8 @@ void bcc_usdt_close(void *usdt) { ...@@ -357,7 +355,8 @@ void bcc_usdt_close(void *usdt) {
delete ctx; delete ctx;
} }
int bcc_usdt_enable_probe(void *usdt, const char *probe_name, const char *fn_name) { int bcc_usdt_enable_probe(void *usdt, const char *probe_name,
const char *fn_name) {
USDT::Context *ctx = static_cast<USDT::Context *>(usdt); USDT::Context *ctx = static_cast<USDT::Context *>(usdt);
return ctx->enable_probe(probe_name, fn_name) ? 0 : -1; return ctx->enable_probe(probe_name, fn_name) ? 0 : -1;
} }
...@@ -374,5 +373,4 @@ void bcc_usdt_foreach_uprobe(void *usdt, bcc_usdt_uprobe_cb callback) { ...@@ -374,5 +373,4 @@ void bcc_usdt_foreach_uprobe(void *usdt, bcc_usdt_uprobe_cb callback) {
USDT::Context *ctx = static_cast<USDT::Context *>(usdt); USDT::Context *ctx = static_cast<USDT::Context *>(usdt);
ctx->each_uprobe(callback); ctx->each_uprobe(callback);
} }
} }
...@@ -134,7 +134,8 @@ class Probe { ...@@ -134,7 +134,8 @@ class Probe {
std::string largest_arg_type(size_t arg_n); std::string largest_arg_type(size_t arg_n);
bool add_to_semaphore(int pid, int16_t val); bool add_to_semaphore(int pid, int16_t val);
bool resolve_global_address(uint64_t *global, const uint64_t addr, optional<int> pid); bool resolve_global_address(uint64_t *global, const uint64_t addr,
optional<int> pid);
bool lookup_semaphore_addr(uint64_t *address, int pid); bool lookup_semaphore_addr(uint64_t *address, int pid);
void add_location(uint64_t addr, const char *fmt); void add_location(uint64_t addr, const char *fmt);
...@@ -156,7 +157,6 @@ public: ...@@ -156,7 +157,6 @@ public:
bool disable(int pid); bool disable(int pid);
bool enabled() const { return !enabled_semaphores_.empty(); } bool enabled() const { return !enabled_semaphores_.empty(); }
bool in_shared_object(); bool in_shared_object();
const std::string &name() { return name_; } const std::string &name() { return name_; }
const std::string &bin_path() { return bin_path_; } const std::string &bin_path() { return bin_path_; }
......
...@@ -69,7 +69,7 @@ bool Argument::assign_to_local(std::ostream &stream, ...@@ -69,7 +69,7 @@ bool Argument::assign_to_local(std::ostream &stream,
tfm::format(stream, tfm::format(stream,
"{ u64 __addr = ctx->%s + (%d); %s __res = 0x0; " "{ u64 __addr = ctx->%s + (%d); %s __res = 0x0; "
"bpf_probe_read(&__res, sizeof(__res), (void *)__addr); " "bpf_probe_read(&__res, sizeof(__res), (void *)__addr); "
"%s = __res; }", "%s = __res; }",
*register_name_, *deref_offset_, ctype(), local_name); *register_name_, *deref_offset_, ctype(), local_name);
return true; return true;
} }
...@@ -82,7 +82,7 @@ bool Argument::assign_to_local(std::ostream &stream, ...@@ -82,7 +82,7 @@ bool Argument::assign_to_local(std::ostream &stream,
tfm::format(stream, tfm::format(stream,
"{ u64 __addr = 0x%xull + %d; %s __res = 0x0; " "{ u64 __addr = 0x%xull + %d; %s __res = 0x0; "
"bpf_probe_read(&__res, sizeof(__res), (void *)__addr); " "bpf_probe_read(&__res, sizeof(__res), (void *)__addr); "
"%s = __res; }", "%s = __res; }",
global_address, *deref_offset_, ctype(), local_name); global_address, *deref_offset_, ctype(), local_name);
return true; return true;
} }
......
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