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"
39 #include "dwarf_prototypes.h"
41 #ifndef OS_HAVE_PROCESS_DATA
43 os_process_init(struct process *proc)
49 os_process_destroy(struct process *proc)
54 os_process_clone(struct process *retp, struct process *proc)
60 os_process_exec(struct process *proc)
66 #ifndef ARCH_HAVE_PROCESS_DATA
68 arch_process_init(struct process *proc)
74 arch_process_destroy(struct process *proc)
79 arch_process_clone(struct process *retp, struct process *proc)
85 arch_process_exec(struct process *proc)
91 #ifndef ARCH_HAVE_DYNLINK_DONE
93 arch_dynlink_done(struct process *proc)
98 static int add_process(struct process *proc, int was_exec);
99 static void unlist_process(struct process *proc);
102 destroy_unwind(struct process *proc)
104 #if defined(HAVE_LIBUNWIND)
105 if (proc->unwind_priv != NULL)
106 _UPT_destroy(proc->unwind_priv);
107 if (proc->unwind_as != NULL)
108 unw_destroy_addr_space(proc->unwind_as);
109 #endif /* defined(HAVE_LIBUNWIND) */
111 #if defined(HAVE_LIBDW)
112 if (proc->dwfl != NULL)
113 dwfl_end(proc->dwfl);
114 #endif /* defined(HAVE_LIBDW) */
118 process_bare_init(struct process *proc, const char *filename,
119 pid_t pid, int was_exec)
122 memset(proc, 0, sizeof(*proc));
124 proc->filename = strdup(filename);
125 if (proc->filename == NULL) {
127 free(proc->filename);
128 if (proc->breakpoints != NULL) {
129 dict_destroy(proc->breakpoints,
131 free(proc->breakpoints);
132 proc->breakpoints = NULL;
138 /* Add process so that we know who the leader is. */
140 if (add_process(proc, was_exec) < 0)
142 if (proc->leader == NULL) {
145 unlist_process(proc);
149 if (proc->leader == proc) {
150 proc->breakpoints = malloc(sizeof(*proc->breakpoints));
151 if (proc->breakpoints == NULL)
152 goto unlist_and_fail;
153 DICT_INIT(proc->breakpoints,
154 arch_addr_t, struct breakpoint *,
155 arch_addr_hash, arch_addr_eq, NULL);
157 proc->breakpoints = NULL;
160 #if defined(HAVE_LIBUNWIND)
161 if (options.bt_depth > 0) {
162 proc->unwind_priv = _UPT_create(pid);
163 proc->unwind_as = unw_create_addr_space(&_UPT_accessors, 0);
165 if (proc->unwind_priv == NULL || proc->unwind_as == NULL) {
167 "Couldn't initialize unwinding "
168 "for process %d\n", proc->pid);
169 destroy_unwind(proc);
170 proc->unwind_priv = NULL;
171 proc->unwind_as = NULL;
174 #endif /* defined(HAVE_LIBUNWIND) */
176 #if defined(HAVE_LIBDW)
177 proc->dwfl = NULL; /* Initialize for leader only on first library. */
178 proc->should_attach_dwfl = 1; /* should try to attach the DWFL data */
179 #endif /* defined(HAVE_LIBDW) */
185 process_bare_destroy(struct process *proc, int was_exec)
187 dict_destroy(proc->breakpoints, NULL, NULL, NULL);
188 free(proc->breakpoints);
190 free(proc->filename);
191 unlist_process(proc);
192 destroy_unwind(proc);
197 process_init_main(struct process *proc)
199 if (breakpoints_init(proc) < 0) {
200 fprintf(stderr, "failed to init breakpoints %d\n",
209 process_init(struct process *proc, const char *filename, pid_t pid)
211 if (process_bare_init(proc, filename, pid, 0) < 0) {
213 fprintf(stderr, "failed to initialize process %d: %s\n",
214 pid, strerror(errno));
218 if (os_process_init(proc) < 0) {
219 process_bare_destroy(proc, 0);
223 if (arch_process_init(proc) < 0) {
224 os_process_destroy(proc);
225 process_bare_destroy(proc, 0);
229 if (proc->leader != proc) {
230 proc->e_machine = proc->leader->e_machine;
231 proc->e_class = proc->leader->e_class;
233 } else if (process_init_main(proc) < 0) {
234 process_bare_destroy(proc, 0);
240 static enum callback_status
241 destroy_breakpoint_cb(struct process *proc, struct breakpoint *bp, void *data)
243 breakpoint_destroy(bp);
248 // XXX see comment in handle_event.c
249 void callstack_pop(struct process *proc);
252 private_process_destroy(struct process *proc, int was_exec)
254 /* Pop remaining stack elements. */
255 while (proc->callstack_depth > 0) {
256 /* When this is called just before a process is
257 * destroyed, the breakpoints should either have been
258 * retracted by now, or were killed by exec. In any
259 * case, it's safe to pretend that there are no
260 * breakpoints associated with the stack elements, so
261 * that stack_pop doesn't attempt to destroy them. */
262 size_t i = proc->callstack_depth - 1;
263 if (!proc->callstack[i].is_syscall)
264 proc->callstack[i].return_addr = 0;
270 free(proc->filename);
272 /* Libraries and symbols. This is only relevant in
275 for (lib = proc->libraries; lib != NULL; ) {
276 struct library *next = lib->next;
277 library_destroy(lib);
281 proc->libraries = NULL;
284 if (proc->breakpoints != NULL) {
285 proc_each_breakpoint(proc, NULL, destroy_breakpoint_cb, NULL);
286 dict_destroy(proc->breakpoints, NULL, NULL, NULL);
287 free(proc->breakpoints);
288 proc->breakpoints = NULL;
291 destroy_unwind(proc);
295 process_destroy(struct process *proc)
297 arch_process_destroy(proc);
298 os_process_destroy(proc);
299 private_process_destroy(proc, 0);
303 process_exec(struct process *proc)
305 /* Call exec handlers first, before we destroy the main
307 if (arch_process_exec(proc) < 0
308 || os_process_exec(proc) < 0)
311 private_process_destroy(proc, 1);
313 if (process_bare_init(proc, NULL, proc->pid, 1) < 0)
315 if (process_init_main(proc) < 0) {
316 process_bare_destroy(proc, 1);
323 open_program(const char *filename, pid_t pid)
326 struct process *proc = malloc(sizeof(*proc));
327 if (proc == NULL || process_init(proc, filename, pid) < 0) {
334 struct clone_single_bp_data {
335 struct process *old_proc;
336 struct process *new_proc;
339 static enum callback_status
340 clone_single_bp(arch_addr_t *key, struct breakpoint **bpp, void *u)
342 struct breakpoint *bp = *bpp;
343 struct clone_single_bp_data *data = u;
345 struct breakpoint *clone = malloc(sizeof(*clone));
347 || breakpoint_clone(clone, data->new_proc, bp) < 0) {
352 if (proc_add_breakpoint(data->new_proc->leader, clone) < 0) {
353 breakpoint_destroy(clone);
360 process_clone(struct process *retp, struct process *proc, pid_t pid)
362 if (process_bare_init(retp, proc->filename, pid, 0) < 0) {
364 fprintf(stderr, "Failed to clone process %d to %d: %s\n",
365 proc->pid, pid, strerror(errno));
369 retp->tracesysgood = proc->tracesysgood;
370 retp->e_machine = proc->e_machine;
371 retp->e_class = proc->e_class;
373 /* For non-leader processes, that's all we need to do. */
374 if (retp->leader != retp)
377 /* Clone symbols first so that we can clone and relink
380 struct library **nlibp = &retp->libraries;
381 for (lib = proc->leader->libraries; lib != NULL; lib = lib->next) {
382 *nlibp = malloc(sizeof(**nlibp));
385 || library_clone(*nlibp, lib) < 0) {
390 process_bare_destroy(retp, 0);
392 /* Error when cloning. Unroll what was done. */
393 for (lib = retp->libraries; lib != NULL; ) {
394 struct library *next = lib->next;
395 library_destroy(lib);
402 nlibp = &(*nlibp)->next;
405 /* Now clone breakpoints. Symbol relinking is done in
406 * clone_single_bp. */
407 struct clone_single_bp_data data = {
411 if (DICT_EACH(proc->leader->breakpoints,
412 arch_addr_t, struct breakpoint *, NULL,
413 clone_single_bp, &data) != NULL)
416 /* And finally the call stack. */
417 /* XXX clearly the callstack handling should be moved to a
418 * separate module and this whole business extracted to
419 * callstack_clone, or callstack_element_clone. */
420 memcpy(retp->callstack, proc->callstack, sizeof(retp->callstack));
421 retp->callstack_depth = proc->callstack_depth;
424 for (i = 0; i < retp->callstack_depth; ++i) {
425 struct callstack_element *elem = &retp->callstack[i];
426 struct fetch_context *ctx = elem->fetch_context;
428 struct fetch_context *nctx = fetch_arg_clone(retp, ctx);
432 for (j = 0; j < i; ++j) {
433 nctx = retp->callstack[j].fetch_context;
434 fetch_arg_done(nctx);
435 elem->fetch_context = NULL;
439 elem->fetch_context = nctx;
442 if (elem->arguments != NULL) {
443 struct value_dict *nargs = malloc(sizeof(*nargs));
445 || val_dict_clone(nargs, elem->arguments) < 0) {
447 for (j = 0; j < i; ++j) {
448 nargs = retp->callstack[j].arguments;
449 val_dict_destroy(nargs);
451 elem->arguments = NULL;
454 /* Pretend that this round went well,
455 * so that fail3 frees I-th
460 elem->arguments = nargs;
463 /* If it's not a syscall, we need to find the
464 * corresponding library symbol in the cloned
466 if (!elem->is_syscall && elem->c_un.libfunc != NULL) {
467 struct library_symbol *libfunc = elem->c_un.libfunc;
468 int rc = proc_find_symbol(retp, libfunc,
469 NULL, &elem->c_un.libfunc);
474 /* At this point, retp is fully initialized, except for OS and
475 * arch parts, and we can call private_process_destroy. */
476 if (os_process_clone(retp, proc) < 0) {
477 private_process_destroy(retp, 0);
480 if (arch_process_clone(retp, proc) < 0) {
481 os_process_destroy(retp);
482 private_process_destroy(retp, 0);
490 open_one_pid(pid_t pid)
492 debug(DEBUG_PROCESS, "open_one_pid(pid=%d)", pid);
494 /* Get the filename first. Should the trace_pid fail, we can
495 * easily free it, untracing is more work. */
496 char *filename = pid2name(pid);
497 if (filename == NULL || trace_pid(pid) < 0) {
503 struct process *proc = open_program(filename, pid);
507 trace_set_options(proc);
512 static enum callback_status
513 start_one_pid(struct process *proc, void *data)
515 continue_process(proc->pid);
519 static enum callback_status
520 is_main(struct process *proc, struct library *lib, void *data)
522 return CBS_STOP_IF(lib->type == LT_LIBTYPE_MAIN);
526 process_hit_start(struct process *proc)
528 struct process *leader = proc->leader;
529 assert(leader != NULL);
531 struct library *mainlib
532 = proc_each_library(leader, NULL, is_main, NULL);
533 assert(mainlib != NULL);
534 linkmap_init(leader, mainlib->dyn_addr);
535 arch_dynlink_done(leader);
541 debug(DEBUG_PROCESS, "open_pid(pid=%d)", pid);
542 /* If we are already tracing this guy, we should be seeing all
543 * his children via normal tracing route. */
544 if (pid2proc(pid) != NULL)
547 /* First, see if we can attach the requested PID itself. */
548 if (open_one_pid(pid) < 0) {
549 fprintf(stderr, "Cannot attach to pid %u: %s\n",
550 pid, strerror(errno));
551 trace_fail_warning(pid);
555 /* Now attach to all tasks that belong to that PID. There's a
556 * race between process_tasks and open_one_pid. So when we
557 * fail in open_one_pid below, we just do another round.
558 * Chances are that by then that PID will have gone away, and
559 * that's why we have seen the failure. The processes that we
560 * manage to open_one_pid are stopped, so we should eventually
561 * reach a point where process_tasks doesn't give any new
562 * processes (because there's nobody left to produce
564 size_t old_ntasks = 0;
571 if (process_tasks(pid, &tasks, &ntasks) < 0) {
572 fprintf(stderr, "Cannot obtain tasks of pid %u: %s\n",
573 pid, strerror(errno));
578 for (i = 0; i < ntasks; ++i)
579 if (pid2proc(tasks[i]) == NULL
580 && open_one_pid(tasks[i]) < 0)
585 if (have_all && old_ntasks == ntasks)
590 struct process *leader = pid2proc(pid)->leader;
592 /* XXX Is there a way to figure out whether _start has
593 * actually already been hit? */
594 process_hit_start(leader);
596 /* Done. Continue everyone. */
597 each_task(leader, NULL, start_one_pid, NULL);
600 static enum callback_status
601 find_proc(struct process *proc, void *data)
603 return CBS_STOP_IF(proc->pid == (pid_t)(uintptr_t)data);
609 return each_process(NULL, &find_proc, (void *)(uintptr_t)pid);
612 static struct process *list_of_processes = NULL;
615 unlist_process(struct process *proc)
617 if (list_of_processes == proc) {
618 list_of_processes = list_of_processes->next;
623 for (tmp = list_of_processes; ; tmp = tmp->next) {
624 /* If the following assert fails, the process wasn't
626 assert(tmp->next != NULL);
628 if (tmp->next == proc) {
629 tmp->next = tmp->next->next;
636 each_process(struct process *start_after,
637 enum callback_status(*cb)(struct process *proc, void *data),
640 struct process *it = start_after == NULL ? list_of_processes
644 /* Callback might call remove_process. */
645 struct process *next = it->next;
646 switch ((*cb)(it, data)) {
660 each_task(struct process *proc, struct process *start_after,
661 enum callback_status(*cb)(struct process *proc, void *data),
664 assert(proc != NULL);
665 struct process *it = start_after == NULL ? proc->leader
669 struct process *leader = it->leader;
670 while (it != NULL && it->leader == leader) {
671 /* Callback might call remove_process. */
672 struct process *next = it->next;
673 switch ((*cb)(it, data)) {
688 add_process(struct process *proc, int was_exec)
690 struct process **leaderp = &list_of_processes;
692 pid_t tgid = process_leader(proc->pid);
694 /* Must have been terminated before we managed
695 * to fully attach. */
697 if (tgid == proc->pid) {
700 struct process *leader = pid2proc(tgid);
701 proc->leader = leader;
703 leaderp = &leader->next;
708 proc->next = *leaderp;
715 change_process_leader(struct process *proc, struct process *leader)
717 struct process **leaderp = &list_of_processes;
718 if (proc->leader == leader)
721 assert(leader != NULL);
722 unlist_process(proc);
724 leaderp = &leader->next;
726 proc->leader = leader;
727 proc->next = *leaderp;
731 static enum callback_status
732 clear_leader(struct process *proc, void *data)
734 debug(DEBUG_FUNCTION, "detach_task %d from leader %d",
735 proc->pid, proc->leader->pid);
741 remove_process(struct process *proc)
743 debug(DEBUG_FUNCTION, "remove_proc(pid=%d)", proc->pid);
745 if (proc->leader == proc)
746 each_task(proc, NULL, &clear_leader, NULL);
748 unlist_process(proc);
749 process_removed(proc);
750 process_destroy(proc);
755 install_event_handler(struct process *proc, struct event_handler *handler)
757 debug(DEBUG_FUNCTION, "install_event_handler(pid=%d, %p)", proc->pid, handler);
758 assert(proc->event_handler == NULL);
759 proc->event_handler = handler;
763 destroy_event_handler(struct process *proc)
765 struct event_handler *handler = proc->event_handler;
766 debug(DEBUG_FUNCTION, "destroy_event_handler(pid=%d, %p)", proc->pid, handler);
767 assert(handler != NULL);
768 if (handler->destroy != NULL)
769 handler->destroy(handler);
771 proc->event_handler = NULL;
775 breakpoint_for_symbol(struct library_symbol *libsym, struct process *proc)
778 assert(proc->leader == proc);
780 /* Don't enable latent or delayed symbols. */
781 if (libsym->latent || libsym->delayed) {
782 debug(DEBUG_FUNCTION,
783 "delayed and/or latent breakpoint pid=%d, %s@%p",
784 proc->pid, libsym->name, libsym->enter_addr);
788 bp_addr = sym2addr(proc, libsym);
790 /* If there is an artificial breakpoint on the same address,
791 * its libsym will be NULL, and we can smuggle our libsym
792 * there. That artificial breakpoint is there presumably for
793 * the callbacks, which we don't touch. If there is a real
794 * breakpoint, then this is a bug. ltrace-elf.c should filter
795 * symbols and ignore extra symbol aliases.
797 * The other direction is more complicated and currently not
798 * supported. If a breakpoint has custom callbacks, it might
799 * be also custom-allocated, and we would really need to swap
800 * the two: delete the one now in the dictionary, swap values
801 * around, and put the new breakpoint back in. */
802 struct breakpoint *bp;
803 if (DICT_FIND_VAL(proc->breakpoints, &bp_addr, &bp) == 0) {
804 /* MIPS backend makes duplicate requests. This is
805 * likely a bug in the backend. Currently there's no
806 * point assigning more than one symbol to a
807 * breakpoint, because when it hits, we won't know
808 * what to print out. But it's easier to fix it here
809 * before someone who understands MIPS has the time to
810 * look into it. So turn the sanity check off on
813 * http://lists.alioth.debian.org/pipermail/ltrace-devel/2012-November/000764.html
814 * http://lists.alioth.debian.org/pipermail/ltrace-devel/2012-November/000770.html
817 assert(bp->libsym == NULL);
823 bp = malloc(sizeof(*bp));
825 || breakpoint_init(bp, proc, bp_addr, libsym) < 0) {
830 if (proc_add_breakpoint(proc, bp) < 0) {
831 breakpoint_destroy(bp);
835 if (breakpoint_turn_on(bp, proc) < 0) {
836 proc_remove_breakpoint(proc, bp);
837 breakpoint_destroy(bp);
844 static enum callback_status
845 cb_breakpoint_for_symbol(struct library_symbol *libsym, void *data)
847 return CBS_STOP_IF(breakpoint_for_symbol(libsym, data) < 0);
851 proc_activate_latent_symbol(struct process *proc,
852 struct library_symbol *libsym)
854 assert(libsym->latent);
856 debug(DEBUG_FUNCTION, "activated latent symbol");
857 return breakpoint_for_symbol(libsym, proc);
861 proc_activate_delayed_symbol(struct process *proc,
862 struct library_symbol *libsym)
864 assert(libsym->delayed);
866 debug(DEBUG_FUNCTION, "activated delayed symbol");
867 return breakpoint_for_symbol(libsym, proc);
870 static enum callback_status
871 activate_latent_in(struct process *proc, struct library *lib, void *data)
873 struct library_exported_name *exported;
874 for (exported = data; exported != NULL; exported = exported->next) {
875 struct library_symbol *libsym = NULL;
876 while ((libsym = library_each_symbol(lib, libsym,
877 library_symbol_named_cb,
878 (void *)exported->name))
881 && proc_activate_latent_symbol(proc, libsym) < 0)
888 proc_add_library(struct process *proc, struct library *lib)
890 assert(lib->next == NULL);
891 lib->next = proc->libraries;
892 proc->libraries = lib;
893 debug(DEBUG_PROCESS, "added library %s@%p (%s) to %d",
894 lib->soname, lib->base, lib->pathname, proc->pid);
896 #if defined(HAVE_LIBDW)
898 Dwfl_Module *dwfl_module = NULL;
900 /* Setup module tracking for libdwfl unwinding. */
901 struct process *leader = proc->leader;
904 static const Dwfl_Callbacks proc_callbacks = {
905 .find_elf = dwfl_linux_proc_find_elf,
906 .find_debuginfo = dwfl_standard_find_debuginfo
908 dwfl = dwfl_begin(&proc_callbacks);
911 "Couldn't initialize libdwfl unwinding "
912 "for process %d: %s\n", leader->pid,
917 dwfl_report_begin_add(dwfl);
919 dwfl_report_elf(dwfl, lib->soname,
921 (GElf_Addr) lib->base,
923 if (dwfl_module == NULL)
925 "dwfl_report_elf %s@%p (%s) %d: %s\n",
926 lib->soname, lib->base, lib->pathname,
927 proc->pid, dwfl_errmsg (-1));
929 dwfl_report_end(dwfl, NULL, NULL);
931 if (options.bt_depth > 0) {
932 if (proc->should_attach_dwfl) {
933 int r = dwfl_linux_proc_attach(dwfl,
936 proc->should_attach_dwfl = 0;
941 msg = dwfl_errmsg(-1);
944 fprintf(stderr, "Couldn't initialize "
945 "libdwfl (unwinding, prototype "
946 "import) for process %d: %s\n",
953 lib->dwfl_module = dwfl_module;
956 #endif /* defined(HAVE_LIBDW) */
958 /* Insert breakpoints for all active (non-latent) symbols. */
959 struct library_symbol *libsym = NULL;
960 while ((libsym = library_each_symbol(lib, libsym,
961 cb_breakpoint_for_symbol,
964 "Couldn't insert breakpoint for %s to %d: %s.\n",
965 libsym->name, proc->pid, strerror(errno));
967 /* Look through export list of the new library and compare it
968 * with latent symbols of all libraries (including this
969 * library itself). */
970 struct library *lib2 = NULL;
971 while ((lib2 = proc_each_library(proc, lib2, activate_latent_in,
972 lib->exported_names)) != NULL)
974 "Couldn't activate latent symbols for %s in %d: %s.\n",
975 lib2->soname, proc->pid, strerror(errno));
979 proc_remove_library(struct process *proc, struct library *lib)
981 struct library **libp;
982 for (libp = &proc->libraries; *libp != NULL; libp = &(*libp)->next)
991 proc_each_library(struct process *proc, struct library *it,
992 enum callback_status (*cb)(struct process *proc,
993 struct library *lib, void *data),
997 it = proc->libraries;
1001 while (it != NULL) {
1002 struct library *next = it->next;
1004 switch (cb(proc, it, data)) {
1020 check_leader(struct process *proc)
1022 /* Only the group leader should be getting the breakpoints and
1023 * thus have ->breakpoint initialized. */
1024 assert(proc->leader != NULL);
1025 assert(proc->leader == proc);
1026 assert(proc->breakpoints != NULL);
1030 proc_add_breakpoint(struct process *proc, struct breakpoint *bp)
1032 debug(DEBUG_FUNCTION, "proc_add_breakpoint(pid=%d, %s@%p)",
1033 proc->pid, breakpoint_name(bp), bp->addr);
1036 /* XXX We might merge bp->libsym instead of the following
1037 * assert, but that's not necessary right now. Read the
1038 * comment in breakpoint_for_symbol. */
1039 assert(dict_find(proc->breakpoints, &bp->addr) == NULL);
1041 if (DICT_INSERT(proc->breakpoints, &bp->addr, &bp) < 0) {
1043 "couldn't enter breakpoint %s@%p to dictionary: %s\n",
1044 breakpoint_name(bp), bp->addr, strerror(errno));
1052 proc_remove_breakpoint(struct process *proc, struct breakpoint *bp)
1054 debug(DEBUG_FUNCTION, "proc_remove_breakpoint(pid=%d, %s@%p)",
1055 proc->pid, breakpoint_name(bp), bp->addr);
1057 int rc = DICT_ERASE(proc->breakpoints, &bp->addr, struct breakpoint *,
1062 struct each_breakpoint_data
1064 struct process *proc;
1065 enum callback_status (*cb)(struct process *proc,
1066 struct breakpoint *bp,
1071 static enum callback_status
1072 each_breakpoint_cb(arch_addr_t *key, struct breakpoint **bpp, void *d)
1074 struct each_breakpoint_data *data = d;
1075 return data->cb(data->proc, *bpp, data->cb_data);
1079 proc_each_breakpoint(struct process *proc, arch_addr_t *start,
1080 enum callback_status (*cb)(struct process *proc,
1081 struct breakpoint *bp,
1082 void *data), void *data)
1084 struct each_breakpoint_data dd = {
1089 return DICT_EACH(proc->breakpoints,
1090 arch_addr_t, struct breakpoint *, start,
1091 &each_breakpoint_cb, &dd);
1095 proc_find_symbol(struct process *proc, struct library_symbol *sym,
1096 struct library **retlib, struct library_symbol **retsym)
1098 struct library *lib = sym->lib;
1099 assert(lib != NULL);
1101 struct library *flib
1102 = proc_each_library(proc, NULL, library_with_key_cb, &lib->key);
1106 struct library_symbol *fsym
1107 = library_each_symbol(flib, NULL, library_symbol_named_cb,
1120 struct library_symbol *
1121 proc_each_symbol(struct process *proc, struct library_symbol *start_after,
1122 enum callback_status (*cb)(struct library_symbol *, void *),
1125 struct library *lib;
1126 for (lib = start_after != NULL ? start_after->lib : proc->libraries;
1127 lib != NULL; lib = lib->next) {
1128 start_after = library_each_symbol(lib, start_after, cb, data);
1129 if (start_after != NULL)
1136 #define DEF_READER(NAME, SIZE) \
1138 NAME(struct process *proc, arch_addr_t addr, \
1139 uint##SIZE##_t *lp) \
1142 uint##SIZE##_t dst; \
1145 if (umovebytes(proc, addr, &u.buf, sizeof(u.dst)) \
1152 DEF_READER(proc_read_8, 8)
1153 DEF_READER(proc_read_16, 16)
1154 DEF_READER(proc_read_32, 32)
1155 DEF_READER(proc_read_64, 64)