1/* Copyright (C) 2007-2010 The Android Open Source Project
2**
3** This software is licensed under the terms of the GNU General Public
4** License version 2, as published by the Free Software Foundation, and
5** may be copied, distributed, and modified under those terms.
6**
7** This program is distributed in the hope that it will be useful,
8** but WITHOUT ANY WARRANTY; without even the implied warranty of
9** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10** GNU General Public License for more details.
11*/
12
13/*
14 * Contains implementation of routines that encapsulte an API for parsing
15 * an ELF file containing debugging information in DWARF format.
16 */
17
18#include "elff_api.h"
19#include "elf_file.h"
20#include "dwarf_defs.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26ELFF_HANDLE
27elff_init(const char* elf_file_path)
28{
29  ElfFile* elf_file = ElfFile::Create(elf_file_path);
30  return reinterpret_cast<ELFF_HANDLE>(elf_file);
31}
32
33void
34elff_close(ELFF_HANDLE handle)
35{
36  if (handle != NULL) {
37    delete reinterpret_cast<ElfFile*>(handle);
38  }
39}
40
41int
42elff_is_exec(ELFF_HANDLE handle)
43{
44  assert(handle != NULL);
45  if (handle == NULL) {
46    _set_errno(EINVAL);
47    return -1;
48  }
49  return reinterpret_cast<ElfFile*>(handle)->is_exec();
50}
51
52int
53elff_get_pc_address_info(ELFF_HANDLE handle,
54                         uint64_t address,
55                         Elf_AddressInfo* address_info)
56{
57  assert(handle != NULL && address_info != NULL);
58  if (handle == NULL || address_info == NULL) {
59    _set_errno(EINVAL);
60    return -1;
61  }
62
63  if (reinterpret_cast<ElfFile*>(handle)->get_pc_address_info(address,
64                                                              address_info)) {
65    return 0;
66  } else {
67    return -1;
68  }
69}
70
71void
72elff_free_pc_address_info(ELFF_HANDLE handle, Elf_AddressInfo* address_info)
73{
74  assert(handle != NULL && address_info != NULL);
75  if (handle == NULL || address_info == NULL) {
76    return;
77  }
78  reinterpret_cast<ElfFile*>(handle)->free_pc_address_info(address_info);
79}
80
81#ifdef __cplusplus
82}   /* end of extern "C" */
83#endif
84
85