Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#5912: Add caching and clean up PC discontinuity checks #5965

Merged
Merged
Show file tree
Hide file tree
Changes from 205 commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
5033cdc
Initial comments.
lihasgupta Apr 6, 2023
73fa31f
Test case to replicate issue.
lihasgupta Apr 7, 2023
9616088
Remove TODO.
lihasgupta Apr 7, 2023
9b81419
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 7, 2023
31d6e75
Fixed error_ref value in test case.
lihasgupta Apr 7, 2023
03e30fa
Broke up condition statement for debugging purposes.
lihasgupta Apr 7, 2023
be7ff44
Fix typo.
lihasgupta Apr 7, 2023
43f061a
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 10, 2023
4561b64
Fix typo in test error message.
lihasgupta Apr 10, 2023
56d04a8
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 10, 2023
7afbdb3
Add PC discontinuity check for tests.
lihasgupta Apr 11, 2023
3120610
WIP
lihasgupta Apr 11, 2023
6420102
Remove incorrect OR logic.
lihasgupta Apr 11, 2023
89b342a
Added invariant checking logic but broke other tests.
lihasgupta Apr 12, 2023
fb4a9c9
Revert "Added invariant checking logic but broke other tests."
lihasgupta Apr 13, 2023
d939467
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 13, 2023
64aaccd
Positive passing test case.
lihasgupta Apr 13, 2023
8876205
Revert separate condition logic.
lihasgupta Apr 13, 2023
83b7ee7
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 13, 2023
314c016
Added separate condition back in.
lihasgupta Apr 13, 2023
c802e22
Remove unused header.
lihasgupta Apr 14, 2023
fa3a073
Debugging print statements.
lihasgupta Apr 14, 2023
87e15fd
WIP
lihasgupta Apr 14, 2023
f5be683
Shifting print down a layer.
lihasgupta Apr 14, 2023
ce42f5e
Debugging for marker value.
lihasgupta Apr 14, 2023
64627d9
Moved signal transfer PC checking block.
lihasgupta Apr 14, 2023
0659825
Added debug statements in correct block.
lihasgupta Apr 14, 2023
03b4444
WIP
lihasgupta Apr 14, 2023
f0421c3
Compare current marker to prev instruction PC.
lihasgupta Apr 14, 2023
012d9f8
Added boilerplate for PC discontinuity check.
lihasgupta Apr 14, 2023
ddc9efe
Using previous instruction address for comparison.
lihasgupta Apr 15, 2023
f98c4bb
Attempt to run discontinuity at signal transfer event.
lihasgupta Apr 15, 2023
73bfe02
Remove debug print statement.
lihasgupta Apr 15, 2023
767757d
Cleanup.
lihasgupta Apr 15, 2023
7763aae
Added check in the correct logic block.
lihasgupta Apr 15, 2023
90425b1
WIP.
lihasgupta Apr 15, 2023
d4e142f
Getting marker value for PC discontinuity function.
lihasgupta Apr 15, 2023
19f9781
Create current_memref_addr variable to consider both instr and markers.
lihasgupta Apr 15, 2023
089d9bb
Cleanup.
lihasgupta Apr 16, 2023
a73da74
Commented out call to PC discontinuity function.
lihasgupta Apr 16, 2023
e3b9e64
Inserted logic but test is failing.
lihasgupta Apr 16, 2023
b467918
Added comment on failing test.
lihasgupta Apr 16, 2023
3e4f5d1
Commented out failing tests.
lihasgupta Apr 16, 2023
959c731
Remove unused variable.
lihasgupta Apr 17, 2023
244158c
Clean up redundant logic.
lihasgupta Apr 17, 2023
ce23da6
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 17, 2023
64b5dcd
Hacky fix to account for RSEQ aborts.
lihasgupta Apr 17, 2023
300c4ff
Logic that excludes rseq aborts. Tests passing now.
lihasgupta Apr 17, 2023
9cb09ff
Make comment clearer.
lihasgupta Apr 17, 2023
dcaf906
Remove comment.
lihasgupta Apr 17, 2023
5e3001c
Fix comment.
lihasgupta Apr 19, 2023
580d78c
Comment out sigabort for debugging purposes.
lihasgupta Apr 19, 2023
f1c8baa
Debug comment.
lihasgupta Apr 20, 2023
ed2278d
Cleanup.
lihasgupta Apr 20, 2023
bbc7f0e
Fix same PC bug.
lihasgupta Apr 20, 2023
9033d96
Remove unnecessary comment.
lihasgupta Apr 20, 2023
b6b90f7
Cleanup.
lihasgupta Apr 20, 2023
7cf40ec
Uncomment abort.
lihasgupta Apr 20, 2023
59f0636
Removed merge conflict.
lihasgupta Apr 20, 2023
8ac8cd4
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 20, 2023
5be0a46
Const correctness.
lihasgupta Apr 20, 2023
680c220
Temporarily check for online.
lihasgupta Apr 20, 2023
68060e5
Exclude "kernel_xfer_app" for online runs.
lihasgupta Apr 20, 2023
6df767d
Added positive and negative test cases.
lihasgupta Apr 20, 2023
6884923
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 21, 2023
f5c1305
Moved check to later in file.
lihasgupta Apr 21, 2023
95cf886
Remove unnecessary white-space.
lihasgupta Apr 21, 2023
de0e2cf
Updated order and comment on tests.
lihasgupta Apr 21, 2023
9623bb7
Remove nested OR's.
lihasgupta Apr 21, 2023
5607066
Undo change to get rid of merge conflict.
lihasgupta Apr 21, 2023
72ae027
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 21, 2023
c4a21c7
Fix typo in comment.
lihasgupta Apr 21, 2023
7c30823
Add check inside ifdef.
lihasgupta Apr 21, 2023
7a34ea7
Moved logic block into existing if-statement.
lihasgupta Apr 21, 2023
66aaca3
Added unique error message for marker discontinuity.
lihasgupta Apr 21, 2023
d5d7c5e
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Apr 25, 2023
c7f038d
Fixed typo in comment.
lihasgupta May 7, 2023
4759db7
Fix comment to follow convention.
lihasgupta May 7, 2023
e894120
Fixed incorrect comparison logic.
lihasgupta May 7, 2023
beb514b
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta May 7, 2023
847ed8c
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta May 8, 2023
cfd724e
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta May 8, 2023
1d107af
Added TODO.
lihasgupta May 8, 2023
3a56e85
Reverted prev_instr_trace_pc logic.
lihasgupta May 8, 2023
546b64a
Add ifdefs to make check work on Windows.
lihasgupta May 8, 2023
d3b3d74
Added error message suffix logic.
lihasgupta May 8, 2023
bffd0b9
Compare the correct address and size for signals.
lihasgupta May 8, 2023
881c7bd
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta May 10, 2023
b1f832a
Simplify marker check logic.
lihasgupta May 10, 2023
cb7c3a8
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta May 10, 2023
4b1f3dd
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Jun 27, 2023
2c4e29a
WIP
lihasgupta Jun 27, 2023
9d99d10
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Jun 28, 2023
a3ebb73
Take last_instr_in_cur_context_ as prev_instr.
lihasgupta Jul 10, 2023
716846a
const correctness.
lihasgupta Jul 10, 2023
99e552e
Separate string_flow from branch flow logic.
lihasgupta Jul 10, 2023
2382fa3
Added simple sanity test.
lihasgupta Jul 10, 2023
0b4fdb2
Test for pre-signal instr continuing after signal.
lihasgupta Jul 10, 2023
419c867
clang-format.
lihasgupta Jul 10, 2023
6ed0cfd
Added testing for when prev instr is TRACE_TYPE_INSTR_SYSENTER.
lihasgupta Jul 10, 2023
a4bc07f
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Jul 11, 2023
c55105c
Added logic into ifdef for windows compatibility.
lihasgupta Jul 11, 2023
30928d5
Test for no instruction before kernel event.
lihasgupta Jul 11, 2023
ed1eb60
clang-format.
lihasgupta Jul 11, 2023
c626ed3
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Jul 13, 2023
b86692f
Added RSEQ abort and branch test cases.
lihasgupta Jul 18, 2023
91a2380
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Jul 18, 2023
9f58c73
PR feedback, remove current_memref_addr variable.
lihasgupta Jul 18, 2023
6f4b4df
PR feedback. Added markers to sysenter test.
lihasgupta Jul 19, 2023
65967e2
PR feedback. Updated comment.
lihasgupta Jul 19, 2023
af4a76d
PR feedback. Remove unnecessary instr's from tests.
lihasgupta Jul 19, 2023
463bc09
PR feedback. Comment explaining when we use marker value.
lihasgupta Jul 19, 2023
a6fdce3
PR feedback. Explain skipped logic in comment.
lihasgupta Jul 19, 2023
aebf929
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Jul 21, 2023
d20d84d
PR feedback. Reverted logic to use shard->prev_instr_.
lihasgupta Jul 21, 2023
c6f852e
Check for memref marker in instr logic.
lihasgupta Jul 21, 2023
8fd4e26
WIP.
lihasgupta Jul 26, 2023
3d90a71
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 3, 2023
39022dd
Fix broken test.
lihasgupta Aug 3, 2023
7f5e645
Check if this compiles on windows.
lihasgupta Aug 3, 2023
eb8bc43
Fixed windows compilation.
lihasgupta Aug 3, 2023
9012e87
Fix signal xfer bugs.
lihasgupta Aug 6, 2023
96ac180
Fixed all tests.
lihasgupta Aug 7, 2023
41073fc
Used TID variable.
lihasgupta Aug 7, 2023
a0c0a59
Remove TODO.
lihasgupta Aug 7, 2023
487511a
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 7, 2023
d54c9c3
Fixed ifdef logic.
lihasgupta Aug 7, 2023
734c782
PR feedback. ifdef else
lihasgupta Aug 7, 2023
b261ac8
Fixed positive/negative terminology.
lihasgupta Aug 7, 2023
1529fbc
Shortened error message.
lihasgupta Aug 7, 2023
c77ac0c
Updated error message.
lihasgupta Aug 7, 2023
5a9fdc9
PR comment. Explain last_instr_in_cur_context_
lihasgupta Aug 7, 2023
95c27d2
Remove ifdef logic since it is being set by the caller.
lihasgupta Aug 7, 2023
b0f897e
Initial refactor to last instruction decoded.
lihasgupta Aug 12, 2023
7ba7d9d
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 15, 2023
dea0aac
Fixed merge conflict.
lihasgupta Aug 15, 2023
029e4ca
Removed TODO.
lihasgupta Aug 15, 2023
a8f6bae
Fix windows build issue.
lihasgupta Aug 15, 2023
ef26c05
Rename variable.
lihasgupta Aug 15, 2023
37807df
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 16, 2023
6decb33
PR feedback. Remove branch_target_cache.
lihasgupta Aug 16, 2023
99bde65
Remove TODO comment.
lihasgupta Aug 16, 2023
9e598a2
Refactor with decoding related attributes.
lihasgupta Aug 17, 2023
684a67e
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 17, 2023
6efded0
Convert shared_ptr to unique_ptr.
lihasgupta Aug 17, 2023
aa05a6d
Change to unique_ptr.
lihasgupta Aug 17, 2023
3a34d57
Minor fixes.
lihasgupta Aug 17, 2023
e8eabc0
Remove TODO.
lihasgupta Aug 17, 2023
4e52270
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 17, 2023
b06437a
Added logic back into failing test.
lihasgupta Aug 17, 2023
3b7a045
PR feedback. has_valid_decoding field.
lihasgupta Aug 18, 2023
4f8294c
PR feedback. Change field name to memref.
lihasgupta Aug 18, 2023
27a6152
Added the sysenter logic back into check.
lihasgupta Aug 19, 2023
6268921
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 19, 2023
f15a42d
PR feedback. Use instr_info_t for cur_instr.
lihasgupta Aug 21, 2023
ca9e718
Added cache for decode_from_copy.
lihasgupta Aug 21, 2023
18e9ac9
Use the trace PC as key for cache.
lihasgupta Aug 22, 2023
02c67e4
Moved decode_cache into per_shard.
lihasgupta Aug 22, 2023
d0aae0a
Create variable for trace_pc.
lihasgupta Aug 23, 2023
a8d1888
Working cache.
lihasgupta Aug 23, 2023
1878364
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 24, 2023
c62ab5a
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 28, 2023
21d28cc
PR feedback. Make branch_target an addr_t.
lihasgupta Aug 28, 2023
af91153
Add opnd_is_pc check.
lihasgupta Aug 28, 2023
504cd9a
PR feedback. Add comment.
lihasgupta Aug 29, 2023
5ca0cf2
PR feedback. Also reset has_valid_decoding field.
lihasgupta Aug 29, 2023
0bd46b2
PR feedback. Add instr_info_t into signal context.
lihasgupta Aug 29, 2023
e9d8a91
Added tests for branching with signal handler.
lihasgupta Aug 31, 2023
1581a34
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Aug 31, 2023
3ee794e
Only cache decoding-related attributes.
lihasgupta Aug 31, 2023
706d9df
Fix typo in comment.
lihasgupta Aug 31, 2023
adac4a0
Refactor. Get rid of prev_instr_.
lihasgupta Aug 31, 2023
955bbfa
Revert "Refactor. Get rid of prev_instr_."
lihasgupta Aug 31, 2023
d2c1147
Comment out test that is failing on windows.
lihasgupta Sep 1, 2023
de48111
Add in commented out test.
lihasgupta Sep 1, 2023
77bfbb0
Move prev_prev_entry_ out of ifdef UNIX block.
lihasgupta Sep 12, 2023
f3f7188
Fix typo.
lihasgupta Sep 12, 2023
32e544a
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Sep 12, 2023
44e704d
Fixed issues caused by merge conflict.
lihasgupta Sep 13, 2023
cf448f9
Fix windows compilation issue.
lihasgupta Sep 13, 2023
6e48c01
Added dr_standalone_init().
lihasgupta Sep 13, 2023
0617707
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Sep 13, 2023
618344a
Fixed merge conflicts and update CMakeLists.txt to add standalone inv…
lihasgupta Sep 14, 2023
3a39468
Resolve TODO.
lihasgupta Sep 14, 2023
80a0662
Make histogram_launcher standalone also.
lihasgupta Sep 15, 2023
efc1528
Flatten nested if statements.
lihasgupta Sep 15, 2023
22d9cbe
Empty-Commit
lihasgupta Sep 15, 2023
36b2564
Remove pre_signal_flow_continuity.
lihasgupta Sep 20, 2023
3f01a6c
PR feedback. Comment above prev_instr_.
lihasgupta Sep 20, 2023
cae897a
PR feedback. Remove stale comment.
lihasgupta Sep 20, 2023
dc3c3c7
PR feedback. Add parameter comments.
lihasgupta Sep 20, 2023
34f2112
PR feedback. Update comment.
lihasgupta Sep 20, 2023
8d80f1d
PR feedback. Added WILL_BE_REPLACED constant.
lihasgupta Sep 20, 2023
696999f
PR feedback. Move encoding logic after syscall test.
lihasgupta Sep 20, 2023
1908cbe
PR feedback. Use trace_pc variable.
lihasgupta Sep 20, 2023
e1c348d
PR feedback. Remove unnecessary if statement.
lihasgupta Sep 20, 2023
5bd7105
PR feedback. Add default constructors.
lihasgupta Sep 20, 2023
fff38fe
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Sep 20, 2023
1694b68
PR feedback. Add comment explaining cur_instr_info when at kernel xfer.
lihasgupta Sep 20, 2023
4546cea
PR feedback. Rename cur_instr_info parameter.
lihasgupta Sep 20, 2023
f25fcd3
PR feedback. Added TODO comment for missing check.
lihasgupta Sep 20, 2023
49bff98
PR feedback.
lihasgupta Sep 22, 2023
3c7e17f
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Sep 22, 2023
617aa7f
PR feedback. Updated comment.
lihasgupta Sep 22, 2023
7fb600a
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Sep 22, 2023
4f3bb2c
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Sep 23, 2023
c2c19d0
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Sep 23, 2023
f6cad67
Merge branch 'master' into i5912-incorrect-invariant-pc-discontinuity…
lihasgupta Sep 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ target_link_libraries(drmemtrace_invariant_checker drdecode)

lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
configure_DynamoRIO_standalone(drmemtrace_opcode_mix)
lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
configure_DynamoRIO_standalone(drmemtrace_view)
configure_DynamoRIO_standalone(drmemtrace_invariant_checker)

# We combine the cache and TLB simulators as they share code already.
add_exported_library(drmemtrace_simulator STATIC
Expand Down Expand Up @@ -342,6 +343,7 @@ add_library(test_helpers STATIC tests/test_helpers.cpp)
add_executable(histogram_launcher
tools/histogram_launcher.cpp
)
configure_DynamoRIO_standalone(histogram_launcher)
target_link_libraries(histogram_launcher drmemtrace_analyzer drmemtrace_histogram
drfrontendlib drmemtrace_invariant_checker)
use_DynamoRIO_extension(histogram_launcher droption)
Expand Down
259 changes: 236 additions & 23 deletions clients/drcachesim/tests/invariant_checker_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ bool
check_branch_target_after_branch()
lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
{
std::cerr << "Testing branch targets\n";
// Positive simple test.
// Correct simple test.
{
std::vector<memref_t> memrefs = {
gen_instr(1, 1), gen_branch(1, 2),
Expand All @@ -186,7 +186,7 @@ check_branch_target_after_branch()
if (!run_checker(memrefs, false))
return false;
}
// Negative simple test.
// Incorrect simple test.
{
constexpr uintptr_t TIMESTAMP = 3;
constexpr memref_tid_t TID = 1;
Expand Down Expand Up @@ -230,7 +230,7 @@ check_sane_control_flow()
{
std::cerr << "Testing control flow\n";
constexpr memref_tid_t TID = 1;
// Negative simple test.
// Incorrect simple test.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, 1),
Expand All @@ -243,7 +243,7 @@ check_sane_control_flow()
"Failed to catch bad control flow"))
return false;
}
// Negative test with timestamp markers.
// Incorrect test with timestamp markers.
{
std::vector<memref_t> memrefs = {
gen_marker(TID, TRACE_MARKER_TYPE_TIMESTAMP, 2),
Expand All @@ -259,7 +259,7 @@ check_sane_control_flow()
return false;
}
}
// Positive test: branches with no encodings.
// Correct test: branches with no encodings.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, 1), gen_branch(TID, 2), gen_instr(TID, 3), // Not taken.
Expand All @@ -275,7 +275,7 @@ check_sane_control_flow()
// XXX: We hardcode encodings here. If we need many more we should generate them
// from DR IR.

// Negative test: branches with encodings which do not go to their targets.
// Incorrect test: branches with encodings which do not go to their targets.
{
instr_t *move1 = XINST_CREATE_move(GLOBAL_DCONTEXT, opnd_create_reg(REG1),
opnd_create_reg(REG2));
Expand Down Expand Up @@ -306,7 +306,7 @@ check_sane_control_flow()
return false;
}
}
// Positive test: branches with encodings which go to their targets.
// Correct test: branches with encodings which go to their targets.
{
instr_t *move1 = XINST_CREATE_move(GLOBAL_DCONTEXT, opnd_create_reg(REG1),
opnd_create_reg(REG2));
Expand Down Expand Up @@ -348,13 +348,222 @@ check_sane_control_flow()
// Kernel-mediated.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, 1),
gen_instr(TID, /*pc=*/1, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 2),
gen_instr(TID, 101),
gen_instr(TID, /*pc=*/101, /*size=*/1),
};
if (!run_checker(memrefs, false))
return false;
}
lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
#ifdef UNIX
// Incorrect test (PC discontinuity): Transition from instr to kernel_xfer event
// marker.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, /*pc=*/1, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 3),
};
if (!run_checker(
memrefs, true,
{ "Non-explicit control flow has no marker @ kernel_event marker", TID,
/*ref_ordinal=*/2, /*last_timestamp=*/0,
/*instrs_since_last_timestamp=*/1 },
"Failed to catch PC discontinuity for an instruction followed by "
"kernel xfer marker")) {
return false;
}
}
// Correct test: Transition from instr to kernel_xfer event marker, goes to the next
// instruction.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, /*pc=*/1, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 2),
gen_instr(TID, /*pc=*/101, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_XFER, 102),
gen_instr(TID, /*pc=*/2, /*size=*/1),
};
if (!run_checker(memrefs, false)) {
return false;
}
}
// Correct test: We should skip the check if there is no instruction before the
// kernel event.
{
std::vector<memref_t> memrefs = {
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 3),
};
if (!run_checker(memrefs, false)) {
return false;
}
}
// Correct test: Pre-signal instr continues after signal.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, /*pc=*/2, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 2),
gen_instr(TID, /*pc=*/101, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_XFER, 102),
gen_instr(TID, /*pc=*/2, /*size=*/1),
};
if (!run_checker(memrefs, false)) {
return false;
}
}
// Correct test: We should not report a PC discontinuity when the previous instr is
// of type TRACE_TYPE_INSTR_SYSENTER.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, /*pc=*/5, /*size=*/1),
gen_instr_type(TRACE_TYPE_INSTR_SYSENTER, TID, /*pc=*/6, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_TIMESTAMP, 2),
gen_marker(TID, TRACE_MARKER_TYPE_CPU_ID, 3),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 2),
gen_instr(TID, /*pc=*/101, /*size=*/1),
};
if (!run_checker(memrefs, false)) {
return false;
}
}
// Correct test: RSEQ abort in last signal context.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, /*pc=*/1, /*size=*/1),
// The RSEQ_ABORT marker is always follwed by a KERNEL_EVENT marker.
gen_marker(TID, TRACE_MARKER_TYPE_RSEQ_ABORT, 40),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 40),
// We get a signal after the RSEQ abort.
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 4),
};
if (!run_checker(memrefs, false)) {
return false;
}
}
lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
// Correct test: Branch before signal. This is correct only because the branch doesn't
// have an encoding with it. This case will only occur in legacy or stripped traces.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, /*pc=*/1, /*size=*/1),
gen_branch(TID, 2),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 50),
};
if (!run_checker(memrefs, false)) {
return false;
}
}
// Correct test: back-to-back signals without any intervening instruction.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, /*pc=*/101, /*size=*/1),
// First signal.
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 102),
gen_instr(TID, /*pc=*/201, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_XFER, 202),
// Second signal.
// The Marker value for this signal needs to be 102.
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 102),
gen_instr(TID, /*pc=*/201, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_XFER, 202),
gen_instr(TID, /*pc=*/102, /*size=*/1),
};
if (!run_checker(memrefs, false)) {
return false;
}
}
// Incorrect test: back-to-back signals without any intervening instruction.
{
std::vector<memref_t> memrefs = {
gen_instr(TID, /*pc=*/101, /*size=*/1),
// First signal.
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 102),
gen_instr(TID, /*pc=*/201, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_XFER, 202),
// Second signal.
// There will be a PC discontinuity here since the marker value is 500, and
// the previous PC is 101.
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 500),
gen_instr(TID, /*pc=*/201, /*size=*/1),
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_XFER, 202),
};
if (!run_checker(
memrefs, true,
{ "Non-explicit control flow has no marker @ kernel_event marker", TID,
/*ref_ordinal=*/5, /*last_timestamp=*/0,
/*instrs_since_last_timestamp=*/2 },
"Failed to catch PC discontinuity for back-to-back signals without any "
"intervening instruction")) {
return false;
}
}
// Correct test: Taken branch with signal in between branch and its target.
{
instr_t *move = XINST_CREATE_move(GLOBAL_DCONTEXT, opnd_create_reg(REG1),
opnd_create_reg(REG2));
instr_t *cbr_to_move =
XINST_CREATE_jump_cond(GLOBAL_DCONTEXT, DR_PRED_EQ, opnd_create_instr(move));
instr_t *nop = XINST_CREATE_nop(GLOBAL_DCONTEXT);
instrlist_t *ilist = instrlist_create(GLOBAL_DCONTEXT);
instrlist_append(ilist, cbr_to_move);
instrlist_append(ilist, nop);
instrlist_append(ilist, move);
static constexpr addr_t BASE_ADDR = 0x123450;
static constexpr uintptr_t WILL_BE_REPLACED = 0;
std::vector<memref_with_IR_t> memref_setup = {
{ gen_marker(TID, TRACE_MARKER_TYPE_VERSION, TRACE_ENTRY_VERSION_BRANCH_INFO),
nullptr },
{ gen_marker(TID, TRACE_MARKER_TYPE_FILETYPE, OFFLINE_FILE_TYPE_ENCODINGS),
nullptr },
{ gen_instr_type(TRACE_TYPE_INSTR_TAKEN_JUMP, TID), cbr_to_move },
{ gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, WILL_BE_REPLACED), move },
/* TODO i#6316: The nop PC is incorrect. We need to add a check for equality
beteen the KERNEL_XFER marker and the prev instr fall-through. */
{ gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_XFER, WILL_BE_REPLACED), nop },
{ gen_instr(TID), move },
};
std::vector<memref_t> memrefs =
add_encodings_to_memrefs(ilist, memref_setup, BASE_ADDR);
instrlist_clear_and_destroy(GLOBAL_DCONTEXT, ilist);
if (!run_checker(memrefs, false)) {
return false;
}
}
// Incorrect test: Taken branch with signal in between branch and its target. Return
// to the wrong place after the signal.
{
instr_t *move = XINST_CREATE_move(GLOBAL_DCONTEXT, opnd_create_reg(REG1),
opnd_create_reg(REG2));
instr_t *cbr_to_move =
XINST_CREATE_jump_cond(GLOBAL_DCONTEXT, DR_PRED_EQ, opnd_create_instr(move));
instr_t *nop = XINST_CREATE_nop(GLOBAL_DCONTEXT);
instrlist_t *ilist = instrlist_create(GLOBAL_DCONTEXT);
instrlist_append(ilist, cbr_to_move);
instrlist_append(ilist, nop);
instrlist_append(ilist, move);
static constexpr addr_t BASE_ADDR = 0x123450;
static constexpr uintptr_t WILL_BE_REPLACED = 0;
std::vector<memref_with_IR_t> memref_setup = {
{ gen_marker(TID, TRACE_MARKER_TYPE_VERSION, TRACE_ENTRY_VERSION_BRANCH_INFO),
nullptr },
{ gen_marker(TID, TRACE_MARKER_TYPE_FILETYPE, OFFLINE_FILE_TYPE_ENCODINGS),
nullptr },
{ gen_instr_type(TRACE_TYPE_INSTR_TAKEN_JUMP, TID), cbr_to_move },
{ gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, WILL_BE_REPLACED), move },
{ gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_XFER, WILL_BE_REPLACED), nop },
{ gen_instr(TID), nop },
};
std::vector<memref_t> memrefs =
add_encodings_to_memrefs(ilist, memref_setup, BASE_ADDR);
instrlist_clear_and_destroy(GLOBAL_DCONTEXT, ilist);
if (!run_checker(memrefs, true,
{ "Signal handler return point incorrect", TID,
/*ref_ordinal=*/6, /*last_timestamp=*/0,
/*instrs_since_last_timestamp=*/2 },
"Failed to catch bad signal handler return")) {
return false;
}
}

lihasgupta marked this conversation as resolved.
Show resolved Hide resolved
#endif
return true;
}

Expand Down Expand Up @@ -1107,7 +1316,7 @@ bool
check_duplicate_syscall_with_same_pc()
{
std::cerr << "Testing duplicate syscall\n";
// Negative: syscalls with the same PC.
// Incorrect: syscalls with the same PC.
#if defined(X86_64) || defined(X86_32) || defined(ARM_64)
constexpr addr_t ADDR = 0x7fcf3b9d;
{
Expand Down Expand Up @@ -1137,7 +1346,7 @@ check_duplicate_syscall_with_same_pc()
return false;
}

// Positive test: syscalls with different PCs.
// Correct: syscalls with different PCs.
{
std::vector<memref_t> memrefs = {
gen_marker(1, TRACE_MARKER_TYPE_FILETYPE, OFFLINE_FILE_TYPE_ENCODINGS),
Expand Down Expand Up @@ -1345,7 +1554,7 @@ bool
check_rseq_side_exit_discontinuity()
{
std::cerr << "Testing rseq side exits\n";
// Negative test: Seemingly missing instructions in a basic block due to rseq side
// Incorrect test: Seemingly missing instructions in a basic block due to rseq side
// exit.
instr_t *store = XINST_CREATE_store(GLOBAL_DCONTEXT, OPND_CREATE_MEMPTR(REG2, 0),
opnd_create_reg(REG1));
Expand Down Expand Up @@ -1596,12 +1805,14 @@ check_branch_decoration()
gen_marker(TID, TRACE_MARKER_TYPE_KERNEL_EVENT, 999),
gen_instr(TID, /*pc=*/32),
};
if (!run_checker(memrefs, true,
{ "Branch does not go to the correct target", TID,
/*ref_ordinal=*/4, /*last_timestamp=*/0,
/*instrs_since_last_timestamp=*/2 },
"Failed to catch bad indirect branch target field"))
if (!run_checker(
memrefs, true,
{ "Branch does not go to the correct target @ kernel_event marker", TID,
/*ref_ordinal=*/4, /*last_timestamp=*/0,
/*instrs_since_last_timestamp=*/2 },
"Failed to catch bad indirect branch target field")) {
return false;
}
}
#endif
// Deprecated branch type.
Expand Down Expand Up @@ -1725,11 +1936,13 @@ check_branch_decoration()
};
auto memrefs = add_encodings_to_memrefs(ilist, memref_setup, BASE_ADDR);
instrlist_clear_and_destroy(GLOBAL_DCONTEXT, ilist);
if (!run_checker(memrefs, true,
{ "Branch does not go to the correct target", /*tid=*/1,
/*ref_ordinal=*/4, /*last_timestamp=*/0,
/*instrs_since_last_timestamp=*/1 },
"Failed to catch taken branch falling through to signal"))
if (!run_checker(
memrefs, true,
{ "Branch does not go to the correct target @ kernel_event marker",
/*tid=*/1,
/*ref_ordinal=*/4, /*last_timestamp=*/0,
/*instrs_since_last_timestamp=*/1 },
"Failed to catch taken branch falling through to signal"))
return false;
}
#endif
Expand Down Expand Up @@ -1841,7 +2054,7 @@ check_branch_decoration()
instrlist_clear_and_destroy(GLOBAL_DCONTEXT, ilist);
if (!run_checker(
memrefs, true,
{ "Branch does not go to the correct target", TID,
{ "Branch does not go to the correct target @ kernel_event marker", TID,
/*ref_ordinal=*/4, /*last_timestamp=*/0,
/*instrs_since_last_timestamp=*/1 },
"Failed to catch untaken branch going to taken target at signal"))
Expand Down
Loading