trace: initial import of a stack backtrace function for native
Sometimes the debugger just isn't fast enough to debug that pesky race conditions. This module provides at least a little help.
This commit is contained in:
parent
565341c9fd
commit
875a5c165d
@ -22,6 +22,9 @@ endif
|
|||||||
ifneq (,$(filter can_linux,$(USEMODULE)))
|
ifneq (,$(filter can_linux,$(USEMODULE)))
|
||||||
DIRS += can
|
DIRS += can
|
||||||
endif
|
endif
|
||||||
|
ifneq (,$(filter trace,$(USEMODULE)))
|
||||||
|
DIRS += trace
|
||||||
|
endif
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.base
|
include $(RIOTBASE)/Makefile.base
|
||||||
|
|
||||||
|
|||||||
49
cpu/native/include/trace.h
Normal file
49
cpu/native/include/trace.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Freie Universität Berlin
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
* directory for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup trace Stack traceback (only under native)
|
||||||
|
* @ingroup core_util
|
||||||
|
* @brief Address-trace back.
|
||||||
|
*
|
||||||
|
* If you call the @ref trace_print() function a stack traceback of all return
|
||||||
|
* addresses up to @ref TRACE_SIZE will be printed from the point of execution.
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||||
|
*/
|
||||||
|
#ifndef TRACE_H
|
||||||
|
#define TRACE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Maximum number of return addresses to print
|
||||||
|
*/
|
||||||
|
#ifndef TRACE_SIZE
|
||||||
|
#define TRACE_SIZE (4U)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Print the last @ref TRACE_SIZE return addresses from call of this
|
||||||
|
* function
|
||||||
|
*/
|
||||||
|
void trace_print(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* TRACE_H */
|
||||||
|
/** @} */
|
||||||
1
cpu/native/trace/Makefile
Normal file
1
cpu/native/trace/Makefile
Normal file
@ -0,0 +1 @@
|
|||||||
|
include $(RIOTBASE)/Makefile.base
|
||||||
35
cpu/native/trace/trace.c
Normal file
35
cpu/native/trace/trace.c
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Freie Universität Berlin
|
||||||
|
*
|
||||||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||||||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||||||
|
* directory for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <execinfo.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "trace.h"
|
||||||
|
|
||||||
|
void trace_print(void)
|
||||||
|
{
|
||||||
|
void *array[TRACE_SIZE + 1];
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
size = backtrace(array, TRACE_SIZE + 1);
|
||||||
|
|
||||||
|
/* skip above line's return address and start with 1 */
|
||||||
|
for (size_t i = 1; i < size; i++) {
|
||||||
|
printf("%p\n", array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @} */
|
||||||
Loading…
x
Reference in New Issue
Block a user