Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo commit in src/patchsets/gdb/6.8: 50_all_gdb-pie-1.patch 50_all_gdb-pie-2.patch README.history
Date: Sat, 21 Jun 2008 06:44:19
Message-Id: E1K9wpU-0002tZ-Tq@stork.gentoo.org
1 vapier 08/06/21 06:44:08
2
3 Modified: README.history
4 Added: 50_all_gdb-pie-1.patch 50_all_gdb-pie-2.patch
5 Log:
6 add pie patches #223533
7
8 Revision Changes Path
9 1.4 src/patchsets/gdb/6.8/README.history
10
11 file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/README.history?rev=1.4&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/README.history?rev=1.4&content-type=text/plain
13 diff : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/README.history?r1=1.3&r2=1.4
14
15 Index: README.history
16 ===================================================================
17 RCS file: /var/cvsroot/gentoo/src/patchsets/gdb/6.8/README.history,v
18 retrieving revision 1.3
19 retrieving revision 1.4
20 diff -u -r1.3 -r1.4
21 --- README.history 7 Apr 2008 23:01:58 -0000 1.3
22 +++ README.history 21 Jun 2008 06:44:08 -0000 1.4
23 @@ -1,3 +1,7 @@
24 +1.3 21.06.2008
25 + + 50_all_gdb-pie-1.patch
26 + + 50_all_gdb-pie-2.patch
27 +
28 1.2 07.04.2008
29 U 10_all_gdb-6.6-duel.patch
30 U 11_all_gdb-6.6-duel-integrate.patch
31
32
33
34 1.1 src/patchsets/gdb/6.8/50_all_gdb-pie-1.patch
35
36 file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/50_all_gdb-pie-1.patch?rev=1.1&view=markup
37 plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/50_all_gdb-pie-1.patch?rev=1.1&content-type=text/plain
38
39 Index: 50_all_gdb-pie-1.patch
40 ===================================================================
41 http://bugs.gentoo.org/223533
42
43 2007-11-02 Jan Kratochvil <jan.kratochvil@××××××.com>
44
45 Port to GDB-6.7.1.
46
47 2007-11-02 Jan Kratochvil <jan.kratochvil@××××××.com>
48
49 Port to post-GDB-6.7.1 multi-PC breakpoints.
50
51 2007-11-09 Jan Kratochvil <jan.kratochvil@××××××.com>
52
53 * solib-svr4.c (svr4_current_sos): Fix segfault on NULL EXEC_BFD.
54
55 2008-02-24 Jan Kratochvil <jan.kratochvil@××××××.com>
56
57 Port to GDB-6.8pre.
58
59 2008-02-27 Jan Kratochvil <jan.kratochvil@××××××.com>
60
61 Port to gdb-6.7.50.20080227.
62
63 Index: gdb/dwarf2read.c
64 ===================================================================
65 --- gdb/dwarf2read.c 2008-02-27 08:57:20.000000000 +0100
66 +++ gdb/dwarf2read.c 2008-02-27 08:57:31.000000000 +0100
67 @@ -1217,7 +1217,7 @@ dwarf2_build_psymtabs (struct objfile *o
68 else
69 dwarf2_per_objfile->loc_buffer = NULL;
70
71 - if (mainline
72 + if ((mainline == 1)
73 || (objfile->global_psymbols.size == 0
74 && objfile->static_psymbols.size == 0))
75 {
76 Index: gdb/auxv.c
77 ===================================================================
78 --- gdb/auxv.c 2008-01-16 17:27:37.000000000 +0100
79 +++ gdb/auxv.c 2008-02-27 08:57:31.000000000 +0100
80 @@ -80,7 +80,7 @@ procfs_xfer_auxv (struct target_ops *ops
81 Return 1 if an entry was read into *TYPEP and *VALP. */
82 int
83 target_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
84 - gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
85 + gdb_byte *endptr, ULONGEST *typep, CORE_ADDR *valp)
86 {
87 const int sizeof_auxv_field = TYPE_LENGTH (builtin_type_void_data_ptr);
88 gdb_byte *ptr = *readptr;
89 @@ -105,9 +105,10 @@ target_auxv_parse (struct target_ops *op
90 an error getting the information. On success, return 1 after
91 storing the entry's value field in *VALP. */
92 int
93 -target_auxv_search (struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
94 +target_auxv_search (struct target_ops *ops, ULONGEST match, CORE_ADDR *valp)
95 {
96 - CORE_ADDR type, val;
97 + CORE_ADDR val;
98 + ULONGEST at_type;
99 gdb_byte *data;
100 LONGEST n = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL, &data);
101 gdb_byte *ptr = data;
102 @@ -117,10 +118,10 @@ target_auxv_search (struct target_ops *o
103 return n;
104
105 while (1)
106 - switch (target_auxv_parse (ops, &ptr, data + n, &type, &val))
107 + switch (target_auxv_parse (ops, &ptr, data + n, &at_type, &val))
108 {
109 case 1: /* Here's an entry, check it. */
110 - if (type == match)
111 + if (at_type == match)
112 {
113 xfree (data);
114 *valp = val;
115 @@ -143,7 +144,8 @@ target_auxv_search (struct target_ops *o
116 int
117 fprint_target_auxv (struct ui_file *file, struct target_ops *ops)
118 {
119 - CORE_ADDR type, val;
120 + CORE_ADDR val;
121 + ULONGEST at_type;
122 gdb_byte *data;
123 LONGEST len = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL,
124 &data);
125 @@ -153,14 +155,14 @@ fprint_target_auxv (struct ui_file *file
126 if (len <= 0)
127 return len;
128
129 - while (target_auxv_parse (ops, &ptr, data + len, &type, &val) > 0)
130 + while (target_auxv_parse (ops, &ptr, data + len, &at_type, &val) > 0)
131 {
132 extern int addressprint;
133 const char *name = "???";
134 const char *description = "";
135 enum { dec, hex, str } flavor = hex;
136
137 - switch (type)
138 + switch (at_type)
139 {
140 #define TAG(tag, text, kind) \
141 case tag: name = #tag; description = text; flavor = kind; break
142 @@ -213,7 +215,7 @@ fprint_target_auxv (struct ui_file *file
143 }
144
145 fprintf_filtered (file, "%-4s %-20s %-30s ",
146 - paddr_d (type), name, description);
147 + paddr_d (at_type), name, description);
148 switch (flavor)
149 {
150 case dec:
151 Index: gdb/auxv.h
152 ===================================================================
153 --- gdb/auxv.h 2008-01-01 23:53:09.000000000 +0100
154 +++ gdb/auxv.h 2008-02-27 08:57:31.000000000 +0100
155 @@ -35,14 +35,14 @@ struct target_ops; /* Forward declarati
156 Return 1 if an entry was read into *TYPEP and *VALP. */
157 extern int target_auxv_parse (struct target_ops *ops,
158 gdb_byte **readptr, gdb_byte *endptr,
159 - CORE_ADDR *typep, CORE_ADDR *valp);
160 + ULONGEST *typep, CORE_ADDR *valp);
161
162 /* Extract the auxiliary vector entry with a_type matching MATCH.
163 Return zero if no such entry was found, or -1 if there was
164 an error getting the information. On success, return 1 after
165 storing the entry's value field in *VALP. */
166 extern int target_auxv_search (struct target_ops *ops,
167 - CORE_ADDR match, CORE_ADDR *valp);
168 + ULONGEST match, CORE_ADDR *valp);
169
170 /* Print the contents of the target's AUXV on the specified file. */
171 extern int fprint_target_auxv (struct ui_file *file, struct target_ops *ops);
172 Index: gdb/breakpoint.h
173 ===================================================================
174 --- gdb/breakpoint.h 2008-02-01 17:24:46.000000000 +0100
175 +++ gdb/breakpoint.h 2008-02-27 08:57:31.000000000 +0100
176 @@ -144,6 +144,7 @@ enum enable_state
177 automatically enabled and reset when the call
178 "lands" (either completes, or stops at another
179 eventpoint). */
180 + bp_startup_disabled,
181 bp_permanent /* There is a breakpoint instruction hard-wired into
182 the target's code. Don't try to write another
183 breakpoint instruction on top of it, or restore
184 @@ -823,6 +824,10 @@ extern void remove_thread_event_breakpoi
185
186 extern void disable_breakpoints_in_shlibs (void);
187
188 +extern void disable_breakpoints_at_startup (int silent);
189 +
190 +extern void re_enable_breakpoints_at_startup (void);
191 +
192 /* This function returns TRUE if ep is a catchpoint. */
193 extern int ep_is_catchpoint (struct breakpoint *);
194
195 Index: gdb/symfile-mem.c
196 ===================================================================
197 --- gdb/symfile-mem.c 2008-01-01 23:53:13.000000000 +0100
198 +++ gdb/symfile-mem.c 2008-02-27 08:57:31.000000000 +0100
199 @@ -108,7 +108,7 @@ symbol_file_add_from_memory (struct bfd
200 }
201
202 objf = symbol_file_add_from_bfd (nbfd, from_tty,
203 - sai, 0, OBJF_SHARED);
204 + sai, 2, OBJF_SHARED);
205
206 /* This might change our ideas about frames already looked at. */
207 reinit_frame_cache ();
208 Index: gdb/infrun.c
209 ===================================================================
210 --- gdb/infrun.c 2008-02-27 08:57:20.000000000 +0100
211 +++ gdb/infrun.c 2008-02-27 08:57:31.000000000 +0100
212 @@ -2277,6 +2277,11 @@ process_event_stop_test:
213 #endif
214 target_terminal_inferior ();
215
216 + /* For PIE executables, we dont really know where the
217 + breakpoints are going to be until we start up the
218 + inferior. */
219 + re_enable_breakpoints_at_startup ();
220 +
221 /* If requested, stop when the dynamic linker notifies
222 gdb of events. This allows the user to get control
223 and place breakpoints in initializer routines for
224 Index: gdb/objfiles.c
225 ===================================================================
226 --- gdb/objfiles.c 2008-01-01 23:53:12.000000000 +0100
227 +++ gdb/objfiles.c 2008-02-27 08:57:31.000000000 +0100
228 @@ -49,6 +49,9 @@
229 #include "source.h"
230 #include "addrmap.h"
231
232 +#include "auxv.h"
233 +#include "elf/common.h"
234 +
235 /* Prototypes for local functions */
236
237 static void objfile_alloc_data (struct objfile *objfile);
238 @@ -260,7 +263,19 @@ init_entry_point_info (struct objfile *o
239 CORE_ADDR
240 entry_point_address (void)
241 {
242 - return symfile_objfile ? symfile_objfile->ei.entry_point : 0;
243 + int ret;
244 + CORE_ADDR entry_addr;
245 +
246 + /* Find the address of the entry point of the program from the
247 + auxv vector. */
248 + ret = target_auxv_search (&current_target, AT_ENTRY, &entry_addr);
249 + if (ret == 1)
250 + return entry_addr;
251 + /*if (ret == 0 || ret == -1)*/
252 + else
253 + {
254 + return symfile_objfile ? symfile_objfile->ei.entry_point : 0;
255 + }
256 }
257
258 /* Create the terminating entry of OBJFILE's minimal symbol table.
259 Index: gdb/solib-svr4.c
260 ===================================================================
261 --- gdb/solib-svr4.c 2008-02-27 08:57:19.000000000 +0100
262 +++ gdb/solib-svr4.c 2008-02-27 08:59:06.000000000 +0100
263 @@ -31,6 +31,8 @@
264 #include "gdbcore.h"
265 #include "target.h"
266 #include "inferior.h"
267 +#include "auxv.h"
268 +#include "command.h"
269
270 #include "gdb_assert.h"
271
272 @@ -246,7 +248,9 @@ static char *debug_loader_name;
273
274 /* Local function prototypes */
275
276 +#if 0
277 static int match_main (char *);
278 +#endif
279
280 static CORE_ADDR bfd_lookup_symbol (bfd *, char *);
281
282 @@ -349,10 +353,12 @@ scan_dyntag (int dyntag, bfd *abfd, CORE
283 int arch_size, step, sect_size;
284 long dyn_tag;
285 CORE_ADDR dyn_ptr, dyn_addr;
286 + CORE_ADDR entry_addr;
287 gdb_byte *bufend, *bufstart, *buf;
288 Elf32_External_Dyn *x_dynp_32;
289 Elf64_External_Dyn *x_dynp_64;
290 struct bfd_section *sect;
291 + int ret;
292
293 if (abfd == NULL)
294 return 0;
295 @@ -360,19 +366,74 @@ scan_dyntag (int dyntag, bfd *abfd, CORE
296 if (arch_size == -1)
297 return 0;
298
299 + /* The auxv vector based relocatable files reading is limited to the main
300 + executable. */
301 + gdb_assert (abfd == exec_bfd || ptr == NULL);
302 +
303 + if (ptr != NULL)
304 + {
305 + /* Find the address of the entry point of the program from the
306 + auxv vector. */
307 + ret = target_auxv_search (&current_target, AT_ENTRY, &entry_addr);
308 +
309 + if (ret == 0 || ret == -1)
310 + {
311 + /* No auxv info, maybe an older kernel. Fake our way through. */
312 + entry_addr = bfd_get_start_address (exec_bfd);
313 +
314 + if (debug_solib)
315 + fprintf_unfiltered (gdb_stdlog,
316 + "elf_locate_base: program entry address not found. Using bfd's 0x%s for %s\n",
317 + paddr_nz (entry_addr), exec_bfd->filename);
318 + }
319 + else
320 + {
321 + if (debug_solib)
322 + fprintf_unfiltered (gdb_stdlog,
323 + "elf_locate_base: found program entry address 0x%s for %s\n",
324 + paddr_nz (entry_addr), exec_bfd->filename);
325 + }
326 + }
327 +
328 /* Find the start address of the .dynamic section. */
329 sect = bfd_get_section_by_name (abfd, ".dynamic");
330 if (sect == NULL)
331 - return 0;
332 + {
333 + if (debug_solib)
334 + fprintf_unfiltered (gdb_stdlog,
335 + "elf_locate_base: .dynamic section not found in %s -- return now\n",
336 + exec_bfd->filename);
337 + return 0;
338 + }
339 + else
340 + {
341 + if (debug_solib)
342 + fprintf_unfiltered (gdb_stdlog,
343 + "elf_locate_base: .dynamic section found in %s\n",
344 + exec_bfd->filename);
345 + }
346 +
347 dyn_addr = bfd_section_vma (abfd, sect);
348 + if (debug_solib)
349 + fprintf_unfiltered (gdb_stdlog,
350 + "elf_locate_base: .dynamic addr 0x%s\n",
351 + paddr_nz (dyn_addr));
352
353 /* Read in .dynamic from the BFD. We will get the actual value
354 from memory later. */
355 sect_size = bfd_section_size (abfd, sect);
356 buf = bufstart = alloca (sect_size);
357 + if (debug_solib)
358 + fprintf_unfiltered (gdb_stdlog,
359 + "elf_locate_base: read in .dynamic section\n");
360 if (!bfd_get_section_contents (abfd, sect,
361 buf, 0, sect_size))
362 - return 0;
363 + {
364 + if (debug_solib)
365 + fprintf_unfiltered (gdb_stdlog,
366 + "elf_locate_base: couldn't read .dynamic section -- return now\n");
367 + return 0;
368 + }
369
370 /* Iterate over BUF and scan for DYNTAG. If found, set PTR and return. */
371 step = (arch_size == 32) ? sizeof (Elf32_External_Dyn)
372 @@ -405,9 +466,43 @@ scan_dyntag (int dyntag, bfd *abfd, CORE
373 CORE_ADDR ptr_addr;
374
375 ptr_addr = dyn_addr + (buf - bufstart) + arch_size / 8;
376 + if (ptr != NULL)
377 + {
378 + if (debug_solib)
379 + fprintf_unfiltered (gdb_stdlog,
380 + "elf_locate_base: unrelocated ptr addr 0x%s\n",
381 + paddr_nz (ptr_addr));
382 + ptr_addr += entry_addr - bfd_get_start_address (exec_bfd);
383 + if (debug_solib)
384 + fprintf_unfiltered (gdb_stdlog,
385 + "elf_locate_base: relocated ptr addr 0x%s"
386 + " (auxv entry 0x%s, bfd start address 0x%s)"
387 + " for %s\n",
388 + paddr_nz (ptr_addr), paddr_nz (entry_addr),
389 + paddr_nz (bfd_get_start_address (exec_bfd)),
390 + exec_bfd->filename);
391 + }
392 if (target_read_memory (ptr_addr, ptr_buf, arch_size / 8) == 0)
393 - dyn_ptr = extract_typed_address (ptr_buf,
394 - builtin_type_void_data_ptr);
395 + {
396 + dyn_ptr = extract_typed_address (ptr_buf,
397 + builtin_type_void_data_ptr);
398 + if (ptr != NULL)
399 + {
400 + if (debug_solib)
401 + fprintf_unfiltered (gdb_stdlog,
402 + "elf_locate_base: Tag entry has value 0x%s -- return now\n",
403 + paddr_nz (dyn_ptr));
404 + }
405 + }
406 + else
407 + {
408 + if (ptr != NULL)
409 + {
410 + if (debug_solib)
411 + fprintf_unfiltered (gdb_stdlog,
412 + "elf_locate_base: Couldn't read tag entry value -- return now\n");
413 + }
414 + }
415 *ptr = dyn_ptr;
416 }
417 return 1;
418 @@ -544,6 +639,10 @@ solib_svr4_r_map (void)
419 {
420 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
421
422 + if (debug_solib)
423 + fprintf_unfiltered (gdb_stdlog,
424 + "solib_svr4_r_map: read at 0x%s\n",
425 + paddr_nz (debug_base + lmo->r_map_offset));
426 return read_memory_typed_address (debug_base + lmo->r_map_offset,
427 builtin_type_void_data_ptr);
428 }
429 @@ -713,6 +812,11 @@ svr4_current_sos (void)
430 struct so_list *head = 0;
431 struct so_list **link_ptr = &head;
432 CORE_ADDR ldsomap = 0;
433 + const char *filename = exec_bfd ? exec_bfd->filename : "<none>";
434 +
435 + if (debug_solib)
436 + fprintf_unfiltered (gdb_stdlog,
437 + "svr4_current_sos: exec_bfd %s\n", filename);
438
439 /* Always locate the debug struct, in case it has moved. */
440 debug_base = 0;
441 @@ -721,10 +825,19 @@ svr4_current_sos (void)
442 /* If we can't find the dynamic linker's base structure, this
443 must not be a dynamically linked executable. Hmm. */
444 if (! debug_base)
445 - return svr4_default_sos ();
446 + {
447 + if (debug_solib)
448 + fprintf_unfiltered (gdb_stdlog,
449 + "svr4_current_sos: no DT_DEBUG found in %s -- return now\n",
450 + filename);
451 + return svr4_default_sos ();
452 + }
453
454 /* Walk the inferior's link map list, and build our list of
455 `struct so_list' nodes. */
456 + if (debug_solib)
457 + fprintf_unfiltered (gdb_stdlog,
458 + "svr4_current_sos: walk link map in %s\n", filename);
459 lm = solib_svr4_r_map ();
460
461 while (lm)
462 @@ -740,23 +853,103 @@ svr4_current_sos (void)
463 new->lm_info->lm = xzalloc (lmo->link_map_size);
464 make_cleanup (xfree, new->lm_info->lm);
465
466 + if (debug_solib)
467 + fprintf_unfiltered (gdb_stdlog,
468 + "svr4_current_sos: read lm at 0x%s\n", paddr_nz(lm));
469 read_memory (lm, new->lm_info->lm, lmo->link_map_size);
470
471 lm = LM_NEXT (new);
472
473 + if (debug_solib)
474 + fprintf_unfiltered (gdb_stdlog,
475 + "svr4_current_sos: is first link entry? %d\n",
476 + IGNORE_FIRST_LINK_MAP_ENTRY (new));
477 +
478 /* For SVR4 versions, the first entry in the link map is for the
479 inferior executable, so we must ignore it. For some versions of
480 SVR4, it has no name. For others (Solaris 2.3 for example), it
481 does have a name, so we can no longer use a missing name to
482 decide when to ignore it. */
483 - if (IGNORE_FIRST_LINK_MAP_ENTRY (new) && ldsomap == 0)
484 - free_so (new);
485 + if (exec_bfd != NULL && IGNORE_FIRST_LINK_MAP_ENTRY (new) && ldsomap == 0)
486 + {
487 + /* It is the first link map entry, i.e. it is the main executable. */
488 +
489 + if (bfd_get_start_address (exec_bfd) == entry_point_address ())
490 + {
491 + /* Non-pie case, main executable has not been relocated. */
492 + free_so (new);
493 + }
494 + else
495 + {
496 + /* Pie case, main executable has been relocated. */
497 + struct so_list *gdb_solib;
498 +
499 + if (debug_solib)
500 + fprintf_unfiltered (gdb_stdlog,
501 + "svr4_current_sos: Processing first link map entry\n");
502 + strncpy (new->so_name, exec_bfd->filename,
503 + SO_NAME_MAX_PATH_SIZE - 1);
504 + new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
505 + strcpy (new->so_original_name, new->so_name);
506 + /*new->main = 1;*/
507 + new->main_relocated = 0;
508 +
509 + if (debug_solib)
510 + {
511 + fprintf_unfiltered (gdb_stdlog,
512 + "svr4_current_sos: Processing nameless DSO\n");
513 + fprintf_unfiltered (gdb_stdlog,
514 + "svr4_current_sos: adding name %s\n",
515 + new->so_name);
516 + }
517 +
518 + for (gdb_solib = master_so_list ();
519 + gdb_solib;
520 + gdb_solib = gdb_solib->next)
521 + {
522 + if (debug_solib)
523 + fprintf_unfiltered (gdb_stdlog,
524 + "svr4_current_sos: compare gdb %s and new %s\n",
525 + gdb_solib->so_name, new->so_name);
526 + if (strcmp (gdb_solib->so_name, new->so_name) == 0)
527 + if (gdb_solib->main_relocated)
528 + {
529 + if (debug_solib)
530 + fprintf_unfiltered (gdb_stdlog,
531 + "svr4_current_sos: found main relocated\n");
532 + break;
533 + }
534 + }
535 +
536 + if ((gdb_solib && !gdb_solib->main_relocated) || (!gdb_solib))
537 + {
538 + add_to_target_sections (0 /*from_tty*/, &current_target, new);
539 + new->main = 1;
540 + }
541 +
542 + /* We need this in the list of shared libs we return because
543 + solib_add_stub will loop through it and add the symbol file. */
544 + new->next = 0;
545 + *link_ptr = new;
546 + link_ptr = &new->next;
547 + }
548 + } /* End of IGNORE_FIRST_LINK_MAP_ENTRY */
549 else
550 {
551 + /* This is not the first link map entry, i.e. is not the main
552 + executable. Note however that it could be the DSO supplied on
553 + certain systems (i.e. Linux 2.6) containing information about
554 + the vsyscall page. We must ignore such entry. This entry is
555 + nameless (just like the one for the main executable, sigh). */
556 +
557 int errcode;
558 char *buffer;
559
560 /* Extract this shared object's name. */
561 + if (debug_solib)
562 + fprintf_unfiltered (gdb_stdlog,
563 + "svr4_current_sos: read LM_NAME\n");
564 +
565 target_read_string (LM_NAME (new), &buffer,
566 SO_NAME_MAX_PATH_SIZE - 1, &errcode);
567 if (errcode != 0)
568 @@ -764,23 +957,35 @@ svr4_current_sos (void)
569 safe_strerror (errcode));
570 else
571 {
572 - strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
573 - new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
574 - strcpy (new->so_original_name, new->so_name);
575 - }
576 - xfree (buffer);
577 -
578 - /* If this entry has no name, or its name matches the name
579 - for the main executable, don't include it in the list. */
580 - if (! new->so_name[0]
581 - || match_main (new->so_name))
582 - free_so (new);
583 - else
584 - {
585 - new->next = 0;
586 - *link_ptr = new;
587 - link_ptr = &new->next;
588 + if (debug_solib)
589 + fprintf_unfiltered (gdb_stdlog,
590 + "svr4_current_sos: LM_NAME is <%s>\n",
591 + buffer);
592 + /* The name could be empty, in which case it is the
593 + system supplied DSO. */
594 + if (strcmp (buffer, "") == 0)
595 + free_so (new);
596 + else
597 + {
598 + strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
599 + new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
600 + strcpy (new->so_original_name, new->so_name);
601 + if (debug_solib)
602 + {
603 + fprintf_unfiltered (gdb_stdlog,
604 + "svr4_current_sos: Processing DSO: %s\n",
605 + new->so_name);
606 + fprintf_unfiltered (gdb_stdlog,
607 + "svr4_current_sos: first link entry %d\n",
608 + IGNORE_FIRST_LINK_MAP_ENTRY (new));
609 + }
610 +
611 + new->next = 0;
612 + *link_ptr = new;
613 + link_ptr = &new->next;
614 + }
615 }
616 + xfree (buffer);
617 }
618
619 /* On Solaris, the dynamic linker is not in the normal list of
620 @@ -796,6 +1001,9 @@ svr4_current_sos (void)
621 if (head == NULL)
622 return svr4_default_sos ();
623
624 + if (debug_solib)
625 + fprintf_unfiltered (gdb_stdlog, "svr4_current_sos: ENDS %s\n", filename);
626 +
627 return head;
628 }
629
630 @@ -875,7 +1083,7 @@ svr4_fetch_objfile_link_map (struct objf
631 /* On some systems, the only way to recognize the link map entry for
632 the main executable file is by looking at its name. Return
633 non-zero iff SONAME matches one of the known main executable names. */
634 -
635 +#if 0
636 static int
637 match_main (char *soname)
638 {
639 @@ -889,6 +1097,7 @@ match_main (char *soname)
640
641 return (0);
642 }
643 +#endif
644
645 /* Return 1 if PC lies in the dynamic symbol resolution code of the
646 SVR4 run time loader. */
647 @@ -1040,6 +1249,11 @@ enable_break (void)
648 /* Find the .interp section; if not found, warn the user and drop
649 into the old breakpoint at symbol code. */
650 interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
651 +
652 + if (debug_solib)
653 + fprintf_unfiltered (gdb_stdlog,
654 + "enable_break: search for .interp in %s\n",
655 + exec_bfd->filename);
656 if (interp_sect)
657 {
658 unsigned int interp_sect_size;
659 @@ -1074,6 +1288,9 @@ enable_break (void)
660 if (tmp_fd >= 0)
661 tmp_bfd = bfd_fopen (tmp_pathname, gnutarget, FOPEN_RB, tmp_fd);
662
663 + if (debug_solib)
664 + fprintf_unfiltered (gdb_stdlog,
665 + "enable_break: opening %s\n", tmp_pathname);
666 if (tmp_bfd == NULL)
667 goto bkpt_at_symbol;
668
669 @@ -1180,6 +1397,9 @@ enable_break (void)
670 if (sym_addr != 0)
671 {
672 create_solib_event_breakpoint (load_addr + sym_addr);
673 + if (debug_solib)
674 + fprintf_unfiltered (gdb_stdlog,
675 + "enable_break: solib bp set\n");
676 return 1;
677 }
678
679 @@ -1440,6 +1660,8 @@ svr4_solib_create_inferior_hook (void)
680 while (stop_signal != TARGET_SIGNAL_TRAP);
681 stop_soon = NO_STOP_QUIETLY;
682 #endif /* defined(_SCO_DS) */
683 +
684 + disable_breakpoints_at_startup (1);
685 }
686
687 static void
688 @@ -1620,6 +1842,75 @@ svr4_lp64_fetch_link_map_offsets (void)
689
690 return lmp;
691 }
692 +void
693 +info_linkmap_command (char *cmd, int from_tty)
694 +{
695 + CORE_ADDR lm;
696 +
697 + /* Make sure we've looked up the inferior's dynamic linker's base
698 + structure. */
699 + if (! debug_base)
700 + {
701 + debug_base = locate_base ();
702 +
703 + /* If we can't find the dynamic linker's base structure, this
704 + must not be a dynamically linked executable. Hmm. */
705 + if (! debug_base)
706 + {
707 + if (debug_solib)
708 + fprintf_unfiltered (gdb_stdlog,
709 + "svr4_print_linkmap: no DT_DEBUG found in %s -- return now\n",
710 + exec_bfd->filename);
711 + return;
712 + }
713 + }
714 +
715 + /* Walk the inferior's link map list, and print the info. */
716 +
717 + lm = solib_svr4_r_map ();
718 + while (lm)
719 + {
720 + int errcode;
721 + char *buffer;
722 + CORE_ADDR load_addr;
723 +
724 + struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
725 + struct so_list *new
726 + = (struct so_list *) xmalloc (sizeof (struct so_list));
727 + struct cleanup *old_chain = make_cleanup (xfree, new);
728 +
729 + memset (new, 0, sizeof (*new));
730 +
731 + new->lm_info = xmalloc (sizeof (struct lm_info));
732 + make_cleanup (xfree, new->lm_info);
733 +
734 + new->lm_info->lm = xmalloc (lmo->link_map_size);
735 + make_cleanup (xfree, new->lm_info->lm);
736 + memset (new->lm_info->lm, 0, lmo->link_map_size);
737 +
738 + if (debug_solib)
739 + fprintf_unfiltered (gdb_stdlog,
740 + "svr4_print_linkmap: read lm at 0x%s\n", paddr_nz(lm));
741 + read_memory (lm, new->lm_info->lm, lmo->link_map_size);
742 +
743 + lm = LM_NEXT (new);
744 +
745 + /* Load address. */
746 + load_addr = LM_ADDR_CHECK (new, NULL);
747 + /* Shared object's name. */
748 + target_read_string (LM_NAME (new), &buffer,
749 + SO_NAME_MAX_PATH_SIZE - 1, &errcode);
750 + make_cleanup (xfree, buffer);
751 + if (errcode != 0)
752 + {
753 + warning ("svr4_print_linkmap: Can't read pathname for load map: %s\n",
754 + safe_strerror (errcode));
755 + }
756 + fprintf_filtered (gdb_stdout, "%-8s %-30s\n", paddr(load_addr), buffer);
757 + do_cleanups (old_chain);
758 + }
759 +}
760 +
761
762
763 struct target_so_ops svr4_so_ops;
764 @@ -1678,4 +1969,7 @@ _initialize_svr4_solib (void)
765 svr4_so_ops.in_dynsym_resolve_code = svr4_in_dynsym_resolve_code;
766 svr4_so_ops.lookup_lib_global_symbol = elf_lookup_lib_symbol;
767 svr4_so_ops.same = svr4_same;
768 +
769 + add_info ("linkmap", info_linkmap_command,
770 + "Display the inferior's linkmap.");
771 }
772 Index: gdb/varobj.c
773 ===================================================================
774 --- gdb/varobj.c 2008-02-04 08:49:04.000000000 +0100
775 +++ gdb/varobj.c 2008-02-27 08:57:31.000000000 +0100
776 @@ -1078,6 +1078,62 @@ install_new_value (struct varobj *var, s
777 return changed;
778 }
779
780 +void
781 +varobj_refresh (void)
782 +{
783 + struct varobj *var;
784 + struct varobj_root *croot;
785 + int mycount = rootcount;
786 + char * name;
787 +
788 + croot = rootlist;
789 + while ((croot != NULL) && (mycount > 0))
790 + {
791 + var = croot->rootvar;
792 +
793 + /* Get rid of the memory for the old expression. This also
794 + leaves var->root->exp == NULL, which is ok for the parsing
795 + below. */
796 + free_current_contents (&var->root->exp);
797 +
798 + value_free (var->value);
799 + var->type = NULL;
800 +
801 + name = xstrdup (var->name);
802 +
803 + /* Reparse the expression. Wrap the call to parse expression,
804 + so we can return a sensible error. */
805 + if (!gdb_parse_exp_1 (&name, var->root->valid_block, 0, &var->root->exp))
806 + {
807 + return;
808 + }
809 +
810 + /* We definitively need to catch errors here.
811 + If evaluate_expression succeeds we got the value we wanted.
812 + But if it fails, we still go on with a call to evaluate_type() */
813 + if (gdb_evaluate_expression (var->root->exp, &var->value))
814 + {
815 + /* no error */
816 + release_value (var->value);
817 + if (value_lazy (var->value))
818 + gdb_value_fetch_lazy (var->value);
819 + }
820 + else
821 + var->value = evaluate_type (var->root->exp);
822 +
823 + var->type = value_type (var->value);
824 +
825 + mycount--;
826 + croot = croot->next;
827 + }
828 +
829 + if (mycount || (croot != NULL))
830 + warning
831 + ("varobj_refresh: assertion failed - wrong tally of root vars (%d:%d)",
832 + rootcount, mycount);
833 +}
834 +
835 +
836 /* Update the values for a variable and its children. This is a
837 two-pronged attack. First, re-parse the value for the root's
838 expression to see if it's changed. Then go all the way
839 Index: gdb/solist.h
840 ===================================================================
841 --- gdb/solist.h 2008-01-07 16:19:58.000000000 +0100
842 +++ gdb/solist.h 2008-02-27 08:57:31.000000000 +0100
843 @@ -61,6 +61,8 @@ struct so_list
844 bfd *abfd;
845 char symbols_loaded; /* flag: symbols read in yet? */
846 char from_tty; /* flag: print msgs? */
847 + char main; /* flag: is this the main executable? */
848 + char main_relocated; /* flag: has it been relocated yet? */
849 struct objfile *objfile; /* objfile for loaded lib */
850 struct section_table *sections;
851 struct section_table *sections_end;
852 @@ -127,9 +129,15 @@ void free_so (struct so_list *so);
853 /* Return address of first so_list entry in master shared object list. */
854 struct so_list *master_so_list (void);
855
856 +/* Return address of first so_list entry in master shared object list. */
857 +struct so_list *master_so_list (void);
858 +
859 /* Find solib binary file and open it. */
860 extern int solib_open (char *in_pathname, char **found_pathname);
861
862 +/* Add the list of sections in so_list to the target to_sections. */
863 +extern void add_to_target_sections (int, struct target_ops *, struct so_list *);
864 +
865 /* FIXME: gdbarch needs to control this variable */
866 extern struct target_so_ops *current_target_so_ops;
867
868 @@ -140,4 +148,6 @@ struct symbol *solib_global_lookup (cons
869 const domain_enum domain,
870 struct symtab **symtab);
871
872 +/* Controls the printing of debugging output. */
873 +extern int debug_solib;
874 #endif
875 Index: gdb/varobj.h
876 ===================================================================
877 --- gdb/varobj.h 2008-01-30 08:17:31.000000000 +0100
878 +++ gdb/varobj.h 2008-02-27 08:57:31.000000000 +0100
879 @@ -122,4 +122,6 @@ extern void varobj_invalidate (void);
880
881 extern int varobj_editable_p (struct varobj *var);
882
883 +extern void varobj_refresh(void);
884 +
885 #endif /* VAROBJ_H */
886 Index: gdb/symfile.c
887 ===================================================================
888 --- gdb/symfile.c 2008-01-29 23:47:20.000000000 +0100
889 +++ gdb/symfile.c 2008-02-27 08:57:31.000000000 +0100
890 @@ -47,6 +47,7 @@
891 #include "readline/readline.h"
892 #include "gdb_assert.h"
893 #include "block.h"
894 +#include "varobj.h"
895 #include "observer.h"
896 #include "exec.h"
897 #include "parser-defs.h"
898 @@ -778,7 +779,7 @@ syms_from_objfile (struct objfile *objfi
899
900 /* Now either addrs or offsets is non-zero. */
901
902 - if (mainline)
903 + if (mainline == 1)
904 {
905 /* We will modify the main symbol table, make sure that all its users
906 will be cleaned up if an error occurs during symbol reading. */
907 @@ -806,7 +807,7 @@ syms_from_objfile (struct objfile *objfi
908
909 We no longer warn if the lowest section is not a text segment (as
910 happens for the PA64 port. */
911 - if (!mainline && addrs && addrs->other[0].name)
912 + if (/*!mainline &&*/ addrs && addrs->other[0].name)
913 {
914 asection *lower_sect;
915 asection *sect;
916 @@ -975,17 +976,21 @@ new_symfile_objfile (struct objfile *obj
917 /* If this is the main symbol file we have to clean up all users of the
918 old main symbol file. Otherwise it is sufficient to fixup all the
919 breakpoints that may have been redefined by this symbol file. */
920 - if (mainline)
921 + if (mainline == 1)
922 {
923 /* OK, make it the "real" symbol file. */
924 symfile_objfile = objfile;
925
926 clear_symtab_users ();
927 }
928 - else
929 + else if (mainline == 0)
930 {
931 breakpoint_re_set ();
932 }
933 + else
934 + {
935 + /* Don't reset breakpoints or it will screw up PIE. */
936 + }
937
938 /* We're done reading the symbol file; finish off complaints. */
939 clear_complaints (&symfile_complaints, 0, verbo);
940 @@ -1028,7 +1033,7 @@ symbol_file_add_with_addrs_or_offsets (b
941 interactively wiping out any existing symbols. */
942
943 if ((have_full_symbols () || have_partial_symbols ())
944 - && mainline
945 + && (mainline == 1)
946 && from_tty
947 && !query ("Load new symbol table from \"%s\"? ", name))
948 error (_("Not confirmed."));
949 @@ -1212,6 +1217,10 @@ symbol_file_clear (int from_tty)
950 symfile_objfile->name)
951 : !query (_("Discard symbol table? "))))
952 error (_("Not confirmed."));
953 +#ifdef CLEAR_SOLIB
954 + CLEAR_SOLIB ();
955 +#endif
956 +
957 free_all_objfiles ();
958
959 /* solib descriptors may have handles to objfiles. Since their
960 @@ -2466,6 +2475,8 @@ reread_symbols (void)
961 /* Discard cleanups as symbol reading was successful. */
962 discard_cleanups (old_cleanups);
963
964 + init_entry_point_info (objfile);
965 +
966 /* If the mtime has changed between the time we set new_modtime
967 and now, we *want* this to be out of date, so don't call stat
968 again now. */
969 @@ -2834,6 +2845,7 @@ clear_symtab_users (void)
970 breakpoint_re_set ();
971 set_default_breakpoint (0, 0, 0, 0);
972 clear_pc_function_cache ();
973 + varobj_refresh ();
974 observer_notify_new_objfile (NULL);
975
976 /* Clear globals which might have pointed into a removed objfile.
977 Index: gdb/breakpoint.c
978 ===================================================================
979 --- gdb/breakpoint.c 2008-02-27 08:57:20.000000000 +0100
980 +++ gdb/breakpoint.c 2008-02-27 08:57:31.000000000 +0100
981 @@ -923,7 +923,7 @@ update_watchpoint (struct breakpoint *b,
982 value_release_to_mark (mark);
983
984 /* Look at each value on the value chain. */
985 - for (; v; v = next)
986 + for (; v; v = value_next (v))
987 {
988 /* If it's a memory location, and GDB actually needed
989 its contents to evaluate the expression, then we
990 @@ -3882,7 +3882,8 @@ describe_other_breakpoints (CORE_ADDR pc
991 printf_filtered (" (thread %d)", b->thread);
992 printf_filtered ("%s%s ",
993 ((b->enable_state == bp_disabled ||
994 - b->enable_state == bp_call_disabled)
995 + b->enable_state == bp_call_disabled ||
996 + b->enable_state == bp_startup_disabled)
997 ? " (disabled)"
998 : b->enable_state == bp_permanent
999 ? " (permanent)"
1000 @@ -4534,6 +4535,62 @@ disable_breakpoints_in_unloaded_shlib (s
1001 }
1002 }
1003
1004 +void
1005 +disable_breakpoints_at_startup (int silent)
1006 +{
1007 + struct breakpoint *b;
1008 + int disabled_startup_breaks = 0;
1009 +
1010 + if (bfd_get_start_address (exec_bfd) != entry_point_address ())
1011 + {
1012 + ALL_BREAKPOINTS (b)
1013 + {
1014 + if (((b->type == bp_breakpoint) ||
1015 + (b->type == bp_hardware_breakpoint)) &&
1016 + b->enable_state == bp_enabled &&
1017 + !b->loc->duplicate)
1018 + {
1019 + b->enable_state = bp_startup_disabled;
1020 + if (!silent)
1021 + {
1022 + if (!disabled_startup_breaks)
1023 + {
1024 + target_terminal_ours_for_output ();
1025 + warning ("Temporarily disabling breakpoints:");
1026 + }
1027 + disabled_startup_breaks = 1;
1028 + warning ("breakpoint #%d addr 0x%s", b->number, paddr_nz(b->loc->address));
1029 + }
1030 + }
1031 + }
1032 + }
1033 +}
1034 +
1035 +/* Try to reenable any breakpoints after startup. */
1036 +void
1037 +re_enable_breakpoints_at_startup (void)
1038 +{
1039 + struct breakpoint *b;
1040 +
1041 + if (bfd_get_start_address (exec_bfd) != entry_point_address ())
1042 + {
1043 + ALL_BREAKPOINTS (b)
1044 + if (b->enable_state == bp_startup_disabled)
1045 + {
1046 + char buf[1];
1047 +
1048 + /* Do not reenable the breakpoint if the shared library
1049 + is still not mapped in. */
1050 + if (target_read_memory (b->loc->address, buf, 1) == 0)
1051 + {
1052 + /*printf ("enabling breakpoint at 0x%s\n", paddr_nz(b->loc->address));*/
1053 + b->enable_state = bp_enabled;
1054 + }
1055 + }
1056 + }
1057 +}
1058 +
1059 +
1060 static void
1061 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
1062 enum bptype bp_kind)
1063 Index: gdb/solib.c
1064 ===================================================================
1065 --- gdb/solib.c 2008-01-07 16:19:58.000000000 +0100
1066 +++ gdb/solib.c 2008-02-27 08:57:31.000000000 +0100
1067 @@ -79,6 +79,8 @@ set_solib_ops (struct gdbarch *gdbarch,
1068
1069 /* external data declarations */
1070
1071 +int debug_solib;
1072 +
1073 /* FIXME: gdbarch needs to control this variable, or else every
1074 configuration needs to call set_solib_ops. */
1075 struct target_so_ops *current_target_so_ops;
1076 @@ -102,6 +104,8 @@ The search path for loading non-absolute
1077 value);
1078 }
1079
1080 +void add_to_target_sections (int, struct target_ops *, struct so_list *);
1081 +
1082 /*
1083
1084 GLOBAL FUNCTION
1085 @@ -391,7 +395,6 @@ free_so (struct so_list *so)
1086 xfree (so);
1087 }
1088
1089 -
1090 /* Return address of first so_list entry in master shared object list. */
1091 struct so_list *
1092 master_so_list (void)
1093 @@ -399,7 +402,6 @@ master_so_list (void)
1094 return so_list_head;
1095 }
1096
1097 -
1098 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
1099
1100 static int
1101 @@ -411,15 +413,40 @@ symbol_add_stub (void *arg)
1102 /* Have we already loaded this shared object? */
1103 ALL_OBJFILES (so->objfile)
1104 {
1105 - if (strcmp (so->objfile->name, so->so_name) == 0)
1106 + /* Found an already loaded shared library. */
1107 + if (strcmp (so->objfile->name, so->so_name) == 0
1108 + && !so->main)
1109 return 1;
1110 + /* Found an already loaded main executable. This could happen in
1111 + two circumstances.
1112 + First case: the main file has already been read in
1113 + as the first thing that gdb does at startup, and the file
1114 + hasn't been relocated properly yet. Therefor we need to read
1115 + it in with the proper section info.
1116 + Second case: it has been read in with the correct relocation,
1117 + and therefore we need to skip it. */
1118 + if (strcmp (so->objfile->name, so->so_name) == 0
1119 + && so->main
1120 + && so->main_relocated)
1121 + return 1;
1122 }
1123
1124 sap = build_section_addr_info_from_section_table (so->sections,
1125 so->sections_end);
1126
1127 - so->objfile = symbol_file_add (so->so_name, so->from_tty,
1128 - sap, 0, OBJF_SHARED);
1129 + if (so->main)
1130 + {
1131 + if (debug_solib)
1132 + fprintf_unfiltered (gdb_stdlog,
1133 + "symbol_add_stub: adding symbols for main\n");
1134 + so->objfile = symbol_file_add (so->so_name, /*so->from_tty*/ 0,
1135 + sap, 1, 0);
1136 + so->main_relocated = 1;
1137 + }
1138 + else
1139 + so->objfile = symbol_file_add (so->so_name, so->from_tty,
1140 + sap, 0, OBJF_SHARED);
1141 +
1142 free_section_addr_info (sap);
1143
1144 return (1);
1145 @@ -545,6 +572,10 @@ update_solib_list (int from_tty, struct
1146 }
1147 else
1148 {
1149 + if (debug_solib)
1150 + fprintf_unfiltered (gdb_stdlog,
1151 + "update_solib_list: compare gdb:%s and inferior:%s\n",
1152 + gdb->so_original_name, i->so_original_name);
1153 if (! strcmp (gdb->so_original_name, i->so_original_name))
1154 break;
1155 }
1156 @@ -599,28 +630,7 @@ update_solib_list (int from_tty, struct
1157 /* Fill in the rest of each of the `struct so_list' nodes. */
1158 for (i = inferior; i; i = i->next)
1159 {
1160 - i->from_tty = from_tty;
1161 -
1162 - /* Fill in the rest of the `struct so_list' node. */
1163 - catch_errors (solib_map_sections, i,
1164 - "Error while mapping shared library sections:\n",
1165 - RETURN_MASK_ALL);
1166 -
1167 - /* If requested, add the shared object's sections to the TARGET's
1168 - section table. Do this immediately after mapping the object so
1169 - that later nodes in the list can query this object, as is needed
1170 - in solib-osf.c. */
1171 - if (target)
1172 - {
1173 - int count = (i->sections_end - i->sections);
1174 - if (count > 0)
1175 - {
1176 - int space = target_resize_to_sections (target, count);
1177 - memcpy (target->to_sections + space,
1178 - i->sections,
1179 - count * sizeof (i->sections[0]));
1180 - }
1181 - }
1182 + add_to_target_sections (from_tty, target, i);
1183
1184 /* Notify any observer that the shared object has been
1185 loaded now that we've added it to GDB's tables. */
1186 @@ -716,6 +726,41 @@ solib_add (char *pattern, int from_tty,
1187 }
1188 }
1189
1190 +void
1191 +add_to_target_sections (int from_tty, struct target_ops *target, struct so_list *solib)
1192 +{
1193 + /* If this is set, then the sections have been already added to the
1194 + target list. */
1195 + if (solib->main)
1196 + return;
1197 +
1198 + solib->from_tty = from_tty;
1199 +
1200 + /* Fill in the rest of the `struct so_list' node. */
1201 + catch_errors (solib_map_sections, solib,
1202 + "Error while mapping shared library sections:\n",
1203 + RETURN_MASK_ALL);
1204 +
1205 + /* If requested, add the shared object's sections to the TARGET's
1206 + section table. Do this immediately after mapping the object so
1207 + that later nodes in the list can query this object, as is needed
1208 + in solib-osf.c. */
1209 + if (target)
1210 + {
1211 + int count = (solib->sections_end - solib->sections);
1212 + if (count > 0)
1213 + {
1214 + int space = target_resize_to_sections (target, count);
1215 + if (debug_solib)
1216 + fprintf_unfiltered (gdb_stdlog,
1217 + "add_to_target_sections: add %s to to_sections\n",
1218 + solib->so_original_name);
1219 + memcpy (target->to_sections + space,
1220 + solib->sections,
1221 + count * sizeof (solib->sections[0]));
1222 + }
1223 + }
1224 +}
1225
1226 /*
1227
1228 @@ -1035,4 +1080,12 @@ This takes precedence over the environme
1229 reload_shared_libraries,
1230 show_solib_search_path,
1231 &setlist, &showlist);
1232 +
1233 + add_setshow_boolean_cmd ("solib", no_class, &debug_solib,
1234 + _("\
1235 +Set debugging of GNU/Linux shlib module.\n"), _("\
1236 +Show debugging status of GNU/Linux shlib module.\n"), _("\
1237 +Enables printf debugging output of GNU/Linux shlib module.\n"),
1238 + NULL, NULL,
1239 + &setdebuglist, &showdebuglist);
1240 }
1241 Index: gdb/elfread.c
1242 ===================================================================
1243 --- gdb/elfread.c 2008-01-01 23:53:09.000000000 +0100
1244 +++ gdb/elfread.c 2008-02-27 08:57:31.000000000 +0100
1245 @@ -644,7 +644,7 @@ elf_symfile_read (struct objfile *objfil
1246 /* If we are reinitializing, or if we have never loaded syms yet,
1247 set table to empty. MAINLINE is cleared so that *_read_psymtab
1248 functions do not all also re-initialize the psymbol table. */
1249 - if (mainline)
1250 + if (mainline == 1)
1251 {
1252 init_psymbol_list (objfile, 0);
1253 mainline = 0;
1254 Index: gdb/Makefile.in
1255 ===================================================================
1256 --- gdb/Makefile.in 2008-02-27 08:57:20.000000000 +0100
1257 +++ gdb/Makefile.in 2008-02-27 08:57:31.000000000 +0100
1258 @@ -1914,7 +1914,7 @@ amd64-tdep.o: amd64-tdep.c $(defs_h) $(a
1259 $(dummy_frame_h) $(frame_h) $(frame_base_h) $(frame_unwind_h) \
1260 $(inferior_h) $(gdbcmd_h) $(gdbcore_h) $(objfiles_h) $(regcache_h) \
1261 $(regset_h) $(symfile_h) $(gdb_assert_h) $(amd64_tdep_h) \
1262 - $(i387_tdep_h)
1263 + $(i387_tdep_h) $(exceptions_h)
1264 annotate.o: annotate.c $(defs_h) $(annotate_h) $(value_h) $(target_h) \
1265 $(gdbtypes_h) $(breakpoint_h)
1266 arch-utils.o: arch-utils.c $(defs_h) $(arch_utils_h) $(buildsym_h) \
1267 Index: gdb/amd64-tdep.c
1268 ===================================================================
1269 --- gdb/amd64-tdep.c 2008-02-27 08:57:19.000000000 +0100
1270 +++ gdb/amd64-tdep.c 2008-02-27 08:57:31.000000000 +0100
1271 @@ -36,6 +36,7 @@
1272 #include "symfile.h"
1273 #include "dwarf2-frame.h"
1274 #include "gdb_assert.h"
1275 +#include "exceptions.h"
1276
1277 #include "amd64-tdep.h"
1278 #include "i387-tdep.h"
1279 @@ -731,16 +732,28 @@ amd64_alloc_frame_cache (void)
1280 Any function that doesn't start with this sequence will be assumed
1281 to have no prologue and thus no valid frame pointer in %rbp. */
1282
1283 -static CORE_ADDR
1284 -amd64_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
1285 - struct amd64_frame_cache *cache)
1286 +struct amd64_analyze_prologue_data
1287 + {
1288 + CORE_ADDR pc, current_pc;
1289 + struct amd64_frame_cache *cache;
1290 + CORE_ADDR retval;
1291 + };
1292 +
1293 +static int
1294 +amd64_analyze_prologue_1 (void *data_pointer)
1295 {
1296 + struct amd64_analyze_prologue_data *data = data_pointer;
1297 + CORE_ADDR pc = data->pc, current_pc = data->current_pc;
1298 + struct amd64_frame_cache *cache = data->cache;
1299 static gdb_byte proto[3] = { 0x48, 0x89, 0xe5 }; /* movq %rsp, %rbp */
1300 gdb_byte buf[3];
1301 gdb_byte op;
1302
1303 if (current_pc <= pc)
1304 - return current_pc;
1305 + {
1306 + data->retval = current_pc;
1307 + return 1;
1308 + }
1309
1310 op = read_memory_unsigned_integer (pc, 1);
1311
1312 @@ -753,18 +766,57 @@ amd64_analyze_prologue (CORE_ADDR pc, CO
1313
1314 /* If that's all, return now. */
1315 if (current_pc <= pc + 1)
1316 - return current_pc;
1317 + {
1318 + data->retval = current_pc;
1319 + return 1;
1320 + }
1321
1322 /* Check for `movq %rsp, %rbp'. */
1323 read_memory (pc + 1, buf, 3);
1324 if (memcmp (buf, proto, 3) != 0)
1325 - return pc + 1;
1326 + {
1327 + data->retval = pc + 1;
1328 + return 1;
1329 + }
1330
1331 /* OK, we actually have a frame. */
1332 cache->frameless_p = 0;
1333 - return pc + 4;
1334 + data->retval = pc + 4;
1335 + return 1;
1336 }
1337
1338 + data->retval = pc;
1339 + return 1;
1340 +}
1341 +
1342 +/* Catch memory read errors and return just PC in such case.
1343 + It occurs very early on enable_break->new_symfile_objfile->
1344 + ->breakpoint_re_set->decode_line_1->decode_variable_1->
1345 + ->find_function_start_sal */
1346 +
1347 +static CORE_ADDR
1348 +amd64_analyze_prologue (CORE_ADDR pc, CORE_ADDR current_pc,
1349 + struct amd64_frame_cache *cache)
1350 +{
1351 + int status;
1352 + struct amd64_analyze_prologue_data data;
1353 + struct ui_file *saved_gdb_stderr;
1354 +
1355 + /* Suppress error messages. */
1356 + saved_gdb_stderr = gdb_stderr;
1357 + gdb_stderr = ui_file_new ();
1358 +
1359 + data.pc = pc;
1360 + data.current_pc = current_pc;
1361 + data.cache = cache;
1362 + status = catch_errors (amd64_analyze_prologue_1, &data, "", RETURN_MASK_ALL);
1363 +
1364 + /* Stop suppressing error messages. */
1365 + ui_file_delete (gdb_stderr);
1366 + gdb_stderr = saved_gdb_stderr;
1367 +
1368 + if (status)
1369 + return data.retval;
1370 return pc;
1371 }
1372
1373
1374
1375
1376 1.1 src/patchsets/gdb/6.8/50_all_gdb-pie-2.patch
1377
1378 file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/50_all_gdb-pie-2.patch?rev=1.1&view=markup
1379 plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/gdb/6.8/50_all_gdb-pie-2.patch?rev=1.1&content-type=text/plain
1380
1381 Index: 50_all_gdb-pie-2.patch
1382 ===================================================================
1383 http://bugs.gentoo.org/223533
1384
1385 Index: gdb-6.8/gdb/testsuite/configure
1386 ===================================================================
1387 --- gdb-6.8.orig/gdb/testsuite/configure 2007-12-29 06:01:30.000000000 -0800
1388 +++ gdb-6.8/gdb/testsuite/configure 2008-03-30 09:00:52.000000000 -0700
1389 @@ -3104,7 +3104,7 @@
1390
1391
1392
1393 - ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.fortran/Makefile gdb.server/Makefile gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile"
1394 + ac_config_files="$ac_config_files Makefile gdb.ada/Makefile gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile gdb.fortran/Makefile gdb.server/Makefile gdb.pie/Makefile gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile"
1395 cat >confcache <<\_ACEOF
1396 # This file is a shell script that caches the results of configure
1397 # tests run on this system so they can be shared between configure
1398 @@ -3665,6 +3665,7 @@
1399 "gdb.dwarf2/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.dwarf2/Makefile" ;;
1400 "gdb.fortran/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.fortran/Makefile" ;;
1401 "gdb.server/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.server/Makefile" ;;
1402 + "gdb.pie/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.pie/Makefile" ;;
1403 "gdb.java/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.java/Makefile" ;;
1404 "gdb.mi/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.mi/Makefile" ;;
1405 "gdb.modula2/Makefile" ) CONFIG_FILES="$CONFIG_FILES gdb.modula2/Makefile" ;;
1406 Index: gdb-6.8/gdb/testsuite/configure.ac
1407 ===================================================================
1408 --- gdb-6.8.orig/gdb/testsuite/configure.ac 2007-10-25 13:30:26.000000000 -0700
1409 +++ gdb-6.8/gdb/testsuite/configure.ac 2008-03-30 09:00:22.000000000 -0700
1410 @@ -114,7 +114,7 @@
1411 gdb.ada/Makefile \
1412 gdb.arch/Makefile gdb.asm/Makefile gdb.base/Makefile \
1413 gdb.cp/Makefile gdb.disasm/Makefile gdb.dwarf2/Makefile \
1414 - gdb.fortran/Makefile gdb.server/Makefile \
1415 + gdb.fortran/Makefile gdb.server/Makefile gdb.pie/Makefile \
1416 gdb.java/Makefile gdb.mi/Makefile gdb.modula2/Makefile \
1417 gdb.objc/Makefile gdb.opt/Makefile gdb.pascal/Makefile \
1418 gdb.threads/Makefile gdb.trace/Makefile gdb.xml/Makefile])
1419 Index: gdb-6.8/gdb/testsuite/gdb.pie/Makefile.in
1420 ===================================================================
1421 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1422 +++ gdb-6.8/gdb/testsuite/gdb.pie/Makefile.in 2008-03-30 08:59:12.000000000 -0700
1423 @@ -0,0 +1,19 @@
1424 +VPATH = @srcdir@
1425 +srcdir = @srcdir@
1426 +
1427 +EXECUTABLES =
1428 +MISCELLANEOUS = arch.inc
1429 +
1430 +all info install-info dvi install uninstall installcheck check:
1431 + @echo "Nothing to be done for $@..."
1432 +
1433 +clean mostlyclean:
1434 + -rm -f *~ *.o a.out *.x *.ci *.tmp
1435 + -rm -f core core.coremaker coremaker.core corefile $(EXECUTABLES)
1436 + -rm -f $(MISCELLANEOUS)
1437 +
1438 +distclean maintainer-clean realclean: clean
1439 + -rm -f *~ core
1440 + -rm -f Makefile config.status config.log
1441 + -rm -f *-init.exp
1442 + -rm -fr *.log summary detail *.plog *.sum *.psum site.*
1443 Index: gdb-6.8/gdb/testsuite/gdb.pie/attach.c
1444 ===================================================================
1445 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1446 +++ gdb-6.8/gdb/testsuite/gdb.pie/attach.c 2008-03-30 08:59:12.000000000 -0700
1447 @@ -0,0 +1,20 @@
1448 +/* This program is intended to be started outside of gdb, and then
1449 + attached to by gdb. Thus, it simply spins in a loop. The loop
1450 + is exited when & if the variable 'should_exit' is non-zero. (It
1451 + is initialized to zero in this program, so the loop will never
1452 + exit unless/until gdb sets the variable to non-zero.)
1453 + */
1454 +#include <stdio.h>
1455 +
1456 +int should_exit = 0;
1457 +
1458 +int main ()
1459 +{
1460 + int local_i = 0;
1461 +
1462 + while (! should_exit)
1463 + {
1464 + local_i++;
1465 + }
1466 + return 0;
1467 +}
1468 Index: gdb-6.8/gdb/testsuite/gdb.pie/attach.exp
1469 ===================================================================
1470 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1471 +++ gdb-6.8/gdb/testsuite/gdb.pie/attach.exp 2008-03-30 08:59:12.000000000 -0700
1472 @@ -0,0 +1,432 @@
1473 +# Copyright 1997, 1999, 2002 Free Software Foundation, Inc.
1474 +
1475 +# This program is free software; you can redistribute it and/or modify
1476 +# it under the terms of the GNU General Public License as published by
1477 +# the Free Software Foundation; either version 2 of the License, or
1478 +# (at your option) any later version.
1479 +#
1480 +# This program is distributed in the hope that it will be useful,
1481 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1482 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1483 +# GNU General Public License for more details.
1484 +#
1485 +# You should have received a copy of the GNU General Public License
1486 +# along with this program; if not, write to the Free Software
1487 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
1488 +
1489 +# Please email any bugs, comments, and/or additions to this file to:
1490 +# bug-gdb@×××××××××××.edu
1491 +
1492 +if $tracelevel then {
1493 + strace $tracelevel
1494 + }
1495 +
1496 +set prms_id 0
1497 +set bug_id 0
1498 +
1499 +# On HP-UX 11.0, this test is causing a process running the program
1500 +# "attach" to be left around spinning. Until we figure out why, I am
1501 +# commenting out the test to avoid polluting tiamat (our 11.0 nightly
1502 +# test machine) with these processes. RT
1503 +#
1504 +# Setting the magic bit in the target app should work. I added a
1505 +# "kill", and also a test for the R3 register warning. JB
1506 +if { [istarget "hppa*-*-hpux*"] } {
1507 + return 0
1508 +}
1509 +
1510 +# are we on a target board
1511 +if [is_remote target] then {
1512 + return 0
1513 +}
1514 +
1515 +set testfile "attach"
1516 +set srcfile ${testfile}.c
1517 +set srcfile2 ${testfile}2.c
1518 +set binfile ${objdir}/${subdir}/${testfile}
1519 +set binfile2 ${objdir}/${subdir}/${testfile}2
1520 +set escapedbinfile [string_to_regexp ${objdir}/${subdir}/${testfile}]
1521 +set cleanupfile ${objdir}/${subdir}/${testfile}.awk
1522 +
1523 +#execute_anywhere "rm -f ${binfile} ${binfile2}"
1524 +remote_exec build "rm -f ${binfile} ${binfile2}"
1525 +# For debugging this test
1526 +#
1527 +#log_user 1
1528 +
1529 +# Clean out any old files from past runs.
1530 +#
1531 +remote_exec build "${cleanupfile}"
1532 +
1533 +# build the first test case
1534 +#
1535 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags= -fpie -pie"}] != "" } {
1536 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
1537 +}
1538 +
1539 +# Build the in-system-call test
1540 +
1541 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug "additional_flags= -fpie -pie"}] != "" } {
1542 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
1543 +}
1544 +
1545 +if [get_compiler_info ${binfile}] {
1546 + return -1
1547 +}
1548 +
1549 +proc do_attach_tests {} {
1550 + global gdb_prompt
1551 + global binfile
1552 + global escapedbinfile
1553 + global srcfile
1554 + global testfile
1555 + global objdir
1556 + global subdir
1557 + global timeout
1558 +
1559 + # Start the program running and then wait for a bit, to be sure
1560 + # that it can be attached to.
1561 + #
1562 + set testpid [eval exec $binfile &]
1563 + exec sleep 2
1564 +
1565 + # Verify that we cannot attach to nonsense.
1566 + #
1567 + send_gdb "attach abc\n"
1568 + gdb_expect {
1569 + -re ".*Illegal process-id: abc.*$gdb_prompt $"\
1570 + {pass "attach to nonsense is prohibited"}
1571 + -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
1572 + {
1573 + # Response expected from /proc-based systems.
1574 + pass "attach to nonsense is prohibited"
1575 + }
1576 + -re "Attaching to.*$gdb_prompt $"\
1577 + {fail "attach to nonsense is prohibited (bogus pid allowed)"}
1578 + -re "$gdb_prompt $" {fail "attach to nonsense is prohibited"}
1579 + timeout {fail "(timeout) attach to nonsense is prohibited"}
1580 + }
1581 +
1582 + # Verify that we cannot attach to what appears to be a valid
1583 + # process ID, but is a process that doesn't exist. Traditionally,
1584 + # most systems didn't have a process with ID 0, so we take that as
1585 + # the default. However, there are a few exceptions.
1586 + #
1587 + set boguspid 0
1588 + if { [istarget "*-*-*bsd*"] } {
1589 + # In FreeBSD 5.0, PID 0 is used for "swapper". Use -1 instead
1590 + # (which should have the desired effect on any version of
1591 + # FreeBSD, and probably other *BSD's too).
1592 + set boguspid -1
1593 + }
1594 + send_gdb "attach $boguspid\n"
1595 + gdb_expect {
1596 + -re "Attaching to.*, process $boguspid.*No such process.*$gdb_prompt $"\
1597 + {
1598 + # Response expected on ptrace-based systems (i.e. HP-UX 10.20).
1599 + pass "attach to nonexistent process is prohibited"
1600 + }
1601 + -re "Attaching to.*, process $boguspid failed.*Hint.*$gdb_prompt $"\
1602 + {
1603 + # Response expected on ttrace-based systems (i.e. HP-UX 11.0).
1604 + pass "attach to nonexistent process is prohibited"
1605 + }
1606 + -re "Attaching to.*, process $boguspid.*denied.*$gdb_prompt $"\
1607 + {pass "attach to nonexistent process is prohibited"}
1608 + -re "Attaching to.*, process $boguspid.*not permitted.*$gdb_prompt $"\
1609 + {pass "attach to nonexistent process is prohibited"}
1610 + -re "Attaching to.*, process .*couldn't open /proc file.*$gdb_prompt $"\
1611 + {
1612 + # Response expected from /proc-based systems.
1613 + pass "attach to nonexistent process is prohibited"
1614 + }
1615 + -re "$gdb_prompt $" {fail "attach to nonexistent process is prohibited"}
1616 + timeout {
1617 + fail "(timeout) attach to nonexistent process is prohibited"
1618 + }
1619 + }
1620 +
1621 + # Verify that we can attach to the process by first giving its
1622 + # executable name via the file command, and using attach with
1623 + # the process ID.
1624 + #
1625 + # (Actually, the test system appears to do this automatically
1626 + # for us. So, we must also be prepared to be asked if we want
1627 + # to discard an existing set of symbols.)
1628 + #
1629 + send_gdb "file $binfile\n"
1630 + gdb_expect {
1631 + -re "Load new symbol table from.*y or n.*$" {
1632 + send_gdb "y\n"
1633 + gdb_expect {
1634 + -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
1635 + {pass "(re)set file, before attach1"}
1636 + -re "$gdb_prompt $" {fail "(re)set file, before attach1"}
1637 + timeout {fail "(timeout) (re)set file, before attach1"}
1638 + }
1639 + }
1640 + -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $"\
1641 + {pass "set file, before attach1"}
1642 + -re "$gdb_prompt $" {fail "set file, before attach1"}
1643 + timeout {fail "(timeout) set file, before attach1"}
1644 + }
1645 +
1646 + send_gdb "attach $testpid\n"
1647 + gdb_expect {
1648 + -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*main.*at .*$srcfile:.*$gdb_prompt $"\
1649 + {pass "attach1, after setting file"}
1650 + -re "$gdb_prompt $" {fail "attach1, after setting file"}
1651 + timeout {fail "(timeout) attach1, after setting file"}
1652 + }
1653 +
1654 + # Verify that we can "see" the variable "should_exit" in the
1655 + # program, and that it is zero.
1656 + #
1657 + send_gdb "print should_exit\n"
1658 + gdb_expect {
1659 + -re ".* = 0.*$gdb_prompt $"\
1660 + {pass "after attach1, print should_exit"}
1661 + -re "$gdb_prompt $" {fail "after attach1, print should_exit"}
1662 + timeout {fail "(timeout) after attach1, print should_exit"}
1663 + }
1664 +
1665 + # Detach the process.
1666 + #
1667 + send_gdb "detach\n"
1668 + gdb_expect {
1669 + -re "Detaching from program: .*$escapedbinfile.*$gdb_prompt $"\
1670 + {pass "attach1 detach"}
1671 + -re "$gdb_prompt $" {fail "attach1 detach"}
1672 + timeout {fail "(timeout) attach1 detach"}
1673 + }
1674 +
1675 + # Wait a bit for gdb to finish detaching
1676 + #
1677 + exec sleep 5
1678 +
1679 + # Purge the symbols from gdb's brain. (We want to be certain
1680 + # the next attach, which won't be preceded by a "file" command,
1681 + # is really getting the executable file without our help.)
1682 + #
1683 + set old_timeout $timeout
1684 + set timeout 15
1685 + send_gdb "file\n"
1686 + gdb_expect {
1687 + -re ".*gdb internal error.*$" {
1688 + fail "Internal error, prob. Memory corruption"
1689 + }
1690 + -re "No executable file now.*Discard symbol table.*y or n.*$" {
1691 + send_gdb "y\n"
1692 + gdb_expect {
1693 + -re "No symbol file now.*$gdb_prompt $"\
1694 + {pass "attach1, purging symbols after detach"}
1695 + -re "$gdb_prompt $" {fail "attach1, purging symbols after detach"}
1696 + timeout {fail "(timeout) attach1, purging symbols after detach"}
1697 + }
1698 + }
1699 + -re "$gdb_prompt $" {fail "attach1, purging file after detach"}
1700 + timeout {
1701 + fail "(timeout) attach1, purging file after detach"
1702 + }
1703 + }
1704 + set timeout $old_timeout
1705 +
1706 + # Verify that we can attach to the process just by giving the
1707 + # process ID.
1708 + #
1709 + send_gdb "attach $testpid\n"
1710 + gdb_expect {
1711 + -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
1712 + {pass "attach2"}
1713 + -re "$gdb_prompt $" {fail "attach2"}
1714 + timeout {fail "(timeout) attach2"}
1715 + }
1716 +
1717 + # Verify that we can modify the variable "should_exit" in the
1718 + # program.
1719 + #
1720 + send_gdb "set should_exit=1\n"
1721 + gdb_expect {
1722 + -re "$gdb_prompt $" {pass "after attach2, set should_exit"}
1723 + timeout {fail "(timeout) after attach2, set should_exit"}
1724 + }
1725 +
1726 + # Verify that the modification really happened.
1727 + #
1728 + send_gdb "tbreak 19\n"
1729 + gdb_expect {
1730 + -re "Breakpoint .*at.*$srcfile, line 19.*$gdb_prompt $"\
1731 + {pass "after attach2, set tbreak postloop"}
1732 + -re "$gdb_prompt $" {fail "after attach2, set tbreak postloop"}
1733 + timeout {fail "(timeout) after attach2, set tbreak postloop"}
1734 + }
1735 + send_gdb "continue\n"
1736 + gdb_expect {
1737 + -re "main.*at.*$srcfile:19.*$gdb_prompt $"\
1738 + {pass "after attach2, reach tbreak postloop"}
1739 + -re "$gdb_prompt $" {fail "after attach2, reach tbreak postloop"}
1740 + timeout {fail "(timeout) after attach2, reach tbreak postloop"}
1741 + }
1742 +
1743 + # Allow the test process to exit, to cleanup after ourselves.
1744 + #
1745 + send_gdb "continue\n"
1746 + gdb_expect {
1747 + -re "Program exited normally.*$gdb_prompt $"\
1748 + {pass "after attach2, exit"}
1749 + -re "$gdb_prompt $" {fail "after attach2, exit"}
1750 + timeout {fail "(timeout) after attach2, exit"}
1751 + }
1752 +
1753 + # Make sure we don't leave a process around to confuse
1754 + # the next test run (and prevent the compile by keeping
1755 + # the text file busy), in case the "set should_exit" didn't
1756 + # work.
1757 + #
1758 + remote_exec build "kill -9 ${testpid}"
1759 + # Start the program running and then wait for a bit, to be sure
1760 + # that it can be attached to.
1761 + #
1762 + set testpid [eval exec $binfile &]
1763 + exec sleep 2
1764 +
1765 + # Verify that we can attach to the process, and find its a.out
1766 + # when we're cd'd to some directory that doesn't contain the
1767 + # a.out. (We use the source path set by the "dir" command.)
1768 + #
1769 + send_gdb "dir ${objdir}/${subdir}\n"
1770 + gdb_expect {
1771 + -re ".*Source directories searched: .*$gdb_prompt $"\
1772 + {pass "set source path"}
1773 + -re "$gdb_prompt $" {fail "set source path"}
1774 + timeout {fail "(timeout) set source path"}
1775 + }
1776 +
1777 + send_gdb "cd /tmp\n"
1778 + gdb_expect {
1779 + -re ".*Working directory /tmp.*$gdb_prompt $"\
1780 + {pass "cd away from process' a.out"}
1781 + -re "$gdb_prompt $" {fail "cd away from process' a.out"}
1782 + timeout {fail "(timeout) cd away from process' a.out"}
1783 + }
1784 +
1785 + # Explicitly flush out any knowledge of the previous attachment.
1786 + send_gdb "symbol\n"
1787 + gdb_expect {
1788 + -re ".*Discard symbol table from.*y or n. $"\
1789 + {send_gdb "y\n"
1790 + gdb_expect {
1791 + -re ".*No symbol file now.*$gdb_prompt $"\
1792 + {pass "before attach3, flush symbols"}
1793 + -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
1794 + timeout {fail "(timeout) before attach3, flush symbols"}
1795 + }
1796 + }
1797 + -re ".*No symbol file now.*$gdb_prompt $"\
1798 + {pass "before attach3, flush symbols"}
1799 + -re "$gdb_prompt $" {fail "before attach3, flush symbols"}
1800 + timeout {fail "(timeout) before attach3, flush symbols"}
1801 + }
1802 + send_gdb "exec\n"
1803 + gdb_expect {
1804 + -re ".*No executable file now.*$gdb_prompt $"\
1805 + {pass "before attach3, flush exec"}
1806 + -re "$gdb_prompt $" {fail "before attach3, flush exec"}
1807 + timeout {fail "(timeout) before attach3, flush exec"}
1808 + }
1809 +
1810 + send_gdb "attach $testpid\n"
1811 + gdb_expect {
1812 + -re "Attaching to process $testpid.*Reading symbols from $escapedbinfile.*main.*at .*$gdb_prompt $"\
1813 + {pass "attach when process' a.out not in cwd"}
1814 + -re "$gdb_prompt $" {fail "attach when process' a.out not in cwd"}
1815 + timeout {fail "(timeout) attach when process' a.out not in cwd"}
1816 + }
1817 +
1818 + send_gdb "kill\n"
1819 + gdb_expect {
1820 + -re ".*Kill the program being debugged.*y or n. $"\
1821 + {send_gdb "y\n"
1822 + gdb_expect {
1823 + -re "$gdb_prompt $" {pass "after attach3, exit"}
1824 + timeout {fail "(timeout) after attach3, exit"}
1825 + }
1826 + }
1827 + -re "$gdb_prompt $" {fail "after attach3, exit"}
1828 + timeout {fail "(timeout) after attach3, exit"}
1829 + }
1830 +
1831 + # Another "don't leave a process around"
1832 + remote_exec build "kill -9 ${testpid}"
1833 +}
1834 +
1835 +proc do_call_attach_tests {} {
1836 + global gdb_prompt
1837 + global binfile2
1838 +
1839 + # Start the program running and then wait for a bit, to be sure
1840 + # that it can be attached to.
1841 + #
1842 + set testpid [eval exec $binfile2 &]
1843 + exec sleep 2
1844 +
1845 + # Attach
1846 + #
1847 + gdb_test "file $binfile2" ".*" "force switch to gdb64, if necessary"
1848 + send_gdb "attach $testpid\n"
1849 + gdb_expect {
1850 + -re ".*warning: reading register.*I.*O error.*$gdb_prompt $" {
1851 + fail "attach call, read register 3 error"
1852 + }
1853 + -re "Attaching to.*process $testpid.*libc.*$gdb_prompt $" {
1854 + pass "attach call"
1855 + }
1856 + -re "$gdb_prompt $" {fail "attach call"}
1857 + timeout {fail "(timeout) attach call"}
1858 + }
1859 +
1860 + # See if other registers are problems
1861 + #
1862 + send_gdb "i r r3\n"
1863 + gdb_expect {
1864 + -re ".*warning: reading register.*$gdb_prompt $" {
1865 + pass "CHFts23490: known bug"
1866 + }
1867 + -re ".*r3.*$gdb_prompt $" {
1868 + pass "Bug fixed, Yayyy!"
1869 + }
1870 + timeout { fail "timeout on info reg" }
1871 + }
1872 +
1873 + # Get rid of the process
1874 + #
1875 + gdb_test "p should_exit = 1" ".*"
1876 + gdb_test "c" ".*Program exited normally.*"
1877 +
1878 + # Be paranoid
1879 + #
1880 + remote_exec build "kill -9 ${testpid}"
1881 +
1882 +}
1883 +
1884 +
1885 +# Start with a fresh gdb
1886 +#
1887 +gdb_exit
1888 +gdb_start
1889 +gdb_reinitialize_dir $srcdir/$subdir
1890 +gdb_load ${binfile}
1891 +
1892 +# This is a test of gdb's ability to attach to a running process.
1893 +#
1894 +do_attach_tests
1895 +
1896 +# Test attaching when the target is inside a system call
1897 +#
1898 +gdb_exit
1899 +gdb_start
1900 +
1901 +gdb_reinitialize_dir $srcdir/$subdir
1902 +do_call_attach_tests
1903 +
1904 +return 0
1905 Index: gdb-6.8/gdb/testsuite/gdb.pie/attach2.c
1906 ===================================================================
1907 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1908 +++ gdb-6.8/gdb/testsuite/gdb.pie/attach2.c 2008-03-30 08:59:12.000000000 -0700
1909 @@ -0,0 +1,24 @@
1910 +/* This program is intended to be started outside of gdb, and then
1911 + attached to by gdb. Thus, it simply spins in a loop. The loop
1912 + is exited when & if the variable 'should_exit' is non-zero. (It
1913 + is initialized to zero in this program, so the loop will never
1914 + exit unless/until gdb sets the variable to non-zero.)
1915 + */
1916 +#include <stdio.h>
1917 +#include <stdlib.h>
1918 +#include <unistd.h>
1919 +
1920 +int should_exit = 0;
1921 +
1922 +int main ()
1923 +{
1924 + int local_i = 0;
1925 +
1926 + sleep( 10 ); /* System call causes register fetch to fail */
1927 + /* This is a known HPUX "feature" */
1928 + while (! should_exit)
1929 + {
1930 + local_i++;
1931 + }
1932 + return (0);
1933 +}
1934 Index: gdb-6.8/gdb/testsuite/gdb.pie/break.c
1935 ===================================================================
1936 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1937 +++ gdb-6.8/gdb/testsuite/gdb.pie/break.c 2008-03-30 08:59:12.000000000 -0700
1938 @@ -0,0 +1,146 @@
1939 +/* This testcase is part of GDB, the GNU debugger.
1940 +
1941 + Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003 Free Software
1942 + Foundation, Inc.
1943 +
1944 + This program is free software; you can redistribute it and/or modify
1945 + it under the terms of the GNU General Public License as published by
1946 + the Free Software Foundation; either version 2 of the License, or
1947 + (at your option) any later version.
1948 +
1949 + This program is distributed in the hope that it will be useful,
1950 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1951 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1952 + GNU General Public License for more details.
1953 +
1954 + You should have received a copy of the GNU General Public License
1955 + along with this program; if not, write to the Free Software
1956 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1957 +
1958 + Please email any bugs, comments, and/or additions to this file to:
1959 + bug-gdb@×××××××××××.edu */
1960 +
1961 +#ifdef vxworks
1962 +
1963 +# include <stdio.h>
1964 +
1965 +/* VxWorks does not supply atoi. */
1966 +static int
1967 +atoi (z)
1968 + char *z;
1969 +{
1970 + int i = 0;
1971 +
1972 + while (*z >= '0' && *z <= '9')
1973 + i = i * 10 + (*z++ - '0');
1974 + return i;
1975 +}
1976 +
1977 +/* I don't know of any way to pass an array to VxWorks. This function
1978 + can be called directly from gdb. */
1979 +
1980 +vxmain (arg)
1981 +char *arg;
1982 +{
1983 + char *argv[2];
1984 +
1985 + argv[0] = "";
1986 + argv[1] = arg;
1987 + main (2, argv, (char **) 0);
1988 +}
1989 +
1990 +#else /* ! vxworks */
1991 +# include <stdio.h>
1992 +# include <stdlib.h>
1993 +#endif /* ! vxworks */
1994 +
1995 +#ifdef PROTOTYPES
1996 +extern int marker1 (void);
1997 +extern int marker2 (int a);
1998 +extern void marker3 (char *a, char *b);
1999 +extern void marker4 (long d);
2000 +#else
2001 +extern int marker1 ();
2002 +extern int marker2 ();
2003 +extern void marker3 ();
2004 +extern void marker4 ();
2005 +#endif
2006 +
2007 +/*
2008 + * This simple classical example of recursion is useful for
2009 + * testing stack backtraces and such.
2010 + */
2011 +
2012 +#ifdef PROTOTYPES
2013 +int factorial(int);
2014 +
2015 +int
2016 +main (int argc, char **argv, char **envp)
2017 +#else
2018 +int
2019 +main (argc, argv, envp)
2020 +int argc;
2021 +char *argv[], **envp;
2022 +#endif
2023 +{
2024 +#ifdef usestubs
2025 + set_debug_traps(); /* set breakpoint 5 here */
2026 + breakpoint();
2027 +#endif
2028 + if (argc == 12345) { /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
2029 + fprintf (stderr, "usage: factorial <number>\n");
2030 + return 1;
2031 + }
2032 + printf ("%d\n", factorial (atoi ("6"))); /* set breakpoint 1 here */
2033 + /* set breakpoint 12 here */
2034 + marker1 (); /* set breakpoint 11 here */
2035 + marker2 (43); /* set breakpoint 20 here */
2036 + marker3 ("stack", "trace"); /* set breakpoint 21 here */
2037 + marker4 (177601976L);
2038 + argc = (argc == 12345); /* This is silly, but we can step off of it */ /* set breakpoint 2 here */
2039 + return argc; /* set breakpoint 10 here */
2040 +}
2041 +
2042 +#ifdef PROTOTYPES
2043 +int factorial (int value)
2044 +#else
2045 +int factorial (value)
2046 +int value;
2047 +#endif
2048 +{
2049 + if (value > 1) { /* set breakpoint 7 here */
2050 + value *= factorial (value - 1);
2051 + }
2052 + return (value); /* set breakpoint 19 here */
2053 +}
2054 +
2055 +#ifdef PROTOTYPES
2056 +int multi_line_if_conditional (int a, int b, int c)
2057 +#else
2058 +int multi_line_if_conditional (a, b, c)
2059 + int a, b, c;
2060 +#endif
2061 +{
2062 + if (a /* set breakpoint 3 here */
2063 + && b
2064 + && c)
2065 + return 0;
2066 + else
2067 + return 1;
2068 +}
2069 +
2070 +#ifdef PROTOTYPES
2071 +int multi_line_while_conditional (int a, int b, int c)
2072 +#else
2073 +int multi_line_while_conditional (a, b, c)
2074 + int a, b, c;
2075 +#endif
2076 +{
2077 + while (a /* set breakpoint 4 here */
2078 + && b
2079 + && c)
2080 + {
2081 + a--, b--, c--;
2082 + }
2083 + return 0;
2084 +}
2085 Index: gdb-6.8/gdb/testsuite/gdb.pie/break.exp
2086 ===================================================================
2087 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
2088 +++ gdb-6.8/gdb/testsuite/gdb.pie/break.exp 2008-03-30 08:59:12.000000000 -0700
2089 @@ -0,0 +1,973 @@
2090 +# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999,
2091 +# 2000, 2002, 2003, 2004
2092 +# Free Software Foundation, Inc.
2093 +
2094 +# This program is free software; you can redistribute it and/or modify
2095 +# it under the terms of the GNU General Public License as published by
2096 +# the Free Software Foundation; either version 2 of the License, or
2097 +# (at your option) any later version.
2098 +#
2099 +# This program is distributed in the hope that it will be useful,
2100 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2101 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2102 +# GNU General Public License for more details.
2103 +#
2104 +# You should have received a copy of the GNU General Public License
2105 +# along with this program; if not, write to the Free Software
2106 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2107 +
2108 +# Please email any bugs, comments, and/or additions to this file to:
2109 +# bug-gdb@×××××××××××.edu
2110 +
2111 +# This file was written by Rob Savoye. (rob@××××××.com)
2112 +
2113 +# Test the same stuff but with PIE executables
2114 +
2115 +if $tracelevel then {
2116 + strace $tracelevel
2117 +}
2118 +
2119 +
2120 +#
2121 +# test running programs
2122 +#
2123 +set prms_id 0
2124 +set bug_id 0
2125 +
2126 +set testfile "break"
2127 +set srcfile ${testfile}.c
2128 +set srcfile1 ${testfile}1.c
2129 +set binfile ${objdir}/${subdir}/${testfile}
2130 +
2131 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug "additional_flags=-w -fpie -pie"}] != "" } {
2132 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
2133 +}
2134 +
2135 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug "additional_flags=-w -fpie -pie"}] != "" } {
2136 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
2137 +}
2138 +
2139 +if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug "additional_flags=-w -fpie -pie"}] != "" } {
2140 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
2141 +}
2142 +
2143 +if [get_compiler_info ${binfile}] {
2144 + return -1
2145 +}
2146 +
2147 +gdb_exit
2148 +gdb_start
2149 +gdb_reinitialize_dir $srcdir/$subdir
2150 +gdb_load ${binfile}
2151 +
2152 +if [target_info exists gdb_stub] {
2153 + gdb_step_for_stub;
2154 +}
2155 +#
2156 +# test simple breakpoint setting commands
2157 +#
2158 +
2159 +# Test deleting all breakpoints when there are none installed,
2160 +# GDB should not prompt for confirmation.
2161 +# Note that gdb-init.exp provides a "delete_breakpoints" proc
2162 +# for general use elsewhere.
2163 +
2164 +send_gdb "delete breakpoints\n"
2165 +gdb_expect {
2166 + -re "Delete all breakpoints.*$" {
2167 + send_gdb "y\n"
2168 + gdb_expect {
2169 + -re "$gdb_prompt $" {
2170 + fail "Delete all breakpoints when none (unexpected prompt)"
2171 + }
2172 + timeout { fail "Delete all breakpoints when none (timeout after unexpected prompt)" }
2173 + }
2174 + }
2175 + -re ".*$gdb_prompt $" { pass "Delete all breakpoints when none" }
2176 + timeout { fail "Delete all breakpoints when none (timeout)" }
2177 +}
2178 +
2179 +#
2180 +# test break at function
2181 +#
2182 +gdb_test "break main" \
2183 + "Breakpoint.*at.* file .*$srcfile, line.*" \
2184 + "breakpoint function"
2185 +
2186 +#
2187 +# test break at quoted function
2188 +#
2189 +gdb_test "break \"marker2\"" \
2190 + "Breakpoint.*at.* file .*$srcfile1, line.*" \
2191 + "breakpoint quoted function"
2192 +
2193 +#
2194 +# test break at function in file
2195 +#
2196 +gdb_test "break $srcfile:factorial" \
2197 + "Breakpoint.*at.* file .*$srcfile, line.*" \
2198 + "breakpoint function in file"
2199 +
2200 +set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
2201 +
2202 +#
2203 +# test break at line number
2204 +#
2205 +# Note that the default source file is the last one whose source text
2206 +# was printed. For native debugging, before we've executed the
2207 +# program, this is the file containing main, but for remote debugging,
2208 +# it's wherever the processor was stopped when we connected to the
2209 +# board. So, to be sure, we do a list command.
2210 +#
2211 +gdb_test "list main" \
2212 + ".*main \\(argc, argv, envp\\).*" \
2213 + "use `list' to establish default source file"
2214 +gdb_test "break $bp_location1" \
2215 + "Breakpoint.*at.* file .*$srcfile, line $bp_location1\\." \
2216 + "breakpoint line number"
2217 +
2218 +#
2219 +# test duplicate breakpoint
2220 +#
2221 +gdb_test "break $bp_location1" \
2222 + "Note: breakpoint \[0-9\]+ also set at pc.*Breakpoint \[0-9\]+ at.* file .*$srcfile, line $bp_location1\\." \
2223 + "breakpoint duplicate"
2224 +
2225 +set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
2226 +
2227 +#
2228 +# test break at line number in file
2229 +#
2230 +gdb_test "break $srcfile:$bp_location2" \
2231 + "Breakpoint.*at.* file .*$srcfile, line $bp_location2\\." \
2232 + "breakpoint line number in file"
2233 +
2234 +set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
2235 +set bp_location4 [gdb_get_line_number "set breakpoint 4 here"]
2236 +
2237 +#
2238 +# Test putting a break at the start of a multi-line if conditional.
2239 +# Verify the breakpoint was put at the start of the conditional.
2240 +#
2241 +gdb_test "break multi_line_if_conditional" \
2242 + "Breakpoint.*at.* file .*$srcfile, line $bp_location3\\." \
2243 + "breakpoint at start of multi line if conditional"
2244 +
2245 +gdb_test "break multi_line_while_conditional" \
2246 + "Breakpoint.*at.* file .*$srcfile, line $bp_location4\\." \
2247 + "breakpoint at start of multi line while conditional"
2248 +
2249 +set bp_location5 [gdb_get_line_number "set breakpoint 5 here"]
2250 +set bp_location6 [gdb_get_line_number "set breakpoint 6 here"]
2251 +
2252 +#
2253 +# check to see what breakpoints are set
2254 +#
2255 +if [target_info exists gdb_stub] {
2256 + set main_line $bp_location5
2257 +} else {
2258 + set main_line $bp_location6
2259 +}
2260 +
2261 +if {$hp_aCC_compiler} {
2262 + set proto "\\(int\\)"
2263 +} else {
2264 + set proto ""
2265 +}
2266 +
2267 +set bp_location7 [gdb_get_line_number "set breakpoint 7 here"]
2268 +set bp_location8 [gdb_get_line_number "set breakpoint 8 here" $srcfile1]
2269 +set bp_location9 [gdb_get_line_number "set breakpoint 9 here" $srcfile1]
2270 +
2271 +gdb_test "info break" \
2272 + "Num Type\[ \]+Disp Enb Address\[ \]+What.*
2273 +\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$main_line.*
2274 +\[0-9\]+\[\t \]+breakpoint keep y.* in marker2 at .*$srcfile1:($bp_location8|$bp_location9).*
2275 +\[0-9\]+\[\t \]+breakpoint keep y.* in factorial$proto at .*$srcfile:$bp_location7.*
2276 +\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
2277 +\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location1.*
2278 +\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*$srcfile:$bp_location2.*
2279 +\[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_if_conditional at .*$srcfile:$bp_location3.*
2280 +\[0-9\]+\[\t \]+breakpoint keep y.* in multi_line_while_conditional at .*$srcfile:$bp_location4" \
2281 + "breakpoint info"
2282 +
2283 +# FIXME: The rest of this test doesn't work with anything that can't
2284 +# handle arguments.
2285 +# Huh? There doesn't *appear* to be anything that passes arguments
2286 +# below.
2287 +if [istarget "mips-idt-*"] then {
2288 + return
2289 +}
2290 +
2291 +#
2292 +# run until the breakpoint at main is hit. For non-stubs-using targets.
2293 +#
2294 +if ![target_info exists use_gdb_stub] {
2295 + if [istarget "*-*-vxworks*"] then {
2296 + send_gdb "run vxmain \"2\"\n"
2297 + set timeout 120
2298 + verbose "Timeout is now $timeout seconds" 2
2299 + } else {
2300 + send_gdb "run\n"
2301 + }
2302 + gdb_expect {
2303 + -re "The program .* has been started already.*y or n. $" {
2304 + send_gdb "y\n"
2305 + exp_continue
2306 + }
2307 + -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
2308 + { pass "run until function breakpoint" }
2309 + -re ".*$gdb_prompt $" { fail "run until function breakpoint" }
2310 + timeout { fail "run until function breakpoint (timeout)" }
2311 + }
2312 +} else {
2313 + if ![target_info exists gdb_stub] {
2314 + gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue"
2315 + }
2316 +}
2317 +
2318 +#
2319 +# run until the breakpoint at a line number
2320 +#
2321 +gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location1.*$bp_location1\[\t \]+printf.*factorial.*" \
2322 + "run until breakpoint set at a line number"
2323 +
2324 +#
2325 +# Run until the breakpoint set in a function in a file
2326 +#
2327 +for {set i 6} {$i >= 1} {incr i -1} {
2328 + gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, factorial \\(value=$i\\) at .*$srcfile:$bp_location7.*$bp_location7\[\t \]+.*if .value > 1. \{.*" \
2329 + "run until file:function($i) breakpoint"
2330 +}
2331 +
2332 +#
2333 +# Run until the breakpoint set at a quoted function
2334 +#
2335 +gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, (0x\[0-9a-f\]+ in )?marker2 \\(a=43\\) at .*$srcfile1:($bp_location8|$bp_location9).*" \
2336 + "run until quoted breakpoint"
2337 +#
2338 +# run until the file:function breakpoint at a line number in a file
2339 +#
2340 +gdb_test continue "Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location2.*$bp_location2\[\t \]+argc = \\(argc == 12345\\);.*" \
2341 + "run until file:linenum breakpoint"
2342 +
2343 +# Test break at offset +1
2344 +set bp_location10 [gdb_get_line_number "set breakpoint 10 here"]
2345 +
2346 +gdb_test "break +1" \
2347 + "Breakpoint.*at.* file .*$srcfile, line $bp_location10\\." \
2348 + "breakpoint offset +1"
2349 +
2350 +# Check to see if breakpoint is hit when stepped onto
2351 +
2352 +gdb_test "step" \
2353 + ".*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location10.*$bp_location10\[\t \]+return argc;.*breakpoint 10 here.*" \
2354 + "step onto breakpoint"
2355 +
2356 +#
2357 +# delete all breakpoints so we can start over, course this can be a test too
2358 +#
2359 +delete_breakpoints
2360 +
2361 +#
2362 +# test temporary breakpoint at function
2363 +#
2364 +
2365 +gdb_test "tbreak main" "Breakpoint.*at.* file .*$srcfile, line.*" "Temporary breakpoint function"
2366 +
2367 +#
2368 +# test break at function in file
2369 +#
2370 +
2371 +gdb_test "tbreak $srcfile:factorial" "Breakpoint.*at.* file .*$srcfile, line.*" \
2372 + "Temporary breakpoint function in file"
2373 +
2374 +#
2375 +# test break at line number
2376 +#
2377 +send_gdb "tbreak $bp_location1\n"
2378 +gdb_expect {
2379 + -re "Breakpoint.*at.* file .*$srcfile, line $bp_location1.*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
2380 + -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number #1" }
2381 + timeout { fail "breakpoint line number #1 (timeout)" }
2382 +}
2383 +
2384 +gdb_test "tbreak $bp_location6" "Breakpoint.*at.* file .*$srcfile, line $bp_location6.*" "Temporary breakpoint line number #2"
2385 +
2386 +#
2387 +# test break at line number in file
2388 +#
2389 +send_gdb "tbreak $srcfile:$bp_location2\n"
2390 +gdb_expect {
2391 + -re "Breakpoint.*at.* file .*$srcfile, line $bp_location2.*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
2392 + -re ".*$gdb_prompt $" { pass "Temporary breakpoint line number in file #1" }
2393 + timeout { fail "Temporary breakpoint line number in file #1 (timeout)" }
2394 +}
2395 +
2396 +set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
2397 +gdb_test "tbreak $srcfile:$bp_location11" "Breakpoint.*at.* file .*$srcfile, line $bp_location11.*" "Temporary breakpoint line number in file #2"
2398 +
2399 +#
2400 +# check to see what breakpoints are set (temporary this time)
2401 +#
2402 +gdb_test "info break" "Num Type.*Disp Enb Address.*What.*\[\r\n\]
2403 +\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$main_line.*\[\r\n\]
2404 +\[0-9\]+\[\t \]+breakpoint del.*y.*in factorial$proto at .*$srcfile:$bp_location7.*\[\r\n\]
2405 +\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location1.*\[\r\n\]
2406 +\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location6.*\[\r\n\]
2407 +\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location2.*\[\r\n\]
2408 +\[0-9\]+\[\t \]+breakpoint del.*y.*in main at .*$srcfile:$bp_location11.*" \
2409 + "Temporary breakpoint info"
2410 +
2411 +
2412 +#***********
2413 +
2414 +# Verify that catchpoints for fork, vfork and exec don't trigger
2415 +# inappropriately. (There are no calls to those system functions
2416 +# in this test program.)
2417 +#
2418 +if ![runto_main] then { fail "break tests suppressed" }
2419 +
2420 +send_gdb "catch\n"
2421 +gdb_expect {
2422 + -re "Catch requires an event name.*$gdb_prompt $"\
2423 + {pass "catch requires an event name"}
2424 + -re "$gdb_prompt $"\
2425 + {fail "catch requires an event name"}
2426 + timeout {fail "(timeout) catch requires an event name"}
2427 +}
2428 +
2429 +
2430 +set name "set catch fork, never expected to trigger"
2431 +send_gdb "catch fork\n"
2432 +gdb_expect {
2433 + -re "Catchpoint \[0-9\]* .fork..*$gdb_prompt $"
2434 + {pass $name}
2435 + -re "Catch of fork not yet implemented.*$gdb_prompt $"
2436 + {pass $name}
2437 + -re "$gdb_prompt $"
2438 + {fail $name}
2439 + timeout {fail "(timeout) $name"}
2440 +}
2441 +
2442 +
2443 +set name "set catch vfork, never expected to trigger"
2444 +send_gdb "catch vfork\n"
2445 +
2446 +# If we are on HP-UX 10.20, we expect an error message to be
2447 +# printed if we type "catch vfork" at the gdb gdb_prompt. This is
2448 +# because on HP-UX 10.20, we cannot catch vfork events.
2449 +
2450 +if [istarget "hppa*-hp-hpux10.20"] then {
2451 + gdb_expect {
2452 + -re "Catch of vfork events not supported on HP-UX 10.20..*$gdb_prompt $"
2453 + {pass $name}
2454 + -re "$gdb_prompt $"
2455 + {fail $name}
2456 + timeout {fail "(timeout) $name"}
2457 + }
2458 +} else {
2459 + gdb_expect {
2460 + -re "Catchpoint \[0-9\]* .vfork..*$gdb_prompt $"
2461 + {pass $name}
2462 + -re "Catch of vfork not yet implemented.*$gdb_prompt $"
2463 + {pass $name}
2464 + -re "$gdb_prompt $"
2465 + {fail $name}
2466 + timeout {fail "(timeout) $name"}
2467 + }
2468 +}
2469 +
2470 +set name "set catch exec, never expected to trigger"
2471 +send_gdb "catch exec\n"
2472 +gdb_expect {
2473 + -re "Catchpoint \[0-9\]* .exec..*$gdb_prompt $"
2474 + {pass $name}
2475 + -re "Catch of exec not yet implemented.*$gdb_prompt $"
2476 + {pass $name}
2477 + -re "$gdb_prompt $" {fail $name}
2478 + timeout {fail "(timeout) $name"}
2479 +}
2480 +
2481 +# Verify that GDB responds gracefully when asked to set a breakpoint
2482 +# on a nonexistent source line.
2483 +#
2484 +send_gdb "break 999\n"
2485 +gdb_expect {
2486 + -re "No line 999 in file .*$gdb_prompt $"\
2487 + {pass "break on non-existent source line"}
2488 + -re "$gdb_prompt $"\
2489 + {fail "break on non-existent source line"}
2490 + timeout {fail "(timeout) break on non-existent source line"}
2491 +}
2492 +
2493 +# Run to the desired default location. If not positioned here, the
2494 +# tests below don't work.
2495 +#
2496 +gdb_test "until $bp_location1" "main .* at .*:$bp_location1.*" "until bp_location1"
2497 +
2498 +
2499 +# Verify that GDB allows one to just say "break", which is treated
2500 +# as the "default" breakpoint. Note that GDB gets cute when printing
2501 +# the informational message about other breakpoints at the same
2502 +# location. We'll hit that bird with this stone too.
2503 +#
2504 +send_gdb "break\n"
2505 +gdb_expect {
2506 + -re "Breakpoint \[0-9\]*.*$gdb_prompt $"\
2507 + {pass "break on default location, 1st time"}
2508 + -re "$gdb_prompt $"\
2509 + {fail "break on default location, 1st time"}
2510 + timeout {fail "(timeout) break on default location, 1st time"}
2511 +}
2512 +
2513 +send_gdb "break\n"
2514 +gdb_expect {
2515 + -re "Note: breakpoint \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
2516 + {pass "break on default location, 2nd time"}
2517 + -re "$gdb_prompt $"\
2518 + {fail "break on default location, 2nd time"}
2519 + timeout {fail "(timeout) break on default location, 2nd time"}
2520 +}
2521 +
2522 +send_gdb "break\n"
2523 +gdb_expect {
2524 + -re "Note: breakpoints \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
2525 + {pass "break on default location, 3rd time"}
2526 + -re "$gdb_prompt $"\
2527 + {fail "break on default location, 3rd time"}
2528 + timeout {fail "(timeout) break on default location, 3rd time"}
2529 +}
2530 +
2531 +send_gdb "break\n"
2532 +gdb_expect {
2533 + -re "Note: breakpoints \[0-9\]*, \[0-9\]* and \[0-9\]* also set at .*Breakpoint \[0-9\]*.*$gdb_prompt $"\
2534 + {pass "break on default location, 4th time"}
2535 + -re "$gdb_prompt $"\
2536 + {fail "break on default location, 4th time"}
2537 + timeout {fail "(timeout) break on default location, 4th time"}
2538 +}
2539 +
2540 +# Verify that a "silent" breakpoint can be set, and that GDB is indeed
2541 +# "silent" about its triggering.
2542 +#
2543 +if ![runto_main] then { fail "break tests suppressed" }
2544 +
2545 +send_gdb "break $bp_location1\n"
2546 +gdb_expect {
2547 + -re "Breakpoint (\[0-9\]*) at .*, line $bp_location1.*$gdb_prompt $"\
2548 + {pass "set to-be-silent break bp_location1"}
2549 + -re "$gdb_prompt $"\
2550 + {fail "set to-be-silent break bp_location1"}
2551 + timeout {fail "(timeout) set to-be-silent break bp_location1"}
2552 +}
2553 +
2554 +send_gdb "commands $expect_out(1,string)\n"
2555 +send_gdb "silent\n"
2556 +send_gdb "end\n"
2557 +gdb_expect {
2558 + -re ".*$gdb_prompt $"\
2559 + {pass "set silent break bp_location1"}
2560 + timeout {fail "(timeout) set silent break bp_location1"}
2561 +}
2562 +
2563 +send_gdb "info break $expect_out(1,string)\n"
2564 +gdb_expect {
2565 + -re "\[0-9\]*\[ \t\]*breakpoint.*:$bp_location1\r\n\[ \t\]*silent.*$gdb_prompt $"\
2566 + {pass "info silent break bp_location1"}
2567 + -re "$gdb_prompt $"\
2568 + {fail "info silent break bp_location1"}
2569 + timeout {fail "(timeout) info silent break bp_location1"}
2570 +}
2571 +send_gdb "continue\n"
2572 +gdb_expect {
2573 + -re "Continuing.\r\n$gdb_prompt $"\
2574 + {pass "hit silent break bp_location1"}
2575 + -re "$gdb_prompt $"\
2576 + {fail "hit silent break bp_location1"}
2577 + timeout {fail "(timeout) hit silent break bp_location1"}
2578 +}
2579 +send_gdb "bt\n"
2580 +gdb_expect {
2581 + -re "#0 main .* at .*:$bp_location1.*$gdb_prompt $"\
2582 + {pass "stopped for silent break bp_location1"}
2583 + -re "$gdb_prompt $"\
2584 + {fail "stopped for silent break bp_location1"}
2585 + timeout {fail "(timeout) stopped for silent break bp_location1"}
2586 +}
2587 +
2588 +# Verify that GDB can at least parse a breakpoint with the
2589 +# "thread" keyword. (We won't attempt to test here that a
2590 +# thread-specific breakpoint really triggers appropriately.
2591 +# The gdb.threads subdirectory contains tests for that.)
2592 +#
2593 +set bp_location12 [gdb_get_line_number "set breakpoint 12 here"]
2594 +send_gdb "break $bp_location12 thread 999\n"
2595 +gdb_expect {
2596 + -re "Unknown thread 999.*$gdb_prompt $"\
2597 + {pass "thread-specific breakpoint on non-existent thread disallowed"}
2598 + -re "$gdb_prompt $"\
2599 + {fail "thread-specific breakpoint on non-existent thread disallowed"}
2600 + timeout {fail "(timeout) thread-specific breakpoint on non-existent thread disallowed"}
2601 +}
2602 +send_gdb "break $bp_location12 thread foo\n"
2603 +gdb_expect {
2604 + -re "Junk after thread keyword..*$gdb_prompt $"\
2605 + {pass "thread-specific breakpoint on bogus thread ID disallowed"}
2606 + -re "$gdb_prompt $"\
2607 + {fail "thread-specific breakpoint on bogus thread ID disallowed"}
2608 + timeout {fail "(timeout) thread-specific breakpoint on bogus thread ID disallowed"}
2609 +}
2610 +
2611 +# Verify that GDB responds gracefully to a breakpoint command with
2612 +# trailing garbage.
2613 +#
2614 +send_gdb "break $bp_location12 foo\n"
2615 +gdb_expect {
2616 + -re "Junk at end of arguments..*$gdb_prompt $"\
2617 + {pass "breakpoint with trailing garbage disallowed"}
2618 + -re "$gdb_prompt $"\
2619 + {fail "breakpoint with trailing garbage disallowed"}
2620 + timeout {fail "(timeout) breakpoint with trailing garbage disallowed"}
2621 +}
2622 +
2623 +# Verify that GDB responds gracefully to a "clear" command that has
2624 +# no matching breakpoint. (First, get us off the current source line,
2625 +# which we know has a breakpoint.)
2626 +#
2627 +send_gdb "next\n"
2628 +gdb_expect {
2629 + -re ".*$gdb_prompt $"\
2630 + {pass "step over breakpoint"}
2631 + timeout {fail "(timeout) step over breakpoint"}
2632 +}
2633 +send_gdb "clear 81\n"
2634 +gdb_expect {
2635 + -re "No breakpoint at 81..*$gdb_prompt $"\
2636 + {pass "clear line has no breakpoint disallowed"}
2637 + -re "$gdb_prompt $"\
2638 + {fail "clear line has no breakpoint disallowed"}
2639 + timeout {fail "(timeout) clear line has no breakpoint disallowed"}
2640 +}
2641 +send_gdb "clear\n"
2642 +gdb_expect {
2643 + -re "No breakpoint at this line..*$gdb_prompt $"\
2644 + {pass "clear current line has no breakpoint disallowed"}
2645 + -re "$gdb_prompt $"\
2646 + {fail "clear current line has no breakpoint disallowed"}
2647 + timeout {fail "(timeout) clear current line has no breakpoint disallowed"}
2648 +}
2649 +
2650 +# Verify that we can set and clear multiple breakpoints.
2651 +#
2652 +# We don't test that it deletes the correct breakpoints. We do at
2653 +# least test that it deletes more than one breakpoint.
2654 +#
2655 +gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #1"
2656 +gdb_test "break marker3" "Breakpoint.*at.*" "break marker3 #2"
2657 +gdb_test "clear marker3" {Deleted breakpoints [0-9]+ [0-9]+.*}
2658 +
2659 +# Verify that a breakpoint can be set via a convenience variable.
2660 +#
2661 +send_gdb "set \$foo=$bp_location11\n"
2662 +gdb_expect {
2663 + -re "$gdb_prompt $"\
2664 + {pass "set convenience variable \$foo to bp_location11"}
2665 + timeout {fail "(timeout) set convenience variable \$foo to bp_location11"}
2666 +}
2667 +send_gdb "break \$foo\n"
2668 +gdb_expect {
2669 + -re "Breakpoint (\[0-9\]*) at .*, line $bp_location11.*$gdb_prompt $"\
2670 + {pass "set breakpoint via convenience variable"}
2671 + -re "$gdb_prompt $"\
2672 + {fail "set breakpoint via convenience variable"}
2673 + timeout {fail "(timeout) set breakpoint via convenience variable"}
2674 +}
2675 +
2676 +# Verify that GDB responds gracefully to an attempt to set a
2677 +# breakpoint via a convenience variable whose type is not integer.
2678 +#
2679 +send_gdb "set \$foo=81.5\n"
2680 +gdb_expect {
2681 + -re "$gdb_prompt $"\
2682 + {pass "set convenience variable \$foo to 81.5"}
2683 + timeout {fail "(timeout) set convenience variable \$foo to 81.5"}
2684 +}
2685 +send_gdb "break \$foo\n"
2686 +gdb_expect {
2687 + -re "Convenience variables used in line specs must have integer values..*$gdb_prompt $"\
2688 + {pass "set breakpoint via non-integer convenience variable disallowed"}
2689 + -re "$gdb_prompt $"\
2690 + {fail "set breakpoint via non-integer convenience variable disallowed"}
2691 + timeout {fail "(timeout) set breakpoint via non-integer convenience variable disallowed"}
2692 +}
2693 +
2694 +# Verify that we can set and trigger a breakpoint in a user-called function.
2695 +#
2696 +send_gdb "break marker2\n"
2697 +gdb_expect {
2698 + -re "Breakpoint (\[0-9\]*) at .*, line ($bp_location8|$bp_location9).*$gdb_prompt $"\
2699 + {pass "set breakpoint on to-be-called function"}
2700 + -re "$gdb_prompt $"\
2701 + {fail "set breakpoint on to-be-called function"}
2702 + timeout {fail "(timeout) set breakpoint on to-be-called function"}
2703 +}
2704 +send_gdb "print marker2(99)\n"
2705 +gdb_expect {
2706 + -re "The program being debugged stopped while in a function called from GDB.\r\nWhen the function .marker2$proto. is done executing, GDB will silently\r\nstop .instead of continuing to evaluate the expression containing\r\nthe function call...*$gdb_prompt $"\
2707 + {pass "hit breakpoint on called function"}
2708 + -re "$gdb_prompt $"\
2709 + {fail "hit breakpoint on called function"}
2710 + timeout {fail "(timeout) hit breakpoint on called function"}
2711 +}
2712 +
2713 +# As long as we're stopped (breakpointed) in a called function,
2714 +# verify that we can successfully backtrace & such from here.
2715 +#
2716 +# In this and the following test, the _sr4export check apparently is needed
2717 +# for hppa*-*-hpux.
2718 +#
2719 +send_gdb "bt\n"
2720 +gdb_expect {
2721 + -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*_sr4export.*$gdb_prompt $"\
2722 + {pass "backtrace while in called function"}
2723 + -re "#0\[ \t\]*($hex in )?marker2.*:($bp_location8|$bp_location9)\r\n#1.*function called from gdb.*$gdb_prompt $"\
2724 + {pass "backtrace while in called function"}
2725 + -re "$gdb_prompt $"\
2726 + {fail "backtrace while in called function"}
2727 + timeout {fail "(timeout) backtrace while in called function"}
2728 +}
2729 +
2730 +# Return from the called function. For remote targets, it's important to do
2731 +# this before runto_main, which otherwise may silently stop on the dummy
2732 +# breakpoint inserted by GDB at the program's entry point.
2733 +#
2734 +send_gdb "finish\n"
2735 +gdb_expect {
2736 + -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.* in _sr4export.*$gdb_prompt $"\
2737 + {pass "finish from called function"}
2738 + -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*function called from gdb.*$gdb_prompt $"\
2739 + {pass "finish from called function"}
2740 + -re "Run till exit from .*marker2.* at .*($bp_location8|$bp_location9)\r\n.*Value returned.*$gdb_prompt $"\
2741 + {pass "finish from called function"}
2742 + -re "$gdb_prompt $"\
2743 + {fail "finish from called function"}
2744 + timeout {fail "(timeout) finish from called function"}
2745 +}
2746 +
2747 +# Verify that GDB responds gracefully to a "finish" command with
2748 +# arguments.
2749 +#
2750 +if ![runto_main] then { fail "break tests suppressed" }
2751 +
2752 +send_gdb "finish 123\n"
2753 +gdb_expect {
2754 + -re "The \"finish\" command does not take any arguments.\r\n$gdb_prompt $"\
2755 + {pass "finish with arguments disallowed"}
2756 + -re "$gdb_prompt $"\
2757 + {fail "finish with arguments disallowed"}
2758 + timeout {fail "(timeout) finish with arguments disallowed"}
2759 +}
2760 +
2761 +# Verify that GDB responds gracefully to a request to "finish" from
2762 +# the outermost frame. On a stub that never exits, this will just
2763 +# run to the stubs routine, so we don't get this error... Thus the
2764 +# second condition.
2765 +#
2766 +
2767 +send_gdb "finish\n"
2768 +gdb_expect {
2769 + -re "\"finish\" not meaningful in the outermost frame.\r\n$gdb_prompt $"\
2770 + {pass "finish from outermost frame disallowed"}
2771 + -re "Run till exit from.*\r\n$gdb_prompt $" {
2772 + pass "finish from outermost frame disallowed"
2773 + }
2774 + -re "$gdb_prompt $"\
2775 + {fail "finish from outermost frame disallowed"}
2776 + timeout {fail "(timeout) finish from outermost frame disallowed"}
2777 +}
2778 +
2779 +# Verify that we can explicitly ask GDB to stop on all shared library
2780 +# events, and that it does so.
2781 +#
2782 +if [istarget "hppa*-*-hpux*"] then {
2783 + if ![runto_main] then { fail "break tests suppressed" }
2784 +
2785 + send_gdb "set stop-on-solib-events 1\n"
2786 + gdb_expect {
2787 + -re "$gdb_prompt $"\
2788 + {pass "set stop-on-solib-events"}
2789 + timeout {fail "(timeout) set stop-on-solib-events"}
2790 + }
2791 +
2792 + send_gdb "run\n"
2793 + gdb_expect {
2794 + -re ".*Start it from the beginning.*y or n. $"\
2795 + {send_gdb "y\n"
2796 + gdb_expect {
2797 + -re ".*Stopped due to shared library event.*$gdb_prompt $"\
2798 + {pass "triggered stop-on-solib-events"}
2799 + -re "$gdb_prompt $"\
2800 + {fail "triggered stop-on-solib-events"}
2801 + timeout {fail "(timeout) triggered stop-on-solib-events"}
2802 + }
2803 + }
2804 + -re "$gdb_prompt $"\
2805 + {fail "rerun for stop-on-solib-events"}
2806 + timeout {fail "(timeout) rerun for stop-on-solib-events"}
2807 + }
2808 +
2809 + send_gdb "set stop-on-solib-events 0\n"
2810 + gdb_expect {
2811 + -re "$gdb_prompt $"\
2812 + {pass "reset stop-on-solib-events"}
2813 + timeout {fail "(timeout) reset stop-on-solib-events"}
2814 + }
2815 +}
2816 +
2817 +# Hardware breakpoints are unsupported on HP-UX. Verify that GDB
2818 +# gracefully responds to requests to create them.
2819 +#
2820 +if [istarget "hppa*-*-hpux*"] then {
2821 + if ![runto_main] then { fail "break tests suppressed" }
2822 +
2823 + send_gdb "hbreak\n"
2824 + gdb_expect {
2825 + -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
2826 + {pass "hw breaks disallowed"}
2827 + -re "$gdb_prompt $"\
2828 + {fail "hw breaks disallowed"}
2829 + timeout {fail "(timeout) hw breaks disallowed"}
2830 + }
2831 +
2832 + send_gdb "thbreak\n"
2833 + gdb_expect {
2834 + -re "No hardware breakpoint support in the target.*$gdb_prompt $"\
2835 + {pass "temporary hw breaks disallowed"}
2836 + -re "$gdb_prompt $"\
2837 + {fail "temporary hw breaks disallowed"}
2838 + timeout {fail "(timeout) temporary hw breaks disallowed"}
2839 + }
2840 +}
2841 +
2842 +#********
2843 +
2844 +
2845 +#
2846 +# Test "next" over recursive function call.
2847 +#
2848 +
2849 +proc test_next_with_recursion {} {
2850 + global gdb_prompt
2851 + global decimal
2852 + global binfile
2853 +
2854 + if [target_info exists use_gdb_stub] {
2855 + # Reload the program.
2856 + delete_breakpoints
2857 + gdb_load ${binfile};
2858 + } else {
2859 + # FIXME: should be using runto
2860 + gdb_test "kill" "" "kill program" "Kill the program being debugged.*y or n. $" "y"
2861 +
2862 + delete_breakpoints
2863 + }
2864 +
2865 + gdb_test "break factorial" "Breakpoint $decimal at .*" "break at factorial"
2866 +
2867 + # Run until we call factorial with 6
2868 +
2869 + if [istarget "*-*-vxworks*"] then {
2870 + send_gdb "run vxmain \"6\"\n"
2871 + } else {
2872 + gdb_run_cmd
2873 + }
2874 + gdb_expect {
2875 + -re "Break.* factorial .value=6. .*$gdb_prompt $" {}
2876 + -re ".*$gdb_prompt $" {
2877 + fail "run to factorial(6)";
2878 + gdb_suppress_tests;
2879 + }
2880 + timeout { fail "run to factorial(6) (timeout)" ; gdb_suppress_tests }
2881 + }
2882 +
2883 + # Continue until we call factorial recursively with 5.
2884 +
2885 + if [gdb_test "continue" \
2886 + "Continuing.*Break.* factorial .value=5. .*" \
2887 + "continue to factorial(5)"] then { gdb_suppress_tests }
2888 +
2889 + # Do a backtrace just to confirm how many levels deep we are.
2890 +
2891 + if [gdb_test "backtrace" \
2892 + "#0\[ \t\]+ factorial .value=5..*" \
2893 + "backtrace from factorial(5)"] then { gdb_suppress_tests }
2894 +
2895 + # Now a "next" should position us at the recursive call, which
2896 + # we will be performing with 4.
2897 +
2898 + if [gdb_test "next" \
2899 + ".* factorial .value - 1.;.*" \
2900 + "next to recursive call"] then { gdb_suppress_tests }
2901 +
2902 + # Disable the breakpoint at the entry to factorial by deleting them all.
2903 + # The "next" should run until we return to the next line from this
2904 + # recursive call to factorial with 4.
2905 + # Buggy versions of gdb will stop instead at the innermost frame on
2906 + # the line where we are trying to "next" to.
2907 +
2908 + delete_breakpoints
2909 +
2910 + if [istarget "mips*tx39-*"] {
2911 + set timeout 60
2912 + }
2913 + # We used to set timeout here for all other targets as well. This
2914 + # is almost certainly wrong. The proper timeout depends on the
2915 + # target system in use, and how we communicate with it, so there
2916 + # is no single value appropriate for all targets. The timeout
2917 + # should be established by the Dejagnu config file(s) for the
2918 + # board, and respected by the test suite.
2919 + #
2920 + # For example, if I'm running GDB over an SSH tunnel talking to a
2921 + # portmaster in California talking to an ancient 68k board running
2922 + # a crummy ROM monitor (a situation I can only wish were
2923 + # hypothetical), then I need a large timeout. But that's not the
2924 + # kind of knowledge that belongs in this file.
2925 +
2926 + gdb_test next "\[0-9\]*\[\t \]+return \\(value\\);.*" \
2927 + "next over recursive call"
2928 +
2929 + # OK, we should be back in the same stack frame we started from.
2930 + # Do a backtrace just to confirm.
2931 +
2932 + set result [gdb_test "backtrace" \
2933 + "#0\[ \t\]+ factorial .value=120.*\r\n#1\[ \t\]+ \[0-9a-fx\]+ in factorial .value=6..*" \
2934 + "backtrace from factorial(5.1)"]
2935 + if { $result != 0 } { gdb_suppress_tests }
2936 +
2937 + if [target_info exists gdb,noresults] { gdb_suppress_tests }
2938 + gdb_continue_to_end "recursive next test"
2939 + gdb_stop_suppressing_tests;
2940 +}
2941 +
2942 +test_next_with_recursion
2943 +
2944 +
2945 +#********
2946 +
2947 +# build a new file with optimization enabled so that we can try breakpoints
2948 +# on targets with optimized prologues
2949 +
2950 +set binfileo2 ${objdir}/${subdir}/${testfile}o2
2951 +
2952 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}O0.o" object {debug "additional_flags=-w -O2 -fpie -pie"}] != "" } {
2953 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
2954 +}
2955 +
2956 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}O1.o" object {debug "additional_flags=-w -O2 -fpie -pie"}] != "" } {
2957 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
2958 +}
2959 +
2960 +if { [gdb_compile "${binfile}O0.o ${binfile}O1.o" "${binfileo2}" executable {debug "additional_flags=-w -fpie -pie"}] != "" } {
2961 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
2962 +}
2963 +
2964 +if [get_compiler_info ${binfileo2}] {
2965 + return -1
2966 +}
2967 +
2968 +gdb_exit
2969 +gdb_start
2970 +gdb_reinitialize_dir $srcdir/$subdir
2971 +gdb_load ${binfileo2}
2972 +
2973 +if [target_info exists gdb_stub] {
2974 + gdb_step_for_stub;
2975 +}
2976 +
2977 +#
2978 +# test break at function
2979 +#
2980 +gdb_test "break main" \
2981 + "Breakpoint.*at.* file .*$srcfile, line.*" \
2982 + "breakpoint function, optimized file"
2983 +
2984 +#
2985 +# test break at function
2986 +#
2987 +gdb_test "break marker4" \
2988 + "Breakpoint.*at.* file .*$srcfile1, line.*" \
2989 + "breakpoint small function, optimized file"
2990 +
2991 +#
2992 +# run until the breakpoint at main is hit. For non-stubs-using targets.
2993 +#
2994 +if ![target_info exists use_gdb_stub] {
2995 + if [istarget "*-*-vxworks*"] then {
2996 + send_gdb "run vxmain \"2\"\n"
2997 + set timeout 120
2998 + verbose "Timeout is now $timeout seconds" 2
2999 + } else {
3000 + send_gdb "run\n"
3001 + }
3002 + gdb_expect {
3003 + -re "The program .* has been started already.*y or n. $" {
3004 + send_gdb "y\n"
3005 + exp_continue
3006 + }
3007 + -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.* \{.*$gdb_prompt $"\
3008 + { pass "run until function breakpoint, optimized file" }
3009 + -re "Starting program.*Breakpoint \[0-9\]+,.*main .*argc.*argv.* at .*$gdb_prompt $"\
3010 + { pass "run until function breakpoint, optimized file (code motion)" }
3011 + -re ".*$gdb_prompt $" { fail "run until function breakpoint, optimized file" }
3012 + timeout { fail "run until function breakpoint, optimized file (timeout)" }
3013 + }
3014 +} else {
3015 + if ![target_info exists gdb_stub] {
3016 + gdb_test continue ".*Continuing\\..*Breakpoint \[0-9\]+, main \\(argc=.*, argv=.*, envp=.*\\) at .*$srcfile:$bp_location6.*$bp_location6\[\t \]+if .argc.*\{.*" "stub continue, optimized file"
3017 + }
3018 +}
3019 +
3020 +#
3021 +# run until the breakpoint at a small function
3022 +#
3023 +
3024 +#
3025 +# Add a second pass pattern. The behavior differs here between stabs
3026 +# and dwarf for one-line functions. Stabs preserves two line symbols
3027 +# (one before the prologue and one after) with the same line number,
3028 +# but dwarf regards these as duplicates and discards one of them.
3029 +# Therefore the address after the prologue (where the breakpoint is)
3030 +# has no exactly matching line symbol, and GDB reports the breakpoint
3031 +# as if it were in the middle of a line rather than at the beginning.
3032 +
3033 +set bp_location13 [gdb_get_line_number "set breakpoint 13 here" $srcfile1]
3034 +set bp_location14 [gdb_get_line_number "set breakpoint 14 here" $srcfile1]
3035 +send_gdb "continue\n"
3036 +gdb_expect {
3037 + -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
3038 + pass "run until breakpoint set at small function, optimized file"
3039 + }
3040 + -re "Breakpoint $decimal, $hex in marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location13\[\r\n\]+$bp_location13\[\t \]+void marker4.*" {
3041 + pass "run until breakpoint set at small function, optimized file"
3042 + }
3043 + -re "Breakpoint $decimal, marker4 \\(d=177601976\\) at .*$srcfile1:$bp_location14\[\r\n\]+$bp_location14\[\t \]+void marker4.*" {
3044 + # marker4() is defined at line 46 when compiled with -DPROTOTYPES
3045 + pass "run until breakpoint set at small function, optimized file (line bp_location14)"
3046 + }
3047 + -re ".*$gdb_prompt " {
3048 + fail "run until breakpoint set at small function, optimized file"
3049 + }
3050 + timeout {
3051 + fail "run until breakpoint set at small function, optimized file (timeout)"
3052 + }
3053 +}
3054 +
3055 +
3056 +# Reset the default arguments for VxWorks
3057 +if [istarget "*-*-vxworks*"] {
3058 + set timeout 10
3059 + verbose "Timeout is now $timeout seconds" 2
3060 + send_gdb "set args main\n"
3061 + gdb_expect -re ".*$gdb_prompt $" {}
3062 +}
3063 Index: gdb-6.8/gdb/testsuite/gdb.pie/break1.c
3064 ===================================================================
3065 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3066 +++ gdb-6.8/gdb/testsuite/gdb.pie/break1.c 2008-03-30 08:59:12.000000000 -0700
3067 @@ -0,0 +1,44 @@
3068 +/* This testcase is part of GDB, the GNU debugger.
3069 +
3070 + Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003 Free Software
3071 + Foundation, Inc.
3072 +
3073 + This program is free software; you can redistribute it and/or modify
3074 + it under the terms of the GNU General Public License as published by
3075 + the Free Software Foundation; either version 2 of the License, or
3076 + (at your option) any later version.
3077 +
3078 + This program is distributed in the hope that it will be useful,
3079 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3080 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3081 + GNU General Public License for more details.
3082 +
3083 + You should have received a copy of the GNU General Public License
3084 + along with this program; if not, write to the Free Software
3085 + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3086 +
3087 + Please email any bugs, comments, and/or additions to this file to:
3088 + bug-gdb@×××××××××××.edu */
3089 +
3090 +/* The code for this file was extracted from the gdb testsuite
3091 + testcase "break.c". */
3092 +
3093 +/* The following functions do nothing useful. They are included
3094 + simply as places to try setting breakpoints at. They are
3095 + explicitly "one-line functions" to verify that this case works
3096 + (some versions of gcc have or have had problems with this).
3097 +
3098 + These functions are in a separate source file to prevent an
3099 + optimizing compiler from inlining them and optimizing them away. */
3100 +
3101 +#ifdef PROTOTYPES
3102 +int marker1 (void) { return (0); } /* set breakpoint 15 here */
3103 +int marker2 (int a) { return (1); } /* set breakpoint 8 here */
3104 +void marker3 (char *a, char *b) {} /* set breakpoint 17 here */
3105 +void marker4 (long d) {} /* set breakpoint 14 here */
3106 +#else
3107 +int marker1 () { return (0); } /* set breakpoint 16 here */
3108 +int marker2 (a) int a; { return (1); } /* set breakpoint 9 here */
3109 +void marker3 (a, b) char *a, *b; {} /* set breakpoint 18 here */
3110 +void marker4 (d) long d; {} /* set breakpoint 13 here */
3111 +#endif
3112 Index: gdb-6.8/gdb/testsuite/gdb.pie/corefile.exp
3113 ===================================================================
3114 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3115 +++ gdb-6.8/gdb/testsuite/gdb.pie/corefile.exp 2008-03-30 08:59:12.000000000 -0700
3116 @@ -0,0 +1,243 @@
3117 +# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
3118 +# Free Software Foundation, Inc.
3119 +
3120 +# This program is free software; you can redistribute it and/or modify
3121 +# it under the terms of the GNU General Public License as published by
3122 +# the Free Software Foundation; either version 2 of the License, or
3123 +# (at your option) any later version.
3124 +#
3125 +# This program is distributed in the hope that it will be useful,
3126 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
3127 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3128 +# GNU General Public License for more details.
3129 +#
3130 +# You should have received a copy of the GNU General Public License
3131 +# along with this program; if not, write to the Free Software
3132 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3133 +
3134 +# Please email any bugs, comments, and/or additions to this file to:
3135 +# bug-gdb@×××××××××××.edu
3136 +
3137 +# This file was written by Fred Fish. (fnf@××××××.com)
3138 +
3139 +if $tracelevel then {
3140 + strace $tracelevel
3141 +}
3142 +
3143 +set prms_id 0
3144 +set bug_id 0
3145 +
3146 +# are we on a target board
3147 +if ![isnative] then {
3148 + return
3149 +}
3150 +
3151 +set testfile "coremaker"
3152 +set srcfile ${testfile}.c
3153 +set binfile ${objdir}/${subdir}/${testfile}
3154 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug "additional_flags=-fpie -pie"}] != "" } {
3155 + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
3156 +}
3157 +
3158 +# Create and source the file that provides information about the compiler
3159 +# used to compile the test case.
3160 +if [get_compiler_info ${binfile}] {
3161 + return -1;
3162 +}
3163 +
3164 +# Create a core file named "corefile" rather than just "core", to
3165 +# avoid problems with sys admin types that like to regularly prune all
3166 +# files named "core" from the system.
3167 +#
3168 +# Arbitrarily try setting the core size limit to "unlimited" since
3169 +# this does not hurt on systems where the command does not work and
3170 +# allows us to generate a core on systems where it does.
3171 +#
3172 +# Some systems append "core" to the name of the program; others append
3173 +# the name of the program to "core"; still others (like Linux, as of
3174 +# May 2003) create cores named "core.PID". In the latter case, we
3175 +# could have many core files lying around, and it may be difficult to
3176 +# tell which one is ours, so let's run the program in a subdirectory.
3177 +set found 0
3178 +set coredir "${objdir}/${subdir}/coredir.[getpid]"
3179 +file mkdir $coredir
3180 +catch "system \"(cd ${coredir}; ulimit -c unlimited; ${binfile}; true) >/dev/null 2>&1\""
3181 +# remote_exec host "${binfile}"
3182 +foreach i "${coredir}/core ${coredir}/core.coremaker.c ${binfile}.core" {
3183 + if [remote_file build exists $i] {
3184 + remote_exec build "mv $i ${objdir}/${subdir}/corefile"
3185 + set found 1
3186 + }
3187 +}
3188 +# Check for "core.PID".
3189 +if { $found == 0 } {
3190 + set names [glob -nocomplain -directory $coredir core.*]
3191 + if {[llength $names] == 1} {
3192 + set corefile [file join $coredir [lindex $names 0]]
3193 + remote_exec build "mv $corefile ${objdir}/${subdir}/corefile"
3194 + set found 1
3195 + }
3196 +}
3197 +if { $found == 0 } {
3198 + # The braindamaged HPUX shell quits after the ulimit -c above
3199 + # without executing ${binfile}. So we try again without the
3200 + # ulimit here if we didn't find a core file above.
3201 + # Oh, I should mention that any "braindamaged" non-Unix system has
3202 + # the same problem. I like the cd bit too, it's really neat'n stuff.
3203 + catch "system \"(cd ${objdir}/${subdir}; ${binfile}; true) >/dev/null 2>&1\""
3204 + foreach i "${objdir}/${subdir}/core ${objdir}/${subdir}/core.coremaker.c ${binfile}.core" {
3205 + if [remote_file build exists $i] {
3206 + remote_exec build "mv $i ${objdir}/${subdir}/corefile"
3207 + set found 1
3208 + }
3209 + }
3210 +}
3211 +
3212 +# Try to clean up after ourselves.
3213 +remote_file build delete [file join $coredir coremmap.data]
3214 +remote_exec build "rmdir $coredir"
3215 +
3216 +if { $found == 0 } {
3217 + warning "can't generate a core file - core tests suppressed - check ulimit -c"
3218 + return 0
3219 +}
3220 +
3221 +#
3222 +# Test that we can simply startup with a "-core=corefile" command line arg
3223 +# and recognize that the core file is a valid, usable core file.
3224 +# To do this, we must shutdown the currently running gdb and restart
3225 +# with the -core args. We can't use gdb_start because it looks for
3226 +# the first gdb prompt, and the message we are looking for occurs
3227 +# before the first prompt. Also, we can't include GDBFLAGS because
3228 +# if it is empty, this confuses gdb with an empty argument that it
3229 +# grumbles about (said grumbling currently being ignored in gdb_start).
3230 +# **FIXME**
3231 +#
3232 +# Another problem is that on some systems (solaris for example), there
3233 +# is apparently a limit on the length of a fully specified path to
3234 +# the coremaker executable, at about 80 chars. For this case, consider
3235 +# it a pass, but note that the program name is bad.
3236 +
3237 +gdb_exit
3238 +if $verbose>1 then {
3239 + send_user "Spawning $GDB -nw $GDBFLAGS -core=$objdir/$subdir/corefile\n"
3240 +}
3241 +
3242 +set oldtimeout $timeout
3243 +set timeout [expr "$timeout + 60"]
3244 +verbose "Timeout is now $timeout seconds" 2
3245 +eval "spawn $GDB -nw $GDBFLAGS -core=$objdir/$subdir/corefile"
3246 +expect {
3247 + -re "Couldn't find .* registers in core file.*$gdb_prompt $" {
3248 + fail "args: -core=corefile (couldn't find regs)"
3249 + }
3250 + -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
3251 + pass "args: -core=corefile"
3252 + }
3253 + -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
3254 + pass "args: -core=corefile (with bad program name)"
3255 + }
3256 + -re ".*registers from core file: File in wrong format.* $" {
3257 + fail "args: -core=corefile (could not read registers from core file)"
3258 + }
3259 + -re ".*$gdb_prompt $" { fail "args: -core=corefile" }
3260 + timeout { fail "(timeout) starting with -core" }
3261 +}
3262 +
3263 +
3264 +#
3265 +# Test that startup with both an executable file and -core argument.
3266 +# See previous comments above, they are still applicable.
3267 +#
3268 +
3269 +close;
3270 +
3271 +if $verbose>1 then {
3272 + send_user "Spawning $GDB -nw $GDBFLAGS $binfile -core=$objdir/$subdir/corefile\n"
3273 +}
3274 +
3275 +
3276 +eval "spawn $GDB -nw $GDBFLAGS $binfile -core=$objdir/$subdir/corefile";
3277 +expect {
3278 + -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
3279 + pass "args: execfile -core=corefile"
3280 + }
3281 + -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
3282 + pass "args: execfile -core=corefile (with bad program name)"
3283 + }
3284 + -re ".*registers from core file: File in wrong format.* $" {
3285 + fail "args: execfile -core=corefile (could not read registers from core file)"
3286 + }
3287 + -re ".*$gdb_prompt $" { fail "args: execfile -core=corefile" }
3288 + timeout { fail "(timeout) starting with -core" }
3289 +}
3290 +set timeout $oldtimeout
3291 +verbose "Timeout is now $timeout seconds" 2
3292 +
3293 +close;
3294 +
3295 +# Now restart normally.
3296 +
3297 +gdb_start
3298 +gdb_reinitialize_dir $srcdir/$subdir
3299 +gdb_load ${binfile}
3300 +
3301 +# Test basic corefile recognition via core-file command.
3302 +
3303 +send_gdb "core-file $objdir/$subdir/corefile\n"
3304 +gdb_expect {
3305 + -re ".* program is being debugged already.*y or n. $" {
3306 + # gdb_load may connect us to a gdbserver.
3307 + send_gdb "y\n"
3308 + exp_continue;
3309 + }
3310 + -re "Core was generated by .*coremaker.*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
3311 + pass "core-file command"
3312 + }
3313 + -re "Core was generated by .*\r\n\#0 .*\(\).*\r\n$gdb_prompt $" {
3314 + pass "core-file command (with bad program name)"
3315 + }
3316 + -re ".*registers from core file: File in wrong format.* $" {
3317 + fail "core-file command (could not read registers from core file)"
3318 + }
3319 + -re ".*$gdb_prompt $" { fail "core-file command" }
3320 + timeout { fail "(timeout) core-file command" }
3321 +}
3322 +
3323 +# Test correct mapping of corefile sections by printing some variables.
3324 +
3325 +gdb_test "print coremaker_data" "\\\$$decimal = 202"
3326 +gdb_test "print coremaker_bss" "\\\$$decimal = 10"
3327 +gdb_test "print coremaker_ro" "\\\$$decimal = 201"
3328 +
3329 +gdb_test "print func2::coremaker_local" "\\\$$decimal = \\{0, 1, 2, 3, 4\\}"
3330 +
3331 +# Somehow we better test the ability to read the registers out of the core
3332 +# file correctly. I don't think the other tests do this.
3333 +
3334 +gdb_test "bt" "abort.*func2.*func1.*main.*" "backtrace in corefile.exp"
3335 +gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(.*\\).*" "up in corefile.exp"
3336 +
3337 +# Test ability to read mmap'd data
3338 +
3339 +gdb_test "x/8bd buf1" ".*:.*0.*1.*2.*3.*4.*5.*6.*7" "accessing original mmap data in core file"
3340 +setup_xfail "*-*-sunos*" "*-*-ultrix*" "*-*-aix*"
3341 +set test "accessing mmapped data in core file"
3342 +gdb_test_multiple "x/8bd buf2" "$test" {
3343 + -re ".*:.*0.*1.*2.*3.*4.*5.*6.*7.*$gdb_prompt $" {
3344 + pass "$test"
3345 + }
3346 + -re "0x\[f\]*:.*Cannot access memory at address 0x\[f\]*.*$gdb_prompt $" {
3347 + fail "$test (mapping failed at runtime)"
3348 + }
3349 + -re "0x.*:.*Cannot access memory at address 0x.*$gdb_prompt $" {
3350 + fail "$test (mapping address not found in core file)"
3351 + }
3352 +}
3353 +
3354 +# test reinit_frame_cache
3355 +
3356 +gdb_load ${binfile}
3357 +gdb_test "up" "#\[0-9\]* *\[0-9xa-fH'\]* in .* \\(\\).*" "up in corefile.exp (reinit)"
3358 +
3359 +gdb_test "core" "No core file now."
3360 Index: gdb-6.8/gdb/testsuite/gdb.pie/coremaker.c
3361 ===================================================================
3362 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
3363 +++ gdb-6.8/gdb/testsuite/gdb.pie/coremaker.c 2008-03-30 08:59:12.000000000 -0700
3364 @@ -0,0 +1,142 @@
3365 +/* Copyright 1992, 1993, 1994, 1995, 1996, 1999
3366 + Free Software Foundation, Inc.
3367 +
3368 + This file is part of GDB.
3369 +
3370 + This program is free software; you can redistribute it and/or modify
3371 + it under the terms of the GNU General Public License as published by
3372 + the Free Software Foundation; either version 2 of the License, or (at
3373 + your option) any later version.
3374 +
3375 + This program is distributed in the hope that it will be useful, but
3376 + WITHOUT ANY WARRANTY; without even the implied warranty of
3377 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3378 + General Public License for more details.
3379 +
3380 + You should have received a copy of the GNU General Public License
3381 + along with this program; if not, write to the Free Software
3382 + Foundation, Inc., 59 Temple Place - Suite 330,
3383 + Boston, MA 02111-1307, USA. */
3384 +
3385 +/* Simple little program that just generates a core dump from inside some
3386 + nested function calls. */
3387 +
3388 +#include <stdio.h>
3389 +#include <sys/types.h>
3390 +#include <fcntl.h>
3391 +#include <sys/mman.h>
3392 +#include <signal.h>
3393 +#include <stdlib.h>
3394 +#include <unistd.h>
3395 +
3396 +#ifndef __STDC__
3397 +#define const /**/
3398 +#endif
3399 +
3400 +#define MAPSIZE (8 * 1024)
3401 +
3402 +/* Don't make these automatic vars or we will have to walk back up the
3403 + stack to access them. */
3404 +
3405 +char *buf1;
3406 +char *buf2;
3407 +
3408 +int coremaker_data = 1; /* In Data section */
3409 +int coremaker_bss; /* In BSS section */
3410 +
3411 +const int coremaker_ro = 201; /* In Read-Only Data section */
3412 +
3413 +/* Note that if the mapping fails for any reason, we set buf2
3414 + to -1 and the testsuite notices this and reports it as
3415 + a failure due to a mapping error. This way we don't have
3416 + to test for specific errors when running the core maker. */
3417 +
3418 +void
3419 +mmapdata ()
3420 +{
3421 + int j, fd;
3422 +
3423 + /* Allocate and initialize a buffer that will be used to write
3424 + the file that is later mapped in. */
3425 +
3426 + buf1 = (char *) malloc (MAPSIZE);
3427 + for (j = 0; j < MAPSIZE; ++j)
3428 + {
3429 + buf1[j] = j;
3430 + }
3431 +
3432 + /* Write the file to map in */
3433 +
3434 + fd = open ("coremmap.data", O_CREAT | O_RDWR, 0666);
3435 + if (fd == -1)
3436 + {
3437 + perror ("coremmap.data open failed");
3438 + buf2 = (char *) -1;
3439 + return;
3440 + }
3441 + write (fd, buf1, MAPSIZE);
3442 +
3443 + /* Now map the file into our address space as buf2 */
3444 +
3445 + buf2 = (char *) mmap (0, MAPSIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
3446 + if (buf2 == (char *) -1)
3447 + {
3448 + perror ("mmap failed");
3449 + return;
3450 + }
3451 +
3452 + /* Verify that the original data and the mapped data are identical.
3453 + If not, we'd rather fail now than when trying to access the mapped
3454 + data from the core file. */
3455 +
3456 + for (j = 0; j < MAPSIZE; ++j)
3457 + {
3458 + if (buf1[j] != buf2[j])
3459 + {
3460 + fprintf (stderr, "mapped data is incorrect");
3461 + buf2 = (char *) -1;
3462 + return;
3463 + }
3464 + }
3465 +}
3466 +
3467 +void
3468 +func2 ()
3469 +{
3470 + int coremaker_local[5];
3471 + int i;
3472 +
3473 +#ifdef SA_FULLDUMP
3474 + /* Force a corefile that includes the data section for AIX. */
3475 + {
3476 + struct sigaction sa;
3477 +
3478 + sigaction (SIGABRT, (struct sigaction *)0, &sa);
3479 + sa.sa_flags |= SA_FULLDUMP;
3480 + sigaction (SIGABRT, &sa, (struct sigaction *)0);
3481 + }
3482 +#endif
3483 +
3484 + /* Make sure that coremaker_local doesn't get optimized away. */
3485 + for (i = 0; i < 5; i++)
3486 + coremaker_local[i] = i;
3487 + coremaker_bss = 0;
3488 + for (i = 0; i < 5; i++)
3489 + coremaker_bss += coremaker_local[i];
3490 + coremaker_data = coremaker_ro + 1;
3491 + abort ();
3492 +}
3493 +
3494 +void
3495 +func1 ()
3496 +{
3497 + func2 ();
3498 +}
3499 +
3500 +int main ()
3501 +{
3502 + mmapdata ();
3503 + func1 ();
3504 + return 0;
3505 +}
3506 +
3507
3508
3509
3510 --
3511 gentoo-commits@l.g.o mailing list