proc.h revision fd43ef7bb48260aadd4d8335371f75015e680108
1#ifndef _PROC_H_
2#define _PROC_H_
3
4#if defined(HAVE_LIBUNWIND)
5# include <libunwind.h>
6#endif /* defined(HAVE_LIBUNWIND) */
7
8#include "ltrace.h"
9#include "dict.h"
10
11struct event_handler {
12	/* Event handler that overrides the default one.  Should
13	 * return NULL if the event was handled, otherwise the
14	 * returned event is passed to the default handler.  */
15	Event *(*on_event)(struct event_handler *self, Event *event);
16
17	/* Called when the event handler removal is requested.  */
18	void (*destroy)(struct event_handler *self);
19};
20
21enum process_state {
22	STATE_ATTACHED = 0,
23	STATE_BEING_CREATED,
24	STATE_IGNORED  /* ignore this process (it's a fork and no -f was used) */
25};
26
27enum pcb_status {
28	pcb_stop, /* The iteration should stop.  */
29	pcb_cont, /* The iteration should continue.  */
30};
31
32struct callstack_element {
33	union {
34		int syscall;
35		struct library_symbol * libfunc;
36	} c_un;
37	int is_syscall;
38	void * return_addr;
39	struct timeval time_spent;
40	void * arch_ptr;
41};
42
43/* XXX We should get rid of this.  */
44#define MAX_CALLDEPTH 64
45
46/* XXX We would rather have this all organized a little differently,
47 * have Process for the whole group and Task for what's there for
48 * per-thread stuff.  But for now this is the less invasive way of
49 * structuring it.  */
50typedef struct Process Process;
51struct Process {
52	enum process_state state;
53	Process * parent;         /* needed by STATE_BEING_CREATED */
54	char * filename;
55	pid_t pid;
56
57	/* Dictionary of breakpoints (which is a mapping
58	 * address->breakpoint).  This is NULL for non-leader
59	 * processes.  */
60	Dict * breakpoints;
61
62	int mask_32bit;           /* 1 if 64-bit ltrace is tracing 32-bit process */
63	unsigned int personality;
64	int tracesysgood;         /* signal indicating a PTRACE_SYSCALL trap */
65
66	int callstack_depth;
67	struct callstack_element callstack[MAX_CALLDEPTH];
68	struct library_symbol * list_of_symbols;
69
70	int libdl_hooked;
71	/* Arch-dependent: */
72	void * debug;	/* arch-dep process debug struct */
73	long debug_state; /* arch-dep debug state */
74	void * instruction_pointer;
75	void * stack_pointer;      /* To get return addr, args... */
76	void * return_addr;
77	void * arch_ptr;
78	short e_machine;
79	short need_to_reinitialize_breakpoints;
80#ifdef __arm__
81	int thumb_mode;           /* ARM execution mode: 0: ARM, 1: Thumb */
82#endif
83
84#if defined(HAVE_LIBUNWIND)
85	/* libunwind address space */
86	unw_addr_space_t unwind_as;
87	void *unwind_priv;
88#endif /* defined(HAVE_LIBUNWIND) */
89
90	/* Set in leader.  */
91	struct event_handler *event_handler;
92
93	/**
94	 * Process chaining.
95	 **/
96	Process * next;
97
98	/* LEADER points to the leader thread of the POSIX.1 process.
99	   If X->LEADER == X, then X is the leader thread and the
100	   Process structures chained by NEXT represent other threads,
101	   up until, but not including, the next leader thread.
102	   LEADER may be NULL after the leader has already exited.  In
103	   that case this process is waiting to be collected.  */
104	Process * leader;
105};
106
107Process * open_program(char *filename, pid_t pid, int init_breakpoints);
108void open_pid(pid_t pid);
109Process * pid2proc(pid_t pid);
110Process *each_process(Process *start,
111		      enum pcb_status (* cb)(Process *proc, void *data),
112		      void *data);
113Process *each_task(Process *start,
114		   enum pcb_status (* cb)(Process *proc, void *data),
115		   void *data);
116void add_process(Process *proc);
117void change_process_leader(Process *proc, Process *leader);
118void remove_process(Process *proc);
119void install_event_handler(Process *proc, struct event_handler *handler);
120void destroy_event_handler(Process *proc);
121
122#endif /* _PROC_H_ */
123