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 static long i386_get_frame_setup (CORE_ADDR
);
38 static void i386_follow_jump (void);
40 static void codestream_read (unsigned char *, int);
42 static void codestream_seek (CORE_ADDR
);
44 static unsigned char codestream_fill (int);
46 CORE_ADDR
skip_trampoline_code (CORE_ADDR
, char *);
48 static int gdb_print_insn_i386 (bfd_vma
, disassemble_info
*);
50 void _initialize_i386_tdep (void);
52 /* i386_register_byte[i] is the offset into the register file of the
53 start of register number i. We initialize this from
54 i386_register_raw_size. */
55 int i386_register_byte
[MAX_NUM_REGS
];
57 /* i386_register_raw_size[i] is the number of bytes of storage in
58 GDB's register array occupied by register i. */
59 int i386_register_raw_size
[MAX_NUM_REGS
] = {
73 /* i386_register_virtual_size[i] is the size in bytes of the virtual
74 type of register i. */
75 int i386_register_virtual_size
[MAX_NUM_REGS
];
78 /* This is the variable the is set with "set disassembly-flavor",
79 and its legitimate values. */
80 static const char att_flavor
[] = "att";
81 static const char intel_flavor
[] = "intel";
82 static const char *valid_flavors
[] =
88 static const char *disassembly_flavor
= att_flavor
;
90 static void i386_print_register (char *, int, int);
92 /* This is used to keep the bfd arch_info in sync with the disassembly flavor. */
93 static void set_disassembly_flavor_sfunc (char *, int,
94 struct cmd_list_element
*);
95 static void set_disassembly_flavor (void);
97 /* Stdio style buffering was used to minimize calls to ptrace, but this
98 buffering did not take into account that the code section being accessed
99 may not be an even number of buffers long (even if the buffer is only
100 sizeof(int) long). In cases where the code section size happened to
101 be a non-integral number of buffers long, attempting to read the last
102 buffer would fail. Simply using target_read_memory and ignoring errors,
103 rather than read_memory, is not the correct solution, since legitimate
104 access errors would then be totally ignored. To properly handle this
105 situation and continue to use buffering would require that this code
106 be able to determine the minimum code section size granularity (not the
107 alignment of the section itself, since the actual failing case that
108 pointed out this problem had a section alignment of 4 but was not a
109 multiple of 4 bytes long), on a target by target basis, and then
110 adjust it's buffer size accordingly. This is messy, but potentially
111 feasible. It probably needs the bfd library's help and support. For
112 now, the buffer size is set to 1. (FIXME -fnf) */
114 #define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
115 static CORE_ADDR codestream_next_addr
;
116 static CORE_ADDR codestream_addr
;
117 static unsigned char codestream_buf
[CODESTREAM_BUFSIZ
];
118 static int codestream_off
;
119 static int codestream_cnt
;
121 #define codestream_tell() (codestream_addr + codestream_off)
122 #define codestream_peek() (codestream_cnt == 0 ? \
123 codestream_fill(1): codestream_buf[codestream_off])
124 #define codestream_get() (codestream_cnt-- == 0 ? \
125 codestream_fill(0) : codestream_buf[codestream_off++])
128 codestream_fill (int peek_flag
)
130 codestream_addr
= codestream_next_addr
;
131 codestream_next_addr
+= CODESTREAM_BUFSIZ
;
133 codestream_cnt
= CODESTREAM_BUFSIZ
;
134 read_memory (codestream_addr
, (char *) codestream_buf
, CODESTREAM_BUFSIZ
);
137 return (codestream_peek ());
139 return (codestream_get ());
143 codestream_seek (CORE_ADDR place
)
145 codestream_next_addr
= place
/ CODESTREAM_BUFSIZ
;
146 codestream_next_addr
*= CODESTREAM_BUFSIZ
;
149 while (codestream_tell () != place
)
154 codestream_read (unsigned char *buf
, int count
)
159 for (i
= 0; i
< count
; i
++)
160 *p
++ = codestream_get ();
163 /* next instruction is a jump, move to target */
166 i386_follow_jump (void)
168 unsigned char buf
[4];
174 pos
= codestream_tell ();
177 if (codestream_peek () == 0x66)
183 switch (codestream_get ())
186 /* relative jump: if data16 == 0, disp32, else disp16 */
189 codestream_read (buf
, 2);
190 delta
= extract_signed_integer (buf
, 2);
192 /* include size of jmp inst (including the 0x66 prefix). */
197 codestream_read (buf
, 4);
198 delta
= extract_signed_integer (buf
, 4);
204 /* relative jump, disp8 (ignore data16) */
205 codestream_read (buf
, 1);
206 /* Sign-extend it. */
207 delta
= extract_signed_integer (buf
, 1);
212 codestream_seek (pos
);
216 * find & return amound a local space allocated, and advance codestream to
217 * first register push (if any)
219 * if entry sequence doesn't make sense, return -1, and leave
220 * codestream pointer random
224 i386_get_frame_setup (CORE_ADDR pc
)
228 codestream_seek (pc
);
232 op
= codestream_get ();
234 if (op
== 0x58) /* popl %eax */
237 * this function must start with
240 * xchgl %eax, (%esp) 0x87 0x04 0x24
241 * or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
243 * (the system 5 compiler puts out the second xchg
244 * inst, and the assembler doesn't try to optimize it,
245 * so the 'sib' form gets generated)
247 * this sequence is used to get the address of the return
248 * buffer for a function that returns a structure
251 unsigned char buf
[4];
252 static unsigned char proto1
[3] =
254 static unsigned char proto2
[4] =
255 {0x87, 0x44, 0x24, 0x00};
256 pos
= codestream_tell ();
257 codestream_read (buf
, 4);
258 if (memcmp (buf
, proto1
, 3) == 0)
260 else if (memcmp (buf
, proto2
, 4) == 0)
263 codestream_seek (pos
);
264 op
= codestream_get (); /* update next opcode */
267 if (op
== 0x68 || op
== 0x6a)
270 * this function may start with
280 unsigned char buf
[8];
282 /* Skip past the pushl instruction; it has either a one-byte
283 or a four-byte operand, depending on the opcode. */
284 pos
= codestream_tell ();
289 codestream_seek (pos
);
291 /* Read the following 8 bytes, which should be "call _probe" (6 bytes)
292 followed by "addl $4,%esp" (2 bytes). */
293 codestream_read (buf
, sizeof (buf
));
294 if (buf
[0] == 0xe8 && buf
[6] == 0xc4 && buf
[7] == 0x4)
296 codestream_seek (pos
);
297 op
= codestream_get (); /* update next opcode */
300 if (op
== 0x55) /* pushl %ebp */
302 /* check for movl %esp, %ebp - can be written two ways */
303 switch (codestream_get ())
306 if (codestream_get () != 0xec)
310 if (codestream_get () != 0xe5)
316 /* check for stack adjustment
320 * note: you can't subtract a 16 bit immediate
321 * from a 32 bit reg, so we don't have to worry
322 * about a data16 prefix
324 op
= codestream_peek ();
327 /* subl with 8 bit immed */
329 if (codestream_get () != 0xec)
330 /* Some instruction starting with 0x83 other than subl. */
332 codestream_seek (codestream_tell () - 2);
335 /* subl with signed byte immediate
336 * (though it wouldn't make sense to be negative)
338 return (codestream_get ());
343 /* Maybe it is subl with 32 bit immedediate. */
345 if (codestream_get () != 0xec)
346 /* Some instruction starting with 0x81 other than subl. */
348 codestream_seek (codestream_tell () - 2);
351 /* It is subl with 32 bit immediate. */
352 codestream_read ((unsigned char *) buf
, 4);
353 return extract_signed_integer (buf
, 4);
363 /* enter instruction: arg is 16 bit unsigned immed */
364 codestream_read ((unsigned char *) buf
, 2);
365 codestream_get (); /* flush final byte of enter instruction */
366 return extract_unsigned_integer (buf
, 2);
371 /* Return number of args passed to a frame.
372 Can return -1, meaning no way to tell. */
375 i386_frame_num_args (struct frame_info
*fi
)
380 /* This loses because not only might the compiler not be popping the
381 args right after the function call, it might be popping args from both
382 this call and a previous one, and we would say there are more args
383 than there really are. */
387 struct frame_info
*pfi
;
389 /* on the 386, the instruction following the call could be:
391 addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
392 anything else - zero args */
396 frameless
= FRAMELESS_FUNCTION_INVOCATION (fi
);
398 /* In the absence of a frame pointer, GDB doesn't get correct values
399 for nameless arguments. Return -1, so it doesn't print any
400 nameless arguments. */
403 pfi
= get_prev_frame (fi
);
406 /* Note: this can happen if we are looking at the frame for
407 main, because FRAME_CHAIN_VALID won't let us go into
408 start. If we have debugging symbols, that's not really
409 a big deal; it just means it will only show as many arguments
410 to main as are declared. */
416 op
= read_memory_integer (retpc
, 1);
422 op
= read_memory_integer (retpc
+ 1, 1);
424 /* addl $<signed imm 8 bits>, %esp */
425 return (read_memory_integer (retpc
+ 2, 1) & 0xff) / 4;
430 { /* add with 32 bit immediate */
431 op
= read_memory_integer (retpc
+ 1, 1);
433 /* addl $<imm 32>, %esp */
434 return read_memory_integer (retpc
+ 2, 4) / 4;
447 * parse the first few instructions of the function to see
448 * what registers were stored.
450 * We handle these cases:
452 * The startup sequence can be at the start of the function,
453 * or the function can start with a branch to startup code at the end.
455 * %ebp can be set up with either the 'enter' instruction, or
456 * 'pushl %ebp, movl %esp, %ebp' (enter is too slow to be useful,
457 * but was once used in the sys5 compiler)
459 * Local space is allocated just below the saved %ebp by either the
460 * 'enter' instruction, or by 'subl $<size>, %esp'. 'enter' has
461 * a 16 bit unsigned argument for space to allocate, and the
462 * 'addl' instruction could have either a signed byte, or
465 * Next, the registers used by this function are pushed. In
466 * the sys5 compiler they will always be in the order: %edi, %esi, %ebx
467 * (and sometimes a harmless bug causes it to also save but not restore %eax);
468 * however, the code below is willing to see the pushes in any order,
469 * and will handle up to 8 of them.
471 * If the setup sequence is at the end of the function, then the
472 * next instruction will be a branch back to the start.
476 i386_frame_init_saved_regs (struct frame_info
*fip
)
480 CORE_ADDR dummy_bottom
;
488 frame_saved_regs_zalloc (fip
);
490 /* if frame is the end of a dummy, compute where the
493 dummy_bottom
= fip
->frame
- 4 - REGISTER_BYTES
- CALL_DUMMY_LENGTH
;
495 /* check if the PC is in the stack, in a dummy frame */
496 if (dummy_bottom
<= fip
->pc
&& fip
->pc
<= fip
->frame
)
498 /* all regs were saved by push_call_dummy () */
500 for (i
= 0; i
< NUM_REGS
; i
++)
502 adr
-= REGISTER_RAW_SIZE (i
);
503 fip
->saved_regs
[i
] = adr
;
508 pc
= get_pc_function_start (fip
->pc
);
510 locals
= i386_get_frame_setup (pc
);
514 adr
= fip
->frame
- 4 - locals
;
515 for (i
= 0; i
< 8; i
++)
517 op
= codestream_get ();
518 if (op
< 0x50 || op
> 0x57)
520 #ifdef I386_REGNO_TO_SYMMETRY
521 /* Dynix uses different internal numbering. Ick. */
522 fip
->saved_regs
[I386_REGNO_TO_SYMMETRY (op
- 0x50)] = adr
;
524 fip
->saved_regs
[op
- 0x50] = adr
;
530 fip
->saved_regs
[PC_REGNUM
] = fip
->frame
+ 4;
531 fip
->saved_regs
[FP_REGNUM
] = fip
->frame
;
534 /* return pc of first real instruction */
537 i386_skip_prologue (int pc
)
541 static unsigned char pic_pat
[6] =
542 {0xe8, 0, 0, 0, 0, /* call 0x0 */
543 0x5b, /* popl %ebx */
547 if (i386_get_frame_setup (pc
) < 0)
550 /* found valid frame setup - codestream now points to
551 * start of push instructions for saving registers
554 /* skip over register saves */
555 for (i
= 0; i
< 8; i
++)
557 op
= codestream_peek ();
558 /* break if not pushl inst */
559 if (op
< 0x50 || op
> 0x57)
564 /* The native cc on SVR4 in -K PIC mode inserts the following code to get
565 the address of the global offset table (GOT) into register %ebx.
568 movl %ebx,x(%ebp) (optional)
570 This code is with the rest of the prologue (at the end of the
571 function), so we have to skip it to get to the first real
572 instruction at the start of the function. */
574 pos
= codestream_tell ();
575 for (i
= 0; i
< 6; i
++)
577 op
= codestream_get ();
578 if (pic_pat
[i
] != op
)
583 unsigned char buf
[4];
586 op
= codestream_get ();
587 if (op
== 0x89) /* movl %ebx, x(%ebp) */
589 op
= codestream_get ();
590 if (op
== 0x5d) /* one byte offset from %ebp */
593 codestream_read (buf
, 1);
595 else if (op
== 0x9d) /* four byte offset from %ebp */
598 codestream_read (buf
, 4);
600 else /* unexpected instruction */
602 op
= codestream_get ();
605 if (delta
> 0 && op
== 0x81 && codestream_get () == 0xc3)
610 codestream_seek (pos
);
614 return (codestream_tell ());
618 i386_push_dummy_frame (void)
620 CORE_ADDR sp
= read_register (SP_REGNUM
);
622 char regbuf
[MAX_REGISTER_RAW_SIZE
];
624 sp
= push_word (sp
, read_register (PC_REGNUM
));
625 sp
= push_word (sp
, read_register (FP_REGNUM
));
626 write_register (FP_REGNUM
, sp
);
627 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
629 read_register_gen (regnum
, regbuf
);
630 sp
= push_bytes (sp
, regbuf
, REGISTER_RAW_SIZE (regnum
));
632 write_register (SP_REGNUM
, sp
);
635 /* Insert the (relative) function address into the call sequence
639 i386_fix_call_dummy (char *dummy
, CORE_ADDR pc
, CORE_ADDR fun
, int nargs
,
640 value_ptr
*args
, struct type
*type
, int gcc_p
)
642 int from
, to
, delta
, loc
;
644 loc
= (int)(read_register (SP_REGNUM
) - CALL_DUMMY_LENGTH
);
649 *((char *)(dummy
) + 1) = (delta
& 0xff);
650 *((char *)(dummy
) + 2) = ((delta
>> 8) & 0xff);
651 *((char *)(dummy
) + 3) = ((delta
>> 16) & 0xff);
652 *((char *)(dummy
) + 4) = ((delta
>> 24) & 0xff);
656 i386_pop_frame (void)
658 struct frame_info
*frame
= get_current_frame ();
661 char regbuf
[MAX_REGISTER_RAW_SIZE
];
663 fp
= FRAME_FP (frame
);
664 i386_frame_init_saved_regs (frame
);
666 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
669 adr
= frame
->saved_regs
[regnum
];
672 read_memory (adr
, regbuf
, REGISTER_RAW_SIZE (regnum
));
673 write_register_bytes (REGISTER_BYTE (regnum
), regbuf
,
674 REGISTER_RAW_SIZE (regnum
));
677 write_register (FP_REGNUM
, read_memory_integer (fp
, 4));
678 write_register (PC_REGNUM
, read_memory_integer (fp
+ 4, 4));
679 write_register (SP_REGNUM
, fp
+ 8);
680 flush_cached_frames ();
683 #ifdef GET_LONGJMP_TARGET
685 /* Figure out where the longjmp will land. Slurp the args out of the stack.
686 We expect the first arg to be a pointer to the jmp_buf structure from which
687 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
688 This routine returns true on success. */
691 get_longjmp_target (CORE_ADDR
*pc
)
693 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
694 CORE_ADDR sp
, jb_addr
;
696 sp
= read_register (SP_REGNUM
);
698 if (target_read_memory (sp
+ SP_ARG0
, /* Offset of first arg on stack */
700 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
703 jb_addr
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
705 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
706 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
709 *pc
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
714 #endif /* GET_LONGJMP_TARGET */
716 /* These registers are used for returning integers (and on some
717 targets also for returning `struct' and `union' values when their
718 size and alignment match an integer type). */
719 #define LOW_RETURN_REGNUM 0 /* %eax */
720 #define HIGH_RETURN_REGNUM 2 /* %edx */
722 /* Extract from an array REGBUF containing the (raw) register state, a
723 function return value of TYPE, and copy that, in virtual format,
727 i386_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
729 int len
= TYPE_LENGTH (type
);
731 if (TYPE_CODE_FLT
== TYPE_CODE (type
))
735 warning ("Cannot find floating-point return value.");
736 memset (valbuf
, 0, len
);
740 /* Floating-point return values can be found in %st(0). */
741 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
742 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
744 /* Copy straight over, but take care of the padding. */
745 memcpy (valbuf
, ®buf
[REGISTER_BYTE (FP0_REGNUM
)],
747 memset (valbuf
+ FPU_REG_RAW_SIZE
, 0, len
- FPU_REG_RAW_SIZE
);
751 /* Convert the extended floating-point number found in
752 %st(0) to the desired type. This is probably not exactly
753 how it would happen on the target itself, but it is the
756 floatformat_to_doublest (&floatformat_i387_ext
,
757 ®buf
[REGISTER_BYTE (FP0_REGNUM
)], &val
);
758 store_floating (valbuf
, TYPE_LENGTH (type
), val
);
763 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
764 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
767 memcpy (valbuf
, ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], len
);
768 else if (len
<= (low_size
+ high_size
))
771 ®buf
[REGISTER_BYTE (LOW_RETURN_REGNUM
)], low_size
);
772 memcpy (valbuf
+ low_size
,
773 ®buf
[REGISTER_BYTE (HIGH_RETURN_REGNUM
)], len
- low_size
);
776 internal_error (__FILE__
, __LINE__
,
777 "Cannot extract return value of %d bytes long.", len
);
781 /* Write into the appropriate registers a function return value stored
782 in VALBUF of type TYPE, given in virtual format. */
785 i386_store_return_value (struct type
*type
, char *valbuf
)
787 int len
= TYPE_LENGTH (type
);
789 if (TYPE_CODE_FLT
== TYPE_CODE (type
))
793 warning ("Cannot set floating-point return value.");
797 /* Floating-point return values can be found in %st(0). */
798 if (len
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
799 && TARGET_LONG_DOUBLE_FORMAT
== &floatformat_i387_ext
)
801 /* Copy straight over. */
802 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), valbuf
,
807 char buf
[FPU_REG_RAW_SIZE
];
810 /* Convert the value found in VALBUF to the extended
811 floating point format used by the FPU. This is probably
812 not exactly how it would happen on the target itself, but
813 it is the best we can do. */
814 val
= extract_floating (valbuf
, TYPE_LENGTH (type
));
815 floatformat_from_doublest (&floatformat_i387_ext
, &val
, buf
);
816 write_register_bytes (REGISTER_BYTE (FP0_REGNUM
), buf
,
822 int low_size
= REGISTER_RAW_SIZE (LOW_RETURN_REGNUM
);
823 int high_size
= REGISTER_RAW_SIZE (HIGH_RETURN_REGNUM
);
826 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
), valbuf
, len
);
827 else if (len
<= (low_size
+ high_size
))
829 write_register_bytes (REGISTER_BYTE (LOW_RETURN_REGNUM
),
831 write_register_bytes (REGISTER_BYTE (HIGH_RETURN_REGNUM
),
832 valbuf
+ low_size
, len
- low_size
);
835 internal_error (__FILE__
, __LINE__
,
836 "Cannot store return value of %d bytes long.", len
);
840 /* Convert data from raw format for register REGNUM in buffer FROM to
841 virtual format with type TYPE in buffer TO. In principle both
842 formats are identical except that the virtual format has two extra
843 bytes appended that aren't used. We set these to zero. */
846 i386_register_convert_to_virtual (int regnum
, struct type
*type
,
847 char *from
, char *to
)
849 /* Copy straight over, but take care of the padding. */
850 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
851 memset (to
+ FPU_REG_RAW_SIZE
, 0, TYPE_LENGTH (type
) - FPU_REG_RAW_SIZE
);
854 /* Convert data from virtual format with type TYPE in buffer FROM to
855 raw format for register REGNUM in buffer TO. Simply omit the two
859 i386_register_convert_to_raw (struct type
*type
, int regnum
,
860 char *from
, char *to
)
862 memcpy (to
, from
, FPU_REG_RAW_SIZE
);
866 #ifdef I386V4_SIGTRAMP_SAVED_PC
867 /* Get saved user PC for sigtramp from the pushed ucontext on the stack
868 for all three variants of SVR4 sigtramps. */
871 i386v4_sigtramp_saved_pc (struct frame_info
*frame
)
873 CORE_ADDR saved_pc_offset
= 4;
876 find_pc_partial_function (frame
->pc
, &name
, NULL
, NULL
);
879 if (STREQ (name
, "_sigreturn"))
880 saved_pc_offset
= 132 + 14 * 4;
881 else if (STREQ (name
, "_sigacthandler"))
882 saved_pc_offset
= 80 + 14 * 4;
883 else if (STREQ (name
, "sigvechandler"))
884 saved_pc_offset
= 120 + 14 * 4;
888 return read_memory_integer (frame
->next
->frame
+ saved_pc_offset
, 4);
889 return read_memory_integer (read_register (SP_REGNUM
) + saved_pc_offset
, 4);
891 #endif /* I386V4_SIGTRAMP_SAVED_PC */
894 #ifdef STATIC_TRANSFORM_NAME
895 /* SunPRO encodes the static variables. This is not related to C++ mangling,
896 it is done for C too. */
899 sunpro_static_transform_name (char *name
)
902 if (IS_STATIC_TRANSFORM_NAME (name
))
904 /* For file-local statics there will be a period, a bunch
905 of junk (the contents of which match a string given in the
906 N_OPT), a period and the name. For function-local statics
907 there will be a bunch of junk (which seems to change the
908 second character from 'A' to 'B'), a period, the name of the
909 function, and the name. So just skip everything before the
911 p
= strrchr (name
, '.');
917 #endif /* STATIC_TRANSFORM_NAME */
921 /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
924 skip_trampoline_code (CORE_ADDR pc
, char *name
)
926 if (pc
&& read_memory_unsigned_integer (pc
, 2) == 0x25ff) /* jmp *(dest) */
928 unsigned long indirect
= read_memory_unsigned_integer (pc
+ 2, 4);
929 struct minimal_symbol
*indsym
=
930 indirect
? lookup_minimal_symbol_by_pc (indirect
) : 0;
931 char *symname
= indsym
? SYMBOL_NAME (indsym
) : 0;
935 if (strncmp (symname
, "__imp_", 6) == 0
936 || strncmp (symname
, "_imp_", 5) == 0)
937 return name
? 1 : read_memory_unsigned_integer (indirect
, 4);
940 return 0; /* not a trampoline */
944 gdb_print_insn_i386 (bfd_vma memaddr
, disassemble_info
*info
)
946 if (disassembly_flavor
== att_flavor
)
947 return print_insn_i386_att (memaddr
, info
);
948 else if (disassembly_flavor
== intel_flavor
)
949 return print_insn_i386_intel (memaddr
, info
);
950 /* Never reached - disassembly_flavour is always either att_flavor
952 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
955 /* If the disassembly mode is intel, we have to also switch the
956 bfd mach_type. This function is run in the set disassembly_flavor
957 command, and does that. */
960 set_disassembly_flavor_sfunc (char *args
, int from_tty
,
961 struct cmd_list_element
*c
)
963 set_disassembly_flavor ();
967 set_disassembly_flavor (void)
969 if (disassembly_flavor
== att_flavor
)
970 set_architecture_from_arch_mach (bfd_arch_i386
, bfd_mach_i386_i386
);
971 else if (disassembly_flavor
== intel_flavor
)
972 set_architecture_from_arch_mach (bfd_arch_i386
, bfd_mach_i386_i386_intel_syntax
);
977 _initialize_i386_tdep (void)
979 /* Initialize the table saying where each register starts in the
985 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
987 i386_register_byte
[i
] = offset
;
988 offset
+= i386_register_raw_size
[i
];
992 /* Initialize the table of virtual register sizes. */
996 for (i
= 0; i
< MAX_NUM_REGS
; i
++)
997 i386_register_virtual_size
[i
] = TYPE_LENGTH (REGISTER_VIRTUAL_TYPE (i
));
1000 tm_print_insn
= gdb_print_insn_i386
;
1001 tm_print_insn_info
.mach
= bfd_lookup_arch (bfd_arch_i386
, 0)->mach
;
1003 /* Add the variable that controls the disassembly flavor */
1005 struct cmd_list_element
*new_cmd
;
1007 new_cmd
= add_set_enum_cmd ("disassembly-flavor", no_class
,
1009 &disassembly_flavor
,
1010 "Set the disassembly flavor, the valid values are \"att\" and \"intel\", \
1011 and the default value is \"att\".",
1013 new_cmd
->function
.sfunc
= set_disassembly_flavor_sfunc
;
1014 add_show_from_set (new_cmd
, &showlist
);
1017 /* Finally, initialize the disassembly flavor to the default given
1018 in the disassembly_flavor variable */
1020 set_disassembly_flavor ();