Asan: Support parse asan symbol backtrace log. v5.0.113 (#3324)

* asan: support parse asan symbol log

* asan: refine srs_parse_asan_backtrace_symbols error code

* asan: Refine code, extract asan log to error file.

Co-authored-by: winlin <winlin@vip.126.com>
pull/3321/head
ChenGH 2 years ago committed by GitHub
parent e6f40bd0c7
commit 7eaee46f1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,7 @@ The changelog for SRS.
## SRS 5.0 Changelog
* v5.0, 2022-12-18, Merge [#3324](https://github.com/ossrs/srs/pull/3324): Asan: Support parse asan symbol backtrace log. v5.0.113
* v5.0, 2022-12-17, Merge [#3323](https://github.com/ossrs/srs/pull/3323): SRT: Fix srt to rtmp crash when sps or pps empty. v5.0.112
* v5.0, 2022-12-15, For [#3300](https://github.com/ossrs/srs/issues/3300): GB28181: Fix memory overlap for small packets. v5.0.111
* v5.0, 2022-12-14, For [#939](https://github.com/ossrs/srs/issues/939): FLV: Support set default has_av and disable guessing. v5.0.110

@ -9,6 +9,6 @@
#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 112
#define VERSION_REVISION 113
#endif

@ -7,6 +7,7 @@
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_utility.hpp>
#include <errno.h>
#include <sstream>
@ -15,6 +16,7 @@
#include <assert.h>
#include <map>
#include <vector>
using namespace std;
#if defined(SRS_BACKTRACE) && defined(__linux)
@ -118,6 +120,53 @@ char* addr2line_format(void* addr, char* symbol, char* buffer, int nn_buffer)
}
#endif
int srs_parse_asan_backtrace_symbols(char* symbol, char* out_buf)
{
#if defined(SRS_BACKTRACE) && defined(__linux)
void* frame = parse_symbol_offset(symbol);
if (!frame) {
return ERROR_BACKTRACE_PARSE_OFFSET;
}
char* fmt = addr2line_format(frame, symbol, out_buf, sizeof(out_buf));
if (fmt != out_buf) {
return ERROR_BACKTRACE_ADDR2LINE;
}
return ERROR_SUCCESS;
#endif
return ERROR_BACKTRACE_PARSE_NOT_SUPPORT;
}
#ifdef SRS_SANITIZER_LOG
void asan_report_callback(const char* str)
{
static char buf[256];
// No error code for assert failed.
errno = 0;
std::vector<std::string> asan_logs = srs_string_split(string(str), "\n");
size_t log_count = asan_logs.size();
for (size_t i = 0; i < log_count; i++) {
std::string log = asan_logs[i];
if (!srs_string_starts_with(srs_string_trim_start(log, " "), "#")) {
srs_error("%s", log.c_str());
continue;
}
buf[0] = 0;
int r0 = srs_parse_asan_backtrace_symbols((char*)log.c_str(), buf);
if (r0 != ERROR_SUCCESS) {
srs_error("%s, r0=%d", log.c_str(), r0);
} else {
srs_error("%s, %s", log.c_str(), buf);
}
}
}
#endif
bool srs_is_system_control_error(srs_error_t err)
{
int error_code = srs_error_code(err);

@ -102,6 +102,9 @@
XX(ERROR_APM_AUTH , 1089, "ApmAuth", "APM team or token is invalid") \
XX(ERROR_EXPORTER_DISABLED , 1090, "ExporterDisable", "Prometheus exporter is disabled") \
XX(ERROR_ST_SET_SELECT , 1091, "StSetSelect", "ST set select failed") \
XX(ERROR_BACKTRACE_PARSE_NOT_SUPPORT , 1092, "BacktraceParseNotSupport", "Backtrace parse not supported") \
XX(ERROR_BACKTRACE_PARSE_OFFSET , 1093, "BacktraceParseOffset", "Parse backtrace offset failed") \
XX(ERROR_BACKTRACE_ADDR2LINE , 1094, "BacktraceAddr2Line", "Backtrace addr2line failed") \
/**************************************************/
/* RTMP protocol error. */

@ -42,6 +42,7 @@ using namespace std;
#include <srs_kernel_file.hpp>
#include <srs_app_hybrid.hpp>
#include <srs_app_threads.hpp>
#include <srs_kernel_error.hpp>
#ifdef SRS_RTC
#include <srs_app_rtc_conn.hpp>
@ -82,10 +83,7 @@ const char* _srs_binary = NULL;
extern void srs_free_global_system_ips();
#ifdef SRS_SANITIZER_LOG
void asan_report_callback(const char* str)
{
srs_trace("%s", str);
}
extern void asan_report_callback(const char* str);
#endif
/**

Loading…
Cancel
Save