flat assembler
Message board for the users of flat assembler.

Index > IDE Development > FASMW request: PUSH/POP pairing evenness

Author
Thread Post new topic Reply to topic
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Hi. I have another story to tell. I was compiling a program today(lots of code) and it kept crashing but I could not find the bug since it's too big to even debug.

So I was wondering if you could make FASMW count how many PUSHes and POPs are performed regardless of CALLs.

So, like(generates WARNING):
Code:
PUSH EBP  ;<---- has no POP counterpart

PUSH 1234
PUSH 5678
CALL  add
ret
    

FASMW then would warn the user
WARNING: Uneven number of PUSH/POPs or
WARNING: Your stack frame looks disastrous

However the following does not generate a WARNING)

Code:
PUSH EBP  ;<---- first PUSH

PUSH 1234
PUSH 5678
CALL  add

POP  EBP ;<------first PUSH has a counterpart
ret
    



I'm assuming FASM(compiler) is smart enough to tell if the PUSH being made is for a CALL by checking for (ADD ESP, XXX ) in the case of an __cdecl call convention. But how would you tell with an __stdcall convention?...I do not know.

Also, it would be very very very very very awesome if FASMW supported plugin technology that way we would just do these things on our own instead of nagging you Very Happy
Post 06 May 2012, 20:44
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
You can write such utilities for Fresh and they will be included in the project. But I doubt there exists reliable enough algorithm for such checks.(except of course, code emulation).
Post 06 May 2012, 21:17
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
You can override the instructions with wrapper macros:
Code:
__stack = 0

macro push [x]
{
 forward
        push x
        __stack = __stack + 1
}

macro pop [x]
{
 forward
        pop x

        if __stack = 0
                err Stack underflow
        end if

        __stack = __stack - 1
}

macro ret
{
        ret

        if __stack <> 0
                err Stack imbalance
        end if
}
    
You would also need to extend this for calls/proc macro or other special cases since (AFAIK) FASM has no actual knowledge of parameters to a procedure.
Post 06 May 2012, 21:51
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
@codebase thanks I found the damn error
Code:
push                 edi                      ; string
push                 dword _http.size    ; number
push                 eax                     ; format
push                 ebx                     ;buffer
call                   [_user32.wsprintfA]
add                   esp,    4*3  ; <------------------------- LOL
    

EDI would get stuck on the stack
What a stupid bug. Very Happy wasted my precious time.
Post 07 May 2012, 01:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
typedef wrote:
@codebase thanks I found the damn error
Code:
push                 edi                      ; string
push                 dword _http.size    ; number
push                 eax                     ; format
push                 ebx                     ;buffer
call                   [_user32.wsprintfA]
add                   esp,    4*3  ; <------------------------- LOL
    

EDI would get stuck on the stack
What a stupid bug. Very Happy wasted my precious time.
That is why we have the cinvoke macro. With the macro such off-by-one errors are greatly lessened.
Post 07 May 2012, 02:20
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
typedef wrote:
Hi. I have another story to tell. I was compiling a program today(lots of code) and it kept crashing but I could not find the bug since it's too big to even debug.

So I was wondering if you could make FASMW count how many PUSHes and POPs are performed regardless of CALLs.

So, like(generates WARNING):


I don't think that it is very useful. Because you can not interprete stack content. What about the many used constructions with

Quote:

push ebp
<some code>
pop eax


or

Quote:

push eax ebx ecx edx edi esi
<some code>
add esp,5*4 ; cleanup stack
pop eax


So this is a very complex adventure and you never mind what a programmer wants to do with the stack. In the first example the sequence

Quote:

pop ebp
mov eax,ebp


is quite longer in code and execution and maybe you don't want to destroy ebp contents which have been changed in the code inbetween.

So please do not try to generate warnings, this could be a never ending story. Wink
Post 07 May 2012, 12:32
View user's profile Send private message Send e-mail Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
I agree. Too much of an IDE means less freedom for a coder.
Post 07 May 2012, 14:33
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.