Fix seg fault when displaying linker error message
[deliverable/binutils-gdb.git] / gdb / i386-tdep.c
CommitLineData
f2ebc25f 1/* Intel 386 target-dependent stuff.
f33b2c13 2 Copyright (C) 1988, 1989, 1991, 1994, 1995, 1996 Free Software Foundation, Inc.
bd5635a1
RP
3
4This file is part of GDB.
5
7d9884b9 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
7d9884b9
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
7d9884b9 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
7d9884b9 17along with this program; if not, write to the Free Software
f33b2c13 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
bd5635a1 19
bd5635a1 20#include "defs.h"
f33b2c13 21#include "gdb_string.h"
bd5635a1
RP
22#include "frame.h"
23#include "inferior.h"
24#include "gdbcore.h"
51b57ded 25#include "target.h"
eae3f093 26#include "floatformat.h"
28ee4b42 27#include "symtab.h"
f33b2c13 28#include "gdbcmd.h"
bd5635a1 29
f33b2c13 30static long i386_get_frame_setup PARAMS ((CORE_ADDR));
d747e0af 31
1a494973 32static void i386_follow_jump PARAMS ((void));
d747e0af 33
1a494973 34static void codestream_read PARAMS ((unsigned char *, int));
d747e0af 35
f33b2c13 36static void codestream_seek PARAMS ((CORE_ADDR));
d747e0af 37
f33b2c13 38static unsigned char codestream_fill PARAMS ((int));
bd5635a1 39
d747e0af
MT
40/* Stdio style buffering was used to minimize calls to ptrace, but this
41 buffering did not take into account that the code section being accessed
42 may not be an even number of buffers long (even if the buffer is only
43 sizeof(int) long). In cases where the code section size happened to
44 be a non-integral number of buffers long, attempting to read the last
45 buffer would fail. Simply using target_read_memory and ignoring errors,
46 rather than read_memory, is not the correct solution, since legitimate
47 access errors would then be totally ignored. To properly handle this
48 situation and continue to use buffering would require that this code
49 be able to determine the minimum code section size granularity (not the
50 alignment of the section itself, since the actual failing case that
51 pointed out this problem had a section alignment of 4 but was not a
52 multiple of 4 bytes long), on a target by target basis, and then
53 adjust it's buffer size accordingly. This is messy, but potentially
54 feasible. It probably needs the bfd library's help and support. For
55 now, the buffer size is set to 1. (FIXME -fnf) */
56
57#define CODESTREAM_BUFSIZ 1 /* Was sizeof(int), see note above. */
bd5635a1
RP
58static CORE_ADDR codestream_next_addr;
59static CORE_ADDR codestream_addr;
d747e0af 60static unsigned char codestream_buf[CODESTREAM_BUFSIZ];
bd5635a1
RP
61static int codestream_off;
62static int codestream_cnt;
63
64#define codestream_tell() (codestream_addr + codestream_off)
65#define codestream_peek() (codestream_cnt == 0 ? \
66 codestream_fill(1): codestream_buf[codestream_off])
67#define codestream_get() (codestream_cnt-- == 0 ? \
68 codestream_fill(0) : codestream_buf[codestream_off++])
69
70static unsigned char
71codestream_fill (peek_flag)
d747e0af 72 int peek_flag;
bd5635a1
RP
73{
74 codestream_addr = codestream_next_addr;
d747e0af 75 codestream_next_addr += CODESTREAM_BUFSIZ;
bd5635a1 76 codestream_off = 0;
d747e0af 77 codestream_cnt = CODESTREAM_BUFSIZ;
34df79fc 78 read_memory (codestream_addr, (char *) codestream_buf, CODESTREAM_BUFSIZ);
bd5635a1
RP
79
80 if (peek_flag)
81 return (codestream_peek());
82 else
83 return (codestream_get());
84}
85
86static void
87codestream_seek (place)
f33b2c13 88 CORE_ADDR place;
bd5635a1 89{
d747e0af
MT
90 codestream_next_addr = place / CODESTREAM_BUFSIZ;
91 codestream_next_addr *= CODESTREAM_BUFSIZ;
bd5635a1
RP
92 codestream_cnt = 0;
93 codestream_fill (1);
94 while (codestream_tell() != place)
95 codestream_get ();
96}
97
98static void
99codestream_read (buf, count)
100 unsigned char *buf;
d747e0af 101 int count;
bd5635a1
RP
102{
103 unsigned char *p;
104 int i;
105 p = buf;
106 for (i = 0; i < count; i++)
107 *p++ = codestream_get ();
108}
109
110/* next instruction is a jump, move to target */
d747e0af
MT
111
112static void
bd5635a1
RP
113i386_follow_jump ()
114{
28ee4b42
PS
115 unsigned char buf[4];
116 long delta;
117
bd5635a1 118 int data16;
28ee4b42
PS
119 CORE_ADDR pos;
120
bd5635a1 121 pos = codestream_tell ();
28ee4b42 122
bd5635a1
RP
123 data16 = 0;
124 if (codestream_peek () == 0x66)
125 {
126 codestream_get ();
127 data16 = 1;
128 }
28ee4b42 129
bd5635a1
RP
130 switch (codestream_get ())
131 {
132 case 0xe9:
133 /* relative jump: if data16 == 0, disp32, else disp16 */
134 if (data16)
135 {
28ee4b42
PS
136 codestream_read (buf, 2);
137 delta = extract_signed_integer (buf, 2);
f2ebc25f
JK
138
139 /* include size of jmp inst (including the 0x66 prefix). */
28ee4b42 140 pos += delta + 4;
bd5635a1
RP
141 }
142 else
143 {
28ee4b42
PS
144 codestream_read (buf, 4);
145 delta = extract_signed_integer (buf, 4);
146
147 pos += delta + 5;
bd5635a1
RP
148 }
149 break;
150 case 0xeb:
151 /* relative jump, disp8 (ignore data16) */
28ee4b42
PS
152 codestream_read (buf, 1);
153 /* Sign-extend it. */
154 delta = extract_signed_integer (buf, 1);
155
156 pos += delta + 2;
bd5635a1
RP
157 break;
158 }
f2ebc25f 159 codestream_seek (pos);
bd5635a1
RP
160}
161
162/*
163 * find & return amound a local space allocated, and advance codestream to
164 * first register push (if any)
165 *
166 * if entry sequence doesn't make sense, return -1, and leave
167 * codestream pointer random
168 */
d747e0af 169
bd5635a1
RP
170static long
171i386_get_frame_setup (pc)
f33b2c13 172 CORE_ADDR pc;
bd5635a1
RP
173{
174 unsigned char op;
28ee4b42 175
bd5635a1 176 codestream_seek (pc);
28ee4b42 177
bd5635a1 178 i386_follow_jump ();
28ee4b42 179
bd5635a1 180 op = codestream_get ();
28ee4b42 181
bd5635a1
RP
182 if (op == 0x58) /* popl %eax */
183 {
184 /*
185 * this function must start with
186 *
187 * popl %eax 0x58
188 * xchgl %eax, (%esp) 0x87 0x04 0x24
189 * or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
190 *
191 * (the system 5 compiler puts out the second xchg
192 * inst, and the assembler doesn't try to optimize it,
193 * so the 'sib' form gets generated)
194 *
195 * this sequence is used to get the address of the return
196 * buffer for a function that returns a structure
197 */
198 int pos;
199 unsigned char buf[4];
200 static unsigned char proto1[3] = { 0x87,0x04,0x24 };
201 static unsigned char proto2[4] = { 0x87,0x44,0x24,0x00 };
202 pos = codestream_tell ();
203 codestream_read (buf, 4);
51b57ded 204 if (memcmp (buf, proto1, 3) == 0)
bd5635a1 205 pos += 3;
51b57ded 206 else if (memcmp (buf, proto2, 4) == 0)
bd5635a1 207 pos += 4;
28ee4b42 208
bd5635a1
RP
209 codestream_seek (pos);
210 op = codestream_get (); /* update next opcode */
211 }
28ee4b42 212
bd5635a1
RP
213 if (op == 0x55) /* pushl %ebp */
214 {
215 /* check for movl %esp, %ebp - can be written two ways */
216 switch (codestream_get ())
217 {
218 case 0x8b:
219 if (codestream_get () != 0xec)
220 return (-1);
221 break;
222 case 0x89:
223 if (codestream_get () != 0xe5)
224 return (-1);
225 break;
226 default:
227 return (-1);
228 }
229 /* check for stack adjustment
230 *
231 * subl $XXX, %esp
232 *
233 * note: you can't subtract a 16 bit immediate
234 * from a 32 bit reg, so we don't have to worry
235 * about a data16 prefix
236 */
237 op = codestream_peek ();
238 if (op == 0x83)
239 {
240 /* subl with 8 bit immed */
241 codestream_get ();
242 if (codestream_get () != 0xec)
243 /* Some instruction starting with 0x83 other than subl. */
244 {
245 codestream_seek (codestream_tell () - 2);
246 return 0;
247 }
248 /* subl with signed byte immediate
249 * (though it wouldn't make sense to be negative)
250 */
251 return (codestream_get());
252 }
253 else if (op == 0x81)
254 {
34df79fc
JK
255 char buf[4];
256 /* Maybe it is subl with 32 bit immedediate. */
bd5635a1
RP
257 codestream_get();
258 if (codestream_get () != 0xec)
259 /* Some instruction starting with 0x81 other than subl. */
260 {
261 codestream_seek (codestream_tell () - 2);
262 return 0;
263 }
34df79fc
JK
264 /* It is subl with 32 bit immediate. */
265 codestream_read ((unsigned char *)buf, 4);
266 return extract_signed_integer (buf, 4);
bd5635a1
RP
267 }
268 else
269 {
270 return (0);
271 }
272 }
273 else if (op == 0xc8)
274 {
34df79fc 275 char buf[2];
bd5635a1 276 /* enter instruction: arg is 16 bit unsigned immed */
34df79fc 277 codestream_read ((unsigned char *)buf, 2);
bd5635a1 278 codestream_get (); /* flush final byte of enter instruction */
34df79fc 279 return extract_unsigned_integer (buf, 2);
bd5635a1
RP
280 }
281 return (-1);
282}
283
284/* Return number of args passed to a frame.
285 Can return -1, meaning no way to tell. */
286
bd5635a1
RP
287int
288i386_frame_num_args (fi)
d747e0af 289 struct frame_info *fi;
bd5635a1 290{
34df79fc
JK
291#if 1
292 return -1;
293#else
294 /* This loses because not only might the compiler not be popping the
295 args right after the function call, it might be popping args from both
296 this call and a previous one, and we would say there are more args
297 than there really are. */
298
bd5635a1
RP
299 int retpc;
300 unsigned char op;
301 struct frame_info *pfi;
302
34df79fc
JK
303 /* on the 386, the instruction following the call could be:
304 popl %ecx - one arg
305 addl $imm, %esp - imm/4 args; imm may be 8 or 32 bits
306 anything else - zero args */
307
bd5635a1
RP
308 int frameless;
309
310 FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
311 if (frameless)
312 /* In the absence of a frame pointer, GDB doesn't get correct values
313 for nameless arguments. Return -1, so it doesn't print any
314 nameless arguments. */
315 return -1;
316
d747e0af 317 pfi = get_prev_frame_info (fi);
bd5635a1
RP
318 if (pfi == 0)
319 {
320 /* Note: this can happen if we are looking at the frame for
321 main, because FRAME_CHAIN_VALID won't let us go into
322 start. If we have debugging symbols, that's not really
323 a big deal; it just means it will only show as many arguments
324 to main as are declared. */
325 return -1;
326 }
327 else
328 {
329 retpc = pfi->pc;
330 op = read_memory_integer (retpc, 1);
331 if (op == 0x59)
332 /* pop %ecx */
333 return 1;
334 else if (op == 0x83)
335 {
336 op = read_memory_integer (retpc+1, 1);
337 if (op == 0xc4)
338 /* addl $<signed imm 8 bits>, %esp */
339 return (read_memory_integer (retpc+2,1)&0xff)/4;
340 else
341 return 0;
342 }
343 else if (op == 0x81)
344 { /* add with 32 bit immediate */
345 op = read_memory_integer (retpc+1, 1);
346 if (op == 0xc4)
347 /* addl $<imm 32>, %esp */
348 return read_memory_integer (retpc+2, 4) / 4;
349 else
350 return 0;
351 }
352 else
353 {
354 return 0;
355 }
356 }
34df79fc 357#endif
bd5635a1
RP
358}
359
360/*
361 * parse the first few instructions of the function to see
362 * what registers were stored.
363 *
364 * We handle these cases:
365 *
366 * The startup sequence can be at the start of the function,
367 * or the function can start with a branch to startup code at the end.
368 *
369 * %ebp can be set up with either the 'enter' instruction, or
370 * 'pushl %ebp, movl %esp, %ebp' (enter is too slow to be useful,
371 * but was once used in the sys5 compiler)
372 *
373 * Local space is allocated just below the saved %ebp by either the
374 * 'enter' instruction, or by 'subl $<size>, %esp'. 'enter' has
375 * a 16 bit unsigned argument for space to allocate, and the
376 * 'addl' instruction could have either a signed byte, or
377 * 32 bit immediate.
378 *
379 * Next, the registers used by this function are pushed. In
380 * the sys5 compiler they will always be in the order: %edi, %esi, %ebx
381 * (and sometimes a harmless bug causes it to also save but not restore %eax);
382 * however, the code below is willing to see the pushes in any order,
383 * and will handle up to 8 of them.
384 *
385 * If the setup sequence is at the end of the function, then the
386 * next instruction will be a branch back to the start.
387 */
388
d747e0af 389void
bd5635a1
RP
390i386_frame_find_saved_regs (fip, fsrp)
391 struct frame_info *fip;
392 struct frame_saved_regs *fsrp;
393{
394 long locals;
bd5635a1
RP
395 unsigned char op;
396 CORE_ADDR dummy_bottom;
397 CORE_ADDR adr;
398 int i;
399
34df79fc 400 memset (fsrp, 0, sizeof *fsrp);
bd5635a1
RP
401
402 /* if frame is the end of a dummy, compute where the
403 * beginning would be
404 */
405 dummy_bottom = fip->frame - 4 - REGISTER_BYTES - CALL_DUMMY_LENGTH;
406
407 /* check if the PC is in the stack, in a dummy frame */
408 if (dummy_bottom <= fip->pc && fip->pc <= fip->frame)
409 {
410 /* all regs were saved by push_call_dummy () */
411 adr = fip->frame;
412 for (i = 0; i < NUM_REGS; i++)
413 {
414 adr -= REGISTER_RAW_SIZE (i);
415 fsrp->regs[i] = adr;
416 }
417 return;
418 }
419
420 locals = i386_get_frame_setup (get_pc_function_start (fip->pc));
421
422 if (locals >= 0)
423 {
424 adr = fip->frame - 4 - locals;
425 for (i = 0; i < 8; i++)
426 {
427 op = codestream_get ();
428 if (op < 0x50 || op > 0x57)
429 break;
1a494973
C
430#ifdef I386_REGNO_TO_SYMMETRY
431 /* Dynix uses different internal numbering. Ick. */
432 fsrp->regs[I386_REGNO_TO_SYMMETRY(op - 0x50)] = adr;
433#else
bd5635a1 434 fsrp->regs[op - 0x50] = adr;
1a494973 435#endif
bd5635a1
RP
436 adr -= 4;
437 }
438 }
439
440 fsrp->regs[PC_REGNUM] = fip->frame + 4;
441 fsrp->regs[FP_REGNUM] = fip->frame;
442}
443
444/* return pc of first real instruction */
d747e0af
MT
445
446int
bd5635a1 447i386_skip_prologue (pc)
d747e0af 448 int pc;
bd5635a1
RP
449{
450 unsigned char op;
451 int i;
28ee4b42
PS
452 static unsigned char pic_pat[6] = { 0xe8, 0, 0, 0, 0, /* call 0x0 */
453 0x5b, /* popl %ebx */
454 };
455 CORE_ADDR pos;
bd5635a1
RP
456
457 if (i386_get_frame_setup (pc) < 0)
458 return (pc);
459
460 /* found valid frame setup - codestream now points to
461 * start of push instructions for saving registers
462 */
463
464 /* skip over register saves */
465 for (i = 0; i < 8; i++)
466 {
467 op = codestream_peek ();
468 /* break if not pushl inst */
469 if (op < 0x50 || op > 0x57)
470 break;
471 codestream_get ();
472 }
28ee4b42
PS
473
474 /* The native cc on SVR4 in -K PIC mode inserts the following code to get
475 the address of the global offset table (GOT) into register %ebx.
476 call 0x0
477 popl %ebx
478 movl %ebx,x(%ebp) (optional)
479 addl y,%ebx
480 This code is with the rest of the prologue (at the end of the
481 function), so we have to skip it to get to the first real
482 instruction at the start of the function. */
483
484 pos = codestream_tell ();
485 for (i = 0; i < 6; i++)
486 {
487 op = codestream_get ();
488 if (pic_pat [i] != op)
489 break;
490 }
491 if (i == 6)
492 {
493 unsigned char buf[4];
494 long delta = 6;
495
496 op = codestream_get ();
497 if (op == 0x89) /* movl %ebx, x(%ebp) */
498 {
499 op = codestream_get ();
500 if (op == 0x5d) /* one byte offset from %ebp */
501 {
502 delta += 3;
503 codestream_read (buf, 1);
504 }
505 else if (op == 0x9d) /* four byte offset from %ebp */
506 {
507 delta += 6;
508 codestream_read (buf, 4);
509 }
510 else /* unexpected instruction */
511 delta = -1;
512 op = codestream_get ();
513 }
514 /* addl y,%ebx */
515 if (delta > 0 && op == 0x81 && codestream_get () == 0xc3)
516 {
517 pos += delta + 6;
518 }
519 }
520 codestream_seek (pos);
bd5635a1
RP
521
522 i386_follow_jump ();
523
524 return (codestream_tell ());
525}
526
d747e0af 527void
bd5635a1
RP
528i386_push_dummy_frame ()
529{
530 CORE_ADDR sp = read_register (SP_REGNUM);
531 int regnum;
532 char regbuf[MAX_REGISTER_RAW_SIZE];
533
534 sp = push_word (sp, read_register (PC_REGNUM));
535 sp = push_word (sp, read_register (FP_REGNUM));
536 write_register (FP_REGNUM, sp);
537 for (regnum = 0; regnum < NUM_REGS; regnum++)
538 {
539 read_register_gen (regnum, regbuf);
540 sp = push_bytes (sp, regbuf, REGISTER_RAW_SIZE (regnum));
541 }
542 write_register (SP_REGNUM, sp);
543}
544
d747e0af 545void
bd5635a1
RP
546i386_pop_frame ()
547{
1a494973 548 struct frame_info *frame = get_current_frame ();
bd5635a1
RP
549 CORE_ADDR fp;
550 int regnum;
551 struct frame_saved_regs fsr;
bd5635a1
RP
552 char regbuf[MAX_REGISTER_RAW_SIZE];
553
1a494973
C
554 fp = FRAME_FP (frame);
555 get_frame_saved_regs (frame, &fsr);
bd5635a1
RP
556 for (regnum = 0; regnum < NUM_REGS; regnum++)
557 {
558 CORE_ADDR adr;
559 adr = fsr.regs[regnum];
560 if (adr)
561 {
562 read_memory (adr, regbuf, REGISTER_RAW_SIZE (regnum));
563 write_register_bytes (REGISTER_BYTE (regnum), regbuf,
564 REGISTER_RAW_SIZE (regnum));
565 }
566 }
567 write_register (FP_REGNUM, read_memory_integer (fp, 4));
568 write_register (PC_REGNUM, read_memory_integer (fp + 4, 4));
569 write_register (SP_REGNUM, fp + 8);
570 flush_cached_frames ();
bd5635a1 571}
d747e0af 572
51b57ded
FF
573#ifdef GET_LONGJMP_TARGET
574
575/* Figure out where the longjmp will land. Slurp the args out of the stack.
576 We expect the first arg to be a pointer to the jmp_buf structure from which
577 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
578 This routine returns true on success. */
579
580int
581get_longjmp_target(pc)
582 CORE_ADDR *pc;
583{
34df79fc 584 char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
51b57ded
FF
585 CORE_ADDR sp, jb_addr;
586
34df79fc 587 sp = read_register (SP_REGNUM);
51b57ded 588
34df79fc
JK
589 if (target_read_memory (sp + SP_ARG0, /* Offset of first arg on stack */
590 buf,
591 TARGET_PTR_BIT / TARGET_CHAR_BIT))
51b57ded
FF
592 return 0;
593
34df79fc 594 jb_addr = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
51b57ded 595
34df79fc
JK
596 if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf,
597 TARGET_PTR_BIT / TARGET_CHAR_BIT))
51b57ded
FF
598 return 0;
599
34df79fc 600 *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT);
51b57ded
FF
601
602 return 1;
603}
604
605#endif /* GET_LONGJMP_TARGET */
34df79fc 606
34df79fc
JK
607void
608i386_extract_return_value(type, regbuf, valbuf)
609 struct type *type;
610 char regbuf[REGISTER_BYTES];
611 char *valbuf;
612{
f33b2c13
SG
613/* On AIX, floating point values are returned in floating point registers. */
614#ifdef I386_AIX_TARGET
34df79fc
JK
615 if (TYPE_CODE_FLT == TYPE_CODE(type))
616 {
34df79fc
JK
617 double d;
618 /* 387 %st(0), gcc uses this */
eae3f093
JK
619 floatformat_to_double (&floatformat_i387_ext,
620 &regbuf[REGISTER_BYTE(FP0_REGNUM)],
621 &d);
28ee4b42 622 store_floating (valbuf, TYPE_LENGTH (type), d);
34df79fc
JK
623 }
624 else
f33b2c13 625#endif /* I386_AIX_TARGET */
34df79fc
JK
626 {
627 memcpy (valbuf, regbuf, TYPE_LENGTH (type));
628 }
629}
28ee4b42
PS
630
631#ifdef I386V4_SIGTRAMP_SAVED_PC
632/* Get saved user PC for sigtramp from the pushed ucontext on the stack
633 for all three variants of SVR4 sigtramps. */
634
635CORE_ADDR
636i386v4_sigtramp_saved_pc (frame)
1a494973 637 struct frame_info *frame;
28ee4b42
PS
638{
639 CORE_ADDR saved_pc_offset = 4;
640 char *name = NULL;
641
1a494973 642 find_pc_partial_function (frame->pc, &name, NULL, NULL);
28ee4b42
PS
643 if (name)
644 {
645 if (STREQ (name, "_sigreturn"))
646 saved_pc_offset = 132 + 14 * 4;
137b6849 647 else if (STREQ (name, "_sigacthandler"))
28ee4b42 648 saved_pc_offset = 80 + 14 * 4;
137b6849 649 else if (STREQ (name, "sigvechandler"))
28ee4b42
PS
650 saved_pc_offset = 120 + 14 * 4;
651 }
652
653 if (frame->next)
654 return read_memory_integer (frame->next->frame + saved_pc_offset, 4);
655 return read_memory_integer (read_register (SP_REGNUM) + saved_pc_offset, 4);
656}
657#endif /* I386V4_SIGTRAMP_SAVED_PC */
1a494973 658
f33b2c13
SG
659
660
661/* Stuff for WIN32 PE style DLL's but is pretty generic really. */
662
663CORE_ADDR
664skip_trampoline_code (pc, name)
665 CORE_ADDR pc;
666 char *name;
667{
668 if (pc && read_memory_unsigned_integer (pc, 2) == 0x25ff) /* jmp *(dest) */
669 {
670 unsigned long indirect = read_memory_unsigned_integer (pc+2, 4);
671 struct minimal_symbol *indsym =
672 indirect ? lookup_minimal_symbol_by_pc (indirect) : 0;
673 char *symname = indsym ? SYMBOL_NAME(indsym) : 0;
674
675 if (symname)
676 {
677 if (strncmp (symname,"__imp_", 6) == 0
678 || strncmp (symname,"_imp_", 5) == 0)
679 return name ? 1 : read_memory_unsigned_integer (indirect, 4);
680 }
681 }
682 return 0; /* not a trampoline */
683}
684
685static char *x86_assembly_types[] = {"i386", "i8086", NULL};
686static char *x86_assembly_result = "i386";
687
688static void
689set_assembly_language_command (ignore, from_tty, c)
690 char *ignore;
691 int from_tty;
692 struct cmd_list_element *c;
693{
694 if (strcmp (x86_assembly_result, "i386") == 0)
695 tm_print_insn = print_insn_i386;
696 else
697 tm_print_insn = print_insn_i8086;
698}
699
1a494973
C
700void
701_initialize_i386_tdep ()
702{
f33b2c13
SG
703 struct cmd_list_element *cmd;
704
1a494973 705 tm_print_insn = print_insn_i386;
f33b2c13
SG
706
707 cmd = add_set_enum_cmd ("assembly-language", class_obscure,
708 x86_assembly_types, (char *)&x86_assembly_result,
709 "Set x86 instruction set to use for disassembly.\n\
710This value can be set to either i386 or i8086 to change how instructions are disassembled.",
711 &setlist);
712 add_show_from_set (cmd, &showlist);
713
714 cmd->function.sfunc = set_assembly_language_command;
1a494973 715}
This page took 0.342171 seconds and 4 git commands to generate.