-
Notifications
You must be signed in to change notification settings - Fork 571
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#2511: isolate raw2trace #2512
Conversation
Splits out a self-contained library, which: - only takes already opened std::istream and std::ostream-compatible files and doesn't own them, so it can be used with more exotic filesystems; - takes in the contents of the module file to avoid doing IO from drmodtrack_offline_read(); - returns errors on failure; - doesn't depend on dr_frontend. Preserves the current behavior with raw2trace_helper_t, which walks directories and opens files. TESTED: ctest (failures failed before this commit as well) Fixes DynamoRIO#2511
AppVeyor seems to fail on installing doxygen. I don't have a Windows box handy, if you give me credentials on one, I can take a look. |
This doxygen install issue appeared a few days ago out of the blue, I was hoping it was some transient failure that would just go away (initially it surfaced as more of a network not-found error) but it doesn't seem to be the case. |
I think choco might got upgraded and the new default now is to not allow empty checksums by default. Ideally, the doxygen package would come with a proper checksum, but for now, installing it with |
The appveyor builds should be fixed now, I've used the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly minor style issues
clients/drcachesim/CMakeLists.txt
Outdated
@@ -89,6 +89,7 @@ add_executable(drcachesim | |||
simulator/analyzer_interface.cpp | |||
# We embed the raw2trace conversion for convenience: | |||
tracer/raw2trace.cpp | |||
tracer/raw2trace_helper.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about "directory" or "dir_iter" instead of "helper"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Yup, it's a much better name.
void | ||
raw2trace_t::read_and_map_modules(void) | ||
std::string | ||
raw2trace_t::read_and_map_modules(const char* module_map) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: C-style "char *m..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
trace_entry_t * | ||
raw2trace_t::append_memref(trace_entry_t *buf_in, uint tidx, instr_t *instr, | ||
std::string | ||
raw2trace_t::append_memref(trace_entry_t **buf_in, uint tidx, instr_t *instr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use OUT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
bool | ||
raw2trace_t::append_bb_entries(uint tidx, offline_entry_t *in_entry) | ||
std::string | ||
raw2trace_t::append_bb_entries(uint tidx, offline_entry_t *in_entry, bool *handled) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use OUT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
} while (thread_count > 0); | ||
return std::string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes you're using 'return ""' and others 'return std::string()' -- best to pick one. IMHO "" is clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
*/ | ||
|
||
/* raw2trace helper to iterate directories and open files. | ||
* Separate from raw2trace_t, so that raw2trace doesn't depend on dr_frontend. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: prefer */ on own line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} while (0) | ||
|
||
#define CHECK(val, msg, ...) do { \ | ||
if (!(val)) FATAL_ERROR(msg, ##__VA_ARGS__); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent looks off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
if (this->verbosity >= (level)) { \ | ||
fprintf(stderr, "[drmemtrace]: "); \ | ||
fprintf(stderr, __VA_ARGS__); \ | ||
} \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent is off in above lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
|
||
raw2trace_helper_t::raw2trace_helper_t(const std::string& indir_in, | ||
const std::string& outname_in, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
class raw2trace_helper_t { | ||
public: | ||
raw2trace_helper_t(const std::string& indir, const std::string& outname, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the many style violations. I'll see if I can contribute a minimal .clang_format to catch similar ones.
clients/drcachesim/CMakeLists.txt
Outdated
@@ -89,6 +89,7 @@ add_executable(drcachesim | |||
simulator/analyzer_interface.cpp | |||
# We embed the raw2trace conversion for convenience: | |||
tracer/raw2trace.cpp | |||
tracer/raw2trace_helper.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Yup, it's a much better name.
void | ||
raw2trace_t::read_and_map_modules(void) | ||
std::string | ||
raw2trace_t::read_and_map_modules(const char* module_map) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
trace_entry_t * | ||
raw2trace_t::append_memref(trace_entry_t *buf_in, uint tidx, instr_t *instr, | ||
std::string | ||
raw2trace_t::append_memref(trace_entry_t **buf_in, uint tidx, instr_t *instr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
bool | ||
raw2trace_t::append_bb_entries(uint tidx, offline_entry_t *in_entry) | ||
std::string | ||
raw2trace_t::append_bb_entries(uint tidx, offline_entry_t *in_entry, bool *handled) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
} while (thread_count > 0); | ||
return std::string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} while (0) | ||
|
||
#define CHECK(val, msg, ...) do { \ | ||
if (!(val)) FATAL_ERROR(msg, ##__VA_ARGS__); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
if (this->verbosity >= (level)) { \ | ||
fprintf(stderr, "[drmemtrace]: "); \ | ||
fprintf(stderr, __VA_ARGS__); \ | ||
} \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
thread_files.push_back(new std::ifstream(path, std::ifstream::binary)); | ||
if (!(*thread_files.back())) | ||
FATAL_ERROR("Failed to open thread log file %s", path); | ||
raw2trace_t::check_thread_file(thread_files.back()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks for catching.
} | ||
|
||
raw2trace_helper_t::raw2trace_helper_t(const std::string& indir_in, | ||
const std::string& outname_in, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
class raw2trace_helper_t { | ||
public: | ||
raw2trace_helper_t(const std::string& indir, const std::string& outname, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a test for the i/o interface? The existing code is tested in the various torunonly_drcacheoff() tests through running -indir.
unsigned int verbosity = 0); | ||
~raw2trace_directory_t(); | ||
|
||
char* modfile_bytes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more style issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
(DROPTION_SCOPE_FRONTEND, "verbose", 0, "Verbosity level for diagnostic output", | ||
"Verbosity level for diagnostic output."); | ||
|
||
#define FATAL_ERROR(msg, ...) do { \ | ||
fprintf(stderr, "ERROR: " msg "\n", ##__VA_ARGS__); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation: Looks like this is 6 spaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Sure, added one through the drraw2trace tool. PTAL because I'm very bad at cmake. |
Hmm, I guess I was expecting a custom test of the interface for other than the built-in dir iterator, to ensure the interface fully isolates filesystem access: akin to the burst_replaceall test. |
I think my pointing at the existing end-to-end -indir tests was misleading: I meant that to say we already have a test of the dir iterator, not to suggest that a new test of using the interface for different code from the -indir should follow that template. |
Gotcha, I didn't realize drcachesim's -indir exercises the iterator as well (through analyzer_multi_t), though in hindsight that's obvious. In this case, what I added is definitely redundant. |
This took embarrassingly long. I couldn't use the file op replacement API like in burst_replaceall, because the code we're trying to trace itself calls drmodtrack_* and that didn't seem to isolate well (always ended up segfaulting). So, I ended up just doing a simple ptrace syscall recorder and checking that all new files that we open are only because of loading new modules. |
clients/drcachesim/CMakeLists.txt
Outdated
if (UNIX) | ||
# uses ptrace, which is unix-only | ||
add_executable(tool.drcacheoff.raw2trace_io tests/raw2trace_io.cpp | ||
tracer/instru.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent should be just 2 here and line below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
return 1; | ||
} | ||
/* We don't distinguish syscall entry/exit because orig_rax is set | ||
* on both. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: prefer */ on own line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/* We don't distinguish syscall entry/exit because orig_rax is set | ||
* on both. */ | ||
if (SYS_NUM(regs) == __NR_open || SYS_NUM(regs) == __NR_openat || | ||
SYS_NUM(regs) == __NR_creat) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In cmake UNIX
includes MacOS where there is no __NR_creat. If it's simpler you could just exclude in cmake (and ifdef sanity check at top of this file) via NOT APPLE
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
* so they never get closed. | ||
*/ | ||
raw2trace_directory_t *dir = | ||
new raw2trace_directory_t(op_indir.get_value(), op_out.get_value()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, ok, it's not quite what I was thinking of (which was more of a test that actually uses the new i/o interface), but it does test the i/o isolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.
@derekbruening, can you merge this? The CI failure looks completely unrelated -- I'm assuming from a flaky test. |
OK, the general policy is to cite the issue for any flaky test or file one if it doesn't exist. That looks like #1308. This needs updating to master anyway so it will re-run. |
Splits out a self-contained library, which:
and doesn't own them, so it can be used with more exotic filesystems;
drmodtrack_offline_read();
Preserves the current behavior with raw2trace_helper_t, which walks
directories and opens files.
TESTED: ctest (failures failed before this commit as well)
Fixes #2511