From cb612ae20634e5f3c3c7534b1ad45824f73f86a8 Mon Sep 17 00:00:00 2001 From: Stan Shebs Date: Mon, 14 Nov 2011 20:07:20 +0000 Subject: 2011-11-14 Stan Shebs Kwok Cheung Yeung * NEWS: Document shorter fast tracepoints and qTMinFTPILen packet. * i386-tdep.c (i386_fast_tracepoint_valid_at): Query target for the minimum instruction size for fast tracepoints. * target.h (struct target_ops): Add new method to_get_min_fast_tracepoint_insn_len. (target_get_min_fast_tracepoint_insn_len): New. * target.c (update_current_target): Set up new target operation. * remote.c (remote_write_bytes_aux): Fix typo. (remote_get_min_fast_tracepoint_insn_len): New. (init_remote_ops): Initialize new field. * gdb.texinfo (Create and Delete Tracepoints): Describe what is needed to get shorter fast tracepoints. (Tracepoint Packets): Document new qTMinFTPILen packet. * linux-x86-low.c (small_jump_insn): New. (i386_install_fast_tracepoint_jump_pad): Add arguments for trampoline and error message, build a trampoline and issue a small jump instruction to it. (x86_install_fast_tracepoint_jump_pad): Add arguments for trampoline and error message. (x86_get_min_fast_tracepoint_insn_len): New. (the_low_target): Add call to x86_get_min_fast_tracepoint_insn_len. * linux-low.h (struct linux_target_ops): Add arguments to install_fast_tracepoint_jump_pad operation, add new operation. * linux-low.c (linux_install_fast_tracepoint_jump_pad): Add arguments. (linux_get_min_fast_tracepoint_insn_len): New function. (linux_target_op): Add new operation. * tracepoint.c (gdb_trampoline_buffer): New IPA variable. (gdb_trampoline_buffer_end): Ditto. (gdb_trampoline_buffer_error): Ditto. (struct ipa_sym_addresses): Add fields for new IPA variables. (symbol_list): Add entries for new IPA variables. (struct tracepoint): Add fields to hold the address range of the trampoline used by the tracepoint. (trampoline_buffer_head): New static variable. (trampoline_buffer_tail): Ditto. (claim_trampoline_space): New function. (have_fast_tracepoint_trampoline_buffer): New function. (clone_fast_tracepoint): Fill in trampoline fields of tracepoint structure. (install_fast_tracepoint): Ditto, also add error buffer argument. (cmd_qtminftpilen): New function. (handle_tracepoint_query): Add response to qTMinFTPILen packet. (fast_tracepoint_from_trampoline_address): New function. (fast_tracepoint_collecting): Handle trampoline as part of jump pad space. (set_trampoline_buffer_space): New function. (initialize_tracepoint): Initialize new IPA variables. * target.h (struct target_ops): Add arguments to install_fast_tracepoint_jump_pad operation, add new get_min_fast_tracepoint_insn_len operation. (target_get_min_fast_tracepoint_insn_len): New. (install_fast_tracepoint_jump_pad): Add arguments. * server.h (IPA_BUFSIZ): Define. * linux-i386-ipa.c: Include extra header files. (initialize_fast_tracepoint_trampoline_buffer): New function. (initialize_low_tracepoint): Call it. * server.h (set_trampoline_buffer_space): Declare. (claim_trampoline_space): Ditto. (have_fast_tracepoint_trampoline_buffer): Ditto. * gdb.trace/ftrace.c: New. * gdb.trace/ftrace.exp: New. --- gdb/i386-tdep.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'gdb/i386-tdep.c') diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 2f0b6f5e929..a4e3a220554 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -7109,10 +7109,12 @@ static const int i386_record_regmap[] = }; /* Check that the given address appears suitable for a fast - tracepoint, which on x86 means that we need an instruction of at + tracepoint, which on x86-64 means that we need an instruction of at least 5 bytes, so that we can overwrite it with a 4-byte-offset jump and not have to worry about program jumps to an address in the - middle of the tracepoint jump. Returns 1 if OK, and writes a size + middle of the tracepoint jump. On x86, it may be possible to use + 4-byte jumps with a 2-byte offset to a trampoline located in the + bottom 64 KiB of memory. Returns 1 if OK, and writes a size of instruction to replace, and 0 if not, plus an explanatory string. */ @@ -7123,10 +7125,26 @@ i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch, int len, jumplen; static struct ui_file *gdb_null = NULL; - /* This is based on the target agent using a 4-byte relative jump. - Alternate future possibilities include 8-byte offset for x86-84, - or 3-byte jumps if the program has trampoline space close by. */ - jumplen = 5; + /* Ask the target for the minimum instruction length supported. */ + jumplen = target_get_min_fast_tracepoint_insn_len (); + + if (jumplen < 0) + { + /* If the target does not support the get_min_fast_tracepoint_insn_len + operation, assume that fast tracepoints will always be implemented + using 4-byte relative jumps on both x86 and x86-64. */ + jumplen = 5; + } + else if (jumplen == 0) + { + /* If the target does support get_min_fast_tracepoint_insn_len but + returns zero, then the IPA has not loaded yet. In this case, + we optimistically assume that truncated 2-byte relative jumps + will be available on x86, and compensate later if this assumption + turns out to be incorrect. On x86-64 architectures, 4-byte relative + jumps will always be used. */ + jumplen = (register_size (gdbarch, 0) == 8) ? 5 : 4; + } /* Dummy file descriptor for the disassembler. */ if (!gdb_null) @@ -7134,6 +7152,9 @@ i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch, /* Check for fit. */ len = gdb_print_insn (gdbarch, addr, gdb_null, NULL); + if (isize) + *isize = len; + if (len < jumplen) { /* Return a bit of target-specific detail to add to the caller's @@ -7144,12 +7165,12 @@ i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch, len, jumplen); return 0; } - - if (isize) - *isize = len; - if (msg) - *msg = NULL; - return 1; + else + { + if (msg) + *msg = NULL; + return 1; + } } static int -- cgit v1.2.1