From 766f5c51c3151507d3be26d606710d708302d8b2 Mon Sep 17 00:00:00 2001
From: Ruslan Bukin
Date: Mon, 19 Mar 2018 18:34:08 +0000
Subject: Import Intel Processor Trace library.
Git ID 24982c1a6fce48f1e416461d42899805f74fbb26
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D12815
---
.gitignore | 7 +
CMakeLists.txt | 304 ++
CONTRIBUTING | 107 +
LICENSE | 24 +
README | 79 +
doc/getting_started.md | 93 +
doc/howto_build.md | 197 ++
doc/howto_capture.md | 628 ++++
doc/howto_libipt.md | 1271 +++++++
doc/howto_pttc.md | 482 +++
doc/man/CMakeLists.txt | 147 +
doc/man/pt_alloc_encoder.3.md | 96 +
doc/man/pt_blk_alloc_decoder.3.md | 98 +
doc/man/pt_blk_get_offset.3.md | 82 +
doc/man/pt_blk_next.3.md | 285 ++
doc/man/pt_blk_sync_forward.3.md | 152 +
doc/man/pt_config.3.md | 359 ++
doc/man/pt_enc_get_config.3.md | 77 +
doc/man/pt_enc_get_offset.3.md | 77 +
doc/man/pt_image_add_file.3.md | 135 +
doc/man/pt_image_alloc.3.md | 99 +
doc/man/pt_image_remove_by_filename.3.md | 150 +
doc/man/pt_image_set_callback.3.md | 103 +
doc/man/pt_insn_alloc_decoder.3.md | 101 +
doc/man/pt_insn_get_image.3.md | 93 +
doc/man/pt_insn_get_offset.3.md | 82 +
doc/man/pt_insn_next.3.md | 264 ++
doc/man/pt_insn_sync_forward.3.md | 153 +
doc/man/pt_iscache_add_file.3.md | 98 +
doc/man/pt_iscache_alloc.3.md | 102 +
doc/man/pt_iscache_read.3.md | 89 +
doc/man/pt_iscache_set_limit.3.md | 73 +
doc/man/pt_library_version.3.md | 72 +
doc/man/pt_packet.3.md | 197 ++
doc/man/pt_pkt_alloc_decoder.3.md | 98 +
doc/man/pt_pkt_get_offset.3.md | 81 +
doc/man/pt_pkt_sync_forward.3.md | 115 +
doc/man/pt_qry_alloc_decoder.3.md | 113 +
doc/man/pt_qry_cond_branch.3.md | 152 +
doc/man/pt_qry_event.3.md | 291 ++
doc/man/pt_qry_get_offset.3.md | 83 +
doc/man/pt_qry_sync_forward.3.md | 152 +
doc/man/pt_qry_time.3.md | 128 +
include/posix/threads.h | 259 ++
include/pt_compiler.h | 47 +
include/windows/inttypes.h | 65 +
include/windows/threads.h | 239 ++
libipt/CMakeLists.txt | 172 +
libipt/include/intel-pt.h.in | 2463 +++++++++++++
libipt/internal/include/posix/pt_section_posix.h | 100 +
libipt/internal/include/pt_asid.h | 74 +
libipt/internal/include/pt_block_cache.h | 225 ++
libipt/internal/include/pt_block_decoder.h | 143 +
libipt/internal/include/pt_config.h | 82 +
libipt/internal/include/pt_cpu.h | 54 +
libipt/internal/include/pt_cpuid.h | 40 +
libipt/internal/include/pt_decoder_function.h | 129 +
libipt/internal/include/pt_encoder.h | 125 +
libipt/internal/include/pt_event_queue.h | 143 +
libipt/internal/include/pt_ild.h | 128 +
libipt/internal/include/pt_image.h | 140 +
libipt/internal/include/pt_image_section_cache.h | 206 ++
libipt/internal/include/pt_insn.h | 212 ++
libipt/internal/include/pt_insn_decoder.h | 139 +
libipt/internal/include/pt_last_ip.h | 79 +
libipt/internal/include/pt_mapped_section.h | 199 ++
libipt/internal/include/pt_msec_cache.h | 95 +
libipt/internal/include/pt_opcodes.h | 397 +++
libipt/internal/include/pt_packet.h | 111 +
libipt/internal/include/pt_packet_decoder.h | 92 +
libipt/internal/include/pt_query_decoder.h | 134 +
libipt/internal/include/pt_retstack.h | 87 +
libipt/internal/include/pt_section.h | 392 +++
libipt/internal/include/pt_section_file.h | 106 +
libipt/internal/include/pt_sync.h | 71 +
libipt/internal/include/pt_time.h | 232 ++
libipt/internal/include/pt_tnt_cache.h | 88 +
libipt/internal/include/pti-disp-defs.h | 39 +
libipt/internal/include/pti-disp.h | 544 +++
libipt/internal/include/pti-imm-defs.h | 46 +
libipt/internal/include/pti-imm.h | 544 +++
libipt/internal/include/pti-modrm-defs.h | 38 +
libipt/internal/include/pti-modrm.h | 544 +++
.../internal/include/windows/pt_section_windows.h | 111 +
libipt/src/posix/init.c | 36 +
libipt/src/posix/pt_cpuid.c | 37 +
libipt/src/posix/pt_section_posix.c | 326 ++
libipt/src/pt_asid.c | 106 +
libipt/src/pt_block_cache.c | 96 +
libipt/src/pt_block_decoder.c | 3469 +++++++++++++++++++
libipt/src/pt_config.c | 251 ++
libipt/src/pt_cpu.c | 164 +
libipt/src/pt_decoder_function.c | 379 ++
libipt/src/pt_encoder.c | 917 +++++
libipt/src/pt_error.c | 122 +
libipt/src/pt_event_queue.c | 203 ++
libipt/src/pt_ild.c | 1223 +++++++
libipt/src/pt_image.c | 718 ++++
libipt/src/pt_image_section_cache.c | 1091 ++++++
libipt/src/pt_insn.c | 372 ++
libipt/src/pt_insn_decoder.c | 1765 ++++++++++
libipt/src/pt_last_ip.c | 127 +
libipt/src/pt_msec_cache.c | 136 +
libipt/src/pt_packet.c | 573 +++
libipt/src/pt_packet_decoder.c | 723 ++++
libipt/src/pt_query_decoder.c | 3630 ++++++++++++++++++++
libipt/src/pt_retstack.c | 94 +
libipt/src/pt_section.c | 643 ++++
libipt/src/pt_section_file.c | 255 ++
libipt/src/pt_sync.c | 241 ++
libipt/src/pt_time.c | 674 ++++
libipt/src/pt_tnt_cache.c | 89 +
libipt/src/pt_version.c | 43 +
libipt/src/windows/init.c | 51 +
libipt/src/windows/pt_cpuid.c | 43 +
libipt/src/windows/pt_section_windows.c | 397 +++
libipt/test/src/ptunit-asid.c | 425 +++
libipt/test/src/ptunit-block_cache.c | 370 ++
libipt/test/src/ptunit-config.c | 496 +++
libipt/test/src/ptunit-cpp.cpp | 78 +
libipt/test/src/ptunit-cpu.c | 173 +
libipt/test/src/ptunit-event_queue.c | 470 +++
libipt/test/src/ptunit-fetch.c | 693 ++++
libipt/test/src/ptunit-ild.c | 759 ++++
libipt/test/src/ptunit-image.c | 2286 ++++++++++++
libipt/test/src/ptunit-image_section_cache.c | 2027 +++++++++++
libipt/test/src/ptunit-last_ip.c | 374 ++
libipt/test/src/ptunit-mapped_section.c | 198 ++
libipt/test/src/ptunit-msec_cache.c | 419 +++
libipt/test/src/ptunit-packet.c | 859 +++++
libipt/test/src/ptunit-query.c | 2873 ++++++++++++++++
libipt/test/src/ptunit-retstack.c | 232 ++
libipt/test/src/ptunit-section-file.c | 192 ++
libipt/test/src/ptunit-section.c | 1396 ++++++++
libipt/test/src/ptunit-sync.c | 306 ++
libipt/test/src/ptunit-time.c | 368 ++
libipt/test/src/ptunit-tnt_cache.c | 246 ++
pevent/CMakeLists.txt | 35 +
pevent/include/pevent.h | 268 ++
pevent/src/pevent.c | 664 ++++
pevent/test/src/ptunit-pevent.c | 799 +++++
ptdump/CMakeLists.txt | 54 +
ptdump/src/ptdump.c | 1951 +++++++++++
pttc/CMakeLists.txt | 68 +
pttc/include/errcode.h | 105 +
pttc/include/file.h | 143 +
pttc/include/parse.h | 235 ++
pttc/include/pttc.h | 49 +
pttc/include/util.h | 124 +
pttc/include/yasm.h | 259 ++
pttc/src/errcode.c | 85 +
pttc/src/file.c | 314 ++
pttc/src/main.c | 137 +
pttc/src/parse.c | 2779 +++++++++++++++
pttc/src/posix/util.c | 67 +
pttc/src/pttc.c | 62 +
pttc/src/util.c | 240 ++
pttc/src/windows/util.c | 137 +
pttc/src/yasm.c | 848 +++++
pttc/test/src/test_all_directives.ptt | 58 +
pttc/test/src/test_exp_labels.ptt | 58 +
pttc/test/src/test_label_addr.ptt | 31 +
ptunit/CMakeLists.txt | 43 +
ptunit/include/ptunit.h | 463 +++
ptunit/include/ptunit_mkfile.h | 48 +
ptunit/include/ptunit_threads.h | 158 +
ptunit/src/posix/ptunit_mkfile.c | 79 +
ptunit/src/ptunit.c | 345 ++
ptunit/src/windows/ptunit_mkfile.c | 72 +
ptunit/test/src/ptunit-selftest.c | 469 +++
ptxed/CMakeLists.txt | 79 +
ptxed/include/load_elf.h | 64 +
ptxed/src/load_elf.c | 359 ++
ptxed/src/ptxed.c | 2829 +++++++++++++++
script/perf-copy-mapped-files.bash | 275 ++
script/perf-get-opts.bash | 215 ++
script/perf-read-aux.bash | 124 +
script/perf-read-sideband.bash | 150 +
script/test.bash | 275 ++
sideband/CMakeLists.txt | 65 +
sideband/include/libipt-sb.h.in | 530 +++
sideband/internal/include/pt_sb_context.h | 99 +
sideband/internal/include/pt_sb_decoder.h | 69 +
sideband/internal/include/pt_sb_file.h | 47 +
sideband/internal/include/pt_sb_pevent.h | 155 +
sideband/internal/include/pt_sb_session.h | 101 +
sideband/src/pt_sb_context.c | 162 +
sideband/src/pt_sb_file.c | 99 +
sideband/src/pt_sb_pevent.c | 1710 +++++++++
sideband/src/pt_sb_session.c | 623 ++++
test/CMakeLists.txt | 63 +
test/pevent/CMakeLists.txt | 40 +
test/pevent/src/pevent-comm_exec-mmap-tsc-iret.ptt | 99 +
test/pevent/src/pevent-dump.ptt | 83 +
test/pevent/src/pevent-dump_verbose.ptt | 218 ++
test/pevent/src/pevent-fork.ptt | 91 +
test/pevent/src/pevent-mmap-tip_cached.ptt | 93 +
test/pevent/src/pevent-mmap_secondary-tsc.ptt | 101 +
test/pevent/src/pevent-split.ptt | 135 +
.../pevent-tip_pgd-comm_exec-mmap-tsc-tip_pge.ptt | 98 +
.../pevent/src/pevent-tip_pgd-mmap-tsc-tip_pge.ptt | 104 +
.../src/pevent-tip_pgd-switch-tsc-tip_pge.ptt | 110 +
.../pevent-tip_pgd-switch_cpu_wide-tsc-tip_pge.ptt | 109 +
test/pevent/src/pevent-warn.ptt | 79 +
test/src/apl11.ptt | 80 +
test/src/apl12-psb.ptt | 87 +
test/src/apl12-tip_pge.ptt | 89 +
test/src/bad_cpu.ptt | 60 +
test/src/bdm64-tip-xabort.ptt | 97 +
test/src/bdm64-tnt-cond-xabort.ptt | 107 +
test/src/bdm64-tnt-ind_call-xabort.ptt | 107 +
test/src/bdm70-psb_fup-tip_pge.ptt | 79 +
test/src/bdm70-tip_pgd-psb_fup-tip_pge.ptt | 97 +
test/src/call_direct-ret_compressed-pic.ptt | 68 +
test/src/call_direct-ret_compressed.ptt | 62 +
test/src/call_direct-ret_uncompressed.ptt | 61 +
test/src/call_indirect-ret_compressed.ptt | 63 +
test/src/call_indirect-ret_uncompressed.ptt | 63 +
test/src/call_indirect_deferred-ret_compressed.ptt | 65 +
test/src/cbr-cyc.ptt | 55 +
test/src/cbr-mtc-cyc-mtc.ptt | 54 +
test/src/cbr-tsc-cyc-tma.ptt | 57 +
test/src/cbr-tsc-tma-mtc-cyc.ptt | 56 +
test/src/direct_call-tip_pgd_noip-syscall.ptt | 60 +
test/src/direct_jump-tip_pgd_noip-far_call.ptt | 61 +
test/src/dump-all-packets.ptt | 143 +
test/src/exstop_ip-tip_pgd.ptt | 65 +
test/src/fup-pip-vmcs-tip.ptt | 71 +
test/src/fup-pip-vmcs-tip_pgd.ptt | 65 +
test/src/fup-tip-eos.ptt | 58 +
test/src/fup-tip-fup-tip_pgd.ptt | 67 +
test/src/fup-tip.ptt | 70 +
test/src/fup-tip_pgd-stop.ptt | 60 +
test/src/fup-tip_pgd-tip_pge.ptt | 63 +
test/src/fup-tip_pgd-tip_pge_other_ip.ptt | 66 +
test/src/fup-tip_pgd.ptt | 56 +
test/src/fup-tip_pgd_noip.ptt | 56 +
test/src/int-iret-cpl_0.ptt | 63 +
test/src/int-iret-cpl_3.ptt | 94 +
test/src/int-iret.ptt | 96 +
test/src/linear-fup-tip_pgd.ptt | 59 +
test/src/linear-tip.ptt | 65 +
test/src/loop-tnt-64.ptt | 193 ++
test/src/loop-tnt-tnt.ptt | 90 +
test/src/loop-tnt.ptt | 70 +
test/src/mode_exec-tip.ptt | 67 +
test/src/mtc-cyc_calibrate.ptt | 56 +
test/src/mtc.ptt | 50 +
test/src/mwait-pwre-exstop_ip-fup-ovf.ptt | 64 +
test/src/mwait-pwre-exstop_ip-ovf.ptt | 57 +
test/src/mwait-pwre-exstop_ip-pwrx.ptt | 67 +
test/src/ovf-fup.ptt | 64 +
test/src/ovf-mnt-fup.ptt | 69 +
test/src/ovf-mnt-tip_pge.ptt | 73 +
test/src/ovf-pwre-pwrx-tip_pge.ptt | 67 +
test/src/ovf-timing-fup.ptt | 77 +
test/src/ovf-timing-tip_pge.ptt | 81 +
test/src/ovf-tip_pge.ptt | 68 +
test/src/ovf.ptt | 50 +
test/src/pip-far_call.ptt | 68 +
test/src/pip-pip_mov_cr3-fail.ptt | 61 +
test/src/pip-vmcs-tip_pgd.ptt | 60 +
test/src/pip_mov_cr3-pip_mov_cr3.ptt | 66 +
test/src/psb-empty.ptt | 45 +
test/src/psb-exstop.ptt | 61 +
test/src/psb-fup-psbend.ptt | 53 +
test/src/psb-fup-tip_pgd-stop.ptt | 56 +
test/src/psb-fup-tip_pgd.ptt | 54 +
test/src/psb-mnt-fup-psbend.ptt | 55 +
test/src/psb-mnt-psbend.ptt | 50 +
test/src/psb-ovf-fup.ptt | 61 +
test/src/psb-ovf-tip_pge.ptt | 66 +
test/src/psb-pip-psb.ptt | 55 +
test/src/psb-pip-tip_pge.ptt | 62 +
test/src/psb-psb.ptt | 64 +
test/src/psb-stop.ptt | 48 +
test/src/psb-tnt-psb.ptt | 69 +
test/src/psb-tsx.ptt | 57 +
test/src/psb-tsx_abort-tip-fup-tip_pgd.ptt | 70 +
test/src/psb-tsx_abort-tip_pgd.ptt | 61 +
test/src/psb-tsx_abort.ptt | 69 +
test/src/psb-vmcs.ptt | 46 +
test/src/psb_nofup-psb.ptt | 61 +
test/src/ptdump-exec-mode.ptt | 46 +
test/src/ptdump-last-ip.ptt | 55 +
test/src/ptdump-no-offset-raw.ptt | 45 +
test/src/ptdump-no-offset.ptt | 45 +
test/src/ptw-fup.ptt | 59 +
test/src/ptw.ptt | 56 +
test/src/ptxed-block-stat.ptt | 63 +
test/src/ptxed-block-stat_blocks.ptt | 62 +
test/src/ptxed-end_on_call-fup-tip.ptt | 73 +
test/src/ptxed-end_on_call-fup-tip_pgd.ptt | 66 +
test/src/ptxed-end_on_call-ret_tip.ptt | 82 +
test/src/ptxed-end_on_call-ret_tnt.ptt | 72 +
test/src/ptxed-end_on_call-tip_pgd.ptt | 65 +
test/src/ptxed-end_on_jump-fup-tip_pgd.ptt | 65 +
test/src/ptxed-insn-stat.ptt | 63 +
test/src/ptxed-stat_insn.ptt | 63 +
test/src/ptxed-tick.ptt | 98 +
test/src/pwre-exstop_ip-pwrx.ptt | 72 +
test/src/ret_near_far.ptt | 361 ++
test/src/skd007.ptt | 81 +
test/src/skd010-mode_tsx-fup.ptt | 76 +
test/src/skd010-psb.ptt | 79 +
test/src/skd010-tip.ptt | 73 +
test/src/skd010-tip_pgd.ptt | 84 +
test/src/skd022.ptt | 81 +
test/src/skl014-call.ptt | 70 +
test/src/skl014-jmp-jmp.ptt | 74 +
test/src/skl014-jmp.ptt | 70 +
test/src/skl014-no_filter.ptt | 63 +
test/src/syscall-sysret-cpl_0.ptt | 63 +
test/src/syscall-sysret-cpl_3.ptt | 71 +
test/src/syscall-sysret.ptt | 71 +
test/src/sysenter-sysexit-cpl_0.ptt | 63 +
test/src/sysenter-sysexit-cpl_3.ptt | 71 +
test/src/sysenter-sysexit.ptt | 71 +
test/src/tip-eos.ptt | 55 +
test/src/tip_pgd-direct_call.ptt | 58 +
test/src/tip_pgd-direct_jump.ptt | 58 +
test/src/tip_pgd-exstop-tip_pge.ptt | 70 +
test/src/tip_pgd-indirect_call.ptt | 58 +
test/src/tip_pgd-indirect_jump.ptt | 58 +
test/src/tip_pgd-pip-tip_pge.ptt | 71 +
test/src/tip_pgd-psb-stop.ptt | 64 +
test/src/tip_pgd-stop.ptt | 59 +
test/src/tip_pgd-tnt_not_taken.ptt | 61 +
test/src/tip_pgd-tnt_taken.ptt | 61 +
test/src/tip_pgd-tsx.ptt | 78 +
test/src/tip_pgd_noip-far_jump.ptt | 54 +
test/src/tip_pgd_noip-mov_cr3.ptt | 54 +
test/src/tip_pge-exstop.ptt | 63 +
test/src/tip_pge-fup-tip_pgd-tip_pge.ptt | 66 +
test/src/tip_pge-fup-tip_pgd.ptt | 56 +
test/src/tip_pge-ptw-fup-tip_pgd.ptt | 75 +
test/src/tip_pge-ptw-tip_pgd.ptt | 72 +
test/src/tip_pge-pwre-pwrx-tip_pgd.ptt | 63 +
test/src/tip_pge-tsx_abort-tip-fup-tip_pgd.ptt | 73 +
test/src/tip_pge-tsx_abort-tip_pgd.ptt | 67 +
test/src/tnt-tip_pgd_noip-sysret.ptt | 64 +
test/src/tnt_n-eos.ptt | 55 +
test/src/tnt_t-eos.ptt | 55 +
test/src/truncated.ptt | 63 +
test/src/tsc-cbr-cyc-tsc.ptt | 57 +
test/src/tsc-cyc_calibrate.ptt | 69 +
test/src/tsc-mtc-tma-mtc.ptt | 52 +
test/src/tsc-tma-cbr-cyc-mtc.ptt | 57 +
test/src/tsc-tma-cbr-cyc.ptt | 55 +
test/src/tsc-tma-cbr-mtc-cyc-mtc.ptt | 58 +
test/src/tsc-tma-cbr-mtc-cyc-no_cyc.ptt | 56 +
test/src/tsc-tma-cbr-mtc-cyc-tsc.ptt | 58 +
test/src/tsc-tma-cbr-mtc-cyc.ptt | 56 +
test/src/tsc-tma-cbr-mtc-cyc_calibrate.ptt | 60 +
test/src/tsc-tma-cbr-mtc-mtc-cyc.ptt | 63 +
test/src/tsc-tma-cyc.ptt | 52 +
test/src/tsc-tma-mtc-cyc_calibrate.ptt | 60 +
test/src/tsc-tma-mtc-mtc-cyc_calibrate.ptt | 63 +
test/src/tsc-tma-mtc-tsc.ptt | 54 +
test/src/tsc-tma-mtc_absolute.ptt | 52 +
test/src/tsc-tma-mtc_infreq.ptt | 55 +
test/src/tsc-tma-mtc_infreq_wrap.ptt | 55 +
test/src/tsc-tma-mtc_relative.ptt | 52 +
test/src/tsc-tma-mtc_wrap.ptt | 52 +
test/src/tsc-tma_zero_fc-cbr-cyc.ptt | 56 +
test/src/tsc_tma_mtc_gap.ptt | 52 +
test/src/tsx-abort.ptt | 76 +
test/src/tsx-commit.ptt | 71 +
test/src/tsx-no_spurious_commit.ptt | 71 +
test/src/vmcs-far_call.ptt | 68 +
370 files changed, 82916 insertions(+)
create mode 100644 .gitignore
create mode 100644 CMakeLists.txt
create mode 100755 CONTRIBUTING
create mode 100644 LICENSE
create mode 100644 README
create mode 100755 doc/getting_started.md
create mode 100755 doc/howto_build.md
create mode 100644 doc/howto_capture.md
create mode 100644 doc/howto_libipt.md
create mode 100755 doc/howto_pttc.md
create mode 100644 doc/man/CMakeLists.txt
create mode 100644 doc/man/pt_alloc_encoder.3.md
create mode 100644 doc/man/pt_blk_alloc_decoder.3.md
create mode 100644 doc/man/pt_blk_get_offset.3.md
create mode 100644 doc/man/pt_blk_next.3.md
create mode 100644 doc/man/pt_blk_sync_forward.3.md
create mode 100644 doc/man/pt_config.3.md
create mode 100644 doc/man/pt_enc_get_config.3.md
create mode 100644 doc/man/pt_enc_get_offset.3.md
create mode 100644 doc/man/pt_image_add_file.3.md
create mode 100644 doc/man/pt_image_alloc.3.md
create mode 100644 doc/man/pt_image_remove_by_filename.3.md
create mode 100644 doc/man/pt_image_set_callback.3.md
create mode 100644 doc/man/pt_insn_alloc_decoder.3.md
create mode 100644 doc/man/pt_insn_get_image.3.md
create mode 100644 doc/man/pt_insn_get_offset.3.md
create mode 100644 doc/man/pt_insn_next.3.md
create mode 100644 doc/man/pt_insn_sync_forward.3.md
create mode 100644 doc/man/pt_iscache_add_file.3.md
create mode 100644 doc/man/pt_iscache_alloc.3.md
create mode 100644 doc/man/pt_iscache_read.3.md
create mode 100644 doc/man/pt_iscache_set_limit.3.md
create mode 100644 doc/man/pt_library_version.3.md
create mode 100644 doc/man/pt_packet.3.md
create mode 100644 doc/man/pt_pkt_alloc_decoder.3.md
create mode 100644 doc/man/pt_pkt_get_offset.3.md
create mode 100644 doc/man/pt_pkt_sync_forward.3.md
create mode 100644 doc/man/pt_qry_alloc_decoder.3.md
create mode 100644 doc/man/pt_qry_cond_branch.3.md
create mode 100644 doc/man/pt_qry_event.3.md
create mode 100644 doc/man/pt_qry_get_offset.3.md
create mode 100644 doc/man/pt_qry_sync_forward.3.md
create mode 100644 doc/man/pt_qry_time.3.md
create mode 100644 include/posix/threads.h
create mode 100644 include/pt_compiler.h
create mode 100644 include/windows/inttypes.h
create mode 100644 include/windows/threads.h
create mode 100644 libipt/CMakeLists.txt
create mode 100755 libipt/include/intel-pt.h.in
create mode 100644 libipt/internal/include/posix/pt_section_posix.h
create mode 100644 libipt/internal/include/pt_asid.h
create mode 100644 libipt/internal/include/pt_block_cache.h
create mode 100644 libipt/internal/include/pt_block_decoder.h
create mode 100644 libipt/internal/include/pt_config.h
create mode 100644 libipt/internal/include/pt_cpu.h
create mode 100644 libipt/internal/include/pt_cpuid.h
create mode 100644 libipt/internal/include/pt_decoder_function.h
create mode 100644 libipt/internal/include/pt_encoder.h
create mode 100644 libipt/internal/include/pt_event_queue.h
create mode 100644 libipt/internal/include/pt_ild.h
create mode 100644 libipt/internal/include/pt_image.h
create mode 100644 libipt/internal/include/pt_image_section_cache.h
create mode 100644 libipt/internal/include/pt_insn.h
create mode 100644 libipt/internal/include/pt_insn_decoder.h
create mode 100644 libipt/internal/include/pt_last_ip.h
create mode 100644 libipt/internal/include/pt_mapped_section.h
create mode 100644 libipt/internal/include/pt_msec_cache.h
create mode 100644 libipt/internal/include/pt_opcodes.h
create mode 100644 libipt/internal/include/pt_packet.h
create mode 100644 libipt/internal/include/pt_packet_decoder.h
create mode 100644 libipt/internal/include/pt_query_decoder.h
create mode 100644 libipt/internal/include/pt_retstack.h
create mode 100644 libipt/internal/include/pt_section.h
create mode 100644 libipt/internal/include/pt_section_file.h
create mode 100644 libipt/internal/include/pt_sync.h
create mode 100644 libipt/internal/include/pt_time.h
create mode 100644 libipt/internal/include/pt_tnt_cache.h
create mode 100644 libipt/internal/include/pti-disp-defs.h
create mode 100644 libipt/internal/include/pti-disp.h
create mode 100644 libipt/internal/include/pti-imm-defs.h
create mode 100644 libipt/internal/include/pti-imm.h
create mode 100644 libipt/internal/include/pti-modrm-defs.h
create mode 100644 libipt/internal/include/pti-modrm.h
create mode 100644 libipt/internal/include/windows/pt_section_windows.h
create mode 100644 libipt/src/posix/init.c
create mode 100644 libipt/src/posix/pt_cpuid.c
create mode 100644 libipt/src/posix/pt_section_posix.c
create mode 100644 libipt/src/pt_asid.c
create mode 100644 libipt/src/pt_block_cache.c
create mode 100644 libipt/src/pt_block_decoder.c
create mode 100644 libipt/src/pt_config.c
create mode 100644 libipt/src/pt_cpu.c
create mode 100644 libipt/src/pt_decoder_function.c
create mode 100644 libipt/src/pt_encoder.c
create mode 100644 libipt/src/pt_error.c
create mode 100644 libipt/src/pt_event_queue.c
create mode 100644 libipt/src/pt_ild.c
create mode 100644 libipt/src/pt_image.c
create mode 100644 libipt/src/pt_image_section_cache.c
create mode 100644 libipt/src/pt_insn.c
create mode 100644 libipt/src/pt_insn_decoder.c
create mode 100644 libipt/src/pt_last_ip.c
create mode 100644 libipt/src/pt_msec_cache.c
create mode 100644 libipt/src/pt_packet.c
create mode 100644 libipt/src/pt_packet_decoder.c
create mode 100644 libipt/src/pt_query_decoder.c
create mode 100644 libipt/src/pt_retstack.c
create mode 100644 libipt/src/pt_section.c
create mode 100644 libipt/src/pt_section_file.c
create mode 100644 libipt/src/pt_sync.c
create mode 100644 libipt/src/pt_time.c
create mode 100644 libipt/src/pt_tnt_cache.c
create mode 100644 libipt/src/pt_version.c
create mode 100644 libipt/src/windows/init.c
create mode 100644 libipt/src/windows/pt_cpuid.c
create mode 100644 libipt/src/windows/pt_section_windows.c
create mode 100644 libipt/test/src/ptunit-asid.c
create mode 100644 libipt/test/src/ptunit-block_cache.c
create mode 100644 libipt/test/src/ptunit-config.c
create mode 100644 libipt/test/src/ptunit-cpp.cpp
create mode 100644 libipt/test/src/ptunit-cpu.c
create mode 100644 libipt/test/src/ptunit-event_queue.c
create mode 100644 libipt/test/src/ptunit-fetch.c
create mode 100644 libipt/test/src/ptunit-ild.c
create mode 100644 libipt/test/src/ptunit-image.c
create mode 100644 libipt/test/src/ptunit-image_section_cache.c
create mode 100644 libipt/test/src/ptunit-last_ip.c
create mode 100644 libipt/test/src/ptunit-mapped_section.c
create mode 100644 libipt/test/src/ptunit-msec_cache.c
create mode 100644 libipt/test/src/ptunit-packet.c
create mode 100644 libipt/test/src/ptunit-query.c
create mode 100644 libipt/test/src/ptunit-retstack.c
create mode 100644 libipt/test/src/ptunit-section-file.c
create mode 100644 libipt/test/src/ptunit-section.c
create mode 100644 libipt/test/src/ptunit-sync.c
create mode 100644 libipt/test/src/ptunit-time.c
create mode 100644 libipt/test/src/ptunit-tnt_cache.c
create mode 100644 pevent/CMakeLists.txt
create mode 100644 pevent/include/pevent.h
create mode 100644 pevent/src/pevent.c
create mode 100644 pevent/test/src/ptunit-pevent.c
create mode 100644 ptdump/CMakeLists.txt
create mode 100644 ptdump/src/ptdump.c
create mode 100644 pttc/CMakeLists.txt
create mode 100644 pttc/include/errcode.h
create mode 100644 pttc/include/file.h
create mode 100644 pttc/include/parse.h
create mode 100644 pttc/include/pttc.h
create mode 100644 pttc/include/util.h
create mode 100644 pttc/include/yasm.h
create mode 100644 pttc/src/errcode.c
create mode 100644 pttc/src/file.c
create mode 100644 pttc/src/main.c
create mode 100644 pttc/src/parse.c
create mode 100644 pttc/src/posix/util.c
create mode 100644 pttc/src/pttc.c
create mode 100644 pttc/src/util.c
create mode 100644 pttc/src/windows/util.c
create mode 100644 pttc/src/yasm.c
create mode 100644 pttc/test/src/test_all_directives.ptt
create mode 100644 pttc/test/src/test_exp_labels.ptt
create mode 100644 pttc/test/src/test_label_addr.ptt
create mode 100644 ptunit/CMakeLists.txt
create mode 100644 ptunit/include/ptunit.h
create mode 100644 ptunit/include/ptunit_mkfile.h
create mode 100644 ptunit/include/ptunit_threads.h
create mode 100644 ptunit/src/posix/ptunit_mkfile.c
create mode 100644 ptunit/src/ptunit.c
create mode 100644 ptunit/src/windows/ptunit_mkfile.c
create mode 100644 ptunit/test/src/ptunit-selftest.c
create mode 100644 ptxed/CMakeLists.txt
create mode 100644 ptxed/include/load_elf.h
create mode 100644 ptxed/src/load_elf.c
create mode 100644 ptxed/src/ptxed.c
create mode 100755 script/perf-copy-mapped-files.bash
create mode 100755 script/perf-get-opts.bash
create mode 100755 script/perf-read-aux.bash
create mode 100755 script/perf-read-sideband.bash
create mode 100755 script/test.bash
create mode 100644 sideband/CMakeLists.txt
create mode 100644 sideband/include/libipt-sb.h.in
create mode 100644 sideband/internal/include/pt_sb_context.h
create mode 100644 sideband/internal/include/pt_sb_decoder.h
create mode 100644 sideband/internal/include/pt_sb_file.h
create mode 100644 sideband/internal/include/pt_sb_pevent.h
create mode 100644 sideband/internal/include/pt_sb_session.h
create mode 100644 sideband/src/pt_sb_context.c
create mode 100644 sideband/src/pt_sb_file.c
create mode 100644 sideband/src/pt_sb_pevent.c
create mode 100644 sideband/src/pt_sb_session.c
create mode 100644 test/CMakeLists.txt
create mode 100644 test/pevent/CMakeLists.txt
create mode 100644 test/pevent/src/pevent-comm_exec-mmap-tsc-iret.ptt
create mode 100644 test/pevent/src/pevent-dump.ptt
create mode 100644 test/pevent/src/pevent-dump_verbose.ptt
create mode 100644 test/pevent/src/pevent-fork.ptt
create mode 100644 test/pevent/src/pevent-mmap-tip_cached.ptt
create mode 100644 test/pevent/src/pevent-mmap_secondary-tsc.ptt
create mode 100644 test/pevent/src/pevent-split.ptt
create mode 100644 test/pevent/src/pevent-tip_pgd-comm_exec-mmap-tsc-tip_pge.ptt
create mode 100644 test/pevent/src/pevent-tip_pgd-mmap-tsc-tip_pge.ptt
create mode 100644 test/pevent/src/pevent-tip_pgd-switch-tsc-tip_pge.ptt
create mode 100644 test/pevent/src/pevent-tip_pgd-switch_cpu_wide-tsc-tip_pge.ptt
create mode 100644 test/pevent/src/pevent-warn.ptt
create mode 100644 test/src/apl11.ptt
create mode 100644 test/src/apl12-psb.ptt
create mode 100644 test/src/apl12-tip_pge.ptt
create mode 100644 test/src/bad_cpu.ptt
create mode 100644 test/src/bdm64-tip-xabort.ptt
create mode 100644 test/src/bdm64-tnt-cond-xabort.ptt
create mode 100644 test/src/bdm64-tnt-ind_call-xabort.ptt
create mode 100644 test/src/bdm70-psb_fup-tip_pge.ptt
create mode 100644 test/src/bdm70-tip_pgd-psb_fup-tip_pge.ptt
create mode 100644 test/src/call_direct-ret_compressed-pic.ptt
create mode 100644 test/src/call_direct-ret_compressed.ptt
create mode 100644 test/src/call_direct-ret_uncompressed.ptt
create mode 100644 test/src/call_indirect-ret_compressed.ptt
create mode 100644 test/src/call_indirect-ret_uncompressed.ptt
create mode 100644 test/src/call_indirect_deferred-ret_compressed.ptt
create mode 100644 test/src/cbr-cyc.ptt
create mode 100644 test/src/cbr-mtc-cyc-mtc.ptt
create mode 100644 test/src/cbr-tsc-cyc-tma.ptt
create mode 100644 test/src/cbr-tsc-tma-mtc-cyc.ptt
create mode 100644 test/src/direct_call-tip_pgd_noip-syscall.ptt
create mode 100644 test/src/direct_jump-tip_pgd_noip-far_call.ptt
create mode 100644 test/src/dump-all-packets.ptt
create mode 100644 test/src/exstop_ip-tip_pgd.ptt
create mode 100644 test/src/fup-pip-vmcs-tip.ptt
create mode 100644 test/src/fup-pip-vmcs-tip_pgd.ptt
create mode 100644 test/src/fup-tip-eos.ptt
create mode 100644 test/src/fup-tip-fup-tip_pgd.ptt
create mode 100644 test/src/fup-tip.ptt
create mode 100644 test/src/fup-tip_pgd-stop.ptt
create mode 100644 test/src/fup-tip_pgd-tip_pge.ptt
create mode 100644 test/src/fup-tip_pgd-tip_pge_other_ip.ptt
create mode 100644 test/src/fup-tip_pgd.ptt
create mode 100644 test/src/fup-tip_pgd_noip.ptt
create mode 100644 test/src/int-iret-cpl_0.ptt
create mode 100644 test/src/int-iret-cpl_3.ptt
create mode 100644 test/src/int-iret.ptt
create mode 100644 test/src/linear-fup-tip_pgd.ptt
create mode 100644 test/src/linear-tip.ptt
create mode 100644 test/src/loop-tnt-64.ptt
create mode 100644 test/src/loop-tnt-tnt.ptt
create mode 100644 test/src/loop-tnt.ptt
create mode 100644 test/src/mode_exec-tip.ptt
create mode 100644 test/src/mtc-cyc_calibrate.ptt
create mode 100644 test/src/mtc.ptt
create mode 100644 test/src/mwait-pwre-exstop_ip-fup-ovf.ptt
create mode 100644 test/src/mwait-pwre-exstop_ip-ovf.ptt
create mode 100644 test/src/mwait-pwre-exstop_ip-pwrx.ptt
create mode 100644 test/src/ovf-fup.ptt
create mode 100644 test/src/ovf-mnt-fup.ptt
create mode 100644 test/src/ovf-mnt-tip_pge.ptt
create mode 100644 test/src/ovf-pwre-pwrx-tip_pge.ptt
create mode 100644 test/src/ovf-timing-fup.ptt
create mode 100644 test/src/ovf-timing-tip_pge.ptt
create mode 100644 test/src/ovf-tip_pge.ptt
create mode 100644 test/src/ovf.ptt
create mode 100644 test/src/pip-far_call.ptt
create mode 100644 test/src/pip-pip_mov_cr3-fail.ptt
create mode 100755 test/src/pip-vmcs-tip_pgd.ptt
create mode 100644 test/src/pip_mov_cr3-pip_mov_cr3.ptt
create mode 100644 test/src/psb-empty.ptt
create mode 100644 test/src/psb-exstop.ptt
create mode 100644 test/src/psb-fup-psbend.ptt
create mode 100644 test/src/psb-fup-tip_pgd-stop.ptt
create mode 100644 test/src/psb-fup-tip_pgd.ptt
create mode 100644 test/src/psb-mnt-fup-psbend.ptt
create mode 100644 test/src/psb-mnt-psbend.ptt
create mode 100644 test/src/psb-ovf-fup.ptt
create mode 100644 test/src/psb-ovf-tip_pge.ptt
create mode 100644 test/src/psb-pip-psb.ptt
create mode 100644 test/src/psb-pip-tip_pge.ptt
create mode 100644 test/src/psb-psb.ptt
create mode 100644 test/src/psb-stop.ptt
create mode 100644 test/src/psb-tnt-psb.ptt
create mode 100644 test/src/psb-tsx.ptt
create mode 100644 test/src/psb-tsx_abort-tip-fup-tip_pgd.ptt
create mode 100644 test/src/psb-tsx_abort-tip_pgd.ptt
create mode 100644 test/src/psb-tsx_abort.ptt
create mode 100644 test/src/psb-vmcs.ptt
create mode 100644 test/src/psb_nofup-psb.ptt
create mode 100644 test/src/ptdump-exec-mode.ptt
create mode 100644 test/src/ptdump-last-ip.ptt
create mode 100644 test/src/ptdump-no-offset-raw.ptt
create mode 100644 test/src/ptdump-no-offset.ptt
create mode 100644 test/src/ptw-fup.ptt
create mode 100644 test/src/ptw.ptt
create mode 100644 test/src/ptxed-block-stat.ptt
create mode 100644 test/src/ptxed-block-stat_blocks.ptt
create mode 100644 test/src/ptxed-end_on_call-fup-tip.ptt
create mode 100644 test/src/ptxed-end_on_call-fup-tip_pgd.ptt
create mode 100644 test/src/ptxed-end_on_call-ret_tip.ptt
create mode 100644 test/src/ptxed-end_on_call-ret_tnt.ptt
create mode 100644 test/src/ptxed-end_on_call-tip_pgd.ptt
create mode 100644 test/src/ptxed-end_on_jump-fup-tip_pgd.ptt
create mode 100644 test/src/ptxed-insn-stat.ptt
create mode 100644 test/src/ptxed-stat_insn.ptt
create mode 100644 test/src/ptxed-tick.ptt
create mode 100644 test/src/pwre-exstop_ip-pwrx.ptt
create mode 100644 test/src/ret_near_far.ptt
create mode 100644 test/src/skd007.ptt
create mode 100644 test/src/skd010-mode_tsx-fup.ptt
create mode 100644 test/src/skd010-psb.ptt
create mode 100644 test/src/skd010-tip.ptt
create mode 100644 test/src/skd010-tip_pgd.ptt
create mode 100644 test/src/skd022.ptt
create mode 100644 test/src/skl014-call.ptt
create mode 100644 test/src/skl014-jmp-jmp.ptt
create mode 100644 test/src/skl014-jmp.ptt
create mode 100644 test/src/skl014-no_filter.ptt
create mode 100644 test/src/syscall-sysret-cpl_0.ptt
create mode 100644 test/src/syscall-sysret-cpl_3.ptt
create mode 100644 test/src/syscall-sysret.ptt
create mode 100644 test/src/sysenter-sysexit-cpl_0.ptt
create mode 100644 test/src/sysenter-sysexit-cpl_3.ptt
create mode 100644 test/src/sysenter-sysexit.ptt
create mode 100644 test/src/tip-eos.ptt
create mode 100644 test/src/tip_pgd-direct_call.ptt
create mode 100644 test/src/tip_pgd-direct_jump.ptt
create mode 100644 test/src/tip_pgd-exstop-tip_pge.ptt
create mode 100644 test/src/tip_pgd-indirect_call.ptt
create mode 100644 test/src/tip_pgd-indirect_jump.ptt
create mode 100644 test/src/tip_pgd-pip-tip_pge.ptt
create mode 100644 test/src/tip_pgd-psb-stop.ptt
create mode 100644 test/src/tip_pgd-stop.ptt
create mode 100644 test/src/tip_pgd-tnt_not_taken.ptt
create mode 100644 test/src/tip_pgd-tnt_taken.ptt
create mode 100644 test/src/tip_pgd-tsx.ptt
create mode 100644 test/src/tip_pgd_noip-far_jump.ptt
create mode 100644 test/src/tip_pgd_noip-mov_cr3.ptt
create mode 100644 test/src/tip_pge-exstop.ptt
create mode 100644 test/src/tip_pge-fup-tip_pgd-tip_pge.ptt
create mode 100644 test/src/tip_pge-fup-tip_pgd.ptt
create mode 100644 test/src/tip_pge-ptw-fup-tip_pgd.ptt
create mode 100644 test/src/tip_pge-ptw-tip_pgd.ptt
create mode 100644 test/src/tip_pge-pwre-pwrx-tip_pgd.ptt
create mode 100644 test/src/tip_pge-tsx_abort-tip-fup-tip_pgd.ptt
create mode 100644 test/src/tip_pge-tsx_abort-tip_pgd.ptt
create mode 100644 test/src/tnt-tip_pgd_noip-sysret.ptt
create mode 100644 test/src/tnt_n-eos.ptt
create mode 100644 test/src/tnt_t-eos.ptt
create mode 100644 test/src/truncated.ptt
create mode 100644 test/src/tsc-cbr-cyc-tsc.ptt
create mode 100644 test/src/tsc-cyc_calibrate.ptt
create mode 100644 test/src/tsc-mtc-tma-mtc.ptt
create mode 100644 test/src/tsc-tma-cbr-cyc-mtc.ptt
create mode 100644 test/src/tsc-tma-cbr-cyc.ptt
create mode 100644 test/src/tsc-tma-cbr-mtc-cyc-mtc.ptt
create mode 100644 test/src/tsc-tma-cbr-mtc-cyc-no_cyc.ptt
create mode 100644 test/src/tsc-tma-cbr-mtc-cyc-tsc.ptt
create mode 100644 test/src/tsc-tma-cbr-mtc-cyc.ptt
create mode 100644 test/src/tsc-tma-cbr-mtc-cyc_calibrate.ptt
create mode 100644 test/src/tsc-tma-cbr-mtc-mtc-cyc.ptt
create mode 100644 test/src/tsc-tma-cyc.ptt
create mode 100644 test/src/tsc-tma-mtc-cyc_calibrate.ptt
create mode 100644 test/src/tsc-tma-mtc-mtc-cyc_calibrate.ptt
create mode 100644 test/src/tsc-tma-mtc-tsc.ptt
create mode 100644 test/src/tsc-tma-mtc_absolute.ptt
create mode 100644 test/src/tsc-tma-mtc_infreq.ptt
create mode 100644 test/src/tsc-tma-mtc_infreq_wrap.ptt
create mode 100644 test/src/tsc-tma-mtc_relative.ptt
create mode 100644 test/src/tsc-tma-mtc_wrap.ptt
create mode 100644 test/src/tsc-tma_zero_fc-cbr-cyc.ptt
create mode 100644 test/src/tsc_tma_mtc_gap.ptt
create mode 100644 test/src/tsx-abort.ptt
create mode 100644 test/src/tsx-commit.ptt
create mode 100644 test/src/tsx-no_spurious_commit.ptt
create mode 100644 test/src/vmcs-far_call.ptt
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000..a4fdaf31b7b71
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+*.lst
+*.bin
+*.pt
+*.sb
+*.exp
+*.out
+*.diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000000000..33c5c1617cc47
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,304 @@
+# Copyright (c) 2013-2018, Intel Corporation
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# * Neither the name of Intel Corporation nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+cmake_minimum_required(VERSION 2.8.6)
+
+project(PT C)
+
+# versioning
+#
+# the major and the minor number define the supported Intel PT set.
+#
+# a build number and a version extension can be optionally specified.
+#
+set(PT_VERSION_MAJOR 1)
+set(PT_VERSION_MINOR 6)
+set(PT_VERSION_BUILD "0" CACHE STRING "")
+set(PT_VERSION_EXT "" CACHE STRING "")
+
+set(PT_VERSION "${PT_VERSION_MAJOR}.${PT_VERSION_MINOR}.${PT_VERSION_BUILD}")
+
+add_definitions(
+ -DPT_VERSION_MAJOR=${PT_VERSION_MAJOR}
+ -DPT_VERSION_MINOR=${PT_VERSION_MINOR}
+ -DPT_VERSION_BUILD=${PT_VERSION_BUILD}
+ -DPT_VERSION_EXT=\"${PT_VERSION_EXT}\"
+)
+
+include(GNUInstallDirs)
+include(FindUnixCommands)
+include(CheckCCompilerFlag)
+
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(MAN_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/man)
+
+set(CMAKE_COLOR_MAKEFILE OFF)
+set(CMAKE_VERBOSE_MAKEFILE ON)
+
+set(CMAKE_MACOSX_RPATH ON)
+
+option(FEATURE_THREADS "A small amount of multi-threading support." ON)
+if (FEATURE_THREADS)
+ add_definitions(-DFEATURE_THREADS)
+endif (FEATURE_THREADS)
+
+option(DEVBUILD "Enable compiler warnings and turn them into errors." OFF)
+
+option(PTDUMP "Enable ptdump, a packet dumper")
+option(PTXED "Enable ptxed, an instruction flow dumper")
+option(PTTC "Enable pttc, a test compiler")
+option(PTUNIT "Enable ptunit, a unit test system and libipt unit tests")
+option(MAN "Enable man pages (requires pandoc)." OFF)
+option(SIDEBAND "Enable libipt-sb, a sideband correlation library")
+
+if (SIDEBAND)
+ option(PEVENT "Enable perf_event sideband support." OFF)
+endif (SIDEBAND)
+
+if (PTXED OR PEVENT)
+ option(FEATURE_ELF "Support ELF files." OFF)
+endif (PTXED OR PEVENT)
+
+set(PTT OFF)
+if (BASH AND PTDUMP AND PTXED AND PTTC)
+ set(PTT ON)
+endif ()
+
+if (PTUNIT OR PTT)
+ ENABLE_TESTING()
+endif()
+
+if (PTUNIT)
+ enable_language(CXX)
+endif()
+
+include_directories(
+ include
+ ${CMAKE_CURRENT_BINARY_DIR}/libipt/include
+)
+
+if (PTUNIT)
+ include_directories(
+ ptunit/include
+ )
+endif (PTUNIT)
+
+if (FEATURE_ELF)
+ add_definitions(
+ -DFEATURE_ELF
+ )
+endif (FEATURE_ELF)
+
+if (SIDEBAND)
+ add_definitions(
+ -DFEATURE_SIDEBAND
+ )
+
+ include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}/sideband/include
+ )
+endif (SIDEBAND)
+
+if (PEVENT)
+ add_definitions(
+ -DFEATURE_PEVENT
+ )
+
+ include_directories(
+ pevent/include
+ )
+endif (PEVENT)
+
+
+function(add_cflag_if_available option)
+
+ check_c_compiler_flag(${option} ${option}_supported)
+ if (${option}_supported)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${option}" PARENT_SCOPE)
+ endif (${option}_supported)
+
+endfunction(add_cflag_if_available)
+
+
+if (CMAKE_HOST_WIN32)
+ include_directories(
+ include/windows
+ )
+
+ add_definitions(
+ # cl spells inline __inline in C
+ #
+ /Dinline=__inline
+
+ # cl spells strtoll _strtoi64
+ #
+ /Dstrtoll=_strtoi64
+
+ # cl spells strtoull _strtoui64
+ #
+ /Dstrtoull=_strtoui64
+
+ # avoid annoying warnings about unsecure standard functions
+ #
+ /D_CRT_SECURE_NO_WARNINGS
+ )
+
+ # enable parallel build
+ #
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
+
+ if (DEVBUILD)
+ # compiler warnings
+ #
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
+
+ # warnings are errors
+ #
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
+ endif (DEVBUILD)
+
+ if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
+ # prevent complaints on:
+ # - do {} while(0) constructs
+ # - int arr[] constructs
+ #
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4200")
+
+ endif (CMAKE_C_COMPILER_ID MATCHES "MSVC")
+
+endif (CMAKE_HOST_WIN32)
+
+if (CMAKE_HOST_UNIX)
+ include_directories(
+ include/posix
+ )
+
+ add_definitions(
+ -D_POSIX_C_SOURCE=200809L
+ )
+
+ option(GCOV "Compile for GNU code coverage analysis." OFF)
+
+ if (GCOV)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftest-coverage")
+
+ link_libraries(gcov)
+ endif (GCOV)
+
+ if (FEATURE_THREADS)
+ link_libraries(pthread)
+ endif (FEATURE_THREADS)
+
+ # set the language
+ #
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
+
+ # windows-like dll export model
+ #
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
+
+ if (DEVBUILD)
+ # compiler warnings
+ #
+ if (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Weverything")
+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-disabled-macro-expansion")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-covered-switch-default")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-sign-conversion")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch-enum")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-cast-align")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-padded")
+ else (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
+
+ add_cflag_if_available("-Wimplicit-fallthrough=5")
+ endif (CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
+
+ # warnings are errors
+ #
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
+ endif (DEVBUILD)
+
+endif (CMAKE_HOST_UNIX)
+
+
+function(add_ptunit_test_base name)
+ if (PTUNIT)
+ add_executable(${name} ${ARGN})
+ target_link_libraries(${name} ptunit)
+
+ add_test(NAME ${name} COMMAND ${name})
+ endif (PTUNIT)
+endfunction(add_ptunit_test_base)
+
+function(add_ptunit_c_test name)
+ add_ptunit_test_base(ptunit-${name} test/src/ptunit-${name}.c ${ARGN})
+endfunction(add_ptunit_c_test)
+
+function(add_ptunit_cpp_test name)
+ add_ptunit_test_base(ptunit-${name} test/src/ptunit-${name}.cpp ${ARGN})
+endfunction(add_ptunit_cpp_test)
+
+function(add_ptunit_libraries name)
+ if (PTUNIT)
+ target_link_libraries(ptunit-${name} ${ARGN})
+ endif (PTUNIT)
+endfunction(add_ptunit_libraries)
+
+
+add_subdirectory(libipt)
+
+if (PTDUMP)
+ add_subdirectory(ptdump)
+endif (PTDUMP)
+if (PTXED)
+ add_subdirectory(ptxed)
+endif (PTXED)
+if (PTTC)
+ add_subdirectory(pttc)
+endif (PTTC)
+if (PTUNIT)
+ add_subdirectory(ptunit)
+endif (PTUNIT)
+if (PTT)
+ add_subdirectory(test)
+endif (PTT)
+if (MAN)
+ add_subdirectory(doc/man)
+endif (MAN)
+if (SIDEBAND)
+ add_subdirectory(sideband)
+endif (SIDEBAND)
+if (PEVENT)
+ add_subdirectory(pevent)
+endif (PEVENT)
diff --git a/CONTRIBUTING b/CONTRIBUTING
new file mode 100755
index 0000000000000..51e56117eb2d9
--- /dev/null
+++ b/CONTRIBUTING
@@ -0,0 +1,107 @@
+Contributing to this Project
+============================
+
+## License
+
+This project is licensed under the terms and conditions of the 3-Clause BSD
+[LICENSE](LICENSE). By contributing to this project, you agree that you are
+providing your contribution under the terms and conditions of that license.
+
+
+## Patches
+
+We accept patches to this project as pull requests on GitHub. When submitting
+patches, please keep each patch self-contained and as small as possible. Please
+address one topic per patch series. Intermediate patches must build without
+errors (with DEVBUILD=ON) and not introduce test fails. Please describe what
+each patch is doing in its commit message.
+
+If you are contributing a patch series that addresses a GitHub Issue, the last
+patch in the series should have 'fixes #' in its commit-message.
+
+If the patch series addresses a bug that is not tracked, please provide a
+detailed description of the issue in the commit-message, ideally with a
+description of the 'before' and 'after' behavior.
+
+The patch series should contain regression tests either as PTT tests or as
+ptunit tests. Please make sure that all tests are passing. This may require
+re-ordering patches to introduce the regression test after the issue was fixed.
+
+If the patch series adds a new feature, please make sure to add documentation.
+Prior to submitting this type of contribution, it may be a good idea to first
+discuss the feature as a GitHub issue or via email before implementing it.
+
+This project is using the Linux coding style.
+
+
+## Sign Your Patch
+
+Please use the sign-off line at the end of each patch. Your signature
+certifies that you wrote the patch or otherwise have the right to pass
+it on as an open-source patch. The rules are pretty simple: if you can
+certify the below (from
+[developercertificate.org](http://developercertificate.org/)):
+
+```
+Developer Certificate of Origin
+Version 1.1
+
+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
+660 York Street, Suite 102,
+San Francisco, CA 94110 USA
+
+Everyone is permitted to copy and distribute verbatim copies of this
+license document, but changing it is not allowed.
+
+Developer's Certificate of Origin 1.1
+
+By making a contribution to this project, I certify that:
+
+(a) The contribution was created in whole or in part by me and I
+ have the right to submit it under the open source license
+ indicated in the file; or
+
+(b) The contribution is based upon previous work that, to the best
+ of my knowledge, is covered under an appropriate open source
+ license and I have the right under that license to submit that
+ work with modifications, whether created in whole or in part
+ by me, under the same open source license (unless I am
+ permitted to submit under a different license), as indicated
+ in the file; or
+
+(c) The contribution was provided directly to me by some other
+ person who certified (a), (b) or (c) and I have not modified
+ it.
+
+(d) I understand and agree that this project and the contribution
+ are public and that a record of the contribution (including all
+ personal information I submit with it, including my sign-off) is
+ maintained indefinitely and may be redistributed consistent with
+ this project or the open source license(s) involved.
+```
+
+Then you just add a line to every git commit message:
+
+ Signed-off-by: Joe Smith
+
+Use your real name (sorry, no pseudonyms or anonymous contributions.)
+
+If you set your `user.name` and `user.email` git configs, you can sign your
+commit automatically with `git commit -s`.
+
+
+## Reporting Issues
+
+If you want to report an issue or bug, please report them via the GitHub Issues
+tracker.
+
+When reporting a bug, please provide the steps to reproduce it with the ptdump
+and ptxed tools contained in the tree. Please include the command-line that was
+used and the exact error message. You may also attach a trace file and the
+binaries necessary for reproducing the issue or write a small PTT test to
+demonstrate the issue.
+
+When providing trace snippets, please provide a few extra packets of context.
+
+Please also provide the processor family and model on which the trace was
+recorded and the version of the decoder that was used to decode the trace.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000000..9e92f1510bbcc
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+Copyright (c) 2013-2018, Intel Corporation
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/README b/README
new file mode 100644
index 0000000000000..6da6663c7bb13
--- /dev/null
+++ b/README
@@ -0,0 +1,79 @@
+Intel(R) Processor Trace Decoder Library
+========================================
+
+The Intel Processor Trace (Intel PT) Decoder Library is Intel's reference
+implementation for decoding Intel PT. It can be used as a standalone library or
+it can be partially or fully integrated into your tool.
+
+The library comes with a set of sample tools built on top of it and a test
+system built on top of the sample tools. The samples demonstrate how to use the
+library and may serve as a starting point for integrating the library into your
+tool.
+
+Go to https://software.intel.com/en-us/intel-platform-analysis-library for
+support of upcoming (non-public) processors (NDA required).
+
+
+Contents
+--------
+
+ README this file
+
+ libipt A packet encoder/decoder library
+
+
+Optional Contents and Samples
+-----------------------------
+
+ ptdump Example implementation of a packet dumper
+
+ ptxed Example implementation of a trace disassembler
+
+ pttc A trace test generator
+
+ ptunit A simple unit test system
+
+ sideband A sideband correlation library
+
+ pevent A library for reading/writing Linux perf event records
+
+ script A collection of scripts
+
+ test A collection of tests
+
+ include A collection of substitute headers
+
+ doc A document describing the build
+ A document describing how to get started
+ A document describing the usage of the decoder library
+ A document describing how to capture trace
+ A document describing pttc
+
+ doc/man Man pages for the encoder/decoder library
+
+
+Dependencies
+------------
+
+We use cmake for building.
+
+ cmake The cross-platform open-source build system.
+ http://www.cmake.org
+
+
+Other packages you need for some of the above optional components.
+
+ xed The Intel x86 instruction encoder and decoder.
+ https://github.com/intelxed/xed
+
+ This is needed to build and run ptxed.
+
+ yasm The Yasm Modular Assembler
+ http://github.com/yasm
+
+ This is needed to run pttc.
+
+ pandoc A universal document converter
+ http://pandoc.org
+
+ This is needed for man pages.
diff --git a/doc/getting_started.md b/doc/getting_started.md
new file mode 100755
index 0000000000000..3b3b6ecfb4df2
--- /dev/null
+++ b/doc/getting_started.md
@@ -0,0 +1,93 @@
+Getting Started {#start}
+========================
+
+
+
+This chapter gives a brief introduction into the sample tools using one of the
+tests as example. It assumes that you are already familiar with Intel(R)
+Processor Trace (Intel PT) and that you already built the decoder library and
+the sample tools. For detailed information about Intel PT, please refer to
+chapter 11 of the Intel Architecture Instruction Set Extensions Programming
+Reference at http://www.intel.com/products/processor/manuals/.
+
+Start by compiling the loop-tnt test. It consists of a small assembly program
+with interleaved Intel PT directives:
+
+ $ pttc test/src/loop-tnt.ptt
+ loop-tnt-ptxed.exp
+ loop-tnt-ptdump.exp
+
+This produces the following output files:
+
+ loop-tnt.lst a yasm assembly listing file
+ loop-tnt.bin a raw binary file
+ loop-tnt.pt a Intel PT file
+ loop-tnt-ptxed.exp the expected ptxed output
+ loop-tnt-ptdump.exp the expected ptdump output
+
+The latter two files are generated based on the `@pt .exp()` directives
+found in the `.ptt` file. They are used for automated testing. See
+script/test.bash for details on that.
+
+
+Use `ptdump` to dump the Intel PT packets:
+
+ $ ptdump loop-tnt.pt
+ 0000000000000000 psb
+ 0000000000000010 fup 3: 0x0000000000100000, ip=0x0000000000100000
+ 0000000000000017 mode.exec cs.d=0, cs.l=1 (64-bit mode)
+ 0000000000000019 psbend
+ 000000000000001b tnt8 !!.
+ 000000000000001c tip.pgd 3: 0x0000000000100013, ip=0x0000000000100013
+
+The ptdump tool takes an Intel PT file as input and dumps the packets in
+human-readable form. The number on the very left is the offset into the Intel
+PT packet stream in hex. This is followed by the packet opcode and payload.
+
+
+Use `ptxed` for reconstructing the execution flow. For this, you need the Intel
+PT file as well as the corresponding binary image. You need to specify the load
+address given by the org directive in the .ptt file when using a raw binary
+file.
+
+ $ ptxed --pt loop-tnt.pt --raw loop-tnt.bin:0x100000
+ 0x0000000000100000 mov rax, 0x0
+ 0x0000000000100007 jmp 0x10000d
+ 0x000000000010000d cmp rax, 0x1
+ 0x0000000000100011 jle 0x100009
+ 0x0000000000100009 add rax, 0x1
+ 0x000000000010000d cmp rax, 0x1
+ 0x0000000000100011 jle 0x100009
+ 0x0000000000100009 add rax, 0x1
+ 0x000000000010000d cmp rax, 0x1
+ 0x0000000000100011 jle 0x100009
+ [disabled]
+
+Ptxed prints disassembled instructions in execution order as well as status
+messages enclosed in brackets.
diff --git a/doc/howto_build.md b/doc/howto_build.md
new file mode 100755
index 0000000000000..72417213fc38d
--- /dev/null
+++ b/doc/howto_build.md
@@ -0,0 +1,197 @@
+Building the Intel(R) Processor Trace (Intel PT) Decoder Library and Samples {#build}
+============================================================================
+
+
+
+This chapter gives step-by-step instructions for building the library and the
+sample tools using cmake. For detailed information on cmake, see
+http://www.cmake.org.
+
+
+## Configuration
+
+Besides the standard cmake options of build type and install directory, you will
+find project-specific options for enabling optional features, optional
+components, or optional build variants.
+
+
+### Optional Components
+
+By default, only the decoder library is built. Other components can be enabled
+by setting the respective cmake variable to ON.
+
+The following optional components are availble:
+
+ PTUNIT A simple unit test framework.
+ A collection of unit tests for libipt.
+
+ PTDUMP A packet dumper example.
+
+ PTXED A trace disassembler example.
+
+ PTTC A trace test generator.
+
+ SIDEBAND A sideband correlation library
+
+ PEVENT Support for the Linux perf_event sideband format.
+
+ This feature requires the linux/perf_event.h header.
+
+
+### Optional Features
+
+Features are enabled by setting the respective FEATURE_ cmake variable.
+This causes the FEATURE_ pre-processor macro to be defined and may also
+cause additional source files to be compiled and additional libraries to be
+linked.
+
+Features are enabled globally and will be used by all components that support
+the feature. The following features are supported:
+
+ FEATURE_ELF Support for the ELF object format.
+
+ This feature requires the elf.h header.
+
+
+ FEATURE_THREADS Support some amount of multi-threading.
+
+ This feature makes image functions thread-safe.
+
+
+### Build Variants
+
+Some build variants depend on libraries or header files that may not be
+available on all supported platforms.
+
+ GCOV Support for code coverage using libgcov.
+
+ This build variant requires libgcov and is not availble
+ on Windows.
+
+
+ DEVBUILD Enable compiler warnings and turn them into errors.
+
+
+### Version Settings
+
+The major and minor version numbers are set in the sources and must be changed
+there. You can set the build number and an arbitrary extension string.
+build.
+
+ PT_VERSION_BUILD The build number.
+
+ Defaults to zero.
+
+
+ PT_VERSION_EXT An arbitrary version extension string.
+
+ Defaults to the empty string.
+
+
+### Dependencies
+
+In order to build ptxed, the location of the XED library and the XED header
+files must be specified.
+
+ XED_INCLUDE Path to the directory containing the XED header files.
+
+ XED_LIBDIR Path to the directory containing the XED library.
+
+
+When using XED from a PIN distribution, the respective directories are located
+in `extras/xed2-/`.
+
+
+## Building on Linux``*`` and OS X``*``
+
+We recommend out-of-tree builds. Start by creating the destination directory
+and navigating into it:
+
+ $ mkdir -p /path/to/dest
+ $ cd /path/to/dest
+
+
+From here, call cmake with the top-level source directory as argument. You may
+already pass some or all of the cmake variables as arguments to cmake. Without
+arguments, cmake uses default values.
+
+ $ cmake /path/to/src
+
+
+If you have not passed values for XED_INCLUDE or XED_LIBDIR, you need to
+configure them now if you want to build ptxed. You may also use this command to
+change the configuration at any time later on.
+
+ $ make edit_cache
+
+
+After configuring the cmake cache, you can build either specific targets or
+everything using one of:
+
+ $ make
+ $ make
+
+
+Use the help make target to learn about available make targets:
+
+ $ make help
+
+
+
+## Building on Windows``*``
+
+We recommend using the cmake GUI. After starting the cmake GUI, fill in the
+following fields:
+
+ Where is the source code: Path to the top-level source directory.
+
+ Where to build the binaries: Path to the destination directory.
+
+
+We recommend out-of-tree builds, so the build directory should not be the same
+as or below the source directory. After this first configuration step, press
+the
+
+ Configure
+
+button and select the builder you want to use.
+
+Cmake will now populate the remainder of the window with configuration options.
+Please make sure to specify at least XED_INCLUDE and XED_LIBDIR if you want to
+build ptxed. After completing the configuration, press the
+
+ Generate
+
+button. If you selected a Visual Studio generator in the first step, cmake will
+now generate a Visual Studio solution. You can repeat this step if you want to
+change the configuration later on. Beware that you always need to press the
+Generate button after changing the configuration.
+
+In the case of a Visual Studio generator, you may now open the generated Visual
+Studio solution and build the library and samples.
diff --git a/doc/howto_capture.md b/doc/howto_capture.md
new file mode 100644
index 0000000000000..979991915eb7b
--- /dev/null
+++ b/doc/howto_capture.md
@@ -0,0 +1,628 @@
+Capturing Intel(R) Processor Trace (Intel PT) {#capture}
+=============================================
+
+
+
+This chapter describes how to capture Intel PT for processing with libipt. For
+illustration, we use the sample tools ptdump and ptxed. We assume that they are
+configured with:
+
+ * PEVENT=ON
+ * FEATURE_ELF=ON
+
+
+## Capturing Intel PT on Linux
+
+Starting with version 4.1, the Linux kernel supports Intel PT via the perf_event
+kernel interface. Starting with version 4.3, the perf user-space tool will
+support Intel PT as well.
+
+
+### Capturing Intel PT via Linux perf_event
+
+We start with setting up a perf_event_attr object for capturing Intel PT. The
+structure is declared in `/usr/include/linux/perf_event.h`.
+
+The Intel PT PMU type is dynamic. Its value can be read from
+`/sys/bus/event_source/devices/intel_pt/type`.
+
+~~~{.c}
+ struct perf_event_attr attr;
+
+ memset(&attr, 0, sizeof(attr));
+ attr.size = sizeof(attr);
+ attr.type = ();
+
+ attr.exclude_kernel = 1;
+ ...
+~~~
+
+
+Once all desired fields have been set, we can open a perf_event counter for
+Intel PT. See `perf_event_open(2)` for details. In our example, we configure
+it for tracing a single thread.
+
+The system call returns a file descriptor on success, `-1` otherwise.
+
+~~~{.c}
+ int fd;
+
+ fd = syscall(SYS_perf_event_open, &attr, , -1, -1, 0);
+~~~
+
+
+The Intel PT trace is captured in the AUX area, which has been introduced with
+kernel 4.1. The DATA area contains sideband information such as image changes
+that are necessary for decoding the trace.
+
+In theory, both areas can be configured as circular buffers or as linear buffers
+by mapping them read-only or read-write, respectively. When configured as
+circular buffer, new data will overwrite older data. When configured as linear
+buffer, the user is expected to continuously read out the data and update the
+buffer's tail pointer. New data that do not fit into the buffer will be
+dropped.
+
+When using the AUX area, its size and offset have to be filled into the
+`perf_event_mmap_page`, which is mapped together with the DATA area. This
+requires the DATA area to be mapped read-write and hence configured as linear
+buffer. In our example, we configure the AUX area as circular buffer.
+
+Note that the size of both the AUX and the DATA area has to be a power of two
+pages. The DATA area needs one additional page to contain the
+`perf_event_mmap_page`.
+
+~~~{.c}
+ struct perf_event_mmap_page *header;
+ void *base, *data, *aux;
+
+ base = mmap(NULL, (1+2**n) * PAGE_SIZE, PROT_WRITE, MAP_SHARED, fd, 0);
+ if (base == MAP_FAILED)
+ return ();
+
+ header = base;
+ data = base + header->data_offset;
+
+ header->aux_offset = header->data_offset + header->data_size;
+ header->aux_size = (2**m) * PAGE_SIZE;
+
+ aux = mmap(NULL, header->aux_size, PROT_READ, MAP_SHARED, fd,
+ header->aux_offset);
+ if (aux == MAP_FAILED)
+ return ();
+~~~
+
+
+### Capturing Intel PT via the perf user-space tool
+
+Starting with kernel 4.3, the perf user-space tool can be used to capture Intel
+PT with the `intel_pt` event. See tools/perf/Documentation in the Linux kernel
+tree for further information. In this text, we describe how to use the captured
+trace with the ptdump and ptxed sample tools.
+
+We start with capturing some Intel PT trace using the `intel_pt` event. Note
+that when collecting system-wide (`-a`) trace, we need context switch events
+(`--switch-events`) to decode the trace. See `perf-record(1)` for details.
+
+~~~{.sh}
+ $ perf record -e intel_pt//[uk] [--per-thread] [-a --switch-events] -T -- ls
+ [ perf record: Woken up 1 times to write data ]
+ [ perf record: Captured and wrote 0.384 MB perf.data ]
+~~~
+
+
+This generates a file called `perf.data` that contains the Intel PT trace, the
+sideband information, and some metadata. To process the trace with ptxed, we
+extract the Intel PT trace into one file per thread or cpu.
+
+Looking at the raw trace dump of `perf script -D`, we notice
+`PERF_RECORD_AUXTRACE` records. The raw Intel PT trace is contained directly
+after such records. We can extract it with the `dd` command. The arguments to
+`dd` can be computed from the record's fields. This can be done automatically,
+for example with an AWK script.
+
+~~~{.awk}
+ /PERF_RECORD_AUXTRACE / {
+ offset = strtonum($1)
+ hsize = strtonum(substr($2, 2))
+ size = strtonum($5)
+ idx = strtonum($11)
+
+ ofile = sprintf("perf.data-aux-idx%d.bin", idx)
+ begin = offset + hsize
+
+ cmd = sprintf("dd if=perf.data of=%s conv=notrunc oflag=append ibs=1 \
+ skip=%d count=%d status=none", ofile, begin, size)
+
+ system(cmd)
+ }
+~~~
+
+The libipt tree contains such a script in `script/perf-read-aux.bash`.
+
+If we recorded in snapshot mode (perf record -S), we need to extract the Intel
+PT trace into one file per `PERF_RECORD_AUXTRACE` record. This can be done with
+an AWK script similar to the one above. Use `script/perf-read-aux.bash -S` when
+using the script from the libipt tree.
+
+
+In addition to the Intel PT trace, we need sideband information that describes
+process creation and termination, context switches, and memory image changes.
+This sideband information needs to be processed together with the trace. We
+therefore extract the sideband information from `perf.data`. This can again be
+done automatically with an AWK script:
+
+~~~{.awk}
+ function handle_record(ofile, offset, size) {
+ cmd = sprintf("dd if=%s of=%s conv=notrunc oflag=append ibs=1 skip=%d " \
+ "count=%d status=none", file, ofile, offset, size)
+
+ if (dry_run != 0) {
+ print cmd
+ }
+ else {
+ system(cmd)
+ }
+
+ next
+ }
+
+ function handle_global_record(offset, size) {
+ ofile = sprintf("%s-sideband.pevent", file)
+
+ handle_record(ofile, offset, size)
+ }
+
+ function handle_cpu_record(cpu, offset, size) {
+ # (uint32_t) -1 = 4294967295
+ #
+ if (cpu == -1 || cpu == 4294967295) {
+ handle_global_record(offset, size);
+ }
+ else {
+ ofile = sprintf("%s-sideband-cpu%d.pevent", file, cpu)
+
+ handle_record(ofile, offset, size)
+ }
+ }
+
+ /PERF_RECORD_AUXTRACE_INFO/ { next }
+ /PERF_RECORD_AUXTRACE/ { next }
+ /PERF_RECORD_FINISHED_ROUND/ { next }
+
+ /^[0-9]+ [0-9]+ 0x[0-9a-f]+ \[0x[0-9a-f]+\]: PERF_RECORD_/ {
+ cpu = strtonum($1)
+ begin = strtonum($3)
+ size = strtonum(substr($4, 2))
+
+ handle_cpu_record(cpu, begin, size)
+ }
+
+ /^[0-9]+ 0x[0-9a-f]+ \[0x[0-9a-f]+\]: PERF_RECORD_/ {
+ begin = strtonum($2)
+ size = strtonum(substr($3, 2))
+
+ handle_global_record(begin, size)
+ }
+
+ /^0x[0-9a-f]+ \[0x[0-9a-f]+\]: PERF_RECORD_/ {
+ begin = strtonum($1)
+ size = strtonum(substr($2, 2))
+
+ handle_global_record(begin, size)
+ }
+~~~
+
+The libipt tree contains such a script in `script/perf-read-sideband.bash`.
+
+
+In Linux, sideband is implemented as a sequence of perf_event records. Each
+record can optionally be followed by one or more samples that specify the cpu on
+which the record was created or a timestamp that specifies when the record was
+created. We use the timestamp sample to correlate sideband and trace.
+
+To process those samples, we need to know exactly what was sampled so that we
+can find the timestamp sample we are interested in. This information can be
+found in the `sample_type` field of `struct perf_event_attr`. We can extract
+this information from `perf.data` using the `perf evlist` command:
+
+~~~{.sh}
+ $ perf evlist -v
+ intel_pt//u: [...] sample_type: IP|TID|TIME|CPU|IDENTIFIER [...]
+ dummy:u: [...] sample_type: IP|TID|TIME|IDENTIFIER [...]
+~~~
+
+
+The command lists two items, one for the `intel_pt` perf_event counter and one
+for a `dummy` counter that is used for capturing context switch events.
+
+We translate the sample_type string using `PERF_EVENT_SAMPLE_*` enumeration
+constants defined in `/usr/include/linux/perf_event.h` into a single 64-bit
+integer constant. For example, `IP|TID|TIME|CPU|IDENTIFIER` translates into
+`0x10086`. Note that the `IP` sample type is reported but will not be attached
+to perf_event records. The resulting constant is then supplied as argument to
+the ptdump and ptxed option:
+
+ * --pevent:sample-type
+
+
+The translation can be done automatically using an AWK script, assuming that we
+already extracted the samle_type string:
+
+~~~{.awk}
+ BEGIN { RS = "[|\n]" }
+ /^TID$/ { config += 0x00002 }
+ /^TIME$/ { config += 0x00004 }
+ /^ID$/ { config += 0x00040 }
+ /^CPU$/ { config += 0x00080 }
+ /^STREAM$/ { config += 0x00200 }
+ /^IDENTIFIER$/ { config += 0x10000 }
+ END {
+ if (config != 0) {
+ printf(" --pevent:sample_type 0x%x", config)
+ }
+ }
+~~~
+
+
+Sideband and trace are time-correlated. Since Intel PT and perf use different
+time domains, we need a few parameters to translate between the two domains.
+The parameters can be found in `struct perf_event_mmap_page`, which is declared
+in `/usr/include/linux/perf_event.h`:
+
+ * time_shift
+ * time_mult
+ * time_zero
+
+The header also documents how to calculate TSC from perf_event timestamps.
+
+The ptdump and ptxed sample tools do this translation but we need to supply the
+parameters via corresponding options:
+
+ * --pevent:time-shift
+ * --pevent:time-mult
+ * --pevent:time-zero
+
+We can extract this information from the PERF_RECORD_AUXTRACE_INFO record. This
+is an artificial record that the perf tool synthesizes when capturing the trace.
+We can view it using the `perf script` command:
+
+~~~{.sh}
+ $ perf script --no-itrace -D | grep -A14 PERF_RECORD_AUXTRACE_INFO
+ 0x1a8 [0x88]: PERF_RECORD_AUXTRACE_INFO type: 1
+ PMU Type 6
+ Time Shift 10
+ Time Muliplier 642
+ Time Zero 18446744056970350213
+ Cap Time Zero 1
+ TSC bit 0x400
+ NoRETComp bit 0x800
+ Have sched_switch 0
+ Snapshot mode 0
+ Per-cpu maps 1
+ MTC bit 0x200
+ TSC:CTC numerator 0
+ TSC:CTC denominator 0
+ CYC bit 0x2
+~~~
+
+
+This will also give us the values for `cpuid[0x15].eax` and `cpuid[0x15].ebx`
+that we need for tracking time with `MTC` and `CYC` packets in `TSC:CTC
+denominator` and `TSC:CTC numerator` respectively. On processors that do not
+support `MTC` and `CYC`, the values are reported as zero.
+
+When decoding system-wide trace, we need to correlate context switch sideband
+events with decoded instructions from the trace to find a suitable location for
+switching the traced memory image for the scheduled-in process. The heuristics
+we use rely on sufficiently precise timing information. If timing information
+is too coarse, we might map the contex switch to the wrong location.
+
+When tracing ring-0, we use any code in kernel space. Since the kernel is
+mapped into every process, this is good enough as long as we are not interested
+in identifying processes and threads in the trace. To allow ptxed to
+distinguish kernel from user addresses, we provide the start address of the
+kernel via the option:
+
+ * --pevent:kernel-start
+
+
+We can find the address in `kallsyms` and we can extract it automatically using
+an AWK script:
+
+~~~{.awk}
+ function update_kernel_start(vaddr) {
+ if (vaddr < kernel_start) {
+ kernel_start = vaddr
+ }
+ }
+
+ BEGIN { kernel_start = 0xffffffffffffffff }
+ /^[0-9a-f]+ T _text$/ { update_kernel_start(strtonum("0x" $1)) }
+ /^[0-9a-f]+ T _stext$/ { update_kernel_start(strtonum("0x" $1)) }
+ END {
+ if (kernel_start < 0xffffffffffffffff) {
+ printf(" --pevent:kernel-start 0x%x", kernel_start)
+ }
+ }
+~~~
+
+
+When not tracing ring-0, we use a region where tracing has been disabled
+assuming that tracing is disabled due to a ring transition.
+
+
+To apply processor errata we need to know on which processor the trace was
+collected and provide this information to ptxed using the
+
+ * --cpu
+
+option. We can find this information in the `perf.data` header using the `perf
+script --header-only` command:
+
+~~~{.sh}
+ $ perf script --header-only | grep cpuid
+ # cpuid : GenuineIntel,6,61,4
+~~~
+
+
+The libipt tree contains a script in `script/perf-get-opts.bash` that computes
+all the perf_event related options from `perf.data` and from previously
+extracted sideband information.
+
+
+The kernel uses special filenames in `PERF_RECORD_MMAP` and `PERF_RECORD_MMAP2`
+records to indicate pseudo-files that can not be found directly on disk. One
+such special filename is
+
+ * [vdso]
+
+which corresponds to the virtual dynamic shared object that is mapped into every
+process. See `vdso(7)` for details. Depending on the installation there may be
+different vdso flavors. We need to specify the location of each flavor that is
+referenced in the trace via corresponding options:
+
+ * --pevent:vdso-x64
+ * --pevent:vdso-x32
+ * --pevent:vdso-ia32
+
+The perf tool installation may provide utilities called:
+
+ * perf-read-vdso32
+ * perf-read-vdsox32
+
+for reading the ia32 and the x32 vdso flavors. If the native flavor is not
+specified or the specified file does not exist, ptxed will copy its own vdso
+into a temporary file and use that. This may not work for remote decode, nor
+can ptxed provide other vdso flavors.
+
+
+Let's put it all together. Note that we use the `-m` option of
+`script/perf-get-opts.bash` to specify the master sideband file for the cpu on
+which we want to decode the trace. We further enable tick events for finer
+grain sideband correlation.
+
+~~~{.sh}
+ $ perf record -e intel_pt//u -T --switch-events -- grep -r foo /usr/include
+ [ perf record: Woken up 18 times to write data ]
+ [ perf record: Captured and wrote 30.240 MB perf.data ]
+ $ script/perf-read-aux.bash
+ $ script/perf-read-sideband.bash
+ $ ptdump $(script/perf-get-opts.bash) perf.data-aux-idx0.bin
+ [...]
+ $ ptxed $(script/perf-get-opts.bash -m perf.data-sideband-cpu0.pevent)
+ --pevent:vdso... --event:tick --pt perf.data-aux-idx0.bin
+ [...]
+~~~
+
+
+When tracing ring-0 code, we need to use `perf-with-kcore` for recording and
+supply the `perf.data` directory as additional argument after the `record` perf
+sub-command. When `perf-with-kcore` completes, the `perf.data` directory
+contains `perf.data` as well as a directory `kcore_dir` that contains copies of
+`/proc/kcore` and `/proc/kallsyms`. We need to supply the path to `kcore_dir`
+to `script/perf-get-opts.bash` using the `-k` option.
+
+~~~{.sh}
+ $ perf-with-kcore record dir -e intel_pt// -T -a --switch-events -- sleep 10
+ [ perf record: Woken up 26 times to write data ]
+ [ perf record: Captured and wrote 54.238 MB perf.data ]
+ Copying kcore
+ Done
+ $ cd dir
+ $ script/perf-read-aux.bash
+ $ script/perf-read-sideband.bash
+ $ ptdump $(script/perf-get-opts.bash) perf.data-aux-idx0.bin
+ [...]
+ $ ptxed $(script/perf-get-opts.bash -k kcore_dir
+ -m perf.data-sideband-cpu0.pevent)
+ --pevent:vdso... --event:tick --pt perf.data-aux-idx0.bin
+ [...]
+~~~
+
+
+#### Remote decode
+
+To decode the recorded trace on a different system, we copy all the files
+referenced in the trace to the system on which the trace is being decoded and
+point ptxed to the respective root directory using the option:
+
+ * --pevent:sysroot
+
+
+Ptxed will prepend the sysroot directory to every filename referenced in
+`PERF_RECORD_MMAP` and `PERF_RECORD_MMAP2` records.
+
+Note that like most configuration options, the `--pevent.sysroot` option needs
+to precede `--pevent:primary` and `-pevent:secondary` options.
+
+
+We can extract the referenced file names from `PERF_RECORD_MMAP` and
+`PERF_RECORD_MMAP2` records in the output of `perf script -D` and we can
+automatically copy the files using an AWK script:
+
+~~~{.awk}
+ function dirname(file) {
+ items = split(file, parts, "/", seps)
+
+ delete parts[items]
+
+ dname = ""
+ for (part in parts) {
+ dname = dname seps[part-1] parts[part]
+ }
+
+ return dname
+ }
+
+ function handle_mmap(file) {
+ # ignore any non-absolute filename
+ #
+ # this covers pseudo-files like [kallsyms] or [vdso]
+ #
+ if (substr(file, 0, 1) != "/") {
+ return
+ }
+
+ # ignore kernel modules
+ #
+ # we rely on kcore
+ #
+ if (match(file, /\.ko$/) != 0) {
+ return
+ }
+
+ # ignore //anon
+ #
+ if (file == "//anon") {
+ return
+ }
+
+ dst = outdir file
+ dir = dirname(dst)
+
+ system("mkdir -p " dir)
+ system("cp " file " " dst)
+ }
+
+ /PERF_RECORD_MMAP/ { handle_mmap($NF) }
+~~~
+
+The libipt tree contains such a script in `script/perf-copy-mapped-files.bash`.
+It will also read the vdso flavors for which the perf installation provides
+readers.
+
+We use the `-s` option of `script/perf-get-opts.bash` to have it generate
+options for the sysroot directory and for the vdso flavors found in that
+sysroot.
+
+For the remote decode case, we thus get (assuming kernel and user tracing on a
+64-bit system):
+
+~~~{.sh}
+ [record]
+ $ perf-with-kcore record dir -e intel_pt// -T -a --switch-events -- sleep 10
+ [ perf record: Woken up 26 times to write data ]
+ [ perf record: Captured and wrote 54.238 MB perf.data ]
+ Copying kcore
+ Done
+ $ cd dir
+ $ script/perf-copy-mapped-files.bash -o sysroot
+
+ [copy dir to remote system]
+
+ [decode]
+ $ script/perf-read-aux.bash
+ $ script/perf-read-sideband.bash
+ $ ptdump $(script/perf-get-opts.bash -s sysroot) perf.data-aux-idx0.bin
+ [...]
+ $ ptxed $(script/perf-get-opts.bash -s sysroot -k kcore_dir
+ -m perf.data-sideband-cpu0.pevent)
+ --event:tick --pt perf.data-aux-idx0.bin
+ [...]
+~~~
+
+
+#### Troubleshooting
+
+##### Sideband correlation and `no memory mapped at this address` errors
+
+If timing information in the trace is too coarse, we may end up applying
+sideband events too late. This typically results in `no memory mapped at this
+address` errors.
+
+Try to increase timing precision by increasing the MTC frequency or by enabling
+cycle-accurate tracing. If this does not help or is not an option, ptxed can
+process sideband events earlier than timing information indicates. Supply a
+suitable value to ptxed's option:
+
+ * --pevent:tsc-offset
+
+
+This option adds its argument to the timing information in the trace and so
+causes sideband events to be processed earlier. There is logic in ptxed to
+determine a suitable location in the trace for applying some sideband events.
+For example, a context switch event is postponed until tracing is disabled or
+enters the kernel.
+
+Those heuristics have their limits, of course. If the tsc offset is chosen too
+big, ptxed may end up mapping a sideband event to the wrong kernel entry.
+
+
+##### Sideband and trace losses leading to decode errors
+
+The perf tool reads trace and sideband while it is being collected and stores it
+in `perf.data`. If it fails to keep up, perf_event records or trace may be
+lost. The losses are indicated in the sideband:
+
+ * `PERF_RECORD_LOST` indicates sideband losses
+ * `PERF_RECORD_AUX.TRUNCATED` indicates trace losses
+
+
+Sideband losses may go unnoticed or may lead to decode errors. Typical errors
+are:
+
+ * `no memory mapped at this address`
+ * `decoder out of sync`
+ * `trace stream does not match query`
+
+
+Ptxed diagnoses sideband losses as warning both to stderr and to stdout
+interleaved with the normal output.
+
+Trace losses may go unnoticed or may lead to all kinds of errors. Ptxed
+diagnoses trace losses as warning to stderr.
+
+
+### Capturing Intel PT via Simple-PT
+
+The Simple-PT project on github supports capturing Intel PT on Linux with an
+alternative kernel driver. The spt decoder supports sideband information.
+
+See the project's page at https://github.com/andikleen/simple-pt for more
+information including examples.
diff --git a/doc/howto_libipt.md b/doc/howto_libipt.md
new file mode 100644
index 0000000000000..1b3f2ab1555d9
--- /dev/null
+++ b/doc/howto_libipt.md
@@ -0,0 +1,1271 @@
+Decoding Intel(R) Processor Trace Using libipt {#libipt}
+========================================================
+
+
+
+This chapter describes how to use libipt for various tasks around Intel
+Processor Trace (Intel PT). For code examples, refer to the sample tools that
+are contained in the source tree:
+
+ * *ptdump* A packet dumper example.
+ * *ptxed* A control-flow reconstruction example.
+ * *pttc* A packet encoder example.
+
+
+For detailed information about Intel PT, please refer to the respective chapter
+in Volume 3 of the Intel Software Developer's Manual at
+http://www.intel.com/sdm.
+
+
+## Introduction
+
+The libipt decoder library provides multiple layers of abstraction ranging from
+packet encoding and decoding to full execution flow reconstruction. The layers
+are organized as follows:
+
+ * *packets* This layer deals with raw Intel PT packets.
+
+ * *events* This layer deals with packet combinations that
+ encode higher-level events.
+
+ * *instruction flow* This layer deals with the execution flow on the
+ instruction level.
+
+ * *block* This layer deals with the execution flow on the
+ instruction level.
+
+ It is faster than the instruction flow decoder but
+ requires a small amount of post-processing.
+
+
+Each layer provides its own encoder or decoder struct plus a set of functions
+for allocating and freeing encoder or decoder objects and for synchronizing
+decoders onto the Intel PT packet stream. Function names are prefixed with
+`pt__` where `` is an abbreviation of the layer name. The following
+abbreviations are used:
+
+ * *enc* Packet encoding (packet layer).
+ * *pkt* Packet decoding (packet layer).
+ * *qry* Event (or query) layer.
+ * *insn* Instruction flow layer.
+ * *blk* Block layer.
+
+
+Here is some generic example code for working with decoders:
+
+~~~{.c}
+ struct pt__decoder *decoder;
+ struct pt_config config;
+ int errcode;
+
+ memset(&config, 0, sizeof(config));
+ config.size = sizeof(config);
+ config.begin = ;
+ config.end = ;
+ config.cpu = ;
+ config...
+
+ decoder = pt__alloc_decoder(&config);
+ if (!decoder)
+ (errcode);
+
+ errcode = pt__sync_(decoder);
+ if (errcode < 0)
+ (errcode);
+
+