Board index » cppbuilder » Borland equivalent of _ReturnAddress()?

Borland equivalent of _ReturnAddress()?


2008-01-03 03:16:46 PM
cppbuilder67
Is there a borland equivalent of Microsofts _ReturnAddress():
msdn2.microsoft.com/en-us/library/64ez38eh.aspx
Im using BDS 2006.
Leo Havm°ller.
 
 

Re:Borland equivalent of _ReturnAddress()?

Leo Havm°ller wrote:
Quote
Is there a borland equivalent of Microsofts _ReturnAddress():
I don't think so.
I think a method to do so was covered in the TASM group
several years ago.
Quote
Im using BDS 2006.
But, then again, you are asking in the wrong group.
This group covers the pre-Builder versions while you
are asking about a post-Builder version.
Builder and BDS/TCE/RAD questions belong in groups
with cppbuilder in their names.
 

Re:Borland equivalent of _ReturnAddress()?

Leo Havm°ller < XXXX@XXXXX.COM >wrote:
Quote
Is there a borland equivalent of Microsofts _ReturnAddress():
msdn2.microsoft.com/en-us/library/64ez38eh.aspx
Im using BDS 2006.
I'm afraid I don't know the answer to this one, but I have a question of
my own - what on earth are you trying to do?!
(If you've got someone else's source code that uses this, I don't envy
you.)
Alan Bellingham
--
Team Browns
ACCU Conference 2008: 2-5 April 2008 - Oxford, UK
 

{smallsort}

Re:Borland equivalent of _ReturnAddress()?

"Leo Havm°ller" < XXXX@XXXXX.COM >wrote in message
Quote
Is there a borland equivalent of Microsofts _ReturnAddress():
msdn2.microsoft.com/en-us/library/64ez38eh.aspx
Im using BDS 2006.
Prototype:
#ifdef __cplusplus
extern "C"
#endif
void* _ReturnAddress(void);
Implementation:
#pragma warn -8070 // W8070 Function should return a value
__declspec({*word*192}) void* _ReturnAddress(void)
{
__asm mov eax, [ebp + 4]
__asm ret
}
More info:
nedbatchelder.com/blog/20051006T065335.html
Leo Havm°ller.
 

Re:Borland equivalent of _ReturnAddress()?

Not meant as a nitpick, just an alternative.
__declspec({*word*192}) void* _ReturnAddress(void)
{
__asm mov eax, [ebp + 4] /* or _EAX = _EBP + 4; */
return _EAX;
}
. Ed
Quote
Leo Havm°ller wrote in message
news:477dd195$ XXXX@XXXXX.COM ...

Prototype:
#ifdef __cplusplus
extern "C"
#endif
void* _ReturnAddress(void);

Implementation:
#pragma warn -8070 // W8070 Function should return a value
__declspec({*word*192}) void* _ReturnAddress(void)
{
__asm mov eax, [ebp + 4]
__asm ret
}

More info:
nedbatchelder.com/blog/20051006T065335.html
 

Re:Borland equivalent of _ReturnAddress()?

Leo Havm°ller wrote:
Quote
__declspec({*word*192}) void* _ReturnAddress(void)
Beware of bugs in compiler with {*word*192} functions (5042,5041,2955)
--
Alex
 

Re:Borland equivalent of _ReturnAddress()?

Depending on the assembler (haven't experimented, don't remember enough TASM
from over a decade ago, and no BASM use recently), but your alternate is not
functionally equivalent for all assembler syntaxes, maybe not for B/CG
products either.
The original, I would expect to add 4 to BP, and retrieve the value at that
location.
Your alternate just adds 4 to BP and returns that (address) value, not
what's located at that address...
Yes/No?
"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Not meant as a nitpick, just an alternative.

__declspec({*word*192}) void* _ReturnAddress(void)
{
__asm mov eax, [ebp + 4] /* or _EAX = _EBP + 4; */
return _EAX;
}

. Ed

>Leo Havm°ller wrote in message
>news:477dd195$ XXXX@XXXXX.COM ...
>
>Prototype:
>#ifdef __cplusplus
>extern "C"
>#endif
>void* _ReturnAddress(void);
>
>Implementation:
>#pragma warn -8070 // W8070 Function should return a value
>__declspec({*word*192}) void* _ReturnAddress(void)
>{
>__asm mov eax, [ebp + 4]
>__asm ret
>}
>
>More info:
>nedbatchelder.com/blog/20051006T065335.html


 

Re:Borland equivalent of _ReturnAddress()?

Good catch!
You are correct. The alternative to mov eax,[dbp+4] that I put in the
comment was wrong.
It was meant to be clearer for people more familiar with C/C++ than
assembler. To actually do what is needed is arguably as confusing as the
assembly language.
So the "simplified" boils down to one of these:
__declspec({*word*192}) void* _ReturnAddress(void)
{
__asm mov eax, [ebp + 4]
return _EAX;
}
__declspec({*word*192}) void* _ReturnAddress(void)
{
_EAX = *((unsigned *) (_EBP + 4));
return _EAX;
}
Quote
...don't remember enough TASM from over a decade ago, and no BASM use
recently), but ...
If for no other reason than Call Stack and CPU View you should feel at least
somewhat comfortable with assembly. Here are a couple of links from Borland
veteran Matt Pietrek that serve it up candy coated:
Just Enough Assembly To Get By, parts 1 and 2
www.microsoft.com/msj/0298/hood0298.aspx
www.microsoft.com/msj/0698/hood0698.aspx
. Ed
Quote
dhoke wrote in message
news:47822fb4$ XXXX@XXXXX.COM ...

Depending on the assembler (haven't experimented, don't remember enough
TASM from over a decade ago, and no BASM use recently), but your alternate
is not functionally equivalent for all assembler syntaxes, maybe not for
B/CG products either.

The original, I would expect to add 4 to BP, and retrieve the value at
that location. Your alternate just adds 4 to BP and returns that
(address) value, not what's located at that address...
 

Re:Borland equivalent of _ReturnAddress()?

Leo Havm°ller wrote:
Quote
Is there a borland equivalent of Microsofts _ReturnAddress():
msdn2.microsoft.com/en-us/library/64ez38eh.aspx
Im using BDS 2006.

Leo Havm°ller.
I think I filed a QC report for this a while ago.
 

Re:Borland equivalent of _ReturnAddress()?

AlexB < XXXX@XXXXX.COM >wrote:
Quote
Leo Havm°ller wrote:

>__declspec({*word*192}) void* _ReturnAddress(void)

Beware of bugs in compiler with {*word*192} functions (5042,5041,2955)
Ah, it compiles only decent code?
SCNRobi
--
XXXX@XXXXX.COM is never read
I'm HSchober at gmx dot de
"The trouble with being a god is that you've got
no one to pray to." Terry Pratchett