Home | History | Annotate | Download | only in coregrind
      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-2015 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 
     40 extern int debuglevel;
     41 extern 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 /* Calls malloc (size). Exits if memory can't be allocated. */
     68 extern void *vmalloc(size_t size);
     69 /* Calls realloc (size). Exits if memory can't be allocated. */
     70 extern void *vrealloc(void *ptr,size_t size);
     71 
     72 /* Will be set to True when any condition indicating we have to shutdown
     73    is encountered. */
     74 extern Bool shutting_down;
     75 
     76 extern VgdbShared32 *shared32;
     77 extern VgdbShared64 *shared64;
     78 
     79 /*--------------------------------------------------------------------*/
     80 /*--- Below is vgdb-invoker interface which must be implemented by ---*/
     81 /*--- all vgdb-invoker implementations.                            ---*/
     82 /*--------------------------------------------------------------------*/
     83 
     84 /* Possibly produces additional usage information documenting the
     85    invoker restrictions. */
     86 void invoker_restrictions_msg(void);
     87 
     88 /* Restore the registers to the saved value, then detaches from all threads.
     89    Used as a cleanup handler for thread cancellation. */
     90 void invoker_cleanup_restore_and_detach(void *v_pid);
     91 
     92 /* Ensures that the gdbserver code is invoked by pid.
     93    If an error occurs, resets the valgrind process
     94    to the state it had before being invoked.
     95    Returns True if invoke successful, False otherwise. */
     96 Bool invoker_invoke_gdbserver(pid_t pid);
     97 
     98 /* Called when connection with valgrind is lost.  In case we
     99    have lost the connection, it means that Valgrind has closed the
    100    connection and is busy exiting. We can't and don't have to stop it in
    101    this case. */
    102 void invoker_valgrind_dying(void);
    103 
    104 #endif // __VGDB_H
    105 
    106 /*--------------------------------------------------------------------*/
    107 /*--- end                                                          ---*/
    108 /*--------------------------------------------------------------------*/
    109