Commit Graph

115 Commits

Author SHA1 Message Date
Markus Metzger 633785ff28 record-btrace: provide xfer_partial target method
Provide the xfer_partial target method for the btrace record target.

Only allow memory read accesses to readonly memory while we're replaying,
except for inserting and removing breakpoints.

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* record-btrace.c (record_btrace_xfer_partial)
	(record_btrace_insert_breakpoint, record_btrace_remove_breakpoint)
	(record_btrace_allow_memory_access): New.
	(init_record_btrace_ops): Initialize new methods.
	* target.c (raw_memory_xfer_partial): Bail out if target reports
	that this memory is not available.
2014-01-16 13:06:14 +01:00
Markus Metzger cecac1aba0 record-btrace, frame: supply target-specific unwinder
Supply a target-specific frame unwinder for the record-btrace target that does
not allow unwinding while replaying.

2013-02-11  Jan Kratochvil  <jan.kratochvil@redhat.com>
            Markus Metzger  <markus.t.metzger@intel.com>

gdb/
	* record-btrace.c: Include frame-unwind.h.
	(record_btrace_frame_unwind_stop_reason)
	(record_btrace_frame_this_id, record_btrace_frame_prev_register)
	(record_btrace_frame_sniffer, record_btrace_frame_unwind):
	New.
	(init_record_btrace_ops): Install it.
2014-01-16 13:06:12 +01:00
Markus Metzger 1f3ef5810c record-btrace: supply register target methods
Supply target methods to allow reading the PC.  Forbid anything else.

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* record-btrace.c (record_btrace_fetch_registers)
	(record_btrace_store_registers)
	(record_btrace_to_prepare_to_store): New.
	(init_record_btrace_ops): Add the above.
2014-01-16 13:06:10 +01:00
Markus Metzger 07bbe694e7 btrace: add replay position to btrace thread info
Add a branch trace instruction iterator pointing to the current replay position
to the branch trace thread info struct.

Free the iterator when btrace is cleared.

Start at the replay position for the instruction and function-call histories.

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* btrace.h (replay) <replay>: New.
	(btrace_is_replaying): New.
	* btrace.c (btrace_clear): Free replay iterator.
	(btrace_is_replaying): New.
	* record-btrace.c (record_btrace_is_replaying): New.
	(record_btrace_info): Print insn number if replaying.
	(record_btrace_insn_history): Start at replay position.
	(record_btrace_call_history): Start at replay position.
	(init_record_btrace_ops): Init to_record_is_replaying.
2014-01-16 13:06:09 +01:00
Markus Metzger 0688d04e19 record-btrace: make ranges include begin and end
The "record function-call-history" and "record instruction-history" commands
accept a range "begin, end".  End is not included in both cases.  Include it.

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* record-btrace.c (record_btrace_insn_history_range): Include
	end.
	(record_btrace_insn_history_from): Adjust range.
	(record_btrace_call_history_range): Include
	end.
	(record_btrace_call_history_from): Adjust range.
	* NEWS: Announce changes.

testsuite/
	* gdb.btrace/function_call_history.exp: Update tests.
	* gdb.btrace/instruction_history.exp: Update tests.

doc/
	* gdb.texinfo (Process Record and Replay): Update documentation.
2014-01-16 13:05:38 +01:00
Markus Metzger 8710b7097e record-btrace: optionally indent function call history
Add a new modifier /c to the "record function-call-history" command to
indent the function name based on its depth in the call stack.

Also reorder the optional fields to have the indentation at the very beginning.
Prefix the insn range (/i modifier) with "inst ".
Prefix the source line (/l modifier) with "at ".
Change the range syntax from "begin-end" to "begin,end" to allow copy&paste to
the "record instruction-history" and "list" commands.

Adjust the respective tests and add new tests for the /c modifier.

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* record.h (enum record_print_flag)
	<record_print_indent_calls>: New.
	* record.c (get_call_history_modifiers): Recognize /c modifier.
	(_initialize_record): Document /c modifier.
	* record-btrace.c (btrace_call_history): Add btinfo parameter.
	Reorder fields.  Optionally indent the function name.  Update
	all users.
	* NEWS: Announce changes.

testsuite/
	* gdb.btrace/function_call_history.exp: Fix expected field
	order for "record function-call-history".
	Add new tests for "record function-call-history /c".
	* gdb.btrace/exception.cc: New.
	* gdb.btrace/exception.exp: New.
	* gdb.btrace/tailcall.exp: New.
	* gdb.btrace/x86-tailcall.S: New.
	* gdb.btrace/x86-tailcall.c: New.
	* gdb.btrace/unknown_functions.c: New.
	* gdb.btrace/unknown_functions.exp: New.
	* gdb.btrace/Makefile.in (EXECUTABLES): Add new.

doc/
	* gdb.texinfo (Process Record and Replay): Document new /c
	modifier accepted by "record function-call-history".
	Add /i modifier to "record function-call-history" example.
2014-01-16 13:03:41 +01:00
Markus Metzger 5de9129b06 record-btrace: start counting at one
The record instruction-history and record-function-call-history commands start
counting instructions at zero.  This is somewhat unintuitive when we start
navigating in the recorded instruction history.  Start at one, instead.

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* btrace.c (ftrace_new_function): Start counting at one.
	* record-btrace.c (record_btrace_info): Adjust number of calls
	and insns.
	* NEWS: Announce it.

testsuite/
    * gdb.btrace/instruction_history.exp: Update.
    * gdb.btrace/function_call_history.exp: Update.
2014-01-16 12:58:25 +01:00
Markus Metzger 7acbe13307 record-btrace: fix insn range in function call history
With the "/i" modifier, we print the instruction number range in the
"record function-call-history" command as [begin, end).

It would be more intuitive if we printed the range as [begin, end].

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* record-btrace.c (btrace_call_history_insn_range): Print
	insn range as [begin, end].
2014-01-16 12:45:12 +01:00
Markus Metzger 23a7fe7580 btrace: change branch trace data structure
The branch trace is represented as 3 vectors:
  - a block vector
  - a instruction vector
  - a function vector

Each vector (except for the first) is computed from the one above.

Change this into a graph where a node represents a sequence of instructions
belonging to the same function and where we have three types of edges to connect
the function segments:
  - control flow
  - same function (instance)
  - call stack

This allows us to navigate in the branch trace.  We will need this for "record
goto" and reverse execution.

This patch introduces the data structure and computes the control flow edges.
It also introduces iterator structs to simplify iterating over the branch trace
in control-flow order.

It also fixes PR gdb/15240 since now recursive calls are handled correctly.
Fix the test that got the number of expected fib instances and also the
function numbers wrong.

The current instruction had been part of the branch trace.  This will look odd
once we start support for reverse execution.  Remove it.  We still keep it in
the trace itself to allow extending the branch trace more easily in the future.

2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* btrace.h (struct btrace_func_link): New.
	(enum btrace_function_flag): New.
	(struct btrace_inst): Rename to ...
	(struct btrace_insn): ...this. Update all users.
	(struct btrace_func) <ibegin, iend>: Remove.
	(struct btrace_func_link): New.
	(struct btrace_func): Rename to ...
	(struct btrace_function): ...this. Update all users.
	(struct btrace_function) <segment, flow, up, insn, insn_offset)
	(number, level, flags>: New.
	(struct btrace_insn_iterator): Rename to ...
	(struct btrace_insn_history): ...this.
	Update all users.
	(struct btrace_insn_iterator, btrace_call_iterator): New.
	(struct btrace_target_info) <btrace, itrace, ftrace>: Remove.
	(struct btrace_target_info) <begin, end, level>
	<insn_history, call_history>: New.
	(btrace_insn_get, btrace_insn_number, btrace_insn_begin)
	(btrace_insn_end, btrace_insn_prev, btrace_insn_next)
	(btrace_insn_cmp, btrace_find_insn_by_number, btrace_call_get)
	(btrace_call_number, btrace_call_begin, btrace_call_end)
	(btrace_call_prev, btrace_call_next, btrace_call_cmp)
	(btrace_find_function_by_number, btrace_set_insn_history)
	(btrace_set_call_history): New.
	* btrace.c (btrace_init_insn_iterator)
	(btrace_init_func_iterator, compute_itrace): Remove.
	(ftrace_print_function_name, ftrace_print_filename)
	(ftrace_skip_file): Change
	parameter to const.
	(ftrace_init_func): Remove.
	(ftrace_debug): Use new btrace_function fields.
	(ftrace_function_switched): Also consider gaining and
	losing symbol information).
	(ftrace_print_insn_addr, ftrace_new_call, ftrace_new_return)
	(ftrace_new_switch, ftrace_find_caller, ftrace_new_function)
	(ftrace_update_caller, ftrace_fixup_caller, ftrace_new_tailcall):
	New.
	(ftrace_new_function): Move. Remove debug print.
	(ftrace_update_lines, ftrace_update_insns): New.
	(ftrace_update_function): Check for call, ret, and jump.
	(compute_ftrace): Renamed to ...
	(btrace_compute_ftrace): ...this. Rewritten to compute call
	stack.
	(btrace_fetch, btrace_clear): Updated.
	(btrace_insn_get, btrace_insn_number, btrace_insn_begin)
	(btrace_insn_end, btrace_insn_prev, btrace_insn_next)
	(btrace_insn_cmp, btrace_find_insn_by_number, btrace_call_get)
	(btrace_call_number, btrace_call_begin, btrace_call_end)
	(btrace_call_prev, btrace_call_next, btrace_call_cmp)
	(btrace_find_function_by_number, btrace_set_insn_history)
	(btrace_set_call_history): New.
	* record-btrace.c (require_btrace): Use new btrace thread
	info fields.
	(record_btrace_info, btrace_insn_history)
	(record_btrace_insn_history, record_btrace_insn_history_range):
	Use new btrace thread info fields and new iterator.
	(btrace_func_history_src_line): Rename to ...
	(btrace_call_history_src_line): ...this. Use new btrace
	thread info fields.
	(btrace_func_history): Rename to ...
	(btrace_call_history): ...this. Use new btrace thread info
	fields and new iterator.
	(record_btrace_call_history, record_btrace_call_history_range):
	Use new btrace thread info fields and new iterator.

testsuite/
	* gdb.btrace/function_call_history.exp: Fix expected function
	trace.
	* gdb.btrace/instruction_history.exp: Initialize traced.
	Remove traced_functions.
2014-01-16 12:45:11 +01:00
Pedro Alves 8213266aea Fix "is a record target open" checks.
RECORD_IS_USED and record_full_open look at current_target.to_stratum
to determine whether a record target is in use.  This is wrong because
arch_stratum is greater than record_stratum, so if an arch_stratum
target is pushed, RECORD_IS_USED and record_full_open will miss it.

To fix this, we can use the existing find_record_target instead, which
looks up for a record stratum target across the target stack.  Since
that means exporting find_record_target in record.h, RECORD_IS_USED
ends up redundant, so the patch eliminates it.

That exercise then reveals other issues:

- adjust_pc_after_break is gating record_full_... calls based on
RECORD_IS_USED.  But, record_full_ calls shouldn't be made when
recording with the record-btrace target.  So this adds a new
record_full_is_used predicate to be used in that spot.

- record_full_open says "Process record target already running", even
if the recording target is record-btrace ("process record" is the
original complete name of the record-full target).  record_btrace_open
only says "The process is already being recorded." and does not
suggest "record stop", like record-full does.  The patch factors out
and merges that error to a new record_preopen function that all record
targets call in their open routine.

Tested on x86_64 Fedora 17.

gdb/
2014-01-14  Pedro Alves  <palves@redhat.com>
	    Tom Tromey  <tromey@redhat.com>

	* infrun.c (use_displaced_stepping): Use find_record_target
	instead of RECORD_IS_USED.
	(adjust_pc_after_break): Use record_full_is_used instead of
	RECORD_IS_USED.
	* record-btrace.c (record_btrace_open): Call record_preopen
	instead of checking RECORD_IS_USED.
	* record-full.c (record_full_shortname)
	(record_full_core_shortname): New globals.
	(record_full_is_used): New function.
	(find_full_open): Call record_preopen instead of checking
	RECORD_IS_USED.
	(init_record_full_ops): Set the target's shortname to
	record_full_shortname.
	(init_record_full_core_ops): Set the target's shortname to
	record_full_core_shortname.
	* record-full.h (record_full_is_used): Declare.
	* record.c (find_record_target): Make extern.
	(record_preopen): New function.
	* record.h (RECORD_IS_USED): Delete macro.
	(find_record_target, record_preopen): Declare functions.
2014-01-14 16:12:19 +00:00
Joel Brobecker ecd75fc8ee Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
Markus Metzger 1e038f67a9 record: upcase record_print_flag enumeration constants
* record.h (record_print_flag) <record_print_src_line,
	record_print_insn_range>: Rename into ...
	(record_print_flag) <record_print_src_line,
	record_print_insn_range>: ... this.  Update all users.
2013-09-02 15:06:11 +00:00
Markus Metzger 99c819eea0 record-btrace: fix assertion when enabling recording after re-run
Reading symbols from /bin/true...(no debugging symbols found)...done.
(gdb) b _start
Function "_start" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (_start) pending.
(gdb) r
Starting program: /bin/true

Breakpoint 1, 0x00000039a0400af0 in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) rec b
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /bin/true

Breakpoint 1, 0x00000039a0400af0 in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) rec b
gdb/record-btrace.c:154: internal-error: record_btrace_open:
 Assertion `record_btrace_thread_observer == NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)


gdb/
	* record-btrace.c (record_btrace_close): Call
	record_btrace_auto_disable.

testsuite/
	* gdb.btrace/enable.exp: Add regression test.
2013-03-26 07:15:09 +00:00
Jan Kratochvil 460014f572 gdb/
Code cleanup.
	* bfd-target.c (target_bfd_xclose): Remove parameter quitting.
	* bsd-kvm.c (bsd_kvm_close): Likewise.
	* bsd-uthread.c (bsd_uthread_close): Likewise.
	* corelow.c (core_close): Likewise.
	(core_close_cleanup): Remove parameter quitting from a caller.
	* event-top.c (async_disconnect): Likewise.
	* exec.c (exec_close_1): Remove parameter quitting.
	* go32-nat.c (go32_close): Likewise.
	* linux-nat.c (linux_nat_close): Remove parameter quitting.  Remove
	parameter quitting from a caller.
	* mips-linux-nat.c (super_close): Remove parameter quitting from the
	variable.
	(mips_linux_close): Remove parameter quitting.  Remove parameter
	quitting from a caller.
	* monitor.c (monitor_close): Remove parameter quitting.
	* monitor.h (monitor_close): Likewise.
	* record-btrace.c (record_btrace_close): Likewise.
	* record-full.c (record_full_close): Likewise.
	* remote-m32r-sdi.c (m32r_close): Remove parameter quitting and remove
	it also from fprintf_unfiltered.
	* remote-mips.c (mips_close): Remove parameter quitting.
	(mips_detach): Remove parameter quitting from a caller.
	* remote-sim.c (gdbsim_close): Remove parameter quitting.
	(gdbsim_close): Remove duplicate function comment.  Remove parameter
	quitting and remove it also from printf_filtered.
	* remote.c (remote_close): Remove parameter quitting.
	* solib-svr4.c (enable_break): Remove parameter quitting from a caller.
	* target.c (update_current_target): Remove parameter int from to_close
	de_fault.
	(push_target, unpush_target, pop_target): Remove parameter quitting from
	a caller.
	(pop_all_targets_above, pop_all_targets): Remove parameter quitting.
	Remove parameter quitting from a caller.
	(target_preopen): Remove parameter quitting from a caller.
	(target_close): Remove parameter quitting.  Remove parameter quitting
	from a caller two times.  Remove parameter quitting also from
	fprintf_unfiltered.
	* target.h (struct target_ops): Remove parameter quitting and as int
	from fields to_xclose and to_close.
	(extern struct target_ops current_target):
	(target_close, pop_all_targets): Remove parameter quitting.  Update the
	comment.
	(pop_all_targets_above): Remove parameter quitting.
	* top.c (quit_target): Remove parameter quitting from a caller.
	* tracepoint.c (tfile_close): Remove parameter quitting.
	* windows-nat.c (windows_close): Remove parameter quitting.
2013-03-20 15:46:24 +00:00
Markus Metzger afedecd388 Add a target for branch trace recording.
The target implements the new record sub-commands
"record instruction-history" and
"record function-call-history".

The target does not support reverse execution or navigation in the
recorded execution log.

gdb/
	* Makefile.in (SFILES): Add record-btrace.c
	(COMMON_OBS): Add record-btrace.o
	* record-btrace.c: New.
	* objfiles.c: Include btrace.h.
	(free_objfile): call btrace_free_objfile.
2013-03-11 08:51:58 +00:00