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

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

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
1 change: 1 addition & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 112
#define VERSION_REVISION 113

#endif
49 changes: 49 additions & 0 deletions trunk/src/kernel/srs_kernel_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <srs_kernel_error.hpp>

#include <srs_kernel_log.hpp>
#include <srs_kernel_utility.hpp>

#include <errno.h>
#include <sstream>
Expand All @@ -15,6 +16,7 @@
#include <assert.h>

#include <map>
#include <vector>
using namespace std;

#if defined(SRS_BACKTRACE) && defined(__linux)
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/kernel/srs_kernel_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
6 changes: 2 additions & 4 deletions trunk/src/main/srs_main_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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

/**
Expand Down