It is currently Sun Jun 25, 2017 6:25 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Debugging assembler code...
PostPosted: Sat Jan 28, 2017 2:26 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2156
Hm, the internal debugger is not perfect for debugging assembler code - I would like to be able to switch between hex and decimal values at least (which would be also fine for the constant viewer)...

I am using the following for checking (32 bit) assembler code, does anyone else have a better tool (integrated into the PureBasic environment)?

Code:
Global *a,*b
Global ma.i,mb,i

; Define ShowAsm

   #Hex=1

   EnableASM

   #Asm=0
   #F=20
   #R=65+#Hex!1*10
   #I=120
   #X=905
   #Y=300

   Global AsmInfo.s
   Global AsmMem=@mb

   OpenWindow(#Asm,0,0,#X,#Y,"ASM Information")
   ListIconGadget(#Asm,0,0,#X,#Y,"Info",#I)
   AddGadgetColumn(#Asm,1,"C",#F)
   AddGadgetColumn(#Asm,2,"P",#F)
   AddGadgetColumn(#Asm,3,"A",#F)
   AddGadgetColumn(#Asm,4,"Z",#F)
   AddGadgetColumn(#Asm,5,"S",#F)
   AddGadgetColumn(#Asm,6,"D",#F)
   AddGadgetColumn(#Asm,7,"O",#F)
   AddGadgetColumn(#Asm,8,"EAX",#R)
   AddGadgetColumn(#Asm,9,"EBX",#R)
   AddGadgetColumn(#Asm,10,"ECX",#R)
   AddGadgetColumn(#Asm,11,"EDX",#R)
   AddGadgetColumn(#Asm,12,"EDI",#R)
   AddGadgetColumn(#Asm,13,"ESI",#R)
   AddGadgetColumn(#Asm,14,"EBP",#R)
   AddGadgetColumn(#Asm,15,"ESP",#R)
   AddGadgetColumn(#Asm,16,"Mem Info",#I)

   Macro WaitKey
      Repeat
         Select WaitWindowEvent()
         Case #WM_CHAR
            If EventwParam()=#ESC : End : Else : Break : EndIf
         Case #PB_Event_CloseWindow
            End
         EndSelect
      ForEver
   EndMacro
   Macro OX(number)
      RSet(Hex(number&$FFFFFFFF),8,"0")
   EndMacro
   Macro ShowAsm(Text)

      Global VarAX.l,VarBX.l,VarCX.l,VarDX.l,VarDI.l,VarSI.l,VarBP.l,VarSP.l
      Global gg,gn,FA.b,FC.b,FD.b,FO.b,FP.b,FS.b,FZ.b

      !PUSHFD
      !PUSHAD
      !MOV [v_VarAX],eax
      !MOV [v_VarBX],ebx
      !MOV [v_VarCX],ecx
      !MOV [v_VarDX],edx
      !MOV [v_VarDI],edi
      !MOV [v_VarSI],esi
      !MOV [v_VarBP],ebp
      !MOV [v_VarSP],esp
      !PUSHFD
      !POP eax
      !MOV [v_FC],0
      !SHR eax,1
      !ADC [v_FC],0
      !MOV [v_FP],0;      Parity-Flag
      !SHR eax,2
      !ADC [v_FP],0
      !MOV [v_FA],0;      Auxiliary-Flag
      !SHR eax,2
      !ADC [v_FA],0
      !MOV [v_FZ],0;      Zero-Flag
      !SHR eax,2
      !ADC [v_FZ],0
      !MOV [v_FS],0;      Sign-Flag
      !SHR eax,1
      !ADC [v_FS],0
      !MOV [v_FD],0;      Direction-Flag
      !SHR eax,3
      !ADC [v_FD],0
      !MOV [v_FO],0;      Overflow-Flag
      !SHR eax,1
      !ADC [v_FO],0

      Delay(1)
      AsmInfo=Text+#LF$+Str(FC)+#LF$+Str(FP)+#LF$+Str(FA)+#LF$+Str(FZ)+#LF$+Str(FS)+#LF$+Str(FD)+#LF$+Str(FO)+#LF$
      CompilerIf #Hex
         AsmInfo+Ox(VarAX)+#LF$+Ox(VarBX)+#LF$+Ox(VarCX)+#LF$+Ox(VarDX)+#LF$+Ox(VarDI)+#LF$+Ox(VarSI)+#LF$+Ox(VarBP)+#LF$+Ox(VarSP)+#LF$
      CompilerElse
         AsmInfo+Str(VarAX)+#LF$+Str(VarBX)+#LF$+Str(VarCX)+#LF$+Str(VarDX)+#LF$+Str(VarDI)+#LF$+Str(VarSI)+#LF$+Str(VarBP)+#LF$+Str(VarSP)+#LF$
      CompilerEndIf

      If AsmMem
         AsmInfo+Ox(AsmMem)+"="+Ox(PeekL(AsmMem))
      Else
         AsmInfo+Text
      EndIf

      AddGadgetItem(#Asm,-1,AsmInfo)
      If gg
         If gg&1 : SetGadgetItemColor(#Asm,gg,#PB_Gadget_BackColor,$f0e0e0) : EndIf
         For gn=1 To 15+Bool(AsmMem)
            If GetGadgetItemText(#Asm,gg,gn)<>GetGadgetItemText(#Asm,gg-1,gn)
               SetGadgetItemColor(#Asm,gg,#PB_Gadget_BackColor,#Yellow,gn)
            EndIf
         Next gn
      EndIf
      gg+1

      Waitkey
      !POPAD
      !POPFD

   EndMacro

; EndDefine

Procedure.l GifCopyPattern(*ct,*ptr_output_buffer)

   ShowAsm("init")
   !mov ecx,[p.p_ct]
   ShowAsm("mov ecx,[p.p_ct]")
   !mov edx,[p.p_ptr_output_buffer]
   ShowAsm("mov edx,[p.p_ptr_output_buffer]")
   !movzx eax,word [ecx+8]
   ShowAsm("movzx eax,word [ecx+8]")
   !add [edx],eax
   ShowAsm("add [edx],eax")
   !mov edx,[edx]
   ShowAsm("mov edx,[edx]")
   !gifdecoder_copypattern_loop:
   ShowAsm(":")
   !sub edx,4
   ShowAsm("sub edx,4")
   !mov eax,[ecx+4]
   ShowAsm("mov eax,[ecx+4]")
   !mov [edx],eax
   ShowAsm("mov [edx],eax")
   !mov ecx,[ecx]
   ShowAsm("mov ecx,[ecx]")
   !and ecx,ecx
   ShowAsm("and ecx,ecx")
   !jnz gifdecoder_copypattern_loop
   ShowAsm("done")
   
   ProcedureReturn

EndProcedure

*a=@ma
*b=@mb

ma=0
mb=$4

GifCopyPattern(*a,*b)
WaitKey


Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging assembler code...
PostPosted: Sat Jan 28, 2017 2:31 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1673
x64dbg and Ollydbg are friendly and helping me learn a lot and solve problems, they're not PB IDE-integrated but then i guess nothing else is! i dont really find integration integral though for working on an isolated piece of asm. and its superfast to get straight to where you want to be with !int3

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging assembler code...
PostPosted: Wed Feb 01, 2017 10:10 am 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1211
Keya wrote:
x64dbg and Ollydbg are friendly and helping me learn a lot and solve problems, they're not PB IDE-integrated but then i guess nothing else is! i dont really find integration integral though for working on an isolated piece of asm. and its superfast to get straight to where you want to be with !int3

Thats exactly how i debug asm code in PB. So +1


Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging assembler code...
PostPosted: Wed Feb 01, 2017 7:59 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2156
Thanks, good choice for doing things outside PureBasic.

My hope is, that also the IDE's internal "Asm Debugger" will get an upgrade. Actually, it is nearly useless and the trivial example above gives already much more information for doing first debugging steps...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye