| 1 |
/* |
| 2 |
Copyright 2015-2016 David Anderson. All rights reserved. |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of version 2 of the GNU General |
| 6 |
Public License as published by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it would be |
| 9 |
useful, but WITHOUT ANY WARRANTY; without even the implied |
| 10 |
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 11 |
PURPOSE. |
| 12 |
|
| 13 |
Further, this software is distributed without any warranty |
| 14 |
that it is free of the rightful claim of any third person |
| 15 |
regarding infringement or the like. Any license provided |
| 16 |
herein, whether implied or otherwise, applies only to this |
| 17 |
software file. Patent licenses, if any, provided herein |
| 18 |
do not apply to combinations of this program with other |
| 19 |
software, or any other product whatsoever. |
| 20 |
|
| 21 |
You should have received a copy of the GNU General Public |
| 22 |
License along with this program; if not, write the Free |
| 23 |
Software Foundation, Inc., 51 Franklin Street - Fifth Floor, |
| 24 |
Boston MA 02110-1301, USA. |
| 25 |
|
| 26 |
*/ |
| 27 |
#ifndef MACROCHECK_H |
| 28 |
#define MACROCHECK_H |
| 29 |
|
| 30 |
/* tsearch trees used in macro checking. */ |
| 31 |
extern void * macro_check_tree; /* DWARF5 macros. */ |
| 32 |
extern void * macinfo_check_tree; /* DWARF2,3,4 macros */ |
| 33 |
extern void * macdefundeftree; /* DWARF5 style macros */ |
| 34 |
|
| 35 |
struct Macrocheck_Map_Entry_s { |
| 36 |
Dwarf_Unsigned mp_key; /* Key is offset */ |
| 37 |
Dwarf_Unsigned mp_len; /* len in bytes off this macro set */ |
| 38 |
|
| 39 |
/* We count number of uses. More than 1 primary is an error. |
| 40 |
Both primary and secondary is ok or error? */ |
| 41 |
Dwarf_Unsigned mp_refcount_primary; |
| 42 |
Dwarf_Unsigned mp_refcount_secondary; |
| 43 |
Dwarf_Unsigned mp_import_linenum; |
| 44 |
unsigned mp_import_from_filenum; |
| 45 |
|
| 46 |
/* So we go through each one just once. */ |
| 47 |
Dwarf_Bool mp_printed; |
| 48 |
}; |
| 49 |
/* for def/undef checking. */ |
| 50 |
struct macdef_entry_s { |
| 51 |
char * md_key; /* Tacked on this record. Do not free */ |
| 52 |
unsigned md_operatornum; |
| 53 |
unsigned int md_defined; |
| 54 |
unsigned int md_undefined; |
| 55 |
unsigned int md_defcount; |
| 56 |
unsigned int md_undefcount; |
| 57 |
unsigned md_operator; |
| 58 |
Dwarf_Unsigned md_line; |
| 59 |
Dwarf_Unsigned md_offset; |
| 60 |
Dwarf_Unsigned md_macro_unit_offset; |
| 61 |
char * md_string; /* see create entry. Do not free */ |
| 62 |
unsigned md_file_array_entry; |
| 63 |
}; |
| 64 |
typedef struct macdef_entry_s macdef_entry; |
| 65 |
|
| 66 |
/* for start-file end-file checking. */ |
| 67 |
struct macfile_entry_s { |
| 68 |
unsigned ms_operatornum; |
| 69 |
unsigned ms_operator; |
| 70 |
Dwarf_Unsigned ms_line; |
| 71 |
Dwarf_Unsigned ms_filenum; |
| 72 |
Dwarf_Unsigned ms_offset; |
| 73 |
Dwarf_Unsigned ms_macro_unit_offset; |
| 74 |
unsigned ms_array_number; /* position in macfile_array */ |
| 75 |
char * ms_filename; |
| 76 |
}; |
| 77 |
typedef struct macfile_entry_s macfile_entry; |
| 78 |
#define MACFILE_STACK_DEPTH_MAX 50 /* Arbitrary. Make bigger? */ |
| 79 |
extern unsigned macfile_stack_next_to_use; |
| 80 |
extern unsigned macfile_stack[MACFILE_STACK_DEPTH_MAX+1]; |
| 81 |
extern unsigned macfile_stack_max_seen; |
| 82 |
|
| 83 |
#define MACRO_IMPORT_STACK_DEPTH 20 /* Arbitrary. Make bigger? */ |
| 84 |
extern Dwarf_Unsigned macro_import_stack[MACRO_IMPORT_STACK_DEPTH +1]; |
| 85 |
extern unsigned macro_import_stack_next_to_use; |
| 86 |
extern unsigned macro_import_stack_max_seen; |
| 87 |
/* Returns DW_DLV_ERROR if the push could not done, |
| 88 |
which would be because full. |
| 89 |
Else returns DW_DLV_OK. */ |
| 90 |
int macro_import_stack_push(Dwarf_Unsigned offset); |
| 91 |
|
| 92 |
/* Returns DW_DLV_ERROR if the pop could not done, |
| 93 |
else returns DW_DLV_OK. */ |
| 94 |
int macro_import_stack_pop(void); |
| 95 |
|
| 96 |
/* Returns DW_DLV_OK if offset is in the stack or |
| 97 |
DW_DLV_NO_ENTRY if it is not in the stack. */ |
| 98 |
int macro_import_stack_present(Dwarf_Unsigned offset); |
| 99 |
|
| 100 |
void macro_import_stack_cleanout(void); |
| 101 |
void print_macro_import_stack(void); |
| 102 |
|
| 103 |
struct Macrocheck_Map_Entry_s * macrocheck_map_find( |
| 104 |
Dwarf_Unsigned offset, |
| 105 |
void **map); |
| 106 |
void add_macro_import(void **base,Dwarf_Bool is_primary, |
| 107 |
Dwarf_Unsigned offset, |
| 108 |
Dwarf_Unsigned linenum, |
| 109 |
unsigned mafile_file_number); |
| 110 |
void add_macro_area_len(void **base, Dwarf_Unsigned offset, |
| 111 |
Dwarf_Unsigned len); |
| 112 |
|
| 113 |
void print_split_macro_value(const char *name_in); |
| 114 |
|
| 115 |
int get_next_unprinted_macro_offset(void **base, |
| 116 |
Dwarf_Unsigned * off); |
| 117 |
void mark_macro_offset_printed(void **base, Dwarf_Unsigned offset); |
| 118 |
|
| 119 |
int print_macrocheck_statistics(const char *name,void **basep, |
| 120 |
int isdwarf5, |
| 121 |
Dwarf_Unsigned section_size); |
| 122 |
void clear_macrocheck_statistics(void **basep); |
| 123 |
|
| 124 |
macfile_entry * macfile_from_array_index( unsigned index); |
| 125 |
|
| 126 |
#endif /* MACROCHECK_H */ |