SWDEV-362165 - Escape strings in the API function's arguments
Strings ([const] char *, [const] char[]) passed as arguments to API
functions may not always contain printable characters. All string
arguments should be quoted and escaped in the trace logs.
Change-Id: Ie39058f2190048b1a0090df16d9ac6bc6507e28a
[ROCm/roctracer commit: b556f8681e]
Этот коммит содержится в:
@@ -243,8 +243,8 @@ class file_plugin_t {
|
||||
<< ((record->op == HSA_API_ID_hsa_shut_down) ? record->begin_ns
|
||||
: record->end_ns)
|
||||
<< " " << record->process_id << ":" << record->thread_id << " "
|
||||
<< hsa_api_data_pair_t(record->op, *data) << " :" << data->correlation_id
|
||||
<< std::endl;
|
||||
<< hsa_api_data_pair_t(record->op, *data) << " :" << std::dec
|
||||
<< data->correlation_id << std::endl;
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_DOMAIN_HIP_API: {
|
||||
@@ -265,7 +265,7 @@ class file_plugin_t {
|
||||
*output_file << std::dec << record->begin_ns << ":" << record->end_ns << " "
|
||||
<< record->process_id << ":" << record->thread_id << " "
|
||||
<< hipApiString((hip_api_id_t)record->op, data) << kernel_name << " :"
|
||||
<< data->correlation_id << std::endl;
|
||||
<< std::dec << data->correlation_id << std::endl;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -53,7 +53,20 @@ LICENSE = \
|
||||
|
||||
header_basic = \
|
||||
'namespace detail {\n' + \
|
||||
'template <typename T>\n' + \
|
||||
' inline static void print_escaped_string(std::ostream& out, const char *v, size_t len) {\n' + \
|
||||
' out << \'"\'; \n' + \
|
||||
' for (size_t i = 0; i < len && v[i]; ++i) {\n' + \
|
||||
' if (std::isprint((unsigned char)v[i])) std::operator<<(out, v[i]);\n' + \
|
||||
' else {\n' + \
|
||||
' std::ios_base::fmtflags flags(out.flags());\n' + \
|
||||
' out << "\\\\x" << std::setfill(\'0\') << std::setw(2) << std::hex << (unsigned int)(unsigned char)v[i];\n' + \
|
||||
' out.flags(flags);\n' + \
|
||||
' }\n' + \
|
||||
' }\n' + \
|
||||
' out << \'"\'; \n' + \
|
||||
' }\n' + \
|
||||
'\n' + \
|
||||
' template <typename T>\n' + \
|
||||
' inline static std::ostream& operator<<(std::ostream& out, const T& v) {\n' + \
|
||||
' using std::operator<<;\n' + \
|
||||
' static bool recursion = false;\n' + \
|
||||
@@ -66,6 +79,15 @@ header_basic = \
|
||||
'\n' + \
|
||||
' inline static std::ostream &operator<<(std::ostream &out, const char &v) {\n' + \
|
||||
' out << (unsigned char)v;\n' + \
|
||||
' return out;\n }\n' + \
|
||||
'\n' + \
|
||||
' template <size_t N>\n' + \
|
||||
' inline static std::ostream &operator<<(std::ostream &out, const char (&v)[N]) {\n' + \
|
||||
' print_escaped_string(out, v, N);\n' + \
|
||||
' return out;\n }\n' + \
|
||||
'\n' + \
|
||||
' inline static std::ostream &operator<<(std::ostream &out, const char *v) {\n' + \
|
||||
' print_escaped_string(out, v, strlen(v));\n' + \
|
||||
' return out;\n }\n'
|
||||
|
||||
structs_analyzed = {}
|
||||
@@ -120,9 +142,9 @@ def process_struct(file_handle, cppHeader_struct, cppHeader, parent_hier_name, a
|
||||
indent = ""
|
||||
str += " if (std::string(\"" + cppHeader_struct + "::" + name + "\").find(" + apiname.upper() + "_structs_regex" + ") != std::string::npos) {\n"
|
||||
indent = " "
|
||||
str += indent + " roctracer::" + apiname.lower() + "_support::detail::operator<<(out, \"" + name + "=\");\n"
|
||||
str += indent + " std::operator<<(out, \"" + name + "=\");\n"
|
||||
str += indent + " roctracer::" + apiname.lower() + "_support::detail::operator<<(out, v." + name + ");\n"
|
||||
str += indent + " roctracer::" + apiname.lower() + "_support::detail::operator<<(out, \", \");\n"
|
||||
str += indent + " std::operator<<(out, \", \");\n"
|
||||
str += " }\n"
|
||||
if "void" not in mtype:
|
||||
global_str += str
|
||||
@@ -166,7 +188,9 @@ def gen_cppheader(infilepath, outfilepath, rank):
|
||||
'\n' + \
|
||||
'#ifdef __cplusplus\n' + \
|
||||
'#include <iostream>\n' + \
|
||||
'#include <string>\n'
|
||||
'#include <iomanip>\n' + \
|
||||
'#include <string>\n' + \
|
||||
'#include <cstring>\n'
|
||||
|
||||
output_filename_h.write(header_s)
|
||||
output_filename_h.write('\n')
|
||||
|
||||
Ссылка в новой задаче
Block a user