Christopher Ferris | 7fb2287 | 2013-09-27 12:43:15 -0700 | [diff] [blame^] | 1 | /* |
| 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 | #include <backtrace/backtrace.h> |
| 18 | |
| 19 | #include "common.h" |
| 20 | #include "unwind.h" |
| 21 | |
| 22 | bool backtrace_get_data(backtrace_t* backtrace, pid_t tid) { |
| 23 | backtrace->num_frames = 0; |
| 24 | backtrace->tid = tid; |
| 25 | |
| 26 | backtrace->map_info_list = backtrace_create_map_info_list(tid); |
| 27 | if (tid < 0) { |
| 28 | return local_get_data(backtrace); |
| 29 | } else { |
| 30 | return remote_get_data(backtrace); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /* Free any memory related to the frame data. */ |
| 35 | void backtrace_free_data(backtrace_t* backtrace) { |
| 36 | free_frame_data(backtrace); |
| 37 | |
| 38 | if (backtrace->map_info_list) { |
| 39 | backtrace_destroy_map_info_list(backtrace->map_info_list); |
| 40 | backtrace->map_info_list = NULL; |
| 41 | } |
| 42 | |
| 43 | if (backtrace->tid < 0) { |
| 44 | local_free_data(backtrace); |
| 45 | } else { |
| 46 | remote_free_data(backtrace); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | char* backtrace_get_proc_name(const backtrace_t* backtrace, uintptr_t pc, |
| 51 | uintptr_t* offset) { |
| 52 | if (backtrace->tid < 0) { |
| 53 | return local_get_proc_name(backtrace, pc, offset); |
| 54 | } else { |
| 55 | return remote_get_proc_name(backtrace, pc, offset); |
| 56 | } |
| 57 | } |