-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added linux stack trace with files and line numbers.
- Loading branch information
Showing
20 changed files
with
173 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# mrv2 | ||
# Copyright Contributors to the mrv2 Project. All rights reserved. | ||
|
||
include( ExternalProject ) | ||
|
||
set(libbacktrace_TAG master) | ||
|
||
ExternalProject_Add( | ||
libbacktrace | ||
GIT_REPOSITORY "https://github.com/ianlancetaylor/libbacktrace.git" | ||
GIT_TAG ${libbacktrace_TAG} | ||
CONFIGURE_COMMAND ./configure --prefix=${CMAKE_INSTALL_PREFIX} | ||
BUILD_IN_SOURCE 1 | ||
) | ||
|
||
set( libbacktrace_DEP libbacktrace ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
backtrace.h -- Public header file for stack backtrace library. | ||
Copyright (C) 2012-2021 Free Software Foundation, Inc. | ||
Written by Ian Lance Taylor, Google. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
(1) Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
(2) Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the | ||
distribution. | ||
|
||
(3) The name of the author may not be used to | ||
endorse or promote products derived from this software without | ||
specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,53 @@ | ||
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <backtrace.h> | ||
|
||
#include <execinfo.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <iostream> | ||
|
||
void printStackTrace() | ||
void error_callback(void* data, const char* msg, int errnum) | ||
{ | ||
void* callstack[128]; | ||
int frames = backtrace(callstack, 128); | ||
char** symbols = backtrace_symbols(callstack, frames); | ||
|
||
// Skip first frame which is this stack trace function | ||
for (int i = 1; i < frames; i++) | ||
{ | ||
printf("frame %d: ", i); | ||
|
||
// Use addr2line and c++filt to get the demangled symbol and line number | ||
char exe[256]; | ||
snprintf(exe, 256, "%s/bin/mrv2", getenv("MRV2_ROOT")); | ||
|
||
char command[1024]; | ||
snprintf( | ||
command, sizeof(command), "addr2line -e %s %p | c++filt", exe, | ||
callstack[i]); | ||
FILE* fp = popen(command, "r"); | ||
|
||
char output[512]; | ||
if (fgets(output, sizeof(output), fp) != nullptr) | ||
printf("%s", output); | ||
|
||
pclose(fp); | ||
fprintf(stderr, "%s - Error %d\n", msg, errnum); | ||
} | ||
|
||
// Print the raw symbol as well | ||
printf(" %s\n", symbols[i]); | ||
int full_callback( | ||
void* data, uintptr_t pc, const char* filename, int lineno, | ||
const char* function) | ||
{ | ||
char demangled_name[1024]; | ||
demangled_name[0] = '\0'; | ||
|
||
|
||
char buffer[512]; | ||
if (!filename || !function || strcmp(function, "(null)") == 0) | ||
return 0; | ||
|
||
snprintf(buffer, sizeof(buffer), "c++filt %s", function); | ||
FILE* pipe = popen(buffer, "r"); | ||
if (!pipe) { | ||
perror("popen"); | ||
return 1; | ||
} | ||
fgets(demangled_name, sizeof(demangled_name), pipe); | ||
pclose(pipe); | ||
|
||
size_t len = strlen(demangled_name); | ||
if (len > 0) | ||
demangled_name[len-1] = '\0'; | ||
|
||
printf("0x%lx %s (%s:%d)\n", pc, demangled_name, filename, lineno); | ||
return 0; | ||
} | ||
|
||
void printStackTrace() | ||
{ | ||
// MRV2_ROOT contains the root path of the executable. | ||
char exe[1024]; | ||
snprintf(exe, 1024, "%s/bin/mrv2", getenv("MRV2_ROOT")); | ||
|
||
free(symbols); | ||
auto state = backtrace_create_state(exe, 1, error_callback, nullptr); | ||
int ret = backtrace_full(state, 0, full_callback, error_callback, nullptr); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.