gdb/gdbserver/linux-amd64-ipa.c - gdb

Global variables defined

Functions defined

Macros defined

Source code

  1. /* GNU/Linux/x86-64 specific low level interface, for the in-process
  2.    agent library for GDB.

  3.    Copyright (C) 2010-2015 Free Software Foundation, Inc.

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "server.h"
  16. #include "tracepoint.h"

  17. /* Defined in auto-generated file amd64-linux.c.  */
  18. void init_registers_amd64_linux (void);
  19. extern const struct target_desc *tdesc_amd64_linux;

  20. /* fast tracepoints collect registers.  */

  21. #define FT_CR_RIP 0
  22. #define FT_CR_EFLAGS 1
  23. #define FT_CR_R8 2
  24. #define FT_CR_R9 3
  25. #define FT_CR_R10 4
  26. #define FT_CR_R11 5
  27. #define FT_CR_R12 6
  28. #define FT_CR_R13 7
  29. #define FT_CR_R14 8
  30. #define FT_CR_R15 9
  31. #define FT_CR_RAX 10
  32. #define FT_CR_RBX 11
  33. #define FT_CR_RCX 12
  34. #define FT_CR_RDX 13
  35. #define FT_CR_RSI 14
  36. #define FT_CR_RDI 15
  37. #define FT_CR_RBP 16
  38. #define FT_CR_RSP 17

  39. static const int x86_64_ft_collect_regmap[] = {
  40.   FT_CR_RAX * 8, FT_CR_RBX * 8, FT_CR_RCX * 8, FT_CR_RDX * 8,
  41.   FT_CR_RSI * 8, FT_CR_RDI * 8, FT_CR_RBP * 8, FT_CR_RSP * 8,
  42.   FT_CR_R8 * 8FT_CR_R9 * 8FT_CR_R10 * 8, FT_CR_R11 * 8,
  43.   FT_CR_R12 * 8, FT_CR_R13 * 8, FT_CR_R14 * 8, FT_CR_R15 * 8,
  44.   FT_CR_RIP * 8, FT_CR_EFLAGS * 8
  45. };

  46. #define X86_64_NUM_FT_COLLECT_GREGS \
  47.   (sizeof (x86_64_ft_collect_regmap) / sizeof(x86_64_ft_collect_regmap[0]))

  48. void
  49. supply_fast_tracepoint_registers (struct regcache *regcache,
  50.                                   const unsigned char *buf)
  51. {
  52.   int i;

  53.   for (i = 0; i < X86_64_NUM_FT_COLLECT_GREGS; i++)
  54.     supply_register (regcache, i,
  55.                      ((char *) buf) + x86_64_ft_collect_regmap[i]);
  56. }

  57. ULONGEST __attribute__ ((visibility("default"), used))
  58. gdb_agent_get_raw_reg (const unsigned char *raw_regs, int regnum)
  59. {
  60.   if (regnum >= X86_64_NUM_FT_COLLECT_GREGS)
  61.     return 0;

  62.   return *(ULONGEST *) (raw_regs + x86_64_ft_collect_regmap[regnum]);
  63. }

  64. #ifdef HAVE_UST

  65. #include <ust/processor.h>

  66. /* "struct registers" is the UST object type holding the registers at
  67.    the time of the static tracepoint marker call.  This doesn't
  68.    contain RIP, but we know what it must have been (the marker
  69.    address).  */

  70. #define ST_REGENTRY(REG)                        \
  71.   {                                                \
  72.     offsetof (struct registers, REG),                \
  73.     sizeof (((struct registers *) NULL)->REG)        \
  74.   }

  75. static struct
  76. {
  77.   int offset;
  78.   int size;
  79. } x86_64_st_collect_regmap[] =
  80.   {
  81.     ST_REGENTRY(rax),
  82.     ST_REGENTRY(rbx),
  83.     ST_REGENTRY(rcx),
  84.     ST_REGENTRY(rdx),
  85.     ST_REGENTRY(rsi),
  86.     ST_REGENTRY(rdi),
  87.     ST_REGENTRY(rbp),
  88.     ST_REGENTRY(rsp),
  89.     ST_REGENTRY(r8),
  90.     ST_REGENTRY(r9),
  91.     ST_REGENTRY(r10),
  92.     ST_REGENTRY(r11),
  93.     ST_REGENTRY(r12),
  94.     ST_REGENTRY(r13),
  95.     ST_REGENTRY(r14),
  96.     ST_REGENTRY(r15),
  97.     { -1, 0 },
  98.     ST_REGENTRY(rflags),
  99.     ST_REGENTRY(cs),
  100.     ST_REGENTRY(ss),
  101.   };

  102. #define X86_64_NUM_ST_COLLECT_GREGS \
  103.   (sizeof (x86_64_st_collect_regmap) / sizeof (x86_64_st_collect_regmap[0]))

  104. /* GDB's RIP register number.  */
  105. #define AMD64_RIP_REGNUM 16

  106. void
  107. supply_static_tracepoint_registers (struct regcache *regcache,
  108.                                     const unsigned char *buf,
  109.                                     CORE_ADDR pc)
  110. {
  111.   int i;
  112.   unsigned long newpc = pc;

  113.   supply_register (regcache, AMD64_RIP_REGNUM, &newpc);

  114.   for (i = 0; i < X86_64_NUM_ST_COLLECT_GREGS; i++)
  115.     if (x86_64_st_collect_regmap[i].offset != -1)
  116.       {
  117.         switch (x86_64_st_collect_regmap[i].size)
  118.           {
  119.           case 8:
  120.             supply_register (regcache, i,
  121.                              ((char *) buf)
  122.                              + x86_64_st_collect_regmap[i].offset);
  123.             break;
  124.           case 2:
  125.             {
  126.               unsigned long reg
  127.                 = * (short *) (((char *) buf)
  128.                                + x86_64_st_collect_regmap[i].offset);
  129.               reg &= 0xffff;
  130.               supply_register (regcache, i, &reg);
  131.             }
  132.             break;
  133.           default:
  134.             internal_error (__FILE__, __LINE__,
  135.                             "unhandled register size: %d",
  136.                             x86_64_st_collect_regmap[i].size);
  137.             break;
  138.           }
  139.       }
  140. }

  141. #endif /* HAVE_UST */

  142. void
  143. initialize_low_tracepoint (void)
  144. {
  145.   init_registers_amd64_linux ();
  146.   ipa_tdesc = tdesc_amd64_linux;
  147. }