13b290486cd4cd601b20e04340e593c9ed9717e5fsewardj/* Definitions of interface to the "low" (arch specific) functions 23b290486cd4cd601b20e04340e593c9ed9717e5fsewardj needed for interfacing the Valgrind gdbserver with the Valgrind 33b290486cd4cd601b20e04340e593c9ed9717e5fsewardj guest. 43b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 50447bbd096d5b08db6e4483b8138888a9fa0802aphilippe Copyright (C) 2011, 2012 63b290486cd4cd601b20e04340e593c9ed9717e5fsewardj Free Software Foundation, Inc. 73b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 83b290486cd4cd601b20e04340e593c9ed9717e5fsewardj This file has been inspired from a file that is part of GDB. 93b290486cd4cd601b20e04340e593c9ed9717e5fsewardj It has been modified to integrate it in valgrind 103b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 113b290486cd4cd601b20e04340e593c9ed9717e5fsewardj This program is free software; you can redistribute it and/or modify 123b290486cd4cd601b20e04340e593c9ed9717e5fsewardj it under the terms of the GNU General Public License as published by 133b290486cd4cd601b20e04340e593c9ed9717e5fsewardj the Free Software Foundation; either version 2 of the License, or 143b290486cd4cd601b20e04340e593c9ed9717e5fsewardj (at your option) any later version. 153b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 163b290486cd4cd601b20e04340e593c9ed9717e5fsewardj This program is distributed in the hope that it will be useful, 173b290486cd4cd601b20e04340e593c9ed9717e5fsewardj but WITHOUT ANY WARRANTY; without even the implied warranty of 183b290486cd4cd601b20e04340e593c9ed9717e5fsewardj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 193b290486cd4cd601b20e04340e593c9ed9717e5fsewardj GNU General Public License for more details. 203b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 213b290486cd4cd601b20e04340e593c9ed9717e5fsewardj You should have received a copy of the GNU General Public License 223b290486cd4cd601b20e04340e593c9ed9717e5fsewardj along with this program; if not, write to the Free Software 233b290486cd4cd601b20e04340e593c9ed9717e5fsewardj Foundation, Inc., 51 Franklin Street, Fifth Floor, 243b290486cd4cd601b20e04340e593c9ed9717e5fsewardj Boston, MA 02110-1301, USA. */ 253b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 263b290486cd4cd601b20e04340e593c9ed9717e5fsewardj#ifndef VALGRIND_LOW_H 273b290486cd4cd601b20e04340e593c9ed9717e5fsewardj#define VALGRIND_LOW_H 283b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 29535fb1b49a80f2e880f755ee618381de3e222ddfflorian#include "pub_core_basics.h" // ThreadId 30535fb1b49a80f2e880f755ee618381de3e222ddfflorian#include "server.h" // CORE_ADDR 31535fb1b49a80f2e880f755ee618381de3e222ddfflorian 323b290486cd4cd601b20e04340e593c9ed9717e5fsewardj/* defines the characteristics of the "low" valgrind target architecture. 333b290486cd4cd601b20e04340e593c9ed9717e5fsewardj In other words, struct valgrind_target_ops defines the functions and 343b290486cd4cd601b20e04340e593c9ed9717e5fsewardj data which are specific to the architecture (x86 or amd64 or 353b290486cd4cd601b20e04340e593c9ed9717e5fsewardj ppc32 or ...). */ 363b290486cd4cd601b20e04340e593c9ed9717e5fsewardjstruct valgrind_target_ops 373b290486cd4cd601b20e04340e593c9ed9717e5fsewardj{ 383b290486cd4cd601b20e04340e593c9ed9717e5fsewardj int num_regs; 393b290486cd4cd601b20e04340e593c9ed9717e5fsewardj struct reg *reg_defs; 403b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 413b290486cd4cd601b20e04340e593c9ed9717e5fsewardj int stack_pointer_regno; 423b290486cd4cd601b20e04340e593c9ed9717e5fsewardj /* register number of the stack pointer register */ 433b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 443b290486cd4cd601b20e04340e593c9ed9717e5fsewardj /* transfer the register regno from/to valgrind (guest state) 453b290486cd4cd601b20e04340e593c9ed9717e5fsewardj to/from buf 463b290486cd4cd601b20e04340e593c9ed9717e5fsewardj according to transfer_direction. 473b290486cd4cd601b20e04340e593c9ed9717e5fsewardj *mod set to True if destination content is modified by the transfer 483b290486cd4cd601b20e04340e593c9ed9717e5fsewardj otherwise it is set to False. */ 493b290486cd4cd601b20e04340e593c9ed9717e5fsewardj void (*transfer_register) (ThreadId tid, int regno, void * buf, 503b290486cd4cd601b20e04340e593c9ed9717e5fsewardj transfer_direction dir, int size, Bool *mod); 513b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 523b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 533b290486cd4cd601b20e04340e593c9ed9717e5fsewardj CORE_ADDR (*get_pc) (void); 543b290486cd4cd601b20e04340e593c9ed9717e5fsewardj void (*set_pc) (CORE_ADDR newpc); 553b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 563b290486cd4cd601b20e04340e593c9ed9717e5fsewardj /* What string to report to GDB when it asks for the architecture, 573b290486cd4cd601b20e04340e593c9ed9717e5fsewardj or NULL not to answer. */ 583b290486cd4cd601b20e04340e593c9ed9717e5fsewardj const char *arch_string; 593b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 60419d5f2931a88d5e15e78fdaeac4d550aaf1e789philippe /* Returns the target xml description of the set of registers. 613b290486cd4cd601b20e04340e593c9ed9717e5fsewardj For some architectures (e.g. arm), it is mandatory 623b290486cd4cd601b20e04340e593c9ed9717e5fsewardj to give a description of the registers, otherwise 633b290486cd4cd601b20e04340e593c9ed9717e5fsewardj gdb does not understand the reply to the 'g' packet 64419d5f2931a88d5e15e78fdaeac4d550aaf1e789philippe (which is used to get the registers). 65419d5f2931a88d5e15e78fdaeac4d550aaf1e789philippe If shadow_mode, returns a target xml description 66419d5f2931a88d5e15e78fdaeac4d550aaf1e789philippe including the two shadow registers sets. 67419d5f2931a88d5e15e78fdaeac4d550aaf1e789philippe This is mandatory to use the option --vgdb-shadow-registers=yes. 68419d5f2931a88d5e15e78fdaeac4d550aaf1e789philippe Returns NULL if there is no target xml file*/ 696bd9dc18c043927c1196caba20a327238a179c42florian const char* (*target_xml) (Bool shadow_mode); 703b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 711670b05a4a415dbfd75b1a120713b4a206bb719ephilippe /* Returns the address in the thread control block where dtv is found. 721670b05a4a415dbfd75b1a120713b4a206bb719ephilippe Return NULL if an error occurs or no support for tls/dtv is available. 731670b05a4a415dbfd75b1a120713b4a206bb719ephilippe Note that the addressability of the returned result has not been 741670b05a4a415dbfd75b1a120713b4a206bb719ephilippe verified. In other words, target_get_dtv just adds some magic 751670b05a4a415dbfd75b1a120713b4a206bb719ephilippe offset to the arch specific thread register or thread pointer or ... 761670b05a4a415dbfd75b1a120713b4a206bb719ephilippe 771670b05a4a415dbfd75b1a120713b4a206bb719ephilippe The implementation of this is of course depending on the arch 781670b05a4a415dbfd75b1a120713b4a206bb719ephilippe but also depends on the way pthread lib arranges its data. 791670b05a4a415dbfd75b1a120713b4a206bb719ephilippe For background info about tls handling, read 801670b05a4a415dbfd75b1a120713b4a206bb719ephilippe 'ELF Handling For Thread-Local Storage' 811670b05a4a415dbfd75b1a120713b4a206bb719ephilippe http://www.akkadia.org/drepper/tls.pdf 821670b05a4a415dbfd75b1a120713b4a206bb719ephilippe (slightly obsolete e.g. the size of a dtv entry is 2 words now). 831670b05a4a415dbfd75b1a120713b4a206bb719ephilippe The reference is the glibc source, in particular the arch specific 841670b05a4a415dbfd75b1a120713b4a206bb719ephilippe file tls.h. 851670b05a4a415dbfd75b1a120713b4a206bb719ephilippe 861670b05a4a415dbfd75b1a120713b4a206bb719ephilippe For platforms where the dtv is located in the tcb, the magic offset 871670b05a4a415dbfd75b1a120713b4a206bb719ephilippe to add to the thread pointer/register/... can be found by doing: 881670b05a4a415dbfd75b1a120713b4a206bb719ephilippe cd none/tests 891670b05a4a415dbfd75b1a120713b4a206bb719ephilippe gdb ./tls 901670b05a4a415dbfd75b1a120713b4a206bb719ephilippe set debug-file-directory /usr/lib/debug # or equivalent 911670b05a4a415dbfd75b1a120713b4a206bb719ephilippe start 921670b05a4a415dbfd75b1a120713b4a206bb719ephilippe p &((struct pthread*)0x0)->header.dtv 931670b05a4a415dbfd75b1a120713b4a206bb719ephilippe Currently the dtv offset is hardcoded, based on the assumption 941670b05a4a415dbfd75b1a120713b4a206bb719ephilippe that this is relatively stable. If that would be false, then 951670b05a4a415dbfd75b1a120713b4a206bb719ephilippe getoff-<platform> should be modified to output this offset e.g. 961670b05a4a415dbfd75b1a120713b4a206bb719ephilippe depending on the glibc version. */ 971670b05a4a415dbfd75b1a120713b4a206bb719ephilippe CORE_ADDR** (*target_get_dtv)(ThreadState *tst); 981670b05a4a415dbfd75b1a120713b4a206bb719ephilippe 993b290486cd4cd601b20e04340e593c9ed9717e5fsewardj}; 1003b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 1013b290486cd4cd601b20e04340e593c9ed9717e5fsewardjextern void x86_init_architecture (struct valgrind_target_ops *target); 1023b290486cd4cd601b20e04340e593c9ed9717e5fsewardjextern void amd64_init_architecture (struct valgrind_target_ops *target); 1033b290486cd4cd601b20e04340e593c9ed9717e5fsewardjextern void arm_init_architecture (struct valgrind_target_ops *target); 104f0c1250e324f6684757c6a15545366447ef1d64fsewardjextern void arm64_init_architecture (struct valgrind_target_ops *target); 1053b290486cd4cd601b20e04340e593c9ed9717e5fsewardjextern void ppc32_init_architecture (struct valgrind_target_ops *target); 1063b290486cd4cd601b20e04340e593c9ed9717e5fsewardjextern void ppc64_init_architecture (struct valgrind_target_ops *target); 1073b290486cd4cd601b20e04340e593c9ed9717e5fsewardjextern void s390x_init_architecture (struct valgrind_target_ops *target); 1085db15403e889d4db339b342bc2a824ef0bfaa654sewardjextern void mips32_init_architecture (struct valgrind_target_ops *target); 1094df0bfc0614379192c780c944415dc420d9cfe8epetarjextern void mips64_init_architecture (struct valgrind_target_ops *target); 1103b290486cd4cd601b20e04340e593c9ed9717e5fsewardj 1113b290486cd4cd601b20e04340e593c9ed9717e5fsewardj#endif 112