From a7cd80b716a3f7ff0444176c7a21ade4fecb1f2f Mon Sep 17 00:00:00 2001 From: Saurabh Verma Date: Tue, 31 Aug 2021 15:33:37 -0500 Subject: [PATCH] SWDEV-295878 Fix for seg fault when using --trace-start off Change-Id: Ic76d814b3591f72db18319d78f34596dae1ddfee --- src/roctx/roctx.cpp | 7 +++---- test/tool/tracer_tool.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/roctx/roctx.cpp b/src/roctx/roctx.cpp index e9a0815f16..819cc28773 100644 --- a/src/roctx/roctx.cpp +++ b/src/roctx/roctx.cpp @@ -82,7 +82,7 @@ typedef std::stack message_stack_t; typedef std::map thread_map_t; typedef std::mutex map_mutex_t; map_mutex_t map_mutex; -thread_map_t* thread_map = NULL; +thread_map_t thread_map; static thread_local message_stack_t* message_stack = NULL; roctx_status_t GetExcStatus(const std::exception& e) { @@ -95,8 +95,7 @@ void thread_data_init() { const auto tid = GetTid(); std::lock_guard lck(map_mutex); - if (thread_map == NULL) thread_map = new thread_map_t; - (*thread_map)[tid] = message_stack; + thread_map[tid] = message_stack; } // callbacks table @@ -194,7 +193,7 @@ PUBLIC_API void roctxRangeStop(roctx_range_id_t rangeId) { } PUBLIC_API void RangeStackIterate(roctx_range_iterate_cb_t callback, void* arg) { - for (const auto& entry : *roctx::thread_map) { + for (const auto& entry : roctx::thread_map) { const auto tid = entry.first; for (roctx::message_stack_t stack = *(entry.second); !stack.empty(); stack.pop()){ std::string message = stack.top(); diff --git a/test/tool/tracer_tool.cpp b/test/tool/tracer_tool.cpp index 8656dabf58..e6631174ae 100644 --- a/test/tool/tracer_tool.cpp +++ b/test/tool/tracer_tool.cpp @@ -34,6 +34,7 @@ THE SOFTWARE. #include /* usleep */ #include +#include "src/util/exception.h" #include #include #include @@ -915,11 +916,11 @@ void tool_load() { uint32_t ctrl_len = 0; uint32_t ctrl_rate = 0; - sscanf(ctrl_str, "%d:%d:%d", &ctrl_delay, &ctrl_len, &ctrl_rate); - + if (sscanf(ctrl_str, "%d:%d:%d", &ctrl_delay, &ctrl_len, &ctrl_rate) != 3) { + EXC_RAISING(ROCTRACER_STATUS_ERROR, "Invalid ROCP_CTRL_RATE var(" << ctrl_str << "), expected ctrl_delay:ctrl_len:ctrl_rate"); + } if (ctrl_len > ctrl_rate) { - fprintf(stderr, "ROCTracer: control length value (%u) > rate value (%u)\n", ctrl_len, ctrl_rate); - abort(); + EXC_RAISING(ROCTRACER_STATUS_ERROR, "Control length value " << ctrl_len << " > rate value " << ctrl_rate); } control_dist_us = ctrl_rate - ctrl_len; control_len_us = ctrl_len;