]>
Commit | Line | Data |
---|---|---|
00e5a55c BS |
1 | From: SGI KDB Development <kdb@oss.sgi.com> |
2 | Subject: kdb-v4.4-2.6.27-rc8-common-1.1 | |
3 | References: FATE#303971 | |
4 | X-URL: ftp://oss.sgi.com/www/projects/kdb/download/v4.4/ | |
5 | ||
6 | The KDB common code. | |
7 | ||
8 | Acked-by: Bernhard Walle <bwalle@suse.de> | |
9 | ||
10 | --- | |
11 | Documentation/kdb/bt_x86 | 1837 ++++++++ | |
12 | Documentation/kdb/kdb.mm | 492 ++ | |
13 | Documentation/kdb/kdb_bp.man | 197 | |
14 | Documentation/kdb/kdb_bt.man | 315 + | |
15 | Documentation/kdb/kdb_env.man | 46 | |
16 | Documentation/kdb/kdb_ll.man | 134 | |
17 | Documentation/kdb/kdb_md.man | 136 | |
18 | Documentation/kdb/kdb_ps.man | 96 | |
19 | Documentation/kdb/kdb_rd.man | 170 | |
20 | Documentation/kdb/kdb_sr.man | 68 | |
21 | Documentation/kdb/kdb_ss.man | 109 | |
22 | Documentation/kdb/slides | 1382 ++++++ | |
23 | Makefile | 1 | |
24 | drivers/char/keyboard.c | 10 | |
25 | drivers/hid/usbhid/hid-core.c | 28 | |
26 | drivers/hid/usbhid/usbkbd.c | 17 | |
27 | drivers/serial/8250.c | 53 | |
28 | drivers/serial/8250_early.c | 29 | |
29 | drivers/serial/sn_console.c | 73 | |
30 | drivers/usb/core/hcd.c | 14 | |
31 | drivers/usb/core/hcd.h | 4 | |
32 | drivers/usb/host/ehci-hcd.c | 42 | |
33 | drivers/usb/host/ehci-pci.c | 8 | |
34 | drivers/usb/host/ehci-q.c | 222 + | |
35 | drivers/usb/host/ohci-hcd.c | 67 | |
36 | drivers/usb/host/ohci-pci.c | 8 | |
37 | drivers/usb/host/ohci-q.c | 62 | |
38 | fs/proc/mmu.c | 16 | |
39 | fs/proc/proc_misc.c | 114 | |
40 | include/linux/console.h | 5 | |
41 | include/linux/dis-asm.h | 347 + | |
42 | include/linux/kdb.h | 175 | |
43 | include/linux/kdbprivate.h | 503 ++ | |
44 | include/linux/reboot.h | 7 | |
45 | include/linux/sysctl.h | 1 | |
46 | init/main.c | 32 | |
47 | kdb/ChangeLog | 2012 +++++++++ | |
48 | kdb/Makefile | 43 | |
49 | kdb/kdb_bp.c | 658 +++ | |
50 | kdb/kdb_bt.c | 180 | |
51 | kdb/kdb_cmds | 32 | |
52 | kdb/kdb_id.c | 236 + | |
53 | kdb/kdb_io.c | 856 ++++ | |
54 | kdb/kdbdereference.c | 7257 ++++++++++++++++++++++++++++++++++ | |
55 | kdb/kdbmain.c | 4333 ++++++++++++++++++++ | |
56 | kdb/kdbsupport.c | 1154 +++++ | |
57 | kdb/modules/Makefile | 14 | |
58 | kdb/modules/kdbm_debugtypes.c | 388 + | |
59 | kdb/modules/kdbm_pg.c | 688 +++ | |
60 | kdb/modules/kdbm_sched.c | 57 | |
61 | kdb/modules/kdbm_task.c | 205 | |
62 | kdb/modules/kdbm_vm.c | 1036 ++++ | |
63 | kdb/modules/kdbm_x86.c | 1093 +++++ | |
64 | kdb/modules/lcrash/README | 3 | |
65 | kdb/modules/lcrash/asm/README | 1 | |
66 | kdb/modules/lcrash/asm/kl_dump_ia64.h | 199 | |
67 | kdb/modules/lcrash/asm/kl_types.h | 48 | |
68 | kdb/modules/lcrash/kl_alloc.h | 124 | |
69 | kdb/modules/lcrash/kl_bfd.h | 31 | |
70 | kdb/modules/lcrash/kl_btnode.h | 95 | |
71 | kdb/modules/lcrash/kl_cmp.h | 102 | |
72 | kdb/modules/lcrash/kl_copt.h | 29 | |
73 | kdb/modules/lcrash/kl_debug.h | 168 | |
74 | kdb/modules/lcrash/kl_dump.h | 511 ++ | |
75 | kdb/modules/lcrash/kl_dump_arch.h | 124 | |
76 | kdb/modules/lcrash/kl_dump_ia64.h | 199 | |
77 | kdb/modules/lcrash/kl_dwarfs.h | 27 | |
78 | kdb/modules/lcrash/kl_error.h | 266 + | |
79 | kdb/modules/lcrash/kl_htnode.h | 71 | |
80 | kdb/modules/lcrash/kl_lib.h | 65 | |
81 | kdb/modules/lcrash/kl_libutil.h | 40 | |
82 | kdb/modules/lcrash/kl_mem.h | 104 | |
83 | kdb/modules/lcrash/kl_mem_ia64.h | 149 | |
84 | kdb/modules/lcrash/kl_module.h | 69 | |
85 | kdb/modules/lcrash/kl_queue.h | 89 | |
86 | kdb/modules/lcrash/kl_stabs.h | 122 | |
87 | kdb/modules/lcrash/kl_stringtab.h | 68 | |
88 | kdb/modules/lcrash/kl_sym.h | 131 | |
89 | kdb/modules/lcrash/kl_task.h | 39 | |
90 | kdb/modules/lcrash/kl_typeinfo.h | 199 | |
91 | kdb/modules/lcrash/kl_types.h | 54 | |
92 | kdb/modules/lcrash/klib.h | 480 ++ | |
93 | kdb/modules/lcrash/lc_eval.h | 225 + | |
94 | kernel/exit.c | 3 | |
95 | kernel/kallsyms.c | 22 | |
96 | kernel/kexec.c | 16 | |
97 | kernel/module.c | 19 | |
98 | kernel/panic.c | 8 | |
99 | kernel/printk.c | 14 | |
100 | kernel/sched.c | 93 | |
101 | kernel/signal.c | 49 | |
102 | kernel/sysctl_check.c | 1 | |
103 | lib/bug.c | 8 | |
104 | mm/hugetlb.c | 22 | |
105 | mm/mmzone.c | 4 | |
106 | mm/swapfile.c | 22 | |
107 | 96 files changed, 31168 insertions(+), 7 deletions(-) | |
108 | ||
109 | --- /dev/null | |
110 | +++ b/Documentation/kdb/bt_x86 | |
111 | @@ -0,0 +1,1837 @@ | |
112 | +Copyright Keith Owens, 2007. | |
113 | + | |
114 | +How the KDB backtrace for x86 works, how to diagnose problems and submit a bug | |
115 | +============================================================================== | |
116 | + | |
117 | +Unlike ia64, x86 architectures do not mandate unwind information in the kernel. | |
118 | +gcc will include some unwind information for C functions, but not for assembler | |
119 | +code. Attempts have been made to add unwind information to the assembler code | |
120 | +by hand, with little success. Eventually Linus rejected the x86 unwind code | |
121 | +because it was breaking too often and destroying useful debugging data. | |
122 | + | |
123 | +Even if the x86 unwinder worked correctly, it would only give an accurate | |
124 | +backtrace, it would not give function arguments. Needless to say, function | |
125 | +arguments are what people really want. To get function arguments requires much | |
126 | +more support from the compiler than simple unwind data, the compiler has to | |
127 | +track line by line where each argument is held and make that data available to | |
128 | +the debugger. Compiling with gcc -g will provide that information, but the | |
129 | +resulting kernel is several times larger than normal. | |
130 | + | |
131 | +Although the gcc -g data can be stored on another machine, there are constructs | |
132 | +in the kernel that cannot be tracked by this method. i386 builds with 4K stacks | |
133 | +and all x86_64 builds have multiple kernel stacks. The compiler knows nothing | |
134 | +about these extra stacks and cannot backtrace through them correctly. The | |
135 | +assembler code in arch/{i386,x86_64}/kernel/entry.S is a maze of twisty logic | |
136 | +paths, some of which eventually jump to common labels. Describing this twisty | |
137 | +logic to an unwinder is very difficult, expecially when you try to describe | |
138 | +where arguments and/or registers are held). | |
139 | + | |
140 | +KDB gets an accurate x86 backtrace and extracts the arguments by performing code | |
141 | +decomposition and analysis at run time. This avoids the need to bloat the | |
142 | +running kernel to several times its normal size with gcc -g data. KDB (unlike | |
143 | +gdb) also knows about the additional kernel stacks and twisty assembler code | |
144 | +paths. | |
145 | + | |
146 | +The x86 backtrace code for i386 is very similar to the x86_64 code, with 80% | |
147 | +common code and data. Most of the differences between the backtrace for the two | |
148 | +architectures is due to the assembler code and stack handling. To avoid code | |
149 | +duplication between KDB patches, the x86 backtrace code is actually stored in | |
150 | +the kdb common patch, in source kdb/kdba_bt_x86.c. kdb/Makefile only builds | |
151 | +kdba_bt_x86.o for i386 or x86_64. Most of the code reads as if the architecture | |
152 | +is x86_64, using register names like rsp and rip. i386 is treated as a subset | |
153 | +of x86_64, with fewer registers and printing the names as esp and eip. When | |
154 | +this documentation refers to rsp and rip, read it as esp and eip for i386. The | |
155 | +20% of code and data that is different in held in two large #ifdef sections, | |
156 | +scan kdba_bt_x86.c for CONFIG_X86_64. Be careful when changing anything in the | |
157 | +architecture specific sections, you will need to review the other architecture | |
158 | +to see if it needs changes as well. | |
159 | + | |
160 | +The idea behind the x86 backtrace is to trace one function at a time, which | |
161 | +gives us the calling function. Then apply the same algorithm to the calling | |
162 | +function until you unwind to the first function in the process. The starting | |
163 | +point for tracing any process is to extract the current stack pointer and | |
164 | +current instruction pointer (rsp and rip). The way that these values are | |
165 | +extracted varies between running tasks and blocked tasks, the method is | |
166 | +described later (Process Starting Point) but ignore it for now, just assume that | |
167 | +we have a starting rsp and rip. | |
168 | + | |
169 | +Given the instruction pointer (rip), we identify the start and end of the kernel | |
170 | +or module function it is in, using the kernel symbol table. This is easy for C | |
171 | +code, it is significantly harder for assembler code because of the twisty code | |
172 | +paths that branch to common labels. The method of identifying the current | |
173 | +function is described later (Identifying The Current Function) but ignore it for | |
174 | +now, just assumes that we have the start and end address of the function plus | |
175 | +its name. | |
176 | + | |
177 | +After the rip has been mapped to a function name with sensible start and end | |
178 | +addresses, the next step is to analyse the code paths in that function. KDB | |
179 | +already has a built in disassembler (copied with slight modifications from | |
180 | +binutils) which knows how to decode each x86 instruction. Instead of | |
181 | +duplicating that logic in kdba_bt_x86, it takes advantage of the fact that you | |
182 | +can override the disassembler's print function, sending the output line to a | |
183 | +buffer instead of printing it. kdba_bt_x86 stills has to decode the buffer but | |
184 | +that is a lot easier than decoding the x86 instruction set. | |
185 | + | |
186 | +The code analysis consists of two main passes. There are example below of the | |
187 | +analysis with basic block (bb) debugging activated (Examples of Basic Block | |
188 | +Debugging Output). | |
189 | + | |
190 | +The first pass (bb_pass1) identifies all the basic blocks in the function. For | |
191 | +our purposes, a basic block has a single entry point and one or more exit | |
192 | +points. The start of the function is the start of basic block 0, all other | |
193 | +blocks are the target of jump instructions (conditional or unconditional) from | |
194 | +within the rest of the code. A block ends with an unconditional jump or with a | |
195 | +terminating instruction such as ret, iret, sysexit, sysret or ud2a (BUG). A | |
196 | +block can also end because the next instruction is the start of a new block | |
197 | +(target of jmp or jcc), in this case there is an implied drop through from one | |
198 | +block to the next. | |
199 | + | |
200 | +Although a call instruction also transfers control, it returns to the next | |
201 | +instruction so call is not treated as a transfer. Instead call is treated as a | |
202 | +normal instruction with side effects, the scratch registers are cleared after a | |
203 | +call. | |
204 | + | |
205 | +At the end of the first pass over the function we have a directed graph that | |
206 | +starts at bb[0]. The nodes of the graph (bb_list[]) are the basic blocks with | |
207 | +their start and end address. The vertices are the jmp or jcc instructions | |
208 | +(bb_jmp_list[]) that transfer control between blocks, plus any implied drop | |
209 | +through transfers between consecutive blocks. This graph can have cycles, many | |
210 | +functions have loops in them which transfer control back to earlier in the code | |
211 | +body. | |
212 | + | |
213 | +The second pass (bb_pass2) runs over the directed graph analysing the effect of | |
214 | +each instruction on the register and memory state. It is important to | |
215 | +understand that the analysis in this pass is an abstract one, it does not use | |
216 | +actual hex values for the register contents, instead it uses symbolic values. | |
217 | +When the basic block code says that "register rsi contains value rax" it means | |
218 | +that whatever value was in rax on entry to the function has also been copied to | |
219 | +register rsi at this point in the logic flow. | |
220 | + | |
221 | +At an abstract level, all C functions start with exactly the same state, each | |
222 | +register contains its own symbolic value (except for the stack pointer, see | |
223 | +later) with no local stack variables defined yet. Assembler functions tend to | |
224 | +have unusual starting points, with some registers and/or memory contents defined | |
225 | +differently on entry. For example, ret_from_intr on i386 already has a struct | |
226 | +pt_regs on its stack, ret_from_intr on x86_64 already has a partial struct | |
227 | +pt_regs plus another two words stacked on top of it. The special starting cases | |
228 | +are listed in the arch specific bb_special_cases[]. | |
229 | + | |
230 | +Once the input state of bb[0] has been defined (including any special cases), | |
231 | +bb_pass2_do_changed_blocks() runs over all the nodes in bb_list[]. Each | |
232 | +instruction in each block is analysed (Tracking the Effects of Instructions) to | |
233 | +see what effect it has on the abstract register state, the analysis of each | |
234 | +instruction is done in bb_usage(). An instruction can copy one register to | |
235 | +another, it can copy a register to stack, move from stack to a register or it | |
236 | +can invalidate the contents of a register or memory location. A general rule in | |
237 | +bb_usage() is that any operation whose results cannot be calculated in terms of | |
238 | +an original input value gives an undefined result. Remember that it is the | |
239 | +abstract value that becomes undefined, moving a constant to a register gives a | |
240 | +defined value for the view of the program but it is undefined as far as the | |
241 | +abstract state is concerned. | |
242 | + | |
243 | +References to data on the stack are a little awkward because the stack pointer | |
244 | +frequently changes. To overcome this, kdba_bt_x86 defines a pseudo register | |
245 | +called the 'original stack pointer' (osp). This always represents the stack | |
246 | +pointer on entry to the function, so on entry rsp contains osp+0x0. As rsp is | |
247 | +modified, it still points at osp, but its offset from osp changes. Copying rsp | |
248 | +to another register (e.g. mov %rsp,%rbp) copies the osp offset as well. At the | |
249 | +point that this function calls the next function down the stack, kdba_bt_x86 | |
250 | +knows the delta from osp to rsp. Applying that delta to the actual value of the | |
251 | +stack pointer gives the stack pointer value on input to the current function, | |
252 | +that location contains the return address so we can go up one stack frame and | |
253 | +repeat the process. | |
254 | + | |
255 | +After doing basic block analysis on the current function, kdba_bt_x86 knows what | |
256 | +the abstract register and memory state is at the point this function was | |
257 | +interrupted or it called the next function down the stack, this is the exit | |
258 | +state. For an interrupt the actual register values are saved in a struct | |
259 | +pt_regs, for a call we have unwound from the KDB interrupt back to the called | |
260 | +function so we have some idea of what the register values are in the called | |
261 | +function. The abstract exit state is merged with the known actual register | |
262 | +values to derive the original stack pointer. That in turn gives us any | |
263 | +registers that were saved on stack. The original stack pointer gives the return | |
264 | +address from the calling function, go up one stack frame and repeat the | |
265 | +analysis. | |
266 | + | |
267 | + | |
268 | +Process Starting Point | |
269 | +====================== | |
270 | + | |
271 | +All backtrace code needs a starting point which defines at least the stack | |
272 | +pointer and instruction pointer, it may define other registers as well. The | |
273 | +first part of kdba_bt_stack() extracts the starting point. Processes can be in | |
274 | +one of three states, running (currently on a cpu), blocked (sleeping or ready to | |
275 | +run but not currently on a cpu) or unknown. | |
276 | + | |
277 | +For running processes, the current rsp and rip are dynamic. Because KDB stops | |
278 | +the entire machine by sending an interrupt to the other cpus, KDB can save the | |
279 | +rsp and rip for each cpu at the point where KDB is entered. This data is held | |
280 | +in array kdb_running_process and is stored by kdb_save_running() and the arch | |
281 | +specific kdba_save_running() functions. When backtracing a running process, KDB | |
282 | +uses the data in kdb_running_process as its starting point. | |
283 | + | |
284 | +For blocked processes we always have the saved rsp, it is held in the process's | |
285 | +thread_info. For i386 blocked processes, thread_info also contains the saved | |
286 | +rip. For x86_64 blocked processes, rip is no longer saved in thread_info, it is | |
287 | +assumed that all blocked processes will resume at assembler label thread_return, | |
288 | +so that rip is used on x86_64. See arch specific kdba_bt_stack_rip(). | |
289 | + | |
290 | +Unknown process state only occurs when the user does 'bt <stack_address>'. | |
291 | +Unlike other bt commands, 'bt <stack_address>' does not identify any specific | |
292 | +process, instead it identifies a kernel stack. <stack_address> must be inside a | |
293 | +valid kernel stack and must point to a saved rip from a call instruction. | |
294 | +kdba_bt_x86.c uses the common kdba_get_stack_info() and arch specific | |
295 | +kdba_get_stack_info_alternate() functions to check that the address falls within | |
296 | +a valid kernel stack. If the user gives a stack address that does not point to | |
297 | +a saved rip from a call instruction then the backtrace will be garbage. | |
298 | + | |
299 | + | |
300 | +Identifying The Current Function | |
301 | +================================ | |
302 | + | |
303 | +Given a rip value, KDB uses the kallsyms data to find the start of the function | |
304 | +(first address <= rip) and the end of the function (next symbol in kallsyms). | |
305 | +This works for plain C code because gcc only generates one label per function. | |
306 | +It does not work for assembler code or for assembler code embedded in C | |
307 | +functions, because the assembler labels appear as global entries in kallsyms. | |
308 | +For example, arch/i386/kernel/entry.S has function ret_from_exception which | |
309 | +contains three global labels ret_from_intr, check_userspace and | |
310 | +resume_userspace. If rip points to any of those global labels, KDB wants the | |
311 | +start of the real function, i.e. ret_from_exception. In addition, if rip points | |
312 | +to ret_from_exception, KDB wants the end of the function to be after the last | |
313 | +global label in that function, i.e. after resume_userspace. | |
314 | + | |
315 | +The simplest way to handle these unwanted global labels is to list the spurious | |
316 | +assembler labels, which is done in the arch specific array bb_spurious. After | |
317 | +mapping rip to the nearest start and end labels from kallsyms, kdb_bb() works | |
318 | +backwards until it finds a non-spurious label then works forwards to the next | |
319 | +non-spurious label. That gives a real start and end address and a real name for | |
320 | +the current function. | |
321 | + | |
322 | +Note that this algorithm only applies in kdb_bb() when it maps rip to a suitable | |
323 | +start and end address. When disassembling the code, you will still see the | |
324 | +spurious label names, users need to see the extra labels. ret_from_exception on | |
325 | +i386 disassembles like this (2.6.22) :- | |
326 | + | |
327 | +[0]kdb> id ret_from_exception | |
328 | +0xc0102554 ret_from_exception: cli | |
329 | +0xc0102555 ret_from_intr: mov $0xfffff000,%ebp | |
330 | +0xc010255a ret_from_intr+0x5: and %esp,%ebp | |
331 | +0xc010255c check_userspace: mov 0x34(%esp),%eax | |
332 | +0xc0102560 check_userspace+0x4: mov 0x30(%esp),%al | |
333 | +0xc0102564 check_userspace+0x8: and $0x20003,%eax | |
334 | +0xc0102569 check_userspace+0xd: cmp $0x3,%eax | |
335 | +0xc010256c check_userspace+0x10: jb 0xc010258c resume_kernel | |
336 | +0xc0102572 check_userspace+0x16: mov %esi,%esi | |
337 | +0xc0102574 resume_userspace: cli | |
338 | +0xc0102575 resume_userspace+0x1: mov 0x8(%ebp),%ecx | |
339 | +0xc0102578 resume_userspace+0x4: and $0xfe3e,%ecx | |
340 | +0xc010257e resume_userspace+0xa: jne 0xc01026f4 work_pending | |
341 | +0xc0102584 resume_userspace+0x10: jmp 0xc01026a7 restore_all | |
342 | +0xc0102589 resume_userspace+0x15: lea 0x0(%esi),%esi | |
343 | +0xc010258c resume_kernel: cli | |
344 | + | |
345 | +For the purposes of kdba_bt_x86.c, any rip from 0xc0102554 to 0xc0102589 needs | |
346 | +to map to the range 0xc0102554 (start) to 0xc010258c (end) with function name | |
347 | +ret_from_exception. Therefore ret_from_intr, check_userspace and | |
348 | +resume_userspace are listed in bb_spurious[] for i386 so those symbols are | |
349 | +ignored. The comments in bb_spurious[] list the function that encloses each | |
350 | +spurious label, those comments are only for humans, they do not affect the code. | |
351 | + | |
352 | +Once rip has been mapped to non-spurious labels, the module name, function name, | |
353 | +start and end address are stored in variables bb_mod_name, bb_func_name, | |
354 | +bb_func_start, bb_func_end. These variables are used throughout kdba_bt_x86.c | |
355 | +for processing each function in turn. | |
356 | + | |
357 | +Watch for changes to assembler code, especially in arch/i386/kernel/entry.S, | |
358 | +arch/x86_64/kernel/entry.S and arch/x86_64/ia32/ia32entry.S. When new labels | |
359 | +are added you may need to adjust bb_spurious[] for that architecture. Running | |
360 | +bb_all can help identify assembler labels that have been added or deleted. | |
361 | + | |
362 | + | |
363 | +Tracking the Effects of Instructions | |
364 | +==================================== | |
365 | + | |
366 | +bb_pass2_do_changed_blocks() uses the KDB disassembler to decode the x86 | |
367 | +instructions to something a human can read. bb_dis_pass2() is used as a print | |
368 | +routine to store data for a single instruction in a buffer then | |
369 | +bb_parse_buffer() starts the analysis. Any instruction prefixes like lock or | |
370 | +rep are stripped out. The opcode string is isolated then up to 3 operands are | |
371 | +extracted (imul can have 3 operands), these are src, dst and dst2. The operand | |
372 | +is matched against table bb_opcode_usage_all[] which lists all the instructions | |
373 | +that actually appear in i386 and x86_64 kernels. A lot of the x86 instrcution | |
374 | +set is not used by the kernel so instructions such as SSE do not appear in | |
375 | +bb_opcode_usage_all[]. | |
376 | + | |
377 | +Each operand is decoded by bb_parse_operand() to see whether it has a segment | |
378 | +prefix, displacement, base, index or scale. An indirect call or jmp is | |
379 | +identified. Operands consisting only of a register are classified as 'reg' | |
380 | +type, displacements starting with '$' are immediate values otherwise the operand | |
381 | +refers to a memory location. Any base or index register name is mapped to the | |
382 | +abstract register name that contains it, this takes care of mapping (say) %ah to | |
383 | +rax. | |
384 | + | |
385 | +After decoding the opcode and all its operands, bb_usage() decides what effect | |
386 | +the instruction will have on the abstract state machine. Some x86 instructions | |
387 | +list all the affected registers in their operands and these can be handled as | |
388 | +generic cases. Alas many x86 instructions have side effects and change | |
389 | +registers that are not listed in the operands, these have to be handled as | |
390 | +special cases. enum bb_operand_usage lists the generic and special cases. | |
391 | + | |
392 | +bb_usage() is basically one huge switch statement over the special values in | |
393 | +enum bb_operand_usage. For each special case it tracks the side effects of the | |
394 | +instruction. Once all the special cases have been handled and converted to | |
395 | +generic cases then bb_usage() handles the generic cases. | |
396 | + | |
397 | +bb_usage() detects when a register is copied to another register, a register is | |
398 | +copied to stack or a known stack value is copied to a register and updates the | |
399 | +state data accordingly. It is particularly important that all stack pointer | |
400 | +updates and copies of the stack pointer are tracked, much of the saved state is | |
401 | +on stack and can be accessed via any register that points to the stack, not just | |
402 | +via rsp. | |
403 | + | |
404 | +i386 built with 4K stacks and all x86_64 builds have multiple kernel stacks. | |
405 | +bb_usage() knows which instructions or locations are used to switch stacks and | |
406 | +pretends that these instructions have no effect on the contents of rsp. The | |
407 | +higher level backtrace code knows how to handle stack switching, it is too | |
408 | +complicated for basic block analysis. | |
409 | + | |
410 | + | |
411 | +Transfer of Control Outside the Current Function | |
412 | +================================================ | |
413 | + | |
414 | +Ignoring call instructions, most C code does not transfer control outside the | |
415 | +current function, IOW there are no jump instructions to instructions outside the | |
416 | +function. There are a few cases that this can occur for C code, inline | |
417 | +assembler and tail recursion. | |
418 | + | |
419 | +Tail recursion occurs when a function ends by returning the value from a second | |
420 | +function and that second function has exactly the same arguments and return | |
421 | +value as the current function. For example, | |
422 | + | |
423 | + int bar(int i, char *p) | |
424 | + { | |
425 | + ... do some work and return an int ... | |
426 | + } | |
427 | + | |
428 | + int foo(int i, char *p) | |
429 | + { | |
430 | + return bar(i, p); | |
431 | + } | |
432 | + | |
433 | +If tail recursion is active (gcc -foptimize-sibling-calls) then instead of foo | |
434 | +calling bar, bar returning to foo then foo returning to its caller, gcc will end | |
435 | +foo with a direct jmp to bar. The source code says that something called foo | |
436 | +but the stack trace will show bar is active, with no sign of foo on stack. When | |
437 | +bar returns it will use the return address from the code that called foo. | |
438 | + | |
439 | +bb_transfer() detects an unconditional jmp to code outside the function body and | |
440 | +assumes that this represents tail recursion. For tail recursion to work | |
441 | +correctly, all the preserved registers must contain their original values, | |
442 | +bb_sanity_check() validates this. Any deviation from the expected state will | |
443 | +stop basic block analysis and fall back on the old unreliable backtrace code. | |
444 | + | |
445 | +Besides tail recursion in C code, assembler code can jump to labels outside the | |
446 | +current function. Unfortunately this occurs all the time in the twisty | |
447 | +assembler code and, to make things worse, many of these transfers are done with | |
448 | +non-standard register or memory state. bb_special_case() and the arch specific | |
449 | +bb_special_cases[] handle all the known special cases, including what the | |
450 | +register and/or memory state should be. Any deviation from the expected state | |
451 | +will stop basic block analysis and fall back on the old unreliable backtrace | |
452 | +code. | |
453 | + | |
454 | + | |
455 | +Locating Arguments | |
456 | +================== | |
457 | + | |
458 | +Function arguments can be passed in registers or on stack. The full ABI for | |
459 | +passing arguments is described in | |
460 | + | |
461 | + http://www.caldera.com/developers/devspecs/abi386-4.pdf | |
462 | + http://www.x86-64.org/documentation/abi.pdf | |
463 | + | |
464 | +The short description, ignoring special cases like passing structures by name | |
465 | +and floating point arguments which tend not to apply to the kernel, is :- | |
466 | + | |
467 | +i386. With -mpregparm=0, all arguments are passed on stack, except for | |
468 | + functions defined as FASTCALL, where the first 3 arguments are passed in | |
469 | + registers. | |
470 | + | |
471 | + With -mregparm=3, the first 3 arguments are passed in registers except | |
472 | + for functions defined as asmlinkage or with variable number of | |
473 | + arguments, when arguments are still passed on stack. -mpregparm=3 used | |
474 | + to be a config option, in recent kernels it is the default. | |
475 | + | |
476 | + Arguments defined as long long (64 bit) are passed in two registers or | |
477 | + in two locations on stack. Being passed in two pieces makes a 64 bit | |
478 | + argument look like two 32 bit arguments to KDB, it will be printed as | |
479 | + two separate arguments. | |
480 | + | |
481 | + When compiled with -mregparm=3, if a 64 bit argument is argument number | |
482 | + 2 then it will not be split between register and stack, instead it will | |
483 | + all be on stack and the third argument register will not be used. This | |
484 | + makes it look like there is an extra argument in the list. There is | |
485 | + nothing that KDB can do to detect these corner cases with 64 bit | |
486 | + arguments on i386, which is a pity because they can confuse users. | |
487 | + | |
488 | + The preserved registers are ebx, ebp, esp, esi, edi. Arguments are | |
489 | + passed in eax, edx, ecx. The return value is in eax. | |
490 | + | |
491 | +x86_64. The first 6 arguments are passed in registers, the 7th and later | |
492 | + arguments are passed on stack. Except for functions with a variable | |
493 | + number of arguments (e.g. printk) where all arguments are on stack | |
494 | + except for rax which contains the number of SSE arguments (always 0 for | |
495 | + the kernel). | |
496 | + | |
497 | + The preserved registers are rbx, rbp, rsp, r12, r13, r14, r15. | |
498 | + Arguments are passed in rdi, rsi, rdx, rcx, r8, r9. The return value is | |
499 | + in rax. | |
500 | + | |
501 | +For both architectures, kdba_bt detects an argument that is passed in a register | |
502 | +by the fact that the function code reads from that argument type register while | |
503 | +it contains its original value. IOW, testing the value of rax, copying rax to | |
504 | +another register or storing it on stack without first overwriting rax means that | |
505 | +rax contains a useful input value. Reading from memory which is above the | |
506 | +original stack pointer means that there is a argument at that location on | |
507 | +stack. | |
508 | + | |
509 | +There are some functions in the kernel whose definition contains arguments that | |
510 | +are not actually used. Typically these functions are instantiations of generic | |
511 | +function definitions where some, but not all, instantiations use all the | |
512 | +arguments. For example, a filesystem function may take flags that are not used | |
513 | +by this particular filesystem, but the function definition has to match the | |
514 | +generic filesystem declarations. If the unused arguments are at the end of the | |
515 | +list then there is no way of telling from the object code that they exist, the | |
516 | +function that does not use the trailing aguments will have no code that refers | |
517 | +to them. KDB will print a truncated argument list for this case. | |
518 | + | |
519 | +If the unused arguments are not at the end of the list then KDB can detect the | |
520 | +presence of the unused arguments, because there is code that refers to later | |
521 | +arguments. KDB will print the unused argument, although gcc may have | |
522 | +overwritten the register it is in, in which case KDB prints "invalid". | |
523 | + | |
524 | +Originally kdba_bt_x86 would detect that there was no reference to arguments in | |
525 | +registers but there were still references to arguments on stack and assume that | |
526 | +the function had all its arguments on stack. Unfortunately this did not work | |
527 | +with the large number of 'pass through' functions in the kernel. A 'pass | |
528 | +through' function is one which calls another function with roughly the same | |
529 | +argument list and makes no other reference to the register arguments. For | |
530 | +example, ipv4_doint_and_flush_strategy() takes 7 arguments, calls | |
531 | +devinet_conf_sysctl() with those 7 arguments in the same order and has no other | |
532 | +reference to any of its arguments. | |
533 | + | |
534 | +Pass through functions do not touch the arguments that are passed in registers | |
535 | +because they are already in the right location for the routine about to be | |
536 | +called, so the pass through function has no code that references the argument | |
537 | +registers. No code means that kdba_bt_x86 cannot tell if the function has | |
538 | +register arguments or not. The arguments passed on stack must always be copied | |
539 | +to the new stack frame, even for pass through functions, so the arguments on | |
540 | +stack can always be detected. | |
541 | + | |
542 | +kdba_bt_x86 was changed to assume that if there are any arguments on stack then | |
543 | +there are always arguments in registers, except for a list of functions that are | |
544 | +known to be asmlinkage or to have a variable number of arguments. | |
545 | +bb_assume_pass_through() ignores the known special cases, for other functions | |
546 | +which have stack arguments but no register arguments it assumes the function is | |
547 | +pass through and prints a warning about that assumption. | |
548 | + | |
549 | +The above heuristics mean that there is one case that kdba_bt_x86 cannot detect: | |
550 | +pass through functions where all the arguments are in registers. These have no | |
551 | +argument references at all in their code, so they are printed with no arguments. | |
552 | +All they do is call another function so this class of functions never fails, or | |
553 | +if it does fail then it is due to something that is not argument related. If | |
554 | +the failure is further down the call stack then the arguments are printed at the | |
555 | +next function down the stack, so the user still has the arguments. | |
556 | + | |
557 | +This list of limitations on getting the x86 arguments may seem to be a long one, | |
558 | +but kdba_bt_x86 gives sensible results for most functions. For kernel | |
559 | +debugging, any arguments are far better than none at all. | |
560 | + | |
561 | + | |
562 | +Kernel Stack Switching | |
563 | +====================== | |
564 | + | |
565 | +Understanding the unusual way that x86 kernel stacks are used is very important | |
566 | +when diagnosing backtrace problems. Every process has its own normal kernel | |
567 | +stack, even processes that run entirely within the kernel such as kthread or the | |
568 | +per cpu migration processes. The normal stacks are 4K or 8K on i386 (depending | |
569 | +on CONFIG_4KSTACKS) and 8K on x86_64. The normal stacks are global, they are | |
570 | +not tied to any cpu. | |
571 | + | |
572 | +For i386 with 8K stacks there are no other kernel stacks so there is no stack | |
573 | +switching to worry about. | |
574 | + | |
575 | +For i386 with 4K process stacks, each cpu also has a 4K soft irq stack and a 4K | |
576 | +hard irq stack. It is possible for a process to be running on its own process | |
577 | +stack, for the process to be interrupted by a soft irq which is then interrupted | |
578 | +by a hard irq. At that point the backtrace is split between the hard irq, the | |
579 | +soft irq and the normal normal stacks. | |
580 | + | |
581 | +On x86_64, each cpu always has stacks for stackfault, doublefault, nmi, debug, | |
582 | +mce and interrupts. See Documentation/x86_64/kernel-stacks. | |
583 | + | |
584 | +The arch specific kdba_get_stack_info_alternate() function works out which stack | |
585 | +the backtrace starts on, how big the stack is and how to switch to the next | |
586 | +stack. This information is stored in the kdb_activation_record and used by the | |
587 | +higher level backtrace code to detect a stack switch. | |
588 | + | |
589 | +The normal stack has some padding at the end, this reflects the stack pointer | |
590 | +when the process was created in the kernel. kdba_bt_x86 cannot backtrace | |
591 | +through this padding data, mainly because the code that set the nitial stack | |
592 | +pointer no longer exists after boot. ARCH_NORMAL_PADDING defines how many words | |
593 | +to ignore at the end of the normal stack. | |
594 | + | |
595 | + | |
596 | +Debugging KDB | |
597 | +============= | |
598 | + | |
599 | +KDB has conditional debugging print statements scattered throughout the code. | |
600 | +If KDB is not behaving as expected, you can turn on debugging and rerun the | |
601 | +command. Before debugging KDB, set LINES 10000 and capture the output via a | |
602 | +serial console. If using minicom, turn on word wrap (control-A W) and capture | |
603 | +mode (control-A L). If you are using a serial console via a serial to Ethernet | |
604 | +interface using ssh or telnet, use the 'script' command to start the session. | |
605 | + | |
606 | +The various KDB_DEBUG_FLAG_* flags are listed in include/linux/kdbprivate.h. | |
607 | +You set debug with 'set KDBDEBUG 0xnn' where nn is the or'd value of the desired | |
608 | +flags. 'set KDBDEBUG 0' turns off KDB debugging. When diagnosing x86 backtrace | |
609 | +problems, the most useful debug flags are | |
610 | + | |
611 | + KDB_DEBUG_FLAG_ARA 0x10 Activation record, arch specific | |
612 | + KDB_DEBUG_FLAG_BB_SUMM 0x04 Basic block analysis, summary only | |
613 | + KDB_DEBUG_FLAG_BB 0x20 All basic block analysis | |
614 | + | |
615 | +ARA prints information about the different kernel stacks as kdba_bt_x86 unwinds | |
616 | +through the switched kernel stacks. BB_SUMM prints a summary of the basic block | |
617 | +analysis for each function, including the abstract exit state and the rollback | |
618 | +calculations. BB prints a huge amount of basic block debugging, you probably | |
619 | +only want to turn this for the full backtrace on as a last resort. | |
620 | + | |
621 | +I find 'set KDBDEBUG 0x14' to be best to get an overview of a problem. It gives | |
622 | +both the kernel stack information plus the abstract state and actual location of | |
623 | +data for each function. | |
624 | + | |
625 | +Command 'bb1' does a detailed debug session for a single function, bb1 takes a | |
626 | +single parameter, the address of the exit point from the function, by number, | |
627 | +not by name. bb1 turns on KDB_DEBUG_FLAG_BB, does basic block analysis for the | |
628 | +function that contains the exit point then resets the debug flags to their | |
629 | +previous value. | |
630 | + | |
631 | +Command 'bb_all' runs through every function in the base kernel (not module | |
632 | +functions) and does a basic block analysis of every function. It also validates | |
633 | +the various tables in kdba_bt_x86 where possible. bb_all is meant for the KDB | |
634 | +maintainer to check that all the base kernel function pass the sanity checks, it | |
635 | +can also be used by end users when reporting a bug. bb_all takes no parameters. | |
636 | +It prints a '.' for every 100 functions it has analysed and allows for up to 20 | |
637 | +errors before giving up. The output from bb_all also includes the config | |
638 | +variables that affect basic block analysis plus any assumptions about 'pass | |
639 | +through' functions. | |
640 | + | |
641 | + | |
642 | +Submitting a Bug Report Against kdba_bt_x86 | |
643 | +=========================================== | |
644 | + | |
645 | +Capture the KDB output via a serial console. | |
646 | + | |
647 | +set LINES 10000 | |
648 | +set BTSP 1 | |
649 | +set KDBDEBUG 0x14 | |
650 | +Reproduce the problem. | |
651 | +set KDBDEBUG 0 | |
652 | +bb_all | |
653 | + | |
654 | +If you can identify the rip/eip where kdba_bt_x86 gets confused, run bb1 with | |
655 | +that address. | |
656 | + | |
657 | +Find each set of output from kdba_get_stack_info in the trace, extract the last | |
658 | +two lines and type those lines into KDB. That will give a hex and symbolic dump | |
659 | +of the raw kernel stacks. For example, if the trace data is | |
660 | + | |
661 | +kdba_get_stack_info: esp=0xc04fbef8 cpu=0 task=c047b3e0 | |
662 | +kdba_get_stack_info: ar->stack | |
663 | + physical_start=0xc04fb000 | |
664 | + physical_end=0xc04fc000 | |
665 | + logical_start=0xc04fb038 | |
666 | + logical_end=0xc04fc000 | |
667 | + next=0xc04b4f44 | |
668 | + id=hardirq_ctx | |
669 | + set MDCOUNT 1024 | |
670 | + mds 0xc04fb000 | |
671 | + | |
672 | +then type the last two lines into KDB. Repeat this for each stack listed by | |
673 | +kdba_get_stack_info on the failing backtrace. | |
674 | + | |
675 | +Send all the console output to the KDB maintainer. | |
676 | + | |
677 | + | |
678 | +Examples of Basic Block Debugging Output | |
679 | +======================================== | |
680 | + | |
681 | +Example of the basic block analysis of fs/namei::getname() on i386. Kernel | |
682 | +2.6.22, i386, compiled with frame pointers, gcc 4.1.0. | |
683 | + | |
684 | +Basic block debugging is very verbose, so set a high number of output lines. | |
685 | +You really need a reliable serial console to capture this amount of output. | |
686 | + | |
687 | + [0]kdb> set LINES 10000 | |
688 | + | |
689 | +A simple disassemble of getname(). This is not required for debugging purposes | |
690 | +since each instruction is printed as part of basic block debugging, but this can | |
691 | +be easier to read. | |
692 | + | |
693 | + [0]kdb> id getname | |
694 | + 0xc015cce8 getname: push %ebp | |
695 | + 0xc015cce9 getname+0x1: mov %esp,%ebp | |
696 | + 0xc015cceb getname+0x3: push %edi | |
697 | + 0xc015ccec getname+0x4: push %esi | |
698 | + 0xc015cced getname+0x5: push %ebx | |
699 | + 0xc015ccee getname+0x6: sub $0x4,%esp | |
700 | + 0xc015ccf1 getname+0x9: mov %eax,%edi | |
701 | + 0xc015ccf3 getname+0xb: mov $0xd0,%edx | |
702 | + 0xc015ccf8 getname+0x10: mov 0xc04b2120,%eax | |
703 | + 0xc015ccfd getname+0x15: call 0xc0153009 kmem_cache_alloc | |
704 | + 0xc015cd02 getname+0x1a: mov %eax,0xfffffff0(%ebp) | |
705 | + 0xc015cd05 getname+0x1d: mov $0xfffffff4,%eax | |
706 | + 0xc015cd0a getname+0x22: cmpl $0x0,0xfffffff0(%ebp) | |
707 | + 0xc015cd0e getname+0x26: je 0xc015cd7d getname+0x95 | |
708 | + 0xc015cd10 getname+0x28: mov %esp,%eax | |
709 | + 0xc015cd12 getname+0x2a: and $0xfffff000,%eax | |
710 | + 0xc015cd17 getname+0x2f: cmpl $0xffffffff,0x18(%eax) | |
711 | + 0xc015cd1b getname+0x33: je 0xc015cd39 getname+0x51 | |
712 | + 0xc015cd1d getname+0x35: mov $0xfffffff2,%esi | |
713 | + 0xc015cd22 getname+0x3a: cmp $0xbfffffff,%edi | |
714 | + 0xc015cd28 getname+0x40: ja 0xc015cd60 getname+0x78 | |
715 | + 0xc015cd2a getname+0x42: mov $0xc0000000,%ebx | |
716 | + 0xc015cd2f getname+0x47: sub %edi,%ebx | |
717 | + 0xc015cd31 getname+0x49: cmp $0xfff,%ebx | |
718 | + 0xc015cd37 getname+0x4f: jbe 0xc015cd3e getname+0x56 | |
719 | + 0xc015cd39 getname+0x51: mov $0x1000,%ebx | |
720 | + 0xc015cd3e getname+0x56: mov %ebx,%ecx | |
721 | + 0xc015cd40 getname+0x58: mov %edi,%edx | |
722 | + 0xc015cd42 getname+0x5a: mov 0xfffffff0(%ebp),%eax | |
723 | + 0xc015cd45 getname+0x5d: call 0xc023dbb4 strncpy_from_user | |
724 | + 0xc015cd4a getname+0x62: cmp $0x0,%eax | |
725 | + 0xc015cd4d getname+0x65: jle 0xc015cd5a getname+0x72 | |
726 | + 0xc015cd4f getname+0x67: mov $0xffffffdc,%esi | |
727 | + 0xc015cd54 getname+0x6c: cmp %ebx,%eax | |
728 | + 0xc015cd56 getname+0x6e: jae 0xc015cd60 getname+0x78 | |
729 | + 0xc015cd58 getname+0x70: jmp 0xc015cd71 getname+0x89 | |
730 | + 0xc015cd5a getname+0x72: je 0xc015cd76 getname+0x8e | |
731 | + 0xc015cd5c getname+0x74: jge 0xc015cd71 getname+0x89 | |
732 | + 0xc015cd5e getname+0x76: mov %eax,%esi | |
733 | + 0xc015cd60 getname+0x78: mov 0xfffffff0(%ebp),%edx | |
734 | + 0xc015cd63 getname+0x7b: mov 0xc04b2120,%eax | |
735 | + 0xc015cd68 getname+0x80: call 0xc01521f1 kmem_cache_free | |
736 | + 0xc015cd6d getname+0x85: mov %esi,%eax | |
737 | + 0xc015cd6f getname+0x87: jmp 0xc015cd7d getname+0x95 | |
738 | + 0xc015cd71 getname+0x89: mov 0xfffffff0(%ebp),%eax | |
739 | + 0xc015cd74 getname+0x8c: jmp 0xc015cd7d getname+0x95 | |
740 | + 0xc015cd76 getname+0x8e: mov $0xfffffffe,%esi | |
741 | + 0xc015cd7b getname+0x93: jmp 0xc015cd60 getname+0x78 | |
742 | + 0xc015cd7d getname+0x95: pop %edx | |
743 | + 0xc015cd7e getname+0x96: pop %ebx | |
744 | + 0xc015cd7f getname+0x97: pop %esi | |
745 | + 0xc015cd80 getname+0x98: pop %edi | |
746 | + 0xc015cd81 getname+0x99: pop %ebp | |
747 | + 0xc015cd82 getname+0x9a: ret | |
748 | + | |
749 | +The bb1 command only one argument which must be an address, not a name. bb1 | |
750 | +turns on full basic block debugging and analyses the function containing the | |
751 | +supplied address. Give bb1 the address of the exit point from this function, | |
752 | +IOW the return address that is stored on stack due to a call from this function | |
753 | +to the next function down the call stack. Assume that getname() has called | |
754 | +kmem_cache_free() and something went wrong in kmem_cache_free() or one of the | |
755 | +functions that it calls. The call to kmem_cache_free is at 0xc015cd68 and the | |
756 | +return address on stack is the instruction after the call, i.e. 0xc015cd6d, so | |
757 | + | |
758 | + [0]kdb> bb1 0xc015cd6d | |
759 | + bb_pass1: func_name getname func_start 0xc015cce8 func_end 0xc015cd83 | |
760 | + | |
761 | +bb_pass1 has identified the function name and its start and end address. For C | |
762 | +functions these are just the function start address and the next symbol in | |
763 | +kallsyms. For Assembler code there may be spurious labels so the function name | |
764 | +may not match the label prior to the address given to bb1. For an example of | |
765 | +that on i386, find the address of resume_userspace then pass that address to the | |
766 | +bb1 KDB command. | |
767 | + | |
768 | + bb_pass1: end | |
769 | + bb[0] start 0xc015cce8 end 0xc015cd38 drop_through 1 | |
770 | + bb[1] start 0xc015cd39 end 0xc015cd3d drop_through 1 | |
771 | + bb[2] start 0xc015cd3e end 0xc015cd58 drop_through 0 | |
772 | + bb[3] start 0xc015cd5a end 0xc015cd5f drop_through 1 | |
773 | + bb[4] start 0xc015cd60 end 0xc015cd6f drop_through 0 | |
774 | + bb[5] start 0xc015cd71 end 0xc015cd74 drop_through 0 | |
775 | + bb[6] start 0xc015cd76 end 0xc015cd7b drop_through 0 | |
776 | + bb[7] start 0xc015cd7d end 0xc015cd82 drop_through 0 | |
777 | + bb_jmp[0] from 0xc015cd0e to 0xc015cd7d drop_through 0 | |
778 | + bb_jmp[1] from 0xc015cd1b to 0xc015cd39 drop_through 0 | |
779 | + bb_jmp[2] from 0xc015cd28 to 0xc015cd60 drop_through 0 | |
780 | + bb_jmp[3] from 0xc015cd37 to 0xc015cd3e drop_through 0 | |
781 | + bb_jmp[4] from 0xc015cd4d to 0xc015cd5a drop_through 0 | |
782 | + bb_jmp[5] from 0xc015cd56 to 0xc015cd60 drop_through 0 | |
783 | + bb_jmp[6] from 0xc015cd58 to 0xc015cd71 drop_through 0 | |
784 | + bb_jmp[7] from 0xc015cd5a to 0xc015cd76 drop_through 0 | |
785 | + bb_jmp[8] from 0xc015cd5c to 0xc015cd71 drop_through 0 | |
786 | + bb_jmp[9] from 0xc015cd6f to 0xc015cd7d drop_through 0 | |
787 | + bb_jmp[10] from 0xc015cd74 to 0xc015cd7d drop_through 0 | |
788 | + bb_jmp[11] from 0xc015cd7b to 0xc015cd60 drop_through 0 | |
789 | + bb_jmp[12] from 0xc015cd38 to 0xc015cd39 drop_through 1 | |
790 | + bb_jmp[13] from 0xc015cd3d to 0xc015cd3e drop_through 1 | |
791 | + bb_jmp[14] from 0xc015cd5f to 0xc015cd60 drop_through 1 | |
792 | + | |
793 | +After analysing the logic flow, we can see that getname() consists of 8 basic | |
794 | +blocks (nodes in bb_list[]). 5 of these blocks end in unconditional jumps, the | |
795 | +other 3 drop through to the next block. There are 15 transfers of control | |
796 | +(vertices in bb_jmp_list[]). 12 of these transfers are explicit jmp or jcc | |
797 | +instructions, the other 3 are implicit transfers when dropping through from one | |
798 | +block to the next. The node list is sorted by start address, the vertex list is | |
799 | +not sorted. | |
800 | + | |
801 | +Basic block 0 starts at the function start (0xc015cce8) and ends at 0xc015cd38. | |
802 | +0xc015cd39 is the target of a jump instruction (0xc015cd1b: je 0xc015cd39) so | |
803 | +0xc015cd39 starts a new block, which means that 0xc015cd38 becomes the end of | |
804 | +the previous block. Because bb[0] does not end in an explicit jmp instruction, | |
805 | +there is a drop through from the end of bb[0] to the start of bb[1], see | |
806 | +bb_jmp[12]. | |
807 | + | |
808 | + bb_pass2: start | |
809 | + | |
810 | +To get the most accurate results from pass2, try to scan the directed graph by | |
811 | +only looking at nodes whose inputs are all defined. Initially only process | |
812 | +nodes with no missing inputs. | |
813 | + | |
814 | + bb_pass2_do_changed_blocks: allow_missing 0 | |
815 | + | |
816 | + bb[0] | |
817 | + bb_reg_state c07282e0 | |
818 | + rax = rax | |
819 | + rbx = rbx | |
820 | + rcx = rcx | |
821 | + rdx = rdx | |
822 | + rdi = rdi | |
823 | + rsi = rsi | |
824 | + rbp = rbp | |
825 | + rsp = osp+0x0 | |
826 | + | |
827 | +The initial state for bb[0] is the same for all C functions. Each register | |
828 | +contains its own abstract value, except for rsp which is defined in terms of the | |
829 | +original stack pointer (osp). | |
830 | + | |
831 | + '0xc015cce8 getname: push %ebp' | |
832 | + | |
833 | +The first instruction of getname() saves the frame pointer. | |
834 | + | |
835 | + opcode 'push' matched by 'push', usage 44 | |
836 | + src R: %ebp base_rc 8 (rbp) | |
837 | + | |
838 | +bb_usage() reports how the instruction was recognised and how its operands were | |
839 | +decoded. Although this is i386 (ebp), it is reported as rbp. Using the x86_64 | |
840 | +names for registers throughout makes it easier to create common code for the two | |
841 | +architecures. | |
842 | + | |
843 | + rsp osp offset +0x0 -> -0x4 | |
844 | + | |
845 | +A push instruction decrements rsp by 4 (i386) or 8 (x86_64) bytes. rsp | |
846 | +originally contained the original stack pointer (osp), now it contains the | |
847 | +original stack pointer - 4. | |
848 | + | |
849 | + *(rsp+0x0 osp-0x4) = rbp slot 0 | |
850 | + | |
851 | +The stack location pointed to by *rsp now contains the original value of rbp. | |
852 | +Since rsp contains (osp-0x4), *(osp-0x4) contains rbp. It is slot 0 in the | |
853 | +memory array associated with the register state. | |
854 | + | |
855 | + '0xc015cce9 getname+0x1: mov %esp,%ebp' | |
856 | + opcode 'mov' matched by 'mov', usage 36 | |
857 | + src R: %esp base_rc 9 (rsp) | |
858 | + dst R: %ebp base_rc 8 (rbp) | |
859 | + rbp = rsp (osp-0x4) | |
860 | + | |
861 | +Copy esp (rsp) to ebp (rbp). rsp contained (osp-0x4) so rbp also contains | |
862 | +(osp-0x4). Any reference to data via either rbp or rsp will now be tracked as a | |
863 | +stack location. | |
864 | + | |
865 | + '0xc015cceb getname+0x3: push %edi' | |
866 | + opcode 'push' matched by 'push', usage 44 | |
867 | + src R: %edi base_rc 6 (rdi) | |
868 | + rsp osp offset -0x4 -> -0x8 | |
869 | + *(rsp+0x0 osp-0x8) = rdi slot 1 | |
870 | + '0xc015ccec getname+0x4: push %esi' | |
871 | + opcode 'push' matched by 'push', usage 44 | |
872 | + src R: %esi base_rc 7 (rsi) | |
873 | + rsp osp offset -0x8 -> -0xc | |
874 | + *(rsp+0x0 osp-0xc) = rsi slot 2 | |
875 | + '0xc015cced getname+0x5: push %ebx' | |
876 | + opcode 'push' matched by 'push', usage 44 | |
877 | + src R: %ebx base_rc 3 (rbx) | |
878 | + rsp osp offset -0xc -> -0x10 | |
879 | + *(rsp+0x0 osp-0x10) = rbx slot 3 | |
880 | + | |
881 | +Push 3 registers to stack. rsp is adjusted for each push and stack locations | |
882 | +are assigned to contain the values of edi, esi and ebx. This sequence is very | |
883 | +common in i386 C functions. edi, esi and ebx are preserved registers on i386, | |
884 | +but gcc wants to use them for scratch space. The original contents iof these | |
885 | +registers must be saved on stack and restored before returning to our caller. | |
886 | + | |
887 | + '0xc015ccee getname+0x6: sub $0x4,%esp' | |
888 | + opcode 'sub' matched by 'sub', usage 51 | |
889 | + src I: $0x4 | |
890 | + dst R: %esp base_rc 9 (rsp) | |
891 | + rsp osp offset -0x10 -> -0x14 | |
892 | + | |
893 | +Subtract 4 bytes from esp. This defines the local stack variables. Sorry, | |
894 | +names for local stack variables are not available to KDB. | |
895 | + | |
896 | + '0xc015ccf1 getname+0x9: mov %eax,%edi' | |
897 | + opcode 'mov' matched by 'mov', usage 36 | |
898 | + src R: %eax base_rc 2 (rax) | |
899 | + dst R: %edi base_rc 6 (rdi) | |
900 | + rdi = rax (rax) | |
901 | + | |
902 | +Having saved edi on stack, gcc now overwrites edi with eax. At this point rax | |
903 | +still contains its original value, so rdi now contains a copy of rax, as well as | |
904 | +the original value which is still in rax. This is a common sequence in C code. | |
905 | +rax contains argument 0 but it is also a scratch register. If the code needs to | |
906 | +use argument 0 later then its value must be saved somewhere before executing any | |
907 | +instruction that changes rax. edi is a preserved register so its contents will | |
908 | +not be changed by any function that we call, or if it is changed then it will be | |
909 | +restored before returning to this function. | |
910 | + | |
911 | +rax is listed in the arch specific bb_param_reg[] list and the code is reading | |
912 | +from rax while it still contains its original value. The only way that makes | |
913 | +any sense is when rax is an input argument to getname(). We note that fact in | |
914 | +bb_reg_read(). | |
915 | + | |
916 | + '0xc015ccf3 getname+0xb: mov $0xd0,%edx' | |
917 | + opcode 'mov' matched by 'mov', usage 36 | |
918 | + src I: $0xd0 | |
919 | + dst R: %edx base_rc 5 (rdx) | |
920 | + rdx = undefined | |
921 | + | |
922 | +Moving an constant value to edx. Although this is a constant, it does not refer | |
923 | +to any of the original values that were supplied to this function. Therefore | |
924 | +rdx becomes undefined for the purposes of the code analysis. | |
925 | + | |
926 | + '0xc015ccf8 getname+0x10: mov 0xc04b2120,%eax' | |
927 | + opcode 'mov' matched by 'mov', usage 36 | |
928 | + src M: 0xc04b2120 | |
929 | + dst R: %eax base_rc 2 (rax) | |
930 | + rax = undefined | |
931 | + | |
932 | +Moving a constant value to eax makes rax undefined. | |
933 | + | |
934 | + '0xc015ccfd getname+0x15: call 0xc0153009 <kmem_cache_alloc>' | |
935 | + opcode 'call' matched by 'call', usage 17 | |
936 | + src M: 0xc0153009 | |
937 | + bb_reg_state c0728658 | |
938 | + rax = undefined | |
939 | + rbx = rbx | |
940 | + rcx = rcx | |
941 | + rdx = undefined | |
942 | + rdi = rax | |
943 | + rsi = rsi | |
944 | + rbp = osp-0x4 | |
945 | + rsp = osp-0x14 | |
946 | + slot 0 offset_address -0x4 rbp | |
947 | + slot 1 offset_address -0x8 rdi | |
948 | + slot 2 offset_address -0xc rsi | |
949 | + slot 3 offset_address -0x10 rbx | |
950 | + | |
951 | +Basic block debugging prints the register and memory state when transfering | |
952 | +control between blocks and when issuing call instructions. The call state is | |
953 | +mainly useful when C code calls assembler routines, especially if you are not | |
954 | +sure what state the assembler code expects. Not all of our assembler is as well | |
955 | +documented as it could be :( | |
956 | + | |
957 | + rax = undefined | |
958 | + rcx = undefined | |
959 | + rdx = undefined | |
960 | + | |
961 | +The i386 ABI says that some registers are preserved across calls, see the arch | |
962 | +specific bb_preserved_reg[] list. Any registers not in that list automatically | |
963 | +become undefined after a call instruction. | |
964 | + | |
965 | + '0xc015cd02 getname+0x1a: mov %eax,0xfffffff0(%ebp)' | |
966 | + opcode 'mov' matched by 'mov', usage 36 | |
967 | + src R: %eax base_rc 2 (rax) | |
968 | + dst M: 0xfffffff0(%ebp) base_rc 8 (rbp) | |
969 | + | |
970 | +eax is the return value from the call, it is being saved at offset 0xfffffff0 | |
971 | +(-0x10) from ebp. Since rbp contains (osp-0x4) the return value is being stored | |
972 | +at (osp-0x14). This is a stack location but we have no record of any data being | |
973 | +held at that location, it is part of the local stack variables. | |
974 | + | |
975 | + '0xc015cd05 getname+0x1d: mov $0xfffffff4,%eax' | |
976 | + opcode 'mov' matched by 'mov', usage 36 | |
977 | + src I: $0xfffffff4 | |
978 | + dst R: %eax base_rc 2 (rax) | |
979 | + rax = undefined | |
980 | + '0xc015cd0a getname+0x22: cmpl $0x0,0xfffffff0(%ebp)' | |
981 | + opcode 'cmpl' matched by 'cmp', usage 3 | |
982 | + src I: $0x0 | |
983 | + dst M: 0xfffffff0(%ebp) base_rc 8 (rbp) | |
984 | + '0xc015cd0e getname+0x26: je 0xc015cd7d <getname+0x95>' | |
985 | + opcode 'je' matched by 'j', usage 28 | |
986 | + src M: 0xc015cd7d | |
987 | + bb_reg_state c0728658 | |
988 | + rax = undefined | |
989 | + rbx = rbx | |
990 | + rcx = undefined | |
991 | + rdx = undefined | |
992 | + rdi = rax | |
993 | + rsi = rsi | |
994 | + rbp = osp-0x4 | |
995 | + rsp = osp-0x14 | |
996 | + slot 0 offset_address -0x4 rbp | |
997 | + slot 1 offset_address -0x8 rdi | |
998 | + slot 2 offset_address -0xc rsi | |
999 | + slot 3 offset_address -0x10 rbx | |
1000 | + | |
1001 | +Transfer of control, print the register and memory state. | |
1002 | + | |
1003 | + matched: from 0xc015cd0e to 0xc015cd7d drop_through 0 bb_jmp[0] | |
1004 | + | |
1005 | +Which bb_jmp_list[] entry matches this transfer. | |
1006 | + | |
1007 | + new state c07286b8 | |
1008 | + | |
1009 | +The current abstract register and memory state is cloned at address c07286b8. | |
1010 | +This state becomes one of the inputs to the basic block whose start address is | |
1011 | +0xc015cd7d. | |
1012 | + | |
1013 | + '0xc015cd10 getname+0x28: mov %esp,%eax' | |
1014 | + opcode 'mov' matched by 'mov', usage 36 | |
1015 | + src R: %esp base_rc 9 (rsp) | |
1016 | + dst R: %eax base_rc 2 (rax) | |
1017 | + rax = rsp (osp-0x14) | |
1018 | + | |
1019 | +Copy rsp which contains (osp-0x14) to rax. rax contains a valid stack pointer. | |
1020 | + | |
1021 | + '0xc015cd12 getname+0x2a: and $0xfffff000,%eax' | |
1022 | + opcode 'and' matched by 'and', usage 11 | |
1023 | + src I: $0xfffff000 | |
1024 | + dst R: %eax base_rc 2 (rax) | |
1025 | + rax = undefined | |
1026 | + | |
1027 | +But not for long. | |
1028 | + | |
1029 | + '0xc015cd17 getname+0x2f: cmpl $0xffffffff,0x18(%eax)' | |
1030 | + opcode 'cmpl' matched by 'cmp', usage 3 | |
1031 | + src I: $0xffffffff | |
1032 | + dst M: 0x18(%eax) base_rc 2 (rax) | |
1033 | + '0xc015cd1b getname+0x33: je 0xc015cd39 <getname+0x51>' | |
1034 | + opcode 'je' matched by 'j', usage 28 | |
1035 | + src M: 0xc015cd39 | |
1036 | + bb_reg_state c0728658 | |
1037 | + rax = undefined | |
1038 | + rbx = rbx | |
1039 | + rcx = undefined | |
1040 | + rdx = undefined | |
1041 | + rdi = rax | |
1042 | + rsi = rsi | |
1043 | + rbp = osp-0x4 | |
1044 | + rsp = osp-0x14 | |
1045 | + slot 0 offset_address -0x4 rbp | |
1046 | + slot 1 offset_address -0x8 rdi | |
1047 | + slot 2 offset_address -0xc rsi | |
1048 | + slot 3 offset_address -0x10 rbx | |
1049 | + | |
1050 | +Another transfer of control, print the state. | |
1051 | + | |
1052 | + matched: from 0xc015cd1b to 0xc015cd39 drop_through 0 bb_jmp[1] | |
1053 | + | |
1054 | +Which bb_jmp_list[] entry was used. | |
1055 | + | |
1056 | + reuse bb_jmp[0] | |
1057 | + | |
1058 | +To save space, we only clone the state if it is different. Otherwise we reuse | |
1059 | +the state from another vertex and bump the reference count. | |
1060 | + | |
1061 | + '0xc015cd1d getname+0x35: mov $0xfffffff2,%esi' | |
1062 | + opcode 'mov' matched by 'mov', usage 36 | |
1063 | + src I: $0xfffffff2 | |
1064 | + dst R: %esi base_rc 7 (rsi) | |
1065 | + rsi = undefined | |
1066 | + | |
1067 | +Using esi as a scratch register, even though the i386 ABi says that esi is a | |
1068 | +preserved register. Not to worry, the original value of rsi was saved on stack | |
1069 | +on entry and it will be restored before exit. | |
1070 | + | |
1071 | + '0xc015cd22 getname+0x3a: cmp $0xbfffffff,%edi' | |
1072 | + opcode 'cmp' matched by 'cmp', usage 3 | |
1073 | + src I: $0xbfffffff | |
1074 | + dst R: %edi base_rc 6 (rdi) | |
1075 | + '0xc015cd28 getname+0x40: ja 0xc015cd60 <getname+0x78>' | |
1076 | + opcode 'ja' matched by 'j', usage 28 | |
1077 | + src M: 0xc015cd60 | |
1078 | + bb_reg_state c0728658 | |
1079 | + rax = undefined | |
1080 | + rbx = rbx | |
1081 | + rcx = undefined | |
1082 | + rdx = undefined | |
1083 | + rdi = rax | |
1084 | + rsi = undefined | |
1085 | + rbp = osp-0x4 | |
1086 | + rsp = osp-0x14 | |
1087 | + slot 0 offset_address -0x4 rbp | |
1088 | + slot 1 offset_address -0x8 rdi | |
1089 | + slot 2 offset_address -0xc rsi | |
1090 | + slot 3 offset_address -0x10 rbx | |
1091 | + matched: from 0xc015cd28 to 0xc015cd60 drop_through 0 bb_jmp[2] | |
1092 | + new state c0728710 | |
1093 | + | |
1094 | +This state is different from any states already saved, clone to a new entry. | |
1095 | + | |
1096 | + '0xc015cd2a getname+0x42: mov $0xc0000000,%ebx' | |
1097 | + opcode 'mov' matched by 'mov', usage 36 | |
1098 | + src I: $0xc0000000 | |
1099 | + dst R: %ebx base_rc 3 (rbx) | |
1100 | + rbx = undefined | |
1101 | + '0xc015cd2f getname+0x47: sub %edi,%ebx' | |
1102 | + opcode 'sub' matched by 'sub', usage 51 | |
1103 | + src R: %edi base_rc 6 (rdi) | |
1104 | + dst R: %ebx base_rc 3 (rbx) | |
1105 | + rbx = undefined | |
1106 | + '0xc015cd31 getname+0x49: cmp $0xfff,%ebx' | |
1107 | + opcode 'cmp' matched by 'cmp', usage 3 | |
1108 | + src I: $0xfff | |
1109 | + dst R: %ebx base_rc 3 (rbx) | |
1110 | + '0xc015cd37 getname+0x4f: jbe 0xc015cd3e <getname+0x56>' | |
1111 | + opcode 'jbe' matched by 'j', usage 28 | |
1112 | + src M: 0xc015cd3e | |
1113 | + bb_reg_state c0728658 | |
1114 | + rax = undefined | |
1115 | + rbx = undefined | |
1116 | + rcx = undefined | |
1117 | + rdx = undefined | |
1118 | + rdi = rax | |
1119 | + rsi = undefined | |
1120 | + rbp = osp-0x4 | |
1121 | + rsp = osp-0x14 | |
1122 | + slot 0 offset_address -0x4 rbp | |
1123 | + slot 1 offset_address -0x8 rdi | |
1124 | + slot 2 offset_address -0xc rsi | |
1125 | + slot 3 offset_address -0x10 rbx | |
1126 | + matched: from 0xc015cd37 to 0xc015cd3e drop_through 0 bb_jmp[3] | |
1127 | + new state c0728768 | |
1128 | + | |
1129 | +This state is different from any states already saved, clone to a new entry. | |
1130 | + | |
1131 | + bb_reg_state c0728658 | |
1132 | + rax = undefined | |
1133 | + rbx = undefined | |
1134 | + rcx = undefined | |
1135 | + rdx = undefined | |
1136 | + rdi = rax | |
1137 | + rsi = undefined | |
1138 | + rbp = osp-0x4 | |
1139 | + rsp = osp-0x14 | |
1140 | + slot 0 offset_address -0x4 rbp | |
1141 | + slot 1 offset_address -0x8 rdi | |
1142 | + slot 2 offset_address -0xc rsi | |
1143 | + slot 3 offset_address -0x10 rbx | |
1144 | + matched: from 0xc015cd38 to 0xc015cd39 drop_through 1 bb_jmp[12] | |
1145 | + reuse bb_jmp[3] | |
1146 | + | |
1147 | +Basic block 0 drops through to basic block 1, treat it as an implicit transfer | |
1148 | +of control. The state is the same as the previous jump instruction so reuse it | |
1149 | +and bump the reference count. | |
1150 | + | |
1151 | +That ends basic block 0, now pick the next block in the list that (a) needs to | |
1152 | +be scanned and (b) has all its input states defined. In this case bb[1]. | |
1153 | + | |
1154 | + bb[1] | |
1155 | + | |
1156 | +bb[1] starts at 0xc015cd39 and has two paths that transfer control to it. | |
1157 | +bb_jmp[1] from an explicit jump at 0xc015cd1b and a drop through at bb_jmp[12]. | |
1158 | +Where there is more than one input state we have to merge them and reconcile the | |
1159 | +final value. | |
1160 | + | |
1161 | + first state c07286b8 | |
1162 | + | |
1163 | +The first input state is stored at c07286b8. Looking back through the trace we | |
1164 | +find that entry associated with bb_jmp[0], not bb_jmp[1] as expected. However | |
1165 | +bb_jmp[1] reused the state that was stored for bb_jmp[0] so all is well. | |
1166 | + | |
1167 | + bb_reg_state c0728658 | |
1168 | + rax = undefined | |
1169 | + rbx = rbx | |
1170 | + rcx = undefined | |
1171 | + rdx = undefined | |
1172 | + rdi = rax | |
1173 | + rsi = rsi | |
1174 | + rbp = osp-0x4 | |
1175 | + rsp = osp-0x14 | |
1176 | + slot 0 offset_address -0x4 rbp | |
1177 | + slot 1 offset_address -0x8 rdi | |
1178 | + slot 2 offset_address -0xc rsi | |
1179 | + slot 3 offset_address -0x10 rbx | |
1180 | + | |
1181 | +The first state for bb[1]. | |
1182 | + | |
1183 | + merging state c0728768 | |
1184 | + | |
1185 | +Now merge the second state, which is held at c0728768. | |
1186 | + | |
1187 | + rbx = undefined | |
1188 | + rsi = undefined | |
1189 | + | |
1190 | +The two states disagree on the values being tracked in rbx and rsi. Compiler | |
1191 | +theory 101 says that if two or more paths to a basic block have different values | |
1192 | +for a register then that register cannot be relied on at the start of the block, | |
1193 | +so make it undefined. The same logic applies to memory locations. | |
1194 | + | |
1195 | + final state | |
1196 | + bb_reg_state c0728658 | |
1197 | + rax = undefined | |
1198 | + rbx = undefined | |
1199 | + rcx = undefined | |
1200 | + rdx = undefined | |
1201 | + rdi = rax | |
1202 | + rsi = undefined | |
1203 | + rbp = osp-0x4 | |
1204 | + rsp = osp-0x14 | |
1205 | + slot 0 offset_address -0x4 rbp | |
1206 | + slot 1 offset_address -0x8 rdi | |
1207 | + slot 2 offset_address -0xc rsi | |
1208 | + slot 3 offset_address -0x10 rbx | |
1209 | + | |
1210 | +After merging all the input states, this is the final starting state for bb[1]. | |
1211 | +Now track what bb[1] does to the state. | |
1212 | + | |
1213 | + '0xc015cd39 getname+0x51: mov $0x1000,%ebx' | |
1214 | + opcode 'mov' matched by 'mov', usage 36 | |
1215 | + src I: $0x1000 | |
1216 | + dst R: %ebx base_rc 3 (rbx) | |
1217 | + rbx = undefined | |
1218 | + bb_reg_state c0728658 | |
1219 | + rax = undefined | |
1220 | + rbx = undefined | |
1221 | + rcx = undefined | |
1222 | + rdx = undefined | |
1223 | + rdi = rax | |
1224 | + rsi = undefined | |
1225 | + rbp = osp-0x4 | |
1226 | + rsp = osp-0x14 | |
1227 | + slot 0 offset_address -0x4 rbp | |
1228 | + slot 1 offset_address -0x8 rdi | |
1229 | + slot 2 offset_address -0xc rsi | |
1230 | + slot 3 offset_address -0x10 rbx | |
1231 | + matched: from 0xc015cd3d to 0xc015cd3e drop_through 1 bb_jmp[13] | |
1232 | + reuse bb_jmp[3] | |
1233 | + | |
1234 | +bb[1] is a single instruction which drops through to bb[2]. | |
1235 | + | |
1236 | + bb[2] | |
1237 | + first state c0728768 | |
1238 | + bb_reg_state c0728658 | |
1239 | + rax = undefined | |
1240 | + rbx = undefined | |
1241 | + rcx = undefined | |
1242 | + rdx = undefined | |
1243 | + rdi = rax | |
1244 | + rsi = undefined | |
1245 | + rbp = osp-0x4 | |
1246 | + rsp = osp-0x14 | |
1247 | + slot 0 offset_address -0x4 rbp | |
1248 | + slot 1 offset_address -0x8 rdi | |
1249 | + slot 2 offset_address -0xc rsi | |
1250 | + slot 3 offset_address -0x10 rbx | |
1251 | + merging state c0728768 | |
1252 | + | |
1253 | +bb[2] has two inputs, both vertices are pointing to input state c0728768. | |
1254 | +Merging an entry with itself has no effect. | |
1255 | + | |
1256 | + '0xc015cd3e getname+0x56: mov %ebx,%ecx' | |
1257 | + opcode 'mov' matched by 'mov', usage 36 | |
1258 | + src R: %ebx base_rc 3 (rbx) | |
1259 | + dst R: %ecx base_rc 4 (rcx) | |
1260 | + rcx = rbx (undefined) | |
1261 | + '0xc015cd40 getname+0x58: mov %edi,%edx' | |
1262 | + opcode 'mov' matched by 'mov', usage 36 | |
1263 | + src R: %edi base_rc 6 (rdi) | |
1264 | + dst R: %edx base_rc 5 (rdx) | |
1265 | + rdx = rdi (rax) | |
1266 | + '0xc015cd42 getname+0x5a: mov 0xfffffff0(%ebp),%eax' | |
1267 | + opcode 'mov' matched by 'mov', usage 36 | |
1268 | + src M: 0xfffffff0(%ebp) base_rc 8 (rbp) | |
1269 | + dst R: %eax base_rc 2 (rax) | |
1270 | + rax = *(rbp-0x10) (osp-0x14) rax = undefined | |
1271 | + '0xc015cd45 getname+0x5d: call 0xc023dbb4 <strncpy_from_user>' | |
1272 | + opcode 'call' matched by 'call', usage 17 | |
1273 | + src M: 0xc023dbb4 | |
1274 | + bb_reg_state c0728658 | |
1275 | + rax = undefined | |
1276 | + rbx = undefined | |
1277 | + rcx = undefined | |
1278 | + rdx = rax | |
1279 | + rdi = rax | |
1280 | + rsi = undefined | |
1281 | + rbp = osp-0x4 | |
1282 | + rsp = osp-0x14 | |
1283 | + slot 0 offset_address -0x4 rbp | |
1284 | + slot 1 offset_address -0x8 rdi | |
1285 | + slot 2 offset_address -0xc rsi | |
1286 | + slot 3 offset_address -0x10 rbx | |
1287 | + rax = undefined | |
1288 | + rcx = undefined | |
1289 | + rdx = undefined | |
1290 | + '0xc015cd4a getname+0x62: cmp $0x0,%eax' | |
1291 | + opcode 'cmp' matched by 'cmp', usage 3 | |
1292 | + src I: $0x0 | |
1293 | + dst R: %eax base_rc 2 (rax) | |
1294 | + '0xc015cd4d getname+0x65: jle 0xc015cd5a <getname+0x72>' | |
1295 | + opcode 'jle' matched by 'j', usage 28 | |
1296 | + src M: 0xc015cd5a | |
1297 | + bb_reg_state c0728658 | |
1298 | + rax = undefined | |
1299 | + rbx = undefined | |
1300 | + rcx = undefined | |
1301 | + rdx = undefined | |
1302 | + rdi = rax | |
1303 | + rsi = undefined | |
1304 | + rbp = osp-0x4 | |
1305 | + rsp = osp-0x14 | |
1306 | + slot 0 offset_address -0x4 rbp | |
1307 | + slot 1 offset_address -0x8 rdi | |
1308 | + slot 2 offset_address -0xc rsi | |
1309 | + slot 3 offset_address -0x10 rbx | |
1310 | + matched: from 0xc015cd4d to 0xc015cd5a drop_through 0 bb_jmp[4] | |
1311 | + reuse bb_jmp[3] | |
1312 | + '0xc015cd4f getname+0x67: mov $0xffffffdc,%esi' | |
1313 | + opcode 'mov' matched by 'mov', usage 36 | |
1314 | + src I: $0xffffffdc | |
1315 | + dst R: %esi base_rc 7 (rsi) | |
1316 | + rsi = undefined | |
1317 | + '0xc015cd54 getname+0x6c: cmp %ebx,%eax' | |
1318 | + opcode 'cmp' matched by 'cmp', usage 3 | |
1319 | + src R: %ebx base_rc 3 (rbx) | |
1320 | + dst R: %eax base_rc 2 (rax) | |
1321 | + '0xc015cd56 getname+0x6e: jae 0xc015cd60 <getname+0x78>' | |
1322 | + opcode 'jae' matched by 'j', usage 28 | |
1323 | + src M: 0xc015cd60 | |
1324 | + bb_reg_state c0728658 | |
1325 | + rax = undefined | |
1326 | + rbx = undefined | |
1327 | + rcx = undefined | |
1328 | + rdx = undefined | |
1329 | + rdi = rax | |
1330 | + rsi = undefined | |
1331 | + rbp = osp-0x4 | |
1332 | + rsp = osp-0x14 | |
1333 | + slot 0 offset_address -0x4 rbp | |
1334 | + slot 1 offset_address -0x8 rdi | |
1335 | + slot 2 offset_address -0xc rsi | |
1336 | + slot 3 offset_address -0x10 rbx | |
1337 | + matched: from 0xc015cd56 to 0xc015cd60 drop_through 0 bb_jmp[5] | |
1338 | + reuse bb_jmp[3] | |
1339 | + '0xc015cd58 getname+0x70: jmp 0xc015cd71 <getname+0x89>' | |
1340 | + opcode 'jmp' matched by 'j', usage 28 | |
1341 | + src M: 0xc015cd71 | |
1342 | + bb_reg_state c0728658 | |
1343 | + rax = undefined | |
1344 | + rbx = undefined | |
1345 | + rcx = undefined | |
1346 | + rdx = undefined | |
1347 | + rdi = rax | |
1348 | + rsi = undefined | |
1349 | + rbp = osp-0x4 | |
1350 | + rsp = osp-0x14 | |
1351 | + slot 0 offset_address -0x4 rbp | |
1352 | + slot 1 offset_address -0x8 rdi | |
1353 | + slot 2 offset_address -0xc rsi | |
1354 | + slot 3 offset_address -0x10 rbx | |
1355 | + matched: from 0xc015cd58 to 0xc015cd71 drop_through 0 bb_jmp[6] | |
1356 | + reuse bb_jmp[3] | |
1357 | + | |
1358 | + bb[3] | |
1359 | + first state c0728768 | |
1360 | + bb_reg_state c0728658 | |
1361 | + rax = undefined | |
1362 | + rbx = undefined | |
1363 | + rcx = undefined | |
1364 | + rdx = undefined | |
1365 | + rdi = rax | |
1366 | + rsi = undefined | |
1367 | + rbp = osp-0x4 | |
1368 | + rsp = osp-0x14 | |
1369 | + slot 0 offset_address -0x4 rbp | |
1370 | + slot 1 offset_address -0x8 rdi | |
1371 | + slot 2 offset_address -0xc rsi | |
1372 | + slot 3 offset_address -0x10 rbx | |
1373 | + | |
1374 | +bb[3] only has one input, nothing to merge. | |
1375 | + | |
1376 | + '0xc015cd5a getname+0x72: je 0xc015cd76 <getname+0x8e>' | |
1377 | + opcode 'je' matched by 'j', usage 28 | |
1378 | + src M: 0xc015cd76 | |
1379 | + bb_reg_state c0728658 | |
1380 | + rax = undefined | |
1381 | + rbx = undefined | |
1382 | + rcx = undefined | |
1383 | + rdx = undefined | |
1384 | + rdi = rax | |
1385 | + rsi = undefined | |
1386 | + rbp = osp-0x4 | |
1387 | + rsp = osp-0x14 | |
1388 | + slot 0 offset_address -0x4 rbp | |
1389 | + slot 1 offset_address -0x8 rdi | |
1390 | + slot 2 offset_address -0xc rsi | |
1391 | + slot 3 offset_address -0x10 rbx | |
1392 | + matched: from 0xc015cd5a to 0xc015cd76 drop_through 0 bb_jmp[7] | |
1393 | + reuse bb_jmp[3] | |
1394 | + '0xc015cd5c getname+0x74: jge 0xc015cd71 <getname+0x89>' | |
1395 | + opcode 'jge' matched by 'j', usage 28 | |
1396 | + src M: 0xc015cd71 | |
1397 | + bb_reg_state c0728658 | |
1398 | + rax = undefined | |
1399 | + rbx = undefined | |
1400 | + rcx = undefined | |
1401 | + rdx = undefined | |
1402 | + rdi = rax | |
1403 | + rsi = undefined | |
1404 | + rbp = osp-0x4 | |
1405 | + rsp = osp-0x14 | |
1406 | + slot 0 offset_address -0x4 rbp | |
1407 | + slot 1 offset_address -0x8 rdi | |
1408 | + slot 2 offset_address -0xc rsi | |
1409 | + slot 3 offset_address -0x10 rbx | |
1410 | + matched: from 0xc015cd5c to 0xc015cd71 drop_through 0 bb_jmp[8] | |
1411 | + reuse bb_jmp[3] | |
1412 | + '0xc015cd5e getname+0x76: mov %eax,%esi' | |
1413 | + opcode 'mov' matched by 'mov', usage 36 | |
1414 | + src R: %eax base_rc 2 (rax) | |
1415 | + dst R: %esi base_rc 7 (rsi) | |
1416 | + rsi = rax (undefined) | |
1417 | + bb_reg_state c0728658 | |
1418 | + rax = undefined | |
1419 | + rbx = undefined | |
1420 | + rcx = undefined | |
1421 | + rdx = undefined | |
1422 | + rdi = rax | |
1423 | + rsi = undefined | |
1424 | + rbp = osp-0x4 | |
1425 | + rsp = osp-0x14 | |
1426 | + slot 0 offset_address -0x4 rbp | |
1427 | + slot 1 offset_address -0x8 rdi | |
1428 | + slot 2 offset_address -0xc rsi | |
1429 | + slot 3 offset_address -0x10 rbx | |
1430 | + matched: from 0xc015cd5f to 0xc015cd60 drop_through 1 bb_jmp[14] | |
1431 | + reuse bb_jmp[3] | |
1432 | + | |
1433 | + bb[5] | |
1434 | + first state c0728768 | |
1435 | + bb_reg_state c0728658 | |
1436 | + rax = undefined | |
1437 | + rbx = undefined | |
1438 | + rcx = undefined | |
1439 | + rdx = undefined | |
1440 | + rdi = rax | |
1441 | + rsi = undefined | |
1442 | + rbp = osp-0x4 | |
1443 | + rsp = osp-0x14 | |
1444 | + slot 0 offset_address -0x4 rbp | |
1445 | + slot 1 offset_address -0x8 rdi | |
1446 | + slot 2 offset_address -0xc rsi | |
1447 | + slot 3 offset_address -0x10 rbx | |
1448 | + merging state c0728768 | |
1449 | + '0xc015cd71 getname+0x89: mov 0xfffffff0(%ebp),%eax' | |
1450 | + opcode 'mov' matched by 'mov', usage 36 | |
1451 | + src M: 0xfffffff0(%ebp) base_rc 8 (rbp) | |
1452 | + dst R: %eax base_rc 2 (rax) | |
1453 | + rax = *(rbp-0x10) (osp-0x14) rax = undefined | |
1454 | + '0xc015cd74 getname+0x8c: jmp 0xc015cd7d <getname+0x95>' | |
1455 | + opcode 'jmp' matched by 'j', usage 28 | |
1456 | + src M: 0xc015cd7d | |
1457 | + bb_reg_state c0728658 | |
1458 | + rax = undefined | |
1459 | + rbx = undefined | |
1460 | + rcx = undefined | |
1461 | + rdx = undefined | |
1462 | + rdi = rax | |
1463 | + rsi = undefined | |
1464 | + rbp = osp-0x4 | |
1465 | + rsp = osp-0x14 | |
1466 | + slot 0 offset_address -0x4 rbp | |
1467 | + slot 1 offset_address -0x8 rdi | |
1468 | + slot 2 offset_address -0xc rsi | |
1469 | + slot 3 offset_address -0x10 rbx | |
1470 | + matched: from 0xc015cd74 to 0xc015cd7d drop_through 0 bb_jmp[10] | |
1471 | + reuse bb_jmp[3] | |
1472 | + | |
1473 | + bb[6] | |
1474 | + first state c0728768 | |
1475 | + bb_reg_state c0728658 | |
1476 | + rax = undefined | |
1477 | + rbx = undefined | |
1478 | + rcx = undefined | |
1479 | + rdx = undefined | |
1480 | + rdi = rax | |
1481 | + rsi = undefined | |
1482 | + rbp = osp-0x4 | |
1483 | + rsp = osp-0x14 | |
1484 | + slot 0 offset_address -0x4 rbp | |
1485 | + slot 1 offset_address -0x8 rdi | |
1486 | + slot 2 offset_address -0xc rsi | |
1487 | + slot 3 offset_address -0x10 rbx | |
1488 | + '0xc015cd76 getname+0x8e: mov $0xfffffffe,%esi' | |
1489 | + opcode 'mov' matched by 'mov', usage 36 | |
1490 | + src I: $0xfffffffe | |
1491 | + dst R: %esi base_rc 7 (rsi) | |
1492 | + rsi = undefined | |
1493 | + '0xc015cd7b getname+0x93: jmp 0xc015cd60 <getname+0x78>' | |
1494 | + opcode 'jmp' matched by 'j', usage 28 | |
1495 | + src M: 0xc015cd60 | |
1496 | + bb_reg_state c0728658 | |
1497 | + rax = undefined | |
1498 | + rbx = undefined | |
1499 | + rcx = undefined | |
1500 | + rdx = undefined | |
1501 | + rdi = rax | |
1502 | + rsi = undefined | |
1503 | + rbp = osp-0x4 | |
1504 | + rsp = osp-0x14 | |
1505 | + slot 0 offset_address -0x4 rbp | |
1506 | + slot 1 offset_address -0x8 rdi | |
1507 | + slot 2 offset_address -0xc rsi | |
1508 | + slot 3 offset_address -0x10 rbx | |
1509 | + matched: from 0xc015cd7b to 0xc015cd60 drop_through 0 bb_jmp[11] | |
1510 | + reuse bb_jmp[3] | |
1511 | + | |
1512 | + bb[4] | |
1513 | + first state c0728710 | |
1514 | + bb_reg_state c0728658 | |
1515 | + rax = undefined | |
1516 | + rbx = rbx | |
1517 | + rcx = undefined | |
1518 | + rdx = undefined | |
1519 | + rdi = rax | |
1520 | + rsi = undefined | |
1521 | + rbp = osp-0x4 | |
1522 | + rsp = osp-0x14 | |
1523 | + slot 0 offset_address -0x4 rbp | |
1524 | + slot 1 offset_address -0x8 rdi | |
1525 | + slot 2 offset_address -0xc rsi | |
1526 | + slot 3 offset_address -0x10 rbx | |
1527 | + merging state c0728768 | |
1528 | + rbx = undefined | |
1529 | + merging state c0728768 | |
1530 | + merging state c0728768 | |
1531 | + | |
1532 | +bb[4] has 4 inputs, 3 of which have the same state. One one path (state | |
1533 | +c0728710) rbx is defined, on the others (c0728768) rbx is undefined so the final | |
1534 | +state has rbx as undefined. | |
1535 | + | |
1536 | + final state | |
1537 | + bb_reg_state c0728658 | |
1538 | + rax = undefined | |
1539 | + rbx = undefined | |
1540 | + rcx = undefined | |
1541 | + rdx = undefined | |
1542 | + rdi = rax | |
1543 | + rsi = undefined | |
1544 | + rbp = osp-0x4 | |
1545 | + rsp = osp-0x14 | |
1546 | + slot 0 offset_address -0x4 rbp | |
1547 | + slot 1 offset_address -0x8 rdi | |
1548 | + slot 2 offset_address -0xc rsi | |
1549 | + slot 3 offset_address -0x10 rbx | |
1550 | + '0xc015cd60 getname+0x78: mov 0xfffffff0(%ebp),%edx' | |
1551 | + opcode 'mov' matched by 'mov', usage 36 | |
1552 | + src M: 0xfffffff0(%ebp) base_rc 8 (rbp) | |
1553 | + dst R: %edx base_rc 5 (rdx) | |
1554 | + rdx = *(rbp-0x10) (osp-0x14) rdx = undefined | |
1555 | + '0xc015cd63 getname+0x7b: mov 0xc04b2120,%eax' | |
1556 | + opcode 'mov' matched by 'mov', usage 36 | |
1557 | + src M: 0xc04b2120 | |
1558 | + dst R: %eax base_rc 2 (rax) | |
1559 | + rax = undefined | |
1560 | + '0xc015cd68 getname+0x80: call 0xc01521f1 <kmem_cache_free>' | |
1561 | + opcode 'call' matched by 'call', usage 17 | |
1562 | + src M: 0xc01521f1 | |
1563 | + bb_reg_state c0728658 | |
1564 | + rax = undefined | |
1565 | + rbx = undefined | |
1566 | + rcx = undefined | |
1567 | + rdx = undefined | |
1568 | + rdi = rax | |
1569 | + rsi = undefined | |
1570 | + rbp = osp-0x4 | |
1571 | + rsp = osp-0x14 | |
1572 | + slot 0 offset_address -0x4 rbp | |
1573 | + slot 1 offset_address -0x8 rdi | |
1574 | + slot 2 offset_address -0xc rsi | |
1575 | + slot 3 offset_address -0x10 rbx | |
1576 | + rax = undefined | |
1577 | + rcx = undefined | |
1578 | + rdx = undefined | |
1579 | + bb_reg_state c0728658 | |
1580 | + rax = undefined | |
1581 | + rbx = undefined | |
1582 | + rcx = undefined | |
1583 | + rdx = undefined | |
1584 | + rdi = rax | |
1585 | + rsi = undefined | |
1586 | + rbp = osp-0x4 | |
1587 | + rsp = osp-0x14 | |
1588 | + slot 0 offset_address -0x4 rbp | |
1589 | + slot 1 offset_address -0x8 rdi | |
1590 | + slot 2 offset_address -0xc rsi | |
1591 | + slot 3 offset_address -0x10 rbx | |
1592 | + '0xc015cd6d getname+0x85: mov %esi,%eax' | |
1593 | + opcode 'mov' matched by 'mov', usage 36 | |
1594 | + src R: %esi base_rc 7 (rsi) | |
1595 | + dst R: %eax base_rc 2 (rax) | |
1596 | + rax = rsi (undefined) | |
1597 | + '0xc015cd6f getname+0x87: jmp 0xc015cd7d <getname+0x95>' | |
1598 | + opcode 'jmp' matched by 'j', usage 28 | |
1599 | + src M: 0xc015cd7d | |
1600 | + bb_reg_state c0728658 | |
1601 | + rax = undefined | |
1602 | + rbx = undefined | |
1603 | + rcx = undefined | |
1604 | + rdx = undefined | |
1605 | + rdi = rax | |
1606 | + rsi = undefined | |
1607 | + rbp = osp-0x4 | |
1608 | + rsp = osp-0x14 | |
1609 | + slot 0 offset_address -0x4 rbp | |
1610 | + slot 1 offset_address -0x8 rdi | |
1611 | + slot 2 offset_address -0xc rsi | |
1612 | + slot 3 offset_address -0x10 rbx | |
1613 | + matched: from 0xc015cd6f to 0xc015cd7d drop_through 0 bb_jmp[9] | |
1614 | + reuse bb_jmp[3] | |
1615 | + | |
1616 | + bb[7] | |
1617 | + first state c07286b8 | |
1618 | + bb_reg_state c0728658 | |
1619 | + rax = undefined | |
1620 | + rbx = rbx | |
1621 | + rcx = undefined | |
1622 | + rdx = undefined | |
1623 | + rdi = rax | |
1624 | + rsi = rsi | |
1625 | + rbp = osp-0x4 | |
1626 | + rsp = osp-0x14 | |
1627 | + slot 0 offset_address -0x4 rbp | |
1628 | + slot 1 offset_address -0x8 rdi | |
1629 | + slot 2 offset_address -0xc rsi | |
1630 | + slot 3 offset_address -0x10 rbx | |
1631 | + merging state c0728768 | |
1632 | + rbx = undefined | |
1633 | + rsi = undefined | |
1634 | + merging state c0728768 | |
1635 | + final state | |
1636 | + bb_reg_state c0728658 | |
1637 | + rax = undefined | |
1638 | + rbx = undefined | |
1639 | + rcx = undefined | |
1640 | + rdx = undefined | |
1641 | + rdi = rax | |
1642 | + rsi = undefined | |
1643 | + rbp = osp-0x4 | |
1644 | + rsp = osp-0x14 | |
1645 | + slot 0 offset_address -0x4 rbp | |
1646 | + slot 1 offset_address -0x8 rdi | |
1647 | + slot 2 offset_address -0xc rsi | |
1648 | + slot 3 offset_address -0x10 rbx | |
1649 | + '0xc015cd7d getname+0x95: pop %edx' | |
1650 | + opcode 'pop' matched by 'pop', usage 42 | |
1651 | + src R: %edx base_rc 5 (rdx) | |
1652 | + rdx = *(rsp+0x0) (osp-0x14) rdx = undefined | |
1653 | + rsp osp offset -0x14 -> -0x10 | |
1654 | + | |
1655 | +This instruction is a bit misleading. It looks like gcc is restoring a value | |
1656 | +from the stack *(osp-0x14) to edx, but we have no record of any useful data | |
1657 | +being stored at osp-0x14. In fact gcc is just reducing the stack pointer by 4 | |
1658 | +bytes to reverse the effect of 0xc015ccee: sub $0x4,%esp, the value popped into | |
1659 | +edx contains nothing useful. Why gcc does pop instead of add $0x4,%esp is a | |
1660 | +puzzle, probably some micro optimization. | |
1661 | + | |
1662 | + '0xc015cd7e getname+0x96: pop %ebx' | |
1663 | + opcode 'pop' matched by 'pop', usage 42 | |
1664 | + src R: %ebx base_rc 3 (rbx) | |
1665 | + rbx = *(rsp+0x0) (osp-0x10) value rbx | |
1666 | + rsp osp offset -0x10 -> -0xc | |
1667 | + delete rbx from osp-0x10 slot 3 | |
1668 | + | |
1669 | +This pop is doing something useful. It is restoring the original value of the | |
1670 | +preserved register ebx from stack, reversing 0xc015cced: push %ebx. Note that | |
1671 | +incrementing rsp from osp-0x10 to osp-0xc invalidates the data held in memory at | |
1672 | +osp-0x10, so we delete our record of it. | |
1673 | + | |
1674 | + '0xc015cd7f getname+0x97: pop %esi' | |
1675 | + opcode 'pop' matched by 'pop', usage 42 | |
1676 | + src R: %esi base_rc 7 (rsi) | |
1677 | + rsi = *(rsp+0x0) (osp-0xc) value rsi | |
1678 | + rsp osp offset -0xc -> -0x8 | |
1679 | + delete rsi from osp-0xc slot 2 | |
1680 | + '0xc015cd80 getname+0x98: pop %edi' | |
1681 | + opcode 'pop' matched by 'pop', usage 42 | |
1682 | + src R: %edi base_rc 6 (rdi) | |
1683 | + rdi = *(rsp+0x0) (osp-0x8) value rdi | |
1684 | + rsp osp offset -0x8 -> -0x4 | |
1685 | + delete rdi from osp-0x8 slot 1 | |
1686 | + | |
1687 | +Pop the other preserved registers, in reverse order to the push sequence at the | |
1688 | +start. | |
1689 | + | |
1690 | + '0xc015cd81 getname+0x99: pop %ebp' | |
1691 | + opcode 'pop' matched by 'pop', usage 42 | |
1692 | + src R: %ebp base_rc 8 (rbp) | |
1693 | + rbp = *(rsp+0x0) (osp-0x4) value rbp | |
1694 | + rsp osp offset -0x4 -> +0x0 | |
1695 | + delete rbp from osp-0x4 slot 0 | |
1696 | + | |
1697 | +Pop the previous frame pointer. | |
1698 | + | |
1699 | + '0xc015cd82 getname+0x9a: ret ' | |
1700 | + opcode 'ret' matched by 'ret', usage 48 | |
1701 | + | |
1702 | +When a ret instruction is executed, all the preserved registers must be back to | |
1703 | +their original value and the stack pointer must contain osp+0. | |
1704 | +bb_sanity_check() will complain and abort the backtrace if this is not true. No | |
1705 | +complaints here. | |
1706 | + | |
1707 | + bb_pass2: end bb_reg_params 1 bb_memory_params 0 | |
1708 | + | |
1709 | +We identified one argument passed in a register (the read of rax at 0xc015ccf1) | |
1710 | +and no reference to memory locations above the stack frame. So we have one | |
1711 | +argument being passed in a register and no arguments being passed on stack. | |
1712 | +This matches | |
1713 | + | |
1714 | + char * getname(const char __user * filename) | |
1715 | + | |
1716 | + bb_pass2: bb_exit_state at 0xc015cd6d | |
1717 | + bb_reg_state c07287c0 | |
1718 | + rax = undefined | |
1719 | + rbx = undefined | |
1720 | + rcx = undefined | |
1721 | + rdx = undefined | |
1722 | + rdi = rax | |
1723 | + rsi = undefined | |
1724 | + rbp = osp-0x4 | |
1725 | + rsp = osp-0x14 | |
1726 | + slot 0 offset_address -0x4 rbp | |
1727 | + slot 1 offset_address -0x8 rdi | |
1728 | + slot 2 offset_address -0xc rsi | |
1729 | + slot 3 offset_address -0x10 rbx | |
1730 | + | |
1731 | +We told bb1 that the exit address from this function is 0xc015cd6d. The | |
1732 | +abstract state at this exit point was saved, it defines how we rollback the | |
1733 | +actual register values from the next function down the stack (kmem_cache_free) | |
1734 | +to get the actual register values on entry to this function (getname). See | |
1735 | +bb_actual_rollback() which updates bb_actual[]. | |
1736 | + | |
1737 | +Looking at the exit state above, we see that rsp contains the abstracte value | |
1738 | +osp-0x14. It is a given that we have the actual value of rsp after the call | |
1739 | +from getname() to kmem_cache_free(), otherwise we would not have found the | |
1740 | +return address on stack and we would not be analysing getname(). Adding 0x14 | |
1741 | +(the delta from osp to rsp) to our current actual rsp gives us the actual value | |
1742 | +of osp on entry to getname(). | |
1743 | + | |
1744 | +The main aim of doing all this work is to track the function arguments so we can | |
1745 | +print them if possible. getname() only has one argument which was passed in | |
1746 | +eax. According to the abstract exit state, the original value of rax is | |
1747 | +currently in rdi, so by looking at the actual value of rdi from the next stack | |
1748 | +frame down we are able to get the argument to getname(). | |
1749 | + | |
1750 | +It is not always possible to get register arguments, gcc will only preserve | |
1751 | +input arguments as long as it needs them so there may be no saved copy of | |
1752 | +arguments that are passed in register. In this case, bt_print_one() prints | |
1753 | +"invalid". | |
1754 | + | |
1755 | +If basic block analysis detected any arguments were passed on stack, their | |
1756 | +contents can now be extracted based on the known value of the stack pointer. | |
1757 | +bt_print_one() prints the arguments, if BT_ARGS is non-zero then any argument | |
1758 | +that might be a kernel address is printed as a symbol. | |
1759 | + | |
1760 | +Once rsp has been rolled back to osp, we can calculate that actual address of | |
1761 | +the stack locations that contain useful data. The previous values of rbp, rdi, | |
1762 | +rsi and rbx are then copied from those locations into bb_actual[]. That gives | |
1763 | +the values for those registers at the exit point from the function that called | |
1764 | +getname(). Go up one level and repeat the analysis. | |
1765 | + | |
1766 | +There are two references to rdi in the exit state, which can be confusing. | |
1767 | + | |
1768 | + rdi = rax | |
1769 | + slot 1 offset_address -0x8 rdi | |
1770 | + | |
1771 | +The first reference says that "register rdi contains the original value of rax", | |
1772 | +the second reference says that "*(osp-0x8) contains the original value of rdi". | |
1773 | +Do not confuse the two, one is by name, the other is by value. | |
1774 | + | |
1775 | +getname() is a fairly simple function, it has no loops. __follow_mount is more | |
1776 | +complicated, it has loops as well as BUG() statements. | |
1777 | + | |
1778 | + [0]kdb> id __follow_mount | |
1779 | + 0xc015be76 __follow_mount: push %ebp | |
1780 | + 0xc015be77 __follow_mount+0x1: mov %esp,%ebp | |
1781 | + 0xc015be79 __follow_mount+0x3: push %edi | |
1782 | + 0xc015be7a __follow_mount+0x4: push %esi | |
1783 | + 0xc015be7b __follow_mount+0x5: push %ebx | |
1784 | + 0xc015be7c __follow_mount+0x6: mov %eax,%esi | |
1785 | + 0xc015be7e __follow_mount+0x8: xor %edi,%edi | |
1786 | + 0xc015be80 __follow_mount+0xa: jmp 0xc015beca __follow_mount+0x54 | |
1787 | + 0xc015be82 __follow_mount+0xc: mov (%esi),%eax | |
1788 | + 0xc015be84 __follow_mount+0xe: call 0xc0169664 lookup_mnt | |
1789 | + 0xc015be89 __follow_mount+0x13: mov %eax,%ebx | |
1790 | + 0xc015be8b __follow_mount+0x15: test %eax,%eax | |
1791 | + 0xc015be8d __follow_mount+0x17: je 0xc015bed3 __follow_mount+0x5d | |
1792 | + 0xc015be8f __follow_mount+0x19: mov 0x4(%esi),%eax | |
1793 | + 0xc015be92 __follow_mount+0x1c: call 0xc0163de2 dput | |
1794 | + 0xc015be97 __follow_mount+0x21: test %edi,%edi | |
1795 | + 0xc015be99 __follow_mount+0x23: je 0xc015bead __follow_mount+0x37 | |
1796 | + 0xc015be9b __follow_mount+0x25: mov (%esi),%eax | |
1797 | + 0xc015be9d __follow_mount+0x27: test %eax,%eax | |
1798 | + 0xc015be9f __follow_mount+0x29: je 0xc015bead __follow_mount+0x37 | |
1799 | + 0xc015bea1 __follow_mount+0x2b: movl $0x0,0x64(%eax) | |
1800 | + 0xc015bea8 __follow_mount+0x32: call 0xc016835b mntput_no_expire | |
1801 | + 0xc015bead __follow_mount+0x37: mov %ebx,(%esi) | |
1802 | + 0xc015beaf __follow_mount+0x39: mov 0x10(%ebx),%eax | |
1803 | + 0xc015beb2 __follow_mount+0x3c: test %eax,%eax | |
1804 | + 0xc015beb4 __follow_mount+0x3e: je 0xc015bec2 __follow_mount+0x4c | |
1805 | + 0xc015beb6 __follow_mount+0x40: cmpl $0x0,(%eax) | |
1806 | + 0xc015beb9 __follow_mount+0x43: jne 0xc015bebf __follow_mount+0x49 | |
1807 | + 0xc015bebb __follow_mount+0x45: ud2a | |
1808 | + 0xc015bebd __follow_mount+0x47: jmp 0xc015bebd __follow_mount+0x47 | |
1809 | + 0xc015bebf __follow_mount+0x49: lock incl (%eax) | |
1810 | + 0xc015bec2 __follow_mount+0x4c: mov %eax,0x4(%esi) | |
1811 | + 0xc015bec5 __follow_mount+0x4f: mov $0x1,%edi | |
1812 | + 0xc015beca __follow_mount+0x54: mov 0x4(%esi),%edx | |
1813 | + 0xc015becd __follow_mount+0x57: cmpl $0x0,0x74(%edx) | |
1814 | + 0xc015bed1 __follow_mount+0x5b: jne 0xc015be82 __follow_mount+0xc | |
1815 | + 0xc015bed3 __follow_mount+0x5d: mov %edi,%eax | |
1816 | + 0xc015bed5 __follow_mount+0x5f: pop %ebx | |
1817 | + 0xc015bed6 __follow_mount+0x60: pop %esi | |
1818 | + 0xc015bed7 __follow_mount+0x61: pop %edi | |
1819 | + 0xc015bed8 __follow_mount+0x62: pop %ebp | |
1820 | + 0xc015bed9 __follow_mount+0x63: ret | |
1821 | + | |
1822 | + [0]kdb> bb1 0xc015bed9 | |
1823 | + bb_pass1: func_name __follow_mount func_start 0xc015be76 func_end 0xc015beda | |
1824 | + bb_pass1: end | |
1825 | + bb[0] start 0xc015be76 end 0xc015be80 drop_through 0 | |
1826 | + bb[1] start 0xc015be82 end 0xc015beac drop_through 1 | |
1827 | + bb[2] start 0xc015bead end 0xc015bebb drop_through 0 | |
1828 | + | |
1829 | +Note that the ud2a (BUG) instruction at 0xc015bebb ends bb[2]. | |
1830 | + | |
1831 | + bb[3] start 0xc015bebd end 0xc015bebd drop_through 0 | |
1832 | + | |
1833 | +bb[3] is peculiar, it is a jmp to itself, nothing else refers to 0xc015bebd and | |
1834 | +you cannot drop through from the previous instruction because ud2a kills the | |
1835 | +kernel. The i386 and x86_64 BUG() macros contain for(;;) after ud2a, for no | |
1836 | +good reason that I can see (is there old hardware that does not abort on ud2a?). | |
1837 | +ia64 and the generic versions of BUG() do not contain for(;;). for(;;) after | |
1838 | +ud2a generates a branch to itself than can never be executed. | |
1839 | + | |
1840 | + bb[4] start 0xc015bebf end 0xc015bec1 drop_through 1 | |
1841 | + bb[5] start 0xc015bec2 end 0xc015bec9 drop_through 1 | |
1842 | + bb[6] start 0xc015beca end 0xc015bed2 drop_through 1 | |
1843 | + bb[7] start 0xc015bed3 end 0xc015bed9 drop_through 0 | |
1844 | + bb_jmp[0] from 0xc015be80 to 0xc015beca drop_through 0 | |
1845 | + bb_jmp[1] from 0xc015be8d to 0xc015bed3 drop_through 0 | |
1846 | + bb_jmp[2] from 0xc015be99 to 0xc015bead drop_through 0 | |
1847 | + bb_jmp[3] from 0xc015be9f to 0xc015bead drop_through 0 | |
1848 | + bb_jmp[4] from 0xc015beb4 to 0xc015bec2 drop_through 0 | |
1849 | + bb_jmp[5] from 0xc015beb9 to 0xc015bebf drop_through 0 | |
1850 | + bb_jmp[6] from 0xc015bebd to 0xc015bebd drop_through 0 | |
1851 | + bb_jmp[7] from 0xc015bed1 to 0xc015be82 drop_through 0 | |
1852 | + bb_jmp[8] from 0xc015beac to 0xc015bead drop_through 1 | |
1853 | + bb_jmp[9] from 0xc015bec1 to 0xc015bec2 drop_through 1 | |
1854 | + bb_jmp[10] from 0xc015bec9 to 0xc015beca drop_through 1 | |
1855 | + bb_jmp[11] from 0xc015bed2 to 0xc015bed3 drop_through 1 | |
1856 | + | |
1857 | +Apart from bb[0] and the special case bb[3], all the other blocks are part of a | |
1858 | +cycle. That cycle goes bb[0] -> bb[6]. bb[6] -> {bb[1], bb[7]}. bb[1] -> | |
1859 | +{bb[2], bb[7]}. bb[2] -> {bb[4], bb[5]}. bb[4] -> bb[5]. bb[5] -> bb[6] and | |
1860 | +back to the start. bb[7] ends with 'ret', it does not feed into other blocks. | |
1861 | + | |
1862 | + bb_pass2: start | |
1863 | + | |
1864 | + bb_pass2_do_changed_blocks: allow_missing 0 | |
1865 | + | |
1866 | + bb[0] | |
1867 | + [ ... detail snipped ... ] | |
1868 | + matched: from 0xc015be80 to 0xc015beca drop_through 0 bb_jmp[0] | |
1869 | + new state c07286d8 | |
1870 | + | |
1871 | + bb_pass2_do_changed_blocks: allow_missing 1 | |
1872 | + | |
1873 | +Because of the cycle, only bb[0] can be processed with 0 missing inputs, all the | |
1874 | +other blocks have at least one missing input. Call bb_pass2_do_changed_blocks() | |
1875 | +again, this time allowing one missing input per blocks. | |
1876 | + | |
1877 | + bb[6] | |
1878 | + first state c07286d8 | |
1879 | + [ ... detail snipped ... ] | |
1880 | + matched: from 0xc015bed2 to 0xc015bed3 drop_through 1 bb_jmp[11] | |
1881 | + reuse bb_jmp[7] | |
1882 | + | |
1883 | + bb[7] | |
1884 | + first state c0728730 | |
1885 | + [ ... detail snipped ... ] | |
1886 | + | |
1887 | + bb[1] | |
1888 | + first state c0728730 | |
1889 | + [ ... detail snipped ... ] | |
1890 | + matched: from 0xc015beac to 0xc015bead drop_through 1 bb_jmp[8] | |
1891 | + reuse bb_jmp[1] | |
1892 | + | |
1893 | + bb[2] | |
1894 | + first state c0728788 | |
1895 | + [ ... detail snipped ... ] | |
1896 | + merging state c0728788 | |
1897 | + merging state c0728788 | |
1898 | + [ ... detail snipped ... ] | |
1899 | + matched: from 0xc015beb9 to 0xc015bebf drop_through 0 bb_jmp[5] | |
1900 | + reuse bb_jmp[1] | |
1901 | + | |
1902 | + bb[4] | |
1903 | + first state c0728788 | |
1904 | + [ ... detail snipped ... ] | |
1905 | + matched: from 0xc015bec1 to 0xc015bec2 drop_through 1 bb_jmp[9] | |
1906 | + reuse bb_jmp[1] | |
1907 | + | |
1908 | + bb[5] | |
1909 | + first state c0728788 | |
1910 | + [ ... detail snipped ... ] | |
1911 | + merging state c0728788 | |
1912 | + [ ... detail snipped ... ] | |
1913 | + matched: from 0xc015bec9 to 0xc015beca drop_through 1 bb_jmp[10] | |
1914 | + reuse bb_jmp[1] | |
1915 | + | |
1916 | + bb[6] | |
1917 | + first state c07286d8 | |
1918 | + [ ... detail snipped ... ] | |
1919 | + merging state c0728788 | |
1920 | + matched: from 0xc015bed2 to 0xc015bed3 drop_through 1 bb_jmp[11] | |
1921 | + reuse bb_jmp[1] | |
1922 | + | |
1923 | +Note the rescan of bb[6]. The first scan only had one input from bb[0]. After | |
1924 | +traversing the cycle and getting back from bb[5] to bb[6], bb[6] now has more | |
1925 | +inputs so we need to rescan it. With the additional input, the output state | |
1926 | +from bb[6] has changed since the first scan, which means that every block it | |
1927 | +feeds has to be rescanned. bb[6] feeds bb[1] and bb[7]. | |
1928 | + | |
1929 | + bb[7] | |
1930 | + first state c0728788 | |
1931 | + [ ... detail snipped ... ] | |
1932 | + merging state c0728788 | |
1933 | + [ ... detail snipped ... ] | |
1934 | + | |
1935 | +bb[7] being rescanned, this time it has data for both its inputs. | |
1936 | + | |
1937 | + bb[1] | |
1938 | + first state c0728788 | |
1939 | + [ ... detail snipped ... ] | |
1940 | + matched: from 0xc015beac to 0xc015bead drop_through 1 bb_jmp[8] | |
1941 | + no state change | |
1942 | + | |
1943 | +bb[1] is being rescanned because the input from bb[6] has changed, however the | |
1944 | +rescan of bb[1] reports 'no state change', the changed input from bb[6] did not | |
1945 | +affect the final output state from bb[1]. Because the output state from bb[1] | |
1946 | +has not changed since the previous scan, there is no need to rescan bb[2], bb[7] | |
1947 | +or bb[4]. Since bb[4] is not being rescanned, there is no need to rescan bb[5] | |
1948 | +or bb[6] and the cycle is closed. | |
1949 | --- /dev/null | |
1950 | +++ b/Documentation/kdb/kdb.mm | |
1951 | @@ -0,0 +1,492 @@ | |
1952 | +.TH KDB 8 "September 21, 2005" | |
1953 | +.hy 0 | |
1954 | +.SH NAME | |
1955 | +Built-in Kernel Debugger for Linux - v4.4 | |
1956 | +.SH "Overview" | |
1957 | +This document describes the built-in kernel debugger available | |
1958 | +for linux. This debugger allows the programmer to interactively | |
1959 | +examine kernel memory, disassemble kernel functions, set breakpoints | |
1960 | +in the kernel code and display and modify register contents. | |
1961 | +.P | |
1962 | +A symbol table is included in the kernel image and in modules which | |
1963 | +enables all non-stack symbols (including static symbols) to be used as | |
1964 | +arguments to the kernel debugger commands. | |
1965 | +.SH "Getting Started" | |
1966 | +To include the kernel debugger in a linux kernel, use a | |
1967 | +configuration mechanism (e.g. xconfig, menuconfig, et. al.) | |
1968 | +to enable the \fBCONFIG_KDB\fP option. Additionally, for accurate | |
1969 | +stack tracebacks, it is recommended that the \fBCONFIG_FRAME_POINTER\fP | |
1970 | +option be enabled (if present). \fBCONFIG_FRAME_POINTER\fP changes the compiler | |
1971 | +flags so that the frame pointer register will be used as a frame | |
1972 | +pointer rather than a general purpose register. | |
1973 | +.P | |
1974 | +After linux has been configured to include the kernel debugger, | |
1975 | +make a new kernel with the new configuration file (a make clean | |
1976 | +is recommended before making the kernel), and install the kernel | |
1977 | +as normal. | |
1978 | +.P | |
1979 | +You can compile a kernel with kdb support but have kdb off by default, | |
1980 | +select \fBCONFIG_KDB_OFF\fR. Then the user has to explicitly activate | |
1981 | +kdb by booting with the 'kdb=on' flag or, after /proc is mounted, by | |
1982 | +.nf | |
1983 | + echo "1" > /proc/sys/kernel/kdb | |
1984 | +.fi | |
1985 | +You can also do the reverse, compile a kernel with kdb on and | |
1986 | +deactivate kdb with the boot flag 'kdb=off' or, after /proc is mounted, | |
1987 | +by | |
1988 | +.nf | |
1989 | + echo "0" > /proc/sys/kernel/kdb | |
1990 | +.fi | |
1991 | +.P | |
1992 | +When booting the new kernel, the 'kdb=early' flag | |
1993 | +may be added after the image name on the boot line to | |
1994 | +force the kernel to stop in the kernel debugger early in the | |
1995 | +kernel initialization process. 'kdb=early' implies 'kdb=on'. | |
1996 | +If the 'kdb=early' flag isn't provided, then kdb will automatically be | |
1997 | +invoked upon system panic or when the \fBPAUSE\fP key is used from the | |
1998 | +keyboard, assuming that kdb is on. Older versions of kdb used just a | |
1999 | +boot flag of 'kdb' to activate kdb early, this is no longer supported. | |
2000 | +.P | |
2001 | +KDB can also be used via the serial port. Set up the system to | |
2002 | +have a serial console (see \fIDocumentation/serial-console.txt\fP), you | |
2003 | +must also have a user space program such as agetty set up to read from | |
2004 | +the serial console. | |
2005 | +The control sequence \fB<esc>KDB\fP on the serial port will cause the | |
2006 | +kernel debugger to be entered, assuming that kdb is on, that some | |
2007 | +program is reading from the serial console, at least one cpu is | |
2008 | +accepting interrupts and the serial console driver is still usable. | |
2009 | +.P | |
2010 | +\fBNote:\fR\ When the serial console sequence consists of multiple | |
2011 | +characters such as <esc>KDB then all but the last character are passed | |
2012 | +through to the application that is reading from the serial console. | |
2013 | +After exiting from kdb, you should use backspace to delete the rest of | |
2014 | +the control sequence. | |
2015 | +.P | |
2016 | +You can boot with kdb activated but without the ability to enter kdb | |
2017 | +via any keyboard sequence. | |
2018 | +In this mode, kdb will only be entered after a system failure. | |
2019 | +Booting with kdb=on-nokey will activate kdb but ignore keyboard | |
2020 | +sequences that would normally drop you into kdb. | |
2021 | +kdb=on-nokey is mainly useful when you are using a PC keyboard and your | |
2022 | +application needs to use the Pause key. | |
2023 | +You can also activate this mode by | |
2024 | +.nf | |
2025 | + echo "2" > /proc/sys/kernel/kdb | |
2026 | +.fi | |
2027 | +.P | |
2028 | +If the console is sitting on the login prompt when you enter kdb, then | |
2029 | +the login command may switch into upper case mode. | |
2030 | +This is not a kdb bug, it is a "feature" of login - if the userid is | |
2031 | +all upper case then login assumes that you using a TeleType (circa | |
2032 | +1960) which does not have lower case characters. | |
2033 | +Wait 60 seconds for login to timeout and it will switch back to lower | |
2034 | +case mode. | |
2035 | +.P | |
2036 | +\fBNote:\fR\ Your distributor may have chosen a different kdb | |
2037 | +activation sequence for the serial console. | |
2038 | +Consult your distribution documentation. | |
2039 | +.P | |
2040 | +If you have both a keyboard+video and a serial console, you can use | |
2041 | +either for kdb. | |
2042 | +Define both video and serial consoles with boot parameters | |
2043 | +.P | |
2044 | +.nf | |
2045 | + console=tty0 console=ttyS0,38400 | |
2046 | +.fi | |
2047 | +.P | |
2048 | +Any kdb data entered on the keyboard or the serial console will be echoed | |
2049 | +to both. | |
2050 | +.P | |
2051 | +If you are using a USB keyboard then kdb commands cannot be entered | |
2052 | +until the kernel has initialised the USB subsystem and recognised the | |
2053 | +keyboard. | |
2054 | +Using kdb=early with a USB keyboard will not work, the USB subsystem is | |
2055 | +initialised too late. | |
2056 | +.P | |
2057 | +While kdb is active, the keyboard (not serial console) indicators may strobe. | |
2058 | +The caps lock and scroll lock lights will turn on and off, num lock is not used | |
2059 | +because it can confuse laptop keyboards where the numeric keypad is mapped over | |
2060 | +the normal keys. | |
2061 | +On exit from kdb the keyboard indicators will probably be wrong, they will not match the kernel state. | |
2062 | +Pressing caps lock twice should get the indicators back in sync with | |
2063 | +the kernel. | |
2064 | +.SH "Basic Commands" | |
2065 | +There are several categories of commands available to the | |
2066 | +kernel debugger user including commands providing memory | |
2067 | +display and modification, register display and modification, | |
2068 | +instruction disassemble, breakpoints and stack tracebacks. | |
2069 | +Any command can be prefixed with '-' which will cause kdb to ignore any | |
2070 | +errors on that command, this is useful when packaging commands using | |
2071 | +defcmd. | |
2072 | +A line whose first non-space character is '#' is printed and ignored. | |
2073 | +.P | |
2074 | +The following table shows the currently implemented standard commands, | |
2075 | +these are always available. Other commands can be added by extra | |
2076 | +debugging modules, type '?' at the kdb prompt to get a list of all | |
2077 | +available commands. | |
2078 | +.DS | |
2079 | +.TS | |
2080 | +box, center; | |
2081 | +l | l | |
2082 | +l | l. | |
2083 | +Command Description | |
2084 | +_ | |
2085 | +bc Clear Breakpoint | |
2086 | +bd Disable Breakpoint | |
2087 | +be Enable Breakpoint | |
2088 | +bl Display breakpoints | |
2089 | +bp Set or Display breakpoint | |
2090 | +bph Set or Display hardware breakpoint | |
2091 | +bpa Set or Display breakpoint globally | |
2092 | +bpha Set or Display hardware breakpoint globally | |
2093 | +bt Stack backtrace for current process | |
2094 | +btp Stack backtrace for specific process | |
2095 | +bta Stack backtrace for all processes | |
2096 | +btc Cycle over all live cpus and backtrace each one | |
2097 | +cpu Display or switch cpus | |
2098 | +dmesg Display system messages | |
2099 | +defcmd Define a command as a set of other commands | |
2100 | +ef Print exception frame | |
2101 | +env Show environment | |
2102 | +go Restart execution | |
2103 | +handlers Control the display of IA64 MCA/INIT handlers | |
2104 | +help Display help message | |
2105 | +id Disassemble Instructions | |
2106 | +kill Send a signal to a process | |
2107 | +ll Follow Linked Lists | |
2108 | +lsmod List loaded modules | |
2109 | +md Display memory contents | |
2110 | +mdWcN Display memory contents with width W and count N. | |
2111 | +mdp Display memory based on a physical address | |
2112 | +mdr Display raw memory contents | |
2113 | +mds Display memory contents symbolically | |
2114 | +mm Modify memory contents, words | |
2115 | +mmW Modify memory contents, bytes | |
2116 | +per_cpu Display per_cpu variables | |
2117 | +pid Change the default process context | |
2118 | +ps Display process status | |
2119 | +reboot Reboot the machine | |
2120 | +rd Display register contents | |
2121 | +rm Modify register contents | |
2122 | +rq Display runqueue for one cpu | |
2123 | +rqa Display runqueue for all cpus | |
2124 | +set Add/change environment variable | |
2125 | +sr Invoke SysReq commands | |
2126 | +ss Single step a cpu | |
2127 | +ssb Single step a cpu until a branch instruction | |
2128 | +stackdepth Print the stack depth for selected processes | |
2129 | +summary Summarize the system | |
2130 | +.TE | |
2131 | +.DE | |
2132 | +.P | |
2133 | +Some commands can be abbreviated, such commands are indicated by a | |
2134 | +non-zero \fIminlen\fP parameter to \fBkdb_register\fP; the value of | |
2135 | +\fIminlen\fP being the minimum length to which the command can be | |
2136 | +abbreviated (for example, the \fBgo\fP command can be abbreviated | |
2137 | +legally to \fBg\fP). | |
2138 | +.P | |
2139 | +If an input string does not match a command in the command table, | |
2140 | +it is treated as an address expression and the corresponding address | |
2141 | +value and nearest symbol are shown. | |
2142 | +.P | |
2143 | +Some of the commands are described here. | |
2144 | +Information on the more complicated commands can be found in the | |
2145 | +appropriate manual pages. | |
2146 | +.TP 8 | |
2147 | +cpu | |
2148 | +With no parameters, it lists the available cpus. | |
2149 | +\&'*' after a cpu number indicates a cpu that did not respond to the kdb | |
2150 | +stop signal. | |
2151 | +\&'+' after a cpu number indicates a cpu for which kdb has some data, but | |
2152 | +that cpu is no longer responding to kdb, so you cannot switch to it. | |
2153 | +This could be a cpu that has failed after entering kdb, or the cpu may | |
2154 | +have saved its state for debugging then entered the prom, this is | |
2155 | +normal for an IA64 MCA event. | |
2156 | +\&'I' after a cpu number means that the cpu was idle before it entered | |
2157 | +kdb, it is unlikely to contain any useful data. | |
2158 | +\&'F' after a cpu number means that the cpu is offline. | |
2159 | +There is currenly no way to distinguish between cpus that used to be | |
2160 | +online but are now offline and cpus that were never online, the kernel | |
2161 | +does not maintain the information required to separate those two cases. | |
2162 | +.I cpu | |
2163 | +followed by a number will switch to that cpu, you cannot switch to | |
2164 | +a cpu marked '*', '+' or 'F'. | |
2165 | +This command is only available if the kernel was configured for SMP. | |
2166 | +.TP 8 | |
2167 | +dmesg [lines] [adjust] | |
2168 | +Displays the system messages from the kernel buffer. | |
2169 | +If kdb logging is on, it is disabled by dmesg and is left as disabled. | |
2170 | +With no parameters or a zero value for 'lines', dmesg dumps the entire | |
2171 | +kernel buffer. | |
2172 | +If lines is specified and is positive, dmesg dumps the last 'lines' | |
2173 | +from the buffer. | |
2174 | +If lines is specified and is negative, dmesg dumps the first 'lines' | |
2175 | +from the buffer. | |
2176 | +If adjust is specified, adjust the starting point for the lines that | |
2177 | +are printed. | |
2178 | +When 'lines' is positive, move the starting point back by 'adjust' | |
2179 | +lines, when 'lines' is negative, move the starting point forward by | |
2180 | +\&'adjust' lines. | |
2181 | +.I dmesg -100 | |
2182 | +will dump 100 lines, from the start of the buffer. | |
2183 | +.I dmesg 100 | |
2184 | +will dump 100 lines, starting 100 lines from the end of the buffer, | |
2185 | +.I dmesg 100 100 | |
2186 | +will dump 100 lines, starting 200 lines from the end of the buffer. | |
2187 | +.I dmesg -100 100 | |
2188 | +will dump 100 lines, starting 100 lines from the start of the buffer. | |
2189 | +.TP 8 | |
2190 | +defcmd | |
2191 | +Defines a new command as a set of other commands, all input until | |
2192 | +.I endefcmd | |
2193 | +is saved and executed as a package. | |
2194 | +.I defcmd | |
2195 | +takes three parameters, the command name to be defined and used to | |
2196 | +invoke the package, a quoted string containing the usage text and a | |
2197 | +quoted string containing the help text for the command. | |
2198 | +When using defcmd, it is a good idea to prefix commands that might fail | |
2199 | +with '-', this ignores errors so the following commands are still | |
2200 | +executed. | |
2201 | +For example, | |
2202 | +.P | |
2203 | +.nf | |
2204 | + defcmd diag "" "Standard diagnostics" | |
2205 | + set LINES 2000 | |
2206 | + set BTAPROMPT 0 | |
2207 | + -id %eip-0x40 | |
2208 | + -cpu | |
2209 | + -ps | |
2210 | + -dmesg 80 | |
2211 | + -bt | |
2212 | + -bta | |
2213 | + endefcmd | |
2214 | +.fi | |
2215 | +.P | |
2216 | +When used with no parameters, defcmd prints all the defined commands. | |
2217 | +.TP 8 | |
2218 | +go | |
2219 | +Continue normal execution. | |
2220 | +Active breakpoints are reestablished and the processor(s) allowed to | |
2221 | +run normally. | |
2222 | +To continue at a specific address, use | |
2223 | +.I rm | |
2224 | +to change the instruction pointer then go. | |
2225 | +.TP 8 | |
2226 | +handlers | |
2227 | +Control the display of IA64 MCA/INIT handlers. | |
2228 | +The IA64 MCA/INIT handlers run on separate tasks. | |
2229 | +During an MCA/INIT event, the active tasks are typically the handlers, | |
2230 | +rather than the original tasks, which is not very useful for debugging. | |
2231 | +By default, KDB hides the MCA/INIT handlers so commands such as ps and | |
2232 | +btc will display the original task. | |
2233 | +You can change this behaviour by using | |
2234 | +.I handlers show | |
2235 | +to display the MCA/INIT handlers instead of the original tasks or use | |
2236 | +.I handlers hide | |
2237 | +(the default) to hide the MCA/INIT handlers and display the original | |
2238 | +tasks. | |
2239 | +.I handlers status | |
2240 | +will list the address of the handler task and the original task for | |
2241 | +each cpu. | |
2242 | +\fBNote:\fR\ If the original task was running in user space or it | |
2243 | +failed any of the MCA/INIT verification tests then there is no original | |
2244 | +task to display. | |
2245 | +In this case, the handler will be displayed even if | |
2246 | +.I handlers hide | |
2247 | +is set and | |
2248 | +.I handlers status | |
2249 | +will not show an original task. | |
2250 | +.TP 8 | |
2251 | +id | |
2252 | +Disassemble instructions starting at an address. | |
2253 | +Environment variable IDCOUNT controls how many lines of disassembly | |
2254 | +output the command produces. | |
2255 | +.TP 8 | |
2256 | +kill | |
2257 | +Internal command to send a signal (like kill(1)) to a process. | |
2258 | +kill -signal pid. | |
2259 | +.TP 8 | |
2260 | +lsmod | |
2261 | +Internal command to list modules. | |
2262 | +This does not use any kernel nor user space services so can be used at any time. | |
2263 | +.TP 8 | |
2264 | +per_cpu <variable_name> [<length>] [<cpu>] | |
2265 | +Display the values of a per_cpu variable, the variable_name is | |
2266 | +specified without the \fIper_cpu__\fR prefix. | |
2267 | +Length is the length of the variable, 1-8, if omitted or 0 it defaults | |
2268 | +to the size of the machine's register. | |
2269 | +To display the variable on a specific cpu, the third parameter is the | |
2270 | +cpu number. | |
2271 | +When the third parameter is omitted, the variable's value is printed | |
2272 | +from all cpus, except that zero values are suppressed. | |
2273 | +For each cpu, per_cpu prints the cpu number, the address of the | |
2274 | +variable and its value. | |
2275 | +.TP 8 | |
2276 | +pid <number> | |
2277 | +Change the current process context, with no parameters it displays the | |
2278 | +current process. | |
2279 | +The current process is used to display registers, both kernel and user | |
2280 | +space. | |
2281 | +It is also used when dumping user pages. | |
2282 | +.I pid R | |
2283 | +resets to the original process that was running when kdb was entered. | |
2284 | +This command is useful if you have been looking at other processes and/or | |
2285 | +cpus and you want to get back to the original process. | |
2286 | +It does not switch cpus, it only resets the context to the original process. | |
2287 | +.TP 8 | |
2288 | +reboot | |
2289 | +Reboot the system, with no attempt to do a clean close down. | |
2290 | +.TP 8 | |
2291 | +rq <cpu> | |
2292 | +Display the runqueues for the specified cpu. | |
2293 | +.TP 8 | |
2294 | +rqa | |
2295 | +Display the runqueues for all cpus. | |
2296 | +.TP 8 | |
2297 | +stackdepth <percentage> | |
2298 | +Print the stack usage for processes using more than the specified | |
2299 | +percentage of their stack. | |
2300 | +If percentage is not supplied, it defaults to 60. | |
2301 | +This command is only implemented on i386 and ia64 architectures, | |
2302 | +patches for other architectures will be gratefully accepted. | |
2303 | +.TP 8 | |
2304 | +summary | |
2305 | +Print a summary of the system, including the time (no timezone is | |
2306 | +applied), uname information and various critical system counters. | |
2307 | +.SH INITIAL KDB COMMANDS | |
2308 | +kdb/kdb_cmds is a plain text file where you can define kdb commands | |
2309 | +which are to be issued during kdb_init(). One command per line, blank | |
2310 | +lines are ignored, lines starting with '#' are ignored. kdb_cmds is | |
2311 | +intended for per user customization of kdb, you can use it to set | |
2312 | +environment variables to suit your hardware or to set standard | |
2313 | +breakpoints for the problem you are debugging. This file is converted | |
2314 | +to a small C object, compiled and linked into the kernel. You must | |
2315 | +rebuild and reinstall the kernel after changing kdb_cmds. This file | |
2316 | +will never be shipped with any useful data so you can always override | |
2317 | +it with your local copy. Sample kdb_cmds: | |
2318 | +.P | |
2319 | +.nf | |
2320 | +# Initial commands for kdb, alter to suit your needs. | |
2321 | +# These commands are executed in kdb_init() context, no SMP, no | |
2322 | +# processes. Commands that require process data (including stack or | |
2323 | +# registers) are not reliable this early. set and bp commands should | |
2324 | +# be safe. Global breakpoint commands affect each cpu as it is booted. | |
2325 | + | |
2326 | +set LINES=50 | |
2327 | +set MDCOUNT=25 | |
2328 | +set RECURSE=1 | |
2329 | +bp sys_init_module | |
2330 | +.fi | |
2331 | +.SH INTERRUPTS AND KDB | |
2332 | +When a kdb event occurs, one cpu (the initial cpu) enters kdb state. | |
2333 | +It uses a cross system interrupt to interrupt the | |
2334 | +other cpus and bring them all into kdb state. All cpus run with | |
2335 | +interrupts disabled while they are inside kdb, this prevents most | |
2336 | +external events from disturbing the kernel while kdb is running. | |
2337 | +.B Note: | |
2338 | +Disabled interrupts means that any I/O that relies on interrupts cannot | |
2339 | +proceed while kdb is in control, devices can time out. The clock tick | |
2340 | +is also disabled, machines will lose track of time while they are | |
2341 | +inside kdb. | |
2342 | +.P | |
2343 | +Even with interrupts disabled, some non-maskable interrupt events will | |
2344 | +still occur, these can disturb the kernel while you are debugging it. | |
2345 | +The initial cpu will still accept NMI events, assuming that kdb was not | |
2346 | +entered for an NMI event. Any cpu where you use the SS or SSB commands | |
2347 | +will accept NMI events, even after the instruction has finished and the | |
2348 | +cpu is back in kdb. This is an unavoidable side effect of the fact that | |
2349 | +doing SS[B] requires the cpu to drop all the way out of kdb, including | |
2350 | +exiting from the event that brought the cpu into kdb. Under normal | |
2351 | +circumstances the only NMI event is for the NMI oopser and that is kdb | |
2352 | +aware so it does not disturb the kernel while kdb is running. | |
2353 | +.P | |
2354 | +Sometimes doing SS or SSB on ix86 will allow one interrupt to proceed, | |
2355 | +even though the cpu is disabled for interrupts. I have not been able | |
2356 | +to track this one down but I suspect that the interrupt was pending | |
2357 | +when kdb was entered and it runs when kdb exits through IRET even | |
2358 | +though the popped flags are marked as cli(). If any ix86 hardware | |
2359 | +expert can shed some light on this problem, please notify the kdb | |
2360 | +maintainer. | |
2361 | +.SH RECOVERING FROM KDB ERRORS | |
2362 | +If a kdb command breaks and kdb has enough of a recovery environment | |
2363 | +then kdb will abort the command and drop back into mainline kdb code. | |
2364 | +This means that user written kdb commands can follow bad pointers | |
2365 | +without killing kdb. Ideally all code should verify that data areas | |
2366 | +are valid (using kdb_getarea) before accessing it but lots of calls to | |
2367 | +kdb_getarea can be clumsy. | |
2368 | +.P | |
2369 | +The sparc64 port does not currently provide this error recovery. | |
2370 | +If someone would volunteer to write the necessary longjmp/setjmp | |
2371 | +code, their efforts would be greatly appreciated. In the | |
2372 | +meantime, it is possible for kdb to trigger a panic by accessing | |
2373 | +a bad address. | |
2374 | +.SH DEBUGGING THE DEBUGGER | |
2375 | +kdb has limited support for debugging problems within kdb. If you | |
2376 | +suspect that kdb is failing, you can set environment variable KDBDEBUG | |
2377 | +to a bit pattern which will activate kdb_printf statements within kdb. | |
2378 | +See include/linux/kdb.h, KDB_DEBUG_FLAG_xxx defines. For example | |
2379 | +.nf | |
2380 | + set KDBDEBUG=0x60 | |
2381 | +.fi | |
2382 | +activates the event callbacks into kdb plus state tracing in sections | |
2383 | +of kdb. | |
2384 | +.nf | |
2385 | + set KDBDEBUG=0x18 | |
2386 | +.fi | |
2387 | +gives lots of tracing as kdb tries to decode the process stack. | |
2388 | +.P | |
2389 | +You can also perform one level of recursion in kdb. If environment | |
2390 | +variable RECURSE is not set or is 0 then kdb will either recover from | |
2391 | +an error (if the recovery environment is satisfactory) or kdb will | |
2392 | +allow the error to percolate, usually resulting in a dead system. When | |
2393 | +RECURSE is 1 then kdb will recover from an error or, if there is no | |
2394 | +satisfactory recovery environment, it will drop into kdb state to let | |
2395 | +you diagnose the problem. When RECURSE is 2 then all errors drop into | |
2396 | +kdb state, kdb does not attempt recovery first. Errors while in | |
2397 | +recursive state all drop through, kdb does not even attempt to recover | |
2398 | +from recursive errors. | |
2399 | +.SH KEYBOARD EDITING | |
2400 | +kdb supports a command history, which can be accessed via keyboard | |
2401 | +sequences. | |
2402 | +It supports the special keys on PC keyboards, control characters and | |
2403 | +vt100 sequences on a serial console or a PC keyboard. | |
2404 | +.P | |
2405 | +.DS | |
2406 | +.TS | |
2407 | +box, center; | |
2408 | +l | l | l l | l | |
2409 | +l | l | l l | l. | |
2410 | +PC Special keys Control VT100 key Codes Action | |
2411 | +_ | |
2412 | +Backspace ctrl-H Backspace 0x7f Delete character to the left of the cursor | |
2413 | +Delete ctrl-D Delete \\e[3~ Delete character to the right of the cursor | |
2414 | +Home ctrl-A Home \\e[1~ Go to start of line | |
2415 | +End ctrl-E End \\e[4~ Go to end of line | |
2416 | +Up arrow ctrl-P Up arrow \\e[A Up one command in history | |
2417 | +Down arrow ctrl-N Down arrow \\e[B Down one command in history | |
2418 | +Left arrow ctrl-B Left arrow \\e[D Left one character in current command | |
2419 | +Right arrow ctrl-F Right arrow \\e[C Right one character in current command | |
2420 | +.TE | |
2421 | +.DE | |
2422 | +.P | |
2423 | +There is no toggle for insert/replace mode, kdb editing is always in | |
2424 | +insert mode. | |
2425 | +Use delete and backspace to delete characters. | |
2426 | +.P | |
2427 | +kdb also supports tab completion for kernel symbols | |
2428 | +Type the start of a kernel symbol and press tab (ctrl-I) to complete | |
2429 | +the name | |
2430 | +If there is more than one possible match, kdb will append any common | |
2431 | +characters and wait for more input, pressing tab a second time will | |
2432 | +display the possible matches | |
2433 | +The number of matches is limited by environment variable DTABCOUNT, | |
2434 | +with a default of 30 if that variable is not set. | |
2435 | +.SH AUTHORS | |
2436 | +Scott Lurndal, Richard Bass, Scott Foehner, Srinivasa Thirumalachar, | |
2437 | +Masahiro Adegawa, Marc Esipovich, Ted Kline, Steve Lord, Andi Kleen, | |
2438 | +Sonic Zhang. | |
2439 | +.br | |
2440 | +Keith Owens <kaos@sgi.com> - kdb maintainer. | |
2441 | +.SH SEE ALSO | |
2442 | +.P | |
2443 | +linux/Documentation/kdb/kdb_{bp,bt,env,ll,md,ps,rd,sr,ss}.man | |
2444 | --- /dev/null | |
2445 | +++ b/Documentation/kdb/kdb_bp.man | |
2446 | @@ -0,0 +1,197 @@ | |
2447 | +.TH BD 1 "July 12, 2004" | |
2448 | +.SH NAME | |
2449 | +bp, bpa, bph, bpha, bd, bc, be, bl \- breakpoint commands | |
2450 | +.SH SYNOPSIS | |
2451 | +bp \fIaddress-expression\fP | |
2452 | +.LP | |
2453 | +bpa \fIaddress-expression\fP | |
2454 | +.LP | |
2455 | +bph \fIaddress-expression\fP [\f(CWDATAR|DATAW|DATAA|IO\fP [\fIlength\fP]] | |
2456 | +.LP | |
2457 | +bpha \fIaddress-expression\fP [\f(CWDATAR|DATAW|DATAA|IO\fP [\fIlength\fP]] | |
2458 | +.LP | |
2459 | +bd \fIbreakpoint-number\fP | |
2460 | +.LP | |
2461 | +bc \fIbreakpoint-number\fP | |
2462 | +.LP | |
2463 | +be \fIbreakpoint-number\fP | |
2464 | +.LP | |
2465 | +bl | |
2466 | +.SH DESCRIPTION | |
2467 | +.hy 0 | |
2468 | +The | |
2469 | +.B bp | |
2470 | +family of commands are used to establish a breakpoint. | |
2471 | +The \fIaddress-expression\fP may be a numeric value (decimal or | |
2472 | +hexidecimal), a symbol name, a register name preceeded by a | |
2473 | +percent symbol '%', or a simple expression consisting of a | |
2474 | +symbol name, an addition or subtraction character and a numeric | |
2475 | +value (decimal or hexidecimal). | |
2476 | +.P | |
2477 | +\fBbph\fP and \fBbpha\fP will force the use of a hardware register, provided | |
2478 | +the processor architecture supports them. | |
2479 | +.P | |
2480 | +The \fIaddress-expression\fP may also consist of a single | |
2481 | +asterisk '*' symbol which indicates that the command should | |
2482 | +operate on all existing breakpoints (valid only for \fBbc\fP, | |
2483 | +\fBbd\fP and \fBbe\fP). | |
2484 | +.P | |
2485 | +Four different types of | |
2486 | +breakpoints may be set: | |
2487 | + | |
2488 | +.TP 8 | |
2489 | +Instruction | |
2490 | +Causes the kernel debugger to be invoked from the debug exception | |
2491 | +path when an instruction is fetched from the specified address. This | |
2492 | +is the default if no other type of breakpoint is requested or when | |
2493 | +the \fBbp\fP command is used. | |
2494 | + | |
2495 | +.TP 8 | |
2496 | +DATAR | |
2497 | +Causes the kernel debugger to be entered when data of length | |
2498 | +\fIlength\fP is read from or written to the specified address. | |
2499 | +This type of breakpoint must use a processor debug register which | |
2500 | +places an architecture dependent limit on the number of data and I/O | |
2501 | +breakpoints that may be established. On arm mode XScale platform | |
2502 | +(thumb mode is not supported yet), | |
2503 | +debugger is triggered by reading from the specified address. | |
2504 | +The \fBbph\fP or \fBbpha\fP commands must be used. | |
2505 | + | |
2506 | +.TP 8 | |
2507 | +DATAW | |
2508 | +Enters the kernel debugger when data of length \fIlength\fP | |
2509 | +is written to the specified address. \fIlength\fP defaults | |
2510 | +to four bytes if it is not explicitly specified. | |
2511 | +Note that the processor may have already overwritten the prior data at | |
2512 | +the breakpoint location before the kernel debugger is invoked. | |
2513 | +The prior data should be saved before establishing the breakpoint, if | |
2514 | +required. On arm mode XScale platform, the debugger is triggered | |
2515 | +after having overwritten the specified address. | |
2516 | +The \fBbph\fP or \fBbpha\fP commands must be used. | |
2517 | + | |
2518 | +.TP 8 | |
2519 | +IO | |
2520 | +Enters the kernel debugger when an \fBin\fP or \fBout\fP instruction | |
2521 | +targets the specified I/O address. The \fBbph\fP or \fBbpha\fP | |
2522 | +commands must be used. This type of breakpoint is not valid in | |
2523 | +arm mode XScale platform. This option is not valid in arm | |
2524 | +mode XScale platform. | |
2525 | + | |
2526 | +.TP 8 | |
2527 | +DATAA | |
2528 | +Enters the kernel debugger after the data in specified address has | |
2529 | +been accessed (read or write), this option is only used in arm | |
2530 | +mode XScale platform. | |
2531 | + | |
2532 | +.P | |
2533 | +The | |
2534 | +.B bpha | |
2535 | +command will establish a breakpoint on all processors in an | |
2536 | +SMP system. This command is not available in an uniprocessor | |
2537 | +kernel. | |
2538 | +.P | |
2539 | +The | |
2540 | +.B bd | |
2541 | +command will disable a breakpoint without removing it from the kernel | |
2542 | +debugger's breakpoint table. | |
2543 | +This can be used to keep breakpoints in the table without exceeding the | |
2544 | +architecture limit on breakpoint registers. | |
2545 | +A breakpoint-number of \fI*\fR will disable all break points. | |
2546 | +.P | |
2547 | +The | |
2548 | +.B be | |
2549 | +command will re-enable a disabled breakpoint. | |
2550 | +A breakpoint-number of \fI*\fR will enable all break points. | |
2551 | +.P | |
2552 | +The | |
2553 | +.B bc | |
2554 | +command will clear a breakpoint from the breakpoint table. | |
2555 | +A breakpoint-number of \fI*\fR will clear all break points. | |
2556 | +.P | |
2557 | +The | |
2558 | +.B bl | |
2559 | +command will list the existing set of breakpoints. | |
2560 | +.SH LIMITATIONS | |
2561 | +There is a compile time limit of sixteen entries in the | |
2562 | +breakpoint table at any one time. | |
2563 | +.P | |
2564 | +There are architecture dependent limits on the number of hardware | |
2565 | +breakpoints that can be set. | |
2566 | +.IP ix86 8 | |
2567 | +Four. | |
2568 | +.PD 0 | |
2569 | +.IP xscale 8 | |
2570 | +Two for insruction breakpoints and another two for data breakpoint. | |
2571 | +.PD 0 | |
2572 | +.IP ia64 8 | |
2573 | +? | |
2574 | +.PD 0 | |
2575 | +.IP sparc64 8 | |
2576 | +None. | |
2577 | +.PD 1 | |
2578 | +When issuing the "go" command after entering the debugger due to | |
2579 | +a breakpoint, kdb will silently perform a single step in order to | |
2580 | +reapply the breakpoint. The sparc64 port has some limitations on | |
2581 | +single stepping, which may limit where a breakpoint may be safely | |
2582 | +set. Please read the man page for \fBss\fP for more information. | |
2583 | +.SH ENVIRONMENT | |
2584 | +The breakpoint subsystem does not currently use any environment | |
2585 | +variables. | |
2586 | +.SH SMP CONSIDERATIONS | |
2587 | +Using | |
2588 | +.B bc | |
2589 | +is risky on SMP systems. | |
2590 | +If you clear a breakpoint when another cpu has hit that breakpoint but | |
2591 | +has not been processed then it may not be recognised as a kdb | |
2592 | +breakpoint, usually resulting in incorrect program counters and kernel | |
2593 | +panics. | |
2594 | +It is safer to disable the breakpoint with | |
2595 | +.BR bd , | |
2596 | +then | |
2597 | +.B go | |
2598 | +to let any other processors that are waiting on the breakpoint to | |
2599 | +clear. | |
2600 | +After all processors are clear of the disabled breakpoint then it is | |
2601 | +safe to clear it using | |
2602 | +.BR bc . | |
2603 | +.P | |
2604 | +Breakpoints which use the processor breakpoint registers | |
2605 | +are only established on the processor which is | |
2606 | +currently active. If you wish breakpoints to be universal | |
2607 | +use the | |
2608 | +.B bpa | |
2609 | +or | |
2610 | +.B bpha | |
2611 | +commands. | |
2612 | +.SH EXAMPLES | |
2613 | +.TP 8 | |
2614 | +bp schedule | |
2615 | +Sets an instruction breakpoint at the begining of the | |
2616 | +function \fBschedule\fP. | |
2617 | + | |
2618 | +.TP 8 | |
2619 | +bp schedule+0x12e | |
2620 | +Sets an instruction breakpoint at the instruction located | |
2621 | +at \fBschedule\fP+\fI0x12e\fP. | |
2622 | + | |
2623 | +.TP 8 | |
2624 | +bph ttybuffer+0x24 dataw | |
2625 | +Sets a data write breakpoint at the location referenced by | |
2626 | +\fBttybuffer\fP+\fI0x24\fP for a length of four bytes. | |
2627 | + | |
2628 | +.TP 8 | |
2629 | +bph 0xc0254010 datar 1 | |
2630 | +Establishes a data reference breakpoint at address \fB0xc0254010\fP | |
2631 | +for a length of one byte. | |
2632 | + | |
2633 | +.TP 8 | |
2634 | +bp | |
2635 | +List current breakpoint table. | |
2636 | + | |
2637 | +.TP 8 | |
2638 | +bd 0 | |
2639 | +Disable breakpoint #0. | |
2640 | + | |
2641 | +.TP 8 | |
2642 | +bc * | |
2643 | +Clear all breakpoints | |
2644 | --- /dev/null | |
2645 | +++ b/Documentation/kdb/kdb_bt.man | |
2646 | @@ -0,0 +1,315 @@ | |
2647 | +.TH BT 1 "July 20, 2007" | |
2648 | +.SH NAME | |
2649 | +bt \- Stack Traceback command | |
2650 | +.SH SYNOPSIS | |
2651 | +bt [ <stack-frame-address> ] | |
2652 | +.LP | |
2653 | +btp <pid> | |
2654 | +.LP | |
2655 | +btt <struct-task-address> | |
2656 | +.LP | |
2657 | +bta [ DRSTZUIMA ] | |
2658 | +.LP | |
2659 | +btc [<cpu>] | |
2660 | +.SH DESCRIPTION | |
2661 | +.hy 0 | |
2662 | +The | |
2663 | +.B bt | |
2664 | +command is used to print a stack traceback. It uses the | |
2665 | +current registers (see \fBrd\fP command) to determine | |
2666 | +the starting context and attempts to provide a complete | |
2667 | +stack traceback for the active thread. If \fIstack-frame-address\fP | |
2668 | +is supplied, it is assumed to point to the start of a valid | |
2669 | +stack frame and the stack will be traced back from that | |
2670 | +point. | |
2671 | +On x86 architecture, \fIstack-frame-address\fP must be the stack address of a | |
2672 | +saved \fB%eip\fP (\fB%rip\fP for x86_64) value from a \fBcall\fP instruction. | |
2673 | +.P | |
2674 | +The \fBbtp\fP command will analyze the stack for the given | |
2675 | +process identification (see the \fBps\fP command). | |
2676 | +\fBbtp\fP sets the current process for any following register display or update | |
2677 | +commands. | |
2678 | +.P | |
2679 | +The \fBbtt\fP command will analyze the stack for the given task | |
2680 | +structure. | |
2681 | +It is exactly equivalent to \fBbtp\fR on the pid extracted from the | |
2682 | +task structure. | |
2683 | +\fBbtt\fP sets the current process for any following register display or update | |
2684 | +commands. | |
2685 | +.P | |
2686 | +The \fBbta\fP command lists the stack for all processes in the desired | |
2687 | +state. | |
2688 | +Without any parameters, \fBbta\fP gives a backtrace for all useful processes. | |
2689 | +If a parameter is specified, it is a single string consisting of the | |
2690 | +letters D, R, S, T, Z, U, I, M and A in any order. | |
2691 | +See the kdb \fBps\fR man page for more details. | |
2692 | +\fBbta\fP does not change the current process. | |
2693 | +.P | |
2694 | +The \fBbtc\fP command will analyze the stack for the current process on | |
2695 | +a specified cpu or, if no cpu number is supplied, for the current | |
2696 | +process on all cpus. | |
2697 | +It does not switch to the other cpus, instead it uses the task | |
2698 | +structures to identify and issue \fBbtt\fR against the current task on | |
2699 | +the desired cpus. | |
2700 | +\fBbtc\fP with no arguments does not change the current process. | |
2701 | +\fBbtc\fP with a cpu number sets the current process for any following register | |
2702 | +display or update commands. | |
2703 | +.P | |
2704 | +For each function, the stack trace prints at least two lines. | |
2705 | +The first line contains four or five fields\ :- | |
2706 | +.IP * 3 | |
2707 | +The pointer to the stack frame. | |
2708 | +.PD 0 | |
2709 | +.IP * 3 | |
2710 | +The current address within this frame. | |
2711 | +.IP * 3 | |
2712 | +The address converted to a function name (actually the first non-local | |
2713 | +label which is <= the address). | |
2714 | +.IP * 3 | |
2715 | +The offset of the address within the function. | |
2716 | +.IP * 3 | |
2717 | +Any parameters to the function. | |
2718 | +.PD 1 | |
2719 | +.PP | |
2720 | +If environment variable NOSECT is set to 0 then the next line contains | |
2721 | +five fields which are designed to make it easier to match the trace | |
2722 | +against the kernel code\ :- | |
2723 | +.IP * 3 | |
2724 | +The module name that contains the address, "kernel" if it is in the | |
2725 | +base kernel. | |
2726 | +.PD 0 | |
2727 | +.IP * 3 | |
2728 | +The section name that contains the address (not available on 2.6 kernels). | |
2729 | +.IP * 3 | |
2730 | +The start address of the section (not available on 2.6 kernels). | |
2731 | +.IP * 3 | |
2732 | +The start address of the function. | |
2733 | +.IP * 3 | |
2734 | +The end address of the function (the first non-local label which is > | |
2735 | +the address). | |
2736 | +.PD 1 | |
2737 | +.PP | |
2738 | +If arguments are being converted to symbols, any argument which | |
2739 | +converts to a kernel or module address is printed as\ :- | |
2740 | +.IP * 3 | |
2741 | +Argument address. | |
2742 | +.PD 0 | |
2743 | +.IP * 3 | |
2744 | +The module name that contains the address, "kernel" if it is in the | |
2745 | +base kernel. | |
2746 | +.IP * 3 | |
2747 | +The symbol name the argument maps to. | |
2748 | +.IP * 3 | |
2749 | +The offset of the argument from the symbol, suppressed if 0. | |
2750 | +.PD 1 | |
2751 | +.P | |
2752 | +On architectures that use nested stacks, the backtrace will indicate a | |
2753 | +switch to a new stack by printing a line of equal signs and the type of | |
2754 | +stack. | |
2755 | +.SH MATCHING TRACE TO KERNEL CODE | |
2756 | +The command "objdump\ -S" will disassemble an object and, if the code | |
2757 | +was compiled with debugging (gcc flag -g), objdump will interleave the | |
2758 | +C source lines with the generated object. | |
2759 | +.PP | |
2760 | +A complete objdump of the kernel or a module is too big, normally you | |
2761 | +only want specific functions. | |
2762 | +By default objdump will only print the .text section but Linux uses | |
2763 | +other section names for executable code. | |
2764 | +When objdump prints relocatable objects (modules) it uses an offset of | |
2765 | +0 which is awkward to relate to the stack trace. | |
2766 | +The five fields which are printed for each function are designed to | |
2767 | +make it easier to match the stack trace against the kernel code using | |
2768 | +"objdump\ -S". | |
2769 | +.PP | |
2770 | +If the function is in the kernel then you need the section name, the | |
2771 | +start and end address of the function. The command is | |
2772 | +.PP | |
2773 | +.nf | |
2774 | + objdump -S -j <section_name> \\ | |
2775 | + --start-address=<start-address> \\ | |
2776 | + --stop-address=<end-address> \\ | |
2777 | + /usr/src/linux/vmlinux | |
2778 | +.fi | |
2779 | +.PP | |
2780 | +If the function is in a module then you need the section name, the | |
2781 | +start address of the section, the start and end address of the | |
2782 | +function, the module name. The command is | |
2783 | +.PP | |
2784 | +.nf | |
2785 | + objdump -S -j <section_name> \\ | |
2786 | + --adjust-vma=<section-start> \\ | |
2787 | + --start-address=<start-address> \\ | |
2788 | + --stop-address=<end-address> \\ | |
2789 | + /path/to/module/<module-name>.o | |
2790 | +.fi | |
2791 | +.PP | |
2792 | +Unfortunately the 2.6 kernel does not provide the information required | |
2793 | +to locate the start of the section, which makes it very difficult to | |
2794 | +perform a reliable objdump on a module. | |
2795 | +.PP | |
2796 | +All addresses to objdump must be preceded by '0x' if they are in hex, | |
2797 | +objdump does not assume hex. | |
2798 | +The stack trace values are printed with leading '0x' to make it easy to | |
2799 | +run objdump. | |
2800 | +.SH LIMITATIONS | |
2801 | +Some architectures pass parameters in registers; ia64, x86_64 and i386 (with | |
2802 | +gcc flag -mregparm) fall into this category. | |
2803 | +On these architectures, the compiler may reuse input parameter registers as | |
2804 | +scratch space. | |
2805 | +For example, if a function takes a pointer to a structure and only accesses one | |
2806 | +field in that structure, the compiler may calculate the address of the field by | |
2807 | +adding a value to the input register. | |
2808 | +Once the input register has been updated, it no longer points to the | |
2809 | +start of the structure, but to some field within it. | |
2810 | +This also occurs with array pointers, the compiler may update the input pointer | |
2811 | +directly, leaving it pointing to some element of the array instead of the start | |
2812 | +of the array. | |
2813 | +Always treat parameter values that have been passed in registers with extreme | |
2814 | +suspicion, the compiler may have changed the value. | |
2815 | +The x86 backtrace can generally identify register parameters that are no longer | |
2816 | +valid, it prints them as 'invalid' instead of as a misleading number. | |
2817 | +The ia64 backtrace cannot identify parameter registers that have been | |
2818 | +overwritten. | |
2819 | +.P | |
2820 | +x86 architectures do not have full unwind information in the kernel. | |
2821 | +The KDB backtrace on x86 performs code decomposition and analysis to track the | |
2822 | +frames on the call stack (including stack switches) and to locate parameters. | |
2823 | +if this code analysis does not yield a valid result, KDB falls back on the old | |
2824 | +method of scanning the process stack and printing anything that looks like a | |
2825 | +kernel address. | |
2826 | +This old method is unreliable (it produces lots of false positives in the | |
2827 | +trace) and cannot track parameters at all, so no parameters are printed. | |
2828 | +If you get an x86 backtrace that falls back to the old method, read | |
2829 | +Documentation/kdb/bt_x86 and follow the steps listed to get diagnostics and to | |
2830 | +submit a bug report. | |
2831 | +.P | |
2832 | +There are a lot of functions in the kernel which take some arguments then do | |
2833 | +nothing except call another function with the same initial arguments, sometimes | |
2834 | +adding parameters at the end. For example\ :- | |
2835 | +.nf | |
2836 | +.na | |
2837 | +.ft CW | |
2838 | + | |
2839 | +int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen, | |
2840 | + void __user *oldval, size_t __user *oldlenp, | |
2841 | + void __user *newval, size_t newlen) | |
2842 | +{ | |
2843 | + int ret = devinet_conf_sysctl(table, name, nlen, oldval, oldlenp, | |
2844 | + newval, newlen); | |
2845 | + | |
2846 | + if (ret == 1) | |
2847 | + rt_cache_flush(0); | |
2848 | + | |
2849 | + return ret; | |
2850 | +} | |
2851 | +.ad b | |
2852 | +.fi | |
2853 | +.P | |
2854 | +ipv4_doint_and_flush_strategy() passes all its parameters directly to | |
2855 | +devinet_conf_sysctl() and makes no other use of those parameters, | |
2856 | +so ipv4_doint_and_flush_strategy is a 'pass through' function. | |
2857 | +The x86_64 calling sequence mandates that the first 6 parameters are passed in | |
2858 | +registers, with other parameters being passed on stack. | |
2859 | +The i386 calling sequence with -mregparm=3 (which is the default since about | |
2860 | +2.6.18) passes the first 3 parameters in registers, with other parameters being | |
2861 | +passed on stack. | |
2862 | +The only exceptions to the above calling sequence are for functions declared as | |
2863 | +asmlinkage or functions with a variable number of parameters (e.g. printk). | |
2864 | +.P | |
2865 | +When a pass through function calls another function, the first 3 (i386) or 6 | |
2866 | +(x86) parameters are already in their correct registers so the pass through | |
2867 | +function does not need to access the registers, which means that there are no | |
2868 | +references to these registers in the assembler code for the function. | |
2869 | +Users still want to see those arguments so the x86 backtrace has to assume that | |
2870 | +if\ :- | |
2871 | +.IP * 2 | |
2872 | +There are parameters passed on the stack and | |
2873 | +.IP * | |
2874 | +There are no code references to parameters passed in registers and | |
2875 | +.IP * | |
2876 | +The function is not a known asmlinkage or variadic function, then | |
2877 | +there are pass through register arguments. | |
2878 | +.P | |
2879 | +The x86 backtrace will warn you when it makes this assumption, like this\ :- | |
2880 | +.nf | |
2881 | +.na | |
2882 | +.ft CW | |
2883 | + | |
2884 | + <function_name> has memory parameters but no register parameters. | |
2885 | + Assuming it is a 'pass through' function that does not refer to its register | |
2886 | + parameters and setting <n> register parameters | |
2887 | +.ad b | |
2888 | +.fi | |
2889 | +.P | |
2890 | +The above 3 line message is only printed once, any future assumptions will | |
2891 | +print a shorter message. | |
2892 | +.P | |
2893 | +The \fBbt\fP command may print more or less arguments for a function | |
2894 | +than that function accepts. | |
2895 | +For x86, trailing arguments that are passed in but not used by the function | |
2896 | +will not be printed, resulting in fewer arguments than expected. | |
2897 | +For ia64, the hardware does not distinguish between input and local registers, | |
2898 | +some local registers may be printed as function arguments, resulting in more | |
2899 | +arguments than expected. | |
2900 | +.P | |
2901 | +On i386, 64 bit arguments (long long) occupy two adjacent 32 bit fields. | |
2902 | +There is no way for KDB to tell that this has occurred, so 64 bit arguments | |
2903 | +will be printed as two separate 32 bit arguments. | |
2904 | +.SH ENVIRONMENT | |
2905 | +The \fBBTARGS\fP environment variable governs the maximum number | |
2906 | +of arguments that are printed for any single function. | |
2907 | +On IA64 hardware, there is no difference between input and local registers, the | |
2908 | +first \fBBTARGS\fP registers are printed, up to the total limit of input plus | |
2909 | +local registers. | |
2910 | +Use a large value for \fBBTARGS\fP if you want to see the local registers on | |
2911 | +IA64. | |
2912 | +.PP | |
2913 | +If the \fBBTSP\fP environment variable is non-zero then the entire backtrace is | |
2914 | +printed, otherwise only the backtrace to the point of the last interrupt is | |
2915 | +printed. | |
2916 | +Printing the entire backtrace with 'set\ BTSP\ 1' is useful for diagnosing | |
2917 | +problems with the backtrace algorithms. | |
2918 | +In addition, when BTSP is non-zero, each backtrace frame may print extra lines | |
2919 | +giving information about the stack pointers, this is architecture specific. | |
2920 | +.PP | |
2921 | +If the \fBBTSYMARG\fP environment variable is non-zero then any | |
2922 | +arguments that fall within the kernel or modules are converted to symbols. | |
2923 | +.PP | |
2924 | +If the \fBNOSECT\fP environment variable is non-zero then the | |
2925 | +section information is suppressed. | |
2926 | +The default is NOSECT=1 so section data is suppressed; use set\ NOSECT=0 | |
2927 | +to see section information. | |
2928 | +.PP | |
2929 | +The \fBBTAPROMPT\fP environment variable controls the prompt after each | |
2930 | +process is listed by the \fBbta\fP command. If \fBBTAPROMPT\fP is not | |
2931 | +set or is non-zero then \fBbta\fP issues a prompt after each process is | |
2932 | +listed. If \fBBTAPROMPT\fP is set to zero then no prompt is issued and | |
2933 | +all processes are listed without human intervention. | |
2934 | +.PP | |
2935 | +\fBbt\fR with no parameters uses the \fBPS\fR environment variable, see | |
2936 | +the kdb \fBps\fR man page. | |
2937 | +.SH SMP CONSIDERATIONS | |
2938 | +None. | |
2939 | +.SH EXAMPLES | |
2940 | +.nf | |
2941 | +.na | |
2942 | +.ft CW | |
2943 | +[0]kdb> bt | |
2944 | +Stack traceback for pid 2873 | |
2945 | +0xc2efc0f0 2873 2836 1 0 R 0xc2efc2a0 *mount | |
2946 | +esp eip Function (args) | |
2947 | +0xf65a3c88 0xc0201f9f xfs_mount_validate_sb (0xf68bcb08, 0xf68bcb48, 0x0) | |
2948 | +0xf65a3c94 0xc0202f17 xfs_readsb+0x9d (0xf68bcb08, 0x0) | |
2949 | +0xf65a3cc0 0xc020a72e xfs_mount+0x21d (invalid, 0xf68bc2f0, 0x0) | |
2950 | +0xf65a3cf4 0xc021a84a vfs_mount+0x1a (invalid) | |
2951 | +0xf65a3d04 0xc021a721 xfs_fs_fill_super+0x76 (0xf76b6200, invalid, invalid) | |
2952 | +0xf65a3d78 0xc015ad81 get_sb_bdev+0xd4 (invalid, invalid, invalid, 0xf7257000, 0xc021a6ab, 0xf7594b38) | |
2953 | + xfs_fs_get_sb has memory parameters but no register parameters. | |
2954 | + Assuming it is a 'pass through' function that does not refer to its register | |
2955 | + parameters and setting 3 register parameters | |
2956 | +0xf65a3db4 0xc0219a3a xfs_fs_get_sb+0x21 (invalid, invalid, invalid, 0xf7257000, 0xf7594b38) | |
2957 | +0xf65a3dcc 0xc015a992 vfs_kern_mount+0x41 (0xc04847e0, 0x0, 0xf68e9000, 0xf7257000) | |
2958 | +0xf65a3df0 0xc015aa11 do_kern_mount+0x38 (0xf6818000, 0x0, 0xf68e9000, 0xf7257000) | |
2959 | +0xf65a3e10 0xc016c8b0 do_mount+0x5df (0xf68e9000, 0xf65d6000, 0xf6818000, 0xc0ed0000, 0xf7257000) | |
2960 | +0xf65a3f90 0xc016c996 sys_mount+0x6f (0x8069b50, 0x8069b60, 0x8069b70, 0xc0ed0000, 0x8069ba0) | |
2961 | +0xf65a3fb4 0xc0102646 sysenter_past_esp+0x5f (invalid, invalid, invalid, 0x73, 0x246, 0xbfe52f50) | |
2962 | --- /dev/null | |
2963 | +++ b/Documentation/kdb/kdb_env.man | |
2964 | @@ -0,0 +1,46 @@ | |
2965 | +.TH ENV 1 "24 September 2000" | |
2966 | +.SH NAME | |
2967 | +env, set \- Environment manipulation commands | |
2968 | +.SH SYNOPSIS | |
2969 | +env | |
2970 | +.LP | |
2971 | +set \fIenvironment-variable\fP=\fIvalue\fP | |
2972 | +.SH DESCRIPTION | |
2973 | +The kernel debugger contains an environment which contains a series | |
2974 | +of name-value pairs. Some environment variables are known to the | |
2975 | +various kernel debugger commands and have specific meaning to the | |
2976 | +command; such are enumerated on the respective reference material. | |
2977 | +.P | |
2978 | +Arbitrary environment variables may be created and used with | |
2979 | +many commands (those which require an \fIaddress-expression\fP). | |
2980 | +.P | |
2981 | +The | |
2982 | +.B env | |
2983 | +command is used to display the current environment. | |
2984 | +.P | |
2985 | +The | |
2986 | +.B set | |
2987 | +command is used to alter an existing environment variable or | |
2988 | +establish a new environment variable. | |
2989 | +.SH LIMITATIONS | |
2990 | +There is a compile-time limit of 33 environment variables. | |
2991 | +.P | |
2992 | +There is a compile-time limit of 512 bytes (\fBKDB_ENVBUFSIZE\fP) | |
2993 | +of heap space available for new environment variables and for | |
2994 | +environment variables changed from their compile-time values. | |
2995 | +.SH ENVIRONMENT | |
2996 | +These commands explicitly manipulate the environment. | |
2997 | +.SH SMP CONSIDERATIONS | |
2998 | +None. | |
2999 | +.SH USER SETTINGS | |
3000 | +You can include "set" commands in kdb/kdb_cmds (see kdb.mm) to define | |
3001 | +your environment variables at kernel startup. | |
3002 | +.SH EXAMPLES | |
3003 | +.TP 8 | |
3004 | +env | |
3005 | +Display current environment settings. | |
3006 | + | |
3007 | +.TP 8 | |
3008 | +set IDCOUNT=100 | |
3009 | +Set the number of lines to display for the \fBid\fP command | |
3010 | +to the value \fI100\fP. | |
3011 | --- /dev/null | |
3012 | +++ b/Documentation/kdb/kdb_ll.man | |
3013 | @@ -0,0 +1,134 @@ | |
3014 | +.TH LL 1 "19 April 1999" | |
3015 | +.SH NAME | |
3016 | +ll \- Linked List examination | |
3017 | +.SH SYNOPSIS | |
3018 | +ll <addr> <link-offset> <cmd> | |
3019 | +.SH DESCRIPTION | |
3020 | +The | |
3021 | +.B ll | |
3022 | +command is used to execute a single command repetitively for | |
3023 | +each element of a linked list. | |
3024 | +.P | |
3025 | +The command specified by <cmd> will be executed with a single | |
3026 | +argument, the address of the current element. | |
3027 | +.SH LIMITATIONS | |
3028 | +Be careful if using this command recursively. | |
3029 | +.SH ENVIRONMENT | |
3030 | +None. | |
3031 | +.SH SMP CONSIDERATIONS | |
3032 | +None. | |
3033 | +.SH EXAMPLES | |
3034 | +.nf | |
3035 | +.na | |
3036 | +.ft CW | |
3037 | +# cd modules | |
3038 | +# insmod kdbm_vm.o | |
3039 | +# Entering kdb on processor 0 due to PAUSE | |
3040 | +kdb> ps | |
3041 | +Task Addr Pid Parent cpu lcpu Tss Command | |
3042 | +0xc03de000 0000000001 0000000000 0000 0000 0xc03de2d4 init | |
3043 | +0xc0090000 0000000002 0000000001 0000 0000 0xc00902d4 kflushd | |
3044 | +0xc000e000 0000000003 0000000001 0000 0000 0xc000e2d4 kpiod | |
3045 | +0xc000c000 0000000004 0000000001 0000 0000 0xc000c2d4 kswapd | |
3046 | +0xc7de2000 0000000056 0000000001 0000 0000 0xc7de22d4 kerneld | |
3047 | +0xc7d3a000 0000000179 0000000001 0000 0000 0xc7d3a2d4 syslogd | |
3048 | +0xc7a7e000 0000000188 0000000001 0000 0000 0xc7a7e2d4 klogd | |
3049 | +0xc7a04000 0000000199 0000000001 0000 0000 0xc7a042d4 atd | |
3050 | +0xc7b84000 0000000210 0000000001 0000 0000 0xc7b842d4 crond | |
3051 | +0xc79d6000 0000000221 0000000001 0000 0000 0xc79d62d4 portmap | |
3052 | +0xc798e000 0000000232 0000000001 0000 0000 0xc798e2d4 snmpd | |
3053 | +0xc7904000 0000000244 0000000001 0000 0000 0xc79042d4 inetd | |
3054 | +0xc78fc000 0000000255 0000000001 0000 0000 0xc78fc2d4 lpd | |
3055 | +0xc77ec000 0000000270 0000000001 0000 0000 0xc77ec2d4 sendmail | |
3056 | +0xc77b8000 0000000282 0000000001 0000 0000 0xc77b82d4 gpm | |
3057 | +0xc7716000 0000000300 0000000001 0000 0000 0xc77162d4 smbd | |
3058 | +0xc7ee2000 0000000322 0000000001 0000 0000 0xc7ee22d4 mingetty | |
3059 | +0xc7d6e000 0000000323 0000000001 0000 0000 0xc7d6e2d4 login | |
3060 | +0xc778c000 0000000324 0000000001 0000 0000 0xc778c2d4 mingetty | |
3061 | +0xc78b6000 0000000325 0000000001 0000 0000 0xc78b62d4 mingetty | |
3062 | +0xc77e8000 0000000326 0000000001 0000 0000 0xc77e82d4 mingetty | |
3063 | +0xc7708000 0000000327 0000000001 0000 0000 0xc77082d4 mingetty | |
3064 | +0xc770e000 0000000328 0000000001 0000 0000 0xc770e2d4 mingetty | |
3065 | +0xc76b0000 0000000330 0000000001 0000 0000 0xc76b02d4 update | |
3066 | +0xc7592000 0000000331 0000000323 0000 0000 0xc75922d4 ksh | |
3067 | +0xc7546000 0000000338 0000000331 0000 0000 0xc75462d4 su | |
3068 | +0xc74dc000 0000000339 0000000338 0000 0000 0xc74dc2d4 ksh | |
3069 | +kdb> md 0xc74dc2d4 | |
3070 | +c74dc2d4: 00000000 c74de000 00000018 00000000 .....`MG........ | |
3071 | +c74dc2e4: 00000000 00000000 00000000 074de000 .............`M. | |
3072 | +c74dc2f4: c01123ff 00000000 00000000 00000000 #.@............ | |
3073 | +c74dc304: 00000000 00000000 c74dded0 00000000 ........P^MG.... | |
3074 | +[omitted] | |
3075 | +c74dc474: 00000000 00000000 00000000 00000000 ................ | |
3076 | +c74dc484: 00000000 c7c15d00 c77b0900 c026fbe0 .....]AG..{G`{&@ | |
3077 | +c74dc494: 00000000 c76c2000 00000000 00000000 ..... lG........ | |
3078 | +c74dc4a4: 00000000 00000000 00000000 c74dc4ac ............,DMG | |
3079 | +kdb> md 0xc026fbe0 | |
3080 | +c026fbe0: c0262b60 00000000 c7594940 c74de000 @HYG....@IYG.`MG | |
3081 | +[omitted] | |
3082 | +kdb> md 0xc0262b60 | |
3083 | +c0262b60: c0266660 08048000 0804c000 c7bec360 `f&@.....@..`C>G | |
3084 | +kdb> ll c0262b60 12 md | |
3085 | +c0262b60: c0266660 08048000 0804c000 c7bec360 `f&@.....@..`C>G | |
3086 | +c7bec360: c0266660 0804c000 0804d000 c7becb20 `f&@.@...P.. K>G | |
3087 | +c7becb20: c0266660 0804d000 08050000 c7bec3a0 `f&@.P...... C>G | |
3088 | +c7bec3a0: c0266660 40000000 40009000 c7bec420 `f&@...@...@ D>G | |
3089 | +c7bec420: c0266660 40009000 4000b000 c7bec4a0 `f&@...@.0.@ D>G | |
3090 | +c7bec4a0: c0266660 4000b000 40010000 c7bec8e0 `f&@.0.@...@`H>G | |
3091 | +c7bec8e0: c0266660 40010000 400a1000 c7becbe0 `f&@...@...@`K>G | |
3092 | +c7becbe0: c0266660 400a1000 400a8000 c7becc60 `f&@...@...@`L>G | |
3093 | +c7becc60: c0266660 400a8000 400b4000 c7952300 `f&@...@.@.@.#.G | |
3094 | +c7952300: c0266660 400b5000 400bc000 c79521c0 `f&@.P.@.@.@@!.G | |
3095 | +c79521c0: c0266660 400bc000 400bd000 c7bec6e0 `f&@.@.@.P.@`F>G | |
3096 | +c7bec6e0: c0266660 bffff000 c0000000 00000000 `f&@.p?...@.... | |
3097 | +kdb> | |
3098 | +kdb> ll c0262b60 12 vm | |
3099 | +struct vm_area_struct at 0xc0262b60 for 56 bytes | |
3100 | +vm_start = 0x8048000 vm_end = 0x804c000 | |
3101 | +page_prot = 0x25 avl_height = 2244 vm_offset = 0x0 | |
3102 | +flags: READ EXEC MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE | |
3103 | +struct vm_area_struct at 0xc7bec360 for 56 bytes | |
3104 | +vm_start = 0x804c000 vm_end = 0x804d000 | |
3105 | +page_prot = 0x25 avl_height = -31808 vm_offset = 0x3000 | |
3106 | +flags: READ WRITE MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE | |
3107 | +struct vm_area_struct at 0xc7becb20 for 56 bytes | |
3108 | +vm_start = 0x804d000 vm_end = 0x8050000 | |
3109 | +page_prot = 0x25 avl_height = -28664 vm_offset = 0x0 | |
3110 | +flags: READ WRITE EXEC MAYREAD MAYWRITE MAYEXEC | |
3111 | +struct vm_area_struct at 0xc7bec3a0 for 56 bytes | |
3112 | +vm_start = 0x40000000 vm_end = 0x40009000 | |
3113 | +page_prot = 0x25 avl_height = 30126 vm_offset = 0x0 | |
3114 | +flags: READ EXEC MAYREAD MAYWRITE MAYEXEC DENYWRITE | |
3115 | +struct vm_area_struct at 0xc7bec420 for 56 bytes | |
3116 | +vm_start = 0x40009000 vm_end = 0x4000b000 | |
3117 | +page_prot = 0x25 avl_height = 30126 vm_offset = 0x8000 | |
3118 | +flags: READ WRITE MAYREAD MAYWRITE MAYEXEC DENYWRITE | |
3119 | +struct vm_area_struct at 0xc7bec4a0 for 56 bytes | |
3120 | +vm_start = 0x4000b000 vm_end = 0x40010000 | |
3121 | +page_prot = 0x25 avl_height = 26853 vm_offset = 0x0 | |
3122 | +flags: READ MAYREAD MAYWRITE MAYEXEC | |
3123 | +struct vm_area_struct at 0xc7bec8e0 for 56 bytes | |
3124 | +vm_start = 0x40010000 vm_end = 0x400a1000 | |
3125 | +page_prot = 0x25 avl_height = 2244 vm_offset = 0x0 | |
3126 | +flags: READ EXEC MAYREAD MAYWRITE MAYEXEC | |
3127 | +struct vm_area_struct at 0xc7becbe0 for 56 bytes | |
3128 | +vm_start = 0x400a1000 vm_end = 0x400a8000 | |
3129 | +page_prot = 0x25 avl_height = 30126 vm_offset = 0x90000 | |
3130 | +flags: READ WRITE MAYREAD MAYWRITE MAYEXEC | |
3131 | +struct vm_area_struct at 0xc7becc60 for 56 bytes | |
3132 | +vm_start = 0x400a8000 vm_end = 0x400b4000 | |
3133 | +page_prot = 0x25 avl_height = 2244 vm_offset = 0x0 | |
3134 | +flags: READ WRITE MAYREAD MAYWRITE MAYEXEC | |
3135 | +struct vm_area_struct at 0xc7952300 for 56 bytes | |
3136 | +vm_start = 0x400b5000 vm_end = 0x400bc000 | |
3137 | +page_prot = 0x25 avl_height = 30126 vm_offset = 0x0 | |
3138 | +flags: READ EXEC MAYREAD MAYWRITE MAYEXEC | |
3139 | +struct vm_area_struct at 0xc79521c0 for 56 bytes | |
3140 | +vm_start = 0x400bc000 vm_end = 0x400bd000 | |
3141 | +page_prot = 0x25 avl_height = -16344 vm_offset = 0x6000 | |
3142 | +flags: READ WRITE MAYREAD MAYWRITE MAYEXEC | |
3143 | +struct vm_area_struct at 0xc7bec6e0 for 56 bytes | |
3144 | +vm_start = 0xbffff000 vm_end = 0xc0000000 | |
3145 | +page_prot = 0x25 avl_height = 2244 vm_offset = 0x0 | |
3146 | +flags: READ WRITE EXEC MAYREAD MAYWRITE MAYEXEC GROWSDOWN | |
3147 | +kdb> | |
3148 | --- /dev/null | |
3149 | +++ b/Documentation/kdb/kdb_md.man | |
3150 | @@ -0,0 +1,136 @@ | |
3151 | +.TH MD 1 "August 4, 2004" | |
3152 | +.SH NAME | |
3153 | +md, mdWcN, mdr, mds, mm, mmW\- Memory manipulation commands | |
3154 | +.SH SYNOPSIS | |
3155 | +md [ \fIaddress-expression\fP [ \fIline-count\fP [\fIoutput-radix\fP ] ] ] | |
3156 | +.LP | |
3157 | +md\fIW\fRc\fIn\fR [ \fIaddress-expression\fP [ \fIline-count\fP [\fIoutput-radix\fP ] ] ] | |
3158 | +.LP | |
3159 | +mdp \fIphysical-address-expression\fP,\fIbytes\fP | |
3160 | +.LP | |
3161 | +mdr \fIaddress-expression\fP,\fIbytes\fP | |
3162 | +.LP | |
3163 | +mds [ \fIaddress-expression\fP [ \fIline-count\fP [\fIoutput-radix\fP ] ] ] | |
3164 | +.LP | |
3165 | +mm \fIaddress-expression\fP \fInew-contents\fP | |
3166 | +.LP | |
3167 | +mm\fIW\fR \fIaddress-expression\fP \fInew-contents\fP | |
3168 | +.SH DESCRIPTION | |
3169 | +The | |
3170 | +.B md | |
3171 | +command is used to display the contents of memory. | |
3172 | +The \fIaddress-expression\fP may be a numeric value (decimal or | |
3173 | +hexidecimal), a symbol name, a register name preceeded by one or more | |
3174 | +percent symbols '%', an environment variable name preceeded by | |
3175 | +a currency symbol '$', or a simple expression consisting of a | |
3176 | +symbol name, an addition or subtraction character and a numeric | |
3177 | +value (decimal or hexidecimal). | |
3178 | +.P | |
3179 | +If an address is specified and the \fIline-count\fP or \fIradix\fP arguments | |
3180 | +are omitted, they default to the values of the \fBMDCOUNT\fP and \fBRADIX\fP | |
3181 | +environment variables respectively. If the \fBMDCOUNT\fP or \fBRADIX\fP | |
3182 | +environment variables are unset, the appropriate defaults will be used [see | |
3183 | +\fBENVIRONMENT\fP below]. If no address is specified then md resumes | |
3184 | +after the last address printed, using the previous values of count and | |
3185 | +radix. The start address is rounded down to a multiple of the | |
3186 | +BYTESPERWORD (md) or width (md\fIW\fR). | |
3187 | +.P | |
3188 | +md uses the current value of environment variable \fBBYTESPERWORD\fP to | |
3189 | +read the data. When reading hardware registers that require special | |
3190 | +widths, it is more convenient to use md\fIW\fRc\fIn\fR where \fIW\fR is | |
3191 | +the width for this command and \fRc\fIn\fR is the number of entries to | |
3192 | +read. For example, md1c20 reads 20 bytes, 1 at a time. To continue | |
3193 | +printing just type md, the width and count apply to following md | |
3194 | +commands with no parameters. \fBNote:\fR The count is the number of | |
3195 | +repeats of the width, unlike MDCOUNT which gives the number of md lines | |
3196 | +to print. | |
3197 | +.P | |
3198 | +The | |
3199 | +.B mdp | |
3200 | +command displays the contents of physical memory, starting at the | |
3201 | +specified physical address for the specified number of bytes. | |
3202 | +The address is preceded by 'phys'. | |
3203 | +.P | |
3204 | +The | |
3205 | +.B mdr | |
3206 | +command displays the raw contents of memory, starting at the specified | |
3207 | +address for the specified number of bytes. | |
3208 | +The data is printed in one line without a leading address and no | |
3209 | +trailing character conversion. | |
3210 | +.B mdr | |
3211 | +is intended for interfacing with external debuggers, it is of little | |
3212 | +use to humans. | |
3213 | +.P | |
3214 | +The | |
3215 | +.B mds | |
3216 | +command displays the contents of memory one word per line and | |
3217 | +attempts to correlate the contents of each word with a symbol | |
3218 | +in the symbol table. If no symbol is found, the ascii representation | |
3219 | +of the word is printed, otherwise the symbol name and offset from | |
3220 | +symbol value are printed. | |
3221 | +By default the section data is printed for kernel symbols. | |
3222 | +.P | |
3223 | +The | |
3224 | +.B mm | |
3225 | +and | |
3226 | +\fBmm\fIW\fR | |
3227 | +commands allow modification of memory. The bytes at the address | |
3228 | +represented by \fIaddress-expression\fP are changed to | |
3229 | +\fInew-contents\fP. \fInew-contents\fP is allowed to be an | |
3230 | +\fIaddress-expression\fP. | |
3231 | +.B mm | |
3232 | +changes a machine word, \fBmm\fIW\fR changes \fIW\fR bytes at that | |
3233 | +address. | |
3234 | +.SH LIMITATIONS | |
3235 | +None. | |
3236 | +.SH ENVIRONMENT | |
3237 | +.TP 8 | |
3238 | +MDCOUNT | |
3239 | +This environment variable (default=8) defines the number of lines | |
3240 | +that will be displayed by each invocation of the \fBmd\fP command. | |
3241 | + | |
3242 | +.TP 8 | |
3243 | +RADIX | |
3244 | +This environment variable (default=16) defines the radix used to | |
3245 | +print the memory contents. | |
3246 | + | |
3247 | +.TP 8 | |
3248 | +BYTESPERWORD | |
3249 | +This environment variable (default=4) selects the width of output | |
3250 | +data when printing memory contents. Select the value two to get | |
3251 | +16-bit word output, select the value one to get byte output. | |
3252 | + | |
3253 | +.TP 8 | |
3254 | +LINES | |
3255 | +This environment variable governs the number of lines of output | |
3256 | +that will be presented before the kernel debugger built-in pager | |
3257 | +pauses the output. This variable only affects the functioning | |
3258 | +of the \fBmd\fP and \fBmds\fP if the \fBMDCOUNT\fP variable | |
3259 | +is set to a value greater than the \fBLINES\fP variable. | |
3260 | + | |
3261 | +.TP 8 | |
3262 | +NOSECT | |
3263 | +If the \fBNOSECT\fP environment variable is non-zero then the | |
3264 | +section information is suppressed. | |
3265 | +The default is NOSECT=1 so section data is suppressed; use set\ NOSECT=0 | |
3266 | +to see section information. | |
3267 | +.SH SMP CONSIDERATIONS | |
3268 | +None. | |
3269 | +.SH EXAMPLES | |
3270 | +.TP 8 | |
3271 | +md %edx | |
3272 | +Display memory starting at the address contained in register \fB%edx\fP. | |
3273 | + | |
3274 | +.TP 8 | |
3275 | +mds %esp | |
3276 | +Display stack contents symbolically. This command is quite useful | |
3277 | +in manual stack traceback. | |
3278 | + | |
3279 | +.TP 8 | |
3280 | +mm 0xc0252110 0x25 | |
3281 | +Change the memory location at 0xc0252110 to the value 0x25. | |
3282 | + | |
3283 | +.TP 8 | |
3284 | +md chrdev_table 15 | |
3285 | +Display 15 lines (at 16 bytes per line) starting at address | |
3286 | +represented by the symbol \fIchrdev_table\fP. | |
3287 | --- /dev/null | |
3288 | +++ b/Documentation/kdb/kdb_ps.man | |
3289 | @@ -0,0 +1,96 @@ | |
3290 | +.TH PS 1 "September 14, 2004" | |
3291 | +.SH NAME | |
3292 | +ps \- Display processes | |
3293 | +.SH SYNOPSIS | |
3294 | +ps [ DRSTCZEUIMA ] | |
3295 | +.SH DESCRIPTION | |
3296 | +The | |
3297 | +.B ps | |
3298 | +command displays the status of all processes in the desired state. | |
3299 | +This command does not take any locks (all cpus should be frozen while | |
3300 | +kdb is running) so it can safely be used to debug lock problems with | |
3301 | +the process table. | |
3302 | +.P | |
3303 | +Without any parameters, \fBps\fP displays all the interesting | |
3304 | +processes, excluding idle tasks and sleeping system daemons. | |
3305 | +If a parameter is specified, it is a single string consisting of the | |
3306 | +letters D, R, S, T, C, Z, E, U, I and M, in any order. | |
3307 | +Each letter selects processes in a specific state, when multiple | |
3308 | +letters are specified, a process will be displayed if it is in any of | |
3309 | +the specified states. | |
3310 | +The states are\ :- | |
3311 | +.P | |
3312 | +.DS | |
3313 | +.TS | |
3314 | +box, center; | |
3315 | +l | l | |
3316 | +l | l. | |
3317 | +D Uninterruptible sleep | |
3318 | +R Running | |
3319 | +S Interruptible sleep | |
3320 | +T Stopped | |
3321 | +C Traced | |
3322 | +Z Zombie | |
3323 | +E Dead | |
3324 | +U Unrunnable | |
3325 | +I Idle task | |
3326 | +M Sleeping system daemon | |
3327 | +A All | |
3328 | +.TE | |
3329 | +.DE | |
3330 | +.P | |
3331 | +For state R (running), the process may not be on a cpu at the moment, | |
3332 | +but it is ready to run. | |
3333 | +The header line above the backtrace contains '1' in the fourth field if | |
3334 | +the process is actually on a cpu. | |
3335 | +.P | |
3336 | +The idle task is run on each cpu when there is no work for that cpu to do. | |
3337 | +Unless the idle task is servicing an interrupt, there is no point in | |
3338 | +printing the idle task. | |
3339 | +An idle task that is not servicing a interrupt is marked as state I, | |
3340 | +while servicing an interrupt it is in state R. | |
3341 | +By default, idle tasks are not printed, use \fBps\ I\fR to print them. | |
3342 | +If the idle tasks are not being printed, the start of the \fBps\R | |
3343 | +output contains a list of which cpus are idle. | |
3344 | +.P | |
3345 | +Each cpu has one or more system daemons to handle per cpu work such as | |
3346 | +soft irqs. | |
3347 | +A system daemon (idenified by a NULL mm pointer) that is sleeping is | |
3348 | +marked as state M. | |
3349 | +These processes rarely have any useful data and generate a lot of | |
3350 | +output on large machines, so sleeping system daemons are not printed by | |
3351 | +default. | |
3352 | +Use \fBps\ M\fR to print them. | |
3353 | +.P | |
3354 | +At the start of the \fBps\fR output is a line giving the cpu status, | |
3355 | +see the kdb \fBcpu\fR command. | |
3356 | +.SH LIMITATIONS | |
3357 | +None. | |
3358 | +.SH ENVIRONMENT | |
3359 | +.TP 8 | |
3360 | +PS | |
3361 | +This environment variable (default=DRSTCZEU) is used when \fBps\fR | |
3362 | +is issued with no parameters. | |
3363 | + | |
3364 | +.SH SMP CONSIDERATIONS | |
3365 | +None. | |
3366 | +.SH EXAMPLES | |
3367 | +.TP 8 | |
3368 | +\fBps\fR | |
3369 | +displays the useful tasks, suppressing idle tasks and sleeping | |
3370 | +system daemons. | |
3371 | + | |
3372 | +.TP 8 | |
3373 | +\fBps\ RD\fR | |
3374 | +displays only tasks that are running or are in an uninterruptible | |
3375 | +sleep. | |
3376 | + | |
3377 | +.TP 8 | |
3378 | +\fBps\ DRSTCZEUIM\fR | |
3379 | +displays all tasks. | |
3380 | + | |
3381 | +.TP 8 | |
3382 | +\fBps\ A\fR | |
3383 | +displays all tasks. | |
3384 | +This is easier than remembering DRSTCZEUIM. | |
3385 | + | |
3386 | --- /dev/null | |
3387 | +++ b/Documentation/kdb/kdb_rd.man | |
3388 | @@ -0,0 +1,170 @@ | |
3389 | +.TH RD 1 "September 20, 2005" | |
3390 | +.SH NAME | |
3391 | +rd, rm\- Register manipulation commands | |
3392 | +.SH SYNOPSIS | |
3393 | +rd [[c [n]]|d|u] | |
3394 | +.LP | |
3395 | +rm \fIregister-name\fP \fInew-contents\fP | |
3396 | +.LP | |
3397 | +ef <address> | |
3398 | +.SH DESCRIPTION | |
3399 | +The | |
3400 | +.B rd | |
3401 | +command is used to display the contents of processor and coprocessor registers. | |
3402 | +Without any arguments, the rd command displays the contents of the general | |
3403 | +register set at the point at which the kernel debugger was entered. | |
3404 | +If the bt* or pid commands have been used to change the current process then | |
3405 | +.B rd | |
3406 | +and | |
3407 | +.B rm | |
3408 | +may not be able to display any registers. | |
3409 | +'n' argument is only used for XScale platform to identify the desired | |
3410 | +coprocessor number, while 'd' option is not valid for XScale platform. | |
3411 | +.P | |
3412 | +On IA32 and IA64, with the 'c' argument, the processor control registers | |
3413 | +%cr0, %cr1, %cr2 and %cr4 are displayed, while with the 'd' argument | |
3414 | +the processor debug registers are displayed. If the 'u' argument | |
3415 | +is supplied, the registers for the current task as of the last | |
3416 | +time the current task entered the kernel are displayed. | |
3417 | +.P | |
3418 | +On XScale, 'c' argument is used to display the | |
3419 | +all coprocessor control registers or specified coprocessor registers by | |
3420 | +argumnet 'n'. Argument 'u' is used to display the | |
3421 | +registers for the current task as of the last time the current task | |
3422 | +entered the kernel. Argument 'd' is not supported. | |
3423 | +.P | |
3424 | +On ix86, the | |
3425 | +.B rm | |
3426 | +command allows modification of a register. The following | |
3427 | +register names are valid: \fB%eax\fP, \fB%ebx\fP, \fB%ecx\fP, | |
3428 | +\fB%edx\fP, \fB%esi\fP, \fB%edi\fP, \fB%esp\fP, \fB%eip\fP, | |
3429 | +and \fB%ebp\fP. Note that if two '%' symbols are used | |
3430 | +consecutively, the register set displayed by the 'u' argument | |
3431 | +to the \fBrd\fP command is modified. | |
3432 | +.P | |
3433 | +The debug registers, \fBdr0\fP through \fBdr3\fP and both | |
3434 | +\fBdr6\fP and \fBdr7\fP can also be modified with the \fBrm\fP | |
3435 | +command. | |
3436 | +.P | |
3437 | +On sparc64, the valid registers are named \fB%g0\fP through | |
3438 | +\fB%g7\fP, \fB%l0\fP through \fB%l7\fP, \fB%o0\fP through | |
3439 | +\fB%o7\fP, and \fB%i0\fP through \fB%i7\fP, with the exceptions | |
3440 | +that \fB%o6\fP is called \fB%sp\fP and that \fB%i6\fP is called | |
3441 | +\fB%fp\fP. The registers \fB%tstate\fP, \fB%tpc\fP, \fB%tnpc\fP, | |
3442 | +\fB%y\fP, and \fB%fprs\fP provide state information at the time | |
3443 | +the system entered kdb. Additionally, when viewing registers, two | |
3444 | +convenience names are provided: \fB%®s\fP shows the | |
3445 | +address on the stack of the current registers, and \fB%csp\fP | |
3446 | +shows the current stack pointer within kdb itself. | |
3447 | +.P | |
3448 | +While on XScale, both the cpu registers and most coprocessor | |
3449 | +registers can be be modified. \fIregister-name\fP can be followings like | |
3450 | +r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, | |
3451 | +r15, cpsr to address cpu registers. For the coprocessor registers in XSacle, | |
3452 | +either alias name or \fICpcc[CRndd[CRmbb[Opaa]]]\fP can be used to address | |
3453 | +the register in coprocessor cc with CRn=dd, CRm=bb and opcode2=aa. All aa, bb, cc, dd can be | |
3454 | +1 or 2 decimal digitals, the default value is 0 when any of them is omitted. Name | |
3455 | +acc0_h and acc0_l are used to identify the high byte and | |
3456 | +low word of accumulator in coprocessor 0. | |
3457 | +.P | |
3458 | +On IA64, the parameter to | |
3459 | +.B rd | |
3460 | +can be d (debug registers), u (user registers at most recent entry to kernel), | |
3461 | +i (interrupt registers), %isr (current interrupt status), s (stacked | |
3462 | +registers), k (kernel registers). You can also specify these individual | |
3463 | +registers - | |
3464 | +psr, | |
3465 | +ifs, | |
3466 | +ip, | |
3467 | +unat, | |
3468 | +pfs, | |
3469 | +rsc, | |
3470 | +rnat, | |
3471 | +bsps, | |
3472 | +pr, | |
3473 | +ldrs, | |
3474 | +ccv, | |
3475 | +fpsr, | |
3476 | +b0, | |
3477 | +b6, | |
3478 | +b7, | |
3479 | +r1, | |
3480 | +r2, | |
3481 | +r3, | |
3482 | +r8, | |
3483 | +r9, | |
3484 | +r10, | |
3485 | +r11, | |
3486 | +r12, | |
3487 | +r13, | |
3488 | +r14, | |
3489 | +r15, | |
3490 | +r16, | |
3491 | +r17, | |
3492 | +r18, | |
3493 | +r19, | |
3494 | +r20, | |
3495 | +r21, | |
3496 | +r22, | |
3497 | +r23, | |
3498 | +r24, | |
3499 | +r25, | |
3500 | +r26, | |
3501 | +r27, | |
3502 | +r28, | |
3503 | +r29, | |
3504 | +r30, | |
3505 | +r31. | |
3506 | +.B rm | |
3507 | +can change any of the individual registers or the stacked registers. | |
3508 | +.P | |
3509 | +The | |
3510 | +.B ef | |
3511 | +command displays an exception frame at the specified address. | |
3512 | +.SH LIMITATIONS | |
3513 | +Currently the \fBrm\fP command will not allow modification of the | |
3514 | +control registers. | |
3515 | +.P | |
3516 | +Currently neither the \fBrd\fP command nor the \fBrm\fP command will | |
3517 | +display or modify the model specific registers on the Pentium | |
3518 | +and Pentium Pro families. | |
3519 | +.SH ENVIRONMENT | |
3520 | +None. | |
3521 | +.SH SMP CONSIDERATIONS | |
3522 | +None. | |
3523 | +.SH EXAMPLES | |
3524 | +.TP 8 | |
3525 | +rd | |
3526 | +Display general register set from kdb's current task. | |
3527 | + | |
3528 | +.TP 8 | |
3529 | +rd c 0 | |
3530 | +Display coprocessor 0 registers. | |
3531 | + | |
3532 | +.TP 8 | |
3533 | +rm %eax 0 | |
3534 | +Set the contents of \fB%eax\fP to zero. This will be the | |
3535 | +value of %eax when kdb returns from the condition which | |
3536 | +invoked it. | |
3537 | + | |
3538 | +.TP 8 | |
3539 | +rm %%eax 0 | |
3540 | +Set the value of the \fB%eax\fP register to zero. This will | |
3541 | +be the value the user-mode application will see upon returning | |
3542 | +from the kernel. | |
3543 | + | |
3544 | +.TP 8 | |
3545 | +rm %acc0_h 0 | |
3546 | +Set the contents of high byte of accumulator to zero. | |
3547 | + | |
3548 | +.TP 8 | |
3549 | +rm dr0 0xc1287220 | |
3550 | +Set the value of the \fBdr0\fB register to \f(CW0xc1287220\fP. | |
3551 | + | |
3552 | +.TP 8 | |
3553 | +rm %InVLD_BTB 0 | |
3554 | +Write 0 to coprocessor 15 register with CRn=7, CRm=5, opcode2=6. | |
3555 | + | |
3556 | +.TP 8 | |
3557 | +rm %CP15CRn7CRm5Op6 0 | |
3558 | +Same with above. | |
3559 | --- /dev/null | |
3560 | +++ b/Documentation/kdb/kdb_sr.man | |
3561 | @@ -0,0 +1,68 @@ | |
3562 | +.TH SR 1 "7 October 2002" | |
3563 | +.SH NAME | |
3564 | +sr \- invoke sysrq commands from kdb | |
3565 | +.SH SYNOPSIS | |
3566 | +sr \fIx\fP | |
3567 | +.SH DESCRIPTION | |
3568 | +.hy 0 | |
3569 | +The | |
3570 | +.B sr | |
3571 | +command invokes the existing sysrq handler code in the kernel. | |
3572 | +This command takes a single character which is passed to sysrq | |
3573 | +processing, as if you had entered the sysrq key sequence followed by | |
3574 | +that character. | |
3575 | +.P | |
3576 | +.B Caveats: | |
3577 | +.P | |
3578 | +kdb will always call the sysrq code but sysrq may be disabled. | |
3579 | +If you expect to use sysrq functions during debugging then | |
3580 | +.IP "" | |
3581 | +echo "1" > /proc/sys/kernel/sysrq | |
3582 | +.P | |
3583 | +before starting the debug session. | |
3584 | +Alternatively issue | |
3585 | +.IP "" | |
3586 | +mm4 sysrq_enabled 1 | |
3587 | +.P | |
3588 | +during debugging. | |
3589 | +.P | |
3590 | +The sysrq code prints a heading using console loglevel 7 then reverts | |
3591 | +to the original loglevel for the rest of the sysrq processing. | |
3592 | +If the rest of the sysrq output is printed at a level below your | |
3593 | +current loglevel then you will not see the output on the kdb console, | |
3594 | +the output will only appear in the printk buffer. | |
3595 | +It is the user's responsibility to set the loglevel correctly if they | |
3596 | +want to see the sysrq output on the console. | |
3597 | +Issue | |
3598 | +.IP "" | |
3599 | +sr 7 | |
3600 | +.P | |
3601 | +before any other | |
3602 | +.B sr | |
3603 | +commands if you want to see the output on the console. | |
3604 | +You may even have to adjust the default message loglevel in order to | |
3605 | +see any output from | |
3606 | +.BR sr . | |
3607 | +See Documentation/sysctl/kernel.txt for details on setting console | |
3608 | +loglevels via /proc. | |
3609 | +You can also adjust the loglevel variables via kdb | |
3610 | +.BR mm ; | |
3611 | +on older kernels there are variables such as default_message_level, on | |
3612 | +newer kernels all the loglevel variables are in array console_printk, | |
3613 | +see kernel/printk.c for your kernel. | |
3614 | +.P | |
3615 | +Operations that require interrupt driven I/O can be invoked from kdb | |
3616 | +.BR sr , | |
3617 | +but they will not do anything until you type 'go' to exit from kdb | |
3618 | +(interrupts are disabled while in kdb). | |
3619 | +There is no guarantee that these operations will work, if the machine | |
3620 | +entered kdb because of an error then interrupt driven I/O may already | |
3621 | +be dead. | |
3622 | +Do not assume that | |
3623 | +.B sr\ s | |
3624 | +does anything useful. | |
3625 | +.P | |
3626 | +The sysrq handler uses locks and calls printk which also uses locks. | |
3627 | +If the sysrq handler or any of the sysrq functions have to wait for a | |
3628 | +lock then they will never return and kdb will appear to hang. | |
3629 | +Invoking sysrq code from kdb is inherently unsafe. | |
3630 | --- /dev/null | |
3631 | +++ b/Documentation/kdb/kdb_ss.man | |
3632 | @@ -0,0 +1,109 @@ | |
3633 | +.TH SS 1 "17 January 2002" | |
3634 | +.SH NAME | |
3635 | +ss, ssb \- Single Step | |
3636 | +.SH SYNOPSIS | |
3637 | +ss | |
3638 | +.LP | |
3639 | +ssb | |
3640 | +.SH DESCRIPTION | |
3641 | +The | |
3642 | +.B ss | |
3643 | +command is used to execute a single instruction and return | |
3644 | +to the kernel debugger. | |
3645 | +.P | |
3646 | +Both the instruction that was single-stepped and the next | |
3647 | +instruction to execute are printed. | |
3648 | +.P | |
3649 | +The \fBssb\fP command will execute instructions from the | |
3650 | +current value of the instruction pointer. Each instruction | |
3651 | +may be printed as it is executed, depending upon architecture; | |
3652 | +execution will stop at any instruction which would cause the flow | |
3653 | +of control to change (e.g. branch, call, interrupt instruction, | |
3654 | +return, etc.) | |
3655 | +.SH LIMITATIONS | |
3656 | +On sparc64, there are some circumstances where single-stepping | |
3657 | +can be dangerous. Do not single-step across an instruction which | |
3658 | +changes the interrupt-enable bit in %tstate. Do not single step | |
3659 | +through code which is invoked when entering or leaving the | |
3660 | +kernel, particularly any kernel entry code before %tl is set to | |
3661 | +0, or any kernel exit code after %tl is set to 1. | |
3662 | +.SH ENVIRONMENT | |
3663 | +None. | |
3664 | +.SH SMP CONSIDERATIONS | |
3665 | +Other processors are held in the kernel debugger when the instruction | |
3666 | +is traced. Single stepping though code that requires a lock which is | |
3667 | +in use by another processor is an exercise in futility, it will never | |
3668 | +succeed. | |
3669 | +.SH INTERRUPT CONSIDERATIONS | |
3670 | +When a kdb event occurs, one cpu (the initial cpu) enters kdb state. | |
3671 | +It uses a cross system interrupt to interrupt the | |
3672 | +other cpus and bring them all into kdb state. All cpus run with | |
3673 | +interrupts disabled while they are inside kdb, this prevents most | |
3674 | +external events from disturbing the kernel while kdb is running. | |
3675 | +.B Note: | |
3676 | +Disabled interrupts means that any I/O that relies on interrupts cannot | |
3677 | +proceed while kdb is in control, devices can time out. The clock tick | |
3678 | +is also disabled, machines will lose track of time while they are | |
3679 | +inside kdb. | |
3680 | +.P | |
3681 | +Even with interrupts disabled, some non-maskable interrupt events | |
3682 | +will still occur, these can disturb the kernel while you are | |
3683 | +debugging it. The initial cpu will still accept NMI events, | |
3684 | +assuming that kdb was not entered for an NMI event. Any cpu | |
3685 | +where you use the SS or SSB commands will accept NMI events, even | |
3686 | +after the instruction has finished and the cpu is back in kdb. | |
3687 | +This is an unavoidable side effect of the fact that doing SS[B] | |
3688 | +requires the cpu to drop all the way out of kdb, including | |
3689 | +exiting from the NMI event that brought the cpu into kdb. Under | |
3690 | +normal circumstances the only NMI event is for the NMI oopser and | |
3691 | +that is kdb aware so it does not disturb the kernel while kdb is | |
3692 | +running. | |
3693 | +.P | |
3694 | +Sometimes doing SS or SSB on ix86 will allow one interrupt to proceed, | |
3695 | +even though the cpu is disabled for interrupts. I have not been able | |
3696 | +to track this one down but I suspect that the interrupt was pending | |
3697 | +when kdb was entered and it runs when kdb exits through IRET even | |
3698 | +though the popped flags are marked as cli(). If any ix86 hardware | |
3699 | +expert can shed some light on this problem, please notify the kdb | |
3700 | +maintainer. | |
3701 | +.SH EXAMPLES | |
3702 | +.nf | |
3703 | +.na | |
3704 | +.ft CW | |
3705 | +kdb> bp gendisk_head datar 4 | |
3706 | +Data Access Breakpoint #0 at 0xc024ddf4 (gendisk_head) in dr0 is enabled on cpu 0 | |
3707 | +for 4 bytes | |
3708 | +kdb> go | |
3709 | +... | |
3710 | +[root@host /root]# cat /proc/partitions | |
3711 | +Entering kdb on processor 0 due to Debug Exception @ 0xc01845e3 | |
3712 | +Read/Write breakpoint #0 at 0xc024ddf4 | |
3713 | +[0]kdb> ssb | |
3714 | +sd_finish+0x7b: movzbl 0xc02565d4,%edx | |
3715 | +sd_finish+0x82: leal 0xf(%edx),%eax | |
3716 | +sd_finish+0x85: sarl $0x4,%eax | |
3717 | +sd_finish+0x88: movl 0xc0256654,%ecx | |
3718 | +sd_finish+0x8e: leal (%eax,%eax,4),%edx | |
3719 | +sd_finish+0x91: leal (%eax,%edx,2),%edx | |
3720 | +sd_finish+0x94: movl 0xc0251108,%eax | |
3721 | +sd_finish+0x99: movl %eax,0xffffffc(%ecx,%edx,4) | |
3722 | +sd_finish+0x9d: movl %ecx,0xc0251108 | |
3723 | +sd_finish+0xa3: xorl %ebx,%ebx | |
3724 | +sd_finish+0xa5: cmpb $0x0,0xc02565d4 | |
3725 | +[0]kdb> go | |
3726 | +[root@host /root]# | |
3727 | + | |
3728 | +[0]kdb> ss | |
3729 | +sys_read: pushl %ebp | |
3730 | +SS trap at 0xc01274c1 | |
3731 | +sys_read+0x1: movl %esp,%ebp | |
3732 | +[0]kdb> ss | |
3733 | +sys_read+0x1: movl %esp,%ebp | |
3734 | +SS trap at 0xc01274c3 | |
3735 | +sys_read+0x3: subl $0xc,%esp | |
3736 | +[0]kdb> ss | |
3737 | +sys_read+0x3: subl $0xc,%esp | |
3738 | +SS trap at 0xc01274c6 | |
3739 | +sys_read+0x6: pushl %edi | |
3740 | +[0]kdb> | |
3741 | + | |
3742 | --- /dev/null | |
3743 | +++ b/Documentation/kdb/slides | |
3744 | @@ -0,0 +1,1382 @@ | |
3745 | +#! /opt/cpg/bin/do-mgp | |
3746 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3747 | +%% | |
3748 | +%deffont "standard" tfont "comic.ttf" | |
3749 | +%deffont "thick" tfont "arialb.ttf" | |
3750 | +%deffont "typewriter" xfont "courier new-bold-r" | |
3751 | +%deffont "type2writer" xfont "arial narrow-bold-r" | |
3752 | +%% | |
3753 | +%% Default settings per each line numbers. | |
3754 | +%% | |
3755 | +#%default 1 leftfill, size 2, fore "black", back "LemonChiffon2", font "thick" | |
3756 | +%default 1 leftfill, size 2, fore "black", back "white", font "thick" | |
3757 | +%default 2 size 10, vgap 10, prefix " ", center | |
3758 | +%default 3 size 2, bar "gray70", vgap 10 | |
3759 | +%default 4 size 6, fore "black", vgap 30, prefix " ", font "standard", left | |
3760 | +%% | |
3761 | +%% Default settings that are applied to TAB-indented lines. | |
3762 | +%% | |
3763 | +%tab 1 size 4, vgap 35, prefix " ", icon arc "red" 40 | |
3764 | +%tab 2 size 4, vgap 20, prefix " ", icon delta3 "blue" 40 | |
3765 | +%tab 3 size 4, vgap 20, prefix " ", icon delta3 "green" 40 | |
3766 | +%% | |
3767 | +%% | |
3768 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3769 | +%page | |
3770 | + | |
3771 | +KDB - Kernel Debugger | |
3772 | + | |
3773 | + | |
3774 | + | |
3775 | +%size 7,center, font "thick" | |
3776 | +Introduction | |
3777 | + | |
3778 | +And | |
3779 | + | |
3780 | +Demonstration | |
3781 | + | |
3782 | + | |
3783 | +%size 3 | |
3784 | + | |
3785 | +February 5, 2002 IBM Linux Technology Center Paul Dorwin | |
3786 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3787 | +%page | |
3788 | + | |
3789 | +IBM Legal | |
3790 | + | |
3791 | + | |
3792 | + IBM Legal requires this information: | |
3793 | + | |
3794 | +%size 3 | |
3795 | + | |
3796 | + THE INFORMATION IN THE FOLLOWING PRESENTATION IS PREPARED | |
3797 | + SOLELY FOR THE INFORMATION OF THE READER, AND COMES "AS IS" | |
3798 | + AND WITHOUT WARRANTY OR REPRESENATION OF ANY KIND. | |
3799 | + | |
3800 | + ANY PARTY USING THE MATERIALS IN THIS PRESENTATION DOES SO | |
3801 | + AT ITS OWN RISK LIABILITY AND THE PROVIDER OF THE MATERIALS | |
3802 | + ACCEPTS NO RISK OR LIABILITY FOR SUCH USE OR RESULTING FROM | |
3803 | + DISSEMINATION TO OR USE BY ANY OTHER PARTY | |
3804 | + | |
3805 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3806 | +%page | |
3807 | + | |
3808 | +Agenda | |
3809 | + | |
3810 | +%size 5 | |
3811 | + | |
3812 | + Installing and Configuring KDB | |
3813 | + | |
3814 | + KDB Commands | |
3815 | + | |
3816 | + Scull Demo | |
3817 | + | |
3818 | + Setting Breakpoints | |
3819 | + | |
3820 | + Displaying Data Structures | |
3821 | + | |
3822 | + Kernel Data structures | |
3823 | + | |
3824 | + Take a walk through an IO operation | |
3825 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3826 | +%page | |
3827 | + | |
3828 | +Installing Configuring KDB | |
3829 | + | |
3830 | + | |
3831 | + Install KDB patch. | |
3832 | + Start with a clean source tree | |
3833 | + Apply architecture specific patches | |
3834 | + Obtain patch for your kernel version | |
3835 | + see http://oss.sgi.com/projects/kdb/ | |
3836 | + Apply the kdb patch | |
3837 | + patch -p 1 -N -u -i /path/to/patch | |
3838 | + Apply any other patches | |
3839 | + Build and reboot on your kdb enabled kernel | |
3840 | + Man pages can be found at Documentation/kdb | |
3841 | + | |
3842 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3843 | +%page | |
3844 | + | |
3845 | +Configuring KDB | |
3846 | + | |
3847 | + | |
3848 | + Config kernel with the following options: | |
3849 | + These are documented in Documentation/Configure.help | |
3850 | + | |
3851 | + CONFIG_KDB=y | |
3852 | + Enable compilation of KDB in the kernel.. | |
3853 | + Setting this also sets CONFIG_KALLSYMS=y. | |
3854 | + CONFIG_KDB_MODULES=n | |
3855 | + KDB may be extended, compiling kdb/modules. | |
3856 | + CONFIG_KDB_OFF=n | |
3857 | + y = KDB is disabled by default. | |
3858 | + boot with kdb=on to enable at boot. | |
3859 | + /proc/sys/kernel/kdb to enable/disable when system is up. | |
3860 | + CONFIG_KALLSYMS=y | |
3861 | + This causes all symbols to be exported. | |
3862 | + CONFIG_FRAME_POINTER=y | |
3863 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3864 | +%page | |
3865 | + | |
3866 | +Invoking KDB | |
3867 | + | |
3868 | + | |
3869 | + KDB can be invoked in the following ways: | |
3870 | + | |
3871 | + Early init with "kdb=early" lilo flag | |
3872 | + Hits breakpoint prior to fork_init() (init/main.c) | |
3873 | + | |
3874 | + Serial console with CNTRL-A | |
3875 | + | |
3876 | + Console with PAUSE key | |
3877 | + | |
3878 | + When a pre-set breakpoint is hit | |
3879 | + | |
3880 | + On panic | |
3881 | + | |
3882 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3883 | +%page | |
3884 | + | |
3885 | +KDB Commands | |
3886 | + | |
3887 | + | |
3888 | + KDB environment | |
3889 | + env Show environment variables | |
3890 | + set Set environment variables | |
3891 | + help Display Help Message | |
3892 | + ? Display Help Message | |
3893 | + | |
3894 | + System related | |
3895 | + sections List kernel and module sections | |
3896 | + lsmod List loaded kernel modules | |
3897 | + reboot Reboot the machine immediately | |
3898 | + cpu <cpunum> Switch to new cpu | |
3899 | + | |
3900 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3901 | +%page | |
3902 | + | |
3903 | +KDB Commands | |
3904 | + | |
3905 | + | |
3906 | + Memory Manipulation | |
3907 | + md <vaddr> Display Memory Contents | |
3908 | + mdr <vaddr> <bytes> Display Raw Memory | |
3909 | + mds <vaddr> Display Symbolically | |
3910 | + mm <vaddr> <value> Modify Memory Contents | |
3911 | + id <vaddr> Display Instructions | |
3912 | + | |
3913 | + Register Manipulation | |
3914 | + rd Display Registers | |
3915 | + rm <reg> <value> Modify Registers | |
3916 | + ef <vaddr> Display exception frame | |
3917 | + | |
3918 | + Stack | |
3919 | + bt [<vaddr>] Stack traceback | |
3920 | + btp <pid> Display stack for <pid> | |
3921 | + bta Display all stacks | |
3922 | + | |
3923 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3924 | +%page | |
3925 | + | |
3926 | +KDB Commands | |
3927 | + | |
3928 | + | |
3929 | + Breakpoint | |
3930 | + bc <bpnum> Clear Breakpoint | |
3931 | + bd <bpnum> Disable Breakpoint | |
3932 | + be <bpnum> Enable Breakpoint | |
3933 | + bl [<vaddr>] Display breakpoints | |
3934 | + bp [<vaddr>] Set/Display breakpoints | |
3935 | + bpa [<vaddr>] Set/Display global breakpoints | |
3936 | + bph [<vaddr>] Set hardware breakpoint | |
3937 | + bpha [<vaddr>] Set global hardware breakpoint | |
3938 | + bp* modifiers: | |
3939 | + instruction - break on instruction fetch (default) | |
3940 | + datar - break on read at vaddr | |
3941 | + dataw - break on write at vaddr | |
3942 | + IO - break on in or out op at vaddress | |
3943 | + | |
3944 | + Execution control | |
3945 | + go [<vaddr>] Continue Execution | |
3946 | + ss [<#steps>] Single Step | |
3947 | + ssb Single step to branch/call | |
3948 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3949 | +%page | |
3950 | + | |
3951 | +KDB Commands | |
3952 | + | |
3953 | + | |
3954 | + Kernel structures | |
3955 | + ll <vaddr> <offset> <command> Traverse list and execute command | |
3956 | + ps Display active task list | |
3957 | + vm <vaddr> Display vm_area_struct | |
3958 | + dentry <dentry> Display interesting dentry stuff | |
3959 | + filp <filp> Display interesting filp stuff | |
3960 | + sh <vaddr> Show scsi_host | |
3961 | + sd <vaddr> Show scsi_device | |
3962 | + sc <vaddr> Show scsi_cmnd | |
3963 | + kiobuf <vaddr> Display kiobuf | |
3964 | + page <vaddr> Display page | |
3965 | + inode <vaddr> Display inode | |
3966 | + bh <vaddr> Display buffer head | |
3967 | + inode_pages <inode *> Display pages in an inode | |
3968 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3969 | +%page | |
3970 | + | |
3971 | +Scull Demo | |
3972 | + | |
3973 | + | |
3974 | + Objective | |
3975 | + Find and display the data associated with a scull device | |
3976 | + | |
3977 | + The sequence of events | |
3978 | + Populate the scull device with data | |
3979 | + Identify the breakpoints | |
3980 | + Set breakpoint in the device read function | |
3981 | + Identify the data structure elements | |
3982 | + Identify device structures used to track data | |
3983 | + Display data structures containing the data | |
3984 | + Show the usage of the filp command | |
3985 | + | |
3986 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3987 | +%page | |
3988 | + | |
3989 | +Scull Demo: Populate Device | |
3990 | + | |
3991 | + | |
3992 | + Obtain the code | |
3993 | + Surf to http://examples.oreilly.com/linuxdrive2/ | |
3994 | + Download the tarball | |
3995 | + Untar it to /usr/src | |
3996 | + | |
3997 | + Build and install the module | |
3998 | + cd /usr/src/ldd2-samples-1.0.1/scull | |
3999 | + make | |
4000 | + ./scull.init start | |
4001 | + | |
4002 | + Populate the scull device | |
4003 | + cat main.c > /dev/scull0 | |
4004 | + cat /dev/scull0 | |
4005 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4006 | +%page | |
4007 | + | |
4008 | +Scull Demo: Driver Details | |
4009 | + | |
4010 | + | |
4011 | + cat /dev/scull0 | |
4012 | + fd = | |
4013 | +%fore "blue", cont | |
4014 | +open | |
4015 | +%fore "black", cont | |
4016 | +("/dev/scull0", O_RDONLY); | |
4017 | + Kernel finds the file_operations structure | |
4018 | + Kernel then invokes the open function | |
4019 | +%fore "blue" | |
4020 | + read | |
4021 | +%fore "black", cont | |
4022 | +(fd, buf, size); | |
4023 | + Kernel finds the file_operations structure | |
4024 | + Kernel then invokes the read function | |
4025 | + | |
4026 | + Scull device file operations structure | |
4027 | + | |
4028 | +%font "typewriter", size 3 | |
4029 | + struct file_operations scull_fops = { | |
4030 | + llseek: scull_llseek, | |
4031 | +%fore "blue" | |
4032 | + read: scull_read, | |
4033 | +%fore "black" | |
4034 | + write: scull_write, | |
4035 | + ioctl: scull_ioctl, | |
4036 | +%fore "blue" | |
4037 | + open: scull_open, | |
4038 | +%fore "black" | |
4039 | + release: scull_release, | |
4040 | + }; | |
4041 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4042 | +%page | |
4043 | + | |
4044 | +Scull Demo: Driver Details | |
4045 | + | |
4046 | +%font "typewriter", size 3 | |
4047 | + scull_open code | |
4048 | +%font "typewriter", size 3 | |
4049 | + int | |
4050 | +%fore "blue", cont | |
4051 | +scull_open | |
4052 | +%fore "black", cont | |
4053 | +(struct inode *inode, struct file *filp) | |
4054 | + { | |
4055 | + Scull_Dev *dev; /* device information */ | |
4056 | + int num = NUM(inode->i_rdev); | |
4057 | + | |
4058 | + <snip> | |
4059 | + | |
4060 | + dev = (Scull_Dev *)filp->private_data; | |
4061 | + if (!dev) { | |
4062 | + if (num >= scull_nr_devs) return -ENODEV; | |
4063 | +%fore "blue" | |
4064 | + dev = &scull_devices[num]; | |
4065 | + filp->private_data = dev; | |
4066 | +%fore "black" | |
4067 | + } | |
4068 | + | |
4069 | + <snip> | |
4070 | + | |
4071 | + } | |
4072 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4073 | +%page | |
4074 | + | |
4075 | +Scull Demo: Driver Details | |
4076 | + | |
4077 | +%font "typewriter", size 3 | |
4078 | + scull_read code | |
4079 | +%font "typewriter", size 3 | |
4080 | + ssize_t | |
4081 | +%fore "blue", cont | |
4082 | +scull_read | |
4083 | +%fore "black", cont | |
4084 | +(struct file *filp, char *buf, size_t count, | |
4085 | + loff_t *f_pos) | |
4086 | + { | |
4087 | + | |
4088 | +%fore "blue", cont | |
4089 | + Scull_Dev *dev = filp->private_data; | |
4090 | +%fore "black", cont | |
4091 | + /* the first listitem */ | |
4092 | +%fore "blue" | |
4093 | + Scull_Dev *dptr; | |
4094 | +%fore "black" | |
4095 | + int quantum = dev->quantum; | |
4096 | + int qset = dev->qset; | |
4097 | + int itemsize = quantum * qset; | |
4098 | + if (down_interruptible(&dev->sem)) | |
4099 | + return -ERESTARTSYS; | |
4100 | + if (*f_pos + count > dev->size) | |
4101 | + count = dev->size - *f_pos; | |
4102 | + | |
4103 | + /* find listitem, qset index, and offset in the quantum */ | |
4104 | + item = (long)*f_pos / itemsize; | |
4105 | + rest = (long)*f_pos % itemsize; | |
4106 | + s_pos = rest / quantum; q_pos = rest % quantum; | |
4107 | + | |
4108 | + /* follow the list up to the right position */ | |
4109 | +%fore "blue" | |
4110 | + dptr = scull_follow(dev, item); | |
4111 | +%fore "black" | |
4112 | + | |
4113 | + <snip> | |
4114 | + | |
4115 | + } | |
4116 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4117 | +%page | |
4118 | + | |
4119 | +Scull Demo: Breakpoints | |
4120 | + | |
4121 | + | |
4122 | +%font "typewriter", size 3 | |
4123 | + Determine where to set breakpoint | |
4124 | +%font "typewriter", size 3 | |
4125 | +%fore "blue" | |
4126 | + dptr = scull_follow(dev, item); | |
4127 | +%fore "black" | |
4128 | + | |
4129 | +%font "typewriter", size 3 | |
4130 | + Disassemble scull_read | |
4131 | +%font "typewriter", size 3 | |
4132 | + [0]kdb> | |
4133 | +%fore "blue", cont | |
4134 | +id scull_read | |
4135 | +%fore "black" | |
4136 | + 0xf8c083b4 scull_read: push %ebp | |
4137 | + 0xf8c083b5 scull_read+0x1:mov %esp,%ebp | |
4138 | + 0xf8c083b7 scull_read+0x3:push %edi | |
4139 | + <snip> | |
4140 | + 0xf8c08465 scull_read+0xb1:sub $0x8,%esp | |
4141 | +%fore "blue" | |
4142 | + 0xf8c08468 scull_read+0xb4:push %ecx | |
4143 | + 0xf8c08469 scull_read+0xb5:push %esi | |
4144 | + 0xf8c0846a scull_read+0xb6:call 0xf8c08364 scull_follow: | |
4145 | +%fore "black" | |
4146 | + 0xf8c0846f scull_read+0xbb:mov %eax, | |
4147 | +%fore "blue", cont | |
4148 | + %edx | |
4149 | +%fore "black" | |
4150 | + 0xf8c08471 | |
4151 | +%fore "blue", cont | |
4152 | +scull_read+0xbd | |
4153 | +%fore "black", cont | |
4154 | +:add $0x10,%esp | |
4155 | + <snip> | |
4156 | + | |
4157 | + Set breakpoint in driver read | |
4158 | +%font "typewriter", size 3 | |
4159 | + [0]kdb> | |
4160 | +%fore "blue",cont | |
4161 | +bp scull_read+0xbd | |
4162 | +%fore "black" | |
4163 | + Instruction(i) BP #0 at 0xf8c08471 ([scull]scull_read+0xbd) | |
4164 | + is enabled globally adjust 1 | |
4165 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4166 | +%page | |
4167 | + | |
4168 | +Scull Demo: Breakpoints | |
4169 | + | |
4170 | + | |
4171 | +%font "typewriter", size 3 | |
4172 | + Restart the system | |
4173 | +%font "typewriter", size 3 | |
4174 | + [0]kdb> | |
4175 | +%fore "blue", cont | |
4176 | +go | |
4177 | +%fore "black" | |
4178 | + | |
4179 | + Hit the Breakpoint | |
4180 | +%font "typewriter", size 3 | |
4181 | + [root@elm3b77 root]# | |
4182 | +%fore "blue", cont | |
4183 | +cat /dev/scull0 | |
4184 | +%fore "black" | |
4185 | + Instruction(i) breakpoint #0 at 0xf8c08471 (adjusted) | |
4186 | + 0xf8c08471 scull_read+0xbd:int3 | |
4187 | + Entering kdb (current=0xf73ec000, pid 1249) on processor 2 | |
4188 | + due to Breakpoint @ 0xf8c08471 | |
4189 | + | |
4190 | + Display the registers | |
4191 | +%font "typewriter", size 3 | |
4192 | + [2]kdb> | |
4193 | +%fore "blue", cont | |
4194 | +rd | |
4195 | +%fore "black" | |
4196 | + eax = 0xf77d7b60 ebx = 0x00000000 ecx = 0x00000000 edx = | |
4197 | +%fore "blue", cont | |
4198 | +0xf77d7b60 | |
4199 | +%fore "black" | |
4200 | + esi = | |
4201 | +%fore "blue", cont | |
4202 | +0xf77d7b60 | |
4203 | +%fore "black", cont | |
4204 | + edi = 0x00001000 esp = 0xf7415f40 eip = 0xf8c08471 | |
4205 | + ebp = 0xf7415f78 xss = 0x00000018 xcs = 0x00000010 eflags = 0x00000246 | |
4206 | + xds = 0xf7590018 xes = 0x00000018 origeax = 0xffffffff ®s = 0xf7415f0c | |
4207 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4208 | +%page | |
4209 | + | |
4210 | +Scull Demo: Data Structures | |
4211 | + | |
4212 | +%font "typewriter", size 3 | |
4213 | + Display the Scull_Dev structure | |
4214 | +%font "typewriter", size 3 | |
4215 | + [2]kdb> | |
4216 | +%fore "blue", cont | |
4217 | +md 0xf77d7b60 2 | |
4218 | +%fore "black" | |
4219 | + 0xf77d7b60 | |
4220 | +%fore "blue", cont | |
4221 | +f7400000 | |
4222 | +%fore "black", cont | |
4223 | + 00000000 00000fa0 000003e8 ..@w.... ...h... | |
4224 | + 0xf77d7b70 0000534e 00000000 00000000 00000000 NS.............. | |
4225 | + | |
4226 | + Scull Device Structure | |
4227 | +%font "typewriter", size 3 | |
4228 | + typedef struct Scull_Dev { | |
4229 | +%fore "blue" | |
4230 | + void **data; | |
4231 | +%fore "black" | |
4232 | + struct Scull_Dev *next; /* next listitem */ | |
4233 | + int quantum; /* the current quantum size */ | |
4234 | + int qset; /* the current array size */ | |
4235 | + unsigned long size; | |
4236 | + devfs_handle_t handle; /* only used if devfs is there */ | |
4237 | + unsigned int access_key; /* used by sculluid and scullpriv */ | |
4238 | + struct semaphore sem; /* mutual exclusion semaphore */ | |
4239 | + } Scull_Dev; | |
4240 | +%size 6 | |
4241 | + | |
4242 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4243 | +%page | |
4244 | + | |
4245 | +Scull Demo: Data Structures | |
4246 | + | |
4247 | + | |
4248 | +%font "typewriter", size 3 | |
4249 | + Display the quantum set (dev->data) | |
4250 | +%font "typewriter", size 3 | |
4251 | + [2]kdb> | |
4252 | +%fore "blue", cont | |
4253 | +md f7400000 2 | |
4254 | +%fore "black" | |
4255 | + 0xf7400000 | |
4256 | +%fore "blue", cont | |
4257 | +f73ea000 | |
4258 | +%fore "black", cont | |
4259 | + f73f1000 f740c000 f7ab4000 . >w..?w.@@w.@+w | |
4260 | + 0xf7400010 f73ef000 f755b000 00000000 00000000 .p>w.0Uw........ | |
4261 | + | |
4262 | + Display the first quantum (dev->data[0]) | |
4263 | +%font "typewriter", size 3 | |
4264 | + [2]kdb> | |
4265 | +%fore "blue", cont | |
4266 | +md f73ea000 | |
4267 | +%fore "black" | |
4268 | + 0xf73ea000 200a2a2f 616d202a 632e6e69 202d2d20 /*. * main.c -- | |
4269 | + 0xf73ea010 20656874 65726162 75637320 63206c6c the bare scull c | |
4270 | + 0xf73ea020 20726168 75646f6d 200a656c 2a200a2a har module. *. * | |
4271 | + 0xf73ea030 706f4320 67697279 28207468 32202943 Copyright (C) 2 | |
4272 | + 0xf73ea040 20313030 73656c41 646e6173 52206f72 001 Alessandro R | |
4273 | + 0xf73ea050 6e696275 6e612069 6f4a2064 6874616e ubini and Jonath | |
4274 | + 0xf73ea060 43206e61 6562726f 2a200a74 706f4320 an Corbet. * Cop | |
4275 | + 0xf73ea070 67697279 28207468 32202943 20313030 yright (C) 2001 | |
4276 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4277 | +%page | |
4278 | + | |
4279 | +Scull Demo: filp command | |
4280 | + | |
4281 | + | |
4282 | +%font "typewriter", size 3 | |
4283 | + Show filp usage - here is the scull_read prototype | |
4284 | +%font "typewriter", size 3 | |
4285 | + ssize_t scull_read( | |
4286 | +%fore "blue", cont | |
4287 | +struct file *filp | |
4288 | +%fore "black", cont | |
4289 | +, char *buf, | |
4290 | + size_t count, loff_t *f_pos); | |
4291 | + Show the stack trace: | |
4292 | +%font "typewriter", size 3 | |
4293 | +[2]kdb> | |
4294 | +%fore "blue", cont | |
4295 | +bt | |
4296 | +%fore "black" | |
4297 | + EBP EIP Function(args) | |
4298 | + 0xee9dbf78 0xf8c08471 [scull]scull_read+0xbd ( | |
4299 | +%fore "blue", cont | |
4300 | +0xeaf6c0c0 | |
4301 | +%fore "black", cont | |
4302 | +, 0x804e128, | |
4303 | + 0x1000, 0xeaf6c0e0, 0x804f000) | |
4304 | + scull .text 0xf8c08060 0xf8c083b4 0xf8c084dc | |
4305 | + 0xee9dbfbc 0xc0136278 sys_read+0x98 (0x3, 0x804e128, 0x1000, ... | |
4306 | + kernel .text 0xc0100000 0xc01361e0 0xc01362b0 | |
4307 | + 0xc010702b system_call+0x33 | |
4308 | + kernel .text 0xc0100000 0xc0106ff8 0xc0107030 | |
4309 | + And show the filp output | |
4310 | +%font "typewriter", size 3 | |
4311 | + [2]kdb> | |
4312 | +%fore "blue", cont | |
4313 | +filp 0xeaf6c0c0 | |
4314 | +%fore "black" | |
4315 | + name.name 0xe93889fc name.len 6 | |
4316 | + File Pointer at 0xeaf6c0c0 | |
4317 | + f_list.nxt = 0xe42deca0 f_list.prv = 0xf7e69070 | |
4318 | +%fore "blue" | |
4319 | + f_dentry = 0xe93889a0 | |
4320 | +%fore "black", cont | |
4321 | + f_op = 0xf8c0a200 | |
4322 | + f_count = 2 f_flags = 0x8000 f_mode = 0x1 | |
4323 | + f_pos = 0 f_reada = 0 f_ramax = 0 | |
4324 | + f_raend = 0 f_ralen = 0 f_rawin = 0 | |
4325 | + | |
4326 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4327 | +%page | |
4328 | + | |
4329 | +Scull Demo: filp command | |
4330 | + | |
4331 | + | |
4332 | +%font "typewriter", size 3 | |
4333 | + filp output - continued | |
4334 | +%font "typewriter", size 3 | |
4335 | +%fore "blue" | |
4336 | + Directory Entry at 0xe93889a0 | |
4337 | +%fore "black" | |
4338 | + d_name.len = 6 | |
4339 | +%fore "orange", cont | |
4340 | +d_name.name = 0xe93889fc | |
4341 | +%fore "black", cont | |
4342 | +> | |
4343 | + d_count = 1 d_flags = 0x0 | |
4344 | +%fore "blue", cont | |
4345 | +d_inode = 0xe827b680 | |
4346 | +%fore "black" | |
4347 | + d_hash.nxt = 0xc215aec8 d_hash.prv = 0xc215aec8 | |
4348 | + d_lru.nxt = 0xe93889b8 d_lru.prv = 0xe93889b8 | |
4349 | + d_child.nxt = 0xe89e1e80 d_child.prv = 0xe9388940 | |
4350 | + d_subdirs.nxt = 0xe93889c8 d_subdirs.prv = 0xe93889c8 | |
4351 | + d_alias.nxt = 0xe827b690 d_alias.prv = 0xe827b690 | |
4352 | + d_op = 0x00000000 d_sb = 0xf7e69000 | |
4353 | + | |
4354 | +%fore "blue" | |
4355 | + Inode Entry at 0xe827b680 | |
4356 | +%fore "black" | |
4357 | + i_mode = 0x21a4 i_nlink = 1 i_rdev = 0xfe00 | |
4358 | + i_ino = 37182 i_count = 1 i_dev = 0x821 | |
4359 | + i_hash.nxt = 0xc20e6be8 i_hash.prv = 0xc20e6be8 | |
4360 | + i_list.nxt = 0xe827b2c8 i_list.prv = 0xe827b868 | |
4361 | + i_dentry.nxt = 0xe93889d0 i_dentry.prv = 0xe93889d0 | |
4362 | + | |
4363 | + Check the filename (display d_name.name) | |
4364 | +%font "typewriter", size 3 | |
4365 | + [2]kdb> | |
4366 | +%fore "orange", cont | |
4367 | +md 0xe93889fc 1 | |
4368 | +%fore "black" | |
4369 | + 0xe93889fc 6c756373 0000306c 00000000 00000000 scull0.......... | |
4370 | + | |
4371 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4372 | +%page | |
4373 | + | |
4374 | +Kernel Structures | |
4375 | + | |
4376 | + | |
4377 | + Objective | |
4378 | + Show output from various kernel related kdb commands | |
4379 | + | |
4380 | + Sequence of events | |
4381 | + Simple Program | |
4382 | + Write a simple program which allocates memory and hangs | |
4383 | + Show usage of the ps, vm, and ll commands | |
4384 | + Walk an IO operation | |
4385 | + Hit a breakpoint in qlogic driver (isp1020_queuecommand) | |
4386 | + Show usage of scsi related commands (sc, sh, and sd) | |
4387 | + Show usage of vm related commands (bh, page, inode, inode_pages) | |
4388 | + | |
4389 | + | |
4390 | + | |
4391 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4392 | +%page | |
4393 | + | |
4394 | +Simple program | |
4395 | + | |
4396 | +%font "typewriter", size 3 | |
4397 | + simple.c - simple program which allocates memory | |
4398 | +%font "typewriter", size 3 | |
4399 | +%fore "blue" | |
4400 | + int foo_global[8192]; | |
4401 | +%fore "black" | |
4402 | + main() | |
4403 | + { | |
4404 | + int * | |
4405 | +%fore "blue", cont | |
4406 | +foo_malloc; | |
4407 | +%fore "black" | |
4408 | + int i; | |
4409 | + foo_malloc = (int *)malloc(0x8192); | |
4410 | + for(i = 0; i < 0x100; i++) { | |
4411 | + foo_global[i] = 0xdead0000 | i; | |
4412 | + foo_malloc[i] = 0xbeef0000 | i; | |
4413 | + } | |
4414 | + printf("foo_global at %x\n", (int)foo_global); | |
4415 | + printf("foo_malloc at %x\n", (int)foo_malloc); | |
4416 | + printf("sleep forever\n"); | |
4417 | + sleep(2000000); | |
4418 | + } | |
4419 | + | |
4420 | + simple output | |
4421 | +%font "typewriter", size 3 | |
4422 | + [root@elm3b77 scull]# cc -o simple simple.c | |
4423 | + [root@elm3b77 scull]# ./simple | |
4424 | + foo_global at | |
4425 | +%fore "blue", cont | |
4426 | +8049780 | |
4427 | +%fore "black" | |
4428 | + foo_malloc at | |
4429 | +%fore "blue", cont | |
4430 | +8051788 | |
4431 | +%fore "black" | |
4432 | + sleep forever | |
4433 | + | |
4434 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4435 | +%page | |
4436 | + | |
4437 | +Simple Program | |
4438 | + | |
4439 | +%font "typewriter", size 3 | |
4440 | + Show the output of the ps command | |
4441 | +%font "typewriter", size 3 | |
4442 | + Entering kdb (current=0xc2010000, pid 0) on processor 3 due to | |
4443 | + Keyboard Entry | |
4444 | + [3]kdb> | |
4445 | +%fore "blue", cont | |
4446 | +ps | |
4447 | +%fore "black" | |
4448 | + Task Addr Pid Parent [*] cpu State Thread Command | |
4449 | + 0xf7efe000 00000001 00000000 0 003 stop 0xf7efe370 init | |
4450 | + 0xf7ef0000 00000002 00000001 0 001 stop 0xf7ef0370 keventd | |
4451 | + 0xf7eec000 00000003 00000000 0 000 stop 0xf7eec370 ksoftirqd_CPU0 | |
4452 | + 0xf7eea000 00000004 00000000 0 001 stop 0xf7eea370 ksoftirqd_CPU1 | |
4453 | + 0xf7ee8000 00000005 00000000 0 002 stop 0xf7ee8370 ksoftirqd_CPU2 | |
4454 | + 0xf7ee6000 00000006 00000000 0 003 stop 0xf7ee6370 ksoftirqd_CPU3 | |
4455 | + | |
4456 | + <snip> | |
4457 | + | |
4458 | + 0xf7b46000 00001006 00000737 0 003 stop 0xf7b46370 sshd | |
4459 | + 0xf7ace000 00001007 00001006 0 000 stop 0xf7ace370 bash | |
4460 | + 0xef06a000 00001066 00001007 0 003 stop 0xef06a370 su | |
4461 | + 0xeef88000 00001067 00001066 0 000 stop 0xeef88370 bash | |
4462 | + 0xeef64000 00001119 00000770 0 001 stop 0xeef64370 in.ftpd | |
4463 | +%fore "blue" | |
4464 | + 0xeeeac000 | |
4465 | +%fore "black", cont | |
4466 | + 00001138 00001067 0 001 stop 0xeeeac370 | |
4467 | +%fore "blue", cont | |
4468 | +simple | |
4469 | +%fore "black" | |
4470 | + [3]kdb> | |
4471 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4472 | +%page | |
4473 | + | |
4474 | +Simple Program | |
4475 | + | |
4476 | +%font "typewriter", size 3 | |
4477 | + Display the task struct | |
4478 | +%font "typewriter", size 3 | |
4479 | + [3]kdb> | |
4480 | +%fore "blue", cont | |
4481 | +md 0xeeeac000 | |
4482 | +%fore "black" | |
4483 | + 0xeeeac000 00000001 00000000 00000000 c0000000 ................ | |
4484 | + 0xeeeac010 c0339880 00000000 00000000 ffffffff ................ | |
4485 | + 0xeeeac020 0000000a 00000000 00000000 | |
4486 | +%fore "blue", cont | |
4487 | +f7e10f00 | |
4488 | +%fore "black", cont | |
4489 | + ..............aw | |
4490 | + 0xeeeac030 00000001 ffffffff ffffffff 00000000 ................ | |
4491 | + | |
4492 | +%font "typewriter", size 3 | |
4493 | + Determine offset of mm_struct ptr in task_struct | |
4494 | +%font "typewriter", size 3 | |
4495 | + struct task_struct { | |
4496 | + [0] volatile long state; | |
4497 | + [4] unsigned long flags; | |
4498 | + [8] int sigpending; | |
4499 | + [c] mm_segment_t addr_limit; | |
4500 | + [10] struct exec_domain *exec_domain; | |
4501 | + [14] volatile long need_resched; | |
4502 | + [18] unsigned long ptrace; | |
4503 | + [1c] int lock_depth; | |
4504 | + [20] long counter; | |
4505 | + [24] long nice; | |
4506 | + [28] unsigned long policy; | |
4507 | +%fore "blue" | |
4508 | + [2c] struct mm_struct *mm; | |
4509 | +%fore "black" | |
4510 | + [30] int processor; | |
4511 | + [34] unsigned long cpus_runnable, cpus_allowed; | |
4512 | + <snip> | |
4513 | + }; | |
4514 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4515 | +%page | |
4516 | + | |
4517 | +Simple Program | |
4518 | + | |
4519 | + | |
4520 | +%font "typewriter", size 3 | |
4521 | + Display the mm_struct associated with simple process | |
4522 | +%font "typewriter", size 3 | |
4523 | + [3]kdb> | |
4524 | +%fore "blue", cont | |
4525 | +md f7e10f00 | |
4526 | +%fore "black" | |
4527 | + 0xf7e10f00 | |
4528 | +%fore "blue", cont | |
4529 | +e8357a80 | |
4530 | +%fore "black", cont | |
4531 | + e8357978 f7ac77e0 eb15eac0 .z5hxy5h`w,w@j.k | |
4532 | + 0xf7e10f10 00000001 00000002 0000000b 00000000 ................ | |
4533 | + 0xf7e10f20 00000001 f7e10f24 f7e10f24 00000001 ................ | |
4534 | + 0xf7e10f30 f7e35e70 eea7e8f0 08048000 0804862b ................ | |
4535 | + 0xf7e10f40 0804962c 08049744 08051780 0805a000 ................ | |
4536 | + 0xf7e10f50 bffffd10 bffffe00 bffffe09 bffffe09 ................ | |
4537 | + 0xf7e10f60 bffffff3 0000005a 00000168 00000000 ................ | |
4538 | + 0xf7e10f70 00000000 00000002 00000000 00000001 ................ | |
4539 | + | |
4540 | +%font "typewriter", size 3 | |
4541 | + Determine offset of the first vma in the process | |
4542 | +%font "typewriter", size 3 | |
4543 | + struct mm_struct { | |
4544 | +%fore "blue" | |
4545 | + struct vm_area_struct * mmap; | |
4546 | +%fore "black" | |
4547 | + rb_root_t mm_rb; | |
4548 | + struct vm_area_struct * mmap_cache; | |
4549 | + <snip> | |
4550 | + }; | |
4551 | + | |
4552 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4553 | +%page | |
4554 | + | |
4555 | +Simple Program | |
4556 | + | |
4557 | +%font "typewriter", size 3 | |
4558 | + Display the first vma using md | |
4559 | +%font "typewriter", size 3 | |
4560 | + [3]kdb> | |
4561 | +%fore "blue", cont | |
4562 | +md e8357a80 | |
4563 | +%fore "black" | |
4564 | + 0xe8357a80 f7e10f00 08048000 08049000 | |
4565 | +%fore "blue", cont | |
4566 | +e8727e00 | |
4567 | +%fore "black",cont | |
4568 | + ..aw.........~rh | |
4569 | + 0xe8357a90 00000025 00001875 e8727e18 00000001 %...u....~rh.... | |
4570 | + | |
4571 | + Display the first vma using vma | |
4572 | +%font "typewriter", size 3 | |
4573 | + [3]kdb> | |
4574 | +%fore "blue", cont | |
4575 | +vma e8357a80 | |
4576 | +%fore "black" | |
4577 | + struct vm_area_struct at 0xe8357a80 for 68 bytes | |
4578 | + vm_start = 0x8048000 vm_end = 0x8049000 | |
4579 | + page_prot = 0x25 | |
4580 | + flags: READ EXEC MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE | |
4581 | +%font "typewriter", size 3 | |
4582 | + | |
4583 | + Determine the offset to the vma list | |
4584 | +%font "typewriter", size 3 | |
4585 | + struct vm_area_struct { | |
4586 | + [0] struct mm_struct * vm_mm; | |
4587 | + [4] unsigned long vm_start; | |
4588 | + [8] unsigned long vm_end; | |
4589 | +%fore "blue" | |
4590 | + [c] struct vm_area_struct *vm_next; | |
4591 | +%fore "black" | |
4592 | + <snip> | |
4593 | + }; | |
4594 | + Display the next vma | |
4595 | +%font "typewriter", size 3 | |
4596 | + [3]kdb> vma e8727e00 | |
4597 | + struct vm_area_struct at 0xe8727e00 for 68 bytes | |
4598 | + vm_start = 0x8049000 vm_end = 0x804a000 | |
4599 | + page_prot = 0x25 | |
4600 | + flags: READ WRITE MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE | |
4601 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4602 | +%page | |
4603 | + | |
4604 | +Simple Program | |
4605 | + | |
4606 | +%font "typewriter", size 3 | |
4607 | + Use the ll command to display the list of vma's | |
4608 | +%font "typewriter", size 3 | |
4609 | + [3]kdb> ll e8357a80 0xc vma | |
4610 | +. | |
4611 | + struct vm_area_struct at 0xe8357a80 for 68 bytes | |
4612 | + vm_start = 0x8048000 vm_end = 0x8049000 | |
4613 | + page_prot = 0x25 | |
4614 | + flags: READ EXEC MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE | |
4615 | +. | |
4616 | + struct vm_area_struct at 0xe8727e00 for 68 bytes | |
4617 | + vm_start = | |
4618 | +%fore "orange", cont | |
4619 | +0x8049000 | |
4620 | +%fore "black", cont | |
4621 | + vm_end = | |
4622 | +%fore "orange", cont | |
4623 | +0x804a000 | |
4624 | +%fore "black" | |
4625 | + page_prot = 0x25 | |
4626 | + flags: READ WRITE MAYREAD MAYWRITE MAYEXEC DENYWRITE EXECUTABLE | |
4627 | +. | |
4628 | + struct vm_area_struct at 0xe8727c80 for 68 bytes | |
4629 | + vm_start = | |
4630 | +%fore "blue", cont | |
4631 | +0x804a000 | |
4632 | +%fore "black", cont | |
4633 | + vm_end = | |
4634 | +%fore "blue", cont | |
4635 | +0x805a000 | |
4636 | +%fore "black" | |
4637 | + page_prot = 0x25 | |
4638 | + flags: READ WRITE EXEC MAYREAD MAYWRITE MAYEXEC | |
4639 | + <snip> | |
4640 | + struct vm_area_struct at 0xe8357900 for 68 bytes | |
4641 | + vm_start = 0xbfffe000 vm_end = 0xc0000000 | |
4642 | + page_prot = 0x25 | |
4643 | + flags: READ WRITE EXEC MAYREAD MAYWRITE MAYEXEC GROWSDOWN | |
4644 | + | |
4645 | + Match the vma to the displayed addresses | |
4646 | +%font "typewriter", size 3 | |
4647 | + foo_global at | |
4648 | +%fore "orange", cont | |
4649 | +8049780 | |
4650 | +%fore "black" | |
4651 | + foo_malloc at | |
4652 | +%fore "blue", cont | |
4653 | +8051788 | |
4654 | +%fore "black" | |
4655 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4656 | +%page | |
4657 | + | |
4658 | +Walking IO structures | |
4659 | + | |
4660 | + | |
4661 | + Objective | |
4662 | + Show usage of various scsi and vm related kdb commands | |
4663 | + | |
4664 | + Sequence: | |
4665 | + Set a breakpoint in the scsi driver | |
4666 | + Stops when queueing a command to the controller | |
4667 | + Cause IO on an idle disk | |
4668 | + Show various IO stack traces | |
4669 | + Display the IO data structures | |
4670 | + Display vm information about the data | |
4671 | + | |
4672 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4673 | +%page | |
4674 | + | |
4675 | +Walking IO structures | |
4676 | + | |
4677 | + | |
4678 | +%font "typewriter", size 3 | |
4679 | + Set the breakpoint | |
4680 | + | |
4681 | +%font "typewriter", size 3 | |
4682 | + [3]kdb> | |
4683 | +%fore "blue", cont | |
4684 | +bp isp1020_queuecommand | |
4685 | +%fore "black" | |
4686 | + Instruction(i) BP #0 at 0xc01ecfe0 (isp1020_queuecommand) | |
4687 | + is enabled globally adjust 1 | |
4688 | + | |
4689 | +%font "typewriter", size 3 | |
4690 | + Create some activity on a previously unused disk | |
4691 | + | |
4692 | +%font "typewriter", size 3 | |
4693 | + [3]kdb> | |
4694 | +%fore "blue", cont | |
4695 | +go | |
4696 | +%fore "black" | |
4697 | + [root@elm3b77 root]# | |
4698 | +%fore "blue", cont | |
4699 | +ls /rh62 | |
4700 | +%fore "black" | |
4701 | + | |
4702 | + Instruction(i) breakpoint #0 at 0xc01ecfe0 (adjusted) | |
4703 | + 0xc01ecfe0 isp1020_queuecommand:int3 | |
4704 | + | |
4705 | + Entering kdb (current=0xf75ba000, pid 1181) on processor 3 due to | |
4706 | + Breakpoint @ 0xc01ecfe0 | |
4707 | + | |
4708 | + | |
4709 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4710 | +%page | |
4711 | + | |
4712 | +Walking IO structures | |
4713 | + | |
4714 | + | |
4715 | +%font "typewriter", size 3 | |
4716 | + Show the stack. | |
4717 | + This is a read of the /rh62 directory | |
4718 | + | |
4719 | +%font "typewriter", size 3 | |
4720 | + [1]kdb> | |
4721 | +%fore "blue", cont | |
4722 | +bt | |
4723 | +%fore "black" | |
4724 | + EBP EIP Function(args) | |
4725 | + 0xf75bbdf4 0xc01ecfe0 isp1020_queuecommand | |
4726 | + 0xc01e2c77 scsi_dispatch_cmd+0x1f7 | |
4727 | + 0xf75bbe24 0xc01e99b1 scsi_request_fn+0x2f1 | |
4728 | + 0xf75bbe34 0xc01c84fd generic_unplug_device+0x2d | |
4729 | + 0xf75bbe50 0xc011b3af __run_task_queue+0x5f | |
4730 | + 0xf75bbe6c 0xc013a63c block_sync_page+0x1c | |
4731 | + 0xf75bbe98 0xc0128127 __lock_page+0x77 | |
4732 | + 0xf75bbea4 0xc0128178 lock_page+0x18 | |
4733 | + 0xf75bbec8 0xc012a4b3 read_cache_page+0xc3 | |
4734 | + 0xf75bbef4 0xc0168e23 ext2_get_page+0x23 | |
4735 | + 0xf75bbf48 0xc0168fdd ext2_readdir+0xfd | |
4736 | + 0xf75bbf68 0xc0143d2e vfs_readdir+0x7e | |
4737 | + 0xf75bbfbc 0xc01442ed | |
4738 | +%fore "blue", cont | |
4739 | +sys_getdents64+0x4d | |
4740 | +%fore "black" | |
4741 | + 0xc010702b system_call+0x33 | |
4742 | + | |
4743 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4744 | +%page | |
4745 | + | |
4746 | +Walking IO structures | |
4747 | + | |
4748 | + | |
4749 | +%font "typewriter", size 3 | |
4750 | + Allow the operation to complete | |
4751 | + | |
4752 | +%font "typewriter", size 3 | |
4753 | + [3]kdb> | |
4754 | +%fore "blue", cont | |
4755 | +go | |
4756 | +%fore "black" | |
4757 | + bench build etc lib mnt oldsys rh72 spv usr | |
4758 | + bin data h linux mnt1 opt root test var | |
4759 | + boot dev home lost+found mnt2 proc sbin tmp | |
4760 | + | |
4761 | +%font "typewriter", size 3 | |
4762 | + Force some more activity | |
4763 | + | |
4764 | +%font "typewriter", size 3 | |
4765 | + [root@elm3b77 root]# | |
4766 | +%fore "blue", cont | |
4767 | +cd /rh62/tmp | |
4768 | +%fore "black" | |
4769 | + Instruction(i) breakpoint #0 at 0xc01ecfe0 (adjusted) | |
4770 | + 0xc01ecfe0 isp1020_queuecommand:int3 | |
4771 | + | |
4772 | + Entering kdb (current=0xf768a000, pid 981) on processor 3 due to | |
4773 | + Breakpoint @ 0xc01ecfe0 | |
4774 | + | |
4775 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4776 | +%page | |
4777 | + | |
4778 | +Walking IO structures | |
4779 | + | |
4780 | + | |
4781 | +%font "typewriter", size 3 | |
4782 | + Show the stack. | |
4783 | + This is an inode read for /rh62/tmp | |
4784 | + | |
4785 | +%font "typewriter", size 3 | |
4786 | + [3]kdb> | |
4787 | +%fore "blue", cont | |
4788 | +bt | |
4789 | +%fore "black" | |
4790 | + EBP EIP Function(args) | |
4791 | + 0xf768bd68 0xc01ecfe0 isp1020_queuecommand | |
4792 | + 0xc01e2c77 scsi_dispatch_cmd+0x1f7 | |
4793 | + 0xf768bd98 0xc01e99b1 scsi_request_fn+0x2f1 | |
4794 | + 0xf768bda8 0xc01c84fd generic_unplug_device+0x2d | |
4795 | + 0xf768bdc4 0xc011b3af __run_task_queue+0x5f | |
4796 | + 0xf768bdfc 0xc0137216 __wait_on_buffer+0x56 | |
4797 | + 0xf768be1c 0xc0138600 bread+0x50 | |
4798 | + 0xf768be5c 0xc016b684 ext2_read_inode+0x114 | |
4799 | + 0xf768bf0c 0xc013fbec real_lookup+0x7c | |
4800 | + 0xf768bf78 0xc014035d link_path_walk+0x5ad | |
4801 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4802 | +%page | |
4803 | + | |
4804 | +Walking IO structures | |
4805 | + | |
4806 | + | |
4807 | +%font "typewriter", size 3 | |
4808 | + Create a new file, causing yet more disk activity | |
4809 | + | |
4810 | +%font "typewriter", size 3 | |
4811 | + [3]kdb> | |
4812 | +%fore "blue", cont | |
4813 | +go | |
4814 | +%fore "black" | |
4815 | + | |
4816 | + [root@elm3b77 tmp]# | |
4817 | +%fore "blue", cont | |
4818 | +echo "Hello linux reading group" > j1;sync | |
4819 | +%fore "black" | |
4820 | + | |
4821 | + Instruction(i) breakpoint #0 at 0xc01ecfe0 (adjusted) | |
4822 | + 0xc01ecfe0 isp1020_queuecommand:int3 | |
4823 | + | |
4824 | + Entering kdb (current=0xf768a000, pid 981) on processor 3 due to | |
4825 | + Breakpoint @ 0xc01ecfe0 | |
4826 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4827 | +%page | |
4828 | + | |
4829 | +Walking IO structures | |
4830 | + | |
4831 | + | |
4832 | +%font "typewriter", size 3 | |
4833 | + Show the stack | |
4834 | + This is an inode read in response to the open | |
4835 | +%font "typewriter", size 3 | |
4836 | + [3]kdb> | |
4837 | +%fore "blue", cont | |
4838 | +bt | |
4839 | +%fore "black" | |
4840 | + EBP EIP Function(args) | |
4841 | + 0xf768bd78 0xc01ecfe0 isp1020_queuecommand | |
4842 | + 0xc01e2c77 scsi_dispatch_cmd+0x1f7 | |
4843 | + 0xf768bda8 0xc01e99b1 scsi_request_fn+0x2f1 | |
4844 | + 0xf768bdb8 0xc01c84fd generic_unplug_device+0x2d | |
4845 | + 0xf768bdd4 0xc011b3af __run_task_queue+0x5f | |
4846 | + 0xf768bdf0 0xc013a63c block_sync_page+0x1c | |
4847 | + 0xf768be1c 0xc0128127 __lock_page+0x77 | |
4848 | + 0xf768be28 0xc0128178 lock_page+0x18 | |
4849 | + 0xf768be4c 0xc012a4b3 read_cache_page+0xc3 | |
4850 | + 0xf768be78 0xc0168e23 ext2_get_page+0x23 | |
4851 | + 0xf768beb8 0xc01691ed ext2_find_entry+0x8d | |
4852 | + 0xf768bed4 0xc016933a ext2_inode_by_name+0x1a | |
4853 | + 0xf768befc 0xc016c077 ext2_lookup+0x27 | |
4854 | + 0xf768bf1c 0xc014094a lookup_hash+0x9a | |
4855 | + 0xf768bf64 0xc0140c4d open_namei+0xfd | |
4856 | + 0xf768bfa0 0xc0135907 filp_open+0x37 | |
4857 | + 0xf768bfbc 0xc0135c64 sys_open+0x34 | |
4858 | + 0xc010702b system_call+0x33 | |
4859 | + | |
4860 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4861 | +%page | |
4862 | + | |
4863 | +Walking IO structures | |
4864 | + | |
4865 | + | |
4866 | +%font "typewriter", size 3 | |
4867 | + Let the operation continue | |
4868 | +%font "typewriter", size 3 | |
4869 | + [3]kdb> | |
4870 | +%fore "blue", cont | |
4871 | +go | |
4872 | +%fore "black" | |
4873 | + Instruction(i) breakpoint #0 at 0xc01ecfe0 (adjusted) | |
4874 | + 0xc01ecfe0 isp1020_queuecommand: int3 | |
4875 | + Entering kdb (current=0xc0352000, pid 0) on processor 0 due to | |
4876 | + Breakpoint @ 0xc01ecfe0 | |
4877 | + Show the stack | |
4878 | + This is an io completion queuing the next request | |
4879 | +%font "typewriter", size 3 | |
4880 | + [0]kdb> | |
4881 | +%fore "blue", cont | |
4882 | +bt | |
4883 | +%fore "black" | |
4884 | + EBP EIP Function(args) | |
4885 | + 0xc0353df4 0xc01ecfe0 isp1020_queuecommand( | |
4886 | +%fore "blue", cont | |
4887 | +0xf7e63a00 | |
4888 | +%fore "black", cont | |
4889 | +,0xc01e7fc0... | |
4890 | + 0xc01e2c77 scsi_dispatch_cmd+0x1f7 | |
4891 | + 0xc0353e24 0xc01e99b1 scsi_request_fn+0x2f1 | |
4892 | + 0xc0353e40 0xc01e8f6a | |
4893 | +%fore "blue", cont | |
4894 | +scsi_queue_next_request+0x4a | |
4895 | +%fore "black" | |
4896 | + 0xc0353e5c 0xc01e9166 __scsi_end_request+0x116 | |
4897 | + 0xc0353ea8 0xc01e93e0 | |
4898 | +%fore "blue", cont | |
4899 | +scsi_io_completion+0x170 | |
4900 | +%fore "black" | |
4901 | + 0xc0353ecc 0xc01f658e rw_intr+0x14e | |
4902 | + 0xc0353ef8 0xc01e8668 scsi_old_done+0x6a8 | |
4903 | + 0xc0353fd4 0xc01052c2 cpu_idle+0x52 | |
4904 | + Function prototype | |
4905 | +%font "typewriter", size 3 | |
4906 | + int isp1020_queuecommand( | |
4907 | +%fore "blue", cont | |
4908 | +Scsi_Cmnd *Cmnd, | |
4909 | +%fore "black" | |
4910 | + void (*done)(Scsi_Cmnd *)) | |
4911 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4912 | +%page | |
4913 | + | |
4914 | +Walking IO structures | |
4915 | + | |
4916 | + | |
4917 | +%font "typewriter", size 3 | |
4918 | + Show the command being queued | |
4919 | +%font "typewriter", size 3 | |
4920 | + [0]kdb> | |
4921 | +%fore "blue", cont | |
4922 | +sc 0xf7e63a00 | |
4923 | +%fore "black" | |
4924 | + scsi_cmnd at 0xf7e63a00 | |
4925 | +%fore "blue" | |
4926 | + host = 0xf7e91400 | |
4927 | +%fore "black", cont | |
4928 | + state = 4099 owner = 258 | |
4929 | +%fore "blue", cont | |
4930 | +device = 0xf7ed5d80 | |
4931 | +%fore "black" | |
4932 | + bnext = 0x00000000 reset_chain = 0x00000000 eh_state = 0 | |
4933 | + done = 0xc01f6440 | |
4934 | + serial_number = 3402 serial_num_at_to = 0 retries = 0 timeout = 0 | |
4935 | + id/lun/cmnd = [0/0/0] cmd_len = 10 old_cmd_len = 10 | |
4936 | + cmnd = [2a/00/00/28/00/3f/00/00/10/00/ef/f7] | |
4937 | + data_cmnd = [2a/00/00/28/00/3f/00/00/10/00/ef/f7] | |
4938 | + request_buffer = 0xc03fd000 bh_next = 0x00000000 | |
4939 | + request_bufflen = 8192 | |
4940 | + use_sg = 2 old_use_sg = 2 sglist_len = 512 abore_reason = 0 | |
4941 | + bufflen = 8192 buffer = 0xc03fd000 underflow = 8192 | |
4942 | + transfersize = 512 | |
4943 | + tag = 0 pid = 3401 | |
4944 | + request struct | |
4945 | + rq_status = RQ_ACTIVE rq_dev = [8/1] errors = 1 cmd = 0 | |
4946 | + sector = 2621440 nr_sectors = 16 current_nr_sectors = 8 | |
4947 | + buffer = 0xf7599000 | |
4948 | +%fore "blue", cont | |
4949 | +bh = 0xf75ca300 | |
4950 | +%fore "black", cont | |
4951 | + bhtail = 0xf75ca3c0 | |
4952 | + | |
4953 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4954 | +%page | |
4955 | + | |
4956 | +Walking IO structures | |
4957 | + | |
4958 | + | |
4959 | +%font "typewriter", size 3 | |
4960 | + Display the host adapter | |
4961 | +%font "typewriter", size 3 | |
4962 | + [0]kdb> | |
4963 | +%fore "blue", cont | |
4964 | +sh 0xf7e91400 | |
4965 | +%fore "black" | |
4966 | + Scsi_Host at 0xf7e91400 | |
4967 | + next = 0x00000000 | |
4968 | +%fore "blue", cont | |
4969 | +host_queue = 0xf7ed5d80 | |
4970 | +%fore "black" | |
4971 | + ehandler = 0x00000000 eh_wait = 0x00000000 en_notify = 0x00000000 | |
4972 | + eh_action = 0x00000000 | |
4973 | + h_active = 0x0 host_wait = 0xc0353ac4 hostt = 0xc034bce0 | |
4974 | + host_busy = 1 | |
4975 | + host_failed = 0 extra_bytes = 524 host_no = 0 resetting = 0 | |
4976 | + max id/lun/channel = [16/8/0] this_id = 7 | |
4977 | + can_queue = 64 cmd_per_lun = 1 sg_tablesize = 427 u_isa_dma = 0 | |
4978 | + host_blocked = 0 reverse_ordering = 0 | |
4979 | + | |
4980 | +%font "typewriter", size 3 | |
4981 | + Display the scsi device | |
4982 | +%font "typewriter", size 3 | |
4983 | + [0]kdb> | |
4984 | +%fore "blue", cont | |
4985 | +sd 0xf7ed5d80 | |
4986 | +%fore "black" | |
4987 | + scsi_device at 0xf7ed5d80 | |
4988 | + next = 0xf7ed5c80 prev = 0x00000000 host = 0xf7e91400 | |
4989 | + device_busy = 1 | |
4990 | +%fore "blue", cont | |
4991 | +device_queue 0xf7e63a00 | |
4992 | +%fore "black" | |
4993 | + id/lun/chan = [0/0/0] single_lun = 0 device_blocked = 0 | |
4994 | + queue_depth = 1 current_tag = 0 scsi_level = 4 | |
4995 | + IBM DGHS18X 0360 | |
4996 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4997 | +%page | |
4998 | + | |
4999 | +Walking IO structures | |
5000 | + | |
5001 | + | |
5002 | +%font "typewriter", size 3 | |
5003 | + Display the Buffer header associated with the command | |
5004 | +%font "typewriter", size 3 | |
5005 | + [0]kdb> | |
5006 | +%fore "blue", cont | |
5007 | +bh 0xf75ca300 | |
5008 | +%fore "black" | |
5009 | + buffer_head at 0xf75ca300 | |
5010 | + next 0x00000000 bno 327680 rsec 2621440 size 4096 | |
5011 | + dev 0x801 rdev 0x801 | |
5012 | + count 2 state 0x1d [Uptodate Lock Req Mapped] ftime 0x7695e | |
5013 | + b_list 1 b_reqnext 0xf75ca3c0 b_data 0xf7599000 | |
5014 | +%fore "blue" | |
5015 | + b_page 0xc1dd6640 | |
5016 | +%fore "black", cont | |
5017 | + b_this_page 0xf75ca300 b_private 0x00000000 | |
5018 | + | |
5019 | + Display the associated page structure | |
5020 | +%font "typewriter", size 3 | |
5021 | + [0]kdb> | |
5022 | +%fore "blue", cont | |
5023 | +page 0xc1dd6640 | |
5024 | +%fore "black" | |
5025 | + struct page at 0xc1dd6640 | |
5026 | + next 0xc1dd7300 prev 0xc1dd6240 | |
5027 | +%fore "blue", cont | |
5028 | +addr space 0xf7af04d0 | |
5029 | +%fore "black" | |
5030 | + index 327680 (offset 0x50000000) | |
5031 | + count 2 flags PG_referenced PG_lru virtual 0xf7599000 | |
5032 | + buffers 0xf75ca300 | |
5033 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
5034 | +%page | |
5035 | + | |
5036 | +Walking IO structures | |
5037 | + | |
5038 | + | |
5039 | +%font "typewriter", size 3 | |
5040 | + Display the Address space associated with the page | |
5041 | +%font "typewriter", size 3 | |
5042 | + [0]kdb> | |
5043 | +%fore "blue", cont | |
5044 | +md 0xf7af04d0 | |
5045 | +%fore "black" | |
5046 | + 0xf7af04d0 c1dd6240 c1dea740 f7af04d8 f7af04d8 @b]A@'^AX./wX./w | |
5047 | + 0xf7af04e0 f7af04e0 f7af04e0 00000007 c033b700 `./w`./w.....73@ | |
5048 | + 0xf7af04f0 | |
5049 | +%fore "blue", cont | |
5050 | +f7af0420 | |
5051 | +%fore "black", cont | |
5052 | + 00000000 00000000 00000001 ./w............ | |
5053 | + 0xf7af0500 000001d0 00000000 00000000 f7af050c P............./w | |
5054 | + 0xf7af0510 f7af050c 00000000 f7a8afa0 00000000 ../w.... /(w.... | |
5055 | + | |
5056 | + The structure looks like: | |
5057 | +%size 3 | |
5058 | + struct address_space { | |
5059 | + struct list_head clean_pages; /* list of clean pages */ | |
5060 | + struct list_head dirty_pages; /* list of dirty pages */ | |
5061 | + struct list_head locked_pages;/* list of locked pages */ | |
5062 | + unsigned long nrpages; /* number of total pages */ | |
5063 | + spinlock_t page_lock; /* spinlock protecting them*/ | |
5064 | + struct address_space_operations *a_ops; /* methods */ | |
5065 | +%fore "blue" | |
5066 | + struct inode *host; /* owner: inode, block_dev */ | |
5067 | +%fore "black" | |
5068 | + <snip> | |
5069 | + }; | |
5070 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
5071 | +%page | |
5072 | + | |
5073 | +Walking IO structures | |
5074 | + | |
5075 | + | |
5076 | +%font "typewriter", size 3 | |
5077 | + Display the inode associated with the address space | |
5078 | + I think htis is the inode for the block device. | |
5079 | + | |
5080 | +%font "typewriter", size 3 | |
5081 | + [1]kdb> | |
5082 | +%fore "blue", cont | |
5083 | +inode f7af0420 | |
5084 | +%fore "black" | |
5085 | + struct inode at 0xf7af0420 | |
5086 | + i_ino = 289 i_count = 1 i_dev = 0x801 i_size 4301789184 | |
5087 | + i_mode = 0x8000 i_nlink = 1 i_rdev = 0x801 | |
5088 | + i_hash.nxt = 0xf7af0420 i_hash.prv = 0xf7af0420 | |
5089 | + i_list.nxt = 0xf7af0608 i_list.prv = 0xf7af0068 | |
5090 | + i_dentry.nxt = 0xf7af0430 i_dentry.prv = 0xf7af0430 | |
5091 | + i_dirty_buffers.nxt = 0xf7af0438 i_dirty_buffers.prv = 0xf7af0438 | |
5092 | + i_sb = 0xc201f200 i_op = 0xc03cfdc0 i_data = 0xf7af04d0 nrpages = 6 | |
5093 | + i_mapping = 0xf7af04d0 | |
5094 | + i_flags 0x0 i_state 0x0 [] fs specific info @ 0xf7af0540 | |
5095 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
5096 | +%page | |
5097 | + | |
5098 | +Walking IO structures | |
5099 | + | |
5100 | + | |
5101 | +%font "typewriter", size 3 | |
5102 | + Display the page list associated with the inode | |
5103 | +%font "typewriter", size 3 | |
5104 | + [0]kdb> | |
5105 | +%fore "blue", cont | |
5106 | +inode_pages f7af0420 | |
5107 | +%fore "black" | |
5108 | +CLEAN page_struct index cnt flags | |
5109 | + 0xc1dd6240 327735 2 0x44 bh 0xf75caae0 bno 327735 | |
5110 | + [Lock Req Mapped] | |
5111 | +%fore "blue" | |
5112 | + 0xc1dd6640 327680 2 0x44 bh 0xf75ca300 bno 327680 | |
5113 | + [Uptodate Lock Req Mapped] | |
5114 | +%fore "black" | |
5115 | + 0xc1dd7300 327681 2 0x44 bh 0xf75ca3c0 bno 327681 | |
5116 | + [Uptodate Lock Req Mapped] | |
5117 | + 0xc1dd6e00 327684 2 0x44 bh 0xf75ca420 bno 327684 | |
5118 | + [Uptodate Req Mapped] | |
5119 | + 0xc1de8fc0 4 2 0xc0 bh 0xf7b5ade0 bno 4 | |
5120 | + [Uptodate Req Mapped] | |
5121 | + 0xc1dea700 1 2 0x44 bh 0xf7e02740 bno 1 | |
5122 | + [Uptodate Req Mapped] | |
5123 | + 0xc1dea740 0 2 0x44 bh 0xf7e028c0 bno 0 | |
5124 | + [Uptodate Req Mapped] | |
5125 | +DIRTY page_struct index cnt flags | |
5126 | +LOCKED page_struct index cnt flags | |
5127 | --- a/Makefile | |
5128 | +++ b/Makefile | |
5129 | @@ -645,6 +645,7 @@ export mod_strip_cmd | |
5130 | ||
5131 | ifeq ($(KBUILD_EXTMOD),) | |
5132 | core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ | |
5133 | +core-$(CONFIG_KDB) += kdb/ | |
5134 | ||
5135 | vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ | |
5136 | $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ | |
5137 | --- a/drivers/char/keyboard.c | |
5138 | +++ b/drivers/char/keyboard.c | |
5139 | @@ -43,6 +43,9 @@ | |
5140 | #include <linux/reboot.h> | |
5141 | #include <linux/notifier.h> | |
5142 | #include <linux/jiffies.h> | |
5143 | +#ifdef CONFIG_KDB | |
5144 | +#include <linux/kdb.h> | |
5145 | +#endif /* CONFIG_KDB */ | |
5146 | ||
5147 | extern void ctrl_alt_del(void); | |
5148 | ||
5149 | @@ -1189,6 +1192,13 @@ static void kbd_keycode(unsigned int key | |
5150 | } | |
5151 | #endif | |
5152 | ||
5153 | +#ifdef CONFIG_KDB | |
5154 | + if (down && !rep && keycode == KEY_PAUSE && kdb_on == 1) { | |
5155 | + kdb(KDB_REASON_KEYBOARD, 0, get_irq_regs()); | |
5156 | + return; | |
5157 | + } | |
5158 | +#endif /* CONFIG_KDB */ | |
5159 | + | |
5160 | #ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */ | |
5161 | if (keycode == KEY_SYSRQ && (sysrq_down || (down == 1 && sysrq_alt))) { | |
5162 | if (!sysrq_down) { | |
5163 | --- a/drivers/hid/usbhid/hid-core.c | |
5164 | +++ b/drivers/hid/usbhid/hid-core.c | |
5165 | @@ -44,6 +44,10 @@ | |
5166 | #define DRIVER_DESC "USB HID core driver" | |
5167 | #define DRIVER_LICENSE "GPL" | |
5168 | ||
5169 | +#ifdef CONFIG_KDB_USB | |
5170 | +#include <linux/kdb.h> | |
5171 | +#endif | |
5172 | + | |
5173 | static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick", | |
5174 | "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"}; | |
5175 | /* | |
5176 | @@ -940,6 +944,15 @@ static void hid_disconnect(struct usb_in | |
5177 | ||
5178 | usbhid = hid->driver_data; | |
5179 | ||
5180 | +#ifdef CONFIG_KDB_USB | |
5181 | + /* | |
5182 | + * If the URB was for a Keyboard, detach it from kdb. | |
5183 | + * If the URB was for another type of device, just | |
5184 | + * allow kdb_usb_keyboard_detach() to silently fail. | |
5185 | + */ | |
5186 | + kdb_usb_keyboard_detach(usbhid->urbin); | |
5187 | +#endif | |
5188 | + | |
5189 | spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ | |
5190 | usb_set_intfdata(intf, NULL); | |
5191 | set_bit(HID_DISCONNECTED, &usbhid->iofl); | |
5192 | @@ -1037,6 +1050,21 @@ static int hid_probe(struct usb_interfac | |
5193 | printk(": USB HID v%x.%02x %s [%s] on %s\n", | |
5194 | hid->version >> 8, hid->version & 0xff, c, hid->name, path); | |
5195 | ||
5196 | +#ifdef CONFIG_KDB_USB | |
5197 | + /* Attach USB keyboards to kdb */ | |
5198 | + if (!strcmp(c, "Keyboard")) { | |
5199 | + int ret; | |
5200 | + struct usbhid_device *usbhid = hid->driver_data; | |
5201 | + extern void * usb_hcd_get_kdb_poll_func(struct usb_device *udev); | |
5202 | + ret = kdb_usb_keyboard_attach(usbhid->urbin, usbhid->inbuf, | |
5203 | + usb_hcd_get_kdb_poll_func(interface_to_usbdev(intf))); | |
5204 | + | |
5205 | + if (ret == -1) | |
5206 | + printk(": FAILED to register keyboard (%s) " | |
5207 | + "with KDB\n", path); | |
5208 | + } | |
5209 | +#endif /* CONFIG_KDB_USB */ | |
5210 | + | |
5211 | return 0; | |
5212 | } | |
5213 | ||
5214 | --- a/drivers/hid/usbhid/usbkbd.c | |
5215 | +++ b/drivers/hid/usbhid/usbkbd.c | |
5216 | @@ -30,6 +30,9 @@ | |
5217 | #include <linux/init.h> | |
5218 | #include <linux/usb/input.h> | |
5219 | #include <linux/hid.h> | |
5220 | +#ifdef CONFIG_KDB_USB | |
5221 | +#include <linux/kdb.h> | |
5222 | +#endif | |
5223 | ||
5224 | /* | |
5225 | * Version Information | |
5226 | @@ -289,6 +292,16 @@ static int usb_kbd_probe(struct usb_inte | |
5227 | usb_fill_int_urb(kbd->irq, dev, pipe, | |
5228 | kbd->new, (maxp > 8 ? 8 : maxp), | |
5229 | usb_kbd_irq, kbd, endpoint->bInterval); | |
5230 | + | |
5231 | +#ifdef CONFIG_KDB_USB | |
5232 | + /* Attach keyboard to kdb */ | |
5233 | + extern void * usb_hcd_get_kdb_poll_func(struct usb_device *udev); | |
5234 | + | |
5235 | + kdb_usb_keyboard_attach(kbd->irq, kbd->new, | |
5236 | + usb_hcd_get_kdb_poll_func(dev)); | |
5237 | + | |
5238 | +#endif /* CONFIG_KDB_USB */ | |
5239 | + | |
5240 | kbd->irq->transfer_dma = kbd->new_dma; | |
5241 | kbd->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | |
5242 | ||
5243 | @@ -326,6 +339,10 @@ static void usb_kbd_disconnect(struct us | |
5244 | ||
5245 | usb_set_intfdata(intf, NULL); | |
5246 | if (kbd) { | |
5247 | +#ifdef CONFIG_KDB_USB | |
5248 | + /* Detach the keyboard from kdb */ | |
5249 | + kdb_usb_keyboard_detach(kbd->irq); | |
5250 | +#endif /* CONFIG_KDB_USB */ | |
5251 | usb_kill_urb(kbd->irq); | |
5252 | input_unregister_device(kbd->dev); | |
5253 | usb_kbd_free_mem(interface_to_usbdev(intf), kbd); | |
5254 | --- a/drivers/serial/8250.c | |
5255 | +++ b/drivers/serial/8250.c | |
5256 | @@ -43,6 +43,19 @@ | |
5257 | #include <asm/irq.h> | |
5258 | ||
5259 | #include "8250.h" | |
5260 | +#include <linux/kdb.h> | |
5261 | +#ifdef CONFIG_KDB | |
5262 | +/* | |
5263 | + * kdb_serial_line records the serial line number of the first serial console. | |
5264 | + * NOTE: The kernel ignores characters on the serial line unless a user space | |
5265 | + * program has opened the line first. To enter kdb before user space has opened | |
5266 | + * the serial line, you can use the 'kdb=early' flag to lilo and set the | |
5267 | + * appropriate breakpoints. | |
5268 | + */ | |
5269 | + | |
5270 | +static int kdb_serial_line = -1; | |
5271 | +static const char *kdb_serial_ptr = kdb_serial_str; | |
5272 | +#endif /* CONFIG_KDB */ | |
5273 | ||
5274 | /* | |
5275 | * Configuration: | |
5276 | @@ -1310,6 +1323,20 @@ receive_chars(struct uart_8250_port *up, | |
5277 | * just force the read character to be 0 | |
5278 | */ | |
5279 | ch = 0; | |
5280 | +#ifdef CONFIG_KDB | |
5281 | + if ((up->port.line == kdb_serial_line) && kdb_on == 1) { | |
5282 | + if (ch == *kdb_serial_ptr) { | |
5283 | + if (!(*++kdb_serial_ptr)) { | |
5284 | + atomic_inc(&kdb_8250); | |
5285 | + kdb(KDB_REASON_KEYBOARD, 0, get_irq_regs()); | |
5286 | + atomic_dec(&kdb_8250); | |
5287 | + kdb_serial_ptr = kdb_serial_str; | |
5288 | + break; | |
5289 | + } | |
5290 | + } else | |
5291 | + kdb_serial_ptr = kdb_serial_str; | |
5292 | + } | |
5293 | +#endif /* CONFIG_KDB */ | |
5294 | ||
5295 | flag = TTY_NORMAL; | |
5296 | up->port.icount.rx++; | |
5297 | @@ -2582,7 +2609,7 @@ serial8250_console_write(struct console | |
5298 | if (up->port.sysrq) { | |
5299 | /* serial8250_handle_port() already took the lock */ | |
5300 | locked = 0; | |
5301 | - } else if (oops_in_progress) { | |
5302 | + } else if (oops_in_progress || KDB_8250()) { | |
5303 | locked = spin_trylock(&up->port.lock); | |
5304 | } else | |
5305 | spin_lock(&up->port.lock); | |
5306 | @@ -2640,6 +2667,30 @@ static int __init serial8250_console_set | |
5307 | if (!port->iobase && !port->membase) | |
5308 | return -ENODEV; | |
5309 | ||
5310 | +#ifdef CONFIG_KDB | |
5311 | + /* | |
5312 | + * Remember the line number of the first serial | |
5313 | + * console. We'll make this the kdb serial console too. | |
5314 | + */ | |
5315 | + if (co && kdb_serial_line == -1) { | |
5316 | + kdb_serial_line = co->index; | |
5317 | + kdb_serial.io_type = port->iotype; | |
5318 | + switch (port->iotype) { | |
5319 | + case SERIAL_IO_MEM: | |
5320 | +#ifdef SERIAL_IO_MEM32 | |
5321 | + case SERIAL_IO_MEM32: | |
5322 | +#endif | |
5323 | + kdb_serial.iobase = (unsigned long)(port->membase); | |
5324 | + kdb_serial.ioreg_shift = port->regshift; | |
5325 | + break; | |
5326 | + default: | |
5327 | + kdb_serial.iobase = port->iobase; | |
5328 | + kdb_serial.ioreg_shift = 0; | |
5329 | + break; | |
5330 | + } | |
5331 | + } | |
5332 | +#endif /* CONFIG_KDB */ | |
5333 | + | |
5334 | if (options) | |
5335 | uart_parse_options(options, &baud, &parity, &bits, &flow); | |
5336 | ||
5337 | --- a/drivers/serial/8250_early.c | |
5338 | +++ b/drivers/serial/8250_early.c | |
5339 | @@ -38,6 +38,11 @@ | |
5340 | #include <asm/fixmap.h> | |
5341 | #endif | |
5342 | ||
5343 | +#ifdef CONFIG_KDB | |
5344 | +#include <linux/kdb.h> | |
5345 | +static int kdb_serial_line = -1; | |
5346 | +#endif /* CONFIG_KDB */ | |
5347 | + | |
5348 | struct early_serial8250_device { | |
5349 | struct uart_port port; | |
5350 | char options[16]; /* e.g., 115200n8 */ | |
5351 | @@ -231,6 +236,30 @@ int __init setup_early_serial8250_consol | |
5352 | ||
5353 | register_console(&early_serial8250_console); | |
5354 | ||
5355 | +#ifdef CONFIG_KDB | |
5356 | + /* | |
5357 | + * Remember the line number of the first serial | |
5358 | + * console. We'll make this the kdb serial console too. | |
5359 | + */ | |
5360 | + if (kdb_serial_line == -1) { | |
5361 | + kdb_serial_line = early_serial8250_console.index; | |
5362 | + kdb_serial.io_type = early_device.port.iotype; | |
5363 | + switch (early_device.port.iotype) { | |
5364 | + case SERIAL_IO_MEM: | |
5365 | +#ifdef SERIAL_IO_MEM32 | |
5366 | + case SERIAL_IO_MEM32: | |
5367 | +#endif | |
5368 | + kdb_serial.iobase = (unsigned long)(early_device.port.membase); | |
5369 | + kdb_serial.ioreg_shift = early_device.port.regshift; | |
5370 | + break; | |
5371 | + default: | |
5372 | + kdb_serial.iobase = early_device.port.iobase; | |
5373 | + kdb_serial.ioreg_shift = 0; | |
5374 | + break; | |
5375 | + } | |
5376 | + } | |
5377 | +#endif /* CONFIG_KDB */ | |
5378 | + | |
5379 | return 0; | |
5380 | } | |
5381 | ||
5382 | --- a/drivers/serial/sn_console.c | |
5383 | +++ b/drivers/serial/sn_console.c | |
5384 | @@ -48,6 +48,22 @@ | |
5385 | #include <linux/delay.h> /* for mdelay */ | |
5386 | #include <linux/miscdevice.h> | |
5387 | #include <linux/serial_core.h> | |
5388 | +#ifdef CONFIG_KDB | |
5389 | +#include <linux/kdb.h> | |
5390 | +#include <linux/kdbprivate.h> | |
5391 | +#include <linux/serial_reg.h> | |
5392 | +/* | |
5393 | + * kdb_serial_line records the serial line number of the first serial console. | |
5394 | + * NOTE: The kernel ignores characters on the serial line unless a user space | |
5395 | + * program has opened the line first. To enter kdb before user space has opened | |
5396 | + * the serial line, you can use the 'kdb=early' flag to lilo and set the | |
5397 | + * appropriate breakpoints. | |
5398 | + */ | |
5399 | + | |
5400 | +static int kdb_serial_line = -1; | |
5401 | +static char *kdb_serial_ptr = (char *)kdb_serial_str; | |
5402 | +#endif /* CONFIG_KDB */ | |
5403 | + | |
5404 | ||
5405 | #include <asm/io.h> | |
5406 | #include <asm/sn/simulator.h> | |
5407 | @@ -485,6 +501,26 @@ sn_receive_chars(struct sn_cons_port *po | |
5408 | "obtaining data from the console (0x%0x)\n", ch); | |
5409 | break; | |
5410 | } | |
5411 | +#ifdef CONFIG_KDB | |
5412 | + if (kdb_on == 1) { | |
5413 | + if (ch == *kdb_serial_ptr) { | |
5414 | + if (!(*++kdb_serial_ptr)) { | |
5415 | + spin_unlock_irqrestore(&port->sc_port.lock, flags); | |
5416 | + if (!get_irq_regs()) { | |
5417 | + KDB_STATE_SET(KEYBOARD); | |
5418 | + KDB_ENTER(); /* to get some registers */ | |
5419 | + } else | |
5420 | + kdb(KDB_REASON_KEYBOARD, 0, get_irq_regs()); | |
5421 | + kdb_serial_ptr = (char *)kdb_serial_str; | |
5422 | + spin_lock_irqsave(&port->sc_port.lock, flags); | |
5423 | + break; | |
5424 | + } | |
5425 | + } | |
5426 | + else | |
5427 | + kdb_serial_ptr = (char *)kdb_serial_str; | |
5428 | + } | |
5429 | +#endif /* CONFIG_KDB */ | |
5430 | + | |
5431 | #ifdef CONFIG_MAGIC_SYSRQ | |
5432 | if (sysrq_requested) { | |
5433 | unsigned long sysrq_timeout = sysrq_requested + HZ*5; | |
5434 | @@ -1008,6 +1044,15 @@ sn_sal_console_write(struct console *co, | |
5435 | */ | |
5436 | static int sn_sal_console_setup(struct console *co, char *options) | |
5437 | { | |
5438 | +#ifdef CONFIG_KDB | |
5439 | + /* | |
5440 | + * Remember the line number of the first serial | |
5441 | + * console. We'll make this the kdb serial console too. | |
5442 | + */ | |
5443 | + if (kdb_serial_line == -1) { | |
5444 | + kdb_serial_line = co->index; | |
5445 | + } | |
5446 | +#endif /* CONFIG_KDB */ | |
5447 | return 0; | |
5448 | } | |
5449 | ||
5450 | @@ -1083,3 +1128,31 @@ static int __init sn_sal_serial_console_ | |
5451 | } | |
5452 | ||
5453 | console_initcall(sn_sal_serial_console_init); | |
5454 | + | |
5455 | +#ifdef CONFIG_KDB | |
5456 | +int | |
5457 | +l1_control_in_polled(int offset) | |
5458 | +{ | |
5459 | + int sal_call_status = 0, input; | |
5460 | + int ret = 0; | |
5461 | + if (offset == UART_LSR) { | |
5462 | + ret = (UART_LSR_THRE | UART_LSR_TEMT); /* can send anytime */ | |
5463 | + sal_call_status = ia64_sn_console_check(&input); | |
5464 | + if (!sal_call_status && input) { | |
5465 | + /* input pending */ | |
5466 | + ret |= UART_LSR_DR; | |
5467 | + } | |
5468 | + } | |
5469 | + return ret; | |
5470 | +} | |
5471 | + | |
5472 | +int | |
5473 | +l1_serial_in_polled(void) | |
5474 | +{ | |
5475 | + int ch; | |
5476 | + if (!ia64_sn_console_getc(&ch)) | |
5477 | + return ch; | |
5478 | + else | |
5479 | + return 0; | |
5480 | +} | |
5481 | +#endif /* CONFIG_KDB */ | |
5482 | --- a/drivers/usb/core/hcd.c | |
5483 | +++ b/drivers/usb/core/hcd.c | |
5484 | @@ -2027,6 +2027,20 @@ usb_hcd_platform_shutdown(struct platfor | |
5485 | } | |
5486 | EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown); | |
5487 | ||
5488 | +#ifdef CONFIG_KDB_USB | |
5489 | +void * | |
5490 | +usb_hcd_get_kdb_poll_func(struct usb_device *udev) | |
5491 | +{ | |
5492 | + struct usb_hcd *hcd = bus_to_hcd(udev->bus); | |
5493 | + | |
5494 | + if (hcd && hcd->driver) | |
5495 | + return (void *)(hcd->driver->kdb_poll_char); | |
5496 | + | |
5497 | + return NULL; | |
5498 | +} | |
5499 | +EXPORT_SYMBOL_GPL (usb_hcd_get_kdb_poll_func); | |
5500 | +#endif /* CONFIG_KDB_USB */ | |
5501 | + | |
5502 | /*-------------------------------------------------------------------------*/ | |
5503 | ||
5504 | #if defined(CONFIG_USB_MON) | |
5505 | --- a/drivers/usb/core/hcd.h | |
5506 | +++ b/drivers/usb/core/hcd.h | |
5507 | @@ -217,6 +217,10 @@ struct hc_driver { | |
5508 | void (*relinquish_port)(struct usb_hcd *, int); | |
5509 | /* has a port been handed over to a companion? */ | |
5510 | int (*port_handed_over)(struct usb_hcd *, int); | |
5511 | +#ifdef CONFIG_KDB_USB | |
5512 | + /* KDB poll function for this HC */ | |
5513 | + int (*kdb_poll_char)(struct urb *urb); | |
5514 | +#endif /* CONFIG_KDB_USB */ | |
5515 | }; | |
5516 | ||
5517 | extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); | |
5518 | --- a/drivers/usb/host/ehci-hcd.c | |
5519 | +++ b/drivers/usb/host/ehci-hcd.c | |
5520 | @@ -993,6 +993,48 @@ static int ehci_get_frame (struct usb_hc | |
5521 | ehci->periodic_size; | |
5522 | } | |
5523 | ||
5524 | +#ifdef CONFIG_KDB_USB | |
5525 | + | |
5526 | +int | |
5527 | +ehci_kdb_poll_char(struct urb *urb) | |
5528 | +{ | |
5529 | + struct ehci_hcd *ehci; | |
5530 | + | |
5531 | + /* just to make sure */ | |
5532 | + if (!urb || !urb->dev || !urb->dev->bus) | |
5533 | + return -1; | |
5534 | + | |
5535 | + ehci = (struct ehci_hcd *) hcd_to_ehci(bus_to_hcd(urb->dev->bus)); | |
5536 | + | |
5537 | + /* make sure */ | |
5538 | + if (!ehci) | |
5539 | + return -1; | |
5540 | + | |
5541 | + if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)) | |
5542 | + return -1; | |
5543 | + | |
5544 | + /* | |
5545 | + * If ehci->lock is held coming into this routine, it could | |
5546 | + * mean KDB was entered while the HC driver was in the midst | |
5547 | + * of processing URBs. Therefore it could be dangerous to | |
5548 | + * processes URBs from this poll routine. And, we can't wait on | |
5549 | + * the lock since we are in KDB and kernel threads (including the | |
5550 | + * one holding the lock) are suspended. | |
5551 | + * So, we punt and return an error. Keyboards attached to this | |
5552 | + * HC will not be useable from KDB at this time. | |
5553 | + */ | |
5554 | + if (spin_is_locked(&ehci->lock)) | |
5555 | + return -EBUSY; | |
5556 | + | |
5557 | + /* processes the URB */ | |
5558 | + if (qh_completions_kdb(ehci, urb->hcpriv, urb)) | |
5559 | + return 0; | |
5560 | + | |
5561 | + return -1; | |
5562 | +} | |
5563 | + | |
5564 | +#endif /* CONFIG_KDB_USB */ | |
5565 | + | |
5566 | /*-------------------------------------------------------------------------*/ | |
5567 | ||
5568 | #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC | |
5569 | --- a/drivers/usb/host/ehci-pci.c | |
5570 | +++ b/drivers/usb/host/ehci-pci.c | |
5571 | @@ -22,6 +22,10 @@ | |
5572 | #error "This file is PCI bus glue. CONFIG_PCI must be defined." | |
5573 | #endif | |
5574 | ||
5575 | +#ifdef CONFIG_KDB_USB | |
5576 | +#include <linux/kdb.h> | |
5577 | +#endif | |
5578 | + | |
5579 | /*-------------------------------------------------------------------------*/ | |
5580 | ||
5581 | /* called after powerup, by probe or system-pm "wakeup" */ | |
5582 | @@ -404,6 +408,10 @@ static const struct hc_driver ehci_pci_h | |
5583 | .bus_resume = ehci_bus_resume, | |
5584 | .relinquish_port = ehci_relinquish_port, | |
5585 | .port_handed_over = ehci_port_handed_over, | |
5586 | + | |
5587 | +#ifdef CONFIG_KDB_USB | |
5588 | + .kdb_poll_char = ehci_kdb_poll_char, | |
5589 | +#endif | |
5590 | }; | |
5591 | ||
5592 | /*-------------------------------------------------------------------------*/ | |
5593 | --- a/drivers/usb/host/ehci-q.c | |
5594 | +++ b/drivers/usb/host/ehci-q.c | |
5595 | @@ -499,6 +499,228 @@ halt: | |
5596 | return count; | |
5597 | } | |
5598 | ||
5599 | +#ifdef CONFIG_KDB_USB | |
5600 | +/* | |
5601 | + * This routine is basically a copy of qh_completions() for use by KDB. | |
5602 | + * It is modified to only work on qtds which are associated | |
5603 | + * with 'kdburb'. Also, there are some fixups related to locking. | |
5604 | + */ | |
5605 | +unsigned | |
5606 | +qh_completions_kdb(struct ehci_hcd *ehci, struct ehci_qh *qh, struct urb *kdburb) | |
5607 | +{ | |
5608 | + struct ehci_qtd *last = NULL, *end = qh->dummy; | |
5609 | + struct list_head *entry, *tmp; | |
5610 | + int last_status = -EINPROGRESS; | |
5611 | + int stopped; | |
5612 | + unsigned count = 0; | |
5613 | + int do_status = 0; | |
5614 | + u8 state; | |
5615 | + u32 halt = HALT_BIT(ehci); | |
5616 | + | |
5617 | + /* verify params are valid */ | |
5618 | + if (!qh || !kdburb) | |
5619 | + return 0; | |
5620 | + | |
5621 | + if (unlikely (list_empty (&qh->qtd_list))) | |
5622 | + return count; | |
5623 | + | |
5624 | + /* completions (or tasks on other cpus) must never clobber HALT | |
5625 | + * till we've gone through and cleaned everything up, even when | |
5626 | + * they add urbs to this qh's queue or mark them for unlinking. | |
5627 | + * | |
5628 | + * NOTE: unlinking expects to be done in queue order. | |
5629 | + */ | |
5630 | + state = qh->qh_state; | |
5631 | + qh->qh_state = QH_STATE_COMPLETING; | |
5632 | + stopped = (state == QH_STATE_IDLE); | |
5633 | + | |
5634 | + /* remove de-activated QTDs from front of queue. | |
5635 | + * after faults (including short reads), cleanup this urb | |
5636 | + * then let the queue advance. | |
5637 | + * if queue is stopped, handles unlinks. | |
5638 | + */ | |
5639 | + list_for_each_safe (entry, tmp, &qh->qtd_list) { | |
5640 | + struct ehci_qtd *qtd; | |
5641 | + struct urb *urb; | |
5642 | + u32 token = 0; | |
5643 | + int qtd_status; | |
5644 | + | |
5645 | + qtd = list_entry (entry, struct ehci_qtd, qtd_list); | |
5646 | + urb = qtd->urb; | |
5647 | + | |
5648 | + if (urb != kdburb) | |
5649 | + continue; | |
5650 | + | |
5651 | + /* clean up any state from previous QTD ...*/ | |
5652 | + if (last) { | |
5653 | + if (likely (last->urb != urb)) { | |
5654 | + /* | |
5655 | + * Lock hackery here... | |
5656 | + * ehci_urb_done() makes the assumption | |
5657 | + * that it's called with ehci->lock held. | |
5658 | + * So, lock it if it isn't already. | |
5659 | + */ | |
5660 | + if (!spin_is_locked(&ehci->lock)) | |
5661 | + spin_lock(&ehci->lock); | |
5662 | + | |
5663 | + ehci_urb_done(ehci, last->urb, last_status); | |
5664 | + | |
5665 | + /* | |
5666 | + * ehci_urb_done() releases and reacquires | |
5667 | + * ehci->lock, so release it here. | |
5668 | + */ | |
5669 | + if (spin_is_locked(&ehci->lock)) | |
5670 | + spin_unlock (&ehci->lock); | |
5671 | + | |
5672 | + count++; | |
5673 | + } | |
5674 | + ehci_qtd_free (ehci, last); | |
5675 | + last = NULL; | |
5676 | + last_status = -EINPROGRESS; | |
5677 | + } | |
5678 | + | |
5679 | + /* ignore urbs submitted during completions we reported */ | |
5680 | + if (qtd == end) | |
5681 | + break; | |
5682 | + | |
5683 | + /* hardware copies qtd out of qh overlay */ | |
5684 | + rmb (); | |
5685 | + token = hc32_to_cpu(ehci, qtd->hw_token); | |
5686 | + | |
5687 | + /* always clean up qtds the hc de-activated */ | |
5688 | + if ((token & QTD_STS_ACTIVE) == 0) { | |
5689 | + | |
5690 | + if ((token & QTD_STS_HALT) != 0) { | |
5691 | + stopped = 1; | |
5692 | + | |
5693 | + /* magic dummy for some short reads; qh won't advance. | |
5694 | + * that silicon quirk can kick in with this dummy too. | |
5695 | + */ | |
5696 | + } else if (IS_SHORT_READ (token) | |
5697 | + && !(qtd->hw_alt_next | |
5698 | + & EHCI_LIST_END(ehci))) { | |
5699 | + stopped = 1; | |
5700 | + goto halt; | |
5701 | + } | |
5702 | + | |
5703 | + /* stop scanning when we reach qtds the hc is using */ | |
5704 | + } else if (likely (!stopped | |
5705 | + && HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) { | |
5706 | + break; | |
5707 | + | |
5708 | + } else { | |
5709 | + stopped = 1; | |
5710 | + | |
5711 | + if (unlikely (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))) | |
5712 | + last_status = -ESHUTDOWN; | |
5713 | + | |
5714 | + /* ignore active urbs unless some previous qtd | |
5715 | + * for the urb faulted (including short read) or | |
5716 | + * its urb was canceled. we may patch qh or qtds. | |
5717 | + */ | |
5718 | + if (likely(last_status == -EINPROGRESS && | |
5719 | + !urb->unlinked)) | |
5720 | + continue; | |
5721 | + | |
5722 | + /* issue status after short control reads */ | |
5723 | + if (unlikely (do_status != 0) | |
5724 | + && QTD_PID (token) == 0 /* OUT */) { | |
5725 | + do_status = 0; | |
5726 | + continue; | |
5727 | + } | |
5728 | + | |
5729 | + /* token in overlay may be most current */ | |
5730 | + if (state == QH_STATE_IDLE | |
5731 | + && cpu_to_hc32(ehci, qtd->qtd_dma) | |
5732 | + == qh->hw_current) | |
5733 | + token = hc32_to_cpu(ehci, qh->hw_token); | |
5734 | + | |
5735 | + /* force halt for unlinked or blocked qh, so we'll | |
5736 | + * patch the qh later and so that completions can't | |
5737 | + * activate it while we "know" it's stopped. | |
5738 | + */ | |
5739 | + if ((halt & qh->hw_token) == 0) { | |
5740 | +halt: | |
5741 | + qh->hw_token |= halt; | |
5742 | + wmb (); | |
5743 | + } | |
5744 | + } | |
5745 | + | |
5746 | + /* remove it from the queue */ | |
5747 | + qtd_status = qtd_copy_status(ehci, urb, qtd->length, token); | |
5748 | + if (unlikely(qtd_status == -EREMOTEIO)) { | |
5749 | + do_status = (!urb->unlinked && | |
5750 | + usb_pipecontrol(urb->pipe)); | |
5751 | + qtd_status = 0; | |
5752 | + } | |
5753 | + if (likely(last_status == -EINPROGRESS)) | |
5754 | + last_status = qtd_status; | |
5755 | + | |
5756 | + if (stopped && qtd->qtd_list.prev != &qh->qtd_list) { | |
5757 | + last = list_entry (qtd->qtd_list.prev, | |
5758 | + struct ehci_qtd, qtd_list); | |
5759 | + last->hw_next = qtd->hw_next; | |
5760 | + } | |
5761 | + list_del (&qtd->qtd_list); | |
5762 | + last = qtd; | |
5763 | + } | |
5764 | + | |
5765 | + /* last urb's completion might still need calling */ | |
5766 | + if (likely (last != NULL)) { | |
5767 | + /* | |
5768 | + * Lock hackery here... | |
5769 | + * ehci_urb_done() makes the assumption | |
5770 | + * that it's called with ehci->lock held. | |
5771 | + * So, lock it if it isn't already. | |
5772 | + */ | |
5773 | + if (!spin_is_locked(&ehci->lock)) | |
5774 | + spin_lock(&ehci->lock); | |
5775 | + | |
5776 | + ehci_urb_done(ehci, last->urb, last_status); | |
5777 | + | |
5778 | + /* | |
5779 | + * ehci_urb_done() releases and reacquires | |
5780 | + * ehci->lock, so release it here. | |
5781 | + */ | |
5782 | + if (spin_is_locked(&ehci->lock)) | |
5783 | + spin_unlock (&ehci->lock); | |
5784 | + | |
5785 | + count++; | |
5786 | + ehci_qtd_free (ehci, last); | |
5787 | + } | |
5788 | + | |
5789 | + /* restore original state; caller must unlink or relink */ | |
5790 | + qh->qh_state = state; | |
5791 | + | |
5792 | + /* be sure the hardware's done with the qh before refreshing | |
5793 | + * it after fault cleanup, or recovering from silicon wrongly | |
5794 | + * overlaying the dummy qtd (which reduces DMA chatter). | |
5795 | + */ | |
5796 | + if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END(ehci)) { | |
5797 | + switch (state) { | |
5798 | + case QH_STATE_IDLE: | |
5799 | + qh_refresh(ehci, qh); | |
5800 | + break; | |
5801 | + case QH_STATE_LINKED: | |
5802 | + /* should be rare for periodic transfers, | |
5803 | + * except maybe high bandwidth ... | |
5804 | + */ | |
5805 | + if ((cpu_to_hc32(ehci, QH_SMASK) | |
5806 | + & qh->hw_info2) != 0) { | |
5807 | + intr_deschedule (ehci, qh); | |
5808 | + (void) qh_schedule (ehci, qh); | |
5809 | + } else | |
5810 | + unlink_async (ehci, qh); | |
5811 | + break; | |
5812 | + /* otherwise, unlink already started */ | |
5813 | + } | |
5814 | + } | |
5815 | + | |
5816 | + return count; | |
5817 | +} | |
5818 | + | |
5819 | +#endif /* CONFIG_KDB_USB */ | |
5820 | + | |
5821 | /*-------------------------------------------------------------------------*/ | |
5822 | ||
5823 | // high bandwidth multiplier, as encoded in highspeed endpoint descriptors | |
5824 | --- a/drivers/usb/host/ohci-hcd.c | |
5825 | +++ b/drivers/usb/host/ohci-hcd.c | |
5826 | @@ -984,6 +984,73 @@ static int ohci_restart (struct ohci_hcd | |
5827 | ||
5828 | /*-------------------------------------------------------------------------*/ | |
5829 | ||
5830 | +#ifdef CONFIG_KDB_USB | |
5831 | + | |
5832 | +int | |
5833 | +ohci_kdb_poll_char(struct urb *urb) | |
5834 | +{ | |
5835 | + struct ohci_hcd *ohci; | |
5836 | + struct ohci_regs * regs; | |
5837 | + | |
5838 | + /* just to make sure */ | |
5839 | + if (!urb || !urb->dev || !urb->dev->bus) | |
5840 | + return -1; | |
5841 | + | |
5842 | + ohci = (struct ohci_hcd *) hcd_to_ohci(bus_to_hcd(urb->dev->bus)); | |
5843 | + | |
5844 | + /* make sure */ | |
5845 | + if (!ohci || !ohci->hcca) | |
5846 | + return -1; | |
5847 | + | |
5848 | + if (!HC_IS_RUNNING (ohci_to_hcd(ohci)->state)) | |
5849 | + return -1; | |
5850 | + | |
5851 | + /* | |
5852 | + * If ohci->lock is held coming into this routine, it could | |
5853 | + * mean KDB was entered while the HC driver was in the midst | |
5854 | + * of processing URBs. Therefore it could be dangerous to | |
5855 | + * processes URBs from this poll routine. And, we can't wait on | |
5856 | + * the lock since we are in KDB and kernel threads (including the | |
5857 | + * one holding the lock) are suspended. | |
5858 | + * So, we punt and return an error. Keyboards attached to this | |
5859 | + * HC will not be useable from KDB at this time. | |
5860 | + */ | |
5861 | + if (spin_is_locked(&ohci->lock)) | |
5862 | + return -EBUSY; | |
5863 | + | |
5864 | + regs = ohci->regs; | |
5865 | + | |
5866 | + /* if the urb is not currently in progress resubmit it */ | |
5867 | + if (urb->status != -EINPROGRESS) { | |
5868 | + | |
5869 | + if (usb_submit_urb (urb, GFP_ATOMIC)) | |
5870 | + return -1; | |
5871 | + | |
5872 | + /* make sure the HC registers are set correctly */ | |
5873 | + ohci_writel (ohci, OHCI_INTR_WDH, ®s->intrenable); | |
5874 | + ohci_writel (ohci, OHCI_INTR_WDH, ®s->intrstatus); | |
5875 | + ohci_writel (ohci, OHCI_INTR_MIE, ®s->intrenable); | |
5876 | + | |
5877 | + // flush those pci writes | |
5878 | + (void) ohci_readl (ohci, &ohci->regs->control); | |
5879 | + } | |
5880 | + | |
5881 | + if (ohci->hcca->done_head) { | |
5882 | + dl_done_list_kdb (ohci, urb); | |
5883 | + ohci_writel (ohci, OHCI_INTR_WDH, ®s->intrstatus); | |
5884 | + // flush the pci write | |
5885 | + (void) ohci_readl (ohci, &ohci->regs->control); | |
5886 | + | |
5887 | + return 0; | |
5888 | + } | |
5889 | + | |
5890 | + return -1; | |
5891 | +} | |
5892 | + | |
5893 | +#endif /* CONFIG_KDB_USB */ | |
5894 | + | |
5895 | +/*-------------------------------------------------------------------------*/ | |
5896 | + | |
5897 | #define DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC | |
5898 | ||
5899 | MODULE_AUTHOR (DRIVER_AUTHOR); | |
5900 | --- a/drivers/usb/host/ohci-pci.c | |
5901 | +++ b/drivers/usb/host/ohci-pci.c | |
5902 | @@ -21,6 +21,10 @@ | |
5903 | #include <linux/pci.h> | |
5904 | #include <linux/io.h> | |
5905 | ||
5906 | +#ifdef CONFIG_KDB_USB | |
5907 | +#include <linux/kdb.h> | |
5908 | +#endif | |
5909 | + | |
5910 | ||
5911 | /* constants used to work around PM-related transfer | |
5912 | * glitches in some AMD 700 series southbridges | |
5913 | @@ -367,6 +371,7 @@ static int __devinit ohci_pci_start (str | |
5914 | ohci_err (ohci, "can't start\n"); | |
5915 | ohci_stop (hcd); | |
5916 | } | |
5917 | + | |
5918 | return ret; | |
5919 | } | |
5920 | ||
5921 | @@ -464,6 +469,9 @@ static const struct hc_driver ohci_pci_h | |
5922 | .bus_resume = ohci_bus_resume, | |
5923 | #endif | |
5924 | .start_port_reset = ohci_start_port_reset, | |
5925 | +#ifdef CONFIG_KDB_USB | |
5926 | + .kdb_poll_char = ohci_kdb_poll_char, | |
5927 | +#endif | |
5928 | }; | |
5929 | ||
5930 | /*-------------------------------------------------------------------------*/ | |
5931 | --- a/drivers/usb/host/ohci-q.c | |
5932 | +++ b/drivers/usb/host/ohci-q.c | |
5933 | @@ -1127,3 +1127,65 @@ dl_done_list (struct ohci_hcd *ohci) | |
5934 | td = td_next; | |
5935 | } | |
5936 | } | |
5937 | + | |
5938 | + | |
5939 | +/*-------------------------------------------------------------------------*/ | |
5940 | + | |
5941 | +#ifdef CONFIG_KDB_USB | |
5942 | +static void | |
5943 | +dl_done_list_kdb (struct ohci_hcd *ohci, struct urb *kdburb) | |
5944 | +{ | |
5945 | + struct td *td = dl_reverse_done_list (ohci); | |
5946 | + | |
5947 | + while (td) { | |
5948 | + struct td *td_next = td->next_dl_td; | |
5949 | + struct urb *urb = td->urb; | |
5950 | + urb_priv_t *urb_priv = urb->hcpriv; | |
5951 | + struct ed *ed = td->ed; | |
5952 | + | |
5953 | + if (urb != kdburb) { | |
5954 | + td = td_next; | |
5955 | + continue; | |
5956 | + } | |
5957 | + | |
5958 | + /* update URB's length and status from TD */ | |
5959 | + td_done (ohci, urb, td); | |
5960 | + urb_priv->td_cnt++; | |
5961 | + | |
5962 | + /* If all this urb's TDs are done, just resubmit it */ | |
5963 | + if (urb_priv->td_cnt == urb_priv->length) { | |
5964 | + urb->actual_length = 0; | |
5965 | + urb->status = -EINPROGRESS; | |
5966 | + td_submit_urb (ohci, urb); | |
5967 | + } | |
5968 | + | |
5969 | + /* clean schedule: unlink EDs that are no longer busy */ | |
5970 | + if (list_empty (&ed->td_list)) { | |
5971 | + if (ed->state == ED_OPER) | |
5972 | + start_ed_unlink (ohci, ed); | |
5973 | + | |
5974 | + /* ... reenabling halted EDs only after fault cleanup */ | |
5975 | + } else if ((ed->hwINFO & cpu_to_hc32 (ohci, ED_SKIP | ED_DEQUEUE)) | |
5976 | + == cpu_to_hc32 (ohci, ED_SKIP)) { | |
5977 | + td = list_entry (ed->td_list.next, struct td, td_list); | |
5978 | + if (!(td->hwINFO & cpu_to_hc32 (ohci, TD_DONE))) { | |
5979 | + ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP); | |
5980 | + /* ... hc may need waking-up */ | |
5981 | + switch (ed->type) { | |
5982 | + case PIPE_CONTROL: | |
5983 | + ohci_writel (ohci, OHCI_CLF, | |
5984 | + &ohci->regs->cmdstatus); | |
5985 | + break; | |
5986 | + case PIPE_BULK: | |
5987 | + ohci_writel (ohci, OHCI_BLF, | |
5988 | + &ohci->regs->cmdstatus); | |
5989 | + break; | |
5990 | + } | |
5991 | + } | |
5992 | + } | |
5993 | + | |
5994 | + td = td_next; | |
5995 | + } | |
5996 | +} | |
5997 | + | |
5998 | +#endif /* CONFIG_KDB_USB */ | |
5999 | --- a/fs/proc/mmu.c | |
6000 | +++ b/fs/proc/mmu.c | |
6001 | @@ -14,11 +14,21 @@ | |
6002 | #include <asm/pgtable.h> | |
6003 | #include "internal.h" | |
6004 | ||
6005 | +#ifdef CONFIG_KDB | |
6006 | +#include <linux/kdb.h> | |
6007 | +#endif | |
6008 | + | |
6009 | void get_vmalloc_info(struct vmalloc_info *vmi) | |
6010 | { | |
6011 | struct vm_struct *vma; | |
6012 | unsigned long free_area_size; | |
6013 | unsigned long prev_end; | |
6014 | +#ifdef CONFIG_KDB | |
6015 | + int get_lock = !KDB_IS_RUNNING(); | |
6016 | +#else | |
6017 | +#define get_lock 1 | |
6018 | +#endif | |
6019 | + | |
6020 | ||
6021 | vmi->used = 0; | |
6022 | ||
6023 | @@ -30,7 +40,8 @@ void get_vmalloc_info(struct vmalloc_inf | |
6024 | ||
6025 | prev_end = VMALLOC_START; | |
6026 | ||
6027 | - read_lock(&vmlist_lock); | |
6028 | + if (get_lock) | |
6029 | + read_lock(&vmlist_lock); | |
6030 | ||
6031 | for (vma = vmlist; vma; vma = vma->next) { | |
6032 | unsigned long addr = (unsigned long) vma->addr; | |
6033 | @@ -55,6 +66,7 @@ void get_vmalloc_info(struct vmalloc_inf | |
6034 | if (VMALLOC_END - prev_end > vmi->largest_chunk) | |
6035 | vmi->largest_chunk = VMALLOC_END - prev_end; | |
6036 | ||
6037 | - read_unlock(&vmlist_lock); | |
6038 | + if (get_lock) | |
6039 | + read_unlock(&vmlist_lock); | |
6040 | } | |
6041 | } | |
6042 | --- a/fs/proc/proc_misc.c | |
6043 | +++ b/fs/proc/proc_misc.c | |
6044 | @@ -239,6 +239,120 @@ static int meminfo_read_proc(char *page, | |
6045 | #undef K | |
6046 | } | |
6047 | ||
6048 | +#ifdef CONFIG_KDB | |
6049 | +#include <linux/kdb.h> | |
6050 | +#include <linux/kdbprivate.h> | |
6051 | +/* Like meminfo_read_proc() but without the locks and using kdb_printf() */ | |
6052 | +void | |
6053 | +kdb_meminfo_read_proc(void) | |
6054 | +{ | |
6055 | + struct sysinfo i; | |
6056 | + unsigned long committed; | |
6057 | + unsigned long allowed; | |
6058 | + struct vmalloc_info vmi; | |
6059 | + long cached; | |
6060 | + | |
6061 | +/* | |
6062 | + * display in kilobytes. | |
6063 | + */ | |
6064 | +#define K(x) ((x) << (PAGE_SHIFT - 10)) | |
6065 | + si_meminfo(&i); | |
6066 | + kdb_si_swapinfo(&i); | |
6067 | + committed = atomic_read(&vm_committed_space); | |
6068 | + allowed = ((totalram_pages - hugetlb_total_pages()) | |
6069 | + * sysctl_overcommit_ratio / 100) + total_swap_pages; | |
6070 | + | |
6071 | + cached = global_page_state(NR_FILE_PAGES) - | |
6072 | + total_swapcache_pages - i.bufferram; | |
6073 | + if (cached < 0) | |
6074 | + cached = 0; | |
6075 | + | |
6076 | + get_vmalloc_info(&vmi); | |
6077 | + | |
6078 | + kdb_printf( | |
6079 | + "MemTotal: %8lu kB\n" | |
6080 | + "MemFree: %8lu kB\n" | |
6081 | + "Buffers: %8lu kB\n", | |
6082 | + K(i.totalram), | |
6083 | + K(i.freeram), | |
6084 | + K(i.bufferram) | |
6085 | + ); | |
6086 | + kdb_printf( | |
6087 | + "Cached: %8lu kB\n" | |
6088 | + "SwapCached: %8lu kB\n" | |
6089 | + "Active: %8lu kB\n" | |
6090 | + "Inactive: %8lu kB\n", | |
6091 | + K(cached), | |
6092 | + K(total_swapcache_pages), | |
6093 | + K(global_page_state(NR_ACTIVE)), | |
6094 | + K(global_page_state(NR_INACTIVE)) | |
6095 | + ); | |
6096 | +#ifdef CONFIG_HIGHMEM | |
6097 | + kdb_printf( | |
6098 | + "HighTotal: %8lu kB\n" | |
6099 | + "HighFree: %8lu kB\n" | |
6100 | + "LowTotal: %8lu kB\n" | |
6101 | + "LowFree: %8lu kB\n", | |
6102 | + K(i.totalhigh), | |
6103 | + K(i.freehigh), | |
6104 | + K(i.totalram-i.totalhigh), | |
6105 | + K(i.freeram-i.freehigh) | |
6106 | + ); | |
6107 | +#endif | |
6108 | + kdb_printf( | |
6109 | + "SwapTotal: %8lu kB\n" | |
6110 | + "SwapFree: %8lu kB\n" | |
6111 | + "Dirty: %8lu kB\n", | |
6112 | + K(i.totalswap), | |
6113 | + K(i.freeswap), | |
6114 | + K(global_page_state(NR_FILE_DIRTY)) | |
6115 | + ); | |
6116 | + kdb_printf( | |
6117 | + "Writeback: %8lu kB\n" | |
6118 | + "AnonPages: %8lu kB\n" | |
6119 | + "Mapped: %8lu kB\n", | |
6120 | + K(global_page_state(NR_WRITEBACK)), | |
6121 | + K(global_page_state(NR_ANON_PAGES)), | |
6122 | + K(global_page_state(NR_FILE_MAPPED)) | |
6123 | + ); | |
6124 | + kdb_printf( | |
6125 | + "Slab: %8lu kB\n" | |
6126 | + "SReclaimable: %8lu kB\n" | |
6127 | + "SUnreclaim: %8lu kB\n", | |
6128 | + K(global_page_state(NR_SLAB_RECLAIMABLE) + | |
6129 | + global_page_state(NR_SLAB_UNRECLAIMABLE)), | |
6130 | + K(global_page_state(NR_SLAB_RECLAIMABLE)), | |
6131 | + K(global_page_state(NR_SLAB_UNRECLAIMABLE)) | |
6132 | + ); | |
6133 | + kdb_printf( | |
6134 | + "PageTables: %8lu kB\n" | |
6135 | + "NFS_Unstable: %8lu kB\n" | |
6136 | + "Bounce: %8lu kB\n", | |
6137 | + K(global_page_state(NR_PAGETABLE)), | |
6138 | + K(global_page_state(NR_UNSTABLE_NFS)), | |
6139 | + K(global_page_state(NR_BOUNCE)) | |
6140 | + ); | |
6141 | + kdb_printf( | |
6142 | + "CommitLimit: %8lu kB\n" | |
6143 | + "Committed_AS: %8lu kB\n" | |
6144 | + "VmallocTotal: %8lu kB\n", | |
6145 | + K(allowed), | |
6146 | + K(committed), | |
6147 | + (unsigned long)VMALLOC_TOTAL >> 10 | |
6148 | + ); | |
6149 | + kdb_printf( | |
6150 | + "VmallocUsed: %8lu kB\n" | |
6151 | + "VmallocChunk: %8lu kB\n", | |
6152 | + vmi.used >> 10, | |
6153 | + vmi.largest_chunk >> 10 | |
6154 | + ); | |
6155 | + | |
6156 | +#ifdef CONFIG_HUGETLBFS | |
6157 | + kdb_hugetlb_report_meminfo(); | |
6158 | +#endif | |
6159 | +} | |
6160 | +#endif /* CONFIG_KDB */ | |
6161 | + | |
6162 | static int fragmentation_open(struct inode *inode, struct file *file) | |
6163 | { | |
6164 | (void)inode; | |
6165 | --- a/include/linux/console.h | |
6166 | +++ b/include/linux/console.h | |
6167 | @@ -142,7 +142,12 @@ void vcs_remove_sysfs(struct tty_struct | |
6168 | ||
6169 | /* Some debug stub to catch some of the obvious races in the VT code */ | |
6170 | #if 1 | |
6171 | +#ifdef CONFIG_KDB | |
6172 | +#include <linux/kdb.h> | |
6173 | +#define WARN_CONSOLE_UNLOCKED() WARN_ON(!is_console_locked() && !oops_in_progress && !atomic_read(&kdb_event)) | |
6174 | +#else /* !CONFIG_KDB */ | |
6175 | #define WARN_CONSOLE_UNLOCKED() WARN_ON(!is_console_locked() && !oops_in_progress) | |
6176 | +#endif /* CONFIG_KDB */ | |
6177 | #else | |
6178 | #define WARN_CONSOLE_UNLOCKED() | |
6179 | #endif | |
6180 | --- /dev/null | |
6181 | +++ b/include/linux/dis-asm.h | |
6182 | @@ -0,0 +1,347 @@ | |
6183 | +/* Interface between the opcode library and its callers. | |
6184 | + | |
6185 | + Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 | |
6186 | + Free Software Foundation, Inc. | |
6187 | + | |
6188 | + This program is free software; you can redistribute it and/or modify | |
6189 | + it under the terms of the GNU General Public License as published by | |
6190 | + the Free Software Foundation; either version 2, or (at your option) | |
6191 | + any later version. | |
6192 | + | |
6193 | + This program is distributed in the hope that it will be useful, | |
6194 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6195 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6196 | + GNU General Public License for more details. | |
6197 | + | |
6198 | + You should have received a copy of the GNU General Public License | |
6199 | + along with this program; if not, write to the Free Software | |
6200 | + Foundation, Inc., 51 Franklin Street - Fifth Floor, | |
6201 | + Boston, MA 02110-1301, USA. | |
6202 | + | |
6203 | + Written by Cygnus Support, 1993. | |
6204 | + | |
6205 | + The opcode library (libopcodes.a) provides instruction decoders for | |
6206 | + a large variety of instruction sets, callable with an identical | |
6207 | + interface, for making instruction-processing programs more independent | |
6208 | + of the instruction set being processed. */ | |
6209 | + | |
6210 | +/* Extracted from binutils 2.16.91.0.2 (OpenSUSE 10.0) and modified for kdb use. | |
6211 | + * Any trailing whitespace was removed and #ifdef/ifndef __KERNEL__ added as | |
6212 | + * required. | |
6213 | + * Keith Owens <kaos@sgi.com> 15 May 2006 | |
6214 | + */ | |
6215 | + | |
6216 | +#ifndef DIS_ASM_H | |
6217 | +#define DIS_ASM_H | |
6218 | + | |
6219 | +#ifdef __cplusplus | |
6220 | +extern "C" { | |
6221 | +#endif | |
6222 | + | |
6223 | +#ifdef __KERNEL__ | |
6224 | +#include <asm/ansidecl.h> | |
6225 | +#include <asm/bfd.h> | |
6226 | +typedef void FILE; | |
6227 | +#else /* __KERNEL__ */ | |
6228 | +#include <stdio.h> | |
6229 | +#include "bfd.h" | |
6230 | +#endif /* __KERNEL__ */ | |
6231 | + | |
6232 | +typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2; | |
6233 | + | |
6234 | +enum dis_insn_type { | |
6235 | + dis_noninsn, /* Not a valid instruction */ | |
6236 | + dis_nonbranch, /* Not a branch instruction */ | |
6237 | + dis_branch, /* Unconditional branch */ | |
6238 | + dis_condbranch, /* Conditional branch */ | |
6239 | + dis_jsr, /* Jump to subroutine */ | |
6240 | + dis_condjsr, /* Conditional jump to subroutine */ | |
6241 | + dis_dref, /* Data reference instruction */ | |
6242 | + dis_dref2 /* Two data references in instruction */ | |
6243 | +}; | |
6244 | + | |
6245 | +/* This struct is passed into the instruction decoding routine, | |
6246 | + and is passed back out into each callback. The various fields are used | |
6247 | + for conveying information from your main routine into your callbacks, | |
6248 | + for passing information into the instruction decoders (such as the | |
6249 | + addresses of the callback functions), or for passing information | |
6250 | + back from the instruction decoders to their callers. | |
6251 | + | |
6252 | + It must be initialized before it is first passed; this can be done | |
6253 | + by hand, or using one of the initialization macros below. */ | |
6254 | + | |
6255 | +typedef struct disassemble_info { | |
6256 | + fprintf_ftype fprintf_func; | |
6257 | + void *stream; | |
6258 | + void *application_data; | |
6259 | + | |
6260 | + /* Target description. We could replace this with a pointer to the bfd, | |
6261 | + but that would require one. There currently isn't any such requirement | |
6262 | + so to avoid introducing one we record these explicitly. */ | |
6263 | + /* The bfd_flavour. This can be bfd_target_unknown_flavour. */ | |
6264 | + enum bfd_flavour flavour; | |
6265 | + /* The bfd_arch value. */ | |
6266 | + enum bfd_architecture arch; | |
6267 | + /* The bfd_mach value. */ | |
6268 | + unsigned long mach; | |
6269 | + /* Endianness (for bi-endian cpus). Mono-endian cpus can ignore this. */ | |
6270 | + enum bfd_endian endian; | |
6271 | + /* An arch/mach-specific bitmask of selected instruction subsets, mainly | |
6272 | + for processors with run-time-switchable instruction sets. The default, | |
6273 | + zero, means that there is no constraint. CGEN-based opcodes ports | |
6274 | + may use ISA_foo masks. */ | |
6275 | + unsigned long insn_sets; | |
6276 | + | |
6277 | + /* Some targets need information about the current section to accurately | |
6278 | + display insns. If this is NULL, the target disassembler function | |
6279 | + will have to make its best guess. */ | |
6280 | + asection *section; | |
6281 | + | |
6282 | + /* An array of pointers to symbols either at the location being disassembled | |
6283 | + or at the start of the function being disassembled. The array is sorted | |
6284 | + so that the first symbol is intended to be the one used. The others are | |
6285 | + present for any misc. purposes. This is not set reliably, but if it is | |
6286 | + not NULL, it is correct. */ | |
6287 | + asymbol **symbols; | |
6288 | + /* Number of symbols in array. */ | |
6289 | + int num_symbols; | |
6290 | + | |
6291 | + /* For use by the disassembler. | |
6292 | + The top 16 bits are reserved for public use (and are documented here). | |
6293 | + The bottom 16 bits are for the internal use of the disassembler. */ | |
6294 | + unsigned long flags; | |
6295 | +#define INSN_HAS_RELOC 0x80000000 | |
6296 | + void *private_data; | |
6297 | + | |
6298 | + /* Function used to get bytes to disassemble. MEMADDR is the | |
6299 | + address of the stuff to be disassembled, MYADDR is the address to | |
6300 | + put the bytes in, and LENGTH is the number of bytes to read. | |
6301 | + INFO is a pointer to this struct. | |
6302 | + Returns an errno value or 0 for success. */ | |
6303 | + int (*read_memory_func) | |
6304 | + (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, | |
6305 | + struct disassemble_info *info); | |
6306 | + | |
6307 | + /* Function which should be called if we get an error that we can't | |
6308 | + recover from. STATUS is the errno value from read_memory_func and | |
6309 | + MEMADDR is the address that we were trying to read. INFO is a | |
6310 | + pointer to this struct. */ | |
6311 | + void (*memory_error_func) | |
6312 | + (int status, bfd_vma memaddr, struct disassemble_info *info); | |
6313 | + | |
6314 | + /* Function called to print ADDR. */ | |
6315 | + void (*print_address_func) | |
6316 | + (bfd_vma addr, struct disassemble_info *info); | |
6317 | + | |
6318 | + /* Function called to determine if there is a symbol at the given ADDR. | |
6319 | + If there is, the function returns 1, otherwise it returns 0. | |
6320 | + This is used by ports which support an overlay manager where | |
6321 | + the overlay number is held in the top part of an address. In | |
6322 | + some circumstances we want to include the overlay number in the | |
6323 | + address, (normally because there is a symbol associated with | |
6324 | + that address), but sometimes we want to mask out the overlay bits. */ | |
6325 | + int (* symbol_at_address_func) | |
6326 | + (bfd_vma addr, struct disassemble_info * info); | |
6327 | + | |
6328 | + /* Function called to check if a SYMBOL is can be displayed to the user. | |
6329 | + This is used by some ports that want to hide special symbols when | |
6330 | + displaying debugging outout. */ | |
6331 | + bfd_boolean (* symbol_is_valid) | |
6332 | + (asymbol *, struct disassemble_info * info); | |
6333 | + | |
6334 | + /* These are for buffer_read_memory. */ | |
6335 | + bfd_byte *buffer; | |
6336 | + bfd_vma buffer_vma; | |
6337 | + unsigned int buffer_length; | |
6338 | + | |
6339 | + /* This variable may be set by the instruction decoder. It suggests | |
6340 | + the number of bytes objdump should display on a single line. If | |
6341 | + the instruction decoder sets this, it should always set it to | |
6342 | + the same value in order to get reasonable looking output. */ | |
6343 | + int bytes_per_line; | |
6344 | + | |
6345 | + /* The next two variables control the way objdump displays the raw data. */ | |
6346 | + /* For example, if bytes_per_line is 8 and bytes_per_chunk is 4, the */ | |
6347 | + /* output will look like this: | |
6348 | + 00: 00000000 00000000 | |
6349 | + with the chunks displayed according to "display_endian". */ | |
6350 | + int bytes_per_chunk; | |
6351 | + enum bfd_endian display_endian; | |
6352 | + | |
6353 | + /* Number of octets per incremented target address | |
6354 | + Normally one, but some DSPs have byte sizes of 16 or 32 bits. */ | |
6355 | + unsigned int octets_per_byte; | |
6356 | + | |
6357 | + /* The number of zeroes we want to see at the end of a section before we | |
6358 | + start skipping them. */ | |
6359 | + unsigned int skip_zeroes; | |
6360 | + | |
6361 | + /* The number of zeroes to skip at the end of a section. If the number | |
6362 | + of zeroes at the end is between SKIP_ZEROES_AT_END and SKIP_ZEROES, | |
6363 | + they will be disassembled. If there are fewer than | |
6364 | + SKIP_ZEROES_AT_END, they will be skipped. This is a heuristic | |
6365 | + attempt to avoid disassembling zeroes inserted by section | |
6366 | + alignment. */ | |
6367 | + unsigned int skip_zeroes_at_end; | |
6368 | + | |
6369 | + /* Results from instruction decoders. Not all decoders yet support | |
6370 | + this information. This info is set each time an instruction is | |
6371 | + decoded, and is only valid for the last such instruction. | |
6372 | + | |
6373 | + To determine whether this decoder supports this information, set | |
6374 | + insn_info_valid to 0, decode an instruction, then check it. */ | |
6375 | + | |
6376 | + char insn_info_valid; /* Branch info has been set. */ | |
6377 | + char branch_delay_insns; /* How many sequential insn's will run before | |
6378 | + a branch takes effect. (0 = normal) */ | |
6379 | + char data_size; /* Size of data reference in insn, in bytes */ | |
6380 | + enum dis_insn_type insn_type; /* Type of instruction */ | |
6381 | + bfd_vma target; /* Target address of branch or dref, if known; | |
6382 | + zero if unknown. */ | |
6383 | + bfd_vma target2; /* Second target address for dref2 */ | |
6384 | + | |
6385 | + /* Command line options specific to the target disassembler. */ | |
6386 | + char * disassembler_options; | |
6387 | + | |
6388 | +} disassemble_info; | |
6389 | + | |
6390 | +\f | |
6391 | +/* Standard disassemblers. Disassemble one instruction at the given | |
6392 | + target address. Return number of octets processed. */ | |
6393 | +typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *); | |
6394 | + | |
6395 | +extern int print_insn_big_mips (bfd_vma, disassemble_info *); | |
6396 | +extern int print_insn_little_mips (bfd_vma, disassemble_info *); | |
6397 | +extern int print_insn_i386 (bfd_vma, disassemble_info *); | |
6398 | +extern int print_insn_i386_att (bfd_vma, disassemble_info *); | |
6399 | +extern int print_insn_i386_intel (bfd_vma, disassemble_info *); | |
6400 | +extern int print_insn_ia64 (bfd_vma, disassemble_info *); | |
6401 | +extern int print_insn_i370 (bfd_vma, disassemble_info *); | |
6402 | +extern int print_insn_m68hc11 (bfd_vma, disassemble_info *); | |
6403 | +extern int print_insn_m68hc12 (bfd_vma, disassemble_info *); | |
6404 | +extern int print_insn_m68k (bfd_vma, disassemble_info *); | |
6405 | +extern int print_insn_z8001 (bfd_vma, disassemble_info *); | |
6406 | +extern int print_insn_z8002 (bfd_vma, disassemble_info *); | |
6407 | +extern int print_insn_h8300 (bfd_vma, disassemble_info *); | |
6408 | +extern int print_insn_h8300h (bfd_vma, disassemble_info *); | |
6409 | +extern int print_insn_h8300s (bfd_vma, disassemble_info *); | |
6410 | +extern int print_insn_h8500 (bfd_vma, disassemble_info *); | |
6411 | +extern int print_insn_alpha (bfd_vma, disassemble_info *); | |
6412 | +extern int print_insn_big_arm (bfd_vma, disassemble_info *); | |
6413 | +extern int print_insn_little_arm (bfd_vma, disassemble_info *); | |
6414 | +extern int print_insn_sparc (bfd_vma, disassemble_info *); | |
6415 | +extern int print_insn_big_a29k (bfd_vma, disassemble_info *); | |
6416 | +extern int print_insn_little_a29k (bfd_vma, disassemble_info *); | |
6417 | +extern int print_insn_avr (bfd_vma, disassemble_info *); | |
6418 | +extern int print_insn_d10v (bfd_vma, disassemble_info *); | |
6419 | +extern int print_insn_d30v (bfd_vma, disassemble_info *); | |
6420 | +extern int print_insn_dlx (bfd_vma, disassemble_info *); | |
6421 | +extern int print_insn_fr30 (bfd_vma, disassemble_info *); | |
6422 | +extern int print_insn_hppa (bfd_vma, disassemble_info *); | |
6423 | +extern int print_insn_i860 (bfd_vma, disassemble_info *); | |
6424 | +extern int print_insn_i960 (bfd_vma, disassemble_info *); | |
6425 | +extern int print_insn_ip2k (bfd_vma, disassemble_info *); | |
6426 | +extern int print_insn_m32r (bfd_vma, disassemble_info *); | |
6427 | +extern int print_insn_m88k (bfd_vma, disassemble_info *); | |
6428 | +extern int print_insn_maxq_little (bfd_vma, disassemble_info *); | |
6429 | +extern int print_insn_maxq_big (bfd_vma, disassemble_info *); | |
6430 | +extern int print_insn_mcore (bfd_vma, disassemble_info *); | |
6431 | +extern int print_insn_mmix (bfd_vma, disassemble_info *); | |
6432 | +extern int print_insn_mn10200 (bfd_vma, disassemble_info *); | |
6433 | +extern int print_insn_mn10300 (bfd_vma, disassemble_info *); | |
6434 | +extern int print_insn_ms1 (bfd_vma, disassemble_info *); | |
6435 | +extern int print_insn_msp430 (bfd_vma, disassemble_info *); | |
6436 | +extern int print_insn_ns32k (bfd_vma, disassemble_info *); | |
6437 | +extern int print_insn_crx (bfd_vma, disassemble_info *); | |
6438 | +extern int print_insn_openrisc (bfd_vma, disassemble_info *); | |
6439 | +extern int print_insn_big_or32 (bfd_vma, disassemble_info *); | |
6440 | +extern int print_insn_little_or32 (bfd_vma, disassemble_info *); | |
6441 | +extern int print_insn_pdp11 (bfd_vma, disassemble_info *); | |
6442 | +extern int print_insn_pj (bfd_vma, disassemble_info *); | |
6443 | +extern int print_insn_big_powerpc (bfd_vma, disassemble_info *); | |
6444 | +extern int print_insn_little_powerpc (bfd_vma, disassemble_info *); | |
6445 | +extern int print_insn_rs6000 (bfd_vma, disassemble_info *); | |
6446 | +extern int print_insn_s390 (bfd_vma, disassemble_info *); | |
6447 | +extern int print_insn_sh (bfd_vma, disassemble_info *); | |
6448 | +extern int print_insn_tic30 (bfd_vma, disassemble_info *); | |
6449 | +extern int print_insn_tic4x (bfd_vma, disassemble_info *); | |
6450 | +extern int print_insn_tic54x (bfd_vma, disassemble_info *); | |
6451 | +extern int print_insn_tic80 (bfd_vma, disassemble_info *); | |
6452 | +extern int print_insn_v850 (bfd_vma, disassemble_info *); | |
6453 | +extern int print_insn_vax (bfd_vma, disassemble_info *); | |
6454 | +extern int print_insn_w65 (bfd_vma, disassemble_info *); | |
6455 | +extern int print_insn_xstormy16 (bfd_vma, disassemble_info *); | |
6456 | +extern int print_insn_xtensa (bfd_vma, disassemble_info *); | |
6457 | +extern int print_insn_sh64 (bfd_vma, disassemble_info *); | |
6458 | +extern int print_insn_sh64x_media (bfd_vma, disassemble_info *); | |
6459 | +extern int print_insn_frv (bfd_vma, disassemble_info *); | |
6460 | +extern int print_insn_iq2000 (bfd_vma, disassemble_info *); | |
6461 | +extern int print_insn_m32c (bfd_vma, disassemble_info *); | |
6462 | + | |
6463 | +extern disassembler_ftype arc_get_disassembler (void *); | |
6464 | +extern disassembler_ftype cris_get_disassembler (bfd *); | |
6465 | + | |
6466 | +extern void print_mips_disassembler_options (FILE *); | |
6467 | +extern void print_ppc_disassembler_options (FILE *); | |
6468 | +extern void print_arm_disassembler_options (FILE *); | |
6469 | +extern void parse_arm_disassembler_option (char *); | |
6470 | +extern int get_arm_regname_num_options (void); | |
6471 | +extern int set_arm_regname_option (int); | |
6472 | +extern int get_arm_regnames (int, const char **, const char **, const char *const **); | |
6473 | +extern bfd_boolean arm_symbol_is_valid (asymbol *, struct disassemble_info *); | |
6474 | + | |
6475 | +/* Fetch the disassembler for a given BFD, if that support is available. */ | |
6476 | +extern disassembler_ftype disassembler (bfd *); | |
6477 | + | |
6478 | +/* Amend the disassemble_info structure as necessary for the target architecture. | |
6479 | + Should only be called after initialising the info->arch field. */ | |
6480 | +extern void disassemble_init_for_target (struct disassemble_info * info); | |
6481 | + | |
6482 | +/* Document any target specific options available from the disassembler. */ | |
6483 | +extern void disassembler_usage (FILE *); | |
6484 | + | |
6485 | +\f | |
6486 | +/* This block of definitions is for particular callers who read instructions | |
6487 | + into a buffer before calling the instruction decoder. */ | |
6488 | + | |
6489 | +/* Here is a function which callers may wish to use for read_memory_func. | |
6490 | + It gets bytes from a buffer. */ | |
6491 | +extern int buffer_read_memory | |
6492 | + (bfd_vma, bfd_byte *, unsigned int, struct disassemble_info *); | |
6493 | + | |
6494 | +/* This function goes with buffer_read_memory. | |
6495 | + It prints a message using info->fprintf_func and info->stream. */ | |
6496 | +extern void perror_memory (int, bfd_vma, struct disassemble_info *); | |
6497 | + | |
6498 | + | |
6499 | +/* Just print the address in hex. This is included for completeness even | |
6500 | + though both GDB and objdump provide their own (to print symbolic | |
6501 | + addresses). */ | |
6502 | +extern void generic_print_address | |
6503 | + (bfd_vma, struct disassemble_info *); | |
6504 | + | |
6505 | +/* Always true. */ | |
6506 | +extern int generic_symbol_at_address | |
6507 | + (bfd_vma, struct disassemble_info *); | |
6508 | + | |
6509 | +/* Also always true. */ | |
6510 | +extern bfd_boolean generic_symbol_is_valid | |
6511 | + (asymbol *, struct disassemble_info *); | |
6512 | + | |
6513 | +/* Method to initialize a disassemble_info struct. This should be | |
6514 | + called by all applications creating such a struct. */ | |
6515 | +extern void init_disassemble_info (struct disassemble_info *info, void *stream, | |
6516 | + fprintf_ftype fprintf_func); | |
6517 | + | |
6518 | +/* For compatibility with existing code. */ | |
6519 | +#define INIT_DISASSEMBLE_INFO(INFO, STREAM, FPRINTF_FUNC) \ | |
6520 | + init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC)) | |
6521 | +#define INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC) \ | |
6522 | + init_disassemble_info (&(INFO), (STREAM), (fprintf_ftype) (FPRINTF_FUNC)) | |
6523 | + | |
6524 | + | |
6525 | +#ifdef __cplusplus | |
6526 | +} | |
6527 | +#endif | |
6528 | + | |
6529 | +#endif /* ! defined (DIS_ASM_H) */ | |
6530 | --- /dev/null | |
6531 | +++ b/include/linux/kdb.h | |
6532 | @@ -0,0 +1,175 @@ | |
6533 | +#ifndef _KDB_H | |
6534 | +#define _KDB_H | |
6535 | + | |
6536 | +/* | |
6537 | + * Kernel Debugger Architecture Independent Global Headers | |
6538 | + * | |
6539 | + * This file is subject to the terms and conditions of the GNU General Public | |
6540 | + * License. See the file "COPYING" in the main directory of this archive | |
6541 | + * for more details. | |
6542 | + * | |
6543 | + * Copyright (c) 2000-2007 Silicon Graphics, Inc. All Rights Reserved. | |
6544 | + * Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com> | |
6545 | + */ | |
6546 | + | |
6547 | +#include <linux/init.h> | |
6548 | +#include <linux/sched.h> | |
6549 | +#include <asm/atomic.h> | |
6550 | + | |
6551 | +#ifdef CONFIG_KDB | |
6552 | +/* These are really private, but they must be defined before including | |
6553 | + * asm-$(ARCH)/kdb.h, so make them public and put them here. | |
6554 | + */ | |
6555 | +extern int kdb_getuserarea_size(void *, unsigned long, size_t); | |
6556 | +extern int kdb_putuserarea_size(unsigned long, void *, size_t); | |
6557 | + | |
6558 | +#include <asm/kdb.h> | |
6559 | +#endif | |
6560 | + | |
6561 | +#define KDB_MAJOR_VERSION 4 | |
6562 | +#define KDB_MINOR_VERSION 4 | |
6563 | +#define KDB_TEST_VERSION "" | |
6564 | + | |
6565 | +/* | |
6566 | + * kdb_initial_cpu is initialized to -1, and is set to the cpu | |
6567 | + * number whenever the kernel debugger is entered. | |
6568 | + */ | |
6569 | +extern volatile int kdb_initial_cpu; | |
6570 | +extern atomic_t kdb_event; | |
6571 | +extern atomic_t kdb_8250; | |
6572 | +#ifdef CONFIG_KDB | |
6573 | +#define KDB_IS_RUNNING() (kdb_initial_cpu != -1) | |
6574 | +#define KDB_8250() (atomic_read(&kdb_8250) != 0) | |
6575 | +#else | |
6576 | +#define KDB_IS_RUNNING() (0) | |
6577 | +#define KDB_8250() (0) | |
6578 | +#endif /* CONFIG_KDB */ | |
6579 | + | |
6580 | +/* | |
6581 | + * kdb_on | |
6582 | + * | |
6583 | + * Defines whether kdb is on or not. Default value | |
6584 | + * is set by CONFIG_KDB_OFF. Boot with kdb=on/off/on-nokey | |
6585 | + * or echo "[012]" > /proc/sys/kernel/kdb to change it. | |
6586 | + */ | |
6587 | +extern int kdb_on; | |
6588 | + | |
6589 | +#if defined(CONFIG_SERIAL_8250_CONSOLE) || defined(CONFIG_SERIAL_SGI_L1_CONSOLE) | |
6590 | +/* | |
6591 | + * kdb_serial.iobase is initialized to zero, and is set to the I/O | |
6592 | + * address of the serial port when the console is setup in | |
6593 | + * serial_console_setup. | |
6594 | + */ | |
6595 | +extern struct kdb_serial { | |
6596 | + int io_type; | |
6597 | + unsigned long iobase; | |
6598 | + unsigned long ioreg_shift; | |
6599 | +} kdb_serial; | |
6600 | +#endif | |
6601 | + | |
6602 | +/* | |
6603 | + * kdb_diemsg | |
6604 | + * | |
6605 | + * Contains a pointer to the last string supplied to the | |
6606 | + * kernel 'die' panic function. | |
6607 | + */ | |
6608 | +extern const char *kdb_diemsg; | |
6609 | + | |
6610 | +#define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */ | |
6611 | +#define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */ | |
6612 | +#define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */ | |
6613 | +#define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */ | |
6614 | +#define KDB_FLAG_ONLY_DO_DUMP (1 << 4) /* Only do a dump, used when kdb is off */ | |
6615 | +#define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available, kdb is disabled */ | |
6616 | +#define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do not use keyboard */ | |
6617 | +#define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do not use keyboard */ | |
6618 | +#define KDB_FLAG_RECOVERY (1 << 8) /* kdb is being entered for an error which has been recovered */ | |
6619 | + | |
6620 | +extern volatile int kdb_flags; /* Global flags, see kdb_state for per cpu state */ | |
6621 | + | |
6622 | +extern void kdb_save_flags(void); | |
6623 | +extern void kdb_restore_flags(void); | |
6624 | + | |
6625 | +#define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag) | |
6626 | +#define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag)) | |
6627 | +#define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag)) | |
6628 | + | |
6629 | +/* | |
6630 | + * External entry point for the kernel debugger. The pt_regs | |
6631 | + * at the time of entry are supplied along with the reason for | |
6632 | + * entry to the kernel debugger. | |
6633 | + */ | |
6634 | + | |
6635 | +typedef enum { | |
6636 | + KDB_REASON_ENTER=1, /* KDB_ENTER() trap/fault - regs valid */ | |
6637 | + KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */ | |
6638 | + KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */ | |
6639 | + KDB_REASON_DEBUG, /* Debug Fault - regs valid */ | |
6640 | + KDB_REASON_OOPS, /* Kernel Oops - regs valid */ | |
6641 | + KDB_REASON_SWITCH, /* CPU switch - regs valid*/ | |
6642 | + KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */ | |
6643 | + KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */ | |
6644 | + KDB_REASON_RECURSE, /* Recursive entry to kdb; regs probably valid */ | |
6645 | + KDB_REASON_CPU_UP, /* Add one cpu to kdb; regs invalid */ | |
6646 | + KDB_REASON_SILENT, /* Silent entry/exit to kdb; regs invalid - internal only */ | |
6647 | +} kdb_reason_t; | |
6648 | + | |
6649 | +#ifdef CONFIG_KDB | |
6650 | +extern int kdb(kdb_reason_t, int, struct pt_regs *); | |
6651 | +#else | |
6652 | +#define kdb(reason,error_code,frame) (0) | |
6653 | +#endif | |
6654 | + | |
6655 | +/* Mainly used by kdb code, but this function is sometimes used | |
6656 | + * by hacked debug code so make it generally available, not private. | |
6657 | + */ | |
6658 | +extern void kdb_printf(const char *,...) | |
6659 | + __attribute__ ((format (printf, 1, 2))); | |
6660 | +typedef void (*kdb_printf_t)(const char *, ...) | |
6661 | + __attribute__ ((format (printf, 1, 2))); | |
6662 | +extern void kdb_init(void); | |
6663 | + | |
6664 | +#if defined(CONFIG_SMP) | |
6665 | +/* | |
6666 | + * Kernel debugger non-maskable IPI handler. | |
6667 | + */ | |
6668 | +extern int kdb_ipi(struct pt_regs *, void (*ack_interrupt)(void)); | |
6669 | +extern void smp_kdb_stop(void); | |
6670 | +#else /* CONFIG_SMP */ | |
6671 | +#define smp_kdb_stop() | |
6672 | +#endif /* CONFIG_SMP */ | |
6673 | + | |
6674 | +#ifdef CONFIG_KDB_USB | |
6675 | + | |
6676 | +#include <linux/usb.h> | |
6677 | + | |
6678 | +extern int kdb_usb_keyboard_attach(struct urb *urb, unsigned char *buffer, void *poll_func); | |
6679 | +extern int kdb_usb_keyboard_detach(struct urb *urb); | |
6680 | + | |
6681 | +#endif /* CONFIG_KDB_USB */ | |
6682 | + | |
6683 | +static inline | |
6684 | +int kdb_process_cpu(const struct task_struct *p) | |
6685 | +{ | |
6686 | + unsigned int cpu = task_thread_info(p)->cpu; | |
6687 | + if (cpu > NR_CPUS) | |
6688 | + cpu = 0; | |
6689 | + return cpu; | |
6690 | +} | |
6691 | + | |
6692 | +extern const char kdb_serial_str[]; | |
6693 | + | |
6694 | +#ifdef CONFIG_KDB_KDUMP | |
6695 | +/* Define values for kdb_kdump_state */ | |
6696 | +extern int kdb_kdump_state; /* KDB kdump state */ | |
6697 | +#define KDB_KDUMP_RESET 0 | |
6698 | +#define KDB_KDUMP_KDUMP 1 | |
6699 | + | |
6700 | +void kdba_kdump_prepare(struct pt_regs *); | |
6701 | +void machine_crash_shutdown(struct pt_regs *); | |
6702 | +void machine_crash_shutdown_begin(void); | |
6703 | +void machine_crash_shutdown_end(struct pt_regs *); | |
6704 | + | |
6705 | +#endif /* CONFIG_KDB_KDUMP */ | |
6706 | + | |
6707 | +#endif /* !_KDB_H */ | |
6708 | --- /dev/null | |
6709 | +++ b/include/linux/kdbprivate.h | |
6710 | @@ -0,0 +1,503 @@ | |
6711 | +#ifndef _KDBPRIVATE_H | |
6712 | +#define _KDBPRIVATE_H | |
6713 | + | |
6714 | +/* | |
6715 | + * Kernel Debugger Architecture Independent Private Headers | |
6716 | + * | |
6717 | + * This file is subject to the terms and conditions of the GNU General Public | |
6718 | + * License. See the file "COPYING" in the main directory of this archive | |
6719 | + * for more details. | |
6720 | + * | |
6721 | + * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved. | |
6722 | + */ | |
6723 | + | |
6724 | + | |
6725 | +#include <linux/dis-asm.h> | |
6726 | +#include <asm/kdbprivate.h> | |
6727 | +#include <asm/bfd.h> | |
6728 | + | |
6729 | + /* | |
6730 | + * Kernel Debugger Error codes. Must not overlap with command codes. | |
6731 | + */ | |
6732 | + | |
6733 | +#define KDB_NOTFOUND (-1) | |
6734 | +#define KDB_ARGCOUNT (-2) | |
6735 | +#define KDB_BADWIDTH (-3) | |
6736 | +#define KDB_BADRADIX (-4) | |
6737 | +#define KDB_NOTENV (-5) | |
6738 | +#define KDB_NOENVVALUE (-6) | |
6739 | +#define KDB_NOTIMP (-7) | |
6740 | +#define KDB_ENVFULL (-8) | |
6741 | +#define KDB_ENVBUFFULL (-9 ) | |
6742 | +#define KDB_TOOMANYBPT (-10) | |
6743 | +#define KDB_TOOMANYDBREGS (-11) | |
6744 | +#define KDB_DUPBPT (-12) | |
6745 | +#define KDB_BPTNOTFOUND (-13) | |
6746 | +#define KDB_BADMODE (-14) | |
6747 | +#define KDB_BADINT (-15) | |
6748 | +#define KDB_INVADDRFMT (-16) | |
6749 | +#define KDB_BADREG (-17) | |
6750 | +#define KDB_BADCPUNUM (-18) | |
6751 | +#define KDB_BADLENGTH (-19) | |
6752 | +#define KDB_NOBP (-20) | |
6753 | +#define KDB_BADADDR (-21) | |
6754 | + | |
6755 | + /* | |
6756 | + * Kernel Debugger Command codes. Must not overlap with error codes. | |
6757 | + */ | |
6758 | +#define KDB_CMD_GO (-1001) | |
6759 | +#define KDB_CMD_CPU (-1002) | |
6760 | +#define KDB_CMD_SS (-1003) | |
6761 | +#define KDB_CMD_SSB (-1004) | |
6762 | + | |
6763 | + /* | |
6764 | + * Internal debug flags | |
6765 | + */ | |
6766 | +/* KDB_DEBUG_FLAG_BT 0x0001 Was Stack traceback debug */ | |
6767 | +#define KDB_DEBUG_FLAG_BP 0x0002 /* Breakpoint subsystem debug */ | |
6768 | +#define KDB_DEBUG_FLAG_BB_SUMM 0x0004 /* Basic block analysis, summary only */ | |
6769 | +#define KDB_DEBUG_FLAG_AR 0x0008 /* Activation record, generic */ | |
6770 | +#define KDB_DEBUG_FLAG_ARA 0x0010 /* Activation record, arch specific */ | |
6771 | +#define KDB_DEBUG_FLAG_BB 0x0020 /* All basic block analysis */ | |
6772 | +#define KDB_DEBUG_FLAG_STATE 0x0040 /* State flags */ | |
6773 | +#define KDB_DEBUG_FLAG_MASK 0xffff /* All debug flags */ | |
6774 | +#define KDB_DEBUG_FLAG_SHIFT 16 /* Shift factor for dbflags */ | |
6775 | + | |
6776 | +#define KDB_DEBUG(flag) (kdb_flags & (KDB_DEBUG_FLAG_##flag << KDB_DEBUG_FLAG_SHIFT)) | |
6777 | +#define KDB_DEBUG_STATE(text,value) if (KDB_DEBUG(STATE)) kdb_print_state(text, value) | |
6778 | + | |
6779 | +typedef enum { | |
6780 | + KDB_REPEAT_NONE = 0, /* Do not repeat this command */ | |
6781 | + KDB_REPEAT_NO_ARGS, /* Repeat the command without arguments */ | |
6782 | + KDB_REPEAT_WITH_ARGS, /* Repeat the command including its arguments */ | |
6783 | +} kdb_repeat_t; | |
6784 | + | |
6785 | +typedef int (*kdb_func_t)(int, const char **); | |
6786 | + | |
6787 | + /* | |
6788 | + * Symbol table format returned by kallsyms. | |
6789 | + */ | |
6790 | + | |
6791 | +typedef struct __ksymtab { | |
6792 | + unsigned long value; /* Address of symbol */ | |
6793 | + const char *mod_name; /* Module containing symbol or "kernel" */ | |
6794 | + unsigned long mod_start; | |
6795 | + unsigned long mod_end; | |
6796 | + const char *sec_name; /* Section containing symbol */ | |
6797 | + unsigned long sec_start; | |
6798 | + unsigned long sec_end; | |
6799 | + const char *sym_name; /* Full symbol name, including any version */ | |
6800 | + unsigned long sym_start; | |
6801 | + unsigned long sym_end; | |
6802 | + } kdb_symtab_t; | |
6803 | +extern int kallsyms_symbol_next(char *prefix_name, int flag); | |
6804 | +extern int kallsyms_symbol_complete(char *prefix_name, int max_len); | |
6805 | + | |
6806 | + /* | |
6807 | + * Exported Symbols for kernel loadable modules to use. | |
6808 | + */ | |
6809 | +extern int kdb_register(char *, kdb_func_t, char *, char *, short); | |
6810 | +extern int kdb_register_repeat(char *, kdb_func_t, char *, char *, short, kdb_repeat_t); | |
6811 | +extern int kdb_unregister(char *); | |
6812 | + | |
6813 | +extern int kdb_getarea_size(void *, unsigned long, size_t); | |
6814 | +extern int kdb_putarea_size(unsigned long, void *, size_t); | |
6815 | + | |
6816 | +/* Like get_user and put_user, kdb_getarea and kdb_putarea take variable | |
6817 | + * names, not pointers. The underlying *_size functions take pointers. | |
6818 | + */ | |
6819 | +#define kdb_getarea(x,addr) kdb_getarea_size(&(x), addr, sizeof((x))) | |
6820 | +#define kdb_putarea(addr,x) kdb_putarea_size(addr, &(x), sizeof((x))) | |
6821 | + | |
6822 | +extern int kdb_getphysword(unsigned long *word, | |
6823 | + unsigned long addr, size_t size); | |
6824 | +extern int kdb_getword(unsigned long *, unsigned long, size_t); | |
6825 | +extern int kdb_putword(unsigned long, unsigned long, size_t); | |
6826 | + | |
6827 | +extern int kdbgetularg(const char *, unsigned long *); | |
6828 | +extern char *kdbgetenv(const char *); | |
6829 | +extern int kdbgetintenv(const char *, int *); | |
6830 | +extern int kdbgetaddrarg(int, const char**, int*, unsigned long *, | |
6831 | + long *, char **); | |
6832 | +extern int kdbgetsymval(const char *, kdb_symtab_t *); | |
6833 | +extern int kdbnearsym(unsigned long, kdb_symtab_t *); | |
6834 | +extern void kdbnearsym_cleanup(void); | |
6835 | +extern char *kdb_read(char *buffer, size_t bufsize); | |
6836 | +extern char *kdb_strdup(const char *str, gfp_t type); | |
6837 | +extern void kdb_symbol_print(kdb_machreg_t, const kdb_symtab_t *, unsigned int); | |
6838 | + | |
6839 | + /* | |
6840 | + * Do we have a set of registers? | |
6841 | + */ | |
6842 | + | |
6843 | +#define KDB_NULL_REGS(regs) \ | |
6844 | + (regs == (struct pt_regs *)NULL ? kdb_printf("%s: null regs - should never happen\n", __FUNCTION__), 1 : 0) | |
6845 | + | |
6846 | + /* | |
6847 | + * Routine for debugging the debugger state. | |
6848 | + */ | |
6849 | + | |
6850 | +extern void kdb_print_state(const char *, int); | |
6851 | + | |
6852 | + /* | |
6853 | + * Per cpu kdb state. A cpu can be under kdb control but outside kdb, | |
6854 | + * for example when doing single step. | |
6855 | + */ | |
6856 | +volatile extern int kdb_state[ /*NR_CPUS*/ ]; | |
6857 | +#define KDB_STATE_KDB 0x00000001 /* Cpu is inside kdb */ | |
6858 | +#define KDB_STATE_LEAVING 0x00000002 /* Cpu is leaving kdb */ | |
6859 | +#define KDB_STATE_CMD 0x00000004 /* Running a kdb command */ | |
6860 | +#define KDB_STATE_KDB_CONTROL 0x00000008 /* This cpu is under kdb control */ | |
6861 | +#define KDB_STATE_HOLD_CPU 0x00000010 /* Hold this cpu inside kdb */ | |
6862 | +#define KDB_STATE_DOING_SS 0x00000020 /* Doing ss command */ | |
6863 | +#define KDB_STATE_DOING_SSB 0x00000040 /* Doing ssb command, DOING_SS is also set */ | |
6864 | +#define KDB_STATE_SSBPT 0x00000080 /* Install breakpoint after one ss, independent of DOING_SS */ | |
6865 | +#define KDB_STATE_REENTRY 0x00000100 /* Valid re-entry into kdb */ | |
6866 | +#define KDB_STATE_SUPPRESS 0x00000200 /* Suppress error messages */ | |
6867 | +#define KDB_STATE_LONGJMP 0x00000400 /* longjmp() data is available */ | |
6868 | +#define KDB_STATE_GO_SWITCH 0x00000800 /* go is switching back to initial cpu */ | |
6869 | +#define KDB_STATE_PRINTF_LOCK 0x00001000 /* Holds kdb_printf lock */ | |
6870 | +#define KDB_STATE_WAIT_IPI 0x00002000 /* Waiting for kdb_ipi() NMI */ | |
6871 | +#define KDB_STATE_RECURSE 0x00004000 /* Recursive entry to kdb */ | |
6872 | +#define KDB_STATE_IP_ADJUSTED 0x00008000 /* Restart IP has been adjusted */ | |
6873 | +#define KDB_STATE_GO1 0x00010000 /* go only releases one cpu */ | |
6874 | +#define KDB_STATE_KEYBOARD 0x00020000 /* kdb entered via keyboard on this cpu */ | |
6875 | +#define KDB_STATE_KEXEC 0x00040000 /* kexec issued */ | |
6876 | +#define KDB_STATE_ARCH 0xff000000 /* Reserved for arch specific use */ | |
6877 | + | |
6878 | +#define KDB_STATE_CPU(flag,cpu) (kdb_state[cpu] & KDB_STATE_##flag) | |
6879 | +#define KDB_STATE_SET_CPU(flag,cpu) ((void)(kdb_state[cpu] |= KDB_STATE_##flag)) | |
6880 | +#define KDB_STATE_CLEAR_CPU(flag,cpu) ((void)(kdb_state[cpu] &= ~KDB_STATE_##flag)) | |
6881 | + | |
6882 | +#define KDB_STATE(flag) KDB_STATE_CPU(flag,smp_processor_id()) | |
6883 | +#define KDB_STATE_SET(flag) KDB_STATE_SET_CPU(flag,smp_processor_id()) | |
6884 | +#define KDB_STATE_CLEAR(flag) KDB_STATE_CLEAR_CPU(flag,smp_processor_id()) | |
6885 | + | |
6886 | + /* | |
6887 | + * kdb_nextline | |
6888 | + * | |
6889 | + * Contains the current line number on the screen. Used | |
6890 | + * to handle the built-in pager (LINES env variable) | |
6891 | + */ | |
6892 | +extern volatile int kdb_nextline; | |
6893 | + | |
6894 | + /* | |
6895 | + * Breakpoint state | |
6896 | + * | |
6897 | + * Each active and inactive breakpoint is represented by | |
6898 | + * an instance of the following data structure. | |
6899 | + */ | |
6900 | + | |
6901 | +typedef struct _kdb_bp { | |
6902 | + bfd_vma bp_addr; /* Address breakpoint is present at */ | |
6903 | + kdb_machinst_t bp_inst; /* Replaced instruction */ | |
6904 | + | |
6905 | + unsigned int bp_free:1; /* This entry is available */ | |
6906 | + | |
6907 | + unsigned int bp_enabled:1; /* Breakpoint is active in register */ | |
6908 | + unsigned int bp_global:1; /* Global to all processors */ | |
6909 | + | |
6910 | + unsigned int bp_hardtype:1; /* Uses hardware register */ | |
6911 | + unsigned int bp_forcehw:1; /* Force hardware register */ | |
6912 | + unsigned int bp_installed:1; /* Breakpoint is installed */ | |
6913 | + unsigned int bp_delay:1; /* Do delayed bp handling */ | |
6914 | + unsigned int bp_delayed:1; /* Delayed breakpoint */ | |
6915 | + | |
6916 | + int bp_cpu; /* Cpu # (if bp_global == 0) */ | |
6917 | + kdbhard_bp_t bp_template; /* Hardware breakpoint template */ | |
6918 | + kdbhard_bp_t *bp_hard[NR_CPUS]; /* Hardware breakpoint structure */ | |
6919 | + int bp_adjust; /* Adjustment to PC for real instruction */ | |
6920 | +} kdb_bp_t; | |
6921 | + | |
6922 | + /* | |
6923 | + * Breakpoint handling subsystem global variables | |
6924 | + */ | |
6925 | +extern kdb_bp_t kdb_breakpoints[/* KDB_MAXBPT */]; | |
6926 | + | |
6927 | + /* | |
6928 | + * Breakpoint architecture dependent functions. Must be provided | |
6929 | + * in some form for all architectures. | |
6930 | + */ | |
6931 | +extern void kdba_initbp(void); | |
6932 | +extern void kdba_printbp(kdb_bp_t *); | |
6933 | +extern void kdba_alloc_hwbp(kdb_bp_t *bp, int *diagp); | |
6934 | +extern void kdba_free_hwbp(kdb_bp_t *bp); | |
6935 | +extern int kdba_parsebp(int, const char**, int *, kdb_bp_t*); | |
6936 | +extern char *kdba_bptype(kdbhard_bp_t *); | |
6937 | +extern void kdba_setsinglestep(struct pt_regs *); | |
6938 | +extern void kdba_clearsinglestep(struct pt_regs *); | |
6939 | + | |
6940 | + /* | |
6941 | + * Adjust instruction pointer architecture dependent function. Must be | |
6942 | + * provided in some form for all architectures. | |
6943 | + */ | |
6944 | +extern void kdba_adjust_ip(kdb_reason_t, int, struct pt_regs *); | |
6945 | + | |
6946 | + /* | |
6947 | + * KDB-only global function prototypes. | |
6948 | + */ | |
6949 | +extern void kdb_id1(unsigned long); | |
6950 | +extern void kdb_id_init(void); | |
6951 | + | |
6952 | + /* | |
6953 | + * Initialization functions. | |
6954 | + */ | |
6955 | +extern void kdba_init(void); | |
6956 | +extern void kdb_io_init(void); | |
6957 | + | |
6958 | + /* | |
6959 | + * Architecture specific function to read a string. | |
6960 | + */ | |
6961 | +typedef int (*get_char_func)(void); | |
6962 | +extern get_char_func poll_funcs[]; | |
6963 | + | |
6964 | +#ifndef CONFIG_IA64 | |
6965 | + /* | |
6966 | + * Data for a single activation record on stack. | |
6967 | + */ | |
6968 | + | |
6969 | +struct kdb_stack_info { | |
6970 | + kdb_machreg_t physical_start; | |
6971 | + kdb_machreg_t physical_end; | |
6972 | + kdb_machreg_t logical_start; | |
6973 | + kdb_machreg_t logical_end; | |
6974 | + kdb_machreg_t next; | |
6975 | + const char * id; | |
6976 | +}; | |
6977 | + | |
6978 | +typedef struct { DECLARE_BITMAP(bits, KDBA_MAXARGS); } valid_t; | |
6979 | + | |
6980 | +struct kdb_activation_record { | |
6981 | + struct kdb_stack_info stack; /* information about current stack */ | |
6982 | + int args; /* number of arguments detected */ | |
6983 | + kdb_machreg_t arg[KDBA_MAXARGS]; /* -> arguments */ | |
6984 | + valid_t valid; /* is argument n valid? */ | |
6985 | +}; | |
6986 | +#endif | |
6987 | + | |
6988 | + /* | |
6989 | + * Architecture specific Stack Traceback functions. | |
6990 | + */ | |
6991 | + | |
6992 | +struct task_struct; | |
6993 | + | |
6994 | +extern int kdba_bt_address(kdb_machreg_t, int); | |
6995 | +extern int kdba_bt_process(const struct task_struct *, int); | |
6996 | + | |
6997 | + /* | |
6998 | + * KDB Command Table | |
6999 | + */ | |
7000 | + | |
7001 | +typedef struct _kdbtab { | |
7002 | + char *cmd_name; /* Command name */ | |
7003 | + kdb_func_t cmd_func; /* Function to execute command */ | |
7004 | + char *cmd_usage; /* Usage String for this command */ | |
7005 | + char *cmd_help; /* Help message for this command */ | |
7006 | + short cmd_flags; /* Parsing flags */ | |
7007 | + short cmd_minlen; /* Minimum legal # command chars required */ | |
7008 | + kdb_repeat_t cmd_repeat; /* Does command auto repeat on enter? */ | |
7009 | +} kdbtab_t; | |
7010 | + | |
7011 | + /* | |
7012 | + * External command function declarations | |
7013 | + */ | |
7014 | + | |
7015 | +extern int kdb_id(int, const char **); | |
7016 | +extern int kdb_bt(int, const char **); | |
7017 | + | |
7018 | + /* | |
7019 | + * External utility function declarations | |
7020 | + */ | |
7021 | +extern char* kdb_getstr(char *, size_t, char *); | |
7022 | + | |
7023 | + /* | |
7024 | + * Register contents manipulation | |
7025 | + */ | |
7026 | +extern int kdba_getregcontents(const char *, struct pt_regs *, kdb_machreg_t *); | |
7027 | +extern int kdba_setregcontents(const char *, struct pt_regs *, kdb_machreg_t); | |
7028 | +extern int kdba_dumpregs(struct pt_regs *, const char *, const char *); | |
7029 | +extern int kdba_setpc(struct pt_regs *, kdb_machreg_t); | |
7030 | +extern kdb_machreg_t kdba_getpc(struct pt_regs *); | |
7031 | + | |
7032 | + /* | |
7033 | + * Debug register handling. | |
7034 | + */ | |
7035 | +extern void kdba_installdbreg(kdb_bp_t*); | |
7036 | +extern void kdba_removedbreg(kdb_bp_t*); | |
7037 | + | |
7038 | + /* | |
7039 | + * Breakpoint handling - External interfaces | |
7040 | + */ | |
7041 | +extern void kdb_initbptab(void); | |
7042 | +extern void kdb_bp_install_global(struct pt_regs *); | |
7043 | +extern void kdb_bp_install_local(struct pt_regs *); | |
7044 | +extern void kdb_bp_remove_global(void); | |
7045 | +extern void kdb_bp_remove_local(void); | |
7046 | + | |
7047 | + /* | |
7048 | + * Breakpoint handling - Internal to kdb_bp.c/kdba_bp.c | |
7049 | + */ | |
7050 | +extern int kdba_installbp(struct pt_regs *regs, kdb_bp_t *); | |
7051 | +extern int kdba_removebp(kdb_bp_t *); | |
7052 | + | |
7053 | + | |
7054 | +typedef enum { | |
7055 | + KDB_DB_BPT, /* Breakpoint */ | |
7056 | + KDB_DB_SS, /* Single-step trap */ | |
7057 | + KDB_DB_SSB, /* Single step to branch */ | |
7058 | + KDB_DB_SSBPT, /* Single step over breakpoint */ | |
7059 | + KDB_DB_NOBPT /* Spurious breakpoint */ | |
7060 | +} kdb_dbtrap_t; | |
7061 | + | |
7062 | +extern kdb_dbtrap_t kdba_db_trap(struct pt_regs *, int); /* DEBUG trap/fault handler */ | |
7063 | +extern kdb_dbtrap_t kdba_bp_trap(struct pt_regs *, int); /* Breakpoint trap/fault hdlr */ | |
7064 | + | |
7065 | + /* | |
7066 | + * Interrupt Handling | |
7067 | + */ | |
7068 | +typedef unsigned long kdb_intstate_t; | |
7069 | + | |
7070 | +extern void kdba_disableint(kdb_intstate_t *); | |
7071 | +extern void kdba_restoreint(kdb_intstate_t *); | |
7072 | + | |
7073 | + /* | |
7074 | + * SMP and process stack manipulation routines. | |
7075 | + */ | |
7076 | +extern int kdba_ipi(struct pt_regs *, void (*)(void)); | |
7077 | +extern int kdba_main_loop(kdb_reason_t, kdb_reason_t, int, kdb_dbtrap_t, struct pt_regs *); | |
7078 | +extern int kdb_main_loop(kdb_reason_t, kdb_reason_t, int, kdb_dbtrap_t, struct pt_regs *); | |
7079 | + | |
7080 | + /* | |
7081 | + * General Disassembler interfaces | |
7082 | + */ | |
7083 | +extern int kdb_dis_fprintf(PTR, const char *, ...) __attribute__ ((format (printf, 2, 3))); | |
7084 | +extern int kdb_dis_fprintf_dummy(PTR, const char *, ...) __attribute__ ((format (printf, 2, 3))); | |
7085 | +extern disassemble_info kdb_di; | |
7086 | + | |
7087 | + /* | |
7088 | + * Architecture Dependent Disassembler interfaces | |
7089 | + */ | |
7090 | +extern int kdba_id_printinsn(kdb_machreg_t, disassemble_info *); | |
7091 | +extern int kdba_id_parsemode(const char *, disassemble_info*); | |
7092 | +extern void kdba_id_init(disassemble_info *); | |
7093 | +extern void kdba_check_pc(kdb_machreg_t *); | |
7094 | + | |
7095 | + /* | |
7096 | + * Miscellaneous functions and data areas | |
7097 | + */ | |
7098 | +extern char *kdb_cmds[]; | |
7099 | +extern void kdb_syslog_data(char *syslog_data[]); | |
7100 | +extern unsigned long kdb_task_state_string(const char *); | |
7101 | +extern char kdb_task_state_char (const struct task_struct *); | |
7102 | +extern unsigned long kdb_task_state(const struct task_struct *p, unsigned long mask); | |
7103 | +extern void kdb_ps_suppressed(void); | |
7104 | +extern void kdb_ps1(const struct task_struct *p); | |
7105 | +extern int kdb_parse(const char *cmdstr); | |
7106 | +extern void kdb_print_nameval(const char *name, unsigned long val); | |
7107 | +extern void kdb_send_sig_info(struct task_struct *p, struct siginfo *info, int seqno); | |
7108 | +#ifdef CONFIG_SWAP | |
7109 | +extern void kdb_si_swapinfo(struct sysinfo *); | |
7110 | +#else | |
7111 | +#include <linux/swap.h> | |
7112 | +#define kdb_si_swapinfo(x) si_swapinfo(x) | |
7113 | +#endif | |
7114 | +extern void kdb_meminfo_read_proc(void); | |
7115 | +#ifdef CONFIG_HUGETLB_PAGE | |
7116 | +extern void kdb_hugetlb_report_meminfo(void); | |
7117 | +#endif /* CONFIG_HUGETLB_PAGE */ | |
7118 | +extern const char *kdb_walk_kallsyms(loff_t *pos); | |
7119 | + | |
7120 | + /* | |
7121 | + * Architecture Dependant Local Processor setup & cleanup interfaces | |
7122 | + */ | |
7123 | +extern void kdba_local_arch_setup(void); | |
7124 | +extern void kdba_local_arch_cleanup(void); | |
7125 | + | |
7126 | + /* | |
7127 | + * Defines for kdb_symbol_print. | |
7128 | + */ | |
7129 | +#define KDB_SP_SPACEB 0x0001 /* Space before string */ | |
7130 | +#define KDB_SP_SPACEA 0x0002 /* Space after string */ | |
7131 | +#define KDB_SP_PAREN 0x0004 /* Parenthesis around string */ | |
7132 | +#define KDB_SP_VALUE 0x0008 /* Print the value of the address */ | |
7133 | +#define KDB_SP_SYMSIZE 0x0010 /* Print the size of the symbol */ | |
7134 | +#define KDB_SP_NEWLINE 0x0020 /* Newline after string */ | |
7135 | +#define KDB_SP_DEFAULT (KDB_SP_VALUE|KDB_SP_PAREN) | |
7136 | + | |
7137 | +/* Save data about running processes */ | |
7138 | + | |
7139 | +struct kdb_running_process { | |
7140 | + struct task_struct *p; | |
7141 | + struct pt_regs *regs; | |
7142 | + int seqno; /* kdb sequence number */ | |
7143 | + int irq_depth; /* irq count */ | |
7144 | + struct kdba_running_process arch; /* arch dependent save data */ | |
7145 | +}; | |
7146 | + | |
7147 | +extern struct kdb_running_process kdb_running_process[/* NR_CPUS */]; | |
7148 | + | |
7149 | +extern int kdb_save_running(struct pt_regs *, kdb_reason_t, kdb_reason_t, int, kdb_dbtrap_t); | |
7150 | +extern void kdb_unsave_running(struct pt_regs *); | |
7151 | +extern struct task_struct *kdb_curr_task(int); | |
7152 | + | |
7153 | +/* Incremented each time the main kdb loop is entered on the initial cpu, | |
7154 | + * it gives some indication of how old the saved data is. | |
7155 | + */ | |
7156 | +extern int kdb_seqno; | |
7157 | + | |
7158 | +#define kdb_task_has_cpu(p) (task_curr(p)) | |
7159 | +extern void kdb_runqueue(unsigned long cpu, kdb_printf_t xxx_printf); | |
7160 | + | |
7161 | +/* Simplify coexistence with NPTL */ | |
7162 | +#define kdb_do_each_thread(g, p) do_each_thread(g, p) | |
7163 | +#define kdb_while_each_thread(g, p) while_each_thread(g, p) | |
7164 | + | |
7165 | +#define GFP_KDB (in_interrupt() ? GFP_ATOMIC : GFP_KERNEL) | |
7166 | + | |
7167 | +extern void *debug_kmalloc(size_t size, gfp_t flags); | |
7168 | +extern void debug_kfree(void *); | |
7169 | +extern void debug_kusage(void); | |
7170 | + | |
7171 | +extern void kdba_set_current_task(const struct task_struct *); | |
7172 | +extern const struct task_struct *kdb_current_task; | |
7173 | +extern struct pt_regs *kdb_current_regs; | |
7174 | + | |
7175 | +/* Functions to safely read and write kernel areas. The {to,from}_xxx | |
7176 | + * addresses are not necessarily valid, these functions must check for | |
7177 | + * validity. If the arch already supports get and put routines with suitable | |
7178 | + * validation and/or recovery on invalid addresses then use those routines, | |
7179 | + * otherwise check it yourself. | |
7180 | + */ | |
7181 | + | |
7182 | +extern int kdba_putarea_size(unsigned long to_xxx, void *from, size_t size); | |
7183 | +extern int kdba_getarea_size(void *to, unsigned long from_xxx, size_t size); | |
7184 | +extern int kdba_verify_rw(unsigned long addr, size_t size); | |
7185 | + | |
7186 | +#ifndef KDB_RUNNING_PROCESS_ORIGINAL | |
7187 | +#define KDB_RUNNING_PROCESS_ORIGINAL kdb_running_process | |
7188 | +#endif | |
7189 | + | |
7190 | +extern int kdb_wait_for_cpus_secs; | |
7191 | +extern void kdba_cpu_up(void); | |
7192 | +extern char kdb_prompt_str[]; | |
7193 | + | |
7194 | +#define KDB_WORD_SIZE ((int)sizeof(kdb_machreg_t)) | |
7195 | + | |
7196 | +#ifdef CONFIG_KDB_USB | |
7197 | +#include <linux/usb.h> | |
7198 | + | |
7199 | +struct kdb_usb_kbd_info { | |
7200 | + struct urb *urb; /* pointer to the URB */ | |
7201 | + unsigned char *buffer; /* pointer to the kbd char buffer */ | |
7202 | + int (*poll_func)(struct urb *urb); /* poll function to retrieve chars */ | |
7203 | + int poll_ret; /* return val from poll_func */ | |
7204 | + int caps_lock; /* state of the caps lock for this keyboard */ | |
7205 | +}; | |
7206 | +#endif /* CONFIG_KDB_USB */ | |
7207 | + | |
7208 | +#ifdef CONFIG_KDB_KDUMP | |
7209 | +#define KDUMP_REASON_RESET 0 | |
7210 | +extern void kdba_kdump_shutdown_slave(struct pt_regs *); | |
7211 | +#endif /* CONFIG_KDB_KDUMP */ | |
7212 | + | |
7213 | +#endif /* !_KDBPRIVATE_H */ | |
7214 | --- a/include/linux/reboot.h | |
7215 | +++ b/include/linux/reboot.h | |
7216 | @@ -53,7 +53,14 @@ extern void machine_power_off(void); | |
7217 | ||
7218 | extern void machine_shutdown(void); | |
7219 | struct pt_regs; | |
7220 | +#ifdef CONFIG_KDB_KDUMP | |
7221 | extern void machine_crash_shutdown(struct pt_regs *); | |
7222 | +extern void machine_crash_shutdown_begin(void); | |
7223 | +extern void machine_crash_shutdown_other_cpu(struct pt_regs *); | |
7224 | +extern void machine_crash_shutdown_end(struct pt_regs *); | |
7225 | +#else | |
7226 | +extern void machine_crash_shutdown(struct pt_regs *); | |
7227 | +#endif /* !CONFIG_KDB_KDUMP */ | |
7228 | ||
7229 | /* | |
7230 | * Architecture independent implemenations of sys_reboot commands. | |
7231 | --- a/include/linux/sysctl.h | |
7232 | +++ b/include/linux/sysctl.h | |
7233 | @@ -163,6 +163,7 @@ enum | |
7234 | KERN_MAX_LOCK_DEPTH=74, | |
7235 | KERN_NMI_WATCHDOG=75, /* int: enable/disable nmi watchdog */ | |
7236 | KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */ | |
7237 | + KERN_KDB=77, /* int: kdb on/off */ | |
7238 | }; | |
7239 | ||
7240 | ||
7241 | --- a/init/main.c | |
7242 | +++ b/init/main.c | |
7243 | @@ -71,6 +71,10 @@ | |
7244 | #include <asm/smp.h> | |
7245 | #endif | |
7246 | ||
7247 | +#ifdef CONFIG_KDB | |
7248 | +#include <linux/kdb.h> | |
7249 | +#endif /* CONFIG_KDB */ | |
7250 | + | |
7251 | /* | |
7252 | * This is one of the first .c files built. Error out early if we have compiler | |
7253 | * trouble. | |
7254 | @@ -193,6 +197,26 @@ static const char *panic_later, *panic_p | |
7255 | ||
7256 | extern struct obs_kernel_param __setup_start[], __setup_end[]; | |
7257 | ||
7258 | +#ifdef CONFIG_KDB | |
7259 | +static int __init kdb_setup(char *str) | |
7260 | +{ | |
7261 | + if (strcmp(str, "on") == 0) { | |
7262 | + kdb_on = 1; | |
7263 | + } else if (strcmp(str, "on-nokey") == 0) { | |
7264 | + kdb_on = 2; | |
7265 | + } else if (strcmp(str, "off") == 0) { | |
7266 | + kdb_on = 0; | |
7267 | + } else if (strcmp(str, "early") == 0) { | |
7268 | + kdb_on = 1; | |
7269 | + kdb_flags |= KDB_FLAG_EARLYKDB; | |
7270 | + } else | |
7271 | + printk("kdb flag %s not recognised\n", str); | |
7272 | + return 0; | |
7273 | +} | |
7274 | + | |
7275 | +__setup("kdb=", kdb_setup); | |
7276 | +#endif /* CONFIG_KDB */ | |
7277 | + | |
7278 | static int __init obsolete_checksetup(char *line) | |
7279 | { | |
7280 | struct obs_kernel_param *p; | |
7281 | @@ -659,6 +683,14 @@ asmlinkage void __init start_kernel(void | |
7282 | pgtable_cache_init(); | |
7283 | prio_tree_init(); | |
7284 | anon_vma_init(); | |
7285 | + | |
7286 | +#ifdef CONFIG_KDB | |
7287 | + kdb_init(); | |
7288 | + if (KDB_FLAG(EARLYKDB)) { | |
7289 | + KDB_ENTER(); | |
7290 | + } | |
7291 | +#endif /* CONFIG_KDB */ | |
7292 | + | |
7293 | #ifdef CONFIG_X86 | |
7294 | if (efi_enabled) | |
7295 | efi_enter_virtual_mode(); | |
7296 | --- /dev/null | |
7297 | +++ b/kdb/ChangeLog | |
7298 | @@ -0,0 +1,2012 @@ | |
7299 | +2008-09-30 Jay Lan <jlan@sgi.com> | |
7300 | + | |
7301 | + * kdb-v4.4-2.6.27-rc8-common-1. | |
7302 | + | |
7303 | +2008-09-22 Jay Lan <jlan@sgi.com> | |
7304 | + | |
7305 | + * kdb-v4.4-2.6.27-rc7-common-1. | |
7306 | + | |
7307 | +2008-09-03 Jay Lan <jlan@sgi.com> | |
7308 | + | |
7309 | + * kdb-v4.4-2.6.27-rc5-common-1. | |
7310 | + | |
7311 | +2008-08-19 Jay Lan <jlan@sgi.com> | |
7312 | + | |
7313 | + * kdb-v4.4-2.6.27-rc3-common-1. | |
7314 | + | |
7315 | +2008-08-15 Jay Lan <jlan@sgi.com> | |
7316 | + | |
7317 | + * mm_online_pgdat_export_symbol, Jay Lan <jlan@sgi.com> | |
7318 | + - Fix compilation error by exporting first_online_pgdat & | |
7319 | + next_online_pgdat for 'pgdat' command. | |
7320 | + * kdb-v4.4-2.6.27-rc2-common-2.1. | |
7321 | + | |
7322 | +2008-08-14 Jay Lan <jlan@sgi.com> | |
7323 | + | |
7324 | + * Support 'kdump' command to take a kdump vmcore from KDB, | |
7325 | + Dan Aloni (da-x@monatomic.org), | |
7326 | + Jason Xiao (jidong.xiao@gmail.com), | |
7327 | + Jay Lan (jlan@sgi.com) | |
7328 | + * kdb-v4.4-2.6.27-rc2-common-2. | |
7329 | + | |
7330 | +2008-08-06 Jay Lan <jlan@sgi.com> | |
7331 | + | |
7332 | + * Fix up the NULL pointer deference issue in ohci_kdb_poll_char, | |
7333 | + Jason Xiao <jidong.xiao@gmail.com> | |
7334 | + * kdb-v4.4-2.6.27-rc2-common-1. | |
7335 | + | |
7336 | +2008-07-18 Jay Lan <jlan@sgi.com> | |
7337 | + | |
7338 | + * support Hardware Breakpoint (bph/bpha) commands | |
7339 | + IA64: Greg Banks <gnb@sgi.com> | |
7340 | + X86: Konstantin Baydarov <kbaidarov@ru.mvista.com> | |
7341 | + * kdb-v4.4-2.6.26-common-2. | |
7342 | + | |
7343 | +2008-07-14 Jay Lan <jlan@sgi.com> | |
7344 | + | |
7345 | + * kdb-v4.4-2.6.26-common-1. | |
7346 | + | |
7347 | +2008-07-11 Jay Lan <jlan@sgi.com> | |
7348 | + | |
7349 | + * New commands and some fixups and enhancements, | |
7350 | + Joe Korty <joe.korty@ccur.com> | |
7351 | + John Blackwood <john.blackwood@ccur.com> | |
7352 | + Jim Houston <jim.houston@ccur.com> | |
7353 | + - Use the non-sleeping copy_from_user_atomic. | |
7354 | + - Enhance kdb_cmderror diagnostic output. | |
7355 | + - Expand the KDB 'duplicate command' error message. | |
7356 | + - Touch NMI watchdog in various KDB busy-loops. | |
7357 | + - Support IMB HS20 Blade 8843 platform. | |
7358 | + - Display exactly which cpus needed an NMI to get them into kdb. | |
7359 | + - Better document that kdb's 'ps A' command can be used to show | |
7360 | + _all_ processes and threads | |
7361 | + - Suppress KDB boottime INFO messages if quiet boot. | |
7362 | + - Add a KDB breakpoint to the OOPs path. | |
7363 | + - Add CONFIG_DISCONTIGMEM support to kdbm_memmap. | |
7364 | + - Extend the KDB task command to handle CONFIG_NUMA fields. | |
7365 | + - Extend the KDB vm command to support NUMA stuff. | |
7366 | + - Create the KDB mempolicy command. | |
7367 | + - Create a pgdat command for KDB. | |
7368 | + - Fix a hang on boot on some i386 systems. | |
7369 | + * kdb-v4.4-2.6.26-rc9-common-1. | |
7370 | + | |
7371 | +2008-06-30 Jay Lan <jlan@sgi.com> | |
7372 | + | |
7373 | + * compilation warning cleanup, Cliff Wickman <cpw@sgi.com> | |
7374 | + * kdb-v4.4-2.6.26-rc8-common-1. | |
7375 | + | |
7376 | +2008-06-25 Jay Lan <jlan@sgi.com> | |
7377 | + | |
7378 | + * Added John Blackwood <john.blackwood@ccur.com> to the authors of | |
7379 | + kdb-v4.4-2.6.26-rc4-common-2. | |
7380 | + * kdb-v4.4-2.6.26-rc7-common-1. | |
7381 | + | |
7382 | +2008-06-24 Jay Lan <jlan@sgi.com> | |
7383 | + | |
7384 | + * support lcrash style debug_info file: Cliff Wickman <cpw@sgi.com> | |
7385 | + - It adds to kdb the ability to symbolically dereference structure | |
7386 | + pointers through a lcrash-style debug_info file. | |
7387 | + - Implements "print", "px", and "pd" print commands. | |
7388 | + - Implements "walk" command to follow linked lists. | |
7389 | + - Implements "whatis" to display a structure (with offsets). | |
7390 | + - Implements "sizeof" for types (structures, typedefs, etc.). | |
7391 | + * kdb-v4.4-2.6.26-rc5-common-2. | |
7392 | + | |
7393 | +2008-06-06 Jay Lan <jlan@sgi.com> | |
7394 | + | |
7395 | + * kdb-v4.4-2.6.26-rc5-common-1. | |
7396 | + | |
7397 | +2008-06-05 Jay Lan <jlan@sgi.com> | |
7398 | + | |
7399 | + * fixed 'rq/rqa' command runs off the end of runqueue's rt.active | |
7400 | + priority bitmap array, John Blackwood <john.blackwood@ccur.com> & | |
7401 | + Lachlan McIlroy <lachlan@sgi.com> | |
7402 | + * kdb-v4.4-2.6.26-rc4-common-2. | |
7403 | + | |
7404 | +2008-05-30 Jay Lan <jlan@sgi.com> | |
7405 | + | |
7406 | + * kdb-v4.4-2.6.26-rc4-common-1. | |
7407 | + | |
7408 | +2008-05-20 Jay Lan <jlan@sgi.com> | |
7409 | + | |
7410 | + * kdb-v4.4-2.6.26-rc3-common-1. | |
7411 | + | |
7412 | +2008-05-13 Jay Lan <jlan@sgi.com> | |
7413 | + | |
7414 | + * XPC support is removed from KDB due to XPC changes in 2.6.26-rc1. | |
7415 | + * kdb-v4.4-2.6.26-rc1-common-1. | |
7416 | + | |
7417 | +2008-04-17 Jay Lan <jlan@sgi.com> | |
7418 | + | |
7419 | + * kdb-v4.4-2.6.25-common-1. | |
7420 | + | |
7421 | +2008-03-16 Jay Lan <jlan@sgi.com> | |
7422 | + | |
7423 | + * kdb-v4.4-2.6.25-rc6-common-1. | |
7424 | + | |
7425 | +2008-03-03 Jay Lan <jlan@sgi.com> | |
7426 | + | |
7427 | + * kdb-v4.4-2.6.25-rc3-common-1. | |
7428 | + | |
7429 | +2008-02-26 Jay Lan <jlan@sgi.com> | |
7430 | + | |
7431 | + * remove 'fastcall' from kdb code. | |
7432 | + * kdb-v4.4-2.6.25-rc2-common-1. | |
7433 | + | |
7434 | +2008-02-19 Jay Lan <jlan@sgi.com> | |
7435 | + | |
7436 | + * kdb-v4.4-2.6.25-rc1-common-1. | |
7437 | + | |
7438 | +2008-02-06 Jay Lan <jlan@sgi.com> | |
7439 | + | |
7440 | + * Backed out USB UHCI support since it caused dropped characters and | |
7441 | + broke OHCI. | |
7442 | + * Restored "archkdbcommon" commands for x86. It was lost at the x86 | |
7443 | + merge. | |
7444 | + * Detecting if the HC was "busy", Aaron Young <ayoung@sgi.com> | |
7445 | + * kdb-v4.4-2.6.24-common-2. | |
7446 | + | |
7447 | +2008-01-29 Jay Lan <jlan@sgi.com> | |
7448 | + | |
7449 | + * kdb-v4.4-2.6.24-common-1. | |
7450 | + | |
7451 | +2008-01-22 Jay Lan <jlan@sgi.com> | |
7452 | + | |
7453 | + * USB UHCI kdb support, Konstantin Baydarov <kbaidarov@ru.mvista.com> | |
7454 | + * kdb-v4.4-2.6.24-rc8-common-3. | |
7455 | + | |
7456 | +2008-01-18 Jay Lan <jlan@sgi.com> | |
7457 | + | |
7458 | + * USB EHCI kdb support, Aaron Young <ayoung@sgi.com> | |
7459 | + * kdb-v4.4-2.6.24-rc8-common-2. | |
7460 | + | |
7461 | +2008-01-18 Jay Lan <jlan@sgi.com> | |
7462 | + | |
7463 | + * kdb-v4.4-2.6.24-rc8-common-1. | |
7464 | + | |
7465 | +2008-01-07 Jay Lan <jlan@sgi.com> | |
7466 | + | |
7467 | + * kdb-v4.4-2.6.24-rc7-common-1. | |
7468 | + | |
7469 | +2007-12-21 Jay Lan <jlan@sgi.com> | |
7470 | + | |
7471 | + * Renamed kdb/kdba_bt_x86.c to arch/x86/kdba_bt.c. And thus, the x86 | |
7472 | + backtrace code is now moved into the kdb x86 patch. | |
7473 | + * kdb v4.4-2.6.24-rc6-common-1. | |
7474 | + | |
7475 | +2007-12-12 Jay Lan <jlan@sgi.com> | |
7476 | + | |
7477 | + * kdb v4.4-2.6.24-rc5-common-1. | |
7478 | + | |
7479 | +2007-12-05 Jay Lan <jlan@sgi.com> | |
7480 | + | |
7481 | + * Fixed a 'sysctl table check failed' problem. | |
7482 | + * kdb v4.4-2.6.24-rc4-common-1. | |
7483 | + | |
7484 | +2007-11-26 Jay Lan <jlan@sgi.com> | |
7485 | + | |
7486 | + * kdb v4.4-2.6.24-rc3-common-1. | |
7487 | + | |
7488 | +2007-11-13 Jay Lan <jlan@sgi.com> | |
7489 | + | |
7490 | + * Back ported "New KDB USB interface" from Aaron Young in | |
7491 | + v4.4-2.6.23-common-2 to 2.6.24 kdb patchset. | |
7492 | + * kdb v4.4-2.6.24-rc2-common-2. | |
7493 | + | |
7494 | +2007-11-12 Jay Lan <jlan@sgi.com> | |
7495 | + | |
7496 | + * kdb v4.4-2.6.24-rc2-common-1. | |
7497 | + | |
7498 | +2007-11-09 Jay Lan <jlan@sgi.com> | |
7499 | + | |
7500 | + * Rebase to 2.6.24-rc1 kernel | |
7501 | + * - merged kdb-v4.4-2.6.23-i386-1 and kdb-v4.4-2.6.23-x86_64-1 | |
7502 | + * into kdb-v4.4-2.6.24-rc1-x86-1 | |
7503 | + * - Fields "done", "sglist_len", and "pid" are removed from | |
7504 | + * struct scsi_cmnd. Thus, these fields are no longer displayed | |
7505 | + * on "sc" command. | |
7506 | + * kdb v4.4-2.6.24-rc1-common-1. | |
7507 | + | |
7508 | +2007-11-08 Jay Lan <jlan@sgi.com> | |
7509 | + | |
7510 | + * New KDB USB interface, Aaron Young <ayoung@sgi.com> | |
7511 | + * 1. This patch allows KDB to work with any Host Contoller driver | |
7512 | + * and call the correct HC driver poll routine (as long as the | |
7513 | + * HC driver provides a .kdb_poll_char routine via it's | |
7514 | + * associated hc_driver struct). | |
7515 | + * 2. Hotplugged keyboards are now recognized by KDB. | |
7516 | + * 3. Currently KDB can only make use of 1 USB type keyboard. | |
7517 | + * New code can handle up to 8 attached keyboards - input is | |
7518 | + * multiplexed from all of them while in kdb. | |
7519 | + * kdb v4.4-2.6.23-common-2. | |
7520 | + | |
7521 | +2007-10-24 Jay Lan <jlan@sgi.com> | |
7522 | + | |
7523 | + * kdb v4.4-2.6.23-common-1. | |
7524 | + | |
7525 | +2007-09-26 Jay Lan <jlan@sgi.com> | |
7526 | + | |
7527 | + * kdb v4.4-2.6.23-rc8-common-1. | |
7528 | + | |
7529 | +2007-09-21 Jay Lan <jlan@sgi.com> | |
7530 | + | |
7531 | + * kdb v4.4-2.6.23-rc7-common-1. | |
7532 | + | |
7533 | +2007-09-12 Jay Lan <jlan@sgi.com> | |
7534 | + | |
7535 | + * kdb v4.4-2.6.23-rc6-common-1. | |
7536 | + | |
7537 | +2007-09-06 Jay Lan <jlan@sgi.com> | |
7538 | + | |
7539 | + * kdb v4.4-2.6.23-rc5-common-1. | |
7540 | + | |
7541 | +2007-08-30 Keith Owens <kaos@sgi.com> | |
7542 | + | |
7543 | + * New i386/x86_64 backtrace requires that kdb_save_running() does not | |
7544 | + exit until after kdb_main_loop() has completed. | |
7545 | + * List more noret functions in i386/x86_64 backtrace code. | |
7546 | + * Call to a noret function ends a basic block. | |
7547 | + * After a call to a noret function, eip/rip may be pointing at the next | |
7548 | + function or not, depending on function alignment. Jay Lan. | |
7549 | + * kdb v4.4-2.6.23-rc4-common-2. | |
7550 | + | |
7551 | +2007-08-30 Jay Lan <jlan@sgi.com> | |
7552 | + | |
7553 | + * kdb v4.4-2.6.23-rc4-common-1. | |
7554 | + | |
7555 | +2007-08-28 Keith Owens <kaos@sgi.com> | |
7556 | + | |
7557 | + * kdb/kdba_bt_x86.c: | |
7558 | + * Handle the variable amount of stack data that is pushed by x86_64 | |
7559 | + * hardware on an interrupt. | |
7560 | + * Add instruction vmsave. | |
7561 | + * Handle pop to %rsp. | |
7562 | + * Cope with return address for functions defined as ATTRIB_NORET. | |
7563 | + * Include CONFIG_DEBUG_INFO in the summary line of bb_all. | |
7564 | + * Check for an interrupt that was delivered while user space was in | |
7565 | + * control. | |
7566 | + * A return to child_rip ends a backtrace. | |
7567 | + * Ignore level2_kernel_pgt and level3_kernel_pgt data areas if they | |
7568 | + * occur within the text segment. | |
7569 | + * kdb v4.4-2.6.23-rc3-common-2. | |
7570 | + | |
7571 | +2007-08-24 Keith Owens <kaos@sgi.com> | |
7572 | + | |
7573 | + * kdb v4.4-2.6.23-rc3-common-1. | |
7574 | + | |
7575 | +2007-08-24 Jay Lan <jlan@sgi.com> | |
7576 | + | |
7577 | + * kdb/kdba_bt_x86.c: | |
7578 | + * retint_kernel is only defined for CONFIG_PREEMPT. | |
7579 | + * Handle assembler code for CONFIG_HIBERNATION=y. | |
7580 | + * Handle assembler code for CONFIG_MATH_EMULATION=y. | |
7581 | + * Handle assembler code for CONFIG_XEN=y. | |
7582 | + * Handle assembler code for CONFIG_KPROBES=y. | |
7583 | + * Add CC version to the bb_all header. | |
7584 | + * Handle spurious label in jprobe_return. | |
7585 | + * Handle stack switch in jprobe_return. | |
7586 | + * Prefix register name with '%' in xadd/xchg temporary variable. | |
7587 | + * Require bb_usage_mov() to handle all the special cases internally. | |
7588 | + * Handle stack manipulation for kexec. | |
7589 | + * Handle spurious label in kretprobe_trampoline_holder. | |
7590 | + * Add instructions clgi, invlpga, rcl, rdpmc, stgi, vmclear, | |
7591 | + * vmlaunch, vmload, vmptrld, vmread, vmresume, vmrun, vmwrite, | |
7592 | + * xstore-rng. | |
7593 | + * Exclude more 16 bit and/or real mode acpi functions from bb_all. | |
7594 | + * Handle assembler stack switching code in i386 do_softirq. | |
7595 | + * kdb/kdbmain.c: | |
7596 | + * Add CC version to the summary output. | |
7597 | + * Bump debug_kmalloc pool from 128K to 256K, some of the kernel | |
7598 | + * functions have huge numbers of basic blocks and jumps between them. | |
7599 | + * Correct reinstallation of breakpoints when exiting KDB. | |
7600 | + * Keith Owens. | |
7601 | + * kdb v4.4-2.6.23-rc2-common-2. | |
7602 | + | |
7603 | +2007-08-07 Jay Lan <jlan@sgi.com> | |
7604 | + | |
7605 | + * kdb v4.4-2.6.23-rc2-common-1. | |
7606 | + | |
7607 | +2007-08-03 Keith Owens <kaos@sgi.com> | |
7608 | + | |
7609 | + * kdba_bt_x86.c: Rename some variables to make the code more readable. | |
7610 | + Print more debug information when merging register states and when | |
7611 | + calculating the new stack pointer. | |
7612 | + * kdb v4.4-2.6.23-rc1-common-2. | |
7613 | + | |
7614 | +2007-07-30 Keith Owens <kaos@sgi.com> | |
7615 | + | |
7616 | + * kdb v4.4-2.6.23-rc1-common-1. | |
7617 | + | |
7618 | +2007-07-26 Keith Owens <kaos@sgi.com> | |
7619 | + | |
7620 | + * New x86 backtrace code. | |
7621 | + * kdb v4.4-2.6.22-common-4. | |
7622 | + | |
7623 | +2007-07-17 Keith Owens <kaos@sgi.com> | |
7624 | + | |
7625 | + * Make kdb_printf_lock an irq lock to keep lockdep happy. | |
7626 | + * kdb v4.4-2.6.22-common-3. | |
7627 | + | |
7628 | +2007-07-13 Keith Owens <kaos@sgi.com> | |
7629 | + | |
7630 | + * Increase the size of the debug_alloc pool. | |
7631 | + * Add the caller that obtained each entry in the debug_alloc pool. | |
7632 | + * Poison entries in the debug_alloc pool. | |
7633 | + * Track current and maximum usage in debug_alloc pool. | |
7634 | + * Print the debug_alloc entries that are still in use when kdb exits | |
7635 | + (memory leaks). | |
7636 | + * Increase the default value of BTARGS to 9. | |
7637 | + * kdb v4.4-2.6.22-common-2. | |
7638 | + | |
7639 | +2007-07-09 Keith Owens <kaos@sgi.com> | |
7640 | + | |
7641 | + * kdb v4.4-2.6.22-common-1. | |
7642 | + | |
7643 | +2007-07-02 Keith Owens <kaos@sgi.com> | |
7644 | + | |
7645 | + * kdb v4.4-2.6.22-rc7-common-1. | |
7646 | + | |
7647 | +2007-06-20 Keith Owens <kaos@sgi.com> | |
7648 | + | |
7649 | + * kdb v4.4-2.6.22-rc5-common-1. | |
7650 | + | |
7651 | +2007-06-15 Keith Owens <kaos@sgi.com> | |
7652 | + | |
7653 | + * Do not include asm/kdb.h unless CONFIG_KDB is on. Dave Jiang. | |
7654 | + * kdb v4.4-2.6.22-rc4-common-2. | |
7655 | + | |
7656 | +2007-06-08 Keith Owens <kaos@sgi.com> | |
7657 | + | |
7658 | + * kdb v4.4-2.6.22-rc4-common-1. | |
7659 | + | |
7660 | +2007-05-28 Keith Owens <kaos@sgi.com> | |
7661 | + | |
7662 | + * kdb v4.4-2.6.22-rc3-common-1. | |
7663 | + | |
7664 | +2007-05-22 Keith Owens <kaos@sgi.com> | |
7665 | + | |
7666 | + * kdb v4.4-2.6.22-rc2-common-1. | |
7667 | + | |
7668 | +2007-05-22 Keith Owens <kaos@sgi.com> | |
7669 | + | |
7670 | + * kdb v4.4-2.6.22-rc1-common-1. | |
7671 | + | |
7672 | +2007-05-17 Keith Owens <kaos@sgi.com> | |
7673 | + | |
7674 | + * Add rdmsr and wrmsr commands for i386 and x86_64. Original patch by | |
7675 | + Bernardo Innocenti for i386, reworked by Keith Owens to make it safe | |
7676 | + on all cpu models and to handle both i386 and x86_64. | |
7677 | + * kdb v4.4-2.6.21-common-3. | |
7678 | + | |
7679 | +2007-05-15 Keith Owens <kaos@sgi.com> | |
7680 | + | |
7681 | + * Correct alignment of debug_alloc_header. | |
7682 | + * kdb v4.4-2.6.21-common-2. | |
7683 | + | |
7684 | +2007-04-29 Keith Owens <kaos@sgi.com> | |
7685 | + | |
7686 | + * kdb v4.4-2.6.21-common-1. | |
7687 | + | |
7688 | +2007-04-16 Keith Owens <kaos@sgi.com> | |
7689 | + | |
7690 | + * Remove dead symbol declarations. | |
7691 | + * kdb v4.4-2.6.21-rc7-common-2. | |
7692 | + | |
7693 | +2007-04-16 Keith Owens <kaos@sgi.com> | |
7694 | + | |
7695 | + * kdb v4.4-2.6.21-rc7-common-1. | |
7696 | + | |
7697 | +2007-04-10 Keith Owens <kaos@sgi.com> | |
7698 | + | |
7699 | + * kdb v4.4-2.6.21-rc6-common-1. | |
7700 | + | |
7701 | +2007-04-02 Keith Owens <kaos@sgi.com> | |
7702 | + | |
7703 | + * kdb v4.4-2.6.21-rc5-common-1. | |
7704 | + | |
7705 | +2007-03-19 Keith Owens <kaos@sgi.com> | |
7706 | + | |
7707 | + * kdb v4.4-2.6.21-rc4-common-1. | |
7708 | + | |
7709 | +2007-03-14 Keith Owens <kaos@sgi.com> | |
7710 | + | |
7711 | + * kdb v4.4-2.6.21-rc3-common-1. | |
7712 | + | |
7713 | +2007-03-14 Keith Owens <kaos@sgi.com> | |
7714 | + | |
7715 | + * kdb v4.4-2.6.21-rc2-common-1. | |
7716 | + | |
7717 | +2007-03-01 Keith Owens <kaos@sgi.com> | |
7718 | + | |
7719 | + * kdb v4.4-2.6.21-rc1-common-1. | |
7720 | + | |
7721 | +2007-03-01 Keith Owens <kaos@sgi.com> | |
7722 | + | |
7723 | + * Remove sparse warnings. | |
7724 | + * kdb v4.4-2.6.20-common-6. | |
7725 | + | |
7726 | +2007-02-27 Keith Owens <kaos@sgi.com> | |
7727 | + | |
7728 | + * set_irq_regs() on entry to kdb() if they are not already set. | |
7729 | + * kdb v4.4-2.6.20-common-5. | |
7730 | + | |
7731 | +2007-02-22 Keith Owens <kaos@sgi.com> | |
7732 | + | |
7733 | + * Initialise struct disassemble_info in kdb_id1(). | |
7734 | + * kdb v4.4-2.6.20-common-4. | |
7735 | + | |
7736 | +2007-02-16 Keith Owens <kaos@sgi.com> | |
7737 | + | |
7738 | + * Clean up debug_alloc_pool code. | |
7739 | + * kdb v4.4-2.6.20-common-3. | |
7740 | + | |
7741 | +2007-02-16 Keith Owens <kaos@sgi.com> | |
7742 | + | |
7743 | + * Initialise variable bits of struct disassemble_info each time. | |
7744 | + * kdb v4.4-2.6.20-common-2. | |
7745 | + | |
7746 | +2007-02-06 Keith Owens <kaos@sgi.com> | |
7747 | + | |
7748 | + * kdb v4.4-2.6.20-common-1. | |
7749 | + | |
7750 | +2007-02-01 Keith Owens <kaos@sgi.com> | |
7751 | + | |
7752 | + * kdb v4.4-2.6.20-rc7-common-1. | |
7753 | + | |
7754 | +2007-01-08 Keith Owens <kaos@sgi.com> | |
7755 | + | |
7756 | + * kdb v4.4-2.6.20-rc4-common-1. | |
7757 | + | |
7758 | +2007-01-02 Keith Owens <kaos@sgi.com> | |
7759 | + | |
7760 | + * kdb v4.4-2.6.20-rc3-common-1. | |
7761 | + | |
7762 | +2006-12-21 Keith Owens <kaos@sgi.com> | |
7763 | + | |
7764 | + * Initialize the debug_kmalloc pool on the first call, so it can be | |
7765 | + used at any time. | |
7766 | + * kdb v4.4-2.6.20-rc1-common-2. | |
7767 | + | |
7768 | +2006-12-20 Keith Owens <kaos@sgi.com> | |
7769 | + | |
7770 | + * kdb v4.4-2.6.20-rc1-common-1. | |
7771 | + | |
7772 | +2006-11-30 Keith Owens <kaos@sgi.com> | |
7773 | + | |
7774 | + * kdb v4.4-2.6.19-common-1. | |
7775 | + | |
7776 | +2006-11-30 Keith Owens <kaos@sgi.com> | |
7777 | + | |
7778 | + * Do not access registers if kdb_current_regs is NULL. | |
7779 | + * kdb v4.4-2.6.19-rc6-common-3. | |
7780 | + | |
7781 | +2006-11-27 Keith Owens <kaos@sgi.com> | |
7782 | + | |
7783 | + * Only use VT keyboard if the command line allows it and ACPI indicates | |
7784 | + that there is an i8042. | |
7785 | + * Optimize kdb_read() to reduce the risk of dropping input characters. | |
7786 | + * Print cpumasks as lists instead of hex, also cope with long lists. | |
7787 | + * kdb v4.4-2.6.19-rc6-common-2. | |
7788 | + | |
7789 | +2006-11-20 Keith Owens <kaos@sgi.com> | |
7790 | + | |
7791 | + * kdb v4.4-2.6.19-rc6-common-1. | |
7792 | + | |
7793 | +2006-11-09 Keith Owens <kaos@sgi.com> | |
7794 | + | |
7795 | + * Change kdb() to fastcall. | |
7796 | + * Correct loop in kdb_help(). Georg Nikodym. | |
7797 | + * Only use VT console if the command line allows it. | |
7798 | + * kdb v4.4-2.6.19-rc5-common-2. | |
7799 | + | |
7800 | +2006-11-08 Keith Owens <kaos@sgi.com> | |
7801 | + | |
7802 | + * kdb v4.4-2.6.19-rc5-common-1. | |
7803 | + | |
7804 | +2006-11-01 Keith Owens <kaos@sgi.com> | |
7805 | + | |
7806 | + * kdb v4.4-2.6.19-rc4-common-1. | |
7807 | + | |
7808 | +2006-10-24 Keith Owens <kaos@sgi.com> | |
7809 | + | |
7810 | + * kdb v4.4-2.6.19-rc3-common-1. | |
7811 | + | |
7812 | +2006-10-24 Keith Owens <kaos@sgi.com> | |
7813 | + | |
7814 | + * Remove redundant regs and envp parameters. | |
7815 | + * kdb v4.4-2.6.19-rc2-common-2. | |
7816 | + | |
7817 | +2006-10-18 Keith Owens <kaos@sgi.com> | |
7818 | + | |
7819 | + * kdb v4.4-2.6.19-rc2-common-1. | |
7820 | + | |
7821 | +2006-10-11 Keith Owens <kaos@sgi.com> | |
7822 | + | |
7823 | + * Move kdbm_x86.c from the i386 to the common KDB patch. | |
7824 | + * Expand kdbm_x86.c to work on x86_64 as well as i386. | |
7825 | + * kdb v4.4-2.6.19-rc1-common-2. | |
7826 | + | |
7827 | +2006-10-09 Keith Owens <kaos@sgi.com> | |
7828 | + | |
7829 | + * kdb v4.4-2.6.19-rc1-common-1. | |
7830 | + | |
7831 | +2006-10-06 Keith Owens <kaos@sgi.com> | |
7832 | + | |
7833 | + * Remove #include <linux/config.h> | |
7834 | + * kdb v4.4-2.6.18-common-2. | |
7835 | + | |
7836 | +2006-09-20 Keith Owens <kaos@sgi.com> | |
7837 | + | |
7838 | + * kdb v4.4-2.6.18-common-1. | |
7839 | + | |
7840 | +2006-09-15 Keith Owens <kaos@sgi.com> | |
7841 | + | |
7842 | + * kdb v4.4-2.6.18-rc7-common-1. | |
7843 | + | |
7844 | +2006-08-29 Keith Owens <kaos@sgi.com> | |
7845 | + | |
7846 | + * Rewrite all backtrace code. | |
7847 | + * kdb v4.4-2.6.18-rc5-common-2. | |
7848 | + | |
7849 | +2006-08-28 Keith Owens <kaos@sgi.com> | |
7850 | + | |
7851 | + * kdb v4.4-2.6.18-rc5-common-1. | |
7852 | + | |
7853 | +2006-08-08 Keith Owens <kaos@sgi.com> | |
7854 | + | |
7855 | + * kdb v4.4-2.6.18-rc4-common-1. | |
7856 | + | |
7857 | +2006-08-04 Keith Owens <kaos@sgi.com> | |
7858 | + | |
7859 | + * kdb v4.4-2.6.18-rc3-common-1. | |
7860 | + | |
7861 | +2006-07-18 Keith Owens <kaos@sgi.com> | |
7862 | + | |
7863 | + * 8250.c locking has been fixed so there is no need to break spinlocks | |
7864 | + for keyboard entry. | |
7865 | + * kdb v4.4-2.6.18-rc2-common-2. | |
7866 | + | |
7867 | +2006-07-18 Keith Owens <kaos@sgi.com> | |
7868 | + | |
7869 | + * kdb v4.4-2.6.18-rc2-common-1. | |
7870 | + | |
7871 | +2006-07-12 Keith Owens <kaos@sgi.com> | |
7872 | + | |
7873 | + * Remove dead KDB_REASON codes. | |
7874 | + * The main kdb() function is now always entered with interrupts | |
7875 | + disabled, so there is no need to disable bottom halves. | |
7876 | + * sparse cleanups. | |
7877 | + * kdb v4.4-2.6.18-rc1-common-2. | |
7878 | + | |
7879 | +2006-07-07 Keith Owens <kaos@sgi.com> | |
7880 | + | |
7881 | + * kdb v4.4-2.6.18-rc1-common-1. | |
7882 | + | |
7883 | +2006-07-04 Keith Owens <kaos@sgi.com> | |
7884 | + | |
7885 | + * Add KDB_REASON_CPU_UP and callbacks for cpus coming online. | |
7886 | + * Relegate KDB_REASON_SILENT to KDB internal use only. | |
7887 | + * Backout the v4.4-2.6.15-common-3 change that made KDB_REASON_SILENT | |
7888 | + wait for cpus, the Dell Xeon problem has been fixed. | |
7889 | + * notify_die() is not called for KDB_REASON_SILENT nor | |
7890 | + KDB_REASON_CPU_UP, these events do not stay in KDB. | |
7891 | + * Export kdb_current_task for kdbm_x86. SuSE patch | |
7892 | + kdb-missing-export.diff | |
7893 | + * Scale kdb_wait_for_cpus_secs by the number of online cpus. | |
7894 | + * Delete kdb_enablehwfault, architectures now do their own setup. | |
7895 | + * Delete kdba_enable_mce, architectures now do their own setup. | |
7896 | + * Delete kdba_enable_lbr, kdba_disable_lbr, kdba_print_lbr, | |
7897 | + page_fault_mca. Only ever implemented on x86, difficult to maintain | |
7898 | + and rarely used in the field. | |
7899 | + * Replace #ifdef KDB_HAVE_LONGJMP with #ifdef kdba_setjmp. | |
7900 | + * kdb v4.4-2.6.17-common-2. | |
7901 | + | |
7902 | +2006-06-19 Keith Owens <kaos@sgi.com> | |
7903 | + | |
7904 | + * kdb v4.4-2.6.17-common-1. | |
7905 | + | |
7906 | +2006-05-31 Keith Owens <kaos@sgi.com> | |
7907 | + | |
7908 | + * Break spinlocks for keyboard entry. Hopefully a temporary hack while | |
7909 | + I track down why keyboard entry to KDB is hanging. | |
7910 | + * kdb v4.4-2.6.17-rc5-common-2. | |
7911 | + | |
7912 | +2006-05-25 Keith Owens <kaos@sgi.com> | |
7913 | + | |
7914 | + * kdb v4.4-2.6.17-rc5-common-1. | |
7915 | + | |
7916 | +2006-05-15 Keith Owens <kaos@sgi.com> | |
7917 | + | |
7918 | + * Refresh bfd related files from binutils 2.16.91.0.2. | |
7919 | + * kdb v4.4-2.6.17-rc4-common-2. | |
7920 | + | |
7921 | +2006-05-12 Keith Owens <kaos@sgi.com> | |
7922 | + | |
7923 | + * kdb v4.4-2.6.17-rc4-common-1. | |
7924 | + | |
7925 | +2006-04-28 Keith Owens <kaos@sgi.com> | |
7926 | + | |
7927 | + * kdb v4.4-2.6.17-rc3-common-1. | |
7928 | + | |
7929 | +2006-04-22 Keith Owens <kaos@sgi.com> | |
7930 | + | |
7931 | + * kdb v4.4-2.6.17-rc2-common-1. | |
7932 | + | |
7933 | +2006-04-11 Keith Owens <kaos@sgi.com> | |
7934 | + | |
7935 | + * kdb v4.4-2.6.17-rc1-common-1. | |
7936 | + | |
7937 | +2006-04-05 Keith Owens <kaos@sgi.com> | |
7938 | + | |
7939 | + * More fixes for the timing race with KDB_ENTER_SLAVE. | |
7940 | + * kdb v4.4-2.6.16-common-5. | |
7941 | + | |
7942 | +2006-03-30 Keith Owens <kaos@sgi.com> | |
7943 | + | |
7944 | + * Some code was testing KDB_IS_RUNNING() twice, which left it open to | |
7945 | + races. Cache the result instead. | |
7946 | + * kdb v4.4-2.6.16-common-4. | |
7947 | + | |
7948 | +2006-03-30 Keith Owens <kaos@sgi.com> | |
7949 | + | |
7950 | + * Change CONFIG_LKCD to CONFIG_LKCD_DUMP. | |
7951 | + * kdb v4.4-2.6.16-common-3. | |
7952 | + | |
7953 | +2006-03-22 Keith Owens <kaos@sgi.com> | |
7954 | + | |
7955 | + * Add some more xpc flags. Dean Nelson, SGI. | |
7956 | + * Replace open coded counter references with atomic_read(). | |
7957 | + * Pass early_uart_console to early_uart_setup(). Francois | |
7958 | + Wellenreiter, Bull. | |
7959 | + * Replace open code with for_each_online_cpu(). | |
7960 | + * If cpus do not come into kdb after a few seconds then let | |
7961 | + architectures send a more forceful interrupt. | |
7962 | + * Close a timing race with KDB_ENTER_SLAVE. | |
7963 | + * kdb v4.4-2.6.16-common-2. | |
7964 | + | |
7965 | +2006-03-21 Keith Owens <kaos@sgi.com> | |
7966 | + | |
7967 | + * kdb v4.4-2.6.16-common-1. | |
7968 | + | |
7969 | +2006-03-14 Nathan Scott <nathans@sgi.com> | |
7970 | + | |
7971 | + * kdb v4.4-2.6.16-rc6-common-1. | |
7972 | + | |
7973 | +2006-02-28 Nathan Scott <nathans@sgi.com> | |
7974 | + | |
7975 | + * kdb v4.4-2.6.16-rc5-common-1. | |
7976 | + | |
7977 | +2006-02-20 Nathan Scott <nathans@sgi.com> | |
7978 | + | |
7979 | + * kdb v4.4-2.6.16-rc4-common-1. | |
7980 | + | |
7981 | +2006-02-06 Keith Owens <kaos@sgi.com> | |
7982 | + | |
7983 | + * Change CONFIG_CRASH_DUMP to CONFIG_LKCD. | |
7984 | + * Remove obsolete kdb_notifier_list. | |
7985 | + * kdb v4.4-2.6.16-rc2-common-2. | |
7986 | + | |
7987 | +2006-02-06 Keith Owens <kaos@sgi.com> | |
7988 | + | |
7989 | + * Add xpcusers command. Dean Nelson, SGI. | |
7990 | + * kdb v4.4-2.6.16-rc2-common-1. | |
7991 | + | |
7992 | +2006-02-02 Keith Owens <kaos@sgi.com> | |
7993 | + | |
7994 | + * Check if we have a console before using it for KDB. | |
7995 | + * kdb v4.4-2.6.16-rc1-common-3. | |
7996 | + | |
7997 | +2006-02-01 Keith Owens <kaos@sgi.com> | |
7998 | + | |
7999 | + * Add option 'R' to the pid command to reset to the original task. | |
8000 | + * Include 'pid R' in archkdb* commands to reset up the original failing | |
8001 | + task. Users may have switched to other cpus and/or tasks before | |
8002 | + issuing archkdb. | |
8003 | + * Compile fix for kdbm_pg.c on i386. | |
8004 | + * kdb v4.4-2.6.16-rc1-common-2. | |
8005 | + | |
8006 | +2006-01-18 Keith Owens <kaos@sgi.com> | |
8007 | + | |
8008 | + * kdb v4.4-2.6.16-rc1-common-1. | |
8009 | + | |
8010 | +2006-01-11 Keith Owens <kaos@sgi.com> | |
8011 | + | |
8012 | + * Plug a timing race between KDB_ENTER_SLAVE and KDB_ENTER, and allow | |
8013 | + the cpu command to switch to a slave cpu. | |
8014 | + * KDB_REASON_SILENT now waits for other cpus, to avoid spurious NMI | |
8015 | + events that were seen on some Xeon systems. | |
8016 | + * kdb v4.4-2.6.15-common-3. | |
8017 | + | |
8018 | +2006-01-08 Keith Owens <kaos@sgi.com> | |
8019 | + | |
8020 | + * kdb mainline invokes DIE_KDEBUG_ENTER and DIE_KDEBUG_LEAVE via | |
8021 | + notify_die. | |
8022 | + * Move xpc debug support from xpc to mainline kdb. | |
8023 | + * kdbm_cm.c: check if file_lock_operations or lock_manager_operations | |
8024 | + are set before dereferencing them. Felix Blyakher, SGI. | |
8025 | + * kdb v4.4-2.6.15-common-2. | |
8026 | + | |
8027 | +2006-01-04 Keith Owens <kaos@sgi.com> | |
8028 | + | |
8029 | + * Print all buffers on a page in inode pages and update formatting to be | |
8030 | + legible, too. David Chinner, SGI. | |
8031 | + * Update page flags in kdbm_pg. | |
8032 | + * Remove inline from *.c files. | |
8033 | + * kdb v4.4-2.6.15-common-1. | |
8034 | + | |
8035 | +2005-12-25 Keith Owens <kaos@sgi.com> | |
8036 | + | |
8037 | + * kdb v4.4-2.6.15-rc7-common-1. | |
8038 | + | |
8039 | +2005-12-20 Keith Owens <kaos@sgi.com> | |
8040 | + | |
8041 | + * kdb v4.4-2.6.15-rc6-common-1. | |
8042 | + | |
8043 | +2005-12-10 Keith Owens <kaos@sgi.com> | |
8044 | + | |
8045 | + * Update mapping of flags to strings in kdbm_pg.c and kdbm_vm.c. | |
8046 | + * kdb v4.4-2.6.15-rc5-common-3. | |
8047 | + | |
8048 | +2005-12-06 Keith Owens <kaos@sgi.com> | |
8049 | + | |
8050 | + * Add RECOVERY flag to global KDB flags. | |
8051 | + * Add kdb_{save,restore}_flags. | |
8052 | + * kdb v4.4-2.6.15-rc5-common-2. | |
8053 | + | |
8054 | +2005-12-05 Keith Owens <kaos@sgi.com> | |
8055 | + | |
8056 | + * kdb v4.4-2.6.15-rc5-common-1. | |
8057 | + | |
8058 | +2005-12-02 Keith Owens <kaos@sgi.com> | |
8059 | + | |
8060 | + * kdbm_vm.c: offsets of page macros should be unsigned long. Reported | |
8061 | + by Dean Nelson, SGI. | |
8062 | + * kdb v4.4-2.6.15-rc4-common-1. | |
8063 | + | |
8064 | +2005-11-30 Keith Owens <kaos@sgi.com> | |
8065 | + | |
8066 | + * New follow_page() API. | |
8067 | + * kdb v4.4-2.6.15-rc3-common-1. | |
8068 | + | |
8069 | +2005-11-21 Keith Owens <kaos@sgi.com> | |
8070 | + | |
8071 | + * kdb v4.4-2.6.15-rc2-common-1. | |
8072 | + | |
8073 | +2005-11-15 Keith Owens <kaos@sgi.com> | |
8074 | + | |
8075 | + * kdb v4.4-2.6.15-rc1-common-1. | |
8076 | + | |
8077 | +2005-11-15 Keith Owens <kaos@sgi.com> | |
8078 | + | |
8079 | + * Allow kdb_printf() to be used outside kdb, in preemptible context. | |
8080 | + * Build with CONFIG_SWAP=n. Reported by Leo Yuriev. | |
8081 | + * kdb v4.4-2.6.14-common-2. | |
8082 | + | |
8083 | +2005-10-28 Keith Owens <kaos@sgi.com> | |
8084 | + | |
8085 | + * kdb v4.4-2.6.14-common-1. | |
8086 | + | |
8087 | +2005-10-21 Keith Owens <kaos@sgi.com> | |
8088 | + | |
8089 | + * kdb v4.4-2.6.14-rc5-common-1. | |
8090 | + | |
8091 | +2005-10-11 Keith Owens <kaos@sgi.com> | |
8092 | + | |
8093 | + * Handle removal of USB keyboard. Aaron Young, SGI. | |
8094 | + * kdb v4.4-2.6.14-rc4-common-1. | |
8095 | + | |
8096 | +2005-10-05 Keith Owens <kaos@sgi.com> | |
8097 | + | |
8098 | + * Extend kdb_notifier_list() codes to include dumping. | |
8099 | + * Use emergency_restart() for reboot, it can be called from interrupt | |
8100 | + context, unlike machine_restart(). | |
8101 | + * kdb v4.4-2.6.14-rc3-common-1. | |
8102 | + | |
8103 | +2005-09-21 Keith Owens <kaos@sgi.com> | |
8104 | + | |
8105 | + * Support kdb_current_task in register display and modify commands. | |
8106 | + * Document what changes kdb's notion of the current task. | |
8107 | + * Update rd documentation for IA64. | |
8108 | + * Move some definictions to kdbprivate.h and remove some unused symbol | |
8109 | + exports. | |
8110 | + * kdb v4.4-2.6.14-rc2-common-1. | |
8111 | + | |
8112 | +2005-09-20 Keith Owens <kaos@sgi.com> | |
8113 | + | |
8114 | + * Document IA64 handlers command. | |
8115 | + * Add more fields to the task command. | |
8116 | + * Cope with MCA/INIT handlers in the ps command. | |
8117 | + * Namespace cleanup, delete unused exports, make some functions static. | |
8118 | + * Add a kdb_notifier_list callback when kdb is about to reboot the | |
8119 | + system. | |
8120 | + * kdb v4.4-2.6.14-rc1-common-1. | |
8121 | + | |
8122 | +2005-08-29 Keith Owens <kaos@sgi.com> | |
8123 | + | |
8124 | + * kdb v4.4-2.6.13-common-1. | |
8125 | + | |
8126 | +2005-08-24 Keith Owens <kaos@sgi.com> | |
8127 | + | |
8128 | + * kdb v4.4-2.6.13-rc7-common-1. | |
8129 | + | |
8130 | +2005-08-08 Keith Owens <kaos@sgi.com> | |
8131 | + | |
8132 | + * kdb v4.4-2.6.13-rc6-common-1. | |
8133 | + | |
8134 | +2005-08-02 Keith Owens <kaos@sgi.com> | |
8135 | + | |
8136 | + * Print more fields from filp, dentry. | |
8137 | + * Add kdb=on-nokey to suppress kdb entry from the keyboard. | |
8138 | + * kdb v4.4-2.6.13-rc5-common-1. | |
8139 | + | |
8140 | +2005-07-30 Keith Owens <kaos@sgi.com> | |
8141 | + | |
8142 | + * kdb v4.4-2.6.13-rc4-common-1. | |
8143 | + | |
8144 | +2005-07-26 Keith Owens <kaos@sgi.com> | |
8145 | + | |
8146 | + * Fix compile problem with CONFIG_USB_KBD. | |
8147 | + * kdb v4.4-2.6.13-rc3-common-3. | |
8148 | + | |
8149 | +2005-07-22 Keith Owens <kaos@sgi.com> | |
8150 | + | |
8151 | + * The asmlinkage kdb() patch was lost during packaging. Reinstate it. | |
8152 | + * kdb v4.4-2.6.13-rc3-common-2. | |
8153 | + | |
8154 | +2005-07-19 Keith Owens <kaos@sgi.com> | |
8155 | + | |
8156 | + * Add support for USB keyboard (OHCI only). Aaron Young, SGI. | |
8157 | + * kdb v4.4-2.6.13-rc3-common-1. | |
8158 | + | |
8159 | +2005-07-08 Keith Owens <kaos@sgi.com> | |
8160 | + | |
8161 | + * kdb v4.4-2.6.13-rc2-common-1. | |
8162 | + | |
8163 | +2005-07-01 Keith Owens <kaos@sgi.com> | |
8164 | + | |
8165 | + * Make kdb() asmlinkage to avoid problems with CONFIG_REGPARM. | |
8166 | + * Change some uses of smp_processor_id() to be preempt safe. | |
8167 | + * Use DEFINE_SPINLOCK(). | |
8168 | + * kdb v4.4-2.6.13-rc1-common-1. | |
8169 | + | |
8170 | +2005-06-18 Keith Owens <kaos@sgi.com> | |
8171 | + | |
8172 | + * kdb v4.4-2.6.12-common-1. | |
8173 | + | |
8174 | +2005-06-08 Keith Owens <kaos@sgi.com> | |
8175 | + | |
8176 | + * Correct early exit from bd *. | |
8177 | + * kdb v4.4-2.6.12-rc6-common-1. | |
8178 | + | |
8179 | +2005-05-25 Keith Owens <kaos@sgi.com> | |
8180 | + | |
8181 | + * Delete Documentation/kdb/dump.txt. lkcd now has reasonable | |
8182 | + integration with kdb. | |
8183 | + * kdb v4.4-2.6.12-rc5-common-1. | |
8184 | + | |
8185 | +2005-05-08 Keith Owens <kaos@sgi.com> | |
8186 | + | |
8187 | + * kdb v4.4-2.6.12-rc4-common-1. | |
8188 | + | |
8189 | +2005-04-21 Keith Owens <kaos@sgi.com> | |
8190 | + | |
8191 | + * Add rpte command (find the pte for a physical page). | |
8192 | + * kdb v4.4-2.6.12-rc3-common-1. | |
8193 | + | |
8194 | +2005-04-06 Keith Owens <kaos@sgi.com> | |
8195 | + | |
8196 | + * Add rq and rqa commands. John Hawkes, SGI. | |
8197 | + * kdb v4.4-2.6.12-rc2-common-1. | |
8198 | + | |
8199 | +2005-03-29 Keith Owens <kaos@sgi.com> | |
8200 | + | |
8201 | + * Use register_sysctl_table() instead of patching kernel/sysctl.c. | |
8202 | + * Non-ASCII characters are not printable. | |
8203 | + * kdb v4.4-2.6.12-rc1-common-1. | |
8204 | + | |
8205 | +2005-03-15 Keith Owens <kaos@sgi.com> | |
8206 | + | |
8207 | + * More coexistence patches for lkcd. Jason Uhlenkott, SGI. | |
8208 | + * kdb v4.4-2.6.11-common-3. | |
8209 | + | |
8210 | +2005-03-08 Keith Owens <kaos@sgi.com> | |
8211 | + | |
8212 | + * Coexistence patches for lkcd. Jason Uhlenkott, SGI. | |
8213 | + * kdb v4.4-2.6.11-common-2. | |
8214 | + | |
8215 | +2005-03-03 Keith Owens <kaos@sgi.com> | |
8216 | + | |
8217 | + * Add kdb to drivers/serial/8250_early.c. Francois Wellenreiter, Bull. | |
8218 | + * kdb v4.4-2.6.11-common-1. | |
8219 | + | |
8220 | +2005-02-14 Keith Owens <kaos@sgi.com> | |
8221 | + | |
8222 | + * kdb v4.4-2.6.11-rc4-common-1. | |
8223 | + | |
8224 | +2005-02-08 Keith Owens <kaos@sgi.com> | |
8225 | + | |
8226 | + * kdb v4.4-2.6.11-rc3-bk4-common-1. | |
8227 | + | |
8228 | +2005-02-03 Keith Owens <kaos@sgi.com> | |
8229 | + | |
8230 | + * Print more superblock fields. Nathan Scott, SGI. | |
8231 | + * Remove kallsyms correction for modules, Linus took it. | |
8232 | + * kdb v4.4-2.6.11-rc3-common-1. | |
8233 | + | |
8234 | +2005-01-27 Keith Owens <kaos@sgi.com> | |
8235 | + | |
8236 | + * Add bio command. Nathan Scott, SGI. | |
8237 | + * kdb v4.4-2.6.11-rc2-common-1. | |
8238 | + | |
8239 | +2005-01-20 Keith Owens <kaos@sgi.com> | |
8240 | + | |
8241 | + * Include kallsyms correction for modules until Linus takes it. | |
8242 | + * kdb v4.4-2.6.11-rc1-bk7-common-1. | |
8243 | + | |
8244 | +2005-01-12 Keith Owens <kaos@sgi.com> | |
8245 | + | |
8246 | + * kallsyms now supports all symbols properly, remove kdb patch. | |
8247 | + * Add last ditch allocator for debugging. | |
8248 | + * Update kdb_meminfo_read_proc() for vmalloc changes. | |
8249 | + * Update kdbm_vm.c for 4 level page tables. | |
8250 | + * kdb v4.4-2.6.11-rc1-common-1. | |
8251 | + | |
8252 | +2004-12-25 Keith Owens <kaos@sgi.com> | |
8253 | + | |
8254 | + * Add kobject command. | |
8255 | + * Ignore low addresses and large offsets in kdbnearsym(). | |
8256 | + * Console updates for sn2 simulator. | |
8257 | + * kdb v4.4-2.6.10-common-1. | |
8258 | + | |
8259 | +2004-12-07 Keith Owens <kaos@sgi.com> | |
8260 | + | |
8261 | + * kdb v4.4-2.6.10-rc3-common-1. | |
8262 | + | |
8263 | +2004-11-23 Keith Owens <kaos@sgi.com> | |
8264 | + | |
8265 | + * Remove warning message from kdb_get_one_user_page(), it was too noisy. | |
8266 | + * kdb v4.4-2.6.10-rc2-common-1. | |
8267 | + | |
8268 | +2004-11-02 Keith Owens <kaos@sgi.com> | |
8269 | + | |
8270 | + * Build with kdb patch applied but CONFIG_KDB=n. | |
8271 | + * kdb v4.4-2.6.10-rc1-common-2. | |
8272 | + | |
8273 | +2004-10-29 Keith Owens <kaos@sgi.com> | |
8274 | + | |
8275 | + * Handle new compression scheme for kallsyms. | |
8276 | + * Handle move of DEAD and ZOMBIE for task->state to task->exit_state. | |
8277 | + * Tweak the concept of a valid kernel address to get all symbols, | |
8278 | + including the symbols in the ia64 gate page. | |
8279 | + * kdb v4.4-2.6.10-rc1-common-1. | |
8280 | + | |
8281 | +2004-10-21 Keith Owens <kaos@sgi.com> | |
8282 | + | |
8283 | + * Handle variable size for the kernel log buffer. | |
8284 | + * kdb v4.4-2.6.9-common-2. | |
8285 | + | |
8286 | +2004-10-19 Keith Owens <kaos@sgi.com> | |
8287 | + | |
8288 | + * kdb v4.4-2.6.9-common-1. | |
8289 | + | |
8290 | +2004-10-12 Keith Owens <kaos@sgi.com> | |
8291 | + | |
8292 | + * kdb v4.4-2.6.9-rc4-common-1. | |
8293 | + | |
8294 | +2004-10-01 Keith Owens <kaos@sgi.com> | |
8295 | + | |
8296 | + * kdb v4.4-2.6.9-rc3-common-1. | |
8297 | + | |
8298 | +2004-09-30 Keith Owens <kaos@sgi.com> | |
8299 | + | |
8300 | + * Add stackdepth command to Documentation/kdb/kdb.mm. stackdepth is | |
8301 | + only supported on i386 and ia64 at the moment. | |
8302 | + * Skip kdbm_pg memmap build on x86_64. Scott Lurndal, 3leafnetworks. | |
8303 | + * Export kdb_serial_str for modular I/O. Bryan Cardillo, UPenn. | |
8304 | + * Reinstate tab completion for symbols. | |
8305 | + * kdb v4.4-2.6.9-rc2-common-2. | |
8306 | + | |
8307 | +2004-09-14 Keith Owens <kaos@sgi.com> | |
8308 | + | |
8309 | + * Add task states C (traCed) and E (dEad). | |
8310 | + * kdb v4.4-2.6.9-rc2-common-1. | |
8311 | + | |
8312 | +2004-08-27 Keith Owens <kaos@sgi.com> | |
8313 | + | |
8314 | + * kdb v4.4-2.6.9-rc1-common-1. | |
8315 | + | |
8316 | +2004-08-14 Keith Owens <kaos@sgi.com> | |
8317 | + | |
8318 | + * kdb v4.4-2.6.8-common-1. | |
8319 | + | |
8320 | +2004-08-12 Keith Owens <kaos@sgi.com> | |
8321 | + | |
8322 | + * kdb v4.4-2.6.8-rc4-common-1. | |
8323 | + | |
8324 | +2004-08-05 Keith Owens <kaos@sgi.com> | |
8325 | + | |
8326 | + * Mark kdb_initcall as __attribute_used__ for newer gcc. | |
8327 | + * kdb v4.4-2.6.8-rc3-common-2. | |
8328 | + | |
8329 | +2004-08-04 Keith Owens <kaos@sgi.com> | |
8330 | + | |
8331 | + * Add mdp (memory display physical) comnmand. | |
8332 | + Ananth N Mavinakayanahalli, IBM. | |
8333 | + * kdb v4.4-2.6.8-rc3-common-1. | |
8334 | + | |
8335 | +2004-07-18 Keith Owens <kaos@sgi.com> | |
8336 | + | |
8337 | + * Patch for new sn_console. Erik Jacobson. SGI. | |
8338 | + * kdb v4.4-2.6.8-rc2-common-1. | |
8339 | + | |
8340 | +2004-07-12 Keith Owens <kaos@sgi.com> | |
8341 | + | |
8342 | + * Convert kdbm_task to standard cpumask_t. | |
8343 | + * Document '*' (all breakpoints) option on bd/be/bc commands. | |
8344 | + * kdb v4.4-2.6.8-rc1-common-1. | |
8345 | + | |
8346 | +2004-06-30 Keith Owens <kaos@sgi.com> | |
8347 | + | |
8348 | + * Common changes to help the x86-64 port. | |
8349 | + * kdb v4.4-2.6.7-common-3. | |
8350 | + | |
8351 | +2004-06-20 Keith Owens <kaos@sgi.com> | |
8352 | + | |
8353 | + * Move kdb includes in mm/swapfile.c to reduce conflicts with other | |
8354 | + SGI patches. | |
8355 | + * kdb v4.4-2.6.7-common-2. | |
8356 | + | |
8357 | +2004-06-16 Keith Owens <kaos@sgi.com> | |
8358 | + | |
8359 | + * kdb v4.4-2.6.7-common-1. | |
8360 | + | |
8361 | +2004-06-09 Keith Owens <kaos@sgi.com> | |
8362 | + | |
8363 | + * kdb v4.4-2.6.7-rc3-common-1. | |
8364 | + | |
8365 | +2004-06-09 Keith Owens <kaos@sgi.com> | |
8366 | + | |
8367 | + * Namespace clean up. Mark code/variables as static when it is only | |
8368 | + used in one file, delete dead code/variables. | |
8369 | + * Saved interrupt state requires long, not int. | |
8370 | + * kdb v4.4-2.6.7-rc2-common-3. | |
8371 | + | |
8372 | +2004-06-08 Keith Owens <kaos@sgi.com> | |
8373 | + | |
8374 | + * Whitespace clean up, no code changes. | |
8375 | + * kdb v4.4-2.6.7-rc2-common-2. | |
8376 | + | |
8377 | +2004-06-07 Keith Owens <kaos@sgi.com> | |
8378 | + | |
8379 | + * kdb v4.4-2.6.7-rc2-common-1. | |
8380 | + | |
8381 | +2004-06-06 Keith Owens <kaos@sgi.com> | |
8382 | + | |
8383 | + * Avoid recursion problems in kdb_init(). | |
8384 | + * Add standard archkdb commands. | |
8385 | + * Add per_cpu command. | |
8386 | + * Move kdb_{get,put}userarea_size definitions to linux/kdb.h. | |
8387 | + * kdb v4.4-2.6.6-common-2. | |
8388 | + | |
8389 | +2004-05-23 Keith Owens <kaos@sgi.com> | |
8390 | + | |
8391 | + * Shrink the output from the cpu command. | |
8392 | + * Add cpu state 'I', the cpu is idle. | |
8393 | + * Add cpu state '+', some kdb data is available but the cpu is not | |
8394 | + responding. | |
8395 | + * Do not print tasks in state I or M by default in ps and bta commands. | |
8396 | + * Add states I (idle task) and M (sleeping system daemon) to ps and | |
8397 | + bta commands. | |
8398 | + * Delete unused variables. | |
8399 | + * Move private kdb fields from kdb.h to kdbprivate.h. | |
8400 | + * Print 'for keyboard entry' for the special cases when KDB_ENTER() is | |
8401 | + used to get registers. | |
8402 | + * Move bfd.h and ansidecl.h from arch/$(ARCH)/kdb to include/asm-$(ARCH) | |
8403 | + and remove -I arch/$(ARCH)/kdb. | |
8404 | + * dmesg command now prints from either the start or end of dmesg, or at | |
8405 | + an arbitrary point in the middle of the kernel log buffer. | |
8406 | + * Sensible string dump for multi byte md commands. | |
8407 | + * 'page' command handles ia64 correctly. | |
8408 | + * Show some activity when waiting for cpus to enter kdb. | |
8409 | + * Change the KDB entry code to <esc>KDB. | |
8410 | + * Allow comment commands, starting with '#'. | |
8411 | + * Commands defined using defcmd from kdb_cmds are not printed as they | |
8412 | + are entered, use defcmd with no parameters to print all the defined | |
8413 | + commands. | |
8414 | + * Add summary command. | |
8415 | + * Update copyright notices. | |
8416 | + * Zero suppression on md command. | |
8417 | + * Make set NOSECT=1 the default. | |
8418 | + * PPC64 uses OF-stdout instead of console. Ananth N Mavinakayanahalli. | |
8419 | + * kdb v4.4-2.6.6-common-1. | |
8420 | + | |
8421 | +2004-05-10 Keith Owens <kaos@sgi.com> | |
8422 | + | |
8423 | + * kdb v4.3-2.6.6-common-1. | |
8424 | + | |
8425 | +2004-05-06 Keith Owens <kaos@sgi.com> | |
8426 | + | |
8427 | + * kdb v4.3-2.6.6-rc3-common-1. | |
8428 | + | |
8429 | +2004-05-06 Keith Owens <kaos@sgi.com> | |
8430 | + | |
8431 | + * kdb v4.3-2.6.6-rc2-common-1. | |
8432 | + | |
8433 | +2004-04-30 Keith Owens <kaos@sgi.com> | |
8434 | + | |
8435 | + * Rewrite inode_pages command for new radix code in struct page. | |
8436 | + * kdb v4.3-2.6.6-rc1-common-1. | |
8437 | + | |
8438 | +2004-04-11 Keith Owens <kaos@sgi.com> | |
8439 | + | |
8440 | + * Unlock sn_sal_lock before entering kdb from sn_serial. | |
8441 | + * kdb v4.3-2.6.5-common-2. | |
8442 | + | |
8443 | +2004-04-05 Keith Owens <kaos@sgi.com> | |
8444 | + | |
8445 | + * kdb v4.3-2.6.5-common-1. | |
8446 | + | |
8447 | +2004-03-22 Keith Owens <kaos@sgi.com> | |
8448 | + | |
8449 | + * kdb v4.3-2.6.5-rc2-common-1. | |
8450 | + | |
8451 | +2004-03-12 Keith Owens <kaos@sgi.com> | |
8452 | + | |
8453 | + * More work to avoid spurious messages from WARN_CONSOLE_UNLOCKED(). | |
8454 | + * bh command bug fixes. Nathan Scott. | |
8455 | + * kdb v4.3-2.6.4-common-1. | |
8456 | + | |
8457 | +2004-03-06 Keith Owens <kaos@sgi.com> | |
8458 | + | |
8459 | + * Set KDB_IS_RUNNING() during kdb_init to avoid spurious messages from | |
8460 | + WARN_CONSOLE_UNLOCKED(). | |
8461 | + * Correct loss of symbol names in kdbnearsym. | |
8462 | + * kdb v4.3-2.6.4-rc2-common-1. | |
8463 | + | |
8464 | +2004-02-29 Keith Owens <kaos@sgi.com> | |
8465 | + | |
8466 | + * kdb v4.3-2.6.4-rc1-common-1. | |
8467 | + | |
8468 | +2004-02-21 Keith Owens <kaos@sgi.com> | |
8469 | + | |
8470 | + * Correct build of kdb_cmds when using a separate object directory and | |
8471 | + make it quiet. j-nomura (NEC), Keith Owens. | |
8472 | + * kdb v4.3-2.6.3-common-2. | |
8473 | + | |
8474 | +2004-02-18 Keith Owens <kaos@sgi.com> | |
8475 | + | |
8476 | + * kdb v4.3-2.6.3-common-1. | |
8477 | + | |
8478 | +2004-02-17 Keith Owens <kaos@sgi.com> | |
8479 | + | |
8480 | + * Remove WAR for incorrect console registration patch. | |
8481 | + * kdb v4.3-2.6.3-rc4-common-1. | |
8482 | + | |
8483 | +2004-02-17 Keith Owens <kaos@sgi.com> | |
8484 | + | |
8485 | + * Convert longjmp buffers from static to dynamic allocation, for large | |
8486 | + cpu counts. | |
8487 | + * Tweak kdbm_task for SMP/UP. | |
8488 | + * Reconcile with kdb-v4.3 2.4.25-rc1-common-1. | |
8489 | + * Simplify coexistence with NPTL patches. | |
8490 | + * Support kill command on new scheduler. | |
8491 | + * Do not refetch data when printing a value as characters. | |
8492 | + * Document the pid command. | |
8493 | + * Work around 2.6 kallsyms 'feature'. | |
8494 | + * Upgrade to 2.6.3-rc3. | |
8495 | + * WAR for incorrect console registration patch. | |
8496 | + * kdb v4.3-2.6.3-rc3-common-1. | |
8497 | + | |
8498 | +2003-12-03 Keith Owens <kaos@sgi.com> | |
8499 | + | |
8500 | + * Reconcile 2.6-test versions from Xavier Bru (Bull), Greg Banks (SGI), | |
8501 | + Jim Houston (Concurrent Computer Corp). | |
8502 | + * Reconcile with kdb v4.3-2.4.23-common-2. | |
8503 | + * Clean up CONFIG_KDB changes to {scripts,kernel}/kallsyms.c. | |
8504 | + * Correct handling of kdb command line arguments. | |
8505 | + * Make hooks into module code less intrusive. | |
8506 | + * Delete kdb_active_task, not required with O(1) scheduler. | |
8507 | + * Port kdbm_task.c from 2.4. | |
8508 | + * Disable debug check in exit.c::next_thread() when kdb is running. | |
8509 | + * Remove "only bh_disable when interrupts are set". BH must be disabled | |
8510 | + in kdb to prevent deadlock on breakpoints in interrupt handlers. | |
8511 | + * Add kdb to drivers/char/sn_serial.c. | |
8512 | + * kdb v4.3-2.6.0-test11-common-1. | |
8513 | + | |
8514 | +2003-11-11 Xavier Bru <xavier.bru@bull.net> | |
8515 | + * Merge to 2.6.0-test9 | |
8516 | +2003-10-17 Xavier Bru <xavier.bru@bull.net> | |
8517 | + * fix NUll ptr in kdb_ps at early prompt. | |
8518 | +2003-10-14 Xavier Bru <xavier.bru@bull.net> | |
8519 | + * fix NUll ptr in kdb_ps when cpu not present. | |
8520 | +2003-10-06 Xavier Bru <xavier.bru@bull.net> | |
8521 | + * Merge to 2.6.0-test5 | |
8522 | + * fix compile error with CONFIG_MODULES not set. | |
8523 | + | |
8524 | +2003-09-08 Xavier Bru <xavier.bru@bull.net> | |
8525 | + * Merge to 2.6.0-test4 | |
8526 | + | |
8527 | +2003-07-10 Xavier Bru <xavier.bru@bull.net> | |
8528 | + | |
8529 | + * Merge kdb v4.3 to 2.5.72 ia64 | |
8530 | + * don't call local_bh_enable() with interrupts masked. | |
8531 | + | |
8532 | +2003-04-07 Xavier Bru <xavier.bru@bull.net> | |
8533 | + | |
8534 | + * Merge kdb v4.1 to 2.5.64 ia64 | |
8535 | + * new kernel parameters support | |
8536 | + * new module format | |
8537 | + * new kallsyms support | |
8538 | + | |
8539 | +2003-12-02 Keith Owens <kaos@sgi.com> | |
8540 | + | |
8541 | + * Use correct page alignment in kdb_get_one_user_page(). | |
8542 | + Prasanna S Panchamukhi, IBM. | |
8543 | + * Split pte command into pte -m and pte -p. Dean Roe, SGI. | |
8544 | + * kdb v4.3-2.4.23-common-2. | |
8545 | + | |
8546 | +2003-12-01 Keith Owens <kaos@sgi.com> | |
8547 | + | |
8548 | + * kdb v4.3-2.4.23-common-1. | |
8549 | + | |
8550 | +2003-11-11 Keith Owens <kaos@sgi.com> | |
8551 | + | |
8552 | + * Make KDB for USB keyboards build. Peter T. Breuer. | |
8553 | + * Do not use USB keyboard if it has not been probed. | |
8554 | + * kdb v4.3-2.4.23-rc1-common-1. | |
8555 | + | |
8556 | +2003-10-10 Keith Owens <kaos@sgi.com> | |
8557 | + | |
8558 | + * Sync with XFS 2.4.22 tree. | |
8559 | + * kdb v4.3-2.4.22-common-2. | |
8560 | + | |
8561 | +2003-08-29 Keith Owens <kaos@sgi.com> | |
8562 | + | |
8563 | + * kdb v4.3-2.4.22-common-1. | |
8564 | + | |
8565 | +2003-07-27 Keith Owens <kaos@sgi.com> | |
8566 | + | |
8567 | + * kdb v4.3-2.4.22-pre8-common-8. | |
8568 | + | |
8569 | +2003-07-20 Keith Owens <kaos@sgi.com> | |
8570 | + | |
8571 | + * Make kdb_serial_str a common constant, the same for all consoles. | |
8572 | + * Support SGI L1 console. | |
8573 | + * kdb v4.3-2.4.21-common-8. | |
8574 | + | |
8575 | +2003-07-14 Keith Owens <kaos@sgi.com> | |
8576 | + | |
8577 | + * Correct ll command. | |
8578 | + * kdb v4.3-2.4.21-common-7. | |
8579 | + | |
8580 | +2003-07-08 Keith Owens <kaos@sgi.com> | |
8581 | + | |
8582 | + * Export more kdb symbols. Vamsi Krishna S., IBM. | |
8583 | + * kdb v4.3-2.4.21-common-6. | |
8584 | + | |
8585 | +2003-07-07 Keith Owens <kaos@sgi.com> | |
8586 | + | |
8587 | + * Tweak 'waiting for cpus' message. | |
8588 | + * kdb v4.3-2.4.21-common-5. | |
8589 | + | |
8590 | +2003-07-07 Keith Owens <kaos@sgi.com> | |
8591 | + | |
8592 | + * 2.4.21-ia64-030702 patches common code that affects kdb. Workaround | |
8593 | + this nuisance. | |
8594 | + * kdb v4.3-2.4.21-common-4. | |
8595 | + | |
8596 | +2003-06-24 Keith Owens <kaos@sgi.com> | |
8597 | + | |
8598 | + * Add task and sigset commands. Mark Goodwin, SGI. | |
8599 | + * kdb v4.3-2.4.21-common-3. | |
8600 | + | |
8601 | +2003-06-23 Keith Owens <kaos@sgi.com> | |
8602 | + | |
8603 | + * Sync with XFS 2.4.21 tree. | |
8604 | + * kdb v4.3-2.4.21-common-2. | |
8605 | + | |
8606 | +2003-06-20 Keith Owens <kaos@sgi.com> | |
8607 | + | |
8608 | + * kdb v4.3-2.4.21-common-1. | |
8609 | + | |
8610 | +2003-06-20 Keith Owens <kaos@sgi.com> | |
8611 | + | |
8612 | + * More details on vm command, add vmp and pte commands. | |
8613 | + Dean Nelson, Dean Roe, SGI. | |
8614 | + * YAO1SCF (Yet Another O(1) Scheduler Coexistence Fix). | |
8615 | + * Changes to common code to build on sparc. Tom Duffy. | |
8616 | + * Move Tom Duffy's changes to drivers/sbus from the sparc64 | |
8617 | + patch to the common patch to keep all the serial changes | |
8618 | + together. | |
8619 | + * Changes to common code to build on Xscale. Eddie Dong, Intel. | |
8620 | + * Remove CROSS_COMPILE_INC. | |
8621 | + * Remove obsolete boot parameter 'kdb', long since replaced by | |
8622 | + 'kdb=on'. | |
8623 | + * Remove obsolete kdb_eframe_t casts. | |
8624 | + * Add CONFIG_KDB_CONTINUE_CATASTROPHIC. | |
8625 | + * Wait a short interval for cpus to join kdb before proceeding. | |
8626 | + * Automatically enable sysrq for sr command. | |
8627 | + * Correct double free of kdb_printf lock, spotted by Richard Sanders. | |
8628 | + * Add optional cpu parameter to btc command. | |
8629 | + * kdb v4.3-2.4.20-common-1. | |
8630 | + | |
8631 | +2003-05-02 Keith Owens <kaos@sgi.com> | |
8632 | + | |
8633 | + * Some architectures have problems with the initial empty kallsyms | |
8634 | + section so revert to three kallsyms passes. | |
8635 | + * Flush buffered input at startup and at 'more' prompt. | |
8636 | + * Only print 'more' prompt when longjmp data is available. | |
8637 | + * Print more data for buffers and inodes. | |
8638 | + * Disable kill command when O(1) scheduler is installed, the code | |
8639 | + needs to be redone for O(1). | |
8640 | + * The kernel has an undocumented assumption that enable_bh() is | |
8641 | + always called with interrupts enabled, make it so. | |
8642 | + * Print trailing punctuation even for symbols that are not in kernel. | |
8643 | + * Add read/write access to user pages. Vamsi Krishna S., IBM | |
8644 | + * Rename cpu_is_online to cpu_online, as in 2.5. | |
8645 | + * O(1) scheduler removes init_task so kdb maintains its own list of | |
8646 | + active tasks. | |
8647 | + * Delete btp 0 <cpuid> option, it needed init_tasks. | |
8648 | + * Clean up USB keyboard support. Steven Dake. | |
8649 | + * Sync with XFS 2.4.20 tree. | |
8650 | + * kdb v4.2-2.4.20-common-1. | |
8651 | + | |
8652 | +2003-04-04 Keith Owens <kaos@sgi.com> | |
8653 | + | |
8654 | + * Remove one kallsyms pass. | |
8655 | + * Automatic detection of O(1) scheduler. | |
8656 | + * Rename cpu_online to cpu_is_online. | |
8657 | + * Workarounds for scheduler bugs. | |
8658 | + * Tweak algorithm for detecting if cpu process data is available. | |
8659 | + * Add 'kill' command. Sonic Zhang, Keith Owens. | |
8660 | + * kdb v4.1-2.4.20-common-1. | |
8661 | + | |
8662 | +2003-03-16 Keith Owens <kaos@sgi.com> | |
8663 | + | |
8664 | + * Each cpu saves its state as it enters kdb or before it enters code | |
8665 | + which cannot call kdb. | |
8666 | + * Allow btp on process 0 for a specified cpu. | |
8667 | + * Add btt command, backtrace given a struct task address. | |
8668 | + * btc command no longer switches cpus, instead it uses the saved data. | |
8669 | + * bta shows the idle task on each cpu as well as real tasks, the idle | |
8670 | + task could be handling an interrupt. | |
8671 | + * ps command shows the idle task on each cpu. | |
8672 | + * ps checks that the saved data for a cpu matches the process running on | |
8673 | + that cpu and warns about stale saved data or no saved data at all. | |
8674 | + * Remove special cases for i386 backtrace from common code and simplify | |
8675 | + common bt code. | |
8676 | + * Clean up kdb interaction with CONFIG_SERIAL_CONSOLE. | |
8677 | + * Do not automatically repeat commands after the user typed 'q'. | |
8678 | + * O(1) scheduler patch changes the process cpu field but does not set | |
8679 | + any indicator that O(1) is being used. Adjust kdb_process_cpu() by | |
8680 | + hand after applying O(1). | |
8681 | + * Add kdb_print_nameval() to common code. | |
8682 | + * Convert tests of cpu_online_map to cpu_online() macro. | |
8683 | + * module.h needs errno.h when compiling with CONFIG_MODULES=n. | |
8684 | + * Correct duplicate breakpoint handling. | |
8685 | + * Do not try to send IPI during a catastrophic error, send_ipi can hang | |
8686 | + and take kdb with it. | |
8687 | + * kdb memmap command is i386 only, restrict it. | |
8688 | + * Add large block device (LBD) support from XFS tree. Eric Sandeen. | |
8689 | + * kdb v4.0-2.4.20-common-1. | |
8690 | + | |
8691 | +2003-02-03 Keith Owens <kaos@sgi.com> | |
8692 | + | |
8693 | + * Register kdb commands early. | |
8694 | + * Decode oops via kallsyms if it is available. | |
8695 | + * Update copyright notices to 2003. | |
8696 | + * Add defcmd/endefcmd to allow users to package their own macros. | |
8697 | + * kdb commands that fail are ignored when prefixed with '-'. | |
8698 | + * Add selection options to bta command. | |
8699 | + * Add btc command (switch to each cpu and backtrace). | |
8700 | + * Do real time detection of dead cpus. | |
8701 | + * Clear ip adjusted flag when leaving kdb. | |
8702 | + * Clean up ps command. | |
8703 | + * Print ps output for each task when backtracing. | |
8704 | + * Bump to version v3.0 to reduce confusion between kdb and kernel | |
8705 | + version numbers. | |
8706 | + * Add kdba_local_arch_setup/kdba_local_arch_cleanup to correct | |
8707 | + keyboard freeze. Ashish Kalra. | |
8708 | + * Refuse multiple breakpoints at the same address. | |
8709 | + * Add fl (file_lock) command, from XFS development tree. | |
8710 | + * Correct inode_pages, from XFS development tree. | |
8711 | + * Add command history and editing. Sonic Zhang. | |
8712 | + * Extend command history and editing to handle vt100 escape sequences. | |
8713 | + * Allow tab completion at start of line. | |
8714 | + * Touch nmi watchdog on long running bta and btc commands. | |
8715 | + * Clean up ps output and standardize with bta codes. | |
8716 | + * Correctly handle escaped characters in commands. | |
8717 | + * Update man pages for btc and command history/editing. | |
8718 | + * kdb v3.0-2.4.20-common-1. | |
8719 | + | |
8720 | +2002-11-29 Keith Owens <kaos@sgi.com> | |
8721 | + | |
8722 | + * Upgrade to 2.4.20. | |
8723 | + * Correct Documentation/kdb/kdb_sr.man. | |
8724 | + * Remove leading zeroes from pids, they are decimal, not octal. | |
8725 | + * kdb v2.5-2.4.20-common-1. | |
8726 | + | |
8727 | +2002-11-14 Keith Owens <kaos@sgi.com> | |
8728 | + | |
8729 | + * Upgrade to 2.4.20-rc1. | |
8730 | + * kdb v2.5-2.4.20-rc1-common-1. | |
8731 | + | |
8732 | +2002-11-14 Keith Owens <kaos@sgi.com> | |
8733 | + | |
8734 | + * Fix processing with O(1) scheduler. | |
8735 | + * 'go' switches back to initial cpu first. | |
8736 | + * 'go <address>' only allowed on initial cpu. | |
8737 | + * 'go' installs the global breakpoints from the initial cpu before | |
8738 | + releasing the other cpus. | |
8739 | + * If 'go' has to single step over a breakpoint then it single steps just | |
8740 | + the initial cpu, installs the global breakpoints then releases the | |
8741 | + other cpus. | |
8742 | + * General clean up of handling for breakpoints and single stepping over | |
8743 | + software breakpoints. | |
8744 | + * Add kdb_notifier_block so other code can tell when kdb is in control. | |
8745 | + * kdb v2.5-2.4.19-common-1. | |
8746 | + | |
8747 | +2002-11-02 Keith Owens <kaos@sgi.com> | |
8748 | + | |
8749 | + * Correct build without CONFIG_KDB. | |
8750 | + * kdb v2.4-2.4.19-common-3. | |
8751 | + | |
8752 | +2002-11-01 Keith Owens <kaos@sgi.com> | |
8753 | + | |
8754 | + * Minimize differences from 2.5.44. | |
8755 | + * kdb v2.4-2.4.19-common-2. | |
8756 | + | |
8757 | +2002-10-31 Keith Owens <kaos@sgi.com> | |
8758 | + | |
8759 | + * Add defcmd/endefcmd feature. | |
8760 | + * Remove kdb_eframe_t. | |
8761 | + * Clear bp data before using. | |
8762 | + * Sanity check if we have pt_regs. | |
8763 | + * Force LINES > 1. | |
8764 | + * Remove special case for KDB_REASON_PANIC, use KDB_ENTER() instead. | |
8765 | + * Remove kdba_getcurrentframe(). | |
8766 | + * Coexist with O(1) scheduler. | |
8767 | + * Add lines option to dmesg, speed up dmesg. | |
8768 | + * kdb v2.4-2.4.19-common-1. | |
8769 | + | |
8770 | +2002-10-17 Keith Owens <kaos@sgi.com> | |
8771 | + | |
8772 | + * Add selection critera to ps and bta commands. | |
8773 | + * kdb v2.3-2.4.19-common-4. | |
8774 | + | |
8775 | +2002-10-07 Keith Owens <kaos@sgi.com> | |
8776 | + | |
8777 | + * New man page, Documentation/kdb/kdb_sr.man. | |
8778 | + | |
8779 | +2002-10-04 Keith Owens <kaos@sgi.com> | |
8780 | + | |
8781 | + * Minimize differences between patches for 2.4 and 2.5 kernels. | |
8782 | + * Add Configure.help for CONFIG_KDB_USB. | |
8783 | + * Reduce stack usage. | |
8784 | + * kdb v2.3-2.4.19-common-3. | |
8785 | + | |
8786 | +2002-08-10 Keith Owens <kaos@sgi.com> | |
8787 | + | |
8788 | + * Replace kdb_port with kdb_serial to support memory mapped I/O. | |
8789 | + David Mosberger. | |
8790 | + * kdb v2.3-2.4.19-common-2. | |
8791 | + | |
8792 | +2002-08-07 Keith Owens <kaos@sgi.com> | |
8793 | + | |
8794 | + * Upgrade to 2.4.19. | |
8795 | + * Remove individual SGI copyrights, the general SGI copyright applies. | |
8796 | + * Handle md0. Reported by Hugh Dickins, different fix by Keith Owens. | |
8797 | + * Use page_address() in kdbm_pg.c. Hugh Dickins. | |
8798 | + * Remove debugging printk from kdbm_pg.c. Hugh Dickins. | |
8799 | + * Move breakpoint address verification into arch dependent code. | |
8800 | + * Dynamically resize kdb command table as required. | |
8801 | + * Common code to support USB keyboard. Sebastien Lelarge. | |
8802 | + * kdb v2.3-2.4.19-common-1. | |
8803 | + | |
8804 | +2002-07-09 Keith Owens <kaos@sgi.com> | |
8805 | + | |
8806 | + * Upgrade to 2.4.19-rc1. | |
8807 | + * Add dmesg command. | |
8808 | + * Clean up copyrights, Eric Sandeen. | |
8809 | + * kdb v2.2-2.4.19-rc1-common-1. | |
8810 | + | |
8811 | +2002-06-14 Keith Owens <kaos@sgi.com> | |
8812 | + | |
8813 | + * Upgrade to 2.4.19-pre10. | |
8814 | + * Sync with XFS. | |
8815 | + * kdb v2.1-2.4.19-pre10-common-1. | |
8816 | + | |
8817 | +2002-04-09 Keith Owens <kaos@sgi.com> | |
8818 | + | |
8819 | + * Upgrade to 2.4.19-pre6. | |
8820 | + * kdb v2.1-2.4.19-pre6-common-1. | |
8821 | + | |
8822 | +2002-03-18 Keith Owens <kaos@sgi.com> | |
8823 | + | |
8824 | + * Syntax check mdWcN commands. | |
8825 | + | |
8826 | +2002-03-01 Keith Owens <kaos@sgi.com> | |
8827 | + | |
8828 | + * Sync with XFS 2.4.18. | |
8829 | + * kdb v2.1-2.4.18-common-2. | |
8830 | + | |
8831 | +2002-02-26 Keith Owens <kaos@sgi.com> | |
8832 | + | |
8833 | + * Upgrade to 2.4.18. | |
8834 | + * Add Paul Dorwin (IBM) magicpoint slides on using kdb as | |
8835 | + Documentation/kdb/slides. | |
8836 | + * kdb v2.1-2.4.18-common-1. | |
8837 | + | |
8838 | +2002-01-23 Keith Owens <kaos@sgi.com> | |
8839 | + | |
8840 | + * Sync with XFS pagebuf changes. | |
8841 | + * kdb v2.1-2.4.17-common-2. | |
8842 | + | |
8843 | +2002-01-18 Keith Owens <kaos@sgi.com> | |
8844 | + | |
8845 | + * Ignore single stepping during panic. | |
8846 | + * Remove kdba_getword, kdba_putword. Replace with kdb_getword, | |
8847 | + kdb_putword that rely on copy_xx_user. The new functions return | |
8848 | + an error code, like copy_xx_user. | |
8849 | + * New functions kdb_getarea, kdb_putarea for copying areas of data | |
8850 | + such as structures. These functions also return an error code. | |
8851 | + * Change all common code to use the new functions. | |
8852 | + * bp command checks that it can read and write the word at the | |
8853 | + breakpoint before accepting the address. | |
8854 | + * Break points are now set FIFO and cleared LIFO so overlapping | |
8855 | + entries give sensible results. | |
8856 | + * Verify address before disassembling code. | |
8857 | + * Common changes for sparc64. Ethan Solomita, Tom Duffy. | |
8858 | + * Remove ss <count>, never supported. | |
8859 | + * Remove kallsyms entries from arch vmlinux.lds files. | |
8860 | + * Specify which commands auto repeat. | |
8861 | + * kdb v2.1-2.4.17-common-1. | |
8862 | + | |
8863 | +2002-01-07 Keith Owens <kaos@sgi.com> | |
8864 | + | |
8865 | + * Remove console semaphore code, not good in interrupt. | |
8866 | + * Remove fragment of ia64 patch that had crept into kdb. | |
8867 | + * Release as kdb v2.0-2.4.17-common-3. | |
8868 | + | |
8869 | +2002-01-04 Keith Owens <kaos@sgi.com> | |
8870 | + | |
8871 | + * Sync xfs <-> kdb common code. | |
8872 | + | |
8873 | +2001-12-22 Keith Owens <kaos@sgi.com> | |
8874 | + | |
8875 | + * Upgrade to 2.4.17. | |
8876 | + * Clean up ifdef CONFIG_KDB. | |
8877 | + * Add ifdef CONFIG_KDB around include kdb.h. | |
8878 | + * Delete dummy kdb.h files for unsupported architectures. | |
8879 | + * Delete arch i386 and ia64 specific files. This changelog now | |
8880 | + applies to kdb common code only. | |
8881 | + * Release as kdb v2.0-2.4.17-common-1. | |
8882 | + | |
8883 | +2001-12-03 Keith Owens <kaos@sgi.com> | |
8884 | + | |
8885 | + * Upgrade to 2.4.16. | |
8886 | + * Add include/asm-um/kdb.h stub to allow XFS to be tested under UML. | |
8887 | + * Check if an interrupt frame on i386 came from user space. | |
8888 | + * Out of scope bug fix in kdb_id.c. Ethan Solomita. | |
8889 | + * Changes to common code to support sparc64. Ethan Solomita. | |
8890 | + * Change GFP_KERNEL to GFP_ATOMIC in disasm. Ethan Solomita. | |
8891 | + | |
8892 | +2001-11-16 Keith Owens <kaos@sgi.com> | |
8893 | + | |
8894 | + * Upgrade to 2.4.15-pre5. | |
8895 | + * Wrap () around #define expressions with unary operators. | |
8896 | + | |
8897 | +2001-11-13 Keith Owens <kaos@sgi.com> | |
8898 | + | |
8899 | + * Upgrade to 2.4.15-pre4. | |
8900 | + * kbdm_pg.c patch from Hugh Dickins. | |
8901 | + | |
8902 | +2001-11-07 Keith Owens <kaos@sgi.com> | |
8903 | + | |
8904 | + * Upgrade to 2.4.14-ia64-011105. | |
8905 | + * Change name of l1 serial I/O routine, add ia64 init command. SGI. | |
8906 | + * Sync kdbm_pg with XFS. | |
8907 | + | |
8908 | +2001-11-06 Keith Owens <kaos@sgi.com> | |
8909 | + | |
8910 | + * Upgrade to kernel 2.4.14. | |
8911 | + | |
8912 | +2001-11-02 Keith Owens <kaos@sgi.com> | |
8913 | + | |
8914 | + * Sync kdbm_pg.c with XFS. | |
8915 | + | |
8916 | +2001-10-24 Keith Owens <kaos@sgi.com> | |
8917 | + | |
8918 | + * Upgrade to kernel 2.4.13. | |
8919 | + | |
8920 | +2001-10-14 Keith Owens <kaos@melbourne.sgi.com> | |
8921 | + | |
8922 | + * More use of TMPPREFIX in top level Makefile to speed up NFS compiles. | |
8923 | + | |
8924 | + * Correct repeat calculations in md/mds commands. | |
8925 | + | |
8926 | +2001-10-10 Keith Owens <kaos@melbourne.sgi.com> | |
8927 | + | |
8928 | + * Copy bfd.h and ansidecl.h to arch/$(ARCH)/kdb, remove dependecies on | |
8929 | + user space includes. | |
8930 | + | |
8931 | + * Update kdb v1.9 to kernel 2.4.11. | |
8932 | + | |
8933 | +2001-10-01 Keith Owens <kaos@melbourne.sgi.com> | |
8934 | + | |
8935 | + * Update kdb v1.9 to kernel 2.4.11-pre1 and 2.4.10-ac1. | |
8936 | + | |
8937 | + * Correct loop in kdb_parse, reported by Tachino Nobuhiro. | |
8938 | + | |
8939 | +2001-09-25 Keith Owens <kaos@melbourne.sgi.com> | |
8940 | + | |
8941 | + * Update kdb v1.8 to kernel 2.4.10. | |
8942 | + | |
8943 | + * kdbm_pg patch from Hugh Dickens. | |
8944 | + | |
8945 | + * DProbes patch from Bharata B Rao. | |
8946 | + | |
8947 | + * mdWcn and mmW patch from Vamsi Krishna S. | |
8948 | + | |
8949 | + * i386 disasm layout patch from Jean-Marc Saffroy. | |
8950 | + | |
8951 | + * Work around for 64 bit binutils, Simon Munton. | |
8952 | + | |
8953 | + * kdb.mm doc correction by Chris Pascoe. | |
8954 | + | |
8955 | + * Enter repeats the last command, IA64 disasm only prints one | |
8956 | + instruction. Don Dugger. | |
8957 | + | |
8958 | + * Allow kdb/modules to be linked into vmlinux. | |
8959 | + | |
8960 | + * Remove obsolete code from kdb/modules/kdbm_{pg,vm}.c. | |
8961 | + | |
8962 | + * Warn when commands are entered at more prompt. | |
8963 | + | |
8964 | + * Add MODULE_AUTHOR, DESCRIPTION, LICENSE. | |
8965 | + | |
8966 | + * Release as kdb v1.9. | |
8967 | + | |
8968 | +2001-02-27 Keith Owens <kaos@melbourne.sgi.com> | |
8969 | + | |
8970 | + * Update kdb v1.8 to kernel 2.4.2, sync kdb/modules with XFS. | |
8971 | + | |
8972 | + * Hook into panic() call. | |
8973 | + | |
8974 | +2000-12-18 Keith Owens <kaos@melbourne.sgi.com> | |
8975 | + | |
8976 | + * Update kdb v1.7 to kernel 2.4.0-test13-pre3, sync kdb/modules with | |
8977 | + XFS. | |
8978 | + | |
8979 | +2000-11-18 Keith Owens <kaos@melbourne.sgi.com> | |
8980 | + | |
8981 | + * Update to kernel 2.4.0-test11-pre7, including forward port of | |
8982 | + bug fixes from WIP 2.4.0-test9 tree. | |
8983 | + | |
8984 | + * Update to Cygnus CVS trees for disassembly code. | |
8985 | + | |
8986 | + * Bump to kdb v1.6. | |
8987 | + | |
8988 | +2000-10-19 Keith Owens <kaos@melbourne.sgi.com> | |
8989 | + | |
8990 | + * Update to kernel 2.4.0-test10-pre4. | |
8991 | + | |
8992 | +2000-10-15 Keith Owens <kaos@melbourne.sgi.com> | |
8993 | + | |
8994 | + * kdb/kdbmain.c (kdb_parse): Correctly handle blank input. | |
8995 | + | |
8996 | + * kdb/kdbmain.c (kdb_local, kdb): Reason SILENT can have NULL regs. | |
8997 | + | |
8998 | +2000-10-13 Keith Owens <kaos@melbourne.sgi.com> | |
8999 | + | |
9000 | + * kdb/kdbmain.c: Reduce CMD_LEN to avoid overflowing kdb_printf buffer. | |
9001 | + | |
9002 | +2000-10-11 Keith Owens <kaos@melbourne.sgi.com> | |
9003 | + | |
9004 | + * kdb/kdbmain.c (kdb): Test for userspace breakpoints before driving | |
9005 | + other cpus into kdb. Speeds up gdb and avoids SMP race. | |
9006 | + | |
9007 | + * arch/i386/kdb/kdba_io.c (get_serial_char, get_kbd_char): Ignore | |
9008 | + unprintable characters. | |
9009 | + | |
9010 | + * arch/i386/kdb/kdba_io.c (kdba_read): Better handling of buffer size. | |
9011 | + | |
9012 | +2000-10-04 Keith Owens <kaos@melbourne.sgi.com> | |
9013 | + | |
9014 | + * arch/i386/kdb/kdba_bt.c (kdba_bt_process): Verify that esp is inside | |
9015 | + task_struct. Original patch by Mike Galbraith. | |
9016 | + | |
9017 | + * kdb/kdb_io.c (kdb_getstr): Reset output line counter, remove | |
9018 | + unnecessary prompts. | |
9019 | + | |
9020 | + * arch/i386/kdb/kdbasupport.c (kdb_getregcontents): Change " cs" to | |
9021 | + "xcs", ditto ss, ds, es. gdb2kdb does not like leading spaces. | |
9022 | + | |
9023 | + * include/asm-xxx/kdb.h: Add dummy kdb.h for all architectures except | |
9024 | + ix86. This allows #include <linux/kdb.h> to appear in arch independent | |
9025 | + code without causing compile errors. | |
9026 | + | |
9027 | + * kdb/modules/kdbm_pg: Sync with XFS. | |
9028 | + | |
9029 | +2000-10-03 Keith Owens <kaos@melbourne.sgi.com> | |
9030 | + | |
9031 | + * kdb/kdb_io.c (kdb_read): Ignore NMI while waiting for input. | |
9032 | + | |
9033 | + * kdb/kdb_io.c, kdb/Makefile: Export kdb_read. | |
9034 | + | |
9035 | +2000-10-02 Keith Owens <kaos@melbourne.sgi.com> | |
9036 | + | |
9037 | + * arch/i386/kernel/smpboot.c (do_boot_cpu): Set nmi_watchdog_source to 2 | |
9038 | + to avoid premature NMI oops during cpu bring up. We have to assume that | |
9039 | + a box with more than 1 cpu has a working IO-APIC. | |
9040 | + | |
9041 | + * Documentation/kdb/{kdb.mm,kdb_md.man}: Add mdr command. | |
9042 | + | |
9043 | + * kdb/kdbmain.c (kdb_md): Add mdr command. | |
9044 | + | |
9045 | + * Release as kdb v1.5 against 2.4.0-test9-pre8. | |
9046 | + | |
9047 | + * arch/i386/kdb/kdba_io.c, arch/i386/kdb/kdbasupport.c, kdb/kdbmain.c, | |
9048 | + kdb/kdb_io.c, kdb/kdb_id.c: Remove zero initializers for static | |
9049 | + variables. | |
9050 | + | |
9051 | +2000-09-28 Keith Owens <kaos@melbourne.sgi.com> | |
9052 | + | |
9053 | + * various: Add nmi_watchdog_source, 1 local APIC, 2 IO-APIC. | |
9054 | + Test nmi_watchdog_source instead of nr_ioapics so UP works on SMP hardware. | |
9055 | + | |
9056 | + * arch/i386/kernel/io_apic.c: Rename setup_nmi to setup_nmi_io for clarity. | |
9057 | + | |
9058 | + * kdb/kdbmain.c (kdb_parse): Only set NO_WATCHDOG if it was already set. | |
9059 | + | |
9060 | + * kdb/kdbmain.c (kdb): Clear NO_WATCHDOG on all exit paths. | |
9061 | + | |
9062 | + * include/linux/kdb.h: Add KDB_REASON_SILENT. | |
9063 | + | |
9064 | + * kdb/kdbmain.c (kdb_local): Treat reason SILENT as immediate 'go'. | |
9065 | + | |
9066 | + * kdb/kdbmain.c (kdb_init): Invoke kdb with reason SILENT to instantiate | |
9067 | + any breakpoints on boot cpu. | |
9068 | + | |
9069 | + * arch/i386/kernel/smpboot.c (smp_callin): Invoke kdb with reason SILENT | |
9070 | + to instantiate any global breakpoints on this cpu. | |
9071 | + | |
9072 | + * kdb/kdb_cmds: Remove comment that said initial commands only worked on | |
9073 | + boot cpu. | |
9074 | + | |
9075 | +2000-09-27 Keith Owens <kaos@melbourne.sgi.com> | |
9076 | + | |
9077 | + * arch/i386/kernel/msr.c: Move {rd,wr}msr_eio to include/asm-i386/apic.h. | |
9078 | + | |
9079 | + * include/asm-i386/apic.h: Define NMI interfaces. | |
9080 | + | |
9081 | + * kernel/sysctl.c (kern_table): | |
9082 | + * kernel/sysctl.c (do_proc_set_nmi_watchdog): | |
9083 | + Add /proc/sys/kernel/nmi_watchdog. | |
9084 | + | |
9085 | + * arch/i386/kernel/apic.c: New routines set_nmi_counter_local, | |
9086 | + setup_apic_nmi_watchdog. | |
9087 | + | |
9088 | + * arch/i386/kernel/traps.c: New routine set_nmi_watchdog(). Call apic | |
9089 | + routines to set/clear local apic timer. | |
9090 | + | |
9091 | +2000-09-26 Keith Owens <kaos@melbourne.sgi.com> | |
9092 | + | |
9093 | + * include/linux/sysctl.h (enum): Add NMI_WATCHDOG. | |
9094 | + | |
9095 | + * arch/i386/kernel/traps.c (nmi_watchdog_tick): Check nmi_watchdog is | |
9096 | + still on. | |
9097 | + | |
9098 | + * arch/i386/config.in: Add CONFIG_UP_NMI_WATCHDOG. | |
9099 | + | |
9100 | + * Documentation/Configure.help: Add CONFIG_UP_NMI_WATCHDOG. | |
9101 | + | |
9102 | + * Documentation/nmi_watchdog.txt: Update for UP NMI watchdog. | |
9103 | + | |
9104 | +2000-09-25 Keith Owens <kaos@melbourne.sgi.com> | |
9105 | + | |
9106 | + * arch/i386/kernel/apic.c (init_apic_mappings): | |
9107 | + * arch/i386/kernel/io_apic.c (IO_APIC_init_uniprocessor): | |
9108 | + Merge Keir Fraser's local APIC for uniprocessors patch. | |
9109 | + | |
9110 | +2000-09-24 Keith Owens <kaos@melbourne.sgi.com> | |
9111 | + | |
9112 | + * Various: Declare initialization routines as __init. | |
9113 | + | |
9114 | + * Makefile: Define and export AWK. | |
9115 | + | |
9116 | + * kdb/Makefile: Generate gen-kdb_cmds.c from kdb/kdb_cmds. | |
9117 | + | |
9118 | + * kdb/kdbmain.c (kdb_init): Call new routine kdb_cmds_init to execute | |
9119 | + whatever the user put in kdb/kdb_cmds. | |
9120 | + | |
9121 | + * arch/i386/kdb/kdba_bt.c (kdba_bt_stack): New parameter to | |
9122 | + indicate if esp in regs is known to be valid or not. | |
9123 | + | |
9124 | + * kdb/kdb_bp.c, arch/i386/kdb/kdba_bp.c: More trace prints for | |
9125 | + breakpoint handling. | |
9126 | + | |
9127 | + * arch/i386/kdb/kdba_bp.c (kdba_installbp): Finally found and fixed the | |
9128 | + annoying breakpoint bug where breakpoints where not always installed | |
9129 | + after 'go'. | |
9130 | + | |
9131 | + * Documentation/kdb: Update man pages kdb.mm, kdb_env.man, kdb_ss.man. | |
9132 | + | |
9133 | + * Released as kdb-v1.5-beta1-2.4.0-test8. | |
9134 | + | |
9135 | + * Sync to 2.4.0-test9-pre6 and release as kdb-v1.5-beta1-2.4.0-test9-pre6. | |
9136 | + | |
9137 | +2000-09-23 Keith Owens <kaos@melbourne.sgi.com> | |
9138 | + | |
9139 | + * arch/i386/kdb/kdbasupport.c (kdba_getregcontents): New pseudo | |
9140 | + registers cesp and ceflags to help with debugging the debugger. | |
9141 | + | |
9142 | + * kdb/kdbmain.c (kdb_local, kdb): Add KDB_REASON_RECURSE. Add | |
9143 | + environment variable RECURSE. Add code to cope with some types of | |
9144 | + recursion. | |
9145 | + | |
9146 | + * kdb/kdbmain.c (kdb), arch/i386/kdba/kdba_bp.c: Add | |
9147 | + kdba_clearsinglestep. | |
9148 | + | |
9149 | +2000-09-22 Keith Owens <kaos@melbourne.sgi.com> | |
9150 | + | |
9151 | + * drivers/video/vgacon.c (write_vga): No cli() if kdb is running, avoid | |
9152 | + console deadlock. | |
9153 | + | |
9154 | + * arch/i386/kernel/irq.c (get_irqlock): Warn if kdb is running, may hang. | |
9155 | + | |
9156 | + * include/linux/kdb.h: Define KDB_IS_RUNNING as (0) if no CONFIG_KDB. | |
9157 | + | |
9158 | + * arch/i386/kdb/kdba_bt.c (kdba_bt_stack): Do not attempt a backtrace if | |
9159 | + the code segment is not in the kernel. | |
9160 | + | |
9161 | + * kdb/modules: Change modules from MX_OBJS to M_OBJS. Remove EXPORT_NOSYMBOLS. | |
9162 | + | |
9163 | +2000-09-21 Keith Owens <kaos@melbourne.sgi.com> | |
9164 | + | |
9165 | + * arch/i386/kernel/i386_ksyms.c: Move EXPORT_SYMBOLS for kdb to kdb/kdbmain.c. | |
9166 | + | |
9167 | + * kdb/Makefile: Change kdb/kdbmain.o from O_OBJS to OX_OBJS. | |
9168 | + | |
9169 | + * arch/i386/kernel/smp.c: Remove some #ifdef CONFIG_KDB. Remove kdbprivate.h. | |
9170 | + | |
9171 | + * include/linux/kdb.h: Add kdb_print_state. Add KDB_STATE_WAIT_IPI. | |
9172 | + | |
9173 | + * kdb/kdbmain.c (kdb): Only mark cpu as leaving if it is in KDB state. Maintain | |
9174 | + WAIT_IPI state so a cpu is only driven through NMI once. | |
9175 | + | |
9176 | + * arch/i386/kernel/smp.c (smp_kdb_stop): All state fiddling moved to kdb(). | |
9177 | + | |
9178 | +2000-09-20 Keith Owens <kaos@melbourne.sgi.com> | |
9179 | + | |
9180 | + * include/linux/kdb.h: #define kdb() as (0) if kdb is not configured. | |
9181 | + | |
9182 | + * arch/i386/kernel/traps.c: Remove some #ifdef CONFIG_KDB. | |
9183 | + | |
9184 | + * include/linux/kdbprivate.h: Move per cpu state to kdb.h. | |
9185 | + | |
9186 | + * include/linux/kdb.h: Add KDB_STATE_NO_WATCHDOG, KDB_STATE_PRINTF_LOCK. | |
9187 | + Rename KDB_DEBUG_xxx to KDB_DEBUG_FLAG_xxx. Clean up debug flag | |
9188 | + definitions. | |
9189 | + | |
9190 | + * arch/i386/kernel/traps.c (nmi_watchdog_tick): Check no watchdog. | |
9191 | + | |
9192 | + * kdb/kdbmain.c (kdb): Set no watchdog in normal kdb code. | |
9193 | + | |
9194 | + * kdb/kdbmain.c (kdb_parse): Allow watchdog in commands. | |
9195 | + | |
9196 | + * kdb/kdb_io.c (kdb_printf): No watchdog during printing. Clean up lock handling. | |
9197 | + | |
9198 | + * kdb/kdbmain.c (kdb_set): Clean up debug flag handling. | |
9199 | + | |
9200 | +2000-09-19 Juan J. Quintela <quintela@fi.udc.es> | |
9201 | + | |
9202 | + * kdb/arch/i386/kdb/kdba_io.c: Allow kdb to compile without CONFIG_VT and/or | |
9203 | + serial console. | |
9204 | + | |
9205 | +2000-09-19 Keith Owens <kaos@melbourne.sgi.com> | |
9206 | + | |
9207 | + * include/linux/kdb.h: Define KDB_DEBUG_STATE(). | |
9208 | + | |
9209 | + * kdb/kdbmain.c (kdb): Add kdb_print_state(), calls to KDB_DEBUG_STATE(). | |
9210 | + | |
9211 | +2000-09-16 Keith Owens <kaos@melbourne.sgi.com> | |
9212 | + | |
9213 | + * Move to finer grained control over individual processors in kdb with | |
9214 | + per cpu kdb state. Needed to allow ss[b] to only release one processor, | |
9215 | + previously ss[b] released all processors. Also need to recover from | |
9216 | + errors inside kdb commands, e.g. oops in kdbm_pg code. | |
9217 | + | |
9218 | + * various: | |
9219 | + Move global flags KDB_FLAG_SSB, KDB_FLAG_SUPRESS, KDB_FLAG_FAULT, | |
9220 | + KDB_FLAG_SS, KDB_FLAG_SSBPT, kdb_active, to per cpu state and macros | |
9221 | + KDB_STATE(xxx). | |
9222 | + Replace kdb_flags & KDB_FLAG_xxx with KDB_FLAG(xxx). | |
9223 | + Replace kdb_flags & KDB_DEBUG_xxx with KDB_DEBUG(xxx). | |
9224 | + Replace specific tests with wrapper KDB_IS_RUNNING(). | |
9225 | + | |
9226 | + * various: Remove #ifdef CONFIG_SMP from kdb code wherever | |
9227 | + possible. Simplifies the code and makes it much more readable. | |
9228 | + | |
9229 | + * arch/i386/kdb/kdbasupport.c (kdb_setjmp): Record if we have reliable | |
9230 | + longjmp data instead of assuming it is always set. | |
9231 | + | |
9232 | + * various: Replace smp_kdb_wait with per cpu state, HOLD_CPU. | |
9233 | + | |
9234 | + * init/main.c : Replace #ifdef KDB_DEBUG with KDB_DEBUG(CALLBACK). | |
9235 | + | |
9236 | + * include/linux/kdbprivate.h: Separate command return codes from error | |
9237 | + codes. Add more detailed command codes. | |
9238 | + | |
9239 | + * arch/i386/kernel/traps.c (die): Change spin_lock_irq to | |
9240 | + spin_lock_irqsave. Why did I do this? | |
9241 | + | |
9242 | + * kdb/kdbmain.c (kdb_parse): Set per cpu flag CMD before executing kdb | |
9243 | + command. More detailed return codes for commands that affect | |
9244 | + processors. | |
9245 | + | |
9246 | + * kdb/kdbmain.c (kdb_previous_event): New, check if any processors are | |
9247 | + still executing the previous kdb event. Removes a race window where a | |
9248 | + second event could enter kdb before the first had completely ended. | |
9249 | + | |
9250 | + * kdb/kdbmain.c (kdb): Document all the concurrency conditions and how | |
9251 | + kdb handles them. ss[b] now releases only the current cpu. Do not set | |
9252 | + breakpoints when releasing for ss[b]. Recover from errors in kdb | |
9253 | + commands. Check that we have reliable longjmp data before using it. | |
9254 | + | |
9255 | + * various: Update return code documentation. | |
9256 | + | |
9257 | + * kdb/kdb_bp.c (kdb_ss): Separate ss and ssb return codes. | |
9258 | + | |
9259 | + * kdb/kdbsupport.c (kdb_ipi): Finer grained algorithm for deciding | |
9260 | + whether to call send a stop signal to a cpu. | |
9261 | + | |
9262 | + * arch/i386/kdb/kdba_bp.c (kdba_db_trap): Separate ss and ssb return | |
9263 | + codes. Reinstall delayed software breakpoints per cpu instead of | |
9264 | + globally. Changed algorithm for handling ss[b]. | |
9265 | + | |
9266 | + * arch/i386/kdb/kdba_bp.c (kdba_bp_trap): Match software breakpoints per | |
9267 | + cpu instead of globally. | |
9268 | + | |
9269 | + * include/linux/kdb.h: Bump version to kdb v1.5. | |
9270 | + | |
9271 | +2000-09-16 Keith Owens <kaos@melbourne.sgi.com> | |
9272 | + | |
9273 | + * kernel/sysctl.c (kern_table): add /proc/sys/kernel/kdb. | |
9274 | + | |
9275 | + * init/main.c (parse_options): add boot flags kdb=on, kdb=off, | |
9276 | + kdb=early. | |
9277 | + | |
9278 | + * include/linux/sysctl.h (enum): add KERN_KDB. | |
9279 | + | |
9280 | + * drivers/char/serial.c (receive_chars): check kdb_on. | |
9281 | + | |
9282 | + * drivers/char/keyboard.c (handle_scancode): check kdb_on. | |
9283 | + | |
9284 | + * arch/i386/kernel/traps.c (nmi_watchdog_tick): check kdb_on. | |
9285 | + | |
9286 | + * arch/i386/config.in: add CONFIG_KDB_OFF. | |
9287 | + | |
9288 | + * Documentation/Configure.help: add CONFIG_KDB_OFF. | |
9289 | + | |
9290 | + * kdb/kdbmain.c: add kdb_initial_cpu, kdb_on. | |
9291 | + | |
9292 | + * kdb/kdbmain.c (kdb): check kdb_on, set kdb_initial_cpu. | |
9293 | + | |
9294 | + * kdb/kdbmain.c (kdb_init): add Keith Owens to kdb banner. | |
9295 | + | |
9296 | + * kdb/kdb_io.c (kdb_printf): serialize kdb_printf output. | |
9297 | + | |
9298 | + * kdb/kdb_bt.c (kdb_bt): check environment variable BTAPROMPT. | |
9299 | + | |
9300 | + * kdb/kdbsupport.c (kdb_ipi): ignore NMI for kdb_initial_cpu. | |
9301 | + | |
9302 | + * kdb/modules/kdbm_pg.c (kdbm_page): merge updates from 2.4.0-test5-xfs. | |
9303 | + | |
9304 | + * kdb/kdb_bt.man: add btp, bta, BTAPROMPT. | |
9305 | + | |
9306 | + * kdb/kdb.mm: add CONFIG_KDB_OFF, boot flags, btp, bta. | |
9307 | + | |
9308 | + * include/linux/kdbprivate.h: add kdb_initial_cpu. | |
9309 | + | |
9310 | + * include/linux/kdb.h: add kdb_on, bump version to kdb v1.4. | |
9311 | --- /dev/null | |
9312 | +++ b/kdb/Makefile | |
9313 | @@ -0,0 +1,43 @@ | |
9314 | +# | |
9315 | +# This file is subject to the terms and conditions of the GNU General Public | |
9316 | +# License. See the file "COPYING" in the main directory of this archive | |
9317 | +# for more details. | |
9318 | +# | |
9319 | +# Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved. | |
9320 | +# | |
9321 | + | |
9322 | +CCVERSION := $(shell $(CC) -v 2>&1 | sed -ne '$$p') | |
9323 | +obj-y := kdb_bt.o kdb_bp.o kdb_id.o kdbsupport.o gen-kdb_cmds.o kdbmain.o kdb_io.o kdbdereference.o | |
9324 | +CFLAGS_kdbmain.o += -DCCVERSION="$(CCVERSION)" | |
9325 | + | |
9326 | +subdir-$(CONFIG_KDB_MODULES) := modules | |
9327 | +obj-y += $(addsuffix /built-in.o, $(subdir-y)) | |
9328 | + | |
9329 | +clean-files := gen-kdb_cmds.c | |
9330 | + | |
9331 | +override CFLAGS := $(CFLAGS:%-pg=% ) | |
9332 | + | |
9333 | +# define architecture dependent kdb_cmds | |
9334 | +ifeq ($(CONFIG_IA64),y) | |
9335 | + KDB_CMDS = ia64/kdb/kdb_cmds | |
9336 | +else | |
9337 | + ifeq ($(CONFIG_X86_64),y) | |
9338 | + KDB_CMDS = x86/kdb/kdb_cmds_64 | |
9339 | + else | |
9340 | + ifeq ($(CONFIG_X86_32),y) | |
9341 | + KDB_CMDS = x86/kdb/kdb_cmds_32 | |
9342 | + endif | |
9343 | + endif | |
9344 | +endif | |
9345 | + | |
9346 | +quiet_cmd_gen-kdb = GENKDB $@ | |
9347 | + cmd_gen-kdb = $(AWK) 'BEGIN {print "\#include <linux/stddef.h>"; print "\#include <linux/init.h>"} \ | |
9348 | + /^\#/{next} \ | |
9349 | + /^[ \t]*$$/{next} \ | |
9350 | + {gsub(/"/, "\\\"", $$0); \ | |
9351 | + print "static __initdata char kdb_cmd" cmds++ "[] = \"" $$0 "\\n\";"} \ | |
9352 | + END {print "extern char *kdb_cmds[]; char __initdata *kdb_cmds[] = {"; for (i = 0; i < cmds; ++i) {print " kdb_cmd" i ","}; print(" NULL\n};");}' \ | |
9353 | + $(filter-out %/Makefile,$^) > $@ | |
9354 | + | |
9355 | +$(obj)/gen-kdb_cmds.c: $(src)/kdb_cmds $(wildcard $(TOPDIR)/arch/$(KDB_CMDS)) $(src)/Makefile | |
9356 | + $(call cmd,gen-kdb) | |
9357 | --- /dev/null | |
9358 | +++ b/kdb/kdb_bp.c | |
9359 | @@ -0,0 +1,658 @@ | |
9360 | +/* | |
9361 | + * Kernel Debugger Architecture Independent Breakpoint Handler | |
9362 | + * | |
9363 | + * This file is subject to the terms and conditions of the GNU General Public | |
9364 | + * License. See the file "COPYING" in the main directory of this archive | |
9365 | + * for more details. | |
9366 | + * | |
9367 | + * Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved. | |
9368 | + */ | |
9369 | + | |
9370 | +#include <linux/string.h> | |
9371 | +#include <linux/kernel.h> | |
9372 | +#include <linux/init.h> | |
9373 | +#include <linux/kdb.h> | |
9374 | +#include <linux/kdbprivate.h> | |
9375 | +#include <linux/smp.h> | |
9376 | +#include <linux/sched.h> | |
9377 | +#include <linux/interrupt.h> | |
9378 | +#include <asm/system.h> | |
9379 | + | |
9380 | +/* | |
9381 | + * Table of kdb_breakpoints | |
9382 | + */ | |
9383 | +kdb_bp_t kdb_breakpoints[KDB_MAXBPT]; | |
9384 | + | |
9385 | +/* | |
9386 | + * Predicate to test whether a breakpoint should be installed | |
9387 | + * on this CPU. | |
9388 | + * | |
9389 | + * Note that for purposes of installation, hardware breakpoints | |
9390 | + * are treated as local (even if the global flag is set), on | |
9391 | + * the assumption that the require per-cpu registers to be set. | |
9392 | + */ | |
9393 | + | |
9394 | +static inline int kdb_is_installable_global_bp(const kdb_bp_t *bp) | |
9395 | +{ | |
9396 | + return (bp->bp_enabled && | |
9397 | + bp->bp_global && | |
9398 | + !bp->bp_forcehw); | |
9399 | +} | |
9400 | + | |
9401 | +static int kdb_is_installable_local_bp(const kdb_bp_t *bp) | |
9402 | +{ | |
9403 | + if (!bp->bp_enabled) | |
9404 | + return 0; | |
9405 | + | |
9406 | + if (bp->bp_forcehw) { | |
9407 | + if (bp->bp_cpu == smp_processor_id() || bp->bp_global) | |
9408 | + return 1; | |
9409 | + } else { | |
9410 | + if (bp->bp_cpu == smp_processor_id() && !bp->bp_global) | |
9411 | + return 1; | |
9412 | + } | |
9413 | + return 0; | |
9414 | +} | |
9415 | + | |
9416 | +/* | |
9417 | + * kdb_bp_install_global | |
9418 | + * | |
9419 | + * Install global kdb_breakpoints prior to returning from the | |
9420 | + * kernel debugger. This allows the kdb_breakpoints to be set | |
9421 | + * upon functions that are used internally by kdb, such as | |
9422 | + * printk(). | |
9423 | + * | |
9424 | + * Parameters: | |
9425 | + * regs Execution frame. | |
9426 | + * Outputs: | |
9427 | + * None. | |
9428 | + * Returns: | |
9429 | + * None. | |
9430 | + * Locking: | |
9431 | + * None. | |
9432 | + * Remarks: | |
9433 | + * | |
9434 | + * This function is only called once per kdb session. | |
9435 | + */ | |
9436 | + | |
9437 | +void | |
9438 | +kdb_bp_install_global(struct pt_regs *regs) | |
9439 | +{ | |
9440 | + int i; | |
9441 | + | |
9442 | + for(i=0; i<KDB_MAXBPT; i++) { | |
9443 | + kdb_bp_t *bp = &kdb_breakpoints[i]; | |
9444 | + | |
9445 | + if (KDB_DEBUG(BP)) { | |
9446 | + kdb_printf("kdb_bp_install_global bp %d bp_enabled %d bp_global %d\n", | |
9447 | + i, bp->bp_enabled, bp->bp_global); | |
9448 | + } | |
9449 | + /* HW BP local or global are installed in kdb_bp_install_local*/ | |
9450 | + if (kdb_is_installable_global_bp(bp)) | |
9451 | + kdba_installbp(regs, bp); | |
9452 | + } | |
9453 | +} | |
9454 | + | |
9455 | +/* | |
9456 | + * kdb_bp_install_local | |
9457 | + * | |
9458 | + * Install local kdb_breakpoints prior to returning from the | |
9459 | + * kernel debugger. This allows the kdb_breakpoints to be set | |
9460 | + * upon functions that are used internally by kdb, such as | |
9461 | + * printk(). | |
9462 | + * | |
9463 | + * Parameters: | |
9464 | + * regs Execution frame. | |
9465 | + * Outputs: | |
9466 | + * None. | |
9467 | + * Returns: | |
9468 | + * None. | |
9469 | + * Locking: | |
9470 | + * None. | |
9471 | + * Remarks: | |
9472 | + * | |
9473 | + * This function is called once per processor. | |
9474 | + */ | |
9475 | + | |
9476 | +void | |
9477 | +kdb_bp_install_local(struct pt_regs *regs) | |
9478 | +{ | |
9479 | + int i; | |
9480 | + | |
9481 | + for(i=0; i<KDB_MAXBPT; i++) { | |
9482 | + kdb_bp_t *bp = &kdb_breakpoints[i]; | |
9483 | + | |
9484 | + if (KDB_DEBUG(BP)) { | |
9485 | + kdb_printf("kdb_bp_install_local bp %d bp_enabled %d bp_global %d cpu %d bp_cpu %d\n", | |
9486 | + i, bp->bp_enabled, bp->bp_global, | |
9487 | + smp_processor_id(), bp->bp_cpu); | |
9488 | + } | |
9489 | + if (kdb_is_installable_local_bp(bp)) | |
9490 | + kdba_installbp(regs, bp); | |
9491 | + } | |
9492 | +} | |
9493 | + | |
9494 | +/* | |
9495 | + * kdb_bp_remove_global | |
9496 | + * | |
9497 | + * Remove global kdb_breakpoints upon entry to the kernel debugger. | |
9498 | + * | |
9499 | + * Parameters: | |
9500 | + * None. | |
9501 | + * Outputs: | |
9502 | + * None. | |
9503 | + * Returns: | |
9504 | + * None. | |
9505 | + * Locking: | |
9506 | + * None. | |
9507 | + * Remarks: | |
9508 | + */ | |
9509 | + | |
9510 | +void | |
9511 | +kdb_bp_remove_global(void) | |
9512 | +{ | |
9513 | + int i; | |
9514 | + | |
9515 | + for(i=KDB_MAXBPT-1; i>=0; i--) { | |
9516 | + kdb_bp_t *bp = &kdb_breakpoints[i]; | |
9517 | + | |
9518 | + if (KDB_DEBUG(BP)) { | |
9519 | + kdb_printf("kdb_bp_remove_global bp %d bp_enabled %d bp_global %d\n", | |
9520 | + i, bp->bp_enabled, bp->bp_global); | |
9521 | + } | |
9522 | + if (kdb_is_installable_global_bp(bp)) | |
9523 | + kdba_removebp(bp); | |
9524 | + } | |
9525 | +} | |
9526 | + | |
9527 | + | |
9528 | +/* | |
9529 | + * kdb_bp_remove_local | |
9530 | + * | |
9531 | + * Remove local kdb_breakpoints upon entry to the kernel debugger. | |
9532 | + * | |
9533 | + * Parameters: | |
9534 | + * None. | |
9535 | + * Outputs: | |
9536 | + * None. | |
9537 | + * Returns: | |
9538 | + * None. | |
9539 | + * Locking: | |
9540 | + * None. | |
9541 | + * Remarks: | |
9542 | + */ | |
9543 | + | |
9544 | +void | |
9545 | +kdb_bp_remove_local(void) | |
9546 | +{ | |
9547 | + int i; | |
9548 | + | |
9549 | + for(i=KDB_MAXBPT-1; i>=0; i--) { | |
9550 | + kdb_bp_t *bp = &kdb_breakpoints[i]; | |
9551 | + | |
9552 | + if (KDB_DEBUG(BP)) { | |
9553 | + kdb_printf("kdb_bp_remove_local bp %d bp_enabled %d bp_global %d cpu %d bp_cpu %d\n", | |
9554 | + i, bp->bp_enabled, bp->bp_global, | |
9555 | + smp_processor_id(), bp->bp_cpu); | |
9556 | + } | |
9557 | + if (kdb_is_installable_local_bp(bp)) | |
9558 | + kdba_removebp(bp); | |
9559 | + } | |
9560 | +} | |
9561 | + | |
9562 | +/* | |
9563 | + * kdb_printbp | |
9564 | + * | |
9565 | + * Internal function to format and print a breakpoint entry. | |
9566 | + * | |
9567 | + * Parameters: | |
9568 | + * None. | |
9569 | + * Outputs: | |
9570 | + * None. | |
9571 | + * Returns: | |
9572 | + * None. | |
9573 | + * Locking: | |
9574 | + * None. | |
9575 | + * Remarks: | |
9576 | + */ | |
9577 | + | |
9578 | +static void | |
9579 | +kdb_printbp(kdb_bp_t *bp, int i) | |
9580 | +{ | |
9581 | + if (bp->bp_forcehw) { | |
9582 | + kdb_printf("Forced "); | |
9583 | + } | |
9584 | + | |
9585 | + if (!bp->bp_template.bph_free) { | |
9586 | + kdb_printf("%s ", kdba_bptype(&bp->bp_template)); | |
9587 | + } else { | |
9588 | + kdb_printf("Instruction(i) "); | |
9589 | + } | |
9590 | + | |
9591 | + kdb_printf("BP #%d at ", i); | |
9592 | + kdb_symbol_print(bp->bp_addr, NULL, KDB_SP_DEFAULT); | |
9593 | + | |
9594 | + if (bp->bp_enabled) { | |
9595 | + kdba_printbp(bp); | |
9596 | + if (bp->bp_global) | |
9597 | + kdb_printf(" globally"); | |
9598 | + else | |
9599 | + kdb_printf(" on cpu %d", bp->bp_cpu); | |
9600 | + if (bp->bp_adjust) | |
9601 | + kdb_printf(" adjust %d", bp->bp_adjust); | |
9602 | + } else { | |
9603 | + kdb_printf("\n is disabled"); | |
9604 | + } | |
9605 | + | |
9606 | + kdb_printf("\taddr at %016lx, hardtype=%d, forcehw=%d, installed=%d, hard=%p\n", | |
9607 | + bp->bp_addr, bp->bp_hardtype, bp->bp_forcehw, | |
9608 | + bp->bp_installed, bp->bp_hard); | |
9609 | + | |
9610 | + kdb_printf("\n"); | |
9611 | +} | |
9612 | + | |
9613 | +/* | |
9614 | + * kdb_bp | |
9615 | + * | |
9616 | + * Handle the bp, and bpa commands. | |
9617 | + * | |
9618 | + * [bp|bpa|bph] <addr-expression> [DATAR|DATAW|IO [length]] | |
9619 | + * | |
9620 | + * Parameters: | |
9621 | + * argc Count of arguments in argv | |
9622 | + * argv Space delimited command line arguments | |
9623 | + * Outputs: | |
9624 | + * None. | |
9625 | + * Returns: | |
9626 | + * Zero for success, a kdb diagnostic if failure. | |
9627 | + * Locking: | |
9628 | + * None. | |
9629 | + * Remarks: | |
9630 | + * | |
9631 | + * bp Set breakpoint. Only use hardware assist if necessary. | |
9632 | + * bpa Set breakpoint on all cpus, only use hardware regs if necessary | |
9633 | + * bph Set breakpoint - force hardware register | |
9634 | + * bpha Set breakpoint on all cpus, force hardware register | |
9635 | + */ | |
9636 | + | |
9637 | +static int | |
9638 | +kdb_bp(int argc, const char **argv) | |
9639 | +{ | |
9640 | + int i, bpno; | |
9641 | + kdb_bp_t *bp, *bp_check; | |
9642 | + int diag; | |
9643 | + int free; | |
9644 | + char *symname = NULL; | |
9645 | + long offset = 0ul; | |
9646 | + int nextarg; | |
9647 | + kdb_bp_t template = {0}; | |
9648 | + | |
9649 | + if (argc == 0) { | |
9650 | + /* | |
9651 | + * Display breakpoint table | |
9652 | + */ | |
9653 | + for(bpno=0,bp=kdb_breakpoints; bpno<KDB_MAXBPT; bpno++, bp++) { | |
9654 | + if (bp->bp_free) continue; | |
9655 | + | |
9656 | + kdb_printbp(bp, bpno); | |
9657 | + } | |
9658 | + | |
9659 | + return 0; | |
9660 | + } | |
9661 | + | |
9662 | + template.bp_global = ((strcmp(argv[0], "bpa") == 0) | |
9663 | + || (strcmp(argv[0], "bpha") == 0)); | |
9664 | + template.bp_forcehw = ((strcmp(argv[0], "bph") == 0) | |
9665 | + || (strcmp(argv[0], "bpha") == 0)); | |
9666 | + | |
9667 | + /* Fix me: "bp" is treated as "bpa" to avoid system freeze. -jlan */ | |
9668 | + if (strcmp(argv[0], "bp") == 0) | |
9669 | + template.bp_global = 1; | |
9670 | + | |
9671 | + nextarg = 1; | |
9672 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &template.bp_addr, | |
9673 | + &offset, &symname); | |
9674 | + if (diag) | |
9675 | + return diag; | |
9676 | + if (!template.bp_addr) | |
9677 | + return KDB_BADINT; | |
9678 | + | |
9679 | + /* | |
9680 | + * Find an empty bp structure, to allocate | |
9681 | + */ | |
9682 | + free = KDB_MAXBPT; | |
9683 | + for(bpno=0,bp=kdb_breakpoints; bpno<KDB_MAXBPT; bpno++,bp++) { | |
9684 | + if (bp->bp_free) { | |
9685 | + break; | |
9686 | + } | |
9687 | + } | |
9688 | + | |
9689 | + if (bpno == KDB_MAXBPT) | |
9690 | + return KDB_TOOMANYBPT; | |
9691 | + | |
9692 | + /* | |
9693 | + * Handle architecture dependent parsing | |
9694 | + */ | |
9695 | + diag = kdba_parsebp(argc, argv, &nextarg, &template); | |
9696 | + if (diag) { | |
9697 | + return diag; | |
9698 | + } | |
9699 | + | |
9700 | + | |
9701 | + /* | |
9702 | + * Check for clashing breakpoints. | |
9703 | + * | |
9704 | + * Note, in this design we can't have hardware breakpoints | |
9705 | + * enabled for both read and write on the same address, even | |
9706 | + * though ia64 allows this. | |
9707 | + */ | |
9708 | + for(i=0,bp_check=kdb_breakpoints; i<KDB_MAXBPT; i++,bp_check++) { | |
9709 | + if (!bp_check->bp_free && | |
9710 | + bp_check->bp_addr == template.bp_addr && | |
9711 | + (bp_check->bp_global || | |
9712 | + bp_check->bp_cpu == template.bp_cpu)) { | |
9713 | + kdb_printf("You already have a breakpoint at " kdb_bfd_vma_fmt0 "\n", template.bp_addr); | |
9714 | + return KDB_DUPBPT; | |
9715 | + } | |
9716 | + } | |
9717 | + | |
9718 | + template.bp_enabled = 1; | |
9719 | + | |
9720 | + /* | |
9721 | + * Actually allocate the breakpoint found earlier | |
9722 | + */ | |
9723 | + *bp = template; | |
9724 | + bp->bp_free = 0; | |
9725 | + | |
9726 | + if (!bp->bp_global) { | |
9727 | + bp->bp_cpu = smp_processor_id(); | |
9728 | + } | |
9729 | + | |
9730 | + /* | |
9731 | + * Allocate a hardware breakpoint. If one is not available, | |
9732 | + * disable the breakpoint, but leave it in the breakpoint | |
9733 | + * table. When the breakpoint is re-enabled (via 'be'), we'll | |
9734 | + * attempt to allocate a hardware register for it. | |
9735 | + */ | |
9736 | + if (!bp->bp_template.bph_free) { | |
9737 | + kdba_alloc_hwbp(bp, &diag); | |
9738 | + if (diag) { | |
9739 | + bp->bp_enabled = 0; | |
9740 | + bp->bp_hardtype = 0; | |
9741 | + kdba_free_hwbp(bp); | |
9742 | + return diag; | |
9743 | + } | |
9744 | + } | |
9745 | + | |
9746 | + kdb_printbp(bp, bpno); | |
9747 | + | |
9748 | + return 0; | |
9749 | +} | |
9750 | + | |
9751 | +/* | |
9752 | + * kdb_bc | |
9753 | + * | |
9754 | + * Handles the 'bc', 'be', and 'bd' commands | |
9755 | + * | |
9756 | + * [bd|bc|be] <breakpoint-number> | |
9757 | + * [bd|bc|be] * | |
9758 | + * | |
9759 | + * Parameters: | |
9760 | + * argc Count of arguments in argv | |
9761 | + * argv Space delimited command line arguments | |
9762 | + * Outputs: | |
9763 | + * None. | |
9764 | + * Returns: | |
9765 | + * Zero for success, a kdb diagnostic for failure | |
9766 | + * Locking: | |
9767 | + * None. | |
9768 | + * Remarks: | |
9769 | + */ | |
9770 | + | |
9771 | +#define KDBCMD_BC 0 | |
9772 | +#define KDBCMD_BE 1 | |
9773 | +#define KDBCMD_BD 2 | |
9774 | + | |
9775 | +static int | |
9776 | +kdb_bc(int argc, const char **argv) | |
9777 | +{ | |
9778 | + kdb_machreg_t addr; | |
9779 | + kdb_bp_t *bp = NULL; | |
9780 | + int lowbp = KDB_MAXBPT; | |
9781 | + int highbp = 0; | |
9782 | + int done = 0; | |
9783 | + int i; | |
9784 | + int diag; | |
9785 | + int cmd; /* KDBCMD_B? */ | |
9786 | + | |
9787 | + if (strcmp(argv[0], "be") == 0) { | |
9788 | + cmd = KDBCMD_BE; | |
9789 | + } else if (strcmp(argv[0], "bd") == 0) { | |
9790 | + cmd = KDBCMD_BD; | |
9791 | + } else | |
9792 | + cmd = KDBCMD_BC; | |
9793 | + | |
9794 | + if (argc != 1) | |
9795 | + return KDB_ARGCOUNT; | |
9796 | + | |
9797 | + if (strcmp(argv[1], "*") == 0) { | |
9798 | + lowbp = 0; | |
9799 | + highbp = KDB_MAXBPT; | |
9800 | + } else { | |
9801 | + diag = kdbgetularg(argv[1], &addr); | |
9802 | + if (diag) | |
9803 | + return diag; | |
9804 | + | |
9805 | + /* | |
9806 | + * For addresses less than the maximum breakpoint number, | |
9807 | + * assume that the breakpoint number is desired. | |
9808 | + */ | |
9809 | + if (addr < KDB_MAXBPT) { | |
9810 | + bp = &kdb_breakpoints[addr]; | |
9811 | + lowbp = highbp = addr; | |
9812 | + highbp++; | |
9813 | + } else { | |
9814 | + for(i=0, bp=kdb_breakpoints; i<KDB_MAXBPT; i++, bp++) { | |
9815 | + if (bp->bp_addr == addr) { | |
9816 | + lowbp = highbp = i; | |
9817 | + highbp++; | |
9818 | + break; | |
9819 | + } | |
9820 | + } | |
9821 | + } | |
9822 | + } | |
9823 | + | |
9824 | + /* | |
9825 | + * Now operate on the set of breakpoints matching the input | |
9826 | + * criteria (either '*' for all, or an individual breakpoint). | |
9827 | + */ | |
9828 | + for(bp=&kdb_breakpoints[lowbp], i=lowbp; | |
9829 | + i < highbp; | |
9830 | + i++, bp++) { | |
9831 | + if (bp->bp_free) | |
9832 | + continue; | |
9833 | + | |
9834 | + done++; | |
9835 | + | |
9836 | + switch (cmd) { | |
9837 | + case KDBCMD_BC: | |
9838 | + if (bp->bp_hardtype) | |
9839 | + kdba_free_hwbp(bp); | |
9840 | + | |
9841 | + bp->bp_enabled = 0; | |
9842 | + bp->bp_global = 0; | |
9843 | + | |
9844 | + kdb_printf("Breakpoint %d at " kdb_bfd_vma_fmt " cleared\n", | |
9845 | + i, bp->bp_addr); | |
9846 | + | |
9847 | + bp->bp_addr = 0; | |
9848 | + bp->bp_free = 1; | |
9849 | + | |
9850 | + break; | |
9851 | + case KDBCMD_BE: | |
9852 | + /* | |
9853 | + * Allocate a hardware breakpoint. If one is not | |
9854 | + * available, don't enable the breakpoint. | |
9855 | + */ | |
9856 | + if (!bp->bp_template.bph_free | |
9857 | + && !bp->bp_hardtype) { | |
9858 | + kdba_alloc_hwbp(bp, &diag); | |
9859 | + if (diag) { | |
9860 | + bp->bp_enabled = 0; | |
9861 | + bp->bp_hardtype = 0; | |
9862 | + kdba_free_hwbp(bp); | |
9863 | + return diag; | |
9864 | + } | |
9865 | + } | |
9866 | + | |
9867 | + bp->bp_enabled = 1; | |
9868 | + | |
9869 | + kdb_printf("Breakpoint %d at " kdb_bfd_vma_fmt " enabled", | |
9870 | + i, bp->bp_addr); | |
9871 | + | |
9872 | + kdb_printf("\n"); | |
9873 | + break; | |
9874 | + case KDBCMD_BD: | |
9875 | + if (!bp->bp_enabled) | |
9876 | + break; | |
9877 | + | |
9878 | + /* | |
9879 | + * Since this breakpoint is now disabled, we can | |
9880 | + * give up the hardware register which is allocated | |
9881 | + * to it. | |
9882 | + */ | |
9883 | + if (bp->bp_hardtype) | |
9884 | + kdba_free_hwbp(bp); | |
9885 | + | |
9886 | + bp->bp_enabled = 0; | |
9887 | + | |
9888 | + kdb_printf("Breakpoint %d at " kdb_bfd_vma_fmt " disabled\n", | |
9889 | + i, bp->bp_addr); | |
9890 | + | |
9891 | + break; | |
9892 | + } | |
9893 | + if (bp->bp_delay && (cmd == KDBCMD_BC || cmd == KDBCMD_BD)) { | |
9894 | + bp->bp_delay = 0; | |
9895 | + KDB_STATE_CLEAR(SSBPT); | |
9896 | + } | |
9897 | + } | |
9898 | + | |
9899 | + return (!done)?KDB_BPTNOTFOUND:0; | |
9900 | +} | |
9901 | + | |
9902 | +/* | |
9903 | + * kdb_ss | |
9904 | + * | |
9905 | + * Process the 'ss' (Single Step) and 'ssb' (Single Step to Branch) | |
9906 | + * commands. | |
9907 | + * | |
9908 | + * ss | |
9909 | + * ssb | |
9910 | + * | |
9911 | + * Parameters: | |
9912 | + * argc Argument count | |
9913 | + * argv Argument vector | |
9914 | + * Outputs: | |
9915 | + * None. | |
9916 | + * Returns: | |
9917 | + * KDB_CMD_SS[B] for success, a kdb error if failure. | |
9918 | + * Locking: | |
9919 | + * None. | |
9920 | + * Remarks: | |
9921 | + * | |
9922 | + * Set the arch specific option to trigger a debug trap after the next | |
9923 | + * instruction. | |
9924 | + * | |
9925 | + * For 'ssb', set the trace flag in the debug trap handler | |
9926 | + * after printing the current insn and return directly without | |
9927 | + * invoking the kdb command processor, until a branch instruction | |
9928 | + * is encountered. | |
9929 | + */ | |
9930 | + | |
9931 | +static int | |
9932 | +kdb_ss(int argc, const char **argv) | |
9933 | +{ | |
9934 | + int ssb = 0; | |
9935 | + struct pt_regs *regs = get_irq_regs(); | |
9936 | + | |
9937 | + ssb = (strcmp(argv[0], "ssb") == 0); | |
9938 | + if (argc != 0) | |
9939 | + return KDB_ARGCOUNT; | |
9940 | + | |
9941 | + if (!regs) { | |
9942 | + kdb_printf("%s: pt_regs not available\n", __FUNCTION__); | |
9943 | + return KDB_BADREG; | |
9944 | + } | |
9945 | + | |
9946 | + /* | |
9947 | + * Set trace flag and go. | |
9948 | + */ | |
9949 | + KDB_STATE_SET(DOING_SS); | |
9950 | + if (ssb) | |
9951 | + KDB_STATE_SET(DOING_SSB); | |
9952 | + | |
9953 | + kdba_setsinglestep(regs); /* Enable single step */ | |
9954 | + | |
9955 | + if (ssb) | |
9956 | + return KDB_CMD_SSB; | |
9957 | + return KDB_CMD_SS; | |
9958 | +} | |
9959 | + | |
9960 | +/* | |
9961 | + * kdb_initbptab | |
9962 | + * | |
9963 | + * Initialize the breakpoint table. Register breakpoint commands. | |
9964 | + * | |
9965 | + * Parameters: | |
9966 | + * None. | |
9967 | + * Outputs: | |
9968 | + * None. | |
9969 | + * Returns: | |
9970 | + * None. | |
9971 | + * Locking: | |
9972 | + * None. | |
9973 | + * Remarks: | |
9974 | + */ | |
9975 | + | |
9976 | +void __init | |
9977 | +kdb_initbptab(void) | |
9978 | +{ | |
9979 | + int i; | |
9980 | + kdb_bp_t *bp; | |
9981 | + | |
9982 | + /* | |
9983 | + * First time initialization. | |
9984 | + */ | |
9985 | + memset(&kdb_breakpoints, '\0', sizeof(kdb_breakpoints)); | |
9986 | + | |
9987 | + for (i=0, bp=kdb_breakpoints; i<KDB_MAXBPT; i++, bp++) { | |
9988 | + bp->bp_free = 1; | |
9989 | + /* | |
9990 | + * The bph_free flag is architecturally required. It | |
9991 | + * is set by architecture-dependent code to false (zero) | |
9992 | + * in the event a hardware breakpoint register is required | |
9993 | + * for this breakpoint. | |
9994 | + * | |
9995 | + * The rest of the template is reserved to the architecture | |
9996 | + * dependent code and _must_ not be touched by the architecture | |
9997 | + * independent code. | |
9998 | + */ | |
9999 | + bp->bp_template.bph_free = 1; | |
10000 | + } | |
10001 | + | |
10002 | + kdb_register_repeat("bp", kdb_bp, "[<vaddr>]", "Set/Display breakpoints", 0, KDB_REPEAT_NO_ARGS); | |
10003 | + kdb_register_repeat("bl", kdb_bp, "[<vaddr>]", "Display breakpoints", 0, KDB_REPEAT_NO_ARGS); | |
10004 | + kdb_register_repeat("bpa", kdb_bp, "[<vaddr>]", "Set/Display global breakpoints", 0, KDB_REPEAT_NO_ARGS); | |
10005 | + kdb_register_repeat("bph", kdb_bp, "[<vaddr>]", "Set hardware breakpoint", 0, KDB_REPEAT_NO_ARGS); | |
10006 | + kdb_register_repeat("bpha", kdb_bp, "[<vaddr>]", "Set global hardware breakpoint", 0, KDB_REPEAT_NO_ARGS); | |
10007 | + kdb_register_repeat("bc", kdb_bc, "<bpnum>", "Clear Breakpoint", 0, KDB_REPEAT_NONE); | |
10008 | + kdb_register_repeat("be", kdb_bc, "<bpnum>", "Enable Breakpoint", 0, KDB_REPEAT_NONE); | |
10009 | + kdb_register_repeat("bd", kdb_bc, "<bpnum>", "Disable Breakpoint", 0, KDB_REPEAT_NONE); | |
10010 | + | |
10011 | + kdb_register_repeat("ss", kdb_ss, "", "Single Step", 1, KDB_REPEAT_NO_ARGS); | |
10012 | + kdb_register_repeat("ssb", kdb_ss, "", "Single step to branch/call", 0, KDB_REPEAT_NO_ARGS); | |
10013 | + /* | |
10014 | + * Architecture dependent initialization. | |
10015 | + */ | |
10016 | + kdba_initbp(); | |
10017 | +} | |
10018 | --- /dev/null | |
10019 | +++ b/kdb/kdb_bt.c | |
10020 | @@ -0,0 +1,180 @@ | |
10021 | +/* | |
10022 | + * Kernel Debugger Architecture Independent Stack Traceback | |
10023 | + * | |
10024 | + * This file is subject to the terms and conditions of the GNU General Public | |
10025 | + * License. See the file "COPYING" in the main directory of this archive | |
10026 | + * for more details. | |
10027 | + * | |
10028 | + * Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved. | |
10029 | + */ | |
10030 | + | |
10031 | +#include <linux/ctype.h> | |
10032 | +#include <linux/string.h> | |
10033 | +#include <linux/kernel.h> | |
10034 | +#include <linux/sched.h> | |
10035 | +#include <linux/kdb.h> | |
10036 | +#include <linux/kdbprivate.h> | |
10037 | +#include <linux/nmi.h> | |
10038 | +#include <asm/system.h> | |
10039 | + | |
10040 | + | |
10041 | +/* | |
10042 | + * kdb_bt | |
10043 | + * | |
10044 | + * This function implements the 'bt' command. Print a stack | |
10045 | + * traceback. | |
10046 | + * | |
10047 | + * bt [<address-expression>] (addr-exp is for alternate stacks) | |
10048 | + * btp <pid> Kernel stack for <pid> | |
10049 | + * btt <address-expression> Kernel stack for task structure at <address-expression> | |
10050 | + * bta [DRSTCZEUIMA] All useful processes, optionally filtered by state | |
10051 | + * btc [<cpu>] The current process on one cpu, default is all cpus | |
10052 | + * | |
10053 | + * bt <address-expression> refers to a address on the stack, that location | |
10054 | + * is assumed to contain a return address. | |
10055 | + * | |
10056 | + * btt <address-expression> refers to the address of a struct task. | |
10057 | + * | |
10058 | + * Inputs: | |
10059 | + * argc argument count | |
10060 | + * argv argument vector | |
10061 | + * Outputs: | |
10062 | + * None. | |
10063 | + * Returns: | |
10064 | + * zero for success, a kdb diagnostic if error | |
10065 | + * Locking: | |
10066 | + * none. | |
10067 | + * Remarks: | |
10068 | + * Backtrack works best when the code uses frame pointers. But even | |
10069 | + * without frame pointers we should get a reasonable trace. | |
10070 | + * | |
10071 | + * mds comes in handy when examining the stack to do a manual traceback or | |
10072 | + * to get a starting point for bt <address-expression>. | |
10073 | + */ | |
10074 | + | |
10075 | +static int | |
10076 | +kdb_bt1(const struct task_struct *p, unsigned long mask, int argcount, int btaprompt) | |
10077 | +{ | |
10078 | + int diag; | |
10079 | + char buffer[2]; | |
10080 | + if (kdb_getarea(buffer[0], (unsigned long)p) || | |
10081 | + kdb_getarea(buffer[0], (unsigned long)(p+1)-1)) | |
10082 | + return KDB_BADADDR; | |
10083 | + if (!kdb_task_state(p, mask)) | |
10084 | + return 0; | |
10085 | + kdb_printf("Stack traceback for pid %d\n", p->pid); | |
10086 | + kdb_ps1(p); | |
10087 | + diag = kdba_bt_process(p, argcount); | |
10088 | + if (btaprompt) { | |
10089 | + kdb_getstr(buffer, sizeof(buffer), "Enter <q> to end, <cr> to continue:"); | |
10090 | + if (buffer[0] == 'q') { | |
10091 | + kdb_printf("\n"); | |
10092 | + return 1; | |
10093 | + } | |
10094 | + } | |
10095 | + touch_nmi_watchdog(); | |
10096 | + return 0; | |
10097 | +} | |
10098 | + | |
10099 | +int | |
10100 | +kdb_bt(int argc, const char **argv) | |
10101 | +{ | |
10102 | + int diag; | |
10103 | + int argcount = 5; | |
10104 | + int btaprompt = 1; | |
10105 | + int nextarg; | |
10106 | + unsigned long addr; | |
10107 | + long offset; | |
10108 | + | |
10109 | + kdbgetintenv("BTARGS", &argcount); /* Arguments to print */ | |
10110 | + kdbgetintenv("BTAPROMPT", &btaprompt); /* Prompt after each proc in bta */ | |
10111 | + | |
10112 | + if (strcmp(argv[0], "bta") == 0) { | |
10113 | + struct task_struct *g, *p; | |
10114 | + unsigned long cpu; | |
10115 | + unsigned long mask = kdb_task_state_string(argc ? argv[1] : NULL); | |
10116 | + if (argc == 0) | |
10117 | + kdb_ps_suppressed(); | |
10118 | + /* Run the active tasks first */ | |
10119 | + for (cpu = 0; cpu < NR_CPUS; ++cpu) { | |
10120 | + if (!cpu_online(cpu)) | |
10121 | + continue; | |
10122 | + p = kdb_curr_task(cpu); | |
10123 | + if (kdb_bt1(p, mask, argcount, btaprompt)) | |
10124 | + return 0; | |
10125 | + } | |
10126 | + /* Now the inactive tasks */ | |
10127 | + kdb_do_each_thread(g, p) { | |
10128 | + if (task_curr(p)) | |
10129 | + continue; | |
10130 | + if (kdb_bt1(p, mask, argcount, btaprompt)) | |
10131 | + return 0; | |
10132 | + } kdb_while_each_thread(g, p); | |
10133 | + } else if (strcmp(argv[0], "btp") == 0) { | |
10134 | + struct task_struct *p; | |
10135 | + unsigned long pid; | |
10136 | + if (argc != 1) | |
10137 | + return KDB_ARGCOUNT; | |
10138 | + if ((diag = kdbgetularg((char *)argv[1], &pid))) | |
10139 | + return diag; | |
10140 | + if ((p = find_task_by_pid_type_ns(PIDTYPE_PID, pid, &init_pid_ns))) { | |
10141 | + kdba_set_current_task(p); | |
10142 | + return kdb_bt1(p, ~0UL, argcount, 0); | |
10143 | + } | |
10144 | + kdb_printf("No process with pid == %ld found\n", pid); | |
10145 | + return 0; | |
10146 | + } else if (strcmp(argv[0], "btt") == 0) { | |
10147 | + if (argc != 1) | |
10148 | + return KDB_ARGCOUNT; | |
10149 | + if ((diag = kdbgetularg((char *)argv[1], &addr))) | |
10150 | + return diag; | |
10151 | + kdba_set_current_task((struct task_struct *)addr); | |
10152 | + return kdb_bt1((struct task_struct *)addr, ~0UL, argcount, 0); | |
10153 | + } else if (strcmp(argv[0], "btc") == 0) { | |
10154 | + unsigned long cpu = ~0; | |
10155 | + struct kdb_running_process *krp; | |
10156 | + const struct task_struct *save_current_task = kdb_current_task; | |
10157 | + char buf[80]; | |
10158 | + if (argc > 1) | |
10159 | + return KDB_ARGCOUNT; | |
10160 | + if (argc == 1 && (diag = kdbgetularg((char *)argv[1], &cpu))) | |
10161 | + return diag; | |
10162 | + /* Recursive use of kdb_parse, do not use argv after this point */ | |
10163 | + argv = NULL; | |
10164 | + if (cpu != ~0) { | |
10165 | + krp = kdb_running_process + cpu; | |
10166 | + if (cpu >= NR_CPUS || !krp->seqno || !cpu_online(cpu)) { | |
10167 | + kdb_printf("no process for cpu %ld\n", cpu); | |
10168 | + return 0; | |
10169 | + } | |
10170 | + sprintf(buf, "btt 0x%p\n", krp->p); | |
10171 | + kdb_parse(buf); | |
10172 | + return 0; | |
10173 | + } | |
10174 | + kdb_printf("btc: cpu status: "); | |
10175 | + kdb_parse("cpu\n"); | |
10176 | + for (cpu = 0, krp = kdb_running_process; cpu < NR_CPUS; ++cpu, ++krp) { | |
10177 | + if (!cpu_online(cpu) || !krp->seqno) | |
10178 | + continue; | |
10179 | + sprintf(buf, "btt 0x%p\n", krp->p); | |
10180 | + kdb_parse(buf); | |
10181 | + touch_nmi_watchdog(); | |
10182 | + } | |
10183 | + kdba_set_current_task(save_current_task); | |
10184 | + return 0; | |
10185 | + } else { | |
10186 | + if (argc) { | |
10187 | + nextarg = 1; | |
10188 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, | |
10189 | + &offset, NULL); | |
10190 | + if (diag) | |
10191 | + return diag; | |
10192 | + return kdba_bt_address(addr, argcount); | |
10193 | + } else { | |
10194 | + return kdb_bt1(kdb_current_task, ~0UL, argcount, 0); | |
10195 | + } | |
10196 | + } | |
10197 | + | |
10198 | + /* NOTREACHED */ | |
10199 | + return 0; | |
10200 | +} | |
10201 | --- /dev/null | |
10202 | +++ b/kdb/kdb_cmds | |
10203 | @@ -0,0 +1,32 @@ | |
10204 | +# Initial commands for kdb, alter to suit your needs. | |
10205 | +# These commands are executed in kdb_init() context, no SMP, no | |
10206 | +# processes. Commands that require process data (including stack or | |
10207 | +# registers) are not reliable this early. set and bp commands should | |
10208 | +# be safe. Global breakpoint commands affect each cpu as it is booted. | |
10209 | + | |
10210 | +# Standard debugging information for first level support, just type archkdb | |
10211 | +# or archkdbcpu or archkdbshort at the kdb prompt. | |
10212 | + | |
10213 | +defcmd archkdb "" "First line arch debugging" | |
10214 | + set BTSYMARG 1 | |
10215 | + set BTARGS 9 | |
10216 | + pid R | |
10217 | + -archkdbcommon | |
10218 | + -bta | |
10219 | +endefcmd | |
10220 | + | |
10221 | +defcmd archkdbcpu "" "archkdb with only tasks on cpus" | |
10222 | + set BTSYMARG 1 | |
10223 | + set BTARGS 9 | |
10224 | + pid R | |
10225 | + -archkdbcommon | |
10226 | + -btc | |
10227 | +endefcmd | |
10228 | + | |
10229 | +defcmd archkdbshort "" "archkdb with less detailed backtrace" | |
10230 | + set BTSYMARG 0 | |
10231 | + set BTARGS 0 | |
10232 | + pid R | |
10233 | + -archkdbcommon | |
10234 | + -bta | |
10235 | +endefcmd | |
10236 | --- /dev/null | |
10237 | +++ b/kdb/kdb_id.c | |
10238 | @@ -0,0 +1,236 @@ | |
10239 | +/* | |
10240 | + * Kernel Debugger Architecture Independent Instruction Disassembly | |
10241 | + * | |
10242 | + * This file is subject to the terms and conditions of the GNU General Public | |
10243 | + * License. See the file "COPYING" in the main directory of this archive | |
10244 | + * for more details. | |
10245 | + * | |
10246 | + * Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved. | |
10247 | + */ | |
10248 | + | |
10249 | +#include <stdarg.h> | |
10250 | +#include <linux/kernel.h> | |
10251 | +#include <linux/init.h> | |
10252 | +#include <linux/ctype.h> | |
10253 | +#include <linux/string.h> | |
10254 | +#include <linux/kdb.h> | |
10255 | +#include <linux/kdbprivate.h> | |
10256 | + | |
10257 | +disassemble_info kdb_di; | |
10258 | + | |
10259 | +/* | |
10260 | + * kdb_id | |
10261 | + * | |
10262 | + * Handle the id (instruction display) command. | |
10263 | + * | |
10264 | + * id [<addr>] | |
10265 | + * | |
10266 | + * Parameters: | |
10267 | + * argc Count of arguments in argv | |
10268 | + * argv Space delimited command line arguments | |
10269 | + * Outputs: | |
10270 | + * None. | |
10271 | + * Returns: | |
10272 | + * Zero for success, a kdb diagnostic if failure. | |
10273 | + * Locking: | |
10274 | + * None. | |
10275 | + * Remarks: | |
10276 | + */ | |
10277 | + | |
10278 | +int | |
10279 | +kdb_id(int argc, const char **argv) | |
10280 | +{ | |
10281 | + kdb_machreg_t pc; | |
10282 | + int icount; | |
10283 | + int diag; | |
10284 | + int i; | |
10285 | + char *mode; | |
10286 | + int nextarg; | |
10287 | + long offset = 0; | |
10288 | + static kdb_machreg_t lastpc; | |
10289 | + struct disassemble_info *dip = &kdb_di; | |
10290 | + char lastbuf[50]; | |
10291 | + unsigned long word; | |
10292 | + | |
10293 | + kdb_di.fprintf_func = kdb_dis_fprintf; | |
10294 | + kdba_id_init(&kdb_di); | |
10295 | + | |
10296 | + if (argc != 1) { | |
10297 | + if (lastpc == 0) { | |
10298 | + return KDB_ARGCOUNT; | |
10299 | + } else { | |
10300 | + sprintf(lastbuf, "0x%lx", lastpc); | |
10301 | + argv[1] = lastbuf; | |
10302 | + argc = 1; | |
10303 | + } | |
10304 | + } | |
10305 | + | |
10306 | + | |
10307 | + /* | |
10308 | + * Fetch PC. First, check to see if it is a symbol, if not, | |
10309 | + * try address. | |
10310 | + */ | |
10311 | + nextarg = 1; | |
10312 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &pc, &offset, NULL); | |
10313 | + if (diag) | |
10314 | + return diag; | |
10315 | + kdba_check_pc(&pc); | |
10316 | + if (kdb_getarea(word, pc)) | |
10317 | + return(0); | |
10318 | + | |
10319 | + /* | |
10320 | + * Number of lines to display | |
10321 | + */ | |
10322 | + diag = kdbgetintenv("IDCOUNT", &icount); | |
10323 | + if (diag) | |
10324 | + return diag; | |
10325 | + | |
10326 | + mode = kdbgetenv("IDMODE"); | |
10327 | + diag = kdba_id_parsemode(mode, dip); | |
10328 | + if (diag) { | |
10329 | + return diag; | |
10330 | + } | |
10331 | + | |
10332 | + for(i=0; i<icount; i++) { | |
10333 | + pc += kdba_id_printinsn(pc, &kdb_di); | |
10334 | + kdb_printf("\n"); | |
10335 | + } | |
10336 | + | |
10337 | + lastpc = pc; | |
10338 | + | |
10339 | + return 0; | |
10340 | +} | |
10341 | + | |
10342 | +/* | |
10343 | + * kdb_id1 | |
10344 | + * | |
10345 | + * Disassemble a single instruction at 'pc'. | |
10346 | + * | |
10347 | + * Parameters: | |
10348 | + * pc Address of instruction to disassemble | |
10349 | + * Outputs: | |
10350 | + * None. | |
10351 | + * Returns: | |
10352 | + * Zero for success, a kdb diagnostic if failure. | |
10353 | + * Locking: | |
10354 | + * None. | |
10355 | + * Remarks: | |
10356 | + */ | |
10357 | + | |
10358 | +void | |
10359 | +kdb_id1(unsigned long pc) | |
10360 | +{ | |
10361 | + char *mode; | |
10362 | + int diag; | |
10363 | + | |
10364 | + kdb_di.fprintf_func = kdb_dis_fprintf; | |
10365 | + kdba_id_init(&kdb_di); | |
10366 | + | |
10367 | + /* | |
10368 | + * Allow the user to specify that this instruction | |
10369 | + * should be treated differently. | |
10370 | + */ | |
10371 | + | |
10372 | + mode = kdbgetenv("IDMODE"); | |
10373 | + diag = kdba_id_parsemode(mode, &kdb_di); | |
10374 | + if (diag) { | |
10375 | + kdb_printf("kdb_id: bad value in 'IDMODE' environment variable ignored\n"); | |
10376 | + } | |
10377 | + | |
10378 | + (void) kdba_id_printinsn(pc, &kdb_di); | |
10379 | + kdb_printf("\n"); | |
10380 | +} | |
10381 | + | |
10382 | +/* | |
10383 | + * kdb_dis_fprintf | |
10384 | + * | |
10385 | + * Format and print a string. | |
10386 | + * | |
10387 | + * Parameters: | |
10388 | + * file Unused paramter. | |
10389 | + * fmt Format string | |
10390 | + * ... Optional additional parameters. | |
10391 | + * Returns: | |
10392 | + * 0 | |
10393 | + * Locking: | |
10394 | + * Remarks: | |
10395 | + * Result of format conversion cannot exceed 255 bytes. | |
10396 | + */ | |
10397 | + | |
10398 | +int | |
10399 | +kdb_dis_fprintf(PTR file, const char *fmt, ...) | |
10400 | +{ | |
10401 | + char buffer[256]; | |
10402 | + va_list ap; | |
10403 | + | |
10404 | + va_start(ap, fmt); | |
10405 | + vsprintf(buffer, fmt, ap); | |
10406 | + va_end(ap); | |
10407 | + | |
10408 | + kdb_printf("%s", buffer); | |
10409 | + | |
10410 | + return 0; | |
10411 | +} | |
10412 | + | |
10413 | +/* | |
10414 | + * kdb_dis_fprintf_dummy | |
10415 | + * | |
10416 | + * A dummy printf function for the disassembler, it does nothing. | |
10417 | + * This lets code call the disassembler to step through | |
10418 | + * instructions without actually printing anything. | |
10419 | + * Inputs: | |
10420 | + * Always ignored. | |
10421 | + * Outputs: | |
10422 | + * None. | |
10423 | + * Returns: | |
10424 | + * Always 0. | |
10425 | + * Locking: | |
10426 | + * none. | |
10427 | + * Remarks: | |
10428 | + * None. | |
10429 | + */ | |
10430 | + | |
10431 | +int | |
10432 | +kdb_dis_fprintf_dummy(PTR file, const char *fmt, ...) | |
10433 | +{ | |
10434 | + return(0); | |
10435 | +} | |
10436 | + | |
10437 | +/* | |
10438 | + * kdb_disinit | |
10439 | + * | |
10440 | + * Initialize the disassembly information structure | |
10441 | + * for the GNU disassembler. | |
10442 | + * | |
10443 | + * Parameters: | |
10444 | + * None. | |
10445 | + * Outputs: | |
10446 | + * None. | |
10447 | + * Returns: | |
10448 | + * Zero for success, a kdb diagnostic if failure. | |
10449 | + * Locking: | |
10450 | + * None. | |
10451 | + * Remarks: | |
10452 | + */ | |
10453 | + | |
10454 | +void __init | |
10455 | +kdb_id_init(void) | |
10456 | +{ | |
10457 | + kdb_di.stream = NULL; | |
10458 | + kdb_di.application_data = NULL; | |
10459 | + kdb_di.symbols = NULL; | |
10460 | + kdb_di.num_symbols = 0; | |
10461 | + kdb_di.flags = 0; | |
10462 | + kdb_di.private_data = NULL; | |
10463 | + kdb_di.buffer = NULL; | |
10464 | + kdb_di.buffer_vma = 0; | |
10465 | + kdb_di.buffer_length = 0; | |
10466 | + kdb_di.bytes_per_line = 0; | |
10467 | + kdb_di.bytes_per_chunk = 0; | |
10468 | + kdb_di.insn_info_valid = 0; | |
10469 | + kdb_di.branch_delay_insns = 0; | |
10470 | + kdb_di.data_size = 0; | |
10471 | + kdb_di.insn_type = 0; | |
10472 | + kdb_di.target = 0; | |
10473 | + kdb_di.target2 = 0; | |
10474 | +} | |
10475 | --- /dev/null | |
10476 | +++ b/kdb/kdb_io.c | |
10477 | @@ -0,0 +1,856 @@ | |
10478 | +/* | |
10479 | + * Kernel Debugger Architecture Independent Console I/O handler | |
10480 | + * | |
10481 | + * This file is subject to the terms and conditions of the GNU General Public | |
10482 | + * License. See the file "COPYING" in the main directory of this archive | |
10483 | + * for more details. | |
10484 | + * | |
10485 | + * Copyright (c) 1999-2006 Silicon Graphics, Inc. All Rights Reserved. | |
10486 | + */ | |
10487 | + | |
10488 | +#include <linux/module.h> | |
10489 | +#include <linux/types.h> | |
10490 | +#include <linux/ctype.h> | |
10491 | +#include <linux/kernel.h> | |
10492 | +#include <linux/init.h> | |
10493 | +#include <linux/kdev_t.h> | |
10494 | +#include <linux/console.h> | |
10495 | +#include <linux/string.h> | |
10496 | +#include <linux/sched.h> | |
10497 | +#include <linux/smp.h> | |
10498 | +#include <linux/nmi.h> | |
10499 | +#include <linux/delay.h> | |
10500 | + | |
10501 | +#include <linux/kdb.h> | |
10502 | +#include <linux/kdbprivate.h> | |
10503 | +#include <linux/kallsyms.h> | |
10504 | + | |
10505 | +static struct console *kdbcons; | |
10506 | + | |
10507 | +#ifdef CONFIG_PPC64 | |
10508 | +#include <asm/udbg.h> | |
10509 | +#endif | |
10510 | + | |
10511 | +#define CMD_BUFLEN 256 | |
10512 | +char kdb_prompt_str[CMD_BUFLEN]; | |
10513 | + | |
10514 | +extern int kdb_grepping_flag; | |
10515 | +extern char kdb_grep_string[]; | |
10516 | +extern int kdb_grep_leading; | |
10517 | +extern int kdb_grep_trailing; | |
10518 | + | |
10519 | +/* | |
10520 | + * kdb_read | |
10521 | + * | |
10522 | + * This function reads a string of characters, terminated by | |
10523 | + * a newline, or by reaching the end of the supplied buffer, | |
10524 | + * from the current kernel debugger console device. | |
10525 | + * Parameters: | |
10526 | + * buffer - Address of character buffer to receive input characters. | |
10527 | + * bufsize - size, in bytes, of the character buffer | |
10528 | + * Returns: | |
10529 | + * Returns a pointer to the buffer containing the received | |
10530 | + * character string. This string will be terminated by a | |
10531 | + * newline character. | |
10532 | + * Locking: | |
10533 | + * No locks are required to be held upon entry to this | |
10534 | + * function. It is not reentrant - it relies on the fact | |
10535 | + * that while kdb is running on any one processor all other | |
10536 | + * processors will be spinning at the kdb barrier. | |
10537 | + * Remarks: | |
10538 | + * | |
10539 | + * Davidm asks, why doesn't kdb use the console abstraction; | |
10540 | + * here are some reasons: | |
10541 | + * - you cannot debug the console abstraction with kdb if | |
10542 | + * kdb uses it. | |
10543 | + * - you rely on the correct functioning of the abstraction | |
10544 | + * in the presence of general system failures. | |
10545 | + * - You must acquire the console spinlock thus restricting | |
10546 | + * the usability - what if the kernel fails with the spinlock | |
10547 | + * held - one still wishes to debug such situations. | |
10548 | + * - How about debugging before the console(s) are registered? | |
10549 | + * - None of the current consoles (sercons, vt_console_driver) | |
10550 | + * have read functions defined. | |
10551 | + * - The standard pc keyboard and terminal drivers are interrupt | |
10552 | + * driven. We cannot enable interrupts while kdb is active, | |
10553 | + * so the standard input functions cannot be used by kdb. | |
10554 | + * | |
10555 | + * An implementation could be improved by removing the need for | |
10556 | + * lock acquisition - just keep a 'struct console *kdbconsole;' global | |
10557 | + * variable which refers to the preferred kdb console. | |
10558 | + * | |
10559 | + * The bulk of this function is architecture dependent. | |
10560 | + * | |
10561 | + * The buffer size must be >= 2. A buffer size of 2 means that the caller only | |
10562 | + * wants a single key. | |
10563 | + * | |
10564 | + * An escape key could be the start of a vt100 control sequence such as \e[D | |
10565 | + * (left arrow) or it could be a character in its own right. The standard | |
10566 | + * method for detecting the difference is to wait for 2 seconds to see if there | |
10567 | + * are any other characters. kdb is complicated by the lack of a timer service | |
10568 | + * (interrupts are off), by multiple input sources and by the need to sometimes | |
10569 | + * return after just one key. Escape sequence processing has to be done as | |
10570 | + * states in the polling loop. | |
10571 | + */ | |
10572 | + | |
10573 | +char * | |
10574 | +kdb_read(char *buffer, size_t bufsize) | |
10575 | +{ | |
10576 | + char *cp = buffer; | |
10577 | + char *bufend = buffer+bufsize-2; /* Reserve space for newline and null byte */ | |
10578 | + | |
10579 | + char *lastchar; | |
10580 | + char *p_tmp; | |
10581 | + char tmp; | |
10582 | + static char tmpbuffer[CMD_BUFLEN]; | |
10583 | + int len = strlen(buffer); | |
10584 | + int len_tmp; | |
10585 | + int tab=0; | |
10586 | + int count; | |
10587 | + int i; | |
10588 | + int diag, dtab_count; | |
10589 | + | |
10590 | +#define ESCAPE_UDELAY 1000 | |
10591 | +#define ESCAPE_DELAY 2*1000000/ESCAPE_UDELAY /* 2 seconds worth of udelays */ | |
10592 | + char escape_data[5]; /* longest vt100 escape sequence is 4 bytes */ | |
10593 | + char *ped = escape_data; | |
10594 | + int escape_delay = 0; | |
10595 | + get_char_func *f, *f_escape = NULL; | |
10596 | + | |
10597 | + diag = kdbgetintenv("DTABCOUNT",&dtab_count); | |
10598 | + if (diag) | |
10599 | + dtab_count = 30; | |
10600 | + | |
10601 | + if (len > 0 ) { | |
10602 | + cp += len; | |
10603 | + if (*(buffer+len-1) == '\n') | |
10604 | + cp--; | |
10605 | + } | |
10606 | + | |
10607 | + lastchar = cp; | |
10608 | + *cp = '\0'; | |
10609 | + kdb_printf("%s", buffer); | |
10610 | + | |
10611 | + for (;;) { | |
10612 | + int key; | |
10613 | + for (f = &poll_funcs[0]; ; ++f) { | |
10614 | + if (*f == NULL) { | |
10615 | + /* Reset NMI watchdog once per poll loop */ | |
10616 | + touch_nmi_watchdog(); | |
10617 | + f = &poll_funcs[0]; | |
10618 | + } | |
10619 | + if (escape_delay == 2) { | |
10620 | + *ped = '\0'; | |
10621 | + ped = escape_data; | |
10622 | + --escape_delay; | |
10623 | + } | |
10624 | + if (escape_delay == 1) { | |
10625 | + key = *ped++; | |
10626 | + if (!*ped) | |
10627 | + --escape_delay; | |
10628 | + break; | |
10629 | + } | |
10630 | + key = (*f)(); | |
10631 | + if (key == -1) { | |
10632 | + if (escape_delay) { | |
10633 | + udelay(ESCAPE_UDELAY); | |
10634 | + --escape_delay; | |
10635 | + } | |
10636 | + continue; | |
10637 | + } | |
10638 | + if (bufsize <= 2) { | |
10639 | + if (key == '\r') | |
10640 | + key = '\n'; | |
10641 | + kdb_printf("%c", key); | |
10642 | + *buffer++ = key; | |
10643 | + *buffer = '\0'; | |
10644 | + return buffer; | |
10645 | + } | |
10646 | + if (escape_delay == 0 && key == '\e') { | |
10647 | + escape_delay = ESCAPE_DELAY; | |
10648 | + ped = escape_data; | |
10649 | + f_escape = f; | |
10650 | + } | |
10651 | + if (escape_delay) { | |
10652 | + *ped++ = key; | |
10653 | + if (f_escape != f) { | |
10654 | + escape_delay = 2; | |
10655 | + continue; | |
10656 | + } | |
10657 | + if (ped - escape_data == 1) { | |
10658 | + /* \e */ | |
10659 | + continue; | |
10660 | + } | |
10661 | + else if (ped - escape_data == 2) { | |
10662 | + /* \e<something> */ | |
10663 | + if (key != '[') | |
10664 | + escape_delay = 2; | |
10665 | + continue; | |
10666 | + } else if (ped - escape_data == 3) { | |
10667 | + /* \e[<something> */ | |
10668 | + int mapkey = 0; | |
10669 | + switch (key) { | |
10670 | + case 'A': mapkey = 16; break; /* \e[A, up arrow */ | |
10671 | + case 'B': mapkey = 14; break; /* \e[B, down arrow */ | |
10672 | + case 'C': mapkey = 6; break; /* \e[C, right arrow */ | |
10673 | + case 'D': mapkey = 2; break; /* \e[D, left arrow */ | |
10674 | + case '1': /* dropthrough */ | |
10675 | + case '3': /* dropthrough */ | |
10676 | + case '4': mapkey = -1; break; /* \e[<1,3,4>], may be home, del, end */ | |
10677 | + } | |
10678 | + if (mapkey != -1) { | |
10679 | + if (mapkey > 0) { | |
10680 | + escape_data[0] = mapkey; | |
10681 | + escape_data[1] = '\0'; | |
10682 | + } | |
10683 | + escape_delay = 2; | |
10684 | + } | |
10685 | + continue; | |
10686 | + } else if (ped - escape_data == 4) { | |
10687 | + /* \e[<1,3,4><something> */ | |
10688 | + int mapkey = 0; | |
10689 | + if (key == '~') { | |
10690 | + switch (escape_data[2]) { | |
10691 | + case '1': mapkey = 1; break; /* \e[1~, home */ | |
10692 | + case '3': mapkey = 4; break; /* \e[3~, del */ | |
10693 | + case '4': mapkey = 5; break; /* \e[4~, end */ | |
10694 | + } | |
10695 | + } | |
10696 | + if (mapkey > 0) { | |
10697 | + escape_data[0] = mapkey; | |
10698 | + escape_data[1] = '\0'; | |
10699 | + } | |
10700 | + escape_delay = 2; | |
10701 | + continue; | |
10702 | + } | |
10703 | + } | |
10704 | + break; /* A key to process */ | |
10705 | + } | |
10706 | + | |
10707 | + if (key != 9) | |
10708 | + tab = 0; | |
10709 | + switch (key) { | |
10710 | + case 8: /* backspace */ | |
10711 | + if (cp > buffer) { | |
10712 | + if (cp < lastchar) { | |
10713 | + memcpy(tmpbuffer, cp, lastchar - cp); | |
10714 | + memcpy(cp-1, tmpbuffer, lastchar - cp); | |
10715 | + } | |
10716 | + *(--lastchar) = '\0'; | |
10717 | + --cp; | |
10718 | + kdb_printf("\b%s \r", cp); | |
10719 | + tmp = *cp; | |
10720 | + *cp = '\0'; | |
10721 | + kdb_printf(kdb_prompt_str); | |
10722 | + kdb_printf("%s", buffer); | |
10723 | + *cp = tmp; | |
10724 | + } | |
10725 | + break; | |
10726 | + case 13: /* enter */ | |
10727 | + *lastchar++ = '\n'; | |
10728 | + *lastchar++ = '\0'; | |
10729 | + kdb_printf("\n"); | |
10730 | + return buffer; | |
10731 | + case 4: /* Del */ | |
10732 | + if(cp < lastchar) { | |
10733 | + memcpy(tmpbuffer, cp+1, lastchar - cp -1); | |
10734 | + memcpy(cp, tmpbuffer, lastchar - cp -1); | |
10735 | + *(--lastchar) = '\0'; | |
10736 | + kdb_printf("%s \r", cp); | |
10737 | + tmp = *cp; | |
10738 | + *cp = '\0'; | |
10739 | + kdb_printf(kdb_prompt_str); | |
10740 | + kdb_printf("%s", buffer); | |
10741 | + *cp = tmp; | |
10742 | + } | |
10743 | + break; | |
10744 | + case 1: /* Home */ | |
10745 | + if(cp > buffer) { | |
10746 | + kdb_printf("\r"); | |
10747 | + kdb_printf(kdb_prompt_str); | |
10748 | + cp = buffer; | |
10749 | + } | |
10750 | + break; | |
10751 | + case 5: /* End */ | |
10752 | + if(cp < lastchar) { | |
10753 | + kdb_printf("%s", cp); | |
10754 | + cp = lastchar; | |
10755 | + } | |
10756 | + break; | |
10757 | + case 2: /* Left */ | |
10758 | + if (cp > buffer) { | |
10759 | + kdb_printf("\b"); | |
10760 | + --cp; | |
10761 | + } | |
10762 | + break; | |
10763 | + case 14: /* Down */ | |
10764 | + memset(tmpbuffer, ' ', strlen(kdb_prompt_str)+(lastchar-buffer)); | |
10765 | + *(tmpbuffer+strlen(kdb_prompt_str)+(lastchar-buffer)) = '\0'; | |
10766 | + kdb_printf("\r%s\r", tmpbuffer); | |
10767 | + *lastchar = (char)key; | |
10768 | + *(lastchar+1) = '\0'; | |
10769 | + return lastchar; | |
10770 | + case 6: /* Right */ | |
10771 | + if (cp < lastchar) { | |
10772 | + kdb_printf("%c", *cp); | |
10773 | + ++cp; | |
10774 | + } | |
10775 | + break; | |
10776 | + case 16: /* Up */ | |
10777 | + memset(tmpbuffer, ' ', strlen(kdb_prompt_str)+(lastchar-buffer)); | |
10778 | + *(tmpbuffer+strlen(kdb_prompt_str)+(lastchar-buffer)) = '\0'; | |
10779 | + kdb_printf("\r%s\r", tmpbuffer); | |
10780 | + *lastchar = (char)key; | |
10781 | + *(lastchar+1) = '\0'; | |
10782 | + return lastchar; | |
10783 | + case 9: /* Tab */ | |
10784 | + if (tab < 2) | |
10785 | + ++tab; | |
10786 | + p_tmp = buffer; | |
10787 | + while(*p_tmp==' ') p_tmp++; | |
10788 | + if (p_tmp<=cp) { | |
10789 | + memcpy(tmpbuffer, p_tmp, cp-p_tmp); | |
10790 | + *(tmpbuffer + (cp-p_tmp)) = '\0'; | |
10791 | + p_tmp = strrchr(tmpbuffer, ' '); | |
10792 | + if (p_tmp) | |
10793 | + ++p_tmp; | |
10794 | + else | |
10795 | + p_tmp = tmpbuffer; | |
10796 | + len = strlen(p_tmp); | |
10797 | + count = kallsyms_symbol_complete(p_tmp, sizeof(tmpbuffer) - (p_tmp - tmpbuffer)); | |
10798 | + if (tab == 2) { | |
10799 | + if (count > 0) { | |
10800 | + kdb_printf("\n%d symbols are found.", count); | |
10801 | + if(count>dtab_count) { | |
10802 | + count=dtab_count; | |
10803 | + kdb_printf(" But only first %d symbols will be printed.\nYou can change the environment variable DTABCOUNT.", count); | |
10804 | + } | |
10805 | + kdb_printf("\n"); | |
10806 | + for(i=0;i<count;i++) { | |
10807 | + if(kallsyms_symbol_next(p_tmp, i)<0) | |
10808 | + break; | |
10809 | + kdb_printf("%s ",p_tmp); | |
10810 | + *(p_tmp+len)='\0'; | |
10811 | + } | |
10812 | + if(i>=dtab_count)kdb_printf("..."); | |
10813 | + kdb_printf("\n"); | |
10814 | + kdb_printf(kdb_prompt_str); | |
10815 | + kdb_printf("%s", buffer); | |
10816 | + } | |
10817 | + } | |
10818 | + else { | |
10819 | + if (count > 0) { | |
10820 | + len_tmp = strlen(p_tmp); | |
10821 | + strncpy(p_tmp+len_tmp,cp, lastchar-cp+1); | |
10822 | + len_tmp = strlen(p_tmp); | |
10823 | + strncpy(cp, p_tmp+len, len_tmp-len+1); | |
10824 | + len = len_tmp - len; | |
10825 | + kdb_printf("%s", cp); | |
10826 | + cp+=len; | |
10827 | + lastchar+=len; | |
10828 | + } | |
10829 | + } | |
10830 | + kdb_nextline = 1; /* reset output line number */ | |
10831 | + } | |
10832 | + break; | |
10833 | + default: | |
10834 | + if (key >= 32 &&lastchar < bufend) { | |
10835 | + if (cp < lastchar) { | |
10836 | + memcpy(tmpbuffer, cp, lastchar - cp); | |
10837 | + memcpy(cp+1, tmpbuffer, lastchar - cp); | |
10838 | + *++lastchar = '\0'; | |
10839 | + *cp = key; | |
10840 | + kdb_printf("%s\r", cp); | |
10841 | + ++cp; | |
10842 | + tmp = *cp; | |
10843 | + *cp = '\0'; | |
10844 | + kdb_printf(kdb_prompt_str); | |
10845 | + kdb_printf("%s", buffer); | |
10846 | + *cp = tmp; | |
10847 | + } else { | |
10848 | + *++lastchar = '\0'; | |
10849 | + *cp++ = key; | |
10850 | + kdb_printf("%c", key); | |
10851 | + } | |
10852 | + } | |
10853 | + break; | |
10854 | + } | |
10855 | + } | |
10856 | +} | |
10857 | + | |
10858 | +/* | |
10859 | + * kdb_getstr | |
10860 | + * | |
10861 | + * Print the prompt string and read a command from the | |
10862 | + * input device. | |
10863 | + * | |
10864 | + * Parameters: | |
10865 | + * buffer Address of buffer to receive command | |
10866 | + * bufsize Size of buffer in bytes | |
10867 | + * prompt Pointer to string to use as prompt string | |
10868 | + * Returns: | |
10869 | + * Pointer to command buffer. | |
10870 | + * Locking: | |
10871 | + * None. | |
10872 | + * Remarks: | |
10873 | + * For SMP kernels, the processor number will be | |
10874 | + * substituted for %d, %x or %o in the prompt. | |
10875 | + */ | |
10876 | + | |
10877 | +char * | |
10878 | +kdb_getstr(char *buffer, size_t bufsize, char *prompt) | |
10879 | +{ | |
10880 | + if(prompt && kdb_prompt_str!=prompt) | |
10881 | + strncpy(kdb_prompt_str, prompt, CMD_BUFLEN); | |
10882 | + kdb_printf(kdb_prompt_str); | |
10883 | + kdb_nextline = 1; /* Prompt and input resets line number */ | |
10884 | + return kdb_read(buffer, bufsize); | |
10885 | +} | |
10886 | + | |
10887 | +/* | |
10888 | + * kdb_input_flush | |
10889 | + * | |
10890 | + * Get rid of any buffered console input. | |
10891 | + * | |
10892 | + * Parameters: | |
10893 | + * none | |
10894 | + * Returns: | |
10895 | + * nothing | |
10896 | + * Locking: | |
10897 | + * none | |
10898 | + * Remarks: | |
10899 | + * Call this function whenever you want to flush input. If there is any | |
10900 | + * outstanding input, it ignores all characters until there has been no | |
10901 | + * data for approximately half a second. | |
10902 | + */ | |
10903 | + | |
10904 | +#define FLUSH_UDELAY 100 | |
10905 | +#define FLUSH_DELAY 500000/FLUSH_UDELAY /* 0.5 seconds worth of udelays */ | |
10906 | + | |
10907 | +static void | |
10908 | +kdb_input_flush(void) | |
10909 | +{ | |
10910 | + get_char_func *f; | |
10911 | + int flush_delay = 1; | |
10912 | + while (flush_delay--) { | |
10913 | + touch_nmi_watchdog(); | |
10914 | + for (f = &poll_funcs[0]; *f; ++f) { | |
10915 | + if ((*f)() != -1) { | |
10916 | + flush_delay = FLUSH_DELAY; | |
10917 | + break; | |
10918 | + } | |
10919 | + } | |
10920 | + if (flush_delay) | |
10921 | + udelay(FLUSH_UDELAY); | |
10922 | + } | |
10923 | +} | |
10924 | + | |
10925 | +/* | |
10926 | + * kdb_printf | |
10927 | + * | |
10928 | + * Print a string to the output device(s). | |
10929 | + * | |
10930 | + * Parameters: | |
10931 | + * printf-like format and optional args. | |
10932 | + * Returns: | |
10933 | + * 0 | |
10934 | + * Locking: | |
10935 | + * None. | |
10936 | + * Remarks: | |
10937 | + * use 'kdbcons->write()' to avoid polluting 'log_buf' with | |
10938 | + * kdb output. | |
10939 | + * | |
10940 | + * If the user is doing a cmd args | grep srch | |
10941 | + * then kdb_grepping_flag is set. | |
10942 | + * In that case we need to accumulate full lines (ending in \n) before | |
10943 | + * searching for the pattern. | |
10944 | + */ | |
10945 | + | |
10946 | +static char kdb_buffer[256]; /* A bit too big to go on stack */ | |
10947 | +static char *next_avail=kdb_buffer; | |
10948 | +static int size_avail; | |
10949 | +static int suspend_grep=0; | |
10950 | + | |
10951 | +/* | |
10952 | + * search arg1 to see if it contains arg2 | |
10953 | + * (kdmain.c provides flags for ^pat and pat$) | |
10954 | + * | |
10955 | + * return 1 for found, 0 for not found | |
10956 | + */ | |
10957 | +int | |
10958 | +kdb_search_string(char *searched, char *searchfor) | |
10959 | +{ | |
10960 | + char firstchar, *cp; | |
10961 | + int len1, len2; | |
10962 | + | |
10963 | + /* not counting the newline at the end of "searched" */ | |
10964 | + len1 = strlen(searched)-1; | |
10965 | + len2 = strlen(searchfor); | |
10966 | + if (len1 < len2) return 0; | |
10967 | + if (kdb_grep_leading && kdb_grep_trailing && len1 != len2) return 0; | |
10968 | + | |
10969 | + if (kdb_grep_leading) { | |
10970 | + if (!strncmp(searched, searchfor, len2)) { | |
10971 | + return 1; | |
10972 | + } | |
10973 | + } else if (kdb_grep_trailing) { | |
10974 | + if (!strncmp(searched+len1-len2, searchfor, len2)) { | |
10975 | + return 1; | |
10976 | + } | |
10977 | + } else { | |
10978 | + firstchar = *searchfor; | |
10979 | + cp = searched; | |
10980 | + while ((cp = strchr(cp,firstchar))) { | |
10981 | + if (!strncmp(cp, searchfor, len2)) { | |
10982 | + return 1; | |
10983 | + } | |
10984 | + cp++; | |
10985 | + } | |
10986 | + } | |
10987 | + return 0; | |
10988 | +} | |
10989 | + | |
10990 | +void | |
10991 | +kdb_printf(const char *fmt, ...) | |
10992 | +{ | |
10993 | + va_list ap; | |
10994 | + int diag; | |
10995 | + int linecount; | |
10996 | + int logging, saved_loglevel = 0; | |
10997 | + int do_longjmp = 0; | |
10998 | + int got_printf_lock = 0; | |
10999 | + int fnd, len; | |
11000 | + char *cp, *cp2, *cphold = NULL, replaced_byte = ' '; | |
11001 | + char *moreprompt = "more> "; | |
11002 | + struct console *c = console_drivers; | |
11003 | + static DEFINE_SPINLOCK(kdb_printf_lock); | |
11004 | + unsigned long uninitialized_var(flags); | |
11005 | + | |
11006 | + preempt_disable(); | |
11007 | + /* Serialize kdb_printf if multiple cpus try to write at once. | |
11008 | + * But if any cpu goes recursive in kdb, just print the output, | |
11009 | + * even if it is interleaved with any other text. | |
11010 | + */ | |
11011 | + if (!KDB_STATE(PRINTF_LOCK)) { | |
11012 | + KDB_STATE_SET(PRINTF_LOCK); | |
11013 | + spin_lock_irqsave(&kdb_printf_lock, flags); | |
11014 | + got_printf_lock = 1; | |
11015 | + atomic_inc(&kdb_event); | |
11016 | + } else { | |
11017 | + __acquire(kdb_printf_lock); | |
11018 | + } | |
11019 | + | |
11020 | + diag = kdbgetintenv("LINES", &linecount); | |
11021 | + if (diag || linecount <= 1) | |
11022 | + linecount = 22; | |
11023 | + | |
11024 | + diag = kdbgetintenv("LOGGING", &logging); | |
11025 | + if (diag) | |
11026 | + logging = 0; | |
11027 | + | |
11028 | + if (!kdb_grepping_flag || suspend_grep) { | |
11029 | + /* normally, every vsnprintf starts a new buffer */ | |
11030 | + next_avail = kdb_buffer; | |
11031 | + size_avail = sizeof(kdb_buffer); | |
11032 | + } | |
11033 | + va_start(ap, fmt); | |
11034 | + vsnprintf(next_avail, size_avail, fmt, ap); | |
11035 | + va_end(ap); | |
11036 | + | |
11037 | + /* | |
11038 | + * If kdb_parse() found that the command was cmd xxx | grep yyy | |
11039 | + * then kdb_grepping_flag is set, and kdb_grep_string contains yyy | |
11040 | + * | |
11041 | + * Accumulate the print data up to a newline before searching it. | |
11042 | + * (vsnprintf does null-terminate the string that it generates) | |
11043 | + */ | |
11044 | + | |
11045 | + /* skip the search if prints are temporarily unconditional */ | |
11046 | + if (! suspend_grep) { | |
11047 | + | |
11048 | + if (kdb_grepping_flag) { | |
11049 | + cp = strchr(kdb_buffer, '\n'); | |
11050 | + if (!cp) { | |
11051 | + /* | |
11052 | + * Special cases that don't end with newlines | |
11053 | + * but should be written without one: | |
11054 | + * The "[nn]kdb> " prompt should | |
11055 | + * appear at the front of the buffer. | |
11056 | + * | |
11057 | + * The "[nn]more " prompt should also be | |
11058 | + * (MOREPROMPT -> moreprompt) | |
11059 | + * written * but we print that ourselves, | |
11060 | + * we set the suspend_grep flag to make | |
11061 | + * it unconditional. | |
11062 | + * | |
11063 | + */ | |
11064 | + if (next_avail == kdb_buffer) { | |
11065 | + /* | |
11066 | + * these should occur after a newline, | |
11067 | + * so they will be at the front of | |
11068 | + * the buffer | |
11069 | + */ | |
11070 | + cp2 = kdb_buffer; | |
11071 | + len = strlen(kdb_prompt_str); | |
11072 | + if (!strncmp(cp2,kdb_prompt_str, len)) { | |
11073 | + /* | |
11074 | + * We're about to start a new | |
11075 | + * command, so we can go back | |
11076 | + * to normal mode. | |
11077 | + */ | |
11078 | + kdb_grepping_flag = 0; | |
11079 | + goto kdb_printit; | |
11080 | + } | |
11081 | + } | |
11082 | + /* no newline; don't search/write the buffer | |
11083 | + until one is there */ | |
11084 | + len = strlen(kdb_buffer); | |
11085 | + next_avail = kdb_buffer + len; | |
11086 | + size_avail = sizeof(kdb_buffer) - len; | |
11087 | + goto kdb_print_out; | |
11088 | + } | |
11089 | + | |
11090 | + /* | |
11091 | + * The newline is present; print through it or discard | |
11092 | + * it, depending on the results of the search. | |
11093 | + */ | |
11094 | + cp++; /* to byte after the newline */ | |
11095 | + replaced_byte = *cp; /* remember what/where it was */ | |
11096 | + cphold = cp; | |
11097 | + *cp = '\0'; /* end the string for our search */ | |
11098 | + | |
11099 | + /* | |
11100 | + * We now have a newline at the end of the string | |
11101 | + * Only continue with this output if it contains the | |
11102 | + * search string. | |
11103 | + */ | |
11104 | + fnd = kdb_search_string(kdb_buffer, kdb_grep_string); | |
11105 | + if (!fnd) { | |
11106 | + /* | |
11107 | + * At this point the complete line at the start | |
11108 | + * of kdb_buffer can be discarded, as it does | |
11109 | + * not contain what the user is looking for. | |
11110 | + * Shift the buffer left. | |
11111 | + */ | |
11112 | + *cphold = replaced_byte; | |
11113 | + strcpy(kdb_buffer, cphold); | |
11114 | + len = strlen(kdb_buffer); | |
11115 | + next_avail = kdb_buffer + len; | |
11116 | + size_avail = sizeof(kdb_buffer) - len; | |
11117 | + goto kdb_print_out; | |
11118 | + } | |
11119 | + /* | |
11120 | + * at this point the string is a full line and | |
11121 | + * should be printed, up to the null. | |
11122 | + */ | |
11123 | + } | |
11124 | + } | |
11125 | +kdb_printit: | |
11126 | + | |
11127 | + /* | |
11128 | + * Write to all consoles. | |
11129 | + */ | |
11130 | +#ifdef CONFIG_SPARC64 | |
11131 | + if (c == NULL) | |
11132 | + prom_printf("%s", kdb_buffer); | |
11133 | + else | |
11134 | +#endif | |
11135 | + | |
11136 | +#ifdef CONFIG_PPC64 | |
11137 | + if (udbg_write) | |
11138 | + udbg_write(kdb_buffer, strlen(kdb_buffer)); | |
11139 | + else | |
11140 | +#endif | |
11141 | + | |
11142 | + while (c) { | |
11143 | + c->write(c, kdb_buffer, strlen(kdb_buffer)); | |
11144 | + touch_nmi_watchdog(); | |
11145 | + c = c->next; | |
11146 | + } | |
11147 | + if (logging) { | |
11148 | + saved_loglevel = console_loglevel; | |
11149 | + console_loglevel = 0; | |
11150 | + printk("%s", kdb_buffer); | |
11151 | + } | |
11152 | + | |
11153 | + if (KDB_STATE(LONGJMP) && strchr(kdb_buffer, '\n')) | |
11154 | + kdb_nextline++; | |
11155 | + | |
11156 | + /* check for having reached the LINES number of printed lines */ | |
11157 | + if (kdb_nextline == linecount) { | |
11158 | + char buf1[16]=""; | |
11159 | +#if defined(CONFIG_SMP) | |
11160 | + char buf2[32]; | |
11161 | +#endif | |
11162 | + | |
11163 | + /* Watch out for recursion here. Any routine that calls | |
11164 | + * kdb_printf will come back through here. And kdb_read | |
11165 | + * uses kdb_printf to echo on serial consoles ... | |
11166 | + */ | |
11167 | + kdb_nextline = 1; /* In case of recursion */ | |
11168 | + | |
11169 | + /* | |
11170 | + * Pause until cr. | |
11171 | + */ | |
11172 | + moreprompt = kdbgetenv("MOREPROMPT"); | |
11173 | + if (moreprompt == NULL) { | |
11174 | + moreprompt = "more> "; | |
11175 | + } | |
11176 | + | |
11177 | +#if defined(CONFIG_SMP) | |
11178 | + if (strchr(moreprompt, '%')) { | |
11179 | + sprintf(buf2, moreprompt, get_cpu()); | |
11180 | + put_cpu(); | |
11181 | + moreprompt = buf2; | |
11182 | + } | |
11183 | +#endif | |
11184 | + | |
11185 | + kdb_input_flush(); | |
11186 | + c = console_drivers; | |
11187 | +#ifdef CONFIG_SPARC64 | |
11188 | + if (c == NULL) | |
11189 | + prom_printf("%s", moreprompt); | |
11190 | + else | |
11191 | +#endif | |
11192 | + | |
11193 | +#ifdef CONFIG_PPC64 | |
11194 | + if (udbg_write) | |
11195 | + udbg_write(moreprompt, strlen(moreprompt)); | |
11196 | + else | |
11197 | +#endif | |
11198 | + | |
11199 | + while (c) { | |
11200 | + c->write(c, moreprompt, strlen(moreprompt)); | |
11201 | + touch_nmi_watchdog(); | |
11202 | + c = c->next; | |
11203 | + } | |
11204 | + | |
11205 | + if (logging) | |
11206 | + printk("%s", moreprompt); | |
11207 | + | |
11208 | + kdb_read(buf1, 2); /* '2' indicates to return immediately after getting one key. */ | |
11209 | + kdb_nextline = 1; /* Really set output line 1 */ | |
11210 | + | |
11211 | + /* empty and reset the buffer: */ | |
11212 | + kdb_buffer[0] = '\0'; | |
11213 | + next_avail = kdb_buffer; | |
11214 | + size_avail = sizeof(kdb_buffer); | |
11215 | + if ((buf1[0] == 'q') || (buf1[0] == 'Q')) { | |
11216 | + /* user hit q or Q */ | |
11217 | + do_longjmp = 1; | |
11218 | + KDB_FLAG_SET(CMD_INTERRUPT); /* command was interrupted */ | |
11219 | + /* end of command output; back to normal mode */ | |
11220 | + kdb_grepping_flag = 0; | |
11221 | + kdb_printf("\n"); | |
11222 | + } else if (buf1[0] && buf1[0] != '\n') { | |
11223 | + /* user hit something other than enter */ | |
11224 | + suspend_grep = 1; /* for this recursion */ | |
11225 | + kdb_printf("\nOnly 'q' or 'Q' are processed at more prompt, input ignored\n"); | |
11226 | + } else if (kdb_grepping_flag) { | |
11227 | + /* user hit enter */ | |
11228 | + suspend_grep = 1; /* for this recursion */ | |
11229 | + kdb_printf("\n"); | |
11230 | + } | |
11231 | + kdb_input_flush(); | |
11232 | + } | |
11233 | + | |
11234 | + /* | |
11235 | + * For grep searches, shift the printed string left. | |
11236 | + * replaced_byte contains the character that was overwritten with | |
11237 | + * the terminating null, and cphold points to the null. | |
11238 | + * Then adjust the notion of available space in the buffer. | |
11239 | + */ | |
11240 | + if (kdb_grepping_flag && !suspend_grep) { | |
11241 | + *cphold = replaced_byte; | |
11242 | + strcpy(kdb_buffer, cphold); | |
11243 | + len = strlen(kdb_buffer); | |
11244 | + next_avail = kdb_buffer + len; | |
11245 | + size_avail = sizeof(kdb_buffer) - len; | |
11246 | + } | |
11247 | + | |
11248 | +kdb_print_out: | |
11249 | + suspend_grep = 0; /* end of what may have been a recursive call */ | |
11250 | + if (logging) { | |
11251 | + console_loglevel = saved_loglevel; | |
11252 | + } | |
11253 | + if (KDB_STATE(PRINTF_LOCK) && got_printf_lock) { | |
11254 | + got_printf_lock = 0; | |
11255 | + spin_unlock_irqrestore(&kdb_printf_lock, flags); | |
11256 | + KDB_STATE_CLEAR(PRINTF_LOCK); | |
11257 | + atomic_dec(&kdb_event); | |
11258 | + } else { | |
11259 | + __release(kdb_printf_lock); | |
11260 | + } | |
11261 | + preempt_enable(); | |
11262 | + if (do_longjmp) | |
11263 | +#ifdef kdba_setjmp | |
11264 | + kdba_longjmp(&kdbjmpbuf[smp_processor_id()], 1) | |
11265 | +#endif /* kdba_setjmp */ | |
11266 | + ; | |
11267 | +} | |
11268 | + | |
11269 | +/* | |
11270 | + * kdb_io_init | |
11271 | + * | |
11272 | + * Initialize kernel debugger output environment. | |
11273 | + * | |
11274 | + * Parameters: | |
11275 | + * None. | |
11276 | + * Returns: | |
11277 | + * None. | |
11278 | + * Locking: | |
11279 | + * None. | |
11280 | + * Remarks: | |
11281 | + * Select a console device. Only use a VT console if the user specified | |
11282 | + * or defaulted console= /^tty[0-9]*$/ | |
11283 | + */ | |
11284 | + | |
11285 | +void __init | |
11286 | +kdb_io_init(void) | |
11287 | +{ | |
11288 | + /* | |
11289 | + * Select a console. | |
11290 | + */ | |
11291 | + struct console *c = console_drivers; | |
11292 | + int vt_console = 0; | |
11293 | + | |
11294 | + while (c) { | |
11295 | + if ((c->flags & CON_CONSDEV) && !kdbcons) | |
11296 | + kdbcons = c; | |
11297 | + if ((c->flags & CON_ENABLED) && | |
11298 | + strncmp(c->name, "tty", 3) == 0) { | |
11299 | + char *p = c->name + 3; | |
11300 | + while (isdigit(*p)) | |
11301 | + ++p; | |
11302 | + if (*p == '\0') | |
11303 | + vt_console = 1; | |
11304 | + } | |
11305 | + c = c->next; | |
11306 | + } | |
11307 | + | |
11308 | + if (kdbcons == NULL) { | |
11309 | + printk(KERN_ERR "kdb: Initialization failed - no console. kdb is disabled.\n"); | |
11310 | + KDB_FLAG_SET(NO_CONSOLE); | |
11311 | + kdb_on = 0; | |
11312 | + } | |
11313 | + if (!vt_console) | |
11314 | + KDB_FLAG_SET(NO_VT_CONSOLE); | |
11315 | + kdb_input_flush(); | |
11316 | + return; | |
11317 | +} | |
11318 | + | |
11319 | +#ifdef CONFIG_KDB_USB | |
11320 | + | |
11321 | +int kdb_no_usb = 0; | |
11322 | + | |
11323 | +static int __init opt_kdbnousb(char *str) | |
11324 | +{ | |
11325 | + kdb_no_usb = 1; | |
11326 | + return 0; | |
11327 | +} | |
11328 | + | |
11329 | +early_param("kdbnousb", opt_kdbnousb); | |
11330 | + | |
11331 | +#endif | |
11332 | + | |
11333 | +EXPORT_SYMBOL(kdb_read); | |
11334 | --- /dev/null | |
11335 | +++ b/kdb/kdbdereference.c | |
11336 | @@ -0,0 +1,7257 @@ | |
11337 | +/* | |
11338 | + * | |
11339 | + * Most of this code is borrowed and adapted from the lkcd command "lcrash" | |
11340 | + * and its supporting libarary. | |
11341 | + * | |
11342 | + * This kdb commands for casting memory structures. | |
11343 | + * It provides | |
11344 | + * "print" "px", "pd" * | |
11345 | + * | |
11346 | + * Careful of porting the klib KL_XXX functions (they call thru a jump table | |
11347 | + * that we don't use here) | |
11348 | + * | |
11349 | + * The kernel type information is added be insmod'g the kdb debuginfo module | |
11350 | + * It loads symbolic debugging info (provided from lcrash -o), | |
11351 | + * (this information originally comes from the lcrash "kerntypes" file) | |
11352 | + * | |
11353 | + */ | |
11354 | + | |
11355 | +#define VMALLOC_START_IA64 0xa000000200000000 | |
11356 | +#include <linux/kernel.h> | |
11357 | +#include <linux/module.h> | |
11358 | +#include <linux/kdb.h> | |
11359 | +#include <linux/kdbprivate.h> | |
11360 | +#include <linux/fs.h> | |
11361 | +#include <asm/processor.h> | |
11362 | +#include <asm/uaccess.h> | |
11363 | +#include <asm/fcntl.h> | |
11364 | +#include <linux/vmalloc.h> | |
11365 | +#include <linux/ctype.h> | |
11366 | +#include <linux/file.h> | |
11367 | +#include <linux/err.h> | |
11368 | +#include "modules/lcrash/klib.h" | |
11369 | +#include "modules/lcrash/kl_stringtab.h" | |
11370 | +#include "modules/lcrash/kl_btnode.h" | |
11371 | +#include "modules/lcrash/lc_eval.h" | |
11372 | + | |
11373 | +#undef next_node /* collision with nodemask.h */ | |
11374 | +int have_debug_file = 0; | |
11375 | +dbg_sym_t *types_tree_head; | |
11376 | +dbg_sym_t *typedefs_tree_head; | |
11377 | +kltype_t *kltype_array; | |
11378 | +dbg_sym_t *dsym_types_array; | |
11379 | + | |
11380 | + | |
11381 | +EXPORT_SYMBOL(types_tree_head); | |
11382 | +EXPORT_SYMBOL(typedefs_tree_head); | |
11383 | +EXPORT_SYMBOL(kltype_array); | |
11384 | +EXPORT_SYMBOL(dsym_types_array); | |
11385 | + | |
11386 | +#define C_HEX 0x0002 | |
11387 | +#define C_WHATIS 0x0004 | |
11388 | +#define C_NOVARS 0x0008 | |
11389 | +#define C_SIZEOF 0x0010 | |
11390 | +#define C_SHOWOFFSET 0x0020 | |
11391 | +#define C_LISTHEAD 0x0040 | |
11392 | +#define C_LISTHEAD_N 0x0080 /* walk using list_head.next */ | |
11393 | +#define C_LISTHEAD_P 0x0100 /* walk using list_head.prev */ | |
11394 | +#define C_BINARY 0x0200 | |
11395 | +#define MAX_LONG_LONG 0xffffffffffffffffULL | |
11396 | +klib_t kdb_klib; | |
11397 | +klib_t *KLP = &kdb_klib; | |
11398 | +k_error_t klib_error = 0; | |
11399 | +dbg_sym_t *type_tree = (dbg_sym_t *)NULL; | |
11400 | +dbg_sym_t *typedef_tree = (dbg_sym_t *)NULL; | |
11401 | +dbg_sym_t *func_tree = (dbg_sym_t *)NULL; | |
11402 | +dbg_sym_t *srcfile_tree = (dbg_sym_t *)NULL; | |
11403 | +dbg_sym_t *var_tree = (dbg_sym_t *)NULL; | |
11404 | +dbg_sym_t *xtype_tree = (dbg_sym_t *)NULL; | |
11405 | +dbg_hashrec_t *dbg_hash[TYPE_NUM_SLOTS]; | |
11406 | +int all_count, deall_count; | |
11407 | +void single_type(char *str); | |
11408 | +void sizeof_type(char *str); | |
11409 | +typedef struct chunk_s { | |
11410 | + struct chunk_s *next; /* Must be first */ | |
11411 | + struct chunk_s *prev; /* Must be second */ | |
11412 | + void *addr; | |
11413 | + struct bucket_s *bucketp; | |
11414 | + uint32_t chunksz; /* size of memory chunk (via malloc()) */ | |
11415 | + uint32_t blksz; /* Not including header */ | |
11416 | + short blkcount; /* Number of blksz blocks in chunk */ | |
11417 | +} chunk_t; | |
11418 | + | |
11419 | +typedef struct blkhdr_s { | |
11420 | + struct blkhdr_s *next; | |
11421 | + union { | |
11422 | + struct blkhdr_s *prev; | |
11423 | + chunk_t *chunkp; | |
11424 | + } b_un; | |
11425 | + int flg; | |
11426 | + int size; | |
11427 | +} blkhdr_t; | |
11428 | + | |
11429 | +int ptrsz64 = ((int)sizeof(void *) == 8); | |
11430 | +alloc_functions_t alloc_functions; | |
11431 | + | |
11432 | +/* | |
11433 | + * return 1 if addr is invalid | |
11434 | + */ | |
11435 | +static int | |
11436 | +invalid_address(kaddr_t addr, int count) | |
11437 | +{ | |
11438 | + unsigned char c; | |
11439 | + unsigned long lcount; | |
11440 | + /* FIXME: untested? */ | |
11441 | + lcount = count; | |
11442 | + /* FIXME: use kdb_verify_area */ | |
11443 | + while (count--) { | |
11444 | + if (kdb_getarea(c, addr)) | |
11445 | + return 1; | |
11446 | + } | |
11447 | + return 0; | |
11448 | +} | |
11449 | + | |
11450 | +/* | |
11451 | + * wrappers for calls to kernel-style allocation/deallocation | |
11452 | + */ | |
11453 | +static void * | |
11454 | +kl_alloc_block(int size) | |
11455 | +{ | |
11456 | + void *vp; | |
11457 | + | |
11458 | + vp = kmalloc(size, GFP_KERNEL); | |
11459 | + if (!vp) { | |
11460 | + kdb_printf ("kmalloc of %d bytes failed\n", size); | |
11461 | + } | |
11462 | + /* important: the lcrash code sometimes assumes that the | |
11463 | + * allocation is zeroed out | |
11464 | + */ | |
11465 | + memset(vp, 0, size); | |
11466 | + all_count++; | |
11467 | + return vp; | |
11468 | +} | |
11469 | +static void | |
11470 | +kl_free_block(void *vp) | |
11471 | +{ | |
11472 | + kfree(vp); | |
11473 | + deall_count++; | |
11474 | + return; | |
11475 | +} | |
11476 | + | |
11477 | +int | |
11478 | +get_value(char *s, uint64_t *value) | |
11479 | +{ | |
11480 | + return kl_get_value(s, NULL, 0, value); | |
11481 | +} | |
11482 | + | |
11483 | +/* | |
11484 | + * kl_get_block() | |
11485 | + * | |
11486 | + * Read a size block from virtual address addr in the system memory image. | |
11487 | + */ | |
11488 | +k_error_t | |
11489 | +kl_get_block(kaddr_t addr, unsigned size, void *bp, void *mmap) | |
11490 | +{ | |
11491 | + if (!bp) { | |
11492 | + return(KLE_NULL_BUFF); | |
11493 | + } else if (!size) { | |
11494 | + return(KLE_ZERO_SIZE); | |
11495 | + } | |
11496 | + | |
11497 | + memcpy(bp, (void *)addr, size); | |
11498 | + | |
11499 | + return(0); | |
11500 | +} | |
11501 | + | |
11502 | +/* | |
11503 | + * print_value() | |
11504 | + */ | |
11505 | +void | |
11506 | +print_value(char *ldstr, uint64_t value, int width) | |
11507 | +{ | |
11508 | + int w = 0; | |
11509 | + char fmtstr[12], f, s[2]="\000\000"; | |
11510 | + | |
11511 | + if (ldstr) { | |
11512 | + kdb_printf("%s", ldstr); | |
11513 | + } | |
11514 | + s[0] = '#'; | |
11515 | + f = 'x'; | |
11516 | + if (width) { | |
11517 | + if (ptrsz64) { | |
11518 | + w = 18; /* due to leading "0x" */ | |
11519 | + } else { | |
11520 | + w = 10; /* due to leading "0x" */ | |
11521 | + } | |
11522 | + } | |
11523 | + if (w) { | |
11524 | + sprintf(fmtstr, "%%%s%d"FMT64"%c", s, w, f); | |
11525 | + } else { | |
11526 | + sprintf(fmtstr, "%%%s"FMT64"%c", s, f); | |
11527 | + } | |
11528 | + kdb_printf(fmtstr, value); | |
11529 | +} | |
11530 | + | |
11531 | +/* | |
11532 | + * print_list_head() | |
11533 | + */ | |
11534 | +void | |
11535 | +print_list_head(kaddr_t saddr) | |
11536 | +{ | |
11537 | + print_value("STRUCT ADDR: ", (uint64_t)saddr, 8); | |
11538 | + kdb_printf("\n"); | |
11539 | +} | |
11540 | + | |
11541 | +/* | |
11542 | + * check_prev_ptr() | |
11543 | + */ | |
11544 | +void | |
11545 | +check_prev_ptr(kaddr_t ptr, kaddr_t prev) | |
11546 | +{ | |
11547 | + if(ptr != prev) { | |
11548 | + kdb_printf("\nWARNING: Pointer broken. %#"FMTPTR"x," | |
11549 | + " SHOULD BE: %#"FMTPTR"x\n", prev, ptr); | |
11550 | + } | |
11551 | +} | |
11552 | + | |
11553 | +/* | |
11554 | + * kl_kaddr() -- Return a kernel virtual address stored in a structure | |
11555 | + * | |
11556 | + * Pointer 'p' points to a kernel structure | |
11557 | + * of type 's.' Get the kernel address located in member 'm.' | |
11558 | + */ | |
11559 | +kaddr_t | |
11560 | +kl_kaddr(void *p, char *s, char *m) | |
11561 | +{ | |
11562 | + uint64_t *u64p; | |
11563 | + int offset; | |
11564 | + | |
11565 | + offset = kl_member_offset(s, m); | |
11566 | + u64p = (uint64_t *)(p + offset); | |
11567 | + return((kaddr_t)*u64p); | |
11568 | +} | |
11569 | + | |
11570 | +/* | |
11571 | + * walk_structs() -- walk linked lists of kernel data structures | |
11572 | + */ | |
11573 | +int | |
11574 | +walk_structs(char *s, char *f, char *member, kaddr_t addr, int flags) | |
11575 | +{ | |
11576 | + int size, offset, mem_offset=0; | |
11577 | + kaddr_t last = 0, next; | |
11578 | + kltype_t *klt = (kltype_t *)NULL, *memklt=(kltype_t *)NULL; | |
11579 | + unsigned long long iter_threshold = 10000; | |
11580 | + | |
11581 | + int counter = 0; | |
11582 | + kaddr_t head=0, head_next=0, head_prev=0, entry=0; | |
11583 | + kaddr_t entry_next=0, entry_prev; | |
11584 | + | |
11585 | + /* field name of link pointer, determine its offset in the struct. */ | |
11586 | + if ((offset = kl_member_offset(s, f)) == -1) { | |
11587 | + kdb_printf("Could not determine offset for member %s of %s.\n", | |
11588 | + f, s); | |
11589 | + return 0; | |
11590 | + } | |
11591 | + | |
11592 | + /* Get the type of the enclosing structure */ | |
11593 | + if (!(klt = kl_find_type(s, (KLT_STRUCT|KLT_UNION)))) { | |
11594 | + kdb_printf("Could not find the type of %s\n", s); | |
11595 | + return(1); | |
11596 | + } | |
11597 | + | |
11598 | + /* Get the struct size */ | |
11599 | + if ((size = kl_struct_len(s)) == 0) { | |
11600 | + kdb_printf ("could not get the length of %s\n", s); | |
11601 | + return(1); | |
11602 | + } | |
11603 | + | |
11604 | + /* test for a named member of the structure that should be displayed */ | |
11605 | + if (member) { | |
11606 | + memklt = kl_get_member(klt, member); | |
11607 | + if (!memklt) { | |
11608 | + kdb_printf ("%s has no member %s\n", s, member); | |
11609 | + return 1; | |
11610 | + } | |
11611 | + mem_offset = kl_get_member_offset(klt, member); | |
11612 | + } | |
11613 | + | |
11614 | + if ((next = addr)) { | |
11615 | + /* get head of list (anchor) when struct list_head is used */ | |
11616 | + if (flags & C_LISTHEAD) { | |
11617 | + head = next; | |
11618 | + if (invalid_address(head, sizeof(head))) { | |
11619 | + kdb_printf ("invalid address %#lx\n", | |
11620 | + head); | |
11621 | + return 1; | |
11622 | + } | |
11623 | + /* get contents of addr struct member */ | |
11624 | + head_next = kl_kaddr((void *)head, "list_head", "next"); | |
11625 | + if (invalid_address(head, sizeof(head_next))) { | |
11626 | + kdb_printf ("invalid address %#lx\n", | |
11627 | + head_next); | |
11628 | + return 1; | |
11629 | + } | |
11630 | + /* get prev field of anchor */ | |
11631 | + head_prev = kl_kaddr((void *)head, "list_head", "prev"); | |
11632 | + if (invalid_address(head, sizeof(head_prev))) { | |
11633 | + kdb_printf ("invalid address %#lx\n", | |
11634 | + head_prev); | |
11635 | + return 1; | |
11636 | + } | |
11637 | + entry = 0; | |
11638 | + } | |
11639 | + } | |
11640 | + | |
11641 | + while(next && counter < iter_threshold) { | |
11642 | + counter++; | |
11643 | + if (counter > iter_threshold) { | |
11644 | + kdb_printf("\nWARNING: Iteration threshold reached.\n"); | |
11645 | + kdb_printf("Current threshold: %lld\n", iter_threshold); | |
11646 | + break; | |
11647 | + } | |
11648 | + if(flags & C_LISTHEAD) { | |
11649 | + if(!(entry)){ | |
11650 | + if(flags & C_LISTHEAD_N){ | |
11651 | + entry = head_next; | |
11652 | + } else { | |
11653 | + entry = head_prev; | |
11654 | + } | |
11655 | + last = head; | |
11656 | + } | |
11657 | + | |
11658 | + if(head == entry) { | |
11659 | + if(flags & C_LISTHEAD_N){ | |
11660 | + check_prev_ptr(last, head_prev); | |
11661 | + } else { | |
11662 | + check_prev_ptr(last, head_next); | |
11663 | + } | |
11664 | + break; | |
11665 | + } | |
11666 | + | |
11667 | + next = entry - offset; /* next structure */ | |
11668 | + /* check that the whole structure can be addressed */ | |
11669 | + if (invalid_address(next, size)) { | |
11670 | + kdb_printf( | |
11671 | + "invalid struct address %#lx\n", next); | |
11672 | + return 1; | |
11673 | + } | |
11674 | + /* and validate that it points to valid addresses */ | |
11675 | + entry_next = kl_kaddr((void *)entry,"list_head","next"); | |
11676 | + if (invalid_address(entry_next, sizeof(entry_next))) { | |
11677 | + kdb_printf("invalid address %#lx\n", | |
11678 | + entry_next); | |
11679 | + return 1; | |
11680 | + } | |
11681 | + entry_prev = kl_kaddr((void *)entry,"list_head","prev"); | |
11682 | + if (invalid_address(entry_prev, sizeof(entry_prev))) { | |
11683 | + kdb_printf("invalid address %#lx\n", | |
11684 | + entry_prev); | |
11685 | + return 1; | |
11686 | + } | |
11687 | + if(flags & C_LISTHEAD_N){ | |
11688 | + check_prev_ptr(last, entry_prev); | |
11689 | + } else { | |
11690 | + check_prev_ptr(last, entry_next); | |
11691 | + } | |
11692 | + print_list_head(next); | |
11693 | + last = entry; | |
11694 | + if(flags & C_LISTHEAD_N){ | |
11695 | + entry = entry_next; /* next list_head */ | |
11696 | + } else { | |
11697 | + entry = entry_prev; /* next list_head */ | |
11698 | + } | |
11699 | + } | |
11700 | + | |
11701 | + if (memklt) { | |
11702 | + /* print named sub-structure in C-like struct format. */ | |
11703 | + kl_print_member( | |
11704 | + (void *)((unsigned long)next+mem_offset), | |
11705 | + memklt, 0, C_HEX); | |
11706 | + } else { | |
11707 | + /* print entire structure in C-like struct format. */ | |
11708 | + kl_print_type((void *)next, klt, 0, C_HEX); | |
11709 | + } | |
11710 | + | |
11711 | + if(!(flags & C_LISTHEAD)) { | |
11712 | + last = next; | |
11713 | + next = (kaddr_t) (*(uint64_t*)(next + offset)); | |
11714 | + } | |
11715 | + } | |
11716 | + | |
11717 | + return(0); | |
11718 | +} | |
11719 | + | |
11720 | +/* | |
11721 | + * Implement the lcrash walk -s command | |
11722 | + * see lcrash cmd_walk.c | |
11723 | + */ | |
11724 | +int | |
11725 | +kdb_walk(int argc, const char **argv) | |
11726 | +{ | |
11727 | + int i, nonoptc=0, optc=0, flags=0, init_len=0; | |
11728 | + char *cmd, *arg, *structp=NULL, *forwp=NULL, *memberp=NULL; | |
11729 | + char *addrp=NULL; | |
11730 | + uint64_t value; | |
11731 | + kaddr_t start_addr; | |
11732 | + | |
11733 | + all_count=0; | |
11734 | + deall_count=0; | |
11735 | + if (!have_debug_file) { | |
11736 | + kdb_printf("no debuginfo file\n"); | |
11737 | + return 0; | |
11738 | + } | |
11739 | + /* If there is nothing to evaluate, just return */ | |
11740 | + if (argc == 0) { | |
11741 | + return 0; | |
11742 | + } | |
11743 | + cmd = (char *)*argv; /* s/b "walk" */ | |
11744 | + if (strcmp(cmd,"walk")) { | |
11745 | + kdb_printf("got %s, not \"walk\"\n", cmd); | |
11746 | + return 0; | |
11747 | + } | |
11748 | + | |
11749 | + for (i=1; i<=argc; i++) { | |
11750 | + arg = (char *)*(argv+i); | |
11751 | + if (*arg == '-') { | |
11752 | + optc++; | |
11753 | + if (optc > 2) { | |
11754 | + kdb_printf("too many options\n"); | |
11755 | + kdb_printf("see 'walkhelp'\n"); | |
11756 | + return 0; | |
11757 | + } | |
11758 | + if (*(arg+1) == 's') { | |
11759 | + continue; /* ignore -s */ | |
11760 | + } else if (*(arg+1) == 'h') { | |
11761 | + if ((init_len=kl_struct_len("list_head")) | |
11762 | + == 0) { | |
11763 | + kdb_printf( | |
11764 | + "could not find list_head\n"); | |
11765 | + return 0; | |
11766 | + } | |
11767 | + if (*(arg+2) == 'p') { | |
11768 | + flags = C_LISTHEAD; | |
11769 | + flags |= C_LISTHEAD_P; | |
11770 | + } else if (*(arg+2) == 'n') { | |
11771 | + flags = C_LISTHEAD; | |
11772 | + flags |= C_LISTHEAD_N; | |
11773 | + } else { | |
11774 | + kdb_printf("invalid -h option <%s>\n", | |
11775 | + arg); | |
11776 | + kdb_printf("see 'walkhelp'\n"); | |
11777 | + return 0; | |
11778 | + } | |
11779 | + } else { | |
11780 | + kdb_printf("invalid option <%s>\n", arg); | |
11781 | + kdb_printf("see 'walkhelp'\n"); | |
11782 | + return 0; | |
11783 | + } | |
11784 | + } else { | |
11785 | + nonoptc++; | |
11786 | + if (nonoptc > 4) { | |
11787 | + kdb_printf("too many arguments\n"); | |
11788 | + kdb_printf("see 'walkhelp'\n"); | |
11789 | + return 0; | |
11790 | + } | |
11791 | + if (nonoptc == 1) { | |
11792 | + structp = arg; | |
11793 | + } else if (nonoptc == 2) { | |
11794 | + forwp = arg; | |
11795 | + } else if (nonoptc == 3) { | |
11796 | + addrp = arg; | |
11797 | + } else if (nonoptc == 4) { | |
11798 | + /* the member is optional; if we get | |
11799 | + a fourth, the previous was the member */ | |
11800 | + memberp = addrp; | |
11801 | + addrp = arg; | |
11802 | + } else { | |
11803 | + kdb_printf("invalid argument <%s>\n", arg); | |
11804 | + kdb_printf("see 'walkhelp'\n"); | |
11805 | + return 0; | |
11806 | + } | |
11807 | + } | |
11808 | + } | |
11809 | + if (nonoptc < 3) { | |
11810 | + kdb_printf("too few arguments\n"); | |
11811 | + kdb_printf("see 'walkhelp'\n"); | |
11812 | + return 0; | |
11813 | + } | |
11814 | + if (!(flags & C_LISTHEAD)) { | |
11815 | + if ((init_len=kl_struct_len(structp)) == 0) { | |
11816 | + kdb_printf("could not find %s\n", structp); | |
11817 | + return 0; | |
11818 | + } | |
11819 | + } | |
11820 | + | |
11821 | + /* Get the start address of the structure */ | |
11822 | + if (get_value(addrp, &value)) { | |
11823 | + kdb_printf ("address %s invalid\n", addrp); | |
11824 | + return 0; | |
11825 | + } | |
11826 | + start_addr = (kaddr_t)value; | |
11827 | + if (invalid_address(start_addr, init_len)) { | |
11828 | + kdb_printf ("address %#lx invalid\n", start_addr); | |
11829 | + return 0; | |
11830 | + } | |
11831 | + | |
11832 | + if (memberp) { | |
11833 | + } | |
11834 | + | |
11835 | + if (walk_structs(structp, forwp, memberp, start_addr, flags)) { | |
11836 | + kdb_printf ("walk_structs failed\n"); | |
11837 | + return 0; | |
11838 | + } | |
11839 | + /* kdb_printf("ptc allocated:%d deallocated:%d\n", | |
11840 | + all_count, deall_count); */ | |
11841 | + return 0; | |
11842 | +} | |
11843 | + | |
11844 | +/* | |
11845 | + * Implement the lcrash px (print, pd) command | |
11846 | + * see lcrash cmd_print.c | |
11847 | + * | |
11848 | + * px <expression> | |
11849 | + * e.g. px *(task_struct *) <address> | |
11850 | + */ | |
11851 | +int | |
11852 | +kdb_debuginfo_print(int argc, const char **argv) | |
11853 | +{ | |
11854 | + /* argc does not count the command itself, which is argv[0] */ | |
11855 | + char *cmd, *next, *end, *exp, *cp; | |
11856 | + unsigned char *buf; | |
11857 | + int i, j, iflags; | |
11858 | + node_t *np; | |
11859 | + uint64_t flags = 0; | |
11860 | + | |
11861 | + /* If there is nothing to evaluate, just return */ | |
11862 | + if (argc == 0) { | |
11863 | + return 0; | |
11864 | + } | |
11865 | + all_count=0; | |
11866 | + deall_count=0; | |
11867 | + | |
11868 | + cmd = (char *)*argv; | |
11869 | + | |
11870 | + /* Set up the flags value. If this command was invoked via | |
11871 | + * "pd" or "px", then make sure the appropriate flag is set. | |
11872 | + */ | |
11873 | + flags = 0; | |
11874 | + if (!strcmp(cmd, "pd") || !strcmp(cmd, "print")) { | |
11875 | + flags = 0; | |
11876 | + } else if (!strcmp(cmd, "px")) { | |
11877 | + flags |= C_HEX; | |
11878 | + } else if (!strcmp(cmd, "whatis")) { | |
11879 | + if (argc != 1) { | |
11880 | + kdb_printf("usage: whatis <symbol | type>\n"); | |
11881 | + return 0; | |
11882 | + } | |
11883 | + cp = (char *)*(argv+1); | |
11884 | + single_type(cp); | |
11885 | + /* kdb_printf("allocated:%d deallocated:%d\n", | |
11886 | + all_count, deall_count); */ | |
11887 | + return 0; | |
11888 | + } else if (!strcmp(cmd, "sizeof")) { | |
11889 | + if (!have_debug_file) { | |
11890 | + kdb_printf("no debuginfo file\n"); | |
11891 | + return 0; | |
11892 | + } | |
11893 | + if (argc != 1) { | |
11894 | + kdb_printf("usage: sizeof type\n"); | |
11895 | + return 0; | |
11896 | + } | |
11897 | + cp = (char *)*(argv+1); | |
11898 | + sizeof_type(cp); | |
11899 | + return 0; | |
11900 | + } else { | |
11901 | + kdb_printf("command error: %s\n", cmd); | |
11902 | + return 0; | |
11903 | + } | |
11904 | + | |
11905 | + /* | |
11906 | + * Count the number of bytes necessary to hold the entire expression | |
11907 | + * string. | |
11908 | + */ | |
11909 | + for (i=1, j=0; i <= argc; i++) { | |
11910 | + j += (strlen(*(argv+i)) + 1); | |
11911 | + } | |
11912 | + | |
11913 | + /* | |
11914 | + * Allocate space for the expression string and copy the individual | |
11915 | + * arguments into it. | |
11916 | + */ | |
11917 | + buf = kl_alloc_block(j); | |
11918 | + if (!buf) { | |
11919 | + return 0; | |
11920 | + } | |
11921 | + | |
11922 | + for (i=1; i <= argc; i++) { | |
11923 | + strcat(buf, *(argv+i)); | |
11924 | + /* put spaces between arguments */ | |
11925 | + if (i < argc) { | |
11926 | + strcat(buf, " "); | |
11927 | + } | |
11928 | + } | |
11929 | + | |
11930 | + /* Walk through the expression string, expression by expression. | |
11931 | + * Note that a comma (',') is the delimiting character between | |
11932 | + * expressions. | |
11933 | + */ | |
11934 | + next = buf; | |
11935 | + while (next) { | |
11936 | + if ((end = strchr(next, ','))) { | |
11937 | + *end = (char)0; | |
11938 | + } | |
11939 | + | |
11940 | + /* Copy the next expression to a separate expression string. | |
11941 | + * A separate expresison string is necessary because it is | |
11942 | + * likely to get freed up in eval() when variables get expanded. | |
11943 | + */ | |
11944 | + i = strlen(next)+1; | |
11945 | + exp = (char *)kl_alloc_block(i); | |
11946 | + if (!exp) { | |
11947 | + return 0; | |
11948 | + } | |
11949 | + strcpy(exp, next); | |
11950 | + | |
11951 | + /* Evaluate the expression */ | |
11952 | + np = eval(&exp, 0); | |
11953 | + if (!np || eval_error) { | |
11954 | + print_eval_error(cmd, exp, | |
11955 | + (error_token ? error_token : (char*)NULL), | |
11956 | + eval_error, CMD_NAME_FLG); | |
11957 | + if (np) { | |
11958 | + free_nodes(np); | |
11959 | + } | |
11960 | + kl_free_block(buf); | |
11961 | + kl_free_block(exp); | |
11962 | + free_eval_memory(); | |
11963 | + return 0; | |
11964 | + } | |
11965 | + iflags = flags; | |
11966 | + if (print_eval_results(np, iflags)) { | |
11967 | + free_nodes(np); | |
11968 | + kl_free_block(buf); | |
11969 | + free_eval_memory(); | |
11970 | + return 0; | |
11971 | + } | |
11972 | + kl_free_block(exp); | |
11973 | + | |
11974 | + if (end) { | |
11975 | + next = end + 1; | |
11976 | + kdb_printf(" "); | |
11977 | + } else { | |
11978 | + next = (char*)NULL; | |
11979 | + kdb_printf("\n"); | |
11980 | + } | |
11981 | + free_nodes(np); | |
11982 | + } | |
11983 | + free_eval_memory(); | |
11984 | + kl_free_block(buf); | |
11985 | + /* kdb_printf("allocated:%d deallocated:%d\n", | |
11986 | + all_count, deall_count); */ | |
11987 | + return 0; | |
11988 | +} | |
11989 | + | |
11990 | +/* | |
11991 | + * Display help for the px command | |
11992 | + */ | |
11993 | +int | |
11994 | +kdb_pxhelp(int argc, const char **argv) | |
11995 | +{ | |
11996 | + if (have_debug_file) { | |
11997 | + kdb_printf ("Some examples of using the px command:\n"); | |
11998 | + kdb_printf (" the whole structure:\n"); | |
11999 | + kdb_printf (" px *(task_struct *)0xe0000...\n"); | |
12000 | + kdb_printf (" one member:\n"); | |
12001 | + kdb_printf (" px (*(task_struct *)0xe0000...)->comm\n"); | |
12002 | + kdb_printf (" the address of a member\n"); | |
12003 | + kdb_printf (" px &((task_struct *)0xe0000...)->children\n"); | |
12004 | + kdb_printf (" a structure pointed to by a member:\n"); | |
12005 | + kdb_printf (" px ((*(class_device *)0xe0000...)->class)->name\n"); | |
12006 | + kdb_printf (" array element:\n"); | |
12007 | + kdb_printf (" px (cache_sizes *)0xa0000...[0]\n"); | |
12008 | + kdb_printf (" px (task_struct *)(0xe0000...)->cpus_allowed.bits[0]\n"); | |
12009 | + } else { | |
12010 | + kdb_printf ("There is no debug info file.\n"); | |
12011 | + kdb_printf ("The px/pd/print commands can only evaluate "); | |
12012 | + kdb_printf ("arithmetic expressions.\n"); | |
12013 | + } | |
12014 | + return 0; | |
12015 | +} | |
12016 | + | |
12017 | +/* | |
12018 | + * Display help for the walk command | |
12019 | + */ | |
12020 | +int | |
12021 | +kdb_walkhelp(int argc, const char **argv) | |
12022 | +{ | |
12023 | + if (!have_debug_file) { | |
12024 | + kdb_printf("no debuginfo file\n"); | |
12025 | + return 0; | |
12026 | + } | |
12027 | + kdb_printf ("Using the walk command:\n"); | |
12028 | + kdb_printf (" (only the -s (symbolic) form is supported, so -s is ignored)\n"); | |
12029 | + kdb_printf ("\n"); | |
12030 | + kdb_printf (" If the list is not linked with list_head structures:\n"); | |
12031 | + kdb_printf (" walk [-s] struct name-of-forward-pointer address\n"); | |
12032 | + kdb_printf (" example: walk xyz_struct next 0xe00....\n"); | |
12033 | + kdb_printf ("\n"); | |
12034 | + kdb_printf (" If the list is linked with list_head structures, use -hn\n"); | |
12035 | + kdb_printf (" to walk the 'next' list, -hp for the 'prev' list\n"); | |
12036 | + kdb_printf (" walk -h[n|p] struct name-of-forward-pointer [member-to-show] address-of-list-head\n"); | |
12037 | + kdb_printf (" example, to show the entire task_struct:\n"); | |
12038 | + kdb_printf (" walk -hn task_struct tasks 0xe000....\n"); | |
12039 | + kdb_printf (" example, to show the task_struct member comm:\n"); | |
12040 | + kdb_printf (" walk -hn task_struct tasks comm 0xe000....\n"); | |
12041 | + kdb_printf (" (address is not the address of first member's list_head, "); | |
12042 | + kdb_printf ("but of the anchoring list_head\n"); | |
12043 | + return 0; | |
12044 | +} | |
12045 | + | |
12046 | +/* | |
12047 | + * dup_block() | |
12048 | + */ | |
12049 | +void * | |
12050 | +dup_block(void *b, int len) | |
12051 | +{ | |
12052 | + void *b2; | |
12053 | + | |
12054 | + if ((b2 = kl_alloc_block(len))) { | |
12055 | + memcpy(b2, b, len); /* dst, src, sz */ | |
12056 | + } | |
12057 | + return(b2); | |
12058 | +} | |
12059 | + | |
12060 | +/* | |
12061 | + * kl_reset_error() | |
12062 | + */ | |
12063 | +void | |
12064 | +kl_reset_error(void) | |
12065 | +{ | |
12066 | + klib_error = 0; | |
12067 | +} | |
12068 | + | |
12069 | +/* | |
12070 | + * given a symbol name, look up its address | |
12071 | + * | |
12072 | + * in lcrash, this would return a pointer to the syment_t in | |
12073 | + * a binary tree of them | |
12074 | + * | |
12075 | + * In this one, look up the symbol in the standard kdb way, | |
12076 | + * which fills in the kdb_symtab_t. | |
12077 | + * Then fill in the global syment_t "lkup_syment" -- assuming | |
12078 | + * we'll only need one at a time! | |
12079 | + * | |
12080 | + * kl_lkup_symname returns the address of syment_t if the symbol is | |
12081 | + * found, else null. | |
12082 | + * | |
12083 | + * Note: we allocate a syment_t the caller should kfree it | |
12084 | + */ | |
12085 | +syment_t * | |
12086 | +kl_lkup_symname (char *cp) | |
12087 | +{ | |
12088 | + syment_t *sp; | |
12089 | + kdb_symtab_t kdb_symtab; | |
12090 | + | |
12091 | + if (kdbgetsymval(cp, &kdb_symtab)) { | |
12092 | + sp = (syment_t *)kl_alloc_block(sizeof(syment_t)); | |
12093 | + sp->s_addr = (kaddr_t)kdb_symtab.sym_start; | |
12094 | + KL_ERROR = 0; | |
12095 | + return (sp); | |
12096 | + } else { | |
12097 | + /* returns 0 if the symbol is not found */ | |
12098 | + KL_ERROR = KLE_INVALID_VALUE; | |
12099 | + return ((syment_t *)0); | |
12100 | + } | |
12101 | +} | |
12102 | + | |
12103 | +/* | |
12104 | + * kl_get_ra() | |
12105 | + * | |
12106 | + * This function returns its own return address. | |
12107 | + * Usefule when trying to capture where we came from. | |
12108 | + */ | |
12109 | +void* | |
12110 | +kl_get_ra(void) | |
12111 | +{ | |
12112 | + return (__builtin_return_address(0)); | |
12113 | +} | |
12114 | + | |
12115 | +/* start kl_util.c */ | |
12116 | +/* | |
12117 | + * Definitions for the do_math() routine. | |
12118 | + */ | |
12119 | +#define M_ADD '+' | |
12120 | +#define M_SUBTRACT '-' | |
12121 | +#define M_MULTIPLY '*' | |
12122 | +#define M_DIVIDE '/' | |
12123 | + | |
12124 | +/* | |
12125 | + * do_math() -- Calculate some math values based on a string argument | |
12126 | + * passed into the function. For example, if you use: | |
12127 | + * | |
12128 | + * 0xffffc000*2+6/5-3*19-8 | |
12129 | + * | |
12130 | + * And you will get the value 0xffff7fc0 back. I could | |
12131 | + * probably optimize this a bit more, but right now, it | |
12132 | + * works, which is good enough for me. | |
12133 | + */ | |
12134 | +static uint64_t | |
12135 | +do_math(char *str) | |
12136 | +{ | |
12137 | + int i = 0; | |
12138 | + char *buf, *loc; | |
12139 | + uint64_t value1, value2; | |
12140 | + syment_t *sp; | |
12141 | + | |
12142 | + buf = (char *)kl_alloc_block((strlen(str) + 1)); | |
12143 | + sprintf(buf, "%s", str); | |
12144 | + for (i = strlen(str); i >= 0; i--) { | |
12145 | + if ((str[i] == M_ADD) || (str[i] == M_SUBTRACT)) { | |
12146 | + buf[i] = '\0'; | |
12147 | + value1 = do_math(buf); | |
12148 | + value2 = do_math(&str[i+1]); | |
12149 | + kl_free_block((void *)buf); | |
12150 | + if (str[i] == M_SUBTRACT) { | |
12151 | + return value1 - value2; | |
12152 | + } else { | |
12153 | + return value1 + value2; | |
12154 | + } | |
12155 | + } | |
12156 | + } | |
12157 | + | |
12158 | + for (i = strlen(str); i >= 0; i--) { | |
12159 | + if ((str[i] == M_MULTIPLY) || (str[i] == M_DIVIDE)) { | |
12160 | + buf[i] = '\0'; | |
12161 | + value1 = do_math(buf); | |
12162 | + value2 = do_math(&str[i+1]); | |
12163 | + kl_free_block((void *)buf); | |
12164 | + if (str[i] == M_MULTIPLY) { | |
12165 | + return (value1 * value2); | |
12166 | + } else { | |
12167 | + if (value2 == 0) { | |
12168 | + /* handle divide by zero */ | |
12169 | + /* XXX -- set proper error code */ | |
12170 | + klib_error = 1; | |
12171 | + return (0); | |
12172 | + } else { | |
12173 | + return (value1 / value2); | |
12174 | + } | |
12175 | + } | |
12176 | + } | |
12177 | + } | |
12178 | + | |
12179 | + /* | |
12180 | + * Otherwise, just process the value, and return it. | |
12181 | + */ | |
12182 | + sp = kl_lkup_symname(buf); | |
12183 | + if (KL_ERROR) { | |
12184 | + KL_ERROR = 0; | |
12185 | + value2 = kl_strtoull(buf, &loc, 10); | |
12186 | + if (((!value2) && (buf[0] != '0')) || (*loc) || | |
12187 | + (!strncmp(buf, "0x", 2)) || (!strncmp(buf, "0X", 2))) { | |
12188 | + value1 = (kaddr_t)kl_strtoull(buf, (char**)NULL, 16); | |
12189 | + } else { | |
12190 | + value1 = (unsigned)kl_strtoull(buf, (char**)NULL, 10); | |
12191 | + } | |
12192 | + } else { | |
12193 | + value1 = (kaddr_t)sp->s_addr; | |
12194 | + kl_free_block((void *)sp); | |
12195 | + } | |
12196 | + kl_free_block((void *)buf); | |
12197 | + return (value1); | |
12198 | +} | |
12199 | +/* | |
12200 | + * kl_get_value() -- Translate numeric input strings | |
12201 | + * | |
12202 | + * A generic routine for translating an input string (param) in a | |
12203 | + * number of dfferent ways. If the input string is an equation | |
12204 | + * (contains the characters '+', '-', '/', and '*'), then perform | |
12205 | + * the math evaluation and return one of the following modes (if | |
12206 | + * mode is passed): | |
12207 | + * | |
12208 | + * 0 -- if the resulting value is <= elements, if elements (number | |
12209 | + * of elements in a table) is passed. | |
12210 | + * | |
12211 | + * 1 -- if the first character in param is a pound sign ('#'). | |
12212 | + * | |
12213 | + * 3 -- the numeric result of an equation. | |
12214 | + * | |
12215 | + * If the input string is NOT an equation, mode (if passed) will be | |
12216 | + * set in one of the following ways (depending on the contents of | |
12217 | + * param and elements). | |
12218 | + * | |
12219 | + * o When the first character of param is a pound sign ('#'), mode | |
12220 | + * is set equal to one and the trailing numeric value (assumed to | |
12221 | + * be decimal) is returned. | |
12222 | + * | |
12223 | + * o When the first two characters in param are "0x" or "0X," or | |
12224 | + * when when param contains one of the characers "abcdef," or when | |
12225 | + * the length of the input value is eight characters. mode is set | |
12226 | + * equal to two and the numeric value contained in param is | |
12227 | + * translated as hexadecimal and returned. | |
12228 | + * | |
12229 | + * o The value contained in param is translated as decimal and mode | |
12230 | + * is set equal to zero. The resulting value is then tested to see | |
12231 | + * if it exceeds elements (if passed). If it does, then value is | |
12232 | + * translated as hexadecimal and mode is set equal to two. | |
12233 | + * | |
12234 | + * Note that mode is only set when a pointer is passed in the mode | |
12235 | + * paramater. Also note that when elements is set equal to zero, any | |
12236 | + * non-hex (as determined above) value not starting with a pound sign | |
12237 | + * will be translated as hexadecimal (mode will be set equal to two) -- | |
12238 | + * IF the length of the string of characters is less than 16 (kaddr_t). | |
12239 | + * | |
12240 | + */ | |
12241 | +int | |
12242 | +kl_get_value(char *param, int *mode, int elements, uint64_t *value) | |
12243 | +{ | |
12244 | + char *loc; | |
12245 | + uint64_t v; | |
12246 | + | |
12247 | + kl_reset_error(); | |
12248 | + | |
12249 | + /* Check to see if we are going to need to do any math | |
12250 | + */ | |
12251 | + if (strpbrk(param, "+-/*")) { | |
12252 | + if (!strncmp(param, "#", 1)) { | |
12253 | + v = do_math(¶m[1]); | |
12254 | + if (mode) { | |
12255 | + *mode = 1; | |
12256 | + } | |
12257 | + } else { | |
12258 | + v = do_math(param); | |
12259 | + if (mode) { | |
12260 | + if (elements && (*value <= elements)) { | |
12261 | + *mode = 0; | |
12262 | + } else { | |
12263 | + *mode = 3; | |
12264 | + } | |
12265 | + } | |
12266 | + } | |
12267 | + } else { | |
12268 | + if (!strncmp(param, "#", 1)) { | |
12269 | + if (!strncmp(param, "0x", 2) | |
12270 | + || !strncmp(param, "0X", 2) | |
12271 | + || strpbrk(param, "abcdef")) { | |
12272 | + v = kl_strtoull(¶m[1], &loc, 16); | |
12273 | + } else { | |
12274 | + v = kl_strtoull(¶m[1], &loc, 10); | |
12275 | + } | |
12276 | + if (loc) { | |
12277 | + KL_ERROR = KLE_INVALID_VALUE; | |
12278 | + return (1); | |
12279 | + } | |
12280 | + if (mode) { | |
12281 | + *mode = 1; | |
12282 | + } | |
12283 | + } else if (!strncmp(param, "0x", 2) || !strncmp(param, "0X", 2) | |
12284 | + || strpbrk(param, "abcdef")) { | |
12285 | + v = kl_strtoull(param, &loc, 16); | |
12286 | + if (loc) { | |
12287 | + KL_ERROR = KLE_INVALID_VALUE; | |
12288 | + return (1); | |
12289 | + } | |
12290 | + if (mode) { | |
12291 | + *mode = 2; /* HEX VALUE */ | |
12292 | + } | |
12293 | + } else if (elements || (strlen(param) < 16) || | |
12294 | + (strlen(param) > 16)) { | |
12295 | + v = kl_strtoull(param, &loc, 10); | |
12296 | + if (loc) { | |
12297 | + KL_ERROR = KLE_INVALID_VALUE; | |
12298 | + return (1); | |
12299 | + } | |
12300 | + if (elements && (v >= elements)) { | |
12301 | + v = (kaddr_t)kl_strtoull(param, | |
12302 | + (char**)NULL, 16); | |
12303 | + if (mode) { | |
12304 | + *mode = 2; /* HEX VALUE */ | |
12305 | + } | |
12306 | + } else if (mode) { | |
12307 | + *mode = 0; | |
12308 | + } | |
12309 | + } else { | |
12310 | + v = kl_strtoull(param, &loc, 16); | |
12311 | + if (loc) { | |
12312 | + KL_ERROR = KLE_INVALID_VALUE; | |
12313 | + return (1); | |
12314 | + } | |
12315 | + if (mode) { | |
12316 | + *mode = 2; /* ASSUME HEX VALUE */ | |
12317 | + } | |
12318 | + } | |
12319 | + } | |
12320 | + *value = v; | |
12321 | + return (0); | |
12322 | +} | |
12323 | +/* end kl_util.c */ | |
12324 | + | |
12325 | +/* start kl_libutil.c */ | |
12326 | +static int | |
12327 | +valid_digit(char c, int base) | |
12328 | +{ | |
12329 | + switch(base) { | |
12330 | + case 2: | |
12331 | + if ((c >= '0') && (c <= '1')) { | |
12332 | + return(1); | |
12333 | + } else { | |
12334 | + return(0); | |
12335 | + } | |
12336 | + case 8: | |
12337 | + if ((c >= '0') && (c <= '7')) { | |
12338 | + return(1); | |
12339 | + } else { | |
12340 | + return(0); | |
12341 | + } | |
12342 | + case 10: | |
12343 | + if ((c >= '0') && (c <= '9')) { | |
12344 | + return(1); | |
12345 | + } else { | |
12346 | + return(0); | |
12347 | + } | |
12348 | + case 16: | |
12349 | + if (((c >= '0') && (c <= '9')) | |
12350 | + || ((c >= 'a') && (c <= 'f')) | |
12351 | + || ((c >= 'A') && (c <= 'F'))) { | |
12352 | + return(1); | |
12353 | + } else { | |
12354 | + return(0); | |
12355 | + } | |
12356 | + } | |
12357 | + return(0); | |
12358 | +} | |
12359 | + | |
12360 | +static int | |
12361 | +digit_value(char c, int base, int *val) | |
12362 | +{ | |
12363 | + if (!valid_digit(c, base)) { | |
12364 | + return(1); | |
12365 | + } | |
12366 | + switch (base) { | |
12367 | + case 2: | |
12368 | + case 8: | |
12369 | + case 10: | |
12370 | + *val = (int)((int)(c - 48)); | |
12371 | + break; | |
12372 | + case 16: | |
12373 | + if ((c >= 'a') && (c <= 'f')) { | |
12374 | + *val = ((int)(c - 87)); | |
12375 | + } else if ((c >= 'A') && (c <= 'F')) { | |
12376 | + *val = ((int)(c - 55)); | |
12377 | + } else { | |
12378 | + *val = ((int)(c - 48)); | |
12379 | + } | |
12380 | + } | |
12381 | + return(0); | |
12382 | +} | |
12383 | + | |
12384 | +uint64_t | |
12385 | +kl_strtoull(char *str, char **loc, int base) | |
12386 | +{ | |
12387 | + int dval; | |
12388 | + uint64_t i = 1, v, value = 0; | |
12389 | + char *c, *cp = str; | |
12390 | + | |
12391 | + *loc = (char *)NULL; | |
12392 | + if (base == 0) { | |
12393 | + if (!strncmp(cp, "0x", 2) || !strncmp(cp, "0X", 2)) { | |
12394 | + base = 16; | |
12395 | + } else if (cp[0] == '0') { | |
12396 | + if (cp[1] == 'b') { | |
12397 | + base = 2; | |
12398 | + } else { | |
12399 | + base = 8; | |
12400 | + } | |
12401 | + } else if (strpbrk(cp, "abcdefABCDEF")) { | |
12402 | + base = 16; | |
12403 | + } else { | |
12404 | + base = 10; | |
12405 | + } | |
12406 | + } | |
12407 | + if ((base == 8) && (*cp == '0')) { | |
12408 | + cp += 1; | |
12409 | + } else if ((base == 2) && !strncmp(cp, "0b", 2)) { | |
12410 | + cp += 2; | |
12411 | + } else if ((base == 16) && | |
12412 | + (!strncmp(cp, "0x", 2) || !strncmp(cp, "0X", 2))) { | |
12413 | + cp += 2; | |
12414 | + } | |
12415 | + c = &cp[strlen(cp) - 1]; | |
12416 | + while (c >= cp) { | |
12417 | + | |
12418 | + if (digit_value(*c, base, &dval)) { | |
12419 | + if (loc) { | |
12420 | + *loc = c; | |
12421 | + } | |
12422 | + return(value); | |
12423 | + } | |
12424 | + v = dval * i; | |
12425 | + if ((MAX_LONG_LONG - value) < v) { | |
12426 | + return(MAX_LONG_LONG); | |
12427 | + } | |
12428 | + value += v; | |
12429 | + i *= (uint64_t)base; | |
12430 | + c--; | |
12431 | + } | |
12432 | + return(value); | |
12433 | +} | |
12434 | +/* end kl_libutil.c */ | |
12435 | + | |
12436 | +/* | |
12437 | + * dbg_hash_sym() | |
12438 | + */ | |
12439 | +void | |
12440 | +dbg_hash_sym(uint64_t typenum, dbg_sym_t *stp) | |
12441 | +{ | |
12442 | + dbg_hashrec_t *shp, *hshp; | |
12443 | + | |
12444 | + if ((typenum == 0) || (!stp)) { | |
12445 | + return; | |
12446 | + } | |
12447 | + shp = (dbg_hashrec_t *)kl_alloc_block(sizeof(dbg_hashrec_t)); | |
12448 | + shp->h_typenum = typenum; | |
12449 | + shp->h_ptr = stp; | |
12450 | + shp->h_next = (dbg_hashrec_t *)NULL; | |
12451 | + if ((hshp = dbg_hash[TYPE_NUM_HASH(typenum)])) { | |
12452 | + while (hshp->h_next) { | |
12453 | + hshp = hshp->h_next; | |
12454 | + } | |
12455 | + hshp->h_next = shp; | |
12456 | + } else { | |
12457 | + dbg_hash[TYPE_NUM_HASH(typenum)] = shp; | |
12458 | + } | |
12459 | +} | |
12460 | + | |
12461 | +/* | |
12462 | + * dbg_find_sym() | |
12463 | + */ | |
12464 | +dbg_sym_t * | |
12465 | +dbg_find_sym(char *name, int type, uint64_t typenum) | |
12466 | +{ | |
12467 | + dbg_sym_t *stp = (dbg_sym_t *)NULL; | |
12468 | + | |
12469 | + if (name && strlen(name)) { | |
12470 | + /* Cycle through the type flags and see if any records are | |
12471 | + * present. Note that if multiple type flags or DBG_ALL is | |
12472 | + * passed in, only the first occurance of 'name' will be | |
12473 | + * found and returned. If name exists in multiple trees, | |
12474 | + * then multiple searches are necessary to find them. | |
12475 | + */ | |
12476 | + if (type & DBG_TYPE) { | |
12477 | + if ((stp = (dbg_sym_t *)kl_find_btnode((btnode_t *) | |
12478 | + type_tree, name, (int *)NULL))) { | |
12479 | + goto found_sym; | |
12480 | + } | |
12481 | + } | |
12482 | + if (type & DBG_TYPEDEF) { | |
12483 | + if ((stp = (dbg_sym_t *)kl_find_btnode((btnode_t *) | |
12484 | + typedef_tree, name, (int *)NULL))) { | |
12485 | + goto found_sym; | |
12486 | + } | |
12487 | + } | |
12488 | + if (!stp) { | |
12489 | + return((dbg_sym_t*)NULL); | |
12490 | + } | |
12491 | + } | |
12492 | +found_sym: | |
12493 | + if (typenum) { | |
12494 | + dbg_hashrec_t *hshp; | |
12495 | + | |
12496 | + if (stp) { | |
12497 | + if (stp->sym_typenum == typenum) { | |
12498 | + return(stp); | |
12499 | + } | |
12500 | + } else if ((hshp = dbg_hash[TYPE_NUM_HASH(typenum)])) { | |
12501 | + while (hshp) { | |
12502 | + if (hshp->h_typenum == typenum) { | |
12503 | + return(hshp->h_ptr); | |
12504 | + } | |
12505 | + hshp = hshp->h_next; | |
12506 | + } | |
12507 | + } | |
12508 | + } | |
12509 | + return(stp); | |
12510 | +} | |
12511 | + | |
12512 | +/* | |
12513 | + * kl_find_type() -- find a KLT type by name. | |
12514 | + */ | |
12515 | +kltype_t * | |
12516 | +kl_find_type(char *name, int tnum) | |
12517 | +{ | |
12518 | + dbg_sym_t *stp; | |
12519 | + kltype_t *kltp = (kltype_t *)NULL; | |
12520 | + | |
12521 | + if (!have_debug_file) { | |
12522 | + kdb_printf("no debuginfo file\n"); | |
12523 | + return kltp; | |
12524 | + } | |
12525 | + | |
12526 | + if (!tnum || IS_TYPE(tnum)) { | |
12527 | + if ((stp = dbg_find_sym(name, DBG_TYPE, 0))) { | |
12528 | + kltp = (kltype_t *)stp->sym_kltype; | |
12529 | + if (tnum && !(kltp->kl_type & tnum)) { | |
12530 | + /* We have found a type by this name | |
12531 | + * but it does not have the right | |
12532 | + * type number (e.g., we're looking | |
12533 | + * for a struct and we don't find | |
12534 | + * a KLT_STRUCT type by this name). | |
12535 | + */ | |
12536 | + return((kltype_t *)NULL); | |
12537 | + } | |
12538 | + } | |
12539 | + } | |
12540 | + if (!tnum || IS_TYPEDEF(tnum)) { | |
12541 | + if ((stp = dbg_find_sym(name, DBG_TYPEDEF, 0))) { | |
12542 | + kltp = (kltype_t *)stp->sym_kltype; | |
12543 | + } | |
12544 | + } | |
12545 | + return(kltp); | |
12546 | +} | |
12547 | + | |
12548 | +/* | |
12549 | + * kl_first_btnode() -- non-recursive implementation. | |
12550 | + */ | |
12551 | +btnode_t * | |
12552 | +kl_first_btnode(btnode_t *np) | |
12553 | +{ | |
12554 | + if (!np) { | |
12555 | + return((btnode_t *)NULL); | |
12556 | + } | |
12557 | + | |
12558 | + /* Walk down the left side 'til the end... | |
12559 | + */ | |
12560 | + while (np->bt_left) { | |
12561 | + np = np->bt_left; | |
12562 | + } | |
12563 | + return(np); | |
12564 | +} | |
12565 | + | |
12566 | +/* | |
12567 | + * kl_next_btnode() -- non-recursive implementation. | |
12568 | + */ | |
12569 | +btnode_t * | |
12570 | +kl_next_btnode(btnode_t *node) | |
12571 | +{ | |
12572 | + btnode_t *np = node, *parent; | |
12573 | + | |
12574 | + if (np) { | |
12575 | + if (np->bt_right) { | |
12576 | + return(kl_first_btnode(np->bt_right)); | |
12577 | + } else { | |
12578 | + parent = np->bt_parent; | |
12579 | +next: | |
12580 | + if (parent) { | |
12581 | + if (parent->bt_left == np) { | |
12582 | + return(parent); | |
12583 | + } | |
12584 | + np = parent; | |
12585 | + parent = parent->bt_parent; | |
12586 | + goto next; | |
12587 | + } | |
12588 | + } | |
12589 | + } | |
12590 | + return((btnode_t *)NULL); | |
12591 | +} | |
12592 | + | |
12593 | +/* | |
12594 | + * dbg_next_sym() | |
12595 | + */ | |
12596 | +dbg_sym_t * | |
12597 | +dbg_next_sym(dbg_sym_t *stp) | |
12598 | +{ | |
12599 | + dbg_sym_t *next_stp; | |
12600 | + | |
12601 | + next_stp = (dbg_sym_t *)kl_next_btnode((btnode_t *)stp); | |
12602 | + return(next_stp); | |
12603 | +} | |
12604 | + | |
12605 | +/* | |
12606 | + * kl_prev_btnode() -- non-recursive implementation. | |
12607 | + */ | |
12608 | +btnode_t * | |
12609 | +kl_prev_btnode(btnode_t *node) | |
12610 | +{ | |
12611 | + btnode_t *np = node, *parent; | |
12612 | + | |
12613 | + if (np) { | |
12614 | + if (np->bt_left) { | |
12615 | + np = np->bt_left; | |
12616 | + while (np->bt_right) { | |
12617 | + np = np->bt_right; | |
12618 | + } | |
12619 | + return(np); | |
12620 | + } | |
12621 | + parent = np->bt_parent; | |
12622 | +next: | |
12623 | + if (parent) { | |
12624 | + if (parent->bt_right == np) { | |
12625 | + return(parent); | |
12626 | + } | |
12627 | + np = parent; | |
12628 | + parent = parent->bt_parent; | |
12629 | + goto next; | |
12630 | + } | |
12631 | + } | |
12632 | + return((btnode_t *)NULL); | |
12633 | +} | |
12634 | + | |
12635 | +/* | |
12636 | + * dbg_prev_sym() | |
12637 | + */ | |
12638 | +dbg_sym_t * | |
12639 | +dbg_prev_sym(dbg_sym_t *stp) | |
12640 | +{ | |
12641 | + dbg_sym_t *prev_stp; | |
12642 | + | |
12643 | + prev_stp = (dbg_sym_t *)kl_prev_btnode((btnode_t *)stp); | |
12644 | + return(prev_stp); | |
12645 | +} | |
12646 | + | |
12647 | +/* | |
12648 | + * kl_find_next_type() -- find next KLT type | |
12649 | + */ | |
12650 | +kltype_t * | |
12651 | +kl_find_next_type(kltype_t *kltp, int type) | |
12652 | +{ | |
12653 | + kltype_t *nkltp = NULL; | |
12654 | + dbg_sym_t *nstp; | |
12655 | + | |
12656 | + if (kltp && kltp->kl_ptr) { | |
12657 | + nstp = (dbg_sym_t *)kltp->kl_ptr; | |
12658 | + nkltp = (kltype_t *)nstp->sym_kltype; | |
12659 | + if (type) { | |
12660 | + while(nkltp && !(nkltp->kl_type & type)) { | |
12661 | + if ((nstp = dbg_next_sym(nstp))) { | |
12662 | + nkltp = (kltype_t *)nstp->sym_kltype; | |
12663 | + } else { | |
12664 | + nkltp = (kltype_t *)NULL; | |
12665 | + } | |
12666 | + } | |
12667 | + } | |
12668 | + } | |
12669 | + return(nkltp); | |
12670 | +} | |
12671 | + | |
12672 | +/* | |
12673 | + * dbg_first_sym() | |
12674 | + */ | |
12675 | +dbg_sym_t * | |
12676 | +dbg_first_sym(int type) | |
12677 | +{ | |
12678 | + dbg_sym_t *stp = (dbg_sym_t *)NULL; | |
12679 | + | |
12680 | + switch(type) { | |
12681 | + case DBG_TYPE: | |
12682 | + stp = (dbg_sym_t *) | |
12683 | + kl_first_btnode((btnode_t *)type_tree); | |
12684 | + break; | |
12685 | + case DBG_TYPEDEF: | |
12686 | + stp = (dbg_sym_t *) | |
12687 | + kl_first_btnode((btnode_t *)typedef_tree); | |
12688 | + break; | |
12689 | + } | |
12690 | + return(stp); | |
12691 | +} | |
12692 | + | |
12693 | +/* | |
12694 | + * kl_first_type() | |
12695 | + */ | |
12696 | +kltype_t * | |
12697 | +kl_first_type(int tnum) | |
12698 | +{ | |
12699 | + kltype_t *kltp = NULL; | |
12700 | + dbg_sym_t *stp; | |
12701 | + | |
12702 | + if (IS_TYPE(tnum)) { | |
12703 | + /* If (tnum == KLT_TYPE), then return the first type | |
12704 | + * record, regardless of the type. Otherwise, search | |
12705 | + * for the frst type that mapps into tnum. | |
12706 | + */ | |
12707 | + if ((stp = dbg_first_sym(DBG_TYPE))) { | |
12708 | + kltp = (kltype_t *)stp->sym_kltype; | |
12709 | + if (tnum != KLT_TYPE) { | |
12710 | + while (kltp && !(kltp->kl_type & tnum)) { | |
12711 | + if ((stp = dbg_next_sym(stp))) { | |
12712 | + kltp = (kltype_t *)stp->sym_kltype; | |
12713 | + } else { | |
12714 | + kltp = (kltype_t *)NULL; | |
12715 | + } | |
12716 | + } | |
12717 | + } | |
12718 | + } | |
12719 | + } else if (IS_TYPEDEF(tnum)) { | |
12720 | + if ((stp = dbg_first_sym(DBG_TYPEDEF))) { | |
12721 | + kltp = (kltype_t *)stp->sym_kltype; | |
12722 | + } | |
12723 | + } | |
12724 | + return(kltp); | |
12725 | +} | |
12726 | + | |
12727 | +/* | |
12728 | + * kl_next_type() | |
12729 | + */ | |
12730 | +kltype_t * | |
12731 | +kl_next_type(kltype_t *kltp) | |
12732 | +{ | |
12733 | + dbg_sym_t *stp, *nstp; | |
12734 | + kltype_t *nkltp = (kltype_t *)NULL; | |
12735 | + | |
12736 | + if (!kltp) { | |
12737 | + return((kltype_t *)NULL); | |
12738 | + } | |
12739 | + stp = (dbg_sym_t *)kltp->kl_ptr; | |
12740 | + if ((nstp = dbg_next_sym(stp))) { | |
12741 | + nkltp = (kltype_t *)nstp->sym_kltype; | |
12742 | + } | |
12743 | + return(nkltp); | |
12744 | +} | |
12745 | + | |
12746 | +/* | |
12747 | + * kl_prev_type() | |
12748 | + */ | |
12749 | +kltype_t * | |
12750 | +kl_prev_type(kltype_t *kltp) | |
12751 | +{ | |
12752 | + dbg_sym_t *stp, *pstp; | |
12753 | + kltype_t *pkltp = (kltype_t *)NULL; | |
12754 | + | |
12755 | + if (!kltp) { | |
12756 | + return((kltype_t *)NULL); | |
12757 | + } | |
12758 | + stp = (dbg_sym_t *)kltp->kl_ptr; | |
12759 | + if ((pstp = dbg_prev_sym(stp))) { | |
12760 | + pkltp = (kltype_t *)pstp->sym_kltype; | |
12761 | + } | |
12762 | + return(pkltp); | |
12763 | +} | |
12764 | + | |
12765 | +/* | |
12766 | + * kl_realtype() | |
12767 | + */ | |
12768 | +kltype_t * | |
12769 | +kl_realtype(kltype_t *kltp, int tnum) | |
12770 | +{ | |
12771 | + kltype_t *rkltp = kltp; | |
12772 | + | |
12773 | + while (rkltp) { | |
12774 | + if (tnum && (rkltp->kl_type == tnum)) { | |
12775 | + break; | |
12776 | + } | |
12777 | + if (!rkltp->kl_realtype) { | |
12778 | + break; | |
12779 | + } | |
12780 | + if (rkltp->kl_realtype == rkltp) { | |
12781 | + break; | |
12782 | + } | |
12783 | + rkltp = rkltp->kl_realtype; | |
12784 | + if (rkltp == kltp) { | |
12785 | + break; | |
12786 | + } | |
12787 | + } | |
12788 | + return(rkltp); | |
12789 | +} | |
12790 | + | |
12791 | +/* | |
12792 | + * dbg_find_typenum() | |
12793 | + */ | |
12794 | +dbg_type_t * | |
12795 | +dbg_find_typenum(uint64_t typenum) | |
12796 | +{ | |
12797 | + dbg_sym_t *stp; | |
12798 | + dbg_type_t *sp = (dbg_type_t *)NULL; | |
12799 | + | |
12800 | + if ((stp = dbg_find_sym(0, DBG_TYPE, typenum))) { | |
12801 | + sp = (dbg_type_t *)stp->sym_kltype; | |
12802 | + } | |
12803 | + return(sp); | |
12804 | +} | |
12805 | + | |
12806 | +/* | |
12807 | + * find type by typenum | |
12808 | + */ | |
12809 | +kltype_t * | |
12810 | +kl_find_typenum(uint64_t typenum) | |
12811 | +{ | |
12812 | + kltype_t *kltp; | |
12813 | + | |
12814 | + kltp = (kltype_t *)dbg_find_typenum(typenum); | |
12815 | + return(kltp); | |
12816 | +} | |
12817 | + | |
12818 | +/* | |
12819 | + * kl_find_btnode() -- non-recursive implementation. | |
12820 | + */ | |
12821 | +btnode_t * | |
12822 | +_kl_find_btnode(btnode_t *np, char *key, int *max_depth, size_t len) | |
12823 | +{ | |
12824 | + int ret; | |
12825 | + btnode_t *next, *prev; | |
12826 | + | |
12827 | + if (np) { | |
12828 | + if (max_depth) { | |
12829 | + (*max_depth)++; | |
12830 | + } | |
12831 | + next = np; | |
12832 | +again: | |
12833 | + if (len) { | |
12834 | + ret = strncmp(key, next->bt_key, len); | |
12835 | + } else { | |
12836 | + ret = strcmp(key, next->bt_key); | |
12837 | + } | |
12838 | + if (ret == 0) { | |
12839 | + if ((prev = kl_prev_btnode(next))) { | |
12840 | + if (len) { | |
12841 | + ret = strncmp(key, prev->bt_key, len); | |
12842 | + } else { | |
12843 | + ret = strcmp(key, prev->bt_key); | |
12844 | + } | |
12845 | + if (ret == 0) { | |
12846 | + next = prev; | |
12847 | + goto again; | |
12848 | + } | |
12849 | + } | |
12850 | + return(next); | |
12851 | + } else if (ret < 0) { | |
12852 | + if ((next = next->bt_left)) { | |
12853 | + goto again; | |
12854 | + } | |
12855 | + } else { | |
12856 | + if ((next = next->bt_right)) { | |
12857 | + goto again; | |
12858 | + } | |
12859 | + } | |
12860 | + } | |
12861 | + return((btnode_t *)NULL); | |
12862 | +} | |
12863 | + | |
12864 | +/* | |
12865 | + * kl_type_size() | |
12866 | + */ | |
12867 | +int | |
12868 | +kl_type_size(kltype_t *kltp) | |
12869 | +{ | |
12870 | + kltype_t *rkltp; | |
12871 | + | |
12872 | + if (!kltp) { | |
12873 | + return(0); | |
12874 | + } | |
12875 | + if (!(rkltp = kl_realtype(kltp, 0))) { | |
12876 | + return(0); | |
12877 | + } | |
12878 | + return(rkltp->kl_size); | |
12879 | +} | |
12880 | + | |
12881 | +/* | |
12882 | + * kl_struct_len() | |
12883 | + */ | |
12884 | +int | |
12885 | +kl_struct_len(char *s) | |
12886 | +{ | |
12887 | + kltype_t *kltp; | |
12888 | + | |
12889 | + if ((kltp = kl_find_type(s, (KLT_TYPES)))) { | |
12890 | + return kl_type_size(kltp); | |
12891 | + } | |
12892 | + return(0); | |
12893 | +} | |
12894 | + | |
12895 | +/* | |
12896 | + * kl_get_member() | |
12897 | + */ | |
12898 | +kltype_t * | |
12899 | +kl_get_member(kltype_t *kltp, char *f) | |
12900 | +{ | |
12901 | + kltype_t *mp; | |
12902 | + | |
12903 | + if ((mp = kltp->kl_member)) { | |
12904 | + while (mp) { | |
12905 | + if (mp->kl_flags & TYP_ANONYMOUS_FLG) { | |
12906 | + kltype_t *amp; | |
12907 | + | |
12908 | + if ((amp = kl_get_member(mp->kl_realtype, f))) { | |
12909 | + return(amp); | |
12910 | + } | |
12911 | + } else if (!strcmp(mp->kl_name, f)) { | |
12912 | + break; | |
12913 | + } | |
12914 | + mp = mp->kl_member; | |
12915 | + } | |
12916 | + } | |
12917 | + return(mp); | |
12918 | +} | |
12919 | + | |
12920 | +/* | |
12921 | + * kl_member() | |
12922 | + */ | |
12923 | +kltype_t * | |
12924 | +kl_member(char *s, char *f) | |
12925 | +{ | |
12926 | + kltype_t *kltp, *mp = NULL; | |
12927 | + | |
12928 | + if (!(kltp = kl_find_type(s, (KLT_STRUCT|KLT_UNION)))) { | |
12929 | + if ((kltp = kl_find_type(s, KLT_TYPEDEF))) { | |
12930 | + kltp = kl_realtype(kltp, 0); | |
12931 | + } | |
12932 | + } | |
12933 | + if (kltp) { | |
12934 | + mp = kl_get_member(kltp, f); | |
12935 | + } | |
12936 | + return(mp); | |
12937 | +} | |
12938 | + | |
12939 | + | |
12940 | +/* | |
12941 | + * kl_get_member_offset() | |
12942 | + */ | |
12943 | +int | |
12944 | +kl_get_member_offset(kltype_t *kltp, char *f) | |
12945 | +{ | |
12946 | + kltype_t *mp; | |
12947 | + | |
12948 | + if ((mp = kltp->kl_member)) { | |
12949 | + while (mp) { | |
12950 | + if (mp->kl_flags & TYP_ANONYMOUS_FLG) { | |
12951 | + int off; | |
12952 | + | |
12953 | + /* Drill down to see if the member we are looking for is in | |
12954 | + * an anonymous union or struct. Since this call is recursive, | |
12955 | + * the drill down may actually be multi-layer. | |
12956 | + */ | |
12957 | + off = kl_get_member_offset(mp->kl_realtype, f); | |
12958 | + if (off >= 0) { | |
12959 | + return(mp->kl_offset + off); | |
12960 | + } | |
12961 | + } else if (!strcmp(mp->kl_name, f)) { | |
12962 | + return(mp->kl_offset); | |
12963 | + } | |
12964 | + mp = mp->kl_member; | |
12965 | + } | |
12966 | + } | |
12967 | + return(-1); | |
12968 | +} | |
12969 | + | |
12970 | +/* | |
12971 | + * kl_member_offset() | |
12972 | + */ | |
12973 | +int | |
12974 | +kl_member_offset(char *s, char *f) | |
12975 | +{ | |
12976 | + int off = -1; | |
12977 | + kltype_t *kltp; | |
12978 | + | |
12979 | + if (!(kltp = kl_find_type(s, (KLT_STRUCT|KLT_UNION)))) { | |
12980 | + if ((kltp = kl_find_type(s, KLT_TYPEDEF))) { | |
12981 | + kltp = kl_realtype(kltp, 0); | |
12982 | + } | |
12983 | + } | |
12984 | + if (kltp) { | |
12985 | + off = kl_get_member_offset(kltp, f); | |
12986 | + } | |
12987 | + return(off); | |
12988 | +} | |
12989 | + | |
12990 | +/* | |
12991 | + * kl_is_member() | |
12992 | + */ | |
12993 | +int | |
12994 | +kl_is_member(char *s, char *f) | |
12995 | +{ | |
12996 | + kltype_t *mp; | |
12997 | + | |
12998 | + if ((mp = kl_member(s, f))) { | |
12999 | + return(1); | |
13000 | + } | |
13001 | + return(0); | |
13002 | +} | |
13003 | + | |
13004 | +/* | |
13005 | + * kl_member_size() | |
13006 | + */ | |
13007 | +int | |
13008 | +kl_member_size(char *s, char *f) | |
13009 | +{ | |
13010 | + kltype_t *mp; | |
13011 | + | |
13012 | + if ((mp = kl_member(s, f))) { | |
13013 | + return(mp->kl_size); | |
13014 | + } | |
13015 | + return(0); | |
13016 | +} | |
13017 | + | |
13018 | +#define TAB_SPACES 8 | |
13019 | +#define LEVEL_INDENT(level, flags) {\ | |
13020 | + int i, j; \ | |
13021 | + if (!(flags & NO_INDENT)) { \ | |
13022 | + for (i = 0; i < level; i++) { \ | |
13023 | + for (j = 0; j < TAB_SPACES; j++) { \ | |
13024 | + kdb_printf(" "); \ | |
13025 | + } \ | |
13026 | + }\ | |
13027 | + } \ | |
13028 | +} | |
13029 | +#define PRINT_NL(flags) \ | |
13030 | + if (!(flags & SUPPRESS_NL)) { \ | |
13031 | + kdb_printf("\n"); \ | |
13032 | + } | |
13033 | +#define PRINT_SEMI_COLON(level, flags) \ | |
13034 | + if (level && (!(flags & SUPPRESS_SEMI_COLON))) { \ | |
13035 | + kdb_printf(";"); \ | |
13036 | + } | |
13037 | + | |
13038 | +/* | |
13039 | + * print_realtype() | |
13040 | + */ | |
13041 | +static void | |
13042 | +print_realtype(kltype_t *kltp) | |
13043 | +{ | |
13044 | + kltype_t *rkltp; | |
13045 | + | |
13046 | + if ((rkltp = kltp->kl_realtype)) { | |
13047 | + while (rkltp && rkltp->kl_realtype) { | |
13048 | + rkltp = rkltp->kl_realtype; | |
13049 | + } | |
13050 | + if (rkltp->kl_type == KLT_BASE) { | |
13051 | + kdb_printf(" (%s)", rkltp->kl_name); | |
13052 | + } | |
13053 | + } | |
13054 | +} | |
13055 | + | |
13056 | +int align_chk = 0; | |
13057 | +/* | |
13058 | + * kl_print_uint16() | |
13059 | + * | |
13060 | + */ | |
13061 | +void | |
13062 | +kl_print_uint16(void *ptr, int flags) | |
13063 | +{ | |
13064 | + unsigned long long a; | |
13065 | + | |
13066 | + /* Make sure the pointer is properly aligned (or we will | |
13067 | + * * dump core) | |
13068 | + * */ | |
13069 | + if (align_chk && (uaddr_t)ptr % 16) { | |
13070 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13071 | + return; | |
13072 | + } | |
13073 | + a = *(unsigned long long *) ptr; | |
13074 | + if (flags & C_HEX) { | |
13075 | + kdb_printf("%#llx", a); | |
13076 | + } else if (flags & C_BINARY) { | |
13077 | + kdb_printf("0b"); | |
13078 | + kl_binary_print(a); | |
13079 | + } else { | |
13080 | + kdb_printf("%llu", a); | |
13081 | + } | |
13082 | +} | |
13083 | + | |
13084 | +#if 0 | |
13085 | +/* | |
13086 | + * kl_print_float16() | |
13087 | + * | |
13088 | + */ | |
13089 | +void | |
13090 | +kl_print_float16(void *ptr, int flags) | |
13091 | +{ | |
13092 | + double a; | |
13093 | + | |
13094 | + /* Make sure the pointer is properly aligned (or we will | |
13095 | + * * dump core) | |
13096 | + * */ | |
13097 | + if (align_chk && (uaddr_t)ptr % 16) { | |
13098 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13099 | + return; | |
13100 | + } | |
13101 | + a = *(double*) ptr; | |
13102 | + kdb_printf("%f", a); | |
13103 | +} | |
13104 | +#endif | |
13105 | + | |
13106 | +/* | |
13107 | + * kl_print_int16() | |
13108 | + * | |
13109 | + */ | |
13110 | +void | |
13111 | +kl_print_int16(void *ptr, int flags) | |
13112 | +{ | |
13113 | + long long a; | |
13114 | + | |
13115 | + /* Make sure the pointer is properly aligned (or we will | |
13116 | + * * dump core) | |
13117 | + * */ | |
13118 | + if (align_chk && (uaddr_t)ptr % 16) { | |
13119 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13120 | + return; | |
13121 | + } | |
13122 | + a = *(long long *) ptr; | |
13123 | + if (flags & C_HEX) { | |
13124 | + kdb_printf("%#llx", a); | |
13125 | + } else if (flags & C_BINARY) { | |
13126 | + kdb_printf("0b"); | |
13127 | + kl_binary_print(a); | |
13128 | + } else { | |
13129 | + kdb_printf("%lld", a); | |
13130 | + } | |
13131 | +} | |
13132 | + | |
13133 | +/* | |
13134 | + * kl_print_int8() | |
13135 | + */ | |
13136 | +void | |
13137 | +kl_print_int8(void *ptr, int flags) | |
13138 | +{ | |
13139 | + long long a; | |
13140 | + | |
13141 | + /* Make sure the pointer is properly aligned (or we will | |
13142 | + * dump core) | |
13143 | + */ | |
13144 | + if (align_chk && (uaddr_t)ptr % 8) { | |
13145 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13146 | + return; | |
13147 | + } | |
13148 | + a = *(long long *) ptr; | |
13149 | + if (flags & C_HEX) { | |
13150 | + kdb_printf("%#llx", a); | |
13151 | + } else if (flags & C_BINARY) { | |
13152 | + kdb_printf("0b"); | |
13153 | + kl_binary_print(a); | |
13154 | + } else { | |
13155 | + kdb_printf("%lld", a); | |
13156 | + } | |
13157 | +} | |
13158 | + | |
13159 | +#if 0 | |
13160 | +/* | |
13161 | + * kl_print_float8() | |
13162 | + */ | |
13163 | +void | |
13164 | +kl_print_float8(void *ptr, int flags) | |
13165 | +{ | |
13166 | + double a; | |
13167 | + | |
13168 | + /* Make sure the pointer is properly aligned (or we will | |
13169 | + * dump core) | |
13170 | + */ | |
13171 | + if (align_chk && (uaddr_t)ptr % 8) { | |
13172 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13173 | + return; | |
13174 | + } | |
13175 | + a = *(double*) ptr; | |
13176 | + kdb_printf("%f", a); | |
13177 | +} | |
13178 | +#endif | |
13179 | + | |
13180 | +/* | |
13181 | + * kl_print_uint8() | |
13182 | + */ | |
13183 | +void | |
13184 | +kl_print_uint8(void *ptr, int flags) | |
13185 | +{ | |
13186 | + unsigned long long a; | |
13187 | + | |
13188 | + /* Make sure the pointer is properly aligned (or we will | |
13189 | + * dump core) | |
13190 | + */ | |
13191 | + if (align_chk && (uaddr_t)ptr % 8) { | |
13192 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13193 | + return; | |
13194 | + } | |
13195 | + a = *(unsigned long long *) ptr; | |
13196 | + if (flags & C_HEX) { | |
13197 | + kdb_printf("%#llx", a); | |
13198 | + } else if (flags & C_BINARY) { | |
13199 | + kdb_printf("0b"); | |
13200 | + kl_binary_print(a); | |
13201 | + } else { | |
13202 | + kdb_printf("%llu", a); | |
13203 | + } | |
13204 | +} | |
13205 | + | |
13206 | +/* | |
13207 | + * kl_print_int4() | |
13208 | + */ | |
13209 | +void | |
13210 | +kl_print_int4(void *ptr, int flags) | |
13211 | +{ | |
13212 | + int32_t a; | |
13213 | + | |
13214 | + /* Make sure the pointer is properly aligned (or we will | |
13215 | + * dump core | |
13216 | + */ | |
13217 | + if (align_chk && (uaddr_t)ptr % 4) { | |
13218 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13219 | + return; | |
13220 | + } | |
13221 | + a = *(int32_t*) ptr; | |
13222 | + if (flags & C_HEX) { | |
13223 | + kdb_printf("0x%x", a); | |
13224 | + } else if (flags & C_BINARY) { | |
13225 | + uint64_t value = a & 0xffffffff; | |
13226 | + kdb_printf("0b"); | |
13227 | + kl_binary_print(value); | |
13228 | + } else { | |
13229 | + kdb_printf("%d", a); | |
13230 | + } | |
13231 | +} | |
13232 | + | |
13233 | +#if 0 | |
13234 | +/* | |
13235 | + * kl_print_float4() | |
13236 | + */ | |
13237 | +void | |
13238 | +kl_print_float4(void *ptr, int flags) | |
13239 | +{ | |
13240 | + float a; | |
13241 | + | |
13242 | + /* Make sure the pointer is properly aligned (or we will | |
13243 | + * dump core) | |
13244 | + */ | |
13245 | + if (align_chk && (uaddr_t)ptr % 4) { | |
13246 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13247 | + return; | |
13248 | + } | |
13249 | + a = *(float*) ptr; | |
13250 | + kdb_printf("%f", a); | |
13251 | +} | |
13252 | +#endif | |
13253 | + | |
13254 | +/* | |
13255 | + * kl_print_uint4() | |
13256 | + */ | |
13257 | +void | |
13258 | +kl_print_uint4(void *ptr, int flags) | |
13259 | +{ | |
13260 | + uint32_t a; | |
13261 | + | |
13262 | + /* Make sure the pointer is properly aligned (or we will | |
13263 | + * dump core) | |
13264 | + */ | |
13265 | + if (align_chk && (uaddr_t)ptr % 4) { | |
13266 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13267 | + return; | |
13268 | + } | |
13269 | + a = *(uint32_t*) ptr; | |
13270 | + if (flags & C_HEX) { | |
13271 | + kdb_printf("0x%x", a); | |
13272 | + } else if (flags & C_BINARY) { | |
13273 | + uint64_t value = a & 0xffffffff; | |
13274 | + kdb_printf("0b"); | |
13275 | + kl_binary_print(value); | |
13276 | + } else { | |
13277 | + kdb_printf("%u", a); | |
13278 | + } | |
13279 | +} | |
13280 | + | |
13281 | +/* | |
13282 | + * kl_print_int2() | |
13283 | + */ | |
13284 | +void | |
13285 | +kl_print_int2(void *ptr, int flags) | |
13286 | +{ | |
13287 | + int16_t a; | |
13288 | + | |
13289 | + /* Make sure the pointer is properly aligned (or we will | |
13290 | + * dump core | |
13291 | + */ | |
13292 | + if (align_chk && (uaddr_t)ptr % 2) { | |
13293 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13294 | + return; | |
13295 | + } | |
13296 | + a = *(int16_t*) ptr; | |
13297 | + if (flags & C_HEX) { | |
13298 | + kdb_printf("0x%hx", a); | |
13299 | + } else if (flags & C_BINARY) { | |
13300 | + uint64_t value = a & 0xffff; | |
13301 | + kdb_printf("0b"); | |
13302 | + kl_binary_print(value); | |
13303 | + } else { | |
13304 | + kdb_printf("%hd", a); | |
13305 | + } | |
13306 | +} | |
13307 | + | |
13308 | +/* | |
13309 | + * kl_print_uint2() | |
13310 | + */ | |
13311 | +void | |
13312 | +kl_print_uint2(void *ptr, int flags) | |
13313 | +{ | |
13314 | + uint16_t a; | |
13315 | + | |
13316 | + /* Make sure the pointer is properly aligned (or we will | |
13317 | + * dump core | |
13318 | + */ | |
13319 | + if (align_chk && (uaddr_t)ptr % 2) { | |
13320 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13321 | + return; | |
13322 | + } | |
13323 | + a = *(uint16_t*) ptr; | |
13324 | + if (flags & C_HEX) { | |
13325 | + kdb_printf("0x%hx", a); | |
13326 | + } else if (flags & C_BINARY) { | |
13327 | + uint64_t value = a & 0xffff; | |
13328 | + kdb_printf("0b"); | |
13329 | + kl_binary_print(value); | |
13330 | + } else { | |
13331 | + kdb_printf("%hu", a); | |
13332 | + } | |
13333 | +} | |
13334 | + | |
13335 | +/* | |
13336 | + * kl_print_char() | |
13337 | + */ | |
13338 | +void | |
13339 | +kl_print_char(void *ptr, int flags) | |
13340 | +{ | |
13341 | + char c; | |
13342 | + | |
13343 | + if (flags & C_HEX) { | |
13344 | + kdb_printf("0x%x", (*(char *)ptr) & 0xff); | |
13345 | + } else if (flags & C_BINARY) { | |
13346 | + uint64_t value = (*(char *)ptr) & 0xff; | |
13347 | + kdb_printf("0b"); | |
13348 | + kl_binary_print(value); | |
13349 | + } else { | |
13350 | + c = *(char *)ptr; | |
13351 | + | |
13352 | + kdb_printf("\'\\%03o\'", (unsigned char)c); | |
13353 | + switch (c) { | |
13354 | + case '\a' : | |
13355 | + kdb_printf(" = \'\\a\'"); | |
13356 | + break; | |
13357 | + case '\b' : | |
13358 | + kdb_printf(" = \'\\b\'"); | |
13359 | + break; | |
13360 | + case '\t' : | |
13361 | + kdb_printf(" = \'\\t\'"); | |
13362 | + break; | |
13363 | + case '\n' : | |
13364 | + kdb_printf(" = \'\\n\'"); | |
13365 | + break; | |
13366 | + case '\f' : | |
13367 | + kdb_printf(" = \'\\f\'"); | |
13368 | + break; | |
13369 | + case '\r' : | |
13370 | + kdb_printf(" = \'\\r\'"); | |
13371 | + break; | |
13372 | + case '\e' : | |
13373 | + kdb_printf(" = \'\\e\'"); | |
13374 | + break; | |
13375 | + default : | |
13376 | + if( !iscntrl((unsigned char) c) ) { | |
13377 | + kdb_printf(" = \'%c\'", c); | |
13378 | + } | |
13379 | + break; | |
13380 | + } | |
13381 | + } | |
13382 | +} | |
13383 | + | |
13384 | +/* | |
13385 | + * kl_print_uchar() | |
13386 | + */ | |
13387 | +void | |
13388 | +kl_print_uchar(void *ptr, int flags) | |
13389 | +{ | |
13390 | + if (flags & C_HEX) { | |
13391 | + kdb_printf("0x%x", *(unsigned char *)ptr); | |
13392 | + } else if (flags & C_BINARY) { | |
13393 | + uint64_t value = (*(unsigned char *)ptr) & 0xff; | |
13394 | + kdb_printf("0b"); | |
13395 | + kl_binary_print(value); | |
13396 | + } else { | |
13397 | + kdb_printf("%u", *(unsigned char *)ptr); | |
13398 | + } | |
13399 | +} | |
13400 | + | |
13401 | +/* | |
13402 | + * kl_print_base() | |
13403 | + */ | |
13404 | +void | |
13405 | +kl_print_base(void *ptr, int size, int encoding, int flags) | |
13406 | +{ | |
13407 | + /* FIXME: untested */ | |
13408 | + if (invalid_address((kaddr_t)ptr, size)) { | |
13409 | + kdb_printf("ILLEGAL ADDRESS (%lx)", (uaddr_t)ptr); | |
13410 | + return; | |
13411 | + } | |
13412 | + switch (size) { | |
13413 | + | |
13414 | + case 1: | |
13415 | + if (encoding == ENC_UNSIGNED) { | |
13416 | + kl_print_uchar(ptr, flags); | |
13417 | + } else { | |
13418 | + kl_print_char(ptr, flags); | |
13419 | + } | |
13420 | + break; | |
13421 | + | |
13422 | + case 2: | |
13423 | + if (encoding == ENC_UNSIGNED) { | |
13424 | + kl_print_uint2(ptr, flags); | |
13425 | + } else { | |
13426 | + kl_print_int2(ptr, flags); | |
13427 | + } | |
13428 | + break; | |
13429 | + | |
13430 | + case 4: | |
13431 | + if (encoding == ENC_UNSIGNED) { | |
13432 | + kl_print_uint4(ptr, flags); | |
13433 | + } else if (encoding == ENC_FLOAT) { | |
13434 | + printk("error: print of 4-byte float\n"); | |
13435 | + /* kl_print_float4(ptr, flags); */ | |
13436 | + } else { | |
13437 | + kl_print_int4(ptr, flags); | |
13438 | + } | |
13439 | + break; | |
13440 | + | |
13441 | + case 8: | |
13442 | + if (encoding == ENC_UNSIGNED) { | |
13443 | + kl_print_uint8(ptr, flags); | |
13444 | + } else if (encoding == ENC_FLOAT) { | |
13445 | + printk("error: print of 8-byte float\n"); | |
13446 | + /* kl_print_float8(ptr, flags); */ | |
13447 | + } else { | |
13448 | + kl_print_int8(ptr, flags); | |
13449 | + } | |
13450 | + break; | |
13451 | + | |
13452 | + case 16: | |
13453 | + if (encoding == ENC_UNSIGNED) { | |
13454 | + /* Ex: unsigned long long */ | |
13455 | + kl_print_uint16(ptr, flags); | |
13456 | + } else if (encoding == ENC_FLOAT) { | |
13457 | + printk("error: print of 16-byte float\n"); | |
13458 | + /* Ex: long double */ | |
13459 | + /* kl_print_float16(ptr, flags); */ | |
13460 | + } else { | |
13461 | + /* Ex: long long */ | |
13462 | + kl_print_int16(ptr, flags); | |
13463 | + } | |
13464 | + break; | |
13465 | + | |
13466 | + default: | |
13467 | + break; | |
13468 | + } | |
13469 | +} | |
13470 | + | |
13471 | +/* | |
13472 | + * kl_print_base_value() | |
13473 | + */ | |
13474 | +void | |
13475 | +kl_print_base_value(void *ptr, kltype_t *kltp, int flags) | |
13476 | +{ | |
13477 | + kltype_t *rkltp=NULL; | |
13478 | + | |
13479 | + if (kltp->kl_type != KLT_BASE) { | |
13480 | + if (!(rkltp = kltp->kl_realtype)) { | |
13481 | + return; | |
13482 | + } | |
13483 | + if (rkltp->kl_type != KLT_BASE) { | |
13484 | + return; | |
13485 | + } | |
13486 | + } else { | |
13487 | + rkltp = kltp; | |
13488 | + } | |
13489 | + kl_print_base(ptr, rkltp->kl_size, rkltp->kl_encoding, flags); | |
13490 | +} | |
13491 | + | |
13492 | +/* | |
13493 | + * kl_print_typedef_type() | |
13494 | + */ | |
13495 | +void | |
13496 | +kl_print_typedef_type( | |
13497 | + void *ptr, | |
13498 | + kltype_t *kltp, | |
13499 | + int level, | |
13500 | + int flags) | |
13501 | +{ | |
13502 | + char *name; | |
13503 | + kltype_t *rkltp; | |
13504 | + | |
13505 | + if (ptr) { | |
13506 | + rkltp = kltp->kl_realtype; | |
13507 | + while (rkltp->kl_type == KLT_TYPEDEF) { | |
13508 | + if (rkltp->kl_realtype) { | |
13509 | + rkltp = rkltp->kl_realtype; | |
13510 | + } | |
13511 | + } | |
13512 | + if (rkltp->kl_type == KLT_POINTER) { | |
13513 | + kl_print_pointer_type(ptr, kltp, level, flags); | |
13514 | + return; | |
13515 | + } | |
13516 | + switch (rkltp->kl_type) { | |
13517 | + case KLT_BASE: | |
13518 | + kl_print_base_type(ptr, kltp, | |
13519 | + level, flags); | |
13520 | + break; | |
13521 | + | |
13522 | + case KLT_UNION: | |
13523 | + case KLT_STRUCT: | |
13524 | + kl_print_struct_type(ptr, kltp, | |
13525 | + level, flags); | |
13526 | + break; | |
13527 | + | |
13528 | + case KLT_ARRAY: | |
13529 | + kl_print_array_type(ptr, kltp, | |
13530 | + level, flags); | |
13531 | + break; | |
13532 | + | |
13533 | + case KLT_ENUMERATION: | |
13534 | + kl_print_enumeration_type(ptr, | |
13535 | + kltp, level, flags); | |
13536 | + break; | |
13537 | + | |
13538 | + default: | |
13539 | + kl_print_base_type(ptr, kltp, | |
13540 | + level, flags); | |
13541 | + break; | |
13542 | + } | |
13543 | + } else { | |
13544 | + LEVEL_INDENT(level, flags); | |
13545 | + if (flags & NO_REALTYPE) { | |
13546 | + rkltp = kltp; | |
13547 | + } else { | |
13548 | + rkltp = kltp->kl_realtype; | |
13549 | + while (rkltp && rkltp->kl_type == KLT_POINTER) { | |
13550 | + rkltp = rkltp->kl_realtype; | |
13551 | + } | |
13552 | + } | |
13553 | + if (!rkltp) { | |
13554 | + if (SUPPRESS_NAME) { | |
13555 | + kdb_printf("<UNKNOWN>"); | |
13556 | + } else { | |
13557 | + kdb_printf( "typedef <UNKNOWN>%s;", | |
13558 | + kltp->kl_name); | |
13559 | + } | |
13560 | + return; | |
13561 | + } | |
13562 | + if (rkltp->kl_type == KLT_FUNCTION) { | |
13563 | + if (kltp->kl_realtype->kl_type == KLT_POINTER) { | |
13564 | + kdb_printf("typedef %s(*%s)();", | |
13565 | + kltp->kl_typestr, kltp->kl_name); | |
13566 | + } else { | |
13567 | + kdb_printf( "typedef %s(%s)();", | |
13568 | + kltp->kl_typestr, kltp->kl_name); | |
13569 | + } | |
13570 | + } else if (rkltp->kl_type == KLT_ARRAY) { | |
13571 | + kl_print_array_type(ptr, rkltp, level, flags); | |
13572 | + } else if (rkltp->kl_type == KLT_TYPEDEF) { | |
13573 | + if (!(name = rkltp->kl_name)) { | |
13574 | + name = rkltp->kl_typestr; | |
13575 | + } | |
13576 | + | |
13577 | + if (SUPPRESS_NAME) { | |
13578 | + kdb_printf("%s", name); | |
13579 | + } else { | |
13580 | + kdb_printf("typedef %s%s;", | |
13581 | + name, kltp->kl_name); | |
13582 | + } | |
13583 | + print_realtype(rkltp); | |
13584 | + } else { | |
13585 | + kl_print_type(ptr, rkltp, level, flags); | |
13586 | + } | |
13587 | + PRINT_NL(flags); | |
13588 | + } | |
13589 | +} | |
13590 | + | |
13591 | +/* | |
13592 | + * kl_print_pointer_type() | |
13593 | + */ | |
13594 | +void | |
13595 | +kl_print_pointer_type( | |
13596 | + void *ptr, | |
13597 | + kltype_t *kltp, | |
13598 | + int level, | |
13599 | + int flags) | |
13600 | +{ | |
13601 | + kltype_t *itp; | |
13602 | + | |
13603 | + if (kltp->kl_type == KLT_MEMBER) { | |
13604 | + itp = kltp->kl_realtype; | |
13605 | + } else { | |
13606 | + itp = kltp; | |
13607 | + } | |
13608 | + | |
13609 | + /* See if this is a pointer to a function. If it is, then it | |
13610 | + * has to be handled differently... | |
13611 | + */ | |
13612 | + while (itp->kl_type == KLT_POINTER) { | |
13613 | + if ((itp = itp->kl_realtype)) { | |
13614 | + if (itp->kl_type == KLT_FUNCTION) { | |
13615 | + kl_print_function_type(ptr, | |
13616 | + kltp, level, flags); | |
13617 | + return; | |
13618 | + } | |
13619 | + } else { | |
13620 | + LEVEL_INDENT(level, flags); | |
13621 | + kdb_printf("%s%s;\n", | |
13622 | + kltp->kl_typestr, kltp->kl_name); | |
13623 | + return; | |
13624 | + } | |
13625 | + } | |
13626 | + | |
13627 | + LEVEL_INDENT(level, flags); | |
13628 | + if (ptr) { | |
13629 | + kaddr_t tmp; | |
13630 | + tmp = *(kaddr_t *)ptr; | |
13631 | + flags |= SUPPRESS_SEMI_COLON; | |
13632 | + if(kltp->kl_name){ | |
13633 | + if (*(kaddr_t *)ptr) { | |
13634 | + kdb_printf("%s = 0x%"FMTPTR"x", | |
13635 | + kltp->kl_name, tmp); | |
13636 | + } else { | |
13637 | + kdb_printf("%s = (nil)", kltp->kl_name); | |
13638 | + } | |
13639 | + } else { | |
13640 | + if (tmp != 0) { | |
13641 | + kdb_printf("0x%"FMTPTR"x", tmp); | |
13642 | + } else { | |
13643 | + kdb_printf( "(nil)"); | |
13644 | + } | |
13645 | + } | |
13646 | + } else { | |
13647 | + if (kltp->kl_typestr) { | |
13648 | + if (kltp->kl_name && !(flags & SUPPRESS_NAME)) { | |
13649 | + kdb_printf("%s%s", | |
13650 | + kltp->kl_typestr, kltp->kl_name); | |
13651 | + } else { | |
13652 | + kdb_printf("%s", kltp->kl_typestr); | |
13653 | + } | |
13654 | + } else { | |
13655 | + kdb_printf("<UNKNOWN>"); | |
13656 | + } | |
13657 | + } | |
13658 | + PRINT_SEMI_COLON(level, flags); | |
13659 | + PRINT_NL(flags); | |
13660 | +} | |
13661 | + | |
13662 | +/* | |
13663 | + * kl_print_function_type() | |
13664 | + */ | |
13665 | +void | |
13666 | +kl_print_function_type( | |
13667 | + void *ptr, | |
13668 | + kltype_t *kltp, | |
13669 | + int level, | |
13670 | + int flags) | |
13671 | +{ | |
13672 | + LEVEL_INDENT(level, flags); | |
13673 | + if (ptr) { | |
13674 | + kaddr_t a; | |
13675 | + | |
13676 | + a = *(kaddr_t *)ptr; | |
13677 | + kdb_printf("%s = 0x%"FMTPTR"x", kltp->kl_name, a); | |
13678 | + } else { | |
13679 | + if (flags & SUPPRESS_NAME) { | |
13680 | + kdb_printf("%s(*)()", kltp->kl_typestr); | |
13681 | + } else { | |
13682 | + kdb_printf("%s(*%s)();", | |
13683 | + kltp->kl_typestr, kltp->kl_name); | |
13684 | + } | |
13685 | + } | |
13686 | + PRINT_NL(flags); | |
13687 | +} | |
13688 | + | |
13689 | +/* | |
13690 | + * kl_print_array_type() | |
13691 | + */ | |
13692 | +void | |
13693 | +kl_print_array_type(void *ptr, kltype_t *kltp, int level, int flags) | |
13694 | +{ | |
13695 | + int i, count = 0, anon = 0, size, low, high, multi = 0; | |
13696 | + char typestr[128], *name, *p; | |
13697 | + kltype_t *rkltp, *etp, *retp; | |
13698 | + | |
13699 | + if (kltp->kl_type != KLT_ARRAY) { | |
13700 | + if ((rkltp = kltp->kl_realtype)) { | |
13701 | + while (rkltp->kl_type != KLT_ARRAY) { | |
13702 | + if (!(rkltp = rkltp->kl_realtype)) { | |
13703 | + break; | |
13704 | + } | |
13705 | + } | |
13706 | + } | |
13707 | + if (!rkltp) { | |
13708 | + LEVEL_INDENT(level, flags); | |
13709 | + kdb_printf("<ARRAY_TYPE>"); | |
13710 | + PRINT_SEMI_COLON(level, flags); | |
13711 | + PRINT_NL(flags); | |
13712 | + return; | |
13713 | + } | |
13714 | + } else { | |
13715 | + rkltp = kltp; | |
13716 | + } | |
13717 | + | |
13718 | + etp = rkltp->kl_elementtype; | |
13719 | + if (!etp) { | |
13720 | + LEVEL_INDENT(level, flags); | |
13721 | + kdb_printf("<BAD_ELEMENT_TYPE> %s", rkltp->kl_name); | |
13722 | + PRINT_SEMI_COLON(level, flags); | |
13723 | + PRINT_NL(flags); | |
13724 | + return; | |
13725 | + } | |
13726 | + | |
13727 | + /* Set retp to point to the actual element type. This is necessary | |
13728 | + * for multi-dimensional arrays, which link using the kl_elementtype | |
13729 | + * member. | |
13730 | + */ | |
13731 | + retp = etp; | |
13732 | + while (retp->kl_type == KLT_ARRAY) { | |
13733 | + retp = retp->kl_elementtype; | |
13734 | + } | |
13735 | + low = rkltp->kl_low_bounds + 1; | |
13736 | + high = rkltp->kl_high_bounds; | |
13737 | + | |
13738 | + if (ptr) { | |
13739 | + | |
13740 | + p = ptr; | |
13741 | + | |
13742 | + if ((retp->kl_size == 1) && (retp->kl_encoding == ENC_CHAR)) { | |
13743 | + if (kltp->kl_type == KLT_MEMBER) { | |
13744 | + LEVEL_INDENT(level, flags); | |
13745 | + } | |
13746 | + if (flags & SUPPRESS_NAME) { | |
13747 | + kdb_printf("\""); | |
13748 | + flags &= ~SUPPRESS_NAME; | |
13749 | + } else { | |
13750 | + kdb_printf("%s = \"", kltp->kl_name); | |
13751 | + } | |
13752 | + for (i = 0; i < high; i++) { | |
13753 | + if (*(char*)p == 0) { | |
13754 | + break; | |
13755 | + } | |
13756 | + kdb_printf("%c", *(char *)p); | |
13757 | + p++; | |
13758 | + } | |
13759 | + kdb_printf("\""); | |
13760 | + PRINT_NL(flags); | |
13761 | + } else { | |
13762 | + if (kltp->kl_type == KLT_MEMBER) { | |
13763 | + LEVEL_INDENT(level, flags); | |
13764 | + } | |
13765 | + | |
13766 | + if (flags & SUPPRESS_NAME) { | |
13767 | + kdb_printf("{\n"); | |
13768 | + flags &= ~SUPPRESS_NAME; | |
13769 | + } else { | |
13770 | + kdb_printf("%s = {\n", kltp->kl_name); | |
13771 | + } | |
13772 | + | |
13773 | + if (retp->kl_type == KLT_POINTER) { | |
13774 | + size = sizeof(void *); | |
13775 | + } else { | |
13776 | + while (retp->kl_realtype) { | |
13777 | + retp = retp->kl_realtype; | |
13778 | + } | |
13779 | + size = retp->kl_size; | |
13780 | + } | |
13781 | + if ((retp->kl_type != KLT_STRUCT) && | |
13782 | + (retp->kl_type != KLT_UNION)) { | |
13783 | + /* Turn off the printing of names for all | |
13784 | + * but structs and unions. | |
13785 | + */ | |
13786 | + flags |= SUPPRESS_NAME; | |
13787 | + } | |
13788 | + for (i = low; i <= high; i++) { | |
13789 | + | |
13790 | + LEVEL_INDENT(level + 1, flags); | |
13791 | + kdb_printf("[%d] ", i); | |
13792 | + | |
13793 | + switch (retp->kl_type) { | |
13794 | + case KLT_POINTER : | |
13795 | + kl_print_pointer_type( | |
13796 | + p, retp, level, | |
13797 | + flags|NO_INDENT); | |
13798 | + break; | |
13799 | + | |
13800 | + case KLT_TYPEDEF: | |
13801 | + kl_print_typedef_type( | |
13802 | + p, retp, level, | |
13803 | + flags|NO_INDENT); | |
13804 | + break; | |
13805 | + | |
13806 | + case KLT_BASE: | |
13807 | + kl_print_base_value(p, | |
13808 | + retp, flags|NO_INDENT); | |
13809 | + kdb_printf("\n"); | |
13810 | + break; | |
13811 | + | |
13812 | + case KLT_ARRAY: | |
13813 | + kl_print_array_type(p, retp, | |
13814 | + level + 1, | |
13815 | + flags|SUPPRESS_NAME); | |
13816 | + break; | |
13817 | + | |
13818 | + case KLT_STRUCT: | |
13819 | + case KLT_UNION: | |
13820 | + kl_print_struct_type(p, | |
13821 | + retp, level + 1, | |
13822 | + flags|NO_INDENT); | |
13823 | + break; | |
13824 | + | |
13825 | + default: | |
13826 | + kl_print_base_value( | |
13827 | + p, retp, | |
13828 | + flags|NO_INDENT); | |
13829 | + kdb_printf("\n"); | |
13830 | + break; | |
13831 | + } | |
13832 | + p = (void *)((uaddr_t)p + size); | |
13833 | + } | |
13834 | + LEVEL_INDENT(level, flags); | |
13835 | + kdb_printf("}"); | |
13836 | + PRINT_SEMI_COLON(level, flags); | |
13837 | + PRINT_NL(flags); | |
13838 | + } | |
13839 | + } else { | |
13840 | + if (rkltp) { | |
13841 | + count = (rkltp->kl_high_bounds - | |
13842 | + rkltp->kl_low_bounds) + 1; | |
13843 | + } else { | |
13844 | + count = 1; | |
13845 | + } | |
13846 | + | |
13847 | + if (!strcmp(retp->kl_typestr, "struct ") || | |
13848 | + !strcmp(retp->kl_typestr, "union ")) { | |
13849 | + anon = 1; | |
13850 | + } | |
13851 | +next_dimension: | |
13852 | + switch (retp->kl_type) { | |
13853 | + | |
13854 | + case KLT_UNION: | |
13855 | + case KLT_STRUCT: | |
13856 | + if (anon) { | |
13857 | + if (multi) { | |
13858 | + kdb_printf("[%d]", count); | |
13859 | + break; | |
13860 | + } | |
13861 | + kl_print_struct_type(ptr, retp, level, | |
13862 | + flags| | |
13863 | + SUPPRESS_NL| | |
13864 | + SUPPRESS_SEMI_COLON); | |
13865 | + if (kltp->kl_type == KLT_MEMBER) { | |
13866 | + kdb_printf(" %s[%d]", | |
13867 | + kltp->kl_name, count); | |
13868 | + } else { | |
13869 | + kdb_printf(" [%d]", count); | |
13870 | + } | |
13871 | + break; | |
13872 | + } | |
13873 | + /* else drop through */ | |
13874 | + | |
13875 | + default: | |
13876 | + LEVEL_INDENT(level, flags); | |
13877 | + if (multi) { | |
13878 | + kdb_printf("[%d]", count); | |
13879 | + break; | |
13880 | + } | |
13881 | + name = kltp->kl_name; | |
13882 | + if (retp->kl_type == KLT_TYPEDEF) { | |
13883 | + strcpy(typestr, retp->kl_name); | |
13884 | + strcat(typestr, " "); | |
13885 | + } else { | |
13886 | + strcpy(typestr, retp->kl_typestr); | |
13887 | + } | |
13888 | + if (!name || (flags & SUPPRESS_NAME)) { | |
13889 | + kdb_printf("%s[%d]", typestr, count); | |
13890 | + } else { | |
13891 | + kdb_printf("%s%s[%d]", | |
13892 | + typestr, name, count); | |
13893 | + } | |
13894 | + } | |
13895 | + if (etp->kl_type == KLT_ARRAY) { | |
13896 | + count = etp->kl_high_bounds - etp->kl_low_bounds + 1; | |
13897 | + etp = etp->kl_elementtype; | |
13898 | + multi++; | |
13899 | + goto next_dimension; | |
13900 | + } | |
13901 | + PRINT_SEMI_COLON(level, flags); | |
13902 | + PRINT_NL(flags); | |
13903 | + } | |
13904 | +} | |
13905 | + | |
13906 | +/* | |
13907 | + * kl_print_enumeration_type() | |
13908 | + */ | |
13909 | +void | |
13910 | +kl_print_enumeration_type( | |
13911 | + void *ptr, | |
13912 | + kltype_t *kltp, | |
13913 | + int level, | |
13914 | + int flags) | |
13915 | +{ | |
13916 | + unsigned long long val = 0; | |
13917 | + kltype_t *mp, *rkltp; | |
13918 | + | |
13919 | + rkltp = kl_realtype(kltp, KLT_ENUMERATION); | |
13920 | + if (ptr) { | |
13921 | + switch (kltp->kl_size) { | |
13922 | + case 1: | |
13923 | + val = *(unsigned long long *)ptr; | |
13924 | + break; | |
13925 | + | |
13926 | + case 2: | |
13927 | + val = *(uint16_t *)ptr; | |
13928 | + break; | |
13929 | + | |
13930 | + case 4: | |
13931 | + val = *(uint32_t *)ptr; | |
13932 | + break; | |
13933 | + | |
13934 | + case 8: | |
13935 | + val = *(uint64_t *)ptr; | |
13936 | + break; | |
13937 | + } | |
13938 | + mp = rkltp->kl_member; | |
13939 | + while (mp) { | |
13940 | + if (mp->kl_value == val) { | |
13941 | + break; | |
13942 | + } | |
13943 | + mp = mp->kl_member; | |
13944 | + } | |
13945 | + LEVEL_INDENT(level, flags); | |
13946 | + if (mp) { | |
13947 | + kdb_printf("%s = (%s=%lld)", | |
13948 | + kltp->kl_name, mp->kl_name, val); | |
13949 | + } else { | |
13950 | + kdb_printf("%s = %lld", kltp->kl_name, val); | |
13951 | + } | |
13952 | + PRINT_NL(flags); | |
13953 | + } else { | |
13954 | + LEVEL_INDENT(level, flags); | |
13955 | + kdb_printf ("%s {", kltp->kl_typestr); | |
13956 | + mp = rkltp->kl_member; | |
13957 | + while (mp) { | |
13958 | + kdb_printf("%s = %d", mp->kl_name, mp->kl_value); | |
13959 | + if ((mp = mp->kl_member)) { | |
13960 | + kdb_printf(", "); | |
13961 | + } | |
13962 | + } | |
13963 | + mp = kltp; | |
13964 | + if (level) { | |
13965 | + kdb_printf("} %s;", mp->kl_name); | |
13966 | + } else { | |
13967 | + kdb_printf("};"); | |
13968 | + } | |
13969 | + PRINT_NL(flags); | |
13970 | + } | |
13971 | +} | |
13972 | + | |
13973 | +/* | |
13974 | + * kl_binary_print() | |
13975 | + */ | |
13976 | +void | |
13977 | +kl_binary_print(uint64_t num) | |
13978 | +{ | |
13979 | + int i, pre = 1; | |
13980 | + | |
13981 | + for (i = 63; i >= 0; i--) { | |
13982 | + if (num & ((uint64_t)1 << i)) { | |
13983 | + kdb_printf("1"); | |
13984 | + if (pre) { | |
13985 | + pre = 0; | |
13986 | + } | |
13987 | + } else { | |
13988 | + if (!pre) { | |
13989 | + kdb_printf("0"); | |
13990 | + } | |
13991 | + } | |
13992 | + } | |
13993 | + if (pre) { | |
13994 | + kdb_printf("0"); | |
13995 | + } | |
13996 | +} | |
13997 | + | |
13998 | +/* | |
13999 | + * kl_get_bit_value() | |
14000 | + * | |
14001 | + * x = byte_size, y = bit_size, z = bit_offset | |
14002 | + */ | |
14003 | +uint64_t | |
14004 | +kl_get_bit_value(void *ptr, unsigned int x, unsigned int y, unsigned int z) | |
14005 | +{ | |
14006 | + uint64_t value=0, mask; | |
14007 | + | |
14008 | + /* handle x bytes of buffer -- doing just memcpy won't work | |
14009 | + * on big endian architectures | |
14010 | + */ | |
14011 | + switch (x) { | |
14012 | + case 5: | |
14013 | + case 6: | |
14014 | + case 7: | |
14015 | + case 8: | |
14016 | + x = 8; | |
14017 | + value = *(uint64_t*) ptr; | |
14018 | + break; | |
14019 | + case 3: | |
14020 | + case 4: | |
14021 | + x = 4; | |
14022 | + value = *(uint32_t*) ptr; | |
14023 | + break; | |
14024 | + case 2: | |
14025 | + value = *(uint16_t*) ptr; | |
14026 | + break; | |
14027 | + case 1: | |
14028 | + value = *(uint8_t *)ptr; | |
14029 | + break; | |
14030 | + default: | |
14031 | + /* FIXME: set KL_ERROR */ | |
14032 | + return(0); | |
14033 | + } | |
14034 | + /* | |
14035 | + o FIXME: correct handling of overlapping fields | |
14036 | + */ | |
14037 | + | |
14038 | + /* goto bit offset */ | |
14039 | + value = value >> z; | |
14040 | + | |
14041 | + /* mask bit size bits */ | |
14042 | + mask = (((uint64_t)1 << y) - 1); | |
14043 | + return (value & mask); | |
14044 | +} | |
14045 | + | |
14046 | +/* | |
14047 | + * kl_print_bit_value() | |
14048 | + * | |
14049 | + * x = byte_size, y = bit_size, z = bit_offset | |
14050 | + */ | |
14051 | +void | |
14052 | +kl_print_bit_value(void *ptr, int x, int y, int z, int flags) | |
14053 | +{ | |
14054 | + unsigned long long value; | |
14055 | + | |
14056 | + value = kl_get_bit_value(ptr, x, y, z); | |
14057 | + if (flags & C_HEX) { | |
14058 | + kdb_printf("%#llx", value); | |
14059 | + } else if (flags & C_BINARY) { | |
14060 | + kdb_printf("0b"); | |
14061 | + kl_binary_print(value); | |
14062 | + } else { | |
14063 | + kdb_printf("%lld", value); | |
14064 | + } | |
14065 | +} | |
14066 | + | |
14067 | +/* | |
14068 | + * kl_print_base_type() | |
14069 | + */ | |
14070 | +void | |
14071 | +kl_print_base_type(void *ptr, kltype_t *kltp, int level, int flags) | |
14072 | +{ | |
14073 | + LEVEL_INDENT(level, flags); | |
14074 | + if (ptr) { | |
14075 | + if (!(flags & SUPPRESS_NAME)) { | |
14076 | + kdb_printf ("%s = ", kltp->kl_name); | |
14077 | + } | |
14078 | + } | |
14079 | + if (kltp->kl_type == KLT_MEMBER) { | |
14080 | + if (kltp->kl_bit_size < (kltp->kl_size * 8)) { | |
14081 | + if (ptr) { | |
14082 | + kl_print_bit_value(ptr, kltp->kl_size, | |
14083 | + kltp->kl_bit_size, | |
14084 | + kltp->kl_bit_offset, flags); | |
14085 | + } else { | |
14086 | + if (kltp->kl_name) { | |
14087 | + kdb_printf ("%s%s :%d;", | |
14088 | + kltp->kl_typestr, | |
14089 | + kltp->kl_name, | |
14090 | + kltp->kl_bit_size); | |
14091 | + } else { | |
14092 | + kdb_printf ("%s :%d;", | |
14093 | + kltp->kl_typestr, | |
14094 | + kltp->kl_bit_size); | |
14095 | + } | |
14096 | + } | |
14097 | + PRINT_NL(flags); | |
14098 | + return; | |
14099 | + } | |
14100 | + } | |
14101 | + if (ptr) { | |
14102 | + kltype_t *rkltp; | |
14103 | + | |
14104 | + rkltp = kl_realtype(kltp, 0); | |
14105 | + if (rkltp->kl_encoding == ENC_UNDEFINED) { | |
14106 | + /* This is a void value | |
14107 | + */ | |
14108 | + kdb_printf("<VOID>"); | |
14109 | + } else { | |
14110 | + kl_print_base(ptr, kltp->kl_size, | |
14111 | + rkltp->kl_encoding, flags); | |
14112 | + } | |
14113 | + } else { | |
14114 | + if (kltp->kl_type == KLT_MEMBER) { | |
14115 | + if (flags & SUPPRESS_NAME) { | |
14116 | + kdb_printf ("%s", kltp->kl_typestr); | |
14117 | + } else { | |
14118 | + if (kltp->kl_name) { | |
14119 | + kdb_printf("%s%s;", kltp->kl_typestr, | |
14120 | + kltp->kl_name); | |
14121 | + } else { | |
14122 | + kdb_printf ("%s :%d;", | |
14123 | + kltp->kl_typestr, | |
14124 | + kltp->kl_bit_size); | |
14125 | + } | |
14126 | + } | |
14127 | + } else { | |
14128 | + if (SUPPRESS_NAME) { | |
14129 | + kdb_printf("%s", kltp->kl_name); | |
14130 | + } else { | |
14131 | + kdb_printf("%s;", kltp->kl_name); | |
14132 | + } | |
14133 | + } | |
14134 | + } | |
14135 | + PRINT_NL(flags); | |
14136 | +} | |
14137 | + | |
14138 | +/* | |
14139 | + * kl_print_member() | |
14140 | + */ | |
14141 | +void | |
14142 | +kl_print_member(void *ptr, kltype_t *mp, int level, int flags) | |
14143 | +{ | |
14144 | + int kl_type = 0; | |
14145 | + kltype_t *rkltp; | |
14146 | + | |
14147 | + if (flags & C_SHOWOFFSET) { | |
14148 | + kdb_printf("%#x ", mp->kl_offset); | |
14149 | + } | |
14150 | + | |
14151 | + if ((rkltp = mp->kl_realtype)) { | |
14152 | + kl_type = rkltp->kl_type; | |
14153 | + } else | |
14154 | + kl_type = mp->kl_type; | |
14155 | + switch (kl_type) { | |
14156 | + case KLT_STRUCT: | |
14157 | + case KLT_UNION: | |
14158 | + kl_print_struct_type(ptr, mp, level, flags); | |
14159 | + break; | |
14160 | + case KLT_ARRAY: | |
14161 | + kl_print_array_type(ptr, mp, level, flags); | |
14162 | + break; | |
14163 | + case KLT_POINTER: | |
14164 | + kl_print_pointer_type(ptr, mp, level, flags); | |
14165 | + break; | |
14166 | + case KLT_FUNCTION: | |
14167 | + kl_print_function_type(ptr, mp, level, flags); | |
14168 | + break; | |
14169 | + case KLT_BASE: | |
14170 | + kl_print_base_type(ptr, mp, level, flags); | |
14171 | + break; | |
14172 | + case KLT_ENUMERATION: | |
14173 | + kl_print_enumeration_type(ptr, mp, level, flags); | |
14174 | + break; | |
14175 | + case KLT_TYPEDEF: | |
14176 | + while (rkltp && rkltp->kl_realtype) { | |
14177 | + if (rkltp->kl_realtype == rkltp) { | |
14178 | + break; | |
14179 | + } | |
14180 | + rkltp = rkltp->kl_realtype; | |
14181 | + } | |
14182 | + if (ptr) { | |
14183 | + kl_print_typedef_type(ptr, mp, | |
14184 | + level, flags); | |
14185 | + break; | |
14186 | + } | |
14187 | + LEVEL_INDENT(level, flags); | |
14188 | + if (flags & SUPPRESS_NAME) { | |
14189 | + if (rkltp && (mp->kl_bit_size < | |
14190 | + (rkltp->kl_size * 8))) { | |
14191 | + kdb_printf ("%s :%d", | |
14192 | + mp->kl_typestr, | |
14193 | + mp->kl_bit_size); | |
14194 | + } else { | |
14195 | + kdb_printf("%s", | |
14196 | + mp->kl_realtype->kl_name); | |
14197 | + } | |
14198 | + print_realtype(mp->kl_realtype); | |
14199 | + } else { | |
14200 | + if (rkltp && (mp->kl_bit_size < | |
14201 | + (rkltp->kl_size * 8))) { | |
14202 | + if (mp->kl_name) { | |
14203 | + kdb_printf ("%s%s :%d;", | |
14204 | + mp->kl_typestr, | |
14205 | + mp->kl_name, | |
14206 | + mp->kl_bit_size); | |
14207 | + } else { | |
14208 | + kdb_printf ("%s :%d;", | |
14209 | + mp->kl_typestr, | |
14210 | + mp->kl_bit_size); | |
14211 | + } | |
14212 | + } else { | |
14213 | + kdb_printf("%s %s;", | |
14214 | + mp->kl_realtype->kl_name, | |
14215 | + mp->kl_name); | |
14216 | + } | |
14217 | + } | |
14218 | + PRINT_NL(flags); | |
14219 | + break; | |
14220 | + | |
14221 | + default: | |
14222 | + LEVEL_INDENT(level, flags); | |
14223 | + if (mp->kl_typestr) { | |
14224 | + kdb_printf("%s%s;", | |
14225 | + mp->kl_typestr, mp->kl_name); | |
14226 | + } else { | |
14227 | + kdb_printf("<\?\?\? kl_type:%d> %s;", | |
14228 | + kl_type, mp->kl_name); | |
14229 | + } | |
14230 | + PRINT_NL(flags); | |
14231 | + break; | |
14232 | + } | |
14233 | +} | |
14234 | + | |
14235 | +/* | |
14236 | + * kl_print_struct_type() | |
14237 | + */ | |
14238 | +void | |
14239 | +kl_print_struct_type(void *buf, kltype_t *kltp, int level, int flags) | |
14240 | +{ | |
14241 | + int orig_flags = flags; | |
14242 | + void *ptr = NULL; | |
14243 | + kltype_t *mp, *rkltp; | |
14244 | + | |
14245 | + /* If we are printing out an actual struct, then don't print any | |
14246 | + * semi colons. | |
14247 | + */ | |
14248 | + if (buf) { | |
14249 | + flags |= SUPPRESS_SEMI_COLON; | |
14250 | + } | |
14251 | + | |
14252 | + LEVEL_INDENT(level, flags); | |
14253 | + if ((level == 0) || (flags & NO_INDENT)) { | |
14254 | + kdb_printf("%s{\n", kltp->kl_typestr); | |
14255 | + } else { | |
14256 | + if (buf) { | |
14257 | + if (level && !(kltp->kl_flags & TYP_ANONYMOUS_FLG)) { | |
14258 | + kdb_printf("%s = %s{\n", | |
14259 | + kltp->kl_name, kltp->kl_typestr); | |
14260 | + } else { | |
14261 | + kdb_printf("%s{\n", kltp->kl_typestr); | |
14262 | + } | |
14263 | + flags &= (~SUPPRESS_NL); | |
14264 | + } else { | |
14265 | + if (kltp->kl_typestr) { | |
14266 | + kdb_printf("%s{\n", kltp->kl_typestr); | |
14267 | + } else { | |
14268 | + kdb_printf("<UNKNOWN> {\n"); | |
14269 | + } | |
14270 | + } | |
14271 | + } | |
14272 | + | |
14273 | + /* If the SUPPRESS_NL, SUPPRESS_SEMI_COLON, and SUPPRESS_NAME flags | |
14274 | + * are set and buf is NULL, then turn them off as they only apply | |
14275 | + * at the end of the struct. We save the original flags for that | |
14276 | + * purpose. | |
14277 | + */ | |
14278 | + if (!buf) { | |
14279 | + flags &= ~(SUPPRESS_NL|SUPPRESS_SEMI_COLON|SUPPRESS_NAME); | |
14280 | + } | |
14281 | + | |
14282 | + /* If the NO_INDENT is set, we need to turn it off at this | |
14283 | + * point -- just in case we come across a member of this struct | |
14284 | + * that is also a struct. | |
14285 | + */ | |
14286 | + if (flags & NO_INDENT) { | |
14287 | + flags &= ~(NO_INDENT); | |
14288 | + } | |
14289 | + | |
14290 | + if (kltp->kl_type == KLT_MEMBER) { | |
14291 | + rkltp = kl_realtype(kltp, 0); | |
14292 | + } else { | |
14293 | + rkltp = kltp; | |
14294 | + } | |
14295 | + level++; | |
14296 | + if ((mp = rkltp->kl_member)) { | |
14297 | + while (mp) { | |
14298 | + if (buf) { | |
14299 | + ptr = buf + mp->kl_offset; | |
14300 | + } | |
14301 | + kl_print_member(ptr, mp, level, flags); | |
14302 | + mp = mp->kl_member; | |
14303 | + } | |
14304 | + } else { | |
14305 | + if (kltp->kl_flags & TYP_INCOMPLETE_FLG) { | |
14306 | + LEVEL_INDENT(level, flags); | |
14307 | + kdb_printf("<INCOMPLETE TYPE>\n"); | |
14308 | + } | |
14309 | + } | |
14310 | + level--; | |
14311 | + LEVEL_INDENT(level, flags); | |
14312 | + | |
14313 | + /* kl_size = 0 for empty structs */ | |
14314 | + if (ptr || ((kltp->kl_size == 0) && buf)) { | |
14315 | + kdb_printf("}"); | |
14316 | + } else if ((kltp->kl_type == KLT_MEMBER) && | |
14317 | + !(orig_flags & SUPPRESS_NAME) && | |
14318 | + !(kltp->kl_flags & TYP_ANONYMOUS_FLG)) { | |
14319 | + kdb_printf("} %s", kltp->kl_name); | |
14320 | + } else { | |
14321 | + kdb_printf("}"); | |
14322 | + } | |
14323 | + PRINT_SEMI_COLON(level, orig_flags); | |
14324 | + PRINT_NL(orig_flags); | |
14325 | +} | |
14326 | + | |
14327 | +/* | |
14328 | + * kl_print_type() | |
14329 | + */ | |
14330 | +void | |
14331 | +kl_print_type(void *buf, kltype_t *kltp, int level, int flags) | |
14332 | +{ | |
14333 | + void *ptr; | |
14334 | + | |
14335 | + if (buf) { | |
14336 | + if (kltp->kl_offset) { | |
14337 | + ptr = (void *)((uaddr_t)buf + kltp->kl_offset); | |
14338 | + } else { | |
14339 | + ptr = buf; | |
14340 | + } | |
14341 | + } else { | |
14342 | + ptr = 0; | |
14343 | + } | |
14344 | + | |
14345 | + /* Only allow binary printing for base types | |
14346 | + */ | |
14347 | + if (kltp->kl_type != KLT_BASE) { | |
14348 | + flags &= (~C_BINARY); | |
14349 | + } | |
14350 | + switch (kltp->kl_type) { | |
14351 | + | |
14352 | + case KLT_TYPEDEF: | |
14353 | + kl_print_typedef_type(ptr, kltp, level, flags); | |
14354 | + break; | |
14355 | + | |
14356 | + case KLT_STRUCT: | |
14357 | + case KLT_UNION: | |
14358 | + kl_print_struct_type(ptr, kltp, level, flags); | |
14359 | + break; | |
14360 | + | |
14361 | + case KLT_MEMBER: | |
14362 | + kl_print_member(ptr, kltp, level, flags); | |
14363 | + break; | |
14364 | + | |
14365 | + case KLT_POINTER: | |
14366 | + kl_print_pointer_type(ptr, kltp, level, flags); | |
14367 | + break; | |
14368 | + | |
14369 | + case KLT_FUNCTION: | |
14370 | + LEVEL_INDENT(level, flags); | |
14371 | + kl_print_function_type(ptr, kltp, level, flags); | |
14372 | + break; | |
14373 | + | |
14374 | + case KLT_ARRAY: | |
14375 | + kl_print_array_type(ptr, kltp, level, flags); | |
14376 | + break; | |
14377 | + | |
14378 | + case KLT_ENUMERATION: | |
14379 | + kl_print_enumeration_type(ptr, | |
14380 | + kltp, level, flags); | |
14381 | + break; | |
14382 | + | |
14383 | + case KLT_BASE: | |
14384 | + kl_print_base_type(ptr, kltp, level, flags); | |
14385 | + break; | |
14386 | + | |
14387 | + default: | |
14388 | + LEVEL_INDENT(level, flags); | |
14389 | + if (flags & SUPPRESS_NAME) { | |
14390 | + kdb_printf ("%s", kltp->kl_name); | |
14391 | + } else { | |
14392 | + kdb_printf ("%s %s;", | |
14393 | + kltp->kl_name, kltp->kl_name); | |
14394 | + } | |
14395 | + PRINT_NL(flags); | |
14396 | + } | |
14397 | +} | |
14398 | + | |
14399 | +/* | |
14400 | + * eval is from lcrash eval.c | |
14401 | + */ | |
14402 | + | |
14403 | +/* Forward declarations */ | |
14404 | +static void free_node(node_t *); | |
14405 | +static node_t *make_node(token_t *, int); | |
14406 | +static node_t *get_node_list(token_t *, int); | |
14407 | +static node_t *do_eval(int); | |
14408 | +static int is_unary(int); | |
14409 | +static int is_binary(int); | |
14410 | +static int precedence(int); | |
14411 | +static node_t *get_sizeof(void); | |
14412 | +static int replace_cast(node_t *, int); | |
14413 | +static int replace_unary(node_t *, int); | |
14414 | +static node_t *replace(node_t *, int); | |
14415 | +static void array_to_element(node_t*, node_t*); | |
14416 | +static int type_to_number(node_t *); | |
14417 | +kltype_t *number_to_type(node_t *); | |
14418 | +static type_t *eval_type(node_t *); | |
14419 | +static type_t *get_type(char *, int); | |
14420 | +static int add_rchild(node_t *, node_t *); | |
14421 | +static void free_nodelist(node_t *); | |
14422 | + | |
14423 | +/* Global variables | |
14424 | + */ | |
14425 | +static int logical_flag; | |
14426 | +static node_t *node_list = (node_t *)NULL; | |
14427 | +uint64_t eval_error; | |
14428 | +char *error_token; | |
14429 | + | |
14430 | +/* | |
14431 | + * set_eval_error() | |
14432 | + */ | |
14433 | +static void | |
14434 | +set_eval_error(uint64_t ecode) | |
14435 | +{ | |
14436 | + eval_error = ecode; | |
14437 | +} | |
14438 | + | |
14439 | +/* | |
14440 | + * is_typestr() | |
14441 | + * | |
14442 | + * We check for "struct", "union", etc. separately because they | |
14443 | + * would not be an actual part of the type name. We also assume | |
14444 | + * that the string passed in | |
14445 | + * | |
14446 | + * - does not have any leading blanks or tabs | |
14447 | + * - is NULL terminated | |
14448 | + * - contains only one type name to check | |
14449 | + * - does not contain any '*' characters | |
14450 | + */ | |
14451 | +static int | |
14452 | +is_typestr(char *str) | |
14453 | +{ | |
14454 | + int len; | |
14455 | + | |
14456 | + len = strlen(str); | |
14457 | + if ((len >= 6) && !strncmp(str, "struct", 6)) { | |
14458 | + return(1); | |
14459 | + } else if ((len >= 5) &&!strncmp(str, "union", 5)) { | |
14460 | + return(1); | |
14461 | + } else if ((len >= 5) &&!strncmp(str, "short", 5)) { | |
14462 | + return(1); | |
14463 | + } else if ((len >= 8) &&!strncmp(str, "unsigned", 8)) { | |
14464 | + return(1); | |
14465 | + } else if ((len >= 6) &&!strncmp(str, "signed", 6)) { | |
14466 | + return(1); | |
14467 | + } else if ((len >= 4) &&!strncmp(str, "long", 4)) { | |
14468 | + return(1); | |
14469 | + } | |
14470 | + /* Strip off any trailing blanks | |
14471 | + */ | |
14472 | + while(*str && ((str[strlen(str) - 1] == ' ') | |
14473 | + || (str[strlen(str) - 1] == '\t'))) { | |
14474 | + str[strlen(str) - 1] = 0; | |
14475 | + } | |
14476 | + if (kl_find_type(str, KLT_TYPES)) { | |
14477 | + return (1); | |
14478 | + } | |
14479 | + return(0); | |
14480 | +} | |
14481 | + | |
14482 | +/* | |
14483 | + * free_tokens() | |
14484 | + */ | |
14485 | +static void | |
14486 | +free_tokens(token_t *tp) | |
14487 | +{ | |
14488 | + token_t *t, *tnext; | |
14489 | + | |
14490 | + t = tp; | |
14491 | + while (t) { | |
14492 | + tnext = t->next; | |
14493 | + if (t->string) { | |
14494 | + kl_free_block((void *)t->string); | |
14495 | + } | |
14496 | + kl_free_block((void *)t); | |
14497 | + t = tnext; | |
14498 | + } | |
14499 | +} | |
14500 | + | |
14501 | +/* | |
14502 | + * process_text() | |
14503 | + */ | |
14504 | +static int | |
14505 | +process_text(char **str, token_t *tok) | |
14506 | +{ | |
14507 | + char *cp = *str; | |
14508 | + char *s = NULL; | |
14509 | + int len = 0; | |
14510 | + | |
14511 | + /* Check and see if this token is a STRING or CHARACTER | |
14512 | + * type (beginning with a single or double quote). | |
14513 | + */ | |
14514 | + if (*cp == '\'') { | |
14515 | + /* make sure that only a single character is between | |
14516 | + * the single quotes (it can be an escaped character | |
14517 | + * too). | |
14518 | + */ | |
14519 | + s = strpbrk((cp + 1), "\'"); | |
14520 | + if (!s) { | |
14521 | + set_eval_error(E_SINGLE_QUOTE); | |
14522 | + error_token = tok->ptr; | |
14523 | + return(1); | |
14524 | + } | |
14525 | + len = (uaddr_t)s - (uaddr_t)cp; | |
14526 | + if ((*(cp+1) == '\\')) { | |
14527 | + if (*(cp+2) == '0') { | |
14528 | + long int val; | |
14529 | + unsigned long uval; | |
14530 | + char *ep; | |
14531 | + | |
14532 | + uval = kl_strtoull((char*)(cp+2), | |
14533 | + (char **)&ep, 8); | |
14534 | + val = uval; | |
14535 | + if ((val > 255) || (*ep != '\'')) { | |
14536 | + set_eval_error(E_BAD_CHAR); | |
14537 | + error_token = tok->ptr; | |
14538 | + return(1); | |
14539 | + } | |
14540 | + } else if (*(cp+3) != '\'') { | |
14541 | + set_eval_error(E_BAD_CHAR); | |
14542 | + error_token = tok->ptr; | |
14543 | + return(1); | |
14544 | + } | |
14545 | + tok->type = CHARACTER; | |
14546 | + } else if (len == 2) { | |
14547 | + tok->type = CHARACTER; | |
14548 | + } else { | |
14549 | + | |
14550 | + /* Treat as a single token entry. It's possible | |
14551 | + * that what's between the single quotes is a | |
14552 | + * type name. That will be determined later on. | |
14553 | + */ | |
14554 | + tok->type = STRING; | |
14555 | + } | |
14556 | + *str = cp + len; | |
14557 | + } else if (*cp == '\"') { | |
14558 | + s = strpbrk((cp + 1), "\""); | |
14559 | + if (!s) { | |
14560 | + set_eval_error(E_BAD_STRING); | |
14561 | + error_token = tok->ptr; | |
14562 | + return(1); | |
14563 | + } | |
14564 | + len = (uaddr_t)s - (uaddr_t)cp; | |
14565 | + tok->type = TEXT; | |
14566 | + *str = cp + len; | |
14567 | + } | |
14568 | + if ((tok->type == STRING) || (tok->type == TEXT)) { | |
14569 | + | |
14570 | + if ((tok->type == TEXT) && (strlen(cp) > (len + 1))) { | |
14571 | + | |
14572 | + /* Check to see if there is a comma or semi-colon | |
14573 | + * directly following the string. If there is, | |
14574 | + * then the string is OK (the following characters | |
14575 | + * are part of the next expression). Also, it's OK | |
14576 | + * to have trailing blanks as long as that's all | |
14577 | + * threre is. | |
14578 | + */ | |
14579 | + char *c; | |
14580 | + | |
14581 | + c = s + 1; | |
14582 | + while (*c) { | |
14583 | + if ((*c == ',') || (*c == ';')) { | |
14584 | + break; | |
14585 | + } else if (*c != ' ') { | |
14586 | + set_eval_error(E_END_EXPECTED); | |
14587 | + tok->ptr = c; | |
14588 | + error_token = tok->ptr; | |
14589 | + return(1); | |
14590 | + } | |
14591 | + c++; | |
14592 | + } | |
14593 | + /* Truncate the trailing blanks (they are not | |
14594 | + * part of the string). | |
14595 | + */ | |
14596 | + if (c != (s + 1)) { | |
14597 | + *(s + 1) = 0; | |
14598 | + } | |
14599 | + } | |
14600 | + tok->string = (char *)kl_alloc_block(len); | |
14601 | + memcpy(tok->string, (cp + 1), len - 1); | |
14602 | + tok->string[len - 1] = 0; | |
14603 | + } | |
14604 | + return(0); | |
14605 | +} | |
14606 | + | |
14607 | +/* | |
14608 | + * get_token_list() | |
14609 | + */ | |
14610 | +static token_t * | |
14611 | +get_token_list(char *str) | |
14612 | +{ | |
14613 | + int paren_count = 0; | |
14614 | + char *cp; | |
14615 | + token_t *tok = (token_t*)NULL, *tok_head = (token_t*)NULL; | |
14616 | + token_t *tok_last = (token_t*)NULL; | |
14617 | + | |
14618 | + cp = str; | |
14619 | + eval_error = 0; | |
14620 | + | |
14621 | + while (*cp) { | |
14622 | + | |
14623 | + /* Skip past any "white space" (spaces and tabs). | |
14624 | + */ | |
14625 | + switch (*cp) { | |
14626 | + case ' ' : | |
14627 | + case '\t' : | |
14628 | + case '`' : | |
14629 | + cp++; | |
14630 | + continue; | |
14631 | + default : | |
14632 | + break; | |
14633 | + } | |
14634 | + | |
14635 | + /* Allocate space for the next token */ | |
14636 | + tok = (token_t *)kl_alloc_block(sizeof(token_t)); | |
14637 | + tok->ptr = cp; | |
14638 | + | |
14639 | + switch(*cp) { | |
14640 | + | |
14641 | + /* Check for operators | |
14642 | + */ | |
14643 | + case '+' : | |
14644 | + if (*((char*)cp + 1) == '+') { | |
14645 | + | |
14646 | + /* We aren't doing asignment here, | |
14647 | + * so the ++ operator is not | |
14648 | + * considered valid. | |
14649 | + */ | |
14650 | + set_eval_error(E_BAD_OPERATOR); | |
14651 | + error_token = tok_last->ptr; | |
14652 | + free_tokens(tok_head); | |
14653 | + free_tokens(tok); | |
14654 | + return ((token_t*)NULL); | |
14655 | + } else if (!tok_last || | |
14656 | + (tok_last->operator && | |
14657 | + (tok_last->operator != CLOSE_PAREN))) { | |
14658 | + tok->operator = UNARY_PLUS; | |
14659 | + } else { | |
14660 | + tok->operator = ADD; | |
14661 | + } | |
14662 | + break; | |
14663 | + | |
14664 | + case '-' : | |
14665 | + if (*((char*)cp + 1) == '-') { | |
14666 | + | |
14667 | + /* We aren't doing asignment here, so | |
14668 | + * the -- operator is not considered | |
14669 | + * valid. | |
14670 | + */ | |
14671 | + set_eval_error(E_BAD_OPERATOR); | |
14672 | + error_token = tok_last->ptr; | |
14673 | + free_tokens(tok_head); | |
14674 | + free_tokens(tok); | |
14675 | + return ((token_t*)NULL); | |
14676 | + } else if (*((char*)cp + 1) == '>') { | |
14677 | + tok->operator = RIGHT_ARROW; | |
14678 | + cp++; | |
14679 | + } else if (!tok_last || (tok_last->operator && | |
14680 | + (tok_last->operator != CLOSE_PAREN))) { | |
14681 | + tok->operator = UNARY_MINUS; | |
14682 | + } else { | |
14683 | + tok->operator = SUBTRACT; | |
14684 | + } | |
14685 | + break; | |
14686 | + | |
14687 | + case '.' : | |
14688 | + /* XXX - need to check to see if this is a | |
14689 | + * decimal point in the middle fo a floating | |
14690 | + * point value. | |
14691 | + */ | |
14692 | + tok->operator = DOT; | |
14693 | + break; | |
14694 | + | |
14695 | + case '*' : | |
14696 | + /* XXX - need a better way to tell if this is | |
14697 | + * an INDIRECTION. perhaps check the next | |
14698 | + * token? | |
14699 | + */ | |
14700 | + if (!tok_last || (tok_last->operator && | |
14701 | + ((tok_last->operator != CLOSE_PAREN) && | |
14702 | + (tok_last->operator != CAST)))) { | |
14703 | + tok->operator = INDIRECTION; | |
14704 | + } else { | |
14705 | + tok->operator = MULTIPLY; | |
14706 | + } | |
14707 | + break; | |
14708 | + | |
14709 | + case '/' : | |
14710 | + tok->operator = DIVIDE; | |
14711 | + break; | |
14712 | + | |
14713 | + case '%' : | |
14714 | + tok->operator = MODULUS; | |
14715 | + break; | |
14716 | + | |
14717 | + case '(' : { | |
14718 | + char *s, *s1, *s2; | |
14719 | + int len; | |
14720 | + | |
14721 | + /* Make sure the previous token is an operator | |
14722 | + */ | |
14723 | + if (tok_last && !tok_last->operator) { | |
14724 | + set_eval_error(E_SYNTAX_ERROR); | |
14725 | + error_token = tok_last->ptr; | |
14726 | + free_tokens(tok_head); | |
14727 | + free_tokens(tok); | |
14728 | + return ((token_t*)NULL); | |
14729 | + } | |
14730 | + | |
14731 | + if (tok_last && | |
14732 | + ((tok_last->operator == RIGHT_ARROW) || | |
14733 | + (tok_last->operator == DOT))) { | |
14734 | + set_eval_error(E_SYNTAX_ERROR); | |
14735 | + error_token = tok_last->ptr; | |
14736 | + free_tokens(tok_head); | |
14737 | + free_tokens(tok); | |
14738 | + return ((token_t*)NULL); | |
14739 | + } | |
14740 | + | |
14741 | + /* Check here to see if following tokens | |
14742 | + * constitute a cast. | |
14743 | + */ | |
14744 | + | |
14745 | + /* Skip past any "white space" (spaces | |
14746 | + * and tabs) | |
14747 | + */ | |
14748 | + while ((*(cp+1) == ' ') || (*(cp+1) == '\t')) { | |
14749 | + cp++; | |
14750 | + } | |
14751 | + if ((*(cp+1) == '(') || isdigit(*(cp+1)) || | |
14752 | + (*(cp+1) == '+') || (*(cp+1) == '-') || | |
14753 | + (*(cp+1) == '*') || (*(cp+1) == '&') || | |
14754 | + (*(cp+1) == ')')){ | |
14755 | + tok->operator = OPEN_PAREN; | |
14756 | + paren_count++; | |
14757 | + break; | |
14758 | + } | |
14759 | + | |
14760 | + /* Make sure we have a CLOSE_PAREN. | |
14761 | + */ | |
14762 | + if (!(s1 = strchr(cp+1, ')'))) { | |
14763 | + set_eval_error(E_OPEN_PAREN); | |
14764 | + error_token = tok->ptr; | |
14765 | + free_tokens(tok_head); | |
14766 | + free_tokens(tok); | |
14767 | + return ((token_t*)NULL); | |
14768 | + } | |
14769 | + /* Check to see if this is NOT a simple | |
14770 | + * typecast. | |
14771 | + */ | |
14772 | + if (!(s2 = strchr(cp+1, '.'))) { | |
14773 | + s2 = strstr(cp+1, "->"); | |
14774 | + } | |
14775 | + if (s2 && (s2 < s1)) { | |
14776 | + tok->operator = OPEN_PAREN; | |
14777 | + paren_count++; | |
14778 | + break; | |
14779 | + } | |
14780 | + | |
14781 | + if ((s = strpbrk(cp+1, "*)"))) { | |
14782 | + char str[128]; | |
14783 | + | |
14784 | + len = (uaddr_t)s - (uaddr_t)(cp+1); | |
14785 | + strncpy(str, cp+1, len); | |
14786 | + str[len] = 0; | |
14787 | + if (!is_typestr(str)) { | |
14788 | + set_eval_error(E_BAD_TYPE); | |
14789 | + error_token = tok->ptr; | |
14790 | + free_tokens(tok_head); | |
14791 | + free_tokens(tok); | |
14792 | + return ((token_t*)NULL); | |
14793 | + } | |
14794 | + if (!(s = strpbrk((cp+1), ")"))) { | |
14795 | + set_eval_error(E_OPEN_PAREN); | |
14796 | + error_token = tok->ptr; | |
14797 | + free_tokens(tok_head); | |
14798 | + free_tokens(tok); | |
14799 | + return ((token_t*)NULL); | |
14800 | + } | |
14801 | + len = (uaddr_t)s - (uaddr_t)(cp+1); | |
14802 | + tok->string = (char *) | |
14803 | + kl_alloc_block(len + 1); | |
14804 | + memcpy(tok->string, (cp+1), len); | |
14805 | + tok->string[len] = 0; | |
14806 | + tok->operator = CAST; | |
14807 | + cp = (char *)((uaddr_t)(cp+1) + len); | |
14808 | + break; | |
14809 | + } | |
14810 | + tok->operator = OPEN_PAREN; | |
14811 | + paren_count++; | |
14812 | + break; | |
14813 | + } | |
14814 | + | |
14815 | + case ')' : | |
14816 | + if (tok_last && ((tok_last->operator == | |
14817 | + RIGHT_ARROW) || | |
14818 | + (tok_last->operator == DOT))) { | |
14819 | + set_eval_error(E_SYNTAX_ERROR); | |
14820 | + error_token = tok_last->ptr; | |
14821 | + free_tokens(tok_head); | |
14822 | + free_tokens(tok); | |
14823 | + return ((token_t*)NULL); | |
14824 | + } | |
14825 | + tok->operator = CLOSE_PAREN; | |
14826 | + paren_count--; | |
14827 | + break; | |
14828 | + | |
14829 | + case '&' : | |
14830 | + if (*((char*)cp + 1) == '&') { | |
14831 | + tok->operator = LOGICAL_AND; | |
14832 | + cp++; | |
14833 | + } else if (!tok_last || (tok_last && | |
14834 | + (tok_last->operator && | |
14835 | + tok_last->operator != | |
14836 | + CLOSE_PAREN))) { | |
14837 | + tok->operator = ADDRESS; | |
14838 | + } else { | |
14839 | + tok->operator = BITWISE_AND; | |
14840 | + } | |
14841 | + break; | |
14842 | + | |
14843 | + case '|' : | |
14844 | + if (*((char*)cp + 1) == '|') { | |
14845 | + tok->operator = LOGICAL_OR; | |
14846 | + cp++; | |
14847 | + } else { | |
14848 | + tok->operator = BITWISE_OR; | |
14849 | + } | |
14850 | + break; | |
14851 | + | |
14852 | + case '=' : | |
14853 | + if (*((char*)cp + 1) == '=') { | |
14854 | + tok->operator = EQUAL; | |
14855 | + cp++; | |
14856 | + } else { | |
14857 | + /* ASIGNMENT -- NOT IMPLEMENTED | |
14858 | + */ | |
14859 | + tok->operator = NOT_YET; | |
14860 | + } | |
14861 | + break; | |
14862 | + | |
14863 | + case '<' : | |
14864 | + if (*((char*)cp + 1) == '<') { | |
14865 | + tok->operator = LEFT_SHIFT; | |
14866 | + cp++; | |
14867 | + } else if (*((char*)cp + 1) == '=') { | |
14868 | + tok->operator = LESS_THAN_OR_EQUAL; | |
14869 | + cp++; | |
14870 | + } else { | |
14871 | + tok->operator = LESS_THAN; | |
14872 | + } | |
14873 | + break; | |
14874 | + | |
14875 | + case '>' : | |
14876 | + if (*((char*)(cp + 1)) == '>') { | |
14877 | + tok->operator = RIGHT_SHIFT; | |
14878 | + cp++; | |
14879 | + } else if (*((char*)cp + 1) == '=') { | |
14880 | + tok->operator = GREATER_THAN_OR_EQUAL; | |
14881 | + cp++; | |
14882 | + } else { | |
14883 | + tok->operator = GREATER_THAN; | |
14884 | + } | |
14885 | + break; | |
14886 | + | |
14887 | + case '!' : | |
14888 | + if (*((char*)cp + 1) == '=') { | |
14889 | + tok->operator = NOT_EQUAL; | |
14890 | + cp++; | |
14891 | + } else { | |
14892 | + tok->operator = LOGICAL_NEGATION; | |
14893 | + } | |
14894 | + break; | |
14895 | + | |
14896 | + case '$' : | |
14897 | + set_eval_error(E_NOT_IMPLEMENTED); | |
14898 | + error_token = tok->ptr; | |
14899 | + free_tokens(tok_head); | |
14900 | + free_tokens(tok); | |
14901 | + return((token_t*)NULL); | |
14902 | + case '~' : | |
14903 | + tok->operator = ONES_COMPLEMENT; | |
14904 | + break; | |
14905 | + | |
14906 | + case '^' : | |
14907 | + tok->operator = BITWISE_EXCLUSIVE_OR; | |
14908 | + break; | |
14909 | + | |
14910 | + case '?' : | |
14911 | + set_eval_error(E_NOT_IMPLEMENTED); | |
14912 | + error_token = tok->ptr; | |
14913 | + free_tokens(tok_head); | |
14914 | + free_tokens(tok); | |
14915 | + return((token_t*)NULL); | |
14916 | + case ':' : | |
14917 | + set_eval_error(E_NOT_IMPLEMENTED); | |
14918 | + error_token = tok->ptr; | |
14919 | + free_tokens(tok_head); | |
14920 | + free_tokens(tok); | |
14921 | + return((token_t*)NULL); | |
14922 | + case '[' : | |
14923 | + tok->operator = OPEN_SQUARE_BRACKET;; | |
14924 | + break; | |
14925 | + | |
14926 | + case ']' : | |
14927 | + tok->operator = CLOSE_SQUARE_BRACKET;; | |
14928 | + break; | |
14929 | + | |
14930 | + default: { | |
14931 | + | |
14932 | + char *s; | |
14933 | + int len; | |
14934 | + | |
14935 | + /* See if the last token is a RIGHT_ARROW | |
14936 | + * or a DOT. If it is, then this token must | |
14937 | + * be the name of a struct/union member. | |
14938 | + */ | |
14939 | + if (tok_last && | |
14940 | + ((tok_last->operator == RIGHT_ARROW) || | |
14941 | + (tok_last->operator == DOT))) { | |
14942 | + tok->type = MEMBER; | |
14943 | + } else if (process_text(&cp, tok)) { | |
14944 | + free_tokens(tok_head); | |
14945 | + free_tokens(tok); | |
14946 | + return((token_t*)NULL); | |
14947 | + } | |
14948 | + if (tok->type == TEXT) { | |
14949 | + return(tok); | |
14950 | + } else if (tok->type == STRING) { | |
14951 | + if (is_typestr(tok->string)) { | |
14952 | + tok->type = TYPE_DEF; | |
14953 | + } else { | |
14954 | + tok->operator = TEXT; | |
14955 | + return(tok); | |
14956 | + } | |
14957 | + break; | |
14958 | + } else if (tok->type == CHARACTER) { | |
14959 | + break; | |
14960 | + } | |
14961 | + | |
14962 | + /* Check and See if the entire string is | |
14963 | + * a typename (valid only for whatis case). | |
14964 | + */ | |
14965 | + s = strpbrk(cp, | |
14966 | + ".\t+-*/()[]|~!$&%^<>?:&=^\"\'"); | |
14967 | + if (!s && !tok->type && is_typestr(cp)) { | |
14968 | + tok->type = TYPE_DEF; | |
14969 | + len = strlen(cp) + 1; | |
14970 | + tok->string = (char *) | |
14971 | + kl_alloc_block(len); | |
14972 | + memcpy(tok->string, cp, len - 1); | |
14973 | + tok->string[len - 1] = 0; | |
14974 | + cp = (char *)((uaddr_t)cp + len - 2); | |
14975 | + break; | |
14976 | + } | |
14977 | + | |
14978 | + /* Now check for everything else | |
14979 | + */ | |
14980 | + if ((s = strpbrk(cp, | |
14981 | + " .\t+-*/()[]|~!$&%^<>?:&=^\"\'"))) { | |
14982 | + len = (uaddr_t)s - (uaddr_t)cp + 1; | |
14983 | + } else { | |
14984 | + len = strlen(cp) + 1; | |
14985 | + } | |
14986 | + | |
14987 | + tok->string = | |
14988 | + (char *)kl_alloc_block(len); | |
14989 | + memcpy(tok->string, cp, len - 1); | |
14990 | + tok->string[len - 1] = 0; | |
14991 | + | |
14992 | + cp = (char *)((uaddr_t)cp + len - 2); | |
14993 | + | |
14994 | + /* Check to see if this is the keyword | |
14995 | + * "sizeof". If not, then check to see if | |
14996 | + * the string is a member name. | |
14997 | + */ | |
14998 | + if (!strcmp(tok->string, "sizeof")) { | |
14999 | + tok->operator = SIZEOF; | |
15000 | + kl_free_block((void *)tok->string); | |
15001 | + tok->string = 0; | |
15002 | + } else if (tok_last && | |
15003 | + ((tok_last->operator == RIGHT_ARROW) || | |
15004 | + (tok_last->operator == DOT))) { | |
15005 | + tok->type = MEMBER; | |
15006 | + } else { | |
15007 | + tok->type = STRING; | |
15008 | + } | |
15009 | + break; | |
15010 | + } | |
15011 | + } | |
15012 | + if (!(tok->type)) { | |
15013 | + tok->type = OPERATOR; | |
15014 | + } | |
15015 | + if (!tok_head) { | |
15016 | + tok_head = tok_last = tok; | |
15017 | + } else { | |
15018 | + tok_last->next = tok; | |
15019 | + tok_last = tok; | |
15020 | + } | |
15021 | + cp++; | |
15022 | + } | |
15023 | + if (paren_count < 0) { | |
15024 | + set_eval_error(E_CLOSE_PAREN); | |
15025 | + error_token = tok->ptr; | |
15026 | + free_tokens(tok_head); | |
15027 | + return((token_t*)NULL); | |
15028 | + } else if (paren_count > 0) { | |
15029 | + set_eval_error(E_OPEN_PAREN); | |
15030 | + error_token = tok->ptr; | |
15031 | + free_tokens(tok_head); | |
15032 | + return((token_t*)NULL); | |
15033 | + } | |
15034 | + return(tok_head); | |
15035 | +} | |
15036 | + | |
15037 | +/* | |
15038 | + * valid_binary_args() | |
15039 | + */ | |
15040 | +int | |
15041 | +valid_binary_args(node_t *np, node_t *left, node_t *right) | |
15042 | +{ | |
15043 | + int op = np->operator; | |
15044 | + | |
15045 | + if ((op == RIGHT_ARROW) || (op == DOT)) { | |
15046 | + if (!left) { | |
15047 | + set_eval_error(E_MISSING_STRUCTURE); | |
15048 | + error_token = np->tok_ptr; | |
15049 | + return(0); | |
15050 | + } else if (!(left->node_type == TYPE_DEF) && | |
15051 | + !(left->node_type == MEMBER) && | |
15052 | + !(left->operator == CLOSE_PAREN) && | |
15053 | + !(left->operator == CLOSE_SQUARE_BRACKET)) { | |
15054 | + set_eval_error(E_BAD_STRUCTURE); | |
15055 | + error_token = left->tok_ptr; | |
15056 | + return(0); | |
15057 | + } | |
15058 | + if (!right || (!(right->node_type == MEMBER))) { | |
15059 | + set_eval_error(E_BAD_MEMBER); | |
15060 | + error_token = np->tok_ptr; | |
15061 | + return(0); | |
15062 | + } | |
15063 | + return(1); | |
15064 | + } | |
15065 | + if (!left || !right) { | |
15066 | + set_eval_error(E_MISSING_OPERAND); | |
15067 | + error_token = np->tok_ptr; | |
15068 | + return(0); | |
15069 | + } | |
15070 | + switch (left->operator) { | |
15071 | + case CLOSE_PAREN: | |
15072 | + case CLOSE_SQUARE_BRACKET: | |
15073 | + break; | |
15074 | + default: | |
15075 | + switch(left->node_type) { | |
15076 | + case NUMBER: | |
15077 | + case STRING: | |
15078 | + case TEXT: | |
15079 | + case CHARACTER: | |
15080 | + case EVAL_VAR: | |
15081 | + case MEMBER: | |
15082 | + break; | |
15083 | + default: | |
15084 | + set_eval_error(E_BAD_OPERAND); | |
15085 | + error_token = np->tok_ptr; | |
15086 | + return(0); | |
15087 | + } | |
15088 | + } | |
15089 | + switch (right->operator) { | |
15090 | + case OPEN_PAREN: | |
15091 | + break; | |
15092 | + default: | |
15093 | + switch(right->node_type) { | |
15094 | + case NUMBER: | |
15095 | + case STRING: | |
15096 | + case TEXT: | |
15097 | + case CHARACTER: | |
15098 | + case EVAL_VAR: | |
15099 | + case MEMBER: | |
15100 | + break; | |
15101 | + default: | |
15102 | + set_eval_error(E_BAD_OPERAND); | |
15103 | + error_token = np->tok_ptr; | |
15104 | + return(0); | |
15105 | + } | |
15106 | + } | |
15107 | + return(1); | |
15108 | +} | |
15109 | + | |
15110 | +/* | |
15111 | + * get_node_list() | |
15112 | + */ | |
15113 | +static node_t * | |
15114 | +get_node_list(token_t *tp, int flags) | |
15115 | +{ | |
15116 | + node_t *root = (node_t *)NULL; | |
15117 | + node_t *np = (node_t *)NULL; | |
15118 | + node_t *last = (node_t *)NULL; | |
15119 | + | |
15120 | + /* Loop through the tokens and convert them to nodes. | |
15121 | + */ | |
15122 | + while (tp) { | |
15123 | + np = make_node(tp, flags); | |
15124 | + if (eval_error) { | |
15125 | + return((node_t *)NULL); | |
15126 | + } | |
15127 | + if (root) { | |
15128 | + last->next = np; | |
15129 | + last = np; | |
15130 | + } else { | |
15131 | + root = last = np; | |
15132 | + } | |
15133 | + tp = tp->next; | |
15134 | + } | |
15135 | + last->next = (node_t *)NULL; /* cpw patch */ | |
15136 | + last = (node_t *)NULL; | |
15137 | + for (np = root; np; np = np->next) { | |
15138 | + if (is_binary(np->operator)) { | |
15139 | + if (!valid_binary_args(np, last, np->next)) { | |
15140 | + free_nodelist(root); | |
15141 | + return((node_t *)NULL); | |
15142 | + } | |
15143 | + } | |
15144 | + last = np; | |
15145 | + } | |
15146 | + return(root); | |
15147 | +} | |
15148 | + | |
15149 | +/* | |
15150 | + * next_node() | |
15151 | + */ | |
15152 | +static node_t * | |
15153 | +next_node(void) | |
15154 | +{ | |
15155 | + node_t *np; | |
15156 | + if ((np = node_list)) { | |
15157 | + node_list = node_list->next; | |
15158 | + np->next = (node_t*)NULL; | |
15159 | + } | |
15160 | + return(np); | |
15161 | +} | |
15162 | + | |
15163 | +/* | |
15164 | + * eval_unary() | |
15165 | + */ | |
15166 | +static node_t * | |
15167 | +eval_unary(node_t *curnp, int flags) | |
15168 | +{ | |
15169 | + node_t *n0, *n1; | |
15170 | + | |
15171 | + n0 = curnp; | |
15172 | + | |
15173 | + /* Peek ahead and make sure there is a next node. | |
15174 | + * Also check to see if the next node requires | |
15175 | + * a recursive call to do_eval(). If it does, we'll | |
15176 | + * let the do_eval() call take care of pulling it | |
15177 | + * off the list. | |
15178 | + */ | |
15179 | + if (!node_list) { | |
15180 | + set_eval_error(E_SYNTAX_ERROR); | |
15181 | + error_token = n0->tok_ptr; | |
15182 | + free_nodes(n0); | |
15183 | + return((node_t*)NULL); | |
15184 | + } | |
15185 | + if (n0->operator == CAST) { | |
15186 | + if (node_list->operator == CLOSE_PAREN) { | |
15187 | + | |
15188 | + /* Free the CLOSE_PAREN and return | |
15189 | + */ | |
15190 | + free_node(next_node()); | |
15191 | + return(n0); | |
15192 | + } | |
15193 | + if (!(node_list->node_type == NUMBER) && | |
15194 | + !(node_list->node_type == VADDR) && | |
15195 | + !((node_list->operator == ADDRESS) || | |
15196 | + (node_list->operator == CAST) || | |
15197 | + (node_list->operator == UNARY_MINUS) || | |
15198 | + (node_list->operator == UNARY_PLUS) || | |
15199 | + (node_list->operator == INDIRECTION) || | |
15200 | + (node_list->operator == OPEN_PAREN))) { | |
15201 | + set_eval_error(E_SYNTAX_ERROR); | |
15202 | + error_token = node_list->tok_ptr; | |
15203 | + free_nodes(n0); | |
15204 | + return((node_t*)NULL); | |
15205 | + } | |
15206 | + } | |
15207 | + if ((n0->operator == INDIRECTION) || | |
15208 | + (n0->operator == ADDRESS) || | |
15209 | + (n0->operator == OPEN_PAREN) || | |
15210 | + is_unary(node_list->operator)) { | |
15211 | + n1 = do_eval(flags); | |
15212 | + if (eval_error) { | |
15213 | + free_nodes(n0); | |
15214 | + free_nodes(n1); | |
15215 | + return((node_t*)NULL); | |
15216 | + } | |
15217 | + } else { | |
15218 | + n1 = next_node(); | |
15219 | + } | |
15220 | + | |
15221 | + if (n1->operator == OPEN_PAREN) { | |
15222 | + /* Get the value contained within the parenthesis. | |
15223 | + * If there was an error, just return. | |
15224 | + */ | |
15225 | + free_node(n1); | |
15226 | + n1 = do_eval(flags); | |
15227 | + if (eval_error) { | |
15228 | + free_nodes(n1); | |
15229 | + free_nodes(n0); | |
15230 | + return((node_t*)NULL); | |
15231 | + } | |
15232 | + } | |
15233 | + | |
15234 | + n0->right = n1; | |
15235 | + if (replace_unary(n0, flags) == -1) { | |
15236 | + if (!eval_error) { | |
15237 | + set_eval_error(E_SYNTAX_ERROR); | |
15238 | + error_token = n0->tok_ptr; | |
15239 | + } | |
15240 | + free_nodes(n0); | |
15241 | + return((node_t*)NULL); | |
15242 | + } | |
15243 | + return(n0); | |
15244 | +} | |
15245 | + | |
15246 | +/* | |
15247 | + * do_eval() -- Reduces an equation to a single value. | |
15248 | + * | |
15249 | + * Any parenthesis (and nested parenthesis) within the equation will | |
15250 | + * be solved first via recursive calls to do_eval(). | |
15251 | + */ | |
15252 | +static node_t * | |
15253 | +do_eval(int flags) | |
15254 | +{ | |
15255 | + node_t *root = (node_t*)NULL, *curnp, *n0, *n1; | |
15256 | + | |
15257 | + /* Loop through the list of nodes until we run out of nodes | |
15258 | + * or we hit a CLOSE_PAREN. If we hit an OPEN_PAREN, make a | |
15259 | + * recursive call to do_eval(). | |
15260 | + */ | |
15261 | + curnp = next_node(); | |
15262 | + while (curnp) { | |
15263 | + n0 = n1 = (node_t *)NULL; | |
15264 | + | |
15265 | + if (curnp->operator == OPEN_PAREN) { | |
15266 | + /* Get the value contained within the parenthesis. | |
15267 | + * If there was an error, just return. | |
15268 | + */ | |
15269 | + free_node(curnp); | |
15270 | + n0 = do_eval(flags); | |
15271 | + if (eval_error) { | |
15272 | + free_nodes(n0); | |
15273 | + free_nodes(root); | |
15274 | + return((node_t *)NULL); | |
15275 | + } | |
15276 | + | |
15277 | + } else if (curnp->operator == SIZEOF) { | |
15278 | + /* Free the SIZEOF node and then make a call | |
15279 | + * to the get_sizeof() function (which will | |
15280 | + * get the next node off the list). | |
15281 | + */ | |
15282 | + n0 = get_sizeof(); | |
15283 | + if (eval_error) { | |
15284 | + if (!error_token) { | |
15285 | + error_token = curnp->tok_ptr; | |
15286 | + } | |
15287 | + free_node(curnp); | |
15288 | + free_nodes(root); | |
15289 | + return((node_t *)NULL); | |
15290 | + } | |
15291 | + free_node(curnp); | |
15292 | + curnp = (node_t *)NULL; | |
15293 | + } else if (is_unary(curnp->operator)) { | |
15294 | + n0 = eval_unary(curnp, flags); | |
15295 | + } else { | |
15296 | + n0 = curnp; | |
15297 | + curnp = (node_t *)NULL; | |
15298 | + } | |
15299 | + if (eval_error) { | |
15300 | + free_nodes(n0); | |
15301 | + free_nodes(root); | |
15302 | + return((node_t *)NULL); | |
15303 | + } | |
15304 | + | |
15305 | + /* n0 should now contain a non-operator node. Check to see if | |
15306 | + * there is a next token. If there isn't, just add the last | |
15307 | + * rchild and return. | |
15308 | + */ | |
15309 | + if (!node_list) { | |
15310 | + if (root) { | |
15311 | + add_rchild(root, n0); | |
15312 | + } else { | |
15313 | + root = n0; | |
15314 | + } | |
15315 | + replace(root, flags); | |
15316 | + if (eval_error) { | |
15317 | + free_nodes(root); | |
15318 | + return((node_t *)NULL); | |
15319 | + } | |
15320 | + return(root); | |
15321 | + } | |
15322 | + | |
15323 | + /* Make sure the next token is an operator. | |
15324 | + */ | |
15325 | + if (!node_list->operator) { | |
15326 | + free_nodes(root); | |
15327 | + free_node(n0); | |
15328 | + set_eval_error(E_SYNTAX_ERROR); | |
15329 | + error_token = node_list->tok_ptr; | |
15330 | + return((node_t *)NULL); | |
15331 | + } else if ((node_list->operator == CLOSE_PAREN) || | |
15332 | + (node_list->operator == CLOSE_SQUARE_BRACKET)) { | |
15333 | + | |
15334 | + if (root) { | |
15335 | + add_rchild(root, n0); | |
15336 | + } else { | |
15337 | + root = n0; | |
15338 | + } | |
15339 | + | |
15340 | + /* Reduce the resulting tree to a single value | |
15341 | + */ | |
15342 | + replace(root, flags); | |
15343 | + if (eval_error) { | |
15344 | + free_nodes(root); | |
15345 | + return((node_t *)NULL); | |
15346 | + } | |
15347 | + | |
15348 | + /* Step over the CLOSE_PAREN or CLOSE_SQUARE_BRACKET | |
15349 | + * and then return. | |
15350 | + */ | |
15351 | + free_node(next_node()); | |
15352 | + return(root); | |
15353 | + } else if (node_list->operator == OPEN_SQUARE_BRACKET) { | |
15354 | +next_dimension1: | |
15355 | + /* skip over the OPEN_SQUARE_BRACKET token | |
15356 | + */ | |
15357 | + free_node(next_node()); | |
15358 | + | |
15359 | + /* Get the value contained within the brackets. This | |
15360 | + * value must represent an array index (value or | |
15361 | + * equation). | |
15362 | + */ | |
15363 | + n1 = do_eval(0); | |
15364 | + if (eval_error) { | |
15365 | + free_nodes(root); | |
15366 | + free_node(n0); | |
15367 | + free_node(n1); | |
15368 | + return((node_t *)NULL); | |
15369 | + } | |
15370 | + | |
15371 | + /* Convert the array (or pointer type) to an | |
15372 | + * element type using the index value obtained | |
15373 | + * above. Make sure that n0 contains some sort | |
15374 | + * of type definition first, however. | |
15375 | + */ | |
15376 | + if (n0->node_type != TYPE_DEF) { | |
15377 | + set_eval_error(E_BAD_TYPE); | |
15378 | + error_token = n0->tok_ptr; | |
15379 | + free_nodes(n0); | |
15380 | + free_nodes(n1); | |
15381 | + free_nodes(root); | |
15382 | + return((node_t *)NULL); | |
15383 | + } | |
15384 | + array_to_element(n0, n1); | |
15385 | + free_node(n1); | |
15386 | + if (eval_error) { | |
15387 | + free_nodes(root); | |
15388 | + free_nodes(n0); | |
15389 | + return((node_t *)NULL); | |
15390 | + } | |
15391 | + | |
15392 | + /* If there aren't any more nodes, just | |
15393 | + * return. | |
15394 | + */ | |
15395 | + if (!node_list) { | |
15396 | + return(n0); | |
15397 | + } | |
15398 | + if (node_list->operator == OPEN_SQUARE_BRACKET) { | |
15399 | + goto next_dimension1; | |
15400 | + } | |
15401 | + } else if (!is_binary(node_list->operator)) { | |
15402 | + set_eval_error(E_BAD_OPERATOR); | |
15403 | + error_token = node_list->tok_ptr; | |
15404 | + free_nodes(root); | |
15405 | + free_nodes(n0); | |
15406 | + return((node_t *)NULL); | |
15407 | + } | |
15408 | + | |
15409 | + /* Now get the operator node | |
15410 | + */ | |
15411 | + if (!(n1 = next_node())) { | |
15412 | + set_eval_error(E_SYNTAX_ERROR); | |
15413 | + error_token = n0->tok_ptr; | |
15414 | + free_nodes(n0); | |
15415 | + free_nodes(root); | |
15416 | + return((node_t *)NULL); | |
15417 | + } | |
15418 | + | |
15419 | + /* Check to see if this binary operator is RIGHT_ARROW or DOT. | |
15420 | + * If it is, we need to reduce it to a single value node now. | |
15421 | + */ | |
15422 | + while ((n1->operator == RIGHT_ARROW) || (n1->operator == DOT)) { | |
15423 | + | |
15424 | + /* The next node must contain the name of the | |
15425 | + * struct|union member. | |
15426 | + */ | |
15427 | + if (!node_list || (node_list->node_type != MEMBER)) { | |
15428 | + set_eval_error(E_BAD_MEMBER); | |
15429 | + error_token = n1->tok_ptr; | |
15430 | + free_nodes(n0); | |
15431 | + free_nodes(n1); | |
15432 | + free_nodes(root); | |
15433 | + return((node_t *)NULL); | |
15434 | + } | |
15435 | + n1->left = n0; | |
15436 | + | |
15437 | + /* Now get the next node and link it as the | |
15438 | + * right child. | |
15439 | + */ | |
15440 | + if (!(n0 = next_node())) { | |
15441 | + set_eval_error(E_SYNTAX_ERROR); | |
15442 | + error_token = n1->tok_ptr; | |
15443 | + free_nodes(n1); | |
15444 | + free_nodes(root); | |
15445 | + return((node_t *)NULL); | |
15446 | + } | |
15447 | + n1->right = n0; | |
15448 | + if (!(n0 = replace(n1, flags))) { | |
15449 | + if (!(eval_error)) { | |
15450 | + set_eval_error(E_SYNTAX_ERROR); | |
15451 | + error_token = n1->tok_ptr; | |
15452 | + } | |
15453 | + free_nodes(n1); | |
15454 | + free_nodes(root); | |
15455 | + return((node_t *)NULL); | |
15456 | + } | |
15457 | + n1 = (node_t *)NULL; | |
15458 | + | |
15459 | + /* Check to see if there is a next node. If there | |
15460 | + * is, check to see if it is the operator CLOSE_PAREN. | |
15461 | + * If it is, then return (skipping over the | |
15462 | + * CLOSE_PAREN first). | |
15463 | + */ | |
15464 | + if (node_list && ((node_list->operator == CLOSE_PAREN) | |
15465 | + || (node_list->operator == | |
15466 | + CLOSE_SQUARE_BRACKET))) { | |
15467 | + if (root) { | |
15468 | + add_rchild(root, n0); | |
15469 | + } else { | |
15470 | + root = n0; | |
15471 | + } | |
15472 | + | |
15473 | + /* Reduce the resulting tree to a single | |
15474 | + * value | |
15475 | + */ | |
15476 | + replace(root, flags); | |
15477 | + if (eval_error) { | |
15478 | + free_nodes(root); | |
15479 | + return((node_t *)NULL); | |
15480 | + } | |
15481 | + | |
15482 | + /* Advance the token pointer past the | |
15483 | + * CLOSE_PAREN and then return. | |
15484 | + */ | |
15485 | + free_node(next_node()); | |
15486 | + return(root); | |
15487 | + } | |
15488 | + | |
15489 | + /* Check to see if the next node is an | |
15490 | + * OPEN_SQUARE_BRACKET. If it is, then we have to | |
15491 | + * reduce the contents of the square brackets to | |
15492 | + * an index array. | |
15493 | + */ | |
15494 | + if (node_list && (node_list->operator | |
15495 | + == OPEN_SQUARE_BRACKET)) { | |
15496 | + | |
15497 | + /* Advance the token pointer and call | |
15498 | + * do_eval() again. | |
15499 | + */ | |
15500 | + free_node(next_node()); | |
15501 | +next_dimension2: | |
15502 | + n1 = do_eval(0); | |
15503 | + if (eval_error) { | |
15504 | + free_node(n0); | |
15505 | + free_node(n1); | |
15506 | + free_nodes(root); | |
15507 | + return((node_t *)NULL); | |
15508 | + } | |
15509 | + | |
15510 | + /* Convert the array (or pointer type) to | |
15511 | + * an element type using the index value | |
15512 | + * obtained above. Make sure that n0 | |
15513 | + * contains some sort of type definition | |
15514 | + * first, however. | |
15515 | + */ | |
15516 | + if (n0->node_type != TYPE_DEF) { | |
15517 | + set_eval_error(E_BAD_TYPE); | |
15518 | + error_token = n0->tok_ptr; | |
15519 | + free_node(n0); | |
15520 | + free_node(n1); | |
15521 | + free_node(root); | |
15522 | + return((node_t *)NULL); | |
15523 | + } | |
15524 | + array_to_element(n0, n1); | |
15525 | + free_node(n1); | |
15526 | + if (eval_error) { | |
15527 | + free_node(n0); | |
15528 | + free_node(root); | |
15529 | + return((node_t *)NULL); | |
15530 | + } | |
15531 | + } | |
15532 | + | |
15533 | + /* Now get the next operator node (if there is one). | |
15534 | + */ | |
15535 | + if (!node_list) { | |
15536 | + if (root) { | |
15537 | + add_rchild(root, n0); | |
15538 | + } else { | |
15539 | + root = n0; | |
15540 | + } | |
15541 | + return(root); | |
15542 | + } | |
15543 | + n1 = next_node(); | |
15544 | + if (n1->operator == OPEN_SQUARE_BRACKET) { | |
15545 | + goto next_dimension2; | |
15546 | + } | |
15547 | + } | |
15548 | + | |
15549 | + if (n1 && ((n1->operator == CLOSE_PAREN) || | |
15550 | + (n1->operator == CLOSE_SQUARE_BRACKET))) { | |
15551 | + free_node(n1); | |
15552 | + if (root) { | |
15553 | + add_rchild(root, n0); | |
15554 | + } else { | |
15555 | + root = n0; | |
15556 | + } | |
15557 | + replace(root, flags); | |
15558 | + if (eval_error) { | |
15559 | + free_nodes(root); | |
15560 | + return((node_t *)NULL); | |
15561 | + } | |
15562 | + return(root); | |
15563 | + } | |
15564 | + | |
15565 | + if (!root) { | |
15566 | + root = n1; | |
15567 | + n1->left = n0; | |
15568 | + } else if (precedence(root->operator) | |
15569 | + >= precedence(n1->operator)) { | |
15570 | + add_rchild(root, n0); | |
15571 | + n1->left = root; | |
15572 | + root = n1; | |
15573 | + } else { | |
15574 | + if (!root->right) { | |
15575 | + n1->left = n0; | |
15576 | + root->right = n1; | |
15577 | + } else { | |
15578 | + add_rchild(root, n0); | |
15579 | + n1->left = root->right; | |
15580 | + root->right = n1; | |
15581 | + } | |
15582 | + } | |
15583 | + curnp = next_node(); | |
15584 | + } /* while(curnp) */ | |
15585 | + return(root); | |
15586 | +} | |
15587 | + | |
15588 | +/* | |
15589 | + * is_unary() | |
15590 | + */ | |
15591 | +static int | |
15592 | +is_unary(int op) | |
15593 | +{ | |
15594 | + switch (op) { | |
15595 | + case LOGICAL_NEGATION : | |
15596 | + case ADDRESS : | |
15597 | + case INDIRECTION : | |
15598 | + case UNARY_MINUS : | |
15599 | + case UNARY_PLUS : | |
15600 | + case ONES_COMPLEMENT : | |
15601 | + case CAST : | |
15602 | + return(1); | |
15603 | + | |
15604 | + default : | |
15605 | + return(0); | |
15606 | + } | |
15607 | +} | |
15608 | + | |
15609 | + | |
15610 | +/* | |
15611 | + * is_binary() | |
15612 | + */ | |
15613 | +static int | |
15614 | +is_binary(int op) | |
15615 | +{ | |
15616 | + switch (op) { | |
15617 | + | |
15618 | + case BITWISE_OR : | |
15619 | + case BITWISE_EXCLUSIVE_OR : | |
15620 | + case BITWISE_AND : | |
15621 | + case RIGHT_SHIFT : | |
15622 | + case LEFT_SHIFT : | |
15623 | + case ADD : | |
15624 | + case SUBTRACT : | |
15625 | + case MULTIPLY : | |
15626 | + case DIVIDE : | |
15627 | + case MODULUS : | |
15628 | + case LOGICAL_OR : | |
15629 | + case LOGICAL_AND : | |
15630 | + case EQUAL : | |
15631 | + case NOT_EQUAL : | |
15632 | + case LESS_THAN : | |
15633 | + case GREATER_THAN : | |
15634 | + case LESS_THAN_OR_EQUAL : | |
15635 | + case GREATER_THAN_OR_EQUAL : | |
15636 | + case RIGHT_ARROW : | |
15637 | + case DOT : | |
15638 | + return(1); | |
15639 | + | |
15640 | + default : | |
15641 | + return(0); | |
15642 | + } | |
15643 | +} | |
15644 | + | |
15645 | +/* | |
15646 | + * precedence() | |
15647 | + */ | |
15648 | +static int | |
15649 | +precedence(int a) | |
15650 | +{ | |
15651 | + if ((a >= CONDITIONAL) && (a <= CONDITIONAL_ELSE)) { | |
15652 | + return(1); | |
15653 | + } else if (a == LOGICAL_OR) { | |
15654 | + return(2); | |
15655 | + } else if (a == LOGICAL_AND) { | |
15656 | + return(3); | |
15657 | + } else if (a == BITWISE_OR) { | |
15658 | + return(4); | |
15659 | + } else if (a == BITWISE_EXCLUSIVE_OR) { | |
15660 | + return(5); | |
15661 | + } else if (a == BITWISE_AND) { | |
15662 | + return(6); | |
15663 | + } else if ((a >= EQUAL) && (a <= NOT_EQUAL)) { | |
15664 | + return(7); | |
15665 | + } else if ((a >= LESS_THAN) && (a <= GREATER_THAN_OR_EQUAL)) { | |
15666 | + return(8); | |
15667 | + } else if ((a >= RIGHT_SHIFT) && (a <= LEFT_SHIFT)) { | |
15668 | + return(9); | |
15669 | + } else if ((a >= ADD) && (a <= SUBTRACT)) { | |
15670 | + return(10); | |
15671 | + } else if ((a >= MULTIPLY) && (a <= MODULUS)) { | |
15672 | + return(11); | |
15673 | + } else if ((a >= LOGICAL_NEGATION) && (a <= SIZEOF)) { | |
15674 | + return(12); | |
15675 | + } else if ((a >= RIGHT_ARROW) && (a <= DOT)) { | |
15676 | + return(13); | |
15677 | + } else { | |
15678 | + return(0); | |
15679 | + } | |
15680 | +} | |
15681 | + | |
15682 | +/* | |
15683 | + * esc_char() | |
15684 | + */ | |
15685 | +char | |
15686 | +esc_char(char *str) | |
15687 | +{ | |
15688 | + long int val; | |
15689 | + unsigned long uval; | |
15690 | + char ch; | |
15691 | + | |
15692 | + if (strlen(str) > 1) { | |
15693 | + uval = kl_strtoull(str, (char **)NULL, 8); | |
15694 | + val = uval; | |
15695 | + ch = (char)val; | |
15696 | + } else { | |
15697 | + ch = str[0]; | |
15698 | + } | |
15699 | + switch (ch) { | |
15700 | + case 'a' : | |
15701 | + return((char)7); | |
15702 | + case 'b' : | |
15703 | + return((char)8); | |
15704 | + case 't' : | |
15705 | + return((char)9); | |
15706 | + case 'n' : | |
15707 | + return((char)10); | |
15708 | + case 'f' : | |
15709 | + return((char)12); | |
15710 | + case 'r' : | |
15711 | + return((char)13); | |
15712 | + case 'e' : | |
15713 | + return((char)27); | |
15714 | + default: | |
15715 | + return(ch); | |
15716 | + } | |
15717 | +} | |
15718 | + | |
15719 | +/* | |
15720 | + * make_node() | |
15721 | + */ | |
15722 | +static node_t * | |
15723 | +make_node(token_t *t, int flags) | |
15724 | +{ | |
15725 | + node_t *np; | |
15726 | + | |
15727 | + set_eval_error(0); | |
15728 | + np = (node_t*)kl_alloc_block(sizeof(*np)); | |
15729 | + | |
15730 | + if (t->type == OPERATOR) { | |
15731 | + | |
15732 | + /* Check to see if this token represents a typecast | |
15733 | + */ | |
15734 | + if (t->operator == CAST) { | |
15735 | + type_t *tp; | |
15736 | + | |
15737 | + if (!(np->type = get_type(t->string, flags))) { | |
15738 | + set_eval_error(E_BAD_CAST); | |
15739 | + error_token = t->ptr; | |
15740 | + free_nodes(np); | |
15741 | + return((node_t*)NULL); | |
15742 | + } | |
15743 | + | |
15744 | + /* Determin if this is a pointer to a type | |
15745 | + */ | |
15746 | + tp = np->type; | |
15747 | + if (tp->flag == POINTER_FLAG) { | |
15748 | + np->flags = POINTER_FLAG; | |
15749 | + tp = tp->t_next; | |
15750 | + while (tp->flag == POINTER_FLAG) { | |
15751 | + tp = tp->t_next; | |
15752 | + } | |
15753 | + } | |
15754 | + switch(tp->flag) { | |
15755 | + case KLTYPE_FLAG: | |
15756 | + np->flags |= KLTYPE_FLAG; | |
15757 | + break; | |
15758 | + | |
15759 | + default: | |
15760 | + free_nodes(np); | |
15761 | + set_eval_error(E_BAD_CAST); | |
15762 | + error_token = t->ptr; | |
15763 | + return((node_t*)NULL); | |
15764 | + } | |
15765 | + if (!t->next) { | |
15766 | + if (flags & C_WHATIS) { | |
15767 | + np->node_type = TYPE_DEF; | |
15768 | + } else { | |
15769 | + set_eval_error(E_BAD_CAST); | |
15770 | + error_token = t->ptr; | |
15771 | + return((node_t*)NULL); | |
15772 | + } | |
15773 | + } else { | |
15774 | + np->node_type = OPERATOR; | |
15775 | + np->operator = CAST; | |
15776 | + } | |
15777 | + } else { | |
15778 | + np->node_type = OPERATOR; | |
15779 | + np->operator = t->operator; | |
15780 | + } | |
15781 | + } else if (t->type == MEMBER) { | |
15782 | + np->name = (char *)dup_block((void *)t->string, strlen(t->string)+1); | |
15783 | + np->node_type = MEMBER; | |
15784 | + } else if ((t->type == STRING) || (t->type == TYPE_DEF)) { | |
15785 | + syment_t *sp; | |
15786 | + dbg_sym_t *stp; | |
15787 | + dbg_type_t *sttp; | |
15788 | + | |
15789 | + if ((sp = kl_lkup_symname(t->string))) { | |
15790 | + if (!(flags & C_NOVARS)) { | |
15791 | + int has_type = 0; | |
15792 | + | |
15793 | + /* The string is a symbol name. We'll treat it as | |
15794 | + * a global kernel variable and, at least, gather in | |
15795 | + * the address of the symbol and the value it points | |
15796 | + * to. | |
15797 | + */ | |
15798 | + np->address = sp->s_addr; | |
15799 | + np->flags |= ADDRESS_FLAG; | |
15800 | + np->name = t->string; | |
15801 | + t->string = (char*)NULL; | |
15802 | + | |
15803 | + /* Need to see if there is type information available | |
15804 | + * for this variable. Since this mapping is not | |
15805 | + * available yet, we will just attach a type struct | |
15806 | + * for either uint32_t or uint64_t (depending on the | |
15807 | + * size of a kernel pointer). That will at least let | |
15808 | + * us do something and will prevent the scenario where | |
15809 | + * we have a type node with out a pointer to a type | |
15810 | + * struct! | |
15811 | + */ | |
15812 | + np->node_type = TYPE_DEF; | |
15813 | + np->flags |= KLTYPE_FLAG; | |
15814 | + np->value = *((kaddr_t *)np->address); | |
15815 | + /* try to get the actual type info for the variable */ | |
15816 | + if(((stp = dbg_find_sym(sp->s_name, DBG_VAR, | |
15817 | + (uint64_t)0)) != NULL)){ | |
15818 | + if((sttp = (dbg_type_t *) | |
15819 | + kl_find_typenum(stp->sym_typenum)) | |
15820 | + != NULL){ | |
15821 | + /* kl_get_typestring(sttp); */ | |
15822 | + has_type = 1; | |
15823 | + if(sttp->st_klt.kl_type == KLT_POINTER){ | |
15824 | + np->flags ^= KLTYPE_FLAG; | |
15825 | + np->flags |= POINTER_FLAG; | |
15826 | + np->type = | |
15827 | + get_type(sttp->st_typestr, | |
15828 | + flags); | |
15829 | + } else { | |
15830 | + np->type = | |
15831 | + kl_alloc_block(sizeof(type_t)); | |
15832 | + np->type->un.kltp = | |
15833 | + &sttp->st_klt; | |
15834 | + } | |
15835 | + } | |
15836 | + } | |
15837 | + /* no type info for the variable found */ | |
15838 | + if(!has_type){ | |
15839 | + if (ptrsz64) { | |
15840 | + np->type = get_type("uint64_t", flags); | |
15841 | + } else { | |
15842 | + np->type = get_type("uint32_t", flags); | |
15843 | + } | |
15844 | + } | |
15845 | + } | |
15846 | + kl_free_block((void *)sp); | |
15847 | + } else if (flags & (C_WHATIS|C_SIZEOF)) { | |
15848 | + | |
15849 | + kltype_t *kltp; | |
15850 | + | |
15851 | + if ((kltp = kl_find_type(t->string, KLT_TYPES))) { | |
15852 | + | |
15853 | + np->node_type = TYPE_DEF; | |
15854 | + np->flags = KLTYPE_FLAG; | |
15855 | + np->type = (type_t*) | |
15856 | + kl_alloc_block(sizeof(type_t)); | |
15857 | + np->type->flag = KLTYPE_FLAG; | |
15858 | + np->type->t_kltp = kltp; | |
15859 | + } else { | |
15860 | + if (get_value(t->string, | |
15861 | + (uint64_t *)&np->value)) { | |
15862 | + set_eval_error(E_BAD_VALUE); | |
15863 | + error_token = t->ptr; | |
15864 | + free_nodes(np); | |
15865 | + return((node_t*)NULL); | |
15866 | + } | |
15867 | + if (!strncmp(t->string, "0x", 2) || | |
15868 | + !strncmp(t->string, "0X", 2)) { | |
15869 | + np->flags |= UNSIGNED_FLAG; | |
15870 | + } | |
15871 | + np->node_type = NUMBER; | |
15872 | + } | |
15873 | + np->tok_ptr = t->ptr; | |
15874 | + return(np); | |
15875 | + } else { | |
15876 | + if (get_value(t->string, (uint64_t *)&np->value)) { | |
15877 | + set_eval_error(E_BAD_VALUE); | |
15878 | + error_token = t->ptr; | |
15879 | + free_nodes(np); | |
15880 | + return((node_t*)NULL); | |
15881 | + } | |
15882 | + if (np->value > 0xffffffff) { | |
15883 | + np->byte_size = 8; | |
15884 | + } else { | |
15885 | + np->byte_size = 4; | |
15886 | + } | |
15887 | + if (!strncmp(t->string, "0x", 2) || | |
15888 | + !strncmp(t->string, "0X", 2)) { | |
15889 | + np->flags |= UNSIGNED_FLAG; | |
15890 | + } | |
15891 | + np->node_type = NUMBER; | |
15892 | + } | |
15893 | + } else if (t->type == CHARACTER) { | |
15894 | + char *cp; | |
15895 | + | |
15896 | + /* Step over the single quote | |
15897 | + */ | |
15898 | + cp = (t->ptr + 1); | |
15899 | + if (*cp == '\\') { | |
15900 | + int i = 0; | |
15901 | + char str[16]; | |
15902 | + | |
15903 | + /* Step over the back slash | |
15904 | + */ | |
15905 | + cp++; | |
15906 | + while (*cp != '\'') { | |
15907 | + str[i++] = *cp++; | |
15908 | + } | |
15909 | + str[i] = 0; | |
15910 | + np->value = esc_char(str); | |
15911 | + } else { | |
15912 | + np->value = *cp; | |
15913 | + } | |
15914 | + np->type = get_type("char", flags); | |
15915 | + np->node_type = TYPE_DEF; | |
15916 | + np->flags |= KLTYPE_FLAG; | |
15917 | + } else if (t->type == TEXT) { | |
15918 | + np->node_type = TEXT; | |
15919 | + np->name = t->string; | |
15920 | + /* So the block doesn't get freed twice */ | |
15921 | + t->string = (char*)NULL; | |
15922 | + } else { | |
15923 | + set_eval_error(E_SYNTAX_ERROR); | |
15924 | + error_token = t->ptr; | |
15925 | + return((node_t*)NULL); | |
15926 | + } | |
15927 | + np->tok_ptr = t->ptr; | |
15928 | + return(np); | |
15929 | +} | |
15930 | + | |
15931 | +/* | |
15932 | + * add_node() | |
15933 | + */ | |
15934 | +static int | |
15935 | +add_node(node_t *root, node_t *new_node) | |
15936 | +{ | |
15937 | + node_t *n = root; | |
15938 | + | |
15939 | + /* Find the most lower-right node | |
15940 | + */ | |
15941 | + while (n->right) { | |
15942 | + n = n->right; | |
15943 | + } | |
15944 | + | |
15945 | + /* If the node we found is a leaf node, return an error (we will | |
15946 | + * have to insert the node instead). | |
15947 | + */ | |
15948 | + if (n->node_type == NUMBER) { | |
15949 | + return(-1); | |
15950 | + } else { | |
15951 | + n->right = new_node; | |
15952 | + } | |
15953 | + return(0); | |
15954 | +} | |
15955 | + | |
15956 | +/* | |
15957 | + * add_rchild() | |
15958 | + */ | |
15959 | +static int | |
15960 | +add_rchild(node_t *root, node_t *new_node) | |
15961 | +{ | |
15962 | + if (add_node(root, new_node) == -1) { | |
15963 | + return(-1); | |
15964 | + } | |
15965 | + return(0); | |
15966 | +} | |
15967 | + | |
15968 | +/* | |
15969 | + * free_type() | |
15970 | + */ | |
15971 | +static void | |
15972 | +free_type(type_t *head) | |
15973 | +{ | |
15974 | + type_t *t0, *t1; | |
15975 | + | |
15976 | + t0 = head; | |
15977 | + while(t0) { | |
15978 | + if (t0->flag == POINTER_FLAG) { | |
15979 | + t1 = t0->t_next; | |
15980 | + kl_free_block((void *)t0); | |
15981 | + t0 = t1; | |
15982 | + } else { | |
15983 | + if (t0->flag != KLTYPE_FLAG) { | |
15984 | + kl_free_block((void *)t0->t_kltp); | |
15985 | + } | |
15986 | + kl_free_block((void *)t0); | |
15987 | + t0 = (type_t *)NULL; | |
15988 | + } | |
15989 | + } | |
15990 | + return; | |
15991 | +} | |
15992 | + | |
15993 | +/* | |
15994 | + * get_type() -- Convert a typecast string into a type. | |
15995 | + * | |
15996 | + * Returns a pointer to a struct containing type information. | |
15997 | + * The type of struct returned is indicated by the contents | |
15998 | + * of type. If the typecast contains an asterisk, set ptr_type | |
15999 | + * equal to one, otherwise set it equal to zero. | |
16000 | + */ | |
16001 | +static type_t * | |
16002 | +get_type(char *s, int flags) | |
16003 | +{ | |
16004 | + int len, type = 0; | |
16005 | + char *cp, typename[128]; | |
16006 | + type_t *t, *head, *last; | |
16007 | + kltype_t *kltp; | |
16008 | + | |
16009 | + head = last = (type_t *)NULL; | |
16010 | + | |
16011 | + /* Get the type string | |
16012 | + */ | |
16013 | + if (!strncmp(s, "struct", 6)) { | |
16014 | + if ((cp = strpbrk(s + 7, " \t*"))) { | |
16015 | + len = cp - (s + 7); | |
16016 | + } else { | |
16017 | + len = strlen(s + 7); | |
16018 | + } | |
16019 | + memcpy(typename, s + 7, len); | |
16020 | + } else if (!strncmp(s, "union", 5)) { | |
16021 | + if ((cp = strpbrk(s + 6, " \t*"))) { | |
16022 | + len = cp - (s + 6); | |
16023 | + } else { | |
16024 | + len = strlen(s + 6); | |
16025 | + } | |
16026 | + memcpy(typename, s + 6, len); | |
16027 | + } else { | |
16028 | + if ((cp = strpbrk(s, "*)"))) { | |
16029 | + len = cp - s; | |
16030 | + } else { | |
16031 | + len = strlen(s); | |
16032 | + } | |
16033 | + memcpy(typename, s, len); | |
16034 | + } | |
16035 | + | |
16036 | + /* Strip off any trailing spaces | |
16037 | + */ | |
16038 | + while (len && ((typename[len - 1] == ' ') || | |
16039 | + (typename[len - 1] == '\t'))) { | |
16040 | + len--; | |
16041 | + } | |
16042 | + typename[len] = 0; | |
16043 | + | |
16044 | + if (!(kltp = kl_find_type(typename, KLT_TYPES))) { | |
16045 | + return ((type_t *)NULL); | |
16046 | + } | |
16047 | + type = KLTYPE_FLAG; | |
16048 | + | |
16049 | + /* check to see if this cast is a pointer to a type, a pointer | |
16050 | + * to a pointer to a type, etc. | |
16051 | + */ | |
16052 | + cp = s; | |
16053 | + while ((cp = strpbrk(cp, "*"))) { | |
16054 | + t = (type_t *)kl_alloc_block(sizeof(type_t)); | |
16055 | + t->flag = POINTER_FLAG; | |
16056 | + if (last) { | |
16057 | + last->t_next = t; | |
16058 | + last = t; | |
16059 | + } else { | |
16060 | + head = last = t; | |
16061 | + } | |
16062 | + cp++; | |
16063 | + } | |
16064 | + | |
16065 | + /* Allocate a type block that will point to the type specific | |
16066 | + * record. | |
16067 | + */ | |
16068 | + t = (type_t *)kl_alloc_block(sizeof(type_t)); | |
16069 | + t->flag = type; | |
16070 | + | |
16071 | + switch (t->flag) { | |
16072 | + | |
16073 | + case KLTYPE_FLAG: | |
16074 | + t->t_kltp = kltp; | |
16075 | + break; | |
16076 | + | |
16077 | + default: | |
16078 | + free_type(head); | |
16079 | + return((type_t*)NULL); | |
16080 | + } | |
16081 | + if (last) { | |
16082 | + last->t_next = t; | |
16083 | + } else { | |
16084 | + head = t; | |
16085 | + } | |
16086 | + return(head); | |
16087 | +} | |
16088 | + | |
16089 | +/* | |
16090 | + * free_node() | |
16091 | + */ | |
16092 | +static void | |
16093 | +free_node(node_t *np) | |
16094 | +{ | |
16095 | + /* If there is nothing to free, just return. | |
16096 | + */ | |
16097 | + if (!np) { | |
16098 | + return; | |
16099 | + } | |
16100 | + if (np->name) { | |
16101 | + kl_free_block((void *)np->name); | |
16102 | + } | |
16103 | + free_type(np->type); | |
16104 | + kl_free_block((void *)np); | |
16105 | +} | |
16106 | + | |
16107 | +/* | |
16108 | + * free_nodes() | |
16109 | + */ | |
16110 | +void | |
16111 | +free_nodes(node_t *np) | |
16112 | +{ | |
16113 | + node_t *q; | |
16114 | + | |
16115 | + /* If there is nothing to free, just return. | |
16116 | + */ | |
16117 | + if (!np) { | |
16118 | + return; | |
16119 | + } | |
16120 | + if ((q = np->left)) { | |
16121 | + free_nodes(q); | |
16122 | + } | |
16123 | + if ((q = np->right)) { | |
16124 | + free_nodes(q); | |
16125 | + } | |
16126 | + if (np->name) { | |
16127 | + kl_free_block((void *)np->name); | |
16128 | + } | |
16129 | + free_type(np->type); | |
16130 | + kl_free_block((void *)np); | |
16131 | +} | |
16132 | + | |
16133 | +/* | |
16134 | + * free_nodelist() | |
16135 | + */ | |
16136 | +static void | |
16137 | +free_nodelist(node_t *np) | |
16138 | +{ | |
16139 | + node_t *nnp; | |
16140 | + | |
16141 | + while(np) { | |
16142 | + nnp = np->next; | |
16143 | + free_node(np); | |
16144 | + np = nnp; | |
16145 | + } | |
16146 | +} | |
16147 | + | |
16148 | +extern int alloc_debug; | |
16149 | + | |
16150 | +/* | |
16151 | + * free_eval_memory() | |
16152 | + */ | |
16153 | +void | |
16154 | +free_eval_memory(void) | |
16155 | +{ | |
16156 | + free_nodelist(node_list); | |
16157 | + node_list = (node_t*)NULL; | |
16158 | +} | |
16159 | + | |
16160 | +/* | |
16161 | + * get_sizeof() | |
16162 | + */ | |
16163 | +static node_t * | |
16164 | +get_sizeof() | |
16165 | +{ | |
16166 | + node_t *curnp, *n0 = NULL; | |
16167 | + | |
16168 | + if (!(curnp = next_node())) { | |
16169 | + set_eval_error(E_SYNTAX_ERROR); | |
16170 | + return((node_t*)NULL); | |
16171 | + } | |
16172 | + | |
16173 | + /* The next token should be a CAST or an open paren. | |
16174 | + * If it's something else, then return an error. | |
16175 | + */ | |
16176 | + if (curnp->operator == OPEN_PAREN) { | |
16177 | + free_nodes(curnp); | |
16178 | + n0 = do_eval(C_SIZEOF); | |
16179 | + if (eval_error) { | |
16180 | + error_token = n0->tok_ptr; | |
16181 | + free_nodes(n0); | |
16182 | + return((node_t*)NULL); | |
16183 | + } | |
16184 | + } else if (curnp->operator == CAST) { | |
16185 | + n0 = curnp; | |
16186 | + } else { | |
16187 | + set_eval_error(E_BAD_TYPE); | |
16188 | + error_token = n0->tok_ptr; | |
16189 | + free_nodes(n0); | |
16190 | + return((node_t*)NULL); | |
16191 | + } | |
16192 | + | |
16193 | + if (!n0->type) { | |
16194 | + set_eval_error(E_NOTYPE); | |
16195 | + error_token = n0->tok_ptr; | |
16196 | + free_nodes(n0); | |
16197 | + return((node_t*)NULL); | |
16198 | + } | |
16199 | + | |
16200 | + if (n0->type->flag & POINTER_FLAG) { | |
16201 | + n0->value = sizeof(void *); | |
16202 | + } else if (n0->type->flag & KLTYPE_FLAG) { | |
16203 | + kltype_t *kltp; | |
16204 | + | |
16205 | + kltp = kl_realtype(n0->type->t_kltp, 0); | |
16206 | + | |
16207 | + if (kltp->kl_bit_size) { | |
16208 | + n0->value = kltp->kl_bit_size / 8; | |
16209 | + if (kltp->kl_bit_size % 8) { | |
16210 | + n0->value += 1; | |
16211 | + } | |
16212 | + } else { | |
16213 | + n0->value = kltp->kl_size; | |
16214 | + } | |
16215 | + } else { | |
16216 | + set_eval_error(E_BAD_TYPE); | |
16217 | + error_token = n0->tok_ptr; | |
16218 | + free_nodes(n0); | |
16219 | + return((node_t*)NULL); | |
16220 | + } | |
16221 | + n0->node_type = NUMBER; | |
16222 | + n0->flags = 0; | |
16223 | + n0->operator = 0; | |
16224 | + n0->byte_size = 0; | |
16225 | + n0->address = 0; | |
16226 | + if (n0->type) { | |
16227 | + free_type(n0->type); | |
16228 | + n0->type = 0; | |
16229 | + } | |
16230 | + return(n0); | |
16231 | +} | |
16232 | + | |
16233 | +/* | |
16234 | + * apply_unary() | |
16235 | + */ | |
16236 | +static int | |
16237 | +apply_unary(node_t *n, uint64_t *value) | |
16238 | +{ | |
16239 | + if (!n || !n->right) { | |
16240 | + return(-1); | |
16241 | + } | |
16242 | + | |
16243 | + switch (n->operator) { | |
16244 | + | |
16245 | + case UNARY_MINUS : | |
16246 | + *value = (0 - n->right->value); | |
16247 | + break; | |
16248 | + | |
16249 | + case UNARY_PLUS : | |
16250 | + *value = (n->right->value); | |
16251 | + break; | |
16252 | + | |
16253 | + case ONES_COMPLEMENT : | |
16254 | + *value = ~(n->right->value); | |
16255 | + break; | |
16256 | + | |
16257 | + case LOGICAL_NEGATION : | |
16258 | + if (n->right->value) { | |
16259 | + *value = 0; | |
16260 | + } else { | |
16261 | + *value = 1; | |
16262 | + } | |
16263 | + logical_flag++; | |
16264 | + break; | |
16265 | + | |
16266 | + default : | |
16267 | + break; | |
16268 | + } | |
16269 | + return(0); | |
16270 | +} | |
16271 | + | |
16272 | +/* | |
16273 | + * pointer_math() | |
16274 | + */ | |
16275 | +static int | |
16276 | +pointer_math(node_t *np, uint64_t *value, int type, int flags) | |
16277 | +{ | |
16278 | + int size; | |
16279 | + uint64_t lvalue, rvalue; | |
16280 | + type_t *tp = NULL, *tp1; | |
16281 | + | |
16282 | + if (type < 0) { | |
16283 | + if (np->left->flags & POINTER_FLAG) { | |
16284 | + | |
16285 | + /* Since we only allow pointer math, | |
16286 | + * anything other than a pointer causes | |
16287 | + * failure. | |
16288 | + */ | |
16289 | + tp = (type_t*)np->left->type; | |
16290 | + if (tp->flag != POINTER_FLAG) { | |
16291 | + set_eval_error(E_SYNTAX_ERROR); | |
16292 | + error_token = np->left->tok_ptr; | |
16293 | + return(-1); | |
16294 | + } | |
16295 | + | |
16296 | + tp = tp->t_next; | |
16297 | + | |
16298 | + switch (tp->flag) { | |
16299 | + | |
16300 | + case POINTER_FLAG : | |
16301 | + size = sizeof(void *); | |
16302 | + break; | |
16303 | + | |
16304 | + case KLTYPE_FLAG : { | |
16305 | + /* Get the size of the real type, | |
16306 | + * not just the size of a pointer | |
16307 | + * If there isn't any type info, | |
16308 | + * then just set size equal to the | |
16309 | + * size of a pointer. | |
16310 | + */ | |
16311 | + kltype_t *kltp, *rkltp; | |
16312 | + | |
16313 | + kltp = tp->t_kltp; | |
16314 | + rkltp = kl_realtype(kltp, 0); | |
16315 | + if (!(size = rkltp->kl_size)) { | |
16316 | + if (kltp != rkltp) { | |
16317 | + size = kltp->kl_size; | |
16318 | + } else { | |
16319 | + size = sizeof(void *); | |
16320 | + } | |
16321 | + } | |
16322 | + break; | |
16323 | + } | |
16324 | + | |
16325 | + default : | |
16326 | + set_eval_error(E_SYNTAX_ERROR); | |
16327 | + error_token = np->left->tok_ptr; | |
16328 | + return(-1); | |
16329 | + } | |
16330 | + lvalue = np->left->value; | |
16331 | + } else { | |
16332 | + size = sizeof(void *); | |
16333 | + lvalue = np->left->address; | |
16334 | + } | |
16335 | + switch (np->operator) { | |
16336 | + case ADD : | |
16337 | + *value = lvalue + (np->right->value * size); | |
16338 | + break; | |
16339 | + | |
16340 | + case SUBTRACT : | |
16341 | + *value = lvalue - (np->right->value * size); | |
16342 | + break; | |
16343 | + | |
16344 | + default : | |
16345 | + set_eval_error(E_BAD_OPERATOR); | |
16346 | + error_token = np->tok_ptr; | |
16347 | + return(-1); | |
16348 | + } | |
16349 | + } else if (type > 0) { | |
16350 | + if (np->right->flags & POINTER_FLAG) { | |
16351 | + | |
16352 | + /* Since we only allow pointer math, | |
16353 | + * anything other than a pointer causes | |
16354 | + * failure. | |
16355 | + */ | |
16356 | + tp = (type_t*)np->right->type; | |
16357 | + if (tp->flag != POINTER_FLAG) { | |
16358 | + set_eval_error(E_SYNTAX_ERROR); | |
16359 | + error_token = np->right->tok_ptr; | |
16360 | + return(-1); | |
16361 | + } | |
16362 | + | |
16363 | + tp = tp->t_next; | |
16364 | + | |
16365 | + switch (tp->flag) { | |
16366 | + | |
16367 | + case POINTER_FLAG : | |
16368 | + size = sizeof(void *); | |
16369 | + break; | |
16370 | + | |
16371 | + case KLTYPE_FLAG : | |
16372 | + size = tp->t_kltp->kl_size; | |
16373 | + break; | |
16374 | + | |
16375 | + default : | |
16376 | + set_eval_error(E_SYNTAX_ERROR); | |
16377 | + error_token = np->right->tok_ptr; | |
16378 | + return(-1); | |
16379 | + } | |
16380 | + rvalue = np->right->value; | |
16381 | + } else { | |
16382 | + size = sizeof(void *); | |
16383 | + rvalue = np->right->address; | |
16384 | + } | |
16385 | + switch (np->operator) { | |
16386 | + case ADD : | |
16387 | + *value = rvalue + (np->left->value * size); | |
16388 | + break; | |
16389 | + | |
16390 | + case SUBTRACT : | |
16391 | + *value = rvalue - (np->left->value * size); | |
16392 | + break; | |
16393 | + | |
16394 | + default : | |
16395 | + set_eval_error(E_BAD_OPERATOR); | |
16396 | + error_token = np->tok_ptr; | |
16397 | + return(-1); | |
16398 | + } | |
16399 | + } else { | |
16400 | + return(-1); | |
16401 | + } | |
16402 | + tp1 = (type_t *)kl_alloc_block(sizeof(type_t)); | |
16403 | + tp1->flag = POINTER_FLAG; | |
16404 | + np->type = tp1; | |
16405 | + while (tp->flag == POINTER_FLAG) { | |
16406 | + tp1->t_next = (type_t *)kl_alloc_block(sizeof(type_t)); | |
16407 | + tp1->flag = POINTER_FLAG; | |
16408 | + tp1 = tp1->t_next; | |
16409 | + tp = tp->t_next; | |
16410 | + } | |
16411 | + if (tp) { | |
16412 | + tp1->t_next = (type_t *)kl_alloc_block(sizeof(type_t)); | |
16413 | + tp1 = tp1->t_next; | |
16414 | + tp1->flag = KLTYPE_FLAG; | |
16415 | + tp1->t_kltp = tp->t_kltp; | |
16416 | + if (type < 0) { | |
16417 | + if (np->left->flags & POINTER_FLAG) { | |
16418 | + np->flags |= POINTER_FLAG; | |
16419 | + } else { | |
16420 | + np->flags |= VADDR; | |
16421 | + } | |
16422 | + } else { | |
16423 | + if (np->right->flags & POINTER_FLAG) { | |
16424 | + np->flags |= POINTER_FLAG; | |
16425 | + } else { | |
16426 | + np->flags |= VADDR; | |
16427 | + } | |
16428 | + } | |
16429 | + } | |
16430 | + return(0); | |
16431 | +} | |
16432 | + | |
16433 | +/* | |
16434 | + * check_unsigned() | |
16435 | + */ | |
16436 | +int | |
16437 | +check_unsigned(node_t *np) | |
16438 | +{ | |
16439 | + kltype_t *kltp, *rkltp; | |
16440 | + | |
16441 | + if (np->flags & UNSIGNED_FLAG) { | |
16442 | + return(1); | |
16443 | + } | |
16444 | + if (!np->type) { | |
16445 | + return(0); | |
16446 | + } | |
16447 | + if (np->type->flag == POINTER_FLAG) { | |
16448 | + return(0); | |
16449 | + } | |
16450 | + kltp = np->type->t_kltp; | |
16451 | + if ((rkltp = kl_realtype(kltp, 0))) { | |
16452 | + if (rkltp->kl_encoding == ENC_UNSIGNED) { | |
16453 | + np->flags |= UNSIGNED_FLAG; | |
16454 | + return(1); | |
16455 | + } | |
16456 | + } | |
16457 | + return(0); | |
16458 | +} | |
16459 | + | |
16460 | +/* | |
16461 | + * apply() | |
16462 | + */ | |
16463 | +static int | |
16464 | +apply(node_t *np, uint64_t *value, int flags) | |
16465 | +{ | |
16466 | + int ltype, rtype, do_signed = 0; | |
16467 | + | |
16468 | + /* There must be two operands | |
16469 | + */ | |
16470 | + if (!np->right || !np->left) { | |
16471 | + set_eval_error(E_MISSING_OPERAND); | |
16472 | + error_token = np->tok_ptr; | |
16473 | + return(-1); | |
16474 | + } | |
16475 | + | |
16476 | + if (np->right->node_type == OPERATOR) { | |
16477 | + replace(np->right, flags); | |
16478 | + if (eval_error) { | |
16479 | + return(-1); | |
16480 | + } | |
16481 | + } | |
16482 | + | |
16483 | + ltype = np->left->node_type; | |
16484 | + rtype = np->right->node_type; | |
16485 | + if ((ltype == TYPE_DEF) || (ltype == VADDR)) { | |
16486 | + if ((rtype == TYPE_DEF) || (rtype == VADDR)) { | |
16487 | + set_eval_error(E_NO_VALUE); | |
16488 | + error_token = np->tok_ptr; | |
16489 | + return(-1); | |
16490 | + } | |
16491 | + if (check_unsigned(np->left)) { | |
16492 | + np->flags |= UNSIGNED_FLAG; | |
16493 | + } else { | |
16494 | + do_signed++; | |
16495 | + } | |
16496 | + if (!type_to_number(np->left)) { | |
16497 | + return(pointer_math(np, value, -1, flags)); | |
16498 | + } | |
16499 | + np->byte_size = np->left->byte_size; | |
16500 | + } else if ((rtype == TYPE_DEF) || (rtype == VADDR)) { | |
16501 | + if ((ltype == TYPE_DEF) || (ltype == VADDR)) { | |
16502 | + error_token = np->tok_ptr; | |
16503 | + set_eval_error(E_NO_VALUE); | |
16504 | + return(-1); | |
16505 | + } | |
16506 | + if (check_unsigned(np->right)) { | |
16507 | + np->flags |= UNSIGNED_FLAG; | |
16508 | + } else { | |
16509 | + do_signed++; | |
16510 | + } | |
16511 | + if (!type_to_number(np->right)) { | |
16512 | + return(pointer_math(np, value, 1, flags)); | |
16513 | + } | |
16514 | + np->byte_size = np->right->byte_size; | |
16515 | + } else if ((np->left->flags & UNSIGNED_FLAG) || | |
16516 | + (np->right->flags & UNSIGNED_FLAG)) { | |
16517 | + np->flags |= UNSIGNED_FLAG; | |
16518 | + } else { | |
16519 | + do_signed++; | |
16520 | + } | |
16521 | + | |
16522 | + if (do_signed) { | |
16523 | + switch (np->operator) { | |
16524 | + case ADD : | |
16525 | + *value = (int64_t)np->left->value + | |
16526 | + (int64_t)np->right->value; | |
16527 | + break; | |
16528 | + | |
16529 | + case SUBTRACT : | |
16530 | + *value = (int64_t)np->left->value - | |
16531 | + (int64_t)np->right->value; | |
16532 | + break; | |
16533 | + | |
16534 | + case MULTIPLY : | |
16535 | + *value = (int64_t)np->left->value * | |
16536 | + (int64_t)np->right->value; | |
16537 | + break; | |
16538 | + | |
16539 | + case DIVIDE : | |
16540 | + if ((int64_t)np->right->value == 0) { | |
16541 | + set_eval_error(E_DIVIDE_BY_ZERO); | |
16542 | + error_token = np->right->tok_ptr; | |
16543 | + return(-1); | |
16544 | + } | |
16545 | + *value = (int64_t)np->left->value / | |
16546 | + (int64_t)np->right->value; | |
16547 | + break; | |
16548 | + | |
16549 | + case BITWISE_OR : | |
16550 | + *value = (int64_t)np->left->value | | |
16551 | + (int64_t)np->right->value; | |
16552 | + break; | |
16553 | + | |
16554 | + case BITWISE_AND : | |
16555 | + *value = (int64_t)np->left->value & | |
16556 | + (int64_t)np->right->value; | |
16557 | + break; | |
16558 | + | |
16559 | + case MODULUS : | |
16560 | + if ((int64_t)np->right->value == 0) { | |
16561 | + set_eval_error(E_DIVIDE_BY_ZERO); | |
16562 | + error_token = np->right->tok_ptr; | |
16563 | + return(-1); | |
16564 | + } | |
16565 | + *value = (int64_t)np->left->value % | |
16566 | + (int64_t)np->right->value; | |
16567 | + break; | |
16568 | + | |
16569 | + case RIGHT_SHIFT : | |
16570 | + *value = | |
16571 | + (int64_t)np->left->value >> | |
16572 | + (int64_t)np->right->value; | |
16573 | + break; | |
16574 | + | |
16575 | + case LEFT_SHIFT : | |
16576 | + *value = | |
16577 | + (int64_t)np->left->value << | |
16578 | + (int64_t)np->right->value; | |
16579 | + break; | |
16580 | + | |
16581 | + case LOGICAL_OR : | |
16582 | + if ((int64_t)np->left->value || | |
16583 | + (int64_t)np->right->value) { | |
16584 | + *value = 1; | |
16585 | + } else { | |
16586 | + *value = 0; | |
16587 | + } | |
16588 | + logical_flag++; | |
16589 | + break; | |
16590 | + | |
16591 | + case LOGICAL_AND : | |
16592 | + if ((int64_t)np->left->value && | |
16593 | + (int64_t)np->right->value) { | |
16594 | + *value = 1; | |
16595 | + } else { | |
16596 | + *value = 0; | |
16597 | + } | |
16598 | + logical_flag++; | |
16599 | + break; | |
16600 | + | |
16601 | + case EQUAL : | |
16602 | + if ((int64_t)np->left->value == | |
16603 | + (int64_t)np->right->value) { | |
16604 | + *value = 1; | |
16605 | + } else { | |
16606 | + *value = 0; | |
16607 | + } | |
16608 | + logical_flag++; | |
16609 | + break; | |
16610 | + | |
16611 | + case NOT_EQUAL : | |
16612 | + if ((int64_t)np->left->value != | |
16613 | + (int64_t)np->right->value) { | |
16614 | + *value = 1; | |
16615 | + } else { | |
16616 | + *value = 0; | |
16617 | + } | |
16618 | + logical_flag++; | |
16619 | + break; | |
16620 | + | |
16621 | + case LESS_THAN : | |
16622 | + if ((int64_t)np->left->value < | |
16623 | + (int64_t)np->right->value) { | |
16624 | + *value = 1; | |
16625 | + } else { | |
16626 | + *value = 0; | |
16627 | + } | |
16628 | + logical_flag++; | |
16629 | + break; | |
16630 | + | |
16631 | + case GREATER_THAN : | |
16632 | + if ((int64_t)np->left->value > | |
16633 | + (int64_t)np->right->value) { | |
16634 | + *value = 1; | |
16635 | + } else { | |
16636 | + *value = 0; | |
16637 | + } | |
16638 | + logical_flag++; | |
16639 | + break; | |
16640 | + | |
16641 | + case LESS_THAN_OR_EQUAL : | |
16642 | + if ((int64_t)np->left->value <= | |
16643 | + (int64_t)np->right->value) { | |
16644 | + *value = 1; | |
16645 | + } else { | |
16646 | + *value = 0; | |
16647 | + } | |
16648 | + logical_flag++; | |
16649 | + break; | |
16650 | + | |
16651 | + case GREATER_THAN_OR_EQUAL : | |
16652 | + if ((int64_t)np->left->value >= | |
16653 | + (int64_t)np->right->value) { | |
16654 | + *value = 1; | |
16655 | + } else { | |
16656 | + *value = 0; | |
16657 | + } | |
16658 | + logical_flag++; | |
16659 | + break; | |
16660 | + | |
16661 | + default : | |
16662 | + break; | |
16663 | + } | |
16664 | + } else { | |
16665 | + switch (np->operator) { | |
16666 | + case ADD : | |
16667 | + *value = np->left->value + np->right->value; | |
16668 | + break; | |
16669 | + | |
16670 | + case SUBTRACT : | |
16671 | + *value = np->left->value - np->right->value; | |
16672 | + break; | |
16673 | + | |
16674 | + case MULTIPLY : | |
16675 | + *value = np->left->value * np->right->value; | |
16676 | + break; | |
16677 | + | |
16678 | + case DIVIDE : | |
16679 | + *value = np->left->value / np->right->value; | |
16680 | + break; | |
16681 | + | |
16682 | + case BITWISE_OR : | |
16683 | + *value = np->left->value | np->right->value; | |
16684 | + break; | |
16685 | + | |
16686 | + case BITWISE_AND : | |
16687 | + *value = np->left->value & np->right->value; | |
16688 | + break; | |
16689 | + | |
16690 | + case MODULUS : | |
16691 | + *value = np->left->value % np->right->value; | |
16692 | + break; | |
16693 | + | |
16694 | + case RIGHT_SHIFT : | |
16695 | + *value = np->left->value >> np->right->value; | |
16696 | + break; | |
16697 | + | |
16698 | + case LEFT_SHIFT : | |
16699 | + *value = np->left->value << np->right->value; | |
16700 | + break; | |
16701 | + | |
16702 | + case LOGICAL_OR : | |
16703 | + if (np->left->value || np->right->value) { | |
16704 | + *value = 1; | |
16705 | + } else { | |
16706 | + *value = 0; | |
16707 | + } | |
16708 | + logical_flag++; | |
16709 | + break; | |
16710 | + | |
16711 | + case LOGICAL_AND : | |
16712 | + if (np->left->value && np->right->value) { | |
16713 | + *value = 1; | |
16714 | + } else { | |
16715 | + *value = 0; | |
16716 | + } | |
16717 | + logical_flag++; | |
16718 | + break; | |
16719 | + | |
16720 | + case EQUAL : | |
16721 | + if (np->left->value == np->right->value) { | |
16722 | + *value = 1; | |
16723 | + } else { | |
16724 | + *value = 0; | |
16725 | + } | |
16726 | + logical_flag++; | |
16727 | + break; | |
16728 | + | |
16729 | + case NOT_EQUAL : | |
16730 | + if (np->left->value != np->right->value) { | |
16731 | + *value = 1; | |
16732 | + } else { | |
16733 | + *value = 0; | |
16734 | + } | |
16735 | + logical_flag++; | |
16736 | + break; | |
16737 | + | |
16738 | + case LESS_THAN : | |
16739 | + if (np->left->value < np->right->value) { | |
16740 | + *value = 1; | |
16741 | + } else { | |
16742 | + *value = 0; | |
16743 | + } | |
16744 | + logical_flag++; | |
16745 | + break; | |
16746 | + | |
16747 | + case GREATER_THAN : | |
16748 | + if (np->left->value > np->right->value) { | |
16749 | + *value = 1; | |
16750 | + } else { | |
16751 | + *value = 0; | |
16752 | + } | |
16753 | + logical_flag++; | |
16754 | + break; | |
16755 | + | |
16756 | + case LESS_THAN_OR_EQUAL : | |
16757 | + if (np->left->value <= np->right->value) { | |
16758 | + *value = 1; | |
16759 | + } else { | |
16760 | + *value = 0; | |
16761 | + } | |
16762 | + logical_flag++; | |
16763 | + break; | |
16764 | + | |
16765 | + case GREATER_THAN_OR_EQUAL : | |
16766 | + if (np->left->value >= np->right->value) { | |
16767 | + *value = 1; | |
16768 | + } else { | |
16769 | + *value = 0; | |
16770 | + } | |
16771 | + logical_flag++; | |
16772 | + break; | |
16773 | + | |
16774 | + default : | |
16775 | + break; | |
16776 | + } | |
16777 | + } | |
16778 | + return(0); | |
16779 | +} | |
16780 | + | |
16781 | +/* | |
16782 | + * member_to_type() | |
16783 | + */ | |
16784 | +static type_t * | |
16785 | +member_to_type(kltype_t *kltp, int flags) | |
16786 | +{ | |
16787 | + kltype_t *rkltp; | |
16788 | + type_t *tp, *head = (type_t *)NULL, *last = (type_t *)NULL; | |
16789 | + | |
16790 | + /* Make sure this is a member | |
16791 | + */ | |
16792 | + if (kltp->kl_type != KLT_MEMBER) { | |
16793 | + return((type_t *)NULL); | |
16794 | + } | |
16795 | + | |
16796 | + rkltp = kltp->kl_realtype; | |
16797 | + while (rkltp && rkltp->kl_type == KLT_POINTER) { | |
16798 | + tp = (type_t *)kl_alloc_block(sizeof(type_t)); | |
16799 | + tp->flag = POINTER_FLAG; | |
16800 | + if (last) { | |
16801 | + last->t_next = tp; | |
16802 | + last = tp; | |
16803 | + } else { | |
16804 | + head = last = tp; | |
16805 | + } | |
16806 | + rkltp = rkltp->kl_realtype; | |
16807 | + } | |
16808 | + | |
16809 | + /* If We step past all the pointer records and don't point | |
16810 | + * at anything, this must be a void pointer. Setup a VOID | |
16811 | + * type struct so that we can maintain a pointer to some | |
16812 | + * type info. | |
16813 | + */ | |
16814 | + if (!rkltp) { | |
16815 | + tp = (type_t *)kl_alloc_block(sizeof(type_t)); | |
16816 | + tp->flag = VOID_FLAG; | |
16817 | + tp->t_kltp = kltp; | |
16818 | + if (last) { | |
16819 | + last->t_next = tp; | |
16820 | + last = tp; | |
16821 | + } else { | |
16822 | + head = last = tp; | |
16823 | + } | |
16824 | + return(head); | |
16825 | + } | |
16826 | + | |
16827 | + tp = (type_t *)kl_alloc_block(sizeof(type_t)); | |
16828 | + tp->flag = KLTYPE_FLAG; | |
16829 | + tp->t_kltp = kltp; | |
16830 | + if (last) { | |
16831 | + last->t_next = tp; | |
16832 | + } else { | |
16833 | + head = tp; | |
16834 | + } | |
16835 | + return(head); | |
16836 | +} | |
16837 | + | |
16838 | +/* | |
16839 | + * replace() -- | |
16840 | + * | |
16841 | + * Replace the tree with a node containing the numerical result of | |
16842 | + * the equation. If pointer math is performed, the result will have | |
16843 | + * the same type as the pointer. | |
16844 | + */ | |
16845 | +static node_t * | |
16846 | +replace(node_t *np, int flags) | |
16847 | +{ | |
16848 | + int offset; | |
16849 | + uint64_t value; | |
16850 | + node_t *q; | |
16851 | + | |
16852 | + if (!np) { | |
16853 | + return((node_t *)NULL); | |
16854 | + } | |
16855 | + | |
16856 | + if (np->node_type == OPERATOR) { | |
16857 | + if (!(q = np->left)) { | |
16858 | + return((node_t *)NULL); | |
16859 | + } | |
16860 | + while (q) { | |
16861 | + if (!replace(q, flags)) { | |
16862 | + return((node_t *)NULL); | |
16863 | + } | |
16864 | + q = q->right; | |
16865 | + } | |
16866 | + | |
16867 | + if ((np->operator == RIGHT_ARROW) || (np->operator == DOT)) { | |
16868 | + kaddr_t addr = 0; | |
16869 | + type_t *tp; | |
16870 | + | |
16871 | + if (!have_debug_file) { | |
16872 | + kdb_printf("no debuginfo file\n"); | |
16873 | + return 0; | |
16874 | + } | |
16875 | + | |
16876 | + /* The left node must point to a TYPE_DEF | |
16877 | + */ | |
16878 | + if (np->left->node_type != TYPE_DEF) { | |
16879 | + if (np->left->flags & NOTYPE_FLAG) { | |
16880 | + set_eval_error(E_NOTYPE); | |
16881 | + error_token = np->left->tok_ptr; | |
16882 | + } else { | |
16883 | + set_eval_error(E_BAD_TYPE); | |
16884 | + error_token = np->left->tok_ptr; | |
16885 | + } | |
16886 | + return((node_t *)NULL); | |
16887 | + } | |
16888 | + | |
16889 | + /* Get the type information. Check to see if we | |
16890 | + * have a pointer to a type. If we do, we need | |
16891 | + * to strip off the pointer and get the type info. | |
16892 | + */ | |
16893 | + if (np->left->type->flag == POINTER_FLAG) { | |
16894 | + tp = np->left->type->t_next; | |
16895 | + kl_free_block((void *)np->left->type); | |
16896 | + } else { | |
16897 | + tp = np->left->type; | |
16898 | + } | |
16899 | + | |
16900 | + /* We need to zero out the left child's type pointer | |
16901 | + * to prevent the type structs from being prematurely | |
16902 | + * freed (upon success). We have to remember, however, | |
16903 | + * to the free the type information before we return. | |
16904 | + */ | |
16905 | + np->left->type = (type_t*)NULL; | |
16906 | + | |
16907 | + /* tp should now point at a type_t struct that | |
16908 | + * references a kltype_t struct. If it points | |
16909 | + * to anything else, return failure. | |
16910 | + * | |
16911 | + */ | |
16912 | + if (tp->flag != KLTYPE_FLAG) { | |
16913 | + set_eval_error(E_BAD_TYPE); | |
16914 | + error_token = np->left->tok_ptr; | |
16915 | + free_type(tp); | |
16916 | + return((node_t *)NULL); | |
16917 | + } | |
16918 | + | |
16919 | + switch (tp->flag) { | |
16920 | + case KLTYPE_FLAG: { | |
16921 | + /* Make sure that the type referenced | |
16922 | + * is a struct, union, or pointer to | |
16923 | + * a struct or union. If it isn't one | |
16924 | + * of these, then return failure. | |
16925 | + */ | |
16926 | + kltype_t *kltp, *kltmp; | |
16927 | + | |
16928 | + kltp = kl_realtype(tp->t_kltp, 0); | |
16929 | + if ((kltp->kl_type != KLT_STRUCT) && | |
16930 | + (kltp->kl_type != KLT_UNION)) { | |
16931 | + error_token = | |
16932 | + np->left->tok_ptr; | |
16933 | + set_eval_error(E_BAD_TYPE); | |
16934 | + free_type(tp); | |
16935 | + return((node_t *)NULL); | |
16936 | + } | |
16937 | + | |
16938 | + /* Get type information for member. | |
16939 | + * If member is a pointer to a type, | |
16940 | + * get the pointer address and load | |
16941 | + * it into value. In any event, load | |
16942 | + * the struct/union address plus the | |
16943 | + * offset of the member. | |
16944 | + */ | |
16945 | + kltmp = kl_get_member(kltp, | |
16946 | + np->right->name); | |
16947 | + if (!kltmp) { | |
16948 | + set_eval_error(E_BAD_MEMBER); | |
16949 | + error_token = | |
16950 | + np->right->tok_ptr; | |
16951 | + free_type(tp); | |
16952 | + return((node_t *)NULL); | |
16953 | + } | |
16954 | + | |
16955 | + /* We can't just use the offset value | |
16956 | + * for the member. That's because it | |
16957 | + * may be from an anonymous struct or | |
16958 | + * union within another struct | |
16959 | + * definition. | |
16960 | + */ | |
16961 | + offset = kl_get_member_offset(kltp, | |
16962 | + np->right->name); | |
16963 | + np->type = member_to_type(kltmp, flags); | |
16964 | + if (!np->type) { | |
16965 | + set_eval_error(E_BAD_MEMBER); | |
16966 | + error_token = | |
16967 | + np->right->tok_ptr; | |
16968 | + free_type(tp); | |
16969 | + return((node_t *)NULL); | |
16970 | + } | |
16971 | + | |
16972 | + /* Now free the struct type information | |
16973 | + */ | |
16974 | + free_type(tp); | |
16975 | + np->node_type = TYPE_DEF; | |
16976 | + np->flags |= KLTYPE_FLAG; | |
16977 | + np->operator = 0; | |
16978 | + addr = 0; | |
16979 | + if (np->left->flags & POINTER_FLAG) { | |
16980 | + addr = np->left->value + | |
16981 | + offset; | |
16982 | + } else if (np->left->flags & | |
16983 | + ADDRESS_FLAG) { | |
16984 | + addr = np->left->address + | |
16985 | + offset; | |
16986 | + } | |
16987 | + if (addr) { | |
16988 | + np->address = addr; | |
16989 | + np->flags |= ADDRESS_FLAG; | |
16990 | + } | |
16991 | + | |
16992 | + if (np->type->flag == POINTER_FLAG) { | |
16993 | + np->flags |= POINTER_FLAG; | |
16994 | + np->value = *((kaddr_t *)addr); | |
16995 | + } else { | |
16996 | + np->value = addr; | |
16997 | + } | |
16998 | + break; | |
16999 | + } | |
17000 | + } | |
17001 | + free_nodes(np->left); | |
17002 | + free_nodes(np->right); | |
17003 | + np->left = np->right = (node_t*)NULL; | |
17004 | + return(np); | |
17005 | + } else { | |
17006 | + if (!np->left || !np->right) { | |
17007 | + set_eval_error(E_MISSING_OPERAND); | |
17008 | + error_token = np->tok_ptr; | |
17009 | + return((node_t *)NULL); | |
17010 | + } | |
17011 | + if (np->left->byte_size && np->right->byte_size) { | |
17012 | + if (np->left->byte_size > | |
17013 | + np->right->byte_size) { | |
17014 | + | |
17015 | + /* Left byte_size is greater than right | |
17016 | + */ | |
17017 | + np->byte_size = np->left->byte_size; | |
17018 | + np->type = np->left->type; | |
17019 | + np->flags = np->left->flags; | |
17020 | + free_type(np->right->type); | |
17021 | + } else if (np->left->byte_size < | |
17022 | + np->right->byte_size) { | |
17023 | + | |
17024 | + /* Right byte_size is greater than left | |
17025 | + */ | |
17026 | + np->byte_size = np->right->byte_size; | |
17027 | + np->type = np->right->type; | |
17028 | + np->flags = np->right->flags; | |
17029 | + free_type(np->left->type); | |
17030 | + } else { | |
17031 | + | |
17032 | + /* Left and right byte_size is equal | |
17033 | + */ | |
17034 | + if (np->left->flags & UNSIGNED_FLAG) { | |
17035 | + np->byte_size = | |
17036 | + np->left->byte_size; | |
17037 | + np->type = np->left->type; | |
17038 | + np->flags = np->left->flags; | |
17039 | + free_type(np->right->type); | |
17040 | + } else if (np->right->flags & | |
17041 | + UNSIGNED_FLAG) { | |
17042 | + np->byte_size = | |
17043 | + np->right->byte_size; | |
17044 | + np->type = np->right->type; | |
17045 | + np->flags = np->right->flags; | |
17046 | + free_type(np->left->type); | |
17047 | + } else { | |
17048 | + np->byte_size = | |
17049 | + np->left->byte_size; | |
17050 | + np->type = np->left->type; | |
17051 | + np->flags = np->left->flags; | |
17052 | + free_type(np->right->type); | |
17053 | + } | |
17054 | + } | |
17055 | + } else if (np->left->byte_size) { | |
17056 | + np->byte_size = np->left->byte_size; | |
17057 | + np->type = np->left->type; | |
17058 | + np->flags = np->left->flags; | |
17059 | + free_type(np->right->type); | |
17060 | + } else if (np->right->byte_size) { | |
17061 | + np->byte_size = np->right->byte_size; | |
17062 | + np->type = np->right->type; | |
17063 | + np->flags = np->right->flags; | |
17064 | + } else { | |
17065 | + /* XXX - No byte sizes | |
17066 | + */ | |
17067 | + } | |
17068 | + | |
17069 | + if (apply(np, &value, flags)) { | |
17070 | + return((node_t *)NULL); | |
17071 | + } | |
17072 | + } | |
17073 | + np->right->type = np->left->type = (type_t*)NULL; | |
17074 | + | |
17075 | + /* Flesh out the rest of the node struct. | |
17076 | + */ | |
17077 | + if (np->type) { | |
17078 | + np->node_type = TYPE_DEF; | |
17079 | + np->flags |= KLTYPE_FLAG; | |
17080 | + } else { | |
17081 | + np->node_type = NUMBER; | |
17082 | + np->flags &= ~(KLTYPE_FLAG); | |
17083 | + } | |
17084 | + np->operator = 0; | |
17085 | + np->value = value; | |
17086 | + kl_free_block((void *)np->left); | |
17087 | + kl_free_block((void *)np->right); | |
17088 | + np->left = np->right = (node_t*)NULL; | |
17089 | + } | |
17090 | + return(np); | |
17091 | +} | |
17092 | + | |
17093 | +/* | |
17094 | + * replace_cast() | |
17095 | + */ | |
17096 | +static int | |
17097 | +replace_cast(node_t *n, int flags) | |
17098 | +{ | |
17099 | + type_t *t; | |
17100 | + | |
17101 | + if (!n) { | |
17102 | + set_eval_error(E_SYNTAX_ERROR); | |
17103 | + return(-1); | |
17104 | + } else if (!n->right) { | |
17105 | + set_eval_error(E_SYNTAX_ERROR); | |
17106 | + error_token = n->tok_ptr; | |
17107 | + return(-1); | |
17108 | + } | |
17109 | + if (n->flags & POINTER_FLAG) { | |
17110 | + if (n->right->node_type == VADDR) { | |
17111 | + if (n->right->flags & ADDRESS_FLAG) { | |
17112 | + n->value = n->right->address; | |
17113 | + } else { | |
17114 | + set_eval_error(E_SYNTAX_ERROR); | |
17115 | + error_token = n->right->tok_ptr; | |
17116 | + return(-1); | |
17117 | + } | |
17118 | + | |
17119 | + } else { | |
17120 | + n->value = n->right->value; | |
17121 | + n->address = 0; | |
17122 | + } | |
17123 | + } else if (n->right->flags & ADDRESS_FLAG) { | |
17124 | + n->flags |= ADDRESS_FLAG; | |
17125 | + n->address = n->right->address; | |
17126 | + n->value = n->right->value; | |
17127 | + } else { | |
17128 | + kltype_t *kltp; | |
17129 | + | |
17130 | + if (!(t = eval_type(n))) { | |
17131 | + set_eval_error(E_BAD_TYPE); | |
17132 | + error_token = n->tok_ptr; | |
17133 | + return(-1); | |
17134 | + } | |
17135 | + if (t->t_kltp->kl_type != KLT_BASE) { | |
17136 | + | |
17137 | + kltp = kl_realtype(t->t_kltp, 0); | |
17138 | + if (kltp->kl_type != KLT_BASE) { | |
17139 | + set_eval_error(E_BAD_CAST); | |
17140 | + error_token = n->tok_ptr; | |
17141 | + return(-1); | |
17142 | + } | |
17143 | + } | |
17144 | + n->value = n->right->value; | |
17145 | + n->type = t; | |
17146 | + } | |
17147 | + n->node_type = TYPE_DEF; | |
17148 | + n->operator = 0; | |
17149 | + free_node(n->right); | |
17150 | + n->right = (node_t *)NULL; | |
17151 | + return(0); | |
17152 | +} | |
17153 | + | |
17154 | +/* | |
17155 | + * replace_indirection() | |
17156 | + */ | |
17157 | +static int | |
17158 | +replace_indirection(node_t *n, int flags) | |
17159 | +{ | |
17160 | + kaddr_t addr; | |
17161 | + type_t *t, *tp, *rtp; | |
17162 | + | |
17163 | + /* Make sure there is a right child and that it is a TYPE_DEF. | |
17164 | + */ | |
17165 | + if (!n->right) { | |
17166 | + set_eval_error(E_BAD_TYPE); | |
17167 | + error_token = n->tok_ptr; | |
17168 | + return(-1); | |
17169 | + } else if (n->right->node_type != TYPE_DEF) { | |
17170 | + set_eval_error(E_BAD_TYPE); | |
17171 | + error_token = n->right->tok_ptr; | |
17172 | + return(-1); | |
17173 | + } | |
17174 | + | |
17175 | + /* Make sure the right node contains a pointer or address value. | |
17176 | + * Note that it's possible for the whatis command to generate | |
17177 | + * this case without any actual pointer/address value. | |
17178 | + */ | |
17179 | + if (!(n->right->flags & (POINTER_FLAG|ADDRESS_FLAG))) { | |
17180 | + set_eval_error(E_BAD_POINTER); | |
17181 | + error_token = n->right->tok_ptr; | |
17182 | + return(-1); | |
17183 | + } | |
17184 | + | |
17185 | + /* Get the pointer to the first type struct and make sure | |
17186 | + * it's a pointer. | |
17187 | + */ | |
17188 | + if (!(tp = n->right->type) || (tp->flag != POINTER_FLAG)) { | |
17189 | + set_eval_error(E_BAD_TYPE); | |
17190 | + error_token = n->right->tok_ptr; | |
17191 | + return(-1); | |
17192 | + } | |
17193 | + | |
17194 | + /* Make sure we have a pointer to a type structure. | |
17195 | + */ | |
17196 | + if (!(n->right->flags & KLTYPE_FLAG)) { | |
17197 | + set_eval_error(E_BAD_TYPE); | |
17198 | + error_token = n->right->tok_ptr; | |
17199 | + return(-1); | |
17200 | + } | |
17201 | + | |
17202 | + n->node_type = TYPE_DEF; | |
17203 | + n->flags = KLTYPE_FLAG; | |
17204 | + n->operator = 0; | |
17205 | + | |
17206 | + if (!(t = tp->t_next)) { | |
17207 | + set_eval_error(E_BAD_TYPE); | |
17208 | + error_token = n->right->tok_ptr; | |
17209 | + return(-1); | |
17210 | + } | |
17211 | + | |
17212 | + if (!(rtp = eval_type(n->right))) { | |
17213 | + set_eval_error(E_BAD_TYPE); | |
17214 | + error_token = n->right->tok_ptr; | |
17215 | + return(-1); | |
17216 | + } | |
17217 | + | |
17218 | + /* Zero out the type field in the right child so | |
17219 | + * it wont accidently be freed when the right child | |
17220 | + * is freed (upon success). | |
17221 | + */ | |
17222 | + n->right->type = (type_t*)NULL; | |
17223 | + | |
17224 | + n->type = t; | |
17225 | + | |
17226 | + /* Free the pointer struct | |
17227 | + */ | |
17228 | + kl_free_block((void *)tp); | |
17229 | + | |
17230 | + /* Get the pointer address | |
17231 | + */ | |
17232 | + addr = n->address = n->right->value; | |
17233 | + n->flags |= ADDRESS_FLAG; | |
17234 | + | |
17235 | + if (rtp->t_kltp->kl_type == KLT_MEMBER) { | |
17236 | + /* If this is a member, we have to step over the KLT_MEMBER | |
17237 | + * struct and then make sure we have a KLT_POINTER struct. | |
17238 | + * If we do, we step over it too...otherwise return an | |
17239 | + * error. | |
17240 | + */ | |
17241 | + if (rtp->t_kltp->kl_realtype->kl_type != KLT_POINTER) { | |
17242 | + set_eval_error(E_BAD_TYPE); | |
17243 | + error_token = n->right->tok_ptr; | |
17244 | + return(-1); | |
17245 | + } | |
17246 | + rtp->t_kltp = rtp->t_kltp->kl_realtype; | |
17247 | + } | |
17248 | + | |
17249 | + if (rtp->t_kltp->kl_type == KLT_POINTER) { | |
17250 | + /* Strip off the pointer type record so that | |
17251 | + * we pick up the actual type definition with | |
17252 | + * our indirection. | |
17253 | + */ | |
17254 | + rtp->t_kltp = rtp->t_kltp->kl_realtype; | |
17255 | + if (rtp->t_kltp->kl_name && | |
17256 | + !strcmp(rtp->t_kltp->kl_name, "char")) { | |
17257 | + n->flags |= STRING_FLAG; | |
17258 | + } | |
17259 | + } | |
17260 | + | |
17261 | + | |
17262 | + /* If this is a pointer to a pointer, get the next | |
17263 | + * pointer value. | |
17264 | + */ | |
17265 | + if (n->type->flag == POINTER_FLAG) { | |
17266 | + n->value = *((kaddr_t *)addr); | |
17267 | + | |
17268 | + /* Set the appropriate node flag values | |
17269 | + */ | |
17270 | + n->flags |= POINTER_FLAG; | |
17271 | + free_node(n->right); | |
17272 | + n->left = n->right = (node_t *)NULL; | |
17273 | + return(0); | |
17274 | + } | |
17275 | + /* Zero out the type field in the right child so it doesn't | |
17276 | + * accidently get freed up when the right child is freed | |
17277 | + * (upon success). | |
17278 | + */ | |
17279 | + n->right->type = (type_t*)NULL; | |
17280 | + free_node(n->right); | |
17281 | + n->left = n->right = (node_t *)NULL; | |
17282 | + return(0); | |
17283 | +} | |
17284 | + | |
17285 | +/* | |
17286 | + * replace_unary() | |
17287 | + * | |
17288 | + * Convert a unary operator node that contains a pointer to a value | |
17289 | + * with a node containing the numerical result. Free the node that | |
17290 | + * originally contained the value. | |
17291 | + */ | |
17292 | +static int | |
17293 | +replace_unary(node_t *n, int flags) | |
17294 | +{ | |
17295 | + uint64_t value; | |
17296 | + | |
17297 | + if (!n->right) { | |
17298 | + set_eval_error(E_MISSING_OPERAND); | |
17299 | + error_token = n->tok_ptr; | |
17300 | + return(-1); | |
17301 | + } | |
17302 | + if (is_unary(n->right->operator)) { | |
17303 | + if (replace_unary(n->right, flags) == -1) { | |
17304 | + return(-1); | |
17305 | + } | |
17306 | + } | |
17307 | + if (n->operator == CAST) { | |
17308 | + return(replace_cast(n, flags)); | |
17309 | + } else if (n->operator == INDIRECTION) { | |
17310 | + return(replace_indirection(n, flags)); | |
17311 | + } else if (n->operator == ADDRESS) { | |
17312 | + type_t *t; | |
17313 | + | |
17314 | + if (n->right->node_type == TYPE_DEF) { | |
17315 | + if (!(n->right->flags & ADDRESS_FLAG)) { | |
17316 | + set_eval_error(E_NO_ADDRESS); | |
17317 | + error_token = n->right->tok_ptr; | |
17318 | + return(-1); | |
17319 | + } | |
17320 | + t = n->right->type; | |
17321 | + } else { | |
17322 | + set_eval_error(E_BAD_TYPE); | |
17323 | + error_token = n->right->tok_ptr; | |
17324 | + return(-1); | |
17325 | + } | |
17326 | + n->type = (type_t*)kl_alloc_block(sizeof(type_t)); | |
17327 | + n->type->flag = POINTER_FLAG; | |
17328 | + n->type->t_next = t; | |
17329 | + n->node_type = TYPE_DEF; | |
17330 | + n->operator = 0; | |
17331 | + n->value = n->right->address; | |
17332 | + n->flags = POINTER_FLAG; | |
17333 | + if (!(t = eval_type(n))) { | |
17334 | + set_eval_error(E_BAD_TYPE); | |
17335 | + error_token = n->tok_ptr; | |
17336 | + return(-1); | |
17337 | + } | |
17338 | + n->flags |= t->flag; | |
17339 | + n->right->type = 0; | |
17340 | + free_nodes(n->right); | |
17341 | + n->left = n->right = (node_t *)NULL; | |
17342 | + return(0); | |
17343 | + } else if (apply_unary(n, &value) == -1) { | |
17344 | + return(-1); | |
17345 | + } | |
17346 | + free_nodes(n->right); | |
17347 | + n->node_type = NUMBER; | |
17348 | + n->operator = 0; | |
17349 | + n->left = n->right = (node_t *)NULL; | |
17350 | + memcpy(&n->value, &value, sizeof(uint64_t)); | |
17351 | + return(0); | |
17352 | +} | |
17353 | + | |
17354 | +/* | |
17355 | + * pointer_to_element() | |
17356 | + */ | |
17357 | +static void | |
17358 | +pointer_to_element(node_t *n0, node_t *n1) | |
17359 | +{ | |
17360 | + int size; | |
17361 | + kltype_t *kltp, *rkltp; | |
17362 | + type_t *tp; | |
17363 | + | |
17364 | + if (!(tp = n0->type)) { | |
17365 | + set_eval_error(E_BAD_INDEX); | |
17366 | + error_token = n0->tok_ptr; | |
17367 | + return; | |
17368 | + } | |
17369 | + if (tp->t_next->flag == POINTER_FLAG) { | |
17370 | + size = sizeof(void *); | |
17371 | + } else { | |
17372 | + kltp = tp->t_next->t_kltp; | |
17373 | + if (!(rkltp = kl_realtype(kltp, 0))) { | |
17374 | + set_eval_error(E_BAD_INDEX); | |
17375 | + error_token = n0->tok_ptr; | |
17376 | + return; | |
17377 | + } | |
17378 | + size = rkltp->kl_size; | |
17379 | + } | |
17380 | + | |
17381 | + /* Get the details on the array element | |
17382 | + */ | |
17383 | + n0->flags |= ADDRESS_FLAG; | |
17384 | + n0->address = n0->value + (n1->value * size); | |
17385 | + n0->type = tp->t_next; | |
17386 | + kl_free_block((char *)tp); | |
17387 | + if (tp->t_next->flag == POINTER_FLAG) { | |
17388 | + n0->flags |= POINTER_FLAG; | |
17389 | + n0->value = *((kaddr_t *)n0->address); | |
17390 | + } else { | |
17391 | + n0->flags &= (~POINTER_FLAG); | |
17392 | + n0->value = 0; | |
17393 | + } | |
17394 | +} | |
17395 | + | |
17396 | +/* | |
17397 | + * array_to_element() | |
17398 | + */ | |
17399 | +static void | |
17400 | +array_to_element(node_t *n0, node_t *n1) | |
17401 | +{ | |
17402 | + kltype_t *kltp, *rkltp, *ip, *ep; | |
17403 | + type_t *tp, *troot = (type_t *)NULL; | |
17404 | + | |
17405 | + if (!(tp = n0->type)) { | |
17406 | + set_eval_error(E_BAD_INDEX); | |
17407 | + error_token = n0->tok_ptr; | |
17408 | + return; | |
17409 | + } | |
17410 | + | |
17411 | + /* If we are indexing a pointer, then make a call to the | |
17412 | + * pointer_to_element() and return. | |
17413 | + */ | |
17414 | + if (tp->flag == POINTER_FLAG) { | |
17415 | + return(pointer_to_element(n0, n1)); | |
17416 | + } | |
17417 | + | |
17418 | + if (!(kltp = n0->type->t_kltp)) { | |
17419 | + set_eval_error(E_BAD_INDEX); | |
17420 | + error_token = n0->tok_ptr; | |
17421 | + return; | |
17422 | + } | |
17423 | + if (!(rkltp = kl_realtype(kltp, KLT_ARRAY))) { | |
17424 | + set_eval_error(E_BAD_INDEX); | |
17425 | + error_token = n0->tok_ptr; | |
17426 | + return; | |
17427 | + } | |
17428 | + ip = rkltp->kl_indextype; | |
17429 | + ep = rkltp->kl_elementtype; | |
17430 | + if (!ip || !ep) { | |
17431 | + set_eval_error(E_BAD_INDEX); | |
17432 | + error_token = n1->tok_ptr; | |
17433 | + return; | |
17434 | + } | |
17435 | + /* Get the details on the array element | |
17436 | + */ | |
17437 | + n0->address = n0->address + (n1->value * ep->kl_size); | |
17438 | + if (ep->kl_type == KLT_POINTER) { | |
17439 | + n0->flags |= POINTER_FLAG; | |
17440 | + n0->value = *((kaddr_t *)n0->address); | |
17441 | + } else { | |
17442 | + n0->value = 0; | |
17443 | + } | |
17444 | + n0->flags |= ADDRESS_FLAG; | |
17445 | + kltp = ep; | |
17446 | + while (kltp->kl_type == KLT_POINTER) { | |
17447 | + if (troot) { | |
17448 | + tp->t_next = (type_t*)kl_alloc_block(sizeof(type_t)); | |
17449 | + tp = tp->t_next; | |
17450 | + } else { | |
17451 | + tp = (type_t*)kl_alloc_block(sizeof(type_t)); | |
17452 | + troot = tp; | |
17453 | + } | |
17454 | + tp->flag = POINTER_FLAG; | |
17455 | + kltp = kltp->kl_realtype; | |
17456 | + } | |
17457 | + if (troot) { | |
17458 | + tp->t_next = (type_t*)kl_alloc_block(sizeof(type_t)); | |
17459 | + tp = tp->t_next; | |
17460 | + n0->type = troot; | |
17461 | + } else { | |
17462 | + tp = (type_t*)kl_alloc_block(sizeof(type_t)); | |
17463 | + n0->type = tp; | |
17464 | + } | |
17465 | + tp->flag = KLTYPE_FLAG; | |
17466 | + tp->t_kltp = ep; | |
17467 | +} | |
17468 | + | |
17469 | +/* | |
17470 | + * number_to_size() | |
17471 | + */ | |
17472 | +int | |
17473 | +number_to_size(node_t *np) | |
17474 | +{ | |
17475 | + int unsigned_flag = 0; | |
17476 | + | |
17477 | + if (np->node_type != NUMBER) { | |
17478 | + set_eval_error(E_BAD_TYPE); | |
17479 | + error_token = np->tok_ptr; | |
17480 | + return(0); | |
17481 | + } | |
17482 | + if (np->flags & UNSIGNED_FLAG) { | |
17483 | + unsigned_flag = 1; | |
17484 | + } | |
17485 | + if ((np->value >= 0) && (np->value <= 0xffffffff)) { | |
17486 | + return(4); | |
17487 | + } else if (((np->value >> 32) & 0xffffffff) == 0xffffffff) { | |
17488 | + if (unsigned_flag) { | |
17489 | + return(8); | |
17490 | + } else if (sizeof(void *) == 4) { | |
17491 | + return(4); | |
17492 | + } else { | |
17493 | + return(8); | |
17494 | + } | |
17495 | + } | |
17496 | + return(8); | |
17497 | +} | |
17498 | + | |
17499 | +/* | |
17500 | + * number_to_type() | |
17501 | + */ | |
17502 | +kltype_t * | |
17503 | +number_to_type(node_t *np) | |
17504 | +{ | |
17505 | + int unsigned_flag = 0; | |
17506 | + kltype_t *kltp, *rkltp = (kltype_t *)NULL; | |
17507 | + | |
17508 | + if (np->node_type != NUMBER) { | |
17509 | + set_eval_error(E_BAD_TYPE); | |
17510 | + error_token = np->tok_ptr; | |
17511 | + return((kltype_t *)NULL); | |
17512 | + } | |
17513 | + if (np->flags & UNSIGNED_FLAG) { | |
17514 | + unsigned_flag = 1; | |
17515 | + } | |
17516 | + if ((np->value >= 0) && (np->value <= 0xffffffff)) { | |
17517 | + if (unsigned_flag) { | |
17518 | + kltp = kl_find_type("uint32_t", KLT_TYPEDEF); | |
17519 | + } else { | |
17520 | + kltp = kl_find_type("int32_t", KLT_TYPEDEF); | |
17521 | + } | |
17522 | + } else if (((np->value >> 32) & 0xffffffff) == 0xffffffff) { | |
17523 | + if (unsigned_flag) { | |
17524 | + kltp = kl_find_type("uint64_t", KLT_TYPEDEF); | |
17525 | + } else if (sizeof(void *) == 4) { | |
17526 | + kltp = kl_find_type("int32_t", KLT_TYPEDEF); | |
17527 | + } else { | |
17528 | + kltp = kl_find_type("int64_t", KLT_TYPEDEF); | |
17529 | + } | |
17530 | + } else { | |
17531 | + if (unsigned_flag) { | |
17532 | + kltp = kl_find_type("uint64_t", KLT_TYPEDEF); | |
17533 | + } else { | |
17534 | + kltp = kl_find_type("int64_t", KLT_TYPEDEF); | |
17535 | + } | |
17536 | + } | |
17537 | + if (kltp) { | |
17538 | + if (!(rkltp = kl_realtype(kltp, 0))) { | |
17539 | + rkltp = kltp; | |
17540 | + } | |
17541 | + } else { | |
17542 | + set_eval_error(E_BAD_TYPE); | |
17543 | + error_token = np->tok_ptr; | |
17544 | + } | |
17545 | + return(rkltp); | |
17546 | +} | |
17547 | + | |
17548 | +/* | |
17549 | + * type_to_number() | |
17550 | + * | |
17551 | + * Convert a base type to a numeric value. Return 1 on successful | |
17552 | + * conversion, 0 if nothing was done. | |
17553 | + */ | |
17554 | +static int | |
17555 | +type_to_number(node_t *np) | |
17556 | +{ | |
17557 | + int byte_size, bit_offset, bit_size, encoding; | |
17558 | + uint64_t value, value1; | |
17559 | + kltype_t *kltp, *rkltp; | |
17560 | + | |
17561 | + /* Sanity check... | |
17562 | + */ | |
17563 | + if (np->node_type != TYPE_DEF) { | |
17564 | + set_eval_error(E_NOTYPE); | |
17565 | + error_token = np->tok_ptr; | |
17566 | + return(0); | |
17567 | + } | |
17568 | + if (!np->type) { | |
17569 | + set_eval_error(E_NOTYPE); | |
17570 | + error_token = np->tok_ptr; | |
17571 | + return(0); | |
17572 | + } | |
17573 | + if (np->type->flag == POINTER_FLAG) { | |
17574 | + return(0); | |
17575 | + } | |
17576 | + | |
17577 | + /* Get the real type record and make sure that it is | |
17578 | + * for a base type. | |
17579 | + */ | |
17580 | + kltp = np->type->t_kltp; | |
17581 | + rkltp = kl_realtype(kltp, 0); | |
17582 | + if (rkltp->kl_type != KLT_BASE) { | |
17583 | + set_eval_error(E_NOTYPE); | |
17584 | + error_token = np->tok_ptr; | |
17585 | + return(0); | |
17586 | + } | |
17587 | + | |
17588 | + byte_size = rkltp->kl_size; | |
17589 | + bit_offset = rkltp->kl_bit_offset; | |
17590 | + if (!(bit_size = rkltp->kl_bit_size)) { | |
17591 | + bit_size = byte_size * 8; | |
17592 | + } | |
17593 | + encoding = rkltp->kl_encoding; | |
17594 | + if (np->flags & ADDRESS_FLAG) { | |
17595 | + /* FIXME: untested */ | |
17596 | + if (invalid_address(np->address, byte_size)) { | |
17597 | + kdb_printf("ILLEGAL ADDRESS (%lx)", | |
17598 | + (uaddr_t)np->address); | |
17599 | + return (0); | |
17600 | + } | |
17601 | + kl_get_block(np->address, byte_size,(void *)&value1,(void *)0); | |
17602 | + } else { | |
17603 | + value1 = np->value; | |
17604 | + } | |
17605 | + value = kl_get_bit_value(&value1, byte_size, bit_size, bit_offset); | |
17606 | + switch (byte_size) { | |
17607 | + | |
17608 | + case 1 : | |
17609 | + if (encoding == ENC_UNSIGNED) { | |
17610 | + np->value = (unsigned char)value; | |
17611 | + np->flags |= UNSIGNED_FLAG; | |
17612 | + } else if (encoding == ENC_SIGNED) { | |
17613 | + np->value = (signed char)value; | |
17614 | + } else { | |
17615 | + np->value = (char)value; | |
17616 | + } | |
17617 | + break; | |
17618 | + | |
17619 | + case 2 : | |
17620 | + if (encoding == ENC_UNSIGNED) { | |
17621 | + np->value = (uint16_t)value; | |
17622 | + np->flags |= UNSIGNED_FLAG; | |
17623 | + } else { | |
17624 | + np->value = (int16_t)value; | |
17625 | + } | |
17626 | + break; | |
17627 | + | |
17628 | + case 4 : | |
17629 | + if (encoding == ENC_UNSIGNED) { | |
17630 | + np->value = (uint32_t)value; | |
17631 | + np->flags |= UNSIGNED_FLAG; | |
17632 | + } else { | |
17633 | + np->value = (int32_t)value; | |
17634 | + } | |
17635 | + break; | |
17636 | + | |
17637 | + case 8 : | |
17638 | + if (encoding == ENC_UNSIGNED) { | |
17639 | + np->value = (uint64_t)value; | |
17640 | + np->flags |= UNSIGNED_FLAG; | |
17641 | + } else { | |
17642 | + np->value = (int64_t)value; | |
17643 | + } | |
17644 | + break; | |
17645 | + | |
17646 | + default : | |
17647 | + set_eval_error(E_BAD_TYPE); | |
17648 | + error_token = np->tok_ptr; | |
17649 | + return(0); | |
17650 | + } | |
17651 | + np->byte_size = byte_size; | |
17652 | + np->node_type = NUMBER; | |
17653 | + return(1); | |
17654 | +} | |
17655 | + | |
17656 | +/* | |
17657 | + * eval_type() | |
17658 | + */ | |
17659 | +static type_t * | |
17660 | +eval_type(node_t *n) | |
17661 | +{ | |
17662 | + type_t *t; | |
17663 | + | |
17664 | + if (!(t = n->type)) { | |
17665 | + return((type_t*)NULL); | |
17666 | + } | |
17667 | + while (t->flag == POINTER_FLAG) { | |
17668 | + t = t->t_next; | |
17669 | + | |
17670 | + /* If for some reason, there is no type pointer (this shouldn't | |
17671 | + * happen but...), we have to make sure that we don't try to | |
17672 | + * reference a NULL pointer and get a SEGV. Return an error if | |
17673 | + * 't' is NULL. | |
17674 | + */ | |
17675 | + if (!t) { | |
17676 | + return((type_t*)NULL); | |
17677 | + } | |
17678 | + } | |
17679 | + if (t->flag == KLTYPE_FLAG) { | |
17680 | + return (t); | |
17681 | + } | |
17682 | + return((type_t*)NULL); | |
17683 | +} | |
17684 | + | |
17685 | +/* | |
17686 | + * expand_variables() | |
17687 | + */ | |
17688 | +static char * | |
17689 | +expand_variables(char *exp, int flags) | |
17690 | +{ | |
17691 | + return((char *)NULL); | |
17692 | +} | |
17693 | + | |
17694 | +/* | |
17695 | + * eval() | |
17696 | + */ | |
17697 | +node_t * | |
17698 | +eval(char **exp, int flags) | |
17699 | +{ | |
17700 | + token_t *tok; | |
17701 | + node_t *n, *root; | |
17702 | + char *e, *s; | |
17703 | + | |
17704 | + eval_error = 0; | |
17705 | + logical_flag = 0; | |
17706 | + | |
17707 | + /* Make sure there is an expression to evaluate | |
17708 | + */ | |
17709 | + if (!(*exp)) { | |
17710 | + return ((node_t*)NULL); | |
17711 | + } | |
17712 | + | |
17713 | + /* Expand any variables that are in the expression string. If | |
17714 | + * a new string is allocated by the expand_variables() function, | |
17715 | + * we need to make sure the original expression string gets | |
17716 | + * freed. In any event, point s at the current expression string | |
17717 | + * so that it gets freed up when we are done. | |
17718 | + */ | |
17719 | + if ((e = expand_variables(*exp, 0))) { | |
17720 | + kl_free_block((void *)*exp); | |
17721 | + *exp = e; | |
17722 | + } else if (eval_error) { | |
17723 | + eval_error |= E_BAD_EVAR; | |
17724 | + error_token = *exp; | |
17725 | + } | |
17726 | + s = *exp; | |
17727 | + tok = get_token_list(s); | |
17728 | + if (eval_error) { | |
17729 | + return((node_t*)NULL); | |
17730 | + } | |
17731 | + | |
17732 | + /* Get the node_list and evaluate the expression. | |
17733 | + */ | |
17734 | + node_list = get_node_list(tok, flags); | |
17735 | + if (eval_error) { | |
17736 | + free_nodelist(node_list); | |
17737 | + node_list = (node_t*)NULL; | |
17738 | + free_tokens(tok); | |
17739 | + return((node_t*)NULL); | |
17740 | + } | |
17741 | + if (!(n = do_eval(flags))) { | |
17742 | + if (!eval_error) { | |
17743 | + set_eval_error(E_SYNTAX_ERROR); | |
17744 | + error_token = s + strlen(s) - 1; | |
17745 | + } | |
17746 | + free_nodes(n); | |
17747 | + free_tokens(tok); | |
17748 | + return((node_t*)NULL); | |
17749 | + } | |
17750 | + | |
17751 | + if (!(root = replace(n, flags))) { | |
17752 | + if (eval_error) { | |
17753 | + free_nodes(n); | |
17754 | + free_tokens(tok); | |
17755 | + return((node_t*)NULL); | |
17756 | + } | |
17757 | + root = n; | |
17758 | + } | |
17759 | + | |
17760 | + /* Check to see if the the result should | |
17761 | + * be interpreted as 'true' or 'false' | |
17762 | + */ | |
17763 | + if (logical_flag && ((root->value == 0) || (root->value == 1))) { | |
17764 | + root->flags |= BOOLIAN_FLAG; | |
17765 | + } | |
17766 | + free_tokens(tok); | |
17767 | + return(root); | |
17768 | +} | |
17769 | + | |
17770 | +/* | |
17771 | + * print_number() | |
17772 | + */ | |
17773 | +void | |
17774 | +print_number(node_t *np, int flags) | |
17775 | +{ | |
17776 | + int size; | |
17777 | + unsigned long long value; | |
17778 | + | |
17779 | + if ((size = number_to_size(np)) && (size != sizeof(uint64_t))) { | |
17780 | + value = np->value & (((uint64_t)1 << (uint64_t)(size*8))-1); | |
17781 | + } else { | |
17782 | + value = np->value; | |
17783 | + } | |
17784 | + if (flags & C_HEX) { | |
17785 | + kdb_printf("0x%llx", value); | |
17786 | + } else if (flags & C_BINARY) { | |
17787 | + kdb_printf("0b"); | |
17788 | + kl_binary_print(value); | |
17789 | + } else { | |
17790 | + if (np->flags & UNSIGNED_FLAG) { | |
17791 | + kdb_printf("%llu", value); | |
17792 | + } else { | |
17793 | + kdb_printf("%lld", np->value); | |
17794 | + } | |
17795 | + } | |
17796 | +} | |
17797 | + | |
17798 | +/* | |
17799 | + * print_string() | |
17800 | + */ | |
17801 | +void | |
17802 | +print_string(kaddr_t addr, int size) | |
17803 | +{ | |
17804 | + int i; | |
17805 | + char *str; | |
17806 | + | |
17807 | + if (!size) { | |
17808 | + size = 255; | |
17809 | + } | |
17810 | + /* FIXME: untested */ | |
17811 | + if (invalid_address(addr, size)) { | |
17812 | + klib_error = KLE_INVALID_PADDR; | |
17813 | + return; | |
17814 | + } | |
17815 | + str = (char*)kl_alloc_block(size); | |
17816 | + kl_get_block(addr, size, (void *)str, (void *)0); | |
17817 | + kdb_printf("\"%s", str); | |
17818 | + for (i = 0; i < size; i++) { | |
17819 | + if (!str[i]) { | |
17820 | + break; | |
17821 | + } | |
17822 | + } | |
17823 | + if (KL_ERROR || (i == size)) { | |
17824 | + kdb_printf("..."); | |
17825 | + } | |
17826 | + kdb_printf("\""); | |
17827 | + kl_free_block(str); | |
17828 | +} | |
17829 | + | |
17830 | +/* | |
17831 | + * kl_print_error() | |
17832 | + */ | |
17833 | +void | |
17834 | +kl_print_error(void) | |
17835 | +{ | |
17836 | + int ecode; | |
17837 | + | |
17838 | + ecode = klib_error & 0xffffffff; | |
17839 | + switch(ecode) { | |
17840 | + | |
17841 | + /** General klib error codes | |
17842 | + **/ | |
17843 | + case KLE_NO_MEMORY: | |
17844 | + kdb_printf("insufficient memory"); | |
17845 | + break; | |
17846 | + case KLE_OPEN_ERROR: | |
17847 | + kdb_printf("unable to open file"); | |
17848 | + break; | |
17849 | + case KLE_ZERO_BLOCK: | |
17850 | + kdb_printf("tried to allocate a zero-sized block"); | |
17851 | + break; | |
17852 | + case KLE_INVALID_VALUE: | |
17853 | + kdb_printf("invalid input value"); | |
17854 | + break; | |
17855 | + case KLE_NULL_BUFF: | |
17856 | + kdb_printf( "NULL buffer pointer"); | |
17857 | + break; | |
17858 | + case KLE_ZERO_SIZE: | |
17859 | + kdb_printf("zero sized block requested"); | |
17860 | + break; | |
17861 | + case KLE_ACTIVE: | |
17862 | + kdb_printf("operation not supported on a live system"); | |
17863 | + break; | |
17864 | + case KLE_UNSUPPORTED_ARCH: | |
17865 | + kdb_printf("unsupported architecture"); | |
17866 | + break; | |
17867 | + case KLE_MISC_ERROR: | |
17868 | + kdb_printf("KLIB error"); | |
17869 | + break; | |
17870 | + case KLE_NOT_SUPPORTED: | |
17871 | + kdb_printf("operation not supported"); | |
17872 | + break; | |
17873 | + case KLE_UNKNOWN_ERROR: | |
17874 | + kdb_printf("unknown error"); | |
17875 | + break; | |
17876 | + | |
17877 | + /** memory error codes | |
17878 | + **/ | |
17879 | + case KLE_BAD_MAP_FILE: | |
17880 | + kdb_printf("bad map file"); | |
17881 | + break; | |
17882 | + case KLE_BAD_DUMP: | |
17883 | + kdb_printf("bad dump file"); | |
17884 | + break; | |
17885 | + case KLE_BAD_DUMPTYPE: | |
17886 | + kdb_printf("bad dumptype"); | |
17887 | + break; | |
17888 | + case KLE_INVALID_LSEEK: | |
17889 | + kdb_printf("lseek error"); | |
17890 | + break; | |
17891 | + case KLE_INVALID_READ: | |
17892 | + kdb_printf("not found in dump file"); | |
17893 | + break; | |
17894 | + case KLE_BAD_KERNINFO: | |
17895 | + kdb_printf("bad kerninfo struct"); | |
17896 | + break; | |
17897 | + case KLE_INVALID_PADDR: | |
17898 | + kdb_printf("invalid physical address"); | |
17899 | + break; | |
17900 | + case KLE_INVALID_VADDR: | |
17901 | + kdb_printf("invalid virtual address"); | |
17902 | + break; | |
17903 | + case KLE_INVALID_VADDR_ALIGN: | |
17904 | + kdb_printf("invalid vaddr alignment"); | |
17905 | + break; | |
17906 | + case KLE_INVALID_MAPPING: | |
17907 | + kdb_printf("invalid address mapping"); | |
17908 | + break; | |
17909 | + case KLE_PAGE_NOT_PRESENT: | |
17910 | + kdb_printf("page not present"); | |
17911 | + break; | |
17912 | + case KLE_BAD_ELF_FILE: | |
17913 | + kdb_printf("bad elf file"); | |
17914 | + break; | |
17915 | + case KLE_ARCHIVE_FILE: | |
17916 | + kdb_printf("archive file"); | |
17917 | + break; | |
17918 | + case KLE_MAP_FILE_PRESENT: | |
17919 | + kdb_printf("map file present"); | |
17920 | + break; | |
17921 | + case KLE_BAD_MAP_FILENAME: | |
17922 | + kdb_printf("bad map filename"); | |
17923 | + break; | |
17924 | + case KLE_BAD_DUMP_FILENAME: | |
17925 | + kdb_printf("bad dump filename"); | |
17926 | + break; | |
17927 | + case KLE_BAD_NAMELIST_FILE: | |
17928 | + kdb_printf("bad namelist file"); | |
17929 | + break; | |
17930 | + case KLE_BAD_NAMELIST_FILENAME: | |
17931 | + kdb_printf("bad namelist filename"); | |
17932 | + break; | |
17933 | + | |
17934 | + /** symbol error codes | |
17935 | + **/ | |
17936 | + case KLE_NO_SYMTAB: | |
17937 | + kdb_printf("no symtab"); | |
17938 | + break; | |
17939 | + case KLE_NO_SYMBOLS: | |
17940 | + kdb_printf("no symbol information"); | |
17941 | + break; | |
17942 | + case KLE_NO_MODULE_LIST: | |
17943 | + kdb_printf("kernel without module support"); | |
17944 | + break; | |
17945 | + | |
17946 | + /** kernel data error codes | |
17947 | + **/ | |
17948 | + case KLE_INVALID_KERNELSTACK: | |
17949 | + kdb_printf("invalid kernel stack"); | |
17950 | + break; | |
17951 | + case KLE_INVALID_STRUCT_SIZE: | |
17952 | + kdb_printf("invalid struct size"); | |
17953 | + break; | |
17954 | + case KLE_BEFORE_RAM_OFFSET: | |
17955 | + kdb_printf("physical address proceeds start of RAM"); | |
17956 | + break; | |
17957 | + case KLE_AFTER_MAXPFN: | |
17958 | + kdb_printf("PFN exceeds maximum PFN"); | |
17959 | + break; | |
17960 | + case KLE_AFTER_PHYSMEM: | |
17961 | + kdb_printf("address exceeds physical memory"); | |
17962 | + break; | |
17963 | + case KLE_AFTER_MAXMEM: | |
17964 | + kdb_printf("address exceeds maximum physical address"); | |
17965 | + break; | |
17966 | + case KLE_PHYSMEM_NOT_INSTALLED: | |
17967 | + kdb_printf("physical memory not installed"); | |
17968 | + break; | |
17969 | + case KLE_NO_DEFTASK: | |
17970 | + kdb_printf("default task not set"); | |
17971 | + break; | |
17972 | + case KLE_PID_NOT_FOUND: | |
17973 | + kdb_printf("PID not found"); | |
17974 | + break; | |
17975 | + case KLE_DEFTASK_NOT_ON_CPU: | |
17976 | + kdb_printf("default task not running on a cpu"); | |
17977 | + break; | |
17978 | + case KLE_NO_CURCPU: | |
17979 | + kdb_printf("current cpu could not be determined"); | |
17980 | + break; | |
17981 | + | |
17982 | + case KLE_KERNEL_MAGIC_MISMATCH: | |
17983 | + kdb_printf("kernel_magic mismatch " | |
17984 | + "of map and memory image"); | |
17985 | + break; | |
17986 | + | |
17987 | + case KLE_INVALID_DUMP_HEADER: | |
17988 | + kdb_printf("invalid dump header in dump"); | |
17989 | + break; | |
17990 | + | |
17991 | + case KLE_DUMP_INDEX_CREATION: | |
17992 | + kdb_printf("cannot create index file"); | |
17993 | + break; | |
17994 | + | |
17995 | + case KLE_DUMP_HEADER_ONLY: | |
17996 | + kdb_printf("dump only has a dump header"); | |
17997 | + break; | |
17998 | + | |
17999 | + case KLE_NO_END_SYMBOL: | |
18000 | + kdb_printf("no _end symbol in kernel"); | |
18001 | + break; | |
18002 | + | |
18003 | + case KLE_NO_CPU: | |
18004 | + kdb_printf("CPU not installed"); | |
18005 | + break; | |
18006 | + | |
18007 | + default: | |
18008 | + break; | |
18009 | + } | |
18010 | + kdb_printf("\n"); | |
18011 | +} | |
18012 | + | |
18013 | +/* | |
18014 | + * kl_print_string() | |
18015 | + * | |
18016 | + * print out a string, translating all embeded control characters | |
18017 | + * (e.g., '\n' for newline, '\t' for tab, etc.) | |
18018 | + */ | |
18019 | +void | |
18020 | +kl_print_string(char *s) | |
18021 | +{ | |
18022 | + char *sp, *cp; | |
18023 | + | |
18024 | + kl_reset_error(); | |
18025 | + | |
18026 | + if (!(sp = s)) { | |
18027 | + klib_error = KLE_BAD_STRING; | |
18028 | + return; | |
18029 | + } | |
18030 | + /* FIXME: untested */ | |
18031 | + if (invalid_address((kaddr_t)sp, 1)) { | |
18032 | + klib_error = KLE_INVALID_PADDR; | |
18033 | + return; | |
18034 | + } | |
18035 | + | |
18036 | + while (sp) { | |
18037 | + if ((cp = strchr(sp, '\\'))) { | |
18038 | + switch (*(cp + 1)) { | |
18039 | + | |
18040 | + case 'n' : | |
18041 | + *cp++ = '\n'; | |
18042 | + *cp++ = 0; | |
18043 | + break; | |
18044 | + | |
18045 | + case 't' : | |
18046 | + *cp++ = '\t'; | |
18047 | + *cp++ = 0; | |
18048 | + break; | |
18049 | + | |
18050 | + default : | |
18051 | + if (*(cp + 1) == 0) { | |
18052 | + klib_error = KLE_BAD_STRING; | |
18053 | + return; | |
18054 | + } | |
18055 | + /* Change the '\' character to a zero | |
18056 | + * and then print the string (the rest | |
18057 | + * of the string will be picked | |
18058 | + * up on the next pass). | |
18059 | + */ | |
18060 | + *cp++ = 0; | |
18061 | + break; | |
18062 | + } | |
18063 | + kdb_printf("%s", sp); | |
18064 | + sp = cp; | |
18065 | + } else { | |
18066 | + kdb_printf("%s", sp); | |
18067 | + sp = 0; | |
18068 | + } | |
18069 | + } | |
18070 | +} | |
18071 | + | |
18072 | +/* | |
18073 | + * print_eval_results() | |
18074 | + */ | |
18075 | +int | |
18076 | +print_eval_results(node_t *np, int flags) | |
18077 | +{ | |
18078 | + int size, i, count, ptr_cnt = 0; | |
18079 | + kaddr_t addr; | |
18080 | + char *typestr; | |
18081 | + kltype_t *kltp, *rkltp = NULL, *nkltp; | |
18082 | + type_t *tp; | |
18083 | + | |
18084 | + /* Print the results | |
18085 | + */ | |
18086 | + switch (np->node_type) { | |
18087 | + | |
18088 | + case NUMBER: | |
18089 | + print_number(np, flags); | |
18090 | + break; | |
18091 | + | |
18092 | + case TYPE_DEF: { | |
18093 | + | |
18094 | + /* First, determine the number of levels of indirection | |
18095 | + * by determining the number of pointer type records. | |
18096 | + */ | |
18097 | + if ((tp = np->type)) { | |
18098 | + while (tp && (tp->flag == POINTER_FLAG)) { | |
18099 | + ptr_cnt++; | |
18100 | + tp = tp->t_next; | |
18101 | + } | |
18102 | + if (tp) { | |
18103 | + rkltp = tp->t_kltp; | |
18104 | + } | |
18105 | + } | |
18106 | + if (!rkltp) { | |
18107 | + kdb_printf("Type information not available\n"); | |
18108 | + return(1); | |
18109 | + } | |
18110 | + | |
18111 | + if (ptr_cnt) { | |
18112 | + | |
18113 | + /* If this is a member, we need to get the | |
18114 | + * first type record. | |
18115 | + */ | |
18116 | + if (rkltp->kl_type == KLT_MEMBER) { | |
18117 | + /* We need to get down to the first | |
18118 | + * real type record... | |
18119 | + */ | |
18120 | + rkltp = rkltp->kl_realtype; | |
18121 | + } | |
18122 | + | |
18123 | + /* step over any KLT_POINTER type records. | |
18124 | + */ | |
18125 | + while (rkltp && rkltp->kl_type == KLT_POINTER) { | |
18126 | + rkltp = rkltp->kl_realtype; | |
18127 | + } | |
18128 | + if (!rkltp) { | |
18129 | + kdb_printf("Bad type information\n"); | |
18130 | + return(1); | |
18131 | + } | |
18132 | + typestr = rkltp->kl_typestr; | |
18133 | + if (rkltp->kl_type == KLT_FUNCTION) { | |
18134 | + kdb_printf("%s(", typestr); | |
18135 | + } else if (rkltp->kl_type == KLT_ARRAY) { | |
18136 | + kdb_printf("(%s(", typestr); | |
18137 | + } else { | |
18138 | + kdb_printf("(%s", typestr); | |
18139 | + } | |
18140 | + for (i = 0; i < ptr_cnt; i++) { | |
18141 | + kdb_printf("*"); | |
18142 | + } | |
18143 | + if (rkltp->kl_type == KLT_FUNCTION) { | |
18144 | + kdb_printf(")("); | |
18145 | + } else if (rkltp->kl_type == KLT_ARRAY) { | |
18146 | + kdb_printf(")"); | |
18147 | + | |
18148 | + nkltp = rkltp; | |
18149 | + while (nkltp->kl_type == KLT_ARRAY) { | |
18150 | + count = nkltp->kl_high_bounds - | |
18151 | + nkltp->kl_low_bounds + 1; | |
18152 | + kdb_printf("[%d]", count); | |
18153 | + nkltp = nkltp->kl_elementtype; | |
18154 | + } | |
18155 | + } | |
18156 | + kdb_printf(") "); | |
18157 | + kdb_printf("0x%llx", np->value); | |
18158 | + | |
18159 | + if (ptr_cnt > 1) { | |
18160 | + break; | |
18161 | + } | |
18162 | + | |
18163 | + if ((rkltp->kl_type == KLT_BASE) && | |
18164 | + rkltp->kl_encoding == ENC_CHAR) { | |
18165 | + kdb_printf(" = "); | |
18166 | + print_string(np->value, 0); | |
18167 | + } | |
18168 | + break; | |
18169 | + } | |
18170 | + if (np->flags & KLTYPE_FLAG) { | |
18171 | + void * ptr; | |
18172 | + | |
18173 | + /* Get the type information. It's possible | |
18174 | + * that the type is a member. In which case, | |
18175 | + * the size may only be from this record | |
18176 | + * (which would be the casse if this is an | |
18177 | + * array). We must check the original type | |
18178 | + * record first, and try the realtype record | |
18179 | + * if the value is zero. | |
18180 | + */ | |
18181 | + kltp = np->type->t_kltp; | |
18182 | + | |
18183 | + if (kltp->kl_type == KLT_MEMBER) { | |
18184 | + rkltp = kltp->kl_realtype; | |
18185 | + } else { | |
18186 | + rkltp = kltp; | |
18187 | + } | |
18188 | + | |
18189 | + /* Check to see if this is a typedef. If | |
18190 | + * it is, then it might be a typedef for | |
18191 | + * a pointer type. Don't walk to the last | |
18192 | + * type record. | |
18193 | + */ | |
18194 | + while (rkltp->kl_type == KLT_TYPEDEF) { | |
18195 | + rkltp = rkltp->kl_realtype; | |
18196 | + } | |
18197 | + | |
18198 | + if (rkltp->kl_type == KLT_POINTER) { | |
18199 | + kdb_printf("0x%llx", np->value); | |
18200 | + break; | |
18201 | + } | |
18202 | + if((rkltp->kl_name != 0) && | |
18203 | + !(strcmp(rkltp->kl_name, "void"))) { | |
18204 | + /* we are about to dereference | |
18205 | + * a void pointer. | |
18206 | + */ | |
18207 | + kdb_printf("Can't dereference a " | |
18208 | + "generic pointer.\n"); | |
18209 | + return(1); | |
18210 | + } | |
18211 | + | |
18212 | + size = rkltp->kl_size; | |
18213 | + if (!size || (size < 0)) { | |
18214 | + size = kltp->kl_size; | |
18215 | + } | |
18216 | + | |
18217 | + if(rkltp->kl_type==KLT_ARRAY) { | |
18218 | + size = rkltp->kl_high_bounds - | |
18219 | + rkltp->kl_low_bounds + 1; | |
18220 | + if(rkltp->kl_elementtype == NULL){ | |
18221 | + kdb_printf("Incomplete array" | |
18222 | + " type.\n"); | |
18223 | + return(1); | |
18224 | + } | |
18225 | + if(rkltp->kl_elementtype->kl_type == | |
18226 | + KLT_POINTER){ | |
18227 | + size *= sizeof(void *); | |
18228 | + } else { | |
18229 | + size *= rkltp->kl_elementtype->kl_size; | |
18230 | + } | |
18231 | + } | |
18232 | + if(size){ | |
18233 | + ptr = kl_alloc_block(size); | |
18234 | + } else { | |
18235 | + ptr = NULL; | |
18236 | + } | |
18237 | + if ((rkltp->kl_type == KLT_BASE) && | |
18238 | + !(np->flags & ADDRESS_FLAG)) { | |
18239 | + switch (size) { | |
18240 | + case 1: | |
18241 | + *(unsigned char *)ptr = | |
18242 | + np->value; | |
18243 | + break; | |
18244 | + | |
18245 | + case 2: | |
18246 | + *(unsigned short *)ptr = | |
18247 | + np->value; | |
18248 | + break; | |
18249 | + | |
18250 | + case 4: | |
18251 | + *(unsigned int *)ptr = | |
18252 | + np->value; | |
18253 | + break; | |
18254 | + | |
18255 | + case 8: | |
18256 | + *(unsigned long long *) | |
18257 | + ptr = np->value; | |
18258 | + break; | |
18259 | + } | |
18260 | + kl_print_type(ptr, rkltp, 0, | |
18261 | + flags|SUPPRESS_NAME); | |
18262 | + kl_free_block(ptr); | |
18263 | + return(1); | |
18264 | + } | |
18265 | + | |
18266 | + if(size){ | |
18267 | + addr = np->address; | |
18268 | + if (invalid_address(addr, size)) { | |
18269 | + kdb_printf ( | |
18270 | + "invalid address %#lx\n", | |
18271 | + addr); | |
18272 | + return 1; | |
18273 | + } | |
18274 | + kl_get_block(addr, size, (void *)ptr, | |
18275 | + (void *)0); | |
18276 | + if (KL_ERROR) { | |
18277 | + kl_print_error(); | |
18278 | + kl_free_block(ptr); | |
18279 | + return(1); | |
18280 | + } | |
18281 | + } | |
18282 | + /* Print out the actual type | |
18283 | + */ | |
18284 | + switch (rkltp->kl_type) { | |
18285 | + case KLT_STRUCT: | |
18286 | + case KLT_UNION: | |
18287 | + kl_print_type(ptr, rkltp, 0, | |
18288 | + flags); | |
18289 | + break; | |
18290 | + | |
18291 | + case KLT_ARRAY: | |
18292 | + kl_print_type(ptr, rkltp, 0, | |
18293 | + flags| SUPPRESS_NAME); | |
18294 | + break; | |
18295 | + | |
18296 | + default: | |
18297 | + kl_print_type(ptr, rkltp, 0, | |
18298 | + (flags| | |
18299 | + SUPPRESS_NAME| | |
18300 | + SUPPRESS_NL)); | |
18301 | + break; | |
18302 | + } | |
18303 | + if(ptr){ | |
18304 | + kl_free_block(ptr); | |
18305 | + } | |
18306 | + } | |
18307 | + break; | |
18308 | + } | |
18309 | + | |
18310 | + case VADDR: | |
18311 | + /* If we get here, there was no type info available. | |
18312 | + * The ADDRESS_FLAG should be set (otherwise we | |
18313 | + * would have returned an error). So, print out | |
18314 | + * the address. | |
18315 | + */ | |
18316 | + kdb_printf("0x%lx", np->address); | |
18317 | + break; | |
18318 | + | |
18319 | + default: | |
18320 | + if (np->node_type == TEXT) { | |
18321 | + kl_print_string(np->name); | |
18322 | + if (KL_ERROR) { | |
18323 | + kl_print_error(); | |
18324 | + return(1); | |
18325 | + } | |
18326 | + } else if (np->node_type == CHARACTER) { | |
18327 | + kdb_printf("\'%c\'", (char)np->value); | |
18328 | + } | |
18329 | + break; | |
18330 | + } | |
18331 | + return(0); | |
18332 | +} | |
18333 | + | |
18334 | +/* | |
18335 | + * print_eval_error() | |
18336 | + */ | |
18337 | +void | |
18338 | +print_eval_error( | |
18339 | + char *cmdname, | |
18340 | + char *s, | |
18341 | + char *bad_ptr, | |
18342 | + uint64_t error, | |
18343 | + int flags) | |
18344 | +{ | |
18345 | + int i, cmd_len; | |
18346 | + | |
18347 | + kdb_printf("%s %s\n", cmdname, s); | |
18348 | + cmd_len = strlen(cmdname); | |
18349 | + | |
18350 | + if (!bad_ptr) { | |
18351 | + for (i = 0; i < (strlen(s) + cmd_len); i++) { | |
18352 | + kdb_printf(" "); | |
18353 | + } | |
18354 | + } else { | |
18355 | + for (i = 0; i < (bad_ptr - s + 1 + cmd_len); i++) { | |
18356 | + kdb_printf(" "); | |
18357 | + } | |
18358 | + } | |
18359 | + kdb_printf("^ "); | |
18360 | + switch (error) { | |
18361 | + case E_OPEN_PAREN : | |
18362 | + kdb_printf("Too many open parenthesis\n"); | |
18363 | + break; | |
18364 | + | |
18365 | + case E_CLOSE_PAREN : | |
18366 | + kdb_printf("Too many close parenthesis\n"); | |
18367 | + break; | |
18368 | + | |
18369 | + case E_BAD_STRUCTURE : | |
18370 | + kdb_printf("Invalid structure\n"); | |
18371 | + break; | |
18372 | + | |
18373 | + case E_MISSING_STRUCTURE : | |
18374 | + kdb_printf("Missing structure\n"); | |
18375 | + break; | |
18376 | + | |
18377 | + case E_BAD_MEMBER : | |
18378 | + kdb_printf("No such member\n"); | |
18379 | + break; | |
18380 | + | |
18381 | + case E_BAD_OPERATOR : | |
18382 | + kdb_printf("Invalid operator\n"); | |
18383 | + break; | |
18384 | + | |
18385 | + case E_MISSING_OPERAND : | |
18386 | + kdb_printf("Missing operand\n"); | |
18387 | + break; | |
18388 | + | |
18389 | + case E_BAD_OPERAND : | |
18390 | + kdb_printf("Invalid operand\n"); | |
18391 | + break; | |
18392 | + | |
18393 | + case E_BAD_TYPE : | |
18394 | + kdb_printf("Invalid type\n"); | |
18395 | + if (!have_debug_file) { | |
18396 | + kdb_printf("no debuginfo file\n"); | |
18397 | + return; | |
18398 | + } | |
18399 | + break; | |
18400 | + | |
18401 | + case E_NOTYPE : | |
18402 | + kdb_printf("Could not find type information\n"); | |
18403 | + break; | |
18404 | + | |
18405 | + case E_BAD_POINTER : | |
18406 | + kdb_printf("Invalid pointer\n"); | |
18407 | + break; | |
18408 | + | |
18409 | + case E_BAD_INDEX : | |
18410 | + kdb_printf("Invalid array index\n"); | |
18411 | + break; | |
18412 | + | |
18413 | + case E_BAD_CHAR : | |
18414 | + kdb_printf("Invalid character value\n"); | |
18415 | + break; | |
18416 | + | |
18417 | + case E_BAD_STRING : | |
18418 | + kdb_printf("Non-termining string\n"); | |
18419 | + break; | |
18420 | + | |
18421 | + case E_END_EXPECTED : | |
18422 | + kdb_printf( | |
18423 | + "Expected end of print statement\n"); | |
18424 | + break; | |
18425 | + | |
18426 | + case E_BAD_EVAR : | |
18427 | + kdb_printf("Invalid eval variable\n"); | |
18428 | + break; | |
18429 | + | |
18430 | + case E_BAD_VALUE : | |
18431 | + kdb_printf("Invalid value\n"); | |
18432 | + break; | |
18433 | + | |
18434 | + case E_NO_VALUE : | |
18435 | + kdb_printf("No value supplied\n"); | |
18436 | + break; | |
18437 | + | |
18438 | + case E_DIVIDE_BY_ZERO : | |
18439 | + kdb_printf("Divide by zero\n"); | |
18440 | + break; | |
18441 | + | |
18442 | + case E_BAD_CAST : | |
18443 | + kdb_printf("Invalid cast\n"); | |
18444 | + break; | |
18445 | + | |
18446 | + case E_NO_ADDRESS : | |
18447 | + kdb_printf("Not an address\n"); | |
18448 | + break; | |
18449 | + | |
18450 | + case E_SINGLE_QUOTE : | |
18451 | + kdb_printf("Missing single quote\n"); | |
18452 | + break; | |
18453 | + | |
18454 | + case E_BAD_WHATIS : | |
18455 | + kdb_printf("Invalid whatis Operation\n"); | |
18456 | + break; | |
18457 | + | |
18458 | + case E_NOT_IMPLEMENTED : | |
18459 | + kdb_printf("Not implemented\n"); | |
18460 | + break; | |
18461 | + | |
18462 | + default : | |
18463 | + kdb_printf("Syntax error\n"); | |
18464 | + break; | |
18465 | + } | |
18466 | +} | |
18467 | + | |
18468 | +/* | |
18469 | + * single_type() | |
18470 | + */ | |
18471 | +void | |
18472 | +single_type(char *str) | |
18473 | +{ | |
18474 | + char buffer[256], *type_name; | |
18475 | + kltype_t *kltp; | |
18476 | + syment_t *sp; | |
18477 | + | |
18478 | + type_name = buffer; | |
18479 | + strcpy(type_name, str); | |
18480 | + | |
18481 | + if (have_debug_file) { | |
18482 | + if ((kltp = kl_find_type(type_name, KLT_TYPE))) { | |
18483 | + kl_print_type((void *)NULL, kltp, 0, C_SHOWOFFSET); | |
18484 | + return; | |
18485 | + } | |
18486 | + if ((kltp = kl_find_type(type_name, KLT_TYPEDEF))) { | |
18487 | + kdb_printf ("typedef %s:\n", type_name); | |
18488 | + kl_print_type((void *)NULL, kltp, 0, C_SHOWOFFSET); | |
18489 | + return; | |
18490 | + } | |
18491 | + } | |
18492 | + if ((sp = kl_lkup_symname(type_name))) { | |
18493 | + kdb_printf ("symbol %s value: %#lx\n", str, sp->s_addr); | |
18494 | + kl_free_block((void *)sp); | |
18495 | + return; | |
18496 | + } | |
18497 | + kdb_printf("could not find type or symbol information for %s\n", | |
18498 | + type_name); | |
18499 | + return; | |
18500 | +} | |
18501 | + | |
18502 | +/* | |
18503 | + * sizeof_type() | |
18504 | + */ | |
18505 | +void | |
18506 | +sizeof_type(char *str) | |
18507 | +{ | |
18508 | + char buffer[256], *type_name; | |
18509 | + kltype_t *kltp; | |
18510 | + | |
18511 | + type_name = buffer; | |
18512 | + strcpy(type_name, str); | |
18513 | + | |
18514 | + if ((kltp = kl_find_type(type_name, KLT_TYPE))) { | |
18515 | + kdb_printf ("%s %d %#x\n", kltp->kl_typestr, | |
18516 | + kltp->kl_size, kltp->kl_size); | |
18517 | + return; | |
18518 | + } | |
18519 | + if ((kltp = kl_find_type(type_name, KLT_TYPEDEF))) { | |
18520 | + kdb_printf ("%s %d %#x\n", kltp->kl_typestr, | |
18521 | + kltp->kl_size, kltp->kl_size); | |
18522 | + return; | |
18523 | + } | |
18524 | + kdb_printf("could not find type information for %s\n", type_name); | |
18525 | +} | |
18526 | + | |
18527 | +EXPORT_SYMBOL(have_debug_file); | |
18528 | +EXPORT_SYMBOL(type_tree); | |
18529 | +EXPORT_SYMBOL(typedef_tree); | |
18530 | + | |
18531 | +#if defined(CONFIG_X86_32) | |
18532 | +/* needed for i386: */ | |
18533 | +#include <linux/types.h> | |
18534 | +#include <asm/div64.h> | |
18535 | +/* | |
18536 | + * Generic C version of full 64 bit by 64 bit division | |
18537 | + * | |
18538 | + * This program is free software; you can redistribute it and/or | |
18539 | + * modify it under the terms of the GNU General Public License | |
18540 | + * version 2 as published by the Free Software Foundation. | |
18541 | + * | |
18542 | + * Code generated for this function might be very inefficient | |
18543 | + * for some CPUs, can be overridden by linking arch-specific | |
18544 | + * assembly versions such as arch/sparc/lib/udivdi.S | |
18545 | + */ | |
18546 | +uint64_t | |
18547 | +__udivdi3(uint64_t dividend, uint64_t divisor) | |
18548 | +{ | |
18549 | + uint32_t d = divisor; | |
18550 | + /* Scale divisor to 32 bits */ | |
18551 | + if (divisor > 0xffffffffULL) { | |
18552 | + unsigned int shift = fls(divisor >> 32); | |
18553 | + d = divisor >> shift; | |
18554 | + dividend >>= shift; | |
18555 | + } | |
18556 | + /* avoid 64 bit division if possible */ | |
18557 | + if (dividend >> 32) | |
18558 | + do_div(dividend, d); | |
18559 | + else | |
18560 | + dividend = (uint32_t) dividend / d; | |
18561 | + return dividend; | |
18562 | +} | |
18563 | + | |
18564 | +int64_t | |
18565 | +__divdi3(int64_t dividend, int64_t divisor) | |
18566 | +{ | |
18567 | + int32_t d = divisor; | |
18568 | + /* Scale divisor to 32 bits */ | |
18569 | + if (divisor > 0xffffffffLL) { | |
18570 | + unsigned int shift = fls(divisor >> 32); | |
18571 | + d = divisor >> shift; | |
18572 | + dividend >>= shift; | |
18573 | + } | |
18574 | + /* avoid 64 bit division if possible */ | |
18575 | + if (dividend >> 32) | |
18576 | + do_div(dividend, d); | |
18577 | + else | |
18578 | + dividend = (int32_t) dividend / d; | |
18579 | + return dividend; | |
18580 | +} | |
18581 | + | |
18582 | +uint64_t | |
18583 | +__umoddi3(uint64_t dividend, uint64_t divisor) | |
18584 | +{ | |
18585 | + return dividend - (__udivdi3(dividend, divisor) * divisor); | |
18586 | +} | |
18587 | + | |
18588 | +int64_t | |
18589 | +__moddi3(int64_t dividend, int64_t divisor) | |
18590 | +{ | |
18591 | + return dividend - (__divdi3(dividend, divisor) * divisor); | |
18592 | +} | |
18593 | +#endif /* CONFIG_x86_32 */ | |
18594 | --- /dev/null | |
18595 | +++ b/kdb/kdbmain.c | |
18596 | @@ -0,0 +1,4333 @@ | |
18597 | +/* | |
18598 | + * Kernel Debugger Architecture Independent Main Code | |
18599 | + * | |
18600 | + * This file is subject to the terms and conditions of the GNU General Public | |
18601 | + * License. See the file "COPYING" in the main directory of this archive | |
18602 | + * for more details. | |
18603 | + * | |
18604 | + * Copyright (C) 1999-2004 Silicon Graphics, Inc. All Rights Reserved. | |
18605 | + * Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com> | |
18606 | + * Xscale (R) modifications copyright (C) 2003 Intel Corporation. | |
18607 | + */ | |
18608 | + | |
18609 | +/* | |
18610 | + * Updated for Xscale (R) architecture support | |
18611 | + * Eddie Dong <eddie.dong@intel.com> 8 Jan 03 | |
18612 | + */ | |
18613 | + | |
18614 | +#include <linux/ctype.h> | |
18615 | +#include <linux/string.h> | |
18616 | +#include <linux/kernel.h> | |
18617 | +#include <linux/reboot.h> | |
18618 | +#include <linux/sched.h> | |
18619 | +#include <linux/sysrq.h> | |
18620 | +#include <linux/smp.h> | |
18621 | +#include <linux/utsname.h> | |
18622 | +#include <linux/vmalloc.h> | |
18623 | +#include <linux/module.h> | |
18624 | +#include <linux/mm.h> | |
18625 | +#include <linux/init.h> | |
18626 | +#include <linux/kallsyms.h> | |
18627 | +#include <linux/kdb.h> | |
18628 | +#include <linux/kdbprivate.h> | |
18629 | +#include <linux/notifier.h> | |
18630 | +#include <linux/interrupt.h> | |
18631 | +#include <linux/delay.h> | |
18632 | +#include <linux/nmi.h> | |
18633 | +#include <linux/ptrace.h> | |
18634 | +#include <linux/sysctl.h> | |
18635 | +#if defined(CONFIG_LKCD_DUMP) || defined(CONFIG_LKCD_DUMP_MODULE) | |
18636 | +#include <linux/dump.h> | |
18637 | +#endif | |
18638 | +#include <linux/cpu.h> | |
18639 | +#include <linux/kdebug.h> | |
18640 | +#ifdef CONFIG_KDB_KDUMP | |
18641 | +#include <linux/kexec.h> | |
18642 | +#endif | |
18643 | + | |
18644 | +#include <acpi/acpi_bus.h> | |
18645 | + | |
18646 | +#include <asm/system.h> | |
18647 | +#include <asm/kdebug.h> | |
18648 | +#include <linux/proc_fs.h> | |
18649 | +#include <asm/uaccess.h> | |
18650 | +char kdb_debug_info_filename[256] = {""}; | |
18651 | +EXPORT_SYMBOL(kdb_debug_info_filename); | |
18652 | +#define GREP_LEN 256 | |
18653 | +char kdb_grep_string[GREP_LEN]; | |
18654 | +int kdb_grepping_flag; | |
18655 | +EXPORT_SYMBOL(kdb_grepping_flag); | |
18656 | +int kdb_grep_leading; | |
18657 | +int kdb_grep_trailing; | |
18658 | + | |
18659 | +/* | |
18660 | + * Kernel debugger state flags | |
18661 | + */ | |
18662 | +volatile int kdb_flags; | |
18663 | +atomic_t kdb_event; | |
18664 | +atomic_t kdb_8250; | |
18665 | + | |
18666 | +/* | |
18667 | + * kdb_lock protects updates to kdb_initial_cpu. Used to | |
18668 | + * single thread processors through the kernel debugger. | |
18669 | + */ | |
18670 | +static DEFINE_SPINLOCK(kdb_lock); | |
18671 | +volatile int kdb_initial_cpu = -1; /* cpu number that owns kdb */ | |
18672 | +int kdb_seqno = 2; /* how many times kdb has been entered */ | |
18673 | + | |
18674 | +volatile int kdb_nextline = 1; | |
18675 | +static volatile int kdb_new_cpu; /* Which cpu to switch to */ | |
18676 | + | |
18677 | +volatile int kdb_state[NR_CPUS]; /* Per cpu state */ | |
18678 | + | |
18679 | +const struct task_struct *kdb_current_task; | |
18680 | +EXPORT_SYMBOL(kdb_current_task); | |
18681 | +struct pt_regs *kdb_current_regs; | |
18682 | + | |
18683 | +#ifdef CONFIG_KDB_OFF | |
18684 | +int kdb_on = 0; /* Default is off */ | |
18685 | +#else | |
18686 | +int kdb_on = 1; /* Default is on */ | |
18687 | +#endif /* CONFIG_KDB_OFF */ | |
18688 | + | |
18689 | +const char *kdb_diemsg; | |
18690 | +static int kdb_go_count; | |
18691 | +#ifdef CONFIG_KDB_CONTINUE_CATASTROPHIC | |
18692 | +static unsigned int kdb_continue_catastrophic = CONFIG_KDB_CONTINUE_CATASTROPHIC; | |
18693 | +#else | |
18694 | +static unsigned int kdb_continue_catastrophic = 0; | |
18695 | +#endif | |
18696 | + | |
18697 | +#ifdef kdba_setjmp | |
18698 | + /* | |
18699 | + * Must have a setjmp buffer per CPU. Switching cpus will | |
18700 | + * cause the jump buffer to be setup for the new cpu, and | |
18701 | + * subsequent switches (and pager aborts) will use the | |
18702 | + * appropriate per-processor values. | |
18703 | + */ | |
18704 | +kdb_jmp_buf *kdbjmpbuf; | |
18705 | +#endif /* kdba_setjmp */ | |
18706 | + | |
18707 | + /* | |
18708 | + * kdb_commands describes the available commands. | |
18709 | + */ | |
18710 | +static kdbtab_t *kdb_commands; | |
18711 | +static int kdb_max_commands; | |
18712 | + | |
18713 | +typedef struct _kdbmsg { | |
18714 | + int km_diag; /* kdb diagnostic */ | |
18715 | + char *km_msg; /* Corresponding message text */ | |
18716 | +} kdbmsg_t; | |
18717 | + | |
18718 | +#define KDBMSG(msgnum, text) \ | |
18719 | + { KDB_##msgnum, text } | |
18720 | + | |
18721 | +static kdbmsg_t kdbmsgs[] = { | |
18722 | + KDBMSG(NOTFOUND,"Command Not Found"), | |
18723 | + KDBMSG(ARGCOUNT, "Improper argument count, see usage."), | |
18724 | + KDBMSG(BADWIDTH, "Illegal value for BYTESPERWORD use 1, 2, 4 or 8, 8 is only allowed on 64 bit systems"), | |
18725 | + KDBMSG(BADRADIX, "Illegal value for RADIX use 8, 10 or 16"), | |
18726 | + KDBMSG(NOTENV, "Cannot find environment variable"), | |
18727 | + KDBMSG(NOENVVALUE, "Environment variable should have value"), | |
18728 | + KDBMSG(NOTIMP, "Command not implemented"), | |
18729 | + KDBMSG(ENVFULL, "Environment full"), | |
18730 | + KDBMSG(ENVBUFFULL, "Environment buffer full"), | |
18731 | + KDBMSG(TOOMANYBPT, "Too many breakpoints defined"), | |
18732 | +#ifdef CONFIG_CPU_XSCALE | |
18733 | + KDBMSG(TOOMANYDBREGS, "More breakpoints than ibcr registers defined"), | |
18734 | +#else | |
18735 | + KDBMSG(TOOMANYDBREGS, "More breakpoints than db registers defined"), | |
18736 | +#endif | |
18737 | + KDBMSG(DUPBPT, "Duplicate breakpoint address"), | |
18738 | + KDBMSG(BPTNOTFOUND, "Breakpoint not found"), | |
18739 | + KDBMSG(BADMODE, "Invalid IDMODE"), | |
18740 | + KDBMSG(BADINT, "Illegal numeric value"), | |
18741 | + KDBMSG(INVADDRFMT, "Invalid symbolic address format"), | |
18742 | + KDBMSG(BADREG, "Invalid register name"), | |
18743 | + KDBMSG(BADCPUNUM, "Invalid cpu number"), | |
18744 | + KDBMSG(BADLENGTH, "Invalid length field"), | |
18745 | + KDBMSG(NOBP, "No Breakpoint exists"), | |
18746 | + KDBMSG(BADADDR, "Invalid address"), | |
18747 | +}; | |
18748 | +#undef KDBMSG | |
18749 | + | |
18750 | +static const int __nkdb_err = sizeof(kdbmsgs) / sizeof(kdbmsg_t); | |
18751 | + | |
18752 | + | |
18753 | +/* | |
18754 | + * Initial environment. This is all kept static and local to | |
18755 | + * this file. We don't want to rely on the memory allocation | |
18756 | + * mechanisms in the kernel, so we use a very limited allocate-only | |
18757 | + * heap for new and altered environment variables. The entire | |
18758 | + * environment is limited to a fixed number of entries (add more | |
18759 | + * to __env[] if required) and a fixed amount of heap (add more to | |
18760 | + * KDB_ENVBUFSIZE if required). | |
18761 | + */ | |
18762 | + | |
18763 | +static char *__env[] = { | |
18764 | +#if defined(CONFIG_SMP) | |
18765 | + "PROMPT=[%d]kdb> ", | |
18766 | + "MOREPROMPT=[%d]more> ", | |
18767 | +#else | |
18768 | + "PROMPT=kdb> ", | |
18769 | + "MOREPROMPT=more> ", | |
18770 | +#endif | |
18771 | + "RADIX=16", | |
18772 | + "LINES=24", | |
18773 | + "COLUMNS=80", | |
18774 | + "MDCOUNT=8", /* lines of md output */ | |
18775 | + "BTARGS=9", /* 9 possible args in bt */ | |
18776 | + KDB_PLATFORM_ENV, | |
18777 | + "DTABCOUNT=30", | |
18778 | + "NOSECT=1", | |
18779 | + (char *)0, | |
18780 | + (char *)0, | |
18781 | + (char *)0, | |
18782 | + (char *)0, | |
18783 | + (char *)0, | |
18784 | + (char *)0, | |
18785 | + (char *)0, | |
18786 | + (char *)0, | |
18787 | + (char *)0, | |
18788 | + (char *)0, | |
18789 | + (char *)0, | |
18790 | + (char *)0, | |
18791 | + (char *)0, | |
18792 | + (char *)0, | |
18793 | + (char *)0, | |
18794 | + (char *)0, | |
18795 | + (char *)0, | |
18796 | + (char *)0, | |
18797 | + (char *)0, | |
18798 | + (char *)0, | |
18799 | + (char *)0, | |
18800 | + (char *)0, | |
18801 | + (char *)0, | |
18802 | +}; | |
18803 | + | |
18804 | +static const int __nenv = (sizeof(__env) / sizeof(char *)); | |
18805 | + | |
18806 | +/* external commands: */ | |
18807 | +int kdb_debuginfo_print(int argc, const char **argv); | |
18808 | +int kdb_pxhelp(int argc, const char **argv); | |
18809 | +int kdb_walkhelp(int argc, const char **argv); | |
18810 | +int kdb_walk(int argc, const char **argv); | |
18811 | + | |
18812 | +/* | |
18813 | + * kdb_serial_str is the sequence that the user must enter on a serial | |
18814 | + * console to invoke kdb. It can be a single character such as "\001" | |
18815 | + * (control-A) or multiple characters such as "\eKDB". NOTE: All except the | |
18816 | + * last character are passed through to the application reading from the serial | |
18817 | + * console. | |
18818 | + * | |
18819 | + * I tried to make the sequence a CONFIG_ option but most of CML1 cannot cope | |
18820 | + * with '\' in strings. CML2 would have been able to do it but we lost CML2. | |
18821 | + * KAO. | |
18822 | + */ | |
18823 | +const char kdb_serial_str[] = "\eKDB"; | |
18824 | +EXPORT_SYMBOL(kdb_serial_str); | |
18825 | + | |
18826 | +struct task_struct * | |
18827 | +kdb_curr_task(int cpu) | |
18828 | +{ | |
18829 | + struct task_struct *p = curr_task(cpu); | |
18830 | +#ifdef _TIF_MCA_INIT | |
18831 | + struct kdb_running_process *krp = kdb_running_process + cpu; | |
18832 | + if ((task_thread_info(p)->flags & _TIF_MCA_INIT) && krp->p) | |
18833 | + p = krp->p; | |
18834 | +#endif | |
18835 | + return p; | |
18836 | +} | |
18837 | + | |
18838 | +/* | |
18839 | + * kdbgetenv | |
18840 | + * | |
18841 | + * This function will return the character string value of | |
18842 | + * an environment variable. | |
18843 | + * | |
18844 | + * Parameters: | |
18845 | + * match A character string representing an environment variable. | |
18846 | + * Outputs: | |
18847 | + * None. | |
18848 | + * Returns: | |
18849 | + * NULL No environment variable matches 'match' | |
18850 | + * char* Pointer to string value of environment variable. | |
18851 | + * Locking: | |
18852 | + * No locking considerations required. | |
18853 | + * Remarks: | |
18854 | + */ | |
18855 | +char * | |
18856 | +kdbgetenv(const char *match) | |
18857 | +{ | |
18858 | + char **ep = __env; | |
18859 | + int matchlen = strlen(match); | |
18860 | + int i; | |
18861 | + | |
18862 | + for(i=0; i<__nenv; i++) { | |
18863 | + char *e = *ep++; | |
18864 | + | |
18865 | + if (!e) continue; | |
18866 | + | |
18867 | + if ((strncmp(match, e, matchlen) == 0) | |
18868 | + && ((e[matchlen] == '\0') | |
18869 | + ||(e[matchlen] == '='))) { | |
18870 | + char *cp = strchr(e, '='); | |
18871 | + return (cp ? ++cp :""); | |
18872 | + } | |
18873 | + } | |
18874 | + return NULL; | |
18875 | +} | |
18876 | + | |
18877 | +/* | |
18878 | + * kdballocenv | |
18879 | + * | |
18880 | + * This function is used to allocate bytes for environment entries. | |
18881 | + * | |
18882 | + * Parameters: | |
18883 | + * match A character string representing a numeric value | |
18884 | + * Outputs: | |
18885 | + * *value the unsigned long represntation of the env variable 'match' | |
18886 | + * Returns: | |
18887 | + * Zero on success, a kdb diagnostic on failure. | |
18888 | + * Locking: | |
18889 | + * No locking considerations required. Must be called with all | |
18890 | + * processors halted. | |
18891 | + * Remarks: | |
18892 | + * We use a static environment buffer (envbuffer) to hold the values | |
18893 | + * of dynamically generated environment variables (see kdb_set). Buffer | |
18894 | + * space once allocated is never free'd, so over time, the amount of space | |
18895 | + * (currently 512 bytes) will be exhausted if env variables are changed | |
18896 | + * frequently. | |
18897 | + */ | |
18898 | +static char * | |
18899 | +kdballocenv(size_t bytes) | |
18900 | +{ | |
18901 | +#define KDB_ENVBUFSIZE 512 | |
18902 | + static char envbuffer[KDB_ENVBUFSIZE]; | |
18903 | + static int envbufsize; | |
18904 | + char *ep = NULL; | |
18905 | + | |
18906 | + if ((KDB_ENVBUFSIZE - envbufsize) >= bytes) { | |
18907 | + ep = &envbuffer[envbufsize]; | |
18908 | + envbufsize += bytes; | |
18909 | + } | |
18910 | + return ep; | |
18911 | +} | |
18912 | + | |
18913 | +/* | |
18914 | + * kdbgetulenv | |
18915 | + * | |
18916 | + * This function will return the value of an unsigned long-valued | |
18917 | + * environment variable. | |
18918 | + * | |
18919 | + * Parameters: | |
18920 | + * match A character string representing a numeric value | |
18921 | + * Outputs: | |
18922 | + * *value the unsigned long represntation of the env variable 'match' | |
18923 | + * Returns: | |
18924 | + * Zero on success, a kdb diagnostic on failure. | |
18925 | + * Locking: | |
18926 | + * No locking considerations required. | |
18927 | + * Remarks: | |
18928 | + */ | |
18929 | + | |
18930 | +static int | |
18931 | +kdbgetulenv(const char *match, unsigned long *value) | |
18932 | +{ | |
18933 | + char *ep; | |
18934 | + | |
18935 | + ep = kdbgetenv(match); | |
18936 | + if (!ep) return KDB_NOTENV; | |
18937 | + if (strlen(ep) == 0) return KDB_NOENVVALUE; | |
18938 | + | |
18939 | + *value = simple_strtoul(ep, NULL, 0); | |
18940 | + | |
18941 | + return 0; | |
18942 | +} | |
18943 | + | |
18944 | +/* | |
18945 | + * kdbgetintenv | |
18946 | + * | |
18947 | + * This function will return the value of an integer-valued | |
18948 | + * environment variable. | |
18949 | + * | |
18950 | + * Parameters: | |
18951 | + * match A character string representing an integer-valued env variable | |
18952 | + * Outputs: | |
18953 | + * *value the integer representation of the environment variable 'match' | |
18954 | + * Returns: | |
18955 | + * Zero on success, a kdb diagnostic on failure. | |
18956 | + * Locking: | |
18957 | + * No locking considerations required. | |
18958 | + * Remarks: | |
18959 | + */ | |
18960 | + | |
18961 | +int | |
18962 | +kdbgetintenv(const char *match, int *value) { | |
18963 | + unsigned long val; | |
18964 | + int diag; | |
18965 | + | |
18966 | + diag = kdbgetulenv(match, &val); | |
18967 | + if (!diag) { | |
18968 | + *value = (int) val; | |
18969 | + } | |
18970 | + return diag; | |
18971 | +} | |
18972 | + | |
18973 | +/* | |
18974 | + * kdbgetularg | |
18975 | + * | |
18976 | + * This function will convert a numeric string | |
18977 | + * into an unsigned long value. | |
18978 | + * | |
18979 | + * Parameters: | |
18980 | + * arg A character string representing a numeric value | |
18981 | + * Outputs: | |
18982 | + * *value the unsigned long represntation of arg. | |
18983 | + * Returns: | |
18984 | + * Zero on success, a kdb diagnostic on failure. | |
18985 | + * Locking: | |
18986 | + * No locking considerations required. | |
18987 | + * Remarks: | |
18988 | + */ | |
18989 | + | |
18990 | +int | |
18991 | +kdbgetularg(const char *arg, unsigned long *value) | |
18992 | +{ | |
18993 | + char *endp; | |
18994 | + unsigned long val; | |
18995 | + | |
18996 | + val = simple_strtoul(arg, &endp, 0); | |
18997 | + | |
18998 | + if (endp == arg) { | |
18999 | + /* | |
19000 | + * Try base 16, for us folks too lazy to type the | |
19001 | + * leading 0x... | |
19002 | + */ | |
19003 | + val = simple_strtoul(arg, &endp, 16); | |
19004 | + if (endp == arg) | |
19005 | + return KDB_BADINT; | |
19006 | + } | |
19007 | + | |
19008 | + *value = val; | |
19009 | + | |
19010 | + return 0; | |
19011 | +} | |
19012 | + | |
19013 | +/* | |
19014 | + * kdb_set | |
19015 | + * | |
19016 | + * This function implements the 'set' command. Alter an existing | |
19017 | + * environment variable or create a new one. | |
19018 | + * | |
19019 | + * Inputs: | |
19020 | + * argc argument count | |
19021 | + * argv argument vector | |
19022 | + * Outputs: | |
19023 | + * None. | |
19024 | + * Returns: | |
19025 | + * zero for success, a kdb diagnostic if error | |
19026 | + * Locking: | |
19027 | + * none. | |
19028 | + * Remarks: | |
19029 | + */ | |
19030 | + | |
19031 | +static int | |
19032 | +kdb_set(int argc, const char **argv) | |
19033 | +{ | |
19034 | + int i; | |
19035 | + char *ep; | |
19036 | + size_t varlen, vallen; | |
19037 | + | |
19038 | + /* | |
19039 | + * we can be invoked two ways: | |
19040 | + * set var=value argv[1]="var", argv[2]="value" | |
19041 | + * set var = value argv[1]="var", argv[2]="=", argv[3]="value" | |
19042 | + * - if the latter, shift 'em down. | |
19043 | + */ | |
19044 | + if (argc == 3) { | |
19045 | + argv[2] = argv[3]; | |
19046 | + argc--; | |
19047 | + } | |
19048 | + | |
19049 | + if (argc != 2) | |
19050 | + return KDB_ARGCOUNT; | |
19051 | + | |
19052 | + /* | |
19053 | + * Check for internal variables | |
19054 | + */ | |
19055 | + if (strcmp(argv[1], "KDBDEBUG") == 0) { | |
19056 | + unsigned int debugflags; | |
19057 | + char *cp; | |
19058 | + | |
19059 | + debugflags = simple_strtoul(argv[2], &cp, 0); | |
19060 | + if (cp == argv[2] || debugflags & ~KDB_DEBUG_FLAG_MASK) { | |
19061 | + kdb_printf("kdb: illegal debug flags '%s'\n", | |
19062 | + argv[2]); | |
19063 | + return 0; | |
19064 | + } | |
19065 | + kdb_flags = (kdb_flags & ~(KDB_DEBUG_FLAG_MASK << KDB_DEBUG_FLAG_SHIFT)) | |
19066 | + | (debugflags << KDB_DEBUG_FLAG_SHIFT); | |
19067 | + | |
19068 | + return 0; | |
19069 | + } | |
19070 | + | |
19071 | + /* | |
19072 | + * Tokenizer squashed the '=' sign. argv[1] is variable | |
19073 | + * name, argv[2] = value. | |
19074 | + */ | |
19075 | + varlen = strlen(argv[1]); | |
19076 | + vallen = strlen(argv[2]); | |
19077 | + ep = kdballocenv(varlen + vallen + 2); | |
19078 | + if (ep == (char *)0) | |
19079 | + return KDB_ENVBUFFULL; | |
19080 | + | |
19081 | + sprintf(ep, "%s=%s", argv[1], argv[2]); | |
19082 | + | |
19083 | + ep[varlen+vallen+1]='\0'; | |
19084 | + | |
19085 | + for(i=0; i<__nenv; i++) { | |
19086 | + if (__env[i] | |
19087 | + && ((strncmp(__env[i], argv[1], varlen)==0) | |
19088 | + && ((__env[i][varlen] == '\0') | |
19089 | + || (__env[i][varlen] == '=')))) { | |
19090 | + __env[i] = ep; | |
19091 | + return 0; | |
19092 | + } | |
19093 | + } | |
19094 | + | |
19095 | + /* | |
19096 | + * Wasn't existing variable. Fit into slot. | |
19097 | + */ | |
19098 | + for(i=0; i<__nenv-1; i++) { | |
19099 | + if (__env[i] == (char *)0) { | |
19100 | + __env[i] = ep; | |
19101 | + return 0; | |
19102 | + } | |
19103 | + } | |
19104 | + | |
19105 | + return KDB_ENVFULL; | |
19106 | +} | |
19107 | + | |
19108 | +static int | |
19109 | +kdb_check_regs(void) | |
19110 | +{ | |
19111 | + if (!kdb_current_regs) { | |
19112 | + kdb_printf("No current kdb registers." | |
19113 | + " You may need to select another task\n"); | |
19114 | + return KDB_BADREG; | |
19115 | + } | |
19116 | + return 0; | |
19117 | +} | |
19118 | + | |
19119 | +/* | |
19120 | + * kdbgetaddrarg | |
19121 | + * | |
19122 | + * This function is responsible for parsing an | |
19123 | + * address-expression and returning the value of | |
19124 | + * the expression, symbol name, and offset to the caller. | |
19125 | + * | |
19126 | + * The argument may consist of a numeric value (decimal or | |
19127 | + * hexidecimal), a symbol name, a register name (preceeded | |
19128 | + * by the percent sign), an environment variable with a numeric | |
19129 | + * value (preceeded by a dollar sign) or a simple arithmetic | |
19130 | + * expression consisting of a symbol name, +/-, and a numeric | |
19131 | + * constant value (offset). | |
19132 | + * | |
19133 | + * Parameters: | |
19134 | + * argc - count of arguments in argv | |
19135 | + * argv - argument vector | |
19136 | + * *nextarg - index to next unparsed argument in argv[] | |
19137 | + * regs - Register state at time of KDB entry | |
19138 | + * Outputs: | |
19139 | + * *value - receives the value of the address-expression | |
19140 | + * *offset - receives the offset specified, if any | |
19141 | + * *name - receives the symbol name, if any | |
19142 | + * *nextarg - index to next unparsed argument in argv[] | |
19143 | + * | |
19144 | + * Returns: | |
19145 | + * zero is returned on success, a kdb diagnostic code is | |
19146 | + * returned on error. | |
19147 | + * | |
19148 | + * Locking: | |
19149 | + * No locking requirements. | |
19150 | + * | |
19151 | + * Remarks: | |
19152 | + * | |
19153 | + */ | |
19154 | + | |
19155 | +int | |
19156 | +kdbgetaddrarg(int argc, const char **argv, int *nextarg, | |
19157 | + kdb_machreg_t *value, long *offset, | |
19158 | + char **name) | |
19159 | +{ | |
19160 | + kdb_machreg_t addr; | |
19161 | + unsigned long off = 0; | |
19162 | + int positive; | |
19163 | + int diag; | |
19164 | + int found = 0; | |
19165 | + char *symname; | |
19166 | + char symbol = '\0'; | |
19167 | + char *cp; | |
19168 | + kdb_symtab_t symtab; | |
19169 | + | |
19170 | + /* | |
19171 | + * Process arguments which follow the following syntax: | |
19172 | + * | |
19173 | + * symbol | numeric-address [+/- numeric-offset] | |
19174 | + * %register | |
19175 | + * $environment-variable | |
19176 | + */ | |
19177 | + | |
19178 | + if (*nextarg > argc) { | |
19179 | + return KDB_ARGCOUNT; | |
19180 | + } | |
19181 | + | |
19182 | + symname = (char *)argv[*nextarg]; | |
19183 | + | |
19184 | + /* | |
19185 | + * If there is no whitespace between the symbol | |
19186 | + * or address and the '+' or '-' symbols, we | |
19187 | + * remember the character and replace it with a | |
19188 | + * null so the symbol/value can be properly parsed | |
19189 | + */ | |
19190 | + if ((cp = strpbrk(symname, "+-")) != NULL) { | |
19191 | + symbol = *cp; | |
19192 | + *cp++ = '\0'; | |
19193 | + } | |
19194 | + | |
19195 | + if (symname[0] == '$') { | |
19196 | + diag = kdbgetulenv(&symname[1], &addr); | |
19197 | + if (diag) | |
19198 | + return diag; | |
19199 | + } else if (symname[0] == '%') { | |
19200 | + if ((diag = kdb_check_regs())) | |
19201 | + return diag; | |
19202 | + diag = kdba_getregcontents(&symname[1], kdb_current_regs, &addr); | |
19203 | + if (diag) | |
19204 | + return diag; | |
19205 | + } else { | |
19206 | + found = kdbgetsymval(symname, &symtab); | |
19207 | + if (found) { | |
19208 | + addr = symtab.sym_start; | |
19209 | + } else { | |
19210 | + diag = kdbgetularg(argv[*nextarg], &addr); | |
19211 | + if (diag) | |
19212 | + return diag; | |
19213 | + } | |
19214 | + } | |
19215 | + | |
19216 | + if (!found) | |
19217 | + found = kdbnearsym(addr, &symtab); | |
19218 | + | |
19219 | + (*nextarg)++; | |
19220 | + | |
19221 | + if (name) | |
19222 | + *name = symname; | |
19223 | + if (value) | |
19224 | + *value = addr; | |
19225 | + if (offset && name && *name) | |
19226 | + *offset = addr - symtab.sym_start; | |
19227 | + | |
19228 | + if ((*nextarg > argc) | |
19229 | + && (symbol == '\0')) | |
19230 | + return 0; | |
19231 | + | |
19232 | + /* | |
19233 | + * check for +/- and offset | |
19234 | + */ | |
19235 | + | |
19236 | + if (symbol == '\0') { | |
19237 | + if ((argv[*nextarg][0] != '+') | |
19238 | + && (argv[*nextarg][0] != '-')) { | |
19239 | + /* | |
19240 | + * Not our argument. Return. | |
19241 | + */ | |
19242 | + return 0; | |
19243 | + } else { | |
19244 | + positive = (argv[*nextarg][0] == '+'); | |
19245 | + (*nextarg)++; | |
19246 | + } | |
19247 | + } else | |
19248 | + positive = (symbol == '+'); | |
19249 | + | |
19250 | + /* | |
19251 | + * Now there must be an offset! | |
19252 | + */ | |
19253 | + if ((*nextarg > argc) | |
19254 | + && (symbol == '\0')) { | |
19255 | + return KDB_INVADDRFMT; | |
19256 | + } | |
19257 | + | |
19258 | + if (!symbol) { | |
19259 | + cp = (char *)argv[*nextarg]; | |
19260 | + (*nextarg)++; | |
19261 | + } | |
19262 | + | |
19263 | + diag = kdbgetularg(cp, &off); | |
19264 | + if (diag) | |
19265 | + return diag; | |
19266 | + | |
19267 | + if (!positive) | |
19268 | + off = -off; | |
19269 | + | |
19270 | + if (offset) | |
19271 | + *offset += off; | |
19272 | + | |
19273 | + if (value) | |
19274 | + *value += off; | |
19275 | + | |
19276 | + return 0; | |
19277 | +} | |
19278 | + | |
19279 | +static void | |
19280 | +kdb_cmderror(int diag) | |
19281 | +{ | |
19282 | + int i; | |
19283 | + | |
19284 | + if (diag >= 0) { | |
19285 | + kdb_printf("no error detected (diagnostic is %d)\n", diag); | |
19286 | + return; | |
19287 | + } | |
19288 | + | |
19289 | + for(i=0; i<__nkdb_err; i++) { | |
19290 | + if (kdbmsgs[i].km_diag == diag) { | |
19291 | + kdb_printf("diag: %d: %s\n", diag, kdbmsgs[i].km_msg); | |
19292 | + return; | |
19293 | + } | |
19294 | + } | |
19295 | + | |
19296 | + kdb_printf("Unknown diag %d\n", -diag); | |
19297 | +} | |
19298 | + | |
19299 | +/* | |
19300 | + * kdb_defcmd, kdb_defcmd2 | |
19301 | + * | |
19302 | + * This function implements the 'defcmd' command which defines one | |
19303 | + * command as a set of other commands, terminated by endefcmd. | |
19304 | + * kdb_defcmd processes the initial 'defcmd' command, kdb_defcmd2 | |
19305 | + * is invoked from kdb_parse for the following commands until | |
19306 | + * 'endefcmd'. | |
19307 | + * | |
19308 | + * Inputs: | |
19309 | + * argc argument count | |
19310 | + * argv argument vector | |
19311 | + * Outputs: | |
19312 | + * None. | |
19313 | + * Returns: | |
19314 | + * zero for success, a kdb diagnostic if error | |
19315 | + * Locking: | |
19316 | + * none. | |
19317 | + * Remarks: | |
19318 | + */ | |
19319 | + | |
19320 | +struct defcmd_set { | |
19321 | + int count; | |
19322 | + int usable; | |
19323 | + char *name; | |
19324 | + char *usage; | |
19325 | + char *help; | |
19326 | + char **command; | |
19327 | +}; | |
19328 | +static struct defcmd_set *defcmd_set; | |
19329 | +static int defcmd_set_count; | |
19330 | +static int defcmd_in_progress; | |
19331 | + | |
19332 | +/* Forward references */ | |
19333 | +static int kdb_exec_defcmd(int argc, const char **argv); | |
19334 | + | |
19335 | +static int | |
19336 | +kdb_defcmd2(const char *cmdstr, const char *argv0) | |
19337 | +{ | |
19338 | + struct defcmd_set *s = defcmd_set + defcmd_set_count - 1; | |
19339 | + char **save_command = s->command; | |
19340 | + if (strcmp(argv0, "endefcmd") == 0) { | |
19341 | + defcmd_in_progress = 0; | |
19342 | + if (!s->count) | |
19343 | + s->usable = 0; | |
19344 | + if (s->usable) | |
19345 | + kdb_register(s->name, kdb_exec_defcmd, s->usage, s->help, 0); | |
19346 | + return 0; | |
19347 | + } | |
19348 | + if (!s->usable) | |
19349 | + return KDB_NOTIMP; | |
19350 | + s->command = kmalloc((s->count + 1) * sizeof(*(s->command)), GFP_KDB); | |
19351 | + if (!s->command) { | |
19352 | + kdb_printf("Could not allocate new kdb_defcmd table for %s\n", cmdstr); | |
19353 | + s->usable = 0; | |
19354 | + return KDB_NOTIMP; | |
19355 | + } | |
19356 | + memcpy(s->command, save_command, s->count * sizeof(*(s->command))); | |
19357 | + s->command[s->count++] = kdb_strdup(cmdstr, GFP_KDB); | |
19358 | + kfree(save_command); | |
19359 | + return 0; | |
19360 | +} | |
19361 | + | |
19362 | +static int | |
19363 | +kdb_defcmd(int argc, const char **argv) | |
19364 | +{ | |
19365 | + struct defcmd_set *save_defcmd_set = defcmd_set, *s; | |
19366 | + if (defcmd_in_progress) { | |
19367 | + kdb_printf("kdb: nested defcmd detected, assuming missing endefcmd\n"); | |
19368 | + kdb_defcmd2("endefcmd", "endefcmd"); | |
19369 | + } | |
19370 | + if (argc == 0) { | |
19371 | + int i; | |
19372 | + for (s = defcmd_set; s < defcmd_set + defcmd_set_count; ++s) { | |
19373 | + kdb_printf("defcmd %s \"%s\" \"%s\"\n", s->name, s->usage, s->help); | |
19374 | + for (i = 0; i < s->count; ++i) | |
19375 | + kdb_printf("%s", s->command[i]); | |
19376 | + kdb_printf("endefcmd\n"); | |
19377 | + } | |
19378 | + return 0; | |
19379 | + } | |
19380 | + if (argc != 3) | |
19381 | + return KDB_ARGCOUNT; | |
19382 | + defcmd_set = kmalloc((defcmd_set_count + 1) * sizeof(*defcmd_set), GFP_KDB); | |
19383 | + if (!defcmd_set) { | |
19384 | + kdb_printf("Could not allocate new defcmd_set entry for %s\n", argv[1]); | |
19385 | + defcmd_set = save_defcmd_set; | |
19386 | + return KDB_NOTIMP; | |
19387 | + } | |
19388 | + memcpy(defcmd_set, save_defcmd_set, defcmd_set_count * sizeof(*defcmd_set)); | |
19389 | + kfree(save_defcmd_set); | |
19390 | + s = defcmd_set + defcmd_set_count; | |
19391 | + memset(s, 0, sizeof(*s)); | |
19392 | + s->usable = 1; | |
19393 | + s->name = kdb_strdup(argv[1], GFP_KDB); | |
19394 | + s->usage = kdb_strdup(argv[2], GFP_KDB); | |
19395 | + s->help = kdb_strdup(argv[3], GFP_KDB); | |
19396 | + if (s->usage[0] == '"') { | |
19397 | + strcpy(s->usage, s->usage+1); | |
19398 | + s->usage[strlen(s->usage)-1] = '\0'; | |
19399 | + } | |
19400 | + if (s->help[0] == '"') { | |
19401 | + strcpy(s->help, s->help+1); | |
19402 | + s->help[strlen(s->help)-1] = '\0'; | |
19403 | + } | |
19404 | + ++defcmd_set_count; | |
19405 | + defcmd_in_progress = 1; | |
19406 | + return 0; | |
19407 | +} | |
19408 | + | |
19409 | +/* | |
19410 | + * kdb_exec_defcmd | |
19411 | + * | |
19412 | + * Execute the set of commands associated with this defcmd name. | |
19413 | + * | |
19414 | + * Inputs: | |
19415 | + * argc argument count | |
19416 | + * argv argument vector | |
19417 | + * Outputs: | |
19418 | + * None. | |
19419 | + * Returns: | |
19420 | + * zero for success, a kdb diagnostic if error | |
19421 | + * Locking: | |
19422 | + * none. | |
19423 | + * Remarks: | |
19424 | + */ | |
19425 | + | |
19426 | +static int | |
19427 | +kdb_exec_defcmd(int argc, const char **argv) | |
19428 | +{ | |
19429 | + int i, ret; | |
19430 | + struct defcmd_set *s; | |
19431 | + if (argc != 0) | |
19432 | + return KDB_ARGCOUNT; | |
19433 | + for (s = defcmd_set, i = 0; i < defcmd_set_count; ++i, ++s) { | |
19434 | + if (strcmp(s->name, argv[0]) == 0) | |
19435 | + break; | |
19436 | + } | |
19437 | + if (i == defcmd_set_count) { | |
19438 | + kdb_printf("kdb_exec_defcmd: could not find commands for %s\n", argv[0]); | |
19439 | + return KDB_NOTIMP; | |
19440 | + } | |
19441 | + for (i = 0; i < s->count; ++i) { | |
19442 | + /* Recursive use of kdb_parse, do not use argv after this point */ | |
19443 | + argv = NULL; | |
19444 | + kdb_printf("[%s]kdb> %s\n", s->name, s->command[i]); | |
19445 | + if ((ret = kdb_parse(s->command[i]))) | |
19446 | + return ret; | |
19447 | + } | |
19448 | + return 0; | |
19449 | +} | |
19450 | + | |
19451 | +/* Command history */ | |
19452 | +#define KDB_CMD_HISTORY_COUNT 32 | |
19453 | +#define CMD_BUFLEN 200 /* kdb_printf: max printline size == 256 */ | |
19454 | +static unsigned int cmd_head=0, cmd_tail=0; | |
19455 | +static unsigned int cmdptr; | |
19456 | +static char cmd_hist[KDB_CMD_HISTORY_COUNT][CMD_BUFLEN]; | |
19457 | +static char cmd_cur[CMD_BUFLEN]; | |
19458 | + | |
19459 | +/* | |
19460 | + * The "str" argument may point to something like | grep xyz | |
19461 | + * | |
19462 | + */ | |
19463 | +static void | |
19464 | +parse_grep(const char *str) | |
19465 | +{ | |
19466 | + int len; | |
19467 | + char *cp = (char *)str, *cp2; | |
19468 | + | |
19469 | + /* sanity check: we should have been called with the \ first */ | |
19470 | + if (*cp != '|') | |
19471 | + return; | |
19472 | + cp++; | |
19473 | + while (isspace(*cp)) cp++; | |
19474 | + if (strncmp(cp,"grep ",5)) { | |
19475 | + kdb_printf ("invalid 'pipe', see grephelp\n"); | |
19476 | + return; | |
19477 | + } | |
19478 | + cp += 5; | |
19479 | + while (isspace(*cp)) cp++; | |
19480 | + cp2 = strchr(cp, '\n'); | |
19481 | + if (cp2) | |
19482 | + *cp2 = '\0'; /* remove the trailing newline */ | |
19483 | + len = strlen(cp); | |
19484 | + if (len == 0) { | |
19485 | + kdb_printf ("invalid 'pipe', see grephelp\n"); | |
19486 | + return; | |
19487 | + } | |
19488 | + /* now cp points to a nonzero length search string */ | |
19489 | + if (*cp == '"') { | |
19490 | + /* allow it be "x y z" by removing the "'s - there must | |
19491 | + be two of them */ | |
19492 | + cp++; | |
19493 | + cp2 = strchr(cp, '"'); | |
19494 | + if (!cp2) { | |
19495 | + kdb_printf ("invalid quoted string, see grephelp\n"); | |
19496 | + return; | |
19497 | + } | |
19498 | + *cp2 = '\0'; /* end the string where the 2nd " was */ | |
19499 | + } | |
19500 | + kdb_grep_leading = 0; | |
19501 | + if (*cp == '^') { | |
19502 | + kdb_grep_leading = 1; | |
19503 | + cp++; | |
19504 | + } | |
19505 | + len = strlen(cp); | |
19506 | + kdb_grep_trailing = 0; | |
19507 | + if (*(cp+len-1) == '$') { | |
19508 | + kdb_grep_trailing = 1; | |
19509 | + *(cp+len-1) = '\0'; | |
19510 | + } | |
19511 | + len = strlen(cp); | |
19512 | + if (!len) return; | |
19513 | + if (len >= GREP_LEN) { | |
19514 | + kdb_printf ("search string too long\n"); | |
19515 | + return; | |
19516 | + } | |
19517 | + strcpy(kdb_grep_string, cp); | |
19518 | + kdb_grepping_flag++; | |
19519 | + return; | |
19520 | +} | |
19521 | + | |
19522 | +/* | |
19523 | + * kdb_parse | |
19524 | + * | |
19525 | + * Parse the command line, search the command table for a | |
19526 | + * matching command and invoke the command function. | |
19527 | + * This function may be called recursively, if it is, the second call | |
19528 | + * will overwrite argv and cbuf. It is the caller's responsibility to | |
19529 | + * save their argv if they recursively call kdb_parse(). | |
19530 | + * | |
19531 | + * Parameters: | |
19532 | + * cmdstr The input command line to be parsed. | |
19533 | + * regs The registers at the time kdb was entered. | |
19534 | + * Outputs: | |
19535 | + * None. | |
19536 | + * Returns: | |
19537 | + * Zero for success, a kdb diagnostic if failure. | |
19538 | + * Locking: | |
19539 | + * None. | |
19540 | + * Remarks: | |
19541 | + * Limited to 20 tokens. | |
19542 | + * | |
19543 | + * Real rudimentary tokenization. Basically only whitespace | |
19544 | + * is considered a token delimeter (but special consideration | |
19545 | + * is taken of the '=' sign as used by the 'set' command). | |
19546 | + * | |
19547 | + * The algorithm used to tokenize the input string relies on | |
19548 | + * there being at least one whitespace (or otherwise useless) | |
19549 | + * character between tokens as the character immediately following | |
19550 | + * the token is altered in-place to a null-byte to terminate the | |
19551 | + * token string. | |
19552 | + */ | |
19553 | + | |
19554 | +#define MAXARGC 20 | |
19555 | + | |
19556 | +int | |
19557 | +kdb_parse(const char *cmdstr) | |
19558 | +{ | |
19559 | + static char *argv[MAXARGC]; | |
19560 | + static int argc = 0; | |
19561 | + static char cbuf[CMD_BUFLEN+2]; | |
19562 | + char *cp; | |
19563 | + char *cpp, quoted; | |
19564 | + kdbtab_t *tp; | |
19565 | + int i, escaped, ignore_errors = 0, check_grep; | |
19566 | + | |
19567 | + /* | |
19568 | + * First tokenize the command string. | |
19569 | + */ | |
19570 | + cp = (char *)cmdstr; | |
19571 | + kdb_grepping_flag = check_grep = 0; | |
19572 | + | |
19573 | + if (KDB_FLAG(CMD_INTERRUPT)) { | |
19574 | + /* Previous command was interrupted, newline must not repeat the command */ | |
19575 | + KDB_FLAG_CLEAR(CMD_INTERRUPT); | |
19576 | + argc = 0; /* no repeat */ | |
19577 | + } | |
19578 | + | |
19579 | + if (*cp != '\n' && *cp != '\0') { | |
19580 | + argc = 0; | |
19581 | + cpp = cbuf; | |
19582 | + while (*cp) { | |
19583 | + /* skip whitespace */ | |
19584 | + while (isspace(*cp)) cp++; | |
19585 | + if ((*cp == '\0') || (*cp == '\n') || (*cp == '#' && !defcmd_in_progress)) | |
19586 | + break; | |
19587 | + /* special case: check for | grep pattern */ | |
19588 | + if (*cp == '|') { | |
19589 | + check_grep++; | |
19590 | + break; | |
19591 | + } | |
19592 | + if (cpp >= cbuf + CMD_BUFLEN) { | |
19593 | + kdb_printf("kdb_parse: command buffer overflow, command ignored\n%s\n", cmdstr); | |
19594 | + return KDB_NOTFOUND; | |
19595 | + } | |
19596 | + if (argc >= MAXARGC - 1) { | |
19597 | + kdb_printf("kdb_parse: too many arguments, command ignored\n%s\n", cmdstr); | |
19598 | + return KDB_NOTFOUND; | |
19599 | + } | |
19600 | + argv[argc++] = cpp; | |
19601 | + escaped = 0; | |
19602 | + quoted = '\0'; | |
19603 | + /* Copy to next unquoted and unescaped whitespace or '=' */ | |
19604 | + while (*cp && *cp != '\n' && (escaped || quoted || !isspace(*cp))) { | |
19605 | + if (cpp >= cbuf + CMD_BUFLEN) | |
19606 | + break; | |
19607 | + if (escaped) { | |
19608 | + escaped = 0; | |
19609 | + *cpp++ = *cp++; | |
19610 | + continue; | |
19611 | + } | |
19612 | + if (*cp == '\\') { | |
19613 | + escaped = 1; | |
19614 | + ++cp; | |
19615 | + continue; | |
19616 | + } | |
19617 | + if (*cp == quoted) { | |
19618 | + quoted = '\0'; | |
19619 | + } else if (*cp == '\'' || *cp == '"') { | |
19620 | + quoted = *cp; | |
19621 | + } | |
19622 | + if ((*cpp = *cp++) == '=' && !quoted) | |
19623 | + break; | |
19624 | + ++cpp; | |
19625 | + } | |
19626 | + *cpp++ = '\0'; /* Squash a ws or '=' character */ | |
19627 | + } | |
19628 | + } | |
19629 | + if (!argc) | |
19630 | + return 0; | |
19631 | + if (check_grep) | |
19632 | + parse_grep(cp); | |
19633 | + if (defcmd_in_progress) { | |
19634 | + int result = kdb_defcmd2(cmdstr, argv[0]); | |
19635 | + if (!defcmd_in_progress) { | |
19636 | + argc = 0; /* avoid repeat on endefcmd */ | |
19637 | + *(argv[0]) = '\0'; | |
19638 | + } | |
19639 | + return result; | |
19640 | + } | |
19641 | + if (argv[0][0] == '-' && argv[0][1] && (argv[0][1] < '0' || argv[0][1] > '9')) { | |
19642 | + ignore_errors = 1; | |
19643 | + ++argv[0]; | |
19644 | + } | |
19645 | + | |
19646 | + for(tp=kdb_commands, i=0; i < kdb_max_commands; i++,tp++) { | |
19647 | + if (tp->cmd_name) { | |
19648 | + /* | |
19649 | + * If this command is allowed to be abbreviated, | |
19650 | + * check to see if this is it. | |
19651 | + */ | |
19652 | + | |
19653 | + if (tp->cmd_minlen | |
19654 | + && (strlen(argv[0]) <= tp->cmd_minlen)) { | |
19655 | + if (strncmp(argv[0], | |
19656 | + tp->cmd_name, | |
19657 | + tp->cmd_minlen) == 0) { | |
19658 | + break; | |
19659 | + } | |
19660 | + } | |
19661 | + | |
19662 | + if (strcmp(argv[0], tp->cmd_name)==0) { | |
19663 | + break; | |
19664 | + } | |
19665 | + } | |
19666 | + } | |
19667 | + | |
19668 | + /* | |
19669 | + * If we don't find a command by this name, see if the first | |
19670 | + * few characters of this match any of the known commands. | |
19671 | + * e.g., md1c20 should match md. | |
19672 | + */ | |
19673 | + if (i == kdb_max_commands) { | |
19674 | + for(tp=kdb_commands, i=0; i < kdb_max_commands; i++,tp++) { | |
19675 | + if (tp->cmd_name) { | |
19676 | + if (strncmp(argv[0], | |
19677 | + tp->cmd_name, | |
19678 | + strlen(tp->cmd_name))==0) { | |
19679 | + break; | |
19680 | + } | |
19681 | + } | |
19682 | + } | |
19683 | + } | |
19684 | + | |
19685 | + if (i < kdb_max_commands) { | |
19686 | + int result; | |
19687 | + KDB_STATE_SET(CMD); | |
19688 | + result = (*tp->cmd_func)(argc-1, | |
19689 | + (const char**)argv); | |
19690 | + if (result && ignore_errors && result > KDB_CMD_GO) | |
19691 | + result = 0; | |
19692 | + KDB_STATE_CLEAR(CMD); | |
19693 | + switch (tp->cmd_repeat) { | |
19694 | + case KDB_REPEAT_NONE: | |
19695 | + argc = 0; | |
19696 | + if (argv[0]) | |
19697 | + *(argv[0]) = '\0'; | |
19698 | + break; | |
19699 | + case KDB_REPEAT_NO_ARGS: | |
19700 | + argc = 1; | |
19701 | + if (argv[1]) | |
19702 | + *(argv[1]) = '\0'; | |
19703 | + break; | |
19704 | + case KDB_REPEAT_WITH_ARGS: | |
19705 | + break; | |
19706 | + } | |
19707 | + return result; | |
19708 | + } | |
19709 | + | |
19710 | + /* | |
19711 | + * If the input with which we were presented does not | |
19712 | + * map to an existing command, attempt to parse it as an | |
19713 | + * address argument and display the result. Useful for | |
19714 | + * obtaining the address of a variable, or the nearest symbol | |
19715 | + * to an address contained in a register. | |
19716 | + */ | |
19717 | + { | |
19718 | + kdb_machreg_t value; | |
19719 | + char *name = NULL; | |
19720 | + long offset; | |
19721 | + int nextarg = 0; | |
19722 | + | |
19723 | + if (kdbgetaddrarg(0, (const char **)argv, &nextarg, | |
19724 | + &value, &offset, &name)) { | |
19725 | + return KDB_NOTFOUND; | |
19726 | + } | |
19727 | + | |
19728 | + kdb_printf("%s = ", argv[0]); | |
19729 | + kdb_symbol_print(value, NULL, KDB_SP_DEFAULT); | |
19730 | + kdb_printf("\n"); | |
19731 | + return 0; | |
19732 | + } | |
19733 | +} | |
19734 | + | |
19735 | + | |
19736 | +static int | |
19737 | +handle_ctrl_cmd(char *cmd) | |
19738 | +{ | |
19739 | +#define CTRL_P 16 | |
19740 | +#define CTRL_N 14 | |
19741 | + | |
19742 | + /* initial situation */ | |
19743 | + if (cmd_head == cmd_tail) return 0; | |
19744 | + | |
19745 | + switch(*cmd) { | |
19746 | + case CTRL_P: | |
19747 | + if (cmdptr != cmd_tail) | |
19748 | + cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT; | |
19749 | + strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); | |
19750 | + return 1; | |
19751 | + case CTRL_N: | |
19752 | + if (cmdptr != cmd_head) | |
19753 | + cmdptr = (cmdptr+1) % KDB_CMD_HISTORY_COUNT; | |
19754 | + strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); | |
19755 | + return 1; | |
19756 | + } | |
19757 | + return 0; | |
19758 | +} | |
19759 | + | |
19760 | +/* | |
19761 | + * kdb_do_dump | |
19762 | + * | |
19763 | + * Call the dump() function if the kernel is configured for LKCD. | |
19764 | + * Inputs: | |
19765 | + * None. | |
19766 | + * Outputs: | |
19767 | + * None. | |
19768 | + * Returns: | |
19769 | + * None. dump() may or may not return. | |
19770 | + * Locking: | |
19771 | + * none. | |
19772 | + * Remarks: | |
19773 | + */ | |
19774 | + | |
19775 | +static void | |
19776 | +kdb_do_dump(void) | |
19777 | +{ | |
19778 | +#if defined(CONFIG_LKCD_DUMP) || defined(CONFIG_LKCD_DUMP_MODULE) | |
19779 | + kdb_printf("Forcing dump (if configured)\n"); | |
19780 | + console_loglevel = 8; /* to see the dump messages */ | |
19781 | + dump("kdb_do_dump"); | |
19782 | +#endif | |
19783 | +} | |
19784 | + | |
19785 | +/* | |
19786 | + * kdb_reboot | |
19787 | + * | |
19788 | + * This function implements the 'reboot' command. Reboot the system | |
19789 | + * immediately. | |
19790 | + * | |
19791 | + * Inputs: | |
19792 | + * argc argument count | |
19793 | + * argv argument vector | |
19794 | + * Outputs: | |
19795 | + * None. | |
19796 | + * Returns: | |
19797 | + * zero for success, a kdb diagnostic if error | |
19798 | + * Locking: | |
19799 | + * none. | |
19800 | + * Remarks: | |
19801 | + * Shouldn't return from this function. | |
19802 | + */ | |
19803 | + | |
19804 | +static int | |
19805 | +kdb_reboot(int argc, const char **argv) | |
19806 | +{ | |
19807 | + emergency_restart(); | |
19808 | + kdb_printf("Hmm, kdb_reboot did not reboot, spinning here\n"); | |
19809 | + while (1) {}; | |
19810 | + /* NOTREACHED */ | |
19811 | + return 0; | |
19812 | +} | |
19813 | + | |
19814 | +#ifdef CONFIG_KDB_KDUMP | |
19815 | + | |
19816 | +int kdb_kdump_state = KDB_KDUMP_RESET; /* KDB kdump state */ | |
19817 | + | |
19818 | +static int kdb_cpu(int argc, const char **argv); | |
19819 | + | |
19820 | +/* | |
19821 | + * kdb_kdump_check | |
19822 | + * | |
19823 | + * This is where the kdump on monarch cpu is handled. | |
19824 | + * | |
19825 | + */ | |
19826 | +void kdb_kdump_check(struct pt_regs *regs) | |
19827 | +{ | |
19828 | + if (kdb_kdump_state != KDB_KDUMP_RESET) { | |
19829 | + crash_kexec(regs); | |
19830 | + | |
19831 | + /* If the call above returned then something | |
19832 | + didn't work */ | |
19833 | + kdb_printf("kdb_kdump_check: crash_kexec failed!\n"); | |
19834 | + kdb_printf(" Please check if the kdump kernel has been properly loaded\n"); | |
19835 | + kdb_kdump_state = KDB_KDUMP_RESET; | |
19836 | + } | |
19837 | +} | |
19838 | + | |
19839 | + | |
19840 | +/* | |
19841 | + * kdb_kdump | |
19842 | + * | |
19843 | + * This function implements the 'kdump' command. | |
19844 | + * | |
19845 | + * Inputs: | |
19846 | + * argc argument count | |
19847 | + * argv argument vector | |
19848 | + * envp environment vector | |
19849 | + * regs registers at time kdb was entered. | |
19850 | + * Outputs: | |
19851 | + * None. | |
19852 | + * Returns: | |
19853 | + * zero for success, a kdb diagnostic if error | |
19854 | + * Locking: | |
19855 | + * none. | |
19856 | + * Remarks: | |
19857 | + * Shouldn't return from this function. | |
19858 | + */ | |
19859 | + | |
19860 | +static int | |
19861 | +kdb_kdump(int argc, const char **argv) | |
19862 | +{ | |
19863 | + char cpu_id[6]; /* up to 99,999 cpus */ | |
19864 | + const char *cpu_argv[] = {NULL, cpu_id, NULL}; | |
19865 | + int ret; | |
19866 | + | |
19867 | + kdb_kdump_state = KDB_KDUMP_KDUMP; | |
19868 | + /* Switch back to the initial cpu before process kdump command */ | |
19869 | + if (smp_processor_id() != kdb_initial_cpu) { | |
19870 | + sprintf(cpu_id, "%d", kdb_initial_cpu); | |
19871 | + ret = kdb_cpu(1, cpu_argv); | |
19872 | + if (ret != KDB_CMD_CPU) { | |
19873 | + kdb_printf("kdump: Failed to switch to initial cpu %d;" | |
19874 | + " aborted\n", kdb_initial_cpu); | |
19875 | + kdb_kdump_state = KDB_KDUMP_RESET; | |
19876 | + } | |
19877 | + } else | |
19878 | + ret = KDB_CMD_CPU; | |
19879 | + | |
19880 | + return ret; | |
19881 | +} | |
19882 | + | |
19883 | +#endif /* CONFIG_KDB_KDUMP */ | |
19884 | + | |
19885 | +static int | |
19886 | +kdb_quiet(int reason) | |
19887 | +{ | |
19888 | + return (reason == KDB_REASON_CPU_UP || reason == KDB_REASON_SILENT); | |
19889 | +} | |
19890 | + | |
19891 | +/* | |
19892 | + * kdb_local | |
19893 | + * | |
19894 | + * The main code for kdb. This routine is invoked on a specific | |
19895 | + * processor, it is not global. The main kdb() routine ensures | |
19896 | + * that only one processor at a time is in this routine. This | |
19897 | + * code is called with the real reason code on the first entry | |
19898 | + * to a kdb session, thereafter it is called with reason SWITCH, | |
19899 | + * even if the user goes back to the original cpu. | |
19900 | + * | |
19901 | + * Inputs: | |
19902 | + * reason The reason KDB was invoked | |
19903 | + * error The hardware-defined error code | |
19904 | + * regs The exception frame at time of fault/breakpoint. NULL | |
19905 | + * for reason SILENT or CPU_UP, otherwise valid. | |
19906 | + * db_result Result code from the break or debug point. | |
19907 | + * Returns: | |
19908 | + * 0 KDB was invoked for an event which it wasn't responsible | |
19909 | + * 1 KDB handled the event for which it was invoked. | |
19910 | + * KDB_CMD_GO User typed 'go'. | |
19911 | + * KDB_CMD_CPU User switched to another cpu. | |
19912 | + * KDB_CMD_SS Single step. | |
19913 | + * KDB_CMD_SSB Single step until branch. | |
19914 | + * Locking: | |
19915 | + * none | |
19916 | + * Remarks: | |
19917 | + * none | |
19918 | + */ | |
19919 | + | |
19920 | +static int | |
19921 | +kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs, kdb_dbtrap_t db_result) | |
19922 | +{ | |
19923 | + char *cmdbuf; | |
19924 | + int diag; | |
19925 | + struct task_struct *kdb_current = kdb_curr_task(smp_processor_id()); | |
19926 | + | |
19927 | +#ifdef CONFIG_KDB_KDUMP | |
19928 | + kdb_kdump_check(regs); | |
19929 | +#endif | |
19930 | + | |
19931 | + /* If kdb has been entered for an event which has been/will be | |
19932 | + * recovered then silently return. We have to get this far into kdb in | |
19933 | + * order to synchronize all the cpus, typically only one cpu (monarch) | |
19934 | + * knows that the event is recoverable but the other cpus (slaves) may | |
19935 | + * also be driven into kdb before that decision is made by the monarch. | |
19936 | + * | |
19937 | + * To pause in kdb even for recoverable events, 'set RECOVERY_PAUSE 1' | |
19938 | + */ | |
19939 | + KDB_DEBUG_STATE("kdb_local 1", reason); | |
19940 | + if (reason == KDB_REASON_ENTER | |
19941 | + && KDB_FLAG(RECOVERY) | |
19942 | + && !KDB_FLAG(CATASTROPHIC)) { | |
19943 | + int recovery_pause = 0; | |
19944 | + kdbgetintenv("RECOVERY_PAUSE", &recovery_pause); | |
19945 | + if (recovery_pause == 0) | |
19946 | + reason = KDB_REASON_SILENT; | |
19947 | + else | |
19948 | + kdb_printf("%s: Recoverable error detected but" | |
19949 | + " RECOVERY_PAUSE is set, staying in KDB\n", | |
19950 | + __FUNCTION__); | |
19951 | + } | |
19952 | + | |
19953 | + KDB_DEBUG_STATE("kdb_local 2", reason); | |
19954 | + kdb_go_count = 0; | |
19955 | + if (kdb_quiet(reason)) { | |
19956 | + /* no message */ | |
19957 | + } else if (reason == KDB_REASON_DEBUG) { | |
19958 | + /* special case below */ | |
19959 | + } else { | |
19960 | + kdb_printf("\nEntering kdb (current=0x%p, pid %d) ", kdb_current, kdb_current->pid); | |
19961 | +#if defined(CONFIG_SMP) | |
19962 | + kdb_printf("on processor %d ", smp_processor_id()); | |
19963 | +#endif | |
19964 | + } | |
19965 | + | |
19966 | + switch (reason) { | |
19967 | + case KDB_REASON_DEBUG: | |
19968 | + { | |
19969 | + /* | |
19970 | + * If re-entering kdb after a single step | |
19971 | + * command, don't print the message. | |
19972 | + */ | |
19973 | + switch(db_result) { | |
19974 | + case KDB_DB_BPT: | |
19975 | + kdb_printf("\nEntering kdb (0x%p, pid %d) ", kdb_current, kdb_current->pid); | |
19976 | +#if defined(CONFIG_SMP) | |
19977 | + kdb_printf("on processor %d ", smp_processor_id()); | |
19978 | +#endif | |
19979 | + kdb_printf("due to Debug @ " kdb_machreg_fmt "\n", kdba_getpc(regs)); | |
19980 | + break; | |
19981 | + case KDB_DB_SSB: | |
19982 | + /* | |
19983 | + * In the midst of ssb command. Just return. | |
19984 | + */ | |
19985 | + KDB_DEBUG_STATE("kdb_local 3", reason); | |
19986 | + return KDB_CMD_SSB; /* Continue with SSB command */ | |
19987 | + | |
19988 | + break; | |
19989 | + case KDB_DB_SS: | |
19990 | + break; | |
19991 | + case KDB_DB_SSBPT: | |
19992 | + KDB_DEBUG_STATE("kdb_local 4", reason); | |
19993 | + return 1; /* kdba_db_trap did the work */ | |
19994 | + default: | |
19995 | + kdb_printf("kdb: Bad result from kdba_db_trap: %d\n", | |
19996 | + db_result); | |
19997 | + break; | |
19998 | + } | |
19999 | + | |
20000 | + } | |
20001 | + break; | |
20002 | + case KDB_REASON_ENTER: | |
20003 | + if (KDB_STATE(KEYBOARD)) | |
20004 | + kdb_printf("due to Keyboard Entry\n"); | |
20005 | + else { | |
20006 | + kdb_printf("due to KDB_ENTER()\n"); | |
20007 | + } | |
20008 | + break; | |
20009 | + case KDB_REASON_KEYBOARD: | |
20010 | + KDB_STATE_SET(KEYBOARD); | |
20011 | + kdb_printf("due to Keyboard Entry\n"); | |
20012 | + break; | |
20013 | + case KDB_REASON_ENTER_SLAVE: /* drop through, slaves only get released via cpu switch */ | |
20014 | + case KDB_REASON_SWITCH: | |
20015 | + kdb_printf("due to cpu switch\n"); | |
20016 | + if (KDB_STATE(GO_SWITCH)) { | |
20017 | + KDB_STATE_CLEAR(GO_SWITCH); | |
20018 | + KDB_DEBUG_STATE("kdb_local 5", reason); | |
20019 | + return KDB_CMD_GO; | |
20020 | + } | |
20021 | + break; | |
20022 | + case KDB_REASON_OOPS: | |
20023 | + kdb_printf("Oops: %s\n", kdb_diemsg); | |
20024 | + kdb_printf("due to oops @ " kdb_machreg_fmt "\n", kdba_getpc(regs)); | |
20025 | + kdba_dumpregs(regs, NULL, NULL); | |
20026 | + break; | |
20027 | + case KDB_REASON_NMI: | |
20028 | + kdb_printf("due to NonMaskable Interrupt @ " kdb_machreg_fmt "\n", | |
20029 | + kdba_getpc(regs)); | |
20030 | + kdba_dumpregs(regs, NULL, NULL); | |
20031 | + break; | |
20032 | + case KDB_REASON_BREAK: | |
20033 | + kdb_printf("due to Breakpoint @ " kdb_machreg_fmt "\n", kdba_getpc(regs)); | |
20034 | + /* | |
20035 | + * Determine if this breakpoint is one that we | |
20036 | + * are interested in. | |
20037 | + */ | |
20038 | + if (db_result != KDB_DB_BPT) { | |
20039 | + kdb_printf("kdb: error return from kdba_bp_trap: %d\n", db_result); | |
20040 | + KDB_DEBUG_STATE("kdb_local 6", reason); | |
20041 | + return 0; /* Not for us, dismiss it */ | |
20042 | + } | |
20043 | + break; | |
20044 | + case KDB_REASON_RECURSE: | |
20045 | + kdb_printf("due to Recursion @ " kdb_machreg_fmt "\n", kdba_getpc(regs)); | |
20046 | + break; | |
20047 | + case KDB_REASON_CPU_UP: | |
20048 | + case KDB_REASON_SILENT: | |
20049 | + KDB_DEBUG_STATE("kdb_local 7", reason); | |
20050 | + if (reason == KDB_REASON_CPU_UP) | |
20051 | + kdba_cpu_up(); | |
20052 | + return KDB_CMD_GO; /* Silent entry, silent exit */ | |
20053 | + break; | |
20054 | + default: | |
20055 | + kdb_printf("kdb: unexpected reason code: %d\n", reason); | |
20056 | + KDB_DEBUG_STATE("kdb_local 8", reason); | |
20057 | + return 0; /* Not for us, dismiss it */ | |
20058 | + } | |
20059 | + | |
20060 | + kdba_local_arch_setup(); | |
20061 | + | |
20062 | + kdba_set_current_task(kdb_current); | |
20063 | + | |
20064 | + while (1) { | |
20065 | + /* | |
20066 | + * Initialize pager context. | |
20067 | + */ | |
20068 | + kdb_nextline = 1; | |
20069 | + KDB_STATE_CLEAR(SUPPRESS); | |
20070 | +#ifdef kdba_setjmp | |
20071 | + /* | |
20072 | + * Use kdba_setjmp/kdba_longjmp to break out of | |
20073 | + * the pager early and to attempt to recover from kdb errors. | |
20074 | + */ | |
20075 | + KDB_STATE_CLEAR(LONGJMP); | |
20076 | + if (kdbjmpbuf) { | |
20077 | + if (kdba_setjmp(&kdbjmpbuf[smp_processor_id()])) { | |
20078 | + /* Command aborted (usually in pager) */ | |
20079 | + continue; | |
20080 | + } | |
20081 | + else | |
20082 | + KDB_STATE_SET(LONGJMP); | |
20083 | + } | |
20084 | +#endif /* kdba_setjmp */ | |
20085 | + | |
20086 | + cmdbuf = cmd_cur; | |
20087 | + *cmdbuf = '\0'; | |
20088 | + *(cmd_hist[cmd_head])='\0'; | |
20089 | + | |
20090 | + if (KDB_FLAG(ONLY_DO_DUMP)) { | |
20091 | + /* kdb is off but a catastrophic error requires a dump. | |
20092 | + * Take the dump and reboot. | |
20093 | + * Turn on logging so the kdb output appears in the log | |
20094 | + * buffer in the dump. | |
20095 | + */ | |
20096 | + const char *setargs[] = { "set", "LOGGING", "1" }; | |
20097 | + kdb_set(2, setargs); | |
20098 | + kdb_do_dump(); | |
20099 | + kdb_reboot(0, NULL); | |
20100 | + /*NOTREACHED*/ | |
20101 | + } | |
20102 | + | |
20103 | +do_full_getstr: | |
20104 | +#if defined(CONFIG_SMP) | |
20105 | + snprintf(kdb_prompt_str, CMD_BUFLEN, kdbgetenv("PROMPT"), smp_processor_id()); | |
20106 | +#else | |
20107 | + snprintf(kdb_prompt_str, CMD_BUFLEN, kdbgetenv("PROMPT")); | |
20108 | +#endif | |
20109 | + if (defcmd_in_progress) | |
20110 | + strncat(kdb_prompt_str, "[defcmd]", CMD_BUFLEN); | |
20111 | + | |
20112 | + /* | |
20113 | + * Fetch command from keyboard | |
20114 | + */ | |
20115 | + cmdbuf = kdb_getstr(cmdbuf, CMD_BUFLEN, kdb_prompt_str); | |
20116 | + if (*cmdbuf != '\n') { | |
20117 | + if (*cmdbuf < 32) { | |
20118 | + if(cmdptr == cmd_head) { | |
20119 | + strncpy(cmd_hist[cmd_head], cmd_cur, CMD_BUFLEN); | |
20120 | + *(cmd_hist[cmd_head]+strlen(cmd_hist[cmd_head])-1) = '\0'; | |
20121 | + } | |
20122 | + if(!handle_ctrl_cmd(cmdbuf)) | |
20123 | + *(cmd_cur+strlen(cmd_cur)-1) = '\0'; | |
20124 | + cmdbuf = cmd_cur; | |
20125 | + goto do_full_getstr; | |
20126 | + } | |
20127 | + else | |
20128 | + strncpy(cmd_hist[cmd_head], cmd_cur, CMD_BUFLEN); | |
20129 | + | |
20130 | + cmd_head = (cmd_head+1) % KDB_CMD_HISTORY_COUNT; | |
20131 | + if (cmd_head == cmd_tail) cmd_tail = (cmd_tail+1) % KDB_CMD_HISTORY_COUNT; | |
20132 | + | |
20133 | + } | |
20134 | + | |
20135 | + cmdptr = cmd_head; | |
20136 | + diag = kdb_parse(cmdbuf); | |
20137 | + if (diag == KDB_NOTFOUND) { | |
20138 | + kdb_printf("Unknown kdb command: '%s'\n", cmdbuf); | |
20139 | + diag = 0; | |
20140 | + } | |
20141 | + if (diag == KDB_CMD_GO | |
20142 | + || diag == KDB_CMD_CPU | |
20143 | + || diag == KDB_CMD_SS | |
20144 | + || diag == KDB_CMD_SSB) | |
20145 | + break; | |
20146 | + | |
20147 | + if (diag) | |
20148 | + kdb_cmderror(diag); | |
20149 | + } | |
20150 | + | |
20151 | + kdba_local_arch_cleanup(); | |
20152 | + | |
20153 | + KDB_DEBUG_STATE("kdb_local 9", diag); | |
20154 | + return diag; | |
20155 | +} | |
20156 | + | |
20157 | + | |
20158 | +/* | |
20159 | + * kdb_print_state | |
20160 | + * | |
20161 | + * Print the state data for the current processor for debugging. | |
20162 | + * | |
20163 | + * Inputs: | |
20164 | + * text Identifies the debug point | |
20165 | + * value Any integer value to be printed, e.g. reason code. | |
20166 | + * Returns: | |
20167 | + * None. | |
20168 | + * Locking: | |
20169 | + * none | |
20170 | + * Remarks: | |
20171 | + * none | |
20172 | + */ | |
20173 | + | |
20174 | +void kdb_print_state(const char *text, int value) | |
20175 | +{ | |
20176 | + kdb_printf("state: %s cpu %d value %d initial %d state %x\n", | |
20177 | + text, smp_processor_id(), value, kdb_initial_cpu, kdb_state[smp_processor_id()]); | |
20178 | +} | |
20179 | + | |
20180 | +/* | |
20181 | + * kdb_previous_event | |
20182 | + * | |
20183 | + * Return a count of cpus that are leaving kdb, i.e. the number | |
20184 | + * of processors that are still handling the previous kdb event. | |
20185 | + * | |
20186 | + * Inputs: | |
20187 | + * None. | |
20188 | + * Returns: | |
20189 | + * Count of cpus in previous event. | |
20190 | + * Locking: | |
20191 | + * none | |
20192 | + * Remarks: | |
20193 | + * none | |
20194 | + */ | |
20195 | + | |
20196 | +static int | |
20197 | +kdb_previous_event(void) | |
20198 | +{ | |
20199 | + int i, leaving = 0; | |
20200 | + for (i = 0; i < NR_CPUS; ++i) { | |
20201 | + if (KDB_STATE_CPU(LEAVING, i)) | |
20202 | + ++leaving; | |
20203 | + } | |
20204 | + return leaving; | |
20205 | +} | |
20206 | + | |
20207 | +/* | |
20208 | + * kdb_wait_for_cpus | |
20209 | + * | |
20210 | + * Invoked once at the start of a kdb event, from the controlling cpu. Wait a | |
20211 | + * short period for the other cpus to enter kdb state. | |
20212 | + * | |
20213 | + * Inputs: | |
20214 | + * none | |
20215 | + * Returns: | |
20216 | + * none | |
20217 | + * Locking: | |
20218 | + * none | |
20219 | + * Remarks: | |
20220 | + * none | |
20221 | + */ | |
20222 | + | |
20223 | +int kdb_wait_for_cpus_secs; | |
20224 | + | |
20225 | +static void | |
20226 | +kdb_wait_for_cpus(void) | |
20227 | +{ | |
20228 | +#ifdef CONFIG_SMP | |
20229 | + int online = 0, kdb_data = 0, prev_kdb_data = 0, c, time; | |
20230 | + mdelay(100); | |
20231 | + for (time = 0; time < kdb_wait_for_cpus_secs; ++time) { | |
20232 | + online = 0; | |
20233 | + kdb_data = 0; | |
20234 | + for_each_online_cpu(c) { | |
20235 | + ++online; | |
20236 | + if (kdb_running_process[c].seqno >= kdb_seqno - 1) | |
20237 | + ++kdb_data; | |
20238 | + } | |
20239 | + if (online == kdb_data) | |
20240 | + break; | |
20241 | + if (prev_kdb_data != kdb_data) { | |
20242 | + kdb_nextline = 0; /* no prompt yet */ | |
20243 | + kdb_printf(" %d out of %d cpus in kdb, waiting for the rest, timeout in %d second(s)\n", | |
20244 | + kdb_data, online, kdb_wait_for_cpus_secs - time); | |
20245 | + prev_kdb_data = kdb_data; | |
20246 | + } | |
20247 | + touch_nmi_watchdog(); | |
20248 | + mdelay(1000); | |
20249 | + /* Architectures may want to send a more forceful interrupt */ | |
20250 | + if (time == min(kdb_wait_for_cpus_secs / 2, 5)) | |
20251 | + kdba_wait_for_cpus(); | |
20252 | + if (time % 4 == 0) | |
20253 | + kdb_printf("."); | |
20254 | + } | |
20255 | + if (time) { | |
20256 | + int wait = online - kdb_data; | |
20257 | + if (wait == 0) | |
20258 | + kdb_printf("All cpus are now in kdb\n"); | |
20259 | + else | |
20260 | + kdb_printf("%d cpu%s not in kdb, %s state is unknown\n", | |
20261 | + wait, | |
20262 | + wait == 1 ? " is" : "s are", | |
20263 | + wait == 1 ? "its" : "their"); | |
20264 | + } | |
20265 | +#endif /* CONFIG_SMP */ | |
20266 | +} | |
20267 | + | |
20268 | +/* | |
20269 | + * kdb_main_loop | |
20270 | + * | |
20271 | + * The main kdb loop. After initial setup and assignment of the controlling | |
20272 | + * cpu, all cpus are in this loop. One cpu is in control and will issue the kdb | |
20273 | + * prompt, the others will spin until 'go' or cpu switch. | |
20274 | + * | |
20275 | + * To get a consistent view of the kernel stacks for all processes, this routine | |
20276 | + * is invoked from the main kdb code via an architecture specific routine. | |
20277 | + * kdba_main_loop is responsible for making the kernel stacks consistent for all | |
20278 | + * processes, there should be no difference between a blocked process and a | |
20279 | + * running process as far as kdb is concerned. | |
20280 | + * | |
20281 | + * Inputs: | |
20282 | + * reason The reason KDB was invoked | |
20283 | + * error The hardware-defined error code | |
20284 | + * reason2 kdb's current reason code. Initially error but can change | |
20285 | + * acording to kdb state. | |
20286 | + * db_result Result code from break or debug point. | |
20287 | + * regs The exception frame at time of fault/breakpoint. If reason | |
20288 | + * is SILENT or CPU_UP then regs is NULL, otherwise it | |
20289 | + * should always be valid. | |
20290 | + * Returns: | |
20291 | + * 0 KDB was invoked for an event which it wasn't responsible | |
20292 | + * 1 KDB handled the event for which it was invoked. | |
20293 | + * Locking: | |
20294 | + * none | |
20295 | + * Remarks: | |
20296 | + * none | |
20297 | + */ | |
20298 | + | |
20299 | +int | |
20300 | +kdb_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error, | |
20301 | + kdb_dbtrap_t db_result, struct pt_regs *regs) | |
20302 | +{ | |
20303 | + int result = 1; | |
20304 | + /* Stay in kdb() until 'go', 'ss[b]' or an error */ | |
20305 | + while (1) { | |
20306 | + /* | |
20307 | + * All processors except the one that is in control | |
20308 | + * will spin here. | |
20309 | + */ | |
20310 | + KDB_DEBUG_STATE("kdb_main_loop 1", reason); | |
20311 | + while (KDB_STATE(HOLD_CPU)) { | |
20312 | + /* state KDB is turned off by kdb_cpu to see if the | |
20313 | + * other cpus are still live, each cpu in this loop | |
20314 | + * turns it back on. | |
20315 | + */ | |
20316 | + if (!KDB_STATE(KDB)) { | |
20317 | + KDB_STATE_SET(KDB); | |
20318 | + } | |
20319 | + | |
20320 | +#if defined(CONFIG_KDB_KDUMP) | |
20321 | + if (KDB_STATE(KEXEC)) { | |
20322 | + struct pt_regs r; | |
20323 | + if (regs == NULL) | |
20324 | + regs = &r; | |
20325 | + | |
20326 | + kdba_kdump_shutdown_slave(regs); | |
20327 | + return 0; | |
20328 | + } | |
20329 | +#endif | |
20330 | + } | |
20331 | + | |
20332 | + KDB_STATE_CLEAR(SUPPRESS); | |
20333 | + KDB_DEBUG_STATE("kdb_main_loop 2", reason); | |
20334 | + if (KDB_STATE(LEAVING)) | |
20335 | + break; /* Another cpu said 'go' */ | |
20336 | + | |
20337 | + if (!kdb_quiet(reason)) | |
20338 | + kdb_wait_for_cpus(); | |
20339 | + /* Still using kdb, this processor is in control */ | |
20340 | + result = kdb_local(reason2, error, regs, db_result); | |
20341 | + KDB_DEBUG_STATE("kdb_main_loop 3", result); | |
20342 | + | |
20343 | + if (result == KDB_CMD_CPU) { | |
20344 | + /* Cpu switch, hold the current cpu, release the target one. */ | |
20345 | + reason2 = KDB_REASON_SWITCH; | |
20346 | + KDB_STATE_SET(HOLD_CPU); | |
20347 | + KDB_STATE_CLEAR_CPU(HOLD_CPU, kdb_new_cpu); | |
20348 | + continue; | |
20349 | + } | |
20350 | + | |
20351 | + if (result == KDB_CMD_SS) { | |
20352 | + KDB_STATE_SET(DOING_SS); | |
20353 | + break; | |
20354 | + } | |
20355 | + | |
20356 | + if (result == KDB_CMD_SSB) { | |
20357 | + KDB_STATE_SET(DOING_SS); | |
20358 | + KDB_STATE_SET(DOING_SSB); | |
20359 | + break; | |
20360 | + } | |
20361 | + | |
20362 | + if (result && result != 1 && result != KDB_CMD_GO) | |
20363 | + kdb_printf("\nUnexpected kdb_local return code %d\n", result); | |
20364 | + | |
20365 | + KDB_DEBUG_STATE("kdb_main_loop 4", reason); | |
20366 | + break; | |
20367 | + } | |
20368 | + if (KDB_STATE(DOING_SS)) | |
20369 | + KDB_STATE_CLEAR(SSBPT); | |
20370 | + return result; | |
20371 | +} | |
20372 | + | |
20373 | +/* iapc_boot_arch was defined in ACPI 2.0, FADT revision 3 onwards. For any | |
20374 | + * FADT prior to revision 3, we have to assume that we have an i8042 I/O | |
20375 | + * device. ACPI initialises after KDB initialises but before using KDB, so | |
20376 | + * check iapc_boot_arch on each entry to KDB. | |
20377 | + */ | |
20378 | +static void | |
20379 | +kdb_check_i8042(void) | |
20380 | +{ | |
20381 | + KDB_FLAG_CLEAR(NO_I8042); | |
20382 | +#ifdef CONFIG_ACPI | |
20383 | + if (acpi_gbl_FADT.header.revision >= 3 && | |
20384 | + (acpi_gbl_FADT.boot_flags & BAF_8042_KEYBOARD_CONTROLLER) == 0) | |
20385 | + KDB_FLAG_SET(NO_I8042); | |
20386 | +#endif /* CONFIG_ACPI */ | |
20387 | +} | |
20388 | + | |
20389 | +/* | |
20390 | + * kdb | |
20391 | + * | |
20392 | + * This function is the entry point for the kernel debugger. It | |
20393 | + * provides a command parser and associated support functions to | |
20394 | + * allow examination and control of an active kernel. | |
20395 | + * | |
20396 | + * The breakpoint trap code should invoke this function with | |
20397 | + * one of KDB_REASON_BREAK (int 03) or KDB_REASON_DEBUG (debug register) | |
20398 | + * | |
20399 | + * the die_if_kernel function should invoke this function with | |
20400 | + * KDB_REASON_OOPS. | |
20401 | + * | |
20402 | + * In single step mode, one cpu is released to run without | |
20403 | + * breakpoints. Interrupts and NMI are reset to their original values, | |
20404 | + * the cpu is allowed to do one instruction which causes a trap | |
20405 | + * into kdb with KDB_REASON_DEBUG. | |
20406 | + * | |
20407 | + * Inputs: | |
20408 | + * reason The reason KDB was invoked | |
20409 | + * error The hardware-defined error code | |
20410 | + * regs The exception frame at time of fault/breakpoint. If reason | |
20411 | + * is SILENT or CPU_UP then regs is NULL, otherwise it | |
20412 | + * should always be valid. | |
20413 | + * Returns: | |
20414 | + * 0 KDB was invoked for an event which it wasn't responsible | |
20415 | + * 1 KDB handled the event for which it was invoked. | |
20416 | + * Locking: | |
20417 | + * none | |
20418 | + * Remarks: | |
20419 | + * No assumptions of system state. This function may be invoked | |
20420 | + * with arbitrary locks held. It will stop all other processors | |
20421 | + * in an SMP environment, disable all interrupts and does not use | |
20422 | + * the operating systems keyboard driver. | |
20423 | + * | |
20424 | + * This code is reentrant but only for cpu switch. Any other | |
20425 | + * reentrancy is an error, although kdb will attempt to recover. | |
20426 | + * | |
20427 | + * At the start of a kdb session the initial processor is running | |
20428 | + * kdb() and the other processors can be doing anything. When the | |
20429 | + * initial processor calls smp_kdb_stop() the other processors are | |
20430 | + * driven through kdb_ipi which calls kdb() with reason SWITCH. | |
20431 | + * That brings all processors into this routine, one with a "real" | |
20432 | + * reason code, the other with SWITCH. | |
20433 | + * | |
20434 | + * Because the other processors are driven via smp_kdb_stop(), | |
20435 | + * they enter here from the NMI handler. Until the other | |
20436 | + * processors exit from here and exit from kdb_ipi, they will not | |
20437 | + * take any more NMI requests. The initial cpu will still take NMI. | |
20438 | + * | |
20439 | + * Multiple race and reentrancy conditions, each with different | |
20440 | + * advoidance mechanisms. | |
20441 | + * | |
20442 | + * Two cpus hit debug points at the same time. | |
20443 | + * | |
20444 | + * kdb_lock and kdb_initial_cpu ensure that only one cpu gets | |
20445 | + * control of kdb. The others spin on kdb_initial_cpu until | |
20446 | + * they are driven through NMI into kdb_ipi. When the initial | |
20447 | + * cpu releases the others from NMI, they resume trying to get | |
20448 | + * kdb_initial_cpu to start a new event. | |
20449 | + * | |
20450 | + * A cpu is released from kdb and starts a new event before the | |
20451 | + * original event has completely ended. | |
20452 | + * | |
20453 | + * kdb_previous_event() prevents any cpu from entering | |
20454 | + * kdb_initial_cpu state until the previous event has completely | |
20455 | + * ended on all cpus. | |
20456 | + * | |
20457 | + * An exception occurs inside kdb. | |
20458 | + * | |
20459 | + * kdb_initial_cpu detects recursive entry to kdb and attempts | |
20460 | + * to recover. The recovery uses longjmp() which means that | |
20461 | + * recursive calls to kdb never return. Beware of assumptions | |
20462 | + * like | |
20463 | + * | |
20464 | + * ++depth; | |
20465 | + * kdb(); | |
20466 | + * --depth; | |
20467 | + * | |
20468 | + * If the kdb call is recursive then longjmp takes over and | |
20469 | + * --depth is never executed. | |
20470 | + * | |
20471 | + * NMI handling. | |
20472 | + * | |
20473 | + * NMI handling is tricky. The initial cpu is invoked by some kdb event, | |
20474 | + * this event could be NMI driven but usually is not. The other cpus are | |
20475 | + * driven into kdb() via kdb_ipi which uses NMI so at the start the other | |
20476 | + * cpus will not accept NMI. Some operations such as SS release one cpu | |
20477 | + * but hold all the others. Releasing a cpu means it drops back to | |
20478 | + * whatever it was doing before the kdb event, this means it drops out of | |
20479 | + * kdb_ipi and hence out of NMI status. But the software watchdog uses | |
20480 | + * NMI and we do not want spurious watchdog calls into kdb. kdba_read() | |
20481 | + * resets the watchdog counters in its input polling loop, when a kdb | |
20482 | + * command is running it is subject to NMI watchdog events. | |
20483 | + * | |
20484 | + * Another problem with NMI handling is the NMI used to drive the other | |
20485 | + * cpus into kdb cannot be distinguished from the watchdog NMI. State | |
20486 | + * flag WAIT_IPI indicates that a cpu is waiting for NMI via kdb_ipi, | |
20487 | + * if not set then software NMI is ignored by kdb_ipi. | |
20488 | + * | |
20489 | + * Cpu switching. | |
20490 | + * | |
20491 | + * All cpus are in kdb (or they should be), all but one are | |
20492 | + * spinning on KDB_STATE(HOLD_CPU). Only one cpu is not in | |
20493 | + * HOLD_CPU state, only that cpu can handle commands. | |
20494 | + * | |
20495 | + * Go command entered. | |
20496 | + * | |
20497 | + * If necessary, go will switch to the initial cpu first. If the event | |
20498 | + * was caused by a software breakpoint (assumed to be global) that | |
20499 | + * requires single-step to get over the breakpoint then only release the | |
20500 | + * initial cpu, after the initial cpu has single-stepped the breakpoint | |
20501 | + * then release the rest of the cpus. If SSBPT is not required then | |
20502 | + * release all the cpus at once. | |
20503 | + */ | |
20504 | + | |
20505 | +int | |
20506 | +kdb(kdb_reason_t reason, int error, struct pt_regs *regs) | |
20507 | +{ | |
20508 | + kdb_intstate_t int_state; /* Interrupt state */ | |
20509 | + kdb_reason_t reason2 = reason; | |
20510 | + int result = 0; /* Default is kdb did not handle it */ | |
20511 | + int ss_event, old_regs_saved = 0; | |
20512 | + struct pt_regs *old_regs = NULL; | |
20513 | + kdb_dbtrap_t db_result=KDB_DB_NOBPT; | |
20514 | + preempt_disable(); | |
20515 | + atomic_inc(&kdb_event); | |
20516 | + | |
20517 | + switch(reason) { | |
20518 | + case KDB_REASON_OOPS: | |
20519 | + case KDB_REASON_NMI: | |
20520 | + KDB_FLAG_SET(CATASTROPHIC); /* kernel state is dubious now */ | |
20521 | + break; | |
20522 | + default: | |
20523 | + break; | |
20524 | + } | |
20525 | + switch(reason) { | |
20526 | + case KDB_REASON_ENTER: | |
20527 | + case KDB_REASON_ENTER_SLAVE: | |
20528 | + case KDB_REASON_BREAK: | |
20529 | + case KDB_REASON_DEBUG: | |
20530 | + case KDB_REASON_OOPS: | |
20531 | + case KDB_REASON_SWITCH: | |
20532 | + case KDB_REASON_KEYBOARD: | |
20533 | + case KDB_REASON_NMI: | |
20534 | + if (regs && regs != get_irq_regs()) { | |
20535 | + old_regs = set_irq_regs(regs); | |
20536 | + old_regs_saved = 1; | |
20537 | + } | |
20538 | + break; | |
20539 | + default: | |
20540 | + break; | |
20541 | + } | |
20542 | + if (kdb_continue_catastrophic > 2) { | |
20543 | + kdb_printf("kdb_continue_catastrophic is out of range, setting to 2\n"); | |
20544 | + kdb_continue_catastrophic = 2; | |
20545 | + } | |
20546 | + if (!kdb_on && KDB_FLAG(CATASTROPHIC) && kdb_continue_catastrophic == 2) { | |
20547 | + KDB_FLAG_SET(ONLY_DO_DUMP); | |
20548 | + } | |
20549 | + if (!kdb_on && !KDB_FLAG(ONLY_DO_DUMP)) | |
20550 | + goto out; | |
20551 | + | |
20552 | + KDB_DEBUG_STATE("kdb 1", reason); | |
20553 | + KDB_STATE_CLEAR(SUPPRESS); | |
20554 | + | |
20555 | + /* Filter out userspace breakpoints first, no point in doing all | |
20556 | + * the kdb smp fiddling when it is really a gdb trap. | |
20557 | + * Save the single step status first, kdba_db_trap clears ss status. | |
20558 | + * kdba_b[dp]_trap sets SSBPT if required. | |
20559 | + */ | |
20560 | + ss_event = KDB_STATE(DOING_SS) || KDB_STATE(SSBPT); | |
20561 | +#ifdef CONFIG_CPU_XSCALE | |
20562 | + if ( KDB_STATE(A_XSC_ICH) ) { | |
20563 | + /* restore changed I_BIT */ | |
20564 | + KDB_STATE_CLEAR(A_XSC_ICH); | |
20565 | + kdba_restore_retirq(regs, KDB_STATE(A_XSC_IRQ)); | |
20566 | + if ( !ss_event ) { | |
20567 | + kdb_printf("Stranger!!! Why IRQ bit is changed====\n"); | |
20568 | + } | |
20569 | + } | |
20570 | +#endif | |
20571 | + if (reason == KDB_REASON_BREAK) { | |
20572 | + db_result = kdba_bp_trap(regs, error); /* Only call this once */ | |
20573 | + } | |
20574 | + if (reason == KDB_REASON_DEBUG) { | |
20575 | + db_result = kdba_db_trap(regs, error); /* Only call this once */ | |
20576 | + } | |
20577 | + | |
20578 | + if ((reason == KDB_REASON_BREAK || reason == KDB_REASON_DEBUG) | |
20579 | + && db_result == KDB_DB_NOBPT) { | |
20580 | + KDB_DEBUG_STATE("kdb 2", reason); | |
20581 | + goto out; /* Not one of mine */ | |
20582 | + } | |
20583 | + | |
20584 | + /* Turn off single step if it was being used */ | |
20585 | + if (ss_event) { | |
20586 | + kdba_clearsinglestep(regs); | |
20587 | + /* Single step after a breakpoint removes the need for a delayed reinstall */ | |
20588 | + if (reason == KDB_REASON_BREAK || reason == KDB_REASON_DEBUG) | |
20589 | + KDB_STATE_CLEAR(SSBPT); | |
20590 | + } | |
20591 | + | |
20592 | + /* kdb can validly reenter but only for certain well defined conditions */ | |
20593 | + if (reason == KDB_REASON_DEBUG | |
20594 | + && !KDB_STATE(HOLD_CPU) | |
20595 | + && ss_event) | |
20596 | + KDB_STATE_SET(REENTRY); | |
20597 | + else | |
20598 | + KDB_STATE_CLEAR(REENTRY); | |
20599 | + | |
20600 | + /* Wait for previous kdb event to completely exit before starting | |
20601 | + * a new event. | |
20602 | + */ | |
20603 | + while (kdb_previous_event()) | |
20604 | + ; | |
20605 | + KDB_DEBUG_STATE("kdb 3", reason); | |
20606 | + | |
20607 | + /* | |
20608 | + * If kdb is already active, print a message and try to recover. | |
20609 | + * If recovery is not possible and recursion is allowed or | |
20610 | + * forced recursion without recovery is set then try to recurse | |
20611 | + * in kdb. Not guaranteed to work but it makes an attempt at | |
20612 | + * debugging the debugger. | |
20613 | + */ | |
20614 | + if (reason != KDB_REASON_SWITCH && | |
20615 | + reason != KDB_REASON_ENTER_SLAVE) { | |
20616 | + if (KDB_IS_RUNNING() && !KDB_STATE(REENTRY)) { | |
20617 | + int recover = 1; | |
20618 | + unsigned long recurse = 0; | |
20619 | + kdb_printf("kdb: Debugger re-entered on cpu %d, new reason = %d\n", | |
20620 | + smp_processor_id(), reason); | |
20621 | + /* Should only re-enter from released cpu */ | |
20622 | + | |
20623 | + if (KDB_STATE(HOLD_CPU)) { | |
20624 | + kdb_printf(" Strange, cpu %d should not be running\n", smp_processor_id()); | |
20625 | + recover = 0; | |
20626 | + } | |
20627 | + if (!KDB_STATE(CMD)) { | |
20628 | + kdb_printf(" Not executing a kdb command\n"); | |
20629 | + recover = 0; | |
20630 | + } | |
20631 | + if (!KDB_STATE(LONGJMP)) { | |
20632 | + kdb_printf(" No longjmp available for recovery\n"); | |
20633 | + recover = 0; | |
20634 | + } | |
20635 | + kdbgetulenv("RECURSE", &recurse); | |
20636 | + if (recurse > 1) { | |
20637 | + kdb_printf(" Forced recursion is set\n"); | |
20638 | + recover = 0; | |
20639 | + } | |
20640 | + if (recover) { | |
20641 | + kdb_printf(" Attempting to abort command and recover\n"); | |
20642 | +#ifdef kdba_setjmp | |
20643 | + kdba_longjmp(&kdbjmpbuf[smp_processor_id()], 0); | |
20644 | +#endif /* kdba_setjmp */ | |
20645 | + } | |
20646 | + if (recurse) { | |
20647 | + if (KDB_STATE(RECURSE)) { | |
20648 | + kdb_printf(" Already in recursive mode\n"); | |
20649 | + } else { | |
20650 | + kdb_printf(" Attempting recursive mode\n"); | |
20651 | + KDB_STATE_SET(RECURSE); | |
20652 | + KDB_STATE_SET(REENTRY); | |
20653 | + reason2 = KDB_REASON_RECURSE; | |
20654 | + recover = 1; | |
20655 | + } | |
20656 | + } | |
20657 | + if (!recover) { | |
20658 | + kdb_printf(" Cannot recover, allowing event to proceed\n"); | |
20659 | + /*temp*/ | |
20660 | + while (KDB_IS_RUNNING()) | |
20661 | + cpu_relax(); | |
20662 | + goto out; | |
20663 | + } | |
20664 | + } | |
20665 | + } else if (reason == KDB_REASON_SWITCH && !KDB_IS_RUNNING()) { | |
20666 | + kdb_printf("kdb: CPU switch without kdb running, I'm confused\n"); | |
20667 | + goto out; | |
20668 | + } | |
20669 | + | |
20670 | + /* | |
20671 | + * Disable interrupts, breakpoints etc. on this processor | |
20672 | + * during kdb command processing | |
20673 | + */ | |
20674 | + KDB_STATE_SET(KDB); | |
20675 | + kdba_disableint(&int_state); | |
20676 | + if (!KDB_STATE(KDB_CONTROL)) { | |
20677 | + kdb_bp_remove_local(); | |
20678 | + KDB_STATE_SET(KDB_CONTROL); | |
20679 | + } | |
20680 | + | |
20681 | + /* | |
20682 | + * If not entering the debugger due to CPU switch or single step | |
20683 | + * reentry, serialize access here. | |
20684 | + * The processors may race getting to this point - if, | |
20685 | + * for example, more than one processor hits a breakpoint | |
20686 | + * at the same time. We'll serialize access to kdb here - | |
20687 | + * other processors will loop here, and the NMI from the stop | |
20688 | + * IPI will take them into kdb as switch candidates. Once | |
20689 | + * the initial processor releases the debugger, the rest of | |
20690 | + * the processors will race for it. | |
20691 | + * | |
20692 | + * The above describes the normal state of affairs, where two or more | |
20693 | + * cpus that are entering kdb at the "same" time are assumed to be for | |
20694 | + * separate events. However some processes such as ia64 MCA/INIT will | |
20695 | + * drive all the cpus into error processing at the same time. For that | |
20696 | + * case, all of the cpus entering kdb at the "same" time are really a | |
20697 | + * single event. | |
20698 | + * | |
20699 | + * That case is handled by the use of KDB_ENTER by one cpu (the | |
20700 | + * monarch) and KDB_ENTER_SLAVE on the other cpus (the slaves). | |
20701 | + * KDB_ENTER_SLAVE maps to KDB_REASON_ENTER_SLAVE. The slave events | |
20702 | + * will be treated as if they had just responded to the kdb IPI, i.e. | |
20703 | + * as if they were KDB_REASON_SWITCH. | |
20704 | + * | |
20705 | + * Because of races across multiple cpus, ENTER_SLAVE can occur before | |
20706 | + * the main ENTER. Hold up ENTER_SLAVE here until the main ENTER | |
20707 | + * arrives. | |
20708 | + */ | |
20709 | + | |
20710 | + if (reason == KDB_REASON_ENTER_SLAVE) { | |
20711 | + spin_lock(&kdb_lock); | |
20712 | + while (!KDB_IS_RUNNING()) { | |
20713 | + spin_unlock(&kdb_lock); | |
20714 | + while (!KDB_IS_RUNNING()) | |
20715 | + cpu_relax(); | |
20716 | + spin_lock(&kdb_lock); | |
20717 | + } | |
20718 | + reason = KDB_REASON_SWITCH; | |
20719 | + KDB_STATE_SET(HOLD_CPU); | |
20720 | + spin_unlock(&kdb_lock); | |
20721 | + } | |
20722 | + | |
20723 | + if (reason == KDB_REASON_SWITCH || KDB_STATE(REENTRY)) | |
20724 | + ; /* drop through */ | |
20725 | + else { | |
20726 | + KDB_DEBUG_STATE("kdb 4", reason); | |
20727 | + spin_lock(&kdb_lock); | |
20728 | + while (KDB_IS_RUNNING() || kdb_previous_event()) { | |
20729 | + spin_unlock(&kdb_lock); | |
20730 | + while (KDB_IS_RUNNING() || kdb_previous_event()) | |
20731 | + cpu_relax(); | |
20732 | + spin_lock(&kdb_lock); | |
20733 | + } | |
20734 | + KDB_DEBUG_STATE("kdb 5", reason); | |
20735 | + | |
20736 | + kdb_initial_cpu = smp_processor_id(); | |
20737 | + ++kdb_seqno; | |
20738 | + spin_unlock(&kdb_lock); | |
20739 | + if (!kdb_quiet(reason)) | |
20740 | + notify_die(DIE_KDEBUG_ENTER, "KDEBUG ENTER", regs, error, 0, 0); | |
20741 | + } | |
20742 | + | |
20743 | + if (smp_processor_id() == kdb_initial_cpu | |
20744 | + && !KDB_STATE(REENTRY)) { | |
20745 | + KDB_STATE_CLEAR(HOLD_CPU); | |
20746 | + KDB_STATE_CLEAR(WAIT_IPI); | |
20747 | + kdb_check_i8042(); | |
20748 | + /* | |
20749 | + * Remove the global breakpoints. This is only done | |
20750 | + * once from the initial processor on initial entry. | |
20751 | + */ | |
20752 | + if (!kdb_quiet(reason) || smp_processor_id() == 0) | |
20753 | + kdb_bp_remove_global(); | |
20754 | + | |
20755 | + /* | |
20756 | + * If SMP, stop other processors. The other processors | |
20757 | + * will enter kdb() with KDB_REASON_SWITCH and spin in | |
20758 | + * kdb_main_loop(). | |
20759 | + */ | |
20760 | + KDB_DEBUG_STATE("kdb 6", reason); | |
20761 | + if (NR_CPUS > 1 && !kdb_quiet(reason)) { | |
20762 | + int i; | |
20763 | + for (i = 0; i < NR_CPUS; ++i) { | |
20764 | + if (!cpu_online(i)) | |
20765 | + continue; | |
20766 | + if (i != kdb_initial_cpu) { | |
20767 | + KDB_STATE_SET_CPU(HOLD_CPU, i); | |
20768 | + KDB_STATE_SET_CPU(WAIT_IPI, i); | |
20769 | + } | |
20770 | + } | |
20771 | + KDB_DEBUG_STATE("kdb 7", reason); | |
20772 | + smp_kdb_stop(); | |
20773 | + KDB_DEBUG_STATE("kdb 8", reason); | |
20774 | + } | |
20775 | + } | |
20776 | + | |
20777 | + if (KDB_STATE(GO1)) { | |
20778 | + kdb_bp_remove_global(); /* They were set for single-step purposes */ | |
20779 | + KDB_STATE_CLEAR(GO1); | |
20780 | + reason = KDB_REASON_SILENT; /* Now silently go */ | |
20781 | + } | |
20782 | + | |
20783 | + /* Set up a consistent set of process stacks before talking to the user */ | |
20784 | + KDB_DEBUG_STATE("kdb 9", result); | |
20785 | + result = kdba_main_loop(reason, reason2, error, db_result, regs); | |
20786 | + reason = reason2; /* back to original event type */ | |
20787 | + | |
20788 | + KDB_DEBUG_STATE("kdb 10", result); | |
20789 | + kdba_adjust_ip(reason, error, regs); | |
20790 | + KDB_STATE_CLEAR(LONGJMP); | |
20791 | + KDB_DEBUG_STATE("kdb 11", result); | |
20792 | + /* go which requires single-step over a breakpoint must only release | |
20793 | + * one cpu. | |
20794 | + */ | |
20795 | + if (result == KDB_CMD_GO && KDB_STATE(SSBPT)) | |
20796 | + KDB_STATE_SET(GO1); | |
20797 | + | |
20798 | + if (smp_processor_id() == kdb_initial_cpu && | |
20799 | + !KDB_STATE(DOING_SS) && | |
20800 | + !KDB_STATE(RECURSE)) { | |
20801 | + /* | |
20802 | + * (Re)install the global breakpoints and cleanup the cached | |
20803 | + * symbol table. This is only done once from the initial | |
20804 | + * processor on go. | |
20805 | + */ | |
20806 | + KDB_DEBUG_STATE("kdb 12", reason); | |
20807 | + if (!kdb_quiet(reason) || smp_processor_id() == 0) { | |
20808 | + kdb_bp_install_global(regs); | |
20809 | + kdbnearsym_cleanup(); | |
20810 | + debug_kusage(); | |
20811 | + } | |
20812 | + if (!KDB_STATE(GO1)) { | |
20813 | + /* | |
20814 | + * Release all other cpus which will see KDB_STATE(LEAVING) is set. | |
20815 | + */ | |
20816 | + int i; | |
20817 | + for (i = 0; i < NR_CPUS; ++i) { | |
20818 | + if (KDB_STATE_CPU(KDB, i)) | |
20819 | + KDB_STATE_SET_CPU(LEAVING, i); | |
20820 | + KDB_STATE_CLEAR_CPU(WAIT_IPI, i); | |
20821 | + KDB_STATE_CLEAR_CPU(HOLD_CPU, i); | |
20822 | + } | |
20823 | + /* Wait until all the other processors leave kdb */ | |
20824 | + while (kdb_previous_event() != 1) | |
20825 | + ; | |
20826 | + if (!kdb_quiet(reason)) | |
20827 | + notify_die(DIE_KDEBUG_LEAVE, "KDEBUG LEAVE", regs, error, 0, 0); | |
20828 | + kdb_initial_cpu = -1; /* release kdb control */ | |
20829 | + KDB_DEBUG_STATE("kdb 13", reason); | |
20830 | + } | |
20831 | + } | |
20832 | + | |
20833 | + KDB_DEBUG_STATE("kdb 14", result); | |
20834 | + kdba_restoreint(&int_state); | |
20835 | +#ifdef CONFIG_CPU_XSCALE | |
20836 | + if ( smp_processor_id() == kdb_initial_cpu && | |
20837 | + ( KDB_STATE(SSBPT) | KDB_STATE(DOING_SS) ) | |
20838 | + ) { | |
20839 | + kdba_setsinglestep(regs); | |
20840 | + // disable IRQ in stack frame | |
20841 | + KDB_STATE_SET(A_XSC_ICH); | |
20842 | + if ( kdba_disable_retirq(regs) ) { | |
20843 | + KDB_STATE_SET(A_XSC_IRQ); | |
20844 | + } | |
20845 | + else { | |
20846 | + KDB_STATE_CLEAR(A_XSC_IRQ); | |
20847 | + } | |
20848 | + } | |
20849 | +#endif | |
20850 | + | |
20851 | + /* Only do this work if we are really leaving kdb */ | |
20852 | + if (!(KDB_STATE(DOING_SS) || KDB_STATE(SSBPT) || KDB_STATE(RECURSE))) { | |
20853 | + KDB_DEBUG_STATE("kdb 15", result); | |
20854 | + kdb_bp_install_local(regs); | |
20855 | + if (old_regs_saved) | |
20856 | + set_irq_regs(old_regs); | |
20857 | + KDB_STATE_CLEAR(KDB_CONTROL); | |
20858 | + } | |
20859 | + | |
20860 | + KDB_DEBUG_STATE("kdb 16", result); | |
20861 | + KDB_FLAG_CLEAR(CATASTROPHIC); | |
20862 | + KDB_STATE_CLEAR(IP_ADJUSTED); /* Re-adjust ip next time in */ | |
20863 | + KDB_STATE_CLEAR(KEYBOARD); | |
20864 | + KDB_STATE_CLEAR(KDB); /* Main kdb state has been cleared */ | |
20865 | + KDB_STATE_CLEAR(RECURSE); | |
20866 | + KDB_STATE_CLEAR(LEAVING); /* No more kdb work after this */ | |
20867 | + KDB_DEBUG_STATE("kdb 17", reason); | |
20868 | +out: | |
20869 | + atomic_dec(&kdb_event); | |
20870 | + preempt_enable(); | |
20871 | + return result != 0; | |
20872 | +} | |
20873 | + | |
20874 | +/* | |
20875 | + * kdb_mdr | |
20876 | + * | |
20877 | + * This function implements the guts of the 'mdr' command. | |
20878 | + * | |
20879 | + * mdr <addr arg>,<byte count> | |
20880 | + * | |
20881 | + * Inputs: | |
20882 | + * addr Start address | |
20883 | + * count Number of bytes | |
20884 | + * Outputs: | |
20885 | + * None. | |
20886 | + * Returns: | |
20887 | + * Always 0. Any errors are detected and printed by kdb_getarea. | |
20888 | + * Locking: | |
20889 | + * none. | |
20890 | + * Remarks: | |
20891 | + */ | |
20892 | + | |
20893 | +static int | |
20894 | +kdb_mdr(kdb_machreg_t addr, unsigned int count) | |
20895 | +{ | |
20896 | + unsigned char c; | |
20897 | + while (count--) { | |
20898 | + if (kdb_getarea(c, addr)) | |
20899 | + return 0; | |
20900 | + kdb_printf("%02x", c); | |
20901 | + addr++; | |
20902 | + } | |
20903 | + kdb_printf("\n"); | |
20904 | + return 0; | |
20905 | +} | |
20906 | + | |
20907 | +/* | |
20908 | + * kdb_md | |
20909 | + * | |
20910 | + * This function implements the 'md', 'md1', 'md2', 'md4', 'md8' | |
20911 | + * 'mdr' and 'mds' commands. | |
20912 | + * | |
20913 | + * md|mds [<addr arg> [<line count> [<radix>]]] | |
20914 | + * mdWcN [<addr arg> [<line count> [<radix>]]] | |
20915 | + * where W = is the width (1, 2, 4 or 8) and N is the count. | |
20916 | + * for eg., md1c20 reads 20 bytes, 1 at a time. | |
20917 | + * mdr <addr arg>,<byte count> | |
20918 | + * | |
20919 | + * Inputs: | |
20920 | + * argc argument count | |
20921 | + * argv argument vector | |
20922 | + * Outputs: | |
20923 | + * None. | |
20924 | + * Returns: | |
20925 | + * zero for success, a kdb diagnostic if error | |
20926 | + * Locking: | |
20927 | + * none. | |
20928 | + * Remarks: | |
20929 | + */ | |
20930 | + | |
20931 | +static void | |
20932 | +kdb_md_line(const char *fmtstr, kdb_machreg_t addr, | |
20933 | + int symbolic, int nosect, int bytesperword, | |
20934 | + int num, int repeat, int phys) | |
20935 | +{ | |
20936 | + /* print just one line of data */ | |
20937 | + kdb_symtab_t symtab; | |
20938 | + char cbuf[32]; | |
20939 | + char *c = cbuf; | |
20940 | + int i; | |
20941 | + unsigned long word; | |
20942 | + | |
20943 | + memset(cbuf, '\0', sizeof(cbuf)); | |
20944 | + if (phys) | |
20945 | + kdb_printf("phys " kdb_machreg_fmt0 " ", addr); | |
20946 | + else | |
20947 | + kdb_printf(kdb_machreg_fmt0 " ", addr); | |
20948 | + | |
20949 | + for (i = 0; i < num && repeat--; i++) { | |
20950 | + if (phys) { | |
20951 | + if (kdb_getphysword(&word, addr, bytesperword)) | |
20952 | + break; | |
20953 | + } else if (kdb_getword(&word, addr, bytesperword)) | |
20954 | + break; | |
20955 | + kdb_printf(fmtstr, word); | |
20956 | + if (symbolic) | |
20957 | + kdbnearsym(word, &symtab); | |
20958 | + else | |
20959 | + memset(&symtab, 0, sizeof(symtab)); | |
20960 | + if (symtab.sym_name) { | |
20961 | + kdb_symbol_print(word, &symtab, 0); | |
20962 | + if (!nosect) { | |
20963 | + kdb_printf("\n"); | |
20964 | + kdb_printf(" %s %s " | |
20965 | + kdb_machreg_fmt " " kdb_machreg_fmt " " kdb_machreg_fmt, | |
20966 | + symtab.mod_name, | |
20967 | + symtab.sec_name, | |
20968 | + symtab.sec_start, | |
20969 | + symtab.sym_start, | |
20970 | + symtab.sym_end); | |
20971 | + } | |
20972 | + addr += bytesperword; | |
20973 | + } else { | |
20974 | + union { | |
20975 | + u64 word; | |
20976 | + unsigned char c[8]; | |
20977 | + } wc; | |
20978 | + unsigned char *cp; | |
20979 | +#ifdef __BIG_ENDIAN | |
20980 | + cp = wc.c + 8 - bytesperword; | |
20981 | +#else | |
20982 | + cp = wc.c; | |
20983 | +#endif | |
20984 | + wc.word = word; | |
20985 | +#define printable_char(c) ({unsigned char __c = c; isascii(__c) && isprint(__c) ? __c : '.';}) | |
20986 | + switch (bytesperword) { | |
20987 | + case 8: | |
20988 | + *c++ = printable_char(*cp++); | |
20989 | + *c++ = printable_char(*cp++); | |
20990 | + *c++ = printable_char(*cp++); | |
20991 | + *c++ = printable_char(*cp++); | |
20992 | + addr += 4; | |
20993 | + case 4: | |
20994 | + *c++ = printable_char(*cp++); | |
20995 | + *c++ = printable_char(*cp++); | |
20996 | + addr += 2; | |
20997 | + case 2: | |
20998 | + *c++ = printable_char(*cp++); | |
20999 | + addr++; | |
21000 | + case 1: | |
21001 | + *c++ = printable_char(*cp++); | |
21002 | + addr++; | |
21003 | + break; | |
21004 | + } | |
21005 | +#undef printable_char | |
21006 | + } | |
21007 | + } | |
21008 | + kdb_printf("%*s %s\n", (int)((num-i)*(2*bytesperword + 1)+1), " ", cbuf); | |
21009 | +} | |
21010 | + | |
21011 | +static int | |
21012 | +kdb_md(int argc, const char **argv) | |
21013 | +{ | |
21014 | + static kdb_machreg_t last_addr; | |
21015 | + static int last_radix, last_bytesperword, last_repeat; | |
21016 | + int radix = 16, mdcount = 8, bytesperword = KDB_WORD_SIZE, repeat; | |
21017 | + int nosect = 0; | |
21018 | + char fmtchar, fmtstr[64]; | |
21019 | + kdb_machreg_t addr; | |
21020 | + unsigned long word; | |
21021 | + long offset = 0; | |
21022 | + int symbolic = 0; | |
21023 | + int valid = 0; | |
21024 | + int phys = 0; | |
21025 | + | |
21026 | + kdbgetintenv("MDCOUNT", &mdcount); | |
21027 | + kdbgetintenv("RADIX", &radix); | |
21028 | + kdbgetintenv("BYTESPERWORD", &bytesperword); | |
21029 | + | |
21030 | + /* Assume 'md <addr>' and start with environment values */ | |
21031 | + repeat = mdcount * 16 / bytesperword; | |
21032 | + | |
21033 | + if (strcmp(argv[0], "mdr") == 0) { | |
21034 | + if (argc != 2) | |
21035 | + return KDB_ARGCOUNT; | |
21036 | + valid = 1; | |
21037 | + } else if (isdigit(argv[0][2])) { | |
21038 | + bytesperword = (int)(argv[0][2] - '0'); | |
21039 | + if (bytesperword == 0) { | |
21040 | + bytesperword = last_bytesperword; | |
21041 | + if (bytesperword == 0) { | |
21042 | + bytesperword = 4; | |
21043 | + } | |
21044 | + } | |
21045 | + last_bytesperword = bytesperword; | |
21046 | + repeat = mdcount * 16 / bytesperword; | |
21047 | + if (!argv[0][3]) | |
21048 | + valid = 1; | |
21049 | + else if (argv[0][3] == 'c' && argv[0][4]) { | |
21050 | + char *p; | |
21051 | + repeat = simple_strtoul(argv[0]+4, &p, 10); | |
21052 | + mdcount = ((repeat * bytesperword) + 15) / 16; | |
21053 | + valid = !*p; | |
21054 | + } | |
21055 | + last_repeat = repeat; | |
21056 | + } else if (strcmp(argv[0], "md") == 0) | |
21057 | + valid = 1; | |
21058 | + else if (strcmp(argv[0], "mds") == 0) | |
21059 | + valid = 1; | |
21060 | + else if (strcmp(argv[0], "mdp") == 0) { | |
21061 | + phys = valid = 1; | |
21062 | + } | |
21063 | + if (!valid) | |
21064 | + return KDB_NOTFOUND; | |
21065 | + | |
21066 | + if (argc == 0) { | |
21067 | + if (last_addr == 0) | |
21068 | + return KDB_ARGCOUNT; | |
21069 | + addr = last_addr; | |
21070 | + radix = last_radix; | |
21071 | + bytesperword = last_bytesperword; | |
21072 | + repeat = last_repeat; | |
21073 | + mdcount = ((repeat * bytesperword) + 15) / 16; | |
21074 | + } | |
21075 | + | |
21076 | + if (argc) { | |
21077 | + kdb_machreg_t val; | |
21078 | + int diag, nextarg = 1; | |
21079 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL); | |
21080 | + if (diag) | |
21081 | + return diag; | |
21082 | + if (argc > nextarg+2) | |
21083 | + return KDB_ARGCOUNT; | |
21084 | + | |
21085 | + if (argc >= nextarg) { | |
21086 | + diag = kdbgetularg(argv[nextarg], &val); | |
21087 | + if (!diag) { | |
21088 | + mdcount = (int) val; | |
21089 | + repeat = mdcount * 16 / bytesperword; | |
21090 | + } | |
21091 | + } | |
21092 | + if (argc >= nextarg+1) { | |
21093 | + diag = kdbgetularg(argv[nextarg+1], &val); | |
21094 | + if (!diag) | |
21095 | + radix = (int) val; | |
21096 | + } | |
21097 | + } | |
21098 | + | |
21099 | + if (strcmp(argv[0], "mdr") == 0) { | |
21100 | + return kdb_mdr(addr, mdcount); | |
21101 | + } | |
21102 | + | |
21103 | + switch (radix) { | |
21104 | + case 10: | |
21105 | + fmtchar = 'd'; | |
21106 | + break; | |
21107 | + case 16: | |
21108 | + fmtchar = 'x'; | |
21109 | + break; | |
21110 | + case 8: | |
21111 | + fmtchar = 'o'; | |
21112 | + break; | |
21113 | + default: | |
21114 | + return KDB_BADRADIX; | |
21115 | + } | |
21116 | + | |
21117 | + last_radix = radix; | |
21118 | + | |
21119 | + if (bytesperword > KDB_WORD_SIZE) | |
21120 | + return KDB_BADWIDTH; | |
21121 | + | |
21122 | + switch (bytesperword) { | |
21123 | + case 8: | |
21124 | + sprintf(fmtstr, "%%16.16l%c ", fmtchar); | |
21125 | + break; | |
21126 | + case 4: | |
21127 | + sprintf(fmtstr, "%%8.8l%c ", fmtchar); | |
21128 | + break; | |
21129 | + case 2: | |
21130 | + sprintf(fmtstr, "%%4.4l%c ", fmtchar); | |
21131 | + break; | |
21132 | + case 1: | |
21133 | + sprintf(fmtstr, "%%2.2l%c ", fmtchar); | |
21134 | + break; | |
21135 | + default: | |
21136 | + return KDB_BADWIDTH; | |
21137 | + } | |
21138 | + | |
21139 | + last_repeat = repeat; | |
21140 | + last_bytesperword = bytesperword; | |
21141 | + | |
21142 | + if (strcmp(argv[0], "mds") == 0) { | |
21143 | + symbolic = 1; | |
21144 | + /* Do not save these changes as last_*, they are temporary mds | |
21145 | + * overrides. | |
21146 | + */ | |
21147 | + bytesperword = KDB_WORD_SIZE; | |
21148 | + repeat = mdcount; | |
21149 | + kdbgetintenv("NOSECT", &nosect); | |
21150 | + } | |
21151 | + | |
21152 | + /* Round address down modulo BYTESPERWORD */ | |
21153 | + | |
21154 | + addr &= ~(bytesperword-1); | |
21155 | + | |
21156 | + while (repeat > 0) { | |
21157 | + unsigned long a; | |
21158 | + int n, z, num = (symbolic ? 1 : (16 / bytesperword)); | |
21159 | + | |
21160 | + for (a = addr, z = 0; z < repeat; a += bytesperword, ++z) { | |
21161 | + if (phys) { | |
21162 | + if (kdb_getphysword(&word, a, bytesperword) | |
21163 | + || word) | |
21164 | + break; | |
21165 | + } else if (kdb_getword(&word, a, bytesperword) || word) | |
21166 | + break; | |
21167 | + } | |
21168 | + n = min(num, repeat); | |
21169 | + kdb_md_line(fmtstr, addr, symbolic, nosect, bytesperword, num, repeat, phys); | |
21170 | + addr += bytesperword * n; | |
21171 | + repeat -= n; | |
21172 | + z = (z + num - 1) / num; | |
21173 | + if (z > 2) { | |
21174 | + int s = num * (z-2); | |
21175 | + kdb_printf(kdb_machreg_fmt0 "-" kdb_machreg_fmt0 " zero suppressed\n", | |
21176 | + addr, addr + bytesperword * s - 1); | |
21177 | + addr += bytesperword * s; | |
21178 | + repeat -= s; | |
21179 | + } | |
21180 | + } | |
21181 | + last_addr = addr; | |
21182 | + | |
21183 | + return 0; | |
21184 | +} | |
21185 | + | |
21186 | +/* | |
21187 | + * kdb_mm | |
21188 | + * | |
21189 | + * This function implements the 'mm' command. | |
21190 | + * | |
21191 | + * mm address-expression new-value | |
21192 | + * | |
21193 | + * Inputs: | |
21194 | + * argc argument count | |
21195 | + * argv argument vector | |
21196 | + * Outputs: | |
21197 | + * None. | |
21198 | + * Returns: | |
21199 | + * zero for success, a kdb diagnostic if error | |
21200 | + * Locking: | |
21201 | + * none. | |
21202 | + * Remarks: | |
21203 | + * mm works on machine words, mmW works on bytes. | |
21204 | + */ | |
21205 | + | |
21206 | +static int | |
21207 | +kdb_mm(int argc, const char **argv) | |
21208 | +{ | |
21209 | + int diag; | |
21210 | + kdb_machreg_t addr; | |
21211 | + long offset = 0; | |
21212 | + unsigned long contents; | |
21213 | + int nextarg; | |
21214 | + int width; | |
21215 | + | |
21216 | + if (argv[0][2] && !isdigit(argv[0][2])) | |
21217 | + return KDB_NOTFOUND; | |
21218 | + | |
21219 | + if (argc < 2) { | |
21220 | + return KDB_ARGCOUNT; | |
21221 | + } | |
21222 | + | |
21223 | + nextarg = 1; | |
21224 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL))) | |
21225 | + return diag; | |
21226 | + | |
21227 | + if (nextarg > argc) | |
21228 | + return KDB_ARGCOUNT; | |
21229 | + | |
21230 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &contents, NULL, NULL))) | |
21231 | + return diag; | |
21232 | + | |
21233 | + if (nextarg != argc + 1) | |
21234 | + return KDB_ARGCOUNT; | |
21235 | + | |
21236 | + width = argv[0][2] ? (argv[0][2] - '0') : (KDB_WORD_SIZE); | |
21237 | + if ((diag = kdb_putword(addr, contents, width))) | |
21238 | + return diag; | |
21239 | + | |
21240 | + kdb_printf(kdb_machreg_fmt " = " kdb_machreg_fmt "\n", addr, contents); | |
21241 | + | |
21242 | + return 0; | |
21243 | +} | |
21244 | + | |
21245 | +/* | |
21246 | + * kdb_go | |
21247 | + * | |
21248 | + * This function implements the 'go' command. | |
21249 | + * | |
21250 | + * go [address-expression] | |
21251 | + * | |
21252 | + * Inputs: | |
21253 | + * argc argument count | |
21254 | + * argv argument vector | |
21255 | + * Outputs: | |
21256 | + * None. | |
21257 | + * Returns: | |
21258 | + * KDB_CMD_GO for success, a kdb diagnostic if error | |
21259 | + * Locking: | |
21260 | + * none. | |
21261 | + * Remarks: | |
21262 | + */ | |
21263 | + | |
21264 | +static int | |
21265 | +kdb_go(int argc, const char **argv) | |
21266 | +{ | |
21267 | + kdb_machreg_t addr; | |
21268 | + int diag; | |
21269 | + int nextarg; | |
21270 | + long offset; | |
21271 | + struct pt_regs *regs = get_irq_regs(); | |
21272 | + | |
21273 | + if (argc == 1) { | |
21274 | + if (smp_processor_id() != kdb_initial_cpu) { | |
21275 | + kdb_printf("go <address> must be issued from the initial cpu, do cpu %d first\n", kdb_initial_cpu); | |
21276 | + return KDB_ARGCOUNT; | |
21277 | + } | |
21278 | + nextarg = 1; | |
21279 | + diag = kdbgetaddrarg(argc, argv, &nextarg, | |
21280 | + &addr, &offset, NULL); | |
21281 | + if (diag) | |
21282 | + return diag; | |
21283 | + | |
21284 | + kdba_setpc(regs, addr); | |
21285 | + } else if (argc) | |
21286 | + return KDB_ARGCOUNT; | |
21287 | + | |
21288 | + diag = KDB_CMD_GO; | |
21289 | + if (KDB_FLAG(CATASTROPHIC)) { | |
21290 | + kdb_printf("Catastrophic error detected\n"); | |
21291 | + kdb_printf("kdb_continue_catastrophic=%d, ", | |
21292 | + kdb_continue_catastrophic); | |
21293 | + if (kdb_continue_catastrophic == 0 && kdb_go_count++ == 0) { | |
21294 | + kdb_printf("type go a second time if you really want to continue\n"); | |
21295 | + return 0; | |
21296 | + } | |
21297 | + if (kdb_continue_catastrophic == 2) { | |
21298 | + kdb_do_dump(); | |
21299 | + kdb_printf("forcing reboot\n"); | |
21300 | + kdb_reboot(0, NULL); | |
21301 | + } | |
21302 | + kdb_printf("attempting to continue\n"); | |
21303 | + } | |
21304 | + if (smp_processor_id() != kdb_initial_cpu) { | |
21305 | + char buf[80]; | |
21306 | + kdb_printf("go was not issued from initial cpu, switching back to cpu %d\n", kdb_initial_cpu); | |
21307 | + sprintf(buf, "cpu %d\n", kdb_initial_cpu); | |
21308 | + /* Recursive use of kdb_parse, do not use argv after this point */ | |
21309 | + argv = NULL; | |
21310 | + diag = kdb_parse(buf); | |
21311 | + if (diag == KDB_CMD_CPU) | |
21312 | + KDB_STATE_SET_CPU(GO_SWITCH, kdb_initial_cpu); | |
21313 | + } | |
21314 | + return diag; | |
21315 | +} | |
21316 | + | |
21317 | +/* | |
21318 | + * kdb_rd | |
21319 | + * | |
21320 | + * This function implements the 'rd' command. | |
21321 | + * | |
21322 | + * rd display all general registers. | |
21323 | + * rd c display all control registers. | |
21324 | + * rd d display all debug registers. | |
21325 | + * | |
21326 | + * Inputs: | |
21327 | + * argc argument count | |
21328 | + * argv argument vector | |
21329 | + * Outputs: | |
21330 | + * None. | |
21331 | + * Returns: | |
21332 | + * zero for success, a kdb diagnostic if error | |
21333 | + * Locking: | |
21334 | + * none. | |
21335 | + * Remarks: | |
21336 | + */ | |
21337 | + | |
21338 | +static int | |
21339 | +kdb_rd(int argc, const char **argv) | |
21340 | +{ | |
21341 | + int diag; | |
21342 | + if (argc == 0) { | |
21343 | + if ((diag = kdb_check_regs())) | |
21344 | + return diag; | |
21345 | + return kdba_dumpregs(kdb_current_regs, NULL, NULL); | |
21346 | + } | |
21347 | + | |
21348 | + if (argc > 2) { | |
21349 | + return KDB_ARGCOUNT; | |
21350 | + } | |
21351 | + | |
21352 | + if ((diag = kdb_check_regs())) | |
21353 | + return diag; | |
21354 | + return kdba_dumpregs(kdb_current_regs, argv[1], argc==2 ? argv[2]: NULL); | |
21355 | +} | |
21356 | + | |
21357 | +/* | |
21358 | + * kdb_rm | |
21359 | + * | |
21360 | + * This function implements the 'rm' (register modify) command. | |
21361 | + * | |
21362 | + * rm register-name new-contents | |
21363 | + * | |
21364 | + * Inputs: | |
21365 | + * argc argument count | |
21366 | + * argv argument vector | |
21367 | + * Outputs: | |
21368 | + * None. | |
21369 | + * Returns: | |
21370 | + * zero for success, a kdb diagnostic if error | |
21371 | + * Locking: | |
21372 | + * none. | |
21373 | + * Remarks: | |
21374 | + * Currently doesn't allow modification of control or | |
21375 | + * debug registers. | |
21376 | + */ | |
21377 | + | |
21378 | +static int | |
21379 | +kdb_rm(int argc, const char **argv) | |
21380 | +{ | |
21381 | + int diag; | |
21382 | + int ind = 0; | |
21383 | + kdb_machreg_t contents; | |
21384 | + | |
21385 | + if (argc != 2) { | |
21386 | + return KDB_ARGCOUNT; | |
21387 | + } | |
21388 | + | |
21389 | + /* | |
21390 | + * Allow presence or absence of leading '%' symbol. | |
21391 | + */ | |
21392 | + | |
21393 | + if (argv[1][0] == '%') | |
21394 | + ind = 1; | |
21395 | + | |
21396 | + diag = kdbgetularg(argv[2], &contents); | |
21397 | + if (diag) | |
21398 | + return diag; | |
21399 | + | |
21400 | + if ((diag = kdb_check_regs())) | |
21401 | + return diag; | |
21402 | + diag = kdba_setregcontents(&argv[1][ind], kdb_current_regs, contents); | |
21403 | + if (diag) | |
21404 | + return diag; | |
21405 | + | |
21406 | + return 0; | |
21407 | +} | |
21408 | + | |
21409 | +#if defined(CONFIG_MAGIC_SYSRQ) | |
21410 | +/* | |
21411 | + * kdb_sr | |
21412 | + * | |
21413 | + * This function implements the 'sr' (SYSRQ key) command which | |
21414 | + * interfaces to the soi-disant MAGIC SYSRQ functionality. | |
21415 | + * | |
21416 | + * sr <magic-sysrq-code> | |
21417 | + * | |
21418 | + * Inputs: | |
21419 | + * argc argument count | |
21420 | + * argv argument vector | |
21421 | + * Outputs: | |
21422 | + * None. | |
21423 | + * Returns: | |
21424 | + * zero for success, a kdb diagnostic if error | |
21425 | + * Locking: | |
21426 | + * none. | |
21427 | + * Remarks: | |
21428 | + * None. | |
21429 | + */ | |
21430 | +static int | |
21431 | +kdb_sr(int argc, const char **argv) | |
21432 | +{ | |
21433 | + extern int __sysrq_enabled; | |
21434 | + if (argc != 1) { | |
21435 | + return KDB_ARGCOUNT; | |
21436 | + } | |
21437 | + if (!__sysrq_enabled) { | |
21438 | + kdb_printf("Auto activating sysrq\n"); | |
21439 | + __sysrq_enabled = 1; | |
21440 | + } | |
21441 | + | |
21442 | + handle_sysrq(*argv[1], NULL); | |
21443 | + | |
21444 | + return 0; | |
21445 | +} | |
21446 | +#endif /* CONFIG_MAGIC_SYSRQ */ | |
21447 | + | |
21448 | +/* | |
21449 | + * kdb_ef | |
21450 | + * | |
21451 | + * This function implements the 'regs' (display exception frame) | |
21452 | + * command. This command takes an address and expects to find | |
21453 | + * an exception frame at that address, formats and prints it. | |
21454 | + * | |
21455 | + * regs address-expression | |
21456 | + * | |
21457 | + * Inputs: | |
21458 | + * argc argument count | |
21459 | + * argv argument vector | |
21460 | + * Outputs: | |
21461 | + * None. | |
21462 | + * Returns: | |
21463 | + * zero for success, a kdb diagnostic if error | |
21464 | + * Locking: | |
21465 | + * none. | |
21466 | + * Remarks: | |
21467 | + * Not done yet. | |
21468 | + */ | |
21469 | + | |
21470 | +static int | |
21471 | +kdb_ef(int argc, const char **argv) | |
21472 | +{ | |
21473 | + int diag; | |
21474 | + kdb_machreg_t addr; | |
21475 | + long offset; | |
21476 | + int nextarg; | |
21477 | + | |
21478 | + if (argc == 1) { | |
21479 | + nextarg = 1; | |
21480 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL); | |
21481 | + if (diag) | |
21482 | + return diag; | |
21483 | + | |
21484 | + return kdba_dumpregs((struct pt_regs *)addr, NULL, NULL); | |
21485 | + } | |
21486 | + | |
21487 | + return KDB_ARGCOUNT; | |
21488 | +} | |
21489 | + | |
21490 | +#if defined(CONFIG_MODULES) | |
21491 | +extern struct list_head *kdb_modules; | |
21492 | +extern void free_module(struct module *); | |
21493 | + | |
21494 | +/* modules using other modules */ | |
21495 | +struct module_use | |
21496 | +{ | |
21497 | + struct list_head list; | |
21498 | + struct module *module_which_uses; | |
21499 | +}; | |
21500 | + | |
21501 | +/* | |
21502 | + * kdb_lsmod | |
21503 | + * | |
21504 | + * This function implements the 'lsmod' command. Lists currently | |
21505 | + * loaded kernel modules. | |
21506 | + * | |
21507 | + * Mostly taken from userland lsmod. | |
21508 | + * | |
21509 | + * Inputs: | |
21510 | + * argc argument count | |
21511 | + * argv argument vector | |
21512 | + * Outputs: | |
21513 | + * None. | |
21514 | + * Returns: | |
21515 | + * zero for success, a kdb diagnostic if error | |
21516 | + * Locking: | |
21517 | + * none. | |
21518 | + * Remarks: | |
21519 | + * | |
21520 | + */ | |
21521 | + | |
21522 | +static int | |
21523 | +kdb_lsmod(int argc, const char **argv) | |
21524 | +{ | |
21525 | + struct module *mod; | |
21526 | + | |
21527 | + if (argc != 0) | |
21528 | + return KDB_ARGCOUNT; | |
21529 | + | |
21530 | + kdb_printf("Module Size modstruct Used by\n"); | |
21531 | + list_for_each_entry(mod, kdb_modules, list) { | |
21532 | + | |
21533 | + kdb_printf("%-20s%8u 0x%p ", mod->name, | |
21534 | + mod->core_size, (void *)mod); | |
21535 | +#ifdef CONFIG_MODULE_UNLOAD | |
21536 | + kdb_printf("%4d ", module_refcount(mod)); | |
21537 | +#endif | |
21538 | + if (mod->state == MODULE_STATE_GOING) | |
21539 | + kdb_printf(" (Unloading)"); | |
21540 | + else if (mod->state == MODULE_STATE_COMING) | |
21541 | + kdb_printf(" (Loading)"); | |
21542 | + else | |
21543 | + kdb_printf(" (Live)"); | |
21544 | + | |
21545 | +#ifdef CONFIG_MODULE_UNLOAD | |
21546 | + { | |
21547 | + struct module_use *use; | |
21548 | + kdb_printf(" [ "); | |
21549 | + list_for_each_entry(use, &mod->modules_which_use_me, list) | |
21550 | + kdb_printf("%s ", use->module_which_uses->name); | |
21551 | + kdb_printf("]\n"); | |
21552 | + } | |
21553 | +#endif | |
21554 | + } | |
21555 | + | |
21556 | + return 0; | |
21557 | +} | |
21558 | + | |
21559 | +#endif /* CONFIG_MODULES */ | |
21560 | + | |
21561 | +/* | |
21562 | + * kdb_env | |
21563 | + * | |
21564 | + * This function implements the 'env' command. Display the current | |
21565 | + * environment variables. | |
21566 | + * | |
21567 | + * Inputs: | |
21568 | + * argc argument count | |
21569 | + * argv argument vector | |
21570 | + * Outputs: | |
21571 | + * None. | |
21572 | + * Returns: | |
21573 | + * zero for success, a kdb diagnostic if error | |
21574 | + * Locking: | |
21575 | + * none. | |
21576 | + * Remarks: | |
21577 | + */ | |
21578 | + | |
21579 | +static int | |
21580 | +kdb_env(int argc, const char **argv) | |
21581 | +{ | |
21582 | + int i; | |
21583 | + | |
21584 | + for(i=0; i<__nenv; i++) { | |
21585 | + if (__env[i]) { | |
21586 | + kdb_printf("%s\n", __env[i]); | |
21587 | + } | |
21588 | + } | |
21589 | + | |
21590 | + if (KDB_DEBUG(MASK)) | |
21591 | + kdb_printf("KDBFLAGS=0x%x\n", kdb_flags); | |
21592 | + | |
21593 | + return 0; | |
21594 | +} | |
21595 | + | |
21596 | +/* | |
21597 | + * kdb_dmesg | |
21598 | + * | |
21599 | + * This function implements the 'dmesg' command to display the contents | |
21600 | + * of the syslog buffer. | |
21601 | + * | |
21602 | + * dmesg [lines] [adjust] | |
21603 | + * | |
21604 | + * Inputs: | |
21605 | + * argc argument count | |
21606 | + * argv argument vector | |
21607 | + * Outputs: | |
21608 | + * None. | |
21609 | + * Returns: | |
21610 | + * zero for success, a kdb diagnostic if error | |
21611 | + * Locking: | |
21612 | + * none. | |
21613 | + * Remarks: | |
21614 | + * None. | |
21615 | + */ | |
21616 | + | |
21617 | +static int | |
21618 | +kdb_dmesg(int argc, const char **argv) | |
21619 | +{ | |
21620 | + char *syslog_data[4], *start, *end, c = '\0', *p; | |
21621 | + int diag, logging, logsize, lines = 0, adjust = 0, n; | |
21622 | + | |
21623 | + if (argc > 2) | |
21624 | + return KDB_ARGCOUNT; | |
21625 | + if (argc) { | |
21626 | + char *cp; | |
21627 | + lines = simple_strtol(argv[1], &cp, 0); | |
21628 | + if (*cp) | |
21629 | + lines = 0; | |
21630 | + if (argc > 1) { | |
21631 | + adjust = simple_strtoul(argv[2], &cp, 0); | |
21632 | + if (*cp || adjust < 0) | |
21633 | + adjust = 0; | |
21634 | + } | |
21635 | + } | |
21636 | + | |
21637 | + /* disable LOGGING if set */ | |
21638 | + diag = kdbgetintenv("LOGGING", &logging); | |
21639 | + if (!diag && logging) { | |
21640 | + const char *setargs[] = { "set", "LOGGING", "0" }; | |
21641 | + kdb_set(2, setargs); | |
21642 | + } | |
21643 | + | |
21644 | + /* syslog_data[0,1] physical start, end+1. syslog_data[2,3] logical start, end+1. */ | |
21645 | + kdb_syslog_data(syslog_data); | |
21646 | + if (syslog_data[2] == syslog_data[3]) | |
21647 | + return 0; | |
21648 | + logsize = syslog_data[1] - syslog_data[0]; | |
21649 | + start = syslog_data[2]; | |
21650 | + end = syslog_data[3]; | |
21651 | +#define KDB_WRAP(p) (((p - syslog_data[0]) % logsize) + syslog_data[0]) | |
21652 | + for (n = 0, p = start; p < end; ++p) { | |
21653 | + if ((c = *KDB_WRAP(p)) == '\n') | |
21654 | + ++n; | |
21655 | + } | |
21656 | + if (c != '\n') | |
21657 | + ++n; | |
21658 | + if (lines < 0) { | |
21659 | + if (adjust >= n) | |
21660 | + kdb_printf("buffer only contains %d lines, nothing printed\n", n); | |
21661 | + else if (adjust - lines >= n) | |
21662 | + kdb_printf("buffer only contains %d lines, last %d lines printed\n", | |
21663 | + n, n - adjust); | |
21664 | + if (adjust) { | |
21665 | + for (; start < end && adjust; ++start) { | |
21666 | + if (*KDB_WRAP(start) == '\n') | |
21667 | + --adjust; | |
21668 | + } | |
21669 | + if (start < end) | |
21670 | + ++start; | |
21671 | + } | |
21672 | + for (p = start; p < end && lines; ++p) { | |
21673 | + if (*KDB_WRAP(p) == '\n') | |
21674 | + ++lines; | |
21675 | + } | |
21676 | + end = p; | |
21677 | + } else if (lines > 0) { | |
21678 | + int skip = n - (adjust + lines); | |
21679 | + if (adjust >= n) { | |
21680 | + kdb_printf("buffer only contains %d lines, nothing printed\n", n); | |
21681 | + skip = n; | |
21682 | + } else if (skip < 0) { | |
21683 | + lines += skip; | |
21684 | + skip = 0; | |
21685 | + kdb_printf("buffer only contains %d lines, first %d lines printed\n", | |
21686 | + n, lines); | |
21687 | + } | |
21688 | + for (; start < end && skip; ++start) { | |
21689 | + if (*KDB_WRAP(start) == '\n') | |
21690 | + --skip; | |
21691 | + } | |
21692 | + for (p = start; p < end && lines; ++p) { | |
21693 | + if (*KDB_WRAP(p) == '\n') | |
21694 | + --lines; | |
21695 | + } | |
21696 | + end = p; | |
21697 | + } | |
21698 | + /* Do a line at a time (max 200 chars) to reduce protocol overhead */ | |
21699 | + c = '\n'; | |
21700 | + while (start != end) { | |
21701 | + char buf[201]; | |
21702 | + p = buf; | |
21703 | + while (start < end && (c = *KDB_WRAP(start)) && (p - buf) < sizeof(buf)-1) { | |
21704 | + ++start; | |
21705 | + *p++ = c; | |
21706 | + if (c == '\n') | |
21707 | + break; | |
21708 | + } | |
21709 | + *p = '\0'; | |
21710 | + kdb_printf("%s", buf); | |
21711 | + } | |
21712 | + if (c != '\n') | |
21713 | + kdb_printf("\n"); | |
21714 | + | |
21715 | + return 0; | |
21716 | +} | |
21717 | + | |
21718 | +/* | |
21719 | + * kdb_cpu | |
21720 | + * | |
21721 | + * This function implements the 'cpu' command. | |
21722 | + * | |
21723 | + * cpu [<cpunum>] | |
21724 | + * | |
21725 | + * Inputs: | |
21726 | + * argc argument count | |
21727 | + * argv argument vector | |
21728 | + * Outputs: | |
21729 | + * None. | |
21730 | + * Returns: | |
21731 | + * KDB_CMD_CPU for success, a kdb diagnostic if error | |
21732 | + * Locking: | |
21733 | + * none. | |
21734 | + * Remarks: | |
21735 | + * All cpu's should be spinning in kdb(). However just in case | |
21736 | + * a cpu did not take the smp_kdb_stop NMI, check that a cpu | |
21737 | + * entered kdb() before passing control to it. | |
21738 | + */ | |
21739 | + | |
21740 | +static void | |
21741 | +kdb_cpu_status(void) | |
21742 | +{ | |
21743 | + int i, start_cpu, first_print = 1; | |
21744 | + char state, prev_state = '?'; | |
21745 | + | |
21746 | + kdb_printf("Currently on cpu %d\n", smp_processor_id()); | |
21747 | + kdb_printf("Available cpus: "); | |
21748 | + for (start_cpu = -1, i = 0; i < NR_CPUS; i++) { | |
21749 | + if (!cpu_online(i)) | |
21750 | + state = 'F'; /* cpu is offline */ | |
21751 | + else { | |
21752 | + struct kdb_running_process *krp = kdb_running_process+i; | |
21753 | + if (KDB_STATE_CPU(KDB, i)) { | |
21754 | + state = ' '; /* cpu is responding to kdb */ | |
21755 | + if (kdb_task_state_char(krp->p) == 'I') | |
21756 | + state = 'I'; /* running the idle task */ | |
21757 | + } else if (krp->seqno && krp->p && krp->seqno >= kdb_seqno - 1) | |
21758 | + state = '+'; /* some kdb data, but not responding */ | |
21759 | + else | |
21760 | + state = '*'; /* no kdb data */ | |
21761 | + } | |
21762 | + if (state != prev_state) { | |
21763 | + if (prev_state != '?') { | |
21764 | + if (!first_print) | |
21765 | + kdb_printf(", "); | |
21766 | + first_print = 0; | |
21767 | + kdb_printf("%d", start_cpu); | |
21768 | + if (start_cpu < i-1) | |
21769 | + kdb_printf("-%d", i-1); | |
21770 | + if (prev_state != ' ') | |
21771 | + kdb_printf("(%c)", prev_state); | |
21772 | + } | |
21773 | + prev_state = state; | |
21774 | + start_cpu = i; | |
21775 | + } | |
21776 | + } | |
21777 | + /* print the trailing cpus, ignoring them if they are all offline */ | |
21778 | + if (prev_state != 'F') { | |
21779 | + if (!first_print) | |
21780 | + kdb_printf(", "); | |
21781 | + kdb_printf("%d", start_cpu); | |
21782 | + if (start_cpu < i-1) | |
21783 | + kdb_printf("-%d", i-1); | |
21784 | + if (prev_state != ' ') | |
21785 | + kdb_printf("(%c)", prev_state); | |
21786 | + } | |
21787 | + kdb_printf("\n"); | |
21788 | +} | |
21789 | + | |
21790 | +static int | |
21791 | +kdb_cpu(int argc, const char **argv) | |
21792 | +{ | |
21793 | + unsigned long cpunum; | |
21794 | + int diag, i; | |
21795 | + | |
21796 | + /* ask the other cpus if they are still active */ | |
21797 | + for (i=0; i<NR_CPUS; i++) { | |
21798 | + if (cpu_online(i)) | |
21799 | + KDB_STATE_CLEAR_CPU(KDB, i); | |
21800 | + } | |
21801 | + KDB_STATE_SET(KDB); | |
21802 | + barrier(); | |
21803 | + /* wait for the other cpus to notice and set state KDB again, | |
21804 | + * see kdb_main_loop | |
21805 | + */ | |
21806 | + udelay(1000); | |
21807 | + | |
21808 | + if (argc == 0) { | |
21809 | + kdb_cpu_status(); | |
21810 | + return 0; | |
21811 | + } | |
21812 | + | |
21813 | + if (argc != 1) | |
21814 | + return KDB_ARGCOUNT; | |
21815 | + | |
21816 | + diag = kdbgetularg(argv[1], &cpunum); | |
21817 | + if (diag) | |
21818 | + return diag; | |
21819 | + | |
21820 | + /* | |
21821 | + * Validate cpunum | |
21822 | + */ | |
21823 | + if ((cpunum > NR_CPUS) | |
21824 | + || !cpu_online(cpunum) | |
21825 | + || !KDB_STATE_CPU(KDB, cpunum)) | |
21826 | + return KDB_BADCPUNUM; | |
21827 | + | |
21828 | + kdb_new_cpu = cpunum; | |
21829 | + | |
21830 | + /* | |
21831 | + * Switch to other cpu | |
21832 | + */ | |
21833 | + return KDB_CMD_CPU; | |
21834 | +} | |
21835 | + | |
21836 | +/* The user may not realize that ps/bta with no parameters does not print idle | |
21837 | + * or sleeping system daemon processes, so tell them how many were suppressed. | |
21838 | + */ | |
21839 | +void | |
21840 | +kdb_ps_suppressed(void) | |
21841 | +{ | |
21842 | + int idle = 0, daemon = 0; | |
21843 | + unsigned long mask_I = kdb_task_state_string("I"), | |
21844 | + mask_M = kdb_task_state_string("M"); | |
21845 | + unsigned long cpu; | |
21846 | + const struct task_struct *p, *g; | |
21847 | + for (cpu = 0; cpu < NR_CPUS; ++cpu) { | |
21848 | + if (!cpu_online(cpu)) | |
21849 | + continue; | |
21850 | + p = kdb_curr_task(cpu); | |
21851 | + if (kdb_task_state(p, mask_I)) | |
21852 | + ++idle; | |
21853 | + } | |
21854 | + kdb_do_each_thread(g, p) { | |
21855 | + if (kdb_task_state(p, mask_M)) | |
21856 | + ++daemon; | |
21857 | + } kdb_while_each_thread(g, p); | |
21858 | + if (idle || daemon) { | |
21859 | + if (idle) | |
21860 | + kdb_printf("%d idle process%s (state I)%s\n", | |
21861 | + idle, idle == 1 ? "" : "es", | |
21862 | + daemon ? " and " : ""); | |
21863 | + if (daemon) | |
21864 | + kdb_printf("%d sleeping system daemon (state M) process%s", | |
21865 | + daemon, daemon == 1 ? "" : "es"); | |
21866 | + kdb_printf(" suppressed,\nuse 'ps A' to see all.\n"); | |
21867 | + } | |
21868 | +} | |
21869 | + | |
21870 | +/* | |
21871 | + * kdb_ps | |
21872 | + * | |
21873 | + * This function implements the 'ps' command which shows | |
21874 | + * a list of the active processes. | |
21875 | + * | |
21876 | + * ps [DRSTCZEUIMA] All processes, optionally filtered by state | |
21877 | + * | |
21878 | + * Inputs: | |
21879 | + * argc argument count | |
21880 | + * argv argument vector | |
21881 | + * Outputs: | |
21882 | + * None. | |
21883 | + * Returns: | |
21884 | + * zero for success, a kdb diagnostic if error | |
21885 | + * Locking: | |
21886 | + * none. | |
21887 | + * Remarks: | |
21888 | + */ | |
21889 | + | |
21890 | +void | |
21891 | +kdb_ps1(const struct task_struct *p) | |
21892 | +{ | |
21893 | + struct kdb_running_process *krp = kdb_running_process + kdb_process_cpu(p); | |
21894 | + kdb_printf("0x%p %8d %8d %d %4d %c 0x%p %c%s\n", | |
21895 | + (void *)p, p->pid, p->parent->pid, | |
21896 | + kdb_task_has_cpu(p), kdb_process_cpu(p), | |
21897 | + kdb_task_state_char(p), | |
21898 | + (void *)(&p->thread), | |
21899 | + p == kdb_curr_task(smp_processor_id()) ? '*': ' ', | |
21900 | + p->comm); | |
21901 | + if (kdb_task_has_cpu(p)) { | |
21902 | + if (!krp->seqno || !krp->p) | |
21903 | + kdb_printf(" Error: no saved data for this cpu\n"); | |
21904 | + else { | |
21905 | + if (krp->seqno < kdb_seqno - 1) | |
21906 | + kdb_printf(" Warning: process state is stale\n"); | |
21907 | + if (krp->p != p) | |
21908 | + kdb_printf(" Error: does not match running process table (0x%p)\n", krp->p); | |
21909 | + } | |
21910 | + } | |
21911 | +} | |
21912 | + | |
21913 | +static int | |
21914 | +kdb_ps(int argc, const char **argv) | |
21915 | +{ | |
21916 | + struct task_struct *g, *p; | |
21917 | + unsigned long mask, cpu; | |
21918 | + | |
21919 | + if (argc == 0) | |
21920 | + kdb_ps_suppressed(); | |
21921 | + kdb_printf("%-*s Pid Parent [*] cpu State %-*s Command\n", | |
21922 | + (int)(2*sizeof(void *))+2, "Task Addr", | |
21923 | + (int)(2*sizeof(void *))+2, "Thread"); | |
21924 | + mask = kdb_task_state_string(argc ? argv[1] : NULL); | |
21925 | + /* Run the active tasks first */ | |
21926 | + for (cpu = 0; cpu < NR_CPUS; ++cpu) { | |
21927 | + if (!cpu_online(cpu)) | |
21928 | + continue; | |
21929 | + p = kdb_curr_task(cpu); | |
21930 | + if (kdb_task_state(p, mask)) | |
21931 | + kdb_ps1(p); | |
21932 | + } | |
21933 | + kdb_printf("\n"); | |
21934 | + /* Now the real tasks */ | |
21935 | + kdb_do_each_thread(g, p) { | |
21936 | + if (kdb_task_state(p, mask)) | |
21937 | + kdb_ps1(p); | |
21938 | + } kdb_while_each_thread(g, p); | |
21939 | + | |
21940 | + return 0; | |
21941 | +} | |
21942 | + | |
21943 | +/* | |
21944 | + * kdb_pid | |
21945 | + * | |
21946 | + * This function implements the 'pid' command which switches | |
21947 | + * the currently active process. | |
21948 | + * | |
21949 | + * pid [<pid> | R] | |
21950 | + * | |
21951 | + * Inputs: | |
21952 | + * argc argument count | |
21953 | + * argv argument vector | |
21954 | + * Outputs: | |
21955 | + * None. | |
21956 | + * Returns: | |
21957 | + * zero for success, a kdb diagnostic if error | |
21958 | + * Locking: | |
21959 | + * none. | |
21960 | + * Remarks: | |
21961 | + */ | |
21962 | + | |
21963 | + | |
21964 | +static int | |
21965 | +kdb_pid(int argc, const char **argv) | |
21966 | +{ | |
21967 | + struct task_struct *p; | |
21968 | + unsigned long val; | |
21969 | + int diag; | |
21970 | + | |
21971 | + if (argc > 1) | |
21972 | + return KDB_ARGCOUNT; | |
21973 | + | |
21974 | + if (argc) { | |
21975 | + if (strcmp(argv[1], "R") == 0) { | |
21976 | + p = KDB_RUNNING_PROCESS_ORIGINAL[kdb_initial_cpu].p; | |
21977 | + } else { | |
21978 | + diag = kdbgetularg(argv[1], &val); | |
21979 | + if (diag) | |
21980 | + return KDB_BADINT; | |
21981 | + | |
21982 | + p = find_task_by_pid_type_ns(PIDTYPE_PID, (pid_t)val, | |
21983 | + &init_pid_ns); | |
21984 | + if (!p) { | |
21985 | + kdb_printf("No task with pid=%d\n", (pid_t)val); | |
21986 | + return 0; | |
21987 | + } | |
21988 | + } | |
21989 | + | |
21990 | + kdba_set_current_task(p); | |
21991 | + } | |
21992 | + | |
21993 | + kdb_printf("KDB current process is %s(pid=%d)\n", kdb_current_task->comm, | |
21994 | + kdb_current_task->pid); | |
21995 | + | |
21996 | + return 0; | |
21997 | +} | |
21998 | + | |
21999 | +/* | |
22000 | + * kdb_ll | |
22001 | + * | |
22002 | + * This function implements the 'll' command which follows a linked | |
22003 | + * list and executes an arbitrary command for each element. | |
22004 | + * | |
22005 | + * Inputs: | |
22006 | + * argc argument count | |
22007 | + * argv argument vector | |
22008 | + * Outputs: | |
22009 | + * None. | |
22010 | + * Returns: | |
22011 | + * zero for success, a kdb diagnostic if error | |
22012 | + * Locking: | |
22013 | + * none. | |
22014 | + * Remarks: | |
22015 | + */ | |
22016 | + | |
22017 | +static int | |
22018 | +kdb_ll(int argc, const char **argv) | |
22019 | +{ | |
22020 | + int diag; | |
22021 | + kdb_machreg_t addr; | |
22022 | + long offset = 0; | |
22023 | + kdb_machreg_t va; | |
22024 | + unsigned long linkoffset; | |
22025 | + int nextarg; | |
22026 | + const char *command; | |
22027 | + | |
22028 | + if (argc != 3) { | |
22029 | + return KDB_ARGCOUNT; | |
22030 | + } | |
22031 | + | |
22032 | + nextarg = 1; | |
22033 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL); | |
22034 | + if (diag) | |
22035 | + return diag; | |
22036 | + | |
22037 | + diag = kdbgetularg(argv[2], &linkoffset); | |
22038 | + if (diag) | |
22039 | + return diag; | |
22040 | + | |
22041 | + /* | |
22042 | + * Using the starting address as | |
22043 | + * the first element in the list, and assuming that | |
22044 | + * the list ends with a null pointer. | |
22045 | + */ | |
22046 | + | |
22047 | + va = addr; | |
22048 | + if (!(command = kdb_strdup(argv[3], GFP_KDB))) { | |
22049 | + kdb_printf("%s: cannot duplicate command\n", __FUNCTION__); | |
22050 | + return 0; | |
22051 | + } | |
22052 | + /* Recursive use of kdb_parse, do not use argv after this point */ | |
22053 | + argv = NULL; | |
22054 | + | |
22055 | + while (va) { | |
22056 | + char buf[80]; | |
22057 | + | |
22058 | + sprintf(buf, "%s " kdb_machreg_fmt "\n", command, va); | |
22059 | + diag = kdb_parse(buf); | |
22060 | + if (diag) | |
22061 | + return diag; | |
22062 | + | |
22063 | + addr = va + linkoffset; | |
22064 | + if (kdb_getword(&va, addr, sizeof(va))) | |
22065 | + return 0; | |
22066 | + } | |
22067 | + kfree(command); | |
22068 | + | |
22069 | + return 0; | |
22070 | +} | |
22071 | + | |
22072 | +/* | |
22073 | + * kdb_help | |
22074 | + * | |
22075 | + * This function implements the 'help' and '?' commands. | |
22076 | + * | |
22077 | + * Inputs: | |
22078 | + * argc argument count | |
22079 | + * argv argument vector | |
22080 | + * Outputs: | |
22081 | + * None. | |
22082 | + * Returns: | |
22083 | + * zero for success, a kdb diagnostic if error | |
22084 | + * Locking: | |
22085 | + * none. | |
22086 | + * Remarks: | |
22087 | + */ | |
22088 | + | |
22089 | +static int | |
22090 | +kdb_help(int argc, const char **argv) | |
22091 | +{ | |
22092 | + kdbtab_t *kt; | |
22093 | + int i; | |
22094 | + | |
22095 | + kdb_printf("%-15.15s %-20.20s %s\n", "Command", "Usage", "Description"); | |
22096 | + kdb_printf("----------------------------------------------------------\n"); | |
22097 | + for(i=0, kt=kdb_commands; i<kdb_max_commands; i++, kt++) { | |
22098 | + if (kt->cmd_name) | |
22099 | + kdb_printf("%-15.15s %-20.20s %s\n", kt->cmd_name, | |
22100 | + kt->cmd_usage, kt->cmd_help); | |
22101 | + } | |
22102 | + return 0; | |
22103 | +} | |
22104 | + | |
22105 | +extern int kdb_wake_up_process(struct task_struct * p); | |
22106 | + | |
22107 | +/* | |
22108 | + * kdb_kill | |
22109 | + * | |
22110 | + * This function implements the 'kill' commands. | |
22111 | + * | |
22112 | + * Inputs: | |
22113 | + * argc argument count | |
22114 | + * argv argument vector | |
22115 | + * Outputs: | |
22116 | + * None. | |
22117 | + * Returns: | |
22118 | + * zero for success, a kdb diagnostic if error | |
22119 | + * Locking: | |
22120 | + * none. | |
22121 | + * Remarks: | |
22122 | + */ | |
22123 | + | |
22124 | +static int | |
22125 | +kdb_kill(int argc, const char **argv) | |
22126 | +{ | |
22127 | + long sig, pid; | |
22128 | + char *endp; | |
22129 | + struct task_struct *p; | |
22130 | + struct siginfo info; | |
22131 | + | |
22132 | + if (argc!=2) | |
22133 | + return KDB_ARGCOUNT; | |
22134 | + | |
22135 | + sig = simple_strtol(argv[1], &endp, 0); | |
22136 | + if (*endp) | |
22137 | + return KDB_BADINT; | |
22138 | + if (sig >= 0 ) { | |
22139 | + kdb_printf("Invalid signal parameter.<-signal>\n"); | |
22140 | + return 0; | |
22141 | + } | |
22142 | + sig=-sig; | |
22143 | + | |
22144 | + pid = simple_strtol(argv[2], &endp, 0); | |
22145 | + if (*endp) | |
22146 | + return KDB_BADINT; | |
22147 | + if (pid <=0 ) { | |
22148 | + kdb_printf("Process ID must be large than 0.\n"); | |
22149 | + return 0; | |
22150 | + } | |
22151 | + | |
22152 | + /* Find the process. */ | |
22153 | + if (!(p = find_task_by_pid_type_ns(PIDTYPE_PID, pid, &init_pid_ns))) { | |
22154 | + kdb_printf("The specified process isn't found.\n"); | |
22155 | + return 0; | |
22156 | + } | |
22157 | + p = p->group_leader; | |
22158 | + info.si_signo = sig; | |
22159 | + info.si_errno = 0; | |
22160 | + info.si_code = SI_USER; | |
22161 | + info.si_pid = pid; /* use same capabilities as process being signalled */ | |
22162 | + info.si_uid = 0; /* kdb has root authority */ | |
22163 | + kdb_send_sig_info(p, &info, kdb_seqno); | |
22164 | + return 0; | |
22165 | +} | |
22166 | + | |
22167 | +struct kdb_tm { | |
22168 | + int tm_sec; /* seconds */ | |
22169 | + int tm_min; /* minutes */ | |
22170 | + int tm_hour; /* hours */ | |
22171 | + int tm_mday; /* day of the month */ | |
22172 | + int tm_mon; /* month */ | |
22173 | + int tm_year; /* year */ | |
22174 | +}; | |
22175 | + | |
22176 | +static void | |
22177 | +kdb_gmtime(struct timespec *tv, struct kdb_tm *tm) | |
22178 | +{ | |
22179 | + /* This will work from 1970-2099, 2100 is not a leap year */ | |
22180 | + static int mon_day[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | |
22181 | + memset(tm, 0, sizeof(*tm)); | |
22182 | + tm->tm_sec = tv->tv_sec % (24 * 60 * 60); | |
22183 | + tm->tm_mday = tv->tv_sec / (24 * 60 * 60) + (2 * 365 + 1); /* shift base from 1970 to 1968 */ | |
22184 | + tm->tm_min = tm->tm_sec / 60 % 60; | |
22185 | + tm->tm_hour = tm->tm_sec / 60 / 60; | |
22186 | + tm->tm_sec = tm->tm_sec % 60; | |
22187 | + tm->tm_year = 68 + 4*(tm->tm_mday / (4*365+1)); | |
22188 | + tm->tm_mday %= (4*365+1); | |
22189 | + mon_day[1] = 29; | |
22190 | + while (tm->tm_mday >= mon_day[tm->tm_mon]) { | |
22191 | + tm->tm_mday -= mon_day[tm->tm_mon]; | |
22192 | + if (++tm->tm_mon == 12) { | |
22193 | + tm->tm_mon = 0; | |
22194 | + ++tm->tm_year; | |
22195 | + mon_day[1] = 28; | |
22196 | + } | |
22197 | + } | |
22198 | + ++tm->tm_mday; | |
22199 | +} | |
22200 | + | |
22201 | +/* | |
22202 | + * Most of this code has been lifted from kernel/timer.c::sys_sysinfo(). | |
22203 | + * I cannot call that code directly from kdb, it has an unconditional | |
22204 | + * cli()/sti() and calls routines that take locks which can stop the debugger. | |
22205 | + */ | |
22206 | + | |
22207 | +static void | |
22208 | +kdb_sysinfo(struct sysinfo *val) | |
22209 | +{ | |
22210 | + struct timespec uptime; | |
22211 | + do_posix_clock_monotonic_gettime(&uptime); | |
22212 | + memset(val, 0, sizeof(*val)); | |
22213 | + val->uptime = uptime.tv_sec; | |
22214 | + val->loads[0] = avenrun[0]; | |
22215 | + val->loads[1] = avenrun[1]; | |
22216 | + val->loads[2] = avenrun[2]; | |
22217 | + val->procs = nr_threads-1; | |
22218 | + si_meminfo(val); | |
22219 | + kdb_si_swapinfo(val); | |
22220 | + | |
22221 | + return; | |
22222 | +} | |
22223 | + | |
22224 | +/* | |
22225 | + * kdb_summary | |
22226 | + * | |
22227 | + * This function implements the 'summary' command. | |
22228 | + * | |
22229 | + * Inputs: | |
22230 | + * argc argument count | |
22231 | + * argv argument vector | |
22232 | + * Outputs: | |
22233 | + * None. | |
22234 | + * Returns: | |
22235 | + * zero for success, a kdb diagnostic if error | |
22236 | + * Locking: | |
22237 | + * none. | |
22238 | + * Remarks: | |
22239 | + */ | |
22240 | + | |
22241 | +static int | |
22242 | +kdb_summary(int argc, const char **argv) | |
22243 | +{ | |
22244 | + extern struct timespec xtime; | |
22245 | + extern struct timezone sys_tz; | |
22246 | + struct kdb_tm tm; | |
22247 | + struct sysinfo val; | |
22248 | + | |
22249 | + if (argc) | |
22250 | + return KDB_ARGCOUNT; | |
22251 | + | |
22252 | + kdb_printf("sysname %s\n", init_uts_ns.name.sysname); | |
22253 | + kdb_printf("release %s\n", init_uts_ns.name.release); | |
22254 | + kdb_printf("version %s\n", init_uts_ns.name.version); | |
22255 | + kdb_printf("machine %s\n", init_uts_ns.name.machine); | |
22256 | + kdb_printf("nodename %s\n", init_uts_ns.name.nodename); | |
22257 | + kdb_printf("domainname %s\n", init_uts_ns.name.domainname); | |
22258 | + kdb_printf("ccversion %s\n", __stringify(CCVERSION)); | |
22259 | + | |
22260 | + kdb_gmtime(&xtime, &tm); | |
22261 | + kdb_printf("date %04d-%02d-%02d %02d:%02d:%02d tz_minuteswest %d\n", | |
22262 | + 1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday, | |
22263 | + tm.tm_hour, tm.tm_min, tm.tm_sec, | |
22264 | + sys_tz.tz_minuteswest); | |
22265 | + | |
22266 | + kdb_sysinfo(&val); | |
22267 | + kdb_printf("uptime "); | |
22268 | + if (val.uptime > (24*60*60)) { | |
22269 | + int days = val.uptime / (24*60*60); | |
22270 | + val.uptime %= (24*60*60); | |
22271 | + kdb_printf("%d day%s ", days, days == 1 ? "" : "s"); | |
22272 | + } | |
22273 | + kdb_printf("%02ld:%02ld\n", val.uptime/(60*60), (val.uptime/60)%60); | |
22274 | + | |
22275 | + /* lifted from fs/proc/proc_misc.c::loadavg_read_proc() */ | |
22276 | + | |
22277 | +#define LOAD_INT(x) ((x) >> FSHIFT) | |
22278 | +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) | |
22279 | + kdb_printf("load avg %ld.%02ld %ld.%02ld %ld.%02ld\n", | |
22280 | + LOAD_INT(val.loads[0]), LOAD_FRAC(val.loads[0]), | |
22281 | + LOAD_INT(val.loads[1]), LOAD_FRAC(val.loads[1]), | |
22282 | + LOAD_INT(val.loads[2]), LOAD_FRAC(val.loads[2])); | |
22283 | + kdb_printf("\n"); | |
22284 | +#undef LOAD_INT | |
22285 | +#undef LOAD_FRAC | |
22286 | + | |
22287 | + kdb_meminfo_read_proc(); /* in fs/proc/proc_misc.c */ | |
22288 | + | |
22289 | + return 0; | |
22290 | +} | |
22291 | + | |
22292 | +/* | |
22293 | + * kdb_per_cpu | |
22294 | + * | |
22295 | + * This function implements the 'per_cpu' command. | |
22296 | + * | |
22297 | + * Inputs: | |
22298 | + * argc argument count | |
22299 | + * argv argument vector | |
22300 | + * Outputs: | |
22301 | + * None. | |
22302 | + * Returns: | |
22303 | + * zero for success, a kdb diagnostic if error | |
22304 | + * Locking: | |
22305 | + * none. | |
22306 | + * Remarks: | |
22307 | + */ | |
22308 | + | |
22309 | +static int | |
22310 | +kdb_per_cpu(int argc, const char **argv) | |
22311 | +{ | |
22312 | + char buf[256], fmtstr[64]; | |
22313 | + kdb_symtab_t symtab; | |
22314 | + cpumask_t suppress = CPU_MASK_NONE; | |
22315 | + int cpu, diag; | |
22316 | + unsigned long addr, val, bytesperword = 0, whichcpu = ~0UL; | |
22317 | + | |
22318 | + if (argc < 1 || argc > 3) | |
22319 | + return KDB_ARGCOUNT; | |
22320 | + | |
22321 | + snprintf(buf, sizeof(buf), "per_cpu__%s", argv[1]); | |
22322 | + if (!kdbgetsymval(buf, &symtab)) { | |
22323 | + kdb_printf("%s is not a per_cpu variable\n", argv[1]); | |
22324 | + return KDB_BADADDR; | |
22325 | + } | |
22326 | + if (argc >=2 && (diag = kdbgetularg(argv[2], &bytesperword))) | |
22327 | + return diag; | |
22328 | + if (!bytesperword) | |
22329 | + bytesperword = KDB_WORD_SIZE; | |
22330 | + else if (bytesperword > KDB_WORD_SIZE) | |
22331 | + return KDB_BADWIDTH; | |
22332 | + sprintf(fmtstr, "%%0%dlx ", (int)(2*bytesperword)); | |
22333 | + if (argc >= 3) { | |
22334 | + if ((diag = kdbgetularg(argv[3], &whichcpu))) | |
22335 | + return diag; | |
22336 | + if (!cpu_online(whichcpu)) { | |
22337 | + kdb_printf("cpu %ld is not online\n", whichcpu); | |
22338 | + return KDB_BADCPUNUM; | |
22339 | + } | |
22340 | + } | |
22341 | + | |
22342 | + /* Most architectures use __per_cpu_offset[cpu], some use | |
22343 | + * __per_cpu_offset(cpu), smp has no __per_cpu_offset. | |
22344 | + */ | |
22345 | +#ifdef __per_cpu_offset | |
22346 | +#define KDB_PCU(cpu) __per_cpu_offset(cpu) | |
22347 | +#else | |
22348 | +#ifdef CONFIG_SMP | |
22349 | +#define KDB_PCU(cpu) __per_cpu_offset[cpu] | |
22350 | +#else | |
22351 | +#define KDB_PCU(cpu) 0 | |
22352 | +#endif | |
22353 | +#endif | |
22354 | + | |
22355 | + for_each_online_cpu(cpu) { | |
22356 | + if (whichcpu != ~0UL && whichcpu != cpu) | |
22357 | + continue; | |
22358 | + addr = symtab.sym_start + KDB_PCU(cpu); | |
22359 | + if ((diag = kdb_getword(&val, addr, bytesperword))) { | |
22360 | + kdb_printf("%5d " kdb_bfd_vma_fmt0 " - unable to read, diag=%d\n", | |
22361 | + cpu, addr, diag); | |
22362 | + continue; | |
22363 | + } | |
22364 | +#ifdef CONFIG_SMP | |
22365 | + if (!val) { | |
22366 | + cpu_set(cpu, suppress); | |
22367 | + continue; | |
22368 | + } | |
22369 | +#endif /* CONFIG_SMP */ | |
22370 | + kdb_printf("%5d ", cpu); | |
22371 | + kdb_md_line(fmtstr, addr, | |
22372 | + bytesperword == KDB_WORD_SIZE, | |
22373 | + 1, bytesperword, 1, 1, 0); | |
22374 | + } | |
22375 | + if (cpus_weight(suppress) == 0) | |
22376 | + return 0; | |
22377 | + kdb_printf("Zero suppressed cpu(s):"); | |
22378 | + for (cpu = first_cpu(suppress); cpu < NR_CPUS; cpu = next_cpu(cpu, suppress)) { | |
22379 | + kdb_printf(" %d", cpu); | |
22380 | + if (cpu == NR_CPUS-1 || next_cpu(cpu, suppress) != cpu + 1) | |
22381 | + continue; | |
22382 | + while (cpu < NR_CPUS && next_cpu(cpu, suppress) == cpu + 1) | |
22383 | + ++cpu; | |
22384 | + kdb_printf("-%d", cpu); | |
22385 | + } | |
22386 | + kdb_printf("\n"); | |
22387 | + | |
22388 | +#undef KDB_PCU | |
22389 | + | |
22390 | + return 0; | |
22391 | +} | |
22392 | + | |
22393 | +/* | |
22394 | + * display help for the use of cmd | grep pattern | |
22395 | + */ | |
22396 | +static int | |
22397 | +kdb_grep_help(int argc, const char **argv) | |
22398 | +{ | |
22399 | + kdb_printf ("Usage of cmd args | grep pattern:\n"); | |
22400 | + kdb_printf (" Any command's output may be filtered through an "); | |
22401 | + kdb_printf ("emulated 'pipe'.\n"); | |
22402 | + kdb_printf (" 'grep' is just a key word.\n"); | |
22403 | + kdb_printf | |
22404 | + (" The pattern may include a very limited set of metacharacters:\n"); | |
22405 | + kdb_printf (" pattern or ^pattern or pattern$ or ^pattern$\n"); | |
22406 | + kdb_printf | |
22407 | + (" And if there are spaces in the pattern, you may quote it:\n"); | |
22408 | + kdb_printf | |
22409 | + (" \"pat tern\" or \"^pat tern\" or \"pat tern$\" or \"^pat tern$\"\n"); | |
22410 | + return 0; | |
22411 | +} | |
22412 | + | |
22413 | +/* | |
22414 | + * kdb_register_repeat | |
22415 | + * | |
22416 | + * This function is used to register a kernel debugger command. | |
22417 | + * | |
22418 | + * Inputs: | |
22419 | + * cmd Command name | |
22420 | + * func Function to execute the command | |
22421 | + * usage A simple usage string showing arguments | |
22422 | + * help A simple help string describing command | |
22423 | + * repeat Does the command auto repeat on enter? | |
22424 | + * Outputs: | |
22425 | + * None. | |
22426 | + * Returns: | |
22427 | + * zero for success, one if a duplicate command. | |
22428 | + * Locking: | |
22429 | + * none. | |
22430 | + * Remarks: | |
22431 | + * | |
22432 | + */ | |
22433 | + | |
22434 | +#define kdb_command_extend 50 /* arbitrary */ | |
22435 | +int | |
22436 | +kdb_register_repeat(char *cmd, | |
22437 | + kdb_func_t func, | |
22438 | + char *usage, | |
22439 | + char *help, | |
22440 | + short minlen, | |
22441 | + kdb_repeat_t repeat) | |
22442 | +{ | |
22443 | + int i; | |
22444 | + kdbtab_t *kp; | |
22445 | + | |
22446 | + /* | |
22447 | + * Brute force method to determine duplicates | |
22448 | + */ | |
22449 | + for (i=0, kp=kdb_commands; i<kdb_max_commands; i++, kp++) { | |
22450 | + if (kp->cmd_name && (strcmp(kp->cmd_name, cmd)==0)) { | |
22451 | + kdb_printf("Duplicate kdb command registered: " | |
22452 | + "%s, func %p help %s\n", cmd, func, help); | |
22453 | + return 1; | |
22454 | + } | |
22455 | + } | |
22456 | + | |
22457 | + /* | |
22458 | + * Insert command into first available location in table | |
22459 | + */ | |
22460 | + for (i=0, kp=kdb_commands; i<kdb_max_commands; i++, kp++) { | |
22461 | + if (kp->cmd_name == NULL) { | |
22462 | + break; | |
22463 | + } | |
22464 | + } | |
22465 | + | |
22466 | + if (i >= kdb_max_commands) { | |
22467 | + kdbtab_t *new = kmalloc((kdb_max_commands + kdb_command_extend) * sizeof(*new), GFP_KDB); | |
22468 | + if (!new) { | |
22469 | + kdb_printf("Could not allocate new kdb_command table\n"); | |
22470 | + return 1; | |
22471 | + } | |
22472 | + if (kdb_commands) { | |
22473 | + memcpy(new, kdb_commands, kdb_max_commands * sizeof(*new)); | |
22474 | + kfree(kdb_commands); | |
22475 | + } | |
22476 | + memset(new + kdb_max_commands, 0, kdb_command_extend * sizeof(*new)); | |
22477 | + kdb_commands = new; | |
22478 | + kp = kdb_commands + kdb_max_commands; | |
22479 | + kdb_max_commands += kdb_command_extend; | |
22480 | + } | |
22481 | + | |
22482 | + kp->cmd_name = cmd; | |
22483 | + kp->cmd_func = func; | |
22484 | + kp->cmd_usage = usage; | |
22485 | + kp->cmd_help = help; | |
22486 | + kp->cmd_flags = 0; | |
22487 | + kp->cmd_minlen = minlen; | |
22488 | + kp->cmd_repeat = repeat; | |
22489 | + | |
22490 | + return 0; | |
22491 | +} | |
22492 | + | |
22493 | +/* | |
22494 | + * kdb_register | |
22495 | + * | |
22496 | + * Compatibility register function for commands that do not need to | |
22497 | + * specify a repeat state. Equivalent to kdb_register_repeat with | |
22498 | + * KDB_REPEAT_NONE. | |
22499 | + * | |
22500 | + * Inputs: | |
22501 | + * cmd Command name | |
22502 | + * func Function to execute the command | |
22503 | + * usage A simple usage string showing arguments | |
22504 | + * help A simple help string describing command | |
22505 | + * Outputs: | |
22506 | + * None. | |
22507 | + * Returns: | |
22508 | + * zero for success, one if a duplicate command. | |
22509 | + * Locking: | |
22510 | + * none. | |
22511 | + * Remarks: | |
22512 | + * | |
22513 | + */ | |
22514 | + | |
22515 | +int | |
22516 | +kdb_register(char *cmd, | |
22517 | + kdb_func_t func, | |
22518 | + char *usage, | |
22519 | + char *help, | |
22520 | + short minlen) | |
22521 | +{ | |
22522 | + return kdb_register_repeat(cmd, func, usage, help, minlen, KDB_REPEAT_NONE); | |
22523 | +} | |
22524 | + | |
22525 | +/* | |
22526 | + * kdb_unregister | |
22527 | + * | |
22528 | + * This function is used to unregister a kernel debugger command. | |
22529 | + * It is generally called when a module which implements kdb | |
22530 | + * commands is unloaded. | |
22531 | + * | |
22532 | + * Inputs: | |
22533 | + * cmd Command name | |
22534 | + * Outputs: | |
22535 | + * None. | |
22536 | + * Returns: | |
22537 | + * zero for success, one command not registered. | |
22538 | + * Locking: | |
22539 | + * none. | |
22540 | + * Remarks: | |
22541 | + * | |
22542 | + */ | |
22543 | + | |
22544 | +int | |
22545 | +kdb_unregister(char *cmd) | |
22546 | +{ | |
22547 | + int i; | |
22548 | + kdbtab_t *kp; | |
22549 | + | |
22550 | + /* | |
22551 | + * find the command. | |
22552 | + */ | |
22553 | + for (i=0, kp=kdb_commands; i<kdb_max_commands; i++, kp++) { | |
22554 | + if (kp->cmd_name && (strcmp(kp->cmd_name, cmd)==0)) { | |
22555 | + kp->cmd_name = NULL; | |
22556 | + return 0; | |
22557 | + } | |
22558 | + } | |
22559 | + | |
22560 | + /* | |
22561 | + * Couldn't find it. | |
22562 | + */ | |
22563 | + return 1; | |
22564 | +} | |
22565 | + | |
22566 | +/* | |
22567 | + * kdb_inittab | |
22568 | + * | |
22569 | + * This function is called by the kdb_init function to initialize | |
22570 | + * the kdb command table. It must be called prior to any other | |
22571 | + * call to kdb_register_repeat. | |
22572 | + * | |
22573 | + * Inputs: | |
22574 | + * None. | |
22575 | + * Outputs: | |
22576 | + * None. | |
22577 | + * Returns: | |
22578 | + * None. | |
22579 | + * Locking: | |
22580 | + * None. | |
22581 | + * Remarks: | |
22582 | + * | |
22583 | + */ | |
22584 | + | |
22585 | +static void __init | |
22586 | +kdb_inittab(void) | |
22587 | +{ | |
22588 | + int i; | |
22589 | + kdbtab_t *kp; | |
22590 | + | |
22591 | + for(i=0, kp=kdb_commands; i < kdb_max_commands; i++,kp++) { | |
22592 | + kp->cmd_name = NULL; | |
22593 | + } | |
22594 | + | |
22595 | + kdb_register_repeat("md", kdb_md, "<vaddr>", "Display Memory Contents, also mdWcN, e.g. md8c1", 1, KDB_REPEAT_NO_ARGS); | |
22596 | + kdb_register_repeat("mdr", kdb_md, "<vaddr> <bytes>", "Display Raw Memory", 0, KDB_REPEAT_NO_ARGS); | |
22597 | + kdb_register_repeat("mdp", kdb_md, "<paddr> <bytes>", "Display Physical Memory", 0, KDB_REPEAT_NO_ARGS); | |
22598 | + kdb_register_repeat("mds", kdb_md, "<vaddr>", "Display Memory Symbolically", 0, KDB_REPEAT_NO_ARGS); | |
22599 | + kdb_register_repeat("mm", kdb_mm, "<vaddr> <contents>", "Modify Memory Contents", 0, KDB_REPEAT_NO_ARGS); | |
22600 | + kdb_register_repeat("id", kdb_id, "<vaddr>", "Display Instructions", 1, KDB_REPEAT_NO_ARGS); | |
22601 | + kdb_register_repeat("go", kdb_go, "[<vaddr>]", "Continue Execution", 1, KDB_REPEAT_NONE); | |
22602 | + kdb_register_repeat("rd", kdb_rd, "", "Display Registers", 1, KDB_REPEAT_NONE); | |
22603 | + kdb_register_repeat("rm", kdb_rm, "<reg> <contents>", "Modify Registers", 0, KDB_REPEAT_NONE); | |
22604 | + kdb_register_repeat("ef", kdb_ef, "<vaddr>", "Display exception frame", 0, KDB_REPEAT_NONE); | |
22605 | + kdb_register_repeat("bt", kdb_bt, "[<vaddr>]", "Stack traceback", 1, KDB_REPEAT_NONE); | |
22606 | + kdb_register_repeat("btp", kdb_bt, "<pid>", "Display stack for process <pid>", 0, KDB_REPEAT_NONE); | |
22607 | + kdb_register_repeat("bta", kdb_bt, "[DRSTCZEUIMA]", "Display stack all processes", 0, KDB_REPEAT_NONE); | |
22608 | + kdb_register_repeat("btc", kdb_bt, "", "Backtrace current process on each cpu", 0, KDB_REPEAT_NONE); | |
22609 | + kdb_register_repeat("btt", kdb_bt, "<vaddr>", "Backtrace process given its struct task address", 0, KDB_REPEAT_NONE); | |
22610 | + kdb_register_repeat("ll", kdb_ll, "<first-element> <linkoffset> <cmd>", "Execute cmd for each element in linked list", 0, KDB_REPEAT_NONE); | |
22611 | + kdb_register_repeat("env", kdb_env, "", "Show environment variables", 0, KDB_REPEAT_NONE); | |
22612 | + kdb_register_repeat("set", kdb_set, "", "Set environment variables", 0, KDB_REPEAT_NONE); | |
22613 | + kdb_register_repeat("help", kdb_help, "", "Display Help Message", 1, KDB_REPEAT_NONE); | |
22614 | + kdb_register_repeat("?", kdb_help, "", "Display Help Message", 0, KDB_REPEAT_NONE); | |
22615 | + kdb_register_repeat("cpu", kdb_cpu, "<cpunum>","Switch to new cpu", 0, KDB_REPEAT_NONE); | |
22616 | + kdb_register_repeat("ps", kdb_ps, "[<flags>|A]", "Display active task list", 0, KDB_REPEAT_NONE); | |
22617 | + kdb_register_repeat("pid", kdb_pid, "<pidnum>", "Switch to another task", 0, KDB_REPEAT_NONE); | |
22618 | + kdb_register_repeat("reboot", kdb_reboot, "", "Reboot the machine immediately", 0, KDB_REPEAT_NONE); | |
22619 | +#if defined(CONFIG_KDB_KDUMP) | |
22620 | + kdb_register_repeat("kdump", kdb_kdump, "", "Calls kdump mode", 0, KDB_REPEAT_NONE); | |
22621 | +#endif | |
22622 | +#if defined(CONFIG_MODULES) | |
22623 | + kdb_register_repeat("lsmod", kdb_lsmod, "", "List loaded kernel modules", 0, KDB_REPEAT_NONE); | |
22624 | +#endif | |
22625 | +#if defined(CONFIG_MAGIC_SYSRQ) | |
22626 | + kdb_register_repeat("sr", kdb_sr, "<key>", "Magic SysRq key", 0, KDB_REPEAT_NONE); | |
22627 | +#endif | |
22628 | + kdb_register_repeat("dmesg", kdb_dmesg, "[lines]", "Display syslog buffer", 0, KDB_REPEAT_NONE); | |
22629 | + kdb_register_repeat("defcmd", kdb_defcmd, "name \"usage\" \"help\"", "Define a set of commands, down to endefcmd", 0, KDB_REPEAT_NONE); | |
22630 | + kdb_register_repeat("kill", kdb_kill, "<-signal> <pid>", "Send a signal to a process", 0, KDB_REPEAT_NONE); | |
22631 | + kdb_register_repeat("summary", kdb_summary, "", "Summarize the system", 4, KDB_REPEAT_NONE); | |
22632 | + kdb_register_repeat("per_cpu", kdb_per_cpu, "", "Display per_cpu variables", 3, KDB_REPEAT_NONE); | |
22633 | + kdb_register_repeat("grephelp", kdb_grep_help, "", | |
22634 | + "Display help on | grep", 0, KDB_REPEAT_NONE); | |
22635 | + kdb_register_repeat("print", kdb_debuginfo_print, "<expression>", | |
22636 | + "Type casting, as in lcrash", 0, KDB_REPEAT_NONE); | |
22637 | + kdb_register_repeat("px", kdb_debuginfo_print, "<expression>", | |
22638 | + "Print in hex (type casting) (see 'pxhelp')", 0, KDB_REPEAT_NONE); | |
22639 | + kdb_register_repeat("pxhelp", kdb_pxhelp, "", | |
22640 | + "Display help for the px command", 0, KDB_REPEAT_NONE); | |
22641 | + kdb_register_repeat("pd", kdb_debuginfo_print, "<expression>", | |
22642 | + "Print in decimal (type casting)", 0, KDB_REPEAT_NONE); | |
22643 | + kdb_register_repeat("whatis", kdb_debuginfo_print,"<type or symbol>", | |
22644 | + "Display the type, or the address for a symbol", 0, KDB_REPEAT_NONE); | |
22645 | + kdb_register_repeat("sizeof", kdb_debuginfo_print, "<type>", | |
22646 | + "Display the size of a structure, typedef, etc.", 0, KDB_REPEAT_NONE); | |
22647 | + kdb_register_repeat("walk", kdb_walk, "", | |
22648 | + "Walk a linked list (see 'walkhelp')", 0, KDB_REPEAT_NONE); | |
22649 | + kdb_register_repeat("walkhelp", kdb_walkhelp, "", | |
22650 | + "Display help for the walk command", 0, KDB_REPEAT_NONE); | |
22651 | +} | |
22652 | + | |
22653 | +/* | |
22654 | + * The user has written to our "file" | |
22655 | + * file: the /proc file | |
22656 | + * buffer: user address of the data he is writing | |
22657 | + * count: number of bytes in the user's buffer | |
22658 | + */ | |
22659 | +static int | |
22660 | +kdb_write_proc_filename(struct file *file, const char __user *buffer, | |
22661 | + unsigned long count, void *data) | |
22662 | +{ | |
22663 | + int ret_count; | |
22664 | + | |
22665 | + /* our buffer is kdb_debug_info_filename[256] */ | |
22666 | + if (count > 256) { | |
22667 | + return 0; | |
22668 | + } | |
22669 | + if (copy_from_user(kdb_debug_info_filename, buffer, count)) { | |
22670 | + return 0; | |
22671 | + } | |
22672 | + ret_count = count; /* actual count */ | |
22673 | + /* remove any newline from the end of the file name */ | |
22674 | + if (kdb_debug_info_filename[count-1] == '\n') count--; | |
22675 | + kdb_debug_info_filename[count] = '\0'; | |
22676 | + | |
22677 | + return ret_count; | |
22678 | +} | |
22679 | + | |
22680 | +/* | |
22681 | + * The user is reading from our "file" | |
22682 | + * page: the beginning of the user's buffer | |
22683 | + * start: pointer to the user's pointer (tells him where we put the data) | |
22684 | + * off: offset into the resource to be read | |
22685 | + * count: length of the read | |
22686 | + */ | |
22687 | +static int | |
22688 | +kdb_read_proc_filename(char *page, char **start, off_t off, | |
22689 | + int count, int *eof, void *data) | |
22690 | +{ | |
22691 | + /* give him kdb_debug_info_filename[]; */ | |
22692 | + return snprintf(page, count, "%s\n", kdb_debug_info_filename); | |
22693 | +} | |
22694 | + | |
22695 | +/* | |
22696 | + * kdb_proc_filename | |
22697 | + * | |
22698 | + * create /proc/kdb/debug_info_name | |
22699 | + */ | |
22700 | +static void | |
22701 | +kdb_proc_filename(void) | |
22702 | +{ | |
22703 | + struct proc_dir_entry *kdb_dir_entry, *kdb_file_entry; | |
22704 | + | |
22705 | + /* create /proc/kdb */ | |
22706 | + kdb_dir_entry = proc_mkdir("kdb", NULL); | |
22707 | + if (!kdb_dir_entry) { | |
22708 | + printk ("kdb could not create /proc/kdb\n"); | |
22709 | + return; | |
22710 | + } | |
22711 | + | |
22712 | + /* read/write by owner (root) only */ | |
22713 | + kdb_file_entry = create_proc_entry("debug_info_name", | |
22714 | + S_IRUSR | S_IWUSR, kdb_dir_entry); | |
22715 | + if (!kdb_file_entry) { | |
22716 | + printk ("kdb could not create /proc/kdb/kdb_dir_entry\n"); | |
22717 | + return; | |
22718 | + } | |
22719 | + kdb_file_entry->nlink = 1; | |
22720 | + kdb_file_entry->data = (void *)NULL; | |
22721 | + kdb_file_entry->read_proc = kdb_read_proc_filename; | |
22722 | + kdb_file_entry->write_proc = kdb_write_proc_filename; | |
22723 | + return; | |
22724 | +} | |
22725 | + | |
22726 | +/* | |
22727 | + * kdb_cmd_init | |
22728 | + * | |
22729 | + * This function is called by the kdb_init function to execute any | |
22730 | + * commands defined in kdb_cmds. | |
22731 | + * | |
22732 | + * Inputs: | |
22733 | + * Commands in *kdb_cmds[]; | |
22734 | + * Outputs: | |
22735 | + * None. | |
22736 | + * Returns: | |
22737 | + * None. | |
22738 | + * Locking: | |
22739 | + * None. | |
22740 | + * Remarks: | |
22741 | + * | |
22742 | + */ | |
22743 | + | |
22744 | +static void __init | |
22745 | +kdb_cmd_init(void) | |
22746 | +{ | |
22747 | + int i, diag; | |
22748 | + for (i = 0; kdb_cmds[i]; ++i) { | |
22749 | + if (!defcmd_in_progress) | |
22750 | + if (console_loglevel >= 6 /* KERN_INFO */) | |
22751 | + kdb_printf("kdb_cmd[%d]: %s", i, kdb_cmds[i]); | |
22752 | + diag = kdb_parse(kdb_cmds[i]); | |
22753 | + if (diag) | |
22754 | + kdb_printf("kdb command %s failed, kdb diag %d\n", | |
22755 | + kdb_cmds[i], diag); | |
22756 | + } | |
22757 | + if (defcmd_in_progress) { | |
22758 | + kdb_printf("Incomplete 'defcmd' set, forcing endefcmd\n"); | |
22759 | + kdb_parse("endefcmd"); | |
22760 | + } | |
22761 | +} | |
22762 | + | |
22763 | +/* | |
22764 | + * kdb_panic | |
22765 | + * | |
22766 | + * Invoked via the panic_notifier_list. | |
22767 | + * | |
22768 | + * Inputs: | |
22769 | + * None. | |
22770 | + * Outputs: | |
22771 | + * None. | |
22772 | + * Returns: | |
22773 | + * Zero. | |
22774 | + * Locking: | |
22775 | + * None. | |
22776 | + * Remarks: | |
22777 | + * When this function is called from panic(), the other cpus have already | |
22778 | + * been stopped. | |
22779 | + * | |
22780 | + */ | |
22781 | + | |
22782 | +static int | |
22783 | +kdb_panic(struct notifier_block *self, unsigned long command, void *ptr) | |
22784 | +{ | |
22785 | + KDB_FLAG_SET(CATASTROPHIC); /* kernel state is dubious now */ | |
22786 | + KDB_ENTER(); | |
22787 | + return 0; | |
22788 | +} | |
22789 | + | |
22790 | +static struct notifier_block kdb_block = { kdb_panic, NULL, 0 }; | |
22791 | + | |
22792 | +#ifdef CONFIG_SYSCTL | |
22793 | +static int proc_do_kdb(ctl_table *table, int write, struct file *filp, | |
22794 | + void __user *buffer, size_t *lenp, loff_t *ppos) | |
22795 | +{ | |
22796 | + if (KDB_FLAG(NO_CONSOLE) && write) { | |
22797 | + printk(KERN_ERR "kdb has no working console and has switched itself off\n"); | |
22798 | + return -EINVAL; | |
22799 | + } | |
22800 | + return proc_dointvec(table, write, filp, buffer, lenp, ppos); | |
22801 | +} | |
22802 | + | |
22803 | +static ctl_table kdb_kern_table[] = { | |
22804 | + { | |
22805 | + .ctl_name = KERN_KDB, | |
22806 | + .procname = "kdb", | |
22807 | + .data = &kdb_on, | |
22808 | + .maxlen = sizeof(int), | |
22809 | + .mode = 0644, | |
22810 | + .proc_handler = &proc_do_kdb, | |
22811 | + .strategy = &sysctl_intvec, | |
22812 | + }, | |
22813 | + {} | |
22814 | +}; | |
22815 | + | |
22816 | +static ctl_table kdb_root_table[] = { | |
22817 | + { | |
22818 | + .ctl_name = CTL_KERN, | |
22819 | + .procname = "kernel", | |
22820 | + .mode = 0555, | |
22821 | + .child = kdb_kern_table, | |
22822 | + }, | |
22823 | + {} | |
22824 | +}; | |
22825 | +#endif /* CONFIG_SYSCTL */ | |
22826 | + | |
22827 | +static int | |
22828 | +kdb_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) | |
22829 | +{ | |
22830 | + if (action == CPU_ONLINE) { | |
22831 | + int cpu =(unsigned long)hcpu; | |
22832 | + cpumask_t save_cpus_allowed = current->cpus_allowed; | |
22833 | + cpumask_t new_cpus_allowed = cpumask_of_cpu(cpu); | |
22834 | + set_cpus_allowed(current, new_cpus_allowed); | |
22835 | + kdb(KDB_REASON_CPU_UP, 0, NULL); /* do kdb setup on this cpu */ | |
22836 | + set_cpus_allowed(current, save_cpus_allowed); | |
22837 | + } | |
22838 | + return NOTIFY_OK; | |
22839 | +} | |
22840 | + | |
22841 | +static struct notifier_block kdb_cpu_nfb = { | |
22842 | + .notifier_call = kdb_cpu_callback | |
22843 | +}; | |
22844 | + | |
22845 | +/* | |
22846 | + * kdb_init | |
22847 | + * | |
22848 | + * Initialize the kernel debugger environment. | |
22849 | + * | |
22850 | + * Parameters: | |
22851 | + * None. | |
22852 | + * Returns: | |
22853 | + * None. | |
22854 | + * Locking: | |
22855 | + * None. | |
22856 | + * Remarks: | |
22857 | + * None. | |
22858 | + */ | |
22859 | + | |
22860 | +void __init | |
22861 | +kdb_init(void) | |
22862 | +{ | |
22863 | + kdb_initial_cpu = smp_processor_id(); | |
22864 | + /* | |
22865 | + * This must be called before any calls to kdb_printf. | |
22866 | + */ | |
22867 | + kdb_io_init(); | |
22868 | + | |
22869 | + kdb_inittab(); /* Initialize Command Table */ | |
22870 | + kdb_initbptab(); /* Initialize Breakpoint Table */ | |
22871 | + kdb_id_init(); /* Initialize Disassembler */ | |
22872 | + kdba_init(); /* Architecture Dependent Initialization */ | |
22873 | + | |
22874 | + /* | |
22875 | + * Use printk() to get message in log_buf[]; | |
22876 | + */ | |
22877 | + printk("kdb version %d.%d%s by Keith Owens, Scott Lurndal. "\ | |
22878 | + "Copyright SGI, All Rights Reserved\n", | |
22879 | + KDB_MAJOR_VERSION, KDB_MINOR_VERSION, KDB_TEST_VERSION); | |
22880 | + | |
22881 | + kdb_cmd_init(); /* Preset commands from kdb_cmds */ | |
22882 | + kdb_initial_cpu = -1; /* Avoid recursion problems */ | |
22883 | + kdb(KDB_REASON_CPU_UP, 0, NULL); /* do kdb setup on boot cpu */ | |
22884 | + kdb_initial_cpu = smp_processor_id(); | |
22885 | + atomic_notifier_chain_register(&panic_notifier_list, &kdb_block); | |
22886 | + register_cpu_notifier(&kdb_cpu_nfb); | |
22887 | + | |
22888 | +#ifdef kdba_setjmp | |
22889 | + kdbjmpbuf = vmalloc(NR_CPUS * sizeof(*kdbjmpbuf)); | |
22890 | + if (!kdbjmpbuf) | |
22891 | + printk(KERN_ERR "Cannot allocate kdbjmpbuf, no kdb recovery will be possible\n"); | |
22892 | +#endif /* kdba_setjmp */ | |
22893 | + | |
22894 | + kdb_initial_cpu = -1; | |
22895 | + kdb_wait_for_cpus_secs = max(10, 2*num_online_cpus()); | |
22896 | +} | |
22897 | + | |
22898 | +#ifdef CONFIG_SYSCTL | |
22899 | +static int __init | |
22900 | +kdb_late_init(void) | |
22901 | +{ | |
22902 | + register_sysctl_table(kdb_root_table); | |
22903 | + /* seems that we cannot allocate with kmalloc until now */ | |
22904 | + kdb_proc_filename(); | |
22905 | + return 0; | |
22906 | +} | |
22907 | + | |
22908 | +__initcall(kdb_late_init); | |
22909 | +#endif | |
22910 | + | |
22911 | +EXPORT_SYMBOL(kdb_register); | |
22912 | +EXPORT_SYMBOL(kdb_register_repeat); | |
22913 | +EXPORT_SYMBOL(kdb_unregister); | |
22914 | +EXPORT_SYMBOL(kdb_getarea_size); | |
22915 | +EXPORT_SYMBOL(kdb_putarea_size); | |
22916 | +EXPORT_SYMBOL(kdb_getuserarea_size); | |
22917 | +EXPORT_SYMBOL(kdb_putuserarea_size); | |
22918 | +EXPORT_SYMBOL(kdbgetularg); | |
22919 | +EXPORT_SYMBOL(kdbgetenv); | |
22920 | +EXPORT_SYMBOL(kdbgetintenv); | |
22921 | +EXPORT_SYMBOL(kdbgetaddrarg); | |
22922 | +EXPORT_SYMBOL(kdb); | |
22923 | +EXPORT_SYMBOL(kdb_on); | |
22924 | +EXPORT_SYMBOL(kdb_seqno); | |
22925 | +EXPORT_SYMBOL(kdb_initial_cpu); | |
22926 | +EXPORT_SYMBOL(kdbnearsym); | |
22927 | +EXPORT_SYMBOL(kdb_printf); | |
22928 | +EXPORT_SYMBOL(kdb_symbol_print); | |
22929 | +EXPORT_SYMBOL(kdb_running_process); | |
22930 | --- /dev/null | |
22931 | +++ b/kdb/kdbsupport.c | |
22932 | @@ -0,0 +1,1154 @@ | |
22933 | +/* | |
22934 | + * Kernel Debugger Architecture Independent Support Functions | |
22935 | + * | |
22936 | + * This file is subject to the terms and conditions of the GNU General Public | |
22937 | + * License. See the file "COPYING" in the main directory of this archive | |
22938 | + * for more details. | |
22939 | + * | |
22940 | + * Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved. | |
22941 | + * 03/02/13 added new 2.5 kallsyms <xavier.bru@bull.net> | |
22942 | + */ | |
22943 | + | |
22944 | +#include <stdarg.h> | |
22945 | +#include <linux/types.h> | |
22946 | +#include <linux/sched.h> | |
22947 | +#include <linux/mm.h> | |
22948 | +#include <linux/kallsyms.h> | |
22949 | +#include <linux/stddef.h> | |
22950 | +#include <linux/vmalloc.h> | |
22951 | +#include <linux/ptrace.h> | |
22952 | +#include <linux/module.h> | |
22953 | +#include <linux/highmem.h> | |
22954 | +#include <linux/hardirq.h> | |
22955 | +#include <linux/delay.h> | |
22956 | + | |
22957 | +#include <asm/uaccess.h> | |
22958 | + | |
22959 | +#include <linux/kdb.h> | |
22960 | +#include <linux/kdbprivate.h> | |
22961 | + | |
22962 | +/* | |
22963 | + * Symbol table functions. | |
22964 | + */ | |
22965 | + | |
22966 | +/* | |
22967 | + * kdbgetsymval | |
22968 | + * | |
22969 | + * Return the address of the given symbol. | |
22970 | + * | |
22971 | + * Parameters: | |
22972 | + * symname Character string containing symbol name | |
22973 | + * symtab Structure to receive results | |
22974 | + * Outputs: | |
22975 | + * Returns: | |
22976 | + * 0 Symbol not found, symtab zero filled | |
22977 | + * 1 Symbol mapped to module/symbol/section, data in symtab | |
22978 | + * Locking: | |
22979 | + * None. | |
22980 | + * Remarks: | |
22981 | + */ | |
22982 | + | |
22983 | +int | |
22984 | +kdbgetsymval(const char *symname, kdb_symtab_t *symtab) | |
22985 | +{ | |
22986 | + if (KDB_DEBUG(AR)) | |
22987 | + kdb_printf("kdbgetsymval: symname=%s, symtab=%p\n", symname, symtab); | |
22988 | + memset(symtab, 0, sizeof(*symtab)); | |
22989 | + | |
22990 | + if ((symtab->sym_start = kallsyms_lookup_name(symname))) { | |
22991 | + if (KDB_DEBUG(AR)) | |
22992 | + kdb_printf("kdbgetsymval: returns 1, symtab->sym_start=0x%lx\n", symtab->sym_start); | |
22993 | + return 1; | |
22994 | + } | |
22995 | + if (KDB_DEBUG(AR)) | |
22996 | + kdb_printf("kdbgetsymval: returns 0\n"); | |
22997 | + return 0; | |
22998 | +} | |
22999 | +EXPORT_SYMBOL(kdbgetsymval); | |
23000 | + | |
23001 | +/* | |
23002 | + * kdbnearsym | |
23003 | + * | |
23004 | + * Return the name of the symbol with the nearest address | |
23005 | + * less than 'addr'. | |
23006 | + * | |
23007 | + * Parameters: | |
23008 | + * addr Address to check for symbol near | |
23009 | + * symtab Structure to receive results | |
23010 | + * Outputs: | |
23011 | + * Returns: | |
23012 | + * 0 No sections contain this address, symtab zero filled | |
23013 | + * 1 Address mapped to module/symbol/section, data in symtab | |
23014 | + * Locking: | |
23015 | + * None. | |
23016 | + * Remarks: | |
23017 | + * 2.6 kallsyms has a "feature" where it unpacks the name into a string. | |
23018 | + * If that string is reused before the caller expects it then the caller | |
23019 | + * sees its string change without warning. To avoid cluttering up the | |
23020 | + * main kdb code with lots of kdb_strdup, tests and kfree calls, kdbnearsym | |
23021 | + * maintains an LRU list of the last few unique strings. The list is sized | |
23022 | + * large enough to hold active strings, no kdb caller of kdbnearsym makes | |
23023 | + * more than ~20 later calls before using a saved value. | |
23024 | + */ | |
23025 | + | |
23026 | +static char *kdb_name_table[100]; /* arbitrary size */ | |
23027 | + | |
23028 | +int | |
23029 | +kdbnearsym(unsigned long addr, kdb_symtab_t *symtab) | |
23030 | +{ | |
23031 | + int ret = 0; | |
23032 | + unsigned long symbolsize; | |
23033 | + unsigned long offset; | |
23034 | +#define knt1_size 128 /* must be >= kallsyms table size */ | |
23035 | + char *knt1 = NULL; | |
23036 | + | |
23037 | + if (KDB_DEBUG(AR)) | |
23038 | + kdb_printf("kdbnearsym: addr=0x%lx, symtab=%p\n", addr, symtab); | |
23039 | + memset(symtab, 0, sizeof(*symtab)); | |
23040 | + | |
23041 | + if (addr < 4096) | |
23042 | + goto out; | |
23043 | + knt1 = debug_kmalloc(knt1_size, GFP_ATOMIC); | |
23044 | + if (!knt1) { | |
23045 | + kdb_printf("kdbnearsym: addr=0x%lx cannot kmalloc knt1\n", addr); | |
23046 | + goto out; | |
23047 | + } | |
23048 | + symtab->sym_name = kallsyms_lookup(addr, &symbolsize , &offset, (char **)(&symtab->mod_name), knt1); | |
23049 | + if (offset > 8*1024*1024) { | |
23050 | + symtab->sym_name = NULL; | |
23051 | + addr = offset = symbolsize = 0; | |
23052 | + } | |
23053 | + symtab->sym_start = addr - offset; | |
23054 | + symtab->sym_end = symtab->sym_start + symbolsize; | |
23055 | + ret = symtab->sym_name != NULL && *(symtab->sym_name) != '\0'; | |
23056 | + | |
23057 | + if (ret) { | |
23058 | + int i; | |
23059 | + /* Another 2.6 kallsyms "feature". Sometimes the sym_name is | |
23060 | + * set but the buffer passed into kallsyms_lookup is not used, | |
23061 | + * so it contains garbage. The caller has to work out which | |
23062 | + * buffer needs to be saved. | |
23063 | + * | |
23064 | + * What was Rusty smoking when he wrote that code? | |
23065 | + */ | |
23066 | + if (symtab->sym_name != knt1) { | |
23067 | + strncpy(knt1, symtab->sym_name, knt1_size); | |
23068 | + knt1[knt1_size-1] = '\0'; | |
23069 | + } | |
23070 | + for (i = 0; i < ARRAY_SIZE(kdb_name_table); ++i) { | |
23071 | + if (kdb_name_table[i] && strcmp(kdb_name_table[i], knt1) == 0) | |
23072 | + break; | |
23073 | + } | |
23074 | + if (i >= ARRAY_SIZE(kdb_name_table)) { | |
23075 | + debug_kfree(kdb_name_table[0]); | |
23076 | + memcpy(kdb_name_table, kdb_name_table+1, | |
23077 | + sizeof(kdb_name_table[0])*(ARRAY_SIZE(kdb_name_table)-1)); | |
23078 | + } else { | |
23079 | + debug_kfree(knt1); | |
23080 | + knt1 = kdb_name_table[i]; | |
23081 | + memcpy(kdb_name_table+i, kdb_name_table+i+1, | |
23082 | + sizeof(kdb_name_table[0])*(ARRAY_SIZE(kdb_name_table)-i-1)); | |
23083 | + } | |
23084 | + i = ARRAY_SIZE(kdb_name_table) - 1; | |
23085 | + kdb_name_table[i] = knt1; | |
23086 | + symtab->sym_name = kdb_name_table[i]; | |
23087 | + knt1 = NULL; | |
23088 | + } | |
23089 | + | |
23090 | + if (symtab->mod_name == NULL) | |
23091 | + symtab->mod_name = "kernel"; | |
23092 | + if (KDB_DEBUG(AR)) | |
23093 | + kdb_printf("kdbnearsym: returns %d symtab->sym_start=0x%lx, symtab->mod_name=%p, symtab->sym_name=%p (%s)\n", ret, symtab->sym_start, symtab->mod_name, symtab->sym_name, symtab->sym_name); | |
23094 | + | |
23095 | +out: | |
23096 | + debug_kfree(knt1); | |
23097 | + return ret; | |
23098 | +} | |
23099 | + | |
23100 | +void | |
23101 | +kdbnearsym_cleanup(void) | |
23102 | +{ | |
23103 | + int i; | |
23104 | + for (i = 0; i < ARRAY_SIZE(kdb_name_table); ++i) { | |
23105 | + if (kdb_name_table[i]) { | |
23106 | + debug_kfree(kdb_name_table[i]); | |
23107 | + kdb_name_table[i] = NULL; | |
23108 | + } | |
23109 | + } | |
23110 | +} | |
23111 | + | |
23112 | +/* | |
23113 | + * kallsyms_symbol_complete | |
23114 | + * | |
23115 | + * Parameters: | |
23116 | + * prefix_name prefix of a symbol name to lookup | |
23117 | + * max_len maximum length that can be returned | |
23118 | + * Returns: | |
23119 | + * Number of symbols which match the given prefix. | |
23120 | + * Notes: | |
23121 | + * prefix_name is changed to contain the longest unique prefix that | |
23122 | + * starts with this prefix (tab completion). | |
23123 | + */ | |
23124 | + | |
23125 | +static char ks_namebuf[KSYM_NAME_LEN+1], ks_namebuf_prev[KSYM_NAME_LEN+1]; | |
23126 | + | |
23127 | +int kallsyms_symbol_complete(char *prefix_name, int max_len) | |
23128 | +{ | |
23129 | + loff_t pos = 0; | |
23130 | + int prefix_len = strlen(prefix_name), prev_len = 0; | |
23131 | + int i, number = 0; | |
23132 | + const char *name; | |
23133 | + | |
23134 | + while ((name = kdb_walk_kallsyms(&pos))) { | |
23135 | + if (strncmp(name, prefix_name, prefix_len) == 0) { | |
23136 | + strcpy(ks_namebuf, name); | |
23137 | + /* Work out the longest name that matches the prefix */ | |
23138 | + if (++number == 1) { | |
23139 | + prev_len = min_t(int, max_len-1, strlen(ks_namebuf)); | |
23140 | + memcpy(ks_namebuf_prev, ks_namebuf, prev_len); | |
23141 | + ks_namebuf_prev[prev_len] = '\0'; | |
23142 | + } else for (i = 0; i < prev_len; ++i) { | |
23143 | + if (ks_namebuf[i] != ks_namebuf_prev[i]) { | |
23144 | + prev_len = i; | |
23145 | + ks_namebuf_prev[i] = '\0'; | |
23146 | + break; | |
23147 | + } | |
23148 | + } | |
23149 | + } | |
23150 | + } | |
23151 | + if (prev_len > prefix_len) | |
23152 | + memcpy(prefix_name, ks_namebuf_prev, prev_len+1); | |
23153 | + return number; | |
23154 | +} | |
23155 | + | |
23156 | +/* | |
23157 | + * kallsyms_symbol_next | |
23158 | + * | |
23159 | + * Parameters: | |
23160 | + * prefix_name prefix of a symbol name to lookup | |
23161 | + * flag 0 means search from the head, 1 means continue search. | |
23162 | + * Returns: | |
23163 | + * 1 if a symbol matches the given prefix. | |
23164 | + * 0 if no string found | |
23165 | + */ | |
23166 | + | |
23167 | +int kallsyms_symbol_next(char *prefix_name, int flag) | |
23168 | +{ | |
23169 | + int prefix_len = strlen(prefix_name); | |
23170 | + static loff_t pos; | |
23171 | + const char *name; | |
23172 | + | |
23173 | + if (!flag) | |
23174 | + pos = 0; | |
23175 | + | |
23176 | + while ((name = kdb_walk_kallsyms(&pos))) { | |
23177 | + if (strncmp(name, prefix_name, prefix_len) == 0) { | |
23178 | + strncpy(prefix_name, name, strlen(name)+1); | |
23179 | + return 1; | |
23180 | + } | |
23181 | + } | |
23182 | + return 0; | |
23183 | +} | |
23184 | + | |
23185 | +#if defined(CONFIG_SMP) | |
23186 | +/* | |
23187 | + * kdb_ipi | |
23188 | + * | |
23189 | + * This function is called from the non-maskable interrupt | |
23190 | + * handler to handle a kdb IPI instruction. | |
23191 | + * | |
23192 | + * Inputs: | |
23193 | + * regs = Exception frame pointer | |
23194 | + * Outputs: | |
23195 | + * None. | |
23196 | + * Returns: | |
23197 | + * 0 - Did not handle NMI | |
23198 | + * 1 - Handled NMI | |
23199 | + * Locking: | |
23200 | + * None. | |
23201 | + * Remarks: | |
23202 | + * Initially one processor is invoked in the kdb() code. That | |
23203 | + * processor sends an ipi which drives this routine on the other | |
23204 | + * processors. All this does is call kdb() with reason SWITCH. | |
23205 | + * This puts all processors into the kdb() routine and all the | |
23206 | + * code for breakpoints etc. is in one place. | |
23207 | + * One problem with the way the kdb NMI is sent, the NMI has no | |
23208 | + * identification that says it came from kdb. If the cpu's kdb state is | |
23209 | + * marked as "waiting for kdb_ipi" then the NMI is treated as coming from | |
23210 | + * kdb, otherwise it is assumed to be for another reason and is ignored. | |
23211 | + */ | |
23212 | + | |
23213 | +int | |
23214 | +kdb_ipi(struct pt_regs *regs, void (*ack_interrupt)(void)) | |
23215 | +{ | |
23216 | + /* Do not print before checking and clearing WAIT_IPI, IPIs are | |
23217 | + * going all the time. | |
23218 | + */ | |
23219 | + if (KDB_STATE(WAIT_IPI)) { | |
23220 | + /* | |
23221 | + * Stopping other processors via smp_kdb_stop(). | |
23222 | + */ | |
23223 | + if (ack_interrupt) | |
23224 | + (*ack_interrupt)(); /* Acknowledge the interrupt */ | |
23225 | + KDB_STATE_CLEAR(WAIT_IPI); | |
23226 | + KDB_DEBUG_STATE("kdb_ipi 1", 0); | |
23227 | + kdb(KDB_REASON_SWITCH, 0, regs); /* Spin in kdb() */ | |
23228 | + KDB_DEBUG_STATE("kdb_ipi 2", 0); | |
23229 | + return 1; | |
23230 | + } | |
23231 | + return 0; | |
23232 | +} | |
23233 | +#endif /* CONFIG_SMP */ | |
23234 | + | |
23235 | +/* | |
23236 | + * kdb_symbol_print | |
23237 | + * | |
23238 | + * Standard method for printing a symbol name and offset. | |
23239 | + * Inputs: | |
23240 | + * addr Address to be printed. | |
23241 | + * symtab Address of symbol data, if NULL this routine does its | |
23242 | + * own lookup. | |
23243 | + * punc Punctuation for string, bit field. | |
23244 | + * Outputs: | |
23245 | + * None. | |
23246 | + * Returns: | |
23247 | + * Always 0. | |
23248 | + * Locking: | |
23249 | + * none. | |
23250 | + * Remarks: | |
23251 | + * The string and its punctuation is only printed if the address | |
23252 | + * is inside the kernel, except that the value is always printed | |
23253 | + * when requested. | |
23254 | + */ | |
23255 | + | |
23256 | +void | |
23257 | +kdb_symbol_print(kdb_machreg_t addr, const kdb_symtab_t *symtab_p, unsigned int punc) | |
23258 | +{ | |
23259 | + kdb_symtab_t symtab, *symtab_p2; | |
23260 | + if (symtab_p) { | |
23261 | + symtab_p2 = (kdb_symtab_t *)symtab_p; | |
23262 | + } | |
23263 | + else { | |
23264 | + symtab_p2 = &symtab; | |
23265 | + kdbnearsym(addr, symtab_p2); | |
23266 | + } | |
23267 | + if (symtab_p2->sym_name || (punc & KDB_SP_VALUE)) { | |
23268 | + ; /* drop through */ | |
23269 | + } | |
23270 | + else { | |
23271 | + return; | |
23272 | + } | |
23273 | + if (punc & KDB_SP_SPACEB) { | |
23274 | + kdb_printf(" "); | |
23275 | + } | |
23276 | + if (punc & KDB_SP_VALUE) { | |
23277 | + kdb_printf(kdb_machreg_fmt0, addr); | |
23278 | + } | |
23279 | + if (symtab_p2->sym_name) { | |
23280 | + if (punc & KDB_SP_VALUE) { | |
23281 | + kdb_printf(" "); | |
23282 | + } | |
23283 | + if (punc & KDB_SP_PAREN) { | |
23284 | + kdb_printf("("); | |
23285 | + } | |
23286 | + if (strcmp(symtab_p2->mod_name, "kernel")) { | |
23287 | + kdb_printf("[%s]", symtab_p2->mod_name); | |
23288 | + } | |
23289 | + kdb_printf("%s", symtab_p2->sym_name); | |
23290 | + if (addr != symtab_p2->sym_start) { | |
23291 | + kdb_printf("+0x%lx", addr - symtab_p2->sym_start); | |
23292 | + } | |
23293 | + if (punc & KDB_SP_SYMSIZE) { | |
23294 | + kdb_printf("/0x%lx", symtab_p2->sym_end - symtab_p2->sym_start); | |
23295 | + } | |
23296 | + if (punc & KDB_SP_PAREN) { | |
23297 | + kdb_printf(")"); | |
23298 | + } | |
23299 | + } | |
23300 | + if (punc & KDB_SP_SPACEA) { | |
23301 | + kdb_printf(" "); | |
23302 | + } | |
23303 | + if (punc & KDB_SP_NEWLINE) { | |
23304 | + kdb_printf("\n"); | |
23305 | + } | |
23306 | +} | |
23307 | + | |
23308 | +/* | |
23309 | + * kdb_strdup | |
23310 | + * | |
23311 | + * kdb equivalent of strdup, for disasm code. | |
23312 | + * Inputs: | |
23313 | + * str The string to duplicate. | |
23314 | + * type Flags to kmalloc for the new string. | |
23315 | + * Outputs: | |
23316 | + * None. | |
23317 | + * Returns: | |
23318 | + * Address of the new string, NULL if storage could not be allocated. | |
23319 | + * Locking: | |
23320 | + * none. | |
23321 | + * Remarks: | |
23322 | + * This is not in lib/string.c because it uses kmalloc which is not | |
23323 | + * available when string.o is used in boot loaders. | |
23324 | + */ | |
23325 | + | |
23326 | +char *kdb_strdup(const char *str, gfp_t type) | |
23327 | +{ | |
23328 | + int n = strlen(str)+1; | |
23329 | + char *s = kmalloc(n, type); | |
23330 | + if (!s) return NULL; | |
23331 | + return strcpy(s, str); | |
23332 | +} | |
23333 | + | |
23334 | +/* | |
23335 | + * kdb_getarea_size | |
23336 | + * | |
23337 | + * Read an area of data. The kdb equivalent of copy_from_user, with | |
23338 | + * kdb messages for invalid addresses. | |
23339 | + * Inputs: | |
23340 | + * res Pointer to the area to receive the result. | |
23341 | + * addr Address of the area to copy. | |
23342 | + * size Size of the area. | |
23343 | + * Outputs: | |
23344 | + * none. | |
23345 | + * Returns: | |
23346 | + * 0 for success, < 0 for error. | |
23347 | + * Locking: | |
23348 | + * none. | |
23349 | + */ | |
23350 | + | |
23351 | +int kdb_getarea_size(void *res, unsigned long addr, size_t size) | |
23352 | +{ | |
23353 | + int ret = kdba_getarea_size(res, addr, size); | |
23354 | + if (ret) { | |
23355 | + if (!KDB_STATE(SUPPRESS)) { | |
23356 | + kdb_printf("kdb_getarea: Bad address 0x%lx\n", addr); | |
23357 | + KDB_STATE_SET(SUPPRESS); | |
23358 | + } | |
23359 | + ret = KDB_BADADDR; | |
23360 | + } | |
23361 | + else { | |
23362 | + KDB_STATE_CLEAR(SUPPRESS); | |
23363 | + } | |
23364 | + return(ret); | |
23365 | +} | |
23366 | + | |
23367 | +/* | |
23368 | + * kdb_putarea_size | |
23369 | + * | |
23370 | + * Write an area of data. The kdb equivalent of copy_to_user, with | |
23371 | + * kdb messages for invalid addresses. | |
23372 | + * Inputs: | |
23373 | + * addr Address of the area to write to. | |
23374 | + * res Pointer to the area holding the data. | |
23375 | + * size Size of the area. | |
23376 | + * Outputs: | |
23377 | + * none. | |
23378 | + * Returns: | |
23379 | + * 0 for success, < 0 for error. | |
23380 | + * Locking: | |
23381 | + * none. | |
23382 | + */ | |
23383 | + | |
23384 | +int kdb_putarea_size(unsigned long addr, void *res, size_t size) | |
23385 | +{ | |
23386 | + int ret = kdba_putarea_size(addr, res, size); | |
23387 | + if (ret) { | |
23388 | + if (!KDB_STATE(SUPPRESS)) { | |
23389 | + kdb_printf("kdb_putarea: Bad address 0x%lx\n", addr); | |
23390 | + KDB_STATE_SET(SUPPRESS); | |
23391 | + } | |
23392 | + ret = KDB_BADADDR; | |
23393 | + } | |
23394 | + else { | |
23395 | + KDB_STATE_CLEAR(SUPPRESS); | |
23396 | + } | |
23397 | + return(ret); | |
23398 | +} | |
23399 | + | |
23400 | +/* | |
23401 | + * kdb_getphys | |
23402 | + * | |
23403 | + * Read data from a physical address. Validate the address is in range, | |
23404 | + * use kmap_atomic() to get data | |
23405 | + * | |
23406 | + * Similar to kdb_getarea() - but for phys addresses | |
23407 | + * | |
23408 | + * Inputs: | |
23409 | + * res Pointer to the word to receive the result | |
23410 | + * addr Physical address of the area to copy | |
23411 | + * size Size of the area | |
23412 | + * Outputs: | |
23413 | + * none. | |
23414 | + * Returns: | |
23415 | + * 0 for success, < 0 for error. | |
23416 | + * Locking: | |
23417 | + * none. | |
23418 | + */ | |
23419 | +static int kdb_getphys(void *res, unsigned long addr, size_t size) | |
23420 | +{ | |
23421 | + unsigned long pfn; | |
23422 | + void *vaddr; | |
23423 | + struct page *page; | |
23424 | + | |
23425 | + pfn = (addr >> PAGE_SHIFT); | |
23426 | + if (!pfn_valid(pfn)) | |
23427 | + return 1; | |
23428 | + page = pfn_to_page(pfn); | |
23429 | + vaddr = kmap_atomic(page, KM_KDB); | |
23430 | + memcpy(res, vaddr + (addr & (PAGE_SIZE -1)), size); | |
23431 | + kunmap_atomic(vaddr, KM_KDB); | |
23432 | + | |
23433 | + return 0; | |
23434 | +} | |
23435 | + | |
23436 | +/* | |
23437 | + * kdb_getphysword | |
23438 | + * | |
23439 | + * Inputs: | |
23440 | + * word Pointer to the word to receive the result. | |
23441 | + * addr Address of the area to copy. | |
23442 | + * size Size of the area. | |
23443 | + * Outputs: | |
23444 | + * none. | |
23445 | + * Returns: | |
23446 | + * 0 for success, < 0 for error. | |
23447 | + * Locking: | |
23448 | + * none. | |
23449 | + */ | |
23450 | +int kdb_getphysword(unsigned long *word, unsigned long addr, size_t size) | |
23451 | +{ | |
23452 | + int diag; | |
23453 | + __u8 w1; | |
23454 | + __u16 w2; | |
23455 | + __u32 w4; | |
23456 | + __u64 w8; | |
23457 | + *word = 0; /* Default value if addr or size is invalid */ | |
23458 | + | |
23459 | + switch (size) { | |
23460 | + case 1: | |
23461 | + if (!(diag = kdb_getphys(&w1, addr, sizeof(w1)))) | |
23462 | + *word = w1; | |
23463 | + break; | |
23464 | + case 2: | |
23465 | + if (!(diag = kdb_getphys(&w2, addr, sizeof(w2)))) | |
23466 | + *word = w2; | |
23467 | + break; | |
23468 | + case 4: | |
23469 | + if (!(diag = kdb_getphys(&w4, addr, sizeof(w4)))) | |
23470 | + *word = w4; | |
23471 | + break; | |
23472 | + case 8: | |
23473 | + if (size <= sizeof(*word)) { | |
23474 | + if (!(diag = kdb_getphys(&w8, addr, sizeof(w8)))) | |
23475 | + *word = w8; | |
23476 | + break; | |
23477 | + } | |
23478 | + /* drop through */ | |
23479 | + default: | |
23480 | + diag = KDB_BADWIDTH; | |
23481 | + kdb_printf("kdb_getphysword: bad width %ld\n", (long) size); | |
23482 | + } | |
23483 | + return(diag); | |
23484 | +} | |
23485 | + | |
23486 | +/* | |
23487 | + * kdb_getword | |
23488 | + * | |
23489 | + * Read a binary value. Unlike kdb_getarea, this treats data as numbers. | |
23490 | + * Inputs: | |
23491 | + * word Pointer to the word to receive the result. | |
23492 | + * addr Address of the area to copy. | |
23493 | + * size Size of the area. | |
23494 | + * Outputs: | |
23495 | + * none. | |
23496 | + * Returns: | |
23497 | + * 0 for success, < 0 for error. | |
23498 | + * Locking: | |
23499 | + * none. | |
23500 | + */ | |
23501 | + | |
23502 | +int kdb_getword(unsigned long *word, unsigned long addr, size_t size) | |
23503 | +{ | |
23504 | + int diag; | |
23505 | + __u8 w1; | |
23506 | + __u16 w2; | |
23507 | + __u32 w4; | |
23508 | + __u64 w8; | |
23509 | + *word = 0; /* Default value if addr or size is invalid */ | |
23510 | + switch (size) { | |
23511 | + case 1: | |
23512 | + if (!(diag = kdb_getarea(w1, addr))) | |
23513 | + *word = w1; | |
23514 | + break; | |
23515 | + case 2: | |
23516 | + if (!(diag = kdb_getarea(w2, addr))) | |
23517 | + *word = w2; | |
23518 | + break; | |
23519 | + case 4: | |
23520 | + if (!(diag = kdb_getarea(w4, addr))) | |
23521 | + *word = w4; | |
23522 | + break; | |
23523 | + case 8: | |
23524 | + if (size <= sizeof(*word)) { | |
23525 | + if (!(diag = kdb_getarea(w8, addr))) | |
23526 | + *word = w8; | |
23527 | + break; | |
23528 | + } | |
23529 | + /* drop through */ | |
23530 | + default: | |
23531 | + diag = KDB_BADWIDTH; | |
23532 | + kdb_printf("kdb_getword: bad width %ld\n", (long) size); | |
23533 | + } | |
23534 | + return(diag); | |
23535 | +} | |
23536 | + | |
23537 | +/* | |
23538 | + * kdb_putword | |
23539 | + * | |
23540 | + * Write a binary value. Unlike kdb_putarea, this treats data as numbers. | |
23541 | + * Inputs: | |
23542 | + * addr Address of the area to write to.. | |
23543 | + * word The value to set. | |
23544 | + * size Size of the area. | |
23545 | + * Outputs: | |
23546 | + * none. | |
23547 | + * Returns: | |
23548 | + * 0 for success, < 0 for error. | |
23549 | + * Locking: | |
23550 | + * none. | |
23551 | + */ | |
23552 | + | |
23553 | +int kdb_putword(unsigned long addr, unsigned long word, size_t size) | |
23554 | +{ | |
23555 | + int diag; | |
23556 | + __u8 w1; | |
23557 | + __u16 w2; | |
23558 | + __u32 w4; | |
23559 | + __u64 w8; | |
23560 | + switch (size) { | |
23561 | + case 1: | |
23562 | + w1 = word; | |
23563 | + diag = kdb_putarea(addr, w1); | |
23564 | + break; | |
23565 | + case 2: | |
23566 | + w2 = word; | |
23567 | + diag = kdb_putarea(addr, w2); | |
23568 | + break; | |
23569 | + case 4: | |
23570 | + w4 = word; | |
23571 | + diag = kdb_putarea(addr, w4); | |
23572 | + break; | |
23573 | + case 8: | |
23574 | + if (size <= sizeof(word)) { | |
23575 | + w8 = word; | |
23576 | + diag = kdb_putarea(addr, w8); | |
23577 | + break; | |
23578 | + } | |
23579 | + /* drop through */ | |
23580 | + default: | |
23581 | + diag = KDB_BADWIDTH; | |
23582 | + kdb_printf("kdb_putword: bad width %ld\n", (long) size); | |
23583 | + } | |
23584 | + return(diag); | |
23585 | +} | |
23586 | + | |
23587 | +/* | |
23588 | + * kdb_task_state_string | |
23589 | + * | |
23590 | + * Convert a string containing any of the letters DRSTCZEUIMA to a mask | |
23591 | + * for the process state field and return the value. If no argument is | |
23592 | + * supplied, return the mask that corresponds to environment variable PS, | |
23593 | + * DRSTCZEU by default. | |
23594 | + * Inputs: | |
23595 | + * s String to convert | |
23596 | + * Outputs: | |
23597 | + * none. | |
23598 | + * Returns: | |
23599 | + * Mask for process state. | |
23600 | + * Locking: | |
23601 | + * none. | |
23602 | + * Notes: | |
23603 | + * The mask folds data from several sources into a single long value, so | |
23604 | + * be carefull not to overlap the bits. TASK_* bits are in the LSB, | |
23605 | + * special cases like UNRUNNABLE are in the MSB. As of 2.6.10-rc1 there | |
23606 | + * is no overlap between TASK_* and EXIT_* but that may not always be | |
23607 | + * true, so EXIT_* bits are shifted left 16 bits before being stored in | |
23608 | + * the mask. | |
23609 | + */ | |
23610 | + | |
23611 | +#define UNRUNNABLE (1UL << (8*sizeof(unsigned long) - 1)) /* unrunnable is < 0 */ | |
23612 | +#define RUNNING (1UL << (8*sizeof(unsigned long) - 2)) | |
23613 | +#define IDLE (1UL << (8*sizeof(unsigned long) - 3)) | |
23614 | +#define DAEMON (1UL << (8*sizeof(unsigned long) - 4)) | |
23615 | + | |
23616 | +unsigned long | |
23617 | +kdb_task_state_string(const char *s) | |
23618 | +{ | |
23619 | + long res = 0; | |
23620 | + if (!s && !(s = kdbgetenv("PS"))) { | |
23621 | + s = "DRSTCZEU"; /* default value for ps */ | |
23622 | + } | |
23623 | + while (*s) { | |
23624 | + switch (*s) { | |
23625 | + case 'D': res |= TASK_UNINTERRUPTIBLE; break; | |
23626 | + case 'R': res |= RUNNING; break; | |
23627 | + case 'S': res |= TASK_INTERRUPTIBLE; break; | |
23628 | + case 'T': res |= TASK_STOPPED; break; | |
23629 | + case 'C': res |= TASK_TRACED; break; | |
23630 | + case 'Z': res |= EXIT_ZOMBIE << 16; break; | |
23631 | + case 'E': res |= EXIT_DEAD << 16; break; | |
23632 | + case 'U': res |= UNRUNNABLE; break; | |
23633 | + case 'I': res |= IDLE; break; | |
23634 | + case 'M': res |= DAEMON; break; | |
23635 | + case 'A': res = ~0UL; break; | |
23636 | + default: | |
23637 | + kdb_printf("%s: unknown flag '%c' ignored\n", __FUNCTION__, *s); | |
23638 | + break; | |
23639 | + } | |
23640 | + ++s; | |
23641 | + } | |
23642 | + return res; | |
23643 | +} | |
23644 | + | |
23645 | +/* | |
23646 | + * kdb_task_state_char | |
23647 | + * | |
23648 | + * Return the character that represents the task state. | |
23649 | + * Inputs: | |
23650 | + * p struct task for the process | |
23651 | + * Outputs: | |
23652 | + * none. | |
23653 | + * Returns: | |
23654 | + * One character to represent the task state. | |
23655 | + * Locking: | |
23656 | + * none. | |
23657 | + */ | |
23658 | + | |
23659 | +char | |
23660 | +kdb_task_state_char (const struct task_struct *p) | |
23661 | +{ | |
23662 | + int cpu = kdb_process_cpu(p); | |
23663 | + struct kdb_running_process *krp = kdb_running_process + cpu; | |
23664 | + char state = (p->state == 0) ? 'R' : | |
23665 | + (p->state < 0) ? 'U' : | |
23666 | + (p->state & TASK_UNINTERRUPTIBLE) ? 'D' : | |
23667 | + (p->state & TASK_STOPPED) ? 'T' : | |
23668 | + (p->state & TASK_TRACED) ? 'C' : | |
23669 | + (p->exit_state & EXIT_ZOMBIE) ? 'Z' : | |
23670 | + (p->exit_state & EXIT_DEAD) ? 'E' : | |
23671 | + (p->state & TASK_INTERRUPTIBLE) ? 'S' : '?'; | |
23672 | + if (p->pid == 0) { | |
23673 | + /* Idle task. Is it really idle, apart from the kdb interrupt? */ | |
23674 | + if (!kdb_task_has_cpu(p) || krp->irq_depth == 1) { | |
23675 | + /* There is a corner case when the idle task takes an | |
23676 | + * interrupt and dies in the interrupt code. It has an | |
23677 | + * interrupt count of 1 but that did not come from kdb. | |
23678 | + * This corner case can only occur on the initial cpu, | |
23679 | + * all the others were entered via the kdb IPI. | |
23680 | + */ | |
23681 | + if (cpu != kdb_initial_cpu || KDB_STATE_CPU(KEYBOARD, cpu)) | |
23682 | + state = 'I'; /* idle task */ | |
23683 | + } | |
23684 | + } | |
23685 | + else if (!p->mm && state == 'S') { | |
23686 | + state = 'M'; /* sleeping system daemon */ | |
23687 | + } | |
23688 | + return state; | |
23689 | +} | |
23690 | + | |
23691 | +/* | |
23692 | + * kdb_task_state | |
23693 | + * | |
23694 | + * Return true if a process has the desired state given by the mask. | |
23695 | + * Inputs: | |
23696 | + * p struct task for the process | |
23697 | + * mask mask from kdb_task_state_string to select processes | |
23698 | + * Outputs: | |
23699 | + * none. | |
23700 | + * Returns: | |
23701 | + * True if the process matches at least one criteria defined by the mask. | |
23702 | + * Locking: | |
23703 | + * none. | |
23704 | + */ | |
23705 | + | |
23706 | +unsigned long | |
23707 | +kdb_task_state(const struct task_struct *p, unsigned long mask) | |
23708 | +{ | |
23709 | + char state[] = { kdb_task_state_char(p), '\0' }; | |
23710 | + return (mask & kdb_task_state_string(state)) != 0; | |
23711 | +} | |
23712 | + | |
23713 | +struct kdb_running_process kdb_running_process[NR_CPUS]; | |
23714 | + | |
23715 | +/* Save the state of a running process and invoke kdb_main_loop. This is | |
23716 | + * invoked on the current process on each cpu (assuming the cpu is responding). | |
23717 | + */ | |
23718 | + | |
23719 | +int | |
23720 | +kdb_save_running(struct pt_regs *regs, kdb_reason_t reason, | |
23721 | + kdb_reason_t reason2, int error, kdb_dbtrap_t db_result) | |
23722 | +{ | |
23723 | + struct kdb_running_process *krp = kdb_running_process + smp_processor_id(); | |
23724 | + krp->p = current; | |
23725 | + krp->regs = regs; | |
23726 | + krp->seqno = kdb_seqno; | |
23727 | + krp->irq_depth = hardirq_count() >> HARDIRQ_SHIFT; | |
23728 | + kdba_save_running(&(krp->arch), regs); | |
23729 | + return kdb_main_loop(reason, reason2, error, db_result, regs); | |
23730 | +} | |
23731 | + | |
23732 | +/* | |
23733 | + * kdb_unsave_running | |
23734 | + * | |
23735 | + * Reverse the effect of kdb_save_running. | |
23736 | + * Inputs: | |
23737 | + * regs struct pt_regs for the process | |
23738 | + * Outputs: | |
23739 | + * Updates kdb_running_process[] for this cpu. | |
23740 | + * Returns: | |
23741 | + * none. | |
23742 | + * Locking: | |
23743 | + * none. | |
23744 | + */ | |
23745 | + | |
23746 | +void | |
23747 | +kdb_unsave_running(struct pt_regs *regs) | |
23748 | +{ | |
23749 | + struct kdb_running_process *krp = kdb_running_process + smp_processor_id(); | |
23750 | + kdba_unsave_running(&(krp->arch), regs); | |
23751 | + krp->seqno = 0; | |
23752 | +} | |
23753 | + | |
23754 | + | |
23755 | +/* | |
23756 | + * kdb_print_nameval | |
23757 | + * | |
23758 | + * Print a name and its value, converting the value to a symbol lookup | |
23759 | + * if possible. | |
23760 | + * Inputs: | |
23761 | + * name field name to print | |
23762 | + * val value of field | |
23763 | + * Outputs: | |
23764 | + * none. | |
23765 | + * Returns: | |
23766 | + * none. | |
23767 | + * Locking: | |
23768 | + * none. | |
23769 | + */ | |
23770 | + | |
23771 | +void | |
23772 | +kdb_print_nameval(const char *name, unsigned long val) | |
23773 | +{ | |
23774 | + kdb_symtab_t symtab; | |
23775 | + kdb_printf(" %-11.11s ", name); | |
23776 | + if (kdbnearsym(val, &symtab)) | |
23777 | + kdb_symbol_print(val, &symtab, KDB_SP_VALUE|KDB_SP_SYMSIZE|KDB_SP_NEWLINE); | |
23778 | + else | |
23779 | + kdb_printf("0x%lx\n", val); | |
23780 | +} | |
23781 | + | |
23782 | +static struct page * kdb_get_one_user_page(const struct task_struct *tsk, unsigned long start, | |
23783 | + int len, int write) | |
23784 | +{ | |
23785 | + struct mm_struct *mm = tsk->mm; | |
23786 | + unsigned int flags; | |
23787 | + struct vm_area_struct * vma; | |
23788 | + | |
23789 | + /* shouldn't cross a page boundary. */ | |
23790 | + if ((start & PAGE_MASK) != ((start+len) & PAGE_MASK)) | |
23791 | + return NULL; | |
23792 | + | |
23793 | + /* we need to align start address to the current page boundy, PAGE_ALIGN | |
23794 | + * aligns to next page boundry. | |
23795 | + * FIXME: What about hugetlb? | |
23796 | + */ | |
23797 | + start = start & PAGE_MASK; | |
23798 | + flags = write ? (VM_WRITE | VM_MAYWRITE) : (VM_READ | VM_MAYREAD); | |
23799 | + | |
23800 | + vma = find_extend_vma(mm, start); | |
23801 | + | |
23802 | + /* may be we can allow access to VM_IO pages inside KDB? */ | |
23803 | + if (!vma || (vma->vm_flags & VM_IO) || !(flags & vma->vm_flags)) | |
23804 | + return NULL; | |
23805 | + | |
23806 | + return follow_page(vma, start, write ? FOLL_WRITE : 0); | |
23807 | +} | |
23808 | + | |
23809 | +int kdb_getuserarea_size(void *to, unsigned long from, size_t size) | |
23810 | +{ | |
23811 | + struct page *page; | |
23812 | + void *vaddr; | |
23813 | + | |
23814 | + page = kdb_get_one_user_page(kdb_current_task, from, size, 0); | |
23815 | + if (!page) | |
23816 | + return size; | |
23817 | + | |
23818 | + vaddr = kmap_atomic(page, KM_KDB); | |
23819 | + memcpy(to, vaddr+ (from & (PAGE_SIZE - 1)), size); | |
23820 | + kunmap_atomic(vaddr, KM_KDB); | |
23821 | + | |
23822 | + return 0; | |
23823 | +} | |
23824 | + | |
23825 | +int kdb_putuserarea_size(unsigned long to, void *from, size_t size) | |
23826 | +{ | |
23827 | + struct page *page; | |
23828 | + void *vaddr; | |
23829 | + | |
23830 | + page = kdb_get_one_user_page(kdb_current_task, to, size, 1); | |
23831 | + if (!page) | |
23832 | + return size; | |
23833 | + | |
23834 | + vaddr = kmap_atomic(page, KM_KDB); | |
23835 | + memcpy(vaddr+ (to & (PAGE_SIZE - 1)), from, size); | |
23836 | + kunmap_atomic(vaddr, KM_KDB); | |
23837 | + | |
23838 | + return 0; | |
23839 | +} | |
23840 | + | |
23841 | +/* Last ditch allocator for debugging, so we can still debug even when the | |
23842 | + * GFP_ATOMIC pool has been exhausted. The algorithms are tuned for space | |
23843 | + * usage, not for speed. One smallish memory pool, the free chain is always in | |
23844 | + * ascending address order to allow coalescing, allocations are done in brute | |
23845 | + * force best fit. | |
23846 | + */ | |
23847 | + | |
23848 | +struct debug_alloc_header { | |
23849 | + u32 next; /* offset of next header from start of pool */ | |
23850 | + u32 size; | |
23851 | + void *caller; | |
23852 | +}; | |
23853 | + | |
23854 | +/* The memory returned by this allocator must be aligned, which means so must | |
23855 | + * the header size. Do not assume that sizeof(struct debug_alloc_header) is a | |
23856 | + * multiple of the alignment, explicitly calculate the overhead of this header, | |
23857 | + * including the alignment. The rest of this code must not use sizeof() on any | |
23858 | + * header or pointer to a header. | |
23859 | + */ | |
23860 | +#define dah_align 8 | |
23861 | +#define dah_overhead ALIGN(sizeof(struct debug_alloc_header), dah_align) | |
23862 | + | |
23863 | +static u64 debug_alloc_pool_aligned[256*1024/dah_align]; /* 256K pool */ | |
23864 | +static char *debug_alloc_pool = (char *)debug_alloc_pool_aligned; | |
23865 | +static u32 dah_first, dah_first_call = 1, dah_used = 0, dah_used_max = 0; | |
23866 | + | |
23867 | +/* Locking is awkward. The debug code is called from all contexts, including | |
23868 | + * non maskable interrupts. A normal spinlock is not safe in NMI context. Try | |
23869 | + * to get the debug allocator lock, if it cannot be obtained after a second | |
23870 | + * then give up. If the lock could not be previously obtained on this cpu then | |
23871 | + * only try once. | |
23872 | + * | |
23873 | + * sparse has no annotation for "this function _sometimes_ acquires a lock", so | |
23874 | + * fudge the acquire/release notation. | |
23875 | + */ | |
23876 | +static DEFINE_SPINLOCK(dap_lock); | |
23877 | +static int | |
23878 | +get_dap_lock(void) | |
23879 | + __acquires(dap_lock) | |
23880 | +{ | |
23881 | + static int dap_locked = -1; | |
23882 | + int count; | |
23883 | + if (dap_locked == smp_processor_id()) | |
23884 | + count = 1; | |
23885 | + else | |
23886 | + count = 1000; | |
23887 | + while (1) { | |
23888 | + if (spin_trylock(&dap_lock)) { | |
23889 | + dap_locked = -1; | |
23890 | + return 1; | |
23891 | + } | |
23892 | + if (!count--) | |
23893 | + break; | |
23894 | + udelay(1000); | |
23895 | + } | |
23896 | + dap_locked = smp_processor_id(); | |
23897 | + __acquire(dap_lock); | |
23898 | + return 0; | |
23899 | +} | |
23900 | + | |
23901 | +void | |
23902 | +*debug_kmalloc(size_t size, gfp_t flags) | |
23903 | +{ | |
23904 | + unsigned int rem, h_offset; | |
23905 | + struct debug_alloc_header *best, *bestprev, *prev, *h; | |
23906 | + void *p = NULL; | |
23907 | + if (!get_dap_lock()) { | |
23908 | + __release(dap_lock); /* we never actually got it */ | |
23909 | + return NULL; | |
23910 | + } | |
23911 | + h = (struct debug_alloc_header *)(debug_alloc_pool + dah_first); | |
23912 | + if (dah_first_call) { | |
23913 | + h->size = sizeof(debug_alloc_pool_aligned) - dah_overhead; | |
23914 | + dah_first_call = 0; | |
23915 | + } | |
23916 | + size = ALIGN(size, dah_align); | |
23917 | + prev = best = bestprev = NULL; | |
23918 | + while (1) { | |
23919 | + if (h->size >= size && (!best || h->size < best->size)) { | |
23920 | + best = h; | |
23921 | + bestprev = prev; | |
23922 | + if (h->size == size) | |
23923 | + break; | |
23924 | + } | |
23925 | + if (!h->next) | |
23926 | + break; | |
23927 | + prev = h; | |
23928 | + h = (struct debug_alloc_header *)(debug_alloc_pool + h->next); | |
23929 | + } | |
23930 | + if (!best) | |
23931 | + goto out; | |
23932 | + rem = best->size - size; | |
23933 | + /* The pool must always contain at least one header */ | |
23934 | + if (best->next == 0 && bestprev == NULL && rem < dah_overhead) | |
23935 | + goto out; | |
23936 | + if (rem >= dah_overhead) { | |
23937 | + best->size = size; | |
23938 | + h_offset = ((char *)best - debug_alloc_pool) + | |
23939 | + dah_overhead + best->size; | |
23940 | + h = (struct debug_alloc_header *)(debug_alloc_pool + h_offset); | |
23941 | + h->size = rem - dah_overhead; | |
23942 | + h->next = best->next; | |
23943 | + } else | |
23944 | + h_offset = best->next; | |
23945 | + best->caller = __builtin_return_address(0); | |
23946 | + dah_used += best->size; | |
23947 | + dah_used_max = max(dah_used, dah_used_max); | |
23948 | + if (bestprev) | |
23949 | + bestprev->next = h_offset; | |
23950 | + else | |
23951 | + dah_first = h_offset; | |
23952 | + p = (char *)best + dah_overhead; | |
23953 | + memset(p, POISON_INUSE, best->size - 1); | |
23954 | + *((char *)p + best->size - 1) = POISON_END; | |
23955 | +out: | |
23956 | + spin_unlock(&dap_lock); | |
23957 | + return p; | |
23958 | +} | |
23959 | + | |
23960 | +void | |
23961 | +debug_kfree(void *p) | |
23962 | +{ | |
23963 | + struct debug_alloc_header *h; | |
23964 | + unsigned int h_offset; | |
23965 | + if (!p) | |
23966 | + return; | |
23967 | + if ((char *)p < debug_alloc_pool || | |
23968 | + (char *)p >= debug_alloc_pool + sizeof(debug_alloc_pool_aligned)) { | |
23969 | + kfree(p); | |
23970 | + return; | |
23971 | + } | |
23972 | + if (!get_dap_lock()) { | |
23973 | + __release(dap_lock); /* we never actually got it */ | |
23974 | + return; /* memory leak, cannot be helped */ | |
23975 | + } | |
23976 | + h = (struct debug_alloc_header *)((char *)p - dah_overhead); | |
23977 | + memset(p, POISON_FREE, h->size - 1); | |
23978 | + *((char *)p + h->size - 1) = POISON_END; | |
23979 | + h->caller = NULL; | |
23980 | + dah_used -= h->size; | |
23981 | + h_offset = (char *)h - debug_alloc_pool; | |
23982 | + if (h_offset < dah_first) { | |
23983 | + h->next = dah_first; | |
23984 | + dah_first = h_offset; | |
23985 | + } else { | |
23986 | + struct debug_alloc_header *prev; | |
23987 | + unsigned int prev_offset; | |
23988 | + prev = (struct debug_alloc_header *)(debug_alloc_pool + dah_first); | |
23989 | + while (1) { | |
23990 | + if (!prev->next || prev->next > h_offset) | |
23991 | + break; | |
23992 | + prev = (struct debug_alloc_header *) | |
23993 | + (debug_alloc_pool + prev->next); | |
23994 | + } | |
23995 | + prev_offset = (char *)prev - debug_alloc_pool; | |
23996 | + if (prev_offset + dah_overhead + prev->size == h_offset) { | |
23997 | + prev->size += dah_overhead + h->size; | |
23998 | + memset(h, POISON_FREE, dah_overhead - 1); | |
23999 | + *((char *)h + dah_overhead - 1) = POISON_END; | |
24000 | + h = prev; | |
24001 | + h_offset = prev_offset; | |
24002 | + } else { | |
24003 | + h->next = prev->next; | |
24004 | + prev->next = h_offset; | |
24005 | + } | |
24006 | + } | |
24007 | + if (h_offset + dah_overhead + h->size == h->next) { | |
24008 | + struct debug_alloc_header *next; | |
24009 | + next = (struct debug_alloc_header *) | |
24010 | + (debug_alloc_pool + h->next); | |
24011 | + h->size += dah_overhead + next->size; | |
24012 | + h->next = next->next; | |
24013 | + memset(next, POISON_FREE, dah_overhead - 1); | |
24014 | + *((char *)next + dah_overhead - 1) = POISON_END; | |
24015 | + } | |
24016 | + spin_unlock(&dap_lock); | |
24017 | +} | |
24018 | + | |
24019 | +void | |
24020 | +debug_kusage(void) | |
24021 | +{ | |
24022 | + struct debug_alloc_header *h_free, *h_used; | |
24023 | +#ifdef CONFIG_IA64 | |
24024 | + /* FIXME: using dah for ia64 unwind always results in a memory leak. | |
24025 | + * Fix that memory leak first, then set debug_kusage_one_time = 1 for | |
24026 | + * all architectures. | |
24027 | + */ | |
24028 | + static int debug_kusage_one_time = 0; | |
24029 | +#else | |
24030 | + static int debug_kusage_one_time = 1; | |
24031 | +#endif | |
24032 | + if (!get_dap_lock()) { | |
24033 | + __release(dap_lock); /* we never actually got it */ | |
24034 | + return; | |
24035 | + } | |
24036 | + h_free = (struct debug_alloc_header *)(debug_alloc_pool + dah_first); | |
24037 | + if (dah_first == 0 && | |
24038 | + (h_free->size == sizeof(debug_alloc_pool_aligned) - dah_overhead || | |
24039 | + dah_first_call)) | |
24040 | + goto out; | |
24041 | + if (!debug_kusage_one_time) | |
24042 | + goto out; | |
24043 | + debug_kusage_one_time = 0; | |
24044 | + kdb_printf("%s: debug_kmalloc memory leak dah_first %d\n", | |
24045 | + __FUNCTION__, dah_first); | |
24046 | + if (dah_first) { | |
24047 | + h_used = (struct debug_alloc_header *)debug_alloc_pool; | |
24048 | + kdb_printf("%s: h_used %p size %d\n", __FUNCTION__, h_used, h_used->size); | |
24049 | + } | |
24050 | + do { | |
24051 | + h_used = (struct debug_alloc_header *) | |
24052 | + ((char *)h_free + dah_overhead + h_free->size); | |
24053 | + kdb_printf("%s: h_used %p size %d caller %p\n", | |
24054 | + __FUNCTION__, h_used, h_used->size, h_used->caller); | |
24055 | + h_free = (struct debug_alloc_header *) | |
24056 | + (debug_alloc_pool + h_free->next); | |
24057 | + } while (h_free->next); | |
24058 | + h_used = (struct debug_alloc_header *) | |
24059 | + ((char *)h_free + dah_overhead + h_free->size); | |
24060 | + if ((char *)h_used - debug_alloc_pool != | |
24061 | + sizeof(debug_alloc_pool_aligned)) | |
24062 | + kdb_printf("%s: h_used %p size %d caller %p\n", | |
24063 | + __FUNCTION__, h_used, h_used->size, h_used->caller); | |
24064 | +out: | |
24065 | + spin_unlock(&dap_lock); | |
24066 | +} | |
24067 | + | |
24068 | +/* Maintain a small stack of kdb_flags to allow recursion without disturbing | |
24069 | + * the global kdb state. | |
24070 | + */ | |
24071 | + | |
24072 | +static int kdb_flags_stack[4], kdb_flags_index; | |
24073 | + | |
24074 | +void | |
24075 | +kdb_save_flags(void) | |
24076 | +{ | |
24077 | + BUG_ON(kdb_flags_index >= ARRAY_SIZE(kdb_flags_stack)); | |
24078 | + kdb_flags_stack[kdb_flags_index++] = kdb_flags; | |
24079 | +} | |
24080 | + | |
24081 | +void | |
24082 | +kdb_restore_flags(void) | |
24083 | +{ | |
24084 | + BUG_ON(kdb_flags_index <= 0); | |
24085 | + kdb_flags = kdb_flags_stack[--kdb_flags_index]; | |
24086 | +} | |
24087 | --- /dev/null | |
24088 | +++ b/kdb/modules/Makefile | |
24089 | @@ -0,0 +1,14 @@ | |
24090 | +# | |
24091 | +# This file is subject to the terms and conditions of the GNU General Public | |
24092 | +# License. See the file "COPYING" in the main directory of this archive | |
24093 | +# for more details. | |
24094 | +# | |
24095 | +# Copyright (c) 1999-2006 Silicon Graphics, Inc. All Rights Reserved. | |
24096 | +# | |
24097 | + | |
24098 | +obj-$(CONFIG_KDB_MODULES) += kdbm_pg.o kdbm_task.o kdbm_vm.o kdbm_sched.o | |
24099 | +obj-m += kdbm_debugtypes.o | |
24100 | +ifdef CONFIG_X86 | |
24101 | +obj-$(CONFIG_KDB_MODULES) += kdbm_x86.o | |
24102 | +endif | |
24103 | +CFLAGS_kdbm_vm.o += -I $(srctree)/drivers/scsi | |
24104 | --- /dev/null | |
24105 | +++ b/kdb/modules/kdbm_debugtypes.c | |
24106 | @@ -0,0 +1,388 @@ | |
24107 | +/* this one has some additional address validation - untested */ | |
24108 | +/* | |
24109 | + * This file is subject to the terms and conditions of the GNU General Public | |
24110 | + * License. See the file "COPYING" in the main directory of this archive | |
24111 | + * for more details. | |
24112 | + * | |
24113 | + * Copyright (c) 2008 Silicon Graphics, Inc. All Rights Reserved. | |
24114 | + */ | |
24115 | + | |
24116 | +/* | |
24117 | + * | |
24118 | + * Most of this code is borrowed and adapted from the lkcd command "lcrash" | |
24119 | + * and its supporting libarary. | |
24120 | + * | |
24121 | + * This module provides kdb commands for casting memory structures. | |
24122 | + * It loads symbolic debugging info (provided from lcrash -o), and provides | |
24123 | + * "print" "px", "pd" | |
24124 | + * (this information originally comes from the lcrash "kerntypes" file) | |
24125 | + * | |
24126 | + * A key here is tacking a file of debug info onto this module, for | |
24127 | + * load with it at insmod time. | |
24128 | + * | |
24129 | + * Careful of porting the klib KL_XXX functions (they call thru a jump table | |
24130 | + * that we don't use here) | |
24131 | + * | |
24132 | + * Usage: | |
24133 | + * in order for the insmod kdbm_debugtypes.ko to succeed in loading types | |
24134 | + * you must first use lcrash -t kerntypes.xxxx -o debug_info | |
24135 | + * and echo debug_info > /proc/kdb/debug_info_name | |
24136 | + */ | |
24137 | + | |
24138 | +#define VMALLOC_START_IA64 0xa000000200000000 | |
24139 | +#include <linux/kernel.h> | |
24140 | +#include <linux/module.h> | |
24141 | +#include <linux/kdb.h> | |
24142 | +#include <linux/kdbprivate.h> | |
24143 | +#include <linux/fs.h> | |
24144 | +#include <asm/processor.h> | |
24145 | +#include <asm/uaccess.h> | |
24146 | +#include <asm/fcntl.h> | |
24147 | +#include <linux/vmalloc.h> | |
24148 | +#include <linux/ctype.h> | |
24149 | +#include <linux/file.h> | |
24150 | +#include <linux/err.h> | |
24151 | +#include "lcrash/klib.h" | |
24152 | +#include "lcrash/kl_stringtab.h" | |
24153 | +#include "lcrash/kl_btnode.h" | |
24154 | +#include "lcrash/lc_eval.h" | |
24155 | + | |
24156 | +MODULE_AUTHOR("SGI"); | |
24157 | +MODULE_DESCRIPTION("Load symbolic debugging information"); | |
24158 | +MODULE_LICENSE("GPL"); | |
24159 | + | |
24160 | +#undef next_node /* collision with nodemask.h */ | |
24161 | +static char *stringstorage, **stringp_array; | |
24162 | +static void *filestorage; | |
24163 | +static long num_strings, num_kltypes, num_dsyms, stringstorage_size; | |
24164 | +extern int have_debug_file; | |
24165 | +extern dbg_sym_t *types_tree_head; | |
24166 | +extern dbg_sym_t *typedefs_tree_head; | |
24167 | +extern kltype_t *kltype_array; | |
24168 | +extern dbg_sym_t *dsym_types_array; | |
24169 | +extern dbg_sym_t *type_tree; | |
24170 | +extern dbg_sym_t *typedef_tree; | |
24171 | + | |
24172 | +/* | |
24173 | + * use a pointer's value as an index in the stringp_array (num_strings) and | |
24174 | + * translate it to string address | |
24175 | + * | |
24176 | + * Return 0 for success, 1 for failure | |
24177 | + */ | |
24178 | +static int | |
24179 | +index_to_char_ptr(char **ptrp) | |
24180 | +{ | |
24181 | + long i; | |
24182 | + | |
24183 | + i = (long)*ptrp; | |
24184 | + /* we use a value of -1 to mean this was a null pointer */ | |
24185 | + if (i == -1) { | |
24186 | + *ptrp = NULL; | |
24187 | + return 0; | |
24188 | + } | |
24189 | + if (i > num_strings-1) { | |
24190 | + printk("Could not translate character string index %#lx\n", i); | |
24191 | + return 1; | |
24192 | + } | |
24193 | + *ptrp = *(stringp_array+i); | |
24194 | + return 0; | |
24195 | +} | |
24196 | + | |
24197 | +/* | |
24198 | + * use a pointer's value as an index in the kltype_array (num_kltypes) and | |
24199 | + * translate it to the kltype_t address | |
24200 | + * | |
24201 | + * return 0 for success, 1 for failure | |
24202 | + */ | |
24203 | +static int | |
24204 | +index_to_kltype_ptr(kltype_t **ptrp) | |
24205 | +{ | |
24206 | + long i; | |
24207 | + | |
24208 | + i = (long)*ptrp; | |
24209 | + /* we use a value of -1 to mean this was a null pointer */ | |
24210 | + if (i == -1) { | |
24211 | + *ptrp = NULL; | |
24212 | + return 0; | |
24213 | + } | |
24214 | + if (i > num_kltypes-1) { | |
24215 | + printk("Could not translate kl_type string index %#lx\n", i); | |
24216 | + return 1; | |
24217 | + } | |
24218 | + *ptrp = kltype_array+i; | |
24219 | + return 0; | |
24220 | +} | |
24221 | + | |
24222 | +/* | |
24223 | + * look up a pointer in the dsym_types_array (num_dsyms) and | |
24224 | + * translate it to the index in the array | |
24225 | + * | |
24226 | + * return 0 for success, 1 for failure | |
24227 | + */ | |
24228 | +static int | |
24229 | +index_to_dbg_ptr(dbg_sym_t **ptrp) | |
24230 | +{ | |
24231 | + long i; | |
24232 | + | |
24233 | + i = (long)*ptrp; | |
24234 | + /* we use a value of -1 to mean this was a null pointer */ | |
24235 | + if (i == -1) { | |
24236 | + *ptrp = NULL; | |
24237 | + return 0; | |
24238 | + } | |
24239 | + if (i > num_dsyms-1) { | |
24240 | + printk("Could not translate dbg_sym_t index %#lx\n", i); | |
24241 | + return 1; | |
24242 | + } | |
24243 | + *ptrp = dsym_types_array+i; | |
24244 | + return 0; | |
24245 | +} | |
24246 | + | |
24247 | + | |
24248 | +/* | |
24249 | + * Work on the image of the file built by lcrash. | |
24250 | + * Unpack the strings, and resolve the pointers in the arrays of kltype_t's | |
24251 | + * and dbg_sym_t's to pointers. | |
24252 | + * | |
24253 | + * see lcrash's lib/libklib/kl_debug.c, which generates this file | |
24254 | + * | |
24255 | + * Return the pointers to the heads of the two binary trees by means of | |
24256 | + * pointer arguments. | |
24257 | + * | |
24258 | + * Return 0 for sucess, 1 for any error. | |
24259 | + */ | |
24260 | +static int | |
24261 | +trans_file_image(void *file_storage, long file_size, dbg_sym_t **type_treepp, | |
24262 | + dbg_sym_t **typedef_treepp) | |
24263 | +{ | |
24264 | + int len; | |
24265 | + long i, section_size, *lp, element_size; | |
24266 | + long head_types_tree, head_typedefs_tree; | |
24267 | + char *ptr, *stringsection, *kltypesection, *dbgsection; | |
24268 | + void *kltypestorage, *dbgstorage; | |
24269 | + kltype_t *klp; | |
24270 | + dbg_sym_t *dbgp; | |
24271 | + | |
24272 | + /* 1) the strings */ | |
24273 | + lp = (long *)file_storage; | |
24274 | + stringsection = (char *)lp; | |
24275 | + section_size = *lp++; | |
24276 | + num_strings = *lp++; | |
24277 | + lp++; /* element size does not apply the strings section */ | |
24278 | + | |
24279 | + stringstorage_size = section_size - (3*sizeof(long)); | |
24280 | + stringstorage = (char *)lp; | |
24281 | + | |
24282 | + stringp_array = (char **)vmalloc(num_strings * sizeof(char *)); | |
24283 | + if (! stringp_array) { | |
24284 | + printk("vmalloc of %ld string pointers failed\n", num_strings); | |
24285 | + return 1; | |
24286 | + } | |
24287 | + ptr = stringstorage; | |
24288 | + for (i=0; i<num_strings; i++) { | |
24289 | + *(stringp_array+i) = ptr; | |
24290 | + len = strlen(ptr) + 1; | |
24291 | + ptr += len; | |
24292 | + } | |
24293 | + | |
24294 | + /* 2) the kltypes */ | |
24295 | + kltypesection = (char *)(stringsection + section_size); | |
24296 | + lp = (long *)kltypesection; | |
24297 | + section_size = *lp++; | |
24298 | + num_kltypes = *lp++; | |
24299 | + element_size = *lp++; | |
24300 | + /* sanity check: */ | |
24301 | + if (element_size != sizeof(kltype_t)) { | |
24302 | + printk("size of kltype_t:%ld does not match\n", element_size); | |
24303 | + goto bad; | |
24304 | + } | |
24305 | + kltypestorage = (void *)lp; | |
24306 | + kltype_array = (kltype_t *)kltypestorage; | |
24307 | + | |
24308 | + /* 3) the dbg_sym_t's */ | |
24309 | + dbgsection = (char *)kltypesection + section_size; | |
24310 | + lp = (long *)dbgsection; | |
24311 | + section_size = *lp++; | |
24312 | + /* sanity check: */ | |
24313 | + if ((dbgsection + section_size) != ((char *)file_storage+file_size)) { | |
24314 | + printk("dbg_sym_ts do not end at end of file\n"); | |
24315 | + goto bad; | |
24316 | + } | |
24317 | + num_dsyms = *lp++; | |
24318 | + element_size = *lp++; | |
24319 | + /* sanity check: */ | |
24320 | + if (element_size != sizeof(dbg_sym_t)) { | |
24321 | + printk("kdb: size of dbg_sym_t does not match lkcd\'s\n"); | |
24322 | + goto bad; | |
24323 | + } | |
24324 | + | |
24325 | + /* two special words ahead of the structures themselves */ | |
24326 | + head_types_tree = *lp++; | |
24327 | + head_typedefs_tree = *lp++; | |
24328 | + | |
24329 | + dbgstorage = (void *)lp; | |
24330 | + dsym_types_array = (dbg_sym_t *)dbgstorage; | |
24331 | + | |
24332 | + /* return the heads of the two binary trees */ | |
24333 | + *type_treepp = dsym_types_array+head_types_tree; | |
24334 | + *typedef_treepp = dsym_types_array+head_typedefs_tree; | |
24335 | + | |
24336 | + /* translate the indices in our our array of kltype_t's to pointers */ | |
24337 | + /* (see write_kltype() for the fields that can be translated) */ | |
24338 | + klp = kltype_array; | |
24339 | + for (i=0; i<num_kltypes; i++, klp++) { | |
24340 | + if (index_to_char_ptr(&klp->kl_name)) | |
24341 | + goto bad; | |
24342 | + if (index_to_char_ptr(&klp->kl_typestr)) | |
24343 | + goto bad; | |
24344 | + if (index_to_kltype_ptr(&klp->kl_member)) | |
24345 | + goto bad; | |
24346 | + if (index_to_kltype_ptr(&klp->kl_next)) | |
24347 | + goto bad; | |
24348 | + if (index_to_kltype_ptr(&klp->kl_realtype)) | |
24349 | + goto bad; | |
24350 | + if (index_to_kltype_ptr(&klp->kl_indextype)) | |
24351 | + goto bad; | |
24352 | + if (index_to_kltype_ptr(&klp->kl_elementtype)) | |
24353 | + goto bad; | |
24354 | + if (index_to_dbg_ptr((dbg_sym_t **)&klp->kl_ptr)) | |
24355 | + goto bad; | |
24356 | + } | |
24357 | + | |
24358 | + /* translate the indices in our our array of dbg_sym_t's to pointers */ | |
24359 | + /* (see write_dbgtype() for the fields that can be translated) */ | |
24360 | + dbgp = dsym_types_array; | |
24361 | + for (i=0; i<num_dsyms; i++, dbgp++) { | |
24362 | + if (index_to_char_ptr(&dbgp->sym_bt.bt_key)) | |
24363 | + goto bad; | |
24364 | + if (index_to_dbg_ptr((dbg_sym_t **)&dbgp->sym_bt.bt_left)) | |
24365 | + goto bad; | |
24366 | + if (index_to_dbg_ptr((dbg_sym_t **)&dbgp->sym_bt.bt_right)) | |
24367 | + goto bad; | |
24368 | + if (index_to_dbg_ptr((dbg_sym_t **)&dbgp->sym_bt.bt_parent)) | |
24369 | + goto bad; | |
24370 | + if (index_to_dbg_ptr((dbg_sym_t **)&dbgp->sym_next)) | |
24371 | + goto bad; | |
24372 | + if (index_to_dbg_ptr((dbg_sym_t **)&dbgp->sym_link)) | |
24373 | + goto bad; | |
24374 | + if (index_to_kltype_ptr(&dbgp->sym_kltype)) | |
24375 | + goto bad; | |
24376 | + } | |
24377 | + | |
24378 | + vfree(stringp_array); | |
24379 | + return 0; | |
24380 | +bad: | |
24381 | + printk("trans_file_image() returning an error\n"); | |
24382 | + vfree(stringp_array); | |
24383 | + return 1; | |
24384 | +} | |
24385 | + | |
24386 | +/* there is /proc interface to this string */ | |
24387 | +extern char kdb_debug_info_filename[]; | |
24388 | +/* | |
24389 | + * This is the module initialization function. | |
24390 | + */ | |
24391 | +static int __init | |
24392 | +kdbm_debuginfo_init(void) | |
24393 | +{ | |
24394 | + int len; | |
24395 | + long ret, file_size; | |
24396 | + ssize_t sizeread; | |
24397 | + mm_segment_t fs; | |
24398 | + struct file *file; | |
24399 | + loff_t inode_size, pos; | |
24400 | + | |
24401 | + len = strlen(kdb_debug_info_filename); | |
24402 | + if (!len) { | |
24403 | + printk("kdb: no file name in /proc/kdb/debug_info_name\n"); | |
24404 | + return -ENODEV; | |
24405 | + } | |
24406 | + | |
24407 | + fs = get_fs(); /* save previous value of address limits */ | |
24408 | + set_fs (get_ds()); /* use kernel limit */ | |
24409 | + | |
24410 | + file = filp_open(kdb_debug_info_filename, O_RDONLY, 0); | |
24411 | + if (IS_ERR(file)) { | |
24412 | + set_fs(fs); | |
24413 | + printk ( | |
24414 | + "kdb: open of %s (from /proc/kdb/debug_info_name) failed\n", | |
24415 | + kdb_debug_info_filename); | |
24416 | + return -ENODEV; | |
24417 | + } | |
24418 | + if (!file->f_op || (!file->f_op->read && !file->f_op->llseek)) { | |
24419 | + printk ("file has no operation for read or seek\n"); | |
24420 | + set_fs(fs); | |
24421 | + return -ENODEV; | |
24422 | + } | |
24423 | + inode_size = file->f_dentry->d_inode->i_size; | |
24424 | + | |
24425 | + /* | |
24426 | + * File has a header word on it that contains the size of the | |
24427 | + * file. We don't need it, but can use it as a sanity check. | |
24428 | + */ | |
24429 | + pos = 0; | |
24430 | + sizeread = file->f_op->read(file, (char *)&file_size, | |
24431 | + sizeof(file_size), &pos); | |
24432 | + if (sizeread != sizeof(file_size)) { | |
24433 | + printk("could not read %d bytes from %s\n", | |
24434 | + (int)sizeof(file_size), kdb_debug_info_filename); | |
24435 | + ret = filp_close(file, NULL); | |
24436 | + set_fs(fs); | |
24437 | + return -ENODEV; | |
24438 | + } | |
24439 | + if (inode_size != file_size) { | |
24440 | + printk("file says %ld, inode says %lld\n", | |
24441 | + file_size, inode_size); | |
24442 | + ret = filp_close(file, NULL); | |
24443 | + set_fs(fs); | |
24444 | + return -ENODEV; | |
24445 | + } | |
24446 | + | |
24447 | + /* space for the rest of the file: */ | |
24448 | + file_size -= sizeof(long); | |
24449 | + filestorage = (void *)vmalloc(file_size); | |
24450 | + | |
24451 | + pos = sizeof(file_size); /* position after the header word */ | |
24452 | + sizeread = file->f_op->read(file, (char *)filestorage, | |
24453 | + file_size, &pos); | |
24454 | + if (sizeread != file_size) { | |
24455 | + printk("could not read %ld bytes from %s\n", | |
24456 | + file_size, kdb_debug_info_filename); | |
24457 | + ret = filp_close(file, NULL); | |
24458 | + set_fs(fs); | |
24459 | + vfree (filestorage); | |
24460 | + return -ENODEV; | |
24461 | + } | |
24462 | + | |
24463 | + ret = filp_close(file, NULL); | |
24464 | + set_fs(fs); /* restore address limits before returning to user space */ | |
24465 | + | |
24466 | + if (trans_file_image(filestorage, file_size, &types_tree_head, | |
24467 | + &typedefs_tree_head)){ | |
24468 | + vfree (filestorage); | |
24469 | + return -ENODEV; | |
24470 | + } | |
24471 | + printk("kdbm_debuginfo loaded %s\n", kdb_debug_info_filename); | |
24472 | + /* set the lcrash code's binary tree head nodes */ | |
24473 | + type_tree = types_tree_head; | |
24474 | + typedef_tree = typedefs_tree_head; | |
24475 | + | |
24476 | + have_debug_file = 1; | |
24477 | + | |
24478 | + return 0; | |
24479 | +} | |
24480 | + | |
24481 | +/* | |
24482 | + * This is the module exit function. | |
24483 | + */ | |
24484 | +static void __exit | |
24485 | +kdbm_debuginfo_exit(void) | |
24486 | +{ | |
24487 | + printk("kdbm_debuginfo unloaded %s\n", kdb_debug_info_filename); | |
24488 | + vfree (filestorage); | |
24489 | + have_debug_file = 0; | |
24490 | + return; | |
24491 | +} | |
24492 | + | |
24493 | +module_init(kdbm_debuginfo_init); | |
24494 | +module_exit(kdbm_debuginfo_exit); | |
24495 | --- /dev/null | |
24496 | +++ b/kdb/modules/kdbm_pg.c | |
24497 | @@ -0,0 +1,688 @@ | |
24498 | +/* | |
24499 | + * This file is subject to the terms and conditions of the GNU General Public | |
24500 | + * License. See the file "COPYING" in the main directory of this archive | |
24501 | + * for more details. | |
24502 | + * | |
24503 | + * Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved. | |
24504 | + */ | |
24505 | + | |
24506 | +#include <linux/module.h> | |
24507 | +#include <linux/init.h> | |
24508 | +#include <linux/mm.h> | |
24509 | +#include <linux/pagemap.h> | |
24510 | +#include <linux/fs.h> | |
24511 | +#include <linux/bio.h> | |
24512 | +#include <linux/buffer_head.h> | |
24513 | +#include <linux/kdb.h> | |
24514 | +#include <linux/kdbprivate.h> | |
24515 | +#include <linux/blkdev.h> | |
24516 | +#include <linux/ctype.h> | |
24517 | + | |
24518 | +MODULE_AUTHOR("SGI"); | |
24519 | +MODULE_DESCRIPTION("Debug page information"); | |
24520 | +MODULE_LICENSE("GPL"); | |
24521 | + | |
24522 | +/* Standard Linux page stuff */ | |
24523 | + | |
24524 | +#if !defined(CONFIG_DISCONTIGMEM) && !defined(CONFIG_NUMA) | |
24525 | +/* From include/linux/page-flags.h */ | |
24526 | +static char *pg_flag_vals[] = { | |
24527 | + "PG_locked", "PG_error", "PG_referenced", "PG_uptodate", | |
24528 | + "PG_dirty", "PG_lru", "PG_active", "PG_slab", | |
24529 | + "PG_owner_priv_1", "PG_arch_1", "PG_reserved", "PG_private", | |
24530 | + "PG_writeback", | |
24531 | +#ifdef CONFIG_PAGEFLAGS_EXTENDED | |
24532 | + "PG_head", "PG_tail", | |
24533 | +#else | |
24534 | + "PG_compound", | |
24535 | +#endif | |
24536 | + "PG_swapcache", "PG_mappedtodisk", "PG_reclaim", "PG_buddy", | |
24537 | +#ifdef CONFIG_IA64_UNCACHED_ALLOCATOR | |
24538 | + "PG_uncached", | |
24539 | +#endif | |
24540 | + NULL }; | |
24541 | +#endif | |
24542 | + | |
24543 | +/* From include/linux/buffer_head.h */ | |
24544 | +static char *bh_state_vals[] = { | |
24545 | + "Uptodate", "Dirty", "Lock", "Req", | |
24546 | + "Uptodate_Lock", "Mapped", "New", "Async_read", | |
24547 | + "Async_write", "Delay", "Boundary", "Write_EIO", | |
24548 | + "Ordered", "Eopnotsupp", "Unwritten", "PriavateStart", | |
24549 | + NULL }; | |
24550 | + | |
24551 | +/* From include/linux/bio.h */ | |
24552 | +static char *bio_flag_vals[] = { | |
24553 | + "Uptodate", "RW_block", "EOF", "Seg_valid", | |
24554 | + "Cloned", "Bounced", "User_mapped", "Eopnotsupp", | |
24555 | + NULL }; | |
24556 | + | |
24557 | +/* From include/linux/fs.h */ | |
24558 | +static char *inode_flag_vals[] = { | |
24559 | + "I_DIRTY_SYNC", "I_DIRTY_DATASYNC", "I_DIRTY_PAGES", "I_NEW", | |
24560 | + "I_WILL_FREE", "I_FREEING", "I_CLEAR", "I_LOCK", | |
24561 | + "I_SYNC", NULL }; | |
24562 | + | |
24563 | +static char *map_flags(unsigned long flags, char *mapping[]) | |
24564 | +{ | |
24565 | + static char buffer[256]; | |
24566 | + int index; | |
24567 | + int offset = 12; | |
24568 | + | |
24569 | + buffer[0] = '\0'; | |
24570 | + | |
24571 | + for (index = 0; flags && mapping[index]; flags >>= 1, index++) { | |
24572 | + if (flags & 1) { | |
24573 | + if ((offset + strlen(mapping[index]) + 1) >= 80) { | |
24574 | + strcat(buffer, "\n "); | |
24575 | + offset = 12; | |
24576 | + } else if (offset > 12) { | |
24577 | + strcat(buffer, " "); | |
24578 | + offset++; | |
24579 | + } | |
24580 | + strcat(buffer, mapping[index]); | |
24581 | + offset += strlen(mapping[index]); | |
24582 | + } | |
24583 | + } | |
24584 | + | |
24585 | + return (buffer); | |
24586 | +} | |
24587 | + | |
24588 | +static int | |
24589 | +kdbm_buffers(int argc, const char **argv) | |
24590 | +{ | |
24591 | + struct buffer_head bh; | |
24592 | + unsigned long addr; | |
24593 | + long offset = 0; | |
24594 | + int nextarg; | |
24595 | + int diag; | |
24596 | + | |
24597 | + if (argc != 1) | |
24598 | + return KDB_ARGCOUNT; | |
24599 | + | |
24600 | + nextarg = 1; | |
24601 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) || | |
24602 | + (diag = kdb_getarea(bh, addr))) | |
24603 | + return(diag); | |
24604 | + | |
24605 | + kdb_printf("buffer_head at 0x%lx\n", addr); | |
24606 | + kdb_printf(" bno %llu size %llu dev 0x%x\n", | |
24607 | + (unsigned long long)bh.b_blocknr, | |
24608 | + (unsigned long long)bh.b_size, | |
24609 | + bh.b_bdev ? bh.b_bdev->bd_dev : 0); | |
24610 | + kdb_printf(" count %d state 0x%lx [%s]\n", | |
24611 | + bh.b_count.counter, bh.b_state, | |
24612 | + map_flags(bh.b_state, bh_state_vals)); | |
24613 | + kdb_printf(" b_data 0x%p\n", | |
24614 | + bh.b_data); | |
24615 | + kdb_printf(" b_page 0x%p b_this_page 0x%p b_private 0x%p\n", | |
24616 | + bh.b_page, bh.b_this_page, bh.b_private); | |
24617 | + kdb_printf(" b_end_io "); | |
24618 | + if (bh.b_end_io) | |
24619 | + kdb_symbol_print(kdba_funcptr_value(bh.b_end_io), NULL, KDB_SP_VALUE); | |
24620 | + else | |
24621 | + kdb_printf("(NULL)"); | |
24622 | + kdb_printf("\n"); | |
24623 | + | |
24624 | + return 0; | |
24625 | +} | |
24626 | + | |
24627 | +static int | |
24628 | +print_biovec(struct bio_vec *vec, int vcount) | |
24629 | +{ | |
24630 | + struct bio_vec bvec; | |
24631 | + unsigned long addr; | |
24632 | + int diag; | |
24633 | + int i; | |
24634 | + | |
24635 | + if (vcount < 1 || vcount > BIO_MAX_PAGES) { | |
24636 | + kdb_printf(" [skipped iovecs, vcnt is %d]\n", vcount); | |
24637 | + return 0; | |
24638 | + } | |
24639 | + | |
24640 | + addr = (unsigned long)vec; | |
24641 | + for (i = 0; i < vcount; i++) { | |
24642 | + if ((diag = kdb_getarea(bvec, addr))) | |
24643 | + return(diag); | |
24644 | + addr += sizeof(bvec); | |
24645 | + kdb_printf(" [%d] page 0x%p length=%u offset=%u\n", | |
24646 | + i, bvec.bv_page, bvec.bv_len, bvec.bv_offset); | |
24647 | + } | |
24648 | + return 0; | |
24649 | +} | |
24650 | + | |
24651 | +static int | |
24652 | +kdbm_bio(int argc, const char **argv) | |
24653 | +{ | |
24654 | + struct bio bio; | |
24655 | + unsigned long addr; | |
24656 | + long offset = 0; | |
24657 | + int nextarg; | |
24658 | + int diag; | |
24659 | + | |
24660 | + if (argc != 1) | |
24661 | + return KDB_ARGCOUNT; | |
24662 | + | |
24663 | + nextarg = 1; | |
24664 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) || | |
24665 | + (diag = kdb_getarea(bio, addr))) | |
24666 | + return(diag); | |
24667 | + | |
24668 | + kdb_printf("bio at 0x%lx\n", addr); | |
24669 | + kdb_printf(" bno %llu next 0x%p dev 0x%x\n", | |
24670 | + (unsigned long long)bio.bi_sector, | |
24671 | + bio.bi_next, bio.bi_bdev ? bio.bi_bdev->bd_dev : 0); | |
24672 | + kdb_printf(" vcnt %u vec 0x%p rw 0x%lx flags 0x%lx [%s]\n", | |
24673 | + bio.bi_vcnt, bio.bi_io_vec, bio.bi_rw, bio.bi_flags, | |
24674 | + map_flags(bio.bi_flags, bio_flag_vals)); | |
24675 | + print_biovec(bio.bi_io_vec, bio.bi_vcnt); | |
24676 | + kdb_printf(" count %d private 0x%p\n", | |
24677 | + atomic_read(&bio.bi_cnt), bio.bi_private); | |
24678 | + kdb_printf(" bi_end_io "); | |
24679 | + if (bio.bi_end_io) | |
24680 | + kdb_symbol_print(kdba_funcptr_value(bio.bi_end_io), NULL, KDB_SP_VALUE); | |
24681 | + else | |
24682 | + kdb_printf("(NULL)"); | |
24683 | + kdb_printf("\n"); | |
24684 | + | |
24685 | + return 0; | |
24686 | +} | |
24687 | + | |
24688 | +#if !defined(CONFIG_DISCONTIGMEM) && !defined(CONFIG_NUMA) | |
24689 | +static char *page_flags(unsigned long flags) | |
24690 | +{ | |
24691 | + return(map_flags(flags, pg_flag_vals)); | |
24692 | +} | |
24693 | + | |
24694 | +static int | |
24695 | +kdbm_page(int argc, const char **argv) | |
24696 | +{ | |
24697 | + struct page page; | |
24698 | + unsigned long addr; | |
24699 | + long offset = 0; | |
24700 | + int nextarg; | |
24701 | + int diag; | |
24702 | + | |
24703 | + if (argc != 1) | |
24704 | + return KDB_ARGCOUNT; | |
24705 | + | |
24706 | + nextarg = 1; | |
24707 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL); | |
24708 | + if (diag) | |
24709 | + return diag; | |
24710 | + | |
24711 | +#ifdef __ia64__ | |
24712 | + if (rgn_index(addr) == 0) | |
24713 | + addr = (unsigned long) &mem_map[addr]; /* assume region 0 is a page index, not an address */ | |
24714 | +#else | |
24715 | + if (addr < PAGE_OFFSET) | |
24716 | + addr = (unsigned long) &mem_map[addr]; | |
24717 | +#endif | |
24718 | + | |
24719 | + if ((diag = kdb_getarea(page, addr))) | |
24720 | + return(diag); | |
24721 | + | |
24722 | + kdb_printf("struct page at 0x%lx\n", addr); | |
24723 | + kdb_printf(" addr space 0x%p index %lu (offset 0x%llx)\n", | |
24724 | + page.mapping, page.index, | |
24725 | + (unsigned long long)page.index << PAGE_CACHE_SHIFT); | |
24726 | + kdb_printf(" count %d flags %s\n", | |
24727 | + page._count.counter, page_flags(page.flags)); | |
24728 | + kdb_printf(" virtual 0x%p\n", page_address((struct page *)addr)); | |
24729 | + if (page_has_buffers(&page)) | |
24730 | + kdb_printf(" buffers 0x%p\n", page_buffers(&page)); | |
24731 | + else | |
24732 | + kdb_printf(" private 0x%lx\n", page_private(&page)); | |
24733 | + | |
24734 | + return 0; | |
24735 | +} | |
24736 | +#endif /* !CONFIG_DISCONTIGMEM && !NUMA */ | |
24737 | + | |
24738 | +static unsigned long | |
24739 | +print_request(unsigned long addr) | |
24740 | +{ | |
24741 | + struct request rq; | |
24742 | + | |
24743 | + if (kdb_getarea(rq, addr)) | |
24744 | + return(0); | |
24745 | + | |
24746 | + kdb_printf("struct request at 0x%lx\n", addr); | |
24747 | + kdb_printf(" errors %d sector %llu nr_sectors %lu\n", | |
24748 | + rq.errors, | |
24749 | + (unsigned long long)rq.sector, rq.nr_sectors); | |
24750 | + | |
24751 | + kdb_printf(" hsect %llu hnrsect %lu nrseg %u currnrsect %u\n", | |
24752 | + (unsigned long long)rq.hard_sector, rq.hard_nr_sectors, | |
24753 | + rq.nr_phys_segments, rq.current_nr_sectors); | |
24754 | + | |
24755 | + return (unsigned long) rq.queuelist.next; | |
24756 | +} | |
24757 | + | |
24758 | +static int | |
24759 | +kdbm_request(int argc, const char **argv) | |
24760 | +{ | |
24761 | + long offset = 0; | |
24762 | + unsigned long addr; | |
24763 | + int nextarg; | |
24764 | + int diag; | |
24765 | + | |
24766 | + if (argc != 1) | |
24767 | + return KDB_ARGCOUNT; | |
24768 | + | |
24769 | + nextarg = 1; | |
24770 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL); | |
24771 | + if (diag) | |
24772 | + return diag; | |
24773 | + | |
24774 | + print_request(addr); | |
24775 | + return 0; | |
24776 | +} | |
24777 | + | |
24778 | + | |
24779 | +static int | |
24780 | +kdbm_rqueue(int argc, const char **argv) | |
24781 | +{ | |
24782 | + struct request_queue rq; | |
24783 | + unsigned long addr, head_addr, next; | |
24784 | + long offset = 0; | |
24785 | + int nextarg; | |
24786 | + int i, diag; | |
24787 | + | |
24788 | + if (argc != 1) | |
24789 | + return KDB_ARGCOUNT; | |
24790 | + | |
24791 | + nextarg = 1; | |
24792 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) || | |
24793 | + (diag = kdb_getarea(rq, addr))) | |
24794 | + return(diag); | |
24795 | + | |
24796 | + kdb_printf("struct request_queue at 0x%lx\n", addr); | |
24797 | + i = 0; | |
24798 | + next = (unsigned long)rq.queue_head.next; | |
24799 | + head_addr = addr + offsetof(struct request_queue, queue_head); | |
24800 | + kdb_printf(" request queue: %s\n", next == head_addr ? | |
24801 | + "empty" : ""); | |
24802 | + while (next != head_addr) { | |
24803 | + i++; | |
24804 | + next = print_request(next); | |
24805 | + } | |
24806 | + | |
24807 | + if (i) | |
24808 | + kdb_printf("%d requests found\n", i); | |
24809 | + | |
24810 | + return 0; | |
24811 | +} | |
24812 | + | |
24813 | + | |
24814 | +static void | |
24815 | +do_buffer(unsigned long addr) | |
24816 | +{ | |
24817 | + struct buffer_head bh; | |
24818 | + | |
24819 | + if (kdb_getarea(bh, addr)) | |
24820 | + return; | |
24821 | + | |
24822 | + kdb_printf("\tbh 0x%lx bno %8llu [%s]\n", addr, | |
24823 | + (unsigned long long)bh.b_blocknr, | |
24824 | + map_flags(bh.b_state, bh_state_vals)); | |
24825 | +} | |
24826 | + | |
24827 | +static void | |
24828 | +kdbm_show_page(struct page *page, int first) | |
24829 | +{ | |
24830 | + if (first) | |
24831 | + kdb_printf("page_struct index cnt zone nid flags\n"); | |
24832 | + kdb_printf("%p%s %6lu %5d %3d %3d 0x%lx", | |
24833 | + page_address(page), sizeof(void *) == 4 ? " " : "", | |
24834 | + page->index, atomic_read(&(page->_count)), | |
24835 | + page_zonenum(page), page_to_nid(page), | |
24836 | + page->flags & (~0UL >> ZONES_SHIFT)); | |
24837 | +#define kdb_page_flags(page, type) if (Page ## type(page)) kdb_printf(" " #type); | |
24838 | + kdb_page_flags(page, Locked); | |
24839 | + kdb_page_flags(page, Error); | |
24840 | + kdb_page_flags(page, Referenced); | |
24841 | + kdb_page_flags(page, Uptodate); | |
24842 | + kdb_page_flags(page, Dirty); | |
24843 | + kdb_page_flags(page, LRU); | |
24844 | + kdb_page_flags(page, Active); | |
24845 | + kdb_page_flags(page, Slab); | |
24846 | + kdb_page_flags(page, Checked); | |
24847 | + if (page->flags & (1UL << PG_arch_1)) | |
24848 | + kdb_printf(" arch_1"); | |
24849 | + kdb_page_flags(page, Reserved); | |
24850 | + kdb_page_flags(page, Private); | |
24851 | + kdb_page_flags(page, Writeback); | |
24852 | + kdb_page_flags(page, Compound); | |
24853 | + kdb_page_flags(page, SwapCache); | |
24854 | + kdb_page_flags(page, MappedToDisk); | |
24855 | + kdb_page_flags(page, Reclaim); | |
24856 | + kdb_page_flags(page, Buddy); | |
24857 | + | |
24858 | + /* PageHighMem is not a flag any more, but treat it as one */ | |
24859 | + kdb_page_flags(page, HighMem); | |
24860 | + | |
24861 | + if (page_has_buffers(page)) { | |
24862 | + struct buffer_head *head, *bh; | |
24863 | + kdb_printf("\n"); | |
24864 | + head = bh = page_buffers(page); | |
24865 | + do { | |
24866 | + do_buffer((unsigned long) bh); | |
24867 | + } while ((bh = bh->b_this_page) != head); | |
24868 | + } else if (page_private(page)) { | |
24869 | + kdb_printf(" private= 0x%lx", page_private(page)); | |
24870 | + } | |
24871 | + /* Cannot use page_mapping(page) here, it needs swapper_space which is | |
24872 | + * not exported. | |
24873 | + */ | |
24874 | + if (page->mapping) | |
24875 | + kdb_printf(" mapping= %p", page->mapping); | |
24876 | + kdb_printf("\n"); | |
24877 | +#undef kdb_page_flags | |
24878 | +} | |
24879 | + | |
24880 | +static int | |
24881 | +kdbm_inode_pages(int argc, const char **argv) | |
24882 | +{ | |
24883 | + struct inode *inode = NULL; | |
24884 | + struct address_space *ap = NULL; | |
24885 | + unsigned long addr, addr1 = 0; | |
24886 | + long offset = 0; | |
24887 | + int nextarg; | |
24888 | + int diag; | |
24889 | + pgoff_t next = 0; | |
24890 | + struct page *page; | |
24891 | + int first; | |
24892 | + | |
24893 | + nextarg = 1; | |
24894 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL); | |
24895 | + if (diag) | |
24896 | + goto out; | |
24897 | + | |
24898 | + if (argc == 2) { | |
24899 | + nextarg = 2; | |
24900 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &addr1, | |
24901 | + &offset, NULL); | |
24902 | + if (diag) | |
24903 | + goto out; | |
24904 | + kdb_printf("Looking for page index 0x%lx ... \n", addr1); | |
24905 | + next = addr1; | |
24906 | + } | |
24907 | + | |
24908 | + if (!(inode = kmalloc(sizeof(*inode), GFP_ATOMIC))) { | |
24909 | + kdb_printf("kdbm_inode_pages: cannot kmalloc inode\n"); | |
24910 | + goto out; | |
24911 | + } | |
24912 | + if (!(ap = kmalloc(sizeof(*ap), GFP_ATOMIC))) { | |
24913 | + kdb_printf("kdbm_inode_pages: cannot kmalloc ap\n"); | |
24914 | + goto out; | |
24915 | + } | |
24916 | + if ((diag = kdb_getarea(*inode, addr))) | |
24917 | + goto out; | |
24918 | + if (!inode->i_mapping) { | |
24919 | + kdb_printf("inode has no mapping\n"); | |
24920 | + goto out; | |
24921 | + } | |
24922 | + if ((diag = kdb_getarea(*ap, (unsigned long) inode->i_mapping))) | |
24923 | + goto out; | |
24924 | + | |
24925 | + /* Run the pages in the radix tree, printing the state of each page */ | |
24926 | + first = 1; | |
24927 | + while (radix_tree_gang_lookup(&ap->page_tree, (void **)&page, next, 1)) { | |
24928 | + kdbm_show_page(page, first); | |
24929 | + if (addr1) | |
24930 | + break; | |
24931 | + first = 0; | |
24932 | + next = page->index + 1; | |
24933 | + } | |
24934 | + | |
24935 | +out: | |
24936 | + if (inode) | |
24937 | + kfree(inode); | |
24938 | + if (ap) | |
24939 | + kfree(ap); | |
24940 | + return diag; | |
24941 | +} | |
24942 | + | |
24943 | +static int | |
24944 | +kdbm_inode(int argc, const char **argv) | |
24945 | +{ | |
24946 | + struct inode *inode = NULL; | |
24947 | + unsigned long addr; | |
24948 | + unsigned char *iaddr; | |
24949 | + long offset = 0; | |
24950 | + int nextarg; | |
24951 | + int diag; | |
24952 | + | |
24953 | + if (argc != 1) | |
24954 | + return KDB_ARGCOUNT; | |
24955 | + | |
24956 | + nextarg = 1; | |
24957 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL))) | |
24958 | + goto out; | |
24959 | + if (!(inode = kmalloc(sizeof(*inode), GFP_ATOMIC))) { | |
24960 | + kdb_printf("kdbm_inode: cannot kmalloc inode\n"); | |
24961 | + goto out; | |
24962 | + } | |
24963 | + if ((diag = kdb_getarea(*inode, addr))) | |
24964 | + goto out; | |
24965 | + | |
24966 | + kdb_printf("struct inode at 0x%lx\n", addr); | |
24967 | + | |
24968 | + kdb_printf(" i_ino = %lu i_count = %u i_size %Ld\n", | |
24969 | + inode->i_ino, atomic_read(&inode->i_count), | |
24970 | + inode->i_size); | |
24971 | + | |
24972 | + kdb_printf(" i_mode = 0%o i_nlink = %d i_rdev = 0x%x\n", | |
24973 | + inode->i_mode, inode->i_nlink, | |
24974 | + inode->i_rdev); | |
24975 | + | |
24976 | + kdb_printf(" i_hash.nxt = 0x%p i_hash.pprev = 0x%p\n", | |
24977 | + inode->i_hash.next, | |
24978 | + inode->i_hash.pprev); | |
24979 | + | |
24980 | + kdb_printf(" i_list.nxt = 0x%p i_list.prv = 0x%p\n", | |
24981 | + list_entry(inode->i_list.next, struct inode, i_list), | |
24982 | + list_entry(inode->i_list.prev, struct inode, i_list)); | |
24983 | + | |
24984 | + kdb_printf(" i_dentry.nxt = 0x%p i_dentry.prv = 0x%p\n", | |
24985 | + list_entry(inode->i_dentry.next, struct dentry, d_alias), | |
24986 | + list_entry(inode->i_dentry.prev, struct dentry, d_alias)); | |
24987 | + | |
24988 | + kdb_printf(" i_sb = 0x%p i_op = 0x%p i_data = 0x%lx nrpages = %lu\n", | |
24989 | + inode->i_sb, inode->i_op, | |
24990 | + addr + offsetof(struct inode, i_data), | |
24991 | + inode->i_data.nrpages); | |
24992 | + kdb_printf(" i_fop= 0x%p i_flock = 0x%p i_mapping = 0x%p\n", | |
24993 | + inode->i_fop, inode->i_flock, inode->i_mapping); | |
24994 | + | |
24995 | + kdb_printf(" i_flags 0x%x i_state 0x%lx [%s]", | |
24996 | + inode->i_flags, inode->i_state, | |
24997 | + map_flags(inode->i_state, inode_flag_vals)); | |
24998 | + | |
24999 | + iaddr = (char *)addr; | |
25000 | + iaddr += offsetof(struct inode, i_private); | |
25001 | + | |
25002 | + kdb_printf(" fs specific info @ 0x%p\n", iaddr); | |
25003 | +out: | |
25004 | + if (inode) | |
25005 | + kfree(inode); | |
25006 | + return diag; | |
25007 | +} | |
25008 | + | |
25009 | +static int | |
25010 | +kdbm_sb(int argc, const char **argv) | |
25011 | +{ | |
25012 | + struct super_block *sb = NULL; | |
25013 | + unsigned long addr; | |
25014 | + long offset = 0; | |
25015 | + int nextarg; | |
25016 | + int diag; | |
25017 | + | |
25018 | + if (argc != 1) | |
25019 | + return KDB_ARGCOUNT; | |
25020 | + | |
25021 | + nextarg = 1; | |
25022 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL))) | |
25023 | + goto out; | |
25024 | + if (!(sb = kmalloc(sizeof(*sb), GFP_ATOMIC))) { | |
25025 | + kdb_printf("kdbm_sb: cannot kmalloc sb\n"); | |
25026 | + goto out; | |
25027 | + } | |
25028 | + if ((diag = kdb_getarea(*sb, addr))) | |
25029 | + goto out; | |
25030 | + | |
25031 | + kdb_printf("struct super_block at 0x%lx\n", addr); | |
25032 | + kdb_printf(" s_dev 0x%x blocksize 0x%lx\n", sb->s_dev, sb->s_blocksize); | |
25033 | + kdb_printf(" s_flags 0x%lx s_root 0x%p\n", sb->s_flags, sb->s_root); | |
25034 | + kdb_printf(" s_dirt %d s_dirty.next 0x%p s_dirty.prev 0x%p\n", | |
25035 | + sb->s_dirt, sb->s_dirty.next, sb->s_dirty.prev); | |
25036 | + kdb_printf(" s_frozen %d s_id [%s]\n", sb->s_frozen, sb->s_id); | |
25037 | +out: | |
25038 | + if (sb) | |
25039 | + kfree(sb); | |
25040 | + return diag; | |
25041 | +} | |
25042 | + | |
25043 | + | |
25044 | +#if !defined(CONFIG_DISCONTIGMEM) && !defined(CONFIG_NUMA) | |
25045 | +/* According to Steve Lord, this code is ix86 specific. Patches to extend it to | |
25046 | + * other architectures will be greatefully accepted. | |
25047 | + */ | |
25048 | +static int | |
25049 | +kdbm_memmap(int argc, const char **argv) | |
25050 | +{ | |
25051 | + struct page page; | |
25052 | + int i, page_count; | |
25053 | + int slab_count = 0; | |
25054 | + int dirty_count = 0; | |
25055 | + int locked_count = 0; | |
25056 | + int page_counts[10]; /* [8] = large counts, [9] = -1 counts */ | |
25057 | + int buffered_count = 0; | |
25058 | +#ifdef buffer_delay | |
25059 | + int delay_count = 0; | |
25060 | +#endif | |
25061 | + int diag; | |
25062 | + unsigned long addr; | |
25063 | +#ifdef CONFIG_DISCONTIGMEM | |
25064 | + int node_id = -1, found_node = 0; | |
25065 | + int tot_page_count = 0; | |
25066 | + unsigned long unode_id; | |
25067 | + pg_data_t *pgdat; | |
25068 | + | |
25069 | + if (argc == 1) { /* node_id was specified */ | |
25070 | + diag = kdbgetularg(argv[argc], &unode_id); | |
25071 | + if (diag) | |
25072 | + return diag; | |
25073 | + node_id = (int)unode_id; | |
25074 | + } | |
25075 | + else if (argc) | |
25076 | + return KDB_ARGCOUNT; | |
25077 | + | |
25078 | + tot_page_count = 0; | |
25079 | + memset(page_counts, 0, sizeof(page_counts)); | |
25080 | + | |
25081 | + for_each_online_pgdat(pgdat) { | |
25082 | + if ((node_id != -1) && (pgdat->node_id != node_id)) | |
25083 | + continue; | |
25084 | + found_node = 1; | |
25085 | + addr = (unsigned long)pgdat->node_mem_map; | |
25086 | + page_count = pgdat->node_spanned_pages; | |
25087 | + tot_page_count += page_count; | |
25088 | +#else | |
25089 | + addr = (unsigned long)mem_map; | |
25090 | + page_count = max_mapnr; | |
25091 | + memset(page_counts, 0, sizeof(page_counts)); | |
25092 | +#endif | |
25093 | + for (i = 0; i < page_count; i++) { | |
25094 | + if ((diag = kdb_getarea(page, addr))) | |
25095 | + return(diag); | |
25096 | + addr += sizeof(page); | |
25097 | + | |
25098 | + if (PageSlab(&page)) | |
25099 | + slab_count++; | |
25100 | + if (PageDirty(&page)) | |
25101 | + dirty_count++; | |
25102 | + if (PageLocked(&page)) | |
25103 | + locked_count++; | |
25104 | + if (page._count.counter == -1) | |
25105 | + page_counts[9]++; | |
25106 | + else if (page._count.counter < 8) | |
25107 | + page_counts[page._count.counter]++; | |
25108 | + else | |
25109 | + page_counts[8]++; | |
25110 | + if (page_has_buffers(&page)) { | |
25111 | + buffered_count++; | |
25112 | +#ifdef buffer_delay | |
25113 | + if (buffer_delay(page.buffers)) | |
25114 | + delay_count++; | |
25115 | +#endif | |
25116 | + } | |
25117 | + } | |
25118 | +#ifdef CONFIG_DISCONTIGMEM | |
25119 | + } | |
25120 | + page_count = tot_page_count; | |
25121 | + if (node_id != -1) { | |
25122 | + if (!found_node) { | |
25123 | + kdb_printf("Node %d does not exist.\n", node_id); | |
25124 | + return 0; | |
25125 | + } | |
25126 | + kdb_printf("Node %d pages:\n", node_id); | |
25127 | + } | |
25128 | +#endif | |
25129 | + kdb_printf(" Total pages: %6d\n", page_count); | |
25130 | + kdb_printf(" Slab pages: %6d\n", slab_count); | |
25131 | + kdb_printf(" Dirty pages: %6d\n", dirty_count); | |
25132 | + kdb_printf(" Locked pages: %6d\n", locked_count); | |
25133 | + kdb_printf(" Buffer pages: %6d\n", buffered_count); | |
25134 | +#ifdef buffer_delay | |
25135 | + kdb_printf(" Delalloc pages: %6d\n", delay_count); | |
25136 | +#endif | |
25137 | + kdb_printf(" -1 page count: %6d\n", page_counts[9]); | |
25138 | + for (i = 0; i < 8; i++) { | |
25139 | + kdb_printf(" %d page count: %6d\n", | |
25140 | + i, page_counts[i]); | |
25141 | + } | |
25142 | + kdb_printf(" high page count: %6d\n", page_counts[8]); | |
25143 | + return 0; | |
25144 | +} | |
25145 | +#endif /* !CONFIG_DISCONTIGMEM && !NUMA */ | |
25146 | + | |
25147 | +static int __init kdbm_pg_init(void) | |
25148 | +{ | |
25149 | +#if !defined(CONFIG_DISCONTIGMEM) && !defined(CONFIG_NUMA) | |
25150 | + kdb_register("page", kdbm_page, "<vaddr>", "Display page", 0); | |
25151 | +#endif | |
25152 | + kdb_register("inode", kdbm_inode, "<vaddr>", "Display inode", 0); | |
25153 | + kdb_register("sb", kdbm_sb, "<vaddr>", "Display super_block", 0); | |
25154 | + kdb_register("bh", kdbm_buffers, "<buffer head address>", "Display buffer", 0); | |
25155 | + kdb_register("bio", kdbm_bio, "<bio address>", "Display bio", 0); | |
25156 | + kdb_register("inode_pages", kdbm_inode_pages, "<inode *>", "Display pages in an inode", 0); | |
25157 | + kdb_register("req", kdbm_request, "<vaddr>", "dump request struct", 0); | |
25158 | + kdb_register("rqueue", kdbm_rqueue, "<vaddr>", "dump request queue", 0); | |
25159 | +#if !defined(CONFIG_DISCONTIGMEM) && !defined(CONFIG_NUMA) | |
25160 | + kdb_register("memmap", kdbm_memmap, "", "page table summary", 0); | |
25161 | +#endif | |
25162 | + | |
25163 | + return 0; | |
25164 | +} | |
25165 | + | |
25166 | + | |
25167 | +static void __exit kdbm_pg_exit(void) | |
25168 | +{ | |
25169 | +#if !defined(CONFIG_DISCONTIGMEM) && !defined(CONFIG_NUMA) | |
25170 | + kdb_unregister("page"); | |
25171 | +#endif | |
25172 | + kdb_unregister("inode"); | |
25173 | + kdb_unregister("sb"); | |
25174 | + kdb_unregister("bh"); | |
25175 | + kdb_unregister("bio"); | |
25176 | + kdb_unregister("inode_pages"); | |
25177 | + kdb_unregister("req"); | |
25178 | + kdb_unregister("rqueue"); | |
25179 | +#if !defined(CONFIG_DISCONTIGMEM) && !defined(CONFIG_NUMA) | |
25180 | + kdb_unregister("memmap"); | |
25181 | +#endif | |
25182 | +} | |
25183 | + | |
25184 | +module_init(kdbm_pg_init) | |
25185 | +module_exit(kdbm_pg_exit) | |
25186 | --- /dev/null | |
25187 | +++ b/kdb/modules/kdbm_sched.c | |
25188 | @@ -0,0 +1,57 @@ | |
25189 | +/* | |
25190 | + * This file is subject to the terms and conditions of the GNU General Public | |
25191 | + * License. See the file "COPYING" in the main directory of this archive | |
25192 | + * for more details. | |
25193 | + * | |
25194 | + * Copyright (c) 2005 Silicon Graphics, Inc. All Rights Reserved. | |
25195 | + */ | |
25196 | + | |
25197 | +#include <linux/kdb.h> | |
25198 | +#include <linux/kdbprivate.h> | |
25199 | +#include <linux/module.h> | |
25200 | +#include <linux/init.h> | |
25201 | +#include <linux/sched.h> | |
25202 | + | |
25203 | +MODULE_AUTHOR("SGI"); | |
25204 | +MODULE_DESCRIPTION("Debug scheduler information"); | |
25205 | +MODULE_LICENSE("GPL"); | |
25206 | + | |
25207 | +static int | |
25208 | +kdbm_runqueues(int argc, const char **argv) | |
25209 | +{ | |
25210 | + unsigned long cpu; | |
25211 | + int ret = 0; | |
25212 | + | |
25213 | + if (argc == 1) { | |
25214 | + ret = kdbgetularg((char *)argv[1], &cpu); | |
25215 | + if (!ret) { | |
25216 | + if (!cpu_online(cpu)) { | |
25217 | + kdb_printf("Invalid cpu number\n"); | |
25218 | + } else | |
25219 | + kdb_runqueue(cpu, kdb_printf); | |
25220 | + } | |
25221 | + } else if (argc == 0) { | |
25222 | + for_each_online_cpu(cpu) | |
25223 | + kdb_runqueue(cpu, kdb_printf); | |
25224 | + } else { | |
25225 | + /* More than one arg */ | |
25226 | + kdb_printf("Specify one cpu number\n"); | |
25227 | + } | |
25228 | + return ret; | |
25229 | +} | |
25230 | + | |
25231 | +static int __init kdbm_sched_init(void) | |
25232 | +{ | |
25233 | + kdb_register("rq", kdbm_runqueues, "<cpunum>", "Display runqueue for <cpunum>", 0); | |
25234 | + kdb_register("rqa", kdbm_runqueues, "", "Display all runqueues", 0); | |
25235 | + return 0; | |
25236 | +} | |
25237 | + | |
25238 | +static void __exit kdbm_sched_exit(void) | |
25239 | +{ | |
25240 | + kdb_unregister("rq"); | |
25241 | + kdb_unregister("rqa"); | |
25242 | +} | |
25243 | + | |
25244 | +module_init(kdbm_sched_init) | |
25245 | +module_exit(kdbm_sched_exit) | |
25246 | --- /dev/null | |
25247 | +++ b/kdb/modules/kdbm_task.c | |
25248 | @@ -0,0 +1,205 @@ | |
25249 | +/* | |
25250 | + * This file is subject to the terms and conditions of the GNU General Public | |
25251 | + * License. See the file "COPYING" in the main directory of this archive | |
25252 | + * for more details. | |
25253 | + * | |
25254 | + * Copyright (c) 1999-2006 Silicon Graphics, Inc. All Rights Reserved. | |
25255 | + */ | |
25256 | + | |
25257 | +#include <linux/blkdev.h> | |
25258 | +#include <linux/types.h> | |
25259 | +#include <linux/kdb.h> | |
25260 | +#include <linux/kdbprivate.h> | |
25261 | +#include <linux/module.h> | |
25262 | +#include <linux/init.h> | |
25263 | +#include <linux/mm.h> | |
25264 | +#include <linux/sched.h> | |
25265 | +#include <asm/signal.h> | |
25266 | + | |
25267 | +MODULE_AUTHOR("SGI"); | |
25268 | +MODULE_DESCRIPTION("Debug struct task and sigset information"); | |
25269 | +MODULE_LICENSE("GPL"); | |
25270 | + | |
25271 | +static char * | |
25272 | +kdb_cpus_allowed_string(struct task_struct *tp) | |
25273 | +{ | |
25274 | + static char maskbuf[NR_CPUS * 8]; | |
25275 | + if (cpus_equal(tp->cpus_allowed, cpu_online_map)) | |
25276 | + strcpy(maskbuf, "ALL"); | |
25277 | + else if (cpus_full(tp->cpus_allowed)) | |
25278 | + strcpy(maskbuf, "ALL(NR_CPUS)"); | |
25279 | + else if (cpus_empty(tp->cpus_allowed)) | |
25280 | + strcpy(maskbuf, "NONE"); | |
25281 | + else if (cpus_weight(tp->cpus_allowed) == 1) | |
25282 | + snprintf(maskbuf, sizeof(maskbuf), "ONLY(%d)", first_cpu(tp->cpus_allowed)); | |
25283 | + else | |
25284 | + cpulist_scnprintf(maskbuf, sizeof(maskbuf), tp->cpus_allowed); | |
25285 | + return maskbuf; | |
25286 | +} | |
25287 | + | |
25288 | +static int | |
25289 | +kdbm_task(int argc, const char **argv) | |
25290 | +{ | |
25291 | + unsigned long addr; | |
25292 | + long offset=0; | |
25293 | + int nextarg; | |
25294 | + int e = 0; | |
25295 | + struct task_struct *tp = NULL, *tp1; | |
25296 | + | |
25297 | + if (argc != 1) | |
25298 | + return KDB_ARGCOUNT; | |
25299 | + | |
25300 | + nextarg = 1; | |
25301 | + if ((e = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) != 0) | |
25302 | + return(e); | |
25303 | + | |
25304 | + if (!(tp = kmalloc(sizeof(*tp), GFP_ATOMIC))) { | |
25305 | + kdb_printf("%s: cannot kmalloc tp\n", __FUNCTION__); | |
25306 | + goto out; | |
25307 | + } | |
25308 | + if ((e = kdb_getarea(*tp, addr))) { | |
25309 | + kdb_printf("%s: invalid task address\n", __FUNCTION__); | |
25310 | + goto out; | |
25311 | + } | |
25312 | + | |
25313 | + tp1 = (struct task_struct *)addr; | |
25314 | + kdb_printf( | |
25315 | + "struct task at 0x%lx, pid=%d flags=0x%x state=%ld comm=\"%s\"\n", | |
25316 | + addr, tp->pid, tp->flags, tp->state, tp->comm); | |
25317 | + | |
25318 | + kdb_printf(" cpu=%d policy=%u ", kdb_process_cpu(tp), tp->policy); | |
25319 | + kdb_printf( | |
25320 | + "prio=%d static_prio=%d cpus_allowed=", | |
25321 | + tp->prio, tp->static_prio); | |
25322 | + { | |
25323 | + /* The cpus allowed string may be longer than kdb_printf() can | |
25324 | + * handle. Print it in chunks. | |
25325 | + */ | |
25326 | + char c, *p; | |
25327 | + p = kdb_cpus_allowed_string(tp); | |
25328 | + while (1) { | |
25329 | + if (strlen(p) < 100) { | |
25330 | + kdb_printf("%s", p); | |
25331 | + break; | |
25332 | + } | |
25333 | + c = p[100]; | |
25334 | + p[100] = '\0'; | |
25335 | + kdb_printf("%s", p); | |
25336 | + p[100] = c; | |
25337 | + p += 100; | |
25338 | + } | |
25339 | + } | |
25340 | + kdb_printf(" &thread=0x%p\n", &tp1->thread); | |
25341 | + | |
25342 | + kdb_printf(" need_resched=%d ", | |
25343 | + test_tsk_thread_flag(tp, TIF_NEED_RESCHED)); | |
25344 | + kdb_printf( | |
25345 | + "time_slice=%u", | |
25346 | + tp->rt.time_slice); | |
25347 | + kdb_printf(" lock_depth=%d\n", tp->lock_depth); | |
25348 | + | |
25349 | + kdb_printf( | |
25350 | + " fs=0x%p files=0x%p mm=0x%p\n", | |
25351 | + tp->fs, tp->files, tp->mm); | |
25352 | + | |
25353 | + kdb_printf( | |
25354 | + " uid=%d euid=%d suid=%d fsuid=%d gid=%d egid=%d sgid=%d fsgid=%d\n", | |
25355 | + tp->uid, tp->euid, tp->suid, tp->fsuid, tp->gid, tp->egid, tp->sgid, tp->fsgid); | |
25356 | + | |
25357 | + kdb_printf( | |
25358 | + " user=0x%p\n", | |
25359 | + tp->user); | |
25360 | + | |
25361 | + if (tp->sysvsem.undo_list) | |
25362 | + kdb_printf( | |
25363 | + " sysvsem.sem_undo refcnt %d list_proc=0x%p\n", | |
25364 | + atomic_read(&tp->sysvsem.undo_list->refcnt), | |
25365 | + &tp->sysvsem.undo_list->list_proc); | |
25366 | + | |
25367 | + kdb_printf( | |
25368 | + " signal=0x%p &blocked=0x%p &pending=0x%p\n", | |
25369 | + tp->signal, &tp1->blocked, &tp1->pending); | |
25370 | + | |
25371 | + kdb_printf( | |
25372 | + " utime=%ld stime=%ld cutime=%ld cstime=%ld\n", | |
25373 | + tp->utime, tp->stime, | |
25374 | + tp->signal ? tp->signal->cutime : 0L, | |
25375 | + tp->signal ? tp->signal->cstime : 0L); | |
25376 | + | |
25377 | + kdb_printf(" thread_info=0x%p\n", task_thread_info(tp)); | |
25378 | + kdb_printf(" ti flags=0x%lx\n", (unsigned long)task_thread_info(tp)->flags); | |
25379 | + | |
25380 | +#ifdef CONFIG_NUMA | |
25381 | + kdb_printf( | |
25382 | + " mempolicy=0x%p il_next=%d\n", | |
25383 | + tp->mempolicy, tp->il_next); | |
25384 | +#endif | |
25385 | + | |
25386 | +out: | |
25387 | + if (tp) | |
25388 | + kfree(tp); | |
25389 | + return e; | |
25390 | +} | |
25391 | + | |
25392 | +static int | |
25393 | +kdbm_sigset(int argc, const char **argv) | |
25394 | +{ | |
25395 | + sigset_t *sp = NULL; | |
25396 | + unsigned long addr; | |
25397 | + long offset=0; | |
25398 | + int nextarg; | |
25399 | + int e = 0; | |
25400 | + int i; | |
25401 | + char fmt[32]; | |
25402 | + | |
25403 | + if (argc != 1) | |
25404 | + return KDB_ARGCOUNT; | |
25405 | + | |
25406 | +#ifndef _NSIG_WORDS | |
25407 | + kdb_printf("unavailable on this platform, _NSIG_WORDS not defined.\n"); | |
25408 | +#else | |
25409 | + nextarg = 1; | |
25410 | + if ((e = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) != 0) | |
25411 | + return(e); | |
25412 | + | |
25413 | + if (!(sp = kmalloc(sizeof(*sp), GFP_ATOMIC))) { | |
25414 | + kdb_printf("%s: cannot kmalloc sp\n", __FUNCTION__); | |
25415 | + goto out; | |
25416 | + } | |
25417 | + if ((e = kdb_getarea(*sp, addr))) { | |
25418 | + kdb_printf("%s: invalid sigset address\n", __FUNCTION__); | |
25419 | + goto out; | |
25420 | + } | |
25421 | + | |
25422 | + sprintf(fmt, "[%%d]=0x%%0%dlx ", (int)sizeof(sp->sig[0])*2); | |
25423 | + kdb_printf("sigset at 0x%p : ", sp); | |
25424 | + for (i=_NSIG_WORDS-1; i >= 0; i--) { | |
25425 | + if (i == 0 || sp->sig[i]) { | |
25426 | + kdb_printf(fmt, i, sp->sig[i]); | |
25427 | + } | |
25428 | + } | |
25429 | + kdb_printf("\n"); | |
25430 | +#endif /* _NSIG_WORDS */ | |
25431 | + | |
25432 | +out: | |
25433 | + if (sp) | |
25434 | + kfree(sp); | |
25435 | + return e; | |
25436 | +} | |
25437 | + | |
25438 | +static int __init kdbm_task_init(void) | |
25439 | +{ | |
25440 | + kdb_register("task", kdbm_task, "<vaddr>", "Display task_struct", 0); | |
25441 | + kdb_register("sigset", kdbm_sigset, "<vaddr>", "Display sigset_t", 0); | |
25442 | + | |
25443 | + return 0; | |
25444 | +} | |
25445 | + | |
25446 | +static void __exit kdbm_task_exit(void) | |
25447 | +{ | |
25448 | + kdb_unregister("task"); | |
25449 | + kdb_unregister("sigset"); | |
25450 | +} | |
25451 | + | |
25452 | +module_init(kdbm_task_init) | |
25453 | +module_exit(kdbm_task_exit) | |
25454 | --- /dev/null | |
25455 | +++ b/kdb/modules/kdbm_vm.c | |
25456 | @@ -0,0 +1,1036 @@ | |
25457 | +/* | |
25458 | + * This file is subject to the terms and conditions of the GNU General Public | |
25459 | + * License. See the file "COPYING" in the main directory of this archive | |
25460 | + * for more details. | |
25461 | + * | |
25462 | + * Copyright (c) 1999-2006 Silicon Graphics, Inc. All Rights Reserved. | |
25463 | + */ | |
25464 | + | |
25465 | +#include <linux/blkdev.h> | |
25466 | +#include <linux/types.h> | |
25467 | +#include <linux/kdb.h> | |
25468 | +#include <linux/kdbprivate.h> | |
25469 | +#include <linux/module.h> | |
25470 | +#include <linux/init.h> | |
25471 | +#include <linux/mm.h> | |
25472 | +#include <linux/swap.h> | |
25473 | +#include <linux/swapops.h> | |
25474 | + | |
25475 | +#include <scsi.h> | |
25476 | +#include <scsi/scsi_host.h> | |
25477 | +#include <asm/pgtable.h> | |
25478 | + | |
25479 | +MODULE_AUTHOR("SGI"); | |
25480 | +MODULE_DESCRIPTION("Debug VM information"); | |
25481 | +MODULE_LICENSE("GPL"); | |
25482 | + | |
25483 | +struct __vmflags { | |
25484 | + unsigned long mask; | |
25485 | + char *name; | |
25486 | +}; | |
25487 | + | |
25488 | +static struct __vmflags vmflags[] = { | |
25489 | + { VM_READ, "VM_READ " }, | |
25490 | + { VM_WRITE, "VM_WRITE " }, | |
25491 | + { VM_EXEC, "VM_EXEC " }, | |
25492 | + { VM_SHARED, "VM_SHARED " }, | |
25493 | + { VM_MAYREAD, "VM_MAYREAD " }, | |
25494 | + { VM_MAYWRITE, "VM_MAYWRITE " }, | |
25495 | + { VM_MAYEXEC, "VM_MAYEXEC " }, | |
25496 | + { VM_MAYSHARE, "VM_MAYSHARE " }, | |
25497 | + { VM_GROWSDOWN, "VM_GROWSDOWN " }, | |
25498 | + { VM_GROWSUP, "VM_GROWSUP " }, | |
25499 | + { VM_PFNMAP, "VM_PFNMAP " }, | |
25500 | + { VM_DENYWRITE, "VM_DENYWRITE " }, | |
25501 | + { VM_EXECUTABLE, "VM_EXECUTABLE " }, | |
25502 | + { VM_LOCKED, "VM_LOCKED " }, | |
25503 | + { VM_IO, "VM_IO " }, | |
25504 | + { VM_SEQ_READ, "VM_SEQ_READ " }, | |
25505 | + { VM_RAND_READ, "VM_RAND_READ " }, | |
25506 | + { VM_DONTCOPY, "VM_DONTCOPY " }, | |
25507 | + { VM_DONTEXPAND, "VM_DONTEXPAND " }, | |
25508 | + { VM_RESERVED, "VM_RESERVED " }, | |
25509 | + { VM_ACCOUNT, "VM_ACCOUNT " }, | |
25510 | + { VM_HUGETLB, "VM_HUGETLB " }, | |
25511 | + { VM_NONLINEAR, "VM_NONLINEAR " }, | |
25512 | + { VM_MAPPED_COPY, "VM_MAPPED_COPY " }, | |
25513 | + { VM_INSERTPAGE, "VM_INSERTPAGE " }, | |
25514 | + { 0, "" } | |
25515 | +}; | |
25516 | + | |
25517 | +static int | |
25518 | +kdbm_print_vm(struct vm_area_struct *vp, unsigned long addr, int verbose_flg) | |
25519 | +{ | |
25520 | + struct __vmflags *tp; | |
25521 | + | |
25522 | + kdb_printf("struct vm_area_struct at 0x%lx for %d bytes\n", | |
25523 | + addr, (int) sizeof (struct vm_area_struct)); | |
25524 | + | |
25525 | + kdb_printf("vm_start = 0x%p vm_end = 0x%p\n", (void *) vp->vm_start, | |
25526 | + (void *) vp->vm_end); | |
25527 | + kdb_printf("vm_page_prot = 0x%llx\n", | |
25528 | + (unsigned long long)pgprot_val(vp->vm_page_prot)); | |
25529 | + | |
25530 | + kdb_printf("vm_flags: "); | |
25531 | + for (tp = vmflags; tp->mask; tp++) { | |
25532 | + if (vp->vm_flags & tp->mask) { | |
25533 | + kdb_printf(" %s", tp->name); | |
25534 | + } | |
25535 | + } | |
25536 | + kdb_printf("\n"); | |
25537 | + | |
25538 | + if (!verbose_flg) | |
25539 | + return 0; | |
25540 | + | |
25541 | + kdb_printf("vm_mm = 0x%p\n", (void *) vp->vm_mm); | |
25542 | + kdb_printf("vm_next = 0x%p\n", (void *) vp->vm_next); | |
25543 | + kdb_printf("shared.vm_set.list.next = 0x%p\n", (void *) vp->shared.vm_set.list.next); | |
25544 | + kdb_printf("shared.vm_set.list.prev = 0x%p\n", (void *) vp->shared.vm_set.list.prev); | |
25545 | + kdb_printf("shared.vm_set.parent = 0x%p\n", (void *) vp->shared.vm_set.parent); | |
25546 | + kdb_printf("shared.vm_set.head = 0x%p\n", (void *) vp->shared.vm_set.head); | |
25547 | + kdb_printf("anon_vma_node.next = 0x%p\n", (void *) vp->anon_vma_node.next); | |
25548 | + kdb_printf("anon_vma_node.prev = 0x%p\n", (void *) vp->anon_vma_node.prev); | |
25549 | + kdb_printf("vm_ops = 0x%p\n", (void *) vp->vm_ops); | |
25550 | + if (vp->vm_ops != NULL) { | |
25551 | + kdb_printf("vm_ops->open = 0x%p\n", vp->vm_ops->open); | |
25552 | + kdb_printf("vm_ops->close = 0x%p\n", vp->vm_ops->close); | |
25553 | + kdb_printf("vm_ops->fault = 0x%p\n", vp->vm_ops->fault); | |
25554 | +#ifdef HAVE_VMOP_MPROTECT | |
25555 | + kdb_printf("vm_ops->mprotect = 0x%p\n", vp->vm_ops->mprotect); | |
25556 | +#endif | |
25557 | +#ifdef CONFIG_NUMA | |
25558 | + kdb_printf("vm_ops->set_policy = 0x%p\n", vp->vm_ops->set_policy); | |
25559 | + kdb_printf("vm_ops->get_policy = 0x%p\n", vp->vm_ops->get_policy); | |
25560 | +#endif | |
25561 | + } | |
25562 | + kdb_printf("vm_pgoff = 0x%lx\n", vp->vm_pgoff); | |
25563 | + kdb_printf("vm_file = 0x%p\n", (void *) vp->vm_file); | |
25564 | + kdb_printf("vm_private_data = 0x%p\n", vp->vm_private_data); | |
25565 | +#ifdef CONFIG_NUMA | |
25566 | + kdb_printf("vm_policy = 0x%p\n", vp->vm_policy); | |
25567 | +#endif | |
25568 | + | |
25569 | + return 0; | |
25570 | +} | |
25571 | + | |
25572 | +static int | |
25573 | +kdbm_print_vmp(struct vm_area_struct *vp, int verbose_flg) | |
25574 | +{ | |
25575 | + struct __vmflags *tp; | |
25576 | + | |
25577 | + if (verbose_flg) { | |
25578 | + kdb_printf("0x%lx: ", (unsigned long) vp); | |
25579 | + } | |
25580 | + | |
25581 | + kdb_printf("0x%p 0x%p ", (void *) vp->vm_start, (void *) vp->vm_end); | |
25582 | + | |
25583 | + for (tp = vmflags; tp->mask; tp++) { | |
25584 | + if (vp->vm_flags & tp->mask) { | |
25585 | + kdb_printf(" %s", tp->name); | |
25586 | + } | |
25587 | + } | |
25588 | + kdb_printf("\n"); | |
25589 | + | |
25590 | + return 0; | |
25591 | +} | |
25592 | + | |
25593 | + | |
25594 | +#ifdef CONFIG_NUMA | |
25595 | +#include <linux/mempolicy.h> | |
25596 | + | |
25597 | +/* | |
25598 | + * kdbm_mpol | |
25599 | + * | |
25600 | + * This function implements the 'mempolicy' command. | |
25601 | + * Print a struct mempolicy. | |
25602 | + * | |
25603 | + * mempolicy <address> Print struct mempolicy at <address> | |
25604 | + */ | |
25605 | +static int | |
25606 | +kdbm_mpol(int argc, const char **argv) | |
25607 | +{ | |
25608 | + unsigned long addr; | |
25609 | + long offset = 0; | |
25610 | + int nextarg; | |
25611 | + int err = 0; | |
25612 | + struct mempolicy *mp = NULL; | |
25613 | + | |
25614 | + if (argc != 1) | |
25615 | + return KDB_ARGCOUNT; | |
25616 | + | |
25617 | + nextarg = 1; | |
25618 | + if ((err = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, | |
25619 | + NULL)) != 0) | |
25620 | + return(err); | |
25621 | + | |
25622 | + if (!(mp = kmalloc(sizeof(*mp), GFP_ATOMIC))) { | |
25623 | + kdb_printf("%s: cannot kmalloc mp\n", __FUNCTION__); | |
25624 | + goto out; | |
25625 | + } | |
25626 | + | |
25627 | + if ((err = kdb_getarea(*mp, addr))) { | |
25628 | + kdb_printf("%s: invalid mempolicy address\n", __FUNCTION__); | |
25629 | + goto out; | |
25630 | + } | |
25631 | + | |
25632 | + kdb_printf("struct mempolicy at 0x%p\n", (struct mempolicy *)addr); | |
25633 | + kdb_printf(" refcnt %d\n", atomic_read(&mp->refcnt)); | |
25634 | + | |
25635 | + switch (mp->mode) { | |
25636 | + case MPOL_DEFAULT: | |
25637 | + kdb_printf(" mode %d (MPOL_DEFAULT)\n", mp->mode); | |
25638 | + break; | |
25639 | + | |
25640 | + case MPOL_PREFERRED: | |
25641 | + kdb_printf(" mode %d (MPOL_PREFERRED)\n", mp->mode); | |
25642 | + kdb_printf(" preferred_node %d\n", mp->v.preferred_node); | |
25643 | + break; | |
25644 | + | |
25645 | + case MPOL_BIND: | |
25646 | + case MPOL_INTERLEAVE: | |
25647 | + { | |
25648 | + int i, nlongs; | |
25649 | + unsigned long *longp; | |
25650 | + | |
25651 | + kdb_printf(" mode %d (%s)\n", mp->mode, | |
25652 | + mp->mode == MPOL_INTERLEAVE | |
25653 | + ? "MPOL_INTERLEAVE" | |
25654 | + : "MPOL_BIND"); | |
25655 | + nlongs = (int)BITS_TO_LONGS(MAX_NUMNODES); | |
25656 | + kdb_printf(" nodes:"); | |
25657 | + longp = mp->v.nodes.bits; | |
25658 | + for (i = 0; i < nlongs; i++, longp++) | |
25659 | + kdb_printf(" 0x%lx ", *longp); | |
25660 | + kdb_printf("\n"); | |
25661 | + break; | |
25662 | + } | |
25663 | + | |
25664 | + default: | |
25665 | + kdb_printf(" mode %d (unknown)\n", mp->mode); | |
25666 | + break; | |
25667 | + } | |
25668 | +out: | |
25669 | + if (mp) | |
25670 | + kfree(mp); | |
25671 | + return err; | |
25672 | +} | |
25673 | + | |
25674 | +#endif /* CONFIG_NUMA */ | |
25675 | + | |
25676 | +/* | |
25677 | + * kdbm_pgdat | |
25678 | + * | |
25679 | + * This function implements the 'pgdat' command. | |
25680 | + * Print a struct pglist_data (pg_dat_t). | |
25681 | + * | |
25682 | + * pgdat <node_id> Print struct pglist_data for node <node_id>. | |
25683 | + * | |
25684 | + * Print pglist_data for node 0 if node_id not specified, | |
25685 | + * or print the one pglist_data structure if !CONFIG_NUMA. | |
25686 | + */ | |
25687 | +static int | |
25688 | +kdbm_pgdat(int argc, const char **argv) | |
25689 | +{ | |
25690 | + int err = 0, node_id = 0, i; | |
25691 | + pg_data_t *pgdatp = NULL; | |
25692 | + | |
25693 | +#ifdef CONFIG_NUMA | |
25694 | + if (argc > 1) | |
25695 | + return KDB_ARGCOUNT; | |
25696 | + if (argc == 1) { | |
25697 | + int nextarg; | |
25698 | + long offset = 0; | |
25699 | + unsigned long node_id_ul; | |
25700 | + | |
25701 | + nextarg = 1; | |
25702 | + if ((err = kdbgetaddrarg(argc, argv, &nextarg, &node_id_ul, | |
25703 | + &offset, NULL)) != 0) { | |
25704 | + return(err); | |
25705 | + } | |
25706 | + node_id = (int)node_id_ul; | |
25707 | + } | |
25708 | +#endif | |
25709 | + for_each_online_pgdat(pgdatp) { | |
25710 | + if (pgdatp->node_id == node_id) | |
25711 | + break; | |
25712 | + } | |
25713 | + if (!pgdatp) { | |
25714 | + kdb_printf("%s: specified node not found\n", __FUNCTION__); | |
25715 | + return 0; | |
25716 | + } | |
25717 | + kdb_printf("struct pglist_data at 0x%p node_id = %d\n", | |
25718 | + pgdatp, pgdatp->node_id); | |
25719 | + | |
25720 | + for (i = 0; i < MAX_ZONELISTS; i++) { | |
25721 | + int zr; | |
25722 | + struct zoneref *zonerefp; | |
25723 | + struct zone *zonep; | |
25724 | + | |
25725 | + zonerefp = pgdatp->node_zonelists[i]._zonerefs; | |
25726 | + kdb_printf(" _zonerefs[%d] at 0x%p\n", i, zonerefp); | |
25727 | + | |
25728 | + for (zr = 0; zr <= MAX_ZONES_PER_ZONELIST; zr++, zonerefp++) { | |
25729 | + int z; | |
25730 | + pg_data_t *tmp_pgdatp; | |
25731 | + | |
25732 | + zonep = zonelist_zone(zonerefp); | |
25733 | + if (!zonep) | |
25734 | + break; | |
25735 | + | |
25736 | + kdb_printf(" 0x%p", zonep); | |
25737 | + | |
25738 | + for_each_online_pgdat(tmp_pgdatp) { | |
25739 | + for (z = 0; z < MAX_NR_ZONES; z++) { | |
25740 | + if (zonep == &tmp_pgdatp->node_zones[z]) { | |
25741 | + kdb_printf (" (node %d node_zones[%d])", | |
25742 | + tmp_pgdatp->node_id, z); | |
25743 | + break; | |
25744 | + } | |
25745 | + } | |
25746 | + if (z != MAX_NR_ZONES) | |
25747 | + break; /* found it */ | |
25748 | + } | |
25749 | + kdb_printf("\n"); | |
25750 | + } | |
25751 | + } | |
25752 | + | |
25753 | + kdb_printf(" nr_zones = %d", pgdatp->nr_zones); | |
25754 | +#ifdef CONFIG_FLAT_NODE_MEM_MAP | |
25755 | + kdb_printf(" node_mem_map = 0x%p\n", pgdatp->node_mem_map); | |
25756 | +#endif | |
25757 | + kdb_printf(" bdata = 0x%p", pgdatp->bdata); | |
25758 | + kdb_printf(" node_start_pfn = 0x%lx\n", pgdatp->node_start_pfn); | |
25759 | + kdb_printf(" node_present_pages = %ld (0x%lx)\n", | |
25760 | + pgdatp->node_present_pages, pgdatp->node_present_pages); | |
25761 | + kdb_printf(" node_spanned_pages = %ld (0x%lx)\n", | |
25762 | + pgdatp->node_spanned_pages, pgdatp->node_spanned_pages); | |
25763 | + kdb_printf(" kswapd = 0x%p\n", pgdatp->kswapd); | |
25764 | + | |
25765 | + return err; | |
25766 | +} | |
25767 | + | |
25768 | +/* | |
25769 | + * kdbm_vm | |
25770 | + * | |
25771 | + * This function implements the 'vm' command. Print a vm_area_struct. | |
25772 | + * | |
25773 | + * vm [-v] <address> Print vm_area_struct at <address> | |
25774 | + * vmp [-v] <pid> Print all vm_area_structs for <pid> | |
25775 | + */ | |
25776 | + | |
25777 | +static int | |
25778 | +kdbm_vm(int argc, const char **argv) | |
25779 | +{ | |
25780 | + unsigned long addr; | |
25781 | + long offset = 0; | |
25782 | + int nextarg; | |
25783 | + int diag; | |
25784 | + int verbose_flg = 0; | |
25785 | + | |
25786 | + if (argc == 2) { | |
25787 | + if (strcmp(argv[1], "-v") != 0) { | |
25788 | + return KDB_ARGCOUNT; | |
25789 | + } | |
25790 | + verbose_flg = 1; | |
25791 | + } else if (argc != 1) { | |
25792 | + return KDB_ARGCOUNT; | |
25793 | + } | |
25794 | + | |
25795 | + if (strcmp(argv[0], "vmp") == 0) { | |
25796 | + struct task_struct *g, *tp; | |
25797 | + struct vm_area_struct *vp; | |
25798 | + pid_t pid; | |
25799 | + | |
25800 | + if ((diag = kdbgetularg(argv[argc], (unsigned long *) &pid))) | |
25801 | + return diag; | |
25802 | + | |
25803 | + kdb_do_each_thread(g, tp) { | |
25804 | + if (tp->pid == pid) { | |
25805 | + if (tp->mm != NULL) { | |
25806 | + if (verbose_flg) | |
25807 | + kdb_printf | |
25808 | + ("vm_area_struct "); | |
25809 | + kdb_printf | |
25810 | + ("vm_start vm_end vm_flags\n"); | |
25811 | + vp = tp->mm->mmap; | |
25812 | + while (vp != NULL) { | |
25813 | + kdbm_print_vmp(vp, verbose_flg); | |
25814 | + vp = vp->vm_next; | |
25815 | + } | |
25816 | + } | |
25817 | + return 0; | |
25818 | + } | |
25819 | + } kdb_while_each_thread(g, tp); | |
25820 | + | |
25821 | + kdb_printf("No process with pid == %d found\n", pid); | |
25822 | + | |
25823 | + } else { | |
25824 | + struct vm_area_struct v; | |
25825 | + | |
25826 | + nextarg = argc; | |
25827 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, | |
25828 | + NULL)) | |
25829 | + || (diag = kdb_getarea(v, addr))) | |
25830 | + return (diag); | |
25831 | + | |
25832 | + kdbm_print_vm(&v, addr, verbose_flg); | |
25833 | + } | |
25834 | + | |
25835 | + return 0; | |
25836 | +} | |
25837 | + | |
25838 | +static int | |
25839 | +kdbm_print_pte(pte_t * pte) | |
25840 | +{ | |
25841 | + kdb_printf("0x%lx (", (unsigned long) pte_val(*pte)); | |
25842 | + | |
25843 | + if (pte_present(*pte)) { | |
25844 | +#ifdef pte_exec | |
25845 | + if (pte_exec(*pte)) | |
25846 | + kdb_printf("X"); | |
25847 | +#endif | |
25848 | + if (pte_write(*pte)) | |
25849 | + kdb_printf("W"); | |
25850 | +#ifdef pte_read | |
25851 | + if (pte_read(*pte)) | |
25852 | + kdb_printf("R"); | |
25853 | +#endif | |
25854 | + if (pte_young(*pte)) | |
25855 | + kdb_printf("A"); | |
25856 | + if (pte_dirty(*pte)) | |
25857 | + kdb_printf("D"); | |
25858 | + | |
25859 | + } else { | |
25860 | + kdb_printf("OFFSET=0x%lx ", swp_offset(pte_to_swp_entry(*pte))); | |
25861 | + kdb_printf("TYPE=0x%ulx", swp_type(pte_to_swp_entry(*pte))); | |
25862 | + } | |
25863 | + | |
25864 | + kdb_printf(")"); | |
25865 | + | |
25866 | + /* final newline is output by caller of kdbm_print_pte() */ | |
25867 | + | |
25868 | + return 0; | |
25869 | +} | |
25870 | + | |
25871 | +/* | |
25872 | + * kdbm_pte | |
25873 | + * | |
25874 | + * This function implements the 'pte' command. Print all pte_t structures | |
25875 | + * that map to the given virtual address range (<address> through <address> | |
25876 | + * plus <nbytes>) for the given process. The default value for nbytes is | |
25877 | + * one. | |
25878 | + * | |
25879 | + * pte -m <mm> <address> [<nbytes>] Print all pte_t structures for | |
25880 | + * virtual <address> in address space | |
25881 | + * of <mm> which is a pointer to a | |
25882 | + * mm_struct | |
25883 | + * pte -p <pid> <address> [<nbytes>] Print all pte_t structures for | |
25884 | + * virtual <address> in address space | |
25885 | + * of <pid> | |
25886 | + */ | |
25887 | + | |
25888 | +static int | |
25889 | +kdbm_pte(int argc, const char **argv) | |
25890 | +{ | |
25891 | + unsigned long addr; | |
25892 | + long offset = 0; | |
25893 | + int nextarg; | |
25894 | + unsigned long nbytes = 1; | |
25895 | + long npgs; | |
25896 | + int diag; | |
25897 | + int found; | |
25898 | + pid_t pid; | |
25899 | + struct task_struct *tp; | |
25900 | + struct mm_struct *mm, copy_of_mm; | |
25901 | + pgd_t *pgd; | |
25902 | + pud_t *pud; | |
25903 | + pmd_t *pmd; | |
25904 | + pte_t *pte; | |
25905 | + | |
25906 | + if (argc < 3 || argc > 4) { | |
25907 | + return KDB_ARGCOUNT; | |
25908 | + } | |
25909 | + | |
25910 | + if (strcmp(argv[1], "-p") == 0) { | |
25911 | + if ((diag = kdbgetularg(argv[2], (unsigned long *) &pid))) { | |
25912 | + return diag; | |
25913 | + } | |
25914 | + | |
25915 | + found = 0; | |
25916 | + for_each_process(tp) { | |
25917 | + if (tp->pid == pid) { | |
25918 | + if (tp->mm != NULL) { | |
25919 | + found = 1; | |
25920 | + break; | |
25921 | + } | |
25922 | + kdb_printf("task structure's mm field is NULL\n"); | |
25923 | + return 0; | |
25924 | + } | |
25925 | + } | |
25926 | + | |
25927 | + if (!found) { | |
25928 | + kdb_printf("No process with pid == %d found\n", pid); | |
25929 | + return 0; | |
25930 | + } | |
25931 | + mm = tp->mm; | |
25932 | + } else if (strcmp(argv[1], "-m") == 0) { | |
25933 | + | |
25934 | + | |
25935 | + nextarg = 2; | |
25936 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, | |
25937 | + NULL)) | |
25938 | + || (diag = kdb_getarea(copy_of_mm, addr))) | |
25939 | + return (diag); | |
25940 | + mm = ©_of_mm; | |
25941 | + } else { | |
25942 | + return KDB_ARGCOUNT; | |
25943 | + } | |
25944 | + | |
25945 | + if ((diag = kdbgetularg(argv[3], &addr))) { | |
25946 | + return diag; | |
25947 | + } | |
25948 | + | |
25949 | + if (argc == 4) { | |
25950 | + if ((diag = kdbgetularg(argv[4], &nbytes))) { | |
25951 | + return diag; | |
25952 | + } | |
25953 | + } | |
25954 | + | |
25955 | + kdb_printf("vaddr pte\n"); | |
25956 | + | |
25957 | + npgs = ((((addr & ~PAGE_MASK) + nbytes) + ~PAGE_MASK) >> PAGE_SHIFT); | |
25958 | + while (npgs-- > 0) { | |
25959 | + | |
25960 | + kdb_printf("0x%p ", (void *) (addr & PAGE_MASK)); | |
25961 | + | |
25962 | + pgd = pgd_offset(mm, addr); | |
25963 | + if (pgd_present(*pgd)) { | |
25964 | + pud = pud_offset(pgd, addr); | |
25965 | + if (pud_present(*pud)) { | |
25966 | + pmd = pmd_offset(pud, addr); | |
25967 | + if (pmd_present(*pmd)) { | |
25968 | + pte = pte_offset_map(pmd, addr); | |
25969 | + if (pte_present(*pte)) { | |
25970 | + kdbm_print_pte(pte); | |
25971 | + } | |
25972 | + } | |
25973 | + } | |
25974 | + } | |
25975 | + | |
25976 | + kdb_printf("\n"); | |
25977 | + addr += PAGE_SIZE; | |
25978 | + } | |
25979 | + | |
25980 | + return 0; | |
25981 | +} | |
25982 | + | |
25983 | +/* | |
25984 | + * kdbm_rpte | |
25985 | + * | |
25986 | + * This function implements the 'rpte' command. Print all pte_t structures | |
25987 | + * that contain the given physical page range (<pfn> through <pfn> | |
25988 | + * plus <npages>) for the given process. The default value for npages is | |
25989 | + * one. | |
25990 | + * | |
25991 | + * rpte -m <mm> <pfn> [<npages>] Print all pte_t structures for | |
25992 | + * physical page <pfn> in address space | |
25993 | + * of <mm> which is a pointer to a | |
25994 | + * mm_struct | |
25995 | + * rpte -p <pid> <pfn> [<npages>] Print all pte_t structures for | |
25996 | + * physical page <pfn> in address space | |
25997 | + * of <pid> | |
25998 | + */ | |
25999 | + | |
26000 | +static int | |
26001 | +kdbm_rpte(int argc, const char **argv) | |
26002 | +{ | |
26003 | + unsigned long addr; | |
26004 | + unsigned long pfn; | |
26005 | + long offset = 0; | |
26006 | + int nextarg; | |
26007 | + unsigned long npages = 1; | |
26008 | + int diag; | |
26009 | + int found; | |
26010 | + pid_t pid; | |
26011 | + struct task_struct *tp; | |
26012 | + struct mm_struct *mm, copy_of_mm; | |
26013 | + pgd_t *pgd; | |
26014 | + pud_t *pud; | |
26015 | + pmd_t *pmd; | |
26016 | + pte_t *pte; | |
26017 | + unsigned long g, u, m, t; | |
26018 | + | |
26019 | + if (argc < 3 || argc > 4) { | |
26020 | + return KDB_ARGCOUNT; | |
26021 | + } | |
26022 | + | |
26023 | + if (strcmp(argv[1], "-p") == 0) { | |
26024 | + if ((diag = kdbgetularg(argv[2], (unsigned long *) &pid))) { | |
26025 | + return diag; | |
26026 | + } | |
26027 | + | |
26028 | + found = 0; | |
26029 | + for_each_process(tp) { | |
26030 | + if (tp->pid == pid) { | |
26031 | + if (tp->mm != NULL) { | |
26032 | + found = 1; | |
26033 | + break; | |
26034 | + } | |
26035 | + kdb_printf("task structure's mm field is NULL\n"); | |
26036 | + return 0; | |
26037 | + } | |
26038 | + } | |
26039 | + | |
26040 | + if (!found) { | |
26041 | + kdb_printf("No process with pid == %d found\n", pid); | |
26042 | + return 0; | |
26043 | + } | |
26044 | + mm = tp->mm; | |
26045 | + } else if (strcmp(argv[1], "-m") == 0) { | |
26046 | + | |
26047 | + | |
26048 | + nextarg = 2; | |
26049 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, | |
26050 | + NULL)) | |
26051 | + || (diag = kdb_getarea(copy_of_mm, addr))) | |
26052 | + return (diag); | |
26053 | + mm = ©_of_mm; | |
26054 | + } else { | |
26055 | + return KDB_ARGCOUNT; | |
26056 | + } | |
26057 | + | |
26058 | + if ((diag = kdbgetularg(argv[3], &pfn))) { | |
26059 | + return diag; | |
26060 | + } | |
26061 | + | |
26062 | + if (argc == 4) { | |
26063 | + if ((diag = kdbgetularg(argv[4], &npages))) { | |
26064 | + return diag; | |
26065 | + } | |
26066 | + } | |
26067 | + | |
26068 | + /* spaces after vaddr depends on sizeof(unsigned long) */ | |
26069 | + kdb_printf("pfn vaddr%*s pte\n", | |
26070 | + (int)(2*sizeof(unsigned long) + 2 - 5), " "); | |
26071 | + | |
26072 | + for (g = 0, pgd = pgd_offset(mm, 0UL); g < PTRS_PER_PGD; ++g, ++pgd) { | |
26073 | + if (pgd_none(*pgd) || pgd_bad(*pgd)) | |
26074 | + continue; | |
26075 | + for (u = 0, pud = pud_offset(pgd, 0UL); u < PTRS_PER_PUD; ++u, ++pud) { | |
26076 | + if (pud_none(*pud) || pud_bad(*pud)) | |
26077 | + continue; | |
26078 | + for (m = 0, pmd = pmd_offset(pud, 0UL); m < PTRS_PER_PMD; ++m, ++pmd) { | |
26079 | + if (pmd_none(*pmd) || pmd_bad(*pmd)) | |
26080 | + continue; | |
26081 | + for (t = 0, pte = pte_offset_map(pmd, 0UL); t < PTRS_PER_PTE; ++t, ++pte) { | |
26082 | + if (pte_none(*pte)) | |
26083 | + continue; | |
26084 | + if (pte_pfn(*pte) < pfn || pte_pfn(*pte) >= (pfn + npages)) | |
26085 | + continue; | |
26086 | + addr = g << PGDIR_SHIFT; | |
26087 | +#ifdef __ia64__ | |
26088 | + /* IA64 plays tricks with the pgd mapping to save space. | |
26089 | + * This reverses pgd_index(). | |
26090 | + */ | |
26091 | + { | |
26092 | + unsigned long region = g >> (PAGE_SHIFT - 6); | |
26093 | + unsigned long l1index = g - (region << (PAGE_SHIFT - 6)); | |
26094 | + addr = (region << 61) + (l1index << PGDIR_SHIFT); | |
26095 | + } | |
26096 | +#endif | |
26097 | + addr += (m << PMD_SHIFT) + (t << PAGE_SHIFT); | |
26098 | + kdb_printf("0x%-14lx " kdb_bfd_vma_fmt0 " ", | |
26099 | + pte_pfn(*pte), addr); | |
26100 | + kdbm_print_pte(pte); | |
26101 | + kdb_printf("\n"); | |
26102 | + } | |
26103 | + } | |
26104 | + } | |
26105 | + } | |
26106 | + | |
26107 | + return 0; | |
26108 | +} | |
26109 | + | |
26110 | +static int | |
26111 | +kdbm_print_dentry(unsigned long daddr) | |
26112 | +{ | |
26113 | + struct dentry d; | |
26114 | + int diag; | |
26115 | + char buf[256]; | |
26116 | + | |
26117 | + kdb_printf("Dentry at 0x%lx\n", daddr); | |
26118 | + if ((diag = kdb_getarea(d, (unsigned long)daddr))) | |
26119 | + return diag; | |
26120 | + | |
26121 | + if ((d.d_name.len > sizeof(buf)) || (diag = kdb_getarea_size(buf, (unsigned long)(d.d_name.name), d.d_name.len))) | |
26122 | + kdb_printf(" d_name.len = %d d_name.name = 0x%p\n", | |
26123 | + d.d_name.len, d.d_name.name); | |
26124 | + else | |
26125 | + kdb_printf(" d_name.len = %d d_name.name = 0x%p <%.*s>\n", | |
26126 | + d.d_name.len, d.d_name.name, | |
26127 | + (int)(d.d_name.len), d.d_name.name); | |
26128 | + | |
26129 | + kdb_printf(" d_count = %d d_flags = 0x%x d_inode = 0x%p\n", | |
26130 | + atomic_read(&d.d_count), d.d_flags, d.d_inode); | |
26131 | + | |
26132 | + kdb_printf(" d_parent = 0x%p\n", d.d_parent); | |
26133 | + | |
26134 | + kdb_printf(" d_hash.nxt = 0x%p d_hash.prv = 0x%p\n", | |
26135 | + d.d_hash.next, d.d_hash.pprev); | |
26136 | + | |
26137 | + kdb_printf(" d_lru.nxt = 0x%p d_lru.prv = 0x%p\n", | |
26138 | + d.d_lru.next, d.d_lru.prev); | |
26139 | + | |
26140 | + kdb_printf(" d_child.nxt = 0x%p d_child.prv = 0x%p\n", | |
26141 | + d.d_u.d_child.next, d.d_u.d_child.prev); | |
26142 | + | |
26143 | + kdb_printf(" d_subdirs.nxt = 0x%p d_subdirs.prv = 0x%p\n", | |
26144 | + d.d_subdirs.next, d.d_subdirs.prev); | |
26145 | + | |
26146 | + kdb_printf(" d_alias.nxt = 0x%p d_alias.prv = 0x%p\n", | |
26147 | + d.d_alias.next, d.d_alias.prev); | |
26148 | + | |
26149 | + kdb_printf(" d_op = 0x%p d_sb = 0x%p d_fsdata = 0x%p\n", | |
26150 | + d.d_op, d.d_sb, d.d_fsdata); | |
26151 | + | |
26152 | + kdb_printf(" d_iname = %s\n", | |
26153 | + d.d_iname); | |
26154 | + | |
26155 | + if (d.d_inode) { | |
26156 | + struct inode i; | |
26157 | + kdb_printf("\nInode Entry at 0x%p\n", d.d_inode); | |
26158 | + if ((diag = kdb_getarea(i, (unsigned long)d.d_inode))) | |
26159 | + return diag; | |
26160 | + kdb_printf(" i_mode = 0%o i_nlink = %d i_rdev = 0x%x\n", | |
26161 | + i.i_mode, i.i_nlink, i.i_rdev); | |
26162 | + | |
26163 | + kdb_printf(" i_ino = %ld i_count = %d\n", | |
26164 | + i.i_ino, atomic_read(&i.i_count)); | |
26165 | + | |
26166 | + kdb_printf(" i_hash.nxt = 0x%p i_hash.prv = 0x%p\n", | |
26167 | + i.i_hash.next, i.i_hash.pprev); | |
26168 | + | |
26169 | + kdb_printf(" i_list.nxt = 0x%p i_list.prv = 0x%p\n", | |
26170 | + i.i_list.next, i.i_list.prev); | |
26171 | + | |
26172 | + kdb_printf(" i_dentry.nxt = 0x%p i_dentry.prv = 0x%p\n", | |
26173 | + i.i_dentry.next, i.i_dentry.prev); | |
26174 | + | |
26175 | + } | |
26176 | + kdb_printf("\n"); | |
26177 | + return 0; | |
26178 | +} | |
26179 | + | |
26180 | +static int | |
26181 | +kdbm_filp(int argc, const char **argv) | |
26182 | +{ | |
26183 | + struct file f; | |
26184 | + int nextarg; | |
26185 | + unsigned long addr; | |
26186 | + long offset; | |
26187 | + int diag; | |
26188 | + | |
26189 | + if (argc != 1) | |
26190 | + return KDB_ARGCOUNT; | |
26191 | + | |
26192 | + nextarg = 1; | |
26193 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) || | |
26194 | + (diag = kdb_getarea(f, addr))) | |
26195 | + return diag; | |
26196 | + | |
26197 | + kdb_printf("File Pointer at 0x%lx\n", addr); | |
26198 | + | |
26199 | + kdb_printf(" fu_list.nxt = 0x%p fu_list.prv = 0x%p\n", | |
26200 | + f.f_u.fu_list.next, f.f_u.fu_list.prev); | |
26201 | + | |
26202 | + kdb_printf(" f_dentry = 0x%p f_vfsmnt = 0x%p f_op = 0x%p\n", | |
26203 | + f.f_dentry, f.f_vfsmnt, f.f_op); | |
26204 | + | |
26205 | + kdb_printf(" f_count = %lld f_flags = 0x%x f_mode = 0x%x\n", | |
26206 | + atomic_read(&f.f_count), f.f_flags, f.f_mode); | |
26207 | + | |
26208 | + kdb_printf(" f_pos = %Ld\n", f.f_pos); | |
26209 | +#ifdef CONFIG_SECURITY | |
26210 | + kdb_printf(" security = 0x%p\n", f.f_security); | |
26211 | +#endif | |
26212 | + | |
26213 | + kdb_printf(" private_data = 0x%p f_mapping = 0x%p\n\n", | |
26214 | + f.private_data, f.f_mapping); | |
26215 | + | |
26216 | + return kdbm_print_dentry((unsigned long)f.f_dentry); | |
26217 | +} | |
26218 | + | |
26219 | +static int | |
26220 | +kdbm_fl(int argc, const char **argv) | |
26221 | +{ | |
26222 | + struct file_lock fl; | |
26223 | + int nextarg; | |
26224 | + unsigned long addr; | |
26225 | + long offset; | |
26226 | + int diag; | |
26227 | + | |
26228 | + | |
26229 | + if (argc != 1) | |
26230 | + return KDB_ARGCOUNT; | |
26231 | + | |
26232 | + nextarg = 1; | |
26233 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) || | |
26234 | + (diag = kdb_getarea(fl, addr))) | |
26235 | + return diag; | |
26236 | + | |
26237 | + kdb_printf("File_lock at 0x%lx\n", addr); | |
26238 | + | |
26239 | + kdb_printf(" fl_next = 0x%p fl_link.nxt = 0x%p fl_link.prv = 0x%p\n", | |
26240 | + fl.fl_next, fl.fl_link.next, fl.fl_link.prev); | |
26241 | + kdb_printf(" fl_block.nxt = 0x%p fl_block.prv = 0x%p\n", | |
26242 | + fl.fl_block.next, fl.fl_block.prev); | |
26243 | + kdb_printf(" fl_owner = 0x%p fl_pid = %d fl_wait = 0x%p\n", | |
26244 | + fl.fl_owner, fl.fl_pid, &fl.fl_wait); | |
26245 | + kdb_printf(" fl_file = 0x%p fl_flags = 0x%x\n", | |
26246 | + fl.fl_file, fl.fl_flags); | |
26247 | + kdb_printf(" fl_type = %d fl_start = 0x%llx fl_end = 0x%llx\n", | |
26248 | + fl.fl_type, fl.fl_start, fl.fl_end); | |
26249 | + | |
26250 | + kdb_printf(" file_lock_operations"); | |
26251 | + if (fl.fl_ops) | |
26252 | + kdb_printf("\n fl_copy_lock = 0x%p fl_release_private = 0x%p\n", | |
26253 | + fl.fl_ops->fl_copy_lock, fl.fl_ops->fl_release_private); | |
26254 | + else | |
26255 | + kdb_printf(" empty\n"); | |
26256 | + | |
26257 | + kdb_printf(" lock_manager_operations"); | |
26258 | + if (fl.fl_lmops) | |
26259 | + kdb_printf("\n fl_compare_owner = 0x%p fl_notify = 0x%p\n", | |
26260 | + fl.fl_lmops->fl_compare_owner, fl.fl_lmops->fl_notify); | |
26261 | + else | |
26262 | + kdb_printf(" empty\n"); | |
26263 | + | |
26264 | + kdb_printf(" fl_fasync = 0x%p fl_break 0x%lx\n", | |
26265 | + fl.fl_fasync, fl.fl_break_time); | |
26266 | + | |
26267 | + return 0; | |
26268 | +} | |
26269 | + | |
26270 | + | |
26271 | +static int | |
26272 | +kdbm_dentry(int argc, const char **argv) | |
26273 | +{ | |
26274 | + int nextarg; | |
26275 | + unsigned long addr; | |
26276 | + long offset; | |
26277 | + int diag; | |
26278 | + | |
26279 | + if (argc != 1) | |
26280 | + return KDB_ARGCOUNT; | |
26281 | + | |
26282 | + nextarg = 1; | |
26283 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL))) | |
26284 | + return diag; | |
26285 | + | |
26286 | + return kdbm_print_dentry(addr); | |
26287 | +} | |
26288 | + | |
26289 | +static int | |
26290 | +kdbm_kobject(int argc, const char **argv) | |
26291 | +{ | |
26292 | + struct kobject k; | |
26293 | + int nextarg; | |
26294 | + unsigned long addr; | |
26295 | + long offset; | |
26296 | + int diag; | |
26297 | + | |
26298 | + if (argc != 1) | |
26299 | + return KDB_ARGCOUNT; | |
26300 | + | |
26301 | + nextarg = 1; | |
26302 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) || | |
26303 | + (diag = kdb_getarea(k, addr))) | |
26304 | + return diag; | |
26305 | + | |
26306 | + | |
26307 | + kdb_printf("kobject at 0x%lx\n", addr); | |
26308 | + | |
26309 | + if (k.name) { | |
26310 | + char c; | |
26311 | + kdb_printf(" name 0x%p", k.name); | |
26312 | + if (kdb_getarea(c, (unsigned long)k.name) == 0) | |
26313 | + kdb_printf(" '%s'", k.name); | |
26314 | + kdb_printf("\n"); | |
26315 | + } | |
26316 | + | |
26317 | + if (k.name != kobject_name((struct kobject *)addr)) | |
26318 | + kdb_printf(" name '%.20s'\n", k.name); | |
26319 | + | |
26320 | + kdb_printf(" kref.refcount %d'\n", atomic_read(&k.kref.refcount)); | |
26321 | + | |
26322 | + kdb_printf(" entry.next = 0x%p entry.prev = 0x%p\n", | |
26323 | + k.entry.next, k.entry.prev); | |
26324 | + | |
26325 | + kdb_printf(" parent = 0x%p kset = 0x%p ktype = 0x%p sd = 0x%p\n", | |
26326 | + k.parent, k.kset, k.ktype, k.sd); | |
26327 | + | |
26328 | + return 0; | |
26329 | +} | |
26330 | + | |
26331 | +static int | |
26332 | +kdbm_sh(int argc, const char **argv) | |
26333 | +{ | |
26334 | + int diag; | |
26335 | + int nextarg; | |
26336 | + unsigned long addr; | |
26337 | + long offset = 0L; | |
26338 | + struct Scsi_Host sh; | |
26339 | + | |
26340 | + if (argc != 1) | |
26341 | + return KDB_ARGCOUNT; | |
26342 | + | |
26343 | + nextarg = 1; | |
26344 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL)) || | |
26345 | + (diag = kdb_getarea(sh, addr))) | |
26346 | + return diag; | |
26347 | + | |
26348 | + kdb_printf("Scsi_Host at 0x%lx\n", addr); | |
26349 | + kdb_printf("host_queue = 0x%p\n", sh.__devices.next); | |
26350 | + kdb_printf("ehandler = 0x%p eh_action = 0x%p\n", | |
26351 | + sh.ehandler, sh.eh_action); | |
26352 | + kdb_printf("host_wait = 0x%p hostt = 0x%p\n", | |
26353 | + &sh.host_wait, sh.hostt); | |
26354 | + kdb_printf("host_failed = %d host_no = %d resetting = %d\n", | |
26355 | + sh.host_failed, sh.host_no, sh.resetting); | |
26356 | + kdb_printf("max id/lun/channel = [%d/%d/%d] this_id = %d\n", | |
26357 | + sh.max_id, sh.max_lun, sh.max_channel, sh.this_id); | |
26358 | + kdb_printf("can_queue = %d cmd_per_lun = %d sg_tablesize = %d u_isa_dma = %d\n", | |
26359 | + sh.can_queue, sh.cmd_per_lun, sh.sg_tablesize, sh.unchecked_isa_dma); | |
26360 | + kdb_printf("host_blocked = %d reverse_ordering = %d \n", | |
26361 | + sh.host_blocked, sh.reverse_ordering); | |
26362 | + | |
26363 | + return 0; | |
26364 | +} | |
26365 | + | |
26366 | +static int | |
26367 | +kdbm_sd(int argc, const char **argv) | |
26368 | +{ | |
26369 | + int diag; | |
26370 | + int nextarg; | |
26371 | + unsigned long addr; | |
26372 | + long offset = 0L; | |
26373 | + struct scsi_device *sd = NULL; | |
26374 | + | |
26375 | + if (argc != 1) | |
26376 | + return KDB_ARGCOUNT; | |
26377 | + | |
26378 | + nextarg = 1; | |
26379 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL))) | |
26380 | + goto out; | |
26381 | + if (!(sd = kmalloc(sizeof(*sd), GFP_ATOMIC))) { | |
26382 | + kdb_printf("kdbm_sd: cannot kmalloc sd\n"); | |
26383 | + goto out; | |
26384 | + } | |
26385 | + if ((diag = kdb_getarea(*sd, addr))) | |
26386 | + goto out; | |
26387 | + | |
26388 | + kdb_printf("scsi_device at 0x%lx\n", addr); | |
26389 | + kdb_printf("next = 0x%p prev = 0x%p host = 0x%p\n", | |
26390 | + sd->siblings.next, sd->siblings.prev, sd->host); | |
26391 | + kdb_printf("device_busy = %d current_cmnd 0x%p\n", | |
26392 | + sd->device_busy, sd->current_cmnd); | |
26393 | + kdb_printf("id/lun/chan = [%d/%d/%d] single_lun = %d device_blocked = %d\n", | |
26394 | + sd->id, sd->lun, sd->channel, sd->sdev_target->single_lun, sd->device_blocked); | |
26395 | + kdb_printf("queue_depth = %d current_tag = %d scsi_level = %d\n", | |
26396 | + sd->queue_depth, sd->current_tag, sd->scsi_level); | |
26397 | + kdb_printf("%8.8s %16.16s %4.4s\n", sd->vendor, sd->model, sd->rev); | |
26398 | +out: | |
26399 | + if (sd) | |
26400 | + kfree(sd); | |
26401 | + return diag; | |
26402 | +} | |
26403 | + | |
26404 | +static int | |
26405 | +kdbm_sc(int argc, const char **argv) | |
26406 | +{ | |
26407 | + int diag; | |
26408 | + int nextarg; | |
26409 | + unsigned long addr; | |
26410 | + long offset = 0L; | |
26411 | + struct scsi_cmnd *sc = NULL; | |
26412 | + | |
26413 | + if (argc != 1) | |
26414 | + return KDB_ARGCOUNT; | |
26415 | + | |
26416 | + nextarg = 1; | |
26417 | + if ((diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL))) | |
26418 | + goto out; | |
26419 | + if (!(sc = kmalloc(sizeof(*sc), GFP_ATOMIC))) { | |
26420 | + kdb_printf("kdbm_sc: cannot kmalloc sc\n"); | |
26421 | + goto out; | |
26422 | + } | |
26423 | + if ((diag = kdb_getarea(*sc, addr))) | |
26424 | + goto out; | |
26425 | + | |
26426 | + kdb_printf("scsi_cmnd at 0x%lx\n", addr); | |
26427 | + kdb_printf("device = 0x%p next = 0x%p\n", | |
26428 | + sc->device, sc->list.next); | |
26429 | + kdb_printf("serial_number = %ld retries = %d\n", | |
26430 | + sc->serial_number, sc->retries); | |
26431 | + kdb_printf("cmd_len = %d\n", sc->cmd_len); | |
26432 | + kdb_printf("cmnd = [%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x/%2.2x]\n", | |
26433 | + sc->cmnd[0], sc->cmnd[1], sc->cmnd[2], sc->cmnd[3], sc->cmnd[4], | |
26434 | + sc->cmnd[5], sc->cmnd[6], sc->cmnd[7], sc->cmnd[8], sc->cmnd[9], | |
26435 | + sc->cmnd[10], sc->cmnd[11]); | |
26436 | + kdb_printf("request_buffer = 0x%p request_bufflen = %d\n", | |
26437 | + scsi_sglist(sc), scsi_bufflen(sc)); | |
26438 | + kdb_printf("use_sg = %d\n", scsi_sg_count(sc)); | |
26439 | + kdb_printf("underflow = %d transfersize = %d\n", | |
26440 | + sc->underflow, sc->transfersize); | |
26441 | + kdb_printf("tag = %d\n", sc->tag); | |
26442 | + | |
26443 | +out: | |
26444 | + if (sc) | |
26445 | + kfree(sc); | |
26446 | + return diag; | |
26447 | +} | |
26448 | + | |
26449 | +static int __init kdbm_vm_init(void) | |
26450 | +{ | |
26451 | + kdb_register("vm", kdbm_vm, "[-v] <vaddr>", "Display vm_area_struct", 0); | |
26452 | + kdb_register("vmp", kdbm_vm, "[-v] <pid>", "Display all vm_area_struct for <pid>", 0); | |
26453 | +#ifdef CONFIG_NUMA | |
26454 | + kdb_register("mempolicy", kdbm_mpol, "<vaddr>", "Display mempolicy structure", 0); | |
26455 | + kdb_register("pgdat", kdbm_pgdat, "<node_id>", "Display pglist_data node structure", 0); | |
26456 | +#else | |
26457 | + kdb_register("pgdat", kdbm_pgdat, "", "Display pglist_data node structure", 0); | |
26458 | +#endif | |
26459 | + kdb_register("pte", kdbm_pte, "( -m <mm> | -p <pid> ) <vaddr> [<nbytes>]", "Display pte_t for mm_struct or pid", 0); | |
26460 | + kdb_register("rpte", kdbm_rpte, "( -m <mm> | -p <pid> ) <pfn> [<npages>]", "Find pte_t containing pfn for mm_struct or pid", 0); | |
26461 | + kdb_register("dentry", kdbm_dentry, "<dentry>", "Display interesting dentry stuff", 0); | |
26462 | + kdb_register("kobject", kdbm_kobject, "<kobject>", "Display interesting kobject stuff", 0); | |
26463 | + kdb_register("filp", kdbm_filp, "<filp>", "Display interesting filp stuff", 0); | |
26464 | + kdb_register("fl", kdbm_fl, "<fl>", "Display interesting file_lock stuff", 0); | |
26465 | + kdb_register("sh", kdbm_sh, "<vaddr>", "Show scsi_host", 0); | |
26466 | + kdb_register("sd", kdbm_sd, "<vaddr>", "Show scsi_device", 0); | |
26467 | + kdb_register("sc", kdbm_sc, "<vaddr>", "Show scsi_cmnd", 0); | |
26468 | + | |
26469 | + return 0; | |
26470 | +} | |
26471 | + | |
26472 | +static void __exit kdbm_vm_exit(void) | |
26473 | +{ | |
26474 | + kdb_unregister("vm"); | |
26475 | + kdb_unregister("vmp"); | |
26476 | +#ifdef CONFIG_NUMA | |
26477 | + kdb_unregister("mempolicy"); | |
26478 | +#endif | |
26479 | + kdb_unregister("pgdat"); | |
26480 | + kdb_unregister("pte"); | |
26481 | + kdb_unregister("rpte"); | |
26482 | + kdb_unregister("dentry"); | |
26483 | + kdb_unregister("kobject"); | |
26484 | + kdb_unregister("filp"); | |
26485 | + kdb_unregister("fl"); | |
26486 | + kdb_unregister("sh"); | |
26487 | + kdb_unregister("sd"); | |
26488 | + kdb_unregister("sc"); | |
26489 | +} | |
26490 | + | |
26491 | +module_init(kdbm_vm_init) | |
26492 | +module_exit(kdbm_vm_exit) | |
26493 | --- /dev/null | |
26494 | +++ b/kdb/modules/kdbm_x86.c | |
26495 | @@ -0,0 +1,1093 @@ | |
26496 | +/* | |
26497 | + * This file is subject to the terms and conditions of the GNU General Public | |
26498 | + * License. See the file "COPYING" in the main directory of this archive | |
26499 | + * for more details. | |
26500 | + * | |
26501 | + * Author: Vamsi Krishna S. <vamsi_krishna@in.ibm.com> | |
26502 | + * (C) 2003 IBM Corporation. | |
26503 | + * 2006-10-10 Keith Owens | |
26504 | + * Reworked to include x86_64 support | |
26505 | + * Copyright (c) 2006 Silicon Graphics, Inc. All Rights Reserved. | |
26506 | + */ | |
26507 | + | |
26508 | +#include <linux/interrupt.h> | |
26509 | +#include <linux/types.h> | |
26510 | +#include <linux/kdb.h> | |
26511 | +#include <linux/kdbprivate.h> | |
26512 | +#include <linux/module.h> | |
26513 | +#include <linux/init.h> | |
26514 | +#include <linux/mm.h> | |
26515 | + | |
26516 | +#include <asm/processor.h> | |
26517 | +#include <asm/uaccess.h> | |
26518 | +#include <asm/desc.h> | |
26519 | +#include <asm/debugreg.h> | |
26520 | +#if 0 | |
26521 | +#include <asm/pgtable.h> | |
26522 | +#endif | |
26523 | + | |
26524 | +MODULE_AUTHOR("Vamsi Krishna S./IBM"); | |
26525 | +MODULE_DESCRIPTION("x86 specific information (gdt/idt/ldt/page tables)"); | |
26526 | +MODULE_LICENSE("GPL"); | |
26527 | + | |
26528 | +/* Isolate as many of the i386/x86_64 differences as possible in one spot */ | |
26529 | + | |
26530 | +#ifdef CONFIG_X86_64 | |
26531 | + | |
26532 | +#define KDB_X86_64 1 | |
26533 | +#define MOVLQ "movq" | |
26534 | + | |
26535 | +typedef struct desc_struct kdb_desc_t; | |
26536 | +typedef struct gate_struct64 kdb_gate_desc_t; | |
26537 | + | |
26538 | +#define KDB_SYS_DESC_OFFSET(d) ((unsigned long)d->offset_high << 32 | d->offset_middle << 16 | d->offset_low) | |
26539 | +#define KDB_SYS_DESC_CALLG_COUNT(d) 0 | |
26540 | + | |
26541 | +#else /* !CONFIG_X86_64 */ | |
26542 | + | |
26543 | +#define KDB_X86_64 0 | |
26544 | +#define MOVLQ "movl" | |
26545 | + | |
26546 | +/* i386 has no detailed mapping for the 8 byte segment descriptor, copy the | |
26547 | + * x86_64 one and merge the l and avl bits. | |
26548 | + */ | |
26549 | +struct kdb_desc { | |
26550 | + u16 limit0; | |
26551 | + u16 base0; | |
26552 | + unsigned base1 : 8, type : 4, s : 1, dpl : 2, p : 1; | |
26553 | + unsigned limit : 4, avl : 2, d : 1, g : 1, base2 : 8; | |
26554 | +} __attribute__((packed)); | |
26555 | +typedef struct kdb_desc kdb_desc_t; | |
26556 | + | |
26557 | +/* i386 has no detailed mapping for the 8 byte gate descriptor, base it on the | |
26558 | + * x86_64 one. | |
26559 | + */ | |
26560 | +struct kdb_gate_desc { | |
26561 | + u16 offset_low; | |
26562 | + u16 segment; | |
26563 | + unsigned res : 8, type : 4, s : 1, dpl : 2, p : 1; | |
26564 | + u16 offset_middle; | |
26565 | +} __attribute__((packed)); | |
26566 | +typedef struct kdb_gate_desc kdb_gate_desc_t; | |
26567 | + | |
26568 | +#define KDB_SYS_DESC_OFFSET(d) ((unsigned long)(d->offset_middle << 16 | d->offset_low)) | |
26569 | +#define KDB_SYS_DESC_CALLG_COUNT(d) ((unsigned int)(d->res & 0x0F)) | |
26570 | + | |
26571 | +#endif /* CONFIG_X86_64 */ | |
26572 | + | |
26573 | +#define KDB_SEL_MAX 0x2000 | |
26574 | +#define KDB_IDT_MAX 0x100 | |
26575 | +#define KDB_SYS_DESC_TYPE_TSS16 0x01 | |
26576 | +#define KDB_SYS_DESC_TYPE_LDT 0x02 | |
26577 | +#define KDB_SYS_DESC_TYPE_TSSB16 0x03 | |
26578 | +#define KDB_SYS_DESC_TYPE_CALLG16 0x04 | |
26579 | +#define KDB_SYS_DESC_TYPE_TASKG 0x05 | |
26580 | +#define KDB_SYS_DESC_TYPE_INTG16 0x06 | |
26581 | +#define KDB_SYS_DESC_TYPE_TRAP16 0x07 | |
26582 | + | |
26583 | +#define KDB_SYS_DESC_TYPE_TSS 0x09 | |
26584 | +#define KDB_SYS_DESC_TYPE_TSSB 0x0b | |
26585 | +#define KDB_SYS_DESC_TYPE_CALLG 0x0c | |
26586 | +#define KDB_SYS_DESC_TYPE_INTG 0x0e | |
26587 | +#define KDB_SYS_DESC_TYPE_TRAPG 0x0f | |
26588 | + | |
26589 | +#define KDB_SEG_DESC_TYPE_CODE 0x08 | |
26590 | +#define KDB_SEG_DESC_TYPE_CODE_R 0x02 | |
26591 | +#define KDB_SEG_DESC_TYPE_DATA_W 0x02 | |
26592 | +#define KDB_SEG_DESC_TYPE_CODE_C 0x02 /* conforming */ | |
26593 | +#define KDB_SEG_DESC_TYPE_DATA_D 0x02 /* expand-down */ | |
26594 | +#define KDB_SEG_DESC_TYPE_A 0x01 /* accessed */ | |
26595 | + | |
26596 | +#define _LIMIT(d) ((unsigned long)((d)->limit << 16 | (d)->limit0)) | |
26597 | +#define KDB_SEG_DESC_LIMIT(d) ((d)->g ? ((_LIMIT(d)+1) << 12) -1 : _LIMIT(d)) | |
26598 | + | |
26599 | +static unsigned long kdb_seg_desc_base(kdb_desc_t *d) | |
26600 | +{ | |
26601 | + unsigned long base = d->base2 << 24 | d->base1 << 16 | d->base0; | |
26602 | +#ifdef CONFIG_X86_64 | |
26603 | + switch (d->type) { | |
26604 | + case KDB_SYS_DESC_TYPE_TSS: | |
26605 | + case KDB_SYS_DESC_TYPE_TSSB: | |
26606 | + case KDB_SYS_DESC_TYPE_LDT: | |
26607 | + base += (unsigned long)(((struct ldttss_desc64 *)d)->base3) << 32; | |
26608 | + break; | |
26609 | + } | |
26610 | +#endif | |
26611 | + return base; | |
26612 | +} | |
26613 | + | |
26614 | +/* helper functions to display system registers in verbose mode */ | |
26615 | +static void display_gdtr(void) | |
26616 | +{ | |
26617 | + struct desc_ptr gdtr; | |
26618 | + | |
26619 | + __asm__ __volatile__ ("sgdt %0\n\t" : "=m"(gdtr)); | |
26620 | + kdb_printf("gdtr.address = " kdb_machreg_fmt0 ", gdtr.size = 0x%x\n", | |
26621 | + gdtr.address, gdtr.size); | |
26622 | + | |
26623 | + return; | |
26624 | +} | |
26625 | + | |
26626 | +static void display_ldtr(void) | |
26627 | +{ | |
26628 | + struct desc_ptr gdtr; | |
26629 | + unsigned long ldtr; | |
26630 | + | |
26631 | + __asm__ __volatile__ ("sgdt %0\n\t" : "=m"(gdtr)); | |
26632 | + __asm__ __volatile__ ("sldt %0\n\t" : "=m"(ldtr)); | |
26633 | + ldtr &= 0xfff8; /* extract the index */ | |
26634 | + | |
26635 | + kdb_printf("ldtr = " kdb_machreg_fmt0 " ", ldtr); | |
26636 | + | |
26637 | + if (ldtr < gdtr.size) { | |
26638 | + kdb_desc_t *ldt_desc = | |
26639 | + (kdb_desc_t *)(gdtr.address + ldtr); | |
26640 | + kdb_printf("base=" kdb_machreg_fmt0 | |
26641 | + ", limit=" kdb_machreg_fmt "\n", | |
26642 | + kdb_seg_desc_base(ldt_desc), | |
26643 | + KDB_SEG_DESC_LIMIT(ldt_desc)); | |
26644 | + } else { | |
26645 | + kdb_printf("invalid\n"); | |
26646 | + } | |
26647 | + | |
26648 | + return; | |
26649 | +} | |
26650 | + | |
26651 | +static void display_idtr(void) | |
26652 | +{ | |
26653 | + struct desc_ptr idtr; | |
26654 | + __asm__ __volatile__ ("sidt %0\n\t" : "=m"(idtr)); | |
26655 | + kdb_printf("idtr.address = " kdb_machreg_fmt0 ", idtr.size = 0x%x\n", | |
26656 | + idtr.address, idtr.size); | |
26657 | + return; | |
26658 | +} | |
26659 | + | |
26660 | +static const char *cr0_flags[] = { | |
26661 | + "pe", "mp", "em", "ts", "et", "ne", NULL, NULL, | |
26662 | + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
26663 | + "wp", NULL, "am", NULL, NULL, NULL, NULL, NULL, | |
26664 | + NULL, NULL, NULL, NULL, NULL, "nw", "cd", "pg"}; | |
26665 | + | |
26666 | +static void display_cr0(void) | |
26667 | +{ | |
26668 | + kdb_machreg_t cr0; | |
26669 | + int i; | |
26670 | + __asm__ (MOVLQ " %%cr0,%0\n\t":"=r"(cr0)); | |
26671 | + kdb_printf("cr0 = " kdb_machreg_fmt0, cr0); | |
26672 | + for (i = 0; i < ARRAY_SIZE(cr0_flags); i++) { | |
26673 | + if (test_bit(i, &cr0) && cr0_flags[i]) | |
26674 | + kdb_printf(" %s", cr0_flags[i]); | |
26675 | + } | |
26676 | + kdb_printf("\n"); | |
26677 | + return; | |
26678 | +} | |
26679 | + | |
26680 | +static void display_cr3(void) | |
26681 | +{ | |
26682 | + kdb_machreg_t cr3; | |
26683 | + __asm__ (MOVLQ " %%cr3,%0\n\t":"=r"(cr3)); | |
26684 | + kdb_printf("cr3 = " kdb_machreg_fmt0 " ", cr3); | |
26685 | + if (cr3 & 0x08) | |
26686 | + kdb_printf("pwt "); | |
26687 | + if (cr3 & 0x10) | |
26688 | + kdb_printf("pcd "); | |
26689 | + kdb_printf("%s=" kdb_machreg_fmt0 "\n", | |
26690 | + KDB_X86_64 ? "pml4" : "pgdir", cr3 & PAGE_MASK); | |
26691 | + return; | |
26692 | +} | |
26693 | + | |
26694 | +static const char *cr4_flags[] = { | |
26695 | + "vme", "pvi", "tsd", "de", | |
26696 | + "pse", "pae", "mce", "pge", | |
26697 | + "pce", "osfxsr" "osxmmexcpt"}; | |
26698 | + | |
26699 | +static void display_cr4(void) | |
26700 | +{ | |
26701 | + kdb_machreg_t cr4; | |
26702 | + int i; | |
26703 | + __asm__ (MOVLQ " %%cr4,%0\n\t":"=r"(cr4)); | |
26704 | + kdb_printf("cr4 = " kdb_machreg_fmt0, cr4); | |
26705 | + for (i = 0; i < ARRAY_SIZE(cr4_flags); i++) { | |
26706 | + if (test_bit(i, &cr4)) | |
26707 | + kdb_printf(" %s", cr4_flags[i]); | |
26708 | + } | |
26709 | + kdb_printf("\n"); | |
26710 | + return; | |
26711 | +} | |
26712 | + | |
26713 | +static void display_cr8(void) | |
26714 | +{ | |
26715 | +#ifdef CONFIG_X86_64 | |
26716 | + kdb_machreg_t cr8; | |
26717 | + __asm__ (MOVLQ " %%cr8,%0\n\t":"=r"(cr8)); | |
26718 | + kdb_printf("cr8 = " kdb_machreg_fmt0 "\n", cr8); | |
26719 | + return; | |
26720 | +#endif /* CONFIG_X86_64 */ | |
26721 | +} | |
26722 | + | |
26723 | +static char *dr_type_name[] = { "exec", "write", "io", "rw" }; | |
26724 | + | |
26725 | +static void display_dr_status(int nr, int enabled, int local, int len, int type) | |
26726 | +{ | |
26727 | + if (!enabled) { | |
26728 | + kdb_printf("\tdebug register %d: not enabled\n", nr); | |
26729 | + return; | |
26730 | + } | |
26731 | + | |
26732 | + kdb_printf(" debug register %d: %s, len = %d, type = %s\n", | |
26733 | + nr, | |
26734 | + local? " local":"global", | |
26735 | + len, | |
26736 | + dr_type_name[type]); | |
26737 | +} | |
26738 | + | |
26739 | +static void display_dr(void) | |
26740 | +{ | |
26741 | + kdb_machreg_t dr0, dr1, dr2, dr3, dr6, dr7; | |
26742 | + int dbnr, set; | |
26743 | + | |
26744 | + __asm__ (MOVLQ " %%db0,%0\n\t":"=r"(dr0)); | |
26745 | + __asm__ (MOVLQ " %%db1,%0\n\t":"=r"(dr1)); | |
26746 | + __asm__ (MOVLQ " %%db2,%0\n\t":"=r"(dr2)); | |
26747 | + __asm__ (MOVLQ " %%db3,%0\n\t":"=r"(dr3)); | |
26748 | + __asm__ (MOVLQ " %%db6,%0\n\t":"=r"(dr6)); | |
26749 | + __asm__ (MOVLQ " %%db7,%0\n\t":"=r"(dr7)); | |
26750 | + | |
26751 | + kdb_printf("dr0 = " kdb_machreg_fmt0 " dr1 = " kdb_machreg_fmt0 | |
26752 | + " dr2 = " kdb_machreg_fmt0 " dr3 = " kdb_machreg_fmt0 "\n", | |
26753 | + dr0, dr1, dr2, dr3); | |
26754 | + kdb_printf("dr6 = " kdb_machreg_fmt0 " ", dr6); | |
26755 | + dbnr = dr6 & DR6_DR_MASK; | |
26756 | + if (dbnr) { | |
26757 | + int nr; | |
26758 | + switch(dbnr) { | |
26759 | + case 1: | |
26760 | + nr = 0; break; | |
26761 | + case 2: | |
26762 | + nr = 1; break; | |
26763 | + case 4: | |
26764 | + nr = 2; break; | |
26765 | + default: | |
26766 | + nr = 3; break; | |
26767 | + } | |
26768 | + kdb_printf("debug register hit = %d", nr); | |
26769 | + } else if (dr6 & DR_STEP) { | |
26770 | + kdb_printf("single step"); | |
26771 | + } else if (dr6 & DR_SWITCH) { | |
26772 | + kdb_printf("task switch"); | |
26773 | + } | |
26774 | + kdb_printf("\n"); | |
26775 | + | |
26776 | + kdb_printf("dr7 = " kdb_machreg_fmt0 "\n", dr7); | |
26777 | + set = DR7_L0(dr7) || DR7_G0(dr7); | |
26778 | + display_dr_status(0, set, DR7_L0(dr7), DR7_LEN0(dr7), DR7_RW0(dr7)); | |
26779 | + set = DR7_L1(dr7) || DR7_G1(dr7); | |
26780 | + display_dr_status(1, set, DR7_L1(dr7), DR7_LEN1(dr7), DR7_RW1(dr7)); | |
26781 | + set = DR7_L2(dr7) || DR7_G2(dr7); | |
26782 | + display_dr_status(2, set, DR7_L2(dr7), DR7_LEN2(dr7), DR7_RW2(dr7)); | |
26783 | + set = DR7_L3(dr7) || DR7_G3(dr7); | |
26784 | + display_dr_status(3, set, DR7_L3(dr7), DR7_LEN3(dr7), DR7_RW3(dr7)); | |
26785 | +} | |
26786 | + | |
26787 | +static char *set_eflags[] = { | |
26788 | + "carry", NULL, "parity", NULL, "adjust", NULL, "zero", "sign", | |
26789 | + "trace", "intr-on", "dir", "overflow", NULL, NULL, "nestedtask", NULL, | |
26790 | + "resume", "vm", "align", "vif", "vip", "id"}; | |
26791 | + | |
26792 | +static void display_eflags(unsigned long ef) | |
26793 | +{ | |
26794 | + int i, iopl; | |
26795 | + kdb_printf("eflags = " kdb_machreg_fmt0 " ", ef); | |
26796 | + for (i = 0; i < ARRAY_SIZE(set_eflags); i++) { | |
26797 | + if (test_bit(i, &ef) && set_eflags[i]) | |
26798 | + kdb_printf("%s ", set_eflags[i]); | |
26799 | + } | |
26800 | + | |
26801 | + iopl = (ef & 0x00003000) >> 12; | |
26802 | + kdb_printf("iopl=%d\n", iopl); | |
26803 | + return; | |
26804 | +} | |
26805 | + | |
26806 | +static void display_tss(struct tss_struct *t) | |
26807 | +{ | |
26808 | +#ifdef CONFIG_X86_64 | |
26809 | + int i; | |
26810 | + kdb_printf(" sp0 = 0x%016Lx, sp1 = 0x%016Lx\n", | |
26811 | + t->x86_tss.sp0, t->x86_tss.sp1); | |
26812 | + kdb_printf(" sp2 = 0x%016Lx\n", t->x86_tss.sp2); | |
26813 | + for (i = 0; i < ARRAY_SIZE(t->x86_tss.ist); ++i) | |
26814 | + kdb_printf(" ist[%d] = 0x%016Lx\n", | |
26815 | + i, t->x86_tss.ist[i]); | |
26816 | + kdb_printf(" iomap = 0x%04x\n", t->x86_tss.io_bitmap_base); | |
26817 | +#else /* !CONFIG_X86_64 */ | |
26818 | + kdb_printf(" cs = %04x, ip = " kdb_machreg_fmt0 "\n", | |
26819 | + t->x86_tss.es, t->x86_tss.ip); | |
26820 | + kdb_printf(" ss = %04x, sp = " kdb_machreg_fmt0 "\n", | |
26821 | + t->x86_tss.ss, t->x86_tss.sp); | |
26822 | + kdb_printf(" ss0 = %04x, sp0 = " kdb_machreg_fmt0 "\n", | |
26823 | + t->x86_tss.ss0, t->x86_tss.sp0); | |
26824 | + kdb_printf(" ss1 = %04x, sp1 = " kdb_machreg_fmt0 "\n", | |
26825 | + t->x86_tss.ss1, t->x86_tss.sp1); | |
26826 | + kdb_printf(" ss2 = %04x, sp2 = " kdb_machreg_fmt0 "\n", | |
26827 | + t->x86_tss.ss2, t->x86_tss.sp2); | |
26828 | + kdb_printf(" ldt = %04x, cr3 = " kdb_machreg_fmt0 "\n", | |
26829 | + t->x86_tss.ldt, t->x86_tss.__cr3); | |
26830 | + kdb_printf(" ds = %04x, es = %04x fs = %04x gs = %04x\n", | |
26831 | + t->x86_tss.ds, t->x86_tss.es, t->x86_tss.fs, t->x86_tss.gs); | |
26832 | + kdb_printf(" ax = " kdb_machreg_fmt0 ", bx = " kdb_machreg_fmt0 | |
26833 | + " cx = " kdb_machreg_fmt0 " dx = " kdb_machreg_fmt0 "\n", | |
26834 | + t->x86_tss.ax, t->x86_tss.bx, t->x86_tss.cx, t->x86_tss.dx); | |
26835 | + kdb_printf(" si = " kdb_machreg_fmt0 ", di = " kdb_machreg_fmt0 | |
26836 | + " bp = " kdb_machreg_fmt0 "\n", | |
26837 | + t->x86_tss.si, t->x86_tss.di, t->x86_tss.bp); | |
26838 | + kdb_printf(" trace = %d, iomap = 0x%04x\n", t->x86_tss.trace, t->x86_tss.io_bitmap_base); | |
26839 | +#endif /* CONFIG_X86_64 */ | |
26840 | +} | |
26841 | + | |
26842 | +static char *gate_desc_types[] = { | |
26843 | +#ifdef CONFIG_X86_64 | |
26844 | + "reserved-0", "reserved-1", "ldt", "reserved-3", | |
26845 | + "reserved-4", "reserved-5", "reserved-6", "reserved-7", | |
26846 | + "reserved-8", "tss-avlb", "reserved-10", "tss-busy", | |
26847 | + "callgate", "reserved-13", "intgate", "trapgate", | |
26848 | +#else /* CONFIG_X86_64 */ | |
26849 | + "reserved-0", "tss16-avlb", "ldt", "tss16-busy", | |
26850 | + "callgate16", "taskgate", "intgate16", "trapgate16", | |
26851 | + "reserved-8", "tss-avlb", "reserved-10", "tss-busy", | |
26852 | + "callgate", "reserved-13", "intgate", "trapgate", | |
26853 | +#endif /* CONFIG_X86_64 */ | |
26854 | +}; | |
26855 | + | |
26856 | +static void | |
26857 | +display_gate_desc(kdb_gate_desc_t *d) | |
26858 | +{ | |
26859 | + kdb_printf("%-11s ", gate_desc_types[d->type]); | |
26860 | + | |
26861 | + switch(d->type) { | |
26862 | + case KDB_SYS_DESC_TYPE_LDT: | |
26863 | + kdb_printf("base="); | |
26864 | + kdb_symbol_print(kdb_seg_desc_base((kdb_desc_t *)d), NULL, | |
26865 | + KDB_SP_DEFAULT); | |
26866 | + kdb_printf(" limit=" kdb_machreg_fmt " dpl=%d\n", | |
26867 | + KDB_SEG_DESC_LIMIT((kdb_desc_t *)d), d->dpl); | |
26868 | + break; | |
26869 | + case KDB_SYS_DESC_TYPE_TSS: | |
26870 | + case KDB_SYS_DESC_TYPE_TSS16: | |
26871 | + case KDB_SYS_DESC_TYPE_TSSB: | |
26872 | + case KDB_SYS_DESC_TYPE_TSSB16: | |
26873 | + { | |
26874 | + struct tss_struct *tss = | |
26875 | + (struct tss_struct *) | |
26876 | + kdb_seg_desc_base((kdb_desc_t *)d); | |
26877 | + kdb_printf("base="); | |
26878 | + kdb_symbol_print((unsigned long)tss, NULL, KDB_SP_DEFAULT); | |
26879 | + kdb_printf(" limit=" kdb_machreg_fmt " dpl=%d\n", | |
26880 | + KDB_SEG_DESC_LIMIT((kdb_desc_t *)d), d->dpl); | |
26881 | + display_tss(tss); | |
26882 | + break; | |
26883 | + } | |
26884 | + case KDB_SYS_DESC_TYPE_CALLG16: | |
26885 | + kdb_printf("segment=0x%4.4x off=", d->segment); | |
26886 | + kdb_symbol_print(KDB_SYS_DESC_OFFSET(d), NULL, KDB_SP_DEFAULT); | |
26887 | + kdb_printf(" dpl=%d wc=%d\n", | |
26888 | + d->dpl, KDB_SYS_DESC_CALLG_COUNT(d)); | |
26889 | + break; | |
26890 | + case KDB_SYS_DESC_TYPE_CALLG: | |
26891 | + kdb_printf("segment=0x%4.4x off=", d->segment); | |
26892 | + kdb_symbol_print(KDB_SYS_DESC_OFFSET(d), NULL, KDB_SP_DEFAULT); | |
26893 | + kdb_printf(" dpl=%d\n", d->dpl); | |
26894 | + break; | |
26895 | + default: | |
26896 | + kdb_printf("segment=0x%4.4x off=", d->segment); | |
26897 | + if (KDB_SYS_DESC_OFFSET(d)) | |
26898 | + kdb_symbol_print(KDB_SYS_DESC_OFFSET(d), NULL, | |
26899 | + KDB_SP_DEFAULT); | |
26900 | + else | |
26901 | + kdb_printf(kdb_machreg_fmt0, KDB_SYS_DESC_OFFSET(d)); | |
26902 | + kdb_printf(" dpl=%d", d->dpl); | |
26903 | +#ifdef CONFIG_X86_64 | |
26904 | + if (d->ist) | |
26905 | + kdb_printf(" ist=%d", d->ist); | |
26906 | +#endif /* CONFIG_X86_64 */ | |
26907 | + kdb_printf("\n"); | |
26908 | + break; | |
26909 | + } | |
26910 | +} | |
26911 | + | |
26912 | +static void | |
26913 | +display_seg_desc(kdb_desc_t *d) | |
26914 | +{ | |
26915 | + unsigned char type = d->type; | |
26916 | + | |
26917 | + if (type & KDB_SEG_DESC_TYPE_CODE) { | |
26918 | + kdb_printf("%-11s base=" kdb_machreg_fmt0 " limit=" | |
26919 | + kdb_machreg_fmt " dpl=%d %c%c%c %s %s %s \n", | |
26920 | + "code", | |
26921 | + kdb_seg_desc_base(d), KDB_SEG_DESC_LIMIT(d), | |
26922 | + d->dpl, | |
26923 | + (type & KDB_SEG_DESC_TYPE_CODE_R)?'r':'-', | |
26924 | + '-', 'x', | |
26925 | +#ifdef CONFIG_X86_64 | |
26926 | + d->l ? "64b" : d->d ? "32b" : "16b", | |
26927 | +#else /* !CONFIG_X86_64 */ | |
26928 | + d->d ? "32b" : "16b", | |
26929 | +#endif /* CONFIG_X86_64 */ | |
26930 | + (type & KDB_SEG_DESC_TYPE_A)?"ac":"", | |
26931 | + (type & KDB_SEG_DESC_TYPE_CODE_C)?"conf":""); | |
26932 | + } else { | |
26933 | + kdb_printf("%-11s base=" kdb_machreg_fmt0 " limit=" | |
26934 | + kdb_machreg_fmt " dpl=%d %c%c%c %s %s %s \n", | |
26935 | + "data", | |
26936 | + kdb_seg_desc_base(d), KDB_SEG_DESC_LIMIT(d), | |
26937 | + d->dpl, | |
26938 | + 'r', | |
26939 | + (type & KDB_SEG_DESC_TYPE_DATA_W)?'w':'-', | |
26940 | + '-', | |
26941 | + d->d ? "32b" : "16b", | |
26942 | + (type & KDB_SEG_DESC_TYPE_A)?"ac":"", | |
26943 | + (type & KDB_SEG_DESC_TYPE_DATA_D)?"down":""); | |
26944 | + } | |
26945 | +} | |
26946 | + | |
26947 | +static int | |
26948 | +kdb_parse_two_numbers(int argc, const char **argv, int *sel, int *count, | |
26949 | + int *last_sel, int *last_count) | |
26950 | +{ | |
26951 | + int diag; | |
26952 | + | |
26953 | + if (argc > 2) | |
26954 | + return KDB_ARGCOUNT; | |
26955 | + | |
26956 | + kdbgetintenv("MDCOUNT", count); | |
26957 | + | |
26958 | + if (argc == 0) { | |
26959 | + *sel = *last_sel; | |
26960 | + if (*last_count) | |
26961 | + *count = *last_count; | |
26962 | + } else { | |
26963 | + unsigned long val; | |
26964 | + | |
26965 | + if (argc >= 1) { | |
26966 | + diag = kdbgetularg(argv[1], &val); | |
26967 | + if (diag) | |
26968 | + return diag; | |
26969 | + *sel = val; | |
26970 | + } | |
26971 | + if (argc >= 2) { | |
26972 | + diag = kdbgetularg(argv[2], &val); | |
26973 | + if (diag) | |
26974 | + return diag; | |
26975 | + *count = (int) val; | |
26976 | + *last_count = (int) val; | |
26977 | + } else if (*last_count) { | |
26978 | + *count = *last_count; | |
26979 | + } | |
26980 | + } | |
26981 | + return 0; | |
26982 | +} | |
26983 | + | |
26984 | +/* | |
26985 | + * kdb_gdt | |
26986 | + * | |
26987 | + * This function implements the 'gdt' command. | |
26988 | + * | |
26989 | + * gdt [<selector> [<line count>]] | |
26990 | + * | |
26991 | + * Inputs: | |
26992 | + * argc argument count | |
26993 | + * argv argument vector | |
26994 | + * Outputs: | |
26995 | + * None. | |
26996 | + * Returns: | |
26997 | + * zero for success, a kdb diagnostic if error | |
26998 | + * Locking: | |
26999 | + * none. | |
27000 | + * Remarks: | |
27001 | + */ | |
27002 | +static int | |
27003 | +kdb_gdt(int argc, const char **argv) | |
27004 | +{ | |
27005 | + int sel = 0; | |
27006 | + struct desc_ptr gdtr; | |
27007 | + int diag, count = 8; | |
27008 | + kdb_desc_t *gdt; | |
27009 | + unsigned int max_sel; | |
27010 | + static int last_sel = 0, last_count = 0; | |
27011 | + | |
27012 | + diag = kdb_parse_two_numbers(argc, argv, &sel, &count, | |
27013 | + &last_sel, &last_count); | |
27014 | + if (diag) | |
27015 | + return diag; | |
27016 | + | |
27017 | + __asm__ __volatile__ ("sgdt %0\n\t" : "=m"(gdtr)); | |
27018 | + gdt = (kdb_desc_t *) gdtr.address; | |
27019 | + | |
27020 | + max_sel = (gdtr.size + 1) / sizeof(kdb_desc_t); | |
27021 | + if (sel >= max_sel) { | |
27022 | + kdb_printf("Maximum selector (%d) reached\n", max_sel); | |
27023 | + return 0; | |
27024 | + } | |
27025 | + | |
27026 | + if (sel + count > max_sel) | |
27027 | + count = max_sel - sel; | |
27028 | + | |
27029 | + while (count--) { | |
27030 | + kdb_desc_t *d = &gdt[sel]; | |
27031 | + kdb_printf("0x%4.4x ", sel++); | |
27032 | + | |
27033 | + if (!d->p) { | |
27034 | + kdb_printf("not present\n"); | |
27035 | + continue; | |
27036 | + } | |
27037 | + if (d->s) { | |
27038 | + display_seg_desc(d); | |
27039 | + } else { | |
27040 | + display_gate_desc((kdb_gate_desc_t *)d); | |
27041 | + if (KDB_X86_64 && count) { | |
27042 | + ++sel; /* this descriptor occupies two slots */ | |
27043 | + --count; | |
27044 | + } | |
27045 | + } | |
27046 | + } | |
27047 | + | |
27048 | + last_sel = sel; | |
27049 | + return 0; | |
27050 | +} | |
27051 | + | |
27052 | +/* | |
27053 | + * kdb_ldt | |
27054 | + * | |
27055 | + * This function implements the 'ldt' command. | |
27056 | + * | |
27057 | + * ldt [<selector> [<line count>]] | |
27058 | + * | |
27059 | + * Inputs: | |
27060 | + * argc argument count | |
27061 | + * argv argument vector | |
27062 | + * Outputs: | |
27063 | + * None. | |
27064 | + * Returns: | |
27065 | + * zero for success, a kdb diagnostic if error | |
27066 | + * Locking: | |
27067 | + * none. | |
27068 | + * Remarks: | |
27069 | + */ | |
27070 | +static int | |
27071 | +kdb_ldt(int argc, const char **argv) | |
27072 | +{ | |
27073 | + int sel = 0; | |
27074 | + struct desc_ptr gdtr; | |
27075 | + unsigned long ldtr = 0; | |
27076 | + int diag, count = 8; | |
27077 | + kdb_desc_t *ldt, *ldt_desc; | |
27078 | + unsigned int max_sel; | |
27079 | + static int last_sel = 0, last_count = 0; | |
27080 | + | |
27081 | + diag = kdb_parse_two_numbers(argc, argv, &sel, &count, | |
27082 | + &last_sel, &last_count); | |
27083 | + if (diag) | |
27084 | + return diag; | |
27085 | + | |
27086 | + if (strcmp(argv[0], "ldtp") == 0) { | |
27087 | + kdb_printf("pid=%d, process=%s\n", | |
27088 | + kdb_current_task->pid, kdb_current_task->comm); | |
27089 | + if (!kdb_current_task->mm || | |
27090 | + !kdb_current_task->mm->context.ldt) { | |
27091 | + kdb_printf("no special LDT for this process\n"); | |
27092 | + return 0; | |
27093 | + } | |
27094 | + ldt = kdb_current_task->mm->context.ldt; | |
27095 | + max_sel = kdb_current_task->mm->context.size; | |
27096 | + } else { | |
27097 | + | |
27098 | + /* sldt gives the GDT selector for the segment containing LDT */ | |
27099 | + __asm__ __volatile__ ("sgdt %0\n\t" : "=m"(gdtr)); | |
27100 | + __asm__ __volatile__ ("sldt %0\n\t" : "=m"(ldtr)); | |
27101 | + ldtr &= 0xfff8; /* extract the index */ | |
27102 | + | |
27103 | + if (ldtr > gdtr.size+1) { | |
27104 | + kdb_printf("invalid ldtr\n"); | |
27105 | + return 0; | |
27106 | + } | |
27107 | + | |
27108 | + ldt_desc = (kdb_desc_t *)(gdtr.address + ldtr); | |
27109 | + ldt = (kdb_desc_t *)kdb_seg_desc_base(ldt_desc); | |
27110 | + max_sel = (KDB_SEG_DESC_LIMIT(ldt_desc)+1) / sizeof(kdb_desc_t); | |
27111 | + } | |
27112 | + | |
27113 | + if (sel >= max_sel) { | |
27114 | + kdb_printf("Maximum selector (%d) reached\n", max_sel); | |
27115 | + return 0; | |
27116 | + } | |
27117 | + | |
27118 | + if (sel + count > max_sel) | |
27119 | + count = max_sel - sel; | |
27120 | + | |
27121 | + while (count--) { | |
27122 | + kdb_desc_t *d = &ldt[sel]; | |
27123 | + kdb_printf("0x%4.4x ", sel++); | |
27124 | + | |
27125 | + if (!d->p) { | |
27126 | + kdb_printf("not present\n"); | |
27127 | + continue; | |
27128 | + } | |
27129 | + if (d->s) { | |
27130 | + display_seg_desc(d); | |
27131 | + } else { | |
27132 | + display_gate_desc((kdb_gate_desc_t *)d); | |
27133 | + if (KDB_X86_64 && count) { | |
27134 | + ++sel; /* this descriptor occupies two slots */ | |
27135 | + --count; | |
27136 | + } | |
27137 | + } | |
27138 | + } | |
27139 | + | |
27140 | + last_sel = sel; | |
27141 | + return 0; | |
27142 | +} | |
27143 | + | |
27144 | +/* | |
27145 | + * kdb_idt | |
27146 | + * | |
27147 | + * This function implements the 'idt' command. | |
27148 | + * | |
27149 | + * idt [<vector> [<line count>]] | |
27150 | + * | |
27151 | + * Inputs: | |
27152 | + * argc argument count | |
27153 | + * argv argument vector | |
27154 | + * Outputs: | |
27155 | + * None. | |
27156 | + * Returns: | |
27157 | + * zero for success, a kdb diagnostic if error | |
27158 | + * Locking: | |
27159 | + * none. | |
27160 | + * Remarks: | |
27161 | + */ | |
27162 | +static int | |
27163 | +kdb_idt(int argc, const char **argv) | |
27164 | +{ | |
27165 | + int vec = 0; | |
27166 | + struct desc_ptr idtr; | |
27167 | + int diag, count = 8; | |
27168 | + kdb_gate_desc_t *idt; | |
27169 | + unsigned int max_entries; | |
27170 | + static int last_vec = 0, last_count = 0; | |
27171 | + | |
27172 | + diag = kdb_parse_two_numbers(argc, argv, &vec, &count, | |
27173 | + &last_vec, &last_count); | |
27174 | + if (diag) | |
27175 | + return diag; | |
27176 | + | |
27177 | + __asm__ __volatile__ ("sidt %0\n\t" : "=m"(idtr)); | |
27178 | + idt = (kdb_gate_desc_t *)idtr.address; | |
27179 | + | |
27180 | + max_entries = (idtr.size+1) / sizeof(kdb_gate_desc_t); | |
27181 | + if (vec >= max_entries) { | |
27182 | + kdb_printf("Maximum vector (%d) reached\n", max_entries); | |
27183 | + return 0; | |
27184 | + } | |
27185 | + | |
27186 | + if (vec + count > max_entries) | |
27187 | + count = max_entries - vec; | |
27188 | + | |
27189 | + while (count--) { | |
27190 | + kdb_gate_desc_t *d = &idt[vec]; | |
27191 | + kdb_printf("0x%4.4x ", vec++); | |
27192 | + if (!d->p) { | |
27193 | + kdb_printf("not present\n"); | |
27194 | + continue; | |
27195 | + } | |
27196 | +#ifndef CONFIG_X86_64 | |
27197 | + if (d->s) { | |
27198 | + kdb_printf("invalid\n"); | |
27199 | + continue; | |
27200 | + } | |
27201 | +#endif /* CONFIG_X86_64 */ | |
27202 | + display_gate_desc(d); | |
27203 | + } | |
27204 | + | |
27205 | + last_vec = vec; | |
27206 | + | |
27207 | + return 0; | |
27208 | +} | |
27209 | + | |
27210 | +#if 0 | |
27211 | +static int | |
27212 | +get_pagetables(unsigned long addr, pgd_t **pgdir, pmd_t **pgmiddle, pte_t **pte) | |
27213 | +{ | |
27214 | + pgd_t *d; | |
27215 | + pmd_t *m; | |
27216 | + pte_t *t; | |
27217 | + | |
27218 | + if (addr > PAGE_OFFSET) { | |
27219 | + d = pgd_offset_k(addr); | |
27220 | + } else { | |
27221 | + kdb_printf("pid=%d, process=%s\n", kdb_current_task->pid, kdb_current_task->comm); | |
27222 | + d = pgd_offset(kdb_current_task->mm, addr); | |
27223 | + } | |
27224 | + | |
27225 | + if (pgd_none(*d) || pgd_bad(*d)) { | |
27226 | + *pgdir = NULL; | |
27227 | + *pgmiddle = NULL; | |
27228 | + *pte = NULL; | |
27229 | + return 0; | |
27230 | + } else { | |
27231 | + *pgdir = d; | |
27232 | + } | |
27233 | + | |
27234 | + /* if _PAGE_PSE is set, pgdir points directly to the page. */ | |
27235 | + if (pgd_val(*d) & _PAGE_PSE) { | |
27236 | + *pgmiddle = NULL; | |
27237 | + *pte = NULL; | |
27238 | + return 0; | |
27239 | + } | |
27240 | + | |
27241 | + m = pmd_offset(d, addr); | |
27242 | + if (pmd_none(*m) || pmd_bad(*m)) { | |
27243 | + *pgmiddle = NULL; | |
27244 | + *pte = NULL; | |
27245 | + return 0; | |
27246 | + } else { | |
27247 | + *pgmiddle = m; | |
27248 | + } | |
27249 | + | |
27250 | + t = pte_offset(m, addr); | |
27251 | + if (pte_none(*t)) { | |
27252 | + *pte = NULL; | |
27253 | + return 0; | |
27254 | + } else { | |
27255 | + *pte = t; | |
27256 | + } | |
27257 | + kdb_printf("\naddr=%08lx, pgd=%08lx, pmd=%08lx, pte=%08lx\n", | |
27258 | + addr, | |
27259 | + (unsigned long) pgd_val(*d), | |
27260 | + (unsigned long) pmd_val(*m), | |
27261 | + (unsigned long) pte_val(*t)); | |
27262 | + return 0; | |
27263 | +} | |
27264 | +#endif | |
27265 | + | |
27266 | +#define FORMAT_PGDIR(entry) \ | |
27267 | + kdb_printf("frame=%05lx %c %s %c %c %c %s %c %s %s \n",\ | |
27268 | + (entry >> PAGE_SHIFT), \ | |
27269 | + (entry & _PAGE_PRESENT)?'p':'n', \ | |
27270 | + (entry & _PAGE_RW)?"rw":"ro", \ | |
27271 | + (entry & _PAGE_USER)?'u':'s', \ | |
27272 | + (entry & _PAGE_ACCESSED)?'a':' ', \ | |
27273 | + ' ', \ | |
27274 | + (entry & _PAGE_PSE)?"4M":"4K", \ | |
27275 | + (entry & _PAGE_GLOBAL)?'g':' ', \ | |
27276 | + (entry & _PAGE_PWT)?"wt":"wb", \ | |
27277 | + (entry & _PAGE_PCD)?"cd":" "); | |
27278 | + | |
27279 | +#define FORMAT_PTE(p, entry) \ | |
27280 | + kdb_printf("frame=%05lx %c%c%c %c %c %c %s %c %s %s\n", \ | |
27281 | + (entry >> PAGE_SHIFT), \ | |
27282 | + (pte_read(p))? 'r':'-', \ | |
27283 | + (pte_write(p))? 'w':'-', \ | |
27284 | + (pte_exec(p))? 'x':'-', \ | |
27285 | + (pte_dirty(p))? 'd':' ', \ | |
27286 | + (pte_young(p))? 'a':' ', \ | |
27287 | + (entry & _PAGE_USER)? 'u':'s', \ | |
27288 | + " ", \ | |
27289 | + (entry & _PAGE_GLOBAL)? 'g':' ', \ | |
27290 | + (entry & _PAGE_PWT)? "wt":"wb", \ | |
27291 | + (entry & _PAGE_PCD)? "cd":" "); | |
27292 | +#if 0 | |
27293 | +static int | |
27294 | +display_pgdir(unsigned long addr, pgd_t *pgdir, int count) | |
27295 | +{ | |
27296 | + unsigned long entry; | |
27297 | + int i; | |
27298 | + int index = pgdir - ((pgd_t *)(((unsigned long)pgdir) & PAGE_MASK)); | |
27299 | + | |
27300 | + count = min(count, PTRS_PER_PGD - index); | |
27301 | + addr &= ~(PGDIR_SIZE-1); | |
27302 | + | |
27303 | + for (i = 0; i < count; i++, pgdir++) { | |
27304 | + entry = pgd_val(*pgdir); | |
27305 | + kdb_printf("pgd: addr=%08lx ", addr); | |
27306 | + if (pgd_none(*pgdir)) { | |
27307 | + kdb_printf("pgdir not present\n"); | |
27308 | + } else { | |
27309 | + FORMAT_PGDIR(entry); | |
27310 | + } | |
27311 | + addr += PGDIR_SIZE; | |
27312 | + } | |
27313 | + return i; | |
27314 | +} | |
27315 | +#endif | |
27316 | + | |
27317 | +#if 0 /* for now, let's not print pgmiddle. */ | |
27318 | +static int | |
27319 | +display_pgmiddle(unsigned long addr, pmd_t *pgmiddle, int count) | |
27320 | +{ | |
27321 | + unsigned long entry; | |
27322 | + int i; | |
27323 | + int index = pgmiddle - ((pmd_t *)(((unsigned long)pgmiddle) & PAGE_MASK)); | |
27324 | + | |
27325 | + count = min(count, PTRS_PER_PMD - index); | |
27326 | + addr &= ~(PMD_SIZE-1); | |
27327 | + | |
27328 | + for (i = 0; i < count; i++, pgmiddle++) { | |
27329 | + entry = pmd_val(*pgmiddle); | |
27330 | + kdb_printf("pmd: addr=%08lx ", addr); | |
27331 | + if (pmd_none(*pgmiddle)) { | |
27332 | + kdb_printf("pgmiddle not present\n"); | |
27333 | + } else { | |
27334 | + FORMAT_PGDIR(entry); | |
27335 | + } | |
27336 | + addr += PMD_SIZE; | |
27337 | + } | |
27338 | + return i; | |
27339 | +} | |
27340 | +#endif | |
27341 | + | |
27342 | +#if 0 | |
27343 | +static int | |
27344 | +display_pte(unsigned long addr, pte_t *pte, int count) | |
27345 | +{ | |
27346 | + unsigned long entry; | |
27347 | + int i; | |
27348 | + int index = pte - ((pte_t *)(((unsigned long)pte) & PAGE_MASK)); | |
27349 | + | |
27350 | + count = min(count, PTRS_PER_PTE - index); | |
27351 | + addr &= PAGE_MASK; | |
27352 | + | |
27353 | + for (i = 0; i < count; i++, pte++) { | |
27354 | + entry = pte_val(*pte); | |
27355 | + kdb_printf("pte: addr=%08lx ", addr); | |
27356 | + if (pte_none(*pte)) { | |
27357 | + kdb_printf("pte not present\n"); | |
27358 | + } else if (!pte_present(*pte)) { | |
27359 | + kdb_printf("page swapped out. swp_offset=%08lx ", SWP_OFFSET(pte_to_swp_entry(*pte))); | |
27360 | + kdb_printf("swp_type=%8lx", SWP_TYPE(pte_to_swp_entry(*pte))); | |
27361 | + } else { | |
27362 | + FORMAT_PTE(*pte, entry); | |
27363 | + } | |
27364 | + addr += PAGE_SIZE; | |
27365 | + } | |
27366 | + return i; | |
27367 | +} | |
27368 | + | |
27369 | + | |
27370 | +/* | |
27371 | + * kdb_pte | |
27372 | + * | |
27373 | + * This function implements the 'pte' command. | |
27374 | + * | |
27375 | + * pte <addr arg> [<line count>] | |
27376 | + * | |
27377 | + * Inputs: | |
27378 | + * argc argument count | |
27379 | + * argv argument vector | |
27380 | + * Outputs: | |
27381 | + * None. | |
27382 | + * Returns: | |
27383 | + * zero for success, a kdb diagnostic if error | |
27384 | + * Locking: | |
27385 | + * none. | |
27386 | + * Remarks: | |
27387 | + */ | |
27388 | +static int | |
27389 | +kdb_pte(int argc, const char **argv) | |
27390 | +{ | |
27391 | + static unsigned long last_addr = 0, last_count = 0; | |
27392 | + int count = 8; | |
27393 | + unsigned long addr; | |
27394 | + long offset = 0; | |
27395 | + pgd_t *pgdir; | |
27396 | + pmd_t *pgmiddle; | |
27397 | + pte_t *pte; | |
27398 | + | |
27399 | +#ifdef CONFIG_X86_PAE | |
27400 | + kdb_printf("This kernel is compiled with PAE support."); | |
27401 | + return KDB_NOTIMP; | |
27402 | +#endif | |
27403 | + kdbgetintenv("MDCOUNT", &count); | |
27404 | + | |
27405 | + if (argc == 0) { | |
27406 | + if (last_addr == 0) | |
27407 | + return KDB_ARGCOUNT; | |
27408 | + addr = last_addr; | |
27409 | + if (last_count) | |
27410 | + count = last_count; | |
27411 | + } else { | |
27412 | + kdb_machreg_t val; | |
27413 | + int diag, nextarg = 1; | |
27414 | + diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL); | |
27415 | + if (diag) | |
27416 | + return diag; | |
27417 | + if (argc > nextarg+1) | |
27418 | + return KDB_ARGCOUNT; | |
27419 | + | |
27420 | + if (argc >= nextarg) { | |
27421 | + diag = kdbgetularg(argv[nextarg], &val); | |
27422 | + if (!diag) { | |
27423 | + count = (int) val; | |
27424 | + last_count = count; | |
27425 | + } else if (last_count) { | |
27426 | + count = last_count; | |
27427 | + } | |
27428 | + } | |
27429 | + } | |
27430 | + | |
27431 | + /* | |
27432 | + * round off the addr to a page boundary. | |
27433 | + */ | |
27434 | + addr &= PAGE_MASK; | |
27435 | + | |
27436 | + get_pagetables(addr, &pgdir, &pgmiddle, &pte); | |
27437 | + | |
27438 | + if (pgdir) | |
27439 | + display_pgdir(addr, pgdir, 1); | |
27440 | +#if 0 /* for now, let's not print pgmiddle. */ | |
27441 | + if (pgmiddle) | |
27442 | + display_pgmiddle(addr, pgmiddle, 1); | |
27443 | +#endif | |
27444 | + if (pte) { | |
27445 | + int displayed; | |
27446 | + displayed = display_pte(addr, pte, count); | |
27447 | + addr += (displayed << PAGE_SHIFT); | |
27448 | + } | |
27449 | + last_addr = addr; | |
27450 | + return 0; | |
27451 | +} | |
27452 | +#else | |
27453 | +/* | |
27454 | + * Todo - In 2.5 the pte_offset macro in asm/pgtable.h seems to be | |
27455 | + * renamed to pte_offset_kernel. | |
27456 | + */ | |
27457 | +static int | |
27458 | +kdb_pte(int argc, const char **argv) | |
27459 | +{ | |
27460 | + kdb_printf("not supported."); | |
27461 | + return KDB_NOTIMP; | |
27462 | +} | |
27463 | +#endif | |
27464 | + | |
27465 | +/* | |
27466 | + * kdb_rdv | |
27467 | + * | |
27468 | + * This function implements the 'rdv' command. | |
27469 | + * It displays all registers of the current processor | |
27470 | + * included control registers in verbose mode. | |
27471 | + * | |
27472 | + * Inputs: | |
27473 | + * argc argument count | |
27474 | + * argv argument vector | |
27475 | + * Outputs: | |
27476 | + * None. | |
27477 | + * Returns: | |
27478 | + * zero for success, a kdb diagnostic if error | |
27479 | + * Locking: | |
27480 | + * none. | |
27481 | + * Remarks: | |
27482 | + * This should have been an option to rd command say "rd v", | |
27483 | + * but it is here as it is a non-essential x86-only command, | |
27484 | + * that need not clutter arch/i386/kdb/kdbasupport.c. | |
27485 | + */ | |
27486 | +static int | |
27487 | +kdb_rdv(int argc, const char **argv) | |
27488 | +{ | |
27489 | + struct pt_regs *regs = get_irq_regs(); | |
27490 | + kdba_dumpregs(regs, NULL, NULL); | |
27491 | + kdb_printf("\n"); | |
27492 | + display_eflags(regs->flags); | |
27493 | + kdb_printf("\n"); | |
27494 | + display_gdtr(); | |
27495 | + display_idtr(); | |
27496 | + display_ldtr(); | |
27497 | + kdb_printf("\n"); | |
27498 | + display_cr0(); | |
27499 | + display_cr3(); | |
27500 | + display_cr4(); | |
27501 | + display_cr8(); | |
27502 | + kdb_printf("\n"); | |
27503 | + display_dr(); | |
27504 | + return 0; | |
27505 | +} | |
27506 | + | |
27507 | +static int | |
27508 | +kdb_rdmsr(int argc, const char **argv) | |
27509 | +{ | |
27510 | + unsigned long addr; | |
27511 | + uint32_t l, h; | |
27512 | + int diag; | |
27513 | + struct cpuinfo_x86 *c = &cpu_data(smp_processor_id()); | |
27514 | + | |
27515 | + if (argc != 1) | |
27516 | + return KDB_ARGCOUNT; | |
27517 | + | |
27518 | + if ((diag = kdbgetularg(argv[1], &addr))) | |
27519 | + return diag; | |
27520 | + | |
27521 | + if (!cpu_has(c, X86_FEATURE_MSR)) | |
27522 | + return KDB_NOTIMP; | |
27523 | + | |
27524 | + kdb_printf("msr(0x%lx) = ", addr); | |
27525 | + if ((diag = rdmsr_safe(addr, &l, &h))) { | |
27526 | + kdb_printf("error %d\n", diag); | |
27527 | + return KDB_BADINT; | |
27528 | + } else { | |
27529 | + kdb_printf("0x%08x_%08x\n", h, l); | |
27530 | + } | |
27531 | + | |
27532 | + return 0; | |
27533 | +} | |
27534 | + | |
27535 | +static int | |
27536 | +kdb_wrmsr(int argc, const char **argv) | |
27537 | +{ | |
27538 | + unsigned long addr; | |
27539 | + unsigned long l, h; | |
27540 | + int diag; | |
27541 | + struct cpuinfo_x86 *c = &cpu_data(smp_processor_id()); | |
27542 | + | |
27543 | + if (argc != 3) | |
27544 | + return KDB_ARGCOUNT; | |
27545 | + | |
27546 | + if ((diag = kdbgetularg(argv[1], &addr)) | |
27547 | + || (diag = kdbgetularg(argv[2], &h)) | |
27548 | + || (diag = kdbgetularg(argv[3], &l))) | |
27549 | + return diag; | |
27550 | + | |
27551 | + if (!cpu_has(c, X86_FEATURE_MSR)) | |
27552 | + return KDB_NOTIMP; | |
27553 | + | |
27554 | + if ((diag = wrmsr_safe(addr, l, h))) { | |
27555 | + kdb_printf("error %d\n", diag); | |
27556 | + return KDB_BADINT; | |
27557 | + } | |
27558 | + | |
27559 | + return 0; | |
27560 | +} | |
27561 | + | |
27562 | +static int __init kdbm_x86_init(void) | |
27563 | +{ | |
27564 | + kdb_register("rdv", kdb_rdv, NULL, "Display registers in verbose mode", 0); | |
27565 | + kdb_register_repeat("gdt", kdb_gdt, "<sel> [<count>]", "Display GDT", 0, KDB_REPEAT_NO_ARGS); | |
27566 | + kdb_register_repeat("idt", kdb_idt, "<int> [<count>]", "Display IDT", 0, KDB_REPEAT_NO_ARGS); | |
27567 | + kdb_register_repeat("ldt", kdb_ldt, "<sel> [<count>]", "Display LDT", 0, KDB_REPEAT_NO_ARGS); | |
27568 | + kdb_register_repeat("ptex", kdb_pte, "<addr> [<count>]", "Display pagetables", 0, KDB_REPEAT_NO_ARGS); | |
27569 | + kdb_register_repeat("ldtp", kdb_ldt, "<sel> [<count>]", "Display Process LDT", 0, KDB_REPEAT_NO_ARGS); | |
27570 | + kdb_register("rdmsr", kdb_rdmsr, "<maddr>", "Display Model Specific Register", 0); | |
27571 | + kdb_register("wrmsr", kdb_wrmsr, "<maddr> <h> <l>", "Modify Model Specific Register", 0); | |
27572 | + return 0; | |
27573 | +} | |
27574 | + | |
27575 | +static void __exit kdbm_x86_exit(void) | |
27576 | +{ | |
27577 | + kdb_unregister("rdv"); | |
27578 | + kdb_unregister("gdt"); | |
27579 | + kdb_unregister("ldt"); | |
27580 | + kdb_unregister("idt"); | |
27581 | + kdb_unregister("ptex"); | |
27582 | + kdb_unregister("ldtp"); | |
27583 | + kdb_unregister("rdmsr"); | |
27584 | + kdb_unregister("wrmsr"); | |
27585 | +} | |
27586 | + | |
27587 | +module_init(kdbm_x86_init) | |
27588 | +module_exit(kdbm_x86_exit) | |
27589 | --- /dev/null | |
27590 | +++ b/kdb/modules/lcrash/README | |
27591 | @@ -0,0 +1,3 @@ | |
27592 | + | |
27593 | + These files are copied from lcrash. | |
27594 | + The only changes are flagged with "cpw". | |
27595 | --- /dev/null | |
27596 | +++ b/kdb/modules/lcrash/asm/README | |
27597 | @@ -0,0 +1 @@ | |
27598 | +This kl_types.h is asm-ia64 version. | |
27599 | --- /dev/null | |
27600 | +++ b/kdb/modules/lcrash/asm/kl_dump_ia64.h | |
27601 | @@ -0,0 +1,199 @@ | |
27602 | +/* | |
27603 | + * $Id: kl_dump_ia64.h 1151 2005-02-23 01:09:12Z tjm $ | |
27604 | + * | |
27605 | + * This file is part of libklib. | |
27606 | + * A library which provides access to Linux system kernel dumps. | |
27607 | + * | |
27608 | + * Created by Silicon Graphics, Inc. | |
27609 | + * Contributions by IBM, NEC, and others | |
27610 | + * | |
27611 | + * Copyright (C) 1999 - 2005 Silicon Graphics, Inc. All rights reserved. | |
27612 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
27613 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
27614 | + * | |
27615 | + * This code is free software; you can redistribute it and/or modify | |
27616 | + * it under the terms of the GNU Lesser Public License as published by | |
27617 | + * the Free Software Foundation; either version 2.1 of the License, or | |
27618 | + * (at your option) any later version. See the file COPYING for more | |
27619 | + * information. | |
27620 | + */ | |
27621 | + | |
27622 | +/* This header file holds the architecture specific crash dump header */ | |
27623 | +#ifndef __KL_DUMP_IA64_H | |
27624 | +#define __KL_DUMP_IA64_H | |
27625 | + | |
27626 | +/* definitions */ | |
27627 | +#ifndef KL_NR_CPUS | |
27628 | +# define KL_NR_CPUS 128 /* max number CPUs */ | |
27629 | +#endif | |
27630 | + | |
27631 | +#define KL_DUMP_MAGIC_NUMBER_IA64 0xdeaddeadULL /* magic number */ | |
27632 | +#define KL_DUMP_VERSION_NUMBER_IA64 0x4 /* version number */ | |
27633 | + | |
27634 | + | |
27635 | +/* | |
27636 | + * mkswap.c calls getpagesize() to get the system page size, | |
27637 | + * which is not necessarily the same as the hardware page size. | |
27638 | + * | |
27639 | + * For ia64 the kernel PAGE_SIZE can be configured from 4KB ... 16KB. | |
27640 | + * | |
27641 | + * The physical memory is layed out out in the hardware/minimal pages. | |
27642 | + * This is the size we need to use for dumping physical pages. | |
27643 | + * | |
27644 | + * Note ths hardware/minimal page size being use in; | |
27645 | + * arch/ia64/kernel/efi.c`efi_memmap_walk(): | |
27646 | + * curr.end = curr.start + (md->num_pages << 12); | |
27647 | + * | |
27648 | + * Since the system page size could change between the kernel we boot | |
27649 | + * on the the kernel that cause the core dume we may want to have something | |
27650 | + * more constant like the maximum system page size (See include/asm-ia64/page.h). | |
27651 | + */ | |
27652 | +#define DUMP_MIN_PAGE_SHIFT 12 | |
27653 | +#define DUMP_MIN_PAGE_SIZE (1UL << DUMP_MIN_PAGE_SHIFT) | |
27654 | +#define DUMP_MIN_PAGE_MASK (~(DUMP_MIN_PAGE_SIZE - 1)) | |
27655 | +#define DUMP_MIN_PAGE_ALIGN(addr) (((addr) + DUMP_MIN_PAGE_SIZE - 1) & DUMP_MIN_PAGE_MASK) | |
27656 | + | |
27657 | +#define DUMP_MAX_PAGE_SHIFT 16 | |
27658 | +#define DUMP_MAX_PAGE_SIZE (1UL << DUMP_MAX_PAGE_SHIFT) | |
27659 | +#define DUMP_MAX_PAGE_MASK (~(DUMP_MAX_PAGE_SIZE - 1)) | |
27660 | +#define DUMP_MAX_PAGE_ALIGN(addr) (((addr) + DUMP_MAX_PAGE_SIZE - 1) & DUMP_MAX_PAGE_MASK) | |
27661 | + | |
27662 | +#define DUMP_HEADER_OFFSET DUMP_MAX_PAGE_SIZE | |
27663 | + | |
27664 | +#define DUMP_EF_PAGE_SHIFT DUMP_MIN_PAGE_SHIFT | |
27665 | + | |
27666 | +#define DUMP_PAGE_SHIFT DUMP_MIN_PAGE_SHIFT | |
27667 | +#define DUMP_PAGE_SIZE DUMP_MIN_PAGE_SIZE | |
27668 | +#define DUMP_PAGE_MASK DUMP_MIN_PAGE_MASK | |
27669 | +#define DUMP_PAGE_ALIGN(addr) DUMP_MIN_PAGE_ALIGN(addr) | |
27670 | + | |
27671 | +struct kl_ia64_fpreg { | |
27672 | + union { | |
27673 | + unsigned long bits[2]; | |
27674 | + long double __dummy; /* force 16-byte alignment */ | |
27675 | + } u; | |
27676 | +}; | |
27677 | + | |
27678 | +struct kl_pt_regs_ia64 { | |
27679 | + /* for 2.6 kernels only. This structure was totally different in 2.4 kernels */ | |
27680 | + unsigned long b6; /* scratch */ | |
27681 | + unsigned long b7; /* scratch */ | |
27682 | + | |
27683 | + unsigned long ar_csd; /* used by cmp8xchg16 (scratch) */ | |
27684 | + unsigned long ar_ssd; /* reserved for future use (scratch) */ | |
27685 | + | |
27686 | + unsigned long r8; /* scratch (return value register 0) */ | |
27687 | + unsigned long r9; /* scratch (return value register 1) */ | |
27688 | + unsigned long r10; /* scratch (return value register 2) */ | |
27689 | + unsigned long r11; /* scratch (return value register 3) */ | |
27690 | + | |
27691 | + unsigned long cr_ipsr; /* interrupted task's psr */ | |
27692 | + unsigned long cr_iip; /* interrupted task's instruction pointer */ | |
27693 | + unsigned long cr_ifs; /* interrupted task's function state */ | |
27694 | + | |
27695 | + unsigned long ar_unat; /* interrupted task's NaT register (preserved) */ | |
27696 | + unsigned long ar_pfs; /* prev function state */ | |
27697 | + unsigned long ar_rsc; /* RSE configuration */ | |
27698 | + /* The following two are valid only if cr_ipsr.cpl > 0: */ | |
27699 | + unsigned long ar_rnat; /* RSE NaT */ | |
27700 | + unsigned long ar_bspstore; /* RSE bspstore */ | |
27701 | + | |
27702 | + unsigned long pr; /* 64 predicate registers (1 bit each) */ | |
27703 | + unsigned long b0; /* return pointer (bp) */ | |
27704 | + unsigned long loadrs; /* size of dirty partition << 16 */ | |
27705 | + | |
27706 | + unsigned long r1; /* the gp pointer */ | |
27707 | + unsigned long r12; /* interrupted task's memory stack pointer */ | |
27708 | + unsigned long r13; /* thread pointer */ | |
27709 | + | |
27710 | + unsigned long ar_fpsr; /* floating point status (preserved) */ | |
27711 | + unsigned long r15; /* scratch */ | |
27712 | + | |
27713 | + /* The remaining registers are NOT saved for system calls. */ | |
27714 | + | |
27715 | + unsigned long r14; /* scratch */ | |
27716 | + unsigned long r2; /* scratch */ | |
27717 | + unsigned long r3; /* scratch */ | |
27718 | + | |
27719 | + /* The following registers are saved by SAVE_REST: */ | |
27720 | + unsigned long r16; /* scratch */ | |
27721 | + unsigned long r17; /* scratch */ | |
27722 | + unsigned long r18; /* scratch */ | |
27723 | + unsigned long r19; /* scratch */ | |
27724 | + unsigned long r20; /* scratch */ | |
27725 | + unsigned long r21; /* scratch */ | |
27726 | + unsigned long r22; /* scratch */ | |
27727 | + unsigned long r23; /* scratch */ | |
27728 | + unsigned long r24; /* scratch */ | |
27729 | + unsigned long r25; /* scratch */ | |
27730 | + unsigned long r26; /* scratch */ | |
27731 | + unsigned long r27; /* scratch */ | |
27732 | + unsigned long r28; /* scratch */ | |
27733 | + unsigned long r29; /* scratch */ | |
27734 | + unsigned long r30; /* scratch */ | |
27735 | + unsigned long r31; /* scratch */ | |
27736 | + | |
27737 | + unsigned long ar_ccv; /* compare/exchange value (scratch) */ | |
27738 | + | |
27739 | + /* | |
27740 | + * * Floating point registers that the kernel considers scratch: | |
27741 | + * */ | |
27742 | + struct kl_ia64_fpreg f6; /* scratch */ | |
27743 | + struct kl_ia64_fpreg f7; /* scratch */ | |
27744 | + struct kl_ia64_fpreg f8; /* scratch */ | |
27745 | + struct kl_ia64_fpreg f9; /* scratch */ | |
27746 | + struct kl_ia64_fpreg f10; /* scratch */ | |
27747 | + struct kl_ia64_fpreg f11; /* scratch */ | |
27748 | +} __attribute__((packed)); | |
27749 | + | |
27750 | +/* | |
27751 | + * Structure: dump_header_asm_t | |
27752 | + * Function: This is the header for architecture-specific stuff. It | |
27753 | + * follows right after the dump header. | |
27754 | + */ | |
27755 | +typedef struct kl_dump_header_ia64_s { | |
27756 | + /* the dump magic number -- unique to verify dump is valid */ | |
27757 | + uint64_t magic_number; | |
27758 | + /* the version number of this dump */ | |
27759 | + uint32_t version; | |
27760 | + /* the size of this header (in case we can't read it) */ | |
27761 | + uint32_t header_size; | |
27762 | + /* pointer to pt_regs */ | |
27763 | + uint64_t pt_regs; | |
27764 | + /* the dump registers */ | |
27765 | + struct kl_pt_regs_ia64 regs; | |
27766 | + /* the rnat register saved after flushrs */ | |
27767 | + uint64_t rnat; | |
27768 | + /* the pfs register saved after flushrs */ | |
27769 | + uint64_t pfs; | |
27770 | + /* the bspstore register saved after flushrs */ | |
27771 | + uint64_t bspstore; | |
27772 | + | |
27773 | + /* smp specific */ | |
27774 | + uint32_t smp_num_cpus; | |
27775 | + uint32_t dumping_cpu; | |
27776 | + struct kl_pt_regs_ia64 smp_regs[KL_NR_CPUS]; | |
27777 | + uint64_t smp_current_task[KL_NR_CPUS]; | |
27778 | + uint64_t stack[KL_NR_CPUS]; | |
27779 | +} __attribute__((packed)) kl_dump_header_ia64_t; | |
27780 | + | |
27781 | +/* The following struct is used just to calculate the size needed | |
27782 | + * to store per CPU info. (Make sure it is sync with the above struct) | |
27783 | + */ | |
27784 | +struct kl_dump_CPU_info_ia64 { | |
27785 | + struct kl_pt_regs_ia64 smp_regs; | |
27786 | + uint64_t smp_current_task; | |
27787 | + uint64_t stack; | |
27788 | +} __attribute__((packed)); | |
27789 | + | |
27790 | +/* function declarations | |
27791 | + */ | |
27792 | +int kl_set_dumparch_ia64(void); | |
27793 | +uint32_t dha_num_cpus_ia64(void); | |
27794 | +kaddr_t dha_current_task_ia64(int cpuid); | |
27795 | +int dha_cpuid_ia64(kaddr_t); | |
27796 | +kaddr_t dha_stack_ia64(int); | |
27797 | +kaddr_t dha_stack_ptr_ia64(int); | |
27798 | +int kl_read_dump_header_ia64(void); | |
27799 | + | |
27800 | +#endif /* __KL_DUMP_IA64_H */ | |
27801 | --- /dev/null | |
27802 | +++ b/kdb/modules/lcrash/asm/kl_types.h | |
27803 | @@ -0,0 +1,48 @@ | |
27804 | +/* | |
27805 | + * $Id: kl_types.h 1122 2004-12-21 23:26:23Z tjm $ | |
27806 | + * | |
27807 | + * This file is part of libklib. | |
27808 | + * A library which provides access to Linux system kernel dumps. | |
27809 | + * | |
27810 | + * Created by Silicon Graphics, Inc. | |
27811 | + * Contributions by IBM, NEC, and others | |
27812 | + * | |
27813 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
27814 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
27815 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
27816 | + * | |
27817 | + * This code is free software; you can redistribute it and/or modify | |
27818 | + * it under the terms of the GNU Lesser Public License as published by | |
27819 | + * the Free Software Foundation; either version 2.1 of the License, or | |
27820 | + * (at your option) any later version. See the file COPYING for more | |
27821 | + * information. | |
27822 | + */ | |
27823 | + | |
27824 | +#ifndef __ASMIA64_KL_TYPES_H | |
27825 | +#define __ASMIA64_KL_TYPES_H | |
27826 | + | |
27827 | +/* cpw */ | |
27828 | +/* was #include <kl_dump_ia64.h> */ | |
27829 | +#include "kl_dump_ia64.h" | |
27830 | + | |
27831 | +#define HOST_ARCH_IA64 | |
27832 | +/* cpw: add this, as otherwise comes from makefile */ | |
27833 | +#define DUMP_ARCH_IA64 | |
27834 | + | |
27835 | +/* Format string that allows a single fprintf() call to work for both | |
27836 | + * 32-bit and 64-bit pointer values (architecture specific). | |
27837 | + */ | |
27838 | +#ifdef CONFIG_X86_32 | |
27839 | +#define FMT64 "ll" | |
27840 | +#else | |
27841 | +#define FMT64 "l" | |
27842 | +#endif | |
27843 | +#define FMTPTR "l" | |
27844 | + | |
27845 | +/* for usage in common code where host architecture | |
27846 | + * specific type/macro is needed | |
27847 | + */ | |
27848 | +typedef kl_dump_header_ia64_t kl_dump_header_asm_t; | |
27849 | +#define KL_DUMP_ASM_MAGIC_NUMBER KL_DUMP_MAGIC_NUMBER_IA64 | |
27850 | + | |
27851 | +#endif /* __ASMIA64_KL_TYPES_H */ | |
27852 | --- /dev/null | |
27853 | +++ b/kdb/modules/lcrash/kl_alloc.h | |
27854 | @@ -0,0 +1,124 @@ | |
27855 | +/* | |
27856 | + * $Id: kl_alloc.h 1122 2004-12-21 23:26:23Z tjm $ | |
27857 | + * | |
27858 | + * This file is part of libutil. | |
27859 | + * A library which provides auxiliary functions. | |
27860 | + * libutil is part of lkcdutils -- utilities for Linux kernel crash dumps. | |
27861 | + * | |
27862 | + * Created by Silicon Graphics, Inc. | |
27863 | + * Contributions by IBM, NEC, and others | |
27864 | + * | |
27865 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
27866 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
27867 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
27868 | + * | |
27869 | + * This code is free software; you can redistribute it and/or modify | |
27870 | + * it under the terms of the GNU Lesser Public License as published by | |
27871 | + * the Free Software Foundation; either version 2.1 of the License, or | |
27872 | + * (at your option) any later version. See the file COPYING for more | |
27873 | + * information. | |
27874 | + */ | |
27875 | + | |
27876 | +#ifndef __KL_ALLOC_H | |
27877 | +#define __KL_ALLOC_H | |
27878 | + | |
27879 | +/** | |
27880 | + ** Header file for kl_alloc.c module | |
27881 | + ** | |
27882 | + **/ | |
27883 | + | |
27884 | +#define K_TEMP 1 | |
27885 | +#define K_PERM 2 | |
27886 | + | |
27887 | +/** function prototypes for register functions | |
27888 | + **/ | |
27889 | + | |
27890 | +/* Memory block allocator. Returns a pointer to an allocated block | |
27891 | + * of size bytes. In case of error, a NULL pointer will be returned | |
27892 | + * and errno will be set to indicate exactly what error occurred. | |
27893 | + * Note that the flag value will determine if the block allocated is | |
27894 | + * temporary (can be freed via a call to kl_free_temp_blks()) or | |
27895 | + * permenant (must be freed with a call to kl_free_block()).. | |
27896 | + */ | |
27897 | +typedef void * (*klib_block_alloc_func) ( | |
27898 | + int /* size of block required */, | |
27899 | + int /* flag value */, | |
27900 | + void * /* return address */); | |
27901 | + | |
27902 | +/* Memory block reallocator. Returns a pointer to a block of new_size | |
27903 | + * bytes. In case of error, a NULL pointer will be returned and | |
27904 | + * errno will be set to indicate exactly what error occurred. | |
27905 | + * Note that the flag value will determine if the block allocated is | |
27906 | + * temporary (can be free via a call to kl_free_temp_blks()) or | |
27907 | + * permenant. | |
27908 | + */ | |
27909 | +typedef void * (*klib_block_realloc_func) ( | |
27910 | + void * /* pointer to block to realloc */, | |
27911 | + int /* size of new block required */, | |
27912 | + int /* flag value */, | |
27913 | + void * /* return address */); | |
27914 | + | |
27915 | +/* Memory block duplicator. Returns a pointer to a block that is | |
27916 | + * a copy of the block passed in via pointer. In case of error, a | |
27917 | + * NULL pointer will be returned and errno will be set to indicate | |
27918 | + * exactly what error occurred. Note that the flag value will | |
27919 | + * determine if the block allocated is temporary (will be freed | |
27920 | + * via a call to kl_free_temp_blks()) or permenant. Note that this | |
27921 | + * function is only supported when liballoc is used (there is no | |
27922 | + * way to tell the size of a malloced block. | |
27923 | + */ | |
27924 | +typedef void * (*klib_block_dup_func) ( | |
27925 | + void * /* pointer to block to dup */, | |
27926 | + int /* flag value */, | |
27927 | + void * /* return address */); | |
27928 | + | |
27929 | +/* Allocates a block large enough to hold a string (plus the terminating | |
27930 | + * NULL character). | |
27931 | + */ | |
27932 | +typedef void * (*klib_str_to_block_func) ( | |
27933 | + char * /* pointer to character string */, | |
27934 | + int /* flag value */, | |
27935 | + void * /* return address */); | |
27936 | + | |
27937 | +/* Frees blocks that were previously allocated. | |
27938 | + */ | |
27939 | +typedef void (*klib_block_free_func) ( | |
27940 | + void * /* pointer to block */); | |
27941 | + | |
27942 | +/* alloc block wrapper function table structure | |
27943 | + */ | |
27944 | +typedef struct alloc_functions_s { | |
27945 | + int flag; /* Functions initialized? */ | |
27946 | + klib_block_alloc_func block_alloc; /* Returns ptr to block */ | |
27947 | + klib_block_realloc_func block_realloc; /* Returns ptr to new blk */ | |
27948 | + klib_block_dup_func block_dup; /* Returns ptr to new blk */ | |
27949 | + klib_str_to_block_func str_to_block; /* Returns ptr to new blk */ | |
27950 | + klib_block_free_func block_free; /* Frees memory block */ | |
27951 | +} alloc_functions_t; | |
27952 | + | |
27953 | +extern alloc_functions_t alloc_functions; | |
27954 | + | |
27955 | +/* Macros for accessing functions in alloc_functions table | |
27956 | + */ | |
27957 | +#define KL_BLOCK_ALLOC() (alloc_functions.block_alloc) | |
27958 | +#define KL_BLOCK_REALLOC() (alloc_functions.block_realloc) | |
27959 | +#define KL_BLOCK_DUP() (alloc_functions.block_dup) | |
27960 | +#define KL_STR_TO_BLOCK() (alloc_functions.str_to_block) | |
27961 | +#define KL_BLOCK_FREE() (alloc_functions.block_free) | |
27962 | + | |
27963 | +void *_kl_alloc_block(int, int, void *); | |
27964 | +void *_kl_realloc_block(void *, int, int, void *); | |
27965 | +void *_kl_dup_block(void *, int, void *); | |
27966 | +void *_kl_str_to_block(char *, int, void *); | |
27967 | +#if 0 | |
27968 | +cpw: we create a new wrappers for these: | |
27969 | +void kl_free_block(void *); | |
27970 | + | |
27971 | +#define kl_alloc_block(size, flags) _kl_alloc_block(size, flags, kl_get_ra()) | |
27972 | +#endif | |
27973 | +#define kl_realloc_block(b, new_size, flags) \ | |
27974 | + _kl_realloc_block(b, new_size, flags, kl_get_ra()) | |
27975 | +#define kl_dup_block(b, flags) _kl_dup_block(b, flags, kl_get_ra()) | |
27976 | +#define kl_str_to_block(s, flags) _kl_str_to_block(s, flags, kl_get_ra()) | |
27977 | + | |
27978 | +#endif /* __KL_ALLOC_H */ | |
27979 | --- /dev/null | |
27980 | +++ b/kdb/modules/lcrash/kl_bfd.h | |
27981 | @@ -0,0 +1,31 @@ | |
27982 | +/* | |
27983 | + * $Id: kl_bfd.h 1122 2004-12-21 23:26:23Z tjm $ | |
27984 | + * | |
27985 | + * This file is part of libklib. | |
27986 | + * A library which provides access to Linux system kernel dumps. | |
27987 | + * | |
27988 | + * Created by Silicon Graphics, Inc. | |
27989 | + * Contributions by IBM, NEC, and others | |
27990 | + * | |
27991 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
27992 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
27993 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
27994 | + * | |
27995 | + * This code is free software; you can redistribute it and/or modify | |
27996 | + * it under the terms of the GNU Lesser Public License as published by | |
27997 | + * the Free Software Foundation; either version 2.1 of the License, or | |
27998 | + * (at your option) any later version. See the file COPYING for more | |
27999 | + * information. | |
28000 | + */ | |
28001 | + | |
28002 | +#ifndef __KL_BFD_H | |
28003 | +#define __KL_BFD_H | |
28004 | + | |
28005 | +/* cpw: " " form: */ | |
28006 | +#include "klib.h" | |
28007 | + | |
28008 | +int kl_check_bfd_error(bfd_error_type); | |
28009 | +int kl_open_elf(char*, bfd**, bfd**); | |
28010 | +int kl_read_bfd_syminfo(maplist_t*); | |
28011 | + | |
28012 | +#endif /* __KL_BFD_H */ | |
28013 | --- /dev/null | |
28014 | +++ b/kdb/modules/lcrash/kl_btnode.h | |
28015 | @@ -0,0 +1,95 @@ | |
28016 | +/* | |
28017 | + * $Id: kl_btnode.h 1122 2004-12-21 23:26:23Z tjm $ | |
28018 | + * | |
28019 | + * This file is part of libutil. | |
28020 | + * A library which provides auxiliary functions. | |
28021 | + * libutil is part of lkcdutils -- utilities for Linux kernel crash dumps. | |
28022 | + * | |
28023 | + * Created by Silicon Graphics, Inc. | |
28024 | + * Contributions by IBM, NEC, and others | |
28025 | + * | |
28026 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
28027 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
28028 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
28029 | + * | |
28030 | + * This code is free software; you can redistribute it and/or modify | |
28031 | + * it under the terms of the GNU Lesser Public License as published by | |
28032 | + * the Free Software Foundation; either version 2.1 of the License, or | |
28033 | + * (at your option) any later version. See the file COPYING for more | |
28034 | + * information. | |
28035 | + */ | |
28036 | + | |
28037 | +#ifndef __KL_BTNODE_H | |
28038 | +#define __KL_BTNODE_H | |
28039 | + | |
28040 | +/* | |
28041 | + * Node header struct for use in binary search tree routines | |
28042 | + */ | |
28043 | +typedef struct btnode_s { | |
28044 | + struct btnode_s *bt_left; | |
28045 | + struct btnode_s *bt_right; | |
28046 | + struct btnode_s *bt_parent; | |
28047 | + char *bt_key; | |
28048 | + int bt_height; | |
28049 | +} btnode_t; | |
28050 | + | |
28051 | +#define DUPLICATES_OK 1 | |
28052 | + | |
28053 | +/** | |
28054 | + ** btnode operation function prototypes | |
28055 | + **/ | |
28056 | + | |
28057 | +/* Return the hight of a given btnode_s struct in a tree. In the | |
28058 | + * event of an error (a NULL btnode_s pointer was passed in), a | |
28059 | + * value of -1 will be returned. | |
28060 | + */ | |
28061 | +int kl_btnode_height( | |
28062 | + btnode_t* /* pointer to btnode_s struct */); | |
28063 | + | |
28064 | +/* Insert a btnode_s struct into a tree. After the insertion, the | |
28065 | + * tree will be left in a reasonibly ballanced state. Note that, if | |
28066 | + * the DUPLICATES_OK flag is set, duplicate keys will be inserted | |
28067 | + * into the tree (otherwise return an error). In the event of an | |
28068 | + * error, a value of -1 will be returned. | |
28069 | + */ | |
28070 | +int kl_insert_btnode( | |
28071 | + btnode_t** /* pointer to root of tree */, | |
28072 | + btnode_t* /* pointer to btnode_s struct to insert */, | |
28073 | + int /* flags (DUPLICATES_OK) */); | |
28074 | + | |
28075 | +/* Finds a btnode in a tree and removes it, making sure to keep | |
28076 | + * the tree in a reasonably balanced state. As part of the | |
28077 | + * delete_btnode() operation, a call will be made to the free | |
28078 | + * function (passed in as a parameter) to free any application | |
28079 | + * specific data. | |
28080 | + */ | |
28081 | +int kl_delete_btnode( | |
28082 | + btnode_t** /* pointer to the root of the btree */, | |
28083 | + btnode_t* /* pointer to btnode_s struct to delete */, | |
28084 | + void(*)(void*) /* pointer to function to actually free the node */, | |
28085 | + int /* flags */); | |
28086 | + | |
28087 | +/* Traverse a tree looking for a particular key. In the event that | |
28088 | + * duplicate keys are allowed in the tree, returns the first occurance | |
28089 | + * of the search key found. A pointer to an int should be passed in | |
28090 | + * to hold the maximum depth reached in the search. Upon success, | |
28091 | + * returns a pointer to a btnode_s struct. Otherwise, a NULL pointer | |
28092 | + * will be returned. | |
28093 | + */ | |
28094 | +btnode_t *_kl_find_btnode( | |
28095 | + btnode_t* /* pointer to btnode_s struct to start search with */, | |
28096 | + char* /* key we are looking for */, | |
28097 | + int* /* pointer to where max depth vlaue will be placed */, | |
28098 | + size_t /* if nonzero compare only first n chars of key */); | |
28099 | +#define kl_find_btnode(A, B, C) _kl_find_btnode(A, B, C, 0) | |
28100 | + | |
28101 | +btnode_t *kl_first_btnode( | |
28102 | + btnode_t * /* pointer to any btnode in a btree */); | |
28103 | + | |
28104 | +btnode_t *kl_next_btnode( | |
28105 | + btnode_t * /* pointer to current btnode */); | |
28106 | + | |
28107 | +btnode_t *kl_prev_btnode( | |
28108 | + btnode_t * /* Pointer to current btnode */); | |
28109 | + | |
28110 | +#endif /* __KL_BTNODE_H */ | |
28111 | --- /dev/null | |
28112 | +++ b/kdb/modules/lcrash/kl_cmp.h | |
28113 | @@ -0,0 +1,102 @@ | |
28114 | +/* | |
28115 | + * $Id: kl_cmp.h 1216 2005-07-06 10:03:13Z holzheu $ | |
28116 | + * | |
28117 | + * This file is part of libklib. | |
28118 | + * A library which provides access to Linux system kernel dumps. | |
28119 | + * | |
28120 | + * Created by Silicon Graphics, Inc. | |
28121 | + * Contributions by IBM, NEC, and others | |
28122 | + * | |
28123 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
28124 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
28125 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
28126 | + * | |
28127 | + * This code is free software; you can redistribute it and/or modify | |
28128 | + * it under the terms of the GNU Lesser Public License as published by | |
28129 | + * the Free Software Foundation; either version 2.1 of the License, or | |
28130 | + * (at your option) any later version. See the file COPYING for more | |
28131 | + * information. | |
28132 | + */ | |
28133 | + | |
28134 | +#ifndef __KL_CMP_H | |
28135 | +#define __KL_CMP_H | |
28136 | + | |
28137 | +#define DUMP_INDEX_MAGIC 0xdeadbeef | |
28138 | +#define DUMP_INDEX_VERSION 31900 | |
28139 | +#define NUM_BUCKETS 65535 | |
28140 | + | |
28141 | +/* | |
28142 | + * Definitions for compressed cached reads. I've recently lowered | |
28143 | + * these ... If they need to be increased later, I'll do so. | |
28144 | + */ | |
28145 | +#define CMP_HIGH_WATER_MARK 25 | |
28146 | +#define CMP_LOW_WATER_MARK 10 | |
28147 | + | |
28148 | +#define CMP_VM_CACHED 0x01 | |
28149 | +#define CMP_VM_UNCACHED 0x02 | |
28150 | + | |
28151 | + | |
28152 | +/* | |
28153 | + * This structure defines a page table entry, what each value will | |
28154 | + * contain. Since these can be cached or uncached, we have a flags | |
28155 | + * variable to specify this. | |
28156 | + */ | |
28157 | +typedef struct _ptableentry { | |
28158 | + int flags; /* flags for page in cache */ | |
28159 | + int length; /* length of page */ | |
28160 | + int cached; /* cached (1 = yes, cached) */ | |
28161 | + kaddr_t addr; /* addr of page */ | |
28162 | + char *data; /* data in page */ | |
28163 | + struct _ptableentry *next; /* ptr to next dump page */ | |
28164 | + struct _ptableentry *prev; /* ptr to prev dump page */ | |
28165 | + struct _ptableentry *nextcache; /* ptr to next cached page */ | |
28166 | + struct _ptableentry *prevcache; /* ptr to prev cached page */ | |
28167 | +} ptableentry; | |
28168 | + | |
28169 | +/* | |
28170 | + * This is for the page table index from the compressed core dump. | |
28171 | + * This is separate from the page table entries because these are | |
28172 | + * simply addresses off of the compressed core dump, and not the | |
28173 | + * actual data from the core dump. If we hash these values, we gain | |
28174 | + * a lot of performance because we only have 1 to search for the | |
28175 | + * page data, 1 to search for the index, and return if both searches | |
28176 | + * failed. | |
28177 | + */ | |
28178 | +typedef struct _ptableindex { | |
28179 | + kl_dump_page_t dir; /* directory entry of page */ | |
28180 | + kaddr_t addr; /* address of page offset */ | |
28181 | + kaddr_t coreaddr; /* address of page in core */ | |
28182 | + unsigned int hash; /* hash value for this index item */ | |
28183 | + struct _ptableindex *next; /* next pointer */ | |
28184 | +} ptableindex; | |
28185 | + | |
28186 | +typedef struct dump_index_s { | |
28187 | + unsigned int magic_number; /* dump index magic number */ | |
28188 | + unsigned int version_number; /* dump index version number */ | |
28189 | + /* struct timeval depends on machine, use two long values here */ | |
28190 | + struct {uint64_t tv_sec; | |
28191 | + uint64_t tv_usec; | |
28192 | + } timebuf; /* the time of the dump */ | |
28193 | +} __attribute__((packed)) dump_index_t; | |
28194 | + | |
28195 | +/* Compression function */ | |
28196 | +typedef int (*kl_compress_fn_t)(const unsigned char *old, uint32_t old_size, unsigned char *new, uint32_t size); | |
28197 | + | |
28198 | +/* function declarations | |
28199 | + */ | |
28200 | +int kl_cmpreadmem(int, kaddr_t, char*, unsigned int, unsigned int); | |
28201 | +int kl_cmpinit( | |
28202 | + int /* fd */, | |
28203 | + char * /* indexname */, | |
28204 | + int /* flags */); | |
28205 | + | |
28206 | +/* Compression routine: No compression */ | |
28207 | +int kl_compress_none(const char *old, uint32_t old_size, char *new, uint32_t new_size); | |
28208 | + | |
28209 | +/* Compression routine: Run length encoding */ | |
28210 | +int kl_compress_rle(const char *old, uint32_t old_size, char *new, uint32_t new_size); | |
28211 | + | |
28212 | +/* Compression routine: GZIP */ | |
28213 | +int kl_compress_gzip(const unsigned char *old, uint32_t old_size, unsigned char *new, uint32_t new_size); | |
28214 | + | |
28215 | +#endif /* __KL_CMP_H */ | |
28216 | --- /dev/null | |
28217 | +++ b/kdb/modules/lcrash/kl_copt.h | |
28218 | @@ -0,0 +1,29 @@ | |
28219 | +/* | |
28220 | + * $Id: kl_copt.h 1122 2004-12-21 23:26:23Z tjm $ | |
28221 | + * | |
28222 | + * This file is part of libutil. | |
28223 | + * A library which provides auxiliary functions. | |
28224 | + * libutil is part of lkcdutils -- utilities for Linux kernel crash dumps. | |
28225 | + * | |
28226 | + * Created by Silicon Graphics, Inc. | |
28227 | + * | |
28228 | + * Copyright (C) 2003, 2004 Silicon Graphics, Inc. All rights reserved. | |
28229 | + * | |
28230 | + * This code is free software; you can redistribute it and/or modify | |
28231 | + * it under the terms of the GNU Lesser Public License as published by | |
28232 | + * the Free Software Foundation; either version 2.1 of the License, or | |
28233 | + * (at your option) any later version. See the file COPYING for more | |
28234 | + * information. | |
28235 | + */ | |
28236 | +#ifndef __KL_COPT_H | |
28237 | +#define __KL_COPT_H | |
28238 | + | |
28239 | +extern int copt_ind; | |
28240 | +extern char *copt_arg; | |
28241 | +extern int copt_error; | |
28242 | + | |
28243 | +void reset_copt(void); | |
28244 | +int is_copt(char *); | |
28245 | +int get_copt(int, char **, const char *, char **); | |
28246 | + | |
28247 | +#endif /* __KL_COPT_H */ | |
28248 | --- /dev/null | |
28249 | +++ b/kdb/modules/lcrash/kl_debug.h | |
28250 | @@ -0,0 +1,168 @@ | |
28251 | +/* | |
28252 | + * $Id: kl_debug.h 1196 2005-05-17 18:34:12Z tjm $ | |
28253 | + * | |
28254 | + * This file is part of libklib. | |
28255 | + * A library which provides access to Linux system kernel dumps. | |
28256 | + * | |
28257 | + * Created by Silicon Graphics, Inc. | |
28258 | + * Contributions by IBM, NEC, and others | |
28259 | + * | |
28260 | + * Copyright (C) 1999 - 2005 Silicon Graphics, Inc. All rights reserved. | |
28261 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
28262 | + * | |
28263 | + * This code is free software; you can redistribute it and/or modify | |
28264 | + * it under the terms of the GNU Lesser Public License as published by | |
28265 | + * the Free Software Foundation; either version 2.1 of the License, or | |
28266 | + * (at your option) any later version. See the file COPYING for more | |
28267 | + * information. | |
28268 | + */ | |
28269 | + | |
28270 | +#ifndef __KL_DEBUG_H | |
28271 | +#define __KL_DEBUG_H | |
28272 | + | |
28273 | +/* generic functions for reading kerntypes in stabs and dwarf2 formats */ | |
28274 | + | |
28275 | +#define DBG_NONE 0 | |
28276 | +#define DBG_STABS 1 | |
28277 | +#define DBG_DWARF2 2 | |
28278 | + | |
28279 | +extern int debug_format; | |
28280 | + | |
28281 | +#define TYPE_NUM(X) ((uint64_t)(X) & 0xffffffff) | |
28282 | +#define SRC_FILE(X) (((uint64_t)(X) >> 48) & 0xfff) | |
28283 | +#define TYPE_NUM_SLOTS (255) | |
28284 | +#define TYPE_NUM_HASH(X) \ | |
28285 | + (((SRC_FILE(X)<<1)+TYPE_NUM(X)) % (TYPE_NUM_SLOTS - 1)) | |
28286 | + | |
28287 | +typedef struct dbg_type_s { | |
28288 | + kltype_t st_klt; /* must be first */ | |
28289 | + | |
28290 | + int st_bit_offset; /* from start of struct/union */ | |
28291 | + uint64_t st_type_num; /* DBG type_num */ | |
28292 | + uint64_t st_real_type; /* real type type_num */ | |
28293 | + uint64_t st_index_type; /* type_num of array index */ | |
28294 | + uint64_t st_element_type; /* type_num of array element */ | |
28295 | +} dbg_type_t; | |
28296 | + | |
28297 | +#define st_name st_klt.kl_name | |
28298 | +#define st_type st_klt.kl_type | |
28299 | +#define st_ptr st_klt.kl_ptr | |
28300 | +#define st_flags st_klt.kl_flags | |
28301 | +#define st_typestr st_klt.kl_typestr | |
28302 | +#define st_size st_klt.kl_size | |
28303 | +#define st_offset st_klt.kl_offset | |
28304 | +#define st_low_bounds st_klt.kl_low_bounds | |
28305 | +#define st_high_bounds st_klt.kl_high_bounds | |
28306 | +#define st_value st_klt.kl_value | |
28307 | +#define st_bit_size st_klt.kl_bit_size | |
28308 | +#define st_next st_klt.kl_next | |
28309 | +#define st_member st_klt.kl_member | |
28310 | +#define st_realtype st_klt.kl_realtype | |
28311 | +#define st_indextype st_klt.kl_indextype | |
28312 | +#define st_elementtype st_klt.kl_elementtype | |
28313 | +#define st_encoding st_klt.kl_encoding | |
28314 | + | |
28315 | +/* Structure containing information about a symbol entry | |
28316 | + */ | |
28317 | +/* this must match the definition in lkcd's libklib/include/kl_debug.h */ | |
28318 | +typedef struct dbg_sym_s { | |
28319 | + btnode_t sym_bt; /* must be first */ | |
28320 | + short sym_dbgtyp; /* STABS, DWARF2, ... */ | |
28321 | + short sym_state; /* current state */ | |
28322 | + short sym_flag; /* current flag value */ | |
28323 | + short sym_type; /* symbol type */ | |
28324 | + short sym_pvttype; /* private type */ | |
28325 | + short sym_nmlist; /* namelist index */ | |
28326 | + short sym_srcfile; /* source file index */ | |
28327 | + short sym_incfile; /* include file index */ | |
28328 | + int sym_num; /* symbol number */ | |
28329 | + int sym_off; /* symbol table offset */ | |
28330 | + int sym_stroff; /* symbol offset in string table */ | |
28331 | + uint64_t sym_typenum; /* arbitrary type number */ | |
28332 | + kltype_t *sym_kltype; /* Full type information */ | |
28333 | + struct dbg_sym_s *sym_next; /* next pointer for chaining */ | |
28334 | + struct dbg_sym_s *sym_link; /* another pointer for chaining */ | |
28335 | + int sym_dup; /* duplicate symbol */ | |
28336 | +} dbg_sym_t; | |
28337 | +#define sym_name sym_bt.bt_key | |
28338 | + | |
28339 | +extern dbg_sym_t *type_tree; | |
28340 | +extern dbg_sym_t *typedef_tree; | |
28341 | +extern dbg_sym_t *func_tree; | |
28342 | +extern dbg_sym_t *srcfile_tree; | |
28343 | +extern dbg_sym_t *var_tree; | |
28344 | +extern dbg_sym_t *xtype_tree; | |
28345 | +extern dbg_sym_t *symlist; | |
28346 | +extern dbg_sym_t *symlist_end; | |
28347 | + | |
28348 | +/* State flags | |
28349 | + */ | |
28350 | +#define DBG_SETUP 0x1 | |
28351 | +#define DBG_SETUP_DONE 0x2 | |
28352 | +#define DBG_SETUP_FAILED 0x4 | |
28353 | + | |
28354 | +/* Flags for identifying individual symbol types | |
28355 | + */ | |
28356 | +#define DBG_SRCFILE 0x0001 | |
28357 | +#define DBG_TYPE 0x0002 | |
28358 | +#define DBG_TYPEDEF 0x0004 | |
28359 | +#define DBG_FUNC 0x0008 | |
28360 | +#define DBG_PARAM 0x0010 | |
28361 | +#define DBG_LINE 0x0020 | |
28362 | +#define DBG_VAR 0x0040 | |
28363 | +#define DBG_XTYPE 0x0100 | |
28364 | +#define DBG_ALL 0xffff | |
28365 | + | |
28366 | +/* Structure for cross referencing one type number to another | |
28367 | + */ | |
28368 | +typedef struct dbg_hashrec_s { | |
28369 | + uint64_t h_typenum; /* type number */ | |
28370 | + dbg_sym_t *h_ptr; /* pointer to actual type */ | |
28371 | + struct dbg_hashrec_s *h_next; /* next pointer (for hashing) */ | |
28372 | +} dbg_hashrec_t; | |
28373 | + | |
28374 | +extern dbg_hashrec_t *dbg_hash[]; | |
28375 | + | |
28376 | +#define HASH_SYM 1 | |
28377 | +#define HASH_XREF 2 | |
28378 | + | |
28379 | +/* DBG function prototypes | |
28380 | + */ | |
28381 | +dbg_sym_t *dbg_alloc_sym( | |
28382 | + int /* format */); | |
28383 | + | |
28384 | +void dbg_free_sym( | |
28385 | + dbg_sym_t * /* dbg_sym_s pointer */); | |
28386 | + | |
28387 | +int dbg_setup_typeinfo( | |
28388 | + dbg_sym_t * /* dbg_sym_s pointer */); | |
28389 | + | |
28390 | +int dbg_insert_sym( | |
28391 | + dbg_sym_t * /* dbg_sym_s pointer */); | |
28392 | + | |
28393 | +void dbg_hash_sym( | |
28394 | + uint64_t /* typenum */, | |
28395 | + dbg_sym_t * /* dbg_sym_s pointer */); | |
28396 | + | |
28397 | +dbg_type_t *dbg_walk_hash( | |
28398 | + int * /* pointer to hash index */, | |
28399 | + void ** /* pointer to hash record pointer */); | |
28400 | + | |
28401 | +dbg_sym_t *dbg_find_sym( | |
28402 | + char * /* name */, | |
28403 | + int /* type number */, | |
28404 | + uint64_t /* typenum */); | |
28405 | + | |
28406 | +dbg_sym_t *dbg_first_sym( | |
28407 | + int /* type number */); | |
28408 | + | |
28409 | +dbg_sym_t *dbg_next_sym( | |
28410 | + dbg_sym_t * /* dbg_sym_s pointer */); | |
28411 | + | |
28412 | +dbg_sym_t *dbg_prev_sym( | |
28413 | + dbg_sym_t * /* dbg_sym_s pointer */); | |
28414 | + | |
28415 | +dbg_type_t *dbg_find_typenum( | |
28416 | + uint64_t /* typenum */); | |
28417 | + | |
28418 | +#endif /* __KL_DEBUG_H */ | |
28419 | --- /dev/null | |
28420 | +++ b/kdb/modules/lcrash/kl_dump.h | |
28421 | @@ -0,0 +1,511 @@ | |
28422 | +/* | |
28423 | + * $Id: kl_dump.h 1336 2006-10-23 23:27:06Z tjm $ | |
28424 | + * | |
28425 | + * This file is part of libklib. | |
28426 | + * A library which provides access to Linux system kernel dumps. | |
28427 | + * | |
28428 | + * Created by Silicon Graphics, Inc. | |
28429 | + * Contributions by IBM, NEC, and others | |
28430 | + * | |
28431 | + * Copyright (C) 1999 - 2005 Silicon Graphics, Inc. All rights reserved. | |
28432 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
28433 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
28434 | + * | |
28435 | + * This code is free software; you can redistribute it and/or modify | |
28436 | + * it under the terms of the GNU Lesser Public License as published by | |
28437 | + * the Free Software Foundation; either version 2.1 of the License, or | |
28438 | + * (at your option) any later version. See the file COPYING for more | |
28439 | + * information. | |
28440 | + */ | |
28441 | + | |
28442 | +#ifndef __KL_DUMP_H | |
28443 | +#define __KL_DUMP_H | |
28444 | + | |
28445 | +#if 0 | |
28446 | +cpw: dont need: | |
28447 | +#include <klib.h> | |
28448 | +#include <asm/ioctl.h> | |
28449 | +#endif | |
28450 | + | |
28451 | +/* | |
28452 | + * DUMP_DEBUG: a debug level for the kernel dump code and | |
28453 | + * the supporting lkcd libraries in user space. | |
28454 | + * | |
28455 | + * 0: FALSE: No Debug Added | |
28456 | + * 1: TRUE: Break Points | |
28457 | + * . | |
28458 | + * . | |
28459 | + * . | |
28460 | + * 6: Add Debug Data to Structures | |
28461 | + * . | |
28462 | + * . | |
28463 | + * 9: Max | |
28464 | + */ | |
28465 | +#define DUMP_DEBUG FALSE | |
28466 | + | |
28467 | +#if DUMP_DEBUG | |
28468 | +void dump_bp(void); /* Called when something exceptional occures */ | |
28469 | +# define DUMP_BP() dump_bp() /* BreakPoint */ | |
28470 | +#else | |
28471 | +# define DUMP_BP() | |
28472 | +#endif | |
28473 | + | |
28474 | + | |
28475 | +#define KL_UTS_LEN 65 /* do not change ... */ | |
28476 | + | |
28477 | +extern int SN2_24X; | |
28478 | + | |
28479 | +/* | |
28480 | + * Size of the buffer that's used to hold: | |
28481 | + * | |
28482 | + * 1. the dump header (paded to fill the complete buffer) | |
28483 | + * 2. the possibly compressed page headers and data | |
28484 | + */ | |
28485 | +extern uint64_t KL_DUMP_BUFFER_SIZE; | |
28486 | +extern uint64_t KL_DUMP_HEADER_SIZE; | |
28487 | + | |
28488 | +#if 0 | |
28489 | +/* Variables that contain page size, mask etc. used in dump format | |
28490 | + * (this is not the system page size stored in the dump header) | |
28491 | + */ | |
28492 | +uint64_t KL_DUMP_PAGE_SIZE; | |
28493 | +uint64_t KL_DUMP_PAGE_MASK; | |
28494 | +uint64_t KL_DUMP_PAGE_SHIFT; | |
28495 | +#endif | |
28496 | + | |
28497 | +/* Dump header offset changed from 4k to 64k to support multiple page sizes */ | |
28498 | +#define KL_DUMP_HEADER_OFFSET (1ULL << 16) | |
28499 | + | |
28500 | + | |
28501 | +/* header definitions for dumps from s390 standalone dump tools */ | |
28502 | +#define KL_DUMP_MAGIC_S390SA 0xa8190173618f23fdULL /* s390sa magic number */ | |
28503 | +#define KL_DUMP_HEADER_SZ_S390SA 4096 | |
28504 | + | |
28505 | +/* standard header definitions */ | |
28506 | +#define KL_DUMP_MAGIC_NUMBER 0xa8190173618f23edULL /* dump magic number */ | |
28507 | +#define KL_DUMP_MAGIC_LIVE 0xa8190173618f23cdULL /* live magic number */ | |
28508 | +#define KL_DUMP_MAGIC_ASM 0xdeaddeadULL /* generic arch magic number */ | |
28509 | +#define KL_DUMP_VERSION_NUMBER 0x8 /* dump version number */ | |
28510 | +#define KL_DUMP_PANIC_LEN 0x100 /* dump panic string length */ | |
28511 | + | |
28512 | +/* dump levels - type specific stuff added later -- add as necessary */ | |
28513 | +#define KL_DUMP_LEVEL_NONE 0x0 /* no dumping at all -- just bail */ | |
28514 | +#define KL_DUMP_LEVEL_HEADER 0x1 /* kernel dump header only */ | |
28515 | +#define KL_DUMP_LEVEL_KERN 0x2 /* dump header and kernel pages */ | |
28516 | +#define KL_DUMP_LEVEL_USED 0x4 /* dump header, kernel/user pages */ | |
28517 | +#define KL_DUMP_LEVEL_ALL_RAM 0x8 /* dump header, all RAM pages */ | |
28518 | +#define KL_DUMP_LEVEL_ALL 0x10 /* dump all memory RAM and firmware */ | |
28519 | + | |
28520 | +/* dump compression options -- add as necessary */ | |
28521 | +#define KL_DUMP_COMPRESS_NONE 0x0 /* don't compress this dump */ | |
28522 | +#define KL_DUMP_COMPRESS_RLE 0x1 /* use RLE compression */ | |
28523 | +#define KL_DUMP_COMPRESS_GZIP 0x2 /* use GZIP compression */ | |
28524 | + | |
28525 | +/* dump flags - any dump-type specific flags -- add as necessary */ | |
28526 | +#define KL_DUMP_FLAGS_NONE 0x0 /* no flags are set for this dump */ | |
28527 | +#define KL_DUMP_FLAGS_NONDISRUPT 0x1 /* try to keep running after dump */ | |
28528 | +#define KL_DUMP_FLAGS_DISKDUMP 0x80000000 /* dump to local disk */ | |
28529 | +#define KL_DUMP_FLAGS_NETDUMP 0x40000000 /* dump to network device */ | |
28530 | + | |
28531 | +/* dump header flags -- add as necessary */ | |
28532 | +#define KL_DUMP_DH_FLAGS_NONE 0x0 /* no flags set (error condition!) */ | |
28533 | +#define KL_DUMP_DH_RAW 0x1 /* raw page (no compression) */ | |
28534 | +#define KL_DUMP_DH_COMPRESSED 0x2 /* page is compressed */ | |
28535 | +#define KL_DUMP_DH_END 0x4 /* end marker on a full dump */ | |
28536 | +#define KL_DUMP_DH_TRUNCATED 0x8 /* dump is incomplete */ | |
28537 | +#define KL_DUMP_DH_TEST_PATTERN 0x10 /* dump page is a test pattern */ | |
28538 | +#define KL_DUMP_DH_NOT_USED 0x20 /* 1st bit not used in flags */ | |
28539 | + | |
28540 | +/* dump ioctl() control options */ | |
28541 | +#ifdef IOCTL26 | |
28542 | +#define DIOSDUMPDEV _IOW('p', 0xA0, unsigned int) /* set the dump device */ | |
28543 | +#define DIOGDUMPDEV _IOR('p', 0xA1, unsigned int) /* get the dump device */ | |
28544 | +#define DIOSDUMPLEVEL _IOW('p', 0xA2, unsigned int) /* set the dump level */ | |
28545 | +#define DIOGDUMPLEVEL _IOR('p', 0xA3, unsigned int) /* get the dump level */ | |
28546 | +#define DIOSDUMPFLAGS _IOW('p', 0xA4, unsigned int) /* set the dump flag parameters */ | |
28547 | +#define DIOGDUMPFLAGS _IOR('p', 0xA5, unsigned int) /* get the dump flag parameters */ | |
28548 | +#define DIOSDUMPCOMPRESS _IOW('p', 0xA6, unsigned int) /* set the dump compress level */ | |
28549 | +#define DIOGDUMPCOMPRESS _IOR('p', 0xA7, unsigned int) /* get the dump compress level */ | |
28550 | + | |
28551 | +/* these ioctls are used only by netdump module */ | |
28552 | +#define DIOSTARGETIP _IOW('p', 0xA8, unsigned int) /* set the target m/c's ip */ | |
28553 | +#define DIOGTARGETIP _IOR('p', 0xA9, unsigned int) /* get the target m/c's ip */ | |
28554 | +#define DIOSTARGETPORT _IOW('p', 0xAA, unsigned int) /* set the target m/c's port */ | |
28555 | +#define DIOGTARGETPORT _IOR('p', 0xAB, unsigned int) /* get the target m/c's port */ | |
28556 | +#define DIOSSOURCEPORT _IOW('p', 0xAC, unsigned int) /* set the source m/c's port */ | |
28557 | +#define DIOGSOURCEPORT _IOR('p', 0xAD, unsigned int) /* get the source m/c's port */ | |
28558 | +#define DIOSETHADDR _IOW('p', 0xAE, unsigned int) /* set ethernet address */ | |
28559 | +#define DIOGETHADDR _IOR('p', 0xAF, unsigned int) /* get ethernet address */ | |
28560 | +#define DIOGDUMPOKAY _IOR('p', 0xB0, unsigned int) /* check if dump is configured */ | |
28561 | +#define DIOSDUMPTAKE _IOW('p', 0xB1, unsigned int) /* take a manual dump */ | |
28562 | +#else | |
28563 | +#define DIOSDUMPDEV 1 /* set the dump device */ | |
28564 | +#define DIOGDUMPDEV 2 /* get the dump device */ | |
28565 | +#define DIOSDUMPLEVEL 3 /* set the dump level */ | |
28566 | +#define DIOGDUMPLEVEL 4 /* get the dump level */ | |
28567 | +#define DIOSDUMPFLAGS 5 /* set the dump flag parameters */ | |
28568 | +#define DIOGDUMPFLAGS 6 /* get the dump flag parameters */ | |
28569 | +#define DIOSDUMPCOMPRESS 7 /* set the dump compress level */ | |
28570 | +#define DIOGDUMPCOMPRESS 8 /* get the dump compress level */ | |
28571 | +#define DIOSTARGETIP 9 /* set the target m/c's ip */ | |
28572 | +#define DIOGTARGETIP 10 /* get the target m/c's ip */ | |
28573 | +#define DIOSTARGETPORT 11 /* set the target m/c's port */ | |
28574 | +#define DIOGTARGETPORT 12 /* get the target m/c's port */ | |
28575 | +#define DIOSSOURCEPORT 13 /* set the source m/c's port */ | |
28576 | +#define DIOGSOURCEPORT 14 /* get the source m/c's port */ | |
28577 | +#define DIOSETHADDR 15 /* set ethernet address */ | |
28578 | +#define DIOGETHADDR 16 /* get ethernet address */ | |
28579 | +#define DIOGDUMPOKAY 17 /* check if dump is configured */ | |
28580 | +#define DIOSDUMPTAKE 18 /* take a manual dump */ | |
28581 | +#endif | |
28582 | + | |
28583 | +/* | |
28584 | + * structures | |
28585 | + */ | |
28586 | + | |
28587 | +/* This is the header dumped at the top of every valid crash dump. | |
28588 | + */ | |
28589 | +typedef struct kl_dump_header_s { | |
28590 | + uint64_t magic_number; /* dump magic number, unique to verify dump */ | |
28591 | + uint32_t version; /* version number of this dump */ | |
28592 | + uint32_t header_size; /* size of this header */ | |
28593 | + uint32_t dump_level; /* level of this dump */ | |
28594 | + /* FIXME: rename page_size to dump_page_size | |
28595 | + * The size of a hardware/physical memory page (DUMP_PAGE_SIZE). | |
28596 | + * NB: Not the configurable system page (PAGE_SIZE) (4K, 8K, 16K, etc.) | |
28597 | + */ | |
28598 | +/* uint32_t dh_dump_page_size; */ | |
28599 | + uint32_t page_size; /* page size (e.g. 4K, 8K, 16K, etc.) */ | |
28600 | + uint64_t memory_size; /* size of entire physical memory */ | |
28601 | + uint64_t memory_start; /* start of physical memory */ | |
28602 | + uint64_t memory_end; /* end of physical memory */ | |
28603 | +#if DUMP_DEBUG >= 6 | |
28604 | + uint64_t num_bytes; /* number of bytes in this dump */ | |
28605 | +#endif | |
28606 | + /* the number of dump pages in this dump specifically */ | |
28607 | + uint32_t num_dump_pages; | |
28608 | + char panic_string[KL_DUMP_PANIC_LEN]; /* panic string, if available*/ | |
28609 | + | |
28610 | + /* timeval depends on machine, two long values */ | |
28611 | + struct {uint64_t tv_sec; | |
28612 | + uint64_t tv_usec; | |
28613 | + } time; /* the time of the system crash */ | |
28614 | + | |
28615 | + /* the NEW utsname (uname) information -- in character form */ | |
28616 | + /* we do this so we don't have to include utsname.h */ | |
28617 | + /* plus it helps us be more architecture independent */ | |
28618 | + char utsname_sysname[KL_UTS_LEN]; | |
28619 | + char utsname_nodename[KL_UTS_LEN]; | |
28620 | + char utsname_release[KL_UTS_LEN]; | |
28621 | + char utsname_version[KL_UTS_LEN]; | |
28622 | + char utsname_machine[KL_UTS_LEN]; | |
28623 | + char utsname_domainname[KL_UTS_LEN]; | |
28624 | + | |
28625 | + uint64_t current_task; /* fixme: better use uint64_t here */ | |
28626 | + uint32_t dump_compress; /* compression type used in this dump */ | |
28627 | + uint32_t dump_flags; /* any additional flags */ | |
28628 | + uint32_t dump_device; /* any additional flags */ | |
28629 | + uint64_t dump_buffer_size; /* version >= 9 */ | |
28630 | +} __attribute__((packed)) kl_dump_header_t; | |
28631 | + | |
28632 | +/* This is the header used by the s390 standalone dump tools | |
28633 | + */ | |
28634 | +typedef struct kl_dump_header_s390sa_s { | |
28635 | + uint64_t magic_number; /* magic number for this dump (unique)*/ | |
28636 | + uint32_t version; /* version number of this dump */ | |
28637 | + uint32_t header_size; /* size of this header */ | |
28638 | + uint32_t dump_level; /* the level of this dump (just a header?) */ | |
28639 | + uint32_t page_size; /* page size of dumped Linux (4K,8K,16K etc.) */ | |
28640 | + uint64_t memory_size; /* the size of all physical memory */ | |
28641 | + uint64_t memory_start; /* the start of physical memory */ | |
28642 | + uint64_t memory_end; /* the end of physical memory */ | |
28643 | + uint32_t num_pages; /* number of pages in this dump */ | |
28644 | + uint32_t pad; /* ensure 8 byte alignment for tod and cpu_id */ | |
28645 | + uint64_t tod; /* the time of the dump generation */ | |
28646 | + uint64_t cpu_id; /* cpu id */ | |
28647 | + uint32_t arch_id; | |
28648 | + uint32_t build_arch_id; | |
28649 | +#define KL_DH_ARCH_ID_S390X 2 | |
28650 | +#define KL_DH_ARCH_ID_S390 1 | |
28651 | +} __attribute__((packed)) kl_dump_header_s390sa_t; | |
28652 | + | |
28653 | +/* Header associated to each physical page of memory saved in the system | |
28654 | + * crash dump. | |
28655 | + */ | |
28656 | +typedef struct kl_dump_page_s { | |
28657 | +#if DUMP_DEBUG >= 6 | |
28658 | + uint64_t byte_offset; /* byte offset */ | |
28659 | + uint64_t page_index; /* page index */ | |
28660 | +#endif | |
28661 | + uint64_t address; /* the address of this dump page */ | |
28662 | + uint32_t size; /* the size of this dump page */ | |
28663 | + uint32_t flags; /* flags (DUMP_COMPRESSED, DUMP_RAW or DUMP_END) */ | |
28664 | +} __attribute__((packed)) kl_dump_page_t; | |
28665 | + | |
28666 | +/* CORE_TYPE indicating type of dump | |
28667 | + */ | |
28668 | +typedef enum { | |
28669 | + dev_kmem, /* image of /dev/kmem, a running kernel */ | |
28670 | + reg_core, /* Regular (uncompressed) core file */ | |
28671 | + s390_core, /* s390 core file */ | |
28672 | + cmp_core, /* compressed core file */ | |
28673 | + unk_core /* unknown core type */ | |
28674 | +} CORE_TYPE; | |
28675 | + | |
28676 | +/* function to determine kernel stack for task */ | |
28677 | +typedef kaddr_t(*kl_kernelstack_t) (kaddr_t); | |
28678 | +/* map virtual address to physical one */ | |
28679 | +typedef int(*kl_virtop_t)(kaddr_t, void*, kaddr_t*); | |
28680 | +/* function to perform page-table traversal */ | |
28681 | +typedef kaddr_t(*kl_mmap_virtop_t)(kaddr_t, void*); | |
28682 | +/* XXX description */ | |
28683 | +typedef int(*kl_valid_physmem_t)(kaddr_t, int); | |
28684 | +/* XXX description */ | |
28685 | +typedef kaddr_t(*kl_next_valid_physaddr_t)(kaddr_t); | |
28686 | +/* write a dump-header-asm, if analyzing a live system */ | |
28687 | +typedef int(*kl_write_dump_header_asm_t)(void*); | |
28688 | +/* redirect addresses pointing into task_union areas for running tasks */ | |
28689 | +typedef kaddr_t(*kl_fix_vaddr_t)(kaddr_t, size_t); | |
28690 | +/* initialize mapping of virtual to physical addresses */ | |
28691 | +typedef int (*kl_init_virtop_t)(void); | |
28692 | + | |
28693 | +/* struct storing dump architecture specific values | |
28694 | + */ | |
28695 | +typedef struct kl_dumparch_s { | |
28696 | + int arch; /* KL_ARCH_ */ | |
28697 | + int ptrsz; /* 32 or 64 bit */ | |
28698 | + int byteorder; /* KL_LITTLE_ENDIAN or KL_BIG_ENDIAN */ | |
28699 | + uint64_t pageoffset; /* PAGE_OFFSET */ | |
28700 | + uint64_t kstacksize; /* size of kernel stack */ | |
28701 | + uint64_t pgdshift; /* PGDIR_SHIFT */ | |
28702 | + uint64_t pgdsize; /* PGDIR_SIZE */ | |
28703 | + uint64_t pgdmask; /* PGDIR_MASK */ | |
28704 | + uint64_t pmdshift; /* PMD_SHIFT */ | |
28705 | + uint64_t pmdsize; /* PMD_SIZE */ | |
28706 | + uint64_t pmdmask; /* PMD_MASK */ | |
28707 | + uint64_t pageshift; /* PAGE_SHIFT */ | |
28708 | + uint64_t pagesize; /* PAGE_SIZE */ | |
28709 | + uint64_t pagemask; /* PAGE_MASK */ | |
28710 | + uint32_t ptrsperpgd; /* PTRS_PER_PGD */ | |
28711 | + uint32_t ptrsperpmd; /* PTRS_PER_PMD */ | |
28712 | + uint32_t ptrsperpte; /* PTRS_PER_PTE */ | |
28713 | + kl_kernelstack_t kernelstack; /* determine kernel stack for task */ | |
28714 | + kl_virtop_t virtop; /* map virtual address to physical */ | |
28715 | + kl_mmap_virtop_t mmap_virtop; /* traverse page table */ | |
28716 | + kl_valid_physmem_t valid_physmem; /* XXX description */ | |
28717 | + kl_next_valid_physaddr_t next_valid_physaddr; /* XXX description */ | |
28718 | + kl_fix_vaddr_t fix_vaddr; /* XXX description */ | |
28719 | + uint32_t dha_size; /* size of kl_dump_header_xxx_t */ | |
28720 | + kl_write_dump_header_asm_t write_dha; /* XXX description */ | |
28721 | + kl_init_virtop_t init_virtop; /* init address translation */ | |
28722 | +} kl_dumparch_t; | |
28723 | + | |
28724 | +/* function types for dumpaccess */ | |
28725 | +typedef kaddr_t (*kl_get_ptr_t) (void*); | |
28726 | +typedef uint8_t (*kl_get_uint8_t) (void*); | |
28727 | +typedef uint16_t(*kl_get_uint16_t)(void*); | |
28728 | +typedef uint32_t(*kl_get_uint32_t)(void*); | |
28729 | +typedef uint64_t(*kl_get_uint64_t)(void*); | |
28730 | +/* function types for dumpaccess */ | |
28731 | +typedef kaddr_t (*kl_read_ptr_t) (kaddr_t); | |
28732 | +typedef uint8_t (*kl_read_uint8_t) (kaddr_t); | |
28733 | +typedef uint16_t (*kl_read_uint16_t)(kaddr_t); | |
28734 | +typedef uint32_t (*kl_read_uint32_t)(kaddr_t); | |
28735 | +typedef uint64_t (*kl_read_uint64_t)(kaddr_t); | |
28736 | + | |
28737 | +/* struct to store dump architecture specific functions | |
28738 | + */ | |
28739 | +typedef struct kl_dumpaccess_s { | |
28740 | + /* get integer value from memory, previously read from dump */ | |
28741 | + kl_get_ptr_t get_ptr; | |
28742 | + kl_get_uint8_t get_uint8; | |
28743 | + kl_get_uint16_t get_uint16; | |
28744 | + kl_get_uint32_t get_uint32; | |
28745 | + kl_get_uint64_t get_uint64; | |
28746 | + /* read integer value from dump (from physical address) */ | |
28747 | + kl_read_ptr_t read_ptr; | |
28748 | + kl_read_uint8_t read_uint8; | |
28749 | + kl_read_uint16_t read_uint16; | |
28750 | + kl_read_uint32_t read_uint32; | |
28751 | + kl_read_uint64_t read_uint64; | |
28752 | + /* read integer value from dump (from virtual address) */ | |
28753 | + kl_read_ptr_t vread_ptr; | |
28754 | + kl_read_uint8_t vread_uint8; | |
28755 | + kl_read_uint16_t vread_uint16; | |
28756 | + kl_read_uint32_t vread_uint32; | |
28757 | + kl_read_uint64_t vread_uint64; | |
28758 | +} kl_dumpaccess_t; | |
28759 | + | |
28760 | +/* Struct containing sizes of frequently used kernel structures. | |
28761 | + */ | |
28762 | +typedef struct struct_sizes_s { | |
28763 | + int task_struct_sz; | |
28764 | + int mm_struct_sz; | |
28765 | + int page_sz; | |
28766 | + int module_sz; | |
28767 | + int new_utsname_sz; | |
28768 | + int switch_stack_sz; | |
28769 | + int pt_regs_sz; | |
28770 | + int pglist_data_sz; | |
28771 | + int runqueue_sz; | |
28772 | +} struct_sizes_t; | |
28773 | + | |
28774 | +/* struct storing memory specifc values of the dumped Linux system | |
28775 | + */ | |
28776 | +typedef struct kl_kerninfo_s{ | |
28777 | + kaddr_t num_physpages; /* number of physical pages */ | |
28778 | + kaddr_t mem_map; /* XXX description */ | |
28779 | + kaddr_t high_memory; /* physical memory size */ | |
28780 | + kaddr_t init_mm; /* address of mm_struct init_mm */ | |
28781 | + uint64_t kernel_flags; /* to indicate kernel features | |
28782 | + * e.g. KL_IS_PAE_I386 on i386 */ | |
28783 | + int num_cpus; /* number of cpus */ | |
28784 | + kaddr_t pgdat_list; /* pgdat_list value. used as MEM_MAP */ | |
28785 | + /* not defined for DISCONTIG memory */ | |
28786 | + int linux_release; /* kernel release of dump */ | |
28787 | + struct_sizes_t struct_sizes; /* frequently needed struct sizes */ | |
28788 | +} kl_kerninfo_t; | |
28789 | + | |
28790 | +/* various flags to indicate Linux kernel compile switches */ | |
28791 | +#define KL_IS_PAE_I386 0x0020 /* i386 kernel with PAE support */ | |
28792 | + | |
28793 | +/* struct where to keep whole information about the dump | |
28794 | + */ | |
28795 | +typedef struct kl_dumpinfo_s { | |
28796 | + CORE_TYPE core_type; /* type of core file */ | |
28797 | + char *dump; /* pathname for dump */ | |
28798 | + char *map; /* pathname for map file */ | |
28799 | + int core_fd; /* file descriptor for dump file */ | |
28800 | + int rw_flag; /* O_RDONLY/O_RDWR (/dev/kmem only) */ | |
28801 | + kl_dumparch_t arch; /* dump arch info */ | |
28802 | + kl_dumpaccess_t func; /* dump access functions */ | |
28803 | + kl_kerninfo_t mem; /* mem info for dump */ | |
28804 | +} kl_dumpinfo_t; | |
28805 | + | |
28806 | +/* External declarations | |
28807 | + */ | |
28808 | +extern char *dh_typename; | |
28809 | +extern char *dha_typename; | |
28810 | +extern void *G_dump_header; | |
28811 | +extern void *G_dump_header_asm; | |
28812 | +extern kl_dump_header_t *KL_DUMP_HEADER; | |
28813 | +extern void *KL_DUMP_HEADER_ASM; | |
28814 | + | |
28815 | +/* function declarations | |
28816 | + */ | |
28817 | + | |
28818 | +/* open dump */ | |
28819 | +int kl_open_dump(void); | |
28820 | + | |
28821 | +/* init sizes for some structures */ | |
28822 | +void kl_init_struct_sizes(void); | |
28823 | + | |
28824 | +/* init host architecture information */ | |
28825 | +int kl_setup_hostinfo(void); | |
28826 | + | |
28827 | +/* init dumpinfo structure */ | |
28828 | +int kl_setup_dumpinfo(char * /* map file */, | |
28829 | + char * /* dump */, | |
28830 | + int /* rwflag */); | |
28831 | + | |
28832 | + | |
28833 | +/* init dumpinfo structure */ | |
28834 | +int kl_set_dumpinfo(char * /* map file */, | |
28835 | + char * /* dump */, | |
28836 | + int /* arch of dump */, | |
28837 | + int /* rwflag */); | |
28838 | + | |
28839 | +/* free dumpinfo structure */ | |
28840 | +void kl_free_dumpinfo(kl_dumpinfo_t *); | |
28841 | + | |
28842 | +/* set memory related characteristics of dump */ | |
28843 | +int kl_set_kerninfo(void); | |
28844 | + | |
28845 | +/* set function pointers for dump access (depends on host and dump arch) */ | |
28846 | +int kl_set_dumpaccess(void); | |
28847 | + | |
28848 | +/* print contents of kl_dumpinfo_t etc. */ | |
28849 | +int kl_print_dumpinfo(int); | |
28850 | +#define KL_INFO_ALL 0 | |
28851 | +#define KL_INFO_ENDIAN 1 | |
28852 | +#define KL_INFO_ARCH 2 | |
28853 | +#define KL_INFO_PTRSZ 3 | |
28854 | +#define KL_INFO_KRELEASE 4 | |
28855 | +#define KL_INFO_MEMSIZE 5 | |
28856 | +#define KL_INFO_NUMCPUS 6 | |
28857 | + | |
28858 | +/* Functions that read data from generic dump_header */ | |
28859 | +int kl_valid_dump_magic(uint64_t); | |
28860 | +int kl_header_swap(void *); | |
28861 | +uint64_t kl_header_magic(void *); | |
28862 | +int kl_valid_header(void *); | |
28863 | +uint32_t kl_header_version(void *); | |
28864 | +int kl_header_size(void *); | |
28865 | +void *kl_read_header(int fd, void *); | |
28866 | + | |
28867 | +/* init common lkcd dump header from dump */ | |
28868 | +void kl_init_dump_header(int); | |
28869 | + | |
28870 | +/* try to evalutate arch from lkcd 4.1 (version <= 7) dump header */ | |
28871 | +int kl_dump_arch_4_1(void *); | |
28872 | + | |
28873 | +/* swap dump header values if necessary */ | |
28874 | +void kl_swap_dump_header_reg(kl_dump_header_t* dh); | |
28875 | +void kl_swap_dump_header_s390sa(kl_dump_header_s390sa_t* dh); | |
28876 | + | |
28877 | +/* Read dump header in from dump */ | |
28878 | +int kl_read_dump_header(void); | |
28879 | +int kl_read_dump_header_asm(void); | |
28880 | + | |
28881 | +/* Determine the architecure of dump */ | |
28882 | +int kl_set_dumparch(int); | |
28883 | + | |
28884 | +/* Finish setting up for access to dump */ | |
28885 | +int kl_setup_dumpaccess(int); | |
28886 | + | |
28887 | +/* get the raw dump header */ | |
28888 | +int kl_get_raw_dh(int); | |
28889 | +int kl_get_raw_asm_dh(int); | |
28890 | + | |
28891 | +/* get common lkcd dump header */ | |
28892 | +int kl_get_dump_header(kl_dump_header_t*); | |
28893 | + | |
28894 | +/* get older style dump headers */ | |
28895 | +kl_dump_header_t *get_dump_header_4_1(void *); | |
28896 | +kl_dump_header_t *get_dump_header_SN2_24X(void *); | |
28897 | + | |
28898 | +/* get task that was running when dump was started */ | |
28899 | +kaddr_t kl_dumptask(void); | |
28900 | + | |
28901 | +/* Print dump header */ | |
28902 | +int kl_print_dump_header(const char* dump); | |
28903 | + | |
28904 | +/* Print dump regular header */ | |
28905 | +void kl_print_dump_header_reg(kl_dump_header_t *); | |
28906 | + | |
28907 | +/* Print s390 dump header */ | |
28908 | +void kl_print_dump_header_s390(char*); | |
28909 | + | |
28910 | +/* Convert s390 to reg header */ | |
28911 | +void kl_s390sa_to_reg_header(kl_dump_header_s390sa_t*, kl_dump_header_t*); | |
28912 | + | |
28913 | +/* Byte swapping functions needed for Xclrash */ | |
28914 | +/* get integer value from buffer and swap bytes */ | |
28915 | +kaddr_t kl_get_swap_ptr(void*); | |
28916 | +uint16_t kl_get_swap_uint16(void*); | |
28917 | +uint32_t kl_get_swap_uint32(void*); | |
28918 | +uint64_t kl_get_swap_uint64(void*); | |
28919 | + | |
28920 | +/* read integer value from dump (physical address) and swap bytes */ | |
28921 | +kaddr_t kl_read_swap_ptr(kaddr_t); | |
28922 | +uint16_t kl_read_swap_uint16(kaddr_t); | |
28923 | +uint32_t kl_read_swap_uint32(kaddr_t); | |
28924 | +uint64_t kl_read_swap_uint64(kaddr_t); | |
28925 | + | |
28926 | +/* read integer value from dump (virtual address) and swap bytes */ | |
28927 | +kaddr_t kl_vread_swap_ptr(kaddr_t); | |
28928 | +uint16_t kl_vread_swap_uint16(kaddr_t); | |
28929 | +uint32_t kl_vread_swap_uint32(kaddr_t); | |
28930 | +uint64_t kl_vread_swap_uint64(kaddr_t); | |
28931 | + | |
28932 | +#endif /* __KL_DUMP_H */ | |
28933 | --- /dev/null | |
28934 | +++ b/kdb/modules/lcrash/kl_dump_arch.h | |
28935 | @@ -0,0 +1,124 @@ | |
28936 | +/* | |
28937 | + * $Id: kl_dump_arch.h 1122 2004-12-21 23:26:23Z tjm $ | |
28938 | + * | |
28939 | + * This file is part of libklib. | |
28940 | + * A library which provides access to Linux system kernel dumps. | |
28941 | + * | |
28942 | + * Created by Silicon Graphics, Inc. | |
28943 | + * Contributions by IBM, NEC, and others | |
28944 | + * | |
28945 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
28946 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
28947 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
28948 | + * | |
28949 | + * This code is free software; you can redistribute it and/or modify | |
28950 | + * it under the terms of the GNU Lesser Public License as published by | |
28951 | + * the Free Software Foundation; either version 2.1 of the License, or | |
28952 | + * (at your option) any later version. See the file COPYING for more | |
28953 | + * information. | |
28954 | + */ | |
28955 | + | |
28956 | +#ifndef __KL_DUMP_ARCH_H | |
28957 | +#define __KL_DUMP_ARCH_H | |
28958 | + | |
28959 | +/* check for valid configuration | |
28960 | + */ | |
28961 | +#if !(defined(HOST_ARCH_ALPHA) || defined(HOST_ARCH_I386) || \ | |
28962 | + defined(HOST_ARCH_IA64) || defined(HOST_ARCH_S390) || \ | |
28963 | + defined(HOST_ARCH_S390X) || defined(HOST_ARCH_ARM) || \ | |
28964 | + defined(HOST_ARCH_PPC64) || defined(HOST_ARCH_X86_64)) | |
28965 | +# error "No valid host architecture defined." | |
28966 | +#endif | |
28967 | +#if ((defined(HOST_ARCH_ALPHA) && \ | |
28968 | + (defined(HOST_ARCH_I386) || defined(HOST_ARCH_IA64) || \ | |
28969 | + defined(HOST_ARCH_S390) || defined(HOST_ARCH_S390X) || \ | |
28970 | + defined(HOST_ARCH_ARM) || defined(HOST_ARCH_PPC64) || \ | |
28971 | + defined(HOST_ARCH_X86_64))) || \ | |
28972 | + (defined(HOST_ARCH_I386) && \ | |
28973 | + (defined(HOST_ARCH_IA64) || defined(HOST_ARCH_S390) || \ | |
28974 | + defined(HOST_ARCH_S390X)|| defined(HOST_ARCH_ARM) || \ | |
28975 | + defined(HOST_ARCH_PPC64)|| defined(HOST_ARCH_X86_64))) || \ | |
28976 | + (defined(HOST_ARCH_IA64) && \ | |
28977 | + (defined(HOST_ARCH_S390)|| defined(HOST_ARCH_S390X) || \ | |
28978 | + defined(HOST_ARCH_ARM) || defined(HOST_ARCH_PPC64) || \ | |
28979 | + defined(HOST_ARCH_X86_64))) || \ | |
28980 | + (defined(HOST_ARCH_S390) && \ | |
28981 | + (defined(HOST_ARCH_S390X) || defined(HOST_ARCH_ARM) || \ | |
28982 | + defined(HOST_ARCH_PPC64) || defined(HOST_ARCH_X86_64))) || \ | |
28983 | + (defined(HOST_ARCH_S390X) && \ | |
28984 | + (defined(HOST_ARCH_ARM) || defined(HOST_ARCH_PPC64) || \ | |
28985 | + defined(HOST_ARCH_X86_64))) || \ | |
28986 | + (defined(HOST_ARCH_ARM) && \ | |
28987 | + (defined(HOST_ARCH_PPC64) || defined(HOST_ARCH_X86_64))) || \ | |
28988 | + (defined(HOST_ARCH_PPC64) && defined(HOST_ARCH_X86_64))) | |
28989 | +# error "More than one valid host architectures defined." | |
28990 | +#endif | |
28991 | +#if !(defined(DUMP_ARCH_ALPHA) || defined(DUMP_ARCH_I386) || \ | |
28992 | + defined(DUMP_ARCH_IA64) || defined(DUMP_ARCH_S390) || \ | |
28993 | + defined(DUMP_ARCH_S390X) || defined(DUMP_ARCH_ARM) || \ | |
28994 | + defined(DUMP_ARCH_PPC64) || defined(DUMP_ARCH_X86_64)) | |
28995 | +# error "No valid dump architecture defined." | |
28996 | +#endif | |
28997 | + | |
28998 | +/* optional: check that host arch equals one supported dump arch | |
28999 | + */ | |
29000 | +#ifdef SUPPORT_HOST_ARCH | |
29001 | +# if (defined(HOST_ARCH_ALPHA) && !defined(DUMP_ARCH_ALPHA)) || \ | |
29002 | + (defined(HOST_ARCH_I386) && !defined(DUMP_ARCH_I386)) || \ | |
29003 | + (defined(HOST_ARCH_IA64) && !defined(DUMP_ARCH_IA64)) || \ | |
29004 | + (defined(HOST_ARCH_S390) && !defined(DUMP_ARCH_S390)) || \ | |
29005 | + (defined(HOST_ARCH_S390X) && !defined(DUMP_ARCH_S390X)) || \ | |
29006 | + (defined(HOST_ARCH_ARM) && !defined(DUMP_ARCH_ARM)) || \ | |
29007 | + (defined(HOST_ARCH_PPC64) && !defined(DUMP_ARCH_PPC64)) || \ | |
29008 | + (defined(HOST_ARCH_X86_64) && !defined(DUMP_ARCH_X86_64)) | |
29009 | +# error "Host architecture not supported as dump architecture." | |
29010 | +# endif | |
29011 | +#endif | |
29012 | + | |
29013 | +/* include dump architecture specific stuff | |
29014 | + */ | |
29015 | +#ifdef DUMP_ARCH_ALPHA | |
29016 | +# include <kl_mem_alpha.h> | |
29017 | +# include <kl_dump_alpha.h> | |
29018 | +#endif | |
29019 | +/* cpw: use the " " form: */ | |
29020 | +#ifdef DUMP_ARCH_IA64 | |
29021 | +# include "kl_mem_ia64.h" | |
29022 | +# include "kl_dump_ia64.h" | |
29023 | +#endif | |
29024 | +#ifdef DUMP_ARCH_I386 | |
29025 | +# include <kl_mem_i386.h> | |
29026 | +# include <kl_dump_i386.h> | |
29027 | +#endif | |
29028 | +#ifdef DUMP_ARCH_S390 | |
29029 | +# include <kl_mem_s390.h> | |
29030 | +# include <kl_dump_s390.h> | |
29031 | +#endif | |
29032 | +#ifdef DUMP_ARCH_S390X | |
29033 | +# include <kl_mem_s390x.h> | |
29034 | +# include <kl_dump_s390.h> | |
29035 | +#endif | |
29036 | +#ifdef DUMP_ARCH_ARM | |
29037 | +# include <kl_mem_arm.h> | |
29038 | +# include <kl_dump_arm.h> | |
29039 | +#endif | |
29040 | +#ifdef DUMP_ARCH_PPC64 | |
29041 | +#include <kl_mem_ppc64.h> | |
29042 | +#include <kl_dump_ppc64.h> | |
29043 | +#endif | |
29044 | +#ifdef DUMP_ARCH_X86_64 | |
29045 | +#include <kl_mem_x86_64.h> | |
29046 | +#include <kl_dump_x86_64.h> | |
29047 | +#endif | |
29048 | + | |
29049 | +/** Function prototypes | |
29050 | + **/ | |
29051 | +int kl_init_kern_info(void); | |
29052 | + | |
29053 | +int kl_get_struct( | |
29054 | + kaddr_t /* address */, | |
29055 | + int /* size of struct */, | |
29056 | + void * /* ptr to buffer */, | |
29057 | + char * /* name of struct */); | |
29058 | + | |
29059 | +#endif /* __KL_DUMP_ARCH_H */ | |
29060 | --- /dev/null | |
29061 | +++ b/kdb/modules/lcrash/kl_dump_ia64.h | |
29062 | @@ -0,0 +1,199 @@ | |
29063 | +/* | |
29064 | + * $Id: kl_dump_ia64.h 1151 2005-02-23 01:09:12Z tjm $ | |
29065 | + * | |
29066 | + * This file is part of libklib. | |
29067 | + * A library which provides access to Linux system kernel dumps. | |
29068 | + * | |
29069 | + * Created by Silicon Graphics, Inc. | |
29070 | + * Contributions by IBM, NEC, and others | |
29071 | + * | |
29072 | + * Copyright (C) 1999 - 2005 Silicon Graphics, Inc. All rights reserved. | |
29073 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
29074 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
29075 | + * | |
29076 | + * This code is free software; you can redistribute it and/or modify | |
29077 | + * it under the terms of the GNU Lesser Public License as published by | |
29078 | + * the Free Software Foundation; either version 2.1 of the License, or | |
29079 | + * (at your option) any later version. See the file COPYING for more | |
29080 | + * information. | |
29081 | + */ | |
29082 | + | |
29083 | +/* This header file holds the architecture specific crash dump header */ | |
29084 | +#ifndef __KL_DUMP_IA64_H | |
29085 | +#define __KL_DUMP_IA64_H | |
29086 | + | |
29087 | +/* definitions */ | |
29088 | +#ifndef KL_NR_CPUS | |
29089 | +# define KL_NR_CPUS 128 /* max number CPUs */ | |
29090 | +#endif | |
29091 | + | |
29092 | +#define KL_DUMP_MAGIC_NUMBER_IA64 0xdeaddeadULL /* magic number */ | |
29093 | +#define KL_DUMP_VERSION_NUMBER_IA64 0x4 /* version number */ | |
29094 | + | |
29095 | + | |
29096 | +/* | |
29097 | + * mkswap.c calls getpagesize() to get the system page size, | |
29098 | + * which is not necessarily the same as the hardware page size. | |
29099 | + * | |
29100 | + * For ia64 the kernel PAGE_SIZE can be configured from 4KB ... 16KB. | |
29101 | + * | |
29102 | + * The physical memory is layed out out in the hardware/minimal pages. | |
29103 | + * This is the size we need to use for dumping physical pages. | |
29104 | + * | |
29105 | + * Note ths hardware/minimal page size being use in; | |
29106 | + * arch/ia64/kernel/efi.c`efi_memmap_walk(): | |
29107 | + * curr.end = curr.start + (md->num_pages << 12); | |
29108 | + * | |
29109 | + * Since the system page size could change between the kernel we boot | |
29110 | + * on the the kernel that cause the core dume we may want to have something | |
29111 | + * more constant like the maximum system page size (See include/asm-ia64/page.h). | |
29112 | + */ | |
29113 | +#define DUMP_MIN_PAGE_SHIFT 12 | |
29114 | +#define DUMP_MIN_PAGE_SIZE (1UL << DUMP_MIN_PAGE_SHIFT) | |
29115 | +#define DUMP_MIN_PAGE_MASK (~(DUMP_MIN_PAGE_SIZE - 1)) | |
29116 | +#define DUMP_MIN_PAGE_ALIGN(addr) (((addr) + DUMP_MIN_PAGE_SIZE - 1) & DUMP_MIN_PAGE_MASK) | |
29117 | + | |
29118 | +#define DUMP_MAX_PAGE_SHIFT 16 | |
29119 | +#define DUMP_MAX_PAGE_SIZE (1UL << DUMP_MAX_PAGE_SHIFT) | |
29120 | +#define DUMP_MAX_PAGE_MASK (~(DUMP_MAX_PAGE_SIZE - 1)) | |
29121 | +#define DUMP_MAX_PAGE_ALIGN(addr) (((addr) + DUMP_MAX_PAGE_SIZE - 1) & DUMP_MAX_PAGE_MASK) | |
29122 | + | |
29123 | +#define DUMP_HEADER_OFFSET DUMP_MAX_PAGE_SIZE | |
29124 | + | |
29125 | +#define DUMP_EF_PAGE_SHIFT DUMP_MIN_PAGE_SHIFT | |
29126 | + | |
29127 | +#define DUMP_PAGE_SHIFT DUMP_MIN_PAGE_SHIFT | |
29128 | +#define DUMP_PAGE_SIZE DUMP_MIN_PAGE_SIZE | |
29129 | +#define DUMP_PAGE_MASK DUMP_MIN_PAGE_MASK | |
29130 | +#define DUMP_PAGE_ALIGN(addr) DUMP_MIN_PAGE_ALIGN(addr) | |
29131 | + | |
29132 | +struct kl_ia64_fpreg { | |
29133 | + union { | |
29134 | + unsigned long bits[2]; | |
29135 | + long double __dummy; /* force 16-byte alignment */ | |
29136 | + } u; | |
29137 | +}; | |
29138 | + | |
29139 | +struct kl_pt_regs_ia64 { | |
29140 | + /* for 2.6 kernels only. This structure was totally different in 2.4 kernels */ | |
29141 | + unsigned long b6; /* scratch */ | |
29142 | + unsigned long b7; /* scratch */ | |
29143 | + | |
29144 | + unsigned long ar_csd; /* used by cmp8xchg16 (scratch) */ | |
29145 | + unsigned long ar_ssd; /* reserved for future use (scratch) */ | |
29146 | + | |
29147 | + unsigned long r8; /* scratch (return value register 0) */ | |
29148 | + unsigned long r9; /* scratch (return value register 1) */ | |
29149 | + unsigned long r10; /* scratch (return value register 2) */ | |
29150 | + unsigned long r11; /* scratch (return value register 3) */ | |
29151 | + | |
29152 | + unsigned long cr_ipsr; /* interrupted task's psr */ | |
29153 | + unsigned long cr_iip; /* interrupted task's instruction pointer */ | |
29154 | + unsigned long cr_ifs; /* interrupted task's function state */ | |
29155 | + | |
29156 | + unsigned long ar_unat; /* interrupted task's NaT register (preserved) */ | |
29157 | + unsigned long ar_pfs; /* prev function state */ | |
29158 | + unsigned long ar_rsc; /* RSE configuration */ | |
29159 | + /* The following two are valid only if cr_ipsr.cpl > 0: */ | |
29160 | + unsigned long ar_rnat; /* RSE NaT */ | |
29161 | + unsigned long ar_bspstore; /* RSE bspstore */ | |
29162 | + | |
29163 | + unsigned long pr; /* 64 predicate registers (1 bit each) */ | |
29164 | + unsigned long b0; /* return pointer (bp) */ | |
29165 | + unsigned long loadrs; /* size of dirty partition << 16 */ | |
29166 | + | |
29167 | + unsigned long r1; /* the gp pointer */ | |
29168 | + unsigned long r12; /* interrupted task's memory stack pointer */ | |
29169 | + unsigned long r13; /* thread pointer */ | |
29170 | + | |
29171 | + unsigned long ar_fpsr; /* floating point status (preserved) */ | |
29172 | + unsigned long r15; /* scratch */ | |
29173 | + | |
29174 | + /* The remaining registers are NOT saved for system calls. */ | |
29175 | + | |
29176 | + unsigned long r14; /* scratch */ | |
29177 | + unsigned long r2; /* scratch */ | |
29178 | + unsigned long r3; /* scratch */ | |
29179 | + | |
29180 | + /* The following registers are saved by SAVE_REST: */ | |
29181 | + unsigned long r16; /* scratch */ | |
29182 | + unsigned long r17; /* scratch */ | |
29183 | + unsigned long r18; /* scratch */ | |
29184 | + unsigned long r19; /* scratch */ | |
29185 | + unsigned long r20; /* scratch */ | |
29186 | + unsigned long r21; /* scratch */ | |
29187 | + unsigned long r22; /* scratch */ | |
29188 | + unsigned long r23; /* scratch */ | |
29189 | + unsigned long r24; /* scratch */ | |
29190 | + unsigned long r25; /* scratch */ | |
29191 | + unsigned long r26; /* scratch */ | |
29192 | + unsigned long r27; /* scratch */ | |
29193 | + unsigned long r28; /* scratch */ | |
29194 | + unsigned long r29; /* scratch */ | |
29195 | + unsigned long r30; /* scratch */ | |
29196 | + unsigned long r31; /* scratch */ | |
29197 | + | |
29198 | + unsigned long ar_ccv; /* compare/exchange value (scratch) */ | |
29199 | + | |
29200 | + /* | |
29201 | + * * Floating point registers that the kernel considers scratch: | |
29202 | + * */ | |
29203 | + struct kl_ia64_fpreg f6; /* scratch */ | |
29204 | + struct kl_ia64_fpreg f7; /* scratch */ | |
29205 | + struct kl_ia64_fpreg f8; /* scratch */ | |
29206 | + struct kl_ia64_fpreg f9; /* scratch */ | |
29207 | + struct kl_ia64_fpreg f10; /* scratch */ | |
29208 | + struct kl_ia64_fpreg f11; /* scratch */ | |
29209 | +} __attribute__((packed)); | |
29210 | + | |
29211 | +/* | |
29212 | + * Structure: dump_header_asm_t | |
29213 | + * Function: This is the header for architecture-specific stuff. It | |
29214 | + * follows right after the dump header. | |
29215 | + */ | |
29216 | +typedef struct kl_dump_header_ia64_s { | |
29217 | + /* the dump magic number -- unique to verify dump is valid */ | |
29218 | + uint64_t magic_number; | |
29219 | + /* the version number of this dump */ | |
29220 | + uint32_t version; | |
29221 | + /* the size of this header (in case we can't read it) */ | |
29222 | + uint32_t header_size; | |
29223 | + /* pointer to pt_regs */ | |
29224 | + uint64_t pt_regs; | |
29225 | + /* the dump registers */ | |
29226 | + struct kl_pt_regs_ia64 regs; | |
29227 | + /* the rnat register saved after flushrs */ | |
29228 | + uint64_t rnat; | |
29229 | + /* the pfs register saved after flushrs */ | |
29230 | + uint64_t pfs; | |
29231 | + /* the bspstore register saved after flushrs */ | |
29232 | + uint64_t bspstore; | |
29233 | + | |
29234 | + /* smp specific */ | |
29235 | + uint32_t smp_num_cpus; | |
29236 | + uint32_t dumping_cpu; | |
29237 | + struct kl_pt_regs_ia64 smp_regs[KL_NR_CPUS]; | |
29238 | + uint64_t smp_current_task[KL_NR_CPUS]; | |
29239 | + uint64_t stack[KL_NR_CPUS]; | |
29240 | +} __attribute__((packed)) kl_dump_header_ia64_t; | |
29241 | + | |
29242 | +/* The following struct is used just to calculate the size needed | |
29243 | + * to store per CPU info. (Make sure it is sync with the above struct) | |
29244 | + */ | |
29245 | +struct kl_dump_CPU_info_ia64 { | |
29246 | + struct kl_pt_regs_ia64 smp_regs; | |
29247 | + uint64_t smp_current_task; | |
29248 | + uint64_t stack; | |
29249 | +} __attribute__((packed)); | |
29250 | + | |
29251 | +/* function declarations | |
29252 | + */ | |
29253 | +int kl_set_dumparch_ia64(void); | |
29254 | +uint32_t dha_num_cpus_ia64(void); | |
29255 | +kaddr_t dha_current_task_ia64(int cpuid); | |
29256 | +int dha_cpuid_ia64(kaddr_t); | |
29257 | +kaddr_t dha_stack_ia64(int); | |
29258 | +kaddr_t dha_stack_ptr_ia64(int); | |
29259 | +int kl_read_dump_header_ia64(void); | |
29260 | + | |
29261 | +#endif /* __KL_DUMP_IA64_H */ | |
29262 | --- /dev/null | |
29263 | +++ b/kdb/modules/lcrash/kl_dwarfs.h | |
29264 | @@ -0,0 +1,27 @@ | |
29265 | +/* | |
29266 | + * $Id: kl_dwarfs.h 1122 2004-12-21 23:26:23Z tjm $ | |
29267 | + * | |
29268 | + * This file is part of libklib. | |
29269 | + * A library which provides access to Linux system kernel dumps. | |
29270 | + * | |
29271 | + * Created by: Prashanth Tamraparni (prasht@in.ibm.com) | |
29272 | + * Contributions by SGI | |
29273 | + * | |
29274 | + * Copyright (C) 2004 International Business Machines Corp. | |
29275 | + * Copyright (C) 2004 Silicon Graphics, Inc. All rights reserved. | |
29276 | + * | |
29277 | + * This code is free software; you can redistribute it and/or modify | |
29278 | + * it under the terms of the GNU Lesser Public License as published by | |
29279 | + * the Free Software Foundation; either version 2.1 of the License, or | |
29280 | + * (at your option) any later version. See the file COPYING for more | |
29281 | + * information. | |
29282 | + */ | |
29283 | +#ifndef __KL_DWARFS_H | |
29284 | +#define __KL_DWARFS_H | |
29285 | + | |
29286 | +/* Dwarf function declarations */ | |
29287 | + | |
29288 | +int dw_open_namelist(char*, int); | |
29289 | +int dw_setup_typeinfo(void); | |
29290 | + | |
29291 | +#endif /* __KL_DWARFS_H */ | |
29292 | --- /dev/null | |
29293 | +++ b/kdb/modules/lcrash/kl_error.h | |
29294 | @@ -0,0 +1,266 @@ | |
29295 | +/* | |
29296 | + * $Id: kl_error.h 1169 2005-03-02 21:38:01Z tjm $ | |
29297 | + * | |
29298 | + * This file is part of libklib. | |
29299 | + * A library which provides access to Linux system kernel dumps. | |
29300 | + * | |
29301 | + * Created by Silicon Graphics, Inc. | |
29302 | + * Contributions by IBM, NEC, and others | |
29303 | + * | |
29304 | + * Copyright (C) 1999 - 2005 Silicon Graphics, Inc. All rights reserved. | |
29305 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
29306 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
29307 | + * | |
29308 | + * This code is free software; you can redistribute it and/or modify | |
29309 | + * it under the terms of the GNU Lesser Public License as published by | |
29310 | + * the Free Software Foundation; either version 2.1 of the License, or | |
29311 | + * (at your option) any later version. See the file COPYING for more | |
29312 | + * information. | |
29313 | + */ | |
29314 | + | |
29315 | +#ifndef __KL_ERROR_H | |
29316 | +#define __KL_ERROR_H | |
29317 | + | |
29318 | +extern uint64_t klib_error; | |
29319 | +extern FILE *kl_stdout; | |
29320 | +extern FILE *kl_stderr; | |
29321 | + | |
29322 | +/* Error Classes | |
29323 | + */ | |
29324 | +#define KLEC_APP 0 | |
29325 | +#define KLEC_KLIB 1 | |
29326 | +#define KLEC_MEM 2 | |
29327 | +#define KLEC_SYM 3 | |
29328 | +#define KLEC_KERN 4 | |
29329 | + | |
29330 | +#define KLEC_CLASS_MASK 0x00000000ff000000ULL | |
29331 | +#define KLEC_CLASS_SHIFT 24 | |
29332 | +#define KLEC_ECODE_MASK 0x0000000000ffffffULL | |
29333 | +#define KLEC_TYPE_MASK 0xffffffff00000000ULL | |
29334 | +#define KLEC_TYPE_SHIFT 32 | |
29335 | +#define KLEC_CLASS(e) ((e & KLEC_CLASS_MASK) >> KLEC_CLASS_SHIFT) | |
29336 | +#define KLEC_ECODE(e) (e & KLEC_ECODE_MASK) | |
29337 | +#define KLEC_TYPE(e) ((e & KLEC_TYPE_MASK) >> KLEC_TYPE_SHIFT) | |
29338 | + | |
29339 | +void kl_reset_error(void); /* reset klib_error */ | |
29340 | +void kl_print_error(void); /* print warning/error messages */ | |
29341 | +void kl_check_error(char*); /* check for/handle errors, generate messages */ | |
29342 | + | |
29343 | +/* FIXME: not used yet -- for changes in future, improve error handling | |
29344 | + */ | |
29345 | +typedef struct klib_error_s{ | |
29346 | + uint32_t code; /* error code */ | |
29347 | + uint16_t class; /* error class */ | |
29348 | + uint16_t severity; /* severity of error: e.g. warning or fatal error */ | |
29349 | + uint32_t datadesc; /* description of data which caused the error */ | |
29350 | + FILE *fp; /* fp where to place warning and error messages */ | |
29351 | +} klib_error_t; | |
29352 | + | |
29353 | +/* | |
29354 | + * Some macros for accessing data in klib_error | |
29355 | + */ | |
29356 | +#define KL_ERROR klib_error | |
29357 | +#define KL_ERRORFP kl_stderr | |
29358 | + | |
29359 | +/* Error codes | |
29360 | + * | |
29361 | + * There are basically two types of error codes -- with each type | |
29362 | + * residing in a single word in a two word error code value. The lower | |
29363 | + * 32-bits contains an error class and code that represents exactly | |
29364 | + * WHAT error occurred (e.g., non-numeric text in a numeric value | |
29365 | + * entered by a user, bad virtual address, etc.). | |
29366 | + * | |
29367 | + * The upper 32-bits represents what type of data was being referenced | |
29368 | + * when the error occurred (e.g., bad proc struct). Having two tiers of | |
29369 | + * error codes makes it easier to generate useful and specific error | |
29370 | + * messages. Note that is possible to have situations where one or the | |
29371 | + * other type of error codes is not set. This is OK as long as at least | |
29372 | + * one type s set. | |
29373 | + */ | |
29374 | + | |
29375 | +/* General klib error codes | |
29376 | + */ | |
29377 | +#define KLE_KLIB (KLEC_KLIB << KLEC_CLASS_SHIFT) | |
29378 | +#define KLE_NO_MEMORY (KLE_KLIB|1) | |
29379 | +#define KLE_OPEN_ERROR (KLE_KLIB|2) | |
29380 | +#define KLE_ZERO_BLOCK (KLE_KLIB|3) | |
29381 | +#define KLE_INVALID_VALUE (KLE_KLIB|4) | |
29382 | +#define KLE_NULL_BUFF (KLE_KLIB|5) | |
29383 | +#define KLE_ZERO_SIZE (KLE_KLIB|6) | |
29384 | +#define KLE_ACTIVE (KLE_KLIB|7) | |
29385 | +#define KLE_NULL_POINTER (KLE_KLIB|8) | |
29386 | +#define KLE_UNSUPPORTED_ARCH (KLE_KLIB|9) | |
29387 | + | |
29388 | +#define KLE_MISC_ERROR (KLE_KLIB|97) | |
29389 | +#define KLE_NOT_SUPPORTED (KLE_KLIB|98) | |
29390 | +#define KLE_UNKNOWN_ERROR (KLE_KLIB|99) | |
29391 | + | |
29392 | +/* memory error codes | |
29393 | + */ | |
29394 | +#define KLE_MEM (KLEC_MEM << KLEC_CLASS_SHIFT) | |
29395 | +#define KLE_BAD_MAP_FILE (KLE_MEM|1) | |
29396 | +#define KLE_BAD_DUMP (KLE_MEM|2) | |
29397 | +#define KLE_BAD_DUMPTYPE (KLE_MEM|3) | |
29398 | +#define KLE_INVALID_LSEEK (KLE_MEM|4) | |
29399 | +#define KLE_INVALID_READ (KLE_MEM|5) | |
29400 | +#define KLE_BAD_KERNINFO (KLE_MEM|6) | |
29401 | +#define KLE_INVALID_PADDR (KLE_MEM|7) | |
29402 | +#define KLE_INVALID_VADDR (KLE_MEM|8) | |
29403 | +#define KLE_INVALID_VADDR_ALIGN (KLE_MEM|9) | |
29404 | +#define KLE_INVALID_MAPPING (KLE_MEM|10) | |
29405 | +#define KLE_CMP_ERROR (KLE_MEM|11) | |
29406 | +#define KLE_INVALID_DUMP_MAGIC (KLE_MEM|12) | |
29407 | +#define KLE_KERNEL_MAGIC_MISMATCH (KLE_MEM|13) | |
29408 | +#define KLE_NO_END_SYMBOL (KLE_MEM|14) | |
29409 | +#define KLE_INVALID_DUMP_HEADER (KLE_MEM|15) | |
29410 | +#define KLE_DUMP_INDEX_CREATION (KLE_MEM|16) | |
29411 | +#define KLE_DUMP_HEADER_ONLY (KLE_MEM|17) | |
29412 | +#define KLE_PAGE_NOT_PRESENT (KLE_MEM|18) | |
29413 | +#define KLE_BAD_ELF_FILE (KLE_MEM|19) | |
29414 | +#define KLE_ARCHIVE_FILE (KLE_MEM|20) | |
29415 | +#define KLE_MAP_FILE_PRESENT (KLE_MEM|21) | |
29416 | +#define KLE_BAD_MAP_FILENAME (KLE_MEM|22) | |
29417 | +#define KLE_BAD_DUMP_FILENAME (KLE_MEM|23) | |
29418 | +#define KLE_BAD_NAMELIST_FILE (KLE_MEM|24) | |
29419 | +#define KLE_BAD_NAMELIST_FILENAME (KLE_MEM|25) | |
29420 | +#define KLE_LIVE_SYSTEM (KLE_MEM|26) | |
29421 | +#define KLE_NOT_INITIALIZED (KLE_MEM|27) | |
29422 | + | |
29423 | +/* symbol error codes | |
29424 | + */ | |
29425 | +#define KLE_SYM (KLEC_SYM << KLEC_CLASS_SHIFT) | |
29426 | +#define KLE_NO_SYMTAB (KLE_SYM|1) | |
29427 | +#define KLE_NO_SYMBOLS (KLE_SYM|2) | |
29428 | +#define KLE_INVALID_TYPE (KLE_SYM|3) | |
29429 | +#define KLE_NO_MODULE_LIST (KLE_SYM|4) | |
29430 | + | |
29431 | +/* kernel data error codes | |
29432 | + */ | |
29433 | +#define KLE_KERN (KLEC_KERN << KLEC_CLASS_SHIFT) | |
29434 | +#define KLE_INVALID_KERNELSTACK (KLE_KERN|1) | |
29435 | +#define KLE_INVALID_STRUCT_SIZE (KLE_KERN|2) | |
29436 | +#define KLE_BEFORE_RAM_OFFSET (KLE_KERN|3) | |
29437 | +#define KLE_AFTER_MAXPFN (KLE_KERN|4) | |
29438 | +#define KLE_AFTER_PHYSMEM (KLE_KERN|5) | |
29439 | +#define KLE_AFTER_MAXMEM (KLE_KERN|6) | |
29440 | +#define KLE_PHYSMEM_NOT_INSTALLED (KLE_KERN|7) | |
29441 | +#define KLE_NO_DEFTASK (KLE_KERN|8) | |
29442 | +#define KLE_PID_NOT_FOUND (KLE_KERN|9) | |
29443 | +#define KLE_DEFTASK_NOT_ON_CPU (KLE_KERN|10) | |
29444 | +#define KLE_NO_CURCPU (KLE_KERN|11) | |
29445 | +#define KLE_NO_CPU (KLE_KERN|12) | |
29446 | +#define KLE_SIG_ERROR (KLE_KERN|13) | |
29447 | +#define KLE_TASK_RUNNING (KLE_KERN|14) | |
29448 | +#define KLE_NO_SWITCH_STACK (KLE_KERN|15) | |
29449 | + | |
29450 | +/* Error codes that indicate what type of data was bad. These are | |
29451 | + * placed in the upper 32-bits of klib_error. | |
29452 | + */ | |
29453 | +#define KLE_BAD_TASK_STRUCT (((uint64_t)1)<<32) | |
29454 | +#define KLE_BAD_SYMNAME (((uint64_t)2)<<32) | |
29455 | +#define KLE_BAD_SYMADDR (((uint64_t)3)<<32) | |
29456 | +#define KLE_BAD_FUNCADDR (((uint64_t)4)<<32) | |
29457 | +#define KLE_BAD_STRUCT (((uint64_t)5)<<32) | |
29458 | +#define KLE_BAD_FIELD (((uint64_t)6)<<32) | |
29459 | +#define KLE_BAD_PC (((uint64_t)7)<<32) | |
29460 | +#define KLE_BAD_RA (((uint64_t)8)<<32) | |
29461 | +#define KLE_BAD_SP (((uint64_t)9)<<32) | |
29462 | +#define KLE_BAD_EP (((uint64_t)10)<<32) | |
29463 | +#define KLE_BAD_SADDR (((uint64_t)11)<<32) | |
29464 | +#define KLE_BAD_KERNELSTACK (((uint64_t)12)<<32) | |
29465 | +#define KLE_BAD_LINENO (((uint64_t)13)<<32) | |
29466 | +#define KLE_MAP_FILE (((uint64_t)14)<<32) | |
29467 | +#define KLE_DUMP (((uint64_t)15)<<32) | |
29468 | +#define KLE_BAD_STRING (((uint64_t)16)<<32) | |
29469 | +#define KLE_ELF_FILE (((uint64_t)17)<<32) | |
29470 | + | |
29471 | +/* flags for function kl_msg() | |
29472 | + * First 3 bits define trace levels. Minimum trace threshold is trace level 1. | |
29473 | + * So maximal 7 trace levels are possible. We are using only KLE_TRACELEVEL_MAX. | |
29474 | + * If no trace level bits are set, it is normal output. | |
29475 | + */ | |
29476 | +#define _KLE_TRACEBIT1 0x00000001 /* trace bit 1 */ | |
29477 | +#define _KLE_TRACEBIT2 0x00000002 /* trace bit 2 */ | |
29478 | +#define _KLE_TRACEBIT3 0x00000004 /* trace bit 3 */ | |
29479 | +#define _KLE_TRACENUM 8 /* used in _KLE_TRACENUM */ | |
29480 | +#define _KLE_TRACEMASK (_KLE_TRACENUM-1) /* mask for trace bits */ | |
29481 | +/* further flags */ | |
29482 | +#define KLE_F_NOORIGIN 0x00001000 /* do not print origin for this msg */ | |
29483 | +#define KLE_F_ERRORMSG 0x00002000 /* treat message as error message */ | |
29484 | +/* trace levels := predefined combinations of trace bits */ | |
29485 | +#define KLE_F_TRACELEVEL1 (_KLE_TRACEBIT1) | |
29486 | +#define KLE_F_TRACELEVEL2 (_KLE_TRACEBIT2) | |
29487 | +#define KLE_F_TRACELEVEL3 (_KLE_TRACEBIT1|_KLE_TRACEBIT2) | |
29488 | +#define KLE_F_TRACELEVEL4 (_KLE_TRACEBIT3) | |
29489 | +#define KLE_TRACELEVELMAX 4 | |
29490 | +#define KLE_TRACELEVEL(flg) (flg & _KLE_TRACEMASK) | |
29491 | +#define KLE_GETTRACELEVEL(flg) \ | |
29492 | + ((KLE_TRACELEVEL(flg) > KLE_TRACELEVELMAX) ? KLE_TRACELEVELMAX : \ | |
29493 | + KLE_TRACELEVEL(flg)) | |
29494 | + | |
29495 | +/* define debug components of libklib (64 components possible) | |
29496 | + * used by kl_msg() | |
29497 | + */ | |
29498 | +#define KL_DBGCOMP_ALLOC 0x0000000001 /* liballoc */ | |
29499 | +#define KL_DBGCOMP_BFD 0x0000000002 /* general bfd support */ | |
29500 | +#define KL_DBGCOMP_BTREE 0x0000000004 /* btree implementation */ | |
29501 | +#define KL_DBGCOMP_COMPRESS 0x0000000008 /* gzip/rle (de)compression */ | |
29502 | +#define KL_DBGCOMP_INIT 0x0000000010 /* klib initialization */ | |
29503 | +#define KL_DBGCOMP_MEMMAP 0x0000000020 /* memory mapping */ | |
29504 | +#define KL_DBGCOMP_MODULE 0x0000000040 /* kernel module handling */ | |
29505 | +#define KL_DBGCOMP_SIGNAL 0x0000000080 /* signal handling */ | |
29506 | +#define KL_DBGCOMP_STABS 0x0000000100 /* stabs format support */ | |
29507 | +#define KL_DBGCOMP_SYMBOL 0x0000000200 /* symbol handling */ | |
29508 | +#define KL_DBGCOMP_TYPE 0x0000000400 /* type information handling */ | |
29509 | +#define KL_DBGCOMP_ALL ((uint64_t) -1) /* all components */ | |
29510 | + | |
29511 | +/* central output routine, shouldn't be used directly, but | |
29512 | + * by following macros | |
29513 | + */ | |
29514 | +void kl_msg(uint64_t, uint32_t, const char*, const char*, int, | |
29515 | + const char*, ...); | |
29516 | + | |
29517 | +/* vararg macros that should be used instead of kl_msg() | |
29518 | + */ | |
29519 | +/* used within libklib to print non-error messages (e.g. progress indication) | |
29520 | + */ | |
29521 | +#define KL_MSG(fmt, args...) \ | |
29522 | +kl_msg(0, 0, NULL, NULL, 0, fmt, ## args) | |
29523 | +/* Can be used by application to print error messages; | |
29524 | + * not used by libklib itself. | |
29525 | + */ | |
29526 | +#define kl_error(fmt, args...) \ | |
29527 | +kl_msg(0, KLE_F_ERRORMSG, __FUNCTION__, __FILE__, __LINE__, fmt, ## args) | |
29528 | +/* Generate trace messages. Used for libklib debugging. Might be used | |
29529 | + * by an application, too. | |
29530 | + * A macro _DBG_COMPONENT has to be defined locally in the module where | |
29531 | + * any trace macro is used. See above debug components. | |
29532 | + * Trace messages are only printed iff _DBG_COMPONENT was set before with a | |
29533 | + * call to kl_set_dbg_component(). | |
29534 | + */ | |
29535 | +#define kl_trace1(flg, fmt, args...) \ | |
29536 | +kl_msg(_DBG_COMPONENT, KLE_F_TRACELEVEL1|(flg), \ | |
29537 | + __FUNCTION__, __FILE__, __LINE__, fmt, ## args) | |
29538 | +#define kl_trace2(flg, fmt, args...) \ | |
29539 | +kl_msg(_DBG_COMPONENT, KLE_F_TRACELEVEL2|(flg), \ | |
29540 | + __FUNCTION__, __FILE__, __LINE__, fmt, ## args) | |
29541 | +#define kl_trace3(flg, fmt, args...) \ | |
29542 | +kl_msg(_DBG_COMPONENT, KLE_F_TRACELEVEL3|(flg), \ | |
29543 | + __FUNCTION__, __FILE__, __LINE__, fmt, ## args) | |
29544 | +#define kl_trace4(flg, fmt, args...) \ | |
29545 | +kl_msg(_DBG_COMPONENT, KLE_F_TRACELEVEL4|(flg), \ | |
29546 | + __FUNCTION__, __FILE__, __LINE__, fmt, ## args) | |
29547 | + | |
29548 | +/* functions to set some global variables for libklib debugging | |
29549 | + */ | |
29550 | +int kl_set_trace_threshold(uint32_t); | |
29551 | +void kl_set_dbg_component(uint64_t); | |
29552 | +void kl_set_stdout(FILE *); | |
29553 | +void kl_set_stderr(FILE *); | |
29554 | + | |
29555 | +/* functions to get contents of global variables for libklib debugging | |
29556 | + */ | |
29557 | +uint32_t kl_get_trace_threshold(void); | |
29558 | +uint64_t kl_get_dbg_component(void); | |
29559 | + | |
29560 | +#endif /* __KL_ERROR_H */ | |
29561 | --- /dev/null | |
29562 | +++ b/kdb/modules/lcrash/kl_htnode.h | |
29563 | @@ -0,0 +1,71 @@ | |
29564 | +/* | |
29565 | + * $Id: kl_htnode.h 1122 2004-12-21 23:26:23Z tjm $ | |
29566 | + * | |
29567 | + * This file is part of libutil. | |
29568 | + * A library which provides auxiliary functions. | |
29569 | + * libutil is part of lkcdutils -- utilities for Linux kernel crash dumps. | |
29570 | + * | |
29571 | + * Created by Silicon Graphics, Inc. | |
29572 | + * Contributions by IBM, NEC, and others | |
29573 | + * | |
29574 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
29575 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
29576 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
29577 | + * | |
29578 | + * This code is free software; you can redistribute it and/or modify | |
29579 | + * it under the terms of the GNU Lesser Public License as published by | |
29580 | + * the Free Software Foundation; either version 2.1 of the License, or | |
29581 | + * (at your option) any later version. See the file COPYING for more | |
29582 | + * information. | |
29583 | + */ | |
29584 | + | |
29585 | +#ifndef __KL_HTNODE_H | |
29586 | +#define __KL_HTNODE_H | |
29587 | + | |
29588 | +/* Node structure for use in hierarchical trees (htrees). | |
29589 | + */ | |
29590 | +typedef struct htnode_s { | |
29591 | + struct htnode_s *next; | |
29592 | + struct htnode_s *prev; | |
29593 | + struct htnode_s *parent; | |
29594 | + struct htnode_s *children; | |
29595 | + int seq; | |
29596 | + int level; | |
29597 | + int key; | |
29598 | +} htnode_t; | |
29599 | + | |
29600 | +/* Flag values | |
29601 | + */ | |
29602 | +#define HT_BEFORE 0x1 | |
29603 | +#define HT_AFTER 0x2 | |
29604 | +#define HT_CHILD 0x4 | |
29605 | +#define HT_PEER 0x8 | |
29606 | + | |
29607 | +/* Function prototypes | |
29608 | + */ | |
29609 | +htnode_t *kl_next_htnode( | |
29610 | + htnode_t * /* htnode pointer */); | |
29611 | + | |
29612 | +htnode_t *kl_prev_htnode( | |
29613 | + htnode_t * /* htnode pointer */); | |
29614 | + | |
29615 | +void ht_insert_peer( | |
29616 | + htnode_t * /* htnode pointer */, | |
29617 | + htnode_t * /* new htnode pointer*/, | |
29618 | + int /* flags */); | |
29619 | + | |
29620 | +void ht_insert_child( | |
29621 | + htnode_t * /* htnode pointer */, | |
29622 | + htnode_t * /* new htnode pointer*/, | |
29623 | + int /* flags */); | |
29624 | + | |
29625 | +int ht_insert( | |
29626 | + htnode_t * /* htnode pointer */, | |
29627 | + htnode_t * /* new htnode pointer*/, | |
29628 | + int /* flags */); | |
29629 | + | |
29630 | +void ht_insert_next_htnode( | |
29631 | + htnode_t * /* htnode pointer */, | |
29632 | + htnode_t * /* new htnode pointer*/); | |
29633 | + | |
29634 | +#endif /* __KL_HTNODE_H */ | |
29635 | --- /dev/null | |
29636 | +++ b/kdb/modules/lcrash/kl_lib.h | |
29637 | @@ -0,0 +1,65 @@ | |
29638 | +/* | |
29639 | + * $Id: kl_lib.h 1122 2004-12-21 23:26:23Z tjm $ | |
29640 | + * | |
29641 | + * This file is part of libutil. | |
29642 | + * A library which provides auxiliary functions. | |
29643 | + * libutil is part of lkcdutils -- utilities for Linux kernel crash dumps. | |
29644 | + * | |
29645 | + * Created by Silicon Graphics, Inc. | |
29646 | + * Contributions by IBM, NEC, and others | |
29647 | + * | |
29648 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
29649 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
29650 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
29651 | + * | |
29652 | + * This code is free software; you can redistribute it and/or modify | |
29653 | + * it under the terms of the GNU Lesser Public License as published by | |
29654 | + * the Free Software Foundation; either version 2.1 of the License, or | |
29655 | + * (at your option) any later version. See the file COPYING for more | |
29656 | + * information. | |
29657 | + */ | |
29658 | + | |
29659 | +#ifndef __KL_LIB_H | |
29660 | +#define __KL_LIB_H | |
29661 | + | |
29662 | +/* Include system header files | |
29663 | + */ | |
29664 | + | |
29665 | +#if 0 | |
29666 | +/* cpw: we don't need this userland stuff: */ | |
29667 | +#include <stdio.h> | |
29668 | +#include <stdlib.h> | |
29669 | +#include <stdint.h> | |
29670 | +#include <unistd.h> | |
29671 | +#include <sys/stat.h> | |
29672 | +#include <sys/types.h> | |
29673 | +#include <sys/time.h> | |
29674 | +#include <unistd.h> | |
29675 | +#include <time.h> | |
29676 | +#include <sys/socket.h> | |
29677 | +#include <netinet/in.h> | |
29678 | +#include <netdb.h> | |
29679 | +#include <sys/ioctl.h> | |
29680 | +#include <net/if.h> | |
29681 | +#include <sys/utsname.h> | |
29682 | +#include <fcntl.h> | |
29683 | +#include <string.h> | |
29684 | +#include <setjmp.h> | |
29685 | +#include <strings.h> | |
29686 | +#include <errno.h> | |
29687 | +#include <assert.h> | |
29688 | +#include <ctype.h> | |
29689 | +#endif | |
29690 | + | |
29691 | +/* Include lkcd library header files | |
29692 | + */ | |
29693 | +/* cpw: change these from the < > form to the " " form: */ | |
29694 | +#include "kl_types.h" | |
29695 | +#include "kl_alloc.h" | |
29696 | +#include "kl_libutil.h" | |
29697 | +#include "kl_btnode.h" | |
29698 | +#include "kl_htnode.h" | |
29699 | +#include "kl_queue.h" | |
29700 | +#include "kl_stringtab.h" | |
29701 | + | |
29702 | +#endif /* __KL_LIB_H */ | |
29703 | --- /dev/null | |
29704 | +++ b/kdb/modules/lcrash/kl_libutil.h | |
29705 | @@ -0,0 +1,40 @@ | |
29706 | +/* | |
29707 | + * $Id: kl_libutil.h 1122 2004-12-21 23:26:23Z tjm $ | |
29708 | + * | |
29709 | + * This file is part of libutil. | |
29710 | + * A library which provides auxiliary functions. | |
29711 | + * libutil is part of lkcdutils -- utilities for Linux kernel crash dumps. | |
29712 | + * | |
29713 | + * Created by Silicon Graphics, Inc. | |
29714 | + * Contributions by IBM, NEC, and others | |
29715 | + * | |
29716 | + * Copyright (C) 1999 - 2004 Silicon Graphics, Inc. All rights reserved. | |
29717 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
29718 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
29719 | + * | |
29720 | + * This code is free software; you can redistribute it and/or modify | |
29721 | + * it under the terms of the GNU Lesser Public License as published by | |
29722 | + * the Free Software Foundation; either version 2.1 of the License, or | |
29723 | + * (at your option) any later version. See the file COPYING for more | |
29724 | + * information. | |
29725 | + */ | |
29726 | + | |
29727 | +#ifndef __KL_LIBUTIL_H | |
29728 | +#define __KL_LIBUTIL_H | |
29729 | + | |
29730 | +/* cpw: change all these from the < > form to the " " form: */ | |
29731 | +#include "kl_alloc.h" | |
29732 | +#include "kl_btnode.h" | |
29733 | +#include "kl_copt.h" | |
29734 | +#include "kl_htnode.h" | |
29735 | +#include "kl_queue.h" | |
29736 | +#include "kl_stringtab.h" | |
29737 | + | |
29738 | +int kl_shift_value(uint64_t ); | |
29739 | +int kl_string_compare(char *, char *); | |
29740 | +int kl_string_match(char *, char *); | |
29741 | +uint64_t kl_strtoull(char *, char **, int); | |
29742 | +time_t kl_str_to_ctime(char *); | |
29743 | +void *kl_get_ra(void); | |
29744 | + | |
29745 | +#endif /* __KL_LIBUTIL_H */ | |
29746 | --- /dev/null | |
29747 | +++ b/kdb/modules/lcrash/kl_mem.h | |
29748 | @@ -0,0 +1,104 @@ | |
29749 | +/* | |
29750 | + * $Id: kl_mem.h 1157 2005-02-25 22:04:05Z tjm $ | |
29751 | + * | |
29752 | + * This file is part of libklib. | |
29753 | + * A library which provides access to Linux system kernel dumps. | |
29754 | + * | |
29755 | + * Created by Silicon Graphics, Inc. | |
29756 | + * Contributions by IBM, NEC, and others | |
29757 | + * | |
29758 | + * Copyright (C) 1999 - 2005 Silicon Graphics, Inc. All rights reserved. | |
29759 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
29760 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
29761 | + * | |
29762 | + * This code is free software; you can redistribute it and/or modify | |
29763 | + * it under the terms of the GNU Lesser Public License as published by | |
29764 | + * the Free Software Foundation; either version 2.1 of the License, or | |
29765 | + * (at your option) any later version. See the file COPYING for more | |
29766 | + * information. | |
29767 | + */ | |
29768 | + | |
29769 | +#ifndef __KL_MEM_H | |
29770 | +#define __KL_MEM_H | |
29771 | + | |
29772 | +#if 0 | |
29773 | +cpw: skip: | |
29774 | +extern kaddr_t VMALLOC_START; | |
29775 | +extern kaddr_t VMALLOC_END; | |
29776 | +#endif | |
29777 | + | |
29778 | +/* | |
29779 | + * Function prototypes | |
29780 | + */ | |
29781 | + | |
29782 | +int kl_linux_release(void); | |
29783 | + | |
29784 | +k_error_t kl_readmem( | |
29785 | + kaddr_t /* physical address to start reading from */, | |
29786 | + unsigned /* number of bytes to read */, | |
29787 | + void * /* pointer to buffer */); | |
29788 | + | |
29789 | +k_error_t kl_readkmem( | |
29790 | + kaddr_t /* virtual address to start reading from */, | |
29791 | + unsigned /* number of bytes to read */, | |
29792 | + void * /* pointer to buffer */); | |
29793 | + | |
29794 | +int kl_virtop( | |
29795 | + kaddr_t /* virtual address to translate */, | |
29796 | + void * /* pointer to mem_map for address translation */, | |
29797 | + kaddr_t * /* pointer to physical address to return */); | |
29798 | + | |
29799 | +k_error_t kl_get_block( | |
29800 | + kaddr_t /* virtual address */, | |
29801 | + unsigned /* size of block to read in */, | |
29802 | + void * /* pointer to buffer */, | |
29803 | + void * /* pointer to mmap */); | |
29804 | + | |
29805 | +/* Wrapper that eliminates the mmap parameter | |
29806 | + */ | |
29807 | +#define GET_BLOCK(a, s, b) kl_get_block(a, s, (void *)b, (void *)0) | |
29808 | + | |
29809 | +uint64_t kl_uint( | |
29810 | + void * /* pointer to buffer containing struct */, | |
29811 | + char * /* name of struct */, | |
29812 | + char * /* name of member */, | |
29813 | + unsigned /* offset */); | |
29814 | + | |
29815 | +int64_t kl_int( | |
29816 | + void * /* pointer to buffer containing struct */, | |
29817 | + char * /* name of struct */, | |
29818 | + char * /* name of member */, | |
29819 | + unsigned /* offset */); | |
29820 | + | |
29821 | +kaddr_t kl_kaddr( | |
29822 | + void * /* pointer to buffer containing struct */, | |
29823 | + char * /* name of struct */, | |
29824 | + char * /* name of member */); | |
29825 | + | |
29826 | +/* XXX deprecated use KL_READ_PTR() instead */ | |
29827 | +kaddr_t kl_kaddr_to_ptr( | |
29828 | + kaddr_t /* Address to dereference */); | |
29829 | + | |
29830 | +int kl_is_valid_kaddr( | |
29831 | + kaddr_t /* Address to test */, | |
29832 | + void * /* pointer to mmap */, | |
29833 | + int /* flags */); | |
29834 | + | |
29835 | +/* REMIND: | |
29836 | + * Likely not right for ia64 | |
29837 | + */ | |
29838 | +#define KL_KADDR_IS_PHYSICAL(vaddr) ((vaddr >= KL_PAGE_OFFSET) && \ | |
29839 | + (vaddr <= KL_HIGH_MEMORY)) | |
29840 | + | |
29841 | +#define PGNO_TO_PADDR(pgno) (pgno << KL_PAGE_SHIFT) | |
29842 | + | |
29843 | +/* | |
29844 | + * declaration of some defaults that are used in kl_set_dumparch() | |
29845 | + */ | |
29846 | +int kl_valid_physaddr(kaddr_t); | |
29847 | +int kl_valid_physmem(kaddr_t, int); | |
29848 | +kaddr_t kl_next_valid_physaddr(kaddr_t); | |
29849 | +kaddr_t kl_fix_vaddr(kaddr_t, size_t); | |
29850 | +int kl_init_virtop(void); | |
29851 | + | |
29852 | +#endif /* __KL_MEM_H */ | |
29853 | --- /dev/null | |
29854 | +++ b/kdb/modules/lcrash/kl_mem_ia64.h | |
29855 | @@ -0,0 +1,149 @@ | |
29856 | +/* | |
29857 | + * $Id: kl_mem_ia64.h 1250 2006-04-18 18:23:44Z cliffpwickman $ | |
29858 | + * | |
29859 | + * This file is part of libklib. | |
29860 | + * A library which provides access to Linux system kernel dumps. | |
29861 | + * | |
29862 | + * Created by Silicon Graphics, Inc. | |
29863 | + * Contributions by IBM, NEC, and others | |
29864 | + * | |
29865 | + * Copyright (C) 1999 - 2005 Silicon Graphics, Inc. All rights reserved. | |
29866 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
29867 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
29868 | + * | |
29869 | + * This code is free software; you can redistribute it and/or modify | |
29870 | + * it under the terms of the GNU Lesser Public License as published by | |
29871 | + * the Free Software Foundation; either version 2.1 of the License, or | |
29872 | + * (at your option) any later version. See the file COPYING for more | |
29873 | + * information. | |
29874 | + */ | |
29875 | + | |
29876 | +#ifndef __KL_MEM_IA64_H | |
29877 | +#define __KL_MEM_IA64_H | |
29878 | + | |
29879 | +/* XXX - the following macros are used by functions in kl_page.c and in */ | |
29880 | +/* function kl_virtop, they still have to be defined properly, */ | |
29881 | +/* all the following macros have first to be set with correct values. */ | |
29882 | +/* I don't have a clue what values to use for ia64 architecture!!! */ | |
29883 | + | |
29884 | +/* KSTACK_SIZE depends on page size (see kernel headers ptrace.h and page.h) | |
29885 | + * #define IA64_STK_OFFSET ((1 << IA64_TASK_STRUCT_LOG_NUM_PAGES)*PAGE_SIZE) | |
29886 | + * and | |
29887 | + * #define PAGE_SIZE 1UL<<PAGE_SHIFT | |
29888 | + * and | |
29889 | + * #if defined(CONFIG_IA64_PAGE_SIZE_4KB) | |
29890 | + * # define PAGE_SHIFT 12 | |
29891 | + * #elif defined(CONFIG_IA64_PAGE_SIZE_8KB) | |
29892 | + * # define PAGE_SHIFT 13 | |
29893 | + * #elif defined(CONFIG_IA64_PAGE_SIZE_16KB) | |
29894 | + * # define PAGE_SHIFT 14 | |
29895 | + * #elif defined(CONFIG_IA64_PAGE_SIZE_64KB) | |
29896 | + * # define PAGE_SHIFT 16 | |
29897 | + * #else | |
29898 | + * # error Unsupported page size! | |
29899 | + * #endif | |
29900 | + * and | |
29901 | + * #if defined(CONFIG_IA64_PAGE_SIZE_4KB) | |
29902 | + * # define IA64_TASK_STRUCT_LOG_NUM_PAGES 3 | |
29903 | + * #elif defined(CONFIG_IA64_PAGE_SIZE_8KB) | |
29904 | + * # define IA64_TASK_STRUCT_LOG_NUM_PAGES 2 | |
29905 | + * #elif defined(CONFIG_IA64_PAGE_SIZE_16KB) | |
29906 | + * # define IA64_TASK_STRUCT_LOG_NUM_PAGES 1 | |
29907 | + * #else | |
29908 | + * # define IA64_TASK_STRUCT_LOG_NUM_PAGES 0 | |
29909 | + * #endif | |
29910 | + * Finally we have for page sizes 4KB, 8K, 16K IA64_STK_OFFSET=32K, and | |
29911 | + * for page size 64K IA64_STK_OFFSET=64K. | |
29912 | + * FIXME: !!!Don't know how to handle 64K page size case!!! | |
29913 | + */ | |
29914 | +#define KL_KSTACK_SIZE_IA64 0x8000ULL | |
29915 | +/* 64KB page size case: | |
29916 | + * #define KL_KSTACK_SIZE_IA64 0x10000ULL | |
29917 | + */ | |
29918 | + | |
29919 | +#define KL_PAGE_OFFSET_IA64 0xe000000000000000 | |
29920 | + | |
29921 | +#define KL_PAGE_SHIFT_IA64 KL_PAGE_SHIFT | |
29922 | +#define KL_PAGE_SIZE_IA64 (1ULL << KL_PAGE_SHIFT_IA64) | |
29923 | +#define KL_PAGE_MASK_IA64 (~(KL_PAGE_SIZE_IA64-1)) | |
29924 | + | |
29925 | +/* for 3-level page tables: */ | |
29926 | +#define KL_PGDIR_SHIFT_IA64 (KL_PAGE_SHIFT_IA64+(KL_PAGE_SHIFT_IA64-3)*2) | |
29927 | +#define KL_PGDIR_SIZE_IA64 (1ULL<<KL_PGDIR_SHIFT_IA64) | |
29928 | +#define KL_PGDIR_MASK_IA64 (~(KL_PGDIR_SIZE_IA64-1)) | |
29929 | + | |
29930 | +/* for 4-level page tables: */ | |
29931 | +#define KL_PGDIR4_SHIFT_IA64 (KL_PAGE_SHIFT_IA64+(KL_PAGE_SHIFT_IA64-3)*3) | |
29932 | +#define KL_PGDIR4_SIZE_IA64 (1ULL<<KL_PGDIR4_SHIFT_IA64) | |
29933 | +#define KL_PGDIR4_MASK_IA64 (~(KL_PGDIR_SIZE4_IA64-1)) | |
29934 | +#define KL_PUD_SHIFT_IA64 (KL_PAGE_SHIFT_IA64+(KL_PAGE_SHIFT_IA64-3)*2) | |
29935 | +#define KL_PUD_SIZE_IA64 (1ULL<<KL_PUD_SHIFT_IA64) | |
29936 | +#define KL_PUD_MASK_IA64 (~(KL_PUD_SIZE_IA64-1)) | |
29937 | + | |
29938 | +#define KL_PMD_SHIFT_IA64 (KL_PAGE_SHIFT_IA64+(KL_PAGE_SHIFT_IA64-3)*1) | |
29939 | +#define KL_PMD_SIZE_IA64 (1ULL<<KL_PMD_SHIFT_IA64) | |
29940 | +#define KL_PMD_MASK_IA64 (~(KL_PMD_SIZE_IA64-1)) | |
29941 | + | |
29942 | +#define KL_PTRS_PER_PGD_IA64 (1ULL<<(KL_PAGE_SHIFT_IA64-3)) | |
29943 | +#define KL_PTRS_PER_PUD_IA64 (1ULL<<(KL_PAGE_SHIFT_IA64-3)) | |
29944 | +#define KL_PTRS_PER_PMD_IA64 (1ULL<<(KL_PAGE_SHIFT_IA64-3)) | |
29945 | +#define KL_PTRS_PER_PTE_IA64 (1ULL<<(KL_PAGE_SHIFT_IA64-3)) | |
29946 | + | |
29947 | +/* These values describe the bits of pgd/pmd/pte entries that are | |
29948 | + * status bits and therefor have to be masked in order to get valid | |
29949 | + * addresses | |
29950 | + */ | |
29951 | +#define KL_PMD_BASE_MASK_IA64 (((1ULL<<50)-1)&(~0xfffULL)) | |
29952 | +#define KL_PT_BASE_MASK_IA64 KL_PMD_BASE_MASK_IA64 | |
29953 | +#define KL_PAGE_BASE_MASK_IA64 KL_PMD_BASE_MASK_IA64 | |
29954 | + | |
29955 | +#define KL_KADDR_IS_HIGHMEM(vaddr) ((KL_HIGH_MEMORY && (vaddr >= KL_HIGH_MEMORY))) | |
29956 | + | |
29957 | +uint32_t dha_num_cpus_ia64(void); | |
29958 | +kaddr_t dha_current_task_ia64(int); | |
29959 | +int dha_cpuid_ia64(kaddr_t); | |
29960 | +kaddr_t dha_stack_ia64(int); | |
29961 | +kaddr_t dha_stack_ptr_ia64(int); | |
29962 | +kaddr_t kl_kernelstack_ia64(kaddr_t); | |
29963 | +kaddr_t kl_mmap_virtop_ia64(kaddr_t, void*); | |
29964 | +int kl_init_virtop_ia64(void); | |
29965 | +int kl_virtop_ia64(kaddr_t, void*, kaddr_t*); | |
29966 | +int kl_vtop_ia64(kaddr_t, kaddr_t*); | |
29967 | +int kl_valid_physmem_ia64(kaddr_t, int); | |
29968 | +kaddr_t kl_next_valid_physaddr_ia64(kaddr_t); | |
29969 | +kaddr_t kl_fix_vaddr_ia64(kaddr_t, size_t); | |
29970 | + | |
29971 | +/* Structure containing key data for ia64 virtual memory mapping. | |
29972 | + * Note that a number of fields are SN system specific. | |
29973 | + */ | |
29974 | +typedef struct ia64_vminfo_s { | |
29975 | + int flags; | |
29976 | + kaddr_t vpernode_base; | |
29977 | + kaddr_t vglobal_base; | |
29978 | + kaddr_t to_phys_mask; | |
29979 | + kaddr_t kernphysbase; | |
29980 | + int nasid_shift; /* SN specific */ | |
29981 | + int nasid_mask; /* SN specific */ | |
29982 | +} ia64_vminfo_t; | |
29983 | + | |
29984 | +extern ia64_vminfo_t ia64_vminfo; | |
29985 | + | |
29986 | +/* Some vminfo flags | |
29987 | + */ | |
29988 | +#define MAPPED_KERN_FLAG 0x1 | |
29989 | +#define SN2_FLAG 0x2 | |
29990 | + | |
29991 | +/* Some vminfo macros | |
29992 | + */ | |
29993 | +#define IS_MAPPED_KERN (ia64_vminfo.flags & MAPPED_KERN_FLAG) | |
29994 | +#define IS_SN2 (ia64_vminfo.flags & SN2_FLAG) | |
29995 | +#define KL_VPERNODE_BASE ia64_vminfo.vpernode_base | |
29996 | +#define KL_VGLOBAL_BASE ia64_vminfo.vglobal_base | |
29997 | +#define KL_TO_PHYS_MASK ia64_vminfo.to_phys_mask | |
29998 | +#define KL_KERNPHYSBASE ia64_vminfo.kernphysbase | |
29999 | +#define KL_NASID_SHIFT ia64_vminfo.nasid_shift | |
30000 | +#define KL_NASID_MASK ia64_vminfo.nasid_mask | |
30001 | + | |
30002 | +#define ADDR_TO_NASID(A) (((A) >> (long)(KL_NASID_SHIFT)) & KL_NASID_MASK) | |
30003 | + | |
30004 | +#endif /* __KL_MEM_IA64_H */ | |
30005 | --- /dev/null | |
30006 | +++ b/kdb/modules/lcrash/kl_module.h | |
30007 | @@ -0,0 +1,69 @@ | |
30008 | +/* | |
30009 | + * $Id: kl_module.h 1122 2004-12-21 23:26:23Z tjm $ | |
30010 | + * | |
30011 | + * This file is part of libklib. | |
30012 | + * A library which provides access to Linux system kernel dumps. | |
30013 | + * | |
30014 | + * Created by Silicon Graphics, Inc. | |
30015 | + * Contributions by IBM, NEC, and others | |
30016 | + * | |
30017 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
30018 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
30019 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
30020 | + * | |
30021 | + * This code is free software; you can redistribute it and/or modify | |
30022 | + * it under the terms of the GNU Lesser Public License as published by | |
30023 | + * the Free Software Foundation; either version 2.1 of the License, or | |
30024 | + * (at your option) any later version. See the file COPYING for more | |
30025 | + * information. | |
30026 | + */ | |
30027 | + | |
30028 | +#ifndef __KL_MODULE_H | |
30029 | +#define __KL_MODULE_H | |
30030 | + | |
30031 | +/* | |
30032 | + * insmod generates ksymoops | |
30033 | + * | |
30034 | + */ | |
30035 | + | |
30036 | +typedef struct kl_modinfo_s { | |
30037 | + char *modname; /* name of module as loaded in dump */ | |
30038 | + /* store ksym info for all modules in a linked list */ | |
30039 | + struct kl_modinfo_s *next; | |
30040 | + char *object_file; /* name of file that module was loaded from*/ | |
30041 | + /* ? possibly store modtime and version here ? */ | |
30042 | + uint64_t header; /* address of module header */ | |
30043 | + uint64_t mtime; /* time of last modification of object_file */ | |
30044 | + uint32_t version; /* kernel version that module was compiled for */ | |
30045 | + uint64_t text_sec; /* address of text section */ | |
30046 | + uint64_t text_len; /* length of text section */ | |
30047 | + uint64_t data_sec; /* address of data section */ | |
30048 | + uint64_t data_len; /* length of data section */ | |
30049 | + uint64_t rodata_sec; /* address of rodata section */ | |
30050 | + uint64_t rodata_len; /* length of rodata section */ | |
30051 | + uint64_t bss_sec; /* address of rodata section */ | |
30052 | + uint64_t bss_len; /* length of rodata section */ | |
30053 | + char *ksym_object; /* ksym for object */ | |
30054 | + char *ksym_text_sec; /* ksym for its text section */ | |
30055 | + char *ksym_data_sec; /* ksym for its data section */ | |
30056 | + char *ksym_rodata_sec; /* ksym for its rodata section */ | |
30057 | + char *ksym_bss_sec; /* ksym for its bss sectio */ | |
30058 | +} kl_modinfo_t; | |
30059 | + | |
30060 | +int kl_get_module(char*, kaddr_t*, void**); | |
30061 | +int kl_get_module_2_6(char*, kaddr_t*, void**); | |
30062 | +int kl_get_modname(char**, void*); | |
30063 | +int kl_new_get_modname(char**, void*); | |
30064 | +void kl_free_modinfo(kl_modinfo_t**); | |
30065 | +int kl_new_modinfo(kl_modinfo_t**, void*); | |
30066 | +int kl_set_modinfo(kaddr_t, char*, kl_modinfo_t*); | |
30067 | +int kl_complete_modinfo(kl_modinfo_t*); | |
30068 | +int kl_load_ksyms(int); | |
30069 | +int kl_load_ksyms_2_6(int); | |
30070 | +int kl_unload_ksyms(void); | |
30071 | +int kl_load_module_sym(char*, char*, char*); | |
30072 | +int kl_unload_module_sym(char*); | |
30073 | +int kl_autoload_module_info(char*); | |
30074 | +kl_modinfo_t * kl_lkup_modinfo(char*); | |
30075 | + | |
30076 | +#endif /* __KL_MODULE_H */ | |
30077 | --- /dev/null | |
30078 | +++ b/kdb/modules/lcrash/kl_queue.h | |
30079 | @@ -0,0 +1,89 @@ | |
30080 | +/* | |
30081 | + * $Id: kl_queue.h 1122 2004-12-21 23:26:23Z tjm $ | |
30082 | + * | |
30083 | + * This file is part of libutil. | |
30084 | + * A library which provides auxiliary functions. | |
30085 | + * libutil is part of lkcdutils -- utilities for Linux kernel crash dumps. | |
30086 | + * | |
30087 | + * Created by Silicon Graphics, Inc. | |
30088 | + * Contributions by IBM, NEC, and others | |
30089 | + * | |
30090 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
30091 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
30092 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
30093 | + * | |
30094 | + * This code is free software; you can redistribute it and/or modify | |
30095 | + * it under the terms of the GNU Lesser Public License as published by | |
30096 | + * the Free Software Foundation; either version 2.1 of the License, or | |
30097 | + * (at your option) any later version. See the file COPYING for more | |
30098 | + * information. | |
30099 | + */ | |
30100 | + | |
30101 | +#ifndef __KL_QUEUE_H | |
30102 | +#define __KL_QUEUE_H | |
30103 | + | |
30104 | +/* List element header | |
30105 | + */ | |
30106 | +typedef struct element_s { | |
30107 | + struct element_s *next; | |
30108 | + struct element_s *prev; | |
30109 | +} element_t; | |
30110 | + | |
30111 | +/* Some useful macros | |
30112 | + */ | |
30113 | +#define ENQUEUE(list, elem) \ | |
30114 | + kl_enqueue((element_t **)list, (element_t *)elem) | |
30115 | +#define DEQUEUE(list) kl_dequeue((element_t **)list) | |
30116 | +#define FINDQUEUE(list, elem) \ | |
30117 | + kl_findqueue((element_t **)list, (element_t *)elem) | |
30118 | +#define REMQUEUE(list, elem) kl_remqueue((element_t **)list, (element_t *)elem) | |
30119 | + | |
30120 | +typedef struct list_of_ptrs { | |
30121 | + element_t elem; | |
30122 | + unsigned long long val64; | |
30123 | +} list_of_ptrs_t; | |
30124 | + | |
30125 | +#define FINDLIST_QUEUE(list, elem, compare) \ | |
30126 | + kl_findlist_queue((list_of_ptrs_t **)list, \ | |
30127 | + (list_of_ptrs_t *)elem, compare) | |
30128 | + | |
30129 | +/** | |
30130 | + ** Function prototypes | |
30131 | + **/ | |
30132 | + | |
30133 | +/* Add a new element to the tail of a doubly linked list. | |
30134 | + */ | |
30135 | +void kl_enqueue( | |
30136 | + element_t** /* ptr to head of list */, | |
30137 | + element_t* /* ptr to element to add to the list */); | |
30138 | + | |
30139 | +/* Remove an element from the head of a doubly linked list. A pointer | |
30140 | + * to the element will be returned. In the event that the list is | |
30141 | + * empty, a NULL pointer will be returned. | |
30142 | + */ | |
30143 | +element_t *kl_dequeue( | |
30144 | + element_t** /* ptr to list head (first item removed) */); | |
30145 | + | |
30146 | +/* Checks to see if a particular element is in a list. If it is, a | |
30147 | + * value of one (1) will be returned. Otherwise, a value of zero (0) | |
30148 | + * will be returned. | |
30149 | + */ | |
30150 | +int kl_findqueue( | |
30151 | + element_t** /* ptr to head of list */, | |
30152 | + element_t* /* ptr to element to find on list */); | |
30153 | + | |
30154 | +/* Walks through a list of pointers to queues and looks for a | |
30155 | + * particular list. | |
30156 | + */ | |
30157 | +int kl_findlist_queue( | |
30158 | + list_of_ptrs_t** /* ptr to list of lists */, | |
30159 | + list_of_ptrs_t* /* ptr to list to look for */, | |
30160 | + int(*)(void *, void *) /* ptr to compare function */); | |
30161 | + | |
30162 | +/* Remove specified element from doubly linked list. | |
30163 | + */ | |
30164 | +void kl_remqueue( | |
30165 | + element_t** /* ptr to head of list */, | |
30166 | + element_t* /* ptr to element to remove from list */); | |
30167 | + | |
30168 | +#endif /* __KL_QUEUE_H */ | |
30169 | --- /dev/null | |
30170 | +++ b/kdb/modules/lcrash/kl_stabs.h | |
30171 | @@ -0,0 +1,122 @@ | |
30172 | +/* | |
30173 | + * $Id: kl_stabs.h 1122 2004-12-21 23:26:23Z tjm $ | |
30174 | + * | |
30175 | + * This file is part of libklib. | |
30176 | + * A library which provides access to Linux system kernel dumps. | |
30177 | + * | |
30178 | + * Created by Silicon Graphics, Inc. | |
30179 | + * Contributions by IBM, NEC, and others | |
30180 | + * | |
30181 | + * Copyright (C) 1999 - 2004 Silicon Graphics, Inc. All rights reserved. | |
30182 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
30183 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
30184 | + * | |
30185 | + * This code is free software; you can redistribute it and/or modify | |
30186 | + * it under the terms of the GNU Lesser Public License as published by | |
30187 | + * the Free Software Foundation; either version 2.1 of the License, or | |
30188 | + * (at your option) any later version. See the file COPYING for more | |
30189 | + * information. | |
30190 | + */ | |
30191 | + | |
30192 | +#ifndef __KL_STABS_H | |
30193 | +#define __KL_STABS_H | |
30194 | + | |
30195 | +/* STABS specific types | |
30196 | + */ | |
30197 | +#define STAB_XSTRUCT 100 /* Cross referense to STAB_STRUCT */ | |
30198 | +#define STAB_XUNION 101 /* Cross referense to STAB_UNIONB */ | |
30199 | +#define STAB_XENUM 102 /* Cross referense to STAB_ENUM */ | |
30200 | + | |
30201 | +/* Structure allocated for every namelist. A namelist can be either an | |
30202 | + * object file (.o or executible), or it can be an archive (.a). | |
30203 | + */ | |
30204 | +typedef struct st_nmlist_s { | |
30205 | + char *sts_filename; /* disk file name */ | |
30206 | + short sts_type; /* ST_OBJ or ST_AR */ | |
30207 | + short sts_nfiles; /* number of source/object files */ | |
30208 | +} st_nmlist_t; | |
30209 | + | |
30210 | +/* Values for type field | |
30211 | + */ | |
30212 | +#define ST_OBJ 1 /* object file (.o or executible) */ | |
30213 | +#define ST_AR 2 /* archive */ | |
30214 | + | |
30215 | +/* Stab entry type Flags. For determining which stab entries to | |
30216 | + * capture from the symbol table. | |
30217 | + */ | |
30218 | +#define ST_UNDF 0x0001 | |
30219 | +#define ST_SO 0x0002 | |
30220 | +#define ST_LSYM 0x0004 | |
30221 | +#define ST_GSYM 0x0008 | |
30222 | +#define ST_PSYM 0x0010 | |
30223 | +#define ST_STSYM 0x0020 | |
30224 | +#define ST_LCSYM 0x0040 | |
30225 | +#define ST_FUN 0x0080 | |
30226 | +#define ST_BINCL 0x0100 | |
30227 | +#define ST_EINCL 0x0200 | |
30228 | +#define ST_EXCL 0x0400 | |
30229 | +#define ST_SLINE 0x0800 | |
30230 | +#define ST_RSYM 0x2000 | |
30231 | +#define ST_ALL 0xffff | |
30232 | +#define ST_DEFAULT (ST_LSYM|ST_GSYM|ST_FUN) | |
30233 | + | |
30234 | +#define N_UNDF 0 | |
30235 | + | |
30236 | +/* Structures that allow us to selectively cycle through only those BFD | |
30237 | + * sections containing STAB data. | |
30238 | + */ | |
30239 | +typedef struct stab_sect_s { | |
30240 | + char *stabsect_name; | |
30241 | + char *strsect_name; | |
30242 | +} stab_sect_t; | |
30243 | + | |
30244 | +/* Local structure that contains the current type string (which may be | |
30245 | + * just a part of the complete type defenition string) and the character | |
30246 | + * index (current) pointer. | |
30247 | + */ | |
30248 | +typedef struct stab_str_s { | |
30249 | + char *str; | |
30250 | + char *ptr; | |
30251 | +} stab_str_t; | |
30252 | + | |
30253 | +/* Local structure containing global values that allow us to cycle | |
30254 | + * through multiple object files without reinitializing. | |
30255 | + */ | |
30256 | +typedef struct st_global_s { | |
30257 | + bfd *abfd; /* current bfd pointer */ | |
30258 | + int type; /* symbol entry type */ | |
30259 | + int flags; /* want flags */ | |
30260 | + int flag; /* current ST flag */ | |
30261 | + int nmlist; /* current namelist index */ | |
30262 | + int srcfile; /* current source file number */ | |
30263 | + int incfile; /* current include file */ | |
30264 | + int symnum; /* symbol entry number */ | |
30265 | + bfd_byte *stabp; /* beg of current string table */ | |
30266 | + bfd_byte *stabs_end; /* end of current string table */ | |
30267 | + int staboff; /* current stab table offset */ | |
30268 | + unsigned int value; /* value (e.g., function addr) */ | |
30269 | + int stroffset; /* offset in stab string table */ | |
30270 | + short desc; /* desc value (e.g, line number) */ | |
30271 | + stab_str_t stab_str; /* current stab string */ | |
30272 | +} st_global_t; | |
30273 | + | |
30274 | +/* Macros for accessing the current global values | |
30275 | + */ | |
30276 | +#define G_abfd G_values.abfd | |
30277 | +#define G_type G_values.type | |
30278 | +#define G_flags G_values.flags | |
30279 | +#define G_flag G_values.flag | |
30280 | +#define G_nmlist G_values.nmlist | |
30281 | +#define G_srcfile G_values.srcfile | |
30282 | +#define G_incfile G_values.incfile | |
30283 | +#define G_symnum G_values.symnum | |
30284 | +#define G_stabp G_values.stabp | |
30285 | +#define G_stabs_end G_values.stabs_end | |
30286 | +#define G_staboff G_values.staboff | |
30287 | +#define G_value G_values.value | |
30288 | +#define G_stroffset G_values.stroffset | |
30289 | +#define G_desc G_values.desc | |
30290 | +#define G_stab_str G_values.stab_str | |
30291 | +#define CUR_CHAR G_stab_str.ptr | |
30292 | + | |
30293 | +#endif /* __KL_STABS_H */ | |
30294 | --- /dev/null | |
30295 | +++ b/kdb/modules/lcrash/kl_stringtab.h | |
30296 | @@ -0,0 +1,68 @@ | |
30297 | +/* | |
30298 | + * $Id: kl_stringtab.h 1122 2004-12-21 23:26:23Z tjm $ | |
30299 | + * | |
30300 | + * This file is part of libutil. | |
30301 | + * A library which provides auxiliary functions. | |
30302 | + * libutil is part of lkcdutils -- utilities for Linux kernel crash dumps. | |
30303 | + * | |
30304 | + * Created by Silicon Graphics, Inc. | |
30305 | + * Contributions by IBM, NEC, and others | |
30306 | + * | |
30307 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
30308 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
30309 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
30310 | + * | |
30311 | + * This code is free software; you can redistribute it and/or modify | |
30312 | + * it under the terms of the GNU Lesser Public License as published by | |
30313 | + * the Free Software Foundation; either version 2.1 of the License, or | |
30314 | + * (at your option) any later version. See the file COPYING for more | |
30315 | + * information. | |
30316 | + */ | |
30317 | + | |
30318 | +#ifndef __KL_STRINGTAB_H | |
30319 | +#define __KL_STRINGTAB_H | |
30320 | + | |
30321 | +/* The string table structure | |
30322 | + * | |
30323 | + * String space is allocated from 4K blocks which are allocated | |
30324 | + * as needed. The first four bytes of each block are reserved so | |
30325 | + * that the blocks can be chained together (to make it easy to free | |
30326 | + * them when the string table is no longer necessary). | |
30327 | + */ | |
30328 | +typedef struct string_table_s { | |
30329 | + int num_strings; | |
30330 | + void *block_list; | |
30331 | +} string_table_t; | |
30332 | + | |
30333 | +#define NO_STRINGTAB 0 | |
30334 | +#define USE_STRINGTAB 1 | |
30335 | + | |
30336 | +/** | |
30337 | + ** Function prototypes | |
30338 | + **/ | |
30339 | + | |
30340 | +/* Initialize a string table. Depending on the value of the flag | |
30341 | + * parameter, either temporary or permenent blocks will be used. | |
30342 | + * Upon success, a pointer to a string table will be returned. | |
30343 | + * Otherwise, a NULL pointer will be returned. | |
30344 | + */ | |
30345 | +string_table_t *kl_init_string_table( | |
30346 | + int /* flag (K_TEMP/K_PERM)*/); | |
30347 | + | |
30348 | +/* Free all memory blocks allocated for a particular string table | |
30349 | + * and then free the table itself. | |
30350 | + */ | |
30351 | +void kl_free_string_table( | |
30352 | + string_table_t* /* pointer to string table */); | |
30353 | + | |
30354 | +/* Search for a string in a string table. If the string does not | |
30355 | + * exist, allocate space from the string table and add the string. | |
30356 | + * In either event, a pointer to the string (from the table) will | |
30357 | + * be returned. | |
30358 | + */ | |
30359 | +char *kl_get_string( | |
30360 | + string_table_t* /* pointer to string table */, | |
30361 | + char* /* string to get/add from/to string table */, | |
30362 | + int /* flag (K_TEMP/K_PERM)*/); | |
30363 | + | |
30364 | +#endif /* __KL_STRINGTAB_H */ | |
30365 | --- /dev/null | |
30366 | +++ b/kdb/modules/lcrash/kl_sym.h | |
30367 | @@ -0,0 +1,131 @@ | |
30368 | +/* | |
30369 | + * $Id: kl_sym.h 1233 2005-09-10 08:01:11Z tjm $ | |
30370 | + * | |
30371 | + * This file is part of libklib. | |
30372 | + * A library which provides access to Linux system kernel dumps. | |
30373 | + * | |
30374 | + * Created by Silicon Graphics, Inc. | |
30375 | + * Contributions by IBM, NEC, and others | |
30376 | + * | |
30377 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
30378 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
30379 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
30380 | + * | |
30381 | + * This code is free software; you can redistribute it and/or modify | |
30382 | + * it under the terms of the GNU Lesser Public License as published by | |
30383 | + * the Free Software Foundation; either version 2.1 of the License, or | |
30384 | + * (at your option) any later version. See the file COPYING for more | |
30385 | + * information. | |
30386 | + */ | |
30387 | + | |
30388 | +#ifndef __KL_SYM_H | |
30389 | +#define __KL_SYM_H | |
30390 | + | |
30391 | +/* The syment struct contains information about kernel symbols (text, | |
30392 | + * data, etc.). The first field in syment_t is a btnode_s sruct. This | |
30393 | + * allows the generic binary search tree routines, insert_tnode() and | |
30394 | + * find_tnode(), to be used. | |
30395 | + */ | |
30396 | +typedef struct syment_s { | |
30397 | + btnode_t s_bt; /* Must be first */ | |
30398 | + struct syment_s *s_next; /* For linked lists */ | |
30399 | + struct syment_s *s_prev; /* For linked lists */ | |
30400 | + kaddr_t s_addr; /* vaddr of symbol */ | |
30401 | + kaddr_t s_end; /* end address of symbol */ | |
30402 | + int s_type; /* text, data */ | |
30403 | + struct syment_s *s_forward; /* For linked lists */ | |
30404 | +} syment_t; | |
30405 | + | |
30406 | +#define s_name s_bt.bt_key | |
30407 | + | |
30408 | +#define SYM_GLOBAL_TEXT 1 | |
30409 | +#define SYM_LOCAL_TEXT 2 | |
30410 | +#define SYM_LOCORE_TEXT 3 | |
30411 | +#define SYM_GLOBAL_DATA 4 | |
30412 | +#define SYM_LOCAL_DATA 5 | |
30413 | +#define SYM_ABS 6 | |
30414 | +#define SYM_UNK 9 | |
30415 | +#define SYM_KSYM 10 | |
30416 | +#define SYM_KSYM_TEXT 11 | |
30417 | +#define SYM_KALLSYMS 12 | |
30418 | + | |
30419 | +#define SYM_MAP_ANY 0 | |
30420 | +#define SYM_MAP_FILE 1 | |
30421 | +#define SYM_MAP_KSYM 2 | |
30422 | +#define SYM_MAP_MODULE 3 | |
30423 | +#define SYM_MAP_KALLSYMS 4 | |
30424 | + | |
30425 | +#define KL_KERNEL_MODULE "kernel_module" | |
30426 | +#define KL_S_BSS ".bss.start" | |
30427 | +#define KL_E_BSS ".bss.end" | |
30428 | +#define KL_S_DATA ".data.start" | |
30429 | +#define KL_E_DATA ".data.end" | |
30430 | +#define KL_S_RODATA ".rodata.start" | |
30431 | +#define KL_E_RODATA ".rodata.end" | |
30432 | +#define KL_S_TEXT ".text.start" | |
30433 | +#define KL_E_TEXT ".text.end" | |
30434 | +#define KL_SYM_END "__end__" | |
30435 | + | |
30436 | + | |
30437 | +#define KL_SYMBOL_NAME_LEN 256 | |
30438 | + | |
30439 | +/* | |
30440 | + * Struct containing symbol table information | |
30441 | + */ | |
30442 | +typedef struct symtab_s { | |
30443 | + int symcnt; /* Number of symbols */ | |
30444 | + int symaddrcnt; /* Number of symbol addrs to track */ | |
30445 | + syment_t **symaddrs; /* Table of symbols by address */ | |
30446 | + btnode_t *symnames; /* tree of symbols by name */ | |
30447 | + syment_t *text_list; /* Linked list of text symbols */ | |
30448 | + syment_t *data_list; /* Linked list of data symbols */ | |
30449 | +} symtab_t; | |
30450 | + | |
30451 | + | |
30452 | +/* support of further mapfiles besides System.map */ | |
30453 | +typedef struct maplist_s { | |
30454 | + struct maplist_s *next; | |
30455 | + int maplist_type; /* type of maplist */ | |
30456 | + char *mapfile; /* name of mapfile */ | |
30457 | + char *modname; /* set if map belongs to a module */ | |
30458 | + symtab_t *syminfo; | |
30459 | +} maplist_t; | |
30460 | + | |
30461 | + | |
30462 | +/* API Function prototypes | |
30463 | + */ | |
30464 | +int kl_read_syminfo(maplist_t*); | |
30465 | +int kl_free_syminfo(char*); | |
30466 | +void kl_free_symtab(symtab_t*); | |
30467 | +void kl_free_syment_list(syment_t*); | |
30468 | +void kl_free_maplist(maplist_t*); | |
30469 | +syment_t *kl_get_similar_name(char*, char*, int*, int*); | |
30470 | +syment_t *kl_lkup_symname(char*); | |
30471 | +syment_t *_kl_lkup_symname(char*, int, size_t len); | |
30472 | +#define KL_LKUP_SYMNAME(NAME, TYPE, LEN) _kl_lkup_symname(NAME, TYPE, LEN) | |
30473 | +syment_t *kl_lkup_funcaddr(kaddr_t); | |
30474 | +syment_t *kl_lkup_symaddr(kaddr_t); | |
30475 | +syment_t *kl_lkup_symaddr_text(kaddr_t); | |
30476 | +syment_t *_kl_lkup_symaddr(kaddr_t, int); | |
30477 | +#define KL_LKUP_SYMADDR(KADDR, TYPE) _kl_lkup_symaddr(KADDR, TYPE) | |
30478 | +kaddr_t kl_symaddr(char * /* symbol name */); | |
30479 | +kaddr_t kl_symptr(char * /* symbol name */); | |
30480 | +kaddr_t kl_funcaddr(kaddr_t /* pc value */); | |
30481 | +char *kl_funcname(kaddr_t /* pc value */); | |
30482 | +int kl_funcsize(kaddr_t /* pc value */); | |
30483 | +int kl_symsize(syment_t*); | |
30484 | +syment_t *kl_alloc_syment(kaddr_t, kaddr_t, int, const char*); | |
30485 | +void kl_insert_symbols(symtab_t*, syment_t*); | |
30486 | +int kl_insert_artificial_symbols(symtab_t*, syment_t**, kl_modinfo_t*); | |
30487 | +int kl_convert_symbol(kaddr_t*, int*, char, kl_modinfo_t*); | |
30488 | +int kl_load_sym(char*); | |
30489 | +int kl_print_symtables(char*, char*, int, int); | |
30490 | +void kl_print_symbol(kaddr_t, syment_t*, int); | |
30491 | + | |
30492 | +/* flag for use by kl_print_symbol() and kl_print_syminfo() | |
30493 | + */ | |
30494 | +#define KL_SYMWOFFSET (0x01) /* with offset field */ | |
30495 | +#define KL_SYMFULL (0x02) /* print detailed syminfo */ | |
30496 | +#define KL_SYMBYNAME (0x04) /* print symbol sorted by name */ | |
30497 | + | |
30498 | +#endif /* __KL_SYM_H */ | |
30499 | --- /dev/null | |
30500 | +++ b/kdb/modules/lcrash/kl_task.h | |
30501 | @@ -0,0 +1,39 @@ | |
30502 | +/* | |
30503 | + * $Id: kl_task.h 1122 2004-12-21 23:26:23Z tjm $ | |
30504 | + * | |
30505 | + * This file is part of libklib. | |
30506 | + * A library which provides access to Linux system kernel dumps. | |
30507 | + * | |
30508 | + * Created by Silicon Graphics, Inc. | |
30509 | + * Contributions by IBM, NEC, and others | |
30510 | + * | |
30511 | + * Copyright (C) 1999 - 2002, 2004 Silicon Graphics, Inc. All rights reserved. | |
30512 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
30513 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
30514 | + * | |
30515 | + * This code is free software; you can redistribute it and/or modify | |
30516 | + * it under the terms of the GNU Lesser Public License as published by | |
30517 | + * the Free Software Foundation; either version 2.1 of the License, or | |
30518 | + * (at your option) any later version. See the file COPYING for more | |
30519 | + * information. | |
30520 | + */ | |
30521 | + | |
30522 | +#ifndef __KL_TASK_H | |
30523 | +#define __KL_TASK_H | |
30524 | + | |
30525 | +extern kaddr_t deftask; | |
30526 | + | |
30527 | +/* Function prototypes | |
30528 | + */ | |
30529 | +k_error_t kl_set_deftask(kaddr_t); | |
30530 | +int kl_parent_pid(void *); | |
30531 | +kaddr_t kl_pid_to_task(kaddr_t); | |
30532 | +k_error_t kl_get_task_struct(kaddr_t, int, void *); | |
30533 | +kaddr_t kl_kernelstack(kaddr_t); | |
30534 | +kaddr_t kl_first_task(void); | |
30535 | +kaddr_t kl_next_task(void *); | |
30536 | +kaddr_t kl_prev_task(void *); | |
30537 | +kaddr_t kl_pid_to_task(kaddr_t); | |
30538 | +int kl_task_size(kaddr_t); | |
30539 | + | |
30540 | +#endif /* __KL_TASK_H */ | |
30541 | --- /dev/null | |
30542 | +++ b/kdb/modules/lcrash/kl_typeinfo.h | |
30543 | @@ -0,0 +1,199 @@ | |
30544 | +/* | |
30545 | + * $Id: kl_typeinfo.h 1259 2006-04-25 18:33:20Z tjm $ | |
30546 | + * | |
30547 | + * This file is part of libklib. | |
30548 | + * A library which provides access to Linux system kernel dumps. | |
30549 | + * | |
30550 | + * Created by Silicon Graphics, Inc. | |
30551 | + * Contributions by IBM, NEC, and others | |
30552 | + * | |
30553 | + * Copyright (C) 1999 - 2006 Silicon Graphics, Inc. All rights reserved. | |
30554 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
30555 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
30556 | + * | |
30557 | + * This code is free software; you can redistribute it and/or modify | |
30558 | + * it under the terms of the GNU Lesser Public License as published by | |
30559 | + * the Free Software Foundation; either version 2.1 of the License, or | |
30560 | + * (at your option) any later version. See the file COPYING for more | |
30561 | + * information. | |
30562 | + */ | |
30563 | + | |
30564 | +#ifndef __KL_TYPEINFO_H | |
30565 | +#define __KL_TYPEINFO_H | |
30566 | + | |
30567 | +#define KLT_BASE 0x001 | |
30568 | +#define KLT_STRUCT 0x002 | |
30569 | +#define KLT_UNION 0x004 | |
30570 | +#define KLT_ENUMERATION 0x008 | |
30571 | +#define KLT_MEMBER 0x010 | |
30572 | +#define KLT_ARRAY 0x020 | |
30573 | +#define KLT_POINTER 0x040 | |
30574 | +#define KLT_TYPEDEF 0x080 | |
30575 | +#define KLT_FUNCTION 0x100 | |
30576 | +#define KLT_VARIABLE 0x200 | |
30577 | +#define KLT_SRCFILE 0x400 | |
30578 | +#define KLT_SUBRANGE 0x800 | |
30579 | +#define KLT_INCOMPLETE 0x4000 | |
30580 | +#define KLT_UNKNOWN 0x8000 | |
30581 | +#define KLT_TYPE (KLT_BASE|KLT_STRUCT|KLT_UNION|KLT_ENUMERATION) | |
30582 | +#define KLT_TYPES (KLT_BASE|KLT_STRUCT|KLT_UNION|KLT_ENUMERATION|KLT_TYPEDEF) | |
30583 | + | |
30584 | +#define IS_TYPE(T) ((T) & KLT_TYPE) | |
30585 | +#define IS_STRUCT(T) ((T) & KLT_STRUCT) | |
30586 | +#define IS_UNION(T) ((T) & KLT_UNION) | |
30587 | +#define IS_ENUM(T) ((T) & KLT_ENUM) | |
30588 | +#define IS_MEMBER(T) ((T) & KLT_MEMBER) | |
30589 | +#define IS_POINTER(T) ((T) & KLT_POINTER) | |
30590 | +#define IS_TYPEDEF(T) ((T) & KLT_TYPEDEF) | |
30591 | + | |
30592 | +#define TYP_SETUP_FLG 0x01 | |
30593 | +#define TYP_TYPESTRING_FLG 0x02 | |
30594 | +#define TYP_INCOMPLETE_FLG 0x04 | |
30595 | +#define TYP_XREFERENCE_FLG 0x08 | |
30596 | +#define TYP_ANONYMOUS_FLG 0x10 /* Denotes anonymous union or struct */ | |
30597 | + | |
30598 | +#define NO_INDENT 0x01000000 | |
30599 | +#define SUPPRESS_NAME 0x02000000 | |
30600 | +#define SUPPRESS_NL 0x04000000 | |
30601 | +#define SUPPRESS_SEMI_COLON 0x08000000 | |
30602 | +#define NO_REALTYPE 0x10000000 | |
30603 | + | |
30604 | +extern int numnmlist; | |
30605 | + | |
30606 | +#define KL_TYPEINFO() (numnmlist) | |
30607 | + | |
30608 | +typedef struct kltype_s { | |
30609 | + char *kl_name; /* type name */ | |
30610 | + char *kl_typestr; /* 'typecast' string */ | |
30611 | + void *kl_ptr; /* ptr to arch typeinfo */ | |
30612 | + int kl_flags; /* (e.g., STAB_FLG) */ | |
30613 | + int kl_type; /* (e.g., KLT_TYPEDEF) */ | |
30614 | + int kl_offset; /* offset to 1st byte */ | |
30615 | + int kl_size; /* number of bytes */ | |
30616 | + int kl_bit_offset; /* offset to 1st data bit */ | |
30617 | + int kl_bit_size; /* total num of data bits */ | |
30618 | + int kl_encoding; /* for base value types */ | |
30619 | + int kl_low_bounds; /* for arrays */ | |
30620 | + int kl_high_bounds; /* for arrays */ | |
30621 | + unsigned int kl_value; /* enum value, etc. */ | |
30622 | + struct kltype_s *kl_member; /* struct/union member list */ | |
30623 | + struct kltype_s *kl_next; /* hash lists, etc. */ | |
30624 | + struct kltype_s *kl_realtype; /* pointer to real type */ | |
30625 | + struct kltype_s *kl_indextype; /* pointer to index_type */ | |
30626 | + struct kltype_s *kl_elementtype; /* pointer to element_type */ | |
30627 | +} kltype_t; | |
30628 | + | |
30629 | +/* Flag values | |
30630 | + */ | |
30631 | +#define K_HEX 0x1 | |
30632 | +#define K_OCTAL 0x2 | |
30633 | +#define K_BINARY 0x4 | |
30634 | +#define K_NO_SWAP 0x8 | |
30635 | + | |
30636 | +/* Base type encoding values | |
30637 | + */ | |
30638 | +#define ENC_CHAR 0x01 | |
30639 | +#define ENC_SIGNED 0x02 | |
30640 | +#define ENC_UNSIGNED 0x04 | |
30641 | +#define ENC_FLOAT 0x08 | |
30642 | +#define ENC_ADDRESS 0x10 | |
30643 | +#define ENC_UNDEFINED 0x20 | |
30644 | + | |
30645 | +/* Maximum number of open namelists | |
30646 | + */ | |
30647 | +#define MAXNMLIST 10 | |
30648 | + | |
30649 | +typedef struct nmlist_s { | |
30650 | + int index; | |
30651 | + char *namelist; | |
30652 | + void *private; /* pointer to private control struct */ | |
30653 | + string_table_t *stringtab; | |
30654 | +} nmlist_t; | |
30655 | + | |
30656 | +extern nmlist_t nmlist[]; | |
30657 | +extern int numnmlist; | |
30658 | +extern int curnmlist; | |
30659 | + | |
30660 | +#define KL_TYPESTR_STRUCT "struct" | |
30661 | +#define KL_TYPESTR_UNION "union" | |
30662 | +#define KL_TYPESTR_ENUM "enum" | |
30663 | +#define KL_TYPESTR_VOID "void" | |
30664 | + | |
30665 | +/* Function prototypes | |
30666 | + */ | |
30667 | +kltype_t *kl_find_type( | |
30668 | + char * /* type name */, | |
30669 | + int /* type number */); | |
30670 | + | |
30671 | +kltype_t *kl_find_next_type( | |
30672 | + kltype_t * /* kltype_t pointer */, | |
30673 | + int /* type number */); | |
30674 | + | |
30675 | +kltype_t *kl_first_type( | |
30676 | + int /* type number */); | |
30677 | + | |
30678 | +kltype_t *kl_next_type( | |
30679 | + kltype_t * /* kltype_t pointer */); | |
30680 | + | |
30681 | +kltype_t *kl_prev_type( | |
30682 | + kltype_t * /* kltype_t pointer */); | |
30683 | + | |
30684 | +kltype_t *kl_realtype( | |
30685 | + kltype_t * /* kltype_t pointer */, | |
30686 | + int /* type number */); | |
30687 | + | |
30688 | +kltype_t *kl_find_typenum( | |
30689 | + uint64_t /* private typenumber */); | |
30690 | + | |
30691 | +int kl_get_first_similar_typedef( | |
30692 | + char * /* type name */, | |
30693 | + char * /* fullname */); | |
30694 | + | |
30695 | +int kl_type_size( | |
30696 | + kltype_t * /* kltype_t pointer */); | |
30697 | + | |
30698 | +int kl_struct_len( | |
30699 | + char * /* struct name */); | |
30700 | + | |
30701 | +kltype_t *kl_get_member( | |
30702 | + kltype_t * /* kltype_t pointer */, | |
30703 | + char * /* member name */); | |
30704 | + | |
30705 | +int kl_get_member_offset( | |
30706 | + kltype_t * /* kltype_t pointer */, | |
30707 | + char * /* member name */); | |
30708 | + | |
30709 | +int kl_is_member( | |
30710 | + char * /* struct name */, | |
30711 | + char * /* member name */); | |
30712 | + | |
30713 | +kltype_t *kl_member( | |
30714 | + char * /* struct name */, | |
30715 | + char * /* member name */); | |
30716 | + | |
30717 | +int kl_member_offset( | |
30718 | + char * /* struct name */, | |
30719 | + char * /* member name */); | |
30720 | + | |
30721 | +int kl_member_size( | |
30722 | + char * /* struct name */, | |
30723 | + char * /* member name */); | |
30724 | + | |
30725 | +/* cpw: get rid of last arguent FILE * */ | |
30726 | +void kl_print_member(void *, kltype_t *, int, int); | |
30727 | +void kl_print_pointer_type(void *, kltype_t *, int, int); | |
30728 | +void kl_print_function_type(void *, kltype_t *, int, int); | |
30729 | +void kl_print_array_type(void *, kltype_t *, int, int); | |
30730 | +void kl_print_enumeration_type(void *, kltype_t *, int, int); | |
30731 | +void kl_print_base_type(void *, kltype_t *, int, int); | |
30732 | +void kl_print_type(void *, kltype_t *, int, int); | |
30733 | +void kl_print_struct_type(void *, kltype_t *, int, int); | |
30734 | +void kl_print_base_value(void *, kltype_t *, int); | |
30735 | + | |
30736 | +void kl_print_type( | |
30737 | + void * /* pointer to data */, | |
30738 | + kltype_t * /* pointer to type information */, | |
30739 | + int /* indent level */, | |
30740 | + int /* flags */); | |
30741 | + | |
30742 | +#endif /* __KL_TYPEINFO_H */ | |
30743 | --- /dev/null | |
30744 | +++ b/kdb/modules/lcrash/kl_types.h | |
30745 | @@ -0,0 +1,54 @@ | |
30746 | +/* | |
30747 | + * $Id: kl_types.h 1122 2004-12-21 23:26:23Z tjm $ | |
30748 | + * | |
30749 | + * This file is part of libklib. | |
30750 | + * A library which provides access to Linux system kernel dumps. | |
30751 | + * | |
30752 | + * Created by Silicon Graphics, Inc. | |
30753 | + * Contributions by IBM, NEC, and others | |
30754 | + * | |
30755 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
30756 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
30757 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
30758 | + * | |
30759 | + * This code is free software; you can redistribute it and/or modify | |
30760 | + * it under the terms of the GNU Lesser Public License as published by | |
30761 | + * the Free Software Foundation; either version 2.1 of the License, or | |
30762 | + * (at your option) any later version. See the file COPYING for more | |
30763 | + * information. | |
30764 | + */ | |
30765 | + | |
30766 | +#ifndef __KL_TYPES_H | |
30767 | +#define __KL_TYPES_H | |
30768 | + | |
30769 | +/* The following typedef should be used for variables or return values | |
30770 | + * that contain kernel virtual or physical addresses. It should be sized | |
30771 | + * such that it can hold both pointers of 64 bit architectures as well as | |
30772 | + * pointers from 32 bit architectures. | |
30773 | + */ | |
30774 | +typedef unsigned long kaddr_t; | |
30775 | + | |
30776 | +/* The following typedef should be used when converting a pointer value | |
30777 | + * (either kernel or application) to an unsigned value for pointer | |
30778 | + * calculations. | |
30779 | + */ | |
30780 | +typedef unsigned long uaddr_t; | |
30781 | + | |
30782 | +/* KLIB error type | |
30783 | + */ | |
30784 | +typedef uint64_t k_error_t; | |
30785 | + | |
30786 | +/* Typedef that allows a single fprintf() call to work for both | |
30787 | + * 32-bit and 64-bit pointer values. | |
30788 | + */ | |
30789 | +#define UADDR(X) ((kaddr_t)X) | |
30790 | +#define UADDR64(X) ((kaddr_t)X)) | |
30791 | +/* #define UADDR(X) ((uaddr_t)X) */ | |
30792 | +/* #define UADDR64(X) ((uint64_t)((uaddr_t)X)) */ | |
30793 | + | |
30794 | + | |
30795 | +/* cpw */ | |
30796 | +/* was: #include <asm/kl_types.h> */ | |
30797 | +#include "asm/kl_types.h" | |
30798 | + | |
30799 | +#endif /* __KL_TYPES_H */ | |
30800 | --- /dev/null | |
30801 | +++ b/kdb/modules/lcrash/klib.h | |
30802 | @@ -0,0 +1,480 @@ | |
30803 | +/* | |
30804 | + * $Id: klib.h 1336 2006-10-23 23:27:06Z tjm $ | |
30805 | + * | |
30806 | + * This file is part of libklib. | |
30807 | + * A library which provides access to Linux system kernel dumps. | |
30808 | + * | |
30809 | + * Created by Silicon Graphics, Inc. | |
30810 | + * Contributions by IBM, NEC, and others | |
30811 | + * | |
30812 | + * Copyright (C) 1999 - 2005 Silicon Graphics, Inc. All rights reserved. | |
30813 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
30814 | + * Copyright 2000 Junichi Nomura, NEC Solutions <j-nomura@ce.jp.nec.com> | |
30815 | + * | |
30816 | + * This code is free software; you can redistribute it and/or modify | |
30817 | + * it under the terms of the GNU Lesser Public License as published by | |
30818 | + * the Free Software Foundation; either version 2.1 of the License, or | |
30819 | + * (at your option) any later version. See the file COPYING for more | |
30820 | + * information. | |
30821 | + */ | |
30822 | + | |
30823 | +/* | |
30824 | + * klib.h -- Interface of the klib library, a library for access to | |
30825 | + * Linux system memory dumps. | |
30826 | + */ | |
30827 | + | |
30828 | +#ifndef __KLIB_H | |
30829 | +#define __KLIB_H | |
30830 | + | |
30831 | +/* Include header files | |
30832 | + */ | |
30833 | +#if 0 | |
30834 | + /* cpw: don't include all this: */ | |
30835 | +#include <stdio.h> | |
30836 | +#include <stdlib.h> | |
30837 | +#include <stdarg.h> | |
30838 | +#include <stdint.h> | |
30839 | +#include <unistd.h> | |
30840 | +#include <sys/stat.h> | |
30841 | +#include <unistd.h> | |
30842 | +#include <time.h> | |
30843 | +#include <sys/time.h> | |
30844 | +#include <sys/types.h> | |
30845 | +#include <fcntl.h> | |
30846 | +#include <string.h> | |
30847 | +#include <setjmp.h> | |
30848 | +#include <strings.h> | |
30849 | +#include <errno.h> | |
30850 | +#include <ctype.h> | |
30851 | +#include <bfd.h> | |
30852 | +#include <assert.h> | |
30853 | +#endif | |
30854 | + | |
30855 | +/* cpw: change all the below includes form the < > form to " " */ | |
30856 | + | |
30857 | +/* Include libutil header | |
30858 | + */ | |
30859 | +#include "kl_lib.h" | |
30860 | + | |
30861 | +/* Include libklib header files | |
30862 | + */ | |
30863 | +#include "kl_types.h" | |
30864 | +#include "kl_error.h" | |
30865 | +#include "kl_dump.h" | |
30866 | +#include "kl_mem.h" | |
30867 | +#include "kl_cmp.h" | |
30868 | +#include "kl_typeinfo.h" | |
30869 | +#include "kl_module.h" | |
30870 | +#include "kl_sym.h" | |
30871 | +#include "kl_bfd.h" | |
30872 | +#include "kl_debug.h" | |
30873 | +#include "kl_stabs.h" | |
30874 | +#include "kl_dwarfs.h" | |
30875 | +#include "kl_task.h" | |
30876 | +#include "kl_dump_arch.h" | |
30877 | + | |
30878 | + | |
30879 | +#ifndef TRUE | |
30880 | +# define TRUE 1 | |
30881 | +#endif | |
30882 | +#ifndef FALSE | |
30883 | +# define FALSE 0 | |
30884 | +#endif | |
30885 | + | |
30886 | +#ifndef MIN | |
30887 | +#define MIN(x,y) (((x)<(y))?(x):(y)) | |
30888 | +#endif | |
30889 | +#ifndef MAX | |
30890 | +#define MAX(x,y) (((x)>(y))?(x):(y)) | |
30891 | +#endif | |
30892 | + | |
30893 | +#define KL_NR_CPUS 128 | |
30894 | + | |
30895 | +/* We have to distinc between HOST_ARCH_* and DUMP_ARCH_*. These two classes of | |
30896 | + * macros are used througout the code for conditional compilation. | |
30897 | + * Additional we have following macros for comparison and switch statements. | |
30898 | + */ | |
30899 | +#define KL_ARCH_UNKNOWN 0 | |
30900 | +#define KL_ARCH_ALPHA 1 | |
30901 | +#define KL_ARCH_ARM 2 | |
30902 | +#define KL_ARCH_I386 3 | |
30903 | +#define KL_ARCH_IA64 4 | |
30904 | +#define KL_ARCH_M68K 5 | |
30905 | +#define KL_ARCH_MIPS 6 | |
30906 | +#define KL_ARCH_MIPS64 7 | |
30907 | +#define KL_ARCH_PPC 8 | |
30908 | +#define KL_ARCH_S390 9 | |
30909 | +#define KL_ARCH_SH 10 | |
30910 | +#define KL_ARCH_SPARK 11 | |
30911 | +#define KL_ARCH_SPARK64 12 | |
30912 | +#define KL_ARCH_S390X 13 | |
30913 | +#define KL_ARCH_PPC64 14 | |
30914 | +#define KL_ARCH_X86_64 15 | |
30915 | +#define KL_ARCH_IA64_SN2 16 | |
30916 | +#define KL_ARCH_IA64_DIG 17 | |
30917 | +#define KL_ARCH_IA64_HPSIM 18 | |
30918 | +#define KL_ARCH_IA64_HPZX1 19 | |
30919 | +#define KL_ARCH_S390SA 20 | |
30920 | + | |
30921 | +#define KL_LIVE_SYSTEM 1000 | |
30922 | + | |
30923 | +#define ARCH_IS_IA64(A) \ | |
30924 | + ((A==KL_ARCH_IA64)|| \ | |
30925 | + (A==KL_ARCH_IA64_SN2)|| \ | |
30926 | + (A==KL_ARCH_IA64_DIG)|| \ | |
30927 | + (A==KL_ARCH_IA64_HPSIM)|| \ | |
30928 | + (A==KL_ARCH_IA64_HPZX1)) | |
30929 | + | |
30930 | +#ifdef HOST_ARCH_ALPHA | |
30931 | +# define KL_HOST_ARCH KL_ARCH_ALPHA | |
30932 | +#endif | |
30933 | +#ifdef HOST_ARCH_ARM | |
30934 | +# define KL_HOST_ARCH KL_ARCH_ARM | |
30935 | +#endif | |
30936 | +#ifdef HOST_ARCH_I386 | |
30937 | +# define KL_HOST_ARCH KL_ARCH_I386 | |
30938 | +#endif | |
30939 | +#ifdef HOST_ARCH_IA64 | |
30940 | +# define KL_HOST_ARCH KL_ARCH_IA64 | |
30941 | +#endif | |
30942 | +#ifdef HOST_ARCH_S390 | |
30943 | +# define KL_HOST_ARCH KL_ARCH_S390 | |
30944 | +#endif | |
30945 | +#ifdef HOST_ARCH_S390X | |
30946 | +# define KL_HOST_ARCH KL_ARCH_S390X | |
30947 | +#endif | |
30948 | +#ifdef HOST_ARCH_PPC64 | |
30949 | +#define KL_HOST_ARCH KL_ARCH_PPC64 | |
30950 | +#endif | |
30951 | +#ifdef HOST_ARCH_X86_64 | |
30952 | +#define KL_HOST_ARCH KL_ARCH_X86_64 | |
30953 | +#endif | |
30954 | + | |
30955 | +#define KL_ARCH_STR_ALPHA "alpha" | |
30956 | +#define KL_ARCH_STR_ARM "arm" | |
30957 | +#define KL_ARCH_STR_I386 "i386" | |
30958 | +#define KL_ARCH_STR_IA64 "ia64" | |
30959 | +#define KL_ARCH_STR_S390 "s390" | |
30960 | +#define KL_ARCH_STR_S390X "s390x" | |
30961 | +#define KL_ARCH_STR_PPC64 "ppc64" | |
30962 | +#define KL_ARCH_STR_X86_64 "x86_64" | |
30963 | +#define KL_ARCH_STR_IA64_SN2 "sn2" | |
30964 | +#define KL_ARCH_STR_UNKNOWN "unknown" | |
30965 | + | |
30966 | +/* for endianess of dump and host arch | |
30967 | + */ | |
30968 | +#define KL_UNKNOWN_ENDIAN 0x00 | |
30969 | +#define KL_LITTLE_ENDIAN 0x01 | |
30970 | +#define KL_BIG_ENDIAN 0x02 | |
30971 | + | |
30972 | +/* macros for handling of different Kernel versions | |
30973 | + */ | |
30974 | +#define LINUX_2_2_X(R) (((R) & 0xffff00) == 0x020200) | |
30975 | +#define LINUX_2_2_16 0x020210 | |
30976 | +#define LINUX_2_2_17 0x020211 | |
30977 | +#define LINUX_2_4_X(R) (((R) & 0xffff00) == 0x020400) | |
30978 | +#define LINUX_2_4_0 0x020400 | |
30979 | +#define LINUX_2_4_4 0x020404 | |
30980 | +#define LINUX_2_4_15 0x02040f | |
30981 | +#define LINUX_2_6_X(R) (((R) & 0xffff00) == 0x020600) | |
30982 | +#define LINUX_2_6_0 0x020600 | |
30983 | + | |
30984 | +/* libklib flags | |
30985 | + */ | |
30986 | +#define KL_FAILSAFE_FLG 0x0001 | |
30987 | +#define KL_NOVERIFY_FLG 0x0002 | |
30988 | +#define KL_SILENT_FLG 0x0004 | |
30989 | +#define KL_SAVETYPES_FLG 0x0008 | |
30990 | +#define KL_USETYPES_FLG 0x0010 | |
30991 | + | |
30992 | +/* macros for backward compatibility | |
30993 | + */ | |
30994 | +#define NUM_PHYSPAGES KLP->dump->mem.num_physpages | |
30995 | +#define MEM_MAP KLP->dump->mem.mem_map | |
30996 | +#define KL_HIGH_MEMORY KLP->dump->mem.high_memory | |
30997 | +#define KL_INIT_MM KLP->dump->mem.init_mm | |
30998 | +#define KL_NUM_CPUS KLP->dump->mem.num_cpus | |
30999 | +#define KL_PGDAT_LIST KLP->dump->mem.pgdat_list | |
31000 | + | |
31001 | +/* macros for better use of dump architecture dependent functions | |
31002 | + */ | |
31003 | + | |
31004 | +/* read integer value from buffer */ | |
31005 | +#define KL_GET_PTR(ptr) (*KLP->dump->func.get_ptr)(ptr) | |
31006 | +#define KL_GET_LONG(ptr) ((int64_t) KL_GET_PTR(ptr)) | |
31007 | +#define KL_GET_ULONG(ptr) KL_GET_PTR(ptr) | |
31008 | +#define KL_GET_UINT8(ptr) (*KLP->dump->func.get_uint8)(ptr) | |
31009 | +#define KL_GET_UINT16(ptr) (*KLP->dump->func.get_uint16)(ptr) | |
31010 | +#define KL_GET_UINT32(ptr) (*KLP->dump->func.get_uint32)(ptr) | |
31011 | +#define KL_GET_UINT64(ptr) (*KLP->dump->func.get_uint64)(ptr) | |
31012 | +#define KL_GET_INT8(ptr) ((int8_t) KL_GET_UINT8(ptr)) | |
31013 | +#define KL_GET_INT16(ptr) ((int16_t) KL_GET_UINT16(ptr)) | |
31014 | +#define KL_GET_INT32(ptr) ((int32_t) KL_GET_UINT32(ptr)) | |
31015 | +#define KL_GET_INT64(ptr) ((int64_t) KL_GET_UINT64(ptr)) | |
31016 | + | |
31017 | +/* read integer value from dump (without address mapping) | |
31018 | + * Use these functions sparsely, e.g. before address translation | |
31019 | + * is properly set up. | |
31020 | + */ | |
31021 | +#define KL_READ_PTR(addr) (*KLP->dump->func.read_ptr)(addr) | |
31022 | +#define KL_READ_LONG(addr) ((int64_t) KL_READ_PTR(addr)) | |
31023 | +#define KL_READ_ULONG(addr) KL_READ_PTR(addr) | |
31024 | +#define KL_READ_UINT8(addr) (*KLP->dump->func.read_uint8)(addr) | |
31025 | +#define KL_READ_UINT16(addr) (*KLP->dump->func.read_uint16)(addr) | |
31026 | +#define KL_READ_UINT32(addr) (*KLP->dump->func.read_uint32)(addr) | |
31027 | +#define KL_READ_UINT64(addr) (*KLP->dump->func.read_uint64)(addr) | |
31028 | +#define KL_READ_INT8(addr) ((int8_t) KL_READ_UINT8(addr)) | |
31029 | +#define KL_READ_INT16(addr) ((int16_t) KL_READ_UINT16(addr)) | |
31030 | +#define KL_READ_INT32(addr) ((int32_t) KL_READ_UINT32(addr)) | |
31031 | +#define KL_READ_INT64(addr) ((int64_t) KL_READ_UINT64(addr)) | |
31032 | + | |
31033 | +/* read integer value from dump (from virtual address) doing address mapping */ | |
31034 | +#define KL_VREAD_PTR(addr) (*KLP->dump->func.vread_ptr)(addr) | |
31035 | +#define KL_VREAD_LONG(addr) ((int64_t) KL_VREAD_PTR(addr)) | |
31036 | +#define KL_VREAD_ULONG(addr) KL_VREAD_PTR(addr) | |
31037 | +#define KL_VREAD_UINT8(addr) (*KLP->dump->func.vread_uint8)(addr) | |
31038 | +#define KL_VREAD_UINT16(addr) (*KLP->dump->func.vread_uint16)(addr) | |
31039 | +#define KL_VREAD_UINT32(addr) (*KLP->dump->func.vread_uint32)(addr) | |
31040 | +#define KL_VREAD_UINT64(addr) (*KLP->dump->func.vread_uint64)(addr) | |
31041 | +#define KL_VREAD_INT8(addr) ((int8_t) KL_VREAD_UINT8(addr)) | |
31042 | +#define KL_VREAD_INT16(addr) ((int16_t) KL_VREAD_UINT16(addr)) | |
31043 | +#define KL_VREAD_INT32(addr) ((int32_t) KL_VREAD_UINT32(addr)) | |
31044 | +#define KL_VREAD_INT64(addr) ((int64_t) KL_VREAD_UINT64(addr)) | |
31045 | + | |
31046 | +/* determine start of stack */ | |
31047 | +#define KL_KERNELSTACK_UINT64 (*KLP->dump->arch.kernelstack) | |
31048 | +/* map virtual adress to physical one */ | |
31049 | +#define KL_VIRTOP (*KLP->dump->arch.virtop) | |
31050 | +/* travers page table */ | |
31051 | +#define KL_MMAP_VIRTOP (*KLP->dump->arch.mmap_virtop) | |
31052 | +/* check whether address points to valid physical memory */ | |
31053 | +#define KL_VALID_PHYSMEM (*KLP->dump->arch.valid_physmem) | |
31054 | +/* determine next valid physical address */ | |
31055 | +#define KL_NEXT_VALID_PHYSADDR (*KLP->dump->arch.next_valid_physaddr) | |
31056 | +/* XXX */ | |
31057 | +#define KL_FIX_VADDR (*KLP->dump->arch.fix_vaddr) | |
31058 | +/* write dump_header_asm_t */ | |
31059 | +#define KL_WRITE_DHA (*KLP->dump->arch.write_dha) | |
31060 | +/* size of dump_header_asm_t */ | |
31061 | +#define KL_DHA_SIZE (KLP->dump->arch.dha_size) | |
31062 | +/* init virtual to physical address mapping */ | |
31063 | +#define KL_INIT_VIRTOP (KLP->dump->arch.init_virtop) | |
31064 | + | |
31065 | + | |
31066 | +/* macros for easier access to dump specific values */ | |
31067 | +#define KL_CORE_TYPE KLP->dump->core_type | |
31068 | +#define KL_CORE_FD KLP->dump->core_fd | |
31069 | +#define KL_ARCH KLP->dump->arch.arch | |
31070 | +#define KL_PTRSZ KLP->dump->arch.ptrsz | |
31071 | +#define KL_NBPW (KL_PTRSZ/8) | |
31072 | +#define KL_BYTE_ORDER KLP->dump->arch.byteorder | |
31073 | +#define KL_PAGE_SHIFT KLP->dump->arch.pageshift | |
31074 | +#define KL_PAGE_SIZE KLP->dump->arch.pagesize | |
31075 | +#define KL_PAGE_MASK KLP->dump->arch.pagemask | |
31076 | +#define KL_PAGE_OFFSET KLP->dump->arch.pageoffset | |
31077 | +#define KL_STACK_OFFSET KLP->dump->arch.kstacksize | |
31078 | +#define IS_BIG_ENDIAN() (KL_BYTE_ORDER == KL_BIG_ENDIAN) | |
31079 | +#define IS_LITTLE_ENDIAN() (KL_BYTE_ORDER == KL_LITTLE_ENDIAN) | |
31080 | +#define KL_LINUX_RELEASE KLP->dump->mem.linux_release | |
31081 | +#define KL_KERNEL_FLAGS KLP->dump->mem.kernel_flags | |
31082 | + | |
31083 | +#if 0 | |
31084 | +/* cpw: don't need all this dump file stuff: */ | |
31085 | +/* macros to access input files */ | |
31086 | +#define KL_MAP_FILE KLP->dump->map | |
31087 | +#define KL_DUMP_FILE KLP->dump->dump | |
31088 | +#define KL_KERNTYPES_FILE KLP->kerntypes | |
31089 | + | |
31090 | +#define CORE_IS_KMEM (KL_CORE_TYPE == dev_kmem) | |
31091 | +#define CORE_IS_DUMP ((KL_CORE_TYPE > dev_kmem) && (KL_CORE_TYPE <= unk_core)) | |
31092 | + | |
31093 | + | |
31094 | +/* Generic dump header structure (the first three members of | |
31095 | + * dump_header and dump_header_asm are the same). | |
31096 | + */ | |
31097 | +typedef struct generic_dump_header_s { | |
31098 | + uint64_t magic_number; | |
31099 | + uint32_t version; | |
31100 | + uint32_t header_size; | |
31101 | +} generic_dump_header_t; | |
31102 | + | |
31103 | +/* Some macros for making it easier to access the generic header | |
31104 | + * information in a dump_header or dump_header_asm stuct. | |
31105 | + */ | |
31106 | +#define DHP(dh) ((generic_dump_header_t*)(dh)) | |
31107 | +#define DH_MAGIC(dh) DHP(dh)->magic_number | |
31108 | +#define DH_VERSION(dh) DHP(dh)->version | |
31109 | +#define DH_HEADER_SIZE(dh) DHP(dh)->header_size | |
31110 | + | |
31111 | +extern kl_dump_header_t *DUMP_HEADER; | |
31112 | +extern void *DUMP_HEADER_ASM; | |
31113 | +#endif | |
31114 | + | |
31115 | +/* Struct to store some host architecture specific values | |
31116 | + */ | |
31117 | +typedef struct kl_hostarch_s { | |
31118 | + int arch; /* KL_ARCH_ */ | |
31119 | + int ptrsz; /* 32 or 64 bit */ | |
31120 | + int byteorder; /* KL_LITTLE_ENDIAN or KL_BIG_ENDIAN */ | |
31121 | +} kl_hostarch_t; | |
31122 | + | |
31123 | +/* Struct klib_s, contains all the information necessary for accessing | |
31124 | + * information in the kernel. A pointer to a klib_t struct will be | |
31125 | + * returned from libkern_init() if core dump analysis (or live system | |
31126 | + * analysis) is possible. | |
31127 | + * | |
31128 | + */ | |
31129 | +typedef struct klib_s { | |
31130 | + int k_flags; /* Flags pertaining to klib_s struct */ | |
31131 | + kl_hostarch_t *host; /* host arch info */ | |
31132 | + kl_dumpinfo_t *dump; /* dump information */ | |
31133 | + maplist_t *k_symmap; /* symbol information */ | |
31134 | + kltype_t *k_typeinfo; /* type information */ | |
31135 | + char *kerntypes; /* pathname for kerntypes file */ | |
31136 | +} klib_t; | |
31137 | + | |
31138 | +/* Structure to accomodate all debug formats */ | |
31139 | +struct namelist_format_opns { | |
31140 | + /* to open/setup the namelist file */ | |
31141 | + int (*open_namelist) (char *filename , int flags); | |
31142 | + int (*setup_typeinfo)(void); | |
31143 | +}; | |
31144 | + | |
31145 | +/* | |
31146 | + * global variables | |
31147 | + */ | |
31148 | + | |
31149 | +/* Here we store almost everything, we need to know about a dump. */ | |
31150 | +extern klib_t *KLP; | |
31151 | + | |
31152 | +/* macros to make live easier */ | |
31153 | +#define MIP KLP->dump | |
31154 | +#define STP KLP->k_symmap | |
31155 | +#define TASK_STRUCT_SZ (KLP->dump->mem.struct_sizes.task_struct_sz) | |
31156 | +#define MM_STRUCT_SZ (KLP->dump->mem.struct_sizes.mm_struct_sz) | |
31157 | +#define PAGE_SZ (KLP->dump->mem.struct_sizes.page_sz) | |
31158 | +#define MODULE_SZ (KLP->dump->mem.struct_sizes.module_sz) | |
31159 | +#define NEW_UTSNAME_SZ (KLP->dump->mem.struct_sizes.new_utsname_sz) | |
31160 | +#define SWITCH_STACK_SZ (KLP->dump->mem.struct_sizes.switch_stack_sz) | |
31161 | +#define PT_REGS_SZ (KLP->dump->mem.struct_sizes.pt_regs_sz) | |
31162 | +#define PGLIST_DATA_SZ (KLP->dump->mem.struct_sizes.pglist_data_sz) | |
31163 | +#define RUNQUEUE_SZ (KLP->dump->mem.struct_sizes.runqueue_sz) | |
31164 | + | |
31165 | +#if 0 | |
31166 | +cpw: used for sial? | |
31167 | +/* klib_jbuf has to be defined outside libklib. | |
31168 | + * Make sure to call setjmp(klib_jbuf) BEFORE kl_sig_setup() is called! */ | |
31169 | +extern jmp_buf klib_jbuf; | |
31170 | +#endif | |
31171 | + | |
31172 | +/* Macros that eliminate the offset paramaters to the kl_uint() and kl_int() | |
31173 | + * functions (just makes things cleaner looking) | |
31174 | + */ | |
31175 | +#define KL_UINT(p, s, m) kl_uint(p, s, m, 0) | |
31176 | +#define KL_INT(p, s, m) kl_int(p, s, m, 0) | |
31177 | + | |
31178 | +/* Macros for translating strings into long numeric values depending | |
31179 | + * on the base of 's'. | |
31180 | + */ | |
31181 | +#define GET_VALUE(s, value) kl_get_value(s, NULL, 0, value) | |
31182 | +#define GET_HEX_VALUE(s) (kaddr_t)strtoull(s, (char**)NULL, 16) | |
31183 | +#define GET_DEC_VALUE(s) (unsigned)strtoull(s, (char**)NULL, 10) | |
31184 | +#define GET_OCT_VALUE(s) (unsigned)strtoull(s, (char**)NULL, 8) | |
31185 | + | |
31186 | +#define KL_SIGFLG_CORE 0x1 | |
31187 | +#define KL_SIGFLG_SILENT 0x2 | |
31188 | +#define KL_SIGFLG_LNGJMP 0x4 | |
31189 | + | |
31190 | +/* Flag that tells kl_is_valid_kaddr() to perform a word aligned check | |
31191 | + */ | |
31192 | +#define WORD_ALIGN_FLAG 1 | |
31193 | + | |
31194 | +#define ADDR_TO_PGNO(addr) ((addr - KL_PAGE_OFFSET) >> KL_PAGE_SHIFT); | |
31195 | + | |
31196 | +/* Generalized macros for pointing at different data types at particular | |
31197 | + * offsets in kernel structs. | |
31198 | + */ | |
31199 | +/* #define K_ADDR(p, s, f) ((uaddr_t)(p) + kl_member_offset(s, f)) */ | |
31200 | +#define K_ADDR(p, s, f) ((p) + kl_member_offset(s, f)) | |
31201 | +#define K_PTR(p, s, f) (K_ADDR((void*)p, s, f)) | |
31202 | +#define CHAR(p, s, f) (K_ADDR((char*)p, s, f)) | |
31203 | + | |
31204 | +#define PTRSZ32 ((KL_PTRSZ == 32) ? 1 : 0) | |
31205 | +#define PTRSZ64 ((KL_PTRSZ == 64) ? 1 : 0) | |
31206 | + | |
31207 | +/* Function prototypes | |
31208 | + */ | |
31209 | +/* cpw: remove the last argument FILE * */ | |
31210 | +void kl_binary_print(uint64_t); | |
31211 | +void kl_print_bit_value(void *, int, int, int, int); | |
31212 | +void kl_print_char(void *, int); | |
31213 | +void kl_print_uchar(void *, int); | |
31214 | +void kl_print_int2(void *, int); | |
31215 | +void kl_print_uint2(void *, int); | |
31216 | +void kl_print_int4(void *, int); | |
31217 | +void kl_print_uint4(void *, int); | |
31218 | +void kl_print_float4(void *, int); | |
31219 | +void kl_print_int8(void *, int); | |
31220 | +void kl_print_uint8(void *, int); | |
31221 | +void kl_print_float8(void *, int); | |
31222 | +void kl_print_base(void *, int, int, int); | |
31223 | +void kl_print_string(char *); | |
31224 | + | |
31225 | +int kl_get_live_filenames( | |
31226 | + char * /* pointer to buffer for map filename */, | |
31227 | + char * /* pointer to buffer for dump filename */, | |
31228 | + char * /* pointer to buffer for namelist filename */); | |
31229 | + | |
31230 | +int kl_init_klib( | |
31231 | + char * /* map file name */, | |
31232 | + char * /* dump file name */, | |
31233 | + char * /* namelist file name */, | |
31234 | + int /* system arch of memory in dump */, | |
31235 | + int /* rwflag flag (/dev/mem only) */, | |
31236 | + int /* Linux release */); | |
31237 | + | |
31238 | +void kl_free_klib( | |
31239 | + klib_t * /* Pointer to klib_s struct */); | |
31240 | + | |
31241 | + | |
31242 | +int kl_dump_retrieve( | |
31243 | + char * /* dumpdev name */, | |
31244 | + char * /* dumpdir name */, | |
31245 | + int /* progress flag (zero or non-zero) */, | |
31246 | + int /* debug flag (zero or non-zero) */); | |
31247 | + | |
31248 | +int kl_dump_erase( | |
31249 | + char * /* dumpdev name */); | |
31250 | + | |
31251 | +uint64_t kl_strtoull( | |
31252 | + char * /* string containing numeric value */, | |
31253 | + char ** /* pointer to pointer to bad char */, | |
31254 | + int /* base */); | |
31255 | + | |
31256 | +int kl_get_value( | |
31257 | + char * /* param */, | |
31258 | + int * /* mode pointer */, | |
31259 | + int /* number of elements */, | |
31260 | + uint64_t * /* pointer to value */); | |
31261 | + | |
31262 | +/* Functions for working with list_head structs | |
31263 | + */ | |
31264 | +kaddr_t kl_list_entry(kaddr_t, char *, char *); | |
31265 | +kaddr_t kl_list_next(kaddr_t); | |
31266 | +kaddr_t kl_list_prev(kaddr_t); | |
31267 | + | |
31268 | +int kl_sig_setup(int); | |
31269 | + | |
31270 | +void kl_set_curnmlist( | |
31271 | + int /* index of namelist */); | |
31272 | + | |
31273 | +int kl_open_namelist( | |
31274 | + char * /* name of namelist */, | |
31275 | + int /* flags */, | |
31276 | + int /* kl_flags */); | |
31277 | + | |
31278 | +int kl_get_structure(kaddr_t, char*, size_t*, void**); | |
31279 | +uint64_t kl_get_bit_value(void*, unsigned int, unsigned int, unsigned int); | |
31280 | +void kl_s390tod_to_timeval(uint64_t, struct timeval*); | |
31281 | + | |
31282 | +#endif /* __KLIB_H */ | |
31283 | --- /dev/null | |
31284 | +++ b/kdb/modules/lcrash/lc_eval.h | |
31285 | @@ -0,0 +1,225 @@ | |
31286 | +/* | |
31287 | + * $Id: lc_eval.h 1122 2004-12-21 23:26:23Z tjm $ | |
31288 | + * | |
31289 | + * This file is part of lcrash, an analysis tool for Linux memory dumps. | |
31290 | + * | |
31291 | + * Created by Silicon Graphics, Inc. | |
31292 | + * Contributions by IBM, and others | |
31293 | + * | |
31294 | + * Copyright (C) 1999 - 2002 Silicon Graphics, Inc. All rights reserved. | |
31295 | + * Copyright (C) 2001, 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation | |
31296 | + * | |
31297 | + * This program is free software; you can redistribute it and/or modify | |
31298 | + * it under the terms of the GNU General Public License as published by | |
31299 | + * the Free Software Foundation; either version 2 of the License, or | |
31300 | + * (at your option) any later version. See the file COPYING for more | |
31301 | + * information. | |
31302 | + */ | |
31303 | + | |
31304 | +#ifndef __LC_EVAL_H | |
31305 | +#define __LC_EVAL_H | |
31306 | + | |
31307 | +typedef struct type_s { | |
31308 | + int flag; | |
31309 | + union { | |
31310 | + struct type_s *next; | |
31311 | + kltype_t *kltp; | |
31312 | + } un; | |
31313 | +} type_t; | |
31314 | + | |
31315 | +#define t_next un.next | |
31316 | +#define t_kltp un.kltp | |
31317 | + | |
31318 | +/* Structure to hold info on "tokens" extracted from eval and print | |
31319 | + * command input strings. | |
31320 | + */ | |
31321 | +typedef struct token_s { | |
31322 | + short type; | |
31323 | + short operator; /* if token is an operator */ | |
31324 | + char *string; /* string holding value or identifier */ | |
31325 | + char *ptr; /* pointer to start of token */ | |
31326 | + struct token_s *next; /* next token in the chain */ | |
31327 | +} token_t; | |
31328 | + | |
31329 | +/* Structure returned by the eval() function containing the result | |
31330 | + * of an expression evaluation. This struct is also used to build the | |
31331 | + * parse tree for the expression. | |
31332 | + */ | |
31333 | +typedef struct node_s { | |
31334 | + struct node_s *next; /* linked list pointer */ | |
31335 | + unsigned char node_type; /* type of node */ | |
31336 | + unsigned short flags; /* see below */ | |
31337 | + unsigned char operator; /* operator if node is type OPERATOR */ | |
31338 | + unsigned char byte_size; /* byte_size of base_type values */ | |
31339 | + char *name; /* name of variable or struct member */ | |
31340 | + /* value and address are uint64_t in lcrash, but for ia32 ... */ | |
31341 | + unsigned long long value; /* numeric value or pointer */ | |
31342 | + unsigned long address; /* address (could be same as pointer) */ | |
31343 | + type_t *type; /* pointer to type related info */ | |
31344 | + char *tok_ptr; /* pointer to token in cmd string */ | |
31345 | + struct node_s *left; /* pointer to left child */ | |
31346 | + struct node_s *right; /* pointer to right child */ | |
31347 | +} node_t; | |
31348 | + | |
31349 | +/* Token and Node types | |
31350 | + */ | |
31351 | +#define OPERATOR 1 | |
31352 | +#define NUMBER 2 | |
31353 | +#define INDEX 3 | |
31354 | +#define TYPE_DEF 4 | |
31355 | +#define VADDR 5 | |
31356 | +#define MEMBER 6 | |
31357 | +#define STRING 7 | |
31358 | +#define TEXT 8 | |
31359 | +#define CHARACTER 9 | |
31360 | +#define EVAL_VAR 10 | |
31361 | + | |
31362 | +/* Flag values | |
31363 | + */ | |
31364 | +#define STRING_FLAG 0x001 | |
31365 | +#define ADDRESS_FLAG 0x002 | |
31366 | +#define INDIRECTION_FLAG 0x004 | |
31367 | +#define POINTER_FLAG 0x008 | |
31368 | +#define MEMBER_FLAG 0x010 | |
31369 | +#define BOOLIAN_FLAG 0x020 | |
31370 | +#define KLTYPE_FLAG 0x040 | |
31371 | +#define NOTYPE_FLAG 0x080 | |
31372 | +#define UNSIGNED_FLAG 0x100 | |
31373 | +#define VOID_FLAG 0x200 | |
31374 | + | |
31375 | +/* Flag value for print_eval_error() function | |
31376 | + */ | |
31377 | +#define CMD_NAME_FLG 1 /* cmdname is not name of a command */ | |
31378 | +#define CMD_STRING_FLG 2 /* cmdname is not name of a command */ | |
31379 | + | |
31380 | +/* Expression operators in order of precedence. | |
31381 | + */ | |
31382 | +#define CONDITIONAL 1 | |
31383 | +#define CONDITIONAL_ELSE 2 | |
31384 | +#define LOGICAL_OR 3 | |
31385 | +#define LOGICAL_AND 4 | |
31386 | +#define BITWISE_OR 5 | |
31387 | +#define BITWISE_EXCLUSIVE_OR 6 | |
31388 | +#define BITWISE_AND 7 | |
31389 | +#define EQUAL 8 | |
31390 | +#define NOT_EQUAL 9 | |
31391 | +#define LESS_THAN 10 | |
31392 | +#define GREATER_THAN 11 | |
31393 | +#define LESS_THAN_OR_EQUAL 12 | |
31394 | +#define GREATER_THAN_OR_EQUAL 13 | |
31395 | +#define RIGHT_SHIFT 14 | |
31396 | +#define LEFT_SHIFT 15 | |
31397 | +#define ADD 16 | |
31398 | +#define SUBTRACT 17 | |
31399 | +#define MULTIPLY 18 | |
31400 | +#define DIVIDE 19 | |
31401 | +#define MODULUS 20 | |
31402 | +#define LOGICAL_NEGATION 21 | |
31403 | +#define ONES_COMPLEMENT 22 | |
31404 | +#define PREFIX_INCREMENT 23 | |
31405 | +#define PREFIX_DECREMENT 24 | |
31406 | +#define POSTFIX_INCREMENT 25 | |
31407 | +#define POSTFIX_DECREMENT 26 | |
31408 | +#define CAST 27 | |
31409 | +#define UNARY_MINUS 28 | |
31410 | +#define UNARY_PLUS 29 | |
31411 | +#define INDIRECTION 30 | |
31412 | +#define ADDRESS 31 | |
31413 | +#define SIZEOF 32 | |
31414 | +#define RIGHT_ARROW 33 | |
31415 | +#define DOT 34 | |
31416 | +#define OPEN_PAREN 100 | |
31417 | +#define CLOSE_PAREN 101 | |
31418 | +#define OPEN_SQUARE_BRACKET 102 | |
31419 | +#define CLOSE_SQUARE_BRACKET 103 | |
31420 | +#define SEMI_COLON 104 | |
31421 | +#define NOT_YET -1 | |
31422 | + | |
31423 | +/* Errors codes primarily for use with eval (print) functions | |
31424 | + */ | |
31425 | +#define E_OPEN_PAREN 1100 | |
31426 | +#define E_CLOSE_PAREN 1101 | |
31427 | +#define E_BAD_STRUCTURE 1102 | |
31428 | +#define E_MISSING_STRUCTURE 1103 | |
31429 | +#define E_BAD_MEMBER 1104 | |
31430 | +#define E_BAD_OPERATOR 1105 | |
31431 | +#define E_BAD_OPERAND 1106 | |
31432 | +#define E_MISSING_OPERAND 1107 | |
31433 | +#define E_BAD_TYPE 1108 | |
31434 | +#define E_NOTYPE 1109 | |
31435 | +#define E_BAD_POINTER 1110 | |
31436 | +#define E_BAD_INDEX 1111 | |
31437 | +#define E_BAD_CHAR 1112 | |
31438 | +#define E_BAD_STRING 1113 | |
31439 | +#define E_END_EXPECTED 1114 | |
31440 | +#define E_BAD_EVAR 1115 /* Bad eval variable */ | |
31441 | +#define E_BAD_VALUE 1116 | |
31442 | +#define E_NO_VALUE 1117 | |
31443 | +#define E_DIVIDE_BY_ZERO 1118 | |
31444 | +#define E_BAD_CAST 1119 | |
31445 | +#define E_NO_ADDRESS 1120 | |
31446 | +#define E_SINGLE_QUOTE 1121 | |
31447 | + | |
31448 | +#define E_BAD_WHATIS 1197 | |
31449 | +#define E_NOT_IMPLEMENTED 1198 | |
31450 | +#define E_SYNTAX_ERROR 1199 | |
31451 | + | |
31452 | +extern uint64_t eval_error; | |
31453 | +extern char *error_token; | |
31454 | + | |
31455 | +/* Function prototypes | |
31456 | + */ | |
31457 | +node_t *eval(char **, int); | |
31458 | +void print_eval_error(char *, char *, char *, uint64_t, int); | |
31459 | +void free_nodes(node_t *); | |
31460 | + | |
31461 | +/* Struct to hold information about eval variables | |
31462 | + */ | |
31463 | +typedef struct variable_s { | |
31464 | + btnode_t v_bt; /* Must be first */ | |
31465 | + int v_flags; | |
31466 | + char *v_exp; /* What was entered on command line */ | |
31467 | + char *v_typestr; /* Actual type string after eval() call */ | |
31468 | + node_t *v_node; | |
31469 | +} variable_t; | |
31470 | + | |
31471 | +#define v_left v_bt.bt_left | |
31472 | +#define v_right v_bt.bt_right | |
31473 | +#define v_name v_bt.bt_key | |
31474 | + | |
31475 | +/* Flag values | |
31476 | + */ | |
31477 | +#define V_PERM 0x001 /* can't be unset - can be modified */ | |
31478 | +#define V_DEFAULT 0x002 /* set at startup */ | |
31479 | +#define V_NOMOD 0x004 /* cannot be modified */ | |
31480 | +#define V_TYPEDEF 0x008 /* contains typed data */ | |
31481 | +#define V_REC_STRUCT 0x010 /* direct ref to struct/member (not pointer) */ | |
31482 | +#define V_STRING 0x020 /* contains ASCII string (no type) */ | |
31483 | +#define V_COMMAND 0x040 /* contains command string (no type) */ | |
31484 | +#define V_OPTION 0x080 /* contains option flag (e.g., $hexints) */ | |
31485 | +#define V_PERM_NODE 0x100 /* Don't free node after setting variable */ | |
31486 | + | |
31487 | +/* Variable table struct | |
31488 | + */ | |
31489 | +typedef struct vtab_s { | |
31490 | + variable_t *vt_root; | |
31491 | + int vt_count; | |
31492 | +} vtab_t; | |
31493 | + | |
31494 | +extern vtab_t *vtab; /* Pointer to table of eval variable info */ | |
31495 | + | |
31496 | +/* Function Prototypes | |
31497 | + */ | |
31498 | +variable_t *make_variable(char *, char *, node_t *, int); | |
31499 | +void clean_variable(variable_t *); | |
31500 | +void free_variable(variable_t *); | |
31501 | +void init_variables(vtab_t *); | |
31502 | +int set_variable(vtab_t *, char *, char *, node_t *, int); | |
31503 | +int unset_variable(vtab_t *, variable_t *); | |
31504 | +variable_t *find_variable(vtab_t *, char *, int); | |
31505 | +kltype_t *number_to_type(node_t *); | |
31506 | +void free_eval_memory(void); | |
31507 | +/* cpw: was int print_eval_results(node_t *, FILE *, int); */ | |
31508 | +int print_eval_results(node_t *, int); | |
31509 | + | |
31510 | +#endif /* __LC_EVAL_H */ | |
31511 | --- a/kernel/exit.c | |
31512 | +++ b/kernel/exit.c | |
31513 | @@ -4,6 +4,9 @@ | |
31514 | * Copyright (C) 1991, 1992 Linus Torvalds | |
31515 | */ | |
31516 | ||
31517 | +#ifdef CONFIG_KDB | |
31518 | +#include <linux/kdb.h> | |
31519 | +#endif | |
31520 | #include <linux/mm.h> | |
31521 | #include <linux/slab.h> | |
31522 | #include <linux/interrupt.h> | |
31523 | --- a/kernel/kallsyms.c | |
31524 | +++ b/kernel/kallsyms.c | |
31525 | @@ -479,3 +479,25 @@ __initcall(kallsyms_init); | |
31526 | ||
31527 | EXPORT_SYMBOL(__print_symbol); | |
31528 | EXPORT_SYMBOL_GPL(sprint_symbol); | |
31529 | + | |
31530 | +#ifdef CONFIG_KDB | |
31531 | +#include <linux/kdb.h> | |
31532 | +#include <linux/kdbprivate.h> | |
31533 | + | |
31534 | +const char *kdb_walk_kallsyms(loff_t *pos) | |
31535 | +{ | |
31536 | + static struct kallsym_iter kdb_walk_kallsyms_iter; | |
31537 | + if (*pos == 0) { | |
31538 | + memset(&kdb_walk_kallsyms_iter, 0, sizeof(kdb_walk_kallsyms_iter)); | |
31539 | + reset_iter(&kdb_walk_kallsyms_iter, 0); | |
31540 | + } | |
31541 | + while (1) { | |
31542 | + if (!update_iter(&kdb_walk_kallsyms_iter, *pos)) | |
31543 | + return NULL; | |
31544 | + ++*pos; | |
31545 | + /* Some debugging symbols have no name. Ignore them. */ | |
31546 | + if (kdb_walk_kallsyms_iter.name[0]) | |
31547 | + return kdb_walk_kallsyms_iter.name; | |
31548 | + } | |
31549 | +} | |
31550 | +#endif /* CONFIG_KDB */ | |
31551 | --- a/kernel/kexec.c | |
31552 | +++ b/kernel/kexec.c | |
31553 | @@ -37,6 +37,12 @@ | |
31554 | #include <asm/system.h> | |
31555 | #include <asm/sections.h> | |
31556 | ||
31557 | +#ifdef CONFIG_KDB_KDUMP | |
31558 | +#include <linux/module.h> | |
31559 | +#include <linux/device.h> | |
31560 | +#include <linux/kdb.h> | |
31561 | +#endif | |
31562 | + | |
31563 | /* Per cpu memory for storing cpu states in case of system crash. */ | |
31564 | note_buf_t* crash_notes; | |
31565 | ||
31566 | @@ -1072,9 +1078,19 @@ void crash_kexec(struct pt_regs *regs) | |
31567 | if (mutex_trylock(&kexec_mutex)) { | |
31568 | if (kexec_crash_image) { | |
31569 | struct pt_regs fixed_regs; | |
31570 | + | |
31571 | crash_setup_regs(&fixed_regs, regs); | |
31572 | crash_save_vmcoreinfo(); | |
31573 | + /* | |
31574 | + * If we enabled KDB, we don't want to automatically | |
31575 | + * perform a kdump since KDB will be responsible for | |
31576 | + * executing kdb through a special 'kdump' command. | |
31577 | + */ | |
31578 | +#ifdef CONFIG_KDB_KDUMP | |
31579 | + kdba_kdump_prepare(&fixed_regs); | |
31580 | +#else | |
31581 | machine_crash_shutdown(&fixed_regs); | |
31582 | +#endif | |
31583 | machine_kexec(kexec_crash_image); | |
31584 | } | |
31585 | mutex_unlock(&kexec_mutex); | |
31586 | --- a/kernel/module.c | |
31587 | +++ b/kernel/module.c | |
31588 | @@ -2576,12 +2576,23 @@ out: | |
31589 | return -ERANGE; | |
31590 | } | |
31591 | ||
31592 | +#ifdef CONFIG_KDB | |
31593 | +#include <linux/kdb.h> | |
31594 | +struct list_head *kdb_modules = &modules; /* kdb needs the list of modules */ | |
31595 | +#endif /* CONFIG_KDB */ | |
31596 | + | |
31597 | int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, | |
31598 | char *name, char *module_name, int *exported) | |
31599 | { | |
31600 | struct module *mod; | |
31601 | +#ifdef CONFIG_KDB | |
31602 | + int get_lock = !KDB_IS_RUNNING(); | |
31603 | +#else | |
31604 | +#define get_lock 1 | |
31605 | +#endif | |
31606 | ||
31607 | - preempt_disable(); | |
31608 | + if (get_lock) | |
31609 | + preempt_disable(); | |
31610 | list_for_each_entry(mod, &modules, list) { | |
31611 | if (symnum < mod->num_symtab) { | |
31612 | *value = mod->symtab[symnum].st_value; | |
31613 | @@ -2590,12 +2601,14 @@ int module_get_kallsym(unsigned int symn | |
31614 | KSYM_NAME_LEN); | |
31615 | strlcpy(module_name, mod->name, MODULE_NAME_LEN); | |
31616 | *exported = is_exported(name, mod); | |
31617 | - preempt_enable(); | |
31618 | + if (get_lock) | |
31619 | + preempt_enable(); | |
31620 | return 0; | |
31621 | } | |
31622 | symnum -= mod->num_symtab; | |
31623 | } | |
31624 | - preempt_enable(); | |
31625 | + if (get_lock) | |
31626 | + preempt_enable(); | |
31627 | return -ERANGE; | |
31628 | } | |
31629 | ||
31630 | --- a/kernel/panic.c | |
31631 | +++ b/kernel/panic.c | |
31632 | @@ -21,6 +21,9 @@ | |
31633 | #include <linux/debug_locks.h> | |
31634 | #include <linux/random.h> | |
31635 | #include <linux/kallsyms.h> | |
31636 | +#ifdef CONFIG_KDB_KDUMP | |
31637 | +#include <linux/kdb.h> | |
31638 | +#endif | |
31639 | ||
31640 | int panic_on_oops; | |
31641 | int tainted; | |
31642 | @@ -82,6 +85,11 @@ NORET_TYPE void panic(const char * fmt, | |
31643 | printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf); | |
31644 | bust_spinlocks(0); | |
31645 | ||
31646 | +#ifdef CONFIG_KDB_KDUMP | |
31647 | + if (kdb_kdump_state == KDB_KDUMP_RESET) { | |
31648 | + (void)kdb(KDB_REASON_OOPS, 999, get_irq_regs()); | |
31649 | + } | |
31650 | +#endif | |
31651 | /* | |
31652 | * If we have crashed and we have a crash kernel loaded let it handle | |
31653 | * everything else. | |
31654 | --- a/kernel/printk.c | |
31655 | +++ b/kernel/printk.c | |
31656 | @@ -443,6 +443,20 @@ void debugger_syslog_data(char *syslog_d | |
31657 | } | |
31658 | #endif /* CONFIG_DEBUG_KERNEL */ | |
31659 | ||
31660 | +#ifdef CONFIG_KDB | |
31661 | +/* kdb dmesg command needs access to the syslog buffer. do_syslog() uses locks | |
31662 | + * so it cannot be used during debugging. Just tell kdb where the start and | |
31663 | + * end of the physical and logical logs are. This is equivalent to do_syslog(3). | |
31664 | + */ | |
31665 | +void kdb_syslog_data(char *syslog_data[4]) | |
31666 | +{ | |
31667 | + syslog_data[0] = log_buf; | |
31668 | + syslog_data[1] = log_buf + log_buf_len; | |
31669 | + syslog_data[2] = log_buf + log_end - (logged_chars < log_buf_len ? logged_chars : log_buf_len); | |
31670 | + syslog_data[3] = log_buf + log_end; | |
31671 | +} | |
31672 | +#endif /* CONFIG_KDB */ | |
31673 | + | |
31674 | /* | |
31675 | * Call the console drivers on a range of log_buf | |
31676 | */ | |
31677 | --- a/kernel/sched.c | |
31678 | +++ b/kernel/sched.c | |
31679 | @@ -8358,7 +8358,7 @@ void normalize_rt_tasks(void) | |
31680 | ||
31681 | #endif /* CONFIG_MAGIC_SYSRQ */ | |
31682 | ||
31683 | -#ifdef CONFIG_IA64 | |
31684 | +#if defined(CONFIG_IA64) || defined(CONFIG_KDB) | |
31685 | /* | |
31686 | * These functions are only useful for the IA64 MCA handling. | |
31687 | * | |
31688 | @@ -9299,3 +9299,94 @@ struct cgroup_subsys cpuacct_subsys = { | |
31689 | .subsys_id = cpuacct_subsys_id, | |
31690 | }; | |
31691 | #endif /* CONFIG_CGROUP_CPUACCT */ | |
31692 | + | |
31693 | +#ifdef CONFIG_KDB | |
31694 | + | |
31695 | +#include <linux/kdb.h> | |
31696 | + | |
31697 | +static void | |
31698 | +kdb_prio(char *name, struct rt_prio_array *array, kdb_printf_t xxx_printf, | |
31699 | + unsigned int cpu) | |
31700 | +{ | |
31701 | + int pri, printed_header = 0; | |
31702 | + struct task_struct *p; | |
31703 | + | |
31704 | + xxx_printf(" %s rt bitmap: 0x%lx 0x%lx 0x%lx\n", | |
31705 | + name, | |
31706 | + array->bitmap[0], array->bitmap[1], array->bitmap[2]); | |
31707 | + | |
31708 | + pri = sched_find_first_bit(array->bitmap); | |
31709 | + if (pri < MAX_RT_PRIO) { | |
31710 | + xxx_printf(" rt bitmap priorities:"); | |
31711 | + while (pri < MAX_RT_PRIO) { | |
31712 | + xxx_printf(" %d", pri); | |
31713 | + pri++; | |
31714 | + pri = find_next_bit(array->bitmap, MAX_RT_PRIO, pri); | |
31715 | + } | |
31716 | + xxx_printf("\n"); | |
31717 | + } | |
31718 | + | |
31719 | + for (pri = 0; pri < MAX_RT_PRIO; pri++) { | |
31720 | + int printed_hdr = 0; | |
31721 | + struct list_head *head, *curr; | |
31722 | + | |
31723 | + head = array->queue + pri; | |
31724 | + curr = head->next; | |
31725 | + while(curr != head) { | |
31726 | + struct task_struct *task; | |
31727 | + if (!printed_hdr) { | |
31728 | + xxx_printf(" queue at priority=%d\n", pri); | |
31729 | + printed_hdr = 1; | |
31730 | + } | |
31731 | + task = list_entry(curr, struct task_struct, rt.run_list); | |
31732 | + if (task) | |
31733 | + xxx_printf(" 0x%p %d %s time_slice:%d\n", | |
31734 | + task, task->pid, task->comm, | |
31735 | + task->rt.time_slice); | |
31736 | + curr = curr->next; | |
31737 | + } | |
31738 | + } | |
31739 | + for_each_process(p) { | |
31740 | + if (p->se.on_rq && (task_cpu(p) == cpu) && | |
31741 | + (p->policy == SCHED_NORMAL)) { | |
31742 | + if (!printed_header) { | |
31743 | + xxx_printf(" sched_normal queue:\n"); | |
31744 | + printed_header = 1; | |
31745 | + } | |
31746 | + xxx_printf(" 0x%p %d %s pri:%d spri:%d npri:%d\n", | |
31747 | + p, p->pid, p->comm, p->prio, | |
31748 | + p->static_prio, p->normal_prio); | |
31749 | + } | |
31750 | + } | |
31751 | +} | |
31752 | + | |
31753 | +/* This code must be in sched.c because struct rq is only defined in this | |
31754 | + * source. To allow most of kdb to be modular, this code cannot call any kdb | |
31755 | + * functions directly, any external functions that it needs must be passed in | |
31756 | + * as parameters. | |
31757 | + */ | |
31758 | + | |
31759 | +void | |
31760 | +kdb_runqueue(unsigned long cpu, kdb_printf_t xxx_printf) | |
31761 | +{ | |
31762 | + struct rq *rq; | |
31763 | + | |
31764 | + rq = cpu_rq(cpu); | |
31765 | + | |
31766 | + xxx_printf("CPU%ld lock:%s curr:0x%p(%d)(%s)", | |
31767 | + cpu, (spin_is_locked(&rq->lock))?"LOCKED":"free", | |
31768 | + rq->curr, rq->curr->pid, rq->curr->comm); | |
31769 | + if (rq->curr == rq->idle) | |
31770 | + xxx_printf(" is idle"); | |
31771 | + xxx_printf("\n "); | |
31772 | +#ifdef CONFIG_SMP | |
31773 | + xxx_printf(" cpu_load:%lu %lu %lu", | |
31774 | + rq->cpu_load[0], rq->cpu_load[1], rq->cpu_load[2]); | |
31775 | +#endif | |
31776 | + xxx_printf(" nr_running:%lu nr_switches:%llu\n", | |
31777 | + rq->nr_running, (long long)rq->nr_switches); | |
31778 | + kdb_prio("active", &rq->rt.active, xxx_printf, (unsigned int)cpu); | |
31779 | +} | |
31780 | +EXPORT_SYMBOL(kdb_runqueue); | |
31781 | + | |
31782 | +#endif /* CONFIG_KDB */ | |
31783 | --- a/kernel/signal.c | |
31784 | +++ b/kernel/signal.c | |
31785 | @@ -2595,3 +2595,52 @@ void __init signals_init(void) | |
31786 | { | |
31787 | sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC); | |
31788 | } | |
31789 | + | |
31790 | +#ifdef CONFIG_KDB | |
31791 | +#include <linux/kdb.h> | |
31792 | +/* | |
31793 | + * kdb_send_sig_info | |
31794 | + * | |
31795 | + * Allows kdb to send signals without exposing signal internals. | |
31796 | + * | |
31797 | + * Inputs: | |
31798 | + * t task | |
31799 | + * siginfo signal information | |
31800 | + * seqno current kdb sequence number (avoid including kdbprivate.h) | |
31801 | + * Outputs: | |
31802 | + * None. | |
31803 | + * Returns: | |
31804 | + * None. | |
31805 | + * Locking: | |
31806 | + * Checks if the required locks are available before calling the main | |
31807 | + * signal code, to avoid kdb deadlocks. | |
31808 | + * Remarks: | |
31809 | + */ | |
31810 | +void | |
31811 | +kdb_send_sig_info(struct task_struct *t, struct siginfo *info, int seqno) | |
31812 | +{ | |
31813 | + static struct task_struct *kdb_prev_t; | |
31814 | + static int kdb_prev_seqno; | |
31815 | + int sig, new_t; | |
31816 | + if (!spin_trylock(&t->sighand->siglock)) { | |
31817 | + kdb_printf("Can't do kill command now.\n" | |
31818 | + "The sigmask lock is held somewhere else in kernel, try again later\n"); | |
31819 | + return; | |
31820 | + } | |
31821 | + spin_unlock(&t->sighand->siglock); | |
31822 | + new_t = kdb_prev_t != t || kdb_prev_seqno != seqno; | |
31823 | + kdb_prev_t = t; | |
31824 | + kdb_prev_seqno = seqno; | |
31825 | + if (t->state != TASK_RUNNING && new_t) { | |
31826 | + kdb_printf("Process is not RUNNING, sending a signal from kdb risks deadlock\n" | |
31827 | + "on the run queue locks. The signal has _not_ been sent.\n" | |
31828 | + "Reissue the kill command if you want to risk the deadlock.\n"); | |
31829 | + return; | |
31830 | + } | |
31831 | + sig = info->si_signo; | |
31832 | + if (send_sig_info(sig, info, t)) | |
31833 | + kdb_printf("Fail to deliver Signal %d to process %d.\n", sig, t->pid); | |
31834 | + else | |
31835 | + kdb_printf("Signal %d is sent to process %d.\n", sig, t->pid); | |
31836 | +} | |
31837 | +#endif /* CONFIG_KDB */ | |
31838 | --- a/kernel/sysctl_check.c | |
31839 | +++ b/kernel/sysctl_check.c | |
31840 | @@ -105,6 +105,7 @@ static const struct trans_ctl_table tran | |
31841 | { KERN_NMI_WATCHDOG, "nmi_watchdog" }, | |
31842 | { KERN_PANIC_ON_NMI, "panic_on_unrecovered_nmi" }, | |
31843 | { KERN_SETUID_DUMPABLE, "suid_dumpable" }, | |
31844 | + { KERN_KDB, "kdb" }, | |
31845 | {} | |
31846 | }; | |
31847 | ||
31848 | --- a/lib/bug.c | |
31849 | +++ b/lib/bug.c | |
31850 | @@ -41,6 +41,10 @@ | |
31851 | #include <linux/bug.h> | |
31852 | #include <linux/sched.h> | |
31853 | ||
31854 | +#ifdef CONFIG_KDB | |
31855 | +#include <linux/kdb.h> | |
31856 | +#endif | |
31857 | + | |
31858 | extern const struct bug_entry __start___bug_table[], __stop___bug_table[]; | |
31859 | ||
31860 | #ifdef CONFIG_MODULES | |
31861 | @@ -162,5 +166,9 @@ enum bug_trap_type report_bug(unsigned l | |
31862 | "[verbose debug info unavailable]\n", | |
31863 | (void *)bugaddr); | |
31864 | ||
31865 | +#ifdef CONFIG_KDB | |
31866 | + kdb(KDB_REASON_ENTER, 0, regs); | |
31867 | +#endif | |
31868 | + | |
31869 | return BUG_TRAP_TYPE_BUG; | |
31870 | } | |
31871 | --- a/mm/hugetlb.c | |
31872 | +++ b/mm/hugetlb.c | |
31873 | @@ -1500,6 +1500,28 @@ int hugetlb_overcommit_handler(struct ct | |
31874 | ||
31875 | #endif /* CONFIG_SYSCTL */ | |
31876 | ||
31877 | +#ifdef CONFIG_KDB | |
31878 | +#include <linux/kdb.h> | |
31879 | +#include <linux/kdbprivate.h> | |
31880 | +/* Like hugetlb_report_meminfo() but using kdb_printf() */ | |
31881 | +void | |
31882 | +kdb_hugetlb_report_meminfo(void) | |
31883 | +{ | |
31884 | + struct hstate *h = &default_hstate; | |
31885 | + kdb_printf( | |
31886 | + "HugePages_Total: %5lu\n" | |
31887 | + "HugePages_Free: %5lu\n" | |
31888 | + "HugePages_Rsvd: %5lu\n" | |
31889 | + "HugePages_Surp: %5lu\n" | |
31890 | + "Hugepagesize: %5lu kB\n", | |
31891 | + h->nr_huge_pages, | |
31892 | + h->free_huge_pages, | |
31893 | + h->resv_huge_pages, | |
31894 | + h->surplus_huge_pages, | |
31895 | + 1UL << (huge_page_order(h) + PAGE_SHIFT - 10)); | |
31896 | +} | |
31897 | +#endif /* CONFIG_KDB */ | |
31898 | + | |
31899 | int hugetlb_report_meminfo(char *buf) | |
31900 | { | |
31901 | struct hstate *h = &default_hstate; | |
31902 | --- a/mm/mmzone.c | |
31903 | +++ b/mm/mmzone.c | |
31904 | @@ -22,6 +22,10 @@ struct pglist_data *next_online_pgdat(st | |
31905 | return NULL; | |
31906 | return NODE_DATA(nid); | |
31907 | } | |
31908 | +#ifdef CONFIG_KDB | |
31909 | +EXPORT_SYMBOL(first_online_pgdat); | |
31910 | +EXPORT_SYMBOL(next_online_pgdat); | |
31911 | +#endif | |
31912 | ||
31913 | /* | |
31914 | * next_zone - helper magic for for_each_zone() | |
31915 | --- a/mm/swapfile.c | |
31916 | +++ b/mm/swapfile.c | |
31917 | @@ -13,6 +13,10 @@ | |
31918 | #include <linux/swap.h> | |
31919 | #include <linux/vmalloc.h> | |
31920 | #include <linux/pagemap.h> | |
31921 | +#ifdef CONFIG_KDB | |
31922 | +#include <linux/kdb.h> | |
31923 | +#include <linux/kdbprivate.h> | |
31924 | +#endif /* CONFIG_KDB */ | |
31925 | #include <linux/namei.h> | |
31926 | #include <linux/shm.h> | |
31927 | #include <linux/blkdev.h> | |
31928 | @@ -1750,6 +1754,24 @@ void si_swapinfo(struct sysinfo *val) | |
31929 | spin_unlock(&swap_lock); | |
31930 | } | |
31931 | ||
31932 | +#ifdef CONFIG_KDB | |
31933 | +/* Like si_swapinfo() but without the locks */ | |
31934 | +void kdb_si_swapinfo(struct sysinfo *val) | |
31935 | +{ | |
31936 | + unsigned int i; | |
31937 | + unsigned long nr_to_be_unused = 0; | |
31938 | + | |
31939 | + for (i = 0; i < nr_swapfiles; i++) { | |
31940 | + if (!(swap_info[i].flags & SWP_USED) || | |
31941 | + (swap_info[i].flags & SWP_WRITEOK)) | |
31942 | + continue; | |
31943 | + nr_to_be_unused += swap_info[i].inuse_pages; | |
31944 | + } | |
31945 | + val->freeswap = nr_swap_pages + nr_to_be_unused; | |
31946 | + val->totalswap = total_swap_pages + nr_to_be_unused; | |
31947 | +} | |
31948 | +#endif /* CONFIG_KDB */ | |
31949 | + | |
31950 | /* | |
31951 | * Verify that a swap entry is valid and increment its swap map count. | |
31952 | * |