• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión586314f2aa62990dead8144e780c4c8c498eece6 (tree)
Tiempo2003-03-04 00:02:29
Autorbellard <bellard@c046...>
Commiterbellard

Log Message

better debug support

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@18 c046a42c-6fe2-441c-8c8c-71466251a162

Cambiar Resumen

Diferencia incremental

--- a/Makefile
+++ b/Makefile
@@ -34,13 +34,10 @@ DEFINES+=-D_GNU_SOURCE
3434 DEFINES+=-DCONFIG_PREFIX=\"/usr/local\"
3535 LDSCRIPT=$(ARCH).ld
3636 LIBS+=-ldl -lm
37+VERSION=0.1
3738
38-#DEFINES+= -DGEMU -DDOSEMU -DNO_TRACE_MSGS
39-#OBJS= i386/fp87.o i386/interp_main.o i386/interp_modrm.o i386/interp_16_32.o \
40-# i386/interp_32_16.o i386/interp_32_32.o i386/emu-utils.o \
41-# i386/dis8086.o i386/emu-ldt.o
39+OBJS= elfload.o main.o thunk.o syscall.o
4240 OBJS+=translate-i386.o op-i386.o
43-OBJS+= elfload.o main.o thunk.o syscall.o
4441 # NOTE: the disassembler code is only needed for debugging
4542 OBJS+=i386-dis.o dis-buf.o
4643 SRCS = $(OBJS:.o=.c)
@@ -53,15 +50,6 @@ gemu: $(OBJS)
5350 depend: $(SRCS)
5451 $(CC) -MM $(CFLAGS) $^ 1>.depend
5552
56-# old i386 emulator
57-i386/interp_32_32.o: i386/interp_32_32.c i386/interp_gen.h
58-
59-i386/interp_gen.h: i386/gencode
60- ./i386/gencode > $@
61-
62-i386/gencode: i386/gencode.c
63- $(CC) -O2 -Wall -g $< -o $@
64-
6553 # new i386 emulator
6654 dyngen: dyngen.c
6755 $(HOST_CC) -O2 -Wall -g $< -o $@
@@ -78,7 +66,7 @@ op-i386.o: op-i386.c opreg_template.h ops_template.h
7866 $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
7967
8068 clean:
81- rm -f *.o *~ i386/*.o i386/*~ gemu TAGS
69+ rm -f *.o *~ gemu dyngen TAGS
8270
8371 # various test targets
8472 test speed: gemu
@@ -87,6 +75,26 @@ test speed: gemu
8775 TAGS:
8876 etags *.[ch] i386/*.[ch]
8977
78+FILES= \
79+COPYING.LIB dyngen.c ioctls.h ops_template.h syscall_types.h\
80+Makefile elf.h linux_bin.h segment.h thunk.c\
81+TODO elfload.c main.c signal.c thunk.h\
82+cpu-i386.h gemu.h op-i386.c syscall-i386.h translate-i386.c\
83+dis-asm.h gen-i386.h op-i386.h syscall.c\
84+dis-buf.c i386-dis.c opreg_template.h syscall_defs.h\
85+i386.ld ppc.ld\
86+tests/test-i386.c tests/test-i386-shift.h tests/test-i386.h\
87+tests/test2.c tests/hello.c tests/sha1.c tests/test1.c
88+
89+FILE=gemu-$(VERSION)
90+
91+tar:
92+ rm -rf /tmp/$(FILE)
93+ mkdir -p /tmp/$(FILE)
94+ cp -P $(FILES) /tmp/$(FILE)
95+ ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) )
96+ rm -rf /tmp/$(FILE)
97+
9098 ifneq ($(wildcard .depend),)
9199 include .depend
92100 endif
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -27,6 +27,11 @@
2727
2828 #include "cpu-i386.h"
2929
30+#define DEBUG_LOGFILE "/tmp/gemu.log"
31+
32+FILE *logfile = NULL;
33+int loglevel;
34+
3035 unsigned long x86_stack_size;
3136 unsigned long stktop;
3237
@@ -83,7 +88,7 @@ int cpu_x86_inl(int addr)
8388 void usage(void)
8489 {
8590 printf("gemu version 0.1, Copyright (c) 2003 Fabrice Bellard\n"
86- "usage: gemu program [arguments...]\n"
91+ "usage: gemu [-d] program [arguments...]\n"
8792 "Linux x86 emulator\n"
8893 );
8994 exit(1);
@@ -95,11 +100,27 @@ int main(int argc, char **argv)
95100 struct target_pt_regs regs1, *regs = &regs1;
96101 struct image_info info1, *info = &info1;
97102 CPUX86State *env;
103+ int optind;
98104
99105 if (argc <= 1)
100106 usage();
101-
102- filename = argv[1];
107+ loglevel = 0;
108+ optind = 1;
109+ if (argv[optind] && !strcmp(argv[optind], "-d")) {
110+ loglevel = 1;
111+ optind++;
112+ }
113+ filename = argv[optind];
114+
115+ /* init debug */
116+ if (loglevel) {
117+ logfile = fopen(DEBUG_LOGFILE, "w");
118+ if (!logfile) {
119+ perror(DEBUG_LOGFILE);
120+ exit(1);
121+ }
122+ setvbuf(logfile, NULL, _IOLBF, 0);
123+ }
103124
104125 /* Zero out regs */
105126 memset(regs, 0, sizeof(struct target_pt_regs));
--- a/op-i386.c
+++ b/op-i386.c
@@ -1,3 +1,5 @@
1+#define DEBUG_EXEC
2+
13 typedef unsigned char uint8_t;
24 typedef unsigned short uint16_t;
35 typedef unsigned int uint32_t;
@@ -10,6 +12,11 @@ typedef signed long long int64_t;
1012
1113 #define NULL 0
1214
15+typedef struct FILE FILE;
16+extern FILE *logfile;
17+extern int loglevel;
18+extern int fprintf(FILE *, const char *, ...);
19+
1320 #ifdef __i386__
1421 register int T0 asm("esi");
1522 register int T1 asm("ebx");
@@ -1636,6 +1643,32 @@ void OPPROTO op_fcos(void)
16361643 /* main execution loop */
16371644 uint8_t code_gen_buffer[65536];
16381645
1646+#ifdef DEBUG_EXEC
1647+static const char *cc_op_str[] = {
1648+ "DYNAMIC",
1649+ "EFLAGS",
1650+ "MUL",
1651+ "ADDB",
1652+ "ADDW",
1653+ "ADDL",
1654+ "SUBB",
1655+ "SUBW",
1656+ "SUBL",
1657+ "LOGICB",
1658+ "LOGICW",
1659+ "LOGICL",
1660+ "INCB",
1661+ "INCW",
1662+ "INCL",
1663+ "DECB",
1664+ "DECW",
1665+ "DECL",
1666+ "SHLB",
1667+ "SHLW",
1668+ "SHLL",
1669+};
1670+#endif
1671+
16391672 int cpu_x86_exec(CPUX86State *env1)
16401673 {
16411674 int saved_T0, saved_T1, saved_A0;
@@ -1653,6 +1686,17 @@ int cpu_x86_exec(CPUX86State *env1)
16531686 /* prepare setjmp context for exception handling */
16541687 if (setjmp(env->jmp_env) == 0) {
16551688 for(;;) {
1689+#ifdef DEBUG_EXEC
1690+ if (loglevel) {
1691+ fprintf(logfile,
1692+ "EAX=%08x EBX=%08X ECX=%08x EDX=%08x\n"
1693+ "ESI=%08x ESI=%08X EBP=%08x ESP=%08x\n"
1694+ "CCS=%08x CCD=%08x CCOP=%s\n",
1695+ env->regs[R_EAX], env->regs[R_EBX], env->regs[R_ECX], env->regs[R_EDX],
1696+ env->regs[R_ESI], env->regs[R_EDI], env->regs[R_EBP], env->regs[R_ESP],
1697+ env->cc_src, env->cc_dst, cc_op_str[env->cc_op]);
1698+ }
1699+#endif
16561700 cpu_x86_gen_code(code_gen_buffer, &code_gen_size, (uint8_t *)env->pc);
16571701 /* execute the generated code */
16581702 gen_func = (void *)code_gen_buffer;
--- a/translate-i386.c
+++ b/translate-i386.c
@@ -5,23 +5,21 @@
55 #include <inttypes.h>
66 #include <assert.h>
77
8-/* dump all code */
98 #define DEBUG_DISAS
10-#define DEBUG_LOGFILE "/tmp/gemu.log"
119
10+#define IN_OP_I386
11+#include "cpu-i386.h"
12+
13+/* dump all code */
1214 #ifdef DEBUG_DISAS
1315 #include "dis-asm.h"
1416 #endif
1517
16-#define IN_OP_I386
17-#include "cpu-i386.h"
18-
1918 static uint8_t *gen_code_ptr;
2019 int __op_param1, __op_param2, __op_param3;
2120
22-#ifdef DEBUG_DISAS
23-static FILE *logfile = NULL;
24-#endif
21+extern FILE *logfile;
22+extern int loglevel;
2523
2624 /* supress that */
2725 static void error(const char *fmt, ...)
@@ -716,9 +714,6 @@ static void gen_lea_modrm(DisasContext *s, int modrm, int *reg_ptr, int *offset_
716714 int reg1, reg2, opreg;
717715 int mod, rm, code;
718716
719-#ifdef DEBUG_DISAS
720- fprintf(logfile, "modrm=0x%x\n", modrm);
721-#endif
722717 mod = (modrm >> 6) & 3;
723718 rm = modrm & 7;
724719
@@ -731,9 +726,6 @@ static void gen_lea_modrm(DisasContext *s, int modrm, int *reg_ptr, int *offset_
731726 if (base == 4) {
732727 havesib = 1;
733728 code = ldub(s->pc++);
734-#ifdef DEBUG_DISAS
735- fprintf(logfile, "sib=0x%x\n", code);
736-#endif
737729 scale = (code >> 6) & 3;
738730 index = (code >> 3) & 7;
739731 base = code & 7;
@@ -988,11 +980,6 @@ long disas_insn(DisasContext *s, uint8_t *pc_start, int *is_jmp_ptr)
988980 // cur_pc = s->pc; /* for insn generation */
989981 next_byte:
990982 b = ldub(s->pc);
991-#ifdef DEBUG_DISAS
992- fprintf(logfile, "ib=0x%02x\n", b);
993-#endif
994- if (b < 0)
995- return -1;
996983 s->pc++;
997984 /* check prefixes */
998985 switch (b) {
@@ -2247,33 +2234,26 @@ int cpu_x86_gen_code(uint8_t *gen_code_buf, int *gen_code_size_ptr,
22472234 gen_start();
22482235
22492236 #ifdef DEBUG_DISAS
2250- if (!logfile) {
2251- logfile = fopen(DEBUG_LOGFILE, "w");
2252- if (!logfile) {
2253- perror(DEBUG_LOGFILE);
2254- exit(1);
2255- }
2256- setvbuf(logfile, NULL, _IOLBF, 0);
2257- }
2258-
2259- INIT_DISASSEMBLE_INFO(disasm_info, logfile, fprintf);
2260- disasm_info.buffer = pc_start;
2261- disasm_info.buffer_vma = (unsigned long)pc_start;
2262- disasm_info.buffer_length = 15;
2237+ if (loglevel) {
2238+ INIT_DISASSEMBLE_INFO(disasm_info, logfile, fprintf);
2239+ disasm_info.buffer = pc_start;
2240+ disasm_info.buffer_vma = (unsigned long)pc_start;
2241+ disasm_info.buffer_length = 15;
22632242 #if 0
2264- disasm_info.flavour = bfd_get_flavour (abfd);
2265- disasm_info.arch = bfd_get_arch (abfd);
2266- disasm_info.mach = bfd_get_mach (abfd);
2243+ disasm_info.flavour = bfd_get_flavour (abfd);
2244+ disasm_info.arch = bfd_get_arch (abfd);
2245+ disasm_info.mach = bfd_get_mach (abfd);
22672246 #endif
22682247 #ifdef WORDS_BIGENDIAN
2269- disasm_info.endian = BFD_ENDIAN_BIG;
2248+ disasm_info.endian = BFD_ENDIAN_BIG;
22702249 #else
2271- disasm_info.endian = BFD_ENDIAN_LITTLE;
2250+ disasm_info.endian = BFD_ENDIAN_LITTLE;
22722251 #endif
2273- fprintf(logfile, "IN:\n");
2274- fprintf(logfile, "0x%08lx: ", (long)pc_start);
2275- print_insn_i386((unsigned long)pc_start, &disasm_info);
2276- fprintf(logfile, "\n\n");
2252+ fprintf(logfile, "IN:\n");
2253+ fprintf(logfile, "0x%08lx: ", (long)pc_start);
2254+ print_insn_i386((unsigned long)pc_start, &disasm_info);
2255+ fprintf(logfile, "\n\n");
2256+ }
22772257 #endif
22782258 is_jmp = 0;
22792259 ret = disas_insn(dc, pc_start, &is_jmp);
@@ -2290,7 +2270,7 @@ int cpu_x86_gen_code(uint8_t *gen_code_buf, int *gen_code_size_ptr,
22902270 *gen_code_size_ptr = gen_code_ptr - gen_code_buf;
22912271
22922272 #ifdef DEBUG_DISAS
2293- {
2273+ if (loglevel) {
22942274 uint8_t *pc;
22952275 int count;
22962276