summaryrefslogtreecommitdiff
path: root/gdb/doc/stack_frame.txt
blob: e6ff020b378ee49e0687599e31ae796ee8f35a93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
                  ^    ->|            |
Frame             |   |  |            |
Number          - |   |  |============|       int fact (int n)
               |  |   |  |   i = 3    |       {
               |  |   |  |------------|         if (0 == n) {
               |  |   |  |   f = ?    |           return  1;  <-------- PC
  #4 main()   <   |   |  |------------|        }
               |  |   |  |            |         else {
               |  |  -+->|------------|   --->    return n * fact (n - 1);
               |   -+-+--+-----o      |  |      }
                =   | |  |============|  |    }
               |    | |  |   n = 3    |  |
               |    | |  |------------|  |    main ()
  #3 fact (3) <     | |  |     o---------+-   {
               |   -+-+->|------------|  | |    int  i;
               |  | |  --+-----o      |  | |
                = | |    |============|  | |    for (i = 0; i < 10; i++) {
               |  | |    |   n = 2    |  |  ->    int  f = fact (i);
               |  | |    |------------|  |        printf ("%d! = %d\n", i , f);
  #2 fact (2) <   | |    |     o------+--|      }
               |  | |  ->|------------|  |    }
               |  |  -+--+-----o      |  |
                = |   |  |============|  |
               |  |   |  |   n = 1    |  |
               |  |   |  |------------|  |
  #1 fact (1) <   |   |  |     o------+--|
               |  |   |  |------------|  |
               |   ---|--+-----o      |<-+------- FP
                =     |  |============|  |                   |
               |      |  |   n = 0    |  |                   |
               |      |  |------------|  |                   |
  #0 fact (0) <       |  |     o---------                    |
               |      |  |------------|                      |
               |       --+-----o      |<--------- SP         |
                =        |============|                      |
               |         |  Red Zone  |                      v  
               |         \/\/\/\/\/\/\/                 Direction of
  #-1         <          \/\/\/\/\/\/\/                 stack growth
               |         |            |