2 * Copyright (c) 2009 Kai Wang
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include "_libdwarf.h"
29 ELFTC_VCSID("$Id: dwarf_pro_init.c 2074 2011-10-27 03:34:33Z jkoshy $");
32 dwarf_producer_init(Dwarf_Unsigned flags, Dwarf_Callback_Func func,
33 Dwarf_Handler errhand, Dwarf_Ptr errarg, Dwarf_Error *error)
38 if (flags & DW_DLC_READ || flags & DW_DLC_RDWR) {
39 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
40 return (DW_DLV_BADADDR);
43 if (flags & DW_DLC_WRITE)
46 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
47 return (DW_DLV_BADADDR);
51 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
52 return (DW_DLV_BADADDR);
55 if (_dwarf_alloc(&dbg, DW_DLC_WRITE, error) != DW_DLE_NONE)
56 return (DW_DLV_BADADDR);
60 if (_dwarf_init(dbg, flags, errhand, errarg, error) != DW_DLE_NONE) {
62 return (DW_DLV_BADADDR);
65 dbg->dbgp_func = func;
71 dwarf_producer_init_b(Dwarf_Unsigned flags, Dwarf_Callback_Func_b func,
72 Dwarf_Handler errhand, Dwarf_Ptr errarg, Dwarf_Error *error)
77 if (flags & DW_DLC_READ || flags & DW_DLC_RDWR) {
78 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
79 return (DW_DLV_BADADDR);
82 if (flags & DW_DLC_WRITE)
85 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
86 return (DW_DLV_BADADDR);
90 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
91 return (DW_DLV_BADADDR);
94 if (_dwarf_alloc(&dbg, DW_DLC_WRITE, error) != DW_DLE_NONE)
95 return (DW_DLV_BADADDR);
99 if (_dwarf_init(dbg, flags, errhand, errarg, error) != DW_DLE_NONE) {
101 return (DW_DLV_BADADDR);
104 dbg->dbgp_func_b = func;
110 dwarf_producer_set_isa(Dwarf_P_Debug dbg, enum Dwarf_ISA isa,
114 if (dbg == NULL || isa >= DW_ISA_MAX) {
115 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
116 return (DW_DLV_ERROR);