proc.c revision ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bda
1/* 2 * This file is part of ltrace. 3 * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc. 4 * Copyright (C) 2010 Joe Damato 5 * Copyright (C) 1998,2009 Juan Cespedes 6 * 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. 11 * 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. 16 * 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 20 * 02110-1301 USA 21 */ 22 23#include "config.h" 24 25#include <sys/types.h> 26#include <assert.h> 27#include <errno.h> 28#include <stdio.h> 29#include <stdlib.h> 30#include <string.h> 31 32#if defined(HAVE_LIBUNWIND) 33#include <libunwind.h> 34#include <libunwind-ptrace.h> 35#endif /* defined(HAVE_LIBUNWIND) */ 36 37#include "backend.h" 38#include "breakpoint.h" 39#include "debug.h" 40#include "fetch.h" 41#include "proc.h" 42#include "value_dict.h" 43 44#ifndef ARCH_HAVE_PROCESS_DATA 45int 46arch_process_init(struct Process *proc) 47{ 48 return 0; 49} 50 51void 52arch_process_destroy(struct Process *proc) 53{ 54} 55 56int 57arch_process_clone(struct Process *retp, struct Process *proc) 58{ 59 return 0; 60} 61 62int 63arch_process_exec(struct Process *proc) 64{ 65 return 0; 66} 67#endif 68 69#ifndef ARCH_HAVE_DYNLINK_DONE 70void 71arch_dynlink_done(struct Process *proc) 72{ 73} 74#endif 75 76static void add_process(struct Process *proc, int was_exec); 77static void unlist_process(struct Process *proc); 78 79static int 80process_bare_init(struct Process *proc, const char *filename, 81 pid_t pid, int was_exec) 82{ 83 if (!was_exec) { 84 memset(proc, 0, sizeof(*proc)); 85 86 proc->filename = strdup(filename); 87 if (proc->filename == NULL) { 88 fail: 89 free(proc->filename); 90 if (proc->breakpoints != NULL) 91 dict_clear(proc->breakpoints); 92 return -1; 93 } 94 } 95 96 /* Add process so that we know who the leader is. */ 97 proc->pid = pid; 98 add_process(proc, was_exec); 99 if (proc->leader == NULL) 100 goto fail; 101 102 if (proc->leader == proc) { 103 proc->breakpoints = dict_init(target_address_hash, 104 target_address_cmp); 105 if (proc->breakpoints == NULL) 106 goto fail; 107 } else { 108 proc->breakpoints = NULL; 109 } 110 111#if defined(HAVE_LIBUNWIND) 112 proc->unwind_priv = _UPT_create(pid); 113 proc->unwind_as = unw_create_addr_space(&_UPT_accessors, 0); 114#endif /* defined(HAVE_LIBUNWIND) */ 115 116 return 0; 117} 118 119static void 120process_bare_destroy(struct Process *proc, int was_exec) 121{ 122 dict_clear(proc->breakpoints); 123 if (!was_exec) { 124 free(proc->filename); 125 unlist_process(proc); 126 } 127} 128 129static int 130process_init_main(struct Process *proc) 131{ 132 if (breakpoints_init(proc) < 0) { 133 fprintf(stderr, "failed to init breakpoints %d\n", 134 proc->pid); 135 return -1; 136 } 137 138 return 0; 139} 140 141int 142process_init(struct Process *proc, const char *filename, pid_t pid) 143{ 144 if (process_bare_init(proc, filename, pid, 0) < 0) { 145 fail: 146 fprintf(stderr, "failed to initialize process %d: %s\n", 147 pid, strerror(errno)); 148 return -1; 149 } 150 151 if (arch_process_init(proc) < 0) { 152 process_bare_destroy(proc, 0); 153 goto fail; 154 } 155 156 if (proc->leader != proc) 157 return 0; 158 if (process_init_main(proc) < 0) { 159 process_bare_destroy(proc, 0); 160 goto fail; 161 } 162 return 0; 163} 164 165static enum callback_status 166destroy_breakpoint_cb(struct Process *proc, struct breakpoint *bp, void *data) 167{ 168 breakpoint_destroy(bp); 169 free(bp); 170 return CBS_CONT; 171} 172 173static void 174private_process_destroy(struct Process *proc, int keep_filename) 175{ 176 if (!keep_filename) 177 free(proc->filename); 178 179 /* Libraries and symbols. This is only relevant in 180 * leader. */ 181 struct library *lib; 182 for (lib = proc->libraries; lib != NULL; ) { 183 struct library *next = lib->next; 184 library_destroy(lib); 185 free(lib); 186 lib = next; 187 } 188 proc->libraries = NULL; 189 190 /* Breakpoints. */ 191 if (proc->breakpoints != NULL) { 192 proc_each_breakpoint(proc, NULL, destroy_breakpoint_cb, NULL); 193 dict_clear(proc->breakpoints); 194 proc->breakpoints = NULL; 195 } 196} 197 198void 199process_destroy(struct Process *proc) 200{ 201 private_process_destroy(proc, 0); 202 arch_process_destroy(proc); 203} 204 205int 206process_exec(struct Process *proc) 207{ 208 /* Call exec first, before we destroy the main state. */ 209 if (arch_process_exec(proc) < 0) 210 return -1; 211 212 private_process_destroy(proc, 1); 213 if (process_bare_init(proc, NULL, proc->pid, 1) < 0) 214 return -1; 215 if (process_init_main(proc) < 0) { 216 process_bare_destroy(proc, 1); 217 return -1; 218 } 219 return 0; 220} 221 222struct Process * 223open_program(const char *filename, pid_t pid) 224{ 225 assert(pid != 0); 226 struct Process *proc = malloc(sizeof(*proc)); 227 if (proc == NULL || process_init(proc, filename, pid) < 0) { 228 free(proc); 229 return NULL; 230 } 231 return proc; 232} 233 234struct clone_single_bp_data { 235 struct Process *old_proc; 236 struct Process *new_proc; 237 int error; 238}; 239 240static void 241clone_single_bp(void *key, void *value, void *u) 242{ 243 struct breakpoint *bp = value; 244 struct clone_single_bp_data *data = u; 245 246 data->error = 0; 247 struct breakpoint *clone = malloc(sizeof(*clone)); 248 if (clone == NULL 249 || breakpoint_clone(clone, data->new_proc, 250 bp, data->old_proc) < 0) { 251 fail: 252 free(clone); 253 data->error = -1; 254 } 255 if (proc_add_breakpoint(data->new_proc->leader, clone) < 0) { 256 breakpoint_destroy(clone); 257 goto fail; 258 } 259} 260 261int 262process_clone(struct Process *retp, struct Process *proc, pid_t pid) 263{ 264 if (process_bare_init(retp, proc->filename, pid, 0) < 0) { 265 fail1: 266 fprintf(stderr, "failed to clone process %d->%d : %s\n", 267 proc->pid, pid, strerror(errno)); 268 return -1; 269 } 270 271 retp->tracesysgood = proc->tracesysgood; 272 retp->e_machine = proc->e_machine; 273 retp->e_class = proc->e_class; 274 275 /* For non-leader processes, that's all we need to do. */ 276 if (retp->leader != retp) 277 return 0; 278 279 /* Clone symbols first so that we can clone and relink 280 * breakpoints. */ 281 struct library *lib; 282 struct library **nlibp = &retp->libraries; 283 for (lib = proc->libraries; lib != NULL; lib = lib->next) { 284 *nlibp = malloc(sizeof(**nlibp)); 285 if (*nlibp == NULL 286 || library_clone(*nlibp, lib) < 0) { 287 fail2: 288 process_bare_destroy(retp, 0); 289 290 /* Error when cloning. Unroll what was done. */ 291 for (lib = retp->libraries; lib != NULL; ) { 292 struct library *next = lib->next; 293 library_destroy(lib); 294 free(lib); 295 lib = next; 296 } 297 goto fail1; 298 } 299 300 nlibp = &(*nlibp)->next; 301 } 302 303 /* Now clone breakpoints. Symbol relinking is done in 304 * clone_single_bp. */ 305 struct clone_single_bp_data data = { 306 .old_proc = proc, 307 .new_proc = retp, 308 .error = 0, 309 }; 310 dict_apply_to_all(proc->breakpoints, &clone_single_bp, &data); 311 if (data.error < 0) 312 goto fail2; 313 314 /* And finally the call stack. */ 315 memcpy(retp->callstack, proc->callstack, sizeof(retp->callstack)); 316 retp->callstack_depth = proc->callstack_depth; 317 318 size_t i; 319 for (i = 0; i < retp->callstack_depth; ++i) { 320 struct fetch_context *ctx = retp->callstack[i].fetch_context; 321 if (ctx != NULL) { 322 struct fetch_context *nctx = fetch_arg_clone(retp, ctx); 323 if (nctx == NULL) { 324 size_t j; 325 fail3: 326 for (j = 0; j < i; ++j) { 327 nctx = retp->callstack[i].fetch_context; 328 fetch_arg_done(nctx); 329 retp->callstack[i].fetch_context = NULL; 330 } 331 goto fail2; 332 } 333 retp->callstack[i].fetch_context = nctx; 334 } 335 336 struct value_dict *args = retp->callstack[i].arguments; 337 if (args != NULL) { 338 struct value_dict *nargs = malloc(sizeof(*nargs)); 339 if (nargs == NULL 340 || val_dict_clone(nargs, args) < 0) { 341 size_t j; 342 fail4: 343 for (j = 0; j < i; ++j) { 344 nargs = retp->callstack[i].arguments; 345 val_dict_destroy(nargs); 346 free(nargs); 347 retp->callstack[i].arguments = NULL; 348 } 349 350 /* Pretend that this round went well, 351 * so that fail3 frees I-th 352 * fetch_context. */ 353 ++i; 354 goto fail3; 355 } 356 retp->callstack[i].arguments = nargs; 357 } 358 } 359 360 if (arch_process_clone(retp, proc) < 0) 361 goto fail4; 362 363 return 0; 364} 365 366static int 367open_one_pid(pid_t pid) 368{ 369 Process *proc; 370 char *filename; 371 debug(DEBUG_PROCESS, "open_one_pid(pid=%d)", pid); 372 373 /* Get the filename first. Should the trace_pid fail, we can 374 * easily free it, untracing is more work. */ 375 if ((filename = pid2name(pid)) == NULL 376 || trace_pid(pid) < 0) { 377 free(filename); 378 return -1; 379 } 380 381 proc = open_program(filename, pid); 382 if (proc == NULL) 383 return -1; 384 trace_set_options(proc); 385 386 return 0; 387} 388 389static enum callback_status 390start_one_pid(Process * proc, void * data) 391{ 392 continue_process(proc->pid); 393 return CBS_CONT; 394} 395 396void 397open_pid(pid_t pid) 398{ 399 debug(DEBUG_PROCESS, "open_pid(pid=%d)", pid); 400 /* If we are already tracing this guy, we should be seeing all 401 * his children via normal tracing route. */ 402 if (pid2proc(pid) != NULL) 403 return; 404 405 /* First, see if we can attach the requested PID itself. */ 406 if (open_one_pid(pid)) { 407 fprintf(stderr, "Cannot attach to pid %u: %s\n", 408 pid, strerror(errno)); 409 trace_fail_warning(pid); 410 return; 411 } 412 413 /* Now attach to all tasks that belong to that PID. There's a 414 * race between process_tasks and open_one_pid. So when we 415 * fail in open_one_pid below, we just do another round. 416 * Chances are that by then that PID will have gone away, and 417 * that's why we have seen the failure. The processes that we 418 * manage to open_one_pid are stopped, so we should eventually 419 * reach a point where process_tasks doesn't give any new 420 * processes (because there's nobody left to produce 421 * them). */ 422 size_t old_ntasks = 0; 423 int have_all; 424 while (1) { 425 pid_t *tasks; 426 size_t ntasks; 427 size_t i; 428 429 if (process_tasks(pid, &tasks, &ntasks) < 0) { 430 fprintf(stderr, "Cannot obtain tasks of pid %u: %s\n", 431 pid, strerror(errno)); 432 break; 433 } 434 435 have_all = 1; 436 for (i = 0; i < ntasks; ++i) 437 if (pid2proc(tasks[i]) == NULL 438 && open_one_pid(tasks[i])) 439 have_all = 0; 440 441 free(tasks); 442 443 if (have_all && old_ntasks == ntasks) 444 break; 445 old_ntasks = ntasks; 446 } 447 448 struct Process *leader = pid2proc(pid)->leader; 449 450 /* XXX Is there a way to figure out whether _start has 451 * actually already been hit? */ 452 arch_dynlink_done(leader); 453 454 /* Done. Continue everyone. */ 455 each_task(leader, NULL, start_one_pid, NULL); 456} 457 458static enum callback_status 459find_proc(Process * proc, void * data) 460{ 461 pid_t pid = (pid_t)(uintptr_t)data; 462 return proc->pid == pid ? CBS_STOP : CBS_CONT; 463} 464 465Process * 466pid2proc(pid_t pid) { 467 return each_process(NULL, &find_proc, (void *)(uintptr_t)pid); 468} 469 470static Process * list_of_processes = NULL; 471 472static void 473unlist_process(Process * proc) 474{ 475 Process *tmp; 476 477 if (list_of_processes == proc) { 478 list_of_processes = list_of_processes->next; 479 return; 480 } 481 482 for (tmp = list_of_processes; ; tmp = tmp->next) { 483 /* If the following assert fails, the process wasn't 484 * in the list. */ 485 assert(tmp->next != NULL); 486 487 if (tmp->next == proc) { 488 tmp->next = tmp->next->next; 489 return; 490 } 491 } 492} 493 494struct Process * 495each_process(struct Process *start_after, 496 enum callback_status(*cb)(struct Process *proc, void *data), 497 void *data) 498{ 499 struct Process *it = start_after == NULL ? list_of_processes 500 : start_after->next; 501 502 while (it != NULL) { 503 /* Callback might call remove_process. */ 504 struct Process *next = it->next; 505 switch ((*cb)(it, data)) { 506 case CBS_FAIL: 507 /* XXX handle me */ 508 case CBS_STOP: 509 return it; 510 case CBS_CONT: 511 break; 512 } 513 it = next; 514 } 515 return NULL; 516} 517 518Process * 519each_task(struct Process *proc, struct Process *start_after, 520 enum callback_status(*cb)(struct Process *proc, void *data), 521 void *data) 522{ 523 assert(proc != NULL); 524 struct Process *it = start_after == NULL ? proc->leader 525 : start_after->next; 526 527 if (it != NULL) { 528 struct Process *leader = it->leader; 529 while (it != NULL && it->leader == leader) { 530 /* Callback might call remove_process. */ 531 struct Process *next = it->next; 532 switch ((*cb)(it, data)) { 533 case CBS_FAIL: 534 /* XXX handle me */ 535 case CBS_STOP: 536 return it; 537 case CBS_CONT: 538 break; 539 } 540 it = next; 541 } 542 } 543 return NULL; 544} 545 546static void 547add_process(struct Process *proc, int was_exec) 548{ 549 Process ** leaderp = &list_of_processes; 550 if (proc->pid) { 551 pid_t tgid = process_leader(proc->pid); 552 if (tgid == 0) 553 /* Must have been terminated before we managed 554 * to fully attach. */ 555 return; 556 if (tgid == proc->pid) 557 proc->leader = proc; 558 else { 559 Process * leader = pid2proc(tgid); 560 proc->leader = leader; 561 if (leader != NULL) 562 leaderp = &leader->next; 563 } 564 } 565 566 if (!was_exec) { 567 proc->next = *leaderp; 568 *leaderp = proc; 569 } 570} 571 572void 573change_process_leader(Process * proc, Process * leader) 574{ 575 Process ** leaderp = &list_of_processes; 576 if (proc->leader == leader) 577 return; 578 579 assert(leader != NULL); 580 unlist_process(proc); 581 if (proc != leader) 582 leaderp = &leader->next; 583 584 proc->leader = leader; 585 proc->next = *leaderp; 586 *leaderp = proc; 587} 588 589static enum callback_status 590clear_leader(struct Process *proc, void *data) 591{ 592 debug(DEBUG_FUNCTION, "detach_task %d from leader %d", 593 proc->pid, proc->leader->pid); 594 proc->leader = NULL; 595 return CBS_CONT; 596} 597 598void 599remove_process(Process *proc) 600{ 601 debug(DEBUG_FUNCTION, "remove_proc(pid=%d)", proc->pid); 602 603 if (proc->leader == proc) 604 each_task(proc, NULL, &clear_leader, NULL); 605 606 unlist_process(proc); 607 process_removed(proc); 608 process_destroy(proc); 609 free(proc); 610} 611 612void 613install_event_handler(Process *proc, struct event_handler *handler) 614{ 615 debug(DEBUG_FUNCTION, "install_event_handler(pid=%d, %p)", proc->pid, handler); 616 assert(proc->event_handler == NULL); 617 proc->event_handler = handler; 618} 619 620void 621destroy_event_handler(Process * proc) 622{ 623 struct event_handler *handler = proc->event_handler; 624 debug(DEBUG_FUNCTION, "destroy_event_handler(pid=%d, %p)", proc->pid, handler); 625 assert(handler != NULL); 626 if (handler->destroy != NULL) 627 handler->destroy(handler); 628 free(handler); 629 proc->event_handler = NULL; 630} 631 632static int 633breakpoint_for_symbol(struct library_symbol *libsym, struct Process *proc) 634{ 635 arch_addr_t bp_addr; 636 assert(proc->leader == proc); 637 638 bp_addr = sym2addr(proc, libsym); 639 640 /* For external function pointers, MIPS brings in stub-less funcs 641 * that point to zero at startup. These symbols get resolved by 642 * the dynamic linker and are ready to use at arch_dynlink_done(). 643 * 644 * Allow the backend to add these into the process representation 645 * but don't put breakpoints at this point. Let the backend fix that 646 * up later. 647 * 648 * XXX This should be changed to delayed symbols. */ 649 if (bp_addr == 0 && libsym->plt_type == LS_TOPLT_GOTONLY) { 650 /* Don't add breakpoints yet. */ 651 return CBS_CONT; 652 } 653 /* Don't enable latent or delayed symbols. */ 654 if (libsym->latent || libsym->delayed) 655 return 0; 656 657 /* If there is an artificial breakpoint on the same address, 658 * its libsym will be NULL, and we can smuggle our libsym 659 * there. That artificial breakpoint is there presumably for 660 * the callbacks, which we don't touch. If there is a real 661 * breakpoint, then this is a bug. ltrace-elf.c should filter 662 * symbols and ignore extra symbol aliases. 663 * 664 * The other direction is more complicated and currently not 665 * supported. If a breakpoint has custom callbacks, it might 666 * be also custom-allocated, and we would really need to swap 667 * the two: delete the one now in the dictionary, swap values 668 * around, and put the new breakpoint back in. */ 669 struct breakpoint *bp = dict_find_entry(proc->breakpoints, 670 bp_addr); 671 if (bp != NULL) { 672 assert(bp->libsym == NULL); 673 bp->libsym = libsym; 674 return 0; 675 } 676 677 bp = malloc(sizeof(*bp)); 678 if (bp == NULL 679 || breakpoint_init(bp, proc, bp_addr, libsym) < 0) { 680 fail: 681 free(bp); 682 return -1; 683 } 684 if (proc_add_breakpoint(proc, bp) < 0) { 685 breakpoint_destroy(bp); 686 goto fail; 687 } 688 689 if (breakpoint_turn_on(bp, proc) < 0) { 690 proc_remove_breakpoint(proc, bp); 691 breakpoint_destroy(bp); 692 goto fail; 693 } 694 695 return 0; 696} 697 698static enum callback_status 699cb_breakpoint_for_symbol(struct library_symbol *libsym, void *data) 700{ 701 return breakpoint_for_symbol(libsym, data) < 0 ? CBS_FAIL : CBS_CONT; 702} 703 704static int 705proc_activate_latent_symbol(struct Process *proc, 706 struct library_symbol *libsym) 707{ 708 assert(libsym->latent); 709 libsym->latent = 0; 710 return breakpoint_for_symbol(libsym, proc); 711} 712 713int 714proc_activate_delayed_symbol(struct Process *proc, 715 struct library_symbol *libsym) 716{ 717 assert(libsym->delayed); 718 libsym->delayed = 0; 719 return breakpoint_for_symbol(libsym, proc); 720} 721 722void 723proc_add_library(struct Process *proc, struct library *lib) 724{ 725 assert(lib->next == NULL); 726 lib->next = proc->libraries; 727 proc->libraries = lib; 728 debug(DEBUG_PROCESS, "added library %s@%p (%s) to %d", 729 lib->soname, lib->base, lib->pathname, proc->pid); 730 731 /* Insert breakpoints for all active (non-latent) symbols. */ 732 struct library_symbol *libsym = NULL; 733 while ((libsym = library_each_symbol(lib, libsym, 734 cb_breakpoint_for_symbol, 735 proc)) != NULL) 736 fprintf(stderr, "Couldn't insert breakpoint for %s to %d: %s.", 737 libsym->name, proc->pid, strerror(errno)); 738} 739 740int 741proc_remove_library(struct Process *proc, struct library *lib) 742{ 743 struct library **libp; 744 for (libp = &proc->libraries; *libp != NULL; libp = &(*libp)->next) 745 if (*libp == lib) { 746 *libp = lib->next; 747 return 0; 748 } 749 return -1; 750} 751 752struct library * 753proc_each_library(struct Process *proc, struct library *it, 754 enum callback_status (*cb)(struct Process *proc, 755 struct library *lib, void *data), 756 void *data) 757{ 758 if (it == NULL) 759 it = proc->libraries; 760 761 while (it != NULL) { 762 struct library *next = it->next; 763 764 switch (cb(proc, it, data)) { 765 case CBS_FAIL: 766 /* XXX handle me */ 767 case CBS_STOP: 768 return it; 769 case CBS_CONT: 770 break; 771 } 772 773 it = next; 774 } 775 776 return NULL; 777} 778 779static void 780check_leader(struct Process *proc) 781{ 782 /* Only the group leader should be getting the breakpoints and 783 * thus have ->breakpoint initialized. */ 784 assert(proc->leader != NULL); 785 assert(proc->leader == proc); 786 assert(proc->breakpoints != NULL); 787} 788 789int 790proc_add_breakpoint(struct Process *proc, struct breakpoint *bp) 791{ 792 debug(DEBUG_FUNCTION, "proc_add_breakpoint(pid=%d, %s@%p)", 793 proc->pid, breakpoint_name(bp), bp->addr); 794 check_leader(proc); 795 796 /* XXX We might merge bp->libsym instead of the following 797 * assert, but that's not necessary right now. Read the 798 * comment in breakpoint_for_symbol. */ 799 assert(dict_find_entry(proc->breakpoints, bp->addr) == NULL); 800 801 if (dict_enter(proc->breakpoints, bp->addr, bp) < 0) { 802 fprintf(stderr, 803 "couldn't enter breakpoint %s@%p to dictionary: %s\n", 804 breakpoint_name(bp), bp->addr, strerror(errno)); 805 return -1; 806 } 807 808 return 0; 809} 810 811void 812proc_remove_breakpoint(struct Process *proc, struct breakpoint *bp) 813{ 814 debug(DEBUG_FUNCTION, "proc_remove_breakpoint(pid=%d, %s@%p)", 815 proc->pid, breakpoint_name(bp), bp->addr); 816 check_leader(proc); 817 struct breakpoint *removed = dict_remove(proc->breakpoints, bp->addr); 818 assert(removed == bp); 819} 820 821/* Dict doesn't support iteration restarts, so here's this contraption 822 * for now. XXX add restarts to dict. */ 823struct each_breakpoint_data 824{ 825 void *start; 826 void *end; 827 struct Process *proc; 828 enum callback_status (*cb)(struct Process *proc, 829 struct breakpoint *bp, 830 void *data); 831 void *cb_data; 832}; 833 834static void 835each_breakpoint_cb(void *key, void *value, void *d) 836{ 837 struct each_breakpoint_data *data = d; 838 if (data->end != NULL) 839 return; 840 if (data->start == key) 841 data->start = NULL; 842 843 if (data->start == NULL) { 844 switch (data->cb(data->proc, value, data->cb_data)) { 845 case CBS_FAIL: 846 /* XXX handle me */ 847 case CBS_STOP: 848 data->end = key; 849 case CBS_CONT: 850 return; 851 } 852 } 853} 854 855void * 856proc_each_breakpoint(struct Process *proc, void *start, 857 enum callback_status (*cb)(struct Process *proc, 858 struct breakpoint *bp, 859 void *data), void *data) 860{ 861 struct each_breakpoint_data dd = { 862 .start = start, 863 .proc = proc, 864 .cb = cb, 865 .cb_data = data, 866 }; 867 dict_apply_to_all(proc->breakpoints, &each_breakpoint_cb, &dd); 868 return dd.end; 869} 870