diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-07-17 11:42:44 -0400 |
---|---|---|
committer | Steven Rostedt <srostedt@redhat.com> | 2009-07-17 11:42:44 -0400 |
commit | 8f1e3f87c141f081d8fb961f97d00b4100459eb5 (patch) | |
tree | b5a89aebda08838c88da93999dc33ba363105bdf | |
parent | ee14f41ea9139587f78d96c01063d26b032b20e1 (diff) |
fix reading data from diffenent endian types
When testing a data file created on x86 on a PPC box, I found that
there was a missing conversion of reading the values. This patch
moves the data2host to the header file and converts the necessary
fields.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
-rw-r--r-- | parse-events.c | 8 | ||||
-rw-r--r-- | parse-events.h | 54 | ||||
-rw-r--r-- | trace-read.c | 41 |
3 files changed, 60 insertions, 43 deletions
diff --git a/parse-events.c b/parse-events.c index 72b8d56..81957cf 100644 --- a/parse-events.c +++ b/parse-events.c | |||
@@ -1597,11 +1597,11 @@ static unsigned long long read_size(void *ptr, int size) | |||
1597 | case 1: | 1597 | case 1: |
1598 | return *(unsigned char *)ptr; | 1598 | return *(unsigned char *)ptr; |
1599 | case 2: | 1599 | case 2: |
1600 | return *(unsigned short *)ptr; | 1600 | return data2host2(ptr); |
1601 | case 4: | 1601 | case 4: |
1602 | return *(unsigned int *)ptr; | 1602 | return data2host4(ptr); |
1603 | case 8: | 1603 | case 8: |
1604 | return *(unsigned long long *)ptr; | 1604 | return data2host8(ptr); |
1605 | default: | 1605 | default: |
1606 | /* BUG! */ | 1606 | /* BUG! */ |
1607 | return 0; | 1607 | return 0; |
@@ -2334,7 +2334,7 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs) | |||
2334 | 2334 | ||
2335 | event = find_event(type); | 2335 | event = find_event(type); |
2336 | if (!event) | 2336 | if (!event) |
2337 | die("ug! no event found"); | 2337 | die("ug! no event found for type %d", type); |
2338 | 2338 | ||
2339 | pid = parse_common_pid(data); | 2339 | pid = parse_common_pid(data); |
2340 | comm = find_cmdline(pid); | 2340 | comm = find_cmdline(pid); |
diff --git a/parse-events.h b/parse-events.h index e77af1f..9ba633f 100644 --- a/parse-events.h +++ b/parse-events.h | |||
@@ -168,4 +168,58 @@ int parse_ftrace_file(char *buf, unsigned long size); | |||
168 | int parse_event_file(char *buf, unsigned long size, char *system); | 168 | int parse_event_file(char *buf, unsigned long size, char *system); |
169 | void print_event(int cpu, void *data, int size, unsigned long long nsecs); | 169 | void print_event(int cpu, void *data, int size, unsigned long long nsecs); |
170 | 170 | ||
171 | extern int file_bigendian; | ||
172 | extern int host_bigendian; | ||
173 | |||
174 | static inline unsigned short __data2host2(unsigned short data) | ||
175 | { | ||
176 | unsigned short swap; | ||
177 | |||
178 | if (host_bigendian == file_bigendian) | ||
179 | return data; | ||
180 | |||
181 | swap = ((data & 0xffULL) << 8) | | ||
182 | ((data & (0xffULL << 8)) >> 8); | ||
183 | |||
184 | return swap; | ||
185 | } | ||
186 | |||
187 | static inline unsigned int __data2host4(unsigned int data) | ||
188 | { | ||
189 | unsigned int swap; | ||
190 | |||
191 | if (host_bigendian == file_bigendian) | ||
192 | return data; | ||
193 | |||
194 | swap = ((data & 0xffULL) << 24) | | ||
195 | ((data & (0xffULL << 8)) << 8) | | ||
196 | ((data & (0xffULL << 16)) >> 8) | | ||
197 | ((data & (0xffULL << 24)) >> 24); | ||
198 | |||
199 | return swap; | ||
200 | } | ||
201 | |||
202 | static inline unsigned long long __data2host8(unsigned long long data) | ||
203 | { | ||
204 | unsigned long long swap; | ||
205 | |||
206 | if (host_bigendian == file_bigendian) | ||
207 | return data; | ||
208 | |||
209 | swap = ((data & 0xffULL) << 56) | | ||
210 | ((data & (0xffULL << 8)) << 40) | | ||
211 | ((data & (0xffULL << 16)) << 24) | | ||
212 | ((data & (0xffULL << 24)) << 8) | | ||
213 | ((data & (0xffULL << 32)) >> 8) | | ||
214 | ((data & (0xffULL << 40)) >> 24) | | ||
215 | ((data & (0xffULL << 48)) >> 40) | | ||
216 | ((data & (0xffULL << 56)) >> 56); | ||
217 | |||
218 | return swap; | ||
219 | } | ||
220 | |||
221 | #define data2host2(ptr) __data2host2(*(unsigned short *)ptr) | ||
222 | #define data2host4(ptr) __data2host4(*(unsigned int *)ptr) | ||
223 | #define data2host8(ptr) __data2host8(*(unsigned long long *)ptr) | ||
224 | |||
171 | #endif /* _PARSE_EVENTS_H */ | 225 | #endif /* _PARSE_EVENTS_H */ |
diff --git a/trace-read.c b/trace-read.c index f65043b..fd8e206 100644 --- a/trace-read.c +++ b/trace-read.c | |||
@@ -42,8 +42,8 @@ static int input_fd; | |||
42 | 42 | ||
43 | static int read_page; | 43 | static int read_page; |
44 | 44 | ||
45 | static int file_bigendian; | 45 | int file_bigendian; |
46 | static int host_bigendian; | 46 | int host_bigendian; |
47 | static int long_size; | 47 | static int long_size; |
48 | 48 | ||
49 | static int filter_cpu = -1; | 49 | static int filter_cpu = -1; |
@@ -68,43 +68,6 @@ static int read_or_die(void *data, int size) | |||
68 | return r; | 68 | return r; |
69 | } | 69 | } |
70 | 70 | ||
71 | static unsigned int __data2host4(unsigned int data) | ||
72 | { | ||
73 | unsigned long long swap; | ||
74 | |||
75 | if (host_bigendian == file_bigendian) | ||
76 | return data; | ||
77 | |||
78 | swap = ((data & 0xffULL) << 24) | | ||
79 | ((data & (0xffULL << 8)) << 8) | | ||
80 | ((data & (0xffULL << 16)) >> 8) | | ||
81 | ((data & (0xffULL << 24)) >> 24); | ||
82 | |||
83 | return swap; | ||
84 | } | ||
85 | |||
86 | static unsigned long long __data2host8(unsigned long long data) | ||
87 | { | ||
88 | unsigned long long swap; | ||
89 | |||
90 | if (host_bigendian == file_bigendian) | ||
91 | return data; | ||
92 | |||
93 | swap = ((data & 0xffULL) << 56) | | ||
94 | ((data & (0xffULL << 8)) << 40) | | ||
95 | ((data & (0xffULL << 16)) << 24) | | ||
96 | ((data & (0xffULL << 24)) << 8) | | ||
97 | ((data & (0xffULL << 32)) >> 8) | | ||
98 | ((data & (0xffULL << 40)) >> 24) | | ||
99 | ((data & (0xffULL << 48)) >> 40) | | ||
100 | ((data & (0xffULL << 56)) >> 56); | ||
101 | |||
102 | return swap; | ||
103 | } | ||
104 | |||
105 | #define data2host4(ptr) __data2host4(*(unsigned int *)ptr) | ||
106 | #define data2host8(ptr) __data2host8(*(unsigned long long *)ptr) | ||
107 | |||
108 | static unsigned int read4(void) | 71 | static unsigned int read4(void) |
109 | { | 72 | { |
110 | unsigned int data; | 73 | unsigned int data; |