breakpoint.h revision 9294d82f67e20f5f2b61f317ad04f5cb717c7d27
19294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata/* 29294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * This file is part of ltrace. 39294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * Copyright (C) 2012 Petr Machata, Red Hat Inc. 49294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * Copyright (C) 2009 Juan Cespedes 59294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * 69294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * This program is free software; you can redistribute it and/or 79294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * modify it under the terms of the GNU General Public License as 89294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * published by the Free Software Foundation; either version 2 of the 99294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * License, or (at your option) any later version. 109294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * 119294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * This program is distributed in the hope that it will be useful, but 129294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * WITHOUT ANY WARRANTY; without even the implied warranty of 139294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 149294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * General Public License for more details. 159294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * 169294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * You should have received a copy of the GNU General Public License 179294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * along with this program; if not, write to the Free Software 189294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 199294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * 02110-1301 USA 209294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata */ 219294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 229294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata#ifndef BREAKPOINT_H 239294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata#define BREAKPOINT_H 249294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 259294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata/* XXX This is currently a very weak abstraction. We would like to 269294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * much expand this to allow things like breakpoints on SDT probes and 279294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * such. 289294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * 299294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * In particular, we would like to add a tracepoint abstraction. 309294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * Tracepoint is a traceable feature--e.g. an exact address, a DWARF 319294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * symbol, an ELF symbol, a PLT entry, or an SDT probe. Tracepoints 329294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * are named and the user can configure which of them he wants to 339294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * enable. Realized tracepoints enable breakpoints, which are a 349294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * low-level realization of high-level tracepoint. 359294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * 369294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * Tracepoints are provided by the main binary as well as by any 379294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * opened libraries: every time an ELF file is mapped into the address 389294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * space, a new set of tracepoints is extracted, and filtered 399294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * according to user settings. Those tracepoints that are left are 409294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * then realized, and the tracing starts. 419294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * 429294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * A scheme like this would take care of gradually introducing 439294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * breakpoints when the library is mapped, and therefore ready, and 449294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * would avoid certain hacks. For example on PPC64, we don't actually 459294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * add breakpoints to PLT. Instead, we read the PLT (which contains 469294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * addresses, not code), to figure out where to put the breakpoints. 479294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * In prelinked code, that address is non-zero, and points to an 489294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * address that's not yet mapped. ptrace then fails when we try to 499294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * add the breakpoint. 509294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * 519294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * Ideally, return breakpoints would be just a special kind of 529294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * tracepoint that has attached some magic. Or a feature of a 539294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * tracepoint. Service breakpoints like the handling of dlopen would 549294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * be a low-level breakpoint, likely without tracepoint attached. 559294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * 569294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * So that's for sometimes. 579294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata */ 589294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 599294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata#include "arch.h" 609294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 619294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machatastruct Process; 629294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 639294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machatatypedef struct breakpoint Breakpoint; 649294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machatastruct breakpoint { 659294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata void *addr; 669294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata unsigned char orig_value[BREAKPOINT_LENGTH]; 679294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata int enabled; 689294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata struct library_symbol *libsym; 699294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata#ifdef __arm__ 709294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata int thumb_mode; 719294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata#endif 729294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata}; 739294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 749294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata/* This is actually three functions rolled in one: 759294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * - breakpoint_init 769294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * - proc_insert_breakpoint 779294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * - breakpoint_enable 789294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata * XXX I think it should be broken up somehow. */ 799294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machatastruct breakpoint *insert_breakpoint(struct Process *proc, void *addr, 809294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata struct library_symbol *libsym, int enable); 819294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 829294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata/* */ 839294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machatavoid delete_breakpoint(struct Process *proc, void *addr); 849294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 859294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata/* XXX some of the following belongs to proc.h/proc.c. */ 869294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machatastruct breakpoint *address2bpstruct(struct Process *proc, void *addr); 879294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machatavoid enable_all_breakpoints(struct Process *proc); 889294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machatavoid disable_all_breakpoints(struct Process *proc); 899294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machataint breakpoints_init(struct Process *proc, int enable); 909294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 919294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machatavoid reinitialize_breakpoints(struct Process *proc); 929294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 939294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata 949294d82f67e20f5f2b61f317ad04f5cb717c7d27Petr Machata#endif /* BREAKPOINT_H */ 95