blob: 3656104b00f6efcc6ba70a9ce73631ef3709258b [file] [log] [blame]
Christopher Ferris17e91d42013-10-21 13:30:52 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _LIBBACKTRACE_UNWIND_CURRENT_H
18#define _LIBBACKTRACE_UNWIND_CURRENT_H
19
Christopher Ferris2c43cff2015-03-26 19:18:36 -070020#include <stdint.h>
21#include <sys/types.h>
22#include <ucontext.h>
23
Christopher Ferris17e91d42013-10-21 13:30:52 -070024#include <string>
25
Christopher Ferris2c43cff2015-03-26 19:18:36 -070026#include <backtrace/Backtrace.h>
27#include <backtrace/BacktraceMap.h>
28
29#include "BacktraceCurrent.h"
Christopher Ferris17e91d42013-10-21 13:30:52 -070030
31#define UNW_LOCAL_ONLY
32#include <libunwind.h>
33
Christopher Ferris2c43cff2015-03-26 19:18:36 -070034class UnwindCurrent : public BacktraceCurrent {
Christopher Ferris82f3bbd2017-03-14 15:22:26 -070035 public:
Christopher Ferris2c43cff2015-03-26 19:18:36 -070036 UnwindCurrent(pid_t pid, pid_t tid, BacktraceMap* map) : BacktraceCurrent(pid, tid, map) {}
37 virtual ~UnwindCurrent() {}
Christopher Ferris17e91d42013-10-21 13:30:52 -070038
Christopher Ferris2c43cff2015-03-26 19:18:36 -070039 std::string GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) override;
Christopher Ferris17e91d42013-10-21 13:30:52 -070040
Christopher Ferris82f3bbd2017-03-14 15:22:26 -070041 private:
Christopher Ferris2c43cff2015-03-26 19:18:36 -070042 void GetUnwContextFromUcontext(const ucontext_t* ucontext);
Christopher Ferris17e91d42013-10-21 13:30:52 -070043
Christopher Ferris2c43cff2015-03-26 19:18:36 -070044 bool UnwindFromContext(size_t num_ignore_frames, ucontext_t* ucontext) override;
Christopher Ferris17e91d42013-10-21 13:30:52 -070045
Christopher Ferris17e91d42013-10-21 13:30:52 -070046 unw_context_t context_;
Christopher Ferris82f3bbd2017-03-14 15:22:26 -070047
48 bool initialized_ = false;
Christopher Ferris17e91d42013-10-21 13:30:52 -070049};
50
Christopher Ferris17e91d42013-10-21 13:30:52 -070051#endif // _LIBBACKTRACE_UNWIND_CURRENT_H