FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / coregrind / vgdb.h
blob03553296ba47297c48dce5d4d4db87c2b4c1164c
2 /*--------------------------------------------------------------------*/
3 /*--- Declarations common for vgdb and implementations ---*/
4 /*--- of vgdb-invoker. vgdb.h ---*/
5 /*--------------------------------------------------------------------*/
7 /*
8 This file is part of Valgrind, a dynamic binary instrumentation
9 framework.
11 Copyright (C) 2011-2017 Philippe Waroquiers
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #ifndef __VGDB_H
30 #define __VGDB_H
32 #include "pub_core_basics.h"
33 #include "pub_core_vki.h"
34 #include "pub_core_gdbserver.h"
36 #include <sys/types.h>
38 extern Bool timestamp;
39 extern char *timestamp_str (Bool produce);
40 extern int debuglevel;
42 /* Optionally prints a timestamp, then prints the given info. This should
43 be used only at the beginning of a new line. */
44 #define TSFPRINTF(stream, ...) ( \
45 fprintf(stream, "%s", timestamp_str(timestamp)), \
46 fprintf(stream, __VA_ARGS__),fflush(stream))
48 /* if level <= debuglevel, print timestamp, then prints provided debug info */
49 #define DEBUG(level, ...) (level <= debuglevel ? \
50 fprintf(stderr, "%s", timestamp_str(True)), \
51 fprintf(stderr, __VA_ARGS__),fflush(stderr) \
52 : 0)
54 /* same as DEBUG but does not print time stamp info */
55 #define PDEBUG(level, ...) (level <= debuglevel ? \
56 fprintf(stderr, __VA_ARGS__),fflush(stderr) \
57 : 0)
59 /* if errno != 0,
60 report the errno and fprintf the ... varargs on stderr. */
61 #define ERROR(errno, ...) ((errno == 0 ? 0 : perror("syscall failed")), \
62 fprintf(stderr, "%s", timestamp_str(timestamp)), \
63 fprintf(stderr, __VA_ARGS__), \
64 fflush(stderr))
65 /* same as ERROR, but also exits with status 1 */
66 #define XERROR(errno, ...) ((errno == 0 ? 0 : perror("syscall failed")), \
67 fprintf(stderr, "%s", timestamp_str(timestamp)), \
68 fprintf(stderr, __VA_ARGS__), \
69 fflush(stderr), \
70 exit(1))
72 /* Calls malloc (size). Exits if memory can't be allocated. */
73 extern void *vmalloc(size_t size);
74 /* Calls realloc (size). Exits if memory can't be allocated. */
75 extern void *vrealloc(void *ptr,size_t size);
77 /* Will be set to True when any condition indicating we have to shutdown
78 is encountered. */
79 extern Bool shutting_down;
81 extern VgdbShared32 *shared32;
82 extern VgdbShared64 *shared64;
84 /*--------------------------------------------------------------------*/
85 /*--- Below is vgdb-invoker interface which must be implemented by ---*/
86 /*--- all vgdb-invoker implementations. ---*/
87 /*--------------------------------------------------------------------*/
89 /* Possibly produces additional usage information documenting the
90 invoker restrictions. */
91 void invoker_restrictions_msg(void);
93 /* Restore the registers to the saved value, then detaches from all threads.
94 Used as a cleanup handler for thread cancellation. */
95 void invoker_cleanup_restore_and_detach(void *v_pid);
97 /* Ensures that the gdbserver code is invoked by pid.
98 If an error occurs, resets the valgrind process
99 to the state it had before being invoked.
100 Returns True if invoke successful, False otherwise. */
101 Bool invoker_invoke_gdbserver(pid_t pid);
103 /* Called when connection with valgrind is lost. In case we
104 have lost the connection, it means that Valgrind has closed the
105 connection and is busy exiting. We can't and don't have to stop it in
106 this case. */
107 void invoker_valgrind_dying(void);
109 #endif // __VGDB_H
111 /*--------------------------------------------------------------------*/
112 /*--- end ---*/
113 /*--------------------------------------------------------------------*/