1 /* Definitions of interface to the "low" (arch specific) functions 2 needed for interfacing the Valgrind gdbserver with the Valgrind 3 guest. 4 5 Copyright (C) 2011, 2012 6 Free Software Foundation, Inc. 7 8 This file has been inspired from a file that is part of GDB. 9 It has been modified to integrate it in valgrind 10 11 This program is free software; you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation; either version 2 of the License, or 14 (at your option) any later version. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin Street, Fifth Floor, 24 Boston, MA 02110-1301, USA. */ 25 26 #ifndef VALGRIND_LOW_H 27 #define VALGRIND_LOW_H 28 29 #include "pub_core_basics.h" // ThreadId 30 #include "server.h" // CORE_ADDR 31 32 /* defines the characteristics of the "low" valgrind target architecture. 33 In other words, struct valgrind_target_ops defines the functions and 34 data which are specific to the architecture (x86 or amd64 or 35 ppc32 or ...). */ 36 struct valgrind_target_ops 37 { 38 int num_regs; 39 struct reg *reg_defs; 40 41 int stack_pointer_regno; 42 /* register number of the stack pointer register */ 43 44 /* transfer the register regno from/to valgrind (guest state) 45 to/from buf 46 according to transfer_direction. 47 *mod set to True if destination content is modified by the transfer 48 otherwise it is set to False. */ 49 void (*transfer_register) (ThreadId tid, int regno, void * buf, 50 transfer_direction dir, int size, Bool *mod); 51 52 53 CORE_ADDR (*get_pc) (void); 54 void (*set_pc) (CORE_ADDR newpc); 55 56 /* What string to report to GDB when it asks for the architecture, 57 or NULL not to answer. */ 58 const char *arch_string; 59 60 /* Returns the target xml description of the set of registers. 61 For some architectures (e.g. arm), it is mandatory 62 to give a description of the registers, otherwise 63 gdb does not understand the reply to the 'g' packet 64 (which is used to get the registers). 65 If shadow_mode, returns a target xml description 66 including the two shadow registers sets. 67 This is mandatory to use the option --vgdb-shadow-registers=yes. 68 Returns NULL if there is no target xml file*/ 69 const char* (*target_xml) (Bool shadow_mode); 70 71 /* Returns the address in the thread control block where dtv is found. 72 Return NULL if an error occurs or no support for tls/dtv is available. 73 Note that the addressability of the returned result has not been 74 verified. In other words, target_get_dtv just adds some magic 75 offset to the arch specific thread register or thread pointer or ... 76 77 The implementation of this is of course depending on the arch 78 but also depends on the way pthread lib arranges its data. 79 For background info about tls handling, read 80 'ELF Handling For Thread-Local Storage' 81 http://www.akkadia.org/drepper/tls.pdf 82 (slightly obsolete e.g. the size of a dtv entry is 2 words now). 83 The reference is the glibc source, in particular the arch specific 84 file tls.h. 85 86 For platforms where the dtv is located in the tcb, the magic offset 87 to add to the thread pointer/register/... can be found by doing: 88 cd none/tests 89 gdb ./tls 90 set debug-file-directory /usr/lib/debug # or equivalent 91 start 92 p &((struct pthread*)0x0)->header.dtv 93 Currently the dtv offset is hardcoded, based on the assumption 94 that this is relatively stable. If that would be false, then 95 getoff-<platform> should be modified to output this offset e.g. 96 depending on the glibc version. */ 97 CORE_ADDR** (*target_get_dtv)(ThreadState *tst); 98 99 }; 100 101 extern void x86_init_architecture (struct valgrind_target_ops *target); 102 extern void amd64_init_architecture (struct valgrind_target_ops *target); 103 extern void arm_init_architecture (struct valgrind_target_ops *target); 104 extern void arm64_init_architecture (struct valgrind_target_ops *target); 105 extern void ppc32_init_architecture (struct valgrind_target_ops *target); 106 extern void ppc64_init_architecture (struct valgrind_target_ops *target); 107 extern void s390x_init_architecture (struct valgrind_target_ops *target); 108 extern void mips32_init_architecture (struct valgrind_target_ops *target); 109 extern void mips64_init_architecture (struct valgrind_target_ops *target); 110 111 #endif 112