OLD | NEW |
1 /* Target-dependent code for GDB, the GNU debugger. | 1 /* Target-dependent code for GDB, the GNU debugger. |
2 | 2 |
3 Copyright (C) 1986-1987, 1989, 1991-1997, 2000-2012 Free Software | 3 Copyright (C) 1986-2013 Free Software Foundation, Inc. |
4 Foundation, Inc. | |
5 | 4 |
6 This file is part of GDB. | 5 This file is part of GDB. |
7 | 6 |
8 This program is free software; you can redistribute it and/or modify | 7 This program is free software; you can redistribute it and/or modify |
9 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
10 the Free Software Foundation; either version 3 of the License, or | 9 the Free Software Foundation; either version 3 of the License, or |
11 (at your option) any later version. | 10 (at your option) any later version. |
12 | 11 |
13 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 14 matching lines...) Expand all Loading... |
29 #include "objfiles.h" | 28 #include "objfiles.h" |
30 #include "regcache.h" | 29 #include "regcache.h" |
31 #include "value.h" | 30 #include "value.h" |
32 #include "osabi.h" | 31 #include "osabi.h" |
33 #include "regset.h" | 32 #include "regset.h" |
34 #include "solib-svr4.h" | 33 #include "solib-svr4.h" |
35 #include "solib-spu.h" | 34 #include "solib-spu.h" |
36 #include "solib.h" | 35 #include "solib.h" |
37 #include "solist.h" | 36 #include "solist.h" |
38 #include "ppc-tdep.h" | 37 #include "ppc-tdep.h" |
| 38 #include "ppc64-tdep.h" |
39 #include "ppc-linux-tdep.h" | 39 #include "ppc-linux-tdep.h" |
40 #include "glibc-tdep.h" | 40 #include "glibc-tdep.h" |
41 #include "trad-frame.h" | 41 #include "trad-frame.h" |
42 #include "frame-unwind.h" | 42 #include "frame-unwind.h" |
43 #include "tramp-frame.h" | 43 #include "tramp-frame.h" |
44 #include "observer.h" | 44 #include "observer.h" |
45 #include "auxv.h" | 45 #include "auxv.h" |
46 #include "elf/common.h" | 46 #include "elf/common.h" |
47 #include "exceptions.h" | 47 #include "exceptions.h" |
48 #include "arch-utils.h" | 48 #include "arch-utils.h" |
49 #include "spu-tdep.h" | 49 #include "spu-tdep.h" |
50 #include "xml-syscall.h" | 50 #include "xml-syscall.h" |
51 #include "linux-tdep.h" | 51 #include "linux-tdep.h" |
52 | 52 |
53 #include "stap-probe.h" | 53 #include "stap-probe.h" |
54 #include "ax.h" | 54 #include "ax.h" |
55 #include "ax-gdb.h" | 55 #include "ax-gdb.h" |
56 #include "cli/cli-utils.h" | 56 #include "cli/cli-utils.h" |
57 #include "parser-defs.h" | 57 #include "parser-defs.h" |
58 #include "user-regs.h" | 58 #include "user-regs.h" |
59 #include <ctype.h> | 59 #include <ctype.h> |
| 60 #include "elf-bfd.h" /* for elfcore_write_* */ |
60 | 61 |
61 #include "features/rs6000/powerpc-32l.c" | 62 #include "features/rs6000/powerpc-32l.c" |
62 #include "features/rs6000/powerpc-altivec32l.c" | 63 #include "features/rs6000/powerpc-altivec32l.c" |
63 #include "features/rs6000/powerpc-cell32l.c" | 64 #include "features/rs6000/powerpc-cell32l.c" |
64 #include "features/rs6000/powerpc-vsx32l.c" | 65 #include "features/rs6000/powerpc-vsx32l.c" |
65 #include "features/rs6000/powerpc-isa205-32l.c" | 66 #include "features/rs6000/powerpc-isa205-32l.c" |
66 #include "features/rs6000/powerpc-isa205-altivec32l.c" | 67 #include "features/rs6000/powerpc-isa205-altivec32l.c" |
67 #include "features/rs6000/powerpc-isa205-vsx32l.c" | 68 #include "features/rs6000/powerpc-isa205-vsx32l.c" |
68 #include "features/rs6000/powerpc-64l.c" | 69 #include "features/rs6000/powerpc-64l.c" |
69 #include "features/rs6000/powerpc-altivec64l.c" | 70 #include "features/rs6000/powerpc-altivec64l.c" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT | 249 if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT |
249 || TYPE_CODE (valtype) == TYPE_CODE_UNION) | 250 || TYPE_CODE (valtype) == TYPE_CODE_UNION) |
250 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8) | 251 && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8) |
251 && TYPE_VECTOR (valtype))) | 252 && TYPE_VECTOR (valtype))) |
252 return RETURN_VALUE_STRUCT_CONVENTION; | 253 return RETURN_VALUE_STRUCT_CONVENTION; |
253 else | 254 else |
254 return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache, | 255 return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache, |
255 readbuf, writebuf); | 256 readbuf, writebuf); |
256 } | 257 } |
257 | 258 |
258 /* Macros for matching instructions. Note that, since all the | |
259 operands are masked off before they're or-ed into the instruction, | |
260 you can use -1 to make masks. */ | |
261 | |
262 #define insn_d(opcd, rts, ra, d) \ | |
263 ((((opcd) & 0x3f) << 26) \ | |
264 | (((rts) & 0x1f) << 21) \ | |
265 | (((ra) & 0x1f) << 16) \ | |
266 | ((d) & 0xffff)) | |
267 | |
268 #define insn_ds(opcd, rts, ra, d, xo) \ | |
269 ((((opcd) & 0x3f) << 26) \ | |
270 | (((rts) & 0x1f) << 21) \ | |
271 | (((ra) & 0x1f) << 16) \ | |
272 | ((d) & 0xfffc) \ | |
273 | ((xo) & 0x3)) | |
274 | |
275 #define insn_xfx(opcd, rts, spr, xo) \ | |
276 ((((opcd) & 0x3f) << 26) \ | |
277 | (((rts) & 0x1f) << 21) \ | |
278 | (((spr) & 0x1f) << 16) \ | |
279 | (((spr) & 0x3e0) << 6) \ | |
280 | (((xo) & 0x3ff) << 1)) | |
281 | |
282 /* Read a PPC instruction from memory. PPC instructions are always | |
283 big-endian, no matter what endianness the program is running in, so | |
284 we can't use read_memory_integer or one of its friends here. */ | |
285 static unsigned int | |
286 read_insn (CORE_ADDR pc) | |
287 { | |
288 unsigned char buf[4]; | |
289 | |
290 read_memory (pc, buf, 4); | |
291 return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
292 } | |
293 | |
294 | |
295 /* An instruction to match. */ | |
296 struct insn_pattern | |
297 { | |
298 unsigned int mask; /* mask the insn with this... */ | |
299 unsigned int data; /* ...and see if it matches this. */ | |
300 int optional; /* If non-zero, this insn may be absent. */ | |
301 }; | |
302 | |
303 /* Return non-zero if the instructions at PC match the series | |
304 described in PATTERN, or zero otherwise. PATTERN is an array of | |
305 'struct insn_pattern' objects, terminated by an entry whose mask is | |
306 zero. | |
307 | |
308 When the match is successful, fill INSN[i] with what PATTERN[i] | |
309 matched. If PATTERN[i] is optional, and the instruction wasn't | |
310 present, set INSN[i] to 0 (which is not a valid PPC instruction). | |
311 INSN should have as many elements as PATTERN. Note that, if | |
312 PATTERN contains optional instructions which aren't present in | |
313 memory, then INSN will have holes, so INSN[i] isn't necessarily the | |
314 i'th instruction in memory. */ | |
315 static int | |
316 insns_match_pattern (CORE_ADDR pc, | |
317 struct insn_pattern *pattern, | |
318 unsigned int *insn) | |
319 { | |
320 int i; | |
321 | |
322 for (i = 0; pattern[i].mask; i++) | |
323 { | |
324 insn[i] = read_insn (pc); | |
325 if ((insn[i] & pattern[i].mask) == pattern[i].data) | |
326 pc += 4; | |
327 else if (pattern[i].optional) | |
328 insn[i] = 0; | |
329 else | |
330 return 0; | |
331 } | |
332 | |
333 return 1; | |
334 } | |
335 | |
336 | |
337 /* Return the 'd' field of the d-form instruction INSN, properly | |
338 sign-extended. */ | |
339 static CORE_ADDR | |
340 insn_d_field (unsigned int insn) | |
341 { | |
342 return ((((CORE_ADDR) insn & 0xffff) ^ 0x8000) - 0x8000); | |
343 } | |
344 | |
345 | |
346 /* Return the 'ds' field of the ds-form instruction INSN, with the two | |
347 zero bits concatenated at the right, and properly | |
348 sign-extended. */ | |
349 static CORE_ADDR | |
350 insn_ds_field (unsigned int insn) | |
351 { | |
352 return ((((CORE_ADDR) insn & 0xfffc) ^ 0x8000) - 0x8000); | |
353 } | |
354 | |
355 | |
356 /* If DESC is the address of a 64-bit PowerPC GNU/Linux function | |
357 descriptor, return the descriptor's entry point. */ | |
358 static CORE_ADDR | |
359 ppc64_desc_entry_point (struct gdbarch *gdbarch, CORE_ADDR desc) | |
360 { | |
361 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
362 /* The first word of the descriptor is the entry point. */ | |
363 return (CORE_ADDR) read_memory_unsigned_integer (desc, 8, byte_order); | |
364 } | |
365 | |
366 | |
367 /* Pattern for the standard linkage function. These are built by | |
368 build_plt_stub in elf64-ppc.c, whose GLINK argument is always | |
369 zero. */ | |
370 static struct insn_pattern ppc64_standard_linkage1[] = | |
371 { | |
372 /* addis r12, r2, <any> */ | |
373 { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 }, | |
374 | |
375 /* std r2, 40(r1) */ | |
376 { -1, insn_ds (62, 2, 1, 40, 0), 0 }, | |
377 | |
378 /* ld r11, <any>(r12) */ | |
379 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 }, | |
380 | |
381 /* addis r12, r12, 1 <optional> */ | |
382 { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 }, | |
383 | |
384 /* ld r2, <any>(r12) */ | |
385 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 }, | |
386 | |
387 /* addis r12, r12, 1 <optional> */ | |
388 { insn_d (-1, -1, -1, -1), insn_d (15, 12, 12, 1), 1 }, | |
389 | |
390 /* mtctr r11 */ | |
391 { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 }, | |
392 | |
393 /* ld r11, <any>(r12) */ | |
394 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 }, | |
395 | |
396 /* bctr */ | |
397 { -1, 0x4e800420, 0 }, | |
398 | |
399 { 0, 0, 0 } | |
400 }; | |
401 #define PPC64_STANDARD_LINKAGE1_LEN \ | |
402 (sizeof (ppc64_standard_linkage1) / sizeof (ppc64_standard_linkage1[0])) | |
403 | |
404 static struct insn_pattern ppc64_standard_linkage2[] = | |
405 { | |
406 /* addis r12, r2, <any> */ | |
407 { insn_d (-1, -1, -1, 0), insn_d (15, 12, 2, 0), 0 }, | |
408 | |
409 /* std r2, 40(r1) */ | |
410 { -1, insn_ds (62, 2, 1, 40, 0), 0 }, | |
411 | |
412 /* ld r11, <any>(r12) */ | |
413 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 }, | |
414 | |
415 /* addi r12, r12, <any> <optional> */ | |
416 { insn_d (-1, -1, -1, 0), insn_d (14, 12, 12, 0), 1 }, | |
417 | |
418 /* mtctr r11 */ | |
419 { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 }, | |
420 | |
421 /* ld r2, <any>(r12) */ | |
422 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 12, 0, 0), 0 }, | |
423 | |
424 /* ld r11, <any>(r12) */ | |
425 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 12, 0, 0), 0 }, | |
426 | |
427 /* bctr */ | |
428 { -1, 0x4e800420, 0 }, | |
429 | |
430 { 0, 0, 0 } | |
431 }; | |
432 #define PPC64_STANDARD_LINKAGE2_LEN \ | |
433 (sizeof (ppc64_standard_linkage2) / sizeof (ppc64_standard_linkage2[0])) | |
434 | |
435 static struct insn_pattern ppc64_standard_linkage3[] = | |
436 { | |
437 /* std r2, 40(r1) */ | |
438 { -1, insn_ds (62, 2, 1, 40, 0), 0 }, | |
439 | |
440 /* ld r11, <any>(r2) */ | |
441 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 }, | |
442 | |
443 /* addi r2, r2, <any> <optional> */ | |
444 { insn_d (-1, -1, -1, 0), insn_d (14, 2, 2, 0), 1 }, | |
445 | |
446 /* mtctr r11 */ | |
447 { insn_xfx (-1, -1, -1, -1), insn_xfx (31, 11, 9, 467), 0 }, | |
448 | |
449 /* ld r11, <any>(r2) */ | |
450 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 11, 2, 0, 0), 0 }, | |
451 | |
452 /* ld r2, <any>(r2) */ | |
453 { insn_ds (-1, -1, -1, 0, -1), insn_ds (58, 2, 2, 0, 0), 0 }, | |
454 | |
455 /* bctr */ | |
456 { -1, 0x4e800420, 0 }, | |
457 | |
458 { 0, 0, 0 } | |
459 }; | |
460 #define PPC64_STANDARD_LINKAGE3_LEN \ | |
461 (sizeof (ppc64_standard_linkage3) / sizeof (ppc64_standard_linkage3[0])) | |
462 | |
463 | |
464 /* When the dynamic linker is doing lazy symbol resolution, the first | |
465 call to a function in another object will go like this: | |
466 | |
467 - The user's function calls the linkage function: | |
468 | |
469 100007c4: 4b ff fc d5 bl 10000498 | |
470 100007c8: e8 41 00 28 ld r2,40(r1) | |
471 | |
472 - The linkage function loads the entry point (and other stuff) from | |
473 the function descriptor in the PLT, and jumps to it: | |
474 | |
475 10000498: 3d 82 00 00 addis r12,r2,0 | |
476 1000049c: f8 41 00 28 std r2,40(r1) | |
477 100004a0: e9 6c 80 98 ld r11,-32616(r12) | |
478 100004a4: e8 4c 80 a0 ld r2,-32608(r12) | |
479 100004a8: 7d 69 03 a6 mtctr r11 | |
480 100004ac: e9 6c 80 a8 ld r11,-32600(r12) | |
481 100004b0: 4e 80 04 20 bctr | |
482 | |
483 - But since this is the first time that PLT entry has been used, it | |
484 sends control to its glink entry. That loads the number of the | |
485 PLT entry and jumps to the common glink0 code: | |
486 | |
487 10000c98: 38 00 00 00 li r0,0 | |
488 10000c9c: 4b ff ff dc b 10000c78 | |
489 | |
490 - The common glink0 code then transfers control to the dynamic | |
491 linker's fixup code: | |
492 | |
493 10000c78: e8 41 00 28 ld r2,40(r1) | |
494 10000c7c: 3d 82 00 00 addis r12,r2,0 | |
495 10000c80: e9 6c 80 80 ld r11,-32640(r12) | |
496 10000c84: e8 4c 80 88 ld r2,-32632(r12) | |
497 10000c88: 7d 69 03 a6 mtctr r11 | |
498 10000c8c: e9 6c 80 90 ld r11,-32624(r12) | |
499 10000c90: 4e 80 04 20 bctr | |
500 | |
501 Eventually, this code will figure out how to skip all of this, | |
502 including the dynamic linker. At the moment, we just get through | |
503 the linkage function. */ | |
504 | |
505 /* If the current thread is about to execute a series of instructions | |
506 at PC matching the ppc64_standard_linkage pattern, and INSN is the result | |
507 from that pattern match, return the code address to which the | |
508 standard linkage function will send them. (This doesn't deal with | |
509 dynamic linker lazy symbol resolution stubs.) */ | |
510 static CORE_ADDR | |
511 ppc64_standard_linkage1_target (struct frame_info *frame, | |
512 CORE_ADDR pc, unsigned int *insn) | |
513 { | |
514 struct gdbarch *gdbarch = get_frame_arch (frame); | |
515 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
516 | |
517 /* The address of the function descriptor this linkage function | |
518 references. */ | |
519 CORE_ADDR desc | |
520 = ((CORE_ADDR) get_frame_register_unsigned (frame, | |
521 tdep->ppc_gp0_regnum + 2) | |
522 + (insn_d_field (insn[0]) << 16) | |
523 + insn_ds_field (insn[2])); | |
524 | |
525 /* The first word of the descriptor is the entry point. Return that. */ | |
526 return ppc64_desc_entry_point (gdbarch, desc); | |
527 } | |
528 | |
529 static struct core_regset_section ppc_linux_vsx_regset_sections[] = | 259 static struct core_regset_section ppc_linux_vsx_regset_sections[] = |
530 { | 260 { |
531 { ".reg", 48 * 4, "general-purpose" }, | 261 { ".reg", 48 * 4, "general-purpose" }, |
532 { ".reg2", 264, "floating-point" }, | 262 { ".reg2", 264, "floating-point" }, |
533 { ".reg-ppc-vmx", 544, "ppc Altivec" }, | 263 { ".reg-ppc-vmx", 544, "ppc Altivec" }, |
534 { ".reg-ppc-vsx", 256, "POWER7 VSX" }, | 264 { ".reg-ppc-vsx", 256, "POWER7 VSX" }, |
535 { NULL, 0} | 265 { NULL, 0} |
536 }; | 266 }; |
537 | 267 |
538 static struct core_regset_section ppc_linux_vmx_regset_sections[] = | 268 static struct core_regset_section ppc_linux_vmx_regset_sections[] = |
(...skipping 28 matching lines...) Expand all Loading... |
567 { NULL, 0} | 297 { NULL, 0} |
568 }; | 298 }; |
569 | 299 |
570 static struct core_regset_section ppc64_linux_fp_regset_sections[] = | 300 static struct core_regset_section ppc64_linux_fp_regset_sections[] = |
571 { | 301 { |
572 { ".reg", 48 * 8, "general-purpose" }, | 302 { ".reg", 48 * 8, "general-purpose" }, |
573 { ".reg2", 264, "floating-point" }, | 303 { ".reg2", 264, "floating-point" }, |
574 { NULL, 0} | 304 { NULL, 0} |
575 }; | 305 }; |
576 | 306 |
577 static CORE_ADDR | |
578 ppc64_standard_linkage2_target (struct frame_info *frame, | |
579 CORE_ADDR pc, unsigned int *insn) | |
580 { | |
581 struct gdbarch *gdbarch = get_frame_arch (frame); | |
582 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
583 | |
584 /* The address of the function descriptor this linkage function | |
585 references. */ | |
586 CORE_ADDR desc | |
587 = ((CORE_ADDR) get_frame_register_unsigned (frame, | |
588 tdep->ppc_gp0_regnum + 2) | |
589 + (insn_d_field (insn[0]) << 16) | |
590 + insn_ds_field (insn[2])); | |
591 | |
592 /* The first word of the descriptor is the entry point. Return that. */ | |
593 return ppc64_desc_entry_point (gdbarch, desc); | |
594 } | |
595 | |
596 static CORE_ADDR | |
597 ppc64_standard_linkage3_target (struct frame_info *frame, | |
598 CORE_ADDR pc, unsigned int *insn) | |
599 { | |
600 struct gdbarch *gdbarch = get_frame_arch (frame); | |
601 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
602 | |
603 /* The address of the function descriptor this linkage function | |
604 references. */ | |
605 CORE_ADDR desc | |
606 = ((CORE_ADDR) get_frame_register_unsigned (frame, | |
607 tdep->ppc_gp0_regnum + 2) | |
608 + insn_ds_field (insn[1])); | |
609 | |
610 /* The first word of the descriptor is the entry point. Return that. */ | |
611 return ppc64_desc_entry_point (gdbarch, desc); | |
612 } | |
613 | |
614 /* PLT stub in executable. */ | 307 /* PLT stub in executable. */ |
615 static struct insn_pattern powerpc32_plt_stub[] = | 308 static struct ppc_insn_pattern powerpc32_plt_stub[] = |
616 { | 309 { |
617 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */ | 310 { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */ |
618 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */ | 311 { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */ |
619 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ | 312 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ |
620 { 0xffffffff, 0x4e800420, 0 }, /* bctr */ | 313 { 0xffffffff, 0x4e800420, 0 }, /* bctr */ |
621 { 0, 0, 0 } | 314 { 0, 0, 0 } |
622 }; | 315 }; |
623 | 316 |
624 /* PLT stub in shared library. */ | 317 /* PLT stub in shared library. */ |
625 static struct insn_pattern powerpc32_plt_stub_so[] = | 318 static struct ppc_insn_pattern powerpc32_plt_stub_so[] = |
626 { | 319 { |
627 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */ | 320 { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */ |
628 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ | 321 { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */ |
629 { 0xffffffff, 0x4e800420, 0 }, /* bctr */ | 322 { 0xffffffff, 0x4e800420, 0 }, /* bctr */ |
630 { 0xffffffff, 0x60000000, 0 }, /* nop */ | 323 { 0xffffffff, 0x60000000, 0 }, /* nop */ |
631 { 0, 0, 0 } | 324 { 0, 0, 0 } |
632 }; | 325 }; |
633 #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub) | 326 #define POWERPC32_PLT_STUB_LEN ARRAY_SIZE (powerpc32_plt_stub) |
634 | 327 |
635 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt | 328 /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt |
636 section. For secure PLT, stub is in .text and we need to check | 329 section. For secure PLT, stub is in .text and we need to check |
637 instruction patterns. */ | 330 instruction patterns. */ |
638 | 331 |
639 static int | 332 static int |
640 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc) | 333 powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc) |
641 { | 334 { |
642 struct minimal_symbol *sym; | 335 struct bound_minimal_symbol sym; |
643 | 336 |
644 /* Check whether PC is in the dynamic linker. This also checks | 337 /* Check whether PC is in the dynamic linker. This also checks |
645 whether it is in the .plt section, used by non-PIC executables. */ | 338 whether it is in the .plt section, used by non-PIC executables. */ |
646 if (svr4_in_dynsym_resolve_code (pc)) | 339 if (svr4_in_dynsym_resolve_code (pc)) |
647 return 1; | 340 return 1; |
648 | 341 |
649 /* Check if we are in the resolver. */ | 342 /* Check if we are in the resolver. */ |
650 sym = lookup_minimal_symbol_by_pc (pc); | 343 sym = lookup_minimal_symbol_by_pc (pc); |
651 if (sym != NULL | 344 if (sym.minsym != NULL |
652 && (strcmp (SYMBOL_LINKAGE_NAME (sym), "__glink") == 0 | 345 && (strcmp (SYMBOL_LINKAGE_NAME (sym.minsym), "__glink") == 0 |
653 » || strcmp (SYMBOL_LINKAGE_NAME (sym), "__glink_PLTresolve") == 0)) | 346 » || strcmp (SYMBOL_LINKAGE_NAME (sym.minsym), |
| 347 » » "__glink_PLTresolve") == 0)) |
654 return 1; | 348 return 1; |
655 | 349 |
656 return 0; | 350 return 0; |
657 } | 351 } |
658 | 352 |
659 /* Follow PLT stub to actual routine. */ | 353 /* Follow PLT stub to actual routine. */ |
660 | 354 |
661 static CORE_ADDR | 355 static CORE_ADDR |
662 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) | 356 ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) |
663 { | 357 { |
664 int insnbuf[POWERPC32_PLT_STUB_LEN]; | 358 unsigned int insnbuf[POWERPC32_PLT_STUB_LEN]; |
665 struct gdbarch *gdbarch = get_frame_arch (frame); | 359 struct gdbarch *gdbarch = get_frame_arch (frame); |
666 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | 360 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
667 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | 361 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
668 CORE_ADDR target = 0; | 362 CORE_ADDR target = 0; |
669 | 363 |
670 if (insns_match_pattern (pc, powerpc32_plt_stub, insnbuf)) | 364 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf)) |
671 { | 365 { |
672 /* Insn pattern is | 366 /* Insn pattern is |
673 lis r11, xxxx | 367 lis r11, xxxx |
674 lwz r11, xxxx(r11) | 368 lwz r11, xxxx(r11) |
675 Branch target is in r11. */ | 369 Branch target is in r11. */ |
676 | 370 |
677 target = (insn_d_field (insnbuf[0]) << 16) | insn_d_field (insnbuf[1]); | 371 target = (ppc_insn_d_field (insnbuf[0]) << 16) |
| 372 » | ppc_insn_d_field (insnbuf[1]); |
678 target = read_memory_unsigned_integer (target, 4, byte_order); | 373 target = read_memory_unsigned_integer (target, 4, byte_order); |
679 } | 374 } |
680 | 375 |
681 if (insns_match_pattern (pc, powerpc32_plt_stub_so, insnbuf)) | 376 if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so, insnbuf)) |
682 { | 377 { |
683 /* Insn pattern is | 378 /* Insn pattern is |
684 lwz r11, xxxx(r30) | 379 lwz r11, xxxx(r30) |
685 Branch target is in r11. */ | 380 Branch target is in r11. */ |
686 | 381 |
687 target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30) | 382 target = get_frame_register_unsigned (frame, tdep->ppc_gp0_regnum + 30) |
688 » + insn_d_field (insnbuf[0]); | 383 » + ppc_insn_d_field (insnbuf[0]); |
689 target = read_memory_unsigned_integer (target, 4, byte_order); | 384 target = read_memory_unsigned_integer (target, 4, byte_order); |
690 } | 385 } |
691 | 386 |
692 return target; | 387 return target; |
693 } | 388 } |
694 | 389 |
695 /* Given that we've begun executing a call trampoline at PC, return | |
696 the entry point of the function the trampoline will go to. */ | |
697 static CORE_ADDR | |
698 ppc64_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc) | |
699 { | |
700 unsigned int ppc64_standard_linkage1_insn[PPC64_STANDARD_LINKAGE1_LEN]; | |
701 unsigned int ppc64_standard_linkage2_insn[PPC64_STANDARD_LINKAGE2_LEN]; | |
702 unsigned int ppc64_standard_linkage3_insn[PPC64_STANDARD_LINKAGE3_LEN]; | |
703 CORE_ADDR target; | |
704 | |
705 if (insns_match_pattern (pc, ppc64_standard_linkage1, | |
706 ppc64_standard_linkage1_insn)) | |
707 pc = ppc64_standard_linkage1_target (frame, pc, | |
708 ppc64_standard_linkage1_insn); | |
709 else if (insns_match_pattern (pc, ppc64_standard_linkage2, | |
710 ppc64_standard_linkage2_insn)) | |
711 pc = ppc64_standard_linkage2_target (frame, pc, | |
712 ppc64_standard_linkage2_insn); | |
713 else if (insns_match_pattern (pc, ppc64_standard_linkage3, | |
714 ppc64_standard_linkage3_insn)) | |
715 pc = ppc64_standard_linkage3_target (frame, pc, | |
716 ppc64_standard_linkage3_insn); | |
717 else | |
718 return 0; | |
719 | |
720 /* The PLT descriptor will either point to the already resolved target | |
721 address, or else to a glink stub. As the latter carry synthetic @plt | |
722 symbols, find_solib_trampoline_target should be able to resolve them. */ | |
723 target = find_solib_trampoline_target (frame, pc); | |
724 return target? target : pc; | |
725 } | |
726 | |
727 | |
728 /* Support for convert_from_func_ptr_addr (ARCH, ADDR, TARG) on PPC64 | |
729 GNU/Linux. | |
730 | |
731 Usually a function pointer's representation is simply the address | |
732 of the function. On GNU/Linux on the PowerPC however, a function | |
733 pointer may be a pointer to a function descriptor. | |
734 | |
735 For PPC64, a function descriptor is a TOC entry, in a data section, | |
736 which contains three words: the first word is the address of the | |
737 function, the second word is the TOC pointer (r2), and the third word | |
738 is the static chain value. | |
739 | |
740 Throughout GDB it is currently assumed that a function pointer contains | |
741 the address of the function, which is not easy to fix. In addition, the | |
742 conversion of a function address to a function pointer would | |
743 require allocation of a TOC entry in the inferior's memory space, | |
744 with all its drawbacks. To be able to call C++ virtual methods in | |
745 the inferior (which are called via function pointers), | |
746 find_function_addr uses this function to get the function address | |
747 from a function pointer. | |
748 | |
749 If ADDR points at what is clearly a function descriptor, transform | |
750 it into the address of the corresponding function, if needed. Be | |
751 conservative, otherwise GDB will do the transformation on any | |
752 random addresses such as occur when there is no symbol table. */ | |
753 | |
754 static CORE_ADDR | |
755 ppc64_linux_convert_from_func_ptr_addr (struct gdbarch *gdbarch, | |
756 CORE_ADDR addr, | |
757 struct target_ops *targ) | |
758 { | |
759 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
760 struct target_section *s = target_section_by_addr (targ, addr); | |
761 | |
762 /* Check if ADDR points to a function descriptor. */ | |
763 if (s && strcmp (s->the_bfd_section->name, ".opd") == 0) | |
764 { | |
765 /* There may be relocations that need to be applied to the .opd | |
766 section. Unfortunately, this function may be called at a time | |
767 where these relocations have not yet been performed -- this can | |
768 happen for example shortly after a library has been loaded with | |
769 dlopen, but ld.so has not yet applied the relocations. | |
770 | |
771 To cope with both the case where the relocation has been applied, | |
772 and the case where it has not yet been applied, we do *not* read | |
773 the (maybe) relocated value from target memory, but we instead | |
774 read the non-relocated value from the BFD, and apply the relocation | |
775 offset manually. | |
776 | |
777 This makes the assumption that all .opd entries are always relocated | |
778 by the same offset the section itself was relocated. This should | |
779 always be the case for GNU/Linux executables and shared libraries. | |
780 Note that other kind of object files (e.g. those added via | |
781 add-symbol-files) will currently never end up here anyway, as this | |
782 function accesses *target* sections only; only the main exec and | |
783 shared libraries are ever added to the target. */ | |
784 | |
785 gdb_byte buf[8]; | |
786 int res; | |
787 | |
788 res = bfd_get_section_contents (s->bfd, s->the_bfd_section, | |
789 &buf, addr - s->addr, 8); | |
790 if (res != 0) | |
791 return extract_unsigned_integer (buf, 8, byte_order) | |
792 - bfd_section_vma (s->bfd, s->the_bfd_section) + s->addr; | |
793 } | |
794 | |
795 return addr; | |
796 } | |
797 | |
798 /* Wrappers to handle Linux-only registers. */ | 390 /* Wrappers to handle Linux-only registers. */ |
799 | 391 |
800 static void | 392 static void |
801 ppc_linux_supply_gregset (const struct regset *regset, | 393 ppc_linux_supply_gregset (const struct regset *regset, |
802 struct regcache *regcache, | 394 struct regcache *regcache, |
803 int regnum, const void *gregs, size_t len) | 395 int regnum, const void *gregs, size_t len) |
804 { | 396 { |
805 const struct ppc_reg_offsets *offsets = regset->descr; | 397 const struct ppc_reg_offsets *offsets = regset->descr; |
806 | 398 |
807 ppc_supply_gregset (regset, regcache, regnum, gregs, len); | 399 ppc_supply_gregset (regset, regcache, regnum, gregs, len); |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1736 set_solib_ops (gdbarch, &powerpc_so_ops); | 1328 set_solib_ops (gdbarch, &powerpc_so_ops); |
1737 | 1329 |
1738 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); | 1330 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); |
1739 } | 1331 } |
1740 | 1332 |
1741 if (tdep->wordsize == 8) | 1333 if (tdep->wordsize == 8) |
1742 { | 1334 { |
1743 /* Handle PPC GNU/Linux 64-bit function pointers (which are really | 1335 /* Handle PPC GNU/Linux 64-bit function pointers (which are really |
1744 function descriptors). */ | 1336 function descriptors). */ |
1745 set_gdbarch_convert_from_func_ptr_addr | 1337 set_gdbarch_convert_from_func_ptr_addr |
1746 » (gdbarch, ppc64_linux_convert_from_func_ptr_addr); | 1338 » (gdbarch, ppc64_convert_from_func_ptr_addr); |
| 1339 |
| 1340 set_gdbarch_elf_make_msymbol_special (gdbarch, |
| 1341 » » » » » ppc64_elf_make_msymbol_special); |
1747 | 1342 |
1748 /* Shared library handling. */ | 1343 /* Shared library handling. */ |
1749 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code); | 1344 set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code); |
1750 set_solib_svr4_fetch_link_map_offsets | 1345 set_solib_svr4_fetch_link_map_offsets |
1751 (gdbarch, svr4_lp64_fetch_link_map_offsets); | 1346 (gdbarch, svr4_lp64_fetch_link_map_offsets); |
1752 | 1347 |
1753 /* Setting the correct XML syscall filename. */ | 1348 /* Setting the correct XML syscall filename. */ |
1754 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64); | 1349 set_xml_syscall_file_name (XML_SYSCALL_FILENAME_PPC64); |
1755 | 1350 |
1756 /* Trampolines. */ | 1351 /* Trampolines. */ |
(...skipping 14 matching lines...) Expand all Loading... |
1771 set_gdbarch_core_regset_sections (gdbarch, | 1366 set_gdbarch_core_regset_sections (gdbarch, |
1772 ppc64_linux_vsx_regset_sections); | 1367 ppc64_linux_vsx_regset_sections); |
1773 else if (tdesc_find_feature (info.target_desc, | 1368 else if (tdesc_find_feature (info.target_desc, |
1774 "org.gnu.gdb.power.altivec")) | 1369 "org.gnu.gdb.power.altivec")) |
1775 set_gdbarch_core_regset_sections (gdbarch, | 1370 set_gdbarch_core_regset_sections (gdbarch, |
1776 ppc64_linux_vmx_regset_sections); | 1371 ppc64_linux_vmx_regset_sections); |
1777 else | 1372 else |
1778 set_gdbarch_core_regset_sections (gdbarch, | 1373 set_gdbarch_core_regset_sections (gdbarch, |
1779 ppc64_linux_fp_regset_sections); | 1374 ppc64_linux_fp_regset_sections); |
1780 } | 1375 } |
| 1376 |
| 1377 /* PPC32 uses a different prpsinfo32 compared to most other Linux |
| 1378 archs. */ |
| 1379 if (tdep->wordsize == 4) |
| 1380 set_gdbarch_elfcore_write_linux_prpsinfo (gdbarch, |
| 1381 elfcore_write_ppc_linux_prpsinfo32
); |
| 1382 |
1781 set_gdbarch_regset_from_core_section (gdbarch, | 1383 set_gdbarch_regset_from_core_section (gdbarch, |
1782 ppc_linux_regset_from_core_section); | 1384 ppc_linux_regset_from_core_section); |
1783 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description); | 1385 set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description); |
1784 | 1386 |
1785 /* Enable TLS support. */ | 1387 /* Enable TLS support. */ |
1786 set_gdbarch_fetch_tls_load_module_address (gdbarch, | 1388 set_gdbarch_fetch_tls_load_module_address (gdbarch, |
1787 svr4_fetch_objfile_link_map); | 1389 svr4_fetch_objfile_link_map); |
1788 | 1390 |
1789 if (tdesc_data) | 1391 if (tdesc_data) |
1790 { | 1392 { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 initialize_tdesc_powerpc_isa205_vsx32l (); | 1462 initialize_tdesc_powerpc_isa205_vsx32l (); |
1861 initialize_tdesc_powerpc_64l (); | 1463 initialize_tdesc_powerpc_64l (); |
1862 initialize_tdesc_powerpc_altivec64l (); | 1464 initialize_tdesc_powerpc_altivec64l (); |
1863 initialize_tdesc_powerpc_cell64l (); | 1465 initialize_tdesc_powerpc_cell64l (); |
1864 initialize_tdesc_powerpc_vsx64l (); | 1466 initialize_tdesc_powerpc_vsx64l (); |
1865 initialize_tdesc_powerpc_isa205_64l (); | 1467 initialize_tdesc_powerpc_isa205_64l (); |
1866 initialize_tdesc_powerpc_isa205_altivec64l (); | 1468 initialize_tdesc_powerpc_isa205_altivec64l (); |
1867 initialize_tdesc_powerpc_isa205_vsx64l (); | 1469 initialize_tdesc_powerpc_isa205_vsx64l (); |
1868 initialize_tdesc_powerpc_e500l (); | 1470 initialize_tdesc_powerpc_e500l (); |
1869 } | 1471 } |
OLD | NEW |