1e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata/*
2e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * This file is part of ltrace.
3e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * Copyright (C) 2009 Juan Cespedes
4e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata *
5e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * This program is free software; you can redistribute it and/or
6e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * modify it under the terms of the GNU General Public License as
7e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * published by the Free Software Foundation; either version 2 of the
8e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * License, or (at your option) any later version.
9e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata *
10e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * This program is distributed in the hope that it will be useful, but
11e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * WITHOUT ANY WARRANTY; without even the implied warranty of
12e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * General Public License for more details.
14e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata *
15e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * You should have received a copy of the GNU General Public License
16e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * along with this program; if not, write to the Free Software
17e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata * 02110-1301 USA
19e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata */
20e99af270a60891e68d465c4cd97dbe29cd1a05e4Petr Machata
21366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#ifndef _LTRACE_H_
22366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#define _LTRACE_H_
23366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
2461da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedestypedef enum Event_type Event_type;
2561da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedesenum Event_type {
262a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_NONE=0,
272a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_SIGNAL,
282a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_EXIT,
292a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_EXIT_SIGNAL,
302a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_SYSCALL,
312a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_SYSRET,
322a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_ARCH_SYSCALL,
332a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_ARCH_SYSRET,
342a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_CLONE,
35cbe29c6c0ad01839a81272c4715ea73d17e89611Petr Machata	EVENT_VFORK,
362a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_EXEC,
372a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_BREAKPOINT,
38427b7811598f905b583ac86b35c72228fd415476Juan Cespedes	EVENT_LIBCALL,
39427b7811598f905b583ac86b35c72228fd415476Juan Cespedes	EVENT_LIBRET,
402a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_NEW,        /* in this case, proc is NULL */
412a61d19bd244dadcde5009f1632cf14b95623e3dJuan Cespedes	EVENT_MAX
4261da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedes};
4361da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedes
4461da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedestypedef struct Event Event;
4561da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedesstruct Event {
4669a03e6f8c15fb0272089e387a658acad887fb9cPetr Machata	struct Event * next;
47929bd57ca202fd2f2e8485ebf65d683e664f67b5Petr Machata	struct process *proc;
4861da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedes	Event_type type;
4940dc6353a443f2eed64fcada3bcf305e56855b15Juan Cespedes	union {
5061da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedes		int ret_val;     /* EVENT_EXIT */
5161da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedes		int signum;      /* EVENT_SIGNAL, EVENT_EXIT_SIGNAL */
5261da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedes		int sysnum;      /* EVENT_SYSCALL, EVENT_SYSRET */
5361da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedes		void * brk_addr; /* EVENT_BREAKPOINT */
5461da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedes		int newpid;      /* EVENT_CLONE, EVENT_NEW */
5540dc6353a443f2eed64fcada3bcf305e56855b15Juan Cespedes	} e_un;
5640dc6353a443f2eed64fcada3bcf305e56855b15Juan Cespedes};
5740dc6353a443f2eed64fcada3bcf305e56855b15Juan Cespedes
5861da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedestypedef void (*callback_func) (Event *);
5961da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedes
603df476b28e4a9cdb43cf29fff8e89481310eb30dJuan Cespedesextern void ltrace_init(int argc, char **argv);
6161da33723c5fb09762e38bd39a26ee15d62ffebcJuan Cespedesextern void ltrace_add_callback(callback_func f, Event_type type);
623df476b28e4a9cdb43cf29fff8e89481310eb30dJuan Cespedesextern void ltrace_main(void);
63366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata
64366c2f46d844f040458df9b7e35fc3b8527ed2d3Petr Machata#endif /* _LTRACE_H_ */
65