1) run python dlm gdb(maksudnya, debug mode)
# gdb /usr/bin/python
2) Start python
(gdb) run
3) Jika nama file libemu_test.py, maka
>> import libemu_test
0x401019L hex: A83D asm: test al,0x3d
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
4) Back trace
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff58650f6 in emu_cpu_step (c=0xc3fb40) at emu_cpu.c:839
#2 0x00007ffff5b51fbb in __pyx_pf_8pylibemu_8Emulator_25cpu_step (__pyx_v_self=, unused= )
at src/pylibemu.c:6735
#3 0x000000000042afec in PyEval_EvalFrameEx ()
#4 0x00000000004317f2 in PyEval_EvalCodeEx ()
#5 0x000000000054a078 in PyImport_ExecCodeModuleEx ()
#6 0x000000000050d091 in ?? ()
#7 0x000000000050da8b in ?? ()
5) tukar kepada frame 1 (frame ni refering to stack) (rasanya lah:))
(gdb) frame 1
#1 0x00007ffff58650f6 in emu_cpu_step (c=0xc3fb40) at emu_cpu.c:839
839 ret = c->cpu_instr_info->function(c, &c->instr.cpu);
6)
(gdb) ptype c
type = struct emu_cpu {
struct emu *emu;
struct emu_memory *mem;
uint32_t debugflags;
uint32_t eip;
uint32_t eflags;
uint32_t reg[8];
uint16_t *reg16[8];
uint8_t *reg8[8];
struct emu_instruction instr;
struct emu_cpu_instruction_info *cpu_instr_info;
uint32_t last_fpu_instr[2];
char *instr_string;
_Bool repeat_current_instr;
struct emu_track_and_source *tracking;
} *
7)
(gdb) print c
$1 = (struct emu_cpu *) 0xc3fb40
8)
(gdb) print c->cpu_instr_info
$2 = (struct emu_cpu_instruction_info *) 0x7ffff5aedbc0
9)
(gdb) print c->cpu_instr_info->function
$3 = (int32_t (*)(struct emu_cpu *, struct emu_cpu_instruction *)) 0
sah yang problem adalah kat sini, sebab value adalah 0 (kosong)(yg paling kanan). Maksudnya pointer fungsi 'function' point to null.
Maka kena semak code yang initialize cpu_instr_info-> function
10)
(gdb) ptype c->cpu_instr_info
type = struct emu_cpu_instruction_info {
int32_t (*function)(struct emu_cpu *, struct emu_cpu_instruction *);
const char *name;
struct {
uint8_t s_bit : 1;
uint8_t w_bit : 1;
uint8_t modrm_byte : 4;
uint8_t imm_data : 3;
uint8_t disp_data : 3;
uint8_t level : 2;
uint8_t type : 2;
uint8_t fpu_info : 1;
} format;
} *
No comments:
Post a Comment
Terima kasih