blob: 3f63f63e0c411f6a2333f976f45c34d1c497caf7 [file] [log] [blame]
Petr Machata9294d822012-02-07 12:35:58 +01001/*
2 * This file is part of ltrace.
Petr Machatae5035522013-01-30 17:48:51 +01003 * Copyright (C) 2012, 2013 Petr Machata, Red Hat Inc.
Petr Machata9294d822012-02-07 12:35:58 +01004 * 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 *
Petr Machata0c3377e2012-04-16 18:43:00 +020036 * Service breakpoints like the handling of dlopen would be a
37 * low-level breakpoint, likely without tracepoint attached.
Petr Machata9294d822012-02-07 12:35:58 +010038 *
39 * So that's for sometimes.
40 */
41
Petr Machatad3dc17b2012-03-21 03:23:25 +010042#include "sysdep.h"
Petr Machata2b46cfc2012-02-18 11:17:29 +010043#include "library.h"
Petr Machata929bd572012-12-17 03:20:34 +010044#include "forward.h"
Petr Machataa9fd8f42012-02-07 13:25:56 +010045
46struct bp_callbacks {
Petr Machata929bd572012-12-17 03:20:34 +010047 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);
Petr Machataa9fd8f42012-02-07 13:25:56 +010050};
Petr Machata9294d822012-02-07 12:35:58 +010051
Petr Machata9294d822012-02-07 12:35:58 +010052struct breakpoint {
Petr Machataa9fd8f42012-02-07 13:25:56 +010053 struct bp_callbacks *cbs;
Petr Machata29add4f2012-02-18 16:38:05 +010054 struct library_symbol *libsym;
Petr Machata9294d822012-02-07 12:35:58 +010055 void *addr;
56 unsigned char orig_value[BREAKPOINT_LENGTH];
57 int enabled;
Petr Machata2b46cfc2012-02-18 11:17:29 +010058 struct arch_breakpoint_data arch;
Petr Machata9294d822012-02-07 12:35:58 +010059};
60
Petr Machataa9fd8f42012-02-07 13:25:56 +010061/* Call on-hit handler of BP, if any is set. */
Petr Machata929bd572012-12-17 03:20:34 +010062void breakpoint_on_hit(struct breakpoint *bp, struct process *proc);
Petr Machataa9fd8f42012-02-07 13:25:56 +010063
Petr Machatad09d2402012-04-13 21:34:08 +020064/* Call on-continue handler of BP. If none is set, call
Petr Machata56a9ea62012-03-27 03:09:29 +020065 * continue_after_breakpoint. */
Petr Machata929bd572012-12-17 03:20:34 +010066void breakpoint_on_continue(struct breakpoint *bp, struct process *proc);
Petr Machata56a9ea62012-03-27 03:09:29 +020067
Petr Machata86d38282012-04-24 18:09:01 +020068/* 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). */
Petr Machata929bd572012-12-17 03:20:34 +010075void breakpoint_on_retract(struct breakpoint *bp, struct process *proc);
Petr Machata86d38282012-04-24 18:09:01 +020076
Petr Machata2b46cfc2012-02-18 11:17:29 +010077/* 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. */
Petr Machata929bd572012-12-17 03:20:34 +010081int breakpoint_init(struct breakpoint *bp, struct process *proc,
Petr Machatabac2da52012-05-29 00:42:59 +020082 arch_addr_t addr, struct library_symbol *libsym);
Petr Machata55ac9322012-03-27 03:07:35 +020083
Petr Machatad3cc9882012-04-13 21:40:23 +020084/* Make a clone of breakpoint BP into the area of memory pointed to by
Petr Machatae5035522013-01-30 17:48:51 +010085 * RETP. Symbols of cloned breakpoint are looked up in NEW_PROC.
Petr Machatad3cc9882012-04-13 21:40:23 +020086 * Returns 0 on success or a negative value on failure. */
Petr Machata929bd572012-12-17 03:20:34 +010087int breakpoint_clone(struct breakpoint *retp, struct process *new_proc,
Petr Machatae5035522013-01-30 17:48:51 +010088 struct breakpoint *bp);
Petr Machatad3cc9882012-04-13 21:40:23 +020089
Petr Machata55ac9322012-03-27 03:07:35 +020090/* Set callbacks. If CBS is non-NULL, then BP->cbs shall be NULL. */
91void breakpoint_set_callbacks(struct breakpoint *bp, struct bp_callbacks *cbs);
Petr Machata2b46cfc2012-02-18 11:17:29 +010092
Petr Machata0fe76c62012-04-14 02:29:30 +020093/* Destroy a breakpoint structure. */
Petr Machata8cce1192012-03-25 01:37:19 +010094void breakpoint_destroy(struct breakpoint *bp);
95
Petr Machata52dbfb12012-03-29 16:38:26 +020096/* Call enable_breakpoint the first time it's called. Returns 0 on
97 * success and a negative value on failure. */
Petr Machata929bd572012-12-17 03:20:34 +010098int breakpoint_turn_on(struct breakpoint *bp, struct process *proc);
Petr Machata52dbfb12012-03-29 16:38:26 +020099
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. */
Petr Machata929bd572012-12-17 03:20:34 +0100103int breakpoint_turn_off(struct breakpoint *bp, struct process *proc);
Petr Machata52dbfb12012-03-29 16:38:26 +0200104
Petr Machatadad1b772013-10-11 16:14:44 +0200105/* This allocates and initializes new breakpoint at ADDR, then calls
106 * INSERT_BREAKPOINT. Returns the new breakpoint or NULL if there are
107 * errors. */
Petr Machata02a796e2013-10-11 17:24:30 +0200108struct breakpoint *insert_breakpoint_at(struct process *proc, arch_addr_t addr,
109 struct library_symbol *libsym);
Petr Machata9294d822012-02-07 12:35:58 +0100110
Petr Machatadad1b772013-10-11 16:14:44 +0200111/* Check if there is a breakpoint on this address already. If yes,
112 * return that breakpoint instead (BP was not added). If no, try to
113 * PROC_ADD_BREAKPOINT and BREAKPOINT_TURN_ON. If it all works,
114 * return BP. Otherwise return NULL. */
115struct breakpoint *insert_breakpoint(struct process *proc,
116 struct breakpoint *bp);
117
Petr Machatae9aebd62012-03-25 01:38:53 +0100118/* Name of a symbol associated with BP. May be NULL. */
119const char *breakpoint_name(const struct breakpoint *bp);
120
Petr Machata52dbfb12012-03-29 16:38:26 +0200121/* A library that this breakpoint comes from. May be NULL. */
122struct library *breakpoint_library(const struct breakpoint *bp);
123
Petr Machata8cce1192012-03-25 01:37:19 +0100124/* Again, this seems to be several interfaces rolled into one:
125 * - breakpoint_disable
Petr Machata52dbfb12012-03-29 16:38:26 +0200126 * - proc_remove_breakpoint
Petr Machata8cce1192012-03-25 01:37:19 +0100127 * - breakpoint_destroy
128 * XXX */
Petr Machata929bd572012-12-17 03:20:34 +0100129void delete_breakpoint(struct process *proc, void *addr);
Petr Machata9294d822012-02-07 12:35:58 +0100130
131/* XXX some of the following belongs to proc.h/proc.c. */
Petr Machata929bd572012-12-17 03:20:34 +0100132struct breakpoint *address2bpstruct(struct process *proc, void *addr);
133void enable_all_breakpoints(struct process *proc);
134void disable_all_breakpoints(struct process *proc);
135int breakpoints_init(struct process *proc);
Petr Machata9294d822012-02-07 12:35:58 +0100136
Petr Machata9294d822012-02-07 12:35:58 +0100137#endif /* BREAKPOINT_H */