/* Target-dependent code for the x86-64 for GDB, the GNU debugger.
- Copyright 2001, 2002 Free Software Foundation, Inc.
+ Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
Contributed by Jiri Smid, SuSE Labs.
This file is part of GDB.
#include "x86-64-tdep.h"
#include "dwarf2cfi.h"
#include "gdb_assert.h"
+#include "block.h"
/* Register numbers of various important registers. */
#define RAX_REGNUM 0
return *x86_64_register_info_table[regno].type;
}
-/* FIXME: cagney/2002-11-11: Once the i386 and x86-64 targets are
- merged, this function can go away. */
-int
-i386_fp_regnum_p (int regnum)
-{
- return (regnum < NUM_REGS
- && (FP0_REGNUM && FP0_REGNUM <= (regnum) && (regnum) < FPC_REGNUM));
-}
-
/* x86_64_register_convertible is true if register N's virtual format is
different from its raw format. Note that this definition assumes
that the host supports IEEE 32-bit floats, since it doesn't say
return x86_64_dwarf2gdb_regno_map[dw_reg];
}
-/* This is the variable that is set with "set disassembly-flavour", and
- its legitimate values. */
-static const char att_flavour[] = "att";
-static const char intel_flavour[] = "intel";
-static const char *valid_flavours[] = {
- att_flavour,
- intel_flavour,
- NULL
-};
-static const char *disassembly_flavour = att_flavour;
-
/* Push the return address (pointing to the call dummy) onto the stack
and return the new value for the stack pointer. */
return 2;
}
break;
+ case TYPE_CODE_ENUM:
+ case TYPE_CODE_REF:
case TYPE_CODE_INT:
case TYPE_CODE_PTR:
switch (bytes)
into VALBUF. */
void
-x86_64_extract_return_value (struct type *type, char *regbuf, char *valbuf)
+x86_64_extract_return_value (struct type *type, struct regcache *regcache,
+ void *valbuf)
{
enum x86_64_reg_class class[MAX_CLASSES];
int n = classify_argument (type, class, 0);
needed_intregs > RET_INT_REGS || needed_sseregs > RET_SSE_REGS)
{ /* memory class */
CORE_ADDR addr;
- memcpy (&addr, regbuf, REGISTER_RAW_SIZE (RAX_REGNUM));
+ regcache_cooked_read (regcache, RAX_REGNUM, &addr);
read_memory (addr, valbuf, TYPE_LENGTH (type));
return;
}
case X86_64_NO_CLASS:
break;
case X86_64_INTEGER_CLASS:
- memcpy (valbuf + offset,
- regbuf + REGISTER_BYTE (ret_int_r[(intreg + 1) / 2]),
- 8);
+ regcache_cooked_read (regcache, ret_int_r[(intreg + 1) / 2],
+ (char *) valbuf + offset);
offset += 8;
intreg += 2;
break;
case X86_64_INTEGERSI_CLASS:
- memcpy (valbuf + offset,
- regbuf + REGISTER_BYTE (ret_int_r[intreg / 2]), 4);
+ regcache_cooked_read_part (regcache, ret_int_r[intreg / 2],
+ 0, 4, (char *) valbuf + offset);
offset += 8;
intreg++;
break;
case X86_64_SSEDF_CLASS:
case X86_64_SSESF_CLASS:
case X86_64_SSE_CLASS:
- memcpy (valbuf + offset,
- regbuf + REGISTER_BYTE (ret_sse_r[(ssereg + 1) / 2]),
- 8);
+ regcache_cooked_read_part (regcache,
+ ret_sse_r[(ssereg + 1) / 2], 0, 8,
+ (char *) valbuf + offset);
offset += 8;
ssereg += 2;
break;
case X86_64_SSEUP_CLASS:
- memcpy (valbuf + offset + 8,
- regbuf + REGISTER_BYTE (ret_sse_r[ssereg / 2]), 8);
+ regcache_cooked_read_part (regcache, ret_sse_r[ssereg / 2],
+ 0, 8, (char *) valbuf + offset);
offset += 8;
ssereg++;
break;
case X86_64_X87_CLASS:
- memcpy (valbuf + offset, regbuf + REGISTER_BYTE (FP0_REGNUM),
- 8);
+ regcache_cooked_read_part (regcache, FP0_REGNUM,
+ 0, 8, (char *) valbuf + offset);
offset += 8;
break;
case X86_64_X87UP_CLASS:
- memcpy (valbuf + offset,
- regbuf + REGISTER_BYTE (FP0_REGNUM) + 8, 8);
+ regcache_cooked_read_part (regcache, FP0_REGNUM,
+ 8, 2, (char *) valbuf + offset);
offset += 8;
break;
case X86_64_MEMORY_CLASS:
intreg += 2;
break;
case X86_64_INTEGERSI_CLASS:
- deprecated_write_register_gen (int_parameter_registers[intreg / 2],
- VALUE_CONTENTS_ALL (args[i]) + offset);
- offset += 8;
- intreg++;
- break;
+ {
+ LONGEST num
+ = extract_signed_integer (VALUE_CONTENTS_ALL (args[i])
+ + offset, 4);
+ regcache_raw_write_signed (current_regcache,
+ int_parameter_registers[intreg / 2], num);
+
+ offset += 8;
+ intreg++;
+ break;
+ }
case X86_64_SSEDF_CLASS:
case X86_64_SSESF_CLASS:
case X86_64_SSE_CLASS:
/* Write into the appropriate registers a function return value stored
in VALBUF of type TYPE, given in virtual format. */
void
-x86_64_store_return_value (struct type *type, char *valbuf)
+x86_64_store_return_value (struct type *type, struct regcache *regcache,
+ const void *valbuf)
{
int len = TYPE_LENGTH (type);
&& TARGET_LONG_DOUBLE_FORMAT == &floatformat_i387_ext)
{
/* Copy straight over. */
- deprecated_write_register_bytes (REGISTER_BYTE (FP0_REGNUM), valbuf,
- FPU_REG_RAW_SIZE);
+ regcache_cooked_write (regcache, FP0_REGNUM, valbuf);
}
else
{
floating point format used by the FPU. This is probably
not exactly how it would happen on the target itself, but
it is the best we can do. */
- val = extract_floating (valbuf, TYPE_LENGTH (type));
+ val = deprecated_extract_floating (valbuf, TYPE_LENGTH (type));
floatformat_from_doublest (&floatformat_i387_ext, &val, buf);
- deprecated_write_register_bytes (REGISTER_BYTE (FP0_REGNUM), buf,
- FPU_REG_RAW_SIZE);
+ regcache_cooked_write_part (regcache, FP0_REGNUM,
+ 0, FPU_REG_RAW_SIZE, buf);
}
}
else
int high_size = REGISTER_RAW_SIZE (1);
if (len <= low_size)
- deprecated_write_register_bytes (REGISTER_BYTE (0), valbuf, len);
+ regcache_cooked_write_part (regcache, 0, 0, len, valbuf);
else if (len <= (low_size + high_size))
{
- deprecated_write_register_bytes (REGISTER_BYTE (0), valbuf,
- low_size);
- deprecated_write_register_bytes (REGISTER_BYTE (1),
- valbuf + low_size, len - low_size);
+ regcache_cooked_write_part (regcache, 0, 0, low_size, valbuf);
+ regcache_cooked_write_part (regcache, 1, 0,
+ len - low_size,
+ (const char *) valbuf + low_size);
}
else
internal_error (__FILE__, __LINE__,
}
\f
-
-/* We have two flavours of disassembly. The machinery on this page
- deals with switching between those. */
-
-static int
-gdb_print_insn_x86_64 (bfd_vma memaddr, disassemble_info * info)
-{
- if (disassembly_flavour == att_flavour)
- return print_insn_i386_att (memaddr, info);
- else if (disassembly_flavour == intel_flavour)
- return print_insn_i386_intel (memaddr, info);
- /* Never reached -- disassembly_flavour is always either att_flavour
- or intel_flavour. */
- internal_error (__FILE__, __LINE__, "failed internal consistency check");
-}
-\f
-
/* Store the address of the place in which to copy the structure the
subroutine will return. This is called from call_function. */
void
return 0;
}
+/* We will handle only functions beginning with:
+ 55 pushq %rbp
+ 48 89 e5 movq %rsp,%rbp
+ Any function that doesn't start with this sequence
+ will be assumed to have no prologue and thus no valid
+ frame pointer in %rbp. */
+#define PROLOG_BUFSIZE 4
+int
+x86_64_function_has_prologue (CORE_ADDR pc)
+{
+ int i;
+ unsigned char prolog_expect[PROLOG_BUFSIZE] = { 0x55, 0x48, 0x89, 0xe5 },
+ prolog_buf[PROLOG_BUFSIZE];
+
+ read_memory (pc, (char *) prolog_buf, PROLOG_BUFSIZE);
+
+ /* First check, whether pc points to pushq %rbp, movq %rsp,%rbp. */
+ for (i = 0; i < PROLOG_BUFSIZE; i++)
+ if (prolog_expect[i] != prolog_buf[i])
+ return 0; /* ... no, it doesn't. Nothing to skip. */
+
+ return 1;
+}
+
/* If a function with debugging information and known beginning
is detected, we will return pc of the next line in the source
code. With this approach we effectively skip the prolog. */
-#define PROLOG_BUFSIZE 4
CORE_ADDR
x86_64_skip_prologue (CORE_ADDR pc)
{
struct symtab_and_line v_sal;
struct symbol *v_function;
CORE_ADDR endaddr;
- unsigned char prolog_buf[PROLOG_BUFSIZE];
-
- /* We will handle only functions starting with: */
- static unsigned char prolog_expect[PROLOG_BUFSIZE] =
- {
- 0x55, /* pushq %rbp */
- 0x48, 0x89, 0xe5 /* movq %rsp, %rbp */
- };
- read_memory (pc, (char *) prolog_buf, PROLOG_BUFSIZE);
-
- /* First check, whether pc points to pushq %rbp, movq %rsp, %rbp. */
- for (i = 0; i < PROLOG_BUFSIZE; i++)
- if (prolog_expect[i] != prolog_buf[i])
- return pc; /* ... no, it doesn't. Nothing to skip. */
+ if (! x86_64_function_has_prologue (pc))
+ return pc;
/* OK, we have found the prologue and want PC of the first
non-prologue instruction. */
return pc;
}
-/* Sequence of bytes for breakpoint instruction. */
-static const unsigned char *
-x86_64_breakpoint_from_pc (CORE_ADDR *pc, int *lenptr)
+static void
+x86_64_save_dummy_frame_tos (CORE_ADDR sp)
{
- static unsigned char breakpoint[] = { 0xcc };
- *lenptr = 1;
- return breakpoint;
+ /* We must add the size of the return address that is already
+ put on the stack. */
+ generic_save_dummy_frame_tos (sp +
+ TYPE_LENGTH (builtin_type_void_func_ptr));
}
-static void
+static struct frame_id
+x86_64_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *frame)
+{
+ CORE_ADDR base;
+ frame_unwind_unsigned_register (frame, SP_REGNUM, &base);
+ return frame_id_build (base, frame_pc_unwind (frame));
+}
+
+void
x86_64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
/* Register numbers of various important registers. */
set_gdbarch_sp_regnum (gdbarch, 7); /* %rsp */
- set_gdbarch_fp_regnum (gdbarch, 6); /* %rbp */
+ set_gdbarch_deprecated_fp_regnum (gdbarch, 6); /* %rbp */
set_gdbarch_pc_regnum (gdbarch, 16); /* %rip */
set_gdbarch_ps_regnum (gdbarch, 17); /* %eflags */
set_gdbarch_fp0_regnum (gdbarch, X86_64_NUM_GREGS); /* %st(0) */
in use on any of the supported x86-64 targets. */
set_gdbarch_register_name (gdbarch, x86_64_register_name);
- set_gdbarch_register_size (gdbarch, 8);
+ set_gdbarch_deprecated_register_size (gdbarch, 8);
/* Total amount of space needed to store our copies of the machine's
register (SIZEOF_GREGS + SIZEOF_FPU_REGS + SIZEOF_FPU_CTRL_REGS +
set_gdbarch_register_byte (gdbarch, x86_64_register_byte);
set_gdbarch_register_virtual_type (gdbarch, x86_64_register_virtual_type);
- /* FIXME: kettenis/20021026: As long as we don't support longjmp,
- that is, as long as we have `tdep->jb_pc_offset == -1', using
- i386_get_longjmp_target is fine. */
-
set_gdbarch_register_convertible (gdbarch, x86_64_register_convertible);
set_gdbarch_register_convert_to_virtual (gdbarch,
x86_64_register_convert_to_virtual);
x86_64_register_convert_to_raw);
/* Getting saved registers is handled by unwind information. */
- set_gdbarch_get_saved_register (gdbarch, cfi_get_saved_register);
+ set_gdbarch_deprecated_get_saved_register (gdbarch, cfi_get_saved_register);
/* FIXME: kettenis/20021026: Should we set parm_boundary to 64 here? */
- set_gdbarch_read_fp (gdbarch, cfi_read_fp);
-
- /* FIXME: kettenis/20021026: Should be undeprecated. */
- set_gdbarch_extract_return_value (gdbarch, NULL);
- set_gdbarch_deprecated_extract_return_value (gdbarch,
- x86_64_extract_return_value);
- set_gdbarch_push_arguments (gdbarch, x86_64_push_arguments);
- set_gdbarch_push_return_address (gdbarch, x86_64_push_return_address);
- set_gdbarch_pop_frame (gdbarch, x86_64_pop_frame);
- set_gdbarch_store_struct_return (gdbarch, x86_64_store_struct_return);
- /* FIXME: kettenis/20021026: Should be undeprecated. */
- set_gdbarch_store_return_value (gdbarch, NULL);
- set_gdbarch_deprecated_store_return_value (gdbarch,
- x86_64_store_return_value);
+ set_gdbarch_deprecated_target_read_fp (gdbarch, cfi_read_fp);
+
+ set_gdbarch_extract_return_value (gdbarch, x86_64_extract_return_value);
+
+ set_gdbarch_deprecated_push_arguments (gdbarch, x86_64_push_arguments);
+ set_gdbarch_deprecated_push_return_address (gdbarch, x86_64_push_return_address);
+ set_gdbarch_deprecated_pop_frame (gdbarch, x86_64_pop_frame);
+ set_gdbarch_deprecated_store_struct_return (gdbarch, x86_64_store_struct_return);
+ set_gdbarch_store_return_value (gdbarch, x86_64_store_return_value);
/* Override, since this is handled by x86_64_extract_return_value. */
set_gdbarch_extract_struct_value_address (gdbarch, NULL);
set_gdbarch_use_struct_convention (gdbarch, x86_64_use_struct_convention);
- set_gdbarch_frame_init_saved_regs (gdbarch, x86_64_frame_init_saved_regs);
+ set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, x86_64_frame_init_saved_regs);
set_gdbarch_skip_prologue (gdbarch, x86_64_skip_prologue);
- set_gdbarch_frame_chain (gdbarch, x86_64_linux_frame_chain);
+ set_gdbarch_deprecated_frame_chain (gdbarch, x86_64_linux_frame_chain);
set_gdbarch_frameless_function_invocation (gdbarch,
x86_64_frameless_function_invocation);
- /* FIXME: kettenis/20021025: Shouldn't this be set to
- generic_file_frame_chain_valid? */
- set_gdbarch_frame_chain_valid (gdbarch, file_frame_chain_valid);
/* FIXME: kettenis/20021026: These two are GNU/Linux-specific and
should be moved elsewhere. */
- set_gdbarch_frame_saved_pc (gdbarch, x86_64_linux_frame_saved_pc);
- set_gdbarch_saved_pc_after_call (gdbarch, x86_64_linux_saved_pc_after_call);
+ set_gdbarch_deprecated_frame_saved_pc (gdbarch, x86_64_linux_frame_saved_pc);
+ set_gdbarch_deprecated_saved_pc_after_call (gdbarch, x86_64_linux_saved_pc_after_call);
set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
/* FIXME: kettenis/20021026: This one is GNU/Linux-specific too. */
set_gdbarch_pc_in_sigtramp (gdbarch, x86_64_linux_in_sigtramp);
+ set_gdbarch_num_pseudo_regs (gdbarch, 0);
+
/* Build call frame information (CFI) from DWARF2 frame debug info. */
set_gdbarch_dwarf2_build_frame_info (gdbarch, dwarf2_build_frame_info);
/* Initialization of per-frame CFI. */
- set_gdbarch_init_extra_frame_info (gdbarch, cfi_init_extra_frame_info);
+ set_gdbarch_deprecated_init_extra_frame_info (gdbarch, cfi_init_extra_frame_info);
/* Frame PC initialization is handled by using CFI. */
- set_gdbarch_init_frame_pc (gdbarch, x86_64_init_frame_pc);
+ set_gdbarch_deprecated_init_frame_pc (gdbarch, x86_64_init_frame_pc);
/* Cons up virtual frame pointer for trace. */
set_gdbarch_virtual_frame_pointer (gdbarch, cfi_virtual_frame_pointer);
since all supported x86-64 targets are ELF, but that might change
in the future. */
set_gdbarch_in_solib_call_trampoline (gdbarch, in_plt_section);
-}
-
-static struct gdbarch *
-x86_64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
-{
- struct gdbarch_tdep *tdep;
- struct gdbarch *gdbarch;
- enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
-
- /* Try to determine the OS ABI of the object we're loading. */
- if (info.abfd != NULL)
- osabi = gdbarch_lookup_osabi (info.abfd);
-
- /* Find a candidate among extant architectures. */
- for (arches = gdbarch_list_lookup_by_info (arches, &info);
- arches != NULL;
- arches = gdbarch_list_lookup_by_info (arches->next, &info))
- {
- /* Make sure the OS ABI selection matches. */
- tdep = gdbarch_tdep (arches->gdbarch);
- if (tdep && tdep->osabi == osabi)
- return arches->gdbarch;
- }
-
- /* Allocate space for the new architecture. */
- tdep = XMALLOC (struct gdbarch_tdep);
- gdbarch = gdbarch_alloc (&info, tdep);
-
- tdep->osabi = osabi;
-
- /* FIXME: kettenis/20021025: The following calls are going to
- disappear when we integrate the x86_64 target into the i386
- target. */
-
- set_gdbarch_long_double_format (gdbarch, &floatformat_i387_ext);
-
- set_gdbarch_max_register_raw_size (gdbarch, 16);
- set_gdbarch_max_register_virtual_size (gdbarch, 16);
-
- set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
-
- set_gdbarch_breakpoint_from_pc (gdbarch, x86_64_breakpoint_from_pc);
- set_gdbarch_decr_pc_after_break (gdbarch, 1);
- set_gdbarch_function_start_offset (gdbarch, 0);
-
- set_gdbarch_frame_args_skip (gdbarch, 8);
-
- set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
- set_gdbarch_call_dummy_start_offset (gdbarch, 0);
- set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
- set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
- set_gdbarch_call_dummy_length (gdbarch, 0);
- set_gdbarch_call_dummy_p (gdbarch, 1);
- set_gdbarch_call_dummy_words (gdbarch, NULL);
- set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
- set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy);
- set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
-
- set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_at_entry_point);
-
- set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
-
- /* FIXME: kettenis/20021025: These already are the default. */
-
- set_gdbarch_register_virtual_size (gdbarch, generic_register_size);
- set_gdbarch_deprecated_extract_struct_value_address (gdbarch, 0);
-
- x86_64_init_abi (info, gdbarch);
-
- return gdbarch;
+
+ /* Dummy frame helper functions. */
+ set_gdbarch_save_dummy_frame_tos (gdbarch, x86_64_save_dummy_frame_tos);
+ set_gdbarch_unwind_dummy_id (gdbarch, x86_64_unwind_dummy_id);
}
void
_initialize_x86_64_tdep (void)
{
- register_gdbarch_init (bfd_arch_i386, x86_64_gdbarch_init);
-
/* Initialize the table saying where each register starts in the
register file. */
{
offset += x86_64_register_info_table[i].size;
}
}
-
- tm_print_insn = gdb_print_insn_x86_64;
- tm_print_insn_info.mach = bfd_mach_x86_64;
-
- /* Add the variable that controls the disassembly flavour. */
- {
- struct cmd_list_element *new_cmd;
-
- new_cmd = add_set_enum_cmd ("disassembly-flavour", no_class,
- valid_flavours, &disassembly_flavour, "\
-Set the disassembly flavour, the valid values are \"att\" and \"intel\", \
-and the default value is \"att\".", &setlist);
- add_show_from_set (new_cmd, &showlist);
- }
}