OS2 World Community Forum

OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: Andi B. on December 21, 2017, 05:06:36 pm

Title: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Andi B. on December 21, 2017, 05:06:36 pm
Topic says it all. I do not find any information to insert a breakpoint INT 3 in my C source code which should be compiled with VAC3.65. Sounds simple but obviously I fed the wrong words into the search engine.
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Tom on December 21, 2017, 07:57:08 pm
Topic says it all. I do not find any information to insert a breakpoint INT 3 in my C source code which should be compiled with VAC3.65. Sounds simple but obviously I fed the wrong words into the search engine.

Insert byte 0xCC for INT 3 (breakpoint)
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: RickCHodgin on December 21, 2017, 08:13:26 pm
Topic says it all. I do not find any information to insert a breakpoint INT 3 in my C source code which should be compiled with VAC3.65. Sounds simple but obviously I fed the wrong words into the search engine.

It looks like other IBM compilers use __asm__ int 3 and asm("int 3").  I've never tried in Visual Age.  In fact, I had difficulty using Visual Age.  It does things in a way I could not figure out.

I have used Open Watcom for OS/2 development and it has worked smoothly.
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Andreas Kohl on December 21, 2017, 11:06:41 pm
The icc from the mentioned VisualAge C++ products simply doesn't support inline assembly. Only later versions for AIX and other systems offered this functionality for C. https://www.ibm.com/support/knowledgecenter/SSAE4W_9.0.0/com.ibm.xlcpp111.aix.doc/language_ref/asm.html (https://www.ibm.com/support/knowledgecenter/SSAE4W_9.0.0/com.ibm.xlcpp111.aix.doc/language_ref/asm.html)
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Lars on December 21, 2017, 11:15:14 pm
Need a little bit of assembly. Write yourself an assembly function. And while you are at it, make it a library so that you can reuse it.
Use ALP for assembly. It's still good enough for not too advanced assembly code (goes up to XMM, supports all protected system instruction).
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Rich Walsh on December 22, 2017, 12:19:33 am
<RTFM>

#include <builtin.h>
void _interrupt(const unsigned int intnum);

Language Level: Extension

_interrupt calls the interrupt procedure specified by intnum using the INT machine instruction. The integer intnum must have a value within the range 0 to 255 inclusive.

Note: _interrupt is a built-in function, which means it is implemented as an inline instruction and has no backing code in the library. For this reason:

You cannot take the address of _interrupt.
You cannot parenthesize a call to _interrupt. (Parentheses specify a call to the function's backing code, and _interrupt has none.)

Return Value
There is no return value, and _interrupt does not set errno.

</RTFM>
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: RickCHodgin on December 22, 2017, 12:28:17 am
<RT..M>

Do you really talk to people with such disdain, Rich?  Are people of such low value that you can assault them anonymously across the Internet in this rude way?

If you have information to help people then help them.  Don't belittle them.
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Ian Manners on December 22, 2017, 08:32:10 am
Quote
Do you really talk to people with such disdain, Rich?  Are people of such low value that you can assault them anonymously across the Internet in this rude way?

If you have information to help people then help them.  Don't belittle them.

RTFM is part of modern language, it's not going away and is simply a saying. Rich is not assaulting or belittling anyone, unless they wish to change the interpretation of what is said. This is simply a quick method of saying the answer is in the manual, and many of us do not actually read manuals, though we should :)
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Andi B. on December 22, 2017, 10:01:01 am
Thanks to all.

I searched the manuals, toolkit headers and samples back and forth for INT, INT3, INT 3, ... tried a lot of code I found in the net and got the feeling it must be something very simple. That's the reason I asked here. Now I do not understand why I missed the _interrupt section. One culprit was #include <builtin.h> and I concentrated on code examples and the toolkit instead the compiler helpers. Thanks again.
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: RickCHodgin on December 22, 2017, 12:26:18 pm
Quote
Do you really talk to people with such disdain, Rich?  Are people of such low value that you can assault them anonymously across the Internet in this rude way?

If you have information to help people then help them.  Don't belittle them.

RT..M is part of modern language...

Yes, profane things have made their way in to everyday speech, as has rudeness and hate.  Peoole treat each other like dogs firing off one mean thing after another.  It shouldn't be like that, and we can choose to be nice and helpful to one another.  We don't have to go the way of modern hateful society with its general view of disposable people.  We are valuable creations, and we should do our best to help one another, and not in modern society's mocking way.
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Lars on December 23, 2017, 11:57:22 pm
Here is my smart ass answer to "_interrupt":

_interrupt(3) will very likely encode an "int 3" instruction as a 2 Byte opcode (0xCD 0x03).
The "real" int3 however is a 1 Byte opcode (0xCC). These two instructions are close but not the same and might confuse a normal debugger that expects 0xCC opcode for int3 (if you intend to execute the application under Debugger control and intend to stop it on the int3).
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: RickCHodgin on December 24, 2017, 12:28:41 am
Here is my smart ass answer to "_interrupt":

Everything in your reply was helpful except this line.  Couldn't resist, could you?  That is the way of this world, Lars, and it has no future.

Quote
_interrupt(3) will very likely encode an "int 3" instruction as a 2 Byte opcode (0xCD 0x03).
The "real" int3 however is a 1 Byte opcode (0xCC). These two instructions are close but not the same and might confuse a normal debugger that expects 0xCC opcode for int3 (if you intend to execute the application under Debugger control and intend to stop it on the int3).

They could examine builtin.h to see what other functions it has.  Maybe there's an _int3() or _debug_break() function.
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Ian Manners on December 24, 2017, 12:37:30 pm
Rick,

Words have more than one meaning, context matters as does the way the meanings of words changes with time and population generation, so does respecting others and not intruding on/in there/their space or beliefs.

This forum is not here for you to complain about how others talk or differences in culture, it is for all OS/2 and derivative operating system users to talk together, seek information, help, and exchange ideas no matter what religion or culture they are from. Take the words as they are said in context, if you don't like something then simply ignore it. Complaining about others in a fashion that I see as meaningless does no more than generate noise and serves no purpose. It is not helpful to you, to others, nor to whichever deity you may believe in.

We are all different and the measure of a person is how well they take these differences and work with them, not complain about or change others because they are not like you.

Now smile, go do something different and have a happy Christmas when it arrives in your part of the world :)
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Andi B. on December 24, 2017, 02:35:21 pm
_interrupt(3) will very likely encode an "int 3" instruction as a 2 Byte opcode (0xCD 0x03).
Just verified with a test sample and it decodes correctly to 0xCC. This is with VAC3.65 and icc /Ti. Idebug stops and the popup says 'A program-generated breakpoint was encountered'.
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Robert Mauro on December 24, 2017, 10:23:11 pm
Bans may last for eternity too...

...and now back to our regularly scheduled program.
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Lars on December 24, 2017, 10:36:09 pm
_interrupt(3) will very likely encode an "int 3" instruction as a 2 Byte opcode (0xCD 0x03).
Just verified with a test sample and it decodes correctly to 0xCC. This is with VAC3.65 and icc /Ti. Idebug stops and the popup says 'A program-generated breakpoint was encountered'.

OK in that case Everything is fine. Thanks for the Feedback.
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Andi B. on December 26, 2017, 11:58:37 am
And the best thing is ICAT stops as well of course. Now I can remotely single step through xwlan source code widget loading code  :)
Title: Re: VAC3.65 / 3.08 inline assembly? How to insert INT 3?
Post by: Lars on December 26, 2017, 08:28:03 pm
If you have the source code, can't you just compile xwlan with source debugging info (ICAT knows CODEVIEW and HLL where unfortunately it no longer understands the CODEVIEW variant that Watcom produces) and then set breakpoints from ICAT ?
If you set a breakpoint via ICAT, that's exactly what it will do: replace the first byte of an instruction with the 0xCC (int3) instruction.
At least that's what I have done over and over again with the USB driver source code.
Of course, the source code will have to be on your ICAT machine (along with the binary with debug info). The binary with debug info will (also, of course) have to go to the MUT.