Commit c489081e authored by Alastair Robertson's avatar Alastair Robertson Committed by GitHub

Merge pull request #205 from rantala/fixlets

Fixlets
parents 8ec651e9 08fdc458
......@@ -1141,7 +1141,7 @@ void CodegenLLVM::visit(Program &program)
probe->accept(*this);
}
int CodegenLLVM::getNextIndexForProbe(std::string probe_name) {
int CodegenLLVM::getNextIndexForProbe(const std::string &probe_name) {
if (next_probe_index_.count(probe_name) == 0)
next_probe_index_[probe_name] = 1;
int index = next_probe_index_[probe_name];
......@@ -1149,7 +1149,7 @@ int CodegenLLVM::getNextIndexForProbe(std::string probe_name) {
return index;
}
std::string CodegenLLVM::getSectionNameForProbe(std::string probe_name, int index) {
std::string CodegenLLVM::getSectionNameForProbe(const std::string &probe_name, int index) {
return "s_" + probe_name + "_" + std::to_string(index);
}
......
......@@ -49,8 +49,8 @@ public:
void visit(Program &program) override;
AllocaInst *getMapKey(Map &map);
AllocaInst *getHistMapKey(Map &map, Value *log2);
int getNextIndexForProbe(std::string probe_name);
std::string getSectionNameForProbe(std::string probe_name, int index);
int getNextIndexForProbe(const std::string &probe_name);
std::string getSectionNameForProbe(const std::string &probe_name, int index);
Value *createLogicalAnd(Binop &binop);
Value *createLogicalOr(Binop &binop);
......
......@@ -104,7 +104,8 @@ AttachedProbe::AttachedProbe(Probe &probe, std::tuple<uint8_t *, uintptr_t> func
AttachedProbe::~AttachedProbe()
{
close(progfd_);
if (progfd_ >= 0)
close(progfd_);
int err = 0;
for (int perf_event_fd : perf_event_fds_)
......@@ -200,9 +201,11 @@ static unsigned kernel_version(int attempt)
return LINUX_VERSION_CODE;
case 1:
struct utsname utsname;
uname(&utsname);
if (uname(&utsname) < 0)
return 0;
unsigned x, y, z;
sscanf(utsname.release, "%d.%d.%d", &x, &y, &z);
if (sscanf(utsname.release, "%u.%u.%u", &x, &y, &z) != 3)
return 0;
return KERNEL_VERSION(x, y, z);
case 2:
// try to get the definition of LINUX_VERSION_CODE at runtime.
......@@ -319,8 +322,7 @@ void AttachedProbe::attach_uprobe()
void AttachedProbe::attach_usdt(int pid)
{
struct bcc_usdt_location loc = {};
int err, i;
std::ostringstream offset_str;
int err;
void *ctx;
if (pid)
......
......@@ -400,7 +400,7 @@ std::unique_ptr<AttachedProbe> BPFtrace::attach_probe(Probe &probe, const BpfOrc
else
return std::make_unique<AttachedProbe>(probe, func->second);
}
catch (std::runtime_error e)
catch (std::runtime_error &e)
{
std::cerr << e.what() << std::endl;
}
......
......@@ -106,7 +106,7 @@ static bool is_dir(const std::string& path)
return S_ISDIR(buf.st_mode);
}
static std::pair<bool, std::string> get_kernel_path_info(const std::string kdir)
static std::pair<bool, std::string> get_kernel_path_info(const std::string &kdir)
{
if (is_dir(kdir + "/build") && is_dir(kdir + "/source"))
return std::make_pair(true, "source");
......
......@@ -61,6 +61,8 @@ void list_dir(const std::string path, std::vector<std::string> &files)
while ((dep = readdir(dp)) != NULL)
files.push_back(std::string(dep->d_name));
closedir(dp);
}
void list_probes(const std::string &search)
......@@ -103,7 +105,6 @@ void list_probes(const std::string &search)
return;
}
std::set<std::string> matches;
size_t loc;
while (std::getline(file, line))
{
......
......@@ -180,7 +180,7 @@ int main(int argc, char *argv[])
return 0;
// Empty signal handler for cleanly terminating the program
struct sigaction act;
struct sigaction act = {};
act.sa_handler = [](int) { };
sigaction(SIGINT, &act, NULL);
......
......@@ -101,7 +101,8 @@ Map::Map(enum bpf_map_type map_type)
Map::~Map()
{
close(mapfd_);
if (mapfd_ >= 0)
close(mapfd_);
}
} // namespace bpftrace
......@@ -5,7 +5,6 @@
namespace bpftrace {
inline std::string GetProviderFromPath(std::string path) {
std::string provider;
int i = path.rfind("/");
return (i != std::string::npos) ? path.substr(i + 1) : path;
}
......
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