2011-03-06 5 views
18

gdb로 디버깅하는 x86 어셈블러 프로그램이 있습니다. "print $ cf"와 같이 gdb 안에 캐리 플래그의 상태를 출력하는 방법이 있습니까?어셈블러가있는 gdb : 캐리 플래그의 인쇄 상태

+0

'layout reg'을 사용하면 레지스터 값 (EFLAGS 포함)으로 분할 화면이 나타납니다. 마지막 단일 단계로 수정 된 레지스터가 강조 표시되므로 디버깅에 정말 좋습니다. 간단한 설명을 보려면 http://stackoverflow.com/tags/x86/info를 참조하십시오. –

+0

'layout reg'은 아주 솔직하게 끔찍합니다. – Sunspawn

답변

27

당신은 사용할 수 있습니다

info registers eflags 

이 플래그의 전체 세트를 얻을 수 있습니다. eflags 레지스터는 캐리와 함께, 0x41로 설정하고 제로 플래그가 설정되어 있음을 의미

eflags 0x41 [ CF ZF ] 

: 당신은 같은 라인을 볼 수 있습니다.

+6

"print $ eflags"또는 "print/x $ eflags" –

+0

감사합니다. 이 페이지에서 "대답 수락"확인란을 찾을 수 있도록 도와 주실 수 있습니까 ^^? 편집 AH ok 큰 체크 표시 – Hinton

+0

@Employed Russian : 답변으로 게시하면 투표 할 수도 있습니다. – Hinton

4

은 내가 EFLAGS는 "P"는 "인쇄"명령에 대한 단지 짧은입니다

(gdb) p $eflags 
$3 = [ PF ZF IF ] 

를 사용하여 등록 확인.

또한 "/ t"(16 진수는/x, 10 진수는/d)를 사용하여 비트를 보는 것이 좋습니다.

(gdb) p/t $eflags 
$4 = 1001000110 

그런 다음 EFLAGS 레지스터에 대한 chart와 비교할 수 있습니다.

0

gdb의 또 다른 좋은 옵션은 eflags에 감시 점을 추가하는 것입니다. TutorialPoint assembly tutorial

[email protected]:~/NASM$ gdb -q add5dig 
Reading symbols from add5dig...done. 
(gdb) set listsize 100 
(gdb) list 0 
1 section .text 
2  global _start 
3 
4 _start: 
5  mov ecx,5 ;number of digits in each number to be added 
6  mov esi,4 ;used to move the esi pointer to point at the rightmost digits to be summed 
7  clc   ;clear carry flag 
8 
9 add_loop:     ;iterates through add_loop, decrementing ecx after each iteration until ecx equals 0 
10  mov al,[num1+esi]  ;mov 
11  adc al,[num2+esi]  ;add with carry, nicely sets carry to 0 if there is no carry and to 1 if there is a carry 
12  aaa     ;ascii adjust after addition 
13  pushf     ;push flags onto stack 
14  or al,30h    ;OR value with 0b0001 1110. (essentially adds 0x30 to the ascii adjusted value, ascii 0x30 is '0', which converts the number to its ascii representation for proper display) 
15  popf     ;pop flags from stack 
16 
17  mov [sum+esi],al  ;moves sum of the two digits into the correct space in memory 
18  dec esi    ;point esi at the next digit to the left 
19  loop add_loop   ;checks if exc==0, loops if not, continues if yes 
20 ;printing message 
21  mov edx,len    
22  mov ecx,msg 
23  mov ebx,1 
24  mov eax,4 
25  int 0x80 
26 ;printing sum 
27  mov edx,5 
28  mov ecx,sum 
29  mov ebx,1 
30  mov eax,4 
31  int 0x80 
32 ;exiting 
33  mov eax,1 
34  int 0x80 
35 
36 section .data 
37 msg db 'The sum is:',0xa 
38 len equ $ - msg 
39 num1 db '12345' 
40 num2 db '23456' 
41 sum db '  '    ;reserves 5 spaces in memory for sum 
(gdb) break _start 
Breakpoint 1 at 0x8048080 
(gdb) break add_loop 
Breakpoint 2 at 0x804808b 
(gdb) run 
Starting program: /home/unroot/NASM/add5dig 

Breakpoint 1, 0x08048080 in _start() 
(gdb) watch $eflags 
Watchpoint 3: $eflags 
(gdb) info registers 
eax   0x0 0 
ecx   0x0 0 
edx   0x0 0 
ebx   0x0 0 
esp   0xbffff0b0 0xbffff0b0 
ebp   0x0 0x0 
esi   0x0 0 
edi   0x0 0 
eip   0x8048080 0x8048080 <_start> 
eflags   0x202 [ IF ] 
cs    0x73 115 
ss    0x7b 123 
ds    0x7b 123 
es    0x7b 123 
fs    0x0 0 
gs    0x0 0 
(gdb) cont 
Continuing. 

Breakpoint 2, 0x0804808b in add_loop() 
(gdb) info registers 
eax   0x0 0 
ecx   0x5 5 
edx   0x0 0 
ebx   0x0 0 
esp   0xbffff0b0 0xbffff0b0 
ebp   0x0 0x0 
esi   0x4 4 
edi   0x0 0 
eip   0x804808b 0x804808b <add_loop> 
eflags   0x202 [ IF ] 
cs    0x73 115 
ss    0x7b 123 
ds    0x7b 123 
es    0x7b 123 
fs    0x0 0 
gs    0x0 0 
(gdb) cont 
Continuing. 

Watchpoint 3: $eflags 

Old value = [ IF ] 
New value = [ CF AF IF ] 
0x08048098 in add_loop() 
(gdb) info registers 
eax   0x101 257 
ecx   0x5 5 
edx   0x0 0 
ebx   0x0 0 
esp   0xbffff0b0 0xbffff0b0 
ebp   0x0 0x0 
esi   0x4 4 
edi   0x0 0 
eip   0x8048098 0x8048098 <add_loop+13> 
eflags   0x213 [ CF AF IF ] 
cs    0x73 115 
ss    0x7b 123 
ds    0x7b 123 
es    0x7b 123 
fs    0x0 0 
gs    0x0 0 
(gdb) 

의 와치 포인트는 EFLAGS가왔다 등록에 캐리 플래그와 국기를 조정하는 것이 잡는다 : tutorialspoint에서 좋은 튜토리얼에서 발견

GDB Examining the Symbol Table

이 프로그램은 12345과 23456을 요약하는 것입니다 프로그램이 '6'과 '5'를 더할 때 변경