Petr Machata | 9294d82 | 2012-02-07 12:35:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of ltrace. |
| 3 | * Copyright (C) 2012 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 | * Tracepoints are provided by the main binary as well as by any |
| 37 | * opened libraries: every time an ELF file is mapped into the address |
| 38 | * space, a new set of tracepoints is extracted, and filtered |
| 39 | * according to user settings. Those tracepoints that are left are |
| 40 | * then realized, and the tracing starts. |
| 41 | * |
| 42 | * A scheme like this would take care of gradually introducing |
| 43 | * breakpoints when the library is mapped, and therefore ready, and |
| 44 | * would avoid certain hacks. For example on PPC64, we don't actually |
| 45 | * add breakpoints to PLT. Instead, we read the PLT (which contains |
| 46 | * addresses, not code), to figure out where to put the breakpoints. |
| 47 | * In prelinked code, that address is non-zero, and points to an |
| 48 | * address that's not yet mapped. ptrace then fails when we try to |
| 49 | * add the breakpoint. |
| 50 | * |
| 51 | * Ideally, return breakpoints would be just a special kind of |
| 52 | * tracepoint that has attached some magic. Or a feature of a |
| 53 | * tracepoint. Service breakpoints like the handling of dlopen would |
| 54 | * be a low-level breakpoint, likely without tracepoint attached. |
| 55 | * |
| 56 | * So that's for sometimes. |
| 57 | */ |
| 58 | |
| 59 | #include "arch.h" |
| 60 | |
| 61 | struct Process; |
Petr Machata | a9fd8f4 | 2012-02-07 13:25:56 +0100 | [diff] [blame^] | 62 | struct breakpoint; |
| 63 | |
| 64 | struct bp_callbacks { |
| 65 | void (*on_hit) (struct breakpoint *bp, struct Process *proc); |
| 66 | void (*on_destroy) (struct breakpoint *bp); |
| 67 | }; |
Petr Machata | 9294d82 | 2012-02-07 12:35:58 +0100 | [diff] [blame] | 68 | |
| 69 | typedef struct breakpoint Breakpoint; |
| 70 | struct breakpoint { |
Petr Machata | a9fd8f4 | 2012-02-07 13:25:56 +0100 | [diff] [blame^] | 71 | struct bp_callbacks *cbs; |
Petr Machata | 9294d82 | 2012-02-07 12:35:58 +0100 | [diff] [blame] | 72 | void *addr; |
| 73 | unsigned char orig_value[BREAKPOINT_LENGTH]; |
| 74 | int enabled; |
| 75 | struct library_symbol *libsym; |
| 76 | #ifdef __arm__ |
| 77 | int thumb_mode; |
| 78 | #endif |
| 79 | }; |
| 80 | |
Petr Machata | a9fd8f4 | 2012-02-07 13:25:56 +0100 | [diff] [blame^] | 81 | /* Call on-hit handler of BP, if any is set. */ |
| 82 | void breakpoint_on_hit(struct breakpoint *bp, struct Process *proc); |
| 83 | |
| 84 | /* Call on-destroy handler of BP, if any is set. */ |
| 85 | void breakpoint_on_destroy(struct breakpoint *bp); |
| 86 | |
Petr Machata | 9294d82 | 2012-02-07 12:35:58 +0100 | [diff] [blame] | 87 | /* This is actually three functions rolled in one: |
| 88 | * - breakpoint_init |
| 89 | * - proc_insert_breakpoint |
| 90 | * - breakpoint_enable |
| 91 | * XXX I think it should be broken up somehow. */ |
| 92 | struct breakpoint *insert_breakpoint(struct Process *proc, void *addr, |
| 93 | struct library_symbol *libsym, int enable); |
| 94 | |
| 95 | /* */ |
| 96 | void delete_breakpoint(struct Process *proc, void *addr); |
| 97 | |
| 98 | /* XXX some of the following belongs to proc.h/proc.c. */ |
| 99 | struct breakpoint *address2bpstruct(struct Process *proc, void *addr); |
| 100 | void enable_all_breakpoints(struct Process *proc); |
| 101 | void disable_all_breakpoints(struct Process *proc); |
| 102 | int breakpoints_init(struct Process *proc, int enable); |
| 103 | |
| 104 | void reinitialize_breakpoints(struct Process *proc); |
| 105 | |
| 106 | |
| 107 | #endif /* BREAKPOINT_H */ |