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

Added function caching and return value logging. #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion drltrace_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ set(srcs
drltrace.cpp
drltrace_libcalls.cpp
drltrace_options.cpp
drltrace_utils.cpp)
drltrace_utils.cpp
drltrace_retval_cache.cpp)

set(DynamoRIO_USE_LIBC OFF)

Expand Down
316 changes: 212 additions & 104 deletions drltrace_src/drltrace.cpp

Large diffs are not rendered by default.

37 changes: 36 additions & 1 deletion drltrace_src/drltrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
* DAMAGE.
*/

#ifndef _DRLTRACE_H
#define _DRLTRACE_H

#include "dr_api.h"
#include "drltrace_options.h"
#include "drmgr.h"
Expand All @@ -40,6 +43,37 @@
#include <string.h>
#include <vector>


/* Temporary workaround for VC2013, which doesn't have snprintf().
* apparently, this was added in later releases... */
#ifdef WINDOWS
#define snprintf _snprintf
#endif

/* Some function on Windows aren't stable to process (i.e.: we can't
* reliably or safely get the thread ID and/or the return value). */
#ifdef WINDOWS
#define skip_unstable_functions(_function_name) \
{ size_t function_name_len = strlen(_function_name); \
if ((fast_strcmp(_function_name, function_name_len, \
"ZwCallbackReturn", 16) == 0) || \
(fast_strcmp(_function_name, function_name_len, \
"KiUserCallbackDispatcher", 24) == 0) || \
(fast_strcmp(_function_name, function_name_len, \
"ExpInterlockedPopEntrySListResume", 33) == 0) || \
(fast_strcmp(_function_name, function_name_len, \
"_dll_crt0", 9) == 0) || \
(fast_strcmp(_function_name, function_name_len, \
"BaseThreadInitThunk", 19) == 0) || \
(fast_strcmp(_function_name, function_name_len, \
"RtlUserThreadStart", 18) == 0) \
) { \
return; \
}}
#else
#define skip_unstable_functions(_unused) {}
#endif

typedef enum {
DRSYS_PARAM_IN = 0x01, /**< Input parameter. */
DRSYS_PARAM_OUT = 0x02, /**< Output parameter. */
Expand Down Expand Up @@ -184,7 +218,8 @@ typedef struct _drltrace_arg_t {
uint64 value64;
} drltrace_arg_t;


void parse_config(void);
std::vector<drltrace_arg_t *> *libcalls_search(const char *name);
void libcalls_hashtable_delete();

#endif /* _DRLTRACE_H */
8 changes: 4 additions & 4 deletions drltrace_src/drltrace_libcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ parse_line(const char *line, int line_num)
std::vector<drltrace_arg_t *> *args_vector = new std::vector<drltrace_arg_t *>();
std::vector<std::string>::iterator it;
for (it = tokens.begin(); it != tokens.end(); ++it) {
/* FIXME DrMemory i#1948: Currently, we don't support ret value printing and
* skipping it here.
*/
if (elem_index >= 2) {
tmp_arg = config_parse_type(*it, elem_index - 2);
args_vector->push_back(tmp_arg);
} else if (elem_index == 1)
func_name = it->c_str();

else {
tmp_arg = config_parse_type(*it, 0);
args_vector->push_back(tmp_arg);
}
elem_index++;
}

Expand Down
11 changes: 11 additions & 0 deletions drltrace_src/drltrace_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,14 @@ droption_t<std::string> op_ltracelib_ops
droption_t<bool> op_grepable
(DROPTION_SCOPE_CLIENT, "grepable", false, "Grepable output",
"Outputs function names and arguments entirely on one line to enable easy log grepping.");

droption_t<bool> op_no_retval
(DROPTION_SCOPE_CLIENT, "no-retval", false, "Disable return value parsing",
"Disable return value caching & parsing.");

droption_t<unsigned int> op_retval_max_cache
(DROPTION_SCOPE_CLIENT, "retval-max-cache", 0,
"Maximum number of cached function calls", "The maximum number of function calls that "
"should be cached while waiting for return values. When reached, the cache will be "
"emptied immediately and return values discarded; new function calls will be cached "
"normally. Only use this option if memory exhaustion occurs.");
2 changes: 2 additions & 0 deletions drltrace_src/drltrace_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ extern droption_t<unsigned int> op_verbose;
extern droption_t<bool> op_use_config;
extern droption_t<std::string> op_ltracelib_ops;
extern droption_t<bool> op_grepable;
extern droption_t<bool> op_no_retval;
extern droption_t<unsigned int> op_retval_max_cache;
Loading