Board index » off-topic » Re: EXCEPTION HANDLING

Re: EXCEPTION HANDLING


2004-09-03 12:54:43 AM
off-topic15
Thank You, Vasya.
I made so on Your suggestion (right click in CPU window, ...). When arises
an access violation, TD32 displays a message "Access violation", I click OK,
then press F7, the de{*word*81} goes somewhere in Windows kernel, but it enters
after a 10-15 steps in a RaiseException routine, then TD32 displays again
the same error message. My exception handler which begins with INT 3, was
not reached. So behaves also on second TD32 start when the exception
handling already set (TD32 saves the settings).
"Vasya Pupkin" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Hi Ivan,

[...]
>It seems that TD32 does not detect exception handler in ASM program.

Right click in CPU window, select "OS Exceptions..."
menu item, then click "User All" and "OK" buttons.

--
Best regards,
Vasya Pupkin.


 
 

Re:Re: EXCEPTION HANDLING

Hi Ivan,
Quote
I made so on Your suggestion (right click in CPU window, ...). When arises
an access violation, TD32 displays a message "Access violation", I click
OK, then press F7, the de{*word*81} goes somewhere in Windows kernel,
[...]
Set a _breakpoint_ somewhere in your handler (and press F9 ;-)
JFYI: There is "borland.public.cpp.turbode{*word*81}" group.
 

Re:Re: EXCEPTION HANDLING

Bob Gonder wrote:
Quote
Ivan Kossey wrote:

>when I press Options/exception in TD32 with loaded program it displays
>"no C, C++ or Pascal exception handler"
This code catches the EH
Created a small program and it works.
TASM32 /MX /ZI /z /m5 /p test1.asm
ilink32 /ap/v/c/C/Gn/Gz/w/s c0x32+test1,,,noeh32+import32+cw32
test1.asm
- - - - - - - -
.386
.model flat
;
dataseg
m1 db 'My Handler',0
;
codeseg
extrn MessageBoxA:near
public _main
_main:
enter 0,0
lea eax,ExH
mov ecx,dword ptr fs:[0]
push ebp ;stack frame pointer
push eax ;my handler code
push ecx ;original handler
mov dword ptr fs:[0],esp ;this (my handler struct)
xor eax,eax
xor ecx,ecx
div ecx ;throw error
pop eax ;original handler struct
mov dword ptr fs:[0],eax
leave
ret
ExH: ;gets called twice for some reason.
push 40040h
lea eax,m1
push eax
push eax
push 0
call MessageBoxA
mov eax,1 ;cancel the op.
ret
ends
end
- - - - - - -
I haven't figured out how to get it to skip the div yet.
Do you have any on-line docs on how it's supposed to behave?
 

{smallsort}

Re:Re: EXCEPTION HANDLING

Ivan Kossey wrote:
Quote
I made so on Your suggestion (right click in CPU window, ...). When arises
an access violation, TD32 displays a message "Access violation", I click OK,
then press F7, the de{*word*81} goes somewhere in Windows kernel, but it enters
after a 10-15 steps in a RaiseException routine, then TD32 displays again
That's about how many instructions there are to the first call in the
NT handler. If you accidentally F8 instead of F7, it will execute your
handler from inside that call. Make sure you Trace into the first
call and not Step (over) it. The other sub-calls can be stepped over.
Eventually you get to a "call ecx" which is handing off to your
handler. You want to Trace that one.
Quote
the same error message. My exception handler which begins with INT 3, was
not reached. So behaves also on second TD32 start when the exception
handling already set (TD32 saves the settings).
See the code in my post just minutes ago.
Compile and run it.
You will see the message box pop up from the handler.
Then the Windows error comes up,
Then the message box again.
 

Re:Re: EXCEPTION HANDLING

Hi Bob,
[...]
Quote
I haven't figured out how to get it to skip the div yet.
In your handler you can specify a new value for EIP which
will be used after handling the exception.
Quote
Do you have any on-line docs on how it's supposed to behave?
www.jorgon.freeserve.co.uk/Except/Except.htm
 

Re:Re: EXCEPTION HANDLING

Vasya Pupkin wrote:
Quote
>I haven't figured out how to get it to skip the div yet.

In your handler you can specify a new value for EIP which
will be used after handling the exception.
I figured there had to be a way, but learning how through TD32 was
frustrating. Only saw one copy of the original eip on the stack,
tried changing it, but didn't seem to help any.
Quote
>Do you have any on-line docs on how it's supposed to behave?

www.jorgon.freeserve.co.uk/Except/Except.htm
*Very Good*
Read 1/3 through it, and it's already explained several things I came
across. Highly recommended.
 

Re:Re: EXCEPTION HANDLING

Hi Bob,
Quote
>In your handler you can specify a new value for EIP which
>will be used after handling the exception.

I figured there had to be a way, but learning how through TD32 was
frustrating. Only saw one copy of the original eip on the stack,
tried changing it, but didn't seem to help any.
You can change any register in CONTEXT structure pointed by the
3rd argument of your handler and return zero. Something like this:
proc ExceptionHandler c ; <-- C, not STDCALL
arg @@lpExceptionRecord:dword,@@lpEstablisherFrame:dword,\
@@lpContextRecord:dword,@@lpDispatcherContext:dword
...
mov eax,[@@lpContextRecord]
mov [(CONTEXT eax).regEsp], ...
mov [(CONTEXT eax).regEbp], ...
mov [(CONTEXT eax).regEip], ...
xor eax,eax ; 0 -->ExceptionContinueExecution
ret
endp
 

Re:Re: EXCEPTION HANDLING

My exception handler begins with INT 3
Thank You for suggestion TD newsgroup. I'll try to write in that NG
I was in vacancy, sorry for "dolgoe molchanie" (how to say in English?)
"Vasya Pupkin" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Hi Ivan,

>I made so on Your suggestion (right click in CPU window, ...). When
arises
>an access violation, TD32 displays a message "Access violation", I click
>OK, then press F7, the de{*word*81} goes somewhere in Windows kernel,
[...]

Set a _breakpoint_ somewhere in your handler (and press F9 ;-)

JFYI: There is "borland.public.cpp.turbode{*word*81}" group.

--
Best regards,
Vasya Pupkin.


 

Re:Re: EXCEPTION HANDLING

Your code seems to be equivalent to my code. However I tryed it - with the
same "result".
"Bob Gonder" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Bob Gonder wrote:

>Ivan Kossey wrote:
>
>>when I press Options/exception in TD32 with loaded program it
displays
>>"no C, C++ or Pascal exception handler"

This code catches the EH

Created a small program and it works.

TASM32 /MX /ZI /z /m5 /p test1.asm

ilink32 /ap/v/c/C/Gn/Gz/w/s c0x32+test1,,,noeh32+import32+cw32

test1.asm
- - - - - - - -
.386
.model flat
;
dataseg
m1 db 'My Handler',0
;
codeseg
extrn MessageBoxA:near

public _main
_main:
enter 0,0

lea eax,ExH
mov ecx,dword ptr fs:[0]
push ebp ;stack frame pointer
push eax ;my handler code
push ecx ;original handler
mov dword ptr fs:[0],esp ;this (my handler struct)

xor eax,eax
xor ecx,ecx
div ecx ;throw error

pop eax ;original handler struct
mov dword ptr fs:[0],eax

leave
ret

ExH: ;gets called twice for some reason.
push 40040h
lea eax,m1
push eax
push eax
push 0
call MessageBoxA

mov eax,1 ;cancel the op.
ret

ends
end
- - - - - - -
I haven't figured out how to get it to skip the div yet.
Do you have any on-line docs on how it's supposed to behave?




 

Re:Re: EXCEPTION HANDLING

now I seen in OS Exception handling window that Range low and Range high was
both set to 0. I set now range low = 0 and range high = 10000000h but it
does not work again. What means this range?
EIP or data address range? what addresses I have to set?
Thank You
Ivan
"Vasya Pupkin" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Hi Ivan,

>I made so on Your suggestion (right click in CPU window, ...). When
arises
>an access violation, TD32 displays a message "Access violation", I click
>OK, then press F7, the de{*word*81} goes somewhere in Windows kernel,
[...]

Set a _breakpoint_ somewhere in your handler (and press F9 ;-)

JFYI: There is "borland.public.cpp.turbode{*word*81}" group.

--
Best regards,
Vasya Pupkin.


 

Re:Re: EXCEPTION HANDLING

Hi Ivan,
Quote
My exception handler begins with INT 3
A bad idea. Your handler executes in ring3 where
INT 3 itself causes EXCEPTION_BREAKPOINT.
Quote
Thank You for suggestion TD newsgroup. I'll try to write in that NG
I was in vacancy, sorry for "dolgoe molchanie" (how to say in English?)
Something like "long silence" ;-)
 

Re:Re: EXCEPTION HANDLING

Hi Ivan,
Quote
now I seen in OS Exception handling window that Range low and Range
high was both set to 0. I set now range low = 0 and range high = 10000000h
but it does not work again. What means this range? EIP or data address
range?
Those are exception codes, not addresses.
Quote
what addresses I have to set?
If you don't use your own exception codes, let both the ranges be zero.
 

Re:Re: EXCEPTION HANDLING

Imagine the method of my Active Server Object which will throw an exception
when _ansicodepage is 'XXX'. The function is part of my Active Server Object
which methods are called from an ASP page. I was asking myself why this
exception does not print out 'Ansicodepage is XXX' in the users browser
whenever the method is called like CBuilderObject.setAnsiCodePage "XXX" from
the ASP page (so _ansicode is 'XXX'). Instead of this error-message i am
getting a standard message in the browser: something like 'an exception
occured: CBuilderObject.setAnsiCodePage'
###
#include "MYOBJECTIMPL.H"
STDMETHODIMP TmyObjectImpl::setAnsiCodePage(BSTR _ansicodepage) {
try {
if (wcscmp(_ansicodepage, L"XXX") == 0) {
throw Exception("Ansicodepage is XXX");
}
ansicodepage = AnsiString(_ansicodepage);
} catch(Exception &e) {
return Error(e.Message.c_str(), IID_ImyObject);
}
return S_OK;
}
###
 

Re:Re: EXCEPTION HANDLING

"Marcel" < XXXX@XXXXX.COM >wrote in message
Quote
I was asking myself why this exception does not print out
'Ansicodepage is XXX' in the users browser whenever
the method is called like CBuilderObject.setAnsiCodePage
"XXX" from the ASP page (so _ansicode is 'XXX').
Because it is not supposed to. That is not how things work.
Does your ASO support the ISupportErrorInfo interface, by chance?
Gambit
 

Re:Re: EXCEPTION HANDLING

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Marcel" < XXXX@XXXXX.COM >wrote in
message
news: XXXX@XXXXX.COM ...

>I was asking myself why this exception does not print out
>'Ansicodepage is XXX' in the users browser whenever
>the method is called like CBuilderObject.setAnsiCodePage
>"XXX" from the ASP page (so _ansicode is 'XXX').

Because it is not supposed to. That is not how things work.

Does your ASO support the ISupportErrorInfo interface, by chance?


Gambit


Hi Gambit,
Sorry i am still a beginner. I don't know the ISupportErrorInfo interface
and really i do not know how to implement it in my ASO.
If it isn't hard to implement can you give me a short explanation of it. I
want to help the users of my ASO with errormessages that make sens so it can
help them to debug theirs ASP scripts.
Marcel