07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Portions Copyright (C) 2007-2010 David Anderson. All Rights Reserved.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe This program is free software; you can redistribute it and/or modify it
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe under the terms of version 2.1 of the GNU Lesser General Public License
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe as published by the Free Software Foundation.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe This program is distributed in the hope that it would be useful, but
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe WITHOUT ANY WARRANTY; without even the implied warranty of
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe Further, this software is distributed without any warranty that it is
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe free of the rightful claim of any third person regarding infringement
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe or the like. Any license provided herein, whether implied or
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe otherwise, applies only to this software file. Patent licenses, if
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe any, provided herein do not apply to combinations of this program with
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe other software, or any other product whatsoever.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe You should have received a copy of the GNU Lesser General Public
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe License along with this program; if not, write the Free Software
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe Mountain View, CA 94043, or:
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe For further information regarding this notice, see:
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe http://oss.sgi.com/projects/GenInfo/NoticeExplan
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe/* The address of the Free Software Foundation is
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Boston, MA 02110-1301, USA.
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe SGI has moved from the Crittenden Lane address.
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe#endif /* HAVE_STDLIB_H */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Given the dwarf macro string, return a pointer to
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe the value. Returns pointer to 0 byte at end of string
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if no value found (meaning the value is the empty string).
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Only understands well-formed dwarf macinfo strings.
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* lcp+1 must be a space, and following char is the value */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* we allow extraneous spaces inside macro parameter **
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe list, just in case... This is not really needed. */
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe /* never found value: returns pointer to the 0 byte at end of
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe Try to keep fileindex correct in every Macro_Details
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe record by tracking file starts and ends.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe Uses high water mark: space reused, not freed.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe Presumption is that this makes sense for most uses.
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe STARTERMAX is set so that the array need not be expanded for
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe most files: it is the initial include file depth.
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowestatic void _dwarf_reset_index_macro_stack(struct macro_stack_s *ms);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowefree_macro_stack(Dwarf_Debug dbg, struct macro_stack_s *ms)
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe_dwarf_reset_index_macro_stack(struct macro_stack_s *ms)
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe_dwarf_macro_stack_push_index(Dwarf_Debug dbg, Dwarf_Signed indx,
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* just leave the old array in place */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe dwarf_dealloc(dbg, ms->st_base, DW_DLA_STRING);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe_dwarf_macro_stack_pop_index(struct macro_stack_s *ms)
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe/* starting at macro_offset in .debug_macinfo,
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if maximum_count is 0, treat as if it is infinite.
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe get macro data up thru
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe maximum_count entries or the end of a compilation
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe unit's entries (whichever comes first).
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* By section 6.3.2 Dwarf3 draft 8/9,
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe the base file should appear as
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe DW_MACINFO_start_file. See
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe http://gcc.gnu.org/ml/gcc-bugs/2005-02/msg03442.html
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe on "[Bug debug/20253] New: [3.4/4.0 regression]:
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Macro debug info broken due to lexer change" for how
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe gcc is broken in some versions. We no longer use
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe depth as a stopping point, it's not needed as a
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe stopping point anyway. */
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe /* count space used by strings */
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe unsigned long max_count = (unsigned long) maximum_count;
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe res = _dwarf_load_section(dbg, &dbg->de_debug_macinfo,error);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (macro_offset >= dbg->de_debug_macinfo.dss_size) {
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe /* how many entries and how much space will they take? */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (endloc >= dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (endloc == dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* normal: found last entry */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_LENGTH_BAD);
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe for (count = 0; !done && count < max_count; ++count) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* line, string */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* number, string */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (((pnext - macro_base)) >= dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (((pnext - macro_base)) >= dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* line, file index */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (((pnext - macro_base)) >= dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (((pnext - macro_base)) >= dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (--depth == 0) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* done = 1; no, do not stop here, at least one gcc had
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe the wrong depth settings in the gcc 3.4 timeframe. */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe break; /* no string or number here */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* end of cu's entries */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_INCONSISTENT);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* bogus macinfo! */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (endloc == dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe } else if (endloc > dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_LENGTH_BAD);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_INTERNAL_ERR);
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe /* we have 'count' array entries to allocate and str_space bytes of
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe string space to provide for. */
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe string_offset = count * sizeof(Dwarf_Macro_Details);
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe /* extra 2 not really needed */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe _dwarf_get_alloc(dbg, DW_DLA_STRING, space_needed);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_MALLOC_SPACE);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* A series ends with a type code of 0. */
49d3bc91e27cd871b950d56c01398fa2f2e12ab4Richard Lowe for (final_count = 0; !done && final_count < count; ++final_count) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe Dwarf_Macro_Details *pdmd = (Dwarf_Macro_Details *) (pdata +
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_LENGTH_BAD);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* line, string */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* number, string */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (((pnext - macro_base)) >= dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe strcpy((char *) latest_str_loc, (char *) pnext);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (((pnext - macro_base)) >= dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* Line, file index */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (((pnext - macro_base)) >= dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe (void) _dwarf_macro_stack_push_index(dbg, fileindex,
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* We ignore the error, we just let fileindex ** be -1 when
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe we pop this one. */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe if (((pnext - macro_base)) >= dbg->de_debug_macinfo.dss_size) {
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe fileindex = _dwarf_macro_stack_pop_index(&msdata);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe break; /* no string or number here */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* Type code of 0 means the end of cu's entries. */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe /* Bogus macinfo! */
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe dwarf_dealloc(dbg, return_data, DW_DLA_STRING);
07dc1947c362e187fb955d283b692f8769dd5defRichard Lowe _dwarf_error(dbg, error, DW_DLE_DEBUG_MACRO_INCONSISTENT);