source: branches/v4/platforms/tsarv4_mono_mmu_ioc/.gdbinit @ 985

Last change on this file since 985 was 643, checked in by porquet, 11 years ago

add my .gdbinit file

it provides a few helpers, especially useful for linux development

File size: 3.4 KB
Line 
1define connect
2    target remote localhost:2346
3end
4
5# useful macros for Linux
6define dmesg
7        set $__log_buf = $arg0
8        set $log_start = $arg1
9        set $log_end = $arg2
10        set $x = $log_start
11        echo "
12        while ($x < $log_end)
13                set $c = (char)(($__log_buf)[$x++])
14                printf "%c" , $c
15        end
16        echo "\n
17end
18document dmesg
19dmesg __log_buf log_start log_end
20Print the content of the kernel message buffer
21end
22
23define thread_info
24    set $th = (struct thread_info*)$gp
25    echo "thread_info="
26    print /x *$th
27end
28define task_struct
29    set $th = (struct thread_info*)$gp
30    set $ts = (struct task_struct*)$th->task
31    echo "task_struct="
32    print /x *$ts
33end
34define active_mm
35    set $th = (struct thread_info*)$gp
36    set $ts = (struct task_struct*)$th->task
37    set $amm = (struct mm_struct*)$ts->active_mm
38    echo "active_mm="
39    print /x *$amm
40end
41define pgd
42    set $th = (struct thread_info*)$gp
43    set $ts = (struct task_struct*)$th->task
44    set $ms = (struct mm_struct*)$ts->active_mm
45    set $pg = (pgd_t*)$ms->pgd
46    echo "pgd="
47    print /x {pgd_t[2048]}$pg
48end
49
50define task_struct_header
51    printf "Address      PID State     [User_EPC] [User-SP]  Kernel-SP  device comm\n"
52end
53
54define task_struct_show
55    # task_struct addr and PID
56    printf "0x%08X %5d", $arg0, $arg0->pid
57    # Place a '<' marker on the current task
58    #  if ($arg0 == current)
59    # For PowerPC, register r2 points to the "current" task
60    if ($arg0 == $r2)
61        printf "<"
62    else
63        printf " "
64    end
65    # State
66    if ($arg0->state == 0)
67        printf "Running   "
68    else
69        if ($arg0->state == 1)
70            printf "Sleeping  "
71        else
72            if ($arg0->state == 2)
73                printf "Disksleep "
74            else
75                if ($arg0->state == 4)
76                    printf "Zombie    "
77                else
78                    if ($arg0->state == 8)
79                        printf "sTopped   "
80                    else
81                        if ($arg0->state == 16)
82                            printf "Wpaging   "
83                        else
84                            printf "%2d        ", $arg0->state
85                        end
86                    end
87                end
88            end
89        end
90    end
91    # User PC
92    set $pt_regs = (struct pt_regs*)($arg0->stack + 0x2000 - sizeof(struct pt_regs))
93    if ($pt_regs->cp0_epc)
94        printf "0x%08X ", $pt_regs->cp0_epc
95    else
96        printf "           "
97    end
98    if ($pt_regs->regs[29])
99        printf "0x%08X ", $pt_regs->regs[29]
100    else
101        printf "           "
102    end
103    # Display the kernel stack pointer
104    set $th = (struct thread_info*)$arg0->stack
105    printf "0x%08X ", $th->ksp
106    # device
107    if ($arg0->signal->tty)
108        printf "%s   ", $arg0->signal->tty->name
109    else
110        printf "(none) "
111    end
112    # comm
113    printf "%s\n", $arg0->comm
114end
115
116define find_next_task
117    # Given a task address, find the next task in the linked list
118    set $t = (struct task_struct *)$arg0
119    set $offset=((char *)&$t->tasks - (char *)$t)
120    set $t=(struct task_struct *)((char *)$t->tasks.next- (char *)$offset)
121end
122
123define ps
124    # Print column headers
125    task_struct_header
126    set $t=&init_task
127    task_struct_show $t
128    find_next_task $t
129    # Walk the list
130    while &init_task!=$t
131        # Display useful info about each task
132        task_struct_show $t
133        find_next_task $t
134    end
135end
136
Note: See TracBrowser for help on using the repository browser.