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#147: Alternate-bitwidth client support #4324

Merged
merged 7 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 29 additions & 4 deletions api/docs/intro.dox
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,15 @@ of time for the child application. To instead only
follow children that are configured (via \c drconfig.exe), use the
\ref op_children "-no_follow_children" runtime option.

To ensure a client is loaded into a child process of a different
bitwidth (i.e., a 32-bit child created by a 64-bit parent), use the \c
-c32 and \c -c64 options to \c drconfig or \c drrun, with \c -- ending
the first client's options:

bin32/drrun.exe -c32 samples/bin32/bbsize.dll -- -c64 samples/bin64/bbsize.dll -- notepad
derekbruening marked this conversation as resolved.
Show resolved Hide resolved

The order matters: \c -c32 must come first.

To \ref sec_comm "nudge" all instances of \c notepad.exe running under
DynamoRIO with argument "5", use:
\code
Expand Down Expand Up @@ -594,6 +603,15 @@ Client options are not allowed to contain semicolons. Additionally, the
client option string combined with the path to the client library cannot
contain all three quote characters (', ", `) simultaneously.

To ensure a client is loaded into a child process of a different
bitwidth (i.e., a 32-bit child created by a 64-bit parent), use the \c
-c32 and \c -c64 options to \c drconfig or \c drrun, with \c -- ending
the first client's options:

bin32/drrun -c32 samples/bin32/bbsize.dll -- -c64 samples/bin64/bbsize.dll -- notepad

The order matters: \c -c32 must come first.

\section multi_client Multiple Clients

DynamoRIO does support multiple clients. It is each client's
Expand Down Expand Up @@ -626,19 +644,26 @@ option. To use the option, first create a file in the \p tools
subdirectory of the root of the DynamoRIO installation called \p
toolname.drrun32 or \p toolname.drrun64, depending on the target
architecture. Here, \p toolname is the desired external name of the tool.
This file should contain one of the following lines:
This file should contain one of the following lines, or two if
they are a pair of CLIENT32_* and CLIENT64_* specifiers:

\code
CLIENT_ABS=/absolute/path/to/client
CLIENT32_ABS=/absolute/path/to/32-bit-client
CLIENT64_ABS=/absolute/path/to/64-bit-client
\endcode

or

\code
CLIENT_REL=relative/path/to/client/from/DynamoRIO/root
CLIENT32_REL=relative/path/to/32-bit-client/from/DynamoRIO/root
CLIENT64_REL=relative/path/to/64-bit-client/from/DynamoRIO/root
\endcode

This enables \p drrun to locate the tool's client library.
This enables \p drrun to locate the tool's client library. The 32 and
64 specifiers allow pointing at alternate-bitwidth paths for use if
the target application creates a child process of a different bitwidth.

The file can also modify the default DynamoRIO runtime options (see \ref
sec_options) via \p DR_OP= lines. Each line contains only one option string
Expand Down Expand Up @@ -698,8 +723,8 @@ FRONTEND_REL=relative/path/to/front-end/from/DynamoRIO/root
\endcode

This will cause \p drrun to transfer control to the specified front-end
executable, passing any tool arguments (including a client path, if \p
CLIENT_ABS or \p CLIENT_REL appears after the \p FRONTEND_* command)
executable, passing any tool arguments (including client paths, if \p
CLIENT{,32,64}_{ABS,REL} appears after the \p FRONTEND_* command)
followed by "--" and the target application command line.

The path to the DynamoRIO install base can be included in the front-end
Expand Down
11 changes: 10 additions & 1 deletion api/docs/release.dox
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ changes:
The changes between version \DR_VERSION and 8.0.0 include the following minor
compatibility changes:

Nothing yet.
- drconfiglib (and thus drrun and drconfig) now sets only the new client path
options which are added in this release to support other-bitwidth child processes.
This means that a drconfiglib from this version will not properly configure for a
DynamoRIO core library from a prior version.

Further non-compatibility-affecting changes include:

Expand All @@ -155,6 +158,12 @@ Further non-compatibility-affecting changes include:
Not all API routines support the setting of error codes. Please look at their
documentation to check if they do.
- Added -instr_only_trace option to drcachesim.
- Added other-bitwidth child process support, with the other client library
specified by "-c32" "-c64" to drrun or drdeploy, by dr_register_client_ex()
with #dr_config_client_t.is_alt_bitwidth=true to drconfiglib, and by
CLIENT{32,64}_{ABS,REL} in tool files.
Added dr_get_client_info_ex() and dr_client_iterator_next_ex() to support
querying other-bitwidth client registration.

**************************************************
<hr>
Expand Down
17 changes: 15 additions & 2 deletions clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ install_target(drraw2trace ${INSTALL_CLIENTS_BIN})
set(INSTALL_DRCACHESIM_CONFIG ${INSTALL_CLIENTS_BASE})

function (write_config_file dst bindir libdir)
# We include the alternate-bitwidth path, though it won't be there for
# a single build dir and such a child will have a fatal error.
if (X64)
string(REPLACE "lib64" "lib32" alt_libdir ${libdir})
set(CUR_BIT "64")
set(ALT_BIT "32")
else ()
set(CUR_BIT "32")
set(ALT_BIT "64")
string(REPLACE "lib64" "lib32" alt_libdir ${libdir})
endif ()
if (DEBUG)
set(debugopt "TOOL_OP=-dr_debug")
else ()
Expand All @@ -426,8 +437,10 @@ TOOL_OP=-dr\n\
TOOL_OP_DR_PATH\n\
TOOL_OP_DR_BUNDLE=-dr_ops\n\
TOOL_OP=-tracer\n\
CLIENT_REL=${libdir}/${LIB_PFX}drmemtrace${LIB_EXT}\n\
${debugopt}")
CLIENT${CUR_BIT}_REL=${libdir}/${LIB_PFX}drmemtrace${LIB_EXT}\n\
TOOL_OP=-tracer_alt\n\
CLIENT${ALT_BIT}_REL=${alt_libdir}/${LIB_PFX}drmemtrace${LIB_EXT}\n\
${debugopt}\n")
endfunction ()

if (X64)
Expand Down
7 changes: 7 additions & 0 deletions clients/drcachesim/common/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ droption_t<std::string> op_tracer(DROPTION_SCOPE_FRONTEND, "tracer", "",
"Path to the tracer",
"The full path to the tracer library.");

droption_t<std::string> op_tracer_alt(DROPTION_SCOPE_FRONTEND, "tracer_alt", "",
derekbruening marked this conversation as resolved.
Show resolved Hide resolved
"Path to the alternate-bitwidth tracer",
"The full path to the tracer library for the other "
"bitwidth, for use on child processes with a "
"different bitwidth from their parent. If empty, "
"such child processes will die with fatal errors.");

droption_t<std::string> op_tracer_ops(
DROPTION_SCOPE_FRONTEND, "tracer_ops",
DROPTION_FLAG_SWEEP | DROPTION_FLAG_ACCUMULATE | DROPTION_FLAG_INTERNAL, "",
Expand Down
1 change: 1 addition & 0 deletions clients/drcachesim/common/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ extern droption_t<std::string> op_dr_root;
extern droption_t<bool> op_dr_debug;
extern droption_t<std::string> op_dr_ops;
extern droption_t<std::string> op_tracer;
extern droption_t<std::string> op_tracer_alt;
extern droption_t<std::string> op_tracer_ops;
extern droption_t<bytesize_t> op_skip_refs;
extern droption_t<bytesize_t> op_warmup_refs;
Expand Down
24 changes: 24 additions & 0 deletions clients/drcachesim/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ configure_application(char *app_name, char **app_argv, std::string tracer_ops,
tracer_ops.c_str()) != DR_SUCCESS) {
FATAL_ERROR("failed to register DynamoRIO client configuration");
}
if (!op_tracer_alt.get_value().empty()) {
dr_config_client_t info;
info.struct_size = sizeof(info);
info.id = CLIENT_ID;
info.priority = 1;
char local_path[MAXIMUM_PATH];
dr_snprintf(local_path, BUFFER_SIZE_ELEMENTS(local_path), "%s",
op_tracer_alt.get_value().c_str());
info.path = (char *)local_path;
char local_ops[MAXIMUM_PATH];
dr_snprintf(local_ops, BUFFER_SIZE_ELEMENTS(local_path), "%s",
op_tracer_ops.get_value().c_str());
info.options = (char *)local_ops;
info.is_alt_bitwidth = true;
NOTIFY(1, "INFO", "configuring alt-bitwidth client \"%s\"",
op_tracer_alt.get_value().c_str());
if (dr_register_client_ex(process, pid, false /*local*/, DR_PLATFORM_DEFAULT,
&info) != DR_SUCCESS)
FATAL_ERROR("failed to register DynamoRIO client configuration");
}
return true;
}

Expand Down Expand Up @@ -269,6 +289,10 @@ _tmain(int argc, const TCHAR *targv[])
if (!file_is_readable(op_tracer.get_value().c_str())) {
FATAL_ERROR("tracer library %s is unreadable", op_tracer.get_value().c_str());
}
// We deliberately do *not* check -tracer_alt, since we're guessing that
// path is available and it won't be for a single build dir.
// An other-bitwidth child will exit with a fatal error if the lib
// is not there and the user runs such an app.
if (!file_is_readable(op_dr_root.get_value().c_str())) {
FATAL_ERROR("invalid -dr_root %s", op_dr_root.get_value().c_str());
}
Expand Down
14 changes: 13 additions & 1 deletion clients/drcov/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,23 @@ else (X64)
endif (X64)

function (write_config_file dst libdir)
# We include the alternate-bitwidth path, though it won't be there for
# a single build dir and such a child will have a fatal error.
if (X64)
string(REPLACE "lib64" "lib32" alt_libdir ${libdir})
set(CUR_BIT "64")
set(ALT_BIT "32")
else ()
set(CUR_BIT "32")
set(ALT_BIT "64")
string(REPLACE "lib64" "lib32" alt_libdir ${libdir})
endif ()
file(WRITE ${dst} "# drcov tool config file\n")
file(APPEND ${dst} "# DynamoRIO options\n")
file(APPEND ${dst} "DR_OP=-nop_initial_bblock\n")
file(APPEND ${dst} "# client tool path\n")
file(APPEND ${dst} "CLIENT_REL=${libdir}/${LIB_PFX}drcov${LIB_EXT}\n")
file(APPEND ${dst} "CLIENT${CUR_BIT}_REL=${libdir}/${LIB_PFX}drcov${LIB_EXT}\n")
file(APPEND ${dst} "CLIENT${ALT_BIT}_REL=${alt_libdir}/${LIB_PFX}drcov${LIB_EXT}\n")
file(APPEND ${dst} "# client tool options\n")
file(APPEND ${dst} "TOOL_OP=\n")
endfunction ()
Expand Down
14 changes: 13 additions & 1 deletion clients/drcpusim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,20 @@ install_target(drcpusim ${INSTALL_CLIENTS_LIB})
set(INSTALL_DRCPUSIM_CONFIG ${INSTALL_CLIENTS_BASE})

function (write_config_file dst bindir libdir)
# We include the alternate-bitwidth path, though it won't be there for
# a single build dir and such a child will have a fatal error.
if (X64)
string(REPLACE "lib64" "lib32" alt_libdir ${libdir})
set(CUR_BIT "64")
set(ALT_BIT "32")
else ()
set(CUR_BIT "32")
set(ALT_BIT "64")
string(REPLACE "lib64" "lib32" alt_libdir ${libdir})
endif ()
file(WRITE ${dst} "# drcpusim tool config file\n")
file(APPEND ${dst} "CLIENT_REL=${libdir}/${LIB_PFX}drcpusim${LIB_EXT}\n")
file(APPEND ${dst} "CLIENT${CUR_BIT}_REL=${libdir}/${LIB_PFX}drcpusim${LIB_EXT}\n")
file(APPEND ${dst} "CLIENT${ALT_BIT}_REL=${alt_libdir}/${LIB_PFX}drcpusim${LIB_EXT}\n")
endfunction ()

if (X64)
Expand Down
Loading