proc.h revision df2c88cec5bf17a92f0d5d740e3b756f00b798c6
12b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata/*
22b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * This file is part of ltrace.
3653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata * Copyright (C) 2010,2011,2012,2013 Petr Machata, Red Hat Inc.
42b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * Copyright (C) 2010 Joe Damato
52b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * Copyright (C) 1998,2001,2008,2009 Juan Cespedes
62b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *
72b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * This program is free software; you can redistribute it and/or
82b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * modify it under the terms of the GNU General Public License as
92b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * published by the Free Software Foundation; either version 2 of the
102b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * License, or (at your option) any later version.
112b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *
122b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * This program is distributed in the hope that it will be useful, but
132b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * WITHOUT ANY WARRANTY; without even the implied warranty of
142b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
152b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * General Public License for more details.
162b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata *
172b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * You should have received a copy of the GNU General Public License
182b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * along with this program; if not, write to the Free Software
192b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
202b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * 02110-1301 USA
212b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata */
222b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
23366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#ifndef _PROC_H_
24366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#define _PROC_H_
25366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
268a568dd4ad368d37c059ec9c8da0e894417a27d9Petr Machata#include "config.h"
278a568dd4ad368d37c059ec9c8da0e894417a27d9Petr Machata
28d2c5dfdf0c746bb0d0365505577461f0058aedf9Andrey Zonov#include <sys/time.h>
29653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata#include <stdint.h>
30d2c5dfdf0c746bb0d0365505577461f0058aedf9Andrey Zonov
31366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#if defined(HAVE_LIBUNWIND)
32366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata# include <libunwind.h>
33366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#endif /* defined(HAVE_LIBUNWIND) */
34366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
35366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "ltrace.h"
36366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "dict.h"
37744f255ed0d676896dbe2f326b9c353c56438f0aPetr Machata#include "sysdep.h"
38a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata#include "callback.h"
396d8aa0bba1fb9473f6e92738975f6be73a6ac722Petr Machata#include "forward.h"
402b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
41366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatastruct event_handler {
42366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Event handler that overrides the default one.  Should
43366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 * return NULL if the event was handled, otherwise the
44366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 * returned event is passed to the default handler.  */
45366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	Event *(*on_event)(struct event_handler *self, Event *event);
46366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
47366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Called when the event handler removal is requested.  */
48366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void (*destroy)(struct event_handler *self);
49366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata};
50366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
51366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machataenum process_state {
52366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	STATE_ATTACHED = 0,
53366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	STATE_BEING_CREATED,
54366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	STATE_IGNORED  /* ignore this process (it's a fork and no -f was used) */
55366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata};
56366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
57f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machatastruct output_state {
58f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata	size_t params_left;
59f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata	int need_delim;
60f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata};
61f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata
62366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatastruct callstack_element {
63366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	union {
64366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		int syscall;
65366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		struct library_symbol * libfunc;
66366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	} c_un;
67366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	int is_syscall;
684dcc3893d488d19c7606acfa80752babbbe04645Petr Machata	arch_addr_t return_addr;
69366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	struct timeval time_spent;
70f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata	struct fetch_context *fetch_context;
7194078ecce3a103c28457e6f90f1e5b0dacc61146Petr Machata	struct value_dict *arguments;
72f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata	struct output_state out;
73366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata};
74366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
75366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata/* XXX We should get rid of this.  */
76366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#define MAX_CALLDEPTH 64
77366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
78366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata/* XXX We would rather have this all organized a little differently,
79929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata * have struct process for the whole group and struct task (or struct
80929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata * lwp, struct thread) for what's there for per-thread stuff.  But for
81929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata * now this is the less invasive way of structuring it.  */
82929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process {
83366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	enum process_state state;
84929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	struct process *parent;         /* needed by STATE_BEING_CREATED */
85366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	char * filename;
86366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	pid_t pid;
87366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
88366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Dictionary of breakpoints (which is a mapping
89366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 * address->breakpoint).  This is NULL for non-leader
90d7e4ca82e1cf20bb2605befb1da74dd1688c706ePetr Machata	 * processes.  */
91d7e4ca82e1cf20bb2605befb1da74dd1688c706ePetr Machata	struct dict *breakpoints;
92366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
93366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	int mask_32bit;           /* 1 if 64-bit ltrace is tracing 32-bit process */
94366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	unsigned int personality;
95366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	int tracesysgood;         /* signal indicating a PTRACE_SYSCALL trap */
96366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
97ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata	size_t callstack_depth;
98366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	struct callstack_element callstack[MAX_CALLDEPTH];
9976dd9290bd760f363a6f39db06020e61e3f7b345Petr Machata
10076dd9290bd760f363a6f39db06020e61e3f7b345Petr Machata	/* Linked list of libraries in backwards order of mapping.
10176dd9290bd760f363a6f39db06020e61e3f7b345Petr Machata	 * The last element is the executed binary itself.  */
1022b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata	struct library *libraries;
103366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
104366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Arch-dependent: */
105366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void * instruction_pointer;
106366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void * stack_pointer;      /* To get return addr, args... */
107366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void * arch_ptr;
1084d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata
1094d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	/* XXX We would like to replace this with a pointer to ABI
1104d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	 * object that would provide the relevant services, instead of
1114d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	 * checking the necessary flags in the back end ad
1124d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	 * nauseam.  */
113366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	short e_machine;
1144d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	char e_class;
1154d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata
116366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#if defined(HAVE_LIBUNWIND)
117366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* libunwind address space */
118366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	unw_addr_space_t unwind_as;
119366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void *unwind_priv;
120366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#endif /* defined(HAVE_LIBUNWIND) */
121366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
122366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Set in leader.  */
123366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	struct event_handler *event_handler;
124366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
125366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/**
126366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 * Process chaining.
127366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 **/
128929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	struct process *next;
129366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
130366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* LEADER points to the leader thread of the POSIX.1 process.
131366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	   If X->LEADER == X, then X is the leader thread and the
132929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	   process structures chained by NEXT represent other threads,
133366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	   up until, but not including, the next leader thread.
134366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	   LEADER may be NULL after the leader has already exited.  In
135366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	   that case this process is waiting to be collected.  */
136929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	struct process *leader;
137744f255ed0d676896dbe2f326b9c353c56438f0aPetr Machata
1380f6e6d9861ce790cb8b7d07aca28a5878d705359Petr Machata	struct os_process_data os;
139744f255ed0d676896dbe2f326b9c353c56438f0aPetr Machata	struct arch_process_data arch;
140366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata};
141366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
14275934ad3b30790f6a892069576d0790a351ef101Petr Machata/* Initialize a process given a path to binary FILENAME, with a PID,
14375934ad3b30790f6a892069576d0790a351ef101Petr Machata * and add the process to an internal chain of traced processes.  */
144929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint process_init(struct process *proc, const char *filename, pid_t pid);
1452b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
1463d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata/* PROC underwent an exec.  This is a bit like process_destroy
1473d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * followed by process_init, except that some state is kept and the
1483d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * process doesn't lose it's place in the list of processes.  */
149929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint process_exec(struct process *proc);
1503d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata
1513d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata/* Release any memory allocated for PROC (but not PROC itself).  Does
1523d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * NOT remove PROC from internal chain.
1533d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata *
1543d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * XXX clearly this init/destroy pair is different than others and
1553d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * should be fixed.  process_init should presumably be separate from
1563d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * process_add.  */
157929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid process_destroy(struct process *proc);
1583d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata
159929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process *open_program(const char *filename, pid_t pid);
160366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatavoid open_pid(pid_t pid);
161929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process *pid2proc(pid_t pid);
1622b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
1632b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata/* Clone the contents of PROC into the memory referenced by RETP.
1642b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * Returns 0 on success or a negative value on failure.  */
165929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint process_clone(struct process *retp, struct process *proc, pid_t pid);
1662b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
167a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata/* Iterate through the processes that ltrace currently traces.  Tasks
168a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * are considered to be processes for the purpose of this iterator.
169a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * See callback.h for notes on iteration interfaces.  */
170929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process *each_process(struct process *start_after,
171929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata			     enum callback_status (*cb)(struct process *proc,
172929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata							void *data),
173929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata			     void *data);
1742b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
175a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata/* Iterate through list of tasks of given process PROC.  See
176a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * callback.h for notes on iteration interfaces.  */
177929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process *each_task(struct process *proc, struct process *start_after,
178929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata			  enum callback_status (*cb)(struct process *proc,
179929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata						     void *data),
180929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata			  void *data);
1812b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
182929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid change_process_leader(struct process *proc, struct process *leader);
183fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata
184df2c88cec5bf17a92f0d5d740e3b756f00b798c6Petr Machata/* Prepare those parts of process initialization that need to be done
185df2c88cec5bf17a92f0d5d740e3b756f00b798c6Petr Machata * after _start is hit (i.e. after dynamic linking was done).  */
186df2c88cec5bf17a92f0d5d740e3b756f00b798c6Petr Machatavoid process_hit_start(struct process *proc);
187df2c88cec5bf17a92f0d5d740e3b756f00b798c6Petr Machata
188fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata/* Remove process from the list of traced processes, drop any events
189fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata * in the event queue, destroy it and free memory.  */
190929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid remove_process(struct process *proc);
191fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata
192929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid install_event_handler(struct process *proc, struct event_handler *handler);
193929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid destroy_event_handler(struct process *proc);
194366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
1952b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata/* Add a library LIB to the list of PROC's libraries.  */
196929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid proc_add_library(struct process *proc, struct library *lib);
1972b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
1982b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata/* Remove LIB from list of PROC's libraries.  Returns 0 if the library
1992b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * was found and unlinked, otherwise returns a negative value.  */
200929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_remove_library(struct process *proc, struct library *lib);
2012b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
202ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata/* Clear a delayed flag.  If a symbol is neither latent, nor delayed,
203ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata * a breakpoint is inserted for it.  Returns 0 if the activation was
204ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata * successful or a negative value if it failed.  Note that if a symbol
205ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata * is both latent and delayed, this will not enable the corresponding
206ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata * breakpoint.  */
207929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_activate_delayed_symbol(struct process *proc,
208ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata				 struct library_symbol *libsym);
209ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata
210a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata/* Iterate through the libraries of PROC.  See callback.h for notes on
211a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * iteration interfaces.  */
2127ac04edc87e07fc68f94274ba3ff0fb2a0a98958Petr Machatastruct library *proc_each_library(struct process *proc,
2137ac04edc87e07fc68f94274ba3ff0fb2a0a98958Petr Machata				  struct library *start_after,
214929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata				  enum callback_status (*cb)(struct process *p,
2152b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata							     struct library *l,
2162b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata							     void *data),
2172b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata				  void *data);
2182b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
21952dbfb161efeab85bddc880966db2f7af9b9cf9aPetr Machata/* Insert BP into PROC.  */
220929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_add_breakpoint(struct process *proc, struct breakpoint *bp);
22152dbfb161efeab85bddc880966db2f7af9b9cf9aPetr Machata
222f7fee43f72667f453bba5aaeea6b5490ece6792aPetr Machata/* Remove BP from PROC.  This has no reason to fail in runtime.  If it
223f7fee43f72667f453bba5aaeea6b5490ece6792aPetr Machata * does not find BP in PROC, it's hard error guarded by assertion.  */
224929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid proc_remove_breakpoint(struct process *proc, struct breakpoint *bp);
2252b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
226a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata/* Iterate through the breakpoints of PROC.  See callback.h for notes
227a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * on iteration interfaces.  */
228929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid *proc_each_breakpoint(struct process *proc, void *start,
229929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata			   enum callback_status (*cb)(struct process *proc,
230d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata						      struct breakpoint *bp,
231d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata						      void *data),
232d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata			   void *data);
233d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata
234cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias/* Iterate through the dynamic section at src_addr looking for D_TAG.
235cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias * If tag is found, fill it's value in RET and return 0.
236cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias * If tag is not found, return a negative value.  */
237929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_find_dynamic_entry_addr(struct process *proc, arch_addr_t src_addr,
238cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias				 int d_tag, arch_addr_t *ret);
239165b566a50b2bd560af3bd9649e456915397066bPetr Machata
240165b566a50b2bd560af3bd9649e456915397066bPetr Machata/* Finds a symbol corresponding to LIBSYM in a process PROC.  Returns
241165b566a50b2bd560af3bd9649e456915397066bPetr Machata * 0 and sets *RETLIB and *RETSYM if the corresponding pointer is
242165b566a50b2bd560af3bd9649e456915397066bPetr Machata * non-NULL.  Returns a negative value when the symbols couldn't be
243165b566a50b2bd560af3bd9649e456915397066bPetr Machata * found.  */
244929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_find_symbol(struct process *proc, struct library_symbol *sym,
245165b566a50b2bd560af3bd9649e456915397066bPetr Machata		     struct library **retlib, struct library_symbol **retsym);
246165b566a50b2bd560af3bd9649e456915397066bPetr Machata
2473240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata/* Iterate through all symbols in all libraries of PROC.  See
2483240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata * callback.h for notes on this interface.  */
2493240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machatastruct library_symbol *proc_each_symbol
250929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	(struct process *proc, struct library_symbol *start_after,
2513240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata	 enum callback_status (*cb)(struct library_symbol *, void *),
2523240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata	 void *data);
2533240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata
254dc70e76a94f842e2b8eaf0b9c2aabb829dc4826aPetr Machata/* Read 8, 16, 32 or 64-bit quantity located at ADDR in PROC.  The
255653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata * resulting value is stored in *LP.  0 is returned on success or a
256653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata * negative value on failure.  This uses umovebytes under the hood
257653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata * (see backend.h).  */
258dc70e76a94f842e2b8eaf0b9c2aabb829dc4826aPetr Machataint proc_read_8(struct process *proc, arch_addr_t addr, uint8_t *lp);
259653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machataint proc_read_16(struct process *proc, arch_addr_t addr, uint16_t *lp);
260653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machataint proc_read_32(struct process *proc, arch_addr_t addr, uint32_t *lp);
261653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machataint proc_read_64(struct process *proc, arch_addr_t addr, uint64_t *lp);
262653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata
263366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#endif /* _PROC_H_ */
264