2 * Copyright (c) 2010 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_macinfo.c 2074 2011-10-27 03:34:33Z jkoshy $");
32 _dwarf_add_macro(Dwarf_P_Debug dbg, int type, Dwarf_Unsigned lineno,
33 Dwarf_Signed fileindex, char *str1, char *str2, Dwarf_Error *error)
35 Dwarf_Macro_Details *md;
38 dbg->dbgp_mdlist = realloc(dbg->dbgp_mdlist,
39 (size_t) dbg->dbgp_mdcnt + 1);
40 if (dbg->dbgp_mdlist == NULL) {
41 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
42 return (DW_DLV_ERROR);
45 md = &dbg->dbgp_mdlist[dbg->dbgp_mdcnt];
50 md->dmd_lineno = lineno;
51 md->dmd_fileindex = fileindex;
56 else if (str2 == NULL) {
57 if ((md->dmd_macro = strdup(str1)) == NULL) {
59 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
60 return (DW_DLV_ERROR);
64 len = strlen(str1) + strlen(str2) + 2;
65 if ((md->dmd_macro = malloc(len)) == NULL) {
67 DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
68 return (DW_DLV_ERROR);
70 snprintf(md->dmd_macro, len, "%s %s", str1, str2);
76 dwarf_def_macro(Dwarf_P_Debug dbg, Dwarf_Unsigned lineno, char *name,
77 char *value, Dwarf_Error *error)
80 if (dbg == NULL || name == NULL) {
81 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
82 return (DW_DLV_ERROR);
85 return (_dwarf_add_macro(dbg, DW_MACINFO_define, lineno, -1, name,
90 dwarf_undef_macro(Dwarf_P_Debug dbg, Dwarf_Unsigned lineno, char *name,
94 if (dbg == NULL || name == NULL) {
95 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
96 return (DW_DLV_ERROR);
99 return (_dwarf_add_macro(dbg, DW_MACINFO_undef, lineno, -1, name,
104 dwarf_start_macro_file(Dwarf_P_Debug dbg, Dwarf_Unsigned lineno,
105 Dwarf_Unsigned fileindex, Dwarf_Error *error)
109 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
110 return (DW_DLV_ERROR);
113 return (_dwarf_add_macro(dbg, DW_MACINFO_start_file, lineno, fileindex,
118 dwarf_end_macro_file(Dwarf_P_Debug dbg, Dwarf_Error *error)
122 DWARF_SET_ERROR(NULL, error, DW_DLE_ARGUMENT);
123 return (DW_DLV_ERROR);
126 return (_dwarf_add_macro(dbg, DW_MACINFO_end_file, 0, -1,
131 dwarf_vendor_ext(Dwarf_P_Debug dbg, Dwarf_Unsigned constant, char *string,
135 if (dbg == NULL || string == NULL) {
136 DWARF_SET_ERROR(dbg, error, DW_DLE_ARGUMENT);
137 return (DW_DLV_ERROR);
140 return (_dwarf_add_macro(dbg, DW_MACINFO_vendor_ext, constant, -1,
141 string, NULL, error));