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