ae75366cc3d0843487d55662179d4c62856ffdbd
[deliverable/linux.git] / Documentation / s390 / Debugging390.txt
1
2 Debugging on Linux for s/390 & z/Architecture
3 by
4 Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
5 Copyright (C) 2000-2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 Best viewed with fixed width fonts
7
8 Overview of Document:
9 =====================
10 This document is intended to give a good overview of how to debug Linux for
11 s/390 and z/Architecture. It is not intended as a complete reference and not a
12 tutorial on the fundamentals of C & assembly. It doesn't go into
13 390 IO in any detail. It is intended to complement the documents in the
14 reference section below & any other worthwhile references you get.
15
16 It is intended like the Enterprise Systems Architecture/390 Reference Summary
17 to be printed out & used as a quick cheat sheet self help style reference when
18 problems occur.
19
20 Contents
21 ========
22 Register Set
23 Address Spaces on Intel Linux
24 Address Spaces on Linux for s/390 & z/Architecture
25 The Linux for s/390 & z/Architecture Kernel Task Structure
26 Register Usage & Stackframes on Linux for s/390 & z/Architecture
27 A sample program with comments
28 Compiling programs for debugging on Linux for s/390 & z/Architecture
29 Debugging under VM
30 s/390 & z/Architecture IO Overview
31 Debugging IO on s/390 & z/Architecture under VM
32 GDB on s/390 & z/Architecture
33 Stack chaining in gdb by hand
34 Examining core dumps
35 ldd
36 Debugging modules
37 The proc file system
38 Starting points for debugging scripting languages etc.
39 SysRq
40 References
41 Special Thanks
42
43 Register Set
44 ============
45 The current architectures have the following registers.
46
47 16 General propose registers, 32 bit on s/390 and 64 bit on z/Architecture,
48 r0-r15 (or gpr0-gpr15), used for arithmetic and addressing.
49
50 16 Control registers, 32 bit on s/390 and 64 bit on z/Architecture, cr0-cr15,
51 kernel usage only, used for memory management, interrupt control, debugging
52 control etc.
53
54 16 Access registers (ar0-ar15), 32 bit on both s/390 and z/Architecture,
55 normally not used by normal programs but potentially could be used as
56 temporary storage. These registers have a 1:1 association with general
57 purpose registers and are designed to be used in the so-called access
58 register mode to select different address spaces.
59 Access register 0 (and access register 1 on z/Architecture, which needs a
60 64 bit pointer) is currently used by the pthread library as a pointer to
61 the current running threads private area.
62
63 16 64 bit floating point registers (fp0-fp15 ) IEEE & HFP floating
64 point format compliant on G5 upwards & a Floating point control reg (FPC)
65 4 64 bit registers (fp0,fp2,fp4 & fp6) HFP only on older machines.
66 Note:
67 Linux (currently) always uses IEEE & emulates G5 IEEE format on older machines,
68 ( provided the kernel is configured for this ).
69
70
71 The PSW is the most important register on the machine it
72 is 64 bit on s/390 & 128 bit on z/Architecture & serves the roles of
73 a program counter (pc), condition code register,memory space designator.
74 In IBM standard notation I am counting bit 0 as the MSB.
75 It has several advantages over a normal program counter
76 in that you can change address translation & program counter
77 in a single instruction. To change address translation,
78 e.g. switching address translation off requires that you
79 have a logical=physical mapping for the address you are
80 currently running at.
81
82 Bit Value
83 s/390 z/Architecture
84 0 0 Reserved ( must be 0 ) otherwise specification exception occurs.
85
86 1 1 Program Event Recording 1 PER enabled,
87 PER is used to facilitate debugging e.g. single stepping.
88
89 2-4 2-4 Reserved ( must be 0 ).
90
91 5 5 Dynamic address translation 1=DAT on.
92
93 6 6 Input/Output interrupt Mask
94
95 7 7 External interrupt Mask used primarily for interprocessor
96 signalling and clock interrupts.
97
98 8-11 8-11 PSW Key used for complex memory protection mechanism
99 (not used under linux)
100
101 12 12 1 on s/390 0 on z/Architecture
102
103 13 13 Machine Check Mask 1=enable machine check interrupts
104
105 14 14 Wait State. Set this to 1 to stop the processor except for
106 interrupts and give time to other LPARS. Used in CPU idle in
107 the kernel to increase overall usage of processor resources.
108
109 15 15 Problem state ( if set to 1 certain instructions are disabled )
110 all linux user programs run with this bit 1
111 ( useful info for debugging under VM ).
112
113 16-17 16-17 Address Space Control
114
115 00 Primary Space Mode:
116 The register CR1 contains the primary address-space control ele-
117 ment (PASCE), which points to the primary space region/segment
118 table origin.
119
120 01 Access register mode
121
122 10 Secondary Space Mode:
123 The register CR7 contains the secondary address-space control
124 element (SASCE), which points to the secondary space region or
125 segment table origin.
126
127 11 Home Space Mode:
128 The register CR13 contains the home space address-space control
129 element (HASCE), which points to the home space region/segment
130 table origin.
131
132 See "Address Spaces on Linux for s/390 & z/Architecture" below
133 for more information about address space usage in Linux.
134
135 18-19 18-19 Condition codes (CC)
136
137 20 20 Fixed point overflow mask if 1=FPU exceptions for this event
138 occur ( normally 0 )
139
140 21 21 Decimal overflow mask if 1=FPU exceptions for this event occur
141 ( normally 0 )
142
143 22 22 Exponent underflow mask if 1=FPU exceptions for this event occur
144 ( normally 0 )
145
146 23 23 Significance Mask if 1=FPU exceptions for this event occur
147 ( normally 0 )
148
149 24-31 24-30 Reserved Must be 0.
150
151 31 Extended Addressing Mode
152 32 Basic Addressing Mode
153 Used to set addressing mode
154 PSW 31 PSW 32
155 0 0 24 bit
156 0 1 31 bit
157 1 1 64 bit
158
159 32 1=31 bit addressing mode 0=24 bit addressing mode (for backward
160 compatibility), linux always runs with this bit set to 1
161
162 33-64 Instruction address.
163 33-63 Reserved must be 0
164 64-127 Address
165 In 24 bits mode bits 64-103=0 bits 104-127 Address
166 In 31 bits mode bits 64-96=0 bits 97-127 Address
167 Note: unlike 31 bit mode on s/390 bit 96 must be zero
168 when loading the address with LPSWE otherwise a
169 specification exception occurs, LPSW is fully backward
170 compatible.
171
172
173 Prefix Page(s)
174 --------------
175 This per cpu memory area is too intimately tied to the processor not to mention.
176 It exists between the real addresses 0-4096 on s/390 and between 0-8192 on
177 z/Architecture and is exchanged with one page on s/390 or two pages on
178 z/Architecture in absolute storage by the set prefix instruction during Linux
179 startup.
180 This page is mapped to a different prefix for each processor in an SMP
181 configuration (assuming the OS designer is sane of course).
182 Bytes 0-512 (200 hex) on s/390 and 0-512, 4096-4544, 4604-5119 currently on
183 z/Architecture are used by the processor itself for holding such information
184 as exception indications and entry points for exceptions.
185 Bytes after 0xc00 hex are used by linux for per processor globals on s/390 and
186 z/Architecture (there is a gap on z/Architecture currently between 0xc00 and
187 0x1000, too, which is used by Linux).
188 The closest thing to this on traditional architectures is the interrupt
189 vector table. This is a good thing & does simplify some of the kernel coding
190 however it means that we now cannot catch stray NULL pointers in the
191 kernel without hard coded checks.
192
193
194
195 Address Spaces on Intel Linux
196 =============================
197
198 The traditional Intel Linux is approximately mapped as follows forgive
199 the ascii art.
200 0xFFFFFFFF 4GB Himem *****************
201 * *
202 * Kernel Space *
203 * *
204 ***************** ****************
205 User Space Himem * User Stack * * *
206 (typically 0xC0000000 3GB ) ***************** * *
207 * Shared Libs * * Next Process *
208 ***************** * to *
209 * * <== * Run * <==
210 * User Program * * *
211 * Data BSS * * *
212 * Text * * *
213 * Sections * * *
214 0x00000000 ***************** ****************
215
216 Now it is easy to see that on Intel it is quite easy to recognise a kernel
217 address as being one greater than user space himem (in this case 0xC0000000),
218 and addresses of less than this are the ones in the current running program on
219 this processor (if an smp box).
220 If using the virtual machine ( VM ) as a debugger it is quite difficult to
221 know which user process is running as the address space you are looking at
222 could be from any process in the run queue.
223
224 The limitation of Intels addressing technique is that the linux
225 kernel uses a very simple real address to virtual addressing technique
226 of Real Address=Virtual Address-User Space Himem.
227 This means that on Intel the kernel linux can typically only address
228 Himem=0xFFFFFFFF-0xC0000000=1GB & this is all the RAM these machines
229 can typically use.
230 They can lower User Himem to 2GB or lower & thus be
231 able to use 2GB of RAM however this shrinks the maximum size
232 of User Space from 3GB to 2GB they have a no win limit of 4GB unless
233 they go to 64 Bit.
234
235
236 On 390 our limitations & strengths make us slightly different.
237 For backward compatibility we are only allowed use 31 bits (2GB)
238 of our 32 bit addresses, however, we use entirely separate address
239 spaces for the user & kernel.
240
241 This means we can support 2GB of non Extended RAM on s/390, & more
242 with the Extended memory management swap device &
243 currently 4TB of physical memory currently on z/Architecture.
244
245
246 Address Spaces on Linux for s/390 & z/Architecture
247 ==================================================
248
249 Our addressing scheme is basically as follows:
250
251 Primary Space Home Space
252 Himem 0x7fffffff 2GB on s/390 ***************** ****************
253 currently 0x3ffffffffff (2^42)-1 * User Stack * * *
254 on z/Architecture. ***************** * *
255 * Shared Libs * * *
256 ***************** * *
257 * * * Kernel *
258 * User Program * * *
259 * Data BSS * * *
260 * Text * * *
261 * Sections * * *
262 0x00000000 ***************** ****************
263
264 This also means that we need to look at the PSW problem state bit and the
265 addressing mode to decide whether we are looking at user or kernel space.
266
267 User space runs in primary address mode (or access register mode within
268 the vdso code).
269
270 The kernel usually also runs in home space mode, however when accessing
271 user space the kernel switches to primary or secondary address mode if
272 the mvcos instruction is not available or if a compare-and-swap (futex)
273 instruction on a user space address is performed.
274
275 When also looking at the ASCE control registers, this means:
276
277 User space:
278 - runs in primary or access register mode
279 - cr1 contains the user asce
280 - cr7 contains the user asce
281 - cr13 contains the kernel asce
282
283 Kernel space:
284 - runs in home space mode
285 - cr1 contains the user or kernel asce
286 -> the kernel asce is loaded when a uaccess requires primary or
287 secondary address mode
288 - cr7 contains the user or kernel asce, (changed with set_fs())
289 - cr13 contains the kernel asce
290
291 In case of uaccess the kernel changes to:
292 - primary space mode in case of a uaccess (copy_to_user) and uses
293 e.g. the mvcp instruction to access user space. However the kernel
294 will stay in home space mode if the mvcos instruction is available
295 - secondary space mode in case of futex atomic operations, so that the
296 instructions come from primary address space and data from secondary
297 space
298
299 In case of KVM, the kernel runs in home space mode, but cr1 gets switched
300 to contain the gmap asce before the SIE instruction gets executed. When
301 the SIE instruction is finished, cr1 will be switched back to contain the
302 user asce.
303
304
305 Virtual Addresses on s/390 & z/Architecture
306 ===========================================
307
308 A virtual address on s/390 is made up of 3 parts
309 The SX (segment index, roughly corresponding to the PGD & PMD in Linux
310 terminology) being bits 1-11.
311 The PX (page index, corresponding to the page table entry (pte) in Linux
312 terminology) being bits 12-19.
313 The remaining bits BX (the byte index are the offset in the page )
314 i.e. bits 20 to 31.
315
316 On z/Architecture in linux we currently make up an address from 4 parts.
317 The region index bits (RX) 0-32 we currently use bits 22-32
318 The segment index (SX) being bits 33-43
319 The page index (PX) being bits 44-51
320 The byte index (BX) being bits 52-63
321
322 Notes:
323 1) s/390 has no PMD so the PMD is really the PGD also.
324 A lot of this stuff is defined in pgtable.h.
325
326 2) Also seeing as s/390's page indexes are only 1k in size
327 (bits 12-19 x 4 bytes per pte ) we use 1 ( page 4k )
328 to make the best use of memory by updating 4 segment indices
329 entries each time we mess with a PMD & use offsets
330 0,1024,2048 & 3072 in this page as for our segment indexes.
331 On z/Architecture our page indexes are now 2k in size
332 ( bits 12-19 x 8 bytes per pte ) we do a similar trick
333 but only mess with 2 segment indices each time we mess with
334 a PMD.
335
336 3) As z/Architecture supports up to a massive 5-level page table lookup we
337 can only use 3 currently on Linux ( as this is all the generic kernel
338 currently supports ) however this may change in future
339 this allows us to access ( according to my sums )
340 4TB of virtual storage per process i.e.
341 4096*512(PTES)*1024(PMDS)*2048(PGD) = 4398046511104 bytes,
342 enough for another 2 or 3 of years I think :-).
343 to do this we use a region-third-table designation type in
344 our address space control registers.
345
346
347 The Linux for s/390 & z/Architecture Kernel Task Structure
348 ==========================================================
349 Each process/thread under Linux for S390 has its own kernel task_struct
350 defined in linux/include/linux/sched.h
351 The S390 on initialisation & resuming of a process on a cpu sets
352 the __LC_KERNEL_STACK variable in the spare prefix area for this cpu
353 (which we use for per-processor globals).
354
355 The kernel stack pointer is intimately tied with the task structure for
356 each processor as follows.
357
358 s/390
359 ************************
360 * 1 page kernel stack *
361 * ( 4K ) *
362 ************************
363 * 1 page task_struct *
364 * ( 4K ) *
365 8K aligned ************************
366
367 z/Architecture
368 ************************
369 * 2 page kernel stack *
370 * ( 8K ) *
371 ************************
372 * 2 page task_struct *
373 * ( 8K ) *
374 16K aligned ************************
375
376 What this means is that we don't need to dedicate any register or global
377 variable to point to the current running process & can retrieve it with the
378 following very simple construct for s/390 & one very similar for z/Architecture.
379
380 static inline struct task_struct * get_current(void)
381 {
382 struct task_struct *current;
383 __asm__("lhi %0,-8192\n\t"
384 "nr %0,15"
385 : "=r" (current) );
386 return current;
387 }
388
389 i.e. just anding the current kernel stack pointer with the mask -8192.
390 Thankfully because Linux doesn't have support for nested IO interrupts
391 & our devices have large buffers can survive interrupts being shut for
392 short amounts of time we don't need a separate stack for interrupts.
393
394
395
396
397 Register Usage & Stackframes on Linux for s/390 & z/Architecture
398 =================================================================
399 Overview:
400 ---------
401 This is the code that gcc produces at the top & the bottom of
402 each function. It usually is fairly consistent & similar from
403 function to function & if you know its layout you can probably
404 make some headway in finding the ultimate cause of a problem
405 after a crash without a source level debugger.
406
407 Note: To follow stackframes requires a knowledge of C or Pascal &
408 limited knowledge of one assembly language.
409
410 It should be noted that there are some differences between the
411 s/390 and z/Architecture stack layouts as the z/Architecture stack layout
412 didn't have to maintain compatibility with older linkage formats.
413
414 Glossary:
415 ---------
416 alloca:
417 This is a built in compiler function for runtime allocation
418 of extra space on the callers stack which is obviously freed
419 up on function exit ( e.g. the caller may choose to allocate nothing
420 of a buffer of 4k if required for temporary purposes ), it generates
421 very efficient code ( a few cycles ) when compared to alternatives
422 like malloc.
423
424 automatics: These are local variables on the stack,
425 i.e they aren't in registers & they aren't static.
426
427 back-chain:
428 This is a pointer to the stack pointer before entering a
429 framed functions ( see frameless function ) prologue got by
430 dereferencing the address of the current stack pointer,
431 i.e. got by accessing the 32 bit value at the stack pointers
432 current location.
433
434 base-pointer:
435 This is a pointer to the back of the literal pool which
436 is an area just behind each procedure used to store constants
437 in each function.
438
439 call-clobbered: The caller probably needs to save these registers if there
440 is something of value in them, on the stack or elsewhere before making a
441 call to another procedure so that it can restore it later.
442
443 epilogue:
444 The code generated by the compiler to return to the caller.
445
446 frameless-function
447 A frameless function in Linux for s390 & z/Architecture is one which doesn't
448 need more than the register save area (96 bytes on s/390, 160 on z/Architecture)
449 given to it by the caller.
450 A frameless function never:
451 1) Sets up a back chain.
452 2) Calls alloca.
453 3) Calls other normal functions
454 4) Has automatics.
455
456 GOT-pointer:
457 This is a pointer to the global-offset-table in ELF
458 ( Executable Linkable Format, Linux'es most common executable format ),
459 all globals & shared library objects are found using this pointer.
460
461 lazy-binding
462 ELF shared libraries are typically only loaded when routines in the shared
463 library are actually first called at runtime. This is lazy binding.
464
465 procedure-linkage-table
466 This is a table found from the GOT which contains pointers to routines
467 in other shared libraries which can't be called to by easier means.
468
469 prologue:
470 The code generated by the compiler to set up the stack frame.
471
472 outgoing-args:
473 This is extra area allocated on the stack of the calling function if the
474 parameters for the callee's cannot all be put in registers, the same
475 area can be reused by each function the caller calls.
476
477 routine-descriptor:
478 A COFF executable format based concept of a procedure reference
479 actually being 8 bytes or more as opposed to a simple pointer to the routine.
480 This is typically defined as follows
481 Routine Descriptor offset 0=Pointer to Function
482 Routine Descriptor offset 4=Pointer to Table of Contents
483 The table of contents/TOC is roughly equivalent to a GOT pointer.
484 & it means that shared libraries etc. can be shared between several
485 environments each with their own TOC.
486
487
488 static-chain: This is used in nested functions a concept adopted from pascal
489 by gcc not used in ansi C or C++ ( although quite useful ), basically it
490 is a pointer used to reference local variables of enclosing functions.
491 You might come across this stuff once or twice in your lifetime.
492
493 e.g.
494 The function below should return 11 though gcc may get upset & toss warnings
495 about unused variables.
496 int FunctionA(int a)
497 {
498 int b;
499 FunctionC(int c)
500 {
501 b=c+1;
502 }
503 FunctionC(10);
504 return(b);
505 }
506
507
508 s/390 & z/Architecture Register usage
509 =====================================
510 r0 used by syscalls/assembly call-clobbered
511 r1 used by syscalls/assembly call-clobbered
512 r2 argument 0 / return value 0 call-clobbered
513 r3 argument 1 / return value 1 (if long long) call-clobbered
514 r4 argument 2 call-clobbered
515 r5 argument 3 call-clobbered
516 r6 argument 4 saved
517 r7 pointer-to arguments 5 to ... saved
518 r8 this & that saved
519 r9 this & that saved
520 r10 static-chain ( if nested function ) saved
521 r11 frame-pointer ( if function used alloca ) saved
522 r12 got-pointer saved
523 r13 base-pointer saved
524 r14 return-address saved
525 r15 stack-pointer saved
526
527 f0 argument 0 / return value ( float/double ) call-clobbered
528 f2 argument 1 call-clobbered
529 f4 z/Architecture argument 2 saved
530 f6 z/Architecture argument 3 saved
531 The remaining floating points
532 f1,f3,f5 f7-f15 are call-clobbered.
533
534 Notes:
535 ------
536 1) The only requirement is that registers which are used
537 by the callee are saved, e.g. the compiler is perfectly
538 capable of using r11 for purposes other than a frame a
539 frame pointer if a frame pointer is not needed.
540 2) In functions with variable arguments e.g. printf the calling procedure
541 is identical to one without variable arguments & the same number of
542 parameters. However, the prologue of this function is somewhat more
543 hairy owing to it having to move these parameters to the stack to
544 get va_start, va_arg & va_end to work.
545 3) Access registers are currently unused by gcc but are used in
546 the kernel. Possibilities exist to use them at the moment for
547 temporary storage but it isn't recommended.
548 4) Only 4 of the floating point registers are used for
549 parameter passing as older machines such as G3 only have only 4
550 & it keeps the stack frame compatible with other compilers.
551 However with IEEE floating point emulation under linux on the
552 older machines you are free to use the other 12.
553 5) A long long or double parameter cannot be have the
554 first 4 bytes in a register & the second four bytes in the
555 outgoing args area. It must be purely in the outgoing args
556 area if crossing this boundary.
557 6) Floating point parameters are mixed with outgoing args
558 on the outgoing args area in the order the are passed in as parameters.
559 7) Floating point arguments 2 & 3 are saved in the outgoing args area for
560 z/Architecture
561
562
563 Stack Frame Layout
564 ------------------
565 s/390 z/Architecture
566 0 0 back chain ( a 0 here signifies end of back chain )
567 4 8 eos ( end of stack, not used on Linux for S390 used in other linkage formats )
568 8 16 glue used in other s/390 linkage formats for saved routine descriptors etc.
569 12 24 glue used in other s/390 linkage formats for saved routine descriptors etc.
570 16 32 scratch area
571 20 40 scratch area
572 24 48 saved r6 of caller function
573 28 56 saved r7 of caller function
574 32 64 saved r8 of caller function
575 36 72 saved r9 of caller function
576 40 80 saved r10 of caller function
577 44 88 saved r11 of caller function
578 48 96 saved r12 of caller function
579 52 104 saved r13 of caller function
580 56 112 saved r14 of caller function
581 60 120 saved r15 of caller function
582 64 128 saved f4 of caller function
583 72 132 saved f6 of caller function
584 80 undefined
585 96 160 outgoing args passed from caller to callee
586 96+x 160+x possible stack alignment ( 8 bytes desirable )
587 96+x+y 160+x+y alloca space of caller ( if used )
588 96+x+y+z 160+x+y+z automatics of caller ( if used )
589 0 back-chain
590
591 A sample program with comments.
592 ===============================
593
594 Comments on the function test
595 -----------------------------
596 1) It didn't need to set up a pointer to the constant pool gpr13 as it is not
597 used ( :-( ).
598 2) This is a frameless function & no stack is bought.
599 3) The compiler was clever enough to recognise that it could return the
600 value in r2 as well as use it for the passed in parameter ( :-) ).
601 4) The basr ( branch relative & save ) trick works as follows the instruction
602 has a special case with r0,r0 with some instruction operands is understood as
603 the literal value 0, some risc architectures also do this ). So now
604 we are branching to the next address & the address new program counter is
605 in r13,so now we subtract the size of the function prologue we have executed
606 + the size of the literal pool to get to the top of the literal pool
607 0040037c int test(int b)
608 { # Function prologue below
609 40037c: 90 de f0 34 stm %r13,%r14,52(%r15) # Save registers r13 & r14
610 400380: 0d d0 basr %r13,%r0 # Set up pointer to constant pool using
611 400382: a7 da ff fa ahi %r13,-6 # basr trick
612 return(5+b);
613 # Huge main program
614 400386: a7 2a 00 05 ahi %r2,5 # add 5 to r2
615
616 # Function epilogue below
617 40038a: 98 de f0 34 lm %r13,%r14,52(%r15) # restore registers r13 & 14
618 40038e: 07 fe br %r14 # return
619 }
620
621 Comments on the function main
622 -----------------------------
623 1) The compiler did this function optimally ( 8-) )
624
625 Literal pool for main.
626 400390: ff ff ff ec .long 0xffffffec
627 main(int argc,char *argv[])
628 { # Function prologue below
629 400394: 90 bf f0 2c stm %r11,%r15,44(%r15) # Save necessary registers
630 400398: 18 0f lr %r0,%r15 # copy stack pointer to r0
631 40039a: a7 fa ff a0 ahi %r15,-96 # Make area for callee saving
632 40039e: 0d d0 basr %r13,%r0 # Set up r13 to point to
633 4003a0: a7 da ff f0 ahi %r13,-16 # literal pool
634 4003a4: 50 00 f0 00 st %r0,0(%r15) # Save backchain
635
636 return(test(5)); # Main Program Below
637 4003a8: 58 e0 d0 00 l %r14,0(%r13) # load relative address of test from
638 # literal pool
639 4003ac: a7 28 00 05 lhi %r2,5 # Set first parameter to 5
640 4003b0: 4d ee d0 00 bas %r14,0(%r14,%r13) # jump to test setting r14 as return
641 # address using branch & save instruction.
642
643 # Function Epilogue below
644 4003b4: 98 bf f0 8c lm %r11,%r15,140(%r15)# Restore necessary registers.
645 4003b8: 07 fe br %r14 # return to do program exit
646 }
647
648
649 Compiler updates
650 ----------------
651
652 main(int argc,char *argv[])
653 {
654 4004fc: 90 7f f0 1c stm %r7,%r15,28(%r15)
655 400500: a7 d5 00 04 bras %r13,400508 <main+0xc>
656 400504: 00 40 04 f4 .long 0x004004f4
657 # compiler now puts constant pool in code to so it saves an instruction
658 400508: 18 0f lr %r0,%r15
659 40050a: a7 fa ff a0 ahi %r15,-96
660 40050e: 50 00 f0 00 st %r0,0(%r15)
661 return(test(5));
662 400512: 58 10 d0 00 l %r1,0(%r13)
663 400516: a7 28 00 05 lhi %r2,5
664 40051a: 0d e1 basr %r14,%r1
665 # compiler adds 1 extra instruction to epilogue this is done to
666 # avoid processor pipeline stalls owing to data dependencies on g5 &
667 # above as register 14 in the old code was needed directly after being loaded
668 # by the lm %r11,%r15,140(%r15) for the br %14.
669 40051c: 58 40 f0 98 l %r4,152(%r15)
670 400520: 98 7f f0 7c lm %r7,%r15,124(%r15)
671 400524: 07 f4 br %r4
672 }
673
674
675 Hartmut ( our compiler developer ) also has been threatening to take out the
676 stack backchain in optimised code as this also causes pipeline stalls, you
677 have been warned.
678
679 64 bit z/Architecture code disassembly
680 --------------------------------------
681
682 If you understand the stuff above you'll understand the stuff
683 below too so I'll avoid repeating myself & just say that
684 some of the instructions have g's on the end of them to indicate
685 they are 64 bit & the stack offsets are a bigger,
686 the only other difference you'll find between 32 & 64 bit is that
687 we now use f4 & f6 for floating point arguments on 64 bit.
688 00000000800005b0 <test>:
689 int test(int b)
690 {
691 return(5+b);
692 800005b0: a7 2a 00 05 ahi %r2,5
693 800005b4: b9 14 00 22 lgfr %r2,%r2 # downcast to integer
694 800005b8: 07 fe br %r14
695 800005ba: 07 07 bcr 0,%r7
696
697
698 }
699
700 00000000800005bc <main>:
701 main(int argc,char *argv[])
702 {
703 800005bc: eb bf f0 58 00 24 stmg %r11,%r15,88(%r15)
704 800005c2: b9 04 00 1f lgr %r1,%r15
705 800005c6: a7 fb ff 60 aghi %r15,-160
706 800005ca: e3 10 f0 00 00 24 stg %r1,0(%r15)
707 return(test(5));
708 800005d0: a7 29 00 05 lghi %r2,5
709 # brasl allows jumps > 64k & is overkill here bras would do fune
710 800005d4: c0 e5 ff ff ff ee brasl %r14,800005b0 <test>
711 800005da: e3 40 f1 10 00 04 lg %r4,272(%r15)
712 800005e0: eb bf f0 f8 00 04 lmg %r11,%r15,248(%r15)
713 800005e6: 07 f4 br %r4
714 }
715
716
717
718 Compiling programs for debugging on Linux for s/390 & z/Architecture
719 ====================================================================
720 -gdwarf-2 now works it should be considered the default debugging
721 format for s/390 & z/Architecture as it is more reliable for debugging
722 shared libraries, normal -g debugging works much better now
723 Thanks to the IBM java compiler developers bug reports.
724
725 This is typically done adding/appending the flags -g or -gdwarf-2 to the
726 CFLAGS & LDFLAGS variables Makefile of the program concerned.
727
728 If using gdb & you would like accurate displays of registers &
729 stack traces compile without optimisation i.e make sure
730 that there is no -O2 or similar on the CFLAGS line of the Makefile &
731 the emitted gcc commands, obviously this will produce worse code
732 ( not advisable for shipment ) but it is an aid to the debugging process.
733
734 This aids debugging because the compiler will copy parameters passed in
735 in registers onto the stack so backtracing & looking at passed in
736 parameters will work, however some larger programs which use inline functions
737 will not compile without optimisation.
738
739 Debugging with optimisation has since much improved after fixing
740 some bugs, please make sure you are using gdb-5.0 or later developed
741 after Nov'2000.
742
743
744
745 Debugging under VM
746 ==================
747
748 Notes
749 -----
750 Addresses & values in the VM debugger are always hex never decimal
751 Address ranges are of the format <HexValue1>-<HexValue2> or
752 <HexValue1>.<HexValue2>
753 For example, the address range 0x2000 to 0x3000 can be described as 2000-3000
754 or 2000.1000
755
756 The VM Debugger is case insensitive.
757
758 VM's strengths are usually other debuggers weaknesses you can get at any
759 resource no matter how sensitive e.g. memory management resources, change
760 address translation in the PSW. For kernel hacking you will reap dividends if
761 you get good at it.
762
763 The VM Debugger displays operators but not operands, and also the debugger
764 displays useful information on the same line as the author of the code probably
765 felt that it was a good idea not to go over the 80 columns on the screen.
766 This isn't as unintuitive as it may seem as the s/390 instructions are easy to
767 decode mentally and you can make a good guess at a lot of them as all the
768 operands are nibble (half byte aligned).
769 So if you have an objdump listing by hand, it is quite easy to follow, and if
770 you don't have an objdump listing keep a copy of the s/390 Reference Summary
771 or alternatively the s/390 principles of operation next to you.
772 e.g. even I can guess that
773 0001AFF8' LR 180F CC 0
774 is a ( load register ) lr r0,r15
775
776 Also it is very easy to tell the length of a 390 instruction from the 2 most
777 significant bits in the instruction (not that this info is really useful except
778 if you are trying to make sense of a hexdump of code).
779 Here is a table
780 Bits Instruction Length
781 ------------------------------------------
782 00 2 Bytes
783 01 4 Bytes
784 10 4 Bytes
785 11 6 Bytes
786
787 The debugger also displays other useful info on the same line such as the
788 addresses being operated on destination addresses of branches & condition codes.
789 e.g.
790 00019736' AHI A7DAFF0E CC 1
791 000198BA' BRC A7840004 -> 000198C2' CC 0
792 000198CE' STM 900EF068 >> 0FA95E78 CC 2
793
794
795
796 Useful VM debugger commands
797 ---------------------------
798
799 I suppose I'd better mention this before I start
800 to list the current active traces do
801 Q TR
802 there can be a maximum of 255 of these per set
803 ( more about trace sets later ).
804 To stop traces issue a
805 TR END.
806 To delete a particular breakpoint issue
807 TR DEL <breakpoint number>
808
809 The PA1 key drops to CP mode so you can issue debugger commands,
810 Doing alt c (on my 3270 console at least ) clears the screen.
811 hitting b <enter> comes back to the running operating system
812 from cp mode ( in our case linux ).
813 It is typically useful to add shortcuts to your profile.exec file
814 if you have one ( this is roughly equivalent to autoexec.bat in DOS ).
815 file here are a few from mine.
816 /* this gives me command history on issuing f12 */
817 set pf12 retrieve
818 /* this continues */
819 set pf8 imm b
820 /* goes to trace set a */
821 set pf1 imm tr goto a
822 /* goes to trace set b */
823 set pf2 imm tr goto b
824 /* goes to trace set c */
825 set pf3 imm tr goto c
826
827
828
829 Instruction Tracing
830 -------------------
831 Setting a simple breakpoint
832 TR I PSWA <address>
833 To debug a particular function try
834 TR I R <function address range>
835 TR I on its own will single step.
836 TR I DATA <MNEMONIC> <OPTIONAL RANGE> will trace for particular mnemonics
837 e.g.
838 TR I DATA 4D R 0197BC.4000
839 will trace for BAS'es ( opcode 4D ) in the range 0197BC.4000
840 if you were inclined you could add traces for all branch instructions &
841 suffix them with the run prefix so you would have a backtrace on screen
842 when a program crashes.
843 TR BR <INTO OR FROM> will trace branches into or out of an address.
844 e.g.
845 TR BR INTO 0 is often quite useful if a program is getting awkward & deciding
846 to branch to 0 & crashing as this will stop at the address before in jumps to 0.
847 TR I R <address range> RUN cmd d g
848 single steps a range of addresses but stays running &
849 displays the gprs on each step.
850
851
852
853 Displaying & modifying Registers
854 --------------------------------
855 D G will display all the gprs
856 Adding a extra G to all the commands is necessary to access the full 64 bit
857 content in VM on z/Architecture. Obviously this isn't required for access
858 registers as these are still 32 bit.
859 e.g. DGG instead of DG
860 D X will display all the control registers
861 D AR will display all the access registers
862 D AR4-7 will display access registers 4 to 7
863 CPU ALL D G will display the GRPS of all CPUS in the configuration
864 D PSW will display the current PSW
865 st PSW 2000 will put the value 2000 into the PSW &
866 cause crash your machine.
867 D PREFIX displays the prefix offset
868
869
870 Displaying Memory
871 -----------------
872 To display memory mapped using the current PSW's mapping try
873 D <range>
874 To make VM display a message each time it hits a particular address and
875 continue try
876 D I<range> will disassemble/display a range of instructions.
877 ST addr 32 bit word will store a 32 bit aligned address
878 D T<range> will display the EBCDIC in an address (if you are that way inclined)
879 D R<range> will display real addresses ( without DAT ) but with prefixing.
880 There are other complex options to display if you need to get at say home space
881 but are in primary space the easiest thing to do is to temporarily
882 modify the PSW to the other addressing mode, display the stuff & then
883 restore it.
884
885
886
887 Hints
888 -----
889 If you want to issue a debugger command without halting your virtual machine
890 with the PA1 key try prefixing the command with #CP e.g.
891 #cp tr i pswa 2000
892 also suffixing most debugger commands with RUN will cause them not
893 to stop just display the mnemonic at the current instruction on the console.
894 If you have several breakpoints you want to put into your program &
895 you get fed up of cross referencing with System.map
896 you can do the following trick for several symbols.
897 grep do_signal System.map
898 which emits the following among other things
899 0001f4e0 T do_signal
900 now you can do
901
902 TR I PSWA 0001f4e0 cmd msg * do_signal
903 This sends a message to your own console each time do_signal is entered.
904 ( As an aside I wrote a perl script once which automatically generated a REXX
905 script with breakpoints on every kernel procedure, this isn't a good idea
906 because there are thousands of these routines & VM can only set 255 breakpoints
907 at a time so you nearly had to spend as long pruning the file down as you would
908 entering the msgs by hand), however, the trick might be useful for a single
909 object file. In the 3270 terminal emulator x3270 there is a very useful option
910 in the file menu called "Save Screen In File" - this is very good for keeping a
911 copy of traces.
912
913 From CMS help <command name> will give you online help on a particular command.
914 e.g.
915 HELP DISPLAY
916
917 Also CP has a file called profile.exec which automatically gets called
918 on startup of CMS ( like autoexec.bat ), keeping on a DOS analogy session
919 CP has a feature similar to doskey, it may be useful for you to
920 use profile.exec to define some keystrokes.
921 e.g.
922 SET PF9 IMM B
923 This does a single step in VM on pressing F8.
924 SET PF10 ^
925 This sets up the ^ key.
926 which can be used for ^c (ctrl-c),^z (ctrl-z) which can't be typed directly
927 into some 3270 consoles.
928 SET PF11 ^-
929 This types the starting keystrokes for a sysrq see SysRq below.
930 SET PF12 RETRIEVE
931 This retrieves command history on pressing F12.
932
933
934 Sometimes in VM the display is set up to scroll automatically this
935 can be very annoying if there are messages you wish to look at
936 to stop this do
937 TERM MORE 255 255
938 This will nearly stop automatic screen updates, however it will
939 cause a denial of service if lots of messages go to the 3270 console,
940 so it would be foolish to use this as the default on a production machine.
941
942
943 Tracing particular processes
944 ----------------------------
945 The kernel's text segment is intentionally at an address in memory that it will
946 very seldom collide with text segments of user programs ( thanks Martin ),
947 this simplifies debugging the kernel.
948 However it is quite common for user processes to have addresses which collide
949 this can make debugging a particular process under VM painful under normal
950 circumstances as the process may change when doing a
951 TR I R <address range>.
952 Thankfully after reading VM's online help I figured out how to debug
953 I particular process.
954
955 Your first problem is to find the STD ( segment table designation )
956 of the program you wish to debug.
957 There are several ways you can do this here are a few
958 1) objdump --syms <program to be debugged> | grep main
959 To get the address of main in the program.
960 tr i pswa <address of main>
961 Start the program, if VM drops to CP on what looks like the entry
962 point of the main function this is most likely the process you wish to debug.
963 Now do a D X13 or D XG13 on z/Architecture.
964 On 31 bit the STD is bits 1-19 ( the STO segment table origin )
965 & 25-31 ( the STL segment table length ) of CR13.
966 now type
967 TR I R STD <CR13's value> 0.7fffffff
968 e.g.
969 TR I R STD 8F32E1FF 0.7fffffff
970 Another very useful variation is
971 TR STORE INTO STD <CR13's value> <address range>
972 for finding out when a particular variable changes.
973
974 An alternative way of finding the STD of a currently running process
975 is to do the following, ( this method is more complex but
976 could be quite convenient if you aren't updating the kernel much &
977 so your kernel structures will stay constant for a reasonable period of
978 time ).
979
980 grep task /proc/<pid>/status
981 from this you should see something like
982 task: 0f160000 ksp: 0f161de8 pt_regs: 0f161f68
983 This now gives you a pointer to the task structure.
984 Now make CC:="s390-gcc -g" kernel/sched.s
985 To get the task_struct stabinfo.
986 ( task_struct is defined in include/linux/sched.h ).
987 Now we want to look at
988 task->active_mm->pgd
989 on my machine the active_mm in the task structure stab is
990 active_mm:(4,12),672,32
991 its offset is 672/8=84=0x54
992 the pgd member in the mm_struct stab is
993 pgd:(4,6)=*(29,5),96,32
994 so its offset is 96/8=12=0xc
995
996 so we'll
997 hexdump -s 0xf160054 /dev/mem | more
998 i.e. task_struct+active_mm offset
999 to look at the active_mm member
1000 f160054 0fee cc60 0019 e334 0000 0000 0000 0011
1001 hexdump -s 0x0feecc6c /dev/mem | more
1002 i.e. active_mm+pgd offset
1003 feecc6c 0f2c 0000 0000 0001 0000 0001 0000 0010
1004 we get something like
1005 now do
1006 TR I R STD <pgd|0x7f> 0.7fffffff
1007 i.e. the 0x7f is added because the pgd only
1008 gives the page table origin & we need to set the low bits
1009 to the maximum possible segment table length.
1010 TR I R STD 0f2c007f 0.7fffffff
1011 on z/Architecture you'll probably need to do
1012 TR I R STD <pgd|0x7> 0.ffffffffffffffff
1013 to set the TableType to 0x1 & the Table length to 3.
1014
1015
1016
1017 Tracing Program Exceptions
1018 --------------------------
1019 If you get a crash which says something like
1020 illegal operation or specification exception followed by a register dump
1021 You can restart linux & trace these using the tr prog <range or value> trace
1022 option.
1023
1024
1025 The most common ones you will normally be tracing for is
1026 1=operation exception
1027 2=privileged operation exception
1028 4=protection exception
1029 5=addressing exception
1030 6=specification exception
1031 10=segment translation exception
1032 11=page translation exception
1033
1034 The full list of these is on page 22 of the current s/390 Reference Summary.
1035 e.g.
1036 tr prog 10 will trace segment translation exceptions.
1037 tr prog on its own will trace all program interruption codes.
1038
1039 Trace Sets
1040 ----------
1041 On starting VM you are initially in the INITIAL trace set.
1042 You can do a Q TR to verify this.
1043 If you have a complex tracing situation where you wish to wait for instance
1044 till a driver is open before you start tracing IO, but know in your
1045 heart that you are going to have to make several runs through the code till you
1046 have a clue whats going on.
1047
1048 What you can do is
1049 TR I PSWA <Driver open address>
1050 hit b to continue till breakpoint
1051 reach the breakpoint
1052 now do your
1053 TR GOTO B
1054 TR IO 7c08-7c09 inst int run
1055 or whatever the IO channels you wish to trace are & hit b
1056
1057 To got back to the initial trace set do
1058 TR GOTO INITIAL
1059 & the TR I PSWA <Driver open address> will be the only active breakpoint again.
1060
1061
1062 Tracing linux syscalls under VM
1063 -------------------------------
1064 Syscalls are implemented on Linux for S390 by the Supervisor call instruction
1065 (SVC). There 256 possibilities of these as the instruction is made up of a 0xA
1066 opcode and the second byte being the syscall number. They are traced using the
1067 simple command:
1068 TR SVC <Optional value or range>
1069 the syscalls are defined in linux/arch/s390/include/asm/unistd.h
1070 e.g. to trace all file opens just do
1071 TR SVC 5 ( as this is the syscall number of open )
1072
1073
1074 SMP Specific commands
1075 ---------------------
1076 To find out how many cpus you have
1077 Q CPUS displays all the CPU's available to your virtual machine
1078 To find the cpu that the current cpu VM debugger commands are being directed at
1079 do Q CPU to change the current cpu VM debugger commands are being directed at do
1080 CPU <desired cpu no>
1081
1082 On a SMP guest issue a command to all CPUs try prefixing the command with cpu
1083 all. To issue a command to a particular cpu try cpu <cpu number> e.g.
1084 CPU 01 TR I R 2000.3000
1085 If you are running on a guest with several cpus & you have a IO related problem
1086 & cannot follow the flow of code but you know it isn't smp related.
1087 from the bash prompt issue
1088 shutdown -h now or halt.
1089 do a Q CPUS to find out how many cpus you have
1090 detach each one of them from cp except cpu 0
1091 by issuing a
1092 DETACH CPU 01-(number of cpus in configuration)
1093 & boot linux again.
1094 TR SIGP will trace inter processor signal processor instructions.
1095 DEFINE CPU 01-(number in configuration)
1096 will get your guests cpus back.
1097
1098
1099 Help for displaying ascii textstrings
1100 -------------------------------------
1101 On the very latest VM Nucleus'es VM can now display ascii
1102 ( thanks Neale for the hint ) by doing
1103 D TX<lowaddr>.<len>
1104 e.g.
1105 D TX0.100
1106
1107 Alternatively
1108 =============
1109 Under older VM debuggers (I love EBDIC too) you can use following little
1110 program which converts a command line of hex digits to ascii text. It can be
1111 compiled under linux and you can copy the hex digits from your x3270 terminal
1112 to your xterm if you are debugging from a linuxbox.
1113
1114 This is quite useful when looking at a parameter passed in as a text string
1115 under VM ( unless you are good at decoding ASCII in your head ).
1116
1117 e.g. consider tracing an open syscall
1118 TR SVC 5
1119 We have stopped at a breakpoint
1120 000151B0' SVC 0A05 -> 0001909A' CC 0
1121
1122 D 20.8 to check the SVC old psw in the prefix area and see was it from userspace
1123 (for the layout of the prefix area consult the "Fixed Storage Locations"
1124 chapter of the s/390 Reference Summary if you have it available).
1125 V00000020 070C2000 800151B2
1126 The problem state bit wasn't set & it's also too early in the boot sequence
1127 for it to be a userspace SVC if it was we would have to temporarily switch the
1128 psw to user space addressing so we could get at the first parameter of the open
1129 in gpr2.
1130 Next do a
1131 D G2
1132 GPR 2 = 00014CB4
1133 Now display what gpr2 is pointing to
1134 D 00014CB4.20
1135 V00014CB4 2F646576 2F636F6E 736F6C65 00001BF5
1136 V00014CC4 FC00014C B4001001 E0001000 B8070707
1137 Now copy the text till the first 00 hex ( which is the end of the string
1138 to an xterm & do hex2ascii on it.
1139 hex2ascii 2F646576 2F636F6E 736F6C65 00
1140 outputs
1141 Decoded Hex:=/ d e v / c o n s o l e 0x00
1142 We were opening the console device,
1143
1144 You can compile the code below yourself for practice :-),
1145 /*
1146 * hex2ascii.c
1147 * a useful little tool for converting a hexadecimal command line to ascii
1148 *
1149 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
1150 * (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation.
1151 */
1152 #include <stdio.h>
1153
1154 int main(int argc,char *argv[])
1155 {
1156 int cnt1,cnt2,len,toggle=0;
1157 int startcnt=1;
1158 unsigned char c,hex;
1159
1160 if(argc>1&&(strcmp(argv[1],"-a")==0))
1161 startcnt=2;
1162 printf("Decoded Hex:=");
1163 for(cnt1=startcnt;cnt1<argc;cnt1++)
1164 {
1165 len=strlen(argv[cnt1]);
1166 for(cnt2=0;cnt2<len;cnt2++)
1167 {
1168 c=argv[cnt1][cnt2];
1169 if(c>='0'&&c<='9')
1170 c=c-'0';
1171 if(c>='A'&&c<='F')
1172 c=c-'A'+10;
1173 if(c>='a'&&c<='f')
1174 c=c-'a'+10;
1175 switch(toggle)
1176 {
1177 case 0:
1178 hex=c<<4;
1179 toggle=1;
1180 break;
1181 case 1:
1182 hex+=c;
1183 if(hex<32||hex>127)
1184 {
1185 if(startcnt==1)
1186 printf("0x%02X ",(int)hex);
1187 else
1188 printf(".");
1189 }
1190 else
1191 {
1192 printf("%c",hex);
1193 if(startcnt==1)
1194 printf(" ");
1195 }
1196 toggle=0;
1197 break;
1198 }
1199 }
1200 }
1201 printf("\n");
1202 }
1203
1204
1205
1206
1207 Stack tracing under VM
1208 ----------------------
1209 A basic backtrace
1210 -----------------
1211
1212 Here are the tricks I use 9 out of 10 times it works pretty well,
1213
1214 When your backchain reaches a dead end
1215 --------------------------------------
1216 This can happen when an exception happens in the kernel and the kernel is
1217 entered twice. If you reach the NULL pointer at the end of the back chain you
1218 should be able to sniff further back if you follow the following tricks.
1219 1) A kernel address should be easy to recognise since it is in
1220 primary space & the problem state bit isn't set & also
1221 The Hi bit of the address is set.
1222 2) Another backchain should also be easy to recognise since it is an
1223 address pointing to another address approximately 100 bytes or 0x70 hex
1224 behind the current stackpointer.
1225
1226
1227 Here is some practice.
1228 boot the kernel & hit PA1 at some random time
1229 d g to display the gprs, this should display something like
1230 GPR 0 = 00000001 00156018 0014359C 00000000
1231 GPR 4 = 00000001 001B8888 000003E0 00000000
1232 GPR 8 = 00100080 00100084 00000000 000FE000
1233 GPR 12 = 00010400 8001B2DC 8001B36A 000FFED8
1234 Note that GPR14 is a return address but as we are real men we are going to
1235 trace the stack.
1236 display 0x40 bytes after the stack pointer.
1237
1238 V000FFED8 000FFF38 8001B838 80014C8E 000FFF38
1239 V000FFEE8 00000000 00000000 000003E0 00000000
1240 V000FFEF8 00100080 00100084 00000000 000FE000
1241 V000FFF08 00010400 8001B2DC 8001B36A 000FFED8
1242
1243
1244 Ah now look at whats in sp+56 (sp+0x38) this is 8001B36A our saved r14 if
1245 you look above at our stackframe & also agrees with GPR14.
1246
1247 now backchain
1248 d 000FFF38.40
1249 we now are taking the contents of SP to get our first backchain.
1250
1251 V000FFF38 000FFFA0 00000000 00014995 00147094
1252 V000FFF48 00147090 001470A0 000003E0 00000000
1253 V000FFF58 00100080 00100084 00000000 001BF1D0
1254 V000FFF68 00010400 800149BA 80014CA6 000FFF38
1255
1256 This displays a 2nd return address of 80014CA6
1257
1258 now do d 000FFFA0.40 for our 3rd backchain
1259
1260 V000FFFA0 04B52002 0001107F 00000000 00000000
1261 V000FFFB0 00000000 00000000 FF000000 0001107F
1262 V000FFFC0 00000000 00000000 00000000 00000000
1263 V000FFFD0 00010400 80010802 8001085A 000FFFA0
1264
1265
1266 our 3rd return address is 8001085A
1267
1268 as the 04B52002 looks suspiciously like rubbish it is fair to assume that the
1269 kernel entry routines for the sake of optimisation don't set up a backchain.
1270
1271 now look at System.map to see if the addresses make any sense.
1272
1273 grep -i 0001b3 System.map
1274 outputs among other things
1275 0001b304 T cpu_idle
1276 so 8001B36A
1277 is cpu_idle+0x66 ( quiet the cpu is asleep, don't wake it )
1278
1279
1280 grep -i 00014 System.map
1281 produces among other things
1282 00014a78 T start_kernel
1283 so 0014CA6 is start_kernel+some hex number I can't add in my head.
1284
1285 grep -i 00108 System.map
1286 this produces
1287 00010800 T _stext
1288 so 8001085A is _stext+0x5a
1289
1290 Congrats you've done your first backchain.
1291
1292
1293
1294 s/390 & z/Architecture IO Overview
1295 ==================================
1296
1297 I am not going to give a course in 390 IO architecture as this would take me
1298 quite a while and I'm no expert. Instead I'll give a 390 IO architecture
1299 summary for Dummies. If you have the s/390 principles of operation available
1300 read this instead. If nothing else you may find a few useful keywords in here
1301 and be able to use them on a web search engine to find more useful information.
1302
1303 Unlike other bus architectures modern 390 systems do their IO using mostly
1304 fibre optics and devices such as tapes and disks can be shared between several
1305 mainframes. Also S390 can support up to 65536 devices while a high end PC based
1306 system might be choking with around 64.
1307
1308 Here is some of the common IO terminology:
1309
1310 Subchannel:
1311 This is the logical number most IO commands use to talk to an IO device. There
1312 can be up to 0x10000 (65536) of these in a configuration, typically there are a
1313 few hundred. Under VM for simplicity they are allocated contiguously, however
1314 on the native hardware they are not. They typically stay consistent between
1315 boots provided no new hardware is inserted or removed.
1316 Under Linux for s390 we use these as IRQ's and also when issuing an IO command
1317 (CLEAR SUBCHANNEL, HALT SUBCHANNEL, MODIFY SUBCHANNEL, RESUME SUBCHANNEL,
1318 START SUBCHANNEL, STORE SUBCHANNEL and TEST SUBCHANNEL). We use this as the ID
1319 of the device we wish to talk to. The most important of these instructions are
1320 START SUBCHANNEL (to start IO), TEST SUBCHANNEL (to check whether the IO
1321 completed successfully) and HALT SUBCHANNEL (to kill IO). A subchannel can have
1322 up to 8 channel paths to a device, this offers redundancy if one is not
1323 available.
1324
1325 Device Number:
1326 This number remains static and is closely tied to the hardware. There are 65536
1327 of these, made up of a CHPID (Channel Path ID, the most significant 8 bits) and
1328 another lsb 8 bits. These remain static even if more devices are inserted or
1329 removed from the hardware. There is a 1 to 1 mapping between subchannels and
1330 device numbers, provided devices aren't inserted or removed.
1331
1332 Channel Control Words:
1333 CCWs are linked lists of instructions initially pointed to by an operation
1334 request block (ORB), which is initially given to Start Subchannel (SSCH)
1335 command along with the subchannel number for the IO subsystem to process
1336 while the CPU continues executing normal code.
1337 CCWs come in two flavours, Format 0 (24 bit for backward compatibility) and
1338 Format 1 (31 bit). These are typically used to issue read and write (and many
1339 other) instructions. They consist of a length field and an absolute address
1340 field.
1341 Each IO typically gets 1 or 2 interrupts, one for channel end (primary status)
1342 when the channel is idle, and the second for device end (secondary status).
1343 Sometimes you get both concurrently. You check how the IO went on by issuing a
1344 TEST SUBCHANNEL at each interrupt, from which you receive an Interruption
1345 response block (IRB). If you get channel and device end status in the IRB
1346 without channel checks etc. your IO probably went okay. If you didn't you
1347 probably need to examine the IRB, extended status word etc.
1348 If an error occurs, more sophisticated control units have a facility known as
1349 concurrent sense. This means that if an error occurs Extended sense information
1350 will be presented in the Extended status word in the IRB. If not you have to
1351 issue a subsequent SENSE CCW command after the test subchannel.
1352
1353
1354 TPI (Test pending interrupt) can also be used for polled IO, but in
1355 multitasking multiprocessor systems it isn't recommended except for
1356 checking special cases (i.e. non looping checks for pending IO etc.).
1357
1358 Store Subchannel and Modify Subchannel can be used to examine and modify
1359 operating characteristics of a subchannel (e.g. channel paths).
1360
1361 Other IO related Terms:
1362 Sysplex: S390's Clustering Technology
1363 QDIO: S390's new high speed IO architecture to support devices such as gigabit
1364 ethernet, this architecture is also designed to be forward compatible with
1365 upcoming 64 bit machines.
1366
1367
1368 General Concepts
1369
1370 Input Output Processors (IOP's) are responsible for communicating between
1371 the mainframe CPU's & the channel & relieve the mainframe CPU's from the
1372 burden of communicating with IO devices directly, this allows the CPU's to
1373 concentrate on data processing.
1374
1375 IOP's can use one or more links ( known as channel paths ) to talk to each
1376 IO device. It first checks for path availability & chooses an available one,
1377 then starts ( & sometimes terminates IO ).
1378 There are two types of channel path: ESCON & the Parallel IO interface.
1379
1380 IO devices are attached to control units, control units provide the
1381 logic to interface the channel paths & channel path IO protocols to
1382 the IO devices, they can be integrated with the devices or housed separately
1383 & often talk to several similar devices ( typical examples would be raid
1384 controllers or a control unit which connects to 1000 3270 terminals ).
1385
1386
1387 +---------------------------------------------------------------+
1388 | +-----+ +-----+ +-----+ +-----+ +----------+ +----------+ |
1389 | | CPU | | CPU | | CPU | | CPU | | Main | | Expanded | |
1390 | | | | | | | | | | Memory | | Storage | |
1391 | +-----+ +-----+ +-----+ +-----+ +----------+ +----------+ |
1392 |---------------------------------------------------------------+
1393 | IOP | IOP | IOP |
1394 |---------------------------------------------------------------
1395 | C | C | C | C | C | C | C | C | C | C | C | C | C | C | C | C |
1396 ----------------------------------------------------------------
1397 || ||
1398 || Bus & Tag Channel Path || ESCON
1399 || ====================== || Channel
1400 || || || || Path
1401 +----------+ +----------+ +----------+
1402 | | | | | |
1403 | CU | | CU | | CU |
1404 | | | | | |
1405 +----------+ +----------+ +----------+
1406 | | | | |
1407 +----------+ +----------+ +----------+ +----------+ +----------+
1408 |I/O Device| |I/O Device| |I/O Device| |I/O Device| |I/O Device|
1409 +----------+ +----------+ +----------+ +----------+ +----------+
1410 CPU = Central Processing Unit
1411 C = Channel
1412 IOP = IP Processor
1413 CU = Control Unit
1414
1415 The 390 IO systems come in 2 flavours the current 390 machines support both
1416
1417 The Older 360 & 370 Interface,sometimes called the Parallel I/O interface,
1418 sometimes called Bus-and Tag & sometimes Original Equipment Manufacturers
1419 Interface (OEMI).
1420
1421 This byte wide Parallel channel path/bus has parity & data on the "Bus" cable
1422 and control lines on the "Tag" cable. These can operate in byte multiplex mode
1423 for sharing between several slow devices or burst mode and monopolize the
1424 channel for the whole burst. Up to 256 devices can be addressed on one of these
1425 cables. These cables are about one inch in diameter. The maximum unextended
1426 length supported by these cables is 125 Meters but this can be extended up to
1427 2km with a fibre optic channel extended such as a 3044. The maximum burst speed
1428 supported is 4.5 megabytes per second. However, some really old processors
1429 support only transfer rates of 3.0, 2.0 & 1.0 MB/sec.
1430 One of these paths can be daisy chained to up to 8 control units.
1431
1432
1433 ESCON if fibre optic it is also called FICON
1434 Was introduced by IBM in 1990. Has 2 fibre optic cables and uses either leds or
1435 lasers for communication at a signaling rate of up to 200 megabits/sec. As
1436 10bits are transferred for every 8 bits info this drops to 160 megabits/sec
1437 and to 18.6 Megabytes/sec once control info and CRC are added. ESCON only
1438 operates in burst mode.
1439
1440 ESCONs typical max cable length is 3km for the led version and 20km for the
1441 laser version known as XDF (extended distance facility). This can be further
1442 extended by using an ESCON director which triples the above mentioned ranges.
1443 Unlike Bus & Tag as ESCON is serial it uses a packet switching architecture,
1444 the standard Bus & Tag control protocol is however present within the packets.
1445 Up to 256 devices can be attached to each control unit that uses one of these
1446 interfaces.
1447
1448 Common 390 Devices include:
1449 Network adapters typically OSA2,3172's,2116's & OSA-E gigabit ethernet adapters,
1450 Consoles 3270 & 3215 (a teletype emulated under linux for a line mode console).
1451 DASD's direct access storage devices ( otherwise known as hard disks ).
1452 Tape Drives.
1453 CTC ( Channel to Channel Adapters ),
1454 ESCON or Parallel Cables used as a very high speed serial link
1455 between 2 machines.
1456
1457
1458 Debugging IO on s/390 & z/Architecture under VM
1459 ===============================================
1460
1461 Now we are ready to go on with IO tracing commands under VM
1462
1463 A few self explanatory queries:
1464 Q OSA
1465 Q CTC
1466 Q DISK ( This command is CMS specific )
1467 Q DASD
1468
1469
1470
1471
1472
1473
1474 Q OSA on my machine returns
1475 OSA 7C08 ON OSA 7C08 SUBCHANNEL = 0000
1476 OSA 7C09 ON OSA 7C09 SUBCHANNEL = 0001
1477 OSA 7C14 ON OSA 7C14 SUBCHANNEL = 0002
1478 OSA 7C15 ON OSA 7C15 SUBCHANNEL = 0003
1479
1480 If you have a guest with certain privileges you may be able to see devices
1481 which don't belong to you. To avoid this, add the option V.
1482 e.g.
1483 Q V OSA
1484
1485 Now using the device numbers returned by this command we will
1486 Trace the io starting up on the first device 7c08 & 7c09
1487 In our simplest case we can trace the
1488 start subchannels
1489 like TR SSCH 7C08-7C09
1490 or the halt subchannels
1491 or TR HSCH 7C08-7C09
1492 MSCH's ,STSCH's I think you can guess the rest
1493
1494 A good trick is tracing all the IO's and CCWS and spooling them into the reader
1495 of another VM guest so he can ftp the logfile back to his own machine. I'll do
1496 a small bit of this and give you a look at the output.
1497
1498 1) Spool stdout to VM reader
1499 SP PRT TO (another vm guest ) or * for the local vm guest
1500 2) Fill the reader with the trace
1501 TR IO 7c08-7c09 INST INT CCW PRT RUN
1502 3) Start up linux
1503 i 00c
1504 4) Finish the trace
1505 TR END
1506 5) close the reader
1507 C PRT
1508 6) list reader contents
1509 RDRLIST
1510 7) copy it to linux4's minidisk
1511 RECEIVE / LOG TXT A1 ( replace
1512 8)
1513 filel & press F11 to look at it
1514 You should see something like:
1515
1516 00020942' SSCH B2334000 0048813C CC 0 SCH 0000 DEV 7C08
1517 CPA 000FFDF0 PARM 00E2C9C4 KEY 0 FPI C0 LPM 80
1518 CCW 000FFDF0 E4200100 00487FE8 0000 E4240100 ........
1519 IDAL 43D8AFE8
1520 IDAL 0FB76000
1521 00020B0A' I/O DEV 7C08 -> 000197BC' SCH 0000 PARM 00E2C9C4
1522 00021628' TSCH B2354000 >> 00488164 CC 0 SCH 0000 DEV 7C08
1523 CCWA 000FFDF8 DEV STS 0C SCH STS 00 CNT 00EC
1524 KEY 0 FPI C0 CC 0 CTLS 4007
1525 00022238' STSCH B2344000 >> 00488108 CC 0 SCH 0000 DEV 7C08
1526
1527 If you don't like messing up your readed ( because you possibly booted from it )
1528 you can alternatively spool it to another readers guest.
1529
1530
1531 Other common VM device related commands
1532 ---------------------------------------------
1533 These commands are listed only because they have
1534 been of use to me in the past & may be of use to
1535 you too. For more complete info on each of the commands
1536 use type HELP <command> from CMS.
1537 detaching devices
1538 DET <devno range>
1539 ATT <devno range> <guest>
1540 attach a device to guest * for your own guest
1541 READY <devno> cause VM to issue a fake interrupt.
1542
1543 The VARY command is normally only available to VM administrators.
1544 VARY ON PATH <path> TO <devno range>
1545 VARY OFF PATH <PATH> FROM <devno range>
1546 This is used to switch on or off channel paths to devices.
1547
1548 Q CHPID <channel path ID>
1549 This displays state of devices using this channel path
1550 D SCHIB <subchannel>
1551 This displays the subchannel information SCHIB block for the device.
1552 this I believe is also only available to administrators.
1553 DEFINE CTC <devno>
1554 defines a virtual CTC channel to channel connection
1555 2 need to be defined on each guest for the CTC driver to use.
1556 COUPLE devno userid remote devno
1557 Joins a local virtual device to a remote virtual device
1558 ( commonly used for the CTC driver ).
1559
1560 Building a VM ramdisk under CMS which linux can use
1561 def vfb-<blocksize> <subchannel> <number blocks>
1562 blocksize is commonly 4096 for linux.
1563 Formatting it
1564 format <subchannel> <driver letter e.g. x> (blksize <blocksize>
1565
1566 Sharing a disk between multiple guests
1567 LINK userid devno1 devno2 mode password
1568
1569
1570
1571 GDB on S390
1572 ===========
1573 N.B. if compiling for debugging gdb works better without optimisation
1574 ( see Compiling programs for debugging )
1575
1576 invocation
1577 ----------
1578 gdb <victim program> <optional corefile>
1579
1580 Online help
1581 -----------
1582 help: gives help on commands
1583 e.g.
1584 help
1585 help display
1586 Note gdb's online help is very good use it.
1587
1588
1589 Assembly
1590 --------
1591 info registers: displays registers other than floating point.
1592 info all-registers: displays floating points as well.
1593 disassemble: disassembles
1594 e.g.
1595 disassemble without parameters will disassemble the current function
1596 disassemble $pc $pc+10
1597
1598 Viewing & modifying variables
1599 -----------------------------
1600 print or p: displays variable or register
1601 e.g. p/x $sp will display the stack pointer
1602
1603 display: prints variable or register each time program stops
1604 e.g.
1605 display/x $pc will display the program counter
1606 display argc
1607
1608 undisplay : undo's display's
1609
1610 info breakpoints: shows all current breakpoints
1611
1612 info stack: shows stack back trace (if this doesn't work too well, I'll show
1613 you the stacktrace by hand below).
1614
1615 info locals: displays local variables.
1616
1617 info args: display current procedure arguments.
1618
1619 set args: will set argc & argv each time the victim program is invoked.
1620
1621 set <variable>=value
1622 set argc=100
1623 set $pc=0
1624
1625
1626
1627 Modifying execution
1628 -------------------
1629 step: steps n lines of sourcecode
1630 step steps 1 line.
1631 step 100 steps 100 lines of code.
1632
1633 next: like step except this will not step into subroutines
1634
1635 stepi: steps a single machine code instruction.
1636 e.g. stepi 100
1637
1638 nexti: steps a single machine code instruction but will not step into
1639 subroutines.
1640
1641 finish: will run until exit of the current routine
1642
1643 run: (re)starts a program
1644
1645 cont: continues a program
1646
1647 quit: exits gdb.
1648
1649
1650 breakpoints
1651 ------------
1652
1653 break
1654 sets a breakpoint
1655 e.g.
1656
1657 break main
1658
1659 break *$pc
1660
1661 break *0x400618
1662
1663 Here's a really useful one for large programs
1664 rbr
1665 Set a breakpoint for all functions matching REGEXP
1666 e.g.
1667 rbr 390
1668 will set a breakpoint with all functions with 390 in their name.
1669
1670 info breakpoints
1671 lists all breakpoints
1672
1673 delete: delete breakpoint by number or delete them all
1674 e.g.
1675 delete 1 will delete the first breakpoint
1676 delete will delete them all
1677
1678 watch: This will set a watchpoint ( usually hardware assisted ),
1679 This will watch a variable till it changes
1680 e.g.
1681 watch cnt, will watch the variable cnt till it changes.
1682 As an aside unfortunately gdb's, architecture independent watchpoint code
1683 is inconsistent & not very good, watchpoints usually work but not always.
1684
1685 info watchpoints: Display currently active watchpoints
1686
1687 condition: ( another useful one )
1688 Specify breakpoint number N to break only if COND is true.
1689 Usage is `condition N COND', where N is an integer and COND is an
1690 expression to be evaluated whenever breakpoint N is reached.
1691
1692
1693
1694 User defined functions/macros
1695 -----------------------------
1696 define: ( Note this is very very useful,simple & powerful )
1697 usage define <name> <list of commands> end
1698
1699 examples which you should consider putting into .gdbinit in your home directory
1700 define d
1701 stepi
1702 disassemble $pc $pc+10
1703 end
1704
1705 define e
1706 nexti
1707 disassemble $pc $pc+10
1708 end
1709
1710
1711 Other hard to classify stuff
1712 ----------------------------
1713 signal n:
1714 sends the victim program a signal.
1715 e.g. signal 3 will send a SIGQUIT.
1716
1717 info signals:
1718 what gdb does when the victim receives certain signals.
1719
1720 list:
1721 e.g.
1722 list lists current function source
1723 list 1,10 list first 10 lines of current file.
1724 list test.c:1,10
1725
1726
1727 directory:
1728 Adds directories to be searched for source if gdb cannot find the source.
1729 (note it is a bit sensitive about slashes)
1730 e.g. To add the root of the filesystem to the searchpath do
1731 directory //
1732
1733
1734 call <function>
1735 This calls a function in the victim program, this is pretty powerful
1736 e.g.
1737 (gdb) call printf("hello world")
1738 outputs:
1739 $1 = 11
1740
1741 You might now be thinking that the line above didn't work, something extra had
1742 to be done.
1743 (gdb) call fflush(stdout)
1744 hello world$2 = 0
1745 As an aside the debugger also calls malloc & free under the hood
1746 to make space for the "hello world" string.
1747
1748
1749
1750 hints
1751 -----
1752 1) command completion works just like bash
1753 ( if you are a bad typist like me this really helps )
1754 e.g. hit br <TAB> & cursor up & down :-).
1755
1756 2) if you have a debugging problem that takes a few steps to recreate
1757 put the steps into a file called .gdbinit in your current working directory
1758 if you have defined a few extra useful user defined commands put these in
1759 your home directory & they will be read each time gdb is launched.
1760
1761 A typical .gdbinit file might be.
1762 break main
1763 run
1764 break runtime_exception
1765 cont
1766
1767
1768 stack chaining in gdb by hand
1769 -----------------------------
1770 This is done using a the same trick described for VM
1771 p/x (*($sp+56))&0x7fffffff get the first backchain.
1772
1773 For z/Architecture
1774 Replace 56 with 112 & ignore the &0x7fffffff
1775 in the macros below & do nasty casts to longs like the following
1776 as gdb unfortunately deals with printed arguments as ints which
1777 messes up everything.
1778 i.e. here is a 3rd backchain dereference
1779 p/x *(long *)(***(long ***)$sp+112)
1780
1781
1782 this outputs
1783 $5 = 0x528f18
1784 on my machine.
1785 Now you can use
1786 info symbol (*($sp+56))&0x7fffffff
1787 you might see something like.
1788 rl_getc + 36 in section .text telling you what is located at address 0x528f18
1789 Now do.
1790 p/x (*(*$sp+56))&0x7fffffff
1791 This outputs
1792 $6 = 0x528ed0
1793 Now do.
1794 info symbol (*(*$sp+56))&0x7fffffff
1795 rl_read_key + 180 in section .text
1796 now do
1797 p/x (*(**$sp+56))&0x7fffffff
1798 & so on.
1799
1800 Disassembling instructions without debug info
1801 ---------------------------------------------
1802 gdb typically complains if there is a lack of debugging
1803 symbols in the disassemble command with
1804 "No function contains specified address." To get around
1805 this do
1806 x/<number lines to disassemble>xi <address>
1807 e.g.
1808 x/20xi 0x400730
1809
1810
1811
1812 Note: Remember gdb has history just like bash you don't need to retype the
1813 whole line just use the up & down arrows.
1814
1815
1816
1817 For more info
1818 -------------
1819 From your linuxbox do
1820 man gdb or info gdb.
1821
1822 core dumps
1823 ----------
1824 What a core dump ?,
1825 A core dump is a file generated by the kernel (if allowed) which contains the
1826 registers and all active pages of the program which has crashed.
1827 From this file gdb will allow you to look at the registers, stack trace and
1828 memory of the program as if it just crashed on your system. It is usually
1829 called core and created in the current working directory.
1830 This is very useful in that a customer can mail a core dump to a technical
1831 support department and the technical support department can reconstruct what
1832 happened. Provided they have an identical copy of this program with debugging
1833 symbols compiled in and the source base of this build is available.
1834 In short it is far more useful than something like a crash log could ever hope
1835 to be.
1836
1837 Why have I never seen one ?.
1838 Probably because you haven't used the command
1839 ulimit -c unlimited in bash
1840 to allow core dumps, now do
1841 ulimit -a
1842 to verify that the limit was accepted.
1843
1844 A sample core dump
1845 To create this I'm going to do
1846 ulimit -c unlimited
1847 gdb
1848 to launch gdb (my victim app. ) now be bad & do the following from another
1849 telnet/xterm session to the same machine
1850 ps -aux | grep gdb
1851 kill -SIGSEGV <gdb's pid>
1852 or alternatively use killall -SIGSEGV gdb if you have the killall command.
1853 Now look at the core dump.
1854 ./gdb core
1855 Displays the following
1856 GNU gdb 4.18
1857 Copyright 1998 Free Software Foundation, Inc.
1858 GDB is free software, covered by the GNU General Public License, and you are
1859 welcome to change it and/or distribute copies of it under certain conditions.
1860 Type "show copying" to see the conditions.
1861 There is absolutely no warranty for GDB. Type "show warranty" for details.
1862 This GDB was configured as "s390-ibm-linux"...
1863 Core was generated by `./gdb'.
1864 Program terminated with signal 11, Segmentation fault.
1865 Reading symbols from /usr/lib/libncurses.so.4...done.
1866 Reading symbols from /lib/libm.so.6...done.
1867 Reading symbols from /lib/libc.so.6...done.
1868 Reading symbols from /lib/ld-linux.so.2...done.
1869 #0 0x40126d1a in read () from /lib/libc.so.6
1870 Setting up the environment for debugging gdb.
1871 Breakpoint 1 at 0x4dc6f8: file utils.c, line 471.
1872 Breakpoint 2 at 0x4d87a4: file top.c, line 2609.
1873 (top-gdb) info stack
1874 #0 0x40126d1a in read () from /lib/libc.so.6
1875 #1 0x528f26 in rl_getc (stream=0x7ffffde8) at input.c:402
1876 #2 0x528ed0 in rl_read_key () at input.c:381
1877 #3 0x5167e6 in readline_internal_char () at readline.c:454
1878 #4 0x5168ee in readline_internal_charloop () at readline.c:507
1879 #5 0x51692c in readline_internal () at readline.c:521
1880 #6 0x5164fe in readline (prompt=0x7ffff810)
1881 at readline.c:349
1882 #7 0x4d7a8a in command_line_input (prompt=0x564420 "(gdb) ", repeat=1,
1883 annotation_suffix=0x4d6b44 "prompt") at top.c:2091
1884 #8 0x4d6cf0 in command_loop () at top.c:1345
1885 #9 0x4e25bc in main (argc=1, argv=0x7ffffdf4) at main.c:635
1886
1887
1888 LDD
1889 ===
1890 This is a program which lists the shared libraries which a library needs,
1891 Note you also get the relocations of the shared library text segments which
1892 help when using objdump --source.
1893 e.g.
1894 ldd ./gdb
1895 outputs
1896 libncurses.so.4 => /usr/lib/libncurses.so.4 (0x40018000)
1897 libm.so.6 => /lib/libm.so.6 (0x4005e000)
1898 libc.so.6 => /lib/libc.so.6 (0x40084000)
1899 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
1900
1901
1902 Debugging shared libraries
1903 ==========================
1904 Most programs use shared libraries, however it can be very painful
1905 when you single step instruction into a function like printf for the
1906 first time & you end up in functions like _dl_runtime_resolve this is
1907 the ld.so doing lazy binding, lazy binding is a concept in ELF where
1908 shared library functions are not loaded into memory unless they are
1909 actually used, great for saving memory but a pain to debug.
1910 To get around this either relink the program -static or exit gdb type
1911 export LD_BIND_NOW=true this will stop lazy binding & restart the gdb'ing
1912 the program in question.
1913
1914
1915
1916 Debugging modules
1917 =================
1918 As modules are dynamically loaded into the kernel their address can be
1919 anywhere to get around this use the -m option with insmod to emit a load
1920 map which can be piped into a file if required.
1921
1922 The proc file system
1923 ====================
1924 What is it ?.
1925 It is a filesystem created by the kernel with files which are created on demand
1926 by the kernel if read, or can be used to modify kernel parameters,
1927 it is a powerful concept.
1928
1929 e.g.
1930
1931 cat /proc/sys/net/ipv4/ip_forward
1932 On my machine outputs
1933 0
1934 telling me ip_forwarding is not on to switch it on I can do
1935 echo 1 > /proc/sys/net/ipv4/ip_forward
1936 cat it again
1937 cat /proc/sys/net/ipv4/ip_forward
1938 On my machine now outputs
1939 1
1940 IP forwarding is on.
1941 There is a lot of useful info in here best found by going in and having a look
1942 around, so I'll take you through some entries I consider important.
1943
1944 All the processes running on the machine have their own entry defined by
1945 /proc/<pid>
1946 So lets have a look at the init process
1947 cd /proc/1
1948
1949 cat cmdline
1950 emits
1951 init [2]
1952
1953 cd /proc/1/fd
1954 This contains numerical entries of all the open files,
1955 some of these you can cat e.g. stdout (2)
1956
1957 cat /proc/29/maps
1958 on my machine emits
1959
1960 00400000-00478000 r-xp 00000000 5f:00 4103 /bin/bash
1961 00478000-0047e000 rw-p 00077000 5f:00 4103 /bin/bash
1962 0047e000-00492000 rwxp 00000000 00:00 0
1963 40000000-40015000 r-xp 00000000 5f:00 14382 /lib/ld-2.1.2.so
1964 40015000-40016000 rw-p 00014000 5f:00 14382 /lib/ld-2.1.2.so
1965 40016000-40017000 rwxp 00000000 00:00 0
1966 40017000-40018000 rw-p 00000000 00:00 0
1967 40018000-4001b000 r-xp 00000000 5f:00 14435 /lib/libtermcap.so.2.0.8
1968 4001b000-4001c000 rw-p 00002000 5f:00 14435 /lib/libtermcap.so.2.0.8
1969 4001c000-4010d000 r-xp 00000000 5f:00 14387 /lib/libc-2.1.2.so
1970 4010d000-40111000 rw-p 000f0000 5f:00 14387 /lib/libc-2.1.2.so
1971 40111000-40114000 rw-p 00000000 00:00 0
1972 40114000-4011e000 r-xp 00000000 5f:00 14408 /lib/libnss_files-2.1.2.so
1973 4011e000-4011f000 rw-p 00009000 5f:00 14408 /lib/libnss_files-2.1.2.so
1974 7fffd000-80000000 rwxp ffffe000 00:00 0
1975
1976
1977 Showing us the shared libraries init uses where they are in memory
1978 & memory access permissions for each virtual memory area.
1979
1980 /proc/1/cwd is a softlink to the current working directory.
1981 /proc/1/root is the root of the filesystem for this process.
1982
1983 /proc/1/mem is the current running processes memory which you
1984 can read & write to like a file.
1985 strace uses this sometimes as it is a bit faster than the
1986 rather inefficient ptrace interface for peeking at DATA.
1987
1988
1989 cat status
1990
1991 Name: init
1992 State: S (sleeping)
1993 Pid: 1
1994 PPid: 0
1995 Uid: 0 0 0 0
1996 Gid: 0 0 0 0
1997 Groups:
1998 VmSize: 408 kB
1999 VmLck: 0 kB
2000 VmRSS: 208 kB
2001 VmData: 24 kB
2002 VmStk: 8 kB
2003 VmExe: 368 kB
2004 VmLib: 0 kB
2005 SigPnd: 0000000000000000
2006 SigBlk: 0000000000000000
2007 SigIgn: 7fffffffd7f0d8fc
2008 SigCgt: 00000000280b2603
2009 CapInh: 00000000fffffeff
2010 CapPrm: 00000000ffffffff
2011 CapEff: 00000000fffffeff
2012
2013 User PSW: 070de000 80414146
2014 task: 004b6000 tss: 004b62d8 ksp: 004b7ca8 pt_regs: 004b7f68
2015 User GPRS:
2016 00000400 00000000 0000000b 7ffffa90
2017 00000000 00000000 00000000 0045d9f4
2018 0045cafc 7ffffa90 7fffff18 0045cb08
2019 00010400 804039e8 80403af8 7ffff8b0
2020 User ACRS:
2021 00000000 00000000 00000000 00000000
2022 00000001 00000000 00000000 00000000
2023 00000000 00000000 00000000 00000000
2024 00000000 00000000 00000000 00000000
2025 Kernel BackChain CallChain BackChain CallChain
2026 004b7ca8 8002bd0c 004b7d18 8002b92c
2027 004b7db8 8005cd50 004b7e38 8005d12a
2028 004b7f08 80019114
2029 Showing among other things memory usage & status of some signals &
2030 the processes'es registers from the kernel task_structure
2031 as well as a backchain which may be useful if a process crashes
2032 in the kernel for some unknown reason.
2033
2034 Some driver debugging techniques
2035 ================================
2036 debug feature
2037 -------------
2038 Some of our drivers now support a "debug feature" in
2039 /proc/s390dbf see s390dbf.txt in the linux/Documentation directory
2040 for more info.
2041 e.g.
2042 to switch on the lcs "debug feature"
2043 echo 5 > /proc/s390dbf/lcs/level
2044 & then after the error occurred.
2045 cat /proc/s390dbf/lcs/sprintf >/logfile
2046 the logfile now contains some information which may help
2047 tech support resolve a problem in the field.
2048
2049
2050
2051 high level debugging network drivers
2052 ------------------------------------
2053 ifconfig is a quite useful command
2054 it gives the current state of network drivers.
2055
2056 If you suspect your network device driver is dead
2057 one way to check is type
2058 ifconfig <network device>
2059 e.g. tr0
2060 You should see something like
2061 tr0 Link encap:16/4 Mbps Token Ring (New) HWaddr 00:04:AC:20:8E:48
2062 inet addr:9.164.185.132 Bcast:9.164.191.255 Mask:255.255.224.0
2063 UP BROADCAST RUNNING MULTICAST MTU:2000 Metric:1
2064 RX packets:246134 errors:0 dropped:0 overruns:0 frame:0
2065 TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
2066 collisions:0 txqueuelen:100
2067
2068 if the device doesn't say up
2069 try
2070 /etc/rc.d/init.d/network start
2071 ( this starts the network stack & hopefully calls ifconfig tr0 up ).
2072 ifconfig looks at the output of /proc/net/dev and presents it in a more
2073 presentable form.
2074 Now ping the device from a machine in the same subnet.
2075 if the RX packets count & TX packets counts don't increment you probably
2076 have problems.
2077 next
2078 cat /proc/net/arp
2079 Do you see any hardware addresses in the cache if not you may have problems.
2080 Next try
2081 ping -c 5 <broadcast_addr> i.e. the Bcast field above in the output of
2082 ifconfig. Do you see any replies from machines other than the local machine
2083 if not you may have problems. also if the TX packets count in ifconfig
2084 hasn't incremented either you have serious problems in your driver
2085 (e.g. the txbusy field of the network device being stuck on )
2086 or you may have multiple network devices connected.
2087
2088
2089 chandev
2090 -------
2091 There is a new device layer for channel devices, some
2092 drivers e.g. lcs are registered with this layer.
2093 If the device uses the channel device layer you'll be
2094 able to find what interrupts it uses & the current state
2095 of the device.
2096 See the manpage chandev.8 &type cat /proc/chandev for more info.
2097
2098
2099
2100 Starting points for debugging scripting languages etc.
2101 ======================================================
2102
2103 bash/sh
2104
2105 bash -x <scriptname>
2106 e.g. bash -x /usr/bin/bashbug
2107 displays the following lines as it executes them.
2108 + MACHINE=i586
2109 + OS=linux-gnu
2110 + CC=gcc
2111 + CFLAGS= -DPROGRAM='bash' -DHOSTTYPE='i586' -DOSTYPE='linux-gnu' -DMACHTYPE='i586-pc-linux-gnu' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./lib -O2 -pipe
2112 + RELEASE=2.01
2113 + PATCHLEVEL=1
2114 + RELSTATUS=release
2115 + MACHTYPE=i586-pc-linux-gnu
2116
2117 perl -d <scriptname> runs the perlscript in a fully interactive debugger
2118 <like gdb>.
2119 Type 'h' in the debugger for help.
2120
2121 for debugging java type
2122 jdb <filename> another fully interactive gdb style debugger.
2123 & type ? in the debugger for help.
2124
2125
2126
2127 SysRq
2128 =====
2129 This is now supported by linux for s/390 & z/Architecture.
2130 To enable it do compile the kernel with
2131 Kernel Hacking -> Magic SysRq Key Enabled
2132 echo "1" > /proc/sys/kernel/sysrq
2133 also type
2134 echo "8" >/proc/sys/kernel/printk
2135 To make printk output go to console.
2136 On 390 all commands are prefixed with
2137 ^-
2138 e.g.
2139 ^-t will show tasks.
2140 ^-? or some unknown command will display help.
2141 The sysrq key reading is very picky ( I have to type the keys in an
2142 xterm session & paste them into the x3270 console )
2143 & it may be wise to predefine the keys as described in the VM hints above
2144
2145 This is particularly useful for syncing disks unmounting & rebooting
2146 if the machine gets partially hung.
2147
2148 Read Documentation/sysrq.txt for more info
2149
2150 References:
2151 ===========
2152 Enterprise Systems Architecture Reference Summary
2153 Enterprise Systems Architecture Principles of Operation
2154 Hartmut Penners s390 stack frame sheet.
2155 IBM Mainframe Channel Attachment a technology brief from a CISCO webpage
2156 Various bits of man & info pages of Linux.
2157 Linux & GDB source.
2158 Various info & man pages.
2159 CMS Help on tracing commands.
2160 Linux for s/390 Elf Application Binary Interface
2161 Linux for z/Series Elf Application Binary Interface ( Both Highly Recommended )
2162 z/Architecture Principles of Operation SA22-7832-00
2163 Enterprise Systems Architecture/390 Reference Summary SA22-7209-01 & the
2164 Enterprise Systems Architecture/390 Principles of Operation SA22-7201-05
2165
2166 Special Thanks
2167 ==============
2168 Special thanks to Neale Ferguson who maintains a much
2169 prettier HTML version of this page at
2170 http://linuxvm.org/penguinvm/
2171 Bob Grainger Stefan Bader & others for reporting bugs
This page took 0.074986 seconds and 4 git commands to generate.