summaryrefslogtreecommitdiff
path: root/src/libcamera/base/log.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-09-24 04:39:58 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-10-15 05:05:20 +0300
commitbae9d2bdb32ee8cdc717537ae498eee03a25543b (patch)
treec582f59b5bf2a00363d17e4982f64997b9a4ce29 /src/libcamera/base/log.cpp
parentca5fb994091e7b3ba6db484ae0a58e2ecd00abbf (diff)
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>
Diffstat (limited to 'src/libcamera/base/log.cpp')
-rw-r--r--src/libcamera/base/log.cpp27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
index a3e3f9ea..64813b66 100644
--- a/src/libcamera/base/log.cpp
+++ b/src/libcamera/base/log.cpp
@@ -8,9 +8,6 @@
#include <libcamera/base/log.h>
#include <array>
-#if HAVE_BACKTRACE
-#include <execinfo.h>
-#endif
#include <fstream>
#include <iostream>
#include <list>
@@ -23,6 +20,7 @@
#include <libcamera/logging.h>
+#include <libcamera/base/backtrace.h>
#include <libcamera/base/thread.h>
#include <libcamera/base/utils.h>
@@ -418,31 +416,22 @@ void Logger::write(const LogMessage &msg)
*/
void Logger::backtrace()
{
-#if HAVE_BACKTRACE
std::shared_ptr<LogOutput> output = std::atomic_load(&output_);
if (!output)
return;
- void *buffer[32];
- int num_entries = ::backtrace(buffer, std::size(buffer));
- char **strings = backtrace_symbols(buffer, num_entries);
- if (!strings)
- return;
-
- std::ostringstream msg;
- msg << "Backtrace:" << std::endl;
-
/*
* Skip the first two entries that correspond to this function and
* ~LogMessage().
*/
- for (int i = 2; i < num_entries; ++i)
- msg << strings[i] << std::endl;
-
- output->write(msg.str());
+ std::string backtrace = Backtrace().toString(2);
+ if (backtrace.empty()) {
+ output->write("Backtrace not available\n");
+ return;
+ }
- free(strings);
-#endif
+ output->write("Backtrace:\n");
+ output->write(backtrace);
}
/**