2 * This file is part of ltrace.
3 * Copyright (C) 2011,2012,2013,2014 Petr Machata, Red Hat Inc.
4 * Copyright (C) 2010 Joe Damato
5 * Copyright (C) 1998,2009 Juan Cespedes
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include <sys/types.h>
33 #include "breakpoint.h"
38 #include "value_dict.h"
40 #ifndef OS_HAVE_PROCESS_DATA
42 os_process_init(struct process *proc)
48 os_process_destroy(struct process *proc)
53 os_process_clone(struct process *retp, struct process *proc)
59 os_process_exec(struct process *proc)
65 #ifndef ARCH_HAVE_PROCESS_DATA
67 arch_process_init(struct process *proc)
73 arch_process_destroy(struct process *proc)
78 arch_process_clone(struct process *retp, struct process *proc)
84 arch_process_exec(struct process *proc)
90 #ifndef ARCH_HAVE_DYNLINK_DONE
92 arch_dynlink_done(struct process *proc)
97 static int add_process(struct process *proc, int was_exec);
98 static void unlist_process(struct process *proc);
101 destroy_unwind(struct process *proc)
103 #if defined(HAVE_LIBUNWIND)
104 if (proc->unwind_priv != NULL)
105 _UPT_destroy(proc->unwind_priv);
106 if (proc->unwind_as != NULL)
107 unw_destroy_addr_space(proc->unwind_as);
108 #endif /* defined(HAVE_LIBUNWIND) */
110 #if defined(HAVE_LIBDW)
111 if (proc->dwfl != NULL)
112 dwfl_end(proc->dwfl);
113 #endif /* defined(HAVE_LIBDW) */
117 process_bare_init(struct process *proc, const char *filename,
118 pid_t pid, int was_exec)
121 memset(proc, 0, sizeof(*proc));
123 proc->filename = strdup(filename);
124 if (proc->filename == NULL) {
126 free(proc->filename);
127 if (proc->breakpoints != NULL) {
128 dict_destroy(proc->breakpoints,
130 free(proc->breakpoints);
131 proc->breakpoints = NULL;
137 /* Add process so that we know who the leader is. */
139 if (add_process(proc, was_exec) < 0)
141 if (proc->leader == NULL) {
144 unlist_process(proc);
148 if (proc->leader == proc) {
149 proc->breakpoints = malloc(sizeof(*proc->breakpoints));
150 if (proc->breakpoints == NULL)
151 goto unlist_and_fail;
152 DICT_INIT(proc->breakpoints,
153 arch_addr_t, struct breakpoint *,
154 arch_addr_hash, arch_addr_eq, NULL);
156 proc->breakpoints = NULL;
159 #if defined(HAVE_LIBUNWIND)
160 if (options.bt_depth > 0) {
161 proc->unwind_priv = _UPT_create(pid);
162 proc->unwind_as = unw_create_addr_space(&_UPT_accessors, 0);
164 if (proc->unwind_priv == NULL || proc->unwind_as == NULL) {
166 "Couldn't initialize unwinding "
167 "for process %d\n", proc->pid);
168 destroy_unwind(proc);
169 proc->unwind_priv = NULL;
170 proc->unwind_as = NULL;
173 #endif /* defined(HAVE_LIBUNWIND) */
175 #if defined(HAVE_LIBDW)
176 proc->dwfl = NULL; /* Initialize for leader only on first library. */
177 #endif /* defined(HAVE_LIBDW) */
183 process_bare_destroy(struct process *proc, int was_exec)
185 dict_destroy(proc->breakpoints, NULL, NULL, NULL);
186 free(proc->breakpoints);
188 free(proc->filename);
189 unlist_process(proc);
190 destroy_unwind(proc);
195 process_init_main(struct process *proc)
197 if (breakpoints_init(proc) < 0) {
198 fprintf(stderr, "failed to init breakpoints %d\n",
207 process_init(struct process *proc, const char *filename, pid_t pid)
209 if (process_bare_init(proc, filename, pid, 0) < 0) {
211 fprintf(stderr, "failed to initialize process %d: %s\n",
212 pid, strerror(errno));
216 if (os_process_init(proc) < 0) {
217 process_bare_destroy(proc, 0);
221 if (arch_process_init(proc) < 0) {
222 os_process_destroy(proc);
223 process_bare_destroy(proc, 0);
227 if (proc->leader != proc)
229 if (process_init_main(proc) < 0) {
230 process_bare_destroy(proc, 0);
236 static enum callback_status
237 destroy_breakpoint_cb(struct process *proc, struct breakpoint *bp, void *data)
239 breakpoint_destroy(bp);
244 // XXX see comment in handle_event.c
245 void callstack_pop(struct process *proc);
248 private_process_destroy(struct process *proc, int was_exec)
250 /* Pop remaining stack elements. */
251 while (proc->callstack_depth > 0) {
252 /* When this is called just before a process is
253 * destroyed, the breakpoints should either have been
254 * retracted by now, or were killed by exec. In any
255 * case, it's safe to pretend that there are no
256 * breakpoints associated with the stack elements, so
257 * that stack_pop doesn't attempt to destroy them. */
258 size_t i = proc->callstack_depth - 1;
259 if (!proc->callstack[i].is_syscall)
260 proc->callstack[i].return_addr = 0;
266 free(proc->filename);
268 /* Libraries and symbols. This is only relevant in
271 for (lib = proc->libraries; lib != NULL; ) {
272 struct library *next = lib->next;
273 library_destroy(lib);
277 proc->libraries = NULL;
280 if (proc->breakpoints != NULL) {
281 proc_each_breakpoint(proc, NULL, destroy_breakpoint_cb, NULL);
282 dict_destroy(proc->breakpoints, NULL, NULL, NULL);
283 free(proc->breakpoints);
284 proc->breakpoints = NULL;
287 destroy_unwind(proc);
291 process_destroy(struct process *proc)
293 arch_process_destroy(proc);
294 os_process_destroy(proc);
295 private_process_destroy(proc, 0);
299 process_exec(struct process *proc)
301 /* Call exec handlers first, before we destroy the main
303 if (arch_process_exec(proc) < 0
304 || os_process_exec(proc) < 0)
307 private_process_destroy(proc, 1);
309 if (process_bare_init(proc, NULL, proc->pid, 1) < 0)
311 if (process_init_main(proc) < 0) {
312 process_bare_destroy(proc, 1);
319 open_program(const char *filename, pid_t pid)
322 struct process *proc = malloc(sizeof(*proc));
323 if (proc == NULL || process_init(proc, filename, pid) < 0) {
330 struct clone_single_bp_data {
331 struct process *old_proc;
332 struct process *new_proc;
335 static enum callback_status
336 clone_single_bp(arch_addr_t *key, struct breakpoint **bpp, void *u)
338 struct breakpoint *bp = *bpp;
339 struct clone_single_bp_data *data = u;
341 struct breakpoint *clone = malloc(sizeof(*clone));
343 || breakpoint_clone(clone, data->new_proc, bp) < 0) {
348 if (proc_add_breakpoint(data->new_proc->leader, clone) < 0) {
349 breakpoint_destroy(clone);
356 process_clone(struct process *retp, struct process *proc, pid_t pid)
358 if (process_bare_init(retp, proc->filename, pid, 0) < 0) {
360 fprintf(stderr, "Failed to clone process %d to %d: %s\n",
361 proc->pid, pid, strerror(errno));
365 retp->tracesysgood = proc->tracesysgood;
366 retp->e_machine = proc->e_machine;
367 retp->e_class = proc->e_class;
369 /* For non-leader processes, that's all we need to do. */
370 if (retp->leader != retp)
373 /* Clone symbols first so that we can clone and relink
376 struct library **nlibp = &retp->libraries;
377 for (lib = proc->leader->libraries; lib != NULL; lib = lib->next) {
378 *nlibp = malloc(sizeof(**nlibp));
381 || library_clone(*nlibp, lib) < 0) {
386 process_bare_destroy(retp, 0);
388 /* Error when cloning. Unroll what was done. */
389 for (lib = retp->libraries; lib != NULL; ) {
390 struct library *next = lib->next;
391 library_destroy(lib);
398 nlibp = &(*nlibp)->next;
401 /* Now clone breakpoints. Symbol relinking is done in
402 * clone_single_bp. */
403 struct clone_single_bp_data data = {
407 if (DICT_EACH(proc->leader->breakpoints,
408 arch_addr_t, struct breakpoint *, NULL,
409 clone_single_bp, &data) != NULL)
412 /* And finally the call stack. */
413 /* XXX clearly the callstack handling should be moved to a
414 * separate module and this whole business extracted to
415 * callstack_clone, or callstack_element_clone. */
416 memcpy(retp->callstack, proc->callstack, sizeof(retp->callstack));
417 retp->callstack_depth = proc->callstack_depth;
420 for (i = 0; i < retp->callstack_depth; ++i) {
421 struct callstack_element *elem = &retp->callstack[i];
422 struct fetch_context *ctx = elem->fetch_context;
424 struct fetch_context *nctx = fetch_arg_clone(retp, ctx);
428 for (j = 0; j < i; ++j) {
429 nctx = retp->callstack[j].fetch_context;
430 fetch_arg_done(nctx);
431 elem->fetch_context = NULL;
435 elem->fetch_context = nctx;
438 if (elem->arguments != NULL) {
439 struct value_dict *nargs = malloc(sizeof(*nargs));
441 || val_dict_clone(nargs, elem->arguments) < 0) {
443 for (j = 0; j < i; ++j) {
444 nargs = retp->callstack[j].arguments;
445 val_dict_destroy(nargs);
447 elem->arguments = NULL;
450 /* Pretend that this round went well,
451 * so that fail3 frees I-th
456 elem->arguments = nargs;
459 /* If it's not a syscall, we need to find the
460 * corresponding library symbol in the cloned
462 if (!elem->is_syscall && elem->c_un.libfunc != NULL) {
463 struct library_symbol *libfunc = elem->c_un.libfunc;
464 int rc = proc_find_symbol(retp, libfunc,
465 NULL, &elem->c_un.libfunc);
470 /* At this point, retp is fully initialized, except for OS and
471 * arch parts, and we can call private_process_destroy. */
472 if (os_process_clone(retp, proc) < 0) {
473 private_process_destroy(retp, 0);
476 if (arch_process_clone(retp, proc) < 0) {
477 os_process_destroy(retp);
478 private_process_destroy(retp, 0);
486 open_one_pid(pid_t pid)
488 debug(DEBUG_PROCESS, "open_one_pid(pid=%d)", pid);
490 /* Get the filename first. Should the trace_pid fail, we can
491 * easily free it, untracing is more work. */
492 char *filename = pid2name(pid);
493 if (filename == NULL || trace_pid(pid) < 0) {
499 struct process *proc = open_program(filename, pid);
503 trace_set_options(proc);
508 static enum callback_status
509 start_one_pid(struct process *proc, void *data)
511 continue_process(proc->pid);
515 static enum callback_status
516 is_main(struct process *proc, struct library *lib, void *data)
518 return CBS_STOP_IF(lib->type == LT_LIBTYPE_MAIN);
522 process_hit_start(struct process *proc)
524 struct process *leader = proc->leader;
525 assert(leader != NULL);
527 struct library *mainlib
528 = proc_each_library(leader, NULL, is_main, NULL);
529 assert(mainlib != NULL);
530 linkmap_init(leader, mainlib->dyn_addr);
531 arch_dynlink_done(leader);
537 debug(DEBUG_PROCESS, "open_pid(pid=%d)", pid);
538 /* If we are already tracing this guy, we should be seeing all
539 * his children via normal tracing route. */
540 if (pid2proc(pid) != NULL)
543 /* First, see if we can attach the requested PID itself. */
544 if (open_one_pid(pid) < 0) {
545 fprintf(stderr, "Cannot attach to pid %u: %s\n",
546 pid, strerror(errno));
547 trace_fail_warning(pid);
551 /* Now attach to all tasks that belong to that PID. There's a
552 * race between process_tasks and open_one_pid. So when we
553 * fail in open_one_pid below, we just do another round.
554 * Chances are that by then that PID will have gone away, and
555 * that's why we have seen the failure. The processes that we
556 * manage to open_one_pid are stopped, so we should eventually
557 * reach a point where process_tasks doesn't give any new
558 * processes (because there's nobody left to produce
560 size_t old_ntasks = 0;
567 if (process_tasks(pid, &tasks, &ntasks) < 0) {
568 fprintf(stderr, "Cannot obtain tasks of pid %u: %s\n",
569 pid, strerror(errno));
574 for (i = 0; i < ntasks; ++i)
575 if (pid2proc(tasks[i]) == NULL
576 && open_one_pid(tasks[i]) < 0)
581 if (have_all && old_ntasks == ntasks)
586 struct process *leader = pid2proc(pid)->leader;
588 /* XXX Is there a way to figure out whether _start has
589 * actually already been hit? */
590 process_hit_start(leader);
592 /* Done. Continue everyone. */
593 each_task(leader, NULL, start_one_pid, NULL);
596 static enum callback_status
597 find_proc(struct process *proc, void *data)
599 return CBS_STOP_IF(proc->pid == (pid_t)(uintptr_t)data);
605 return each_process(NULL, &find_proc, (void *)(uintptr_t)pid);
608 static struct process *list_of_processes = NULL;
611 unlist_process(struct process *proc)
613 if (list_of_processes == proc) {
614 list_of_processes = list_of_processes->next;
619 for (tmp = list_of_processes; ; tmp = tmp->next) {
620 /* If the following assert fails, the process wasn't
622 assert(tmp->next != NULL);
624 if (tmp->next == proc) {
625 tmp->next = tmp->next->next;
632 each_process(struct process *start_after,
633 enum callback_status(*cb)(struct process *proc, void *data),
636 struct process *it = start_after == NULL ? list_of_processes
640 /* Callback might call remove_process. */
641 struct process *next = it->next;
642 switch ((*cb)(it, data)) {
656 each_task(struct process *proc, struct process *start_after,
657 enum callback_status(*cb)(struct process *proc, void *data),
660 assert(proc != NULL);
661 struct process *it = start_after == NULL ? proc->leader
665 struct process *leader = it->leader;
666 while (it != NULL && it->leader == leader) {
667 /* Callback might call remove_process. */
668 struct process *next = it->next;
669 switch ((*cb)(it, data)) {
684 add_process(struct process *proc, int was_exec)
686 struct process **leaderp = &list_of_processes;
688 pid_t tgid = process_leader(proc->pid);
690 /* Must have been terminated before we managed
691 * to fully attach. */
693 if (tgid == proc->pid) {
696 struct process *leader = pid2proc(tgid);
697 proc->leader = leader;
699 leaderp = &leader->next;
704 proc->next = *leaderp;
711 change_process_leader(struct process *proc, struct process *leader)
713 struct process **leaderp = &list_of_processes;
714 if (proc->leader == leader)
717 assert(leader != NULL);
718 unlist_process(proc);
720 leaderp = &leader->next;
722 proc->leader = leader;
723 proc->next = *leaderp;
727 static enum callback_status
728 clear_leader(struct process *proc, void *data)
730 debug(DEBUG_FUNCTION, "detach_task %d from leader %d",
731 proc->pid, proc->leader->pid);
737 remove_process(struct process *proc)
739 debug(DEBUG_FUNCTION, "remove_proc(pid=%d)", proc->pid);
741 if (proc->leader == proc)
742 each_task(proc, NULL, &clear_leader, NULL);
744 unlist_process(proc);
745 process_removed(proc);
746 process_destroy(proc);
751 install_event_handler(struct process *proc, struct event_handler *handler)
753 debug(DEBUG_FUNCTION, "install_event_handler(pid=%d, %p)", proc->pid, handler);
754 assert(proc->event_handler == NULL);
755 proc->event_handler = handler;
759 destroy_event_handler(struct process *proc)
761 struct event_handler *handler = proc->event_handler;
762 debug(DEBUG_FUNCTION, "destroy_event_handler(pid=%d, %p)", proc->pid, handler);
763 assert(handler != NULL);
764 if (handler->destroy != NULL)
765 handler->destroy(handler);
767 proc->event_handler = NULL;
771 breakpoint_for_symbol(struct library_symbol *libsym, struct process *proc)
774 assert(proc->leader == proc);
776 /* Don't enable latent or delayed symbols. */
777 if (libsym->latent || libsym->delayed) {
778 debug(DEBUG_FUNCTION,
779 "delayed and/or latent breakpoint pid=%d, %s@%p",
780 proc->pid, libsym->name, libsym->enter_addr);
784 bp_addr = sym2addr(proc, libsym);
786 /* If there is an artificial breakpoint on the same address,
787 * its libsym will be NULL, and we can smuggle our libsym
788 * there. That artificial breakpoint is there presumably for
789 * the callbacks, which we don't touch. If there is a real
790 * breakpoint, then this is a bug. ltrace-elf.c should filter
791 * symbols and ignore extra symbol aliases.
793 * The other direction is more complicated and currently not
794 * supported. If a breakpoint has custom callbacks, it might
795 * be also custom-allocated, and we would really need to swap
796 * the two: delete the one now in the dictionary, swap values
797 * around, and put the new breakpoint back in. */
798 struct breakpoint *bp;
799 if (DICT_FIND_VAL(proc->breakpoints, &bp_addr, &bp) == 0) {
800 /* MIPS backend makes duplicate requests. This is
801 * likely a bug in the backend. Currently there's no
802 * point assigning more than one symbol to a
803 * breakpoint, because when it hits, we won't know
804 * what to print out. But it's easier to fix it here
805 * before someone who understands MIPS has the time to
806 * look into it. So turn the sanity check off on
809 * http://lists.alioth.debian.org/pipermail/ltrace-devel/2012-November/000764.html
810 * http://lists.alioth.debian.org/pipermail/ltrace-devel/2012-November/000770.html
813 assert(bp->libsym == NULL);
819 bp = malloc(sizeof(*bp));
821 || breakpoint_init(bp, proc, bp_addr, libsym) < 0) {
826 if (proc_add_breakpoint(proc, bp) < 0) {
827 breakpoint_destroy(bp);
831 if (breakpoint_turn_on(bp, proc) < 0) {
832 proc_remove_breakpoint(proc, bp);
833 breakpoint_destroy(bp);
840 static enum callback_status
841 cb_breakpoint_for_symbol(struct library_symbol *libsym, void *data)
843 return CBS_STOP_IF(breakpoint_for_symbol(libsym, data) < 0);
847 proc_activate_latent_symbol(struct process *proc,
848 struct library_symbol *libsym)
850 assert(libsym->latent);
852 debug(DEBUG_FUNCTION, "activated latent symbol");
853 return breakpoint_for_symbol(libsym, proc);
857 proc_activate_delayed_symbol(struct process *proc,
858 struct library_symbol *libsym)
860 assert(libsym->delayed);
862 debug(DEBUG_FUNCTION, "activated delayed symbol");
863 return breakpoint_for_symbol(libsym, proc);
866 static enum callback_status
867 activate_latent_in(struct process *proc, struct library *lib, void *data)
869 struct library_exported_name *exported;
870 for (exported = data; exported != NULL; exported = exported->next) {
871 struct library_symbol *libsym = NULL;
872 while ((libsym = library_each_symbol(lib, libsym,
873 library_symbol_named_cb,
874 (void *)exported->name))
877 && proc_activate_latent_symbol(proc, libsym) < 0)
884 proc_add_library(struct process *proc, struct library *lib)
886 assert(lib->next == NULL);
887 lib->next = proc->libraries;
888 proc->libraries = lib;
889 debug(DEBUG_PROCESS, "added library %s@%p (%s) to %d",
890 lib->soname, lib->base, lib->pathname, proc->pid);
892 #if defined(HAVE_LIBDW)
893 if (options.bt_depth > 0) {
894 /* Setup module tracking for libdwfl unwinding. */
895 struct process *leader = proc->leader;
896 Dwfl *dwfl = leader->dwfl;
898 static const Dwfl_Callbacks proc_callbacks = {
899 .find_elf = dwfl_linux_proc_find_elf,
900 .find_debuginfo = dwfl_standard_find_debuginfo
902 dwfl = dwfl_begin(&proc_callbacks);
905 "Couldn't initialize libdwfl unwinding "
906 "for process %d: %s\n", leader->pid,
911 dwfl_report_begin_add(dwfl);
912 if (dwfl_report_elf(dwfl, lib->soname,
914 (GElf_Addr) lib->base,
917 "dwfl_report_elf %s@%p (%s) %d: %s\n",
918 lib->soname, lib->base, lib->pathname,
919 proc->pid, dwfl_errmsg (-1));
920 dwfl_report_end(dwfl, NULL, NULL);
922 if (leader->dwfl == NULL) {
923 int r = dwfl_linux_proc_attach(dwfl,
932 msg = dwfl_errmsg(-1);
935 fprintf(stderr, "Couldn't initialize "
936 "libdwfl unwinding for "
943 #endif /* defined(HAVE_LIBDW) */
945 /* Insert breakpoints for all active (non-latent) symbols. */
946 struct library_symbol *libsym = NULL;
947 while ((libsym = library_each_symbol(lib, libsym,
948 cb_breakpoint_for_symbol,
951 "Couldn't insert breakpoint for %s to %d: %s.\n",
952 libsym->name, proc->pid, strerror(errno));
954 /* Look through export list of the new library and compare it
955 * with latent symbols of all libraries (including this
956 * library itself). */
957 struct library *lib2 = NULL;
958 while ((lib2 = proc_each_library(proc, lib2, activate_latent_in,
959 lib->exported_names)) != NULL)
961 "Couldn't activate latent symbols for %s in %d: %s.\n",
962 lib2->soname, proc->pid, strerror(errno));
966 proc_remove_library(struct process *proc, struct library *lib)
968 struct library **libp;
969 for (libp = &proc->libraries; *libp != NULL; libp = &(*libp)->next)
978 proc_each_library(struct process *proc, struct library *it,
979 enum callback_status (*cb)(struct process *proc,
980 struct library *lib, void *data),
984 it = proc->libraries;
989 struct library *next = it->next;
991 switch (cb(proc, it, data)) {
1007 check_leader(struct process *proc)
1009 /* Only the group leader should be getting the breakpoints and
1010 * thus have ->breakpoint initialized. */
1011 assert(proc->leader != NULL);
1012 assert(proc->leader == proc);
1013 assert(proc->breakpoints != NULL);
1017 proc_add_breakpoint(struct process *proc, struct breakpoint *bp)
1019 debug(DEBUG_FUNCTION, "proc_add_breakpoint(pid=%d, %s@%p)",
1020 proc->pid, breakpoint_name(bp), bp->addr);
1023 /* XXX We might merge bp->libsym instead of the following
1024 * assert, but that's not necessary right now. Read the
1025 * comment in breakpoint_for_symbol. */
1026 assert(dict_find(proc->breakpoints, &bp->addr) == NULL);
1028 if (DICT_INSERT(proc->breakpoints, &bp->addr, &bp) < 0) {
1030 "couldn't enter breakpoint %s@%p to dictionary: %s\n",
1031 breakpoint_name(bp), bp->addr, strerror(errno));
1039 proc_remove_breakpoint(struct process *proc, struct breakpoint *bp)
1041 debug(DEBUG_FUNCTION, "proc_remove_breakpoint(pid=%d, %s@%p)",
1042 proc->pid, breakpoint_name(bp), bp->addr);
1044 int rc = DICT_ERASE(proc->breakpoints, &bp->addr, struct breakpoint *,
1049 struct each_breakpoint_data
1051 struct process *proc;
1052 enum callback_status (*cb)(struct process *proc,
1053 struct breakpoint *bp,
1058 static enum callback_status
1059 each_breakpoint_cb(arch_addr_t *key, struct breakpoint **bpp, void *d)
1061 struct each_breakpoint_data *data = d;
1062 return data->cb(data->proc, *bpp, data->cb_data);
1066 proc_each_breakpoint(struct process *proc, arch_addr_t *start,
1067 enum callback_status (*cb)(struct process *proc,
1068 struct breakpoint *bp,
1069 void *data), void *data)
1071 struct each_breakpoint_data dd = {
1076 return DICT_EACH(proc->breakpoints,
1077 arch_addr_t, struct breakpoint *, start,
1078 &each_breakpoint_cb, &dd);
1082 proc_find_symbol(struct process *proc, struct library_symbol *sym,
1083 struct library **retlib, struct library_symbol **retsym)
1085 struct library *lib = sym->lib;
1086 assert(lib != NULL);
1088 struct library *flib
1089 = proc_each_library(proc, NULL, library_with_key_cb, &lib->key);
1093 struct library_symbol *fsym
1094 = library_each_symbol(flib, NULL, library_symbol_named_cb,
1107 struct library_symbol *
1108 proc_each_symbol(struct process *proc, struct library_symbol *start_after,
1109 enum callback_status (*cb)(struct library_symbol *, void *),
1112 struct library *lib;
1113 for (lib = start_after != NULL ? start_after->lib : proc->libraries;
1114 lib != NULL; lib = lib->next) {
1115 start_after = library_each_symbol(lib, start_after, cb, data);
1116 if (start_after != NULL)
1123 #define DEF_READER(NAME, SIZE) \
1125 NAME(struct process *proc, arch_addr_t addr, \
1126 uint##SIZE##_t *lp) \
1129 uint##SIZE##_t dst; \
1132 if (umovebytes(proc, addr, &u.buf, sizeof(u.dst)) \
1139 DEF_READER(proc_read_8, 8)
1140 DEF_READER(proc_read_16, 16)
1141 DEF_READER(proc_read_32, 32)
1142 DEF_READER(proc_read_64, 64)