Lines Matching +full:is +full:- +full:binary +full:- +full:path
1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
21 * Returns 0 on success; -1 on failure. On sucess, returns via `path` the full
22 * path to the program for pid.
24 int get_pid_binary_path(pid_t pid, char *path, size_t path_sz) in get_pid_binary_path() argument
32 return -1; in get_pid_binary_path()
34 ret = readlink(proc_pid_exe, path, path_sz); in get_pid_binary_path()
37 return -1; in get_pid_binary_path()
41 return -1; in get_pid_binary_path()
43 path[ret] = '\0'; in get_pid_binary_path()
49 * Returns 0 on success; -1 on failure. On success, returns via `path` the full
50 * path to a library matching the name `lib` that is loaded into pid's address
53 int get_pid_lib_path(pid_t pid, const char *lib, char *path, size_t path_sz) in get_pid_lib_path() argument
64 return -1; in get_pid_lib_path()
69 return -1; in get_pid_lib_path()
72 if (sscanf(line_buf, "%*x-%*x %*s %*x %*s %*u %s", path_buf) != 1) in get_pid_lib_path()
74 /* e.g. /usr/lib/x86_64-linux-gnu/libc-2.31.so */ in get_pid_lib_path()
84 /* libraries can have - or . after the name */ in get_pid_lib_path()
85 if (*p != '.' && *p != '-') in get_pid_lib_path()
88 warn("path size too small\n"); in get_pid_lib_path()
89 return -1; in get_pid_lib_path()
91 strcpy(path, path_buf); in get_pid_lib_path()
98 return -1; in get_pid_lib_path()
102 * Returns 0 on success; -1 on failure. On success, returns via `path` the full
103 * path to the program.
105 static int which_program(const char *prog, char *path, size_t path_sz) in which_program() argument
112 return -1; in which_program()
117 return -1; in which_program()
119 if (!fgets(path, path_sz, which)) { in which_program()
122 return -1; in which_program()
125 path[strlen(path) - 1] = '\0'; in which_program()
131 * Returns 0 on success; -1 on failure. On success, returns via `path` the full
132 * path to the binary for the given pid.
133 * 1) pid == x, binary == "" : returns the path to x's program
134 * 2) pid == x, binary == "foo" : returns the path to libfoo linked in x
135 * 3) pid == 0, binary == "" : failure: need a pid or a binary
136 * 4) pid == 0, binary == "bar" : returns the path to `which bar`
141 int resolve_binary_path(const char *binary, pid_t pid, char *path, size_t path_sz) in resolve_binary_path() argument
143 if (!strcmp(binary, "")) { in resolve_binary_path()
145 warn("Uprobes need a pid or a binary\n"); in resolve_binary_path()
146 return -1; in resolve_binary_path()
148 return get_pid_binary_path(pid, path, path_sz); in resolve_binary_path()
151 return get_pid_lib_path(pid, binary, path, path_sz); in resolve_binary_path()
153 if (which_program(binary, path, path_sz)) { in resolve_binary_path()
155 * If the user is tracing a program by name, we can find it. in resolve_binary_path()
159 warn("Can't find %s (Need a PID if this is a library)\n", binary); in resolve_binary_path()
160 return -1; in resolve_binary_path()
166 * Opens an elf at `path` of kind ELF_K_ELF. Returns NULL on failure. On
169 Elf *open_elf(const char *path, int *fd_close) in open_elf() argument
178 fd = open(path, O_RDONLY); in open_elf()
180 warn("Could not open %s\n", path); in open_elf()
185 warn("elf_begin failed: %s\n", elf_errmsg(-1)); in open_elf()
190 warn("elf kind %d is not ELF_K_ELF\n", elf_kind(e)); in open_elf()
209 warn("elf_begin failed: %s\n", elf_errmsg(-1)); in open_elf_by_fd()
214 warn("elf kind %d is not ELF_K_ELF\n", elf_kind(e)); in open_elf_by_fd()
228 /* Returns the offset of a function in the elf file `path`, or -1 on failure. */
229 off_t get_elf_func_offset(const char *path, const char *func) in get_elf_func_offset() argument
231 off_t ret = -1; in get_elf_func_offset()
232 int i, fd = -1; in get_elf_func_offset()
243 e = open_elf(path, &fd); in get_elf_func_offset()
255 if (!(shdr->sh_type == SHT_SYMTAB || shdr->sh_type == SHT_DYNSYM)) in get_elf_func_offset()
260 n = elf_strptr(e, shdr->sh_link, sym->st_name); in get_elf_func_offset()
263 if (GELF_ST_TYPE(sym->st_info) != STT_FUNC) in get_elf_func_offset()
266 ret = sym->st_value; in get_elf_func_offset()
276 ret = -1; in get_elf_func_offset()
285 ret = ret - phdr.p_vaddr + phdr.p_offset; in get_elf_func_offset()
289 ret = -1; in get_elf_func_offset()