libcamera: base: Add Backtrace class

Create a new class to abstract generation and access to call stack
backtraces. The current implementation depends on the glibc backtrace()
implementation and is copied from the logger. Future development will
bring support for libunwind, transparently for the users of the class.

The logger backtrace implementation is dropped, replaced by usage of the
new Backtrace class.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2021-09-24 04:39:58 +03:00
parent ca5fb99409
commit bae9d2bdb3
6 changed files with 155 additions and 23 deletions

View file

@ -0,0 +1,34 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2021, Ideas on Board Oy
*
* backtrace.h - Call stack backtraces
*/
#ifndef __LIBCAMERA_BASE_BACKTRACE_H__
#define __LIBCAMERA_BASE_BACKTRACE_H__
#include <string>
#include <vector>
#include <libcamera/base/private.h>
#include <libcamera/base/class.h>
namespace libcamera {
class Backtrace
{
public:
Backtrace();
std::string toString(unsigned int skipLevels = 0) const;
private:
LIBCAMERA_DISABLE_COPY(Backtrace)
std::vector<void *> backtrace_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_BASE_BACKTRACE_H__ */

View file

@ -3,6 +3,7 @@
libcamera_base_include_dir = libcamera_include_dir / 'base'
libcamera_base_headers = files([
'backtrace.h',
'bound_method.h',
'class.h',
'event_dispatcher.h',