1 /* Intel 386 target-dependent stuff.
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
29 #include "floatformat.h"
33 #include "arch-utils.h"
36 /* i386_register_byte[i] is the offset into the register file of the
37 start of register number i. We initialize this from
38 i386_register_raw_size. */
39 int i386_register_byte
[MAX_NUM_REGS
];
41 /* i386_register_raw_size[i] is the number of bytes of storage in
42 GDB's register array occupied by register i. */
43 int i386_register_raw_size
[MAX_NUM_REGS
] = {
57 /* i386_register_virtual_size[i] is the size in bytes of the virtual
58 type of register i. */
59 int i386_register_virtual_size
[MAX_NUM_REGS
];
62 /* This is the variable that is set with "set disassembly-flavor", and
63 its legitimate values. */
64 static const char att_flavor
[] = "att";
65 static const char intel_flavor
[] = "intel";
66 static const char *valid_flavors
[] =
72 static const char *disassembly_flavor
= att_flavor
;
74 /* This is used to keep the bfd arch_info in sync with the disassembly
76 static void set_disassembly_flavor_sfunc (char *, int,
77 struct cmd_list_element
*);
78 static void set_disassembly_flavor (void);
81 /* Stdio style buffering was used to minimize calls to ptrace, but
82 this buffering did not take into account that the code section
83 being accessed may not be an even number of buffers long (even if
84 the buffer is only sizeof(int) long). In cases where the code
85 section size happened to be a non-integral number of buffers long,
86 attempting to read the last buffer would fail. Simply using
87 target_read_memory and ignoring errors, rather than read_memory, is
88 not the correct solution, since legitimate access errors would then
89 be totally ignored. To properly handle this situation and continue
90 to use buffering would require that this code be able to determine
91 the minimum code section size granularity (not the alignment of the
92 section itself, since the actual failing case that pointed out this
93 problem had a section alignment of 4 but was not a multiple of 4
94 bytes long), on a target by target basis, and then adjust it's
95 buffer size accordingly. This is messy, but potentially feasible.
96 It probably needs the bfd library's help and support. For now, the
97 buffer size is set to 1. (FIXME -fnf) */
99 #define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
100 static CORE_ADDR codestream_next_addr
;
101 static CORE_ADDR codestream_addr
;
102 static unsigned char codestream_buf
[CODESTREAM_BUFSIZ
];
103 static int codestream_off
;
104 static int codestream_cnt
;
106 #define codestream_tell() (codestream_addr + codestream_off)
107 #define codestream_peek() \
108 (codestream_cnt == 0 ? \
109 codestream_fill(1) : codestream_buf[codestream_off])
110 #define codestream_get() \
111 (codestream_cnt-- == 0 ? \
112 codestream_fill(0) : codestream_buf[codestream_off++])
115 codestream_fill (int peek_flag
)
117 codestream_addr
= codestream_next_addr
;
118 codestream_next_addr
+= CODESTREAM_BUFSIZ
;
120 codestream_cnt
= CODESTREAM_BUFSIZ
;
121 read_memory (codestream_addr
, (char *) codestream_buf
, CODESTREAM_BUFSIZ
);
124 return (codestream_peek ());
126 return (codestream_get ());
130 codestream_seek (CORE_ADDR place
)
132 codestream_next_addr
= place
/ CODESTREAM_BUFSIZ
;
133 codestream_next_addr
*= CODESTREAM_BUFSIZ
;
136 while (codestream_tell () != place
)
141 codestream_read (unsigned char *buf
, int count
)
146 for (i
= 0; i
< count
; i
++)
147 *p
++ = codestream_get ();
151 /* If the next instruction is a jump, move to its target. */
154 i386_follow_jump (void)
156 unsigned char buf
[4];
162 pos
= codestream_tell ();
165 if (codestream_peek () == 0x66)
171 switch (codestream_get ())
174 /* Relative jump: if data16 == 0, disp32, else disp16. */
177 codestream_read (buf
, 2);
178 delta
= extract_signed_integer (buf
, 2);
180 /* Include the size of the jmp instruction (including the
186 codestream_read (buf
, 4);
187 delta
= extract_signed_integer (buf
, 4);
193 /* Relative jump, disp8 (ignore data16). */
194 codestream_read (buf
, 1);
195 /* Sign-extend it. */
196 delta
= extract_signed_integer (buf
, 1);
201 codestream_seek (pos
);
204 /* Find & return the amount a local space allocated, and advance the
205 codestream to the first register push (if any).
207 If the entry sequence doesn't make sense, return -1, and leave
208 codestream pointer at a random spot. */
211 i386_get_frame_setup (CORE_ADDR pc
)
215 codestream_seek (pc
);
219 op
= codestream_get ();
221 if (op
== 0x58) /* popl %eax */
223 /* This function must start with
226 xchgl %eax, (%esp) 0x87 0x04 0x24
227 or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
229 (the System V compiler puts out the second `xchg'
230 instruction, and the assembler doesn't try to optimize it, so
231 the 'sib' form gets generated). This sequence is used to get
232 the address of the return buffer for a function that returns
235 unsigned char buf
[4];
236 static unsigned char proto1
[3] = { 0x87, 0x04, 0x24 };
237 static unsigned char proto2
[4] = { 0x87, 0x44, 0x24, 0x00 };
239 pos
= codestream_tell ();
240 codestream_read (buf
, 4);
241 if (memcmp (buf
, proto1
, 3) == 0)
243 else if (memcmp (buf
, proto2
, 4) == 0)
246 codestream_seek (pos
);
247 op
= codestream_get (); /* Update next opcode. */
250 if (op
== 0x68 || op
== 0x6a)
252 /* This function may start with
264 unsigned char buf
[8];
266 /* Skip past the `pushl' instruction; it has either a one-byte
267 or a four-byte operand, depending on the opcode. */
268 pos
= codestream_tell ();
273 codestream_seek (pos
);
275 /* Read the following 8 bytes, which should be "call _probe" (6
276 bytes) followed by "addl $4,%esp" (2 bytes). */
277 codestream_read (buf
, sizeof (buf
));
278 if (buf
[0] == 0xe8 && buf
[6] == 0xc4 && buf
[7] == 0x4)
280 codestream_seek (pos
);
281 op
= codestream_get (); /* Update next opcode. */
284 if (op
== 0x55) /* pushl %ebp */
286 /* Check for "movl %esp, %ebp" -- can be written in two ways. */
287 switch (codestream_get ())
290 if (codestream_get () != 0xec)
294 if (codestream_get () != 0xe5)
300 /* Check for stack adjustment
304 NOTE: You can't subtract a 16 bit immediate from a 32 bit
305 reg, so we don't have to worry about a data16 prefix. */
306 op
= codestream_peek ();
309 /* `subl' with 8 bit immediate. */
311 if (codestream_get () != 0xec)
312 /* Some instruction starting with 0x83 other than `subl'. */
314 codestream_seek (codestream_tell () - 2);
317 /* `subl' with signed byte immediate (though it wouldn't
318 make sense to be negative). */
319 return (codestream_get ());
324 /* Maybe it is `subl' with a 32 bit immedediate. */
326 if (codestream_get () != 0xec)
327 /* Some instruction starting with 0x81 other than `subl'. */
329 codestream_seek (codestream_tell () - 2);
332 /* It is `subl' with a 32 bit immediate. */
333 codestream_read ((unsigned char *) buf
, 4);
334 return extract_signed_integer (buf
, 4);
344 /* `enter' with 16 bit unsigned immediate. */
345 codestream_read ((unsigned char *) buf
, 2);
346 codestream_get (); /* Flush final byte of enter instruction. */
347 return extract_unsigned_integer (buf
, 2);
352 /* Return the chain-pointer for FRAME. In the case of the i386, the
353 frame's nominal address is the address of a 4-byte word containing
354 the calling frame's address. */
357 i386_frame_chain (struct frame_info
*frame
)
359 if (frame
->signal_handler_caller
)
362 if (! inside_entry_file (frame
->pc
))
363 return read_memory_unsigned_integer (frame
->frame
, 4);
368 /* Return number of args passed to a frame.
369 Can return -1, meaning no way to tell. */
372 i386_frame_num_args (struct frame_info
*fi
)
377 /* This loses because not only might the compiler not be popping the
378 args right after the function call, it might be popping args from
379 both this call and a previous one, and we would say there are
380 more args than there really are. */
384 struct frame_info
*pfi
;
386 /* On the i386, the instruction following the call could be:
388 addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
389 anything else - zero args. */
393 frameless
= FRAMELESS_FUNCTION_INVOCATION (fi
);
395 /* In the absence of a frame pointer, GDB doesn't get correct
396 values for nameless arguments. Return -1, so it doesn't print
397 any nameless arguments. */
400 pfi
= get_prev_frame (fi
);
403 /* NOTE: This can happen if we are looking at the frame for
404 main, because FRAME_CHAIN_VALID won't let us go into start.
405 If we have debugging symbols, that's not really a big deal;
406 it just means it will only show as many arguments to main as
413 op
= read_memory_integer (retpc
, 1);
414 if (op
== 0x59) /* pop %ecx */
418 op
= read_memory_integer (retpc
+ 1, 1);
420 /* addl $<signed imm 8 bits>, %esp */
421 return (read_memory_integer (retpc
+ 2, 1) & 0xff) / 4;
425 else if (op
== 0x81) /* `add' with 32 bit immediate. */
427 op
= read_memory_integer (retpc
+ 1, 1);
429 /* addl $<imm 32>, %esp */
430 return read_memory_integer (retpc
+ 2, 4) / 4;
442 /* Parse the first few instructions the function to see what registers
445 We handle these cases:
447 The startup sequence can be at the start of the function, or the
448 function can start with a branch to startup code at the end.
450 %ebp can be set up with either the 'enter' instruction, or "pushl
451 %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
452 once used in the System V compiler).
454 Local space is allocated just below the saved %ebp by either the
455 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a 16
456 bit unsigned argument for space to allocate, and the 'addl'
457 instruction could have either a signed byte, or 32 bit immediate.
459 Next, the registers used by this function are pushed. With the
460 System V compiler they will always be in the order: %edi, %esi,
461 %ebx (and sometimes a harmless bug causes it to also save but not
462 restore %eax); however, the code below is willing to see the pushes
463 in any order, and will handle up to 8 of them.
465 If the setup sequence is at the end of the function, then the next
466 instruction will be a branch back to the start. */
469 i386_frame_init_saved_regs (struct frame_info
*fip
)
473 CORE_ADDR dummy_bottom
;
481 frame_saved_regs_zalloc (fip
);
483 /* If the frame is the end of a dummy, compute where the beginning
485 dummy_bottom
= fip
->frame
- 4 - REGISTER_BYTES
- CALL_DUMMY_LENGTH
;
487 /* Check if the PC points in the stack, in a dummy frame. */
488 if (dummy_bottom
<= fip
->pc
&& fip
->pc
<= fip
->frame
)
490 /* All registers were saved by push_call_dummy. */
492 for (i
= 0; i
< NUM_REGS
; i
++)
494 addr
-= REGISTER_RAW_SIZE (i
);
495 fip
->saved_regs
[i
] = addr
;
500 pc
= get_pc_function_start (fip
->pc
);
502 locals
= i386_get_frame_setup (pc
);
506 addr
= fip
->frame
- 4 - locals
;
507 for (i
= 0; i
< 8; i
++)
509 op
= codestream_get ();
510 if (op
< 0x50 || op
> 0x57)
512 #ifdef I386_REGNO_TO_SYMMETRY
513 /* Dynix uses different internal numbering. Ick. */
514 fip
->saved_regs
[I386_REGNO_TO_SYMMETRY (op
- 0x50)] = addr
;
516 fip
->saved_regs
[op
- 0x50] = addr
;
522 fip
->saved_regs
[PC_REGNUM
] = fip
->frame
+ 4;
523 fip
->saved_regs
[FP_REGNUM
] = fip
->frame
;
526 /* Return PC of first real instruction. */
529 i386_skip_prologue (int pc
)
533 static unsigned char pic_pat
[6] =
534 { 0xe8, 0, 0, 0, 0, /* call 0x0 */
535 0x5b, /* popl %ebx */
539 if (i386_get_frame_setup (pc
) < 0)
542 /* Found valid frame setup -- codestream now points to start of push
543 instructions for saving registers. */
545 /* Skip over register saves. */
546 for (i
= 0; i
< 8; i
++)
548 op
= codestream_peek ();
549 /* Break if not `pushl' instrunction. */
550 if (op
< 0x50 || op
> 0x57)
555 /* The native cc on SVR4 in -K PIC mode inserts the following code
556 to get the address of the global offset table (GOT) into register
561 movl %ebx,x(%ebp) (optional)
564 This code is with the rest of the prologue (at the end of the
565 function), so we have to skip it to get to the first real
566 instruction at the start of the function. */
568 pos
= codestream_tell ();
569 for (i
= 0; i
< 6; i
++)
571 op
= codestream_get ();
572 if (pic_pat
[i
] != op
)
577 unsigned char buf
[4];
580 op
= codestream_get ();
581 if (op
== 0x89) /* movl %ebx, x(%ebp) */
583 op
= codestream_get ();
584 if (op
== 0x5d) /* One byte offset from %ebp. */
587 codestream_read (buf
, 1);
589 else if (op
== 0x9d) /* Four byte offset from %ebp. */
592 codestream_read (buf
, 4);
594 else /* Unexpected instruction. */
596 op
= codestream_get ();
599 if (delta
> 0 && op
== 0x81 && codestream_get () == 0xc3)
604 codestream_seek (pos
);
608 return (codestream_tell ());
612 i386_push_dummy_frame (void)
614 CORE_ADDR sp
= read_register (SP_REGNUM
);
616 char regbuf
[MAX_REGISTER_RAW_SIZE
];
618 sp
= push_word (sp
, read_register (PC_REGNUM
));
619 sp
= push_word (sp
, read_register (FP_REGNUM
));
620 write_register (FP_REGNUM
, sp
);
621 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
623 read_register_gen (regnum
, regbuf
);
624 sp
= push_bytes (sp
, regbuf
, REGISTER_RAW_SIZE (regnum
));
626 write_register (SP_REGNUM
, sp
);
629 /* Insert the (relative) function address into the call sequence
633 i386_fix_call_dummy (char *dummy
, CORE_ADDR pc
, CORE_ADDR fun
, int nargs
,
634 value_ptr
*args
, struct type
*type
, int gcc_p
)
636 int from
, to
, delta
, loc
;
638 loc
= (int)(read_register (SP_REGNUM
) - CALL_DUMMY_LENGTH
);
643 *((char *)(dummy
) + 1) = (delta
& 0xff);
644 *((char *)(dummy
) + 2) = ((delta
>> 8) & 0xff);
645 *((char *)(dummy
) + 3) = ((delta
>> 16) & 0xff);
646 *((char *)(dummy
) + 4) = ((delta
>> 24) & 0xff);
650 i386_pop_frame (void)
652 struct frame_info
*frame
= get_current_frame ();
655 char regbuf
[MAX_REGISTER_RAW_SIZE
];
657 fp
= FRAME_FP (frame
);
658 i386_frame_init_saved_regs (frame
);
660 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
663 addr
= frame
->saved_regs
[regnum
];
666 read_memory (addr
, regbuf
, REGISTER_RAW_SIZE (regnum
));
667 write_register_bytes (REGISTER_BYTE (regnum
), regbuf
,
668 REGISTER_RAW_SIZE (regnum
));
671 write_register (FP_REGNUM
, read_memory_integer (fp
, 4));
672 write_register (PC_REGNUM
, read_memory_integer (fp
+ 4, 4));
673 write_register (SP_REGNUM
, fp
+ 8);
674 flush_cached_frames ();
678 #ifdef GET_LONGJMP_TARGET
680 /* Figure out where the longjmp will land. Slurp the args out of the
681 stack. We expect the first arg to be a pointer to the jmp_buf
682 structure from which we extract the pc (JB_PC) that we will land
683 at. The pc is copied into PC. This routine returns true on
687 get_longjmp_target (CORE_ADDR
*pc
)
689 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
690 CORE_ADDR sp
, jb_addr
;
692 sp
= read_register (SP_REGNUM
);
694 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack. */
696 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
699 jb_addr
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
701 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
702 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
705 *pc
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
710 #endif /* GET_LONGJMP_TARGET */
714 i386_push_arguments (int nargs
, value_ptr
*args
, CORE_ADDR sp
,
715 int struct_return
, CORE_ADDR struct_addr
)
717 sp
= default_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
);
724 store_address (buf
, 4, struct_addr
);
725 write_memory (sp
, buf
, 4);
732 i386_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
734 /* Do nothing. Everything was already done by i386_push_arguments. */
737 /* These registers are used for returning integers (and on some
738 targets also for returning `struct' and `union' values when their
739 size and alignment match an integer type). */
740 #define LOW_RETURN_REGNUM 0 /* %eax */
741 #define HIGH_RETURN_REGNUM 2 /* %edx */
743 /* Extract from an array REGBUF containing the (raw) register state, a
744 function return value of TYPE, and copy that, in virtual format,
748 i386_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
750 int len
= TYPE_LENGTH (type
);
752 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
753 && TYPE_NFIELDS (type
) == 1)
755 i386_extract_return_value (TYPE_FIELD_TYPE (type
, 0), regbuf
, valbuf
);
759 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
763 warning ("Cannot find floating-point return value.");
764 memset (valbuf
, 0, len
);
768 /* Floating-point return values can be found in %st(0). */
769 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
770 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
772 /* Copy straight over, but take care of the padding. */
773 memcpy (valbuf
, ®buf
[REGISTER_BYTE (FP0_REGNUM
)],
775 memset (valbuf
+ FPU_REG_RAW_SIZE
, 0, len
- FPU_REG_RAW_SIZE
);
779 /* Convert the extended floating-point number found in
780 %st(0) to the desired type. This is probably not exactly
781 how it would happen on the target itself, but it is the
784 floatformat_to_doublest (&floatformat_i387_ext
,
785 ®buf
[REGISTER_BYTE (FP0_REGNUM
)], &val
);
786 store_floating (valbuf
, TYPE_LENGTH (type
), val
);
791 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
792 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
795 memcpy (valbuf
, ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], len
);
796 else if (len
<= (low_size
+ high_size
))
799 ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], low_size
);
800 memcpy (valbuf
+ low_size
,
801 ®buf
[REGISTER_BYTE (HIGH_RETURN_REGNUM
)], len
- low_size
);
804 internal_error (__FILE__
, __LINE__
,
805 "Cannot extract return value of %d bytes long.", len
);
809 /* Write into the appropriate registers a function return value stored
810 in VALBUF of type TYPE, given in virtual format. */
813 i386_store_return_value (struct type
*type
, char *valbuf
)
815 int len
= TYPE_LENGTH (type
);
817 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
818 && TYPE_NFIELDS (type
) == 1)
820 i386_store_return_value (TYPE_FIELD_TYPE (type
, 0), valbuf
);
824 if (TYPE_CODE (type
) == TYPE_CODE_FLT
)
828 warning ("Cannot set floating-point return value.");
832 /* Floating-point return values can be found in %st(0). */
833 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
834 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
836 /* Copy straight over. */
837 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), valbuf
,
842 char buf
[FPU_REG_RAW_SIZE
];
845 /* Convert the value found in VALBUF to the extended
846 floating point format used by the FPU. This is probably
847 not exactly how it would happen on the target itself, but
848 it is the best we can do. */
849 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
850 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
851 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
857 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
858 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
861 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
), valbuf
, len
);
862 else if (len
<= (low_size
+ high_size
))
864 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
),
866 write_register_bytes (REGISTER_BYTE (HIGH_RETURN_REGNUM
),
867 valbuf
+ low_size
, len
- low_size
);
870 internal_error (__FILE__
, __LINE__
,
871 "Cannot store return value of %d bytes long.", len
);
875 /* Extract from an array REGBUF containing the (raw) register state
876 the address in which a function should return its structure value,
880 i386_extract_struct_value_address (char *regbuf
)
882 return extract_address (®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)],
883 REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
));
887 /* Convert data from raw format for register REGNUM in buffer FROM to
888 virtual format with type TYPE in buffer TO. In principle both
889 formats are identical except that the virtual format has two extra
890 bytes appended that aren't used. We set these to zero. */
893 i386_register_convert_to_virtual (int regnum
, struct type
*type
,
894 char *from
, char *to
)
896 /* Copy straight over, but take care of the padding. */
897 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
898 memset (to
+ FPU_REG_RAW_SIZE
, 0, TYPE_LENGTH (type
) - FPU_REG_RAW_SIZE
);
901 /* Convert data from virtual format with type TYPE in buffer FROM to
902 raw format for register REGNUM in buffer TO. Simply omit the two
906 i386_register_convert_to_raw (struct type
*type
, int regnum
,
907 char *from
, char *to
)
909 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
913 #ifdef I386V4_SIGTRAMP_SAVED_PC
914 /* Get saved user PC for sigtramp from the pushed ucontext on the
915 stack for all three variants of SVR4 sigtramps. */
918 i386v4_sigtramp_saved_pc (struct frame_info
*frame
)
920 CORE_ADDR saved_pc_offset
= 4;
923 find_pc_partial_function (frame
->pc
, &name
, NULL
, NULL
);
926 if (STREQ (name
, "_sigreturn"))
927 saved_pc_offset
= 132 + 14 * 4;
928 else if (STREQ (name
, "_sigacthandler"))
929 saved_pc_offset
= 80 + 14 * 4;
930 else if (STREQ (name
, "sigvechandler"))
931 saved_pc_offset
= 120 + 14 * 4;
935 return read_memory_integer (frame
->next
->frame
+ saved_pc_offset
, 4);
936 return read_memory_integer (read_register (SP_REGNUM
) + saved_pc_offset
, 4);
938 #endif /* I386V4_SIGTRAMP_SAVED_PC */
941 #ifdef STATIC_TRANSFORM_NAME
942 /* SunPRO encodes the static variables. This is not related to C++
943 mangling, it is done for C too. */
946 sunpro_static_transform_name (char *name
)
949 if (IS_STATIC_TRANSFORM_NAME (name
))
951 /* For file-local statics there will be a period, a bunch of
952 junk (the contents of which match a string given in the
953 N_OPT), a period and the name. For function-local statics
954 there will be a bunch of junk (which seems to change the
955 second character from 'A' to 'B'), a period, the name of the
956 function, and the name. So just skip everything before the
958 p
= strrchr (name
, '.');
964 #endif /* STATIC_TRANSFORM_NAME */
967 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
970 skip_trampoline_code (CORE_ADDR pc
, char *name
)
972 if (pc
&& read_memory_unsigned_integer (pc
, 2) == 0x25ff) /* jmp *(dest) */
974 unsigned long indirect
= read_memory_unsigned_integer (pc
+ 2, 4);
975 struct minimal_symbol
*indsym
=
976 indirect
? lookup_minimal_symbol_by_pc (indirect
) : 0;
977 char *symname
= indsym
? SYMBOL_NAME (indsym
) : 0;
981 if (strncmp (symname
, "__imp_", 6) == 0
982 || strncmp (symname
, "_imp_", 5) == 0)
983 return name
? 1 : read_memory_unsigned_integer (indirect
, 4);
986 return 0; /* Not a trampoline. */
990 /* We have two flavours of disassembly. The machinery on this page
991 deals with switching between those. */
994 gdb_print_insn_i386 (bfd_vma memaddr
, disassemble_info
*info
)
996 if (disassembly_flavor
== att_flavor
)
997 return print_insn_i386_att (memaddr
, info
);
998 else if (disassembly_flavor
== intel_flavor
)
999 return print_insn_i386_intel (memaddr
, info
);
1000 /* Never reached -- disassembly_flavour is always either att_flavor
1002 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1005 /* If the disassembly mode is intel, we have to also switch the bfd
1006 mach_type. This function is run in the set disassembly_flavor
1007 command, and does that. */
1010 set_disassembly_flavor_sfunc (char *args
, int from_tty
,
1011 struct cmd_list_element
*c
)
1013 set_disassembly_flavor ();
1017 set_disassembly_flavor (void)
1019 if (disassembly_flavor
== att_flavor
)
1020 set_architecture_from_arch_mach (bfd_arch_i386
, bfd_mach_i386_i386
);
1021 else if (disassembly_flavor
== intel_flavor
)
1022 set_architecture_from_arch_mach (bfd_arch_i386
,
1023 bfd_mach_i386_i386_intel_syntax
);
1027 /* Provide a prototype to silence -Wmissing-prototypes. */
1028 void _initialize_i386_tdep (void);
1031 _initialize_i386_tdep (void)
1033 /* Initialize the table saying where each register starts in the
1039 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
1041 i386_register_byte
[i
] = offset
;
1042 offset
+= i386_register_raw_size
[i
];
1046 /* Initialize the table of virtual register sizes. */
1050 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
1051 i386_register_virtual_size
[i
] = TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (i
));
1054 tm_print_insn
= gdb_print_insn_i386
;
1055 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 0)->mach
;
1057 /* Add the variable that controls the disassembly flavor. */
1059 struct cmd_list_element
*new_cmd
;
1061 new_cmd
= add_set_enum_cmd ("disassembly-flavor", no_class
,
1063 &disassembly_flavor
,
1065 Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
1066 and the default value is \"att\".",
1068 new_cmd
->function
.sfunc
= set_disassembly_flavor_sfunc
;
1069 add_show_from_set (new_cmd
, &showlist
);
1072 /* Finally, initialize the disassembly flavor to the default given
1073 in the disassembly_flavor variable. */
1074 set_disassembly_flavor ();