Magellan Linux

Contents of /trunk/gdb/patches/gdb-6.3-scanmem-gcc4-aware.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144 - (show annotations) (download)
Tue May 8 20:06:05 2007 UTC (17 years ago) by niro
File size: 6652 byte(s)
-import

1 diff -Nrup gdb-6.3.orig/gdb/printcmd.c gdb-6.3/gdb/printcmd.c
2 --- gdb-6.3.orig/gdb/printcmd.c 2004-09-11 06:24:50.000000000 -0400
3 +++ gdb-6.3/gdb/printcmd.c 2004-11-27 19:48:18.000000000 -0500
4 @@ -940,6 +940,195 @@ print_command (char *exp, int from_tty)
5 print_command_1 (exp, 0, 1);
6 }
7
8 +static void
9 +scanmem_command(char *exp, int from_tty)
10 +{
11 + struct expression *expr;
12 + struct value *val;
13 + struct format_data fmt;
14 + CORE_ADDR addr;
15 + unsigned char *data;
16 + unsigned char *size;
17 + unsigned char *pattern;
18 + unsigned char typ;
19 + unsigned char typc;
20 + unsigned char my_buf[4];
21 + unsigned int nfetch;
22 + unsigned int len = 10;
23 + unsigned int memsize;
24 + unsigned int i;
25 + int typi;
26 + int errcode;
27 +
28 + if (exp && *exp) {
29 + struct type *type;
30 + char *str_num = NULL;
31 + char *string_to_seek = NULL;
32 + char *tmp = strdup(exp);
33 + char *c;
34 +
35 + c = tmp;
36 + if (*c == ' ')
37 + while (*c && *c == ' ')
38 + c++;
39 +
40 + while (*c && *c != ' ')
41 + c++;
42 +
43 + *c = '\0';
44 + c++;
45 +
46 + while (*c && *c == ' ')
47 + c++;
48 +
49 + size = c;
50 +
51 + while (*c && *c != ' ')
52 + c++;
53 +
54 + *c = '\0';
55 + c++;
56 +
57 + while (*c && *c == ' ')
58 + c++;
59 +
60 + typ = *c;
61 + c++;
62 +
63 + *c = '\0';
64 + c++;
65 +
66 + while (*c && *c == ' ')
67 + c++;
68 + pattern = c;
69 +
70 + printf_filtered(">>addr %s: size %s: type:%c pattern:%s<< \n",
71 + tmp, size, typ, pattern);
72 +
73 + expr = parse_expression(tmp);
74 + val = evaluate_expression(expr);
75 +
76 + if (TYPE_CODE(VALUE_TYPE(val)) == TYPE_CODE_REF)
77 + val = value_ind(val);
78 +
79 + if (TYPE_CODE(VALUE_TYPE(val)) == TYPE_CODE_FUNC
80 + && VALUE_LVAL(val) == lval_memory)
81 + addr = VALUE_ADDRESS(val);
82 + else
83 + addr = value_as_address(val);
84 +
85 + len = atoi(size);
86 + data = xmalloc(len);
87 + nfetch = partial_memory_read(addr, data, len, &errcode);
88 +
89 + if (nfetch != len)
90 + printf_filtered("we can read only %i bytes\n", nfetch);
91 +
92 + switch (typ) {
93 + case 's':
94 + memsize = strlen(pattern);
95 + if (nfetch < memsize) {
96 + printf_filtered
97 + ("we read only %i bytes and we seek for a pattern of %i bytes\n",
98 + nfetch, memsize);
99 + free(data);
100 + free(tmp);
101 + return;
102 + }
103 + for (i = 0; i <= (nfetch - memsize); i++, addr++) {
104 + if (memcmp(data + i, pattern, memsize) == 0) {
105 + printf_filtered("pattern match at ");
106 + print_address_numeric((addr), 1, gdb_stdout);
107 + printf_filtered("\n");
108 + }
109 + }
110 + break;
111 + case 'i':
112 + memsize = sizeof(int);
113 + typi = atoi(pattern);
114 +
115 + if (nfetch < memsize) {
116 + printf_filtered
117 + ("we read only %i bytes and we seek for a pattern of %i bytes\n",
118 + nfetch, memsize);
119 + free(data);
120 + free(tmp);
121 + return;
122 + }
123 + for (i = 0; i <= (nfetch - memsize); i++, addr++) {
124 + int *pint;
125 + pint = (unsigned char *) (data + i);
126 + if (*pint == typi) {
127 + printf_filtered("pattern match at ");
128 + print_address_numeric((addr), 1, gdb_stdout);
129 + printf_filtered("\n");
130 + }
131 + }
132 + break;
133 + case 'a':
134 + memsize = sizeof(unsigned long);
135 + if (sscanf(pattern, "0x%x", &i) == 0) {
136 + printf_filtered("cant convert to hexa %s\n", pattern);
137 + break;
138 + }
139 + my_buf[0] = (unsigned char) ((i & 0x000000FF));
140 + my_buf[1] = (unsigned char) ((i & 0x0000FF00) >> 8);
141 + my_buf[2] = (unsigned char) ((i & 0x00FF0000) >> 16);
142 + my_buf[3] = (unsigned char) ((i & 0xFF000000) >> 24);
143 + if (nfetch < memsize) {
144 + printf_filtered
145 + ("we read only %i bytes and we seek for a pattern of %i bytes\n",
146 + nfetch, memsize);
147 + free(data);
148 + free(tmp);
149 + return;
150 + }
151 + for (i = 0; i <= (nfetch - memsize); i++, addr++) {
152 + if (memcmp((data + i), my_buf, memsize) == 0) {
153 + printf_filtered("pattern match at ");
154 + print_address_numeric((addr), 1, gdb_stdout);
155 + printf_filtered("\n");
156 + }
157 + }
158 + break;
159 + case 'b':
160 + case 'c':
161 + memsize = sizeof(char);
162 + if (typ == 'c')
163 + typc = *pattern;
164 + else {
165 + if (strncmp("0x", pattern, 2) == 0) {
166 + sscanf(pattern, "0x%02x", &typc);
167 + } else
168 + typc = (unsigned char)atoi(pattern);
169 + }
170 + printf_filtered(">>>%0x2\n", (int) typc);
171 + if (nfetch < memsize) {
172 + printf_filtered
173 + ("we read only %i bytes and we seek for a pattern of %i bytes\n",
174 + nfetch, memsize);
175 + free(data);
176 + free(tmp);
177 + return;
178 + }
179 + for (i = 0; i <= (nfetch - memsize); i++, addr++) {
180 + if (*(data + i) == typc) {
181 + printf_filtered("pattern match at ");
182 + print_address_numeric((addr), 1, gdb_stdout);
183 + printf_filtered("\n");
184 + }
185 + }
186 + break;
187 + default:
188 + printf_filtered("'%c' is not a valid type\n", typ);
189 + break;
190 + }
191 + free(data);
192 + free(tmp);
193 + return;
194 + }
195 +}
196 +
197 /* Same as print, except in epoch, it gets its own window */
198 static void
199 inspect_command (char *exp, int from_tty)
200 @@ -2138,6 +2327,17 @@ EXP may be preceded with /FMT, where FMT
201 but no count or size letter (see \"x\" command).", NULL));
202 set_cmd_completer (c, location_completer);
203 add_com_alias ("p", "print", class_vars, 1);
204 + c =
205 + add_com ("scanmem", class_vars, scanmem_command,
206 + "scanmem <addr> <num> <type> <string>\n"
207 + "example: scanmem $esp 100 a 0x8048434\n"
208 + " scan for this addr into the stack\n\n"
209 + " scanmem 0x08048434 100 s fsck\n"
210 + " seek for a string\n"
211 + " scanmem 0x8048434 100 b 0x75\n"
212 + " scan for the char 0x75\n"
213 + " a = address c = char b = byte i = int s = string\n"
214 + "\n"); /* antilove@zolo.freelsd.net */
215
216 c = add_com ("inspect", class_vars, inspect_command,
217 "Same as \"print\" command, except that if you are running in the epoch\n\
218 diff -Nrup gdb-6.3.orig/gdb/valprint.c gdb-6.3/gdb/valprint.c
219 --- gdb-6.3.orig/gdb/valprint.c 2004-09-12 12:13:04.000000000 -0400
220 +++ gdb-6.3/gdb/valprint.c 2004-11-27 19:23:54.000000000 -0500
221 @@ -39,7 +39,7 @@
222
223 /* Prototypes for local functions */
224
225 -static int partial_memory_read (CORE_ADDR memaddr, char *myaddr,
226 +int partial_memory_read (CORE_ADDR memaddr, char *myaddr,
227 int len, int *errnoptr);
228
229 static void show_print (char *, int);
230 @@ -837,7 +837,7 @@ val_print_array_elements (struct type *t
231 /* FIXME: cagney/1999-10-14: Only used by val_print_string. Can this
232 function be eliminated. */
233
234 -static int
235 +int
236 partial_memory_read (CORE_ADDR memaddr, char *myaddr, int len, int *errnoptr)
237 {
238 int nread; /* Number of bytes actually read. */