linux-old/Documentation/Debugging390.txt
<<
>>
Prefs
   1              
   2                          Debugging on Linux for 390
   3                                       by
   4                Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
   5                Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation           
   6                              Best viewed with fixed width fonts 
   7
   8Overview of Document:
   9=====================
  10This document is intended to give an good overview of how to debug 
  11Linux for S390 it isn't intended as a complete reference & not a
  12tutorial on the fundamentals of C & assembly, it dosen't go into
  13390 IO in any detail. It is intended to compliment the following
  14books.
  15Enterprise Systems Architecture/390 Reference Summary SA22-7209-01 & the
  16Enterprise Systems Architecture/390 Principles of Operation SA22-7201-05
  17& any other worthwhile references you get.
  18
  19It is intended like the Enterprise Systems Architecture/390 Reference Summary
  20to be printed out & used as a quick cheat sheet self help style reference when
  21problems occur.
  22
  23Contents
  24========
  25S390 Register Set
  26Address Spaces on Linux
  27Address Spaces on Linux for S390
  28The Linux for S390 Kernel Task Structure
  29Register Usage & Stackframes on Linux for S390 with glossary
  30Compiling programs for debugging on Linux for S390
  31Figuring out gcc compile errors
  32Debugging Tools
  33objdump
  34strace
  35Debugging under VM
  36Stack Tracing under VM
  37S390 IO Overview
  38Debugging IO on S390 under VM
  39GDB on S390
  40Stack chaining in gdb by hand
  41Examining core dumps
  42LDD
  43Debugging modules
  44The proc file system
  45Starting points for debugging scripting languages etc.
  46
  47S390 Register Set
  48================
  49The current ESA 390 architecture has the following registers.
  50 
  5116 32 bit General propose registers ( r0-r15 or gpr0-gpr15) used for arithmetic & addressing 
  52
  5316 Control registers ( cr0-cr15 kernel usage only ) used for memory managment,
  54interrupt control,debugging control etc.
  55
  5616 Access registers ( ar0-ar15 ) not used by normal programs but potentially could 
  57be used as temporary storage. Their main purpose is their 1 to 1
  58association with general purpose registers and are used in
  59the kernel for copying data between address spaces.
  60
  6116 64 bit floating point registers (fp0-fp15 ) IEEE & HFP floating 
  62point format compliant on G5 upwards & a Floating point control reg (FPC) 
  634  64 bit registers (fp0,fp2,fp4 & fp6) HFP only on older machines.
  64Note:
  65Linux (currently) always uses IEEE & emulates G5 IEEE format on older machines,
  66( provided the kernel is configured for this ).
  67
  68
  69The PSW is the most important register on the machine it
  70is 64 bit & serves the roles of a program counter (pc),
  71condition code register,memory space designator.
  72In IBM standard notation I am counting bit 0 as the MSB.
  73It has several advantages over a normal program counter
  74in that you can change address translation & program counter 
  75in a single instruction. To change address translation,
  76e.g. switching address translation off requires that you
  77have a logical=physical mapping for the address you are
  78currently running at.
  79
  80Bit       Value
  81
  820         Reserved ( must be 0 ) otherwise specification exception occurs.
  83
  841         Program Event Recording 1 PER enabled, 
  85          PER is used to facilititate debugging e.g. single stepping.
  86
  872-4       Reserved ( must be 0 ). 
  88
  895         Dynamic address translation 1=DAT on.
  90
  916         Input/Output interrupt Mask
  92
  937         External interrupt Mask used primarily for interprocessor signalling & 
  94          clock interupts.
  95
  968-12      PSW Key used for complex memory protection mechanism not used under linux
  97
  9813        Machine Check Mask 1=enable machine check interrupts
  99
 10014        Wait State set this to 1 to stop the processor except for interrupts & give 
 101          time to other LPARS used in CPU idle in the kernel to increase overall 
 102          usage of processor resources.
 103
 10415        Problem state ( if set to 1 certain instructions are disabled )
 105          all linux user programs run with this bit 1 ( useful info for debugging under VM ).
 106
 10716-17     Address Space Control
 108
 109          00 Primary Space Mode when DAT on
 110          The linux kernel currently runs in this mode, CR1 is affiliated with this mode
 111          & points to the primary segment table origin etc.
 112
 113          01 Access register mode this mode is used in functions to 
 114          copy data between kernel & user space.
 115
 116          10 Secondary space mode not used in linux however CR7 the
 117          register affiliated with this mode is & this & normally
 118          CR13=CR7 to allow us to copy data between kernel & user space.
 119          We do this as follows:
 120          We set ar2 to 0 to designate its
 121          affiliated gpr ( gpr2 )to point to primary=kernel space.
 122          We set ar4 to 1 to designate its
 123          affiliated gpr ( gpr4 ) to point to secondary=home=user space
 124          & then essentially do a memcopy(gpr2,gpr4,size) to
 125          copy data between the address spaces, the reason we use home space for the
 126          kernel & don't keep secondary space free is that code will not run in secondary space.
 127
 128          11 Home Space Mode all user programs run in this mode.
 129          it is affiliated with CR13.
 130
 13118-19     Condition codes (CC)
 132
 13320        Fixed point overflow mask if 1=FPU exceptions for this event occur ( normally 0 ) 
 134
 13521        Decimal overflow mask if 1=FPU exceptions for this event occur ( normally 0 )
 136
 13722        Exponent underflow mask if 1=FPU exceptions for this event occur ( normally 0 )
 138
 13923        Significance Mask if 1=FPU exceptions for this event occur ( normally 0 )
 140
 14124-31     Reserved Must be 0.
 142
 14332        1=31 bit addressing mode 0=24 bit addressing mode (for backward compatibility ),
 144          linux always runs with this bit set to 1
 145
 14633-64     Instruction address.    
 147          
 148Prefix Page
 149-----------       
 150This per cpu memory area is too intimately tied to the processor not to mention.
 151It exists between the real addresses 0-4096 on the processor & is exchanged 
 152with a page in absolute storage by the set prefix instruction in linux'es startup. 
 153This page different on each processor.
 154Bytes 0-512 ( 200 hex ) are used by the processor itself for holding such
 155information as exception indications & entry points for exceptions.
 156Bytes after 0xc00 hex are used by linux for per processor globals.
 157The closest thing to this on traditional architectures is the interrupt
 158vector table. This is a good thing & does simplify some of the kernel coding
 159however it means that we now cannot catch stray NULL pointers in the
 160kernel without hard coded checks.
 161
 162
 163
 164Address Spaces on Linux
 165=======================
 166
 167The traditional Intel Linux is approximately mapped as follows forgive
 168the ascii art.
 1690xFFFFFFFF 4GB Himem                        *****************
 170                                            *               *
 171                                            * Kernel Space  *
 172                                            *               *
 173                                            *****************          ****************
 174User Space Himem (typically 0xC0000000 3GB )*  User Stack   *          *              *
 175                                            *****************          *              *
 176                                            *  Shared Libs  *          * Next Process *          
 177                                            *****************          *     to       *  
 178                                            *               *    <==   *     Run      *  <==
 179                                            *  User Program *          *              *
 180                                            *   Data BSS    *          *              *
 181                                            *    Text       *          *              *
 182                                            *   Sections    *          *              *
 1830x00000000                                  *****************          ****************
 184
 185Now it is easy to see that on Intel it is quite easy to recognise a kernel address 
 186as being one greater than user space himem ( in this case 0xC0000000).
 187& addresses of less than this are the ones in the current running program on this
 188processor ( if an smp box ).
 189If using the virtual machine ( VM ) as a debugger it is quite difficult to
 190know which user process is running as the address space you are looking at
 191could be from any process in the run queue.
 192Thankfully you normally get lucky as address spaces don't overlap that &
 193you can recognise the code at by cross referencing with a dump made by objdump
 194( more about that later ).
 195
 196The limitation of Intels addressing technique is that the linux
 197kernel uses a very simple real address to virtual addressing technique
 198of Real Address=Virtual Address-User Space Himem.
 199This means that on Intel the kernel linux can typically only address
 200Himem=0xFFFFFFFF-0xC0000000=1GB & this is all the RAM these machines
 201can typically use.
 202They can lower User Himem to 2GB or lower & thus be
 203able to use 2GB of RAM however this shrinks the maximum size
 204of User Space from 3GB to 2GB they have a no win limit of 4GB unless
 205they go to 64 Bit.
 206
 207
 208On 390 our limitations & strengths make us slightly different.
 209For backward compatibility we are only allowed use 31 bits (2GB)
 210of our 32 bit addresses,however, we use entirely separate address 
 211spaces for the user & kernel.
 212
 213This means we can support 2GB of non Extended RAM, & more
 214with the Extended memory managment swap device & 64 Bit
 215when it comes along.
 216
 217
 218Address Spaces on Linux for S390
 219================================
 220
 221Our addressing scheme is as follows
 222
 223
 224Himem 0x7fffffff 2GB            *****************          ****************
 225                                *  User Stack   *          *              *
 226                                *****************          *              *
 227                                *  Shared Libs  *          *              *          
 228                                *****************          *              *  
 229                                *               *          *    Kernel    *  
 230                                *  User Program *          *              *
 231                                *   Data BSS    *          *              *
 232                                *    Text       *          *              *
 233                                *   Sections    *          *              *
 2340x00000000                      *****************          ****************
 235
 236This also means that we need to look at the PSW problem state bit
 237or the addressing mode to decide whether we are looking at
 238user or kernel space. 
 239
 240The Linux for S390 Kernel Task Structure
 241========================================
 242Each process/thread under Linux for S390 has its own kernel task_struct
 243defined in linux/include/linux/sched.h
 244The S390 on initialisation & resuming of a process on a cpu sets
 245the __LC_KERNEL_STACK variable in the spare prefix area for this cpu
 246( which we use for per processor globals).
 247
 248The kernel stack pointer is intimately tied with the task stucture for
 249each processor as follows.
 250
 251            ************************
 252            *  1 page kernel stack *
 253            *        ( 4K )        *
 254            ************************
 255            *   1 page task_struct *        
 256            *        ( 4K )        *
 2578K aligned  ************************ 
 258
 259What this means is that we don't need to dedicate any register or global variable
 260to point to the current running process & can retrieve it with the following
 261very simple construct
 262
 263static inline struct task_struct * get_current(void)
 264{
 265        struct task_struct *current;
 266        __asm__("lhi   %0,-8192\n\t"
 267                "nr    %0,15"
 268                : "=r" (current) );
 269        return current;
 270}
 271
 272i.e. just anding the current kernel stack pointer with the mask -8192.
 273Thankfully because Linux dosen't have support for nested IO interrupts
 274& our devices have large buffers can survive interrupts being shut for 
 275short amounts of time we don't need a separate stack for interrupts.
 276
 277
 278
 279
 280Register Usage & Stackframes on Linux for S390
 281==============================================
 282Overview:
 283---------
 284This is the code that gcc produces at the top & the bottom of
 285each function, it usually is fairly consistent & similar from 
 286function to function & if you know its layout you can probalby
 287make some headway in finding the ultimate cause of a problem
 288after a crash without a source level debugger.
 289
 290Note: To follow stackframes requires a knowledge of C or Pascal &
 291limited knowledge of one assembly language.
 292
 293Glossary:
 294---------
 295alloca:
 296This is a built in compiler function for runtime allocation
 297of extra space on the callers stack which is obviously freed
 298up on function exit ( e.g. the caller may choose to allocate nothing
 299of a buffer of 4k if required for temporary purposes ), it generates 
 300very efficent code ( a few cycles  ) when compared to alternatives 
 301like malloc.
 302
 303automatics: These are local variables on the stack,
 304i.e they aren't in registers & they aren't static.
 305
 306back-chain:
 307This is a pointer to the stack pointer before entering a
 308framed functions ( see frameless function ) prologue got by 
 309deferencing the address of the current stack pointer,
 310 i.e. got by accessing the 32 bit value at the stack pointers
 311current location.
 312
 313base-pointer:
 314This is a pointer to the back of the literal pool which
 315is an area just behind each procedure used to store constants
 316in each function.
 317
 318call-clobbered: The caller probably needs to save these registers if there 
 319is something of value in them, on the stack or elsewhere before making a 
 320call to another procedure so that it can restore it later.
 321
 322epilogue:
 323The code generated by the compiler to return to the caller.
 324
 325frameless-function
 326A frameless function in Linux for 390 is one which doesn't need 
 327more than the 96 bytes given to it by the caller.
 328A frameless function never:
 3291) Sets up a back chain.
 3302) Calls alloca.
 3313) Calls other normal functions
 3324) Has automatics.
 333
 334GOT-pointer:
 335This is a pointer to the global-offset-table in ELF
 336( Executable Linkable Format, Linux'es most common executable format ),
 337all globals & shared library objects are found using this pointer.
 338
 339lazy-binding
 340ELF shared libraries are typically only loaded when routines in the shared
 341library are actually first called at runtime. This is lazy binding.
 342
 343procedure-linkage-table
 344This is a table found from the GOT which contains pointers to routines
 345in other shared libraries which can't be called to by easier means.
 346
 347prologue:
 348The code generated by the compiler to set up the stack frame.
 349
 350outgoing-args:
 351This is extra area allocated on the stack of the calling function if the
 352parameters for the callee's cannot all be put in registers, the same
 353area can be reused by each function the caller calls.
 354
 355routine-descriptor:
 356A COFF  executable format based concept of a procedure reference 
 357actually being 8 bytes or more as opposed to a simple pointer to the routine.
 358This is typically defined as follows
 359Routine Descriptor offset 0=Pointer to Function
 360Routine Descriptor offset 4=Pointer to Table of Contents
 361The table of contents/TOC is roughly equivalent to a GOT pointer.
 362& it means that shared libraries etc. can be shared between several
 363environments each with their own TOC.
 364
 365 
 366static-chain: This is used in nested functions a concept adopted from pascal 
 367by gcc not used in ansi C or C++ ( although quite useful ), basically it
 368is a pointer used to reference local variables of enclosing functions.
 369You might come across this stuff once or twice in your lifetime.
 370
 371e.g.
 372The function below should return 11 though gcc may get upset & toss warnings 
 373about unused variables.
 374int FunctionA(int a)
 375{
 376        int b;
 377        FunctionC(int c)
 378        {
 379                b=c+1;
 380        }
 381        FunctionC(10);
 382        return(b);
 383}
 384
 385
 386S390 Register usage
 387===================
 388r0       used by syscalls/assembly                  call-clobbered
 389r1       used by syscalls/assembly                  call-clobbered
 390r2       argument 0 / return value 0                call-clobbered
 391r3       argument 1 / return value 1 (if long long) call-clobbered
 392r4       argument 2                                 call-clobbered
 393r5       argument 3                                 call-clobbered
 394r6       argument 5                                 saved
 395r7       pointer-to arguments 5 to ...              saved      
 396r8       this & that                                saved
 397r9       this & that                                saved
 398r10      static-chain ( if nested function )        saved
 399r11      frame-pointer ( if function used alloca )  saved
 400r12      got-pointer                                saved
 401r13      base-pointer                               saved
 402r14      return-address                             saved
 403r15      stack-pointer                              saved
 404
 405f0       argument 0 / return value ( float/double ) call-clobbered
 406f2       argument 1                                 call-clobbered
 407f4                                                  saved
 408f6                                                  saved
 409The remaining floating points
 410f1,f3,f5 f7-f15 are call-clobbered.
 411
 412Notes:
 413------
 4141) The only requirement is that registers which are used
 415by the callee are saved, e.g. the compiler is perfectly
 416capible of using r11 for purposes other than a frame a
 417frame pointer if a frame pointer is not needed.
 4182) In functions with variable arguments e.g. printf the calling procedure 
 419is identical to one without variable arguments & the same number of 
 420parameters. However, the prologue of this function is somewhat more
 421hairy owing to it having to move these parameters to the stack to
 422get va_start, va_arg & va_end to work.
 4233) Access registers are currently unused by gcc but are used in
 424the kernel. Possibilities exist to use them at the moment for
 425temporary storage but it isn't recommended.
 4264) Only 4 of the floating point registers are used for
 427parameter passing as older machines such as G3 only have only 4
 428& it keeps the stack frame compatible with other compilers.
 429However with IEEE floating point emulation under linux on the
 430older machines you are free to use the other 12.
 4315) A long long or double parameter cannot be have the 
 432first 4 bytes in a register & the second four bytes in the 
 433outgoing args area. It must be purely in the outgoing args
 434area if crossing this boundary.
 4356) Floating point parameters are mixed with outgoing args
 436on the outgoing args area in the order the are passed in as parameters.
 437
 438Stack Frame Layout
 439==================
 4400            back chain ( a 0 here signifies end of back chain )
 4414            eos ( end of stack, not used on Linux for S390 used in other linkage formats )
 4428            glue used in other linkage formats for saved routine descriptors etc.
 44312           glue used in other linkage formats for saved routine descriptors etc.
 44416           scratch area
 44520           scratch area
 44624           saved r6 of caller function
 44728           saved r7 of caller function
 44832           saved r8 of caller function
 44936           saved r9 of caller function
 45040           saved r10 of caller function
 45144           saved r11 of caller function
 45248           saved r12 of caller function
 45352           saved r13 of caller function
 45456           saved r14 of caller function
 45560           saved r15 of caller function
 45664           saved f4 of caller function
 45772           saved f6 of caller function
 45880           undefined
 45996           outgoing args passed from caller to callee
 46096+x         possible stack alignment ( 8 bytes desirable )
 46196+x+y       alloca space of caller ( if used )
 46296+x+y+z     automatics of caller ( if used )
 4630            back-chain
 464
 465A sample program with comments.
 466===============================
 467
 468Comments on the function test
 469-----------------------------
 4701) It didn't need to set up a pointer to the constant pool gpr13 as it isn't used
 471( :-( ).
 4722) This is a frameless function & no stack is bought.
 4733) The compiler was clever enough to recognise that it could return the
 474value in r2 as well as use it for the passed in parameter ( :-) ).
 4754) The basr ( branch relative & save ) trick works as follows the instruction 
 476has a special case with r0,r0 with some instruction operands is understood as 
 477the literal value 0, some risc architectures also do this ). So now
 478we are branching to the next address & the address new program counter is
 479in r13,so now we subtract the size of the function prologue we have executed
 480+ the size of the literal pool to get to the top of the literal pool
 4810040037c int test(int b)
 482{                                                          # Function prologue below
 483  40037c:       90 de f0 34     stm     %r13,%r14,52(%r15) # Save registers r13 & r14
 484  400380:       0d d0           basr    %r13,%r0           # Set up pointer to constant pool using
 485  400382:       a7 da ff fa     ahi     %r13,-6            # basr trick
 486        return(5+b);
 487                                                           # Huge main program
 488  400386:       a7 2a 00 05     ahi     %r2,5              # add 5 to r2
 489
 490                                                           # Function epilogue below 
 491  40038a:       98 de f0 34     lm      %r13,%r14,52(%r15) # restore registers r13 & 14
 492  40038e:       07 fe           br      %r14               # return
 493}
 494
 495Comments on the function main
 496-----------------------------
 4971) The compiler did this function optimally ( 8-) )
 498
 499Literal pool for main.
 500400390: ff ff ff ec     .long 0xffffffec
 501main(int argc,char *argv[])
 502{                                                          # Function prologue below
 503  400394:       90 bf f0 2c     stm     %r11,%r15,44(%r15) # Save necessary registers
 504  400398:       18 0f           lr      %r0,%r15           # copy stack pointer to r0
 505  40039a:       a7 fa ff a0     ahi     %r15,-96           # Make area for callee saving 
 506  40039e:       0d d0           basr    %r13,%r0           # Set up r13 to point to
 507  4003a0:       a7 da ff f0     ahi     %r13,-16           # literal pool
 508  4003a4:       50 00 f0 00     st      %r0,0(%r15)        # Save backchain
 509
 510        return(test(5));                                   # Main Program Below
 511  4003a8:       58 e0 d0 00     l       %r14,0(%r13)       # load relative address of test from
 512                                                           # literal pool
 513  4003ac:       a7 28 00 05     lhi     %r2,5              # Set first parameter to 5
 514  4003b0:       4d ee d0 00     bas     %r14,0(%r14,%r13)  # jump to test setting r14 as return
 515                                                           # address using branch & save instruction.
 516
 517                                                           # Function Epilogue below
 518  4003b4:       98 bf f0 8c     lm      %r11,%r15,140(%r15)# Restore necessary registers.
 519  4003b8:       07 fe           br      %r14               # return to do program exit 
 520}
 521
 522
 523Compiling programs for debugging on Linux for S390
 524==================================================
 525Make sure that the gcc is compiling & linking with the -g flag on.
 526This is typically done adding/appending the flags -g to the 
 527CFLAGS & LDFLAGS variables Makefile of the program concerned.
 528
 529If using gdb & you would like accurate displays of registers &
 530 stack traces compile without optimisation i.e make sure
 531that there is no -O2 or similar on the CFLAGS line of the Makefile &
 532the emitted gcc commands, obviously this will produce worse code 
 533( not advisable for shipment ) but it is an  aid to the debugging process.
 534
 535This aids debugging because the compiler will copy parameters passed in
 536in registers onto the stack so backtracing & looking at passed in
 537parameters will work, however some larger programs which use inline functions
 538will not compile without optimisation.
 539
 540Figuring out gcc compile errors
 541===============================
 542If you are getting a lot of syntax errors compiling a program & the problem
 543isn't blatantly obvious from the source.
 544It often helps to just preprocess the file, this is done with the -E
 545option in gcc.
 546What this does is that it runs through the very first phase of compilation
 547( compilation in gcc is done in several stages & gcc calls many programs to
 548achieve its end result ) with the -E option gcc just calls the gcc preprocessor (cpp).
 549The c preprocessor does the following, it joins all the files #included together
 550recursively ( #include files can #include other files ) & also the c file you wish to compile.
 551It puts a fully qualified path of the #included files in a comment & it
 552does macro expansion.
 553This is useful for debugging because
 5541) You can double check whether the files you expect to be included are the ones
 555that are being included ( e.g. double check that you aren't going to the i386 asm directory ).
 5562) Check that macro definitions aren't clashing with typedefs,
 5573) Check that definitons aren't being used before they are being included.
 5584) Helps put the line emitting the error under the microscope if it contains macros.
 559
 560For convenience the Linux kernel's makefile will do preprocessing automatically for you
 561by suffixing the file you want built with .i ( instead of .o )
 562
 563e.g.
 564from the linux directory type
 565make arch/s390/kernel/signal.i
 566this will build
 567
 568s390-gcc -D__KERNEL__ -I/home1/barrow/linux/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
 569-fno-strict-aliasing -D__SMP__ -pipe -fno-strength-reduce   -E arch/s390/kernel/signal.c
 570> arch/s390/kernel/signal.i  
 571
 572Now look at signal.i you should see something like.
 573
 574
 575# 1 "/home1/barrow/linux/include/asm/types.h" 1
 576typedef unsigned short umode_t;
 577typedef __signed__ char __s8;
 578typedef unsigned char __u8;
 579typedef __signed__ short __s16;
 580typedef unsigned short __u16;
 581
 582If instead you are getting errors further down e.g.
 583unknown instruction:2515 "move.l" or better still unknown instruction:2515 
 584"Fixme not implemented yet, call Martin" you are probably are attempting to compile some code 
 585meant for another architecture or code that is simply not implemented, with a fixme statement
 586stuck into the inline assembly code so that the author of the file now knows he has work to do.
 587To look at the assembly emitted by gcc just before it is about to call gas ( the gnu assembler )
 588use the -S option.
 589Again for your convenience the Linux kernel's Makefile will hold your hand &
 590do all this donkey work for you also by building the file with the .s suffix.
 591e.g.
 592from the Linux directory type 
 593make arch/s390/kernel/signal.s 
 594
 595s390-gcc -D__KERNEL__ -I/home1/barrow/linux/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
 596-fno-strict-aliasing -D__SMP__ -pipe -fno-strength-reduce  -S arch/s390/kernel/signal.c 
 597-o arch/s390/kernel/signal.s  
 598
 599
 600This will output something like, ( please note the constant pool & the useful comments
 601in the prologue to give you a hand at interpreting it ).
 602
 603.LC54:
 604        .string "misaligned (__u16 *) in __xchg\n"
 605.LC57:
 606        .string "misaligned (__u32 *) in __xchg\n"
 607.L$PG1: # Pool sys_sigsuspend
 608.LC192:
 609        .long   -262401
 610.LC193:
 611        .long   -1
 612.LC194:
 613        .long   schedule-.L$PG1
 614.LC195:
 615        .long   do_signal-.L$PG1
 616        .align 4
 617.globl sys_sigsuspend
 618        .type    sys_sigsuspend,@function
 619sys_sigsuspend:
 620#       leaf function           0
 621#       automatics              16
 622#       outgoing args           0
 623#       need frame pointer      0
 624#       call alloca             0
 625#       has varargs             0
 626#       incoming args (stack)   0
 627#       function length         168
 628        STM     8,15,32(15)
 629        LR      0,15
 630        AHI     15,-112
 631        BASR    13,0
 632.L$CO1: AHI     13,.L$PG1-.L$CO1
 633        ST      0,0(15)
 634        LR    8,2
 635        N     5,.LC192-.L$PG1(13) 
 636
 637Debugging Tools:
 638================
 639
 640objdump
 641=======
 642This is a tool with many options the most useful being ( if compiled with -g).
 643objdump --source <victim program or object file> > <victims debug listing >
 644
 645
 646The whole kernel can be compiled like this ( Doing this will make a 17MB kernel
 647& a 200 MB listing ) however you have to strip it before building the image
 648using the strip command to make it a more reasonable size to boot it.
 649
 650A source/assembly mixed dump of the kernel can be done with the line
 651objdump --source vmlinux > vmlinux.lst
 652Also if the file isn't compiled -g this will output as much debugging information
 653as it can ( e.g. function names ), however, this is very slow as it spends lots
 654of time searching for debugging info, the following self explanitory line should be used 
 655instead if the code isn't compiled -g.
 656objdump --disassemble-all --syms vmlinux > vmlinux.lst  
 657as it is much faster
 658
 659As hard drive space is valuble most of us use the following approach.
 6601) Look at the emitted psw on the console to find the crash address in the kernel.
 6612) Look at the file System.map ( in the linux directory ) produced when building 
 662the kernel to find the closest address less than the current PSW to find the
 663offending function.
 6643) use grep or similar to search the source tree looking for the source file
 665 with this function if you don't know where it is.
 6664) rebuild this object file with -g on, as an example suppose the file was
 667( /arch/s390/kernel/signal.o ) 
 6685) Assuming the file with the erroneous function is signal.c Move to the base of the 
 669Linux source tree
 6706) rm /arch/s390/kernel/signal.o
 6717) make /arch/s390/kernel/signal.o
 6728) watch the gcc command line emitted
 6739) type it in again or alernatively cut & paste it on the console adding the -g option.
 67410) objdump --source arch/s390/kernel/signal.o > signal.lst
 675This will output the source & the assembly intermixed, as the snippet below shows
 676This will unfortunately output addresses which aren't the same
 677as the kernel ones you should be able to get around the mental arithmetic
 678by playing with the --adjust-vma parameter to objdump.
 679
 680extern inline void spin_lock(spinlock_t *lp)
 681{
 682      a0:       18 34           lr      %r3,%r4
 683      a2:       a7 3a 03 bc     ahi     %r3,956
 684        __asm__ __volatile("    lhi   1,-1\n"
 685      a6:       a7 18 ff ff     lhi     %r1,-1
 686      aa:       1f 00           slr     %r0,%r0
 687      ac:       ba 01 30 00     cs      %r0,%r1,0(%r3)
 688      b0:       a7 44 ff fd     jm      aa <sys_sigsuspend+0x2e>
 689        saveset = current->blocked;
 690      b4:       d2 07 f0 68     mvc     104(8,%r15),972(%r4)
 691      b8:       43 cc
 692        return (set->sig[0] & mask) != 0;
 693} 
 694
 6956) If debugging under VM go down to that section in the document for more info.
 696
 697
 698strace:
 699-------
 700Q. What is it ?
 701A. It is a tool for intercepting calls to the kernel & logging them
 702to a file & on the screen.
 703
 704Q. What use is it ?
 705A. You can used it to find out what files a particular program opens.
 706
 707
 708
 709Example 1
 710---------
 711If you wanted to know does ping work but didn't have the source 
 712strace ping -c 1 127.0.0.1  
 713& then look at the man pages for each of the syscalls below,
 714( In fact this is sometimes easier than looking at some spagetti
 715source which conditionally compiles for several architectures )
 716Not everything that it throws out needs to make sense immeadiately
 717
 718Just looking quickly you can see that it is making up a RAW socket
 719for the ICMP protocol.
 720Doing an alarm(10) for a 10 second timeout
 721& doing a gettimeofday call before & after each read to see 
 722how long the replies took, & writing some text to stdout so the user
 723has an idea what is going on.
 724
 725socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = 3
 726getuid()                                = 0
 727setuid(0)                               = 0
 728stat("/usr/share/locale/C/libc.cat", 0xbffff134) = -1 ENOENT (No such file or directory)
 729stat("/usr/share/locale/libc/C", 0xbffff134) = -1 ENOENT (No such file or directory)
 730stat("/usr/local/share/locale/C/libc.cat", 0xbffff134) = -1 ENOENT (No such file or directory)
 731getpid()                                = 353
 732setsockopt(3, SOL_SOCKET, SO_BROADCAST, [1], 4) = 0
 733setsockopt(3, SOL_SOCKET, SO_RCVBUF, [49152], 4) = 0
 734fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(3, 1), ...}) = 0
 735mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40008000
 736ioctl(1, TCGETS, {B9600 opost isig icanon echo ...}) = 0
 737write(1, "PING 127.0.0.1 (127.0.0.1): 56 d"..., 42PING 127.0.0.1 (127.0.0.1): 56 data bytes
 738) = 42
 739sigaction(SIGINT, {0x8049ba0, [], SA_RESTART}, {SIG_DFL}) = 0 
 740sigaction(SIGALRM, {0x8049600, [], SA_RESTART}, {SIG_DFL}) = 0
 741gettimeofday({948904719, 138951}, NULL) = 0
 742sendto(3, "\10\0D\201a\1\0\0\17#\2178\307\36"..., 64, 0, {sin_family=AF_INET,
 743sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")}, 16) = 64
 744sigaction(SIGALRM, {0x8049600, [], SA_RESTART}, {0x8049600, [], SA_RESTART}) = 0
 745sigaction(SIGALRM, {0x8049ba0, [], SA_RESTART}, {0x8049600, [], SA_RESTART}) = 0
 746alarm(10)                               = 0
 747recvfrom(3, "E\0\0T\0005\0\0@\1|r\177\0\0\1\177"..., 192, 0, 
 748{sin_family=AF_INET, sin_port=htons(50882), sin_addr=inet_addr("127.0.0.1")}, [16]) = 84
 749gettimeofday({948904719, 160224}, NULL) = 0
 750recvfrom(3, "E\0\0T\0006\0\0\377\1\275p\177\0"..., 192, 0, 
 751{sin_family=AF_INET, sin_port=htons(50882), sin_addr=inet_addr("127.0.0.1")}, [16]) = 84
 752gettimeofday({948904719, 166952}, NULL) = 0
 753write(1, "64 bytes from 127.0.0.1: icmp_se"..., 
 7545764 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=28.0 ms
 755
 756Example 2
 757---------
 758strace passwd 2>&1 | grep open
 759produces the following output
 760open("/etc/ld.so.cache", O_RDONLY)      = 3
 761open("/opt/kde/lib/libc.so.5", O_RDONLY) = -1 ENOENT (No such file or directory)
 762open("/lib/libc.so.5", O_RDONLY)        = 3
 763open("/dev", O_RDONLY)                  = 3
 764open("/var/run/utmp", O_RDONLY)         = 3
 765open("/etc/passwd", O_RDONLY)           = 3
 766open("/etc/shadow", O_RDONLY)           = 3
 767open("/etc/login.defs", O_RDONLY)       = 4
 768open("/dev/tty", O_RDONLY)              = 4 
 769
 770The 2>&1 is done to redirect stderr to stdout & grep is then filtering this input 
 771through the pipe for each line containing the string open.
 772
 773
 774Example 3
 775---------
 776Getting sophistocated
 777telnetd crashes on & I don't know why
 778Steps
 779-----
 7801) Replace the following line in /etc/inetd.conf
 781telnet  stream  tcp     nowait  root    /usr/sbin/in.telnetd -h 
 782with
 783telnet  stream  tcp     nowait  root    /blah
 784
 7852) Create the file /blah with the following contents to start tracing telnetd 
 786#!/bin/bash
 787/usr/bin/strace -o/t1 -f /usr/sbin/in.telnetd -h 
 7883) chmod 700 /blah to make it executable only to root
 7894)
 790killall -HUP inetd
 791or ps aux | grep inetd
 792get inetd's process id
 793& kill -HUP inetd to restart it.
 794
 795Important options
 796-----------------
 797-o is used to tell strace to output to a file in our case t1 in the root directory
 798-f is to follow children i.e.
 799e.g in our case above telnetd will start the login process & subsequently a shell like bash.
 800You will be able to tell which is which from the process ID's listed on the left hand side
 801of the strace output.
 802-p<pid> will tell strace to attach to a running process, yup this can be done provided
 803 it isn't being traced or debugged already & you have enough privileges,
 804the reason 2 processes cannot trace or debug the same program is that strace
 805becomes the parent process of the one being debugged & processes ( unlike people )
 806can have only one parent.
 807
 808
 809However the file /t1 will get big quite quickly
 810to test it telnet 127.0.0.1
 811
 812now look at what files in.telnetd execve'd
 813413   execve("/usr/sbin/in.telnetd", ["/usr/sbin/in.telnetd", "-h"], [/* 17 vars */]) = 0
 814414   execve("/bin/login", ["/bin/login", "-h", "localhost", "-p"], [/* 2 vars */]) = 0 
 815
 816Whey it worked!.
 817
 818
 819Other hints:
 820------------
 821If the program is not very interactive ( i.e. not much keyboard input )
 822& is crashing in one architecture but not in another you can do 
 823an strace of both programs under as identical a scenario as you can
 824on both architectures outputting to a file then.
 825do a diff of the two traces using the diff program
 826i.e.
 827diff output1 output2
 828& maybe you'll be able to see where the call paths differed, this
 829is possibly near the cause of the crash. 
 830
 831More info
 832---------
 833Look at man pages for strace & the various syscalls
 834e.g. man strace, man alarm, man socket.
 835
 836
 837Debugging under VM
 838==================
 839
 840Notes
 841-----
 842Addresses & values in the VM debugger are always hex never decimal
 843Address ranges are of the format <HexValue1>-<HexValue2> or <HexValue1>.<HexValue2> 
 844e.g. The address range  0x2000 to 0x3000 can be described described as
 8452000-3000 or 2000.1000
 846
 847The VM Debugger is case insensitive.
 848
 849VM's strengths are usually other debuggers weaknesses you can get at any resource
 850no matter how sensitive e.g. memory managment resources,change address translation
 851in the PSW. For kernel hacking you will reap dividends if you get good at it.
 852
 853The VM Debugger displays operators but not operands, probably because some
 854of it was written when memory was expensive & the programmer was probably proud that
 855it fitted into 2k of memory & the programmers & didn't want to shock hardcore VM'ers by
 856changing the interface :-), also the debugger displays useful information on the same line & 
 857the author of the code probably felt that it was a good idea not to go over 
 858the 80 columns on the screen. 
 859
 860As some of you are probably in a panic now this isn't as unintuitive as it may seem
 861as the 390 instructions are easy to decode mentally & you can make a good guess at a lot 
 862of them as all the operands are nibble ( half byte aligned ) & if you have an objdump listing
 863also it is quite easy to follow, if you don't have an objdump listing keep a copy of
 864the ESA Reference Summary & look at between pages 2 & 7 or alternatively the
 865ESA principles of operation.
 866e.g. even I can guess that 
 8670001AFF8' LR    180F        CC 0
 868is a ( load register ) lr r0,r15 
 869
 870Also it is very easy to tell the length of a 390 instruction from the 2 most significant
 871bits in the instruction ( not that this info is really useful except if you are trying to
 872make sense of a hexdump of code ).
 873Here is a table
 874Bits                    Instruction Length
 875------------------------------------------
 87600                          2 Bytes
 87701                          4 Bytes
 87810                          4 Bytes
 87911                          6 Bytes
 880
 881
 882
 883
 884The debugger also displays other useful info on the same line such as the
 885addresses being operated on destination addresses of branches & condition codes.
 886e.g.  
 88700019736' AHI   A7DAFF0E    CC 1
 888000198BA' BRC   A7840004 -> 000198C2'   CC 0
 889000198CE' STM   900EF068 >> 0FA95E78    CC 2
 890
 891
 892
 893Useful VM debugger commands
 894===========================
 895
 896I suppose I'd better mention this before I start
 897to list the current active traces do 
 898Q TR
 899there can be a maximum of 255 of these per set
 900( more about trace sets later ).
 901To stop traces issue a
 902TR END.
 903To delete a particular breakpoint issue
 904TR DEL <breakpoint number>
 905
 906The PA1 key drops to CP mode so you can issue debugger commands,
 907Doing alt c (on my 3270 console at least ) clears the screen. 
 908hitting b <enter> comes back to the running operating system
 909from cp mode ( in our case linux ).
 910It is typically useful to add shortcuts to your profile.exec file
 911if you have one ( this is roughly equivalent to autoexec.bat in DOS ).
 912file here are a few from mine.
 913/* this gives me command history on issuing f12 */
 914set pf12 retrieve 
 915/* this continues */
 916set pf8 imm b
 917/* goes to trace set a */
 918set pf1 imm tr goto a
 919/* goes to trace set b */
 920set pf2 imm tr goto b
 921/* goes to trace set c */
 922set pf3 imm tr goto c
 923
 924
 925
 926Instruction Tracing
 927-------------------
 928Setting a simple breakpoint
 929TR I PSWA <address>
 930To debug a particular function try
 931TR I R <function address range>
 932TR I on its own will single step.
 933TR I DATA <MNEMONIC> <OPTIONAL RANGE> will trace for particular mnemonics
 934e.g.
 935TR I DATA 4D R 0197BC.4000
 936will trace for BAS'es ( opcode 4D ) in the range 0197BC.4000
 937if you were inclined you could add traces for all branch instructions &
 938suffix them with the run prefix so you would have a backtrace on screen 
 939when a program crashes.
 940TR BR <INTO OR FROM> will trace branches into or out of an address.
 941e.g.
 942TR BR INTO 0 is often quite useful if a program is getting awkward & deciding
 943to branch to 0 & crashing as this will stop at the address before in jumps to 0.
 944
 945
 946
 947Displaying & modifying Registers
 948--------------------------------
 949D G will display all the gprs
 950D X will display all the control registers
 951D AR will display all the access registers
 952D AR4-7 will display access registers 4 to 7
 953CPU ALL D G will display the GRPS of all CPUS in the configuration
 954D PSW will display the current PSW
 955st PSW 2000 will put the value 2000 into the PSW &
 956cause crash your machine.
 957D PREFIX
 958
 959
 960Displaying Memory
 961-----------------
 962To display memory mapped using the current PSW's mapping try
 963D <range>
 964To make VM display a message each time it hits a particular address & continue try
 965D I<range> will disassemble/display a range of instructions.
 966ST addr 32 bit word will store a 32 bit aligned address
 967D T<range> will display the EBCDIC in an address ( if you are that way inclined )
 968D R<range> will display real addresses ( without DAT ) but with prefixing.
 969There are other complex options to display if you need to get at say home space
 970but are in primary space the easiest thing to do is to temporarily
 971modify the PSW to the other addressing mode, display the stuff & then
 972restore it. 
 973 
 974Hints
 975-----
 976If you want to issue a debugger command without halting your virtual machine with the
 977PA1 key try prefixing the command with #CP e.g.
 978#cp tr i pswa 2000
 979also suffixing most debugger commands with RUN will cause them not
 980to stop just display the mnemonic at the current instruction on the console.
 981If you have several breakpoints you want to put into your program &
 982you get fed up of cross referencing with System.map
 983you can do the following trick for several symbols.
 984grep do_signal System.map 
 985which emits the following among other things
 9860001f4e0 T do_signal 
 987now you can do
 988TR I PSWA 0001f4e0 cmd msg * do_signal
 989This sends a message to your own console each time do_signal is entered.
 990( As an aside I wrote a perl script once which automatically generated a REXX
 991script with breakpoints on every kernel procedure, this isn't a good idea
 992because there are thousands of these routines & VM can only set 255 breakpoints
 993at a time so you nearly had to spend as long pruning the file down as you would 
 994entering the msg's by hand ),however, the trick might be useful for a single object file.
 995
 996
 997Tracing Program Exceptions
 998--------------------------
 999If you get a crash which says something like
1000illegal operation or specification exception followed by a register dump
1001You can restart linux & trace these using the tr prog <range or value> trace option.
1002
1003The most common ones you will normally be tracing for is
10041=operation exception
10052=privileged operation exception
10064=protection exception
10075=addressing exception
10086=specification exception
100910=segment translation exception
101011=page translation exception
1011
1012The full list of these is on page 22 of the current ESA Reference Summary.
1013e.g.
1014tr prog 10 will trace segment translation exceptions.
1015tr prog on its own will trace all program interruption codes.
1016
1017Trace Sets
1018----------
1019On starting VM you are initially in the INITIAL trace set.
1020You can do a Q TR to verify this.
1021If you have a complex tracing situation where you wish to wait for instance 
1022till a driver is open before you start tracing IO, but know in your
1023heart that you are going to have to make several runs through the code till you
1024have a clue whats going on. 
1025
1026What you can do is
1027TR I PSWA <Driver open address>
1028hit b to continue till breakpoint
1029reach the breakpoint
1030now do your
1031TR GOTO B 
1032TR IO 7c08-7c09 or whatever & trace tour IO
1033to got back to the initial trace set do
1034TR GOTO INITIAL
1035& the TR I PSWA <Driver open address> will be the only active breakpoint again.
1036
1037
1038Tracing linux syscalls under VM
1039-------------------------------
1040Syscalls are implemented on Linux for S390 by the Supervisor call instruction (SVC) there 256 
1041possibilities of these as the instruction is made up of a  0xA opcode & the second byte being
1042the syscall number. They are traced using the simple command.
1043TR SVC  <Optional value or range>
1044the syscalls are defined in linux/include/asm-s390/unistd.h
1045e.g. to trace all file opens just do
1046TR SVC 5 ( as this is the syscall number of open )
1047
1048
1049SMP Specific commands
1050---------------------
1051To find out how many cpus you have
1052Q CPUS displays all the CPU's available to your virtual machine
1053To find the cpu that the current cpu VM debugger commands are being directed at do
1054Q CPU to change the current cpu cpu VM debugger commands are being directed at do
1055CPU <desired cpu no>
1056
1057On a SMP guest issue a command to all CPUs try prefixing the command with cpu all.
1058To issue a command to a particular cpu try cpu <cpu number> e.g.
1059CPU 01 TR I R 2000.3000
1060If you are running on a guest with several cpus & you have a IO related problem
1061& cannot follow the flow of code but you know it isnt smp related.
1062from the bash prompt issue
1063shutdown -h now or halt.
1064do a Q CPUS to find out how many cpus you have
1065detach each one of them from cp except cpu 0 
1066by issueing a 
1067DETACH CPU 01-(number of cpus in configuration)
1068& reboot linux.
1069TR SIGP will trace inter processor signal processor instructions.
1070
1071
1072Help for displaying ascii textstrings
1073-------------------------------------
1074As textstrings are cannot be displayed in ASCII under the VM debugger ( I love EBDIC too ) I have 
1075written this little program which will convert a command line of hex digits to ascii text
1076which can be compiled under linux & you can copy the hex digits from your x3270 terminal to
1077your xterm if you are debugging from a linuxbox.
1078
1079This is quite useful when looking at a parameter passed in as a text string
1080under VM ( unless you are good at decoding ASCII in your head ).
1081
1082e.g. consider tracing an open syscall
1083TR SVC 5
1084We have stopped at a breakpoint
1085000151B0' SVC   0A05     -> 0001909A'   CC 0
1086
1087D 20.8 to check the SVC old psw in the prefix area & see was it from userspace
1088( for the layout of the prefix area consult P18 of the ESA 390 Reference Summary 
1089if you have it available ).
1090V00000020  070C2000 800151B2
1091The problem state bit wasn't set &  it's also too early in the boot sequence
1092for it to be a userspace SVC if it was we would have to temporarily switch the 
1093psw to user space addressing so we could get at the first parameter of the open in
1094gpr2.
1095Next do a 
1096D G2
1097GPR  2 =  00014CB4
1098Now display what gpr2 is pointing to
1099D 00014CB4.20
1100V00014CB4  2F646576 2F636F6E 736F6C65 00001BF5
1101V00014CC4  FC00014C B4001001 E0001000 B8070707
1102Now copy the text till the first 00 hex ( which is the end of the string
1103to an xterm & do hex2ascii on it.
1104hex2ascii 2F646576 2F636F6E 736F6C65 00 
1105outputs
1106Decoded Hex:=/ d e v / c o n s o l e 0x00 
1107We were opening the console device,
1108
1109You can compile the code below yourself for practice :-),
1110/*
1111 *    hex2ascii.c
1112 *    a useful little tool for converting a hexadecimal command line to ascii
1113 *
1114 *    Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
1115 *    (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation.
1116 */   
1117#include <stdio.h>
1118
1119int main(int argc,char *argv[])
1120{
1121  int cnt1,cnt2,len,toggle=0;
1122  int startcnt=1;
1123  unsigned char c,hex;
1124  
1125  if(argc>1&&(strcmp(argv[1],"-a")==0))
1126     startcnt=2;
1127  printf("Decoded Hex:=");
1128  for(cnt1=startcnt;cnt1<argc;cnt1++)
1129  {
1130    len=strlen(argv[cnt1]);
1131    for(cnt2=0;cnt2<len;cnt2++)
1132    {
1133       c=argv[cnt1][cnt2];
1134       if(c>='0'&&c<='9')
1135          c=c-'0';
1136       if(c>='A'&&c<='F')
1137          c=c-'A'+10;
1138       if(c>='a'&&c<='F')
1139          c=c-'a'+10;
1140       switch(toggle)
1141       {
1142          case 0:
1143             hex=c<<4;
1144             toggle=1;
1145          break;
1146          case 1:
1147             hex+=c;
1148             if(hex<32||hex>127)
1149             {
1150                if(startcnt==1)
1151                   printf("0x%02X ",(int)hex);
1152                else
1153                   printf(".");
1154             }
1155             else
1156             {
1157               printf("%c",hex);
1158               if(startcnt==1)
1159                  printf(" ");
1160             }
1161             toggle=0;
1162          break;
1163       }
1164    }
1165  }
1166  printf("\n");
1167}
1168
1169Stack tracing under VM
1170----------------------
1171A basic backtrace
1172-----------------
1173
1174Here are the tricks I use 9 out of 10 times it works pretty well,
1175
1176When your backchain reaches a dead end
1177--------------------------------------
1178This can happen when an exception happens in the kernel & the kernel is entered twice
1179if you reach the NULL pointer at the end of the back chain you should be
1180able to sniff further back if you follow the following tricks.
11811) A kernel address should be easy to recognise since it is in
1182primary space & the problem state bit isn't set & also
1183The Hi bit of the address is set.
11842) Another backchain should also be easy to recognise since it is an 
1185address pointing to another address approximately 100 bytes or 0x70 hex
1186behind the current stackpointer.
1187
1188
1189Here is some practice.
1190boot the kernel & hit PA1 at some random time
1191d g to display the gprs, this should display something like
1192GPR  0 =  00000001  00156018  0014359C  00000000
1193GPR  4 =  00000001  001B8888  000003E0  00000000
1194GPR  8 =  00100080  00100084  00000000  000FE000
1195GPR 12 =  00010400  8001B2DC  8001B36A  000FFED8
1196Note that GPR14 is a return address but as we are real men we are going to
1197trace the stack.
1198display 0x40 bytes after the stack pointer.
1199
1200V000FFED8  000FFF38 8001B838 80014C8E 000FFF38
1201V000FFEE8  00000000 00000000 000003E0 00000000
1202V000FFEF8  00100080 00100084 00000000 000FE000
1203V000FFF08  00010400 8001B2DC 8001B36A 000FFED8
1204
1205
1206Ah now look at whats in sp+56 (sp+0x38) this is 8001B36A our saved r14 if
1207you look above at our stackframe & also agrees with GPR14.
1208
1209now backchain 
1210d 000FFF38.40
1211we now are taking the contents of SP to get our first backchain.
1212
1213V000FFF38  000FFFA0 00000000 00014995 00147094
1214V000FFF48  00147090 001470A0 000003E0 00000000
1215V000FFF58  00100080 00100084 00000000 001BF1D0
1216V000FFF68  00010400 800149BA 80014CA6 000FFF38
1217
1218This displays a 2nd return address of 80014CA6
1219
1220now do d 000FFFA0.40 for our 3rd backchain
1221
1222V000FFFA0  04B52002 0001107F 00000000 00000000
1223V000FFFB0  00000000 00000000 FF000000 0001107F
1224V000FFFC0  00000000 00000000 00000000 00000000
1225V000FFFD0  00010400 80010802 8001085A 000FFFA0
1226
1227
1228our 3rd return address is 8001085A
1229
1230as the 04B52002 looks suspiciously like rubbish it is fair to assume that the kernel entry routines
1231for the sake of optimisation dont set up a backchain.
1232
1233now look at System.map to see if the addresses make any sense.
1234
1235grep -i 0001b3 System.map
1236outputs among other things
12370001b304 T cpu_idle 
1238so 8001B36A
1239is cpu_idle+0x66 ( quiet the cpu is asleep, don't wake it )
1240
1241
1242grep -i 00014 System.map 
1243produces among other things
124400014a78 T start_kernel  
1245so 0014CA6 is start_kernel+some hex number I can't add in my head.
1246
1247grep -i 00108 System.map 
1248this produces
124900010800 T _stext
1250so   8001085A is _stext+0x5a
1251
1252Congrats you've done your first backchain.
1253
1254
1255
1256S390 IO Overview
1257================
1258
1259I am not going to give a course in 390 IO architecture as this would take me quite a
1260while & I'm no expert. Instead I'll give a 390 IO architecture summary for Dummies if you have 
1261the ESA principles of operation available read this instead. If nothing else you may find a few 
1262useful keywords in here & be able to use them on a web search engine like altavista to find 
1263more useful information.
1264
1265Unlike other bus architectures modern 390 systems do their IO using mostly
1266fibre optics & devices such as tapes & disks can be shared between several mainframes,
1267also S390 can support upto 65536 devices while a high end PC based system might be choking 
1268with around 64. Here is some of the common IO terminology
1269
1270Subchannel:
1271This is the logical number most IO commands use to talk to an IO device there can be upto
12720x10000 (65536) of these in a configuration typically there is a few hundred. Under VM
1273for simplicity they are allocated contiguously, however on the native hardware they are not
1274they typically stay consistent between boots provided no new hardware is inserted or removed.
1275Under Linux for 390 we use these as IRQ's & also when issuing an IO command (CLEAR SUBCHANNEL,
1276HALT SUBCHANNEL,MODIFY SUBCHANNEL,RESUME SUBCHANNEL,START SUBCHANNEL,STORE SUBCHANNEL & 
1277TEST SUBCHANNEL ) we use this as the ID of the device we wish to talk to, the most
1278important of these instructions are START SUBCHANNEL ( to start IO ), TEST SUBCHANNEL ( to check
1279whether the IO completed successfully ), & HALT SUBCHANNEL ( to kill IO ), a subchannel
1280can have up to 8 channel paths to a device this offers redunancy if one is not available.
1281
1282
1283Device Number:
1284This number remains static & Is closely tied to the hardware, there are 65536 of these
1285also they are made up of a CHPID ( Channel Path ID, the most significant 8 bits ) 
1286& another lsb 8 bits. These remain static even if more devices are inserted or removed
1287from the hardware, there is a 1 to 1 mapping between Subchannels & Device Numbers provided
1288devices arent inserted or removed.
1289
1290Channel Control Words:
1291CCWS are linked lists of instructions initially pointed to by an operation request block (ORB),
1292which is initially given to Start Subchannel (SSCH) command along with the subchannel number
1293for the IO subsystem to process while the CPU continues executing normal code.
1294These come in two flavours, Format 0 ( 24 bit for backward )
1295compatibility & Format 1 ( 31 bit ). These are typically used to issue read & write 
1296( & many other instructions ) they consist of a length field & an absolute address field.
1297For each IO typically get 1 or 2 interrupts one for channel end ( primary status ) when the
1298channel is idle & the second for device end ( secondary status ) sometimes you get both
1299concurrently, you check how the IO went on by issueing a TEST SUBCHANNEL at each interrupt,
1300from which you receive an Interruption response block (IRB). If you get channel & device end 
1301status in the IRB without channel checks etc. your IO probably went okay. If you didn't you
1302probably need a doctorto examine the IRB & extended status word etc.
1303If an error occurs more sophistocated control units have a facitity known as
1304concurrent sense this means that if an error occurs Extended sense information will
1305be presented in the Extended status word in the IRB if not you have to issue a
1306subsequent SENSE CCW command after the test subchannel. 
1307
1308
1309TPI( Test pending interrupt) can also be used for polled IO but in multitasking multiprocessor
1310systems it isn't recommended except for checking special cases ( i.e. non looping checks for
1311pending IO etc. ).
1312
1313Store Subchannel & Modify Subchannel can be used to examine & modify operating characteristics
1314of a subchannel ( e.g. channel paths ).
1315
1316Other IO related Terms:
1317Sysplex: S390's Clustering Technology
1318QDIO: S390's new high speed IO architecture to support devices such as gigabit ethernet,
1319this architecture is also designed to be forward compatible with up & coming 64 bit machines.
1320
1321
1322General Concepts 
1323
1324Input Output Processors (IOP's) are responsible for communicating between
1325the mainframe CPU's & the channel & relieve the mainframe CPU's from the
1326burden of communicating with IO devices directly, this allows the CPU's to 
1327concentrate on data processing. 
1328
1329IOP's can use one or more links ( known as channel paths ) to talk to each 
1330IO device. It first checks for path availability & chooses an available one,
1331then starts ( & sometimes terminates IO ).
1332There are two types of channel path ESCON & the Paralell IO interface.
1333
1334IO devices are attached to control units, control units provide the
1335logic to interface the channel paths & channel path IO protocols to 
1336the IO devices, they can be integrated with the devices or housed separately
1337& often talk to several similar devices ( typical examples would be raid 
1338controllers or a control unit which connects to 1000 3270 terminals ).
1339
1340
1341    +---------------------------------------------------------------+
1342    | +-----+ +-----+ +-----+ +-----+  +----------+  +----------+   |
1343    | | CPU | | CPU | | CPU | | CPU |  |  Main    |  | Expanded |   |
1344    | |     | |     | |     | |     |  |  Memory  |  |  Storage |   |
1345    | +-----+ +-----+ +-----+ +-----+  +----------+  +----------+   | 
1346    |---------------------------------------------------------------+
1347    |   IOP        |      IOP      |       IOP                      |
1348    |---------------------------------------------------------------
1349    | C | C | C | C | C | C | C | C | C | C | C | C | C | C | C | C | 
1350    ----------------------------------------------------------------
1351         ||                                              ||
1352         ||  Bus & Tag Channel Path                      || ESCON
1353         ||  ======================                      || Channel
1354         ||  ||                  ||                      || Path
1355    +----------+               +----------+         +----------+
1356    |          |               |          |         |          |
1357    |    CU    |               |    CU    |         |    CU    |
1358    |          |               |          |         |          |
1359    +----------+               +----------+         +----------+
1360       |      |                     |                |       |
1361+----------+ +----------+      +----------+   +----------+ +----------+
1362|I/O Device| |I/O Device|      |I/O Device|   |I/O Device| |I/O Device|
1363+----------+ +----------+      +----------+   +----------+ +----------+
1364  CPU = Central Processing Unit    
1365  C = Channel                      
1366  IOP = IP Processor               
1367  CU = Control Unit
1368
1369The 390 IO systems come in 2 flavours the current 390 machines support both
1370
1371The Older 360 & 370 Interface,sometimes called the paralell I/O interface,
1372sometimes called Bus-and Tag & sometimes Original Equipment Manufacturers
1373Interface (OEMI).
1374
1375This byte wide paralell channel path/bus has parity & data on the "Bus" cable 
1376& control lines on the "Tag" cable. These can operate in byte multiplex mode for
1377sharing between several slow devices or burst mode & monopolize the channel for the
1378whole burst. Upto 256 devices can be addressed  on one of these cables. These cables are
1379about one inch in diameter. The maximum unextended length supported by these cables is
1380125 Meters but this can be extended up to 2km with a fibre optic channel extended 
1381such as a 3044. The maximum burst speed supported is 4.5 megabytes per second however
1382some really old processors support only transfer rates of 3.0, 2.0 & 1.0 MB/sec.
1383One of these paths can be daisy chained to up to 8 control units.
1384
1385
1386ESCON if fibre optic it is also called FICON 
1387Was introduced by IBM in 1990. Has 2 fibre optic cables & uses either leds or lasers
1388for communication at a signaling rate of upto 200 megabits/sec. As 10bits are transferred
1389for every 8 bits info this drops to 160 megabits/sec & to 18.6 Megabytes/sec once
1390control info & CRC are added. ESCON only operates in burst mode.
1391 
1392ESCONs typical max cable length is 3km for the led version & 20km for the laser version
1393known as XDF ( extended distance facility ). This can be further extended by using an
1394ESCON director which triples the above mentioned ranges. Unlike Bus & Tag as ESCON is
1395serial it uses a packet switching architecture the standard Bus & Tag control protocol
1396is however present within the packets. Upto 256 devices can be attached to each control 
1397unit that uses one of these interfaces.
1398
1399Common 390 Devices include:
1400Network adapters typically OSA2,3172's,2116's & OSA-E gigabit ethernet adapters,
1401Consoles 3270 & 3215 ( a teletype emulated under linux for a line mode console ).
1402DASD's direct access storage devices ( otherwise known as hard disks ).
1403Tape Drives.
1404CTC ( Channel to Channel Adapters ),
1405ESCON or Paralell Cables used as a very high speed serial link
1406between 2 machines. We use 2 cables under linux to do a bi-directional serial link.
1407
1408
1409Debugging IO on S390 under VM
1410=============================
1411
1412Now we are ready to go on with IO tracing commands under VM
1413
1414A few self explanatory queries:
1415Q OSA
1416Q CTC
1417Q DISK
1418Q DASD
1419
1420Q osa on my machine returns
1421OSA  7C08 ON OSA   7C08 SUBCHANNEL = 0000
1422OSA  7C09 ON OSA   7C09 SUBCHANNEL = 0001
1423OSA  7C14 ON OSA   7C14 SUBCHANNEL = 0002
1424OSA  7C15 ON OSA   7C15 SUBCHANNEL = 0003
1425
1426Now using the device numbers returned by this command we will
1427Trace the io starting up on the first device 7c08 & 7c09
1428In our simplest case we can trace the 
1429start subchannels
1430like TR SSCH 7C08-7C09
1431or the halt subchannels
1432or TR HSCH 7C08-7C09
1433MSCH's ,STSCH's I think you can guess the rest
1434
1435Ingo's favourite trick is tracing all the IO's & CCWS & spooling them into the reader of another
1436VM guest so he can ftp the logfile back to his own machine.I'll do a small bit of this & give you
1437 a look at the output.
1438
14391) Spool stdout to VM guest linux4's reader
1440SP PRT TO * 
14412) Fill linux4's reader with the trace
1442TR IO 7c08-7c09 INST INT CCW PRT RUN
14433) Start up linux 
1444i 00c  
14454) Finish the trace
1446TR END
14475) close the reader
1448C PRT
14496) list reader contents
1450RDRLIST
14517) copy it to linux4's minidisk 
1452RECEIVE / LOG TXT A1 ( replace
14538)
1454filel & press F11 to look at it
1455You should see someting like.
1456
145700020942' SSCH  B2334000    0048813C    CC 0    SCH 0000    DEV 7C08
1458          CPA 000FFDF0   PARM 00E2C9C4    KEY 0  FPI C0  LPM 80
1459          CCW    000FFDF0  E4200100 00487FE8   0000  E4240100 ........
1460          IDAL                                      43D8AFE8
1461          IDAL                                      0FB76000
146200020B0A'   I/O DEV 7C08 -> 000197BC'   SCH 0000   PARM 00E2C9C4
146300021628' TSCH  B2354000 >> 00488164    CC 0    SCH 0000    DEV 7C08
1464          CCWA 000FFDF8   DEV STS 0C  SCH STS 00  CNT 00EC
1465           KEY 0   FPI C0  CC 0   CTLS 4007
146600022238' STSCH B2344000 >> 00488108    CC 0    SCH 0000    DEV 7C08
1467
1468If you don't like messing up your readed ( because you possibly booted from it )
1469you can alternatively spool it to another readers guest.
1470
1471
1472GDB on S390
1473===========
1474N.B. if compiling for debugging gdb works better without optimisation 
1475( see Compiling programs for debugging )
1476
1477invocation
1478----------
1479gdb <victim program> <optional corefile>
1480
1481Online help
1482-----------
1483help: gives help on commands
1484e.g.
1485help
1486help display
1487Note gdb's online help is very good use it.
1488
1489
1490Assembly
1491--------
1492info registers: displays registers other than floating point.
1493info all-registers: displays floating points as well.
1494disassemble: dissassembles
1495e.g.
1496disassemble without parameters will disassemble the current function
1497disassemble $pc $pc+10 
1498
1499Viewing & modifying variables
1500-----------------------------
1501print or p: displays variable or register
1502e.g. p/x $sp will display the stack pointer
1503
1504display: prints variable or register each time program stops
1505e.g.
1506display/x $pc will display the program counter
1507display argc
1508
1509undisplay : undo's display's
1510
1511info breakpoints: shows all current breakpoints
1512
1513info stack: shows stack back trace ( if this dosent work too well, I'll show you the
1514stacktrace by hand below ).
1515
1516info locals: displays local variables.
1517
1518info args: display current procedure arguments.
1519
1520set args: will set argc & argv each time the victim program is invoked.
1521
1522set <variable>=value
1523set argc=100
1524set $pc=0
1525
1526
1527
1528Modifying execution
1529-------------------
1530step: steps n lines of sourcecode
1531step steps 1 line.
1532step 100 steps 100 lines of code.
1533
1534next: like step except this will not step into subroutines
1535
1536stepi: steps a single machine code instruction.
1537e.g. stepi 100
1538
1539nexti: steps a single machine code instruction but will not step into subroutines.
1540
1541finish: will run until exit of the current routine
1542
1543run: (re)starts a program
1544
1545cont: continues a program
1546
1547quit: exits gdb.
1548
1549
1550breakpoints
1551------------
1552
1553break
1554sets a breakpoint
1555e.g.
1556
1557break main
1558
1559break *$pc
1560
1561break *0x400618
1562
1563heres a really useful one for large programs
1564rbr
1565Set a breakpoint for all functions matching REGEXP
1566e.g.
1567rbr 390
1568will set a breakpoint with all functions with 390 in their name.
1569
1570info breakpoints
1571lists all breakpoints
1572
1573delete: delete breakpoint by number or delete them all
1574e.g.
1575delete 1 will delete the first breakpoint
1576delete will delete them all
1577
1578watch: This will set a watchpoint ( usually hardware assisted ),
1579This will watch a variable till it changes
1580e.g.
1581watch cnt, will watch the variable cnt till it changes.
1582As an aside unfortunately gdb's, architecture independent watchpoint code
1583is inconsistent & not very good, watchpoints usually work but not always.
1584
1585info watchpoints: Display currently active watchpoints
1586
1587condition: ( another useful one )
1588Specify breakpoint number N to break only if COND is true.
1589Usage is `condition N COND', where N is an integer and COND is an
1590expression to be evaluated whenever breakpoint N is reached.
1591
1592
1593
1594User defined functions/macros
1595-----------------------------
1596define: ( Note this is very very useful,simple & powerful )
1597usage define <name> <list of commands> end
1598
1599examples which you should consider putting into .gdbinit in your home directory
1600define d
1601stepi
1602disassemble $pc $pc+10
1603end
1604
1605define e
1606nexti
1607disassemble $pc $pc+10
1608end
1609
1610
1611Other hard to classify stuff
1612----------------------------
1613signal n:
1614sends the victim program a signal.
1615e.g. signal 3 will send a SIGQUIT.
1616
1617info signals:
1618what gdb does when the victim receives certain signals.
1619
1620list:
1621e.g.
1622list lists current function source
1623list 1,10 list first 10 lines of curret file.
1624list test.c:1,10
1625
1626
1627directory:
1628Adds directories to be searched for source if gdb cannot find the source.
1629(note it is a bit sensititive about slashes ) 
1630e.g. To add the root of the filesystem to the searchpath do
1631directory //
1632
1633
1634call <function>
1635This calls a function in the victim program, this is pretty powerful
1636e.g.
1637(gdb) call printf("hello world")
1638outputs:
1639$1 = 11 
1640
1641You might now be thinking that the line above didn't work, something extra had to be done.
1642(gdb) call fflush(stdout)
1643hello world$2 = 0
1644As an aside the debugger also calls malloc & free under the hood 
1645to make space for the "hello world" string.
1646
1647
1648
1649hints
1650-----
16511) command completion works just like bash 
1652( if you are a bad typist like me this really helps )
1653e.g. hit br <TAB> & cursor up & down :-).
1654
16552) if you have a debugging problem that takes a few steps to recreate
1656put the steps into a file called .gdbinit in your current working directory
1657if you have defined a few extra useful user defined commands put these in 
1658your home directory & they will be read each time gdb is launched.
1659
1660A typical .gdbinit file might be.
1661break main
1662run
1663break runtime_exception
1664cont 
1665
1666
1667stack chaining in gdb by hand
1668-----------------------------
1669This is done using a the same trick described for VM 
1670p/x (*($sp+56))&0x7fffffff get the first backchain.
1671this outputs 
1672$5 = 0x528f18 
1673on my machine.
1674Now you can use 
1675info symbol (*($sp+56))&0x7fffffff 
1676you might see something like.
1677rl_getc + 36 in section .text  telling you what is located at address 0x528f18
1678Now do.
1679p/x (*(*$sp+56))&0x7fffffff 
1680This outputs
1681$6 = 0x528ed0
1682Now do.
1683info symbol (*(*$sp+56))&0x7fffffff
1684rl_read_key + 180 in section .text
1685now do
1686p/x (*(**$sp+56))&0x7fffffff
1687& so on.
1688
1689
1690
1691Note: Remember gdb has history just like bash you don't need to retype the
1692whole line just use the up & down arrows.
1693
1694
1695
1696For more info
1697-------------
1698From your linuxbox do 
1699man gdb or info gdb.
1700
1701core dumps
1702----------
1703What a core dump ?,
1704A core dump is a file generated by the kernel ( if allowed ) which contains the registers,
1705& all active pages of the program which has crashed.
1706From this file gdb will allow you to look at the registers & stack trace & memory of the
1707program as if it just crashed on your system, it is usually called core & created in the
1708current working directory.
1709This is very useful in that a customer can mail a core dump to a technical support department
1710& the technical support department can reconstruct what happened.
1711Provided the have an indentical copy of this program with debugging symbols compiled in & 
1712the source base of this build is available.
1713In short it is far more useful than something like a crash log could ever hope to be.
1714
1715In theory all that is missing to restart a core dumped program is a kernel patch which
1716will do the following.
17171) Make a new kernel task structure
17182) Reload all the dumped pages back into the kernels memory managment structures.
17193) Do the required clock fixups
17204) Get all files & network connections for the process back into an identical state ( really difficult ).
17215) A few more difficult things I haven't thought of.
1722
1723
1724
1725Why have I never seen one ?.
1726Probably because you haven't used the command 
1727ulimit -c unlimited in bash
1728to allow core dumps, now do 
1729ulimit -a 
1730to verify that the limit was accepted.
1731
1732A sample core dump
1733To create this I'm going to do
1734ulimit -c unlimited
1735gdb 
1736to launch gdb (my victim app. ) now be bad & do the following from another 
1737telnet/xterm session to the same machine
1738ps -aux | grep gdb
1739kill -SIGSEGV <gdb's pid>
1740or alternatively use killall -SIGSEGV gdb if you have the killall command.
1741Now look at the core dump.
1742./gdb ./gdb core
1743Displays the following
1744GNU gdb 4.18
1745Copyright 1998 Free Software Foundation, Inc.
1746GDB is free software, covered by the GNU General Public License, and you are
1747welcome to change it and/or distribute copies of it under certain conditions.
1748Type "show copying" to see the conditions.
1749There is absolutely no warranty for GDB.  Type "show warranty" for details.
1750This GDB was configured as "s390-ibm-linux"...
1751Core was generated by `./gdb'.
1752Program terminated with signal 11, Segmentation fault.
1753Reading symbols from /usr/lib/libncurses.so.4...done.
1754Reading symbols from /lib/libm.so.6...done.
1755Reading symbols from /lib/libc.so.6...done.
1756Reading symbols from /lib/ld-linux.so.2...done.
1757#0  0x40126d1a in read () from /lib/libc.so.6
1758Setting up the environment for debugging gdb.
1759Breakpoint 1 at 0x4dc6f8: file utils.c, line 471.
1760Breakpoint 2 at 0x4d87a4: file top.c, line 2609.
1761(top-gdb) info stack
1762#0  0x40126d1a in read () from /lib/libc.so.6
1763#1  0x528f26 in rl_getc (stream=0x7ffffde8) at input.c:402
1764#2  0x528ed0 in rl_read_key () at input.c:381
1765#3  0x5167e6 in readline_internal_char () at readline.c:454
1766#4  0x5168ee in readline_internal_charloop () at readline.c:507
1767#5  0x51692c in readline_internal () at readline.c:521
1768#6  0x5164fe in readline (prompt=0x7ffff810 "\177ÿøx\177ÿ÷Ø\177ÿøxÀ")
1769    at readline.c:349
1770#7  0x4d7a8a in command_line_input (prrompt=0x564420 "(gdb) ", repeat=1,
1771    annotation_suffix=0x4d6b44 "prompt") at top.c:2091
1772#8  0x4d6cf0 in command_loop () at top.c:1345
1773#9  0x4e25bc in main (argc=1, argv=0x7ffffdf4) at main.c:635
1774
1775
1776LDD
1777===
1778This is a program which lists the shared libraries which a library needs.
1779e.g.
1780 ldd ./gdb
1781outputs
1782libncurses.so.4 => /usr/lib/libncurses.so.4 (0x40018000)
1783libm.so.6 => /lib/libm.so.6 (0x4005e000)
1784libc.so.6 => /lib/libc.so.6 (0x40084000)
1785/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
1786
1787Debugging modules
1788=================
1789As modules are dynamically loaded into the kernel their address can be
1790anywhere to get around this use the -m option with insmod to emit a load
1791map which can be piped into a file if required.
1792
1793The proc file system
1794====================
1795What is it ?.
1796It is a filesystem created by the kernel with files which are created on demand
1797by the kernel if read, or can be used to modify kernel parameters,
1798it is a powerful concept.
1799
1800e.g.
1801
1802cat /proc/sys/net/ipv4/ip_forward 
1803On my machine outputs 
18040 
1805telling me ip_forwarding is not on to switch it on I can do
1806echo 1 >  /proc/sys/net/ipv4/ip_forward
1807cat it again
1808cat /proc/sys/net/ipv4/ip_forward 
1809On my machine now outputs
18101
1811IP forwarding is on.
1812There is a lot of useful info in here best found by going in & having a look around,
1813so I'll take you through some entries I consider important.
1814
1815All the processes running on the machine have there own entry defined by
1816/proc/<pid>
1817So lets have a look at the init process
1818cd /proc/1
1819
1820cat cmdline
1821emits
1822init [2]
1823
1824cd /proc/1/fd
1825This contains numerical entries of all the open files,
1826some of these you can cat e.g. stdout (2)
1827
1828cat /proc/29/maps
1829on my machine emits
1830
183100400000-00478000 r-xp 00000000 5f:00 4103       /bin/bash
183200478000-0047e000 rw-p 00077000 5f:00 4103       /bin/bash
18330047e000-00492000 rwxp 00000000 00:00 0
183440000000-40015000 r-xp 00000000 5f:00 14382      /lib/ld-2.1.2.so
183540015000-40016000 rw-p 00014000 5f:00 14382      /lib/ld-2.1.2.so
183640016000-40017000 rwxp 00000000 00:00 0
183740017000-40018000 rw-p 00000000 00:00 0
183840018000-4001b000 r-xp 00000000 5f:00 14435      /lib/libtermcap.so.2.0.8
18394001b000-4001c000 rw-p 00002000 5f:00 14435      /lib/libtermcap.so.2.0.8
18404001c000-4010d000 r-xp 00000000 5f:00 14387      /lib/libc-2.1.2.so
18414010d000-40111000 rw-p 000f0000 5f:00 14387      /lib/libc-2.1.2.so
184240111000-40114000 rw-p 00000000 00:00 0
184340114000-4011e000 r-xp 00000000 5f:00 14408      /lib/libnss_files-2.1.2.so
18444011e000-4011f000 rw-p 00009000 5f:00 14408      /lib/libnss_files-2.1.2.so
18457fffd000-80000000 rwxp ffffe000 00:00 0
1846
1847
1848Showing us the shared libraries init uses where they are in memory
1849& memory access permissions for each virtual memory area.
1850
1851/proc/1/cwd is a softlink to the current working directory.
1852/proc/1/root is the root of the filesystem for this process. 
1853
1854/proc/1/mem is the current running processes memory which you
1855can read & write to like a file.
1856strace uses this sometimes as it is a bit faster than the
1857rather inefficent ptrace interface for peeking at DATA.
1858
1859
1860cat status 
1861
1862Name:   init
1863State:  S (sleeping)
1864Pid:    1
1865PPid:   0
1866Uid:    0       0       0       0
1867Gid:    0       0       0       0
1868Groups:
1869VmSize:      408 kB
1870VmLck:         0 kB
1871VmRSS:       208 kB
1872VmData:       24 kB
1873VmStk:         8 kB
1874VmExe:       368 kB
1875VmLib:         0 kB
1876SigPnd: 0000000000000000
1877SigBlk: 0000000000000000
1878SigIgn: 7fffffffd7f0d8fc
1879SigCgt: 00000000280b2603
1880CapInh: 00000000fffffeff
1881CapPrm: 00000000ffffffff
1882CapEff: 00000000fffffeff
1883
1884User PSW:    070de000 80414146
1885task: 004b6000 tss: 004b62d8 ksp: 004b7ca8 pt_regs: 004b7f68
1886User GPRS:
188700000400  00000000  0000000b  7ffffa90
188800000000  00000000  00000000  0045d9f4
18890045cafc  7ffffa90  7fffff18  0045cb08
189000010400  804039e8  80403af8  7ffff8b0
1891User ACRS:
189200000000  00000000  00000000  00000000
189300000001  00000000  00000000  00000000
189400000000  00000000  00000000  00000000
189500000000  00000000  00000000  00000000
1896Kernel BackChain  CallChain    BackChain  CallChain
1897       004b7ca8   8002bd0c     004b7d18   8002b92c
1898       004b7db8   8005cd50     004b7e38   8005d12a
1899       004b7f08   80019114                     
1900Showing among other things memory usage & status of some signals &
1901the processes'es registers from the kernel task_structure
1902as well as a backchain which may be useful if a process crashes
1903in the kernel for some unknown reason.
1904
1905Starting points for debugging scripting languages etc.
1906======================================================
1907
1908bash/sh
1909
1910bash -x <scriptname>
1911e.g. bash -x /usr/bin/bashbug
1912displays the following lines as it executes them.
1913+ MACHINE=i586
1914+ OS=linux-gnu
1915+ CC=gcc
1916+ CFLAGS= -DPROGRAM='bash' -DHOSTTYPE='i586' -DOSTYPE='linux-gnu' -DMACHTYPE='i586-pc-linux-gnu' -DSHELL -DHAVE_CONFIG_H   -I. -I. -I./lib -O2 -pipe
1917+ RELEASE=2.01
1918+ PATCHLEVEL=1
1919+ RELSTATUS=release
1920+ MACHTYPE=i586-pc-linux-gnu   
1921
1922perl -d <scriptname> runs the perlscript in a fully intercative debugger
1923<like gdb>.
1924Type 'h' in the debugger for help.
1925
1926for debugging java type
1927jdb <filename> another fully interactive gdb style debugger.
1928& type ? in the debugger for help.
1929
1930
1931References:
1932-----------
1933Enterprise Systems Architecture Reference Summary
1934Enterprise Systems Architecture Principles of Operation
1935Hartmut Penners 390 stack frame sheet.
1936IBM Mainframe Channel Attachment a technology brief from a CISCO webpage
1937Various bits of man & info pages of Linux.
1938Linux & GDB source.
1939Various info & man pages.
1940CMS Help on tracing commands.
1941
1942
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.