Commit c1c2373f authored by Vicent Marti's avatar Vicent Marti

cc: Format C and C++ code according to Google's styleguide

parent 1ad2cef6
......@@ -5,11 +5,10 @@
#include <string.h>
#include <gelf.h>
#include "bcc_helpers.h"
#include "bcc_elf.h"
#define NT_STAPSDT 3
static int openelf(const char *path, Elf **elf_out, int *fd_out)
{
static int openelf(const char *path, Elf **elf_out, int *fd_out) {
if (elf_version(EV_CURRENT) == EV_NONE)
return -1;
......@@ -26,9 +25,8 @@ static int openelf(const char *path, Elf **elf_out, int *fd_out)
return 0;
}
static const char *
parse_stapsdt_note(struct bcc_elf_usdt *probe, const char *desc, int elf_class)
{
static const char *parse_stapsdt_note(struct bcc_elf_usdt *probe,
const char *desc, int elf_class) {
if (elf_class == ELFCLASS32) {
probe->pc = *((uint32_t *)(desc));
probe->base_addr = *((uint32_t *)(desc + 4));
......@@ -53,10 +51,9 @@ parse_stapsdt_note(struct bcc_elf_usdt *probe, const char *desc, int elf_class)
return desc;
}
static int do_note_segment(
Elf_Scn *section, int elf_class,
bcc_elf_probecb callback, const char *binpath, void *payload)
{
static int do_note_segment(Elf_Scn *section, int elf_class,
bcc_elf_probecb callback, const char *binpath,
void *payload) {
Elf_Data *data = NULL;
while ((data = elf_getdata(section, data)) != 0) {
......@@ -64,7 +61,8 @@ static int do_note_segment(
GElf_Nhdr hdr;
size_t name_off, desc_off;
while ((offset = gelf_getnote(data, offset, &hdr, &name_off, &desc_off)) != 0) {
while ((offset = gelf_getnote(data, offset, &hdr, &name_off, &desc_off)) !=
0) {
const char *desc, *desc_end;
struct bcc_elf_usdt probe;
......@@ -87,8 +85,8 @@ static int do_note_segment(
return 0;
}
static int listprobes(Elf *e, bcc_elf_probecb callback, const char *binpath, void *payload)
{
static int listprobes(Elf *e, bcc_elf_probecb callback, const char *binpath,
void *payload) {
Elf_Scn *section = NULL;
size_t stridx;
int elf_class = gelf_getclass(e);
......@@ -116,8 +114,8 @@ static int listprobes(Elf *e, bcc_elf_probecb callback, const char *binpath, voi
return 0;
}
int bcc_elf_foreach_usdt(const char *path, bcc_elf_probecb callback, void *payload)
{
int bcc_elf_foreach_usdt(const char *path, bcc_elf_probecb callback,
void *payload) {
Elf *e;
int fd, res;
......@@ -131,12 +129,8 @@ int bcc_elf_foreach_usdt(const char *path, bcc_elf_probecb callback, void *paylo
return res;
}
static int list_in_scn(
Elf *e, Elf_Scn *section,
size_t stridx, size_t symsize,
bcc_elf_symcb callback, void *payload)
{
static int list_in_scn(Elf *e, Elf_Scn *section, size_t stridx, size_t symsize,
bcc_elf_symcb callback, void *payload) {
Elf_Data *data = NULL;
while ((data = elf_getdata(section, data)) != 0) {
......@@ -163,8 +157,7 @@ static int list_in_scn(
return 0;
}
static int listsymbols(Elf *e, bcc_elf_symcb callback, void *payload)
{
static int listsymbols(Elf *e, bcc_elf_symcb callback, void *payload) {
Elf_Scn *section = NULL;
while ((section = elf_nextscn(e, section)) != 0) {
......@@ -176,16 +169,16 @@ static int listsymbols(Elf *e, bcc_elf_symcb callback, void *payload)
if (header.sh_type != SHT_SYMTAB && header.sh_type != SHT_DYNSYM)
continue;
if (list_in_scn(e, section,
header.sh_link, header.sh_entsize, callback, payload) < 0)
if (list_in_scn(e, section, header.sh_link, header.sh_entsize, callback,
payload) < 0)
return -1;
}
return 0;
}
int bcc_elf_foreach_sym(const char *path, bcc_elf_symcb callback, void *payload)
{
int bcc_elf_foreach_sym(const char *path, bcc_elf_symcb callback,
void *payload) {
Elf *e;
int fd, res;
......@@ -198,8 +191,7 @@ int bcc_elf_foreach_sym(const char *path, bcc_elf_symcb callback, void *payload)
return res;
}
static int loadaddr(Elf *e, uint64_t *addr)
{
static int loadaddr(Elf *e, uint64_t *addr) {
size_t phnum, i;
if (elf_getphdrnum(e, &phnum) != 0)
......@@ -221,8 +213,7 @@ static int loadaddr(Elf *e, uint64_t *addr)
return -1;
}
int bcc_elf_loadaddr(const char *path, uint64_t *address)
{
int bcc_elf_loadaddr(const char *path, uint64_t *address) {
Elf *e;
int fd, res;
......@@ -236,8 +227,7 @@ int bcc_elf_loadaddr(const char *path, uint64_t *address)
return res;
}
int bcc_elf_is_shared_obj(const char *path)
{
int bcc_elf_is_shared_obj(const char *path) {
Elf *e;
GElf_Ehdr hdr;
int fd, res = -1;
......
#ifndef LIBBCC_ELF_H
#define LIBBCC_ELF_H
#ifdef __cplusplus
extern "C" {
#endif
struct bcc_elf_usdt {
uint64_t pc;
uint64_t base_addr;
uint64_t semaphore;
const char *provider;
const char *name;
const char *arg_fmt;
};
typedef void (*bcc_elf_probecb)(const char *, const struct bcc_elf_usdt *,
void *);
typedef int (*bcc_elf_symcb)(const char *, uint64_t, uint64_t, int, void *);
int bcc_elf_foreach_usdt(const char *path, bcc_elf_probecb callback,
void *payload);
int bcc_elf_loadaddr(const char *path, uint64_t *address);
int bcc_elf_foreach_sym(const char *path, bcc_elf_symcb callback,
void *payload);
int bcc_elf_is_shared_obj(const char *path);
#ifdef __cplusplus
}
#endif
#endif
......@@ -10,10 +10,10 @@
#include <ctype.h>
#include <stdio.h>
#include "bcc_helpers.h"
#include "bcc_proc.h"
#include "bcc_elf.h"
static bool is_exe(const char *path)
{
static bool is_exe(const char *path) {
struct stat s;
if (access(path, X_OK) < 0)
return false;
......@@ -24,8 +24,7 @@ static bool is_exe(const char *path)
return S_ISREG(s.st_mode);
}
char *bcc_procutils_which(const char *binpath)
{
char *bcc_procutils_which(const char *binpath) {
char buffer[4096];
const char *PATH;
......@@ -54,8 +53,8 @@ char *bcc_procutils_which(const char *binpath)
return 0;
}
int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback, void *payload)
{
int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback,
void *payload) {
char procmap_filename[128];
FILE *procmap;
int ret;
......@@ -71,8 +70,8 @@ int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback, void *pa
char perm[8], dev[8];
long long begin, end, size, inode;
ret = fscanf(procmap, "%llx-%llx %s %llx %s %llx",
&begin, &end, perm, &size, dev, &inode);
ret = fscanf(procmap, "%llx-%llx %s %llx %s %llx", &begin, &end, perm,
&size, dev, &inode);
if (!fgets(endline, sizeof(endline), procmap))
break;
......@@ -84,8 +83,7 @@ int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback, void *pa
if (newline)
newline[0] = '\0';
while (isspace(mapname[0]))
mapname++;
while (isspace(mapname[0])) mapname++;
if (strchr(perm, 'x') && mapname[0] && mapname[0] != '[')
callback(mapname, (uint64_t)begin, (uint64_t)end, payload);
......@@ -96,8 +94,7 @@ int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback, void *pa
return 0;
}
int bcc_procutils_each_ksym(bcc_procutils_ksymcb callback, void *payload)
{
int bcc_procutils_each_ksym(bcc_procutils_ksymcb callback, void *payload) {
char line[2048];
FILE *kallsyms = fopen("/proc/kallsyms", "r");
......@@ -116,8 +113,7 @@ int bcc_procutils_each_ksym(bcc_procutils_ksymcb callback, void *payload)
addr = strtoull(line, &symname, 16);
endsym = symname = symname + 3;
while (*endsym && !isspace(*endsym))
endsym++;
while (*endsym && !isspace(*endsym)) endsym++;
*endsym = '\0';
callback(symname, addr, payload);
......@@ -168,15 +164,16 @@ static struct ld_lib {
char *libname;
char *path;
int flags;
} *lib_cache;
} * lib_cache;
static int read_cache1(const char *ld_map)
{
static int read_cache1(const char *ld_map) {
struct ld_cache1 *ldcache = (struct ld_cache1 *)ld_map;
const char *ldstrings = (const char *)(ldcache->entries + ldcache->entry_count);
const char *ldstrings =
(const char *)(ldcache->entries + ldcache->entry_count);
uint32_t i;
lib_cache = (struct ld_lib *)malloc(ldcache->entry_count * sizeof(struct ld_lib));
lib_cache =
(struct ld_lib *)malloc(ldcache->entry_count * sizeof(struct ld_lib));
lib_cache_count = (int)ldcache->entry_count;
for (i = 0; i < ldcache->entry_count; ++i) {
......@@ -191,15 +188,15 @@ static int read_cache1(const char *ld_map)
return 0;
}
static int read_cache2(const char *ld_map)
{
static int read_cache2(const char *ld_map) {
struct ld_cache2 *ldcache = (struct ld_cache2 *)ld_map;
uint32_t i;
if (memcmp(ld_map, CACHE2_HEADER, CACHE2_HEADER_LEN))
return -1;
lib_cache = (struct ld_lib *)malloc(ldcache->entry_count * sizeof(struct ld_lib));
lib_cache =
(struct ld_lib *)malloc(ldcache->entry_count * sizeof(struct ld_lib));
lib_cache_count = (int)ldcache->entry_count;
for (i = 0; i < ldcache->entry_count; ++i) {
......@@ -214,8 +211,7 @@ static int read_cache2(const char *ld_map)
return 0;
}
static int load_ld_cache(const char *cache_path)
{
static int load_ld_cache(const char *cache_path) {
struct stat st;
size_t ld_size;
const char *ld_map;
......@@ -265,8 +261,7 @@ static int load_ld_cache(const char *cache_path)
#define ABI_S390_LIB64 0x0400
#define ABI_POWERPC_LIB64 0x0500
static bool match_so_flags(int flags)
{
static bool match_so_flags(int flags) {
if ((flags & FLAG_TYPE_MASK) != TYPE_ELF_LIBC6)
return false;
......@@ -282,8 +277,7 @@ static bool match_so_flags(int flags)
return true;
}
const char *bcc_procutils_which_so(const char *libname)
{
const char *bcc_procutils_which_so(const char *libname) {
const size_t soname_len = strlen(libname) + strlen("lib.so");
char soname[soname_len + 1];
int i;
......@@ -308,53 +302,3 @@ const char *bcc_procutils_which_so(const char *libname)
}
return NULL;
}
static int _find_sym(const char *symname,
uint64_t addr, uint64_t end, int flags, void *payload)
{
struct bcc_symbol *sym = (struct bcc_symbol *)payload;
if (!strcmp(sym->name, symname)) {
sym->offset = addr;
return -1;
}
return 0;
}
int bcc_resolve_symname(const char *module, const char *symname,
const uint64_t addr, struct bcc_symbol *sym)
{
uint64_t load_addr;
sym->module = NULL;
sym->name = NULL;
sym->offset = 0x0;
if (module == NULL)
return -1;
if (strchr(module, '/')) {
sym->module = module;
} else {
sym->module = bcc_procutils_which_so(module);
}
if (sym->module == NULL)
return -1;
if (bcc_elf_loadaddr(sym->module, &load_addr) < 0) {
sym->module = NULL;
return -1;
}
sym->name = symname;
sym->offset = addr;
if (sym->name && sym->offset == 0x0)
bcc_elf_foreach_sym(sym->module, _find_sym, sym);
if (sym->offset == 0x0)
return -1;
sym->offset = (sym->offset - load_addr);
return 0;
}
#ifndef LIBBCC_ELF_H
#define LIBBCC_ELF_H
#ifndef LIBBCC_PROC_H
#define LIBBCC_PROC_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
struct bcc_symbol {
const char *name;
const char *module;
uint64_t offset;
};
struct bcc_elf_usdt {
uint64_t pc;
uint64_t base_addr;
uint64_t semaphore;
const char *provider;
const char *name;
const char *arg_fmt;
};
typedef void (*bcc_elf_probecb)(const char *, const struct bcc_elf_usdt *, void *);
typedef int (*bcc_elf_symcb)(const char *, uint64_t, uint64_t, int, void *);
int bcc_elf_foreach_usdt(const char *path, bcc_elf_probecb callback, void *payload);
int bcc_elf_loadaddr(const char *path, uint64_t *address);
int bcc_elf_foreach_sym(const char *path, bcc_elf_symcb callback, void *payload);
int bcc_elf_is_shared_obj(const char *path);
typedef void (*bcc_procutils_modulecb)(const char *, uint64_t, uint64_t, void *);
typedef void (*bcc_procutils_modulecb)(const char *, uint64_t, uint64_t,
void *);
typedef void (*bcc_procutils_ksymcb)(const char *, uint64_t, void *);
const char *bcc_procutils_which_so(const char *libname);
char *bcc_procutils_which(const char *binpath);
int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback, void *payload);
int bcc_procutils_each_module(int pid, bcc_procutils_modulecb callback,
void *payload);
int bcc_procutils_each_ksym(bcc_procutils_ksymcb callback, void *payload);
int bcc_resolve_symname(const char *module, const char *symname, const uint64_t addr,
struct bcc_symbol *sym);
void *bcc_symcache_new(int pid);
int bcc_symcache_resolve(void *symcache, uint64_t addr, struct bcc_symbol *sym);
int bcc_symcache_resolve_name(void *resolver, const char *name, uint64_t *addr);
void bcc_symcache_refresh(void *resolver);
int bcc_resolve_symname(const char *module, const char *symname,
const uint64_t addr, struct bcc_symbol *sym);
#ifdef __cplusplus
}
......
This diff is collapsed.
#ifndef LIBBCC_SYMS_H
#define LIBBCC_SYMS_H
#ifdef __cplusplus
extern "C" {
#endif
struct bcc_symbol {
const char *name;
const char *module;
uint64_t offset;
};
void *bcc_symcache_new(int pid);
int bcc_symcache_resolve(void *symcache, uint64_t addr, struct bcc_symbol *sym);
int bcc_symcache_resolve_name(void *resolver, const char *name, uint64_t *addr);
void bcc_symcache_refresh(void *resolver);
#ifdef __cplusplus
}
#endif
#endif
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