breakpoint.h revision 02a796e5e49c147982020c78b0066930e979f3e4
1/* 2 * This file is part of ltrace. 3 * Copyright (C) 2012, 2013 Petr Machata, Red Hat Inc. 4 * Copyright (C) 2009 Juan Cespedes 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of the 9 * License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 19 * 02110-1301 USA 20 */ 21 22#ifndef BREAKPOINT_H 23#define BREAKPOINT_H 24 25/* XXX This is currently a very weak abstraction. We would like to 26 * much expand this to allow things like breakpoints on SDT probes and 27 * such. 28 * 29 * In particular, we would like to add a tracepoint abstraction. 30 * Tracepoint is a traceable feature--e.g. an exact address, a DWARF 31 * symbol, an ELF symbol, a PLT entry, or an SDT probe. Tracepoints 32 * are named and the user can configure which of them he wants to 33 * enable. Realized tracepoints enable breakpoints, which are a 34 * low-level realization of high-level tracepoint. 35 * 36 * Service breakpoints like the handling of dlopen would be a 37 * low-level breakpoint, likely without tracepoint attached. 38 * 39 * So that's for sometimes. 40 */ 41 42#include "sysdep.h" 43#include "library.h" 44#include "forward.h" 45 46struct bp_callbacks { 47 void (*on_hit)(struct breakpoint *bp, struct process *proc); 48 void (*on_continue)(struct breakpoint *bp, struct process *proc); 49 void (*on_retract)(struct breakpoint *bp, struct process *proc); 50}; 51 52struct breakpoint { 53 struct bp_callbacks *cbs; 54 struct library_symbol *libsym; 55 void *addr; 56 unsigned char orig_value[BREAKPOINT_LENGTH]; 57 int enabled; 58 struct arch_breakpoint_data arch; 59}; 60 61/* Call on-hit handler of BP, if any is set. */ 62void breakpoint_on_hit(struct breakpoint *bp, struct process *proc); 63 64/* Call on-continue handler of BP. If none is set, call 65 * continue_after_breakpoint. */ 66void breakpoint_on_continue(struct breakpoint *bp, struct process *proc); 67 68/* Call on-retract handler of BP, if any is set. This should be 69 * called before the breakpoints are destroyed. The reason for a 70 * separate interface is that breakpoint_destroy has to be callable 71 * without PROC. ON_DISABLE might be useful as well, but that would 72 * be called every time we disable the breakpoint, which is too often 73 * (a breakpoint has to be disabled every time that we need to execute 74 * the instruction underneath it). */ 75void breakpoint_on_retract(struct breakpoint *bp, struct process *proc); 76 77/* Initialize a breakpoint structure. That doesn't actually realize 78 * the breakpoint. The breakpoint is initially assumed to be 79 * disabled. orig_value has to be set separately. CBS may be 80 * NULL. */ 81int breakpoint_init(struct breakpoint *bp, struct process *proc, 82 arch_addr_t addr, struct library_symbol *libsym); 83 84/* Make a clone of breakpoint BP into the area of memory pointed to by 85 * RETP. Symbols of cloned breakpoint are looked up in NEW_PROC. 86 * Returns 0 on success or a negative value on failure. */ 87int breakpoint_clone(struct breakpoint *retp, struct process *new_proc, 88 struct breakpoint *bp); 89 90/* Set callbacks. If CBS is non-NULL, then BP->cbs shall be NULL. */ 91void breakpoint_set_callbacks(struct breakpoint *bp, struct bp_callbacks *cbs); 92 93/* Destroy a breakpoint structure. */ 94void breakpoint_destroy(struct breakpoint *bp); 95 96/* Call enable_breakpoint the first time it's called. Returns 0 on 97 * success and a negative value on failure. */ 98int breakpoint_turn_on(struct breakpoint *bp, struct process *proc); 99 100/* Call disable_breakpoint when turned off the same number of times 101 * that it was turned on. Returns 0 on success and a negative value 102 * on failure. */ 103int breakpoint_turn_off(struct breakpoint *bp, struct process *proc); 104 105/* Utility function that does what typically needs to be done when a 106 * breakpoint is to be inserted. It checks whether there is another 107 * breakpoint in PROC->LEADER for given ADDR. If not, it allocates 108 * memory for a new breakpoint on the heap, initializes it, and calls 109 * PROC_ADD_BREAKPOINT to add the newly-created breakpoint. For newly 110 * added as well as preexisting breakpoints, it then calls 111 * BREAKPOINT_TURN_ON. If anything fails, it cleans up and returns 112 * NULL. Otherwise it returns the breakpoint for ADDR. */ 113struct breakpoint *insert_breakpoint_at(struct process *proc, arch_addr_t addr, 114 struct library_symbol *libsym); 115 116/* Name of a symbol associated with BP. May be NULL. */ 117const char *breakpoint_name(const struct breakpoint *bp); 118 119/* A library that this breakpoint comes from. May be NULL. */ 120struct library *breakpoint_library(const struct breakpoint *bp); 121 122/* Again, this seems to be several interfaces rolled into one: 123 * - breakpoint_disable 124 * - proc_remove_breakpoint 125 * - breakpoint_destroy 126 * XXX */ 127void delete_breakpoint(struct process *proc, void *addr); 128 129/* XXX some of the following belongs to proc.h/proc.c. */ 130struct breakpoint *address2bpstruct(struct process *proc, void *addr); 131void enable_all_breakpoints(struct process *proc); 132void disable_all_breakpoints(struct process *proc); 133int breakpoints_init(struct process *proc); 134 135#endif /* BREAKPOINT_H */ 136