17f2ac410Schristos /* Target-dependent code for X86-based targets. 27f2ac410Schristos 3*6881a400Schristos Copyright (C) 2018-2023 Free Software Foundation, Inc. 47f2ac410Schristos 57f2ac410Schristos This file is part of GDB. 67f2ac410Schristos 77f2ac410Schristos This program is free software; you can redistribute it and/or modify 87f2ac410Schristos it under the terms of the GNU General Public License as published by 97f2ac410Schristos the Free Software Foundation; either version 3 of the License, or 107f2ac410Schristos (at your option) any later version. 117f2ac410Schristos 127f2ac410Schristos This program is distributed in the hope that it will be useful, 137f2ac410Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 147f2ac410Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 157f2ac410Schristos GNU General Public License for more details. 167f2ac410Schristos 177f2ac410Schristos You should have received a copy of the GNU General Public License 187f2ac410Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 197f2ac410Schristos 207f2ac410Schristos #include "defs.h" 217f2ac410Schristos #include "x86-tdep.h" 227d62b00eSchristos #include "symtab.h" 237f2ac410Schristos 247f2ac410Schristos 257f2ac410Schristos /* Check whether NAME is included in NAMES[LO] (inclusive) to NAMES[HI] 267f2ac410Schristos (exclusive). */ 277f2ac410Schristos 287f2ac410Schristos static bool 29*6881a400Schristos x86_is_thunk_register_name (const char *name, const char * const *names, 30*6881a400Schristos int lo, int hi) 317f2ac410Schristos { 327f2ac410Schristos int reg; 337f2ac410Schristos for (reg = lo; reg < hi; ++reg) 347f2ac410Schristos if (strcmp (name, names[reg]) == 0) 357f2ac410Schristos return true; 367f2ac410Schristos 377f2ac410Schristos return false; 387f2ac410Schristos } 397f2ac410Schristos 407f2ac410Schristos /* See x86-tdep.h. */ 417f2ac410Schristos 427f2ac410Schristos bool 43*6881a400Schristos x86_in_indirect_branch_thunk (CORE_ADDR pc, const char * const *register_names, 447f2ac410Schristos int lo, int hi) 457f2ac410Schristos { 467f2ac410Schristos struct bound_minimal_symbol bmfun = lookup_minimal_symbol_by_pc (pc); 477f2ac410Schristos if (bmfun.minsym == nullptr) 487f2ac410Schristos return false; 497f2ac410Schristos 507d62b00eSchristos const char *name = bmfun.minsym->linkage_name (); 517f2ac410Schristos if (name == nullptr) 527f2ac410Schristos return false; 537f2ac410Schristos 547f2ac410Schristos /* Check the indirect return thunk first. */ 557f2ac410Schristos if (strcmp (name, "__x86_return_thunk") == 0) 567f2ac410Schristos return true; 577f2ac410Schristos 587f2ac410Schristos /* Then check a family of indirect call/jump thunks. */ 597f2ac410Schristos static const char thunk[] = "__x86_indirect_thunk"; 607f2ac410Schristos static const size_t length = sizeof (thunk) - 1; 617f2ac410Schristos if (strncmp (name, thunk, length) != 0) 627f2ac410Schristos return false; 637f2ac410Schristos 647f2ac410Schristos /* If that's the complete name, we're in the memory thunk. */ 657f2ac410Schristos name += length; 667f2ac410Schristos if (*name == '\0') 677f2ac410Schristos return true; 687f2ac410Schristos 697f2ac410Schristos /* Check for suffixes. */ 707f2ac410Schristos if (*name++ != '_') 717f2ac410Schristos return false; 727f2ac410Schristos 737f2ac410Schristos if (x86_is_thunk_register_name (name, register_names, lo, hi)) 747f2ac410Schristos return true; 757f2ac410Schristos 767f2ac410Schristos return false; 777f2ac410Schristos } 78