Merge branch 'dev' into kernel
[kernel/swap-modules.git] / driver / sspt / sspt_debug.h
1 #ifndef __SSPT_DEBUG__
2 #define __SSPT_DEBUG__
3
4 /*
5  *  Dynamic Binary Instrumentation Module based on KProbes
6  *  modules/driver/sspt/sspt_debug.h
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * Copyright (C) Samsung Electronics, 2013
23  *
24  * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
25  *
26  */
27
28 static inline void print_jprobe(struct jprobe *jp)
29 {
30         printk("###         JP: entry=%lx, pre_entry=%lx\n",
31                         (unsigned long)jp->entry, (unsigned long)jp->pre_entry);
32 }
33
34 static inline void print_retprobe(struct uretprobe *rp)
35 {
36         printk("###         RP: handler=%lx\n",
37                         (unsigned long)rp->handler);
38 }
39
40 static inline void print_page_probes(const struct sspt_page *page)
41 {
42         int i = 0;
43         struct us_ip *ip;
44
45         printk("###     offset=%lx\n", page->offset);
46         list_for_each_entry(ip, &page->ip_list, list) {
47
48                 printk("###       addr[%2d]=%lx, J_addr=%lx, R_addr=%lx\n",
49                                 i, (unsigned long)ip->offset, (unsigned long)ip->jprobe.up.kp.addr,
50                                 (unsigned long)ip->retprobe.up.kp.addr);
51                 print_jprobe(&ip->jprobe);
52                 print_retprobe(&ip->retprobe);
53                 ++i;
54         }
55 }
56
57 static inline void print_file_probes(const struct sspt_file *file)
58 {
59         int i;
60         unsigned long table_size;
61         struct sspt_page *page = NULL;
62         struct hlist_node *node = NULL;
63         struct hlist_head *head = NULL;
64         static unsigned char *NA = "N/A";
65         unsigned char *name;
66
67         if (file == NULL) {
68                 printk("### file_p == NULL\n");
69                 return;
70         }
71
72         table_size = (1 << file->page_probes_hash_bits);
73         name = (file->dentry) ? file->dentry->d_iname : NA;
74
75         printk("### print_file_probes: path=%s, d_iname=%s, table_size=%lu, vm_start=%lx\n",
76                         file->name, name, table_size, file->vm_start);
77
78         for (i = 0; i < table_size; ++i) {
79                 head = &file->page_probes_table[i];
80                 swap_hlist_for_each_entry_rcu(page, node, head, hlist) {
81                         print_page_probes(page);
82                 }
83         }
84 }
85
86 static inline void print_proc_probes(const struct sspt_procs *procs)
87 {
88         struct sspt_file *file;
89
90         printk("### print_proc_probes\n");
91         list_for_each_entry(file, &procs->file_list, list) {
92                 print_file_probes(file);
93         }
94         printk("### print_proc_probes\n");
95 }
96
97 static inline void print_inst_us_proc(const inst_us_proc_t *task_inst_info)
98 {
99         int i;
100         int cnt = task_inst_info->libs_count;
101         printk(  "### BUNDLE PRINT START ###\n");
102         printk("\n### BUNDLE PRINT START ###\n");
103         printk("### task_inst_info.libs_count=%d\n", cnt);
104
105         for (i = 0; i < cnt; ++i) {
106                 int j;
107
108                 us_proc_lib_t *lib = &task_inst_info->p_libs[i];
109                 int cnt_j = lib->ips_count;
110                 char *path = lib->path;
111                 printk("###     path=%s, cnt_j=%d\n", path, cnt_j);
112
113                 for (j = 0; j < cnt_j; ++j) {
114                         us_proc_ip_t *ips = &lib->p_ips[j];
115                         unsigned long offset = ips->offset;
116                         printk("###         offset=%lx\n", offset);
117                 }
118         }
119         printk("### BUNDLE PRINT  END  ###\n");
120 }
121
122 #endif /* __SSPT_DEBUG__ */