Commit Graph

12 Commits

Author SHA1 Message Date
Markus Metzger 6e07b1d27e record-btrace: show trace from enable location
The btrace record target shows the branch trace from the location of the first
branch destination.  This is the first BTS records.

After adding incremental updates, we can now add a dummy record for the current
PC when we enable tracing so we show the trace from the location where branch
tracing has been enabled.

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

	* btrace.c: Include regcache.h.
	(btrace_add_pc): New.
	(btrace_enable): Call btrace_add_pc.
	(btrace_is_empty): New.
	* btrace.h (btrace_is_empty): New.
	* record-btrace.c (require_btrace, record_btrace_info): Call
	btrace_is_empty.

testsuite/
	* gdb.btrace/Makefile.in (EXECUTABLES): Add delta.
	* gdb.btrace/exception.exp: Update.
	* gdb.btrace/instruction_history.exp: Update.
	* gdb.btrace/record_goto.exp: Update.
	* gdb.btrace/tailcall.exp: Update.
	* gdb.btrace/unknown_functions.exp: Update.
	* gdb.btrace/delta.exp: New.
2014-01-16 13:12:00 +01:00
Markus Metzger 969c39fbcd btrace, gdbserver: read branch trace incrementally
Read branch trace data incrementally and extend the current trace rather than
discarding it and reading the entire trace buffer each time.

If the branch trace buffer overflowed, we can't extend the current trace so we
discard it and start anew by reading the entire branch trace buffer.

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

	* common/linux-btrace.c (perf_event_read_bts, linux_read_btrace):
	Support delta reads.
	(linux_disable_btrace): Change return type.
	* common/linux-btrace.h (linux_read_btrace): Change parameters
	and return type to allow error reporting.  Update users.
	(linux_disable_btrace): Change return type.  Update users.
	* common/btrace-common.h (btrace_read_type) <BTRACE_READ_DELTA>:
	New.
	(btrace_error): New.
	(btrace_block) <begin>: Comment on BEGIN == 0.
	* btrace.c (btrace_compute_ftrace): Start from the end of
	the current trace.
	(btrace_stitch_trace, btrace_clear_history): New.
	(btrace_fetch): Read delta trace, return if replaying.
	(btrace_clear): Move clear history code to btrace_clear_history.
	(parse_xml_btrace): Throw an error if parsing failed.
	* target.h (struct target_ops) <to_read_btrace>: Change parameters
	and return type to allow error reporting.
	(target_read_btrace): Change parameters and return type to allow
	error reporting.
	* target.c (target_read_btrace): Update.
	* remote.c (remote_read_btrace): Support delta reads.  Pass
	errors on.
	* NEWS: Announce it.

gdbserver/
	* target.h (target_ops) <read_btrace>: Change parameters and
	return type to allow error reporting.
	* server.c (handle_qxfer_btrace): Support delta reads.  Pass
	trace reading errors on.
	* linux-low.c (linux_low_read_btrace): Pass trace reading
	errors on.
	(linux_low_disable_btrace): New.
2014-01-16 13:11:42 +01:00
Markus Metzger 0b722aec57 record-btrace: extend unwinder
Extend the always failing unwinder to provide the PC based on the call
structure detected in the branch trace.

The unwinder supports normal frames and tailcall frames.
Inline frames are not supported.

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

	* record.h (record_btrace_frame_unwind)
	(record_btrace_tailcall_frame_unwind): New declarations.
	* dwarf2-frame: Include record.h
	(dwarf2_frame_cfa): Throw an error for btrace frames.
	* record-btrace.c: Include hashtab.h.
	(btrace_get_bfun_name): New.
	(btrace_call_history): Call btrace_get_bfun_name.
	(struct btrace_frame_cache): New.
	(bfcache): New.
	(bfcache_hash, bfcache_eq, bfcache_new): New.
	(btrace_get_frame_function): New.
	(record_btrace_frame_unwind_stop_reason): Allow unwinding.
	(record_btrace_frame_this_id): Compute own id.
	(record_btrace_frame_prev_register): Provide PC, throw_error
	for all other registers.
	(record_btrace_frame_sniffer): Detect btrace frames.
	(record_btrace_tailcall_frame_sniffer): New.
	(record_btrace_frame_dealloc_cache): New.
	(record_btrace_frame_unwind): Add new functions.
	(record_btrace_tailcall_frame_unwind): New.
	(_initialize_record_btrace): Allocate cache.
	* btrace.c (btrace_clear): Call reinit_frame_cache.
	* NEWS: Announce it.

testsuite/
	* gdb.btrace/record_goto.exp: Add backtrace test.
	* gdb.btrace/tailcall.exp: Add backtrace test.
2014-01-16 13:09:42 +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 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 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
Markus Metzger 864089d2f6 btrace: uppercase btrace_read_type
2014-01-16  Markus Metzger  <markus.t.metzger@intel.com>

	* common/btrace-common.h (btrace_read_type) <btrace_read_all>:
	Change to ...
	(btrace_read_type) <BTRACE_READ_ALL>: ... this.  Update users.
	(btrace_read_type) <btrace_read_new>: Change to ...
	(btrace_read_type) <BTRACE_READ_NEW>: ... this.  Update users.
2014-01-16 12:45:10 +01:00
Joel Brobecker ecd75fc8ee Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
Tom Tromey 7cbd4a934e * minsyms.h (struct bound_minimal_symbol): New.
(lookup_minimal_symbol_and_objfile): Return bound_minimal_symbol.
	Remove objfile argument.
	(lookup_minimal_symbol_by_pc_section, lookup_minimal_symbol_by_pc):
	Return bound_minimal_symbol.
	* minsyms.c (lookup_minimal_symbol_by_pc_1)
	(lookup_minimal_symbol_by_pc_section, lookup_minimal_symbol_by_pc):
	Return bound_minimal_symbol.
	(in_gnu_ifunc_stub): Update.
	(lookup_minimal_symbol_and_objfile): Return bound_minimal_symbol.
	Remove 'objfile_p' argument.
	(lookup_solib_trampoline_symbol_by_pc): Update.
	* ada-tasks.c, amd64-windows-tdep.c, arm-tdep.c,
	arm-wince-tdep.c, block.c, blockframe.c, breakpoint.c, btrace.c,
	c-valprint.c, dwarf2loc.c, elfread.c, frame.c, frv-tdep.c,
	glibc-tdep.c, gnu-v2-abi.c, gnu-v3-abi.c, hppa-hpux-tdep.c,
	i386-tdep.c, ia64-tdep.c, infcall.c, infcmd.c, jit.c,
	linux-fork.c, m32c-tdep.c, m68hc11-tdep.c, maint.c,
	mips-tdep.c, p-valprint.c, parse.c, ppc-linux-tdep.c,
	ppc-sysv-tdep.c, printcmd.c, rs6000-tdep.c, sh64-tdep.c,
	stack.c, symtab.c, tui/tui-disasm.c: Update.
2013-04-08 19:59:09 +00:00
Markus Metzger c12a29171f Define the xml document style for transferring branch trace data.
Add a function to parse a btrace xml document into a vector of branch trace
blocks.

gdb/
	* features/btrace.dtd: New file.
	* Makefile.in (XMLFILES): Add btrace.dtd.
	* btrace.h (parse_xml_btrace): New declaration.
	* btrace.c: Include xml-support.h.
	(parse_xml_btrace): New function.
	(parse_xml_btrace_block): New function.
	(block_attributes): New struct.
	(btrace_attributes): New struct.
	(btrace_children): New struct.
	(btrace_elements): New struct.
2013-03-11 08:28:58 +00:00
Markus Metzger 02d2762576 Add branch trace information to struct thread_info.
Add functions to enable, disable, clear, and fetch a thread's branch trace.

gdb/
	* target.h: Include btrace.h.
	(struct target_ops) <to_supports_btrace, to_enable_btrace,
	to_disable_btrace, to_teardown_btrace, to_read_btrace>: New.
	* target.c (target_supports_btrace): New function.
	(target_enable_btrace): New function.
	(target_disable_btrace): New function.
	(target_teardown_btrace): New function.
	(target_read_btrace): New function.
	* btrace.h: New file.
	* btrace.c: New file.
	* Makefile.in: Add btrace.c.
	* gdbthread.h: Include btrace.h.
	(struct thread_info): Add btrace field.
	* thread.c: Include btrace.h.
	(clear_thread_inferior_resources): Call target_teardown_btrace.
	* common/btrace-common.h: New file.
2013-03-11 08:17:08 +00:00