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#2511: isolate raw2trace #2512

Merged
merged 18 commits into from
Jul 18, 2017
Merged

Conversation

s-kanev
Copy link
Contributor

@s-kanev s-kanev commented Jul 7, 2017

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 #2511

s-kanev added 2 commits July 7, 2017 14:46
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
@s-kanev
Copy link
Contributor Author

s-kanev commented Jul 7, 2017

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.

@derekbruening
Copy link
Contributor

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.

@fhahn
Copy link
Contributor

fhahn commented Jul 10, 2017

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 --allow-empty-checksums should fix the builds: #2513

@fhahn
Copy link
Contributor

fhahn commented Jul 10, 2017

The appveyor builds should be fixed now, I've used the Update branch button, to trigger a new build.

Copy link
Contributor

@derekbruening derekbruening left a 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

@@ -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
Copy link
Contributor

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"?

Copy link
Contributor Author

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)
Copy link
Contributor

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..."

Copy link
Contributor Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use OUT

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use OUT

Copy link
Contributor Author

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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. */
Copy link
Contributor

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

Copy link
Contributor Author

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__); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent looks off

Copy link
Contributor Author

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__); \
} \
Copy link
Contributor

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

Copy link
Contributor Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More style

Copy link
Contributor Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

@s-kanev s-kanev left a 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.

@@ -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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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,
Copy link
Contributor Author

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)
Copy link
Contributor Author

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();
Copy link
Contributor Author

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__); \
Copy link
Contributor Author

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__); \
} \
Copy link
Contributor Author

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());
Copy link
Contributor Author

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,
Copy link
Contributor Author

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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@derekbruening derekbruening left a 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more style issue.

Copy link
Contributor Author

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__); \
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@s-kanev
Copy link
Contributor Author

s-kanev commented Jul 11, 2017

Could we add a test for the i/o interface?

Sure, added one through the drraw2trace tool. PTAL because I'm very bad at cmake.
There's also a slightly finer-grained test in this change's internal counterpart.

@derekbruening
Copy link
Contributor

derekbruening commented Jul 12, 2017

Could we add a test for the i/o interface?

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.

@derekbruening
Copy link
Contributor

Could we add a test for the i/o interface?

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.

@s-kanev
Copy link
Contributor Author

s-kanev commented Jul 12, 2017

I meant that to say we already have a test of the dir iterator

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.
I'll add a standalone test that just invokes raw2trace_t on a set of raw files, similar to what we do downstream.

@s-kanev
Copy link
Contributor Author

s-kanev commented Jul 14, 2017

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.
We could get more sophisticated -- e.g. checking that all trace reads/writes are to pre-opened file descriptors -- but I don't think it's worth the extra effort.

if (UNIX)
# uses ptrace, which is unix-only
add_executable(tool.drcacheoff.raw2trace_io tests/raw2trace_io.cpp
tracer/instru.cpp
Copy link
Contributor

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

Copy link
Contributor Author

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. */
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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());
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

@s-kanev
Copy link
Contributor Author

s-kanev commented Jul 18, 2017

@derekbruening, can you merge this? The CI failure looks completely unrelated -- I'm assuming from a flaky test.

@derekbruening
Copy link
Contributor

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.

@derekbruening derekbruening merged commit 66fa2c7 into DynamoRIO:master Jul 18, 2017
s-kanev added a commit to s-kanev/dynamorio that referenced this pull request Jul 18, 2017
derekbruening pushed a commit that referenced this pull request Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants