1 /** @file
2 
3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution.  The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8 
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 
12 
13 **/
14 
15 #ifndef _EFI_EDB_SYMBOL_H_
16 #define _EFI_EDB_SYMBOL_H_
17 
18 #include <Uefi.h>
19 
20 //
21 // The default base address is 0x10000000
22 //
23 #define EFI_DEBUGGER_DEFAULT_LINK_IMAGEBASE  0x10000000
24 
25 #define EFI_DEBUGGER_MAX_SYMBOL_ADDRESS_DELTA_VALUE  0x100000 // 1 M delta
26 
27 typedef enum {
28   EdbMatchSymbolTypeSameAdderss,
29   EdbMatchSymbolTypeNearestAddress,
30   EdbMatchSymbolTypeLowerAddress,
31   EdbMatchSymbolTypeUpperAddress,
32   EdbMatchSymbolTypeMax,
33 } EDB_MATCH_SYMBOL_TYPE;
34 
35 typedef enum {
36   EdbEbcImageRvaSearchTypeAny,
37   EdbEbcImageRvaSearchTypeFirst,
38   EdbEbcImageRvaSearchTypeLast,
39   EdbEbcImageRvaSearchTypeMax,
40 } EDB_EBC_IMAGE_RVA_SEARCH_TYPE;
41 
42 /**
43 
44   Find symbol by address.
45 
46   @param  Address         - Symbol address
47   @param  Type            - Search type
48   @param  RetObject       - Symbol object
49   @param  RetEntry        - Symbol entry
50 
51   @return Nearest symbol address
52 
53 **/
54 UINTN
55 EbdFindSymbolAddress (
56   IN UINTN                       Address,
57   IN EDB_MATCH_SYMBOL_TYPE       Type,
58   OUT EFI_DEBUGGER_SYMBOL_OBJECT **Object,
59   OUT EFI_DEBUGGER_SYMBOL_ENTRY  **Entry
60   );
61 
62 /**
63 
64   Load symbol file by name.
65 
66   @param  DebuggerPrivate - EBC Debugger private data structure
67   @param  FileName        - Symbol file name
68   @param  BufferSize      - Symbol file buffer size
69   @param  Buffer          - Symbol file buffer
70 
71   @retval EFI_SUCCESS - load symbol successfully
72 
73 **/
74 EFI_STATUS
75 EdbLoadSymbol (
76   IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,
77   IN CHAR16                      *FileName,
78   IN UINTN                       BufferSize,
79   IN VOID                        *Buffer
80   );
81 
82 /**
83 
84   Unload symbol file by name.
85 
86   @param  DebuggerPrivate - EBC Debugger private data structure
87   @param  FileName        - Symbol file name
88 
89   @retval EFI_SUCCESS - unload symbol successfully
90 
91 **/
92 EFI_STATUS
93 EdbUnloadSymbol (
94   IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,
95   IN CHAR16                      *FileName
96   );
97 
98 /**
99 
100   Patch symbol RVA.
101 
102   @param  DebuggerPrivate - EBC Debugger private data structure
103   @param  FileName        - Symbol file name
104   @param  SearchType      - Search type for Object
105 
106   @retval EFI_SUCCESS   - Patch symbol RVA successfully
107   @retval EFI_NOT_FOUND - Symbol RVA base not found
108 
109 **/
110 EFI_STATUS
111 EdbPatchSymbolRVA (
112   IN EFI_DEBUGGER_PRIVATE_DATA     *DebuggerPrivate,
113   IN CHAR16                        *FileName,
114   IN EDB_EBC_IMAGE_RVA_SEARCH_TYPE SearchType
115   );
116 
117 /**
118 
119   Load code.
120 
121   @param  DebuggerPrivate - EBC Debugger private data structure
122   @param  MapFileName     - Symbol file name
123   @param  FileName        - Code file name
124   @param  BufferSize      - Code file buffer size
125   @param  Buffer          - Code file buffer
126 
127   @retval EFI_SUCCESS - Code loaded successfully
128 
129 **/
130 EFI_STATUS
131 EdbLoadCode (
132   IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,
133   IN CHAR16                      *MapFileName,
134   IN CHAR16                      *FileName,
135   IN UINTN                       BufferSize,
136   IN VOID                        *Buffer
137   );
138 
139 /**
140 
141   Unload code.
142 
143   @param  DebuggerPrivate - EBC Debugger private data structure
144   @param  MapFileName     - Symbol file name
145   @param  FileName        - Code file name
146   @param  Buffer          - Code file buffer
147 
148   @retval EFI_SUCCESS - Code unloaded successfully
149 
150 **/
151 EFI_STATUS
152 EdbUnloadCode (
153   IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,
154   IN CHAR16                      *MapFileName,
155   IN CHAR16                      *FileName,
156   OUT VOID                       **Buffer
157   );
158 
159 /**
160 
161   Add code buffer.
162 
163   @param  DebuggerPrivate - EBC Debugger private data structure
164   @param  MapFileName     - Symbol file name
165   @param  CodeFileName    - Code file name
166   @param  SourceBufferSize- Code buffer size
167   @param  SourceBuffer    - Code buffer
168 
169   @retval EFI_SUCCESS - CodeBuffer added successfully
170 
171 **/
172 EFI_STATUS
173 EdbAddCodeBuffer (
174   IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
175   IN     CHAR16                    *MapFileName,
176   IN     CHAR16                    *CodeFileName,
177   IN     UINTN                     SourceBufferSize,
178   IN     VOID                      *SourceBuffer
179   );
180 
181 /**
182 
183   Delete code buffer.
184 
185   @param  DebuggerPrivate - EBC Debugger private data structure
186   @param  MapFileName     - Symbol file name
187   @param  CodeFileName    - Code file name
188   @param  SourceBuffer    - Code buffer
189 
190   @retval EFI_SUCCESS - CodeBuffer deleted successfully
191 
192 **/
193 EFI_STATUS
194 EdbDeleteCodeBuffer (
195   IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
196   IN     CHAR16                    *MapFileName,
197   IN     CHAR16                    *CodeFileName,
198   IN     VOID                      *SourceBuffer
199   );
200 
201 /**
202 
203   Find the symbol string according to address.
204 
205   @param  Address         - Symbol address
206 
207   @return Symbol string
208 
209 **/
210 CHAR8 *
211 FindSymbolStr (
212   IN UINTN Address
213   );
214 
215 /**
216 
217   Print source.
218 
219   @param  Address         - Instruction address
220   @param  IsPrint         - Whether need to print
221 
222   @retval 1 - find the source
223   @retval 0 - not find the source
224 
225 **/
226 UINTN
227 EdbPrintSource (
228   IN UINTN     Address,
229   IN BOOLEAN   IsPrint
230   );
231 
232 /**
233 
234   Convert a symbol to an address.
235 
236   @param  Symbol          - Symbol name
237   @param  Address         - Symbol address
238 
239   @retval EFI_SUCCESS    - symbol found and address returned.
240   @retval EFI_NOT_FOUND  - symbol not found
241   @retval EFI_NO_MAPPING - duplicated symbol not found
242 
243 **/
244 EFI_STATUS
245 Symboltoi (
246   IN CHAR16   *Symbol,
247   OUT UINTN   *Address
248   );
249 
250 #endif
251