vgdb.h revision 436e89c602e787e7a27dd6624b09beed41a0da8a
1
2/*--------------------------------------------------------------------*/
3/*--- Declarations common for vgdb and implementations             ---*/
4/*--- of vgdb-invoker.                                      vgdb.h ---*/
5/*--------------------------------------------------------------------*/
6
7/*
8   This file is part of Valgrind, a dynamic binary instrumentation
9   framework.
10
11   Copyright (C) 2011-2013 Philippe Waroquiers
12
13   This program is free software; you can redistribute it and/or
14   modify it under the terms of the GNU General Public License as
15   published by the Free Software Foundation; either version 2 of the
16   License, or (at your option) any later version.
17
18   This program is distributed in the hope that it will be useful, but
19   WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21   General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with this program; if not, write to the Free Software
25   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26   02111-1307, USA.
27
28   The GNU General Public License is contained in the file COPYING.
29*/
30
31#ifndef __VGDB_H
32#define __VGDB_H
33
34#include "pub_core_basics.h"
35#include "pub_core_vki.h"
36#include "pub_core_gdbserver.h"
37
38#include <sys/types.h>
39
40extern int debuglevel;
41extern struct timeval dbgtv;
42/* if level <= debuglevel, print timestamp, then print provided by debug info */
43#define DEBUG(level, ...) (level <= debuglevel ?                        \
44                           gettimeofday(&dbgtv, NULL),                  \
45                           fprintf(stderr, "%ld.%6.6ld ",               \
46                                   (long int)dbgtv.tv_sec,              \
47                                   (long int)dbgtv.tv_usec),            \
48                           fprintf(stderr, __VA_ARGS__),fflush(stderr)  \
49                           : 0)
50
51/* same as DEBUG but does not print time stamp info */
52#define PDEBUG(level, ...) (level <= debuglevel ?                       \
53                            fprintf(stderr, __VA_ARGS__),fflush(stderr) \
54                            : 0)
55
56/* if errno != 0,
57   report the errno and fprintf the ... varargs on stderr. */
58#define ERROR(errno, ...) ((errno == 0 ? 0 : perror("syscall failed")), \
59                           fprintf(stderr, __VA_ARGS__),                \
60                           fflush(stderr))
61/* same as ERROR, but also exits with status 1 */
62#define XERROR(errno, ...) ((errno == 0 ? 0 : perror("syscall failed")), \
63                            fprintf(stderr, __VA_ARGS__),                \
64                            fflush(stderr),                              \
65                            exit(1))
66
67/* Will be set to True when any condition indicating we have to shutdown
68   is encountered. */
69extern Bool shutting_down;
70
71extern VgdbShared32 *shared32;
72extern VgdbShared64 *shared64;
73
74/*--------------------------------------------------------------------*/
75/*--- Below is vgdb-invoker interface which must be implemented by ---*/
76/*--- all vgdb-invoker implementations.                            ---*/
77/*--------------------------------------------------------------------*/
78
79/* Possibly produces additional usage information documenting the
80   invoker restrictions. */
81void invoker_restrictions_msg(void);
82
83/* Restore the registers to the saved value, then detaches from all threads.
84   Used as a cleanup handler for thread cancellation. */
85void invoker_cleanup_restore_and_detach(void *v_pid);
86
87/* Ensures that the gdbserver code is invoked by pid.
88   If an error occurs, resets the valgrind process
89   to the state it had before being invoked.
90   Returns True if invoke successful, False otherwise. */
91Bool invoker_invoke_gdbserver(pid_t pid);
92
93/* Called when connection with valgrind is lost.  In case we
94   have lost the connection, it means that Valgrind has closed the
95   connection and is busy exiting. We can't and don't have to stop it in
96   this case. */
97void invoker_valgrind_dying(void);
98
99#endif // __VGDB_H
100
101/*--------------------------------------------------------------------*/
102/*--- end                                                          ---*/
103/*--------------------------------------------------------------------*/
104