1*2de3b87aSKai Wang /*-
2*2de3b87aSKai Wang * Copyright (c) 2009 Kai Wang
3*2de3b87aSKai Wang * All rights reserved.
4*2de3b87aSKai Wang *
5*2de3b87aSKai Wang * Redistribution and use in source and binary forms, with or without
6*2de3b87aSKai Wang * modification, are permitted provided that the following conditions
7*2de3b87aSKai Wang * are met:
8*2de3b87aSKai Wang * 1. Redistributions of source code must retain the above copyright
9*2de3b87aSKai Wang * notice, this list of conditions and the following disclaimer.
10*2de3b87aSKai Wang * 2. Redistributions in binary form must reproduce the above copyright
11*2de3b87aSKai Wang * notice, this list of conditions and the following disclaimer in the
12*2de3b87aSKai Wang * documentation and/or other materials provided with the distribution.
13*2de3b87aSKai Wang *
14*2de3b87aSKai Wang * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*2de3b87aSKai Wang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*2de3b87aSKai Wang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*2de3b87aSKai Wang * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*2de3b87aSKai Wang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*2de3b87aSKai Wang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*2de3b87aSKai Wang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*2de3b87aSKai Wang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*2de3b87aSKai Wang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*2de3b87aSKai Wang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*2de3b87aSKai Wang * SUCH DAMAGE.
25*2de3b87aSKai Wang */
26*2de3b87aSKai Wang
27*2de3b87aSKai Wang #include "_libdwarf.h"
28*2de3b87aSKai Wang
29*2de3b87aSKai Wang ELFTC_VCSID("$Id: dwarf_pro_init.c 2074 2011-10-27 03:34:33Z jkoshy $");
30*2de3b87aSKai Wang
31*2de3b87aSKai Wang Dwarf_P_Debug
dwarf_producer_init(Dwarf_Unsigned flags,Dwarf_Callback_Func func,Dwarf_Handler errhand,Dwarf_Ptr errarg,Dwarf_Error * error)32*2de3b87aSKai Wang dwarf_producer_init(Dwarf_Unsigned flags, Dwarf_Callback_Func func,
33*2de3b87aSKai Wang Dwarf_Handler errhand, Dwarf_Ptr errarg, Dwarf_Error *error)
34*2de3b87aSKai Wang {
35*2de3b87aSKai Wang Dwarf_P_Debug dbg;
36*2de3b87aSKai Wang int mode;
37*2de3b87aSKai Wang
38*2de3b87aSKai Wang if (flags & DW_DLC_READ || flags & DW_DLC_RDWR) {
39*2de3b87aSKai Wang DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
40*2de3b87aSKai Wang return (DW_DLV_BADADDR);
41*2de3b87aSKai Wang }
42*2de3b87aSKai Wang
43*2de3b87aSKai Wang if (flags & DW_DLC_WRITE)
44*2de3b87aSKai Wang mode = DW_DLC_WRITE;
45*2de3b87aSKai Wang else {
46*2de3b87aSKai Wang DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
47*2de3b87aSKai Wang return (DW_DLV_BADADDR);
48*2de3b87aSKai Wang }
49*2de3b87aSKai Wang
50*2de3b87aSKai Wang if (func == NULL) {
51*2de3b87aSKai Wang DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
52*2de3b87aSKai Wang return (DW_DLV_BADADDR);
53*2de3b87aSKai Wang }
54*2de3b87aSKai Wang
55*2de3b87aSKai Wang if (_dwarf_alloc(&dbg, DW_DLC_WRITE, error) != DW_DLE_NONE)
56*2de3b87aSKai Wang return (DW_DLV_BADADDR);
57*2de3b87aSKai Wang
58*2de3b87aSKai Wang dbg->dbg_mode = mode;
59*2de3b87aSKai Wang
60*2de3b87aSKai Wang if (_dwarf_init(dbg, flags, errhand, errarg, error) != DW_DLE_NONE) {
61*2de3b87aSKai Wang free(dbg);
62*2de3b87aSKai Wang return (DW_DLV_BADADDR);
63*2de3b87aSKai Wang }
64*2de3b87aSKai Wang
65*2de3b87aSKai Wang dbg->dbgp_func = func;
66*2de3b87aSKai Wang
67*2de3b87aSKai Wang return (dbg);
68*2de3b87aSKai Wang }
69*2de3b87aSKai Wang
70*2de3b87aSKai Wang Dwarf_P_Debug
dwarf_producer_init_b(Dwarf_Unsigned flags,Dwarf_Callback_Func_b func,Dwarf_Handler errhand,Dwarf_Ptr errarg,Dwarf_Error * error)71*2de3b87aSKai Wang dwarf_producer_init_b(Dwarf_Unsigned flags, Dwarf_Callback_Func_b func,
72*2de3b87aSKai Wang Dwarf_Handler errhand, Dwarf_Ptr errarg, Dwarf_Error *error)
73*2de3b87aSKai Wang {
74*2de3b87aSKai Wang Dwarf_P_Debug dbg;
75*2de3b87aSKai Wang int mode;
76*2de3b87aSKai Wang
77*2de3b87aSKai Wang if (flags & DW_DLC_READ || flags & DW_DLC_RDWR) {
78*2de3b87aSKai Wang DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
79*2de3b87aSKai Wang return (DW_DLV_BADADDR);
80*2de3b87aSKai Wang }
81*2de3b87aSKai Wang
82*2de3b87aSKai Wang if (flags & DW_DLC_WRITE)
83*2de3b87aSKai Wang mode = DW_DLC_WRITE;
84*2de3b87aSKai Wang else {
85*2de3b87aSKai Wang DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
86*2de3b87aSKai Wang return (DW_DLV_BADADDR);
87*2de3b87aSKai Wang }
88*2de3b87aSKai Wang
89*2de3b87aSKai Wang if (func == NULL) {
90*2de3b87aSKai Wang DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
91*2de3b87aSKai Wang return (DW_DLV_BADADDR);
92*2de3b87aSKai Wang }
93*2de3b87aSKai Wang
94*2de3b87aSKai Wang if (_dwarf_alloc(&dbg, DW_DLC_WRITE, error) != DW_DLE_NONE)
95*2de3b87aSKai Wang return (DW_DLV_BADADDR);
96*2de3b87aSKai Wang
97*2de3b87aSKai Wang dbg->dbg_mode = mode;
98*2de3b87aSKai Wang
99*2de3b87aSKai Wang if (_dwarf_init(dbg, flags, errhand, errarg, error) != DW_DLE_NONE) {
100*2de3b87aSKai Wang free(dbg);
101*2de3b87aSKai Wang return (DW_DLV_BADADDR);
102*2de3b87aSKai Wang }
103*2de3b87aSKai Wang
104*2de3b87aSKai Wang dbg->dbgp_func_b = func;
105*2de3b87aSKai Wang
106*2de3b87aSKai Wang return (dbg);
107*2de3b87aSKai Wang }
108*2de3b87aSKai Wang
109*2de3b87aSKai Wang int
dwarf_producer_set_isa(Dwarf_P_Debug dbg,enum Dwarf_ISA isa,Dwarf_Error * error)110*2de3b87aSKai Wang dwarf_producer_set_isa(Dwarf_P_Debug dbg, enum Dwarf_ISA isa,
111*2de3b87aSKai Wang Dwarf_Error *error)
112*2de3b87aSKai Wang {
113*2de3b87aSKai Wang
114*2de3b87aSKai Wang if (dbg == NULL || isa >= DW_ISA_MAX) {
115*2de3b87aSKai Wang DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
116*2de3b87aSKai Wang return (DW_DLV_ERROR);
117*2de3b87aSKai Wang }
118*2de3b87aSKai Wang
119*2de3b87aSKai Wang dbg->dbgp_isa = isa;
120*2de3b87aSKai Wang
121*2de3b87aSKai Wang return (DW_DLV_OK);
122*2de3b87aSKai Wang }
123