1 : /*
2 : * OpenBIOS - free your system!
3 : * ( FCode tokenizer )
4 : *
5 : * This program is part of a free implementation of the IEEE 1275-1994
6 : * Standard for Boot (Initialization Configuration) Firmware.
7 : *
8 : * Copyright (C) 2001-2005 Stefan Reinauer, <stepan@openbios.org>
9 : *
10 : * This program is free software; you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License as published by
12 : * the Free Software Foundation; version 2 of the License.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program; if not, write to the Free Software
21 : * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
22 : *
23 : */
24 :
25 : /* **************************************************************************
26 : *
27 : * Support routines for "Trace-Symbols" debugging feature
28 : *
29 : * (C) Copyright 2006 IBM Corporation. All Rights Reserved.
30 : * Module Author: David L. Paktor dlpaktor@us.ibm.com
31 : *
32 : **************************************************************************** */
33 :
34 : /* **************************************************************************
35 : *
36 : * Functions Exported:
37 : * add_to_trace_list Add the given name to the Trace List
38 : * show_initial_traces Show pre-defined names the user
39 : * asked to Trace (if any)
40 : * is_on_trace_list Indicate whether the given name is
41 : * on the Trace List
42 : *
43 : **************************************************************************** */
44 :
45 : #include <string.h>
46 :
47 : #include "tracesyms.h"
48 : #include "errhandler.h"
49 :
50 :
51 : /* **************************************************************************
52 : *
53 : * Internal Static Variables
54 : * trace_list Pointer to last entry in the Trace List linked-list
55 : * data structure
56 : *
57 : *
58 : *
59 : **************************************************************************** */
60 :
61 : /* **************************************************************************
62 : *
63 : * Internal (Static) Structures:
64 : * trace_entry_t Linked-list of entries in the Trace List
65 : *
66 : * Fields:
67 : * tracee Name of the symbol to be traced
68 : * prev Pointer to previous entry in the linked-list
69 : *
70 : **************************************************************************** */
71 :
72 : typedef struct trace_entry {
73 : char *tracee;
74 : struct trace_entry *prev;
75 : } trace_entry_t;
76 :
77 : static trace_entry_t *trace_list = NULL;
78 :
79 :
80 :
81 : /* **************************************************************************
82 : *
83 : * Function name: add_to_trace_list
84 : * Synopsis: Add the given name to the Trace List
85 : *
86 : *
87 : * Inputs:
88 : * Parameters:
89 : * trace_symb Name of the symbol to be added
90 : * Local Static Variables:
91 : * trace_list Pointer to the Trace List
92 : *
93 : * Outputs:
94 : * Returned Value: NONE
95 : * Local Static Variables:
96 : * trace_list Points to new entry in Trace List
97 : * Memory Allocated
98 : * For Trace List entry
99 : * For copy of Symbol Name
100 : * When Freed?
101 : * Never. Well, only on termination of the program. Trace-list
102 : * endures for the entire batch of tokenizations.
103 : *
104 : * Error Detection:
105 : * Memory allocation failure is a FATAL error.
106 : *
107 : **************************************************************************** */
108 :
109 : void add_to_trace_list( char *trace_symb)
110 9 : {
111 : trace_entry_t *new_t_l_entry = safe_malloc( sizeof( trace_entry_t),
112 9 : "adding to trace-list");
113 9 : new_t_l_entry->tracee = strdup( trace_symb);
114 9 : new_t_l_entry->prev = trace_list;
115 :
116 9 : trace_list = new_t_l_entry;
117 9 : }
118 :
119 :
120 : /* **************************************************************************
121 : *
122 : * Function name: is_on_trace_list
123 : * Synopsis: Indicate whether the given name is on the Trace List
124 : *
125 : * Inputs:
126 : * Parameters:
127 : * symb_name Symbol-name to test
128 : * Local Static Variables:
129 : * trace_list Pointer to the Trace List
130 : *
131 : * Outputs:
132 : * Returned Value: TRUE if Symbol-name is on the Trace List
133 : *
134 : **************************************************************************** */
135 :
136 : bool is_on_trace_list( char *symb_name)
137 10665 : {
138 10665 : bool retval = FALSE;
139 10665 : trace_entry_t *test_entry = trace_list;
140 21515 : while ( test_entry != NULL )
141 : {
142 198 : if ( strcasecmp( symb_name, test_entry->tracee) == 0 )
143 : {
144 13 : retval = TRUE;
145 13 : break;
146 : }
147 185 : test_entry = test_entry->prev;
148 : }
149 10665 : return ( retval );
150 : }
151 :
152 :
153 : /* **************************************************************************
154 : *
155 : * Still to be done:
156 : * Implement a function -- name it show_initial_traces --
157 : * that will show any pre-defined names the user asked
158 : * to Trace. That is, if any of the names the user asked
159 : * to Trace belongs to a pre-defined function, macro or
160 : * directive, then, at the beginning of the output, issue
161 : * Advisory Messages identifying the scope of those names.
162 : *
163 : * E.g, if the user had -T 3DUP -T SWAP the function would
164 : * issue Messages like:
165 : * 3DUP is pre-defined as a Macro with Global scope
166 : * SWAP is pre-defined with Global scope
167 : * SWAP is pre-defined in Tokenizer-Escape mode
168 : *
169 : * The names would, of course, remain on the Trace List and
170 : * any re-definitions of them would be reported.
171 : *
172 : **************************************************************************** */
|