dwarf_line.c revision 49d3bc91e27cd871b950d56c01398fa2f2e12ab4
/*
Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. 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., 59 Temple Place - Suite 330, Boston MA 02111-1307,
USA.
Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky,
Mountain View, CA 94043, or:
For further information regarding this notice, see:
*/
#include "config.h"
#include "dwarf_incl.h"
#include <stdio.h>
#include "dwarf_line.h"
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
/*
Although source files is supposed to return the
source files in the compilation-unit, it does
not look for any in the statement program. In
other words, it ignores those defined using the
extended opcode DW_LNE_define_file.
*/
int
char ***srcfiles,
{
/*
This pointer is used to scan the portion of the .debug_line
section for the current cu. */
/*
This points to the last byte of the .debug_line portion for the
current cu. */
/*
This points to the end of the statement program prologue for the
current cu, and serves to check that the prologue was correctly
decoded. */
/*
Pointer to a DW_AT_stmt_list attribute in case it exists in the
die. */
/* Pointer to DW_AT_comp_dir attribute in die. */
/* Pointer to name of compilation directory. */
Dwarf_Small *comp_dir = 0;
/*
Offset into .debug_line specified by a DW_AT_stmt_list
attribute. */
/* Some of the fields of the statement program header. */
Dwarf_Half version = 0;
/* File name excluding included directory. */
char *file_name = 0;
/* Name of directory that the file is in. */
char *dir_name = 0;
/* Name concatenating both directory and file name. */
char *full_name = 0;
/*
This is the directory index for the file. The compilation
directory is 0, and the first included directory is 1. */
Dwarf_Sword dir_index = 0;
Dwarf_Sword i = 0;
Dwarf_Sword file_count = 0;
/*
This is the current opcode read from the statement program. */
/* This is the length of an extended opcode instr. */
/*
This points to a block of char *'s, each of which points to a
file name. */
char **ret_files = 0;
/* The Dwarf_Debug this die belongs to. */
/* Used to chain the file names. */
int resattr;
int lres;
int local_length_size = 0;
/*REFERENCED*/ /* Not used in this instance of the macro */
int local_extension_size = 0;
int res;
/* ***** BEGIN CODE ***** */
/* Reset error. */
return resattr;
}
if (dbg->de_debug_line_index == 0) {
return (DW_DLV_ERROR);
}
res =
&dbg->de_debug_line,
error);
return res;
}
return lres;
}
return (DW_DLV_ERROR);
}
/*
If die has DW_AT_comp_dir attribute, get the string that names
the compilation directory. */
if (resattr == DW_DLV_ERROR) {
return resattr;
}
int cres;
char *cdir;
if (cres == DW_DLV_ERROR) {
return cres;
}
}
}
/*
Following is a straightforward decoding of the statement
program prologue information. */
/* READ_AREA_LENGTH updates line_ptr for consumed bytes */
return (DW_DLV_ERROR);
}
line_ptr, sizeof(Dwarf_Half));
line_ptr += sizeof(Dwarf_Half);
if (version != CURRENT_VERSION_STAMP) {
return (DW_DLV_ERROR);
}
/* Skip over minimum instruction length. */
/* Skip over default_is_stmt. */
/* Skip over line_base. */
/* Skip over line_ptr. */
for (i = 1; i < special_opcode_base; i++) {
/* Skip over opcode lengths for standard opcodes. */
}
directories_count = 0;
while ((*(char *) line_ptr) != '\0') {
}
line_ptr++;
file_count = 0;
while (*(char *) line_ptr != '\0') {
if (dir_index > directories_count) {
return (DW_DLV_ERROR);
}
if (dir_index == 0)
else {
dir_name = (char *) include_directories;
for (i = 1; i < dir_index; i++)
/* FIX: this is probably very slow: redoing strlen!
davea 9/94 */
}
/* dir_name can be NULL if there is no DW_AT_comp_dir */
else {
1);
return (DW_DLV_ERROR);
}
}
/* Skip over time of last modification. */
/* Skip over file length. */
if (curr_chain == NULL) {
return (DW_DLV_ERROR);
}
if (head_chain == NULL)
else {
}
file_count++;
}
line_ptr++;
return (DW_DLV_ERROR);
}
if (file_count == 0) {
*srcfilecount = 0;
return (DW_DLV_NO_ENTRY);
}
ret_files = (char **)
return (DW_DLV_ERROR);
}
for (i = 0; i < file_count; i++) {
}
return (DW_DLV_OK);
}
/*
return DW_DLV_OK if ok. else DW_DLV_NO_ENTRY or DW_DLV_ERROR
*/
int
Dwarf_Line ** linebuf,
{
/*
This pointer is used to scan the portion of the .debug_line
section for the current cu. */
/*
This points to the last byte of the .debug_line portion for the
current cu. */
/*
This points to the end of the statement program prologue for the
current cu, and serves to check that the prologue was correctly
decoded. */
/*
Pointer to a DW_AT_stmt_list attribute in case it exists in the
die. */
/* Pointer to DW_AT_comp_dir attribute in die. */
/* Pointer to name of compilation directory. */
/*
Offset into .debug_line specified by a DW_AT_stmt_list
attribute. */
/* These are the fields of the statement program header. */
/* These are the state machine state variables. */
/*
These pointers are used to build the list of files names by
this cu. cur_file_entry points to the file name being added,
and prev_file_entry to the previous one. */
/*
This is the current opcode read from the statement program. */
/*
Pointer to a Dwarf_Line_Context_s structure that contains the
context such as file names and include directories for the set
of lines being generated. */
/*
This is a pointer to the current line being added to the line
matrix. */
/*
These variables are used to decode leb128 numbers. Leb128_num
holds the decoded number, and leb128_length is its length in
bytes. */
/*
This is the operand of the latest fixed_advance_pc extended
opcode. */
/*
Counts the number of lines in the line matrix. */
Dwarf_Sword line_count = 0;
/* This is the length of an extended opcode instr. */
/*
Used to chain together pointers to line table entries that are
later used to create a block of Dwarf_Line entries. */
/*
This points to a block of Dwarf_Lines, a pointer to which is
returned in linebuf. */
/* The Dwarf_Debug this die belongs to. */
int resattr;
int lres;
int local_length_size = 0;
/*REFERENCED*/ /* Not used in this instance of the macro */
int local_extension_size = 0;
int res;
/* ***** BEGIN CODE ***** */
res =
&dbg->de_debug_line,
error);
return res;
}
return resattr;
}
return lres;
}
return (DW_DLV_ERROR);
}
/*
If die has DW_AT_comp_dir attribute, get the string that names
the compilation directory. */
if (resattr == DW_DLV_ERROR) {
return resattr;
}
int cres;
char *cdir;
if (cres == DW_DLV_ERROR) {
return cres;
}
}
}
/*
Following is a straightforward decoding of the statement
program prologue information. */
/* READ_AREA_LENGTH updates line_ptr for consumed bytes */
return (DW_DLV_ERROR);
}
line_ptr, sizeof(Dwarf_Half));
line_ptr += sizeof(Dwarf_Half);
if (version != CURRENT_VERSION_STAMP) {
return (DW_DLV_ERROR);
}
opcode_length = (Dwarf_Small *)
for (i = 1; i < special_opcode_base; i++) {
}
while ((*(char *) line_ptr) != '\0') {
}
line_ptr++;
file_entry_count = 0;
while (*(char *) line_ptr != '\0') {
if (cur_file_entry == NULL) {
return (DW_DLV_ERROR);
}
if (file_entries == NULL)
else
}
line_ptr++;
return (DW_DLV_ERROR);
}
/* Set up context structure for this set of lines. */
if (line_context == NULL) {
return (DW_DLV_ERROR);
}
/* Initialize the state machine. */
address = 0;
file = 1;
line = 1;
column = 0;
basic_block = false;
end_sequence = false;
/* Start of statement program. */
while (line_ptr < line_ptr_end) {
int type;
line_ptr++;
/* 'type' is the output */
if (type == LOP_DISCARD) {
/* do nothing, necessary ops done */
} else if (type == LOP_SPECIAL) {
/* This op code is a special op in the object, no matter
that it might fall into the standard op range in this
compile Thatis, these are special opcodes between
special_opcode_base and MAX_LINE_OP_CODE. (including
special_opcode_base and MAX_LINE_OP_CODE) */
(opcode / line_range);
if (dolines) {
return (DW_DLV_ERROR);
}
(Dwarf_Sword) file;
(Dwarf_Sword) line;
(Dwarf_Half) column;
line_count++;
if (chain_line == NULL) {
return (DW_DLV_ERROR);
}
if (head_chain == NULL)
else {
}
}
basic_block = false;
} else if (type == LOP_STANDARD) {
switch (opcode) {
case DW_LNS_copy:{
if (opcode_length[DW_LNS_copy] != 0) {
return (DW_DLV_ERROR);
}
if (dolines) {
1);
return (DW_DLV_ERROR);
}
(Dwarf_Sword) file;
(Dwarf_Sword) line;
(Dwarf_Half) column;
line_count++;
if (chain_line == NULL) {
return (DW_DLV_ERROR);
}
if (head_chain == NULL)
else {
}
}
basic_block = false;
break;
}
case DW_LNS_advance_pc:{
return (DW_DLV_ERROR);
}
address =
address +
break;
}
case DW_LNS_advance_line:{
return (DW_DLV_ERROR);
}
break;
}
case DW_LNS_set_file:{
return (DW_DLV_ERROR);
}
break;
}
case DW_LNS_set_column:{
return (DW_DLV_ERROR);
}
break;
}
case DW_LNS_negate_stmt:{
if (opcode_length[DW_LNS_negate_stmt] != 0) {
return (DW_DLV_ERROR);
}
break;
}
case DW_LNS_set_basic_block:{
if (opcode_length[DW_LNS_set_basic_block] != 0) {
return (DW_DLV_ERROR);
}
basic_block = true;
break;
}
case DW_LNS_const_add_pc:{
(opcode / line_range);
break;
}
case DW_LNS_fixed_advance_pc:{
return (DW_DLV_ERROR);
}
line_ptr, sizeof(Dwarf_Half));
line_ptr += sizeof(Dwarf_Half);
break;
}
}
} else if (type == LOP_EXTENDED) {
/* Dwarf_Small is a ubyte and the extended opcode
is a ubyte, though not stated as clearly in
the 2.0.0 spec as one might hope.
*/
line_ptr++;
switch (ext_opcode) {
case DW_LNE_end_sequence:{
end_sequence = true;
if (dolines) {
curr_line = (Dwarf_Line)
return (DW_DLV_ERROR);
}
(Dwarf_Sword) file;
(Dwarf_Sword) line;
(Dwarf_Half) column;
line_count++;
if (chain_line == NULL) {
return (DW_DLV_ERROR);
}
if (head_chain == NULL)
else {
}
}
address = 0;
file = 1;
line = 1;
column = 0;
basic_block = false;
end_sequence = false;
break;
}
case DW_LNE_set_address:{
if (doaddrs) {
1);
return (DW_DLV_ERROR);
}
line_count++;
if (chain_line == NULL) {
return (DW_DLV_ERROR);
}
if (head_chain == NULL)
else {
}
}
} else {
return (DW_DLV_ERROR);
}
break;
}
case DW_LNE_define_file:{
if (dolines) {
if (cur_file_entry == NULL) {
return (DW_DLV_ERROR);
}
(Dwarf_Small *) line_ptr;
line_ptr =
if (file_entries == NULL)
else
}
break;
}
default:{
return (DW_DLV_ERROR);
}
}
}
}
block_line = (Dwarf_Line *)
if (block_line == NULL) {
return (DW_DLV_ERROR);
}
for (i = 0; i < line_count; i++) {
}
*count = line_count;
*linebuf = block_line;
return (DW_DLV_OK);
}
int
Dwarf_Line ** linebuf,
{
int res;
&count, /* addrlist= */ false,
/* linelist= */ true, error);
return res;
}
return res;
}
int
{
return (DW_DLV_ERROR);
}
return DW_DLV_OK;
}
int
{
return (DW_DLV_ERROR);
}
return DW_DLV_OK;
}
int
{
return (DW_DLV_ERROR);
}
return DW_DLV_OK;
}
int
{
return (DW_DLV_ERROR);
}
return DW_DLV_OK;
}
int
{
return (DW_DLV_ERROR);
}
*ret_lineoff =
return DW_DLV_OK;
}
int
{
Dwarf_Signed i;
unsigned int comp_dir_len;
return (DW_DLV_ERROR);
}
return (DW_DLV_ERROR);
}
return (DW_DLV_ERROR);
}
return (DW_DLV_ERROR);
}
return DW_DLV_OK;
}
if (file_entry->fi_dir_index == 0) {
/* dir_index of 0 means that the compilation was in the
'current directory of compilation' */
/* we don't actually *have* a current directory of
compilation: DW_AT_comp_dir was not present Rather than
emitting DW_DLE_NO_COMP_DIR lets just make an empty name
here. In other words, do the best we can with what we do
have instead of reporting an error. _dwarf_error(dbg,
error, DW_DLE_NO_COMP_DIR); return(DW_DLV_ERROR); */
comp_dir_len = 0;
} else {
comp_dir_len = strlen((char *)
(line->li_context->
}
comp_dir_len + 1 +
1);
if (name_buffer == NULL) {
return (DW_DLV_ERROR);
}
if (comp_dir_len > 0) {
/* if comp_dir_len is 0 we do not want to put a / in front
of the fi_file_name as we just don't know anything. */
strcpy((char *) name_buffer,
(char *) (line->li_context->
}
*ret_linesrc = ((char *) name_buffer);
return DW_DLV_OK;
}
if (file_entry->fi_dir_index >
return (DW_DLV_ERROR);
}
comp_dir_len = strlen((char *)
(line->li_context->
} else {
/* No DW_AT_comp_dir present. Do the best we can without it. */
comp_dir_len = 0;
}
(*include_directories == '/' ?
0 : comp_dir_len + 1) +
strlen((char *) include_directories)
+ 1 +
strlen((char *) file_entry->
fi_file_name) + 1);
if (name_buffer == NULL) {
return (DW_DLV_ERROR);
}
if (*include_directories != '/') {
if (comp_dir_len > 0) {
strcpy((char *) name_buffer,
/* Who provides the / needed after the compilation
directory? */
/* Here we provide the / separator */
previous nul
terminator
with needed
/ */
}
}
} else {
}
*ret_linesrc = ((char *) name_buffer);
return DW_DLV_OK;
}
int
{
return (DW_DLV_ERROR);
}
return DW_DLV_OK;
}
#if 0 /* Ignore this. This needs major
re-work. */
/*
This routine works by looking for exact matches between
the current line address and pc, and crossovers from
from less than pc value to greater than. At each line
that satisfies the above, it records a pointer to the
line, and the difference between the address and pc.
It then scans these pointers and picks out those with
the smallest difference between pc and address.
*/
int
Dwarf_Line ** linebuf,
{
/*
Scans the line matrix for the current cu to which a pointer
exists in dbg. */
/*
These flags are for efficiency reasons. Check_line is true
initially, but set false when the address of the current line
is greater than pc. It is set true only when the address of the
current line falls below pc. This assumes that addresses
within the same segment increase, and we are only interested in
the switch from a less than pc address to a greater than.
First_line is set true initially, but set false after the first
line is scanned. This is to prevent looking at the address of
previous line when slide is DW_DLS_BACKWARD, and the first line
is being scanned. */
/*
Diff tracks the smallest difference a line address and the
input pc value. */
Dwarf_Signed diff, i;
/*
For the slide = DW_DLS_BACKWARD case, pc_less is the value of
the address of the line immediately preceding the first line
that has value greater than pc. For the slide = DW_DLS_FORWARD
case, pc_more is the values of address for the first line that
is greater than pc. Diff is the difference between either of
the these values and pc. */
/*
Pc_line_buf points to a chain of pointers to lines of which
those with a diff equal to the smallest difference will be
returned. */
/*
Chain_count counts the number of lines in the above chain for
which the diff is equal to the smallest difference This is the
number returned by this routine. */
chain_head = NULL;
check_line = true;
first_line = true;
for (i = 0; i < dbg->de_cu_line_count; i++) {
return (DW_DLV_ERROR);
}
} else
/*
Look for crossover from less than pc address to greater
than. */
return (DW_DLV_ERROR);
}
}
check_line = false;
} else if (slide == DW_DLS_FORWARD) {
return (DW_DLV_ERROR);
}
}
check_line = false;
} else
/* Check addresses only when they go */
/* below pc. */
check_line = true;
first_line = false;
}
chain_count = 0;
chain_count++;
pc_line++;
}
}
*linebuf = pc_line_buf;
return (chain_count);
}
#endif
/*
Return DW_DLV_OK or, if error,
DW_DLV_ERROR.
Thru pointers, return 2 arrays and a count
for rqs.
*/
int
Dwarf_Addr ** addrs,
Dwarf_Error * err)
{
Dwarf_Signed i;
int res;
&lcount, /* addrlist= */ true,
/* linelist= */ false, err);
return res;
}
laddrs = (Dwarf_Addr *)
return (DW_DLV_ERROR);
}
return (DW_DLV_ERROR);
}
for (i = 0; i < lcount; i++) {
}
*returncount = lcount;
return DW_DLV_OK;
}