12b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata/*
22b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * This file is part of ltrace.
36bcc092da6b7e20c6c2a9a5846536fbd3d77dbb8Petr Machata * Copyright (C) 2010,2011,2012,2013,2014 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
31dfefa9f057857735a073ea655f5cb34351032c8eMark Wielaard#if defined(HAVE_LIBDW)
32dfefa9f057857735a073ea655f5cb34351032c8eMark Wielaard# include <elfutils/libdwfl.h>
33dfefa9f057857735a073ea655f5cb34351032c8eMark Wielaard#endif
34dfefa9f057857735a073ea655f5cb34351032c8eMark Wielaard
35366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#if defined(HAVE_LIBUNWIND)
36366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata# include <libunwind.h>
37af452c67bceba1326bb629d7c1a8241d54c09038Luca Clementi# include <libunwind-ptrace.h>
38366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#endif /* defined(HAVE_LIBUNWIND) */
39366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
40366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "ltrace.h"
41366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#include "dict.h"
42744f255ed0d676896dbe2f326b9c353c56438f0aPetr Machata#include "sysdep.h"
43a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata#include "callback.h"
446d8aa0bba1fb9473f6e92738975f6be73a6ac722Petr Machata#include "forward.h"
452b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
46366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatastruct event_handler {
47366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Event handler that overrides the default one.  Should
48366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 * return NULL if the event was handled, otherwise the
49366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 * returned event is passed to the default handler.  */
50366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	Event *(*on_event)(struct event_handler *self, Event *event);
51366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
52366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Called when the event handler removal is requested.  */
53366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void (*destroy)(struct event_handler *self);
54366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata};
55366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
56366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machataenum process_state {
57366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	STATE_ATTACHED = 0,
58366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	STATE_BEING_CREATED,
59366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	STATE_IGNORED  /* ignore this process (it's a fork and no -f was used) */
60366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata};
61366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
62f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machatastruct output_state {
63f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata	size_t params_left;
64f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata	int need_delim;
65f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata};
66f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata
67366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatastruct callstack_element {
68366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	union {
69366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		int syscall;
70366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata		struct library_symbol * libfunc;
71366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	} c_un;
72366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	int is_syscall;
734dcc3893d488d19c7606acfa80752babbbe04645Petr Machata	arch_addr_t return_addr;
748a730f3e5844b86386032e93f91aa3df814ad9c3Petr Machata	struct timeval enter_time;
75f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata	struct fetch_context *fetch_context;
7694078ecce3a103c28457e6f90f1e5b0dacc61146Petr Machata	struct value_dict *arguments;
77f6ec08afb96292fd3c802c1f633d8de249664c72Petr Machata	struct output_state out;
78366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata};
79366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
80366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata/* XXX We should get rid of this.  */
81366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#define MAX_CALLDEPTH 64
82366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
83366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata/* XXX We would rather have this all organized a little differently,
84929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata * have struct process for the whole group and struct task (or struct
85929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata * lwp, struct thread) for what's there for per-thread stuff.  But for
86929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata * now this is the less invasive way of structuring it.  */
87929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process {
88366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	enum process_state state;
89929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	struct process *parent;         /* needed by STATE_BEING_CREATED */
90366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	char * filename;
91366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	pid_t pid;
92366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
93366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Dictionary of breakpoints (which is a mapping
94366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 * address->breakpoint).  This is NULL for non-leader
95d7e4ca82e1cf20bb2605befb1da74dd1688c706ePetr Machata	 * processes.  */
96d7e4ca82e1cf20bb2605befb1da74dd1688c706ePetr Machata	struct dict *breakpoints;
97366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
98366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	int mask_32bit;           /* 1 if 64-bit ltrace is tracing 32-bit process */
99366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	unsigned int personality;
100366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	int tracesysgood;         /* signal indicating a PTRACE_SYSCALL trap */
101366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
102ba1664b062414481d0f37d06bb01a19874c8d481Petr Machata	size_t callstack_depth;
103366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	struct callstack_element callstack[MAX_CALLDEPTH];
10476dd9290bd760f363a6f39db06020e61e3f7b345Petr Machata
10576dd9290bd760f363a6f39db06020e61e3f7b345Petr Machata	/* Linked list of libraries in backwards order of mapping.
10676dd9290bd760f363a6f39db06020e61e3f7b345Petr Machata	 * The last element is the executed binary itself.  */
1072b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata	struct library *libraries;
108366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
109366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Arch-dependent: */
110366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void * instruction_pointer;
111366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void * stack_pointer;      /* To get return addr, args... */
112366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void * arch_ptr;
1134d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata
1144d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	/* XXX We would like to replace this with a pointer to ABI
1154d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	 * object that would provide the relevant services, instead of
1164d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	 * checking the necessary flags in the back end ad
1174d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	 * nauseam.  */
118366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	short e_machine;
1194d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata	char e_class;
1204d4e1b853db0c97b7c7f023bc301e3c3eee58ce4Petr Machata
121dfefa9f057857735a073ea655f5cb34351032c8eMark Wielaard#if defined(HAVE_LIBDW)
122dfefa9f057857735a073ea655f5cb34351032c8eMark Wielaard	/* Unwind info for leader, NULL for non-leader procs. */
123dfefa9f057857735a073ea655f5cb34351032c8eMark Wielaard	Dwfl *dwfl;
124dfefa9f057857735a073ea655f5cb34351032c8eMark Wielaard#endif /* defined(HAVE_LIBDW) */
125dfefa9f057857735a073ea655f5cb34351032c8eMark Wielaard
126366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#if defined(HAVE_LIBUNWIND)
127366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* libunwind address space */
128366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	unw_addr_space_t unwind_as;
129366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	void *unwind_priv;
130366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#endif /* defined(HAVE_LIBUNWIND) */
131366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
132366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* Set in leader.  */
133366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	struct event_handler *event_handler;
134366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
135366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/**
136366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 * Process chaining.
137366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	 **/
138929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	struct process *next;
139366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
140366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	/* LEADER points to the leader thread of the POSIX.1 process.
141366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	   If X->LEADER == X, then X is the leader thread and the
142929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	   process structures chained by NEXT represent other threads,
143366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	   up until, but not including, the next leader thread.
144366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	   LEADER may be NULL after the leader has already exited.  In
145366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata	   that case this process is waiting to be collected.  */
146929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	struct process *leader;
147744f255ed0d676896dbe2f326b9c353c56438f0aPetr Machata
1480f6e6d9861ce790cb8b7d07aca28a5878d705359Petr Machata	struct os_process_data os;
149744f255ed0d676896dbe2f326b9c353c56438f0aPetr Machata	struct arch_process_data arch;
150366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata};
151366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
15275934ad3b30790f6a892069576d0790a351ef101Petr Machata/* Initialize a process given a path to binary FILENAME, with a PID,
15375934ad3b30790f6a892069576d0790a351ef101Petr Machata * and add the process to an internal chain of traced processes.  */
154929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint process_init(struct process *proc, const char *filename, pid_t pid);
1552b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
1563d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata/* PROC underwent an exec.  This is a bit like process_destroy
1573d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * followed by process_init, except that some state is kept and the
1583d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * process doesn't lose it's place in the list of processes.  */
159929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint process_exec(struct process *proc);
1603d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata
1613d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata/* Release any memory allocated for PROC (but not PROC itself).  Does
1623d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * NOT remove PROC from internal chain.
1633d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata *
1643d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * XXX clearly this init/destroy pair is different than others and
1653d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * should be fixed.  process_init should presumably be separate from
1663d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata * process_add.  */
167929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid process_destroy(struct process *proc);
1683d0c91c0c7b425e2866f9c65f655d399693328a5Petr Machata
169929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process *open_program(const char *filename, pid_t pid);
170366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machatavoid open_pid(pid_t pid);
171929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process *pid2proc(pid_t pid);
1722b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
1732b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata/* Clone the contents of PROC into the memory referenced by RETP.
1742b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * Returns 0 on success or a negative value on failure.  */
175929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint process_clone(struct process *retp, struct process *proc, pid_t pid);
1762b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
177a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata/* Iterate through the processes that ltrace currently traces.  Tasks
178a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * are considered to be processes for the purpose of this iterator.
179a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * See callback.h for notes on iteration interfaces.  */
180929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process *each_process(struct process *start_after,
181929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata			     enum callback_status (*cb)(struct process *proc,
182929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata							void *data),
183929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata			     void *data);
1842b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
185a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata/* Iterate through list of tasks of given process PROC.  See
186a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * callback.h for notes on iteration interfaces.  */
187929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatastruct process *each_task(struct process *proc, struct process *start_after,
188929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata			  enum callback_status (*cb)(struct process *proc,
189929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata						     void *data),
190929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata			  void *data);
1912b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
192929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid change_process_leader(struct process *proc, struct process *leader);
193fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata
194df2c88cec5bf17a92f0d5d740e3b756f00b798c6Petr Machata/* Prepare those parts of process initialization that need to be done
195df2c88cec5bf17a92f0d5d740e3b756f00b798c6Petr Machata * after _start is hit (i.e. after dynamic linking was done).  */
196df2c88cec5bf17a92f0d5d740e3b756f00b798c6Petr Machatavoid process_hit_start(struct process *proc);
197df2c88cec5bf17a92f0d5d740e3b756f00b798c6Petr Machata
198fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata/* Remove process from the list of traced processes, drop any events
199fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata * in the event queue, destroy it and free memory.  */
200929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid remove_process(struct process *proc);
201fd2641c0d27705c89d224e3205b1296110b6598cPetr Machata
202929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid install_event_handler(struct process *proc, struct event_handler *handler);
203929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid destroy_event_handler(struct process *proc);
204366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
2052b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata/* Add a library LIB to the list of PROC's libraries.  */
206929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid proc_add_library(struct process *proc, struct library *lib);
2072b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
2082b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata/* Remove LIB from list of PROC's libraries.  Returns 0 if the library
2092b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata * was found and unlinked, otherwise returns a negative value.  */
210929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_remove_library(struct process *proc, struct library *lib);
2112b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
212ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata/* Clear a delayed flag.  If a symbol is neither latent, nor delayed,
213ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata * a breakpoint is inserted for it.  Returns 0 if the activation was
214ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata * successful or a negative value if it failed.  Note that if a symbol
215ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata * is both latent and delayed, this will not enable the corresponding
216ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata * breakpoint.  */
217929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_activate_delayed_symbol(struct process *proc,
218ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata				 struct library_symbol *libsym);
219ef2fd27a347bbb0e7cca7fdee97422f6ae4d4bdaPetr Machata
220a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata/* Iterate through the libraries of PROC.  See callback.h for notes on
221a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * iteration interfaces.  */
2227ac04edc87e07fc68f94274ba3ff0fb2a0a98958Petr Machatastruct library *proc_each_library(struct process *proc,
2237ac04edc87e07fc68f94274ba3ff0fb2a0a98958Petr Machata				  struct library *start_after,
224929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata				  enum callback_status (*cb)(struct process *p,
2252b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata							     struct library *l,
2262b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata							     void *data),
2272b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata				  void *data);
2282b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
22952dbfb161efeab85bddc880966db2f7af9b9cf9aPetr Machata/* Insert BP into PROC.  */
230929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_add_breakpoint(struct process *proc, struct breakpoint *bp);
23152dbfb161efeab85bddc880966db2f7af9b9cf9aPetr Machata
232f7fee43f72667f453bba5aaeea6b5490ece6792aPetr Machata/* Remove BP from PROC.  This has no reason to fail in runtime.  If it
233f7fee43f72667f453bba5aaeea6b5490ece6792aPetr Machata * does not find BP in PROC, it's hard error guarded by assertion.  */
234929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machatavoid proc_remove_breakpoint(struct process *proc, struct breakpoint *bp);
2352b46cfc1127d390eddd9593fe5ce5399c1f68130Petr Machata
236a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata/* Iterate through the breakpoints of PROC.  See callback.h for notes
237a24021c5abfa8c2482e3224f14ac191cd0826a8fPetr Machata * on iteration interfaces.  */
2386bcc092da6b7e20c6c2a9a5846536fbd3d77dbb8Petr Machataarch_addr_t *proc_each_breakpoint(struct process *proc, arch_addr_t *start,
2396bcc092da6b7e20c6c2a9a5846536fbd3d77dbb8Petr Machata				  enum callback_status (*cb)
2406bcc092da6b7e20c6c2a9a5846536fbd3d77dbb8Petr Machata					(struct process *proc,
2416bcc092da6b7e20c6c2a9a5846536fbd3d77dbb8Petr Machata					 struct breakpoint *bp,
2426bcc092da6b7e20c6c2a9a5846536fbd3d77dbb8Petr Machata					 void *data),
2436bcc092da6b7e20c6c2a9a5846536fbd3d77dbb8Petr Machata				  void *data);
244d3cc9889fdfe2e523e99ca5f664f8ae4b3936612Petr Machata
245cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias/* Iterate through the dynamic section at src_addr looking for D_TAG.
246cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias * If tag is found, fill it's value in RET and return 0.
247cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias * If tag is not found, return a negative value.  */
248929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_find_dynamic_entry_addr(struct process *proc, arch_addr_t src_addr,
249cc77b0e0e735d598f4bc746f8e79b6cd342bd606Edgar E. Iglesias				 int d_tag, arch_addr_t *ret);
250165b566a50b2bd560af3bd9649e456915397066bPetr Machata
251165b566a50b2bd560af3bd9649e456915397066bPetr Machata/* Finds a symbol corresponding to LIBSYM in a process PROC.  Returns
252165b566a50b2bd560af3bd9649e456915397066bPetr Machata * 0 and sets *RETLIB and *RETSYM if the corresponding pointer is
253165b566a50b2bd560af3bd9649e456915397066bPetr Machata * non-NULL.  Returns a negative value when the symbols couldn't be
254165b566a50b2bd560af3bd9649e456915397066bPetr Machata * found.  */
255929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machataint proc_find_symbol(struct process *proc, struct library_symbol *sym,
256165b566a50b2bd560af3bd9649e456915397066bPetr Machata		     struct library **retlib, struct library_symbol **retsym);
257165b566a50b2bd560af3bd9649e456915397066bPetr Machata
2583240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata/* Iterate through all symbols in all libraries of PROC.  See
2593240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata * callback.h for notes on this interface.  */
2603240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machatastruct library_symbol *proc_each_symbol
261929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	(struct process *proc, struct library_symbol *start_after,
2623240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata	 enum callback_status (*cb)(struct library_symbol *, void *),
2633240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata	 void *data);
2643240554e943bf773aa57b7e3e3bf80d7102a8b10Petr Machata
265dc70e76a94f842e2b8eaf0b9c2aabb829dc4826aPetr Machata/* Read 8, 16, 32 or 64-bit quantity located at ADDR in PROC.  The
266653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata * resulting value is stored in *LP.  0 is returned on success or a
267653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata * negative value on failure.  This uses umovebytes under the hood
268653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata * (see backend.h).  */
269dc70e76a94f842e2b8eaf0b9c2aabb829dc4826aPetr Machataint proc_read_8(struct process *proc, arch_addr_t addr, uint8_t *lp);
270653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machataint proc_read_16(struct process *proc, arch_addr_t addr, uint16_t *lp);
271653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machataint proc_read_32(struct process *proc, arch_addr_t addr, uint32_t *lp);
272653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machataint proc_read_64(struct process *proc, arch_addr_t addr, uint64_t *lp);
273653085a32cdc89f5215c2d70249b58c9fe6aebb7Petr Machata
274366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#endif /* _PROC_H_ */
275