473,472 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Single step execution using a callback between two asm commands

Hi,

can anyone help me on how to develop a program in c++ which does single step
execution using a callback between the asm commands? I need something like
debuggers do - a callback function should be called after each command.

I think the resulting code could be fairly small and look somehow like this:

static int numCommands = 0; // Var which stores the number of commands

void callback()
{
numCommands++; // Increase the command count
}

int main()
{
enable_single_step_execution(callback); // Enable single step feature and
set callback
for (int i = 0; i < 100; i++); // callback() should be now called after
each asm command
disable_single_step_execution(); // Disable feature
cout << "The loop consisted of " << numCommands << " asm commands!" <<
endl;
}

Thanks and regards,
- Jo
Sep 29 '06 #1
5 2260
Johannes Röckert wrote:
Hi,

can anyone help me on how to develop a program in c++ which does singlestep
execution using a callback between the asm commands? I need something like
debuggers do - a callback function should be called after each command.

I think the resulting code could be fairly small and look somehow like this:

static int numCommands = 0; // Var which stores the number of commands

void callback()
{
numCommands++; // Increase the command count
}

int main()
{
enable_single_step_execution(callback); // Enable single step feature and
set callback
for (int i = 0; i < 100; i++); // callback() should be now called after
each asm command
disable_single_step_execution(); // Disable feature
cout << "The loop consisted of " << numCommands << " asm commands!" <<
endl;
}
This cannot be done in a portable manner, so you'll
need a platform-specific solution. Unfortunately you
forgot to tell what platform and operating system
you are interested in.

I'd say such thing would be rather difficult to accomplish,
why not use a profiler instead? Some platforms, like most
of the newel Intels have hardware instruction counters,
maybe these will provide the functionality you're after?

HTH,
- J.
Sep 29 '06 #2
Hi,

thank you for answering.

I am looking for a portable solution concerning the OS but for now, windows
and/or linux (preferred linux) would be sufficient. And I'm using Intel
CPUs.

Could you post a link to such a profiler library?

As far as i found out, telling the cpu to automatically trigger a software
interrupt is possible. I think it is possible to catch this interrupt but
the only question is how to tell the cpu to do so. Perhaps, i should check a
debuggers source code :-/

The instruction pointer would only help me if the software made a break
after each command.......

I would be thankful for further help...

Regards,
- Jo
"Jacek Dziedzic" <jacek@no_spam.tygrys.no_spam.netschrieb im Newsbeitrag
news:82**************************@news.chello.pl.. .
Johannes Röckert wrote:
Hi,

can anyone help me on how to develop a program in c++ which does single
step execution using a callback between the asm commands? I need something
like debuggers do - a callback function should be called after each
command.

I think the resulting code could be fairly small and look somehow like
this:

static int numCommands = 0; // Var which stores the number of commands

void callback()
{
numCommands++; // Increase the command count
}

int main()
{
enable_single_step_execution(callback); // Enable single step feature
and set callback
for (int i = 0; i < 100; i++); // callback() should be now called after
each asm command
disable_single_step_execution(); // Disable feature
cout << "The loop consisted of " << numCommands << " asm commands!" <<
endl;
}
This cannot be done in a portable manner, so you'll
need a platform-specific solution. Unfortunately you
forgot to tell what platform and operating system
you are interested in.

I'd say such thing would be rather difficult to accomplish,
why not use a profiler instead? Some platforms, like most
of the newel Intels have hardware instruction counters,
maybe these will provide the functionality you're after?

HTH,
- J.
Sep 29 '06 #3
Hi
"Johannes Röckert" <ne*******@netzidiot.dewrote in message
news:ef**********@newsserver.rz.tu-ilmenau.de...
Hi,

thank you for answering.

I am looking for a portable solution concerning the OS but for now,
windows and/or linux (preferred linux) would be sufficient. And I'm using
Intel CPUs.

Could you post a link to such a profiler library?

As far as i found out, telling the cpu to automatically trigger a software
interrupt is possible. I think it is possible to catch this interrupt but
Triggering a software interrupt could be done by

In visual C++ I often use it to break on a certain condition:
if( A || B ) __asm int 3;

AFAIK this is also what a debugger inserts into your code when inserting a
breakpoint. Then when the breakpoint is hit it will insert the original
code.
the only question is how to tell the cpu to do so. Perhaps, i should check
a debuggers source code :-/

The instruction pointer would only help me if the software made a break
after each command.......

I would be thankful for further help...

Regards,
- Jo
"Jacek Dziedzic" <jacek@no_spam.tygrys.no_spam.netschrieb im Newsbeitrag
news:82**************************@news.chello.pl.. .
Johannes Röckert wrote:
>Hi,

can anyone help me on how to develop a program in c++ which does single
step execution using a callback between the asm commands? I need
something like debuggers do - a callback function should be called after
each command.

I think the resulting code could be fairly small and look somehow like
this:

static int numCommands = 0; // Var which stores the number of commands

void callback()
{
numCommands++; // Increase the command count
}

int main()
{
enable_single_step_execution(callback); // Enable single step feature
and set callback
for (int i = 0; i < 100; i++); // callback() should be now called
after each asm command
disable_single_step_execution(); // Disable feature
cout << "The loop consisted of " << numCommands << " asm commands!" <<
endl;
}

This cannot be done in a portable manner, so you'll
need a platform-specific solution. Unfortunately you
forgot to tell what platform and operating system
you are interested in.

I'd say such thing would be rather difficult to accomplish,
why not use a profiler instead? Some platforms, like most
of the newel Intels have hardware instruction counters,
maybe these will provide the functionality you're after?

HTH,
- J.
--
Regards, Ron AF Greve

http://moonlit.xs4all.nl
Sep 29 '06 #4
Johannes Röckert wrote:
Hi,

thank you for answering.

I am looking for a portable solution concerning the OS but for now, windows
and/or linux (preferred linux) would be sufficient. And I'm using Intel
CPUs.

Could you post a link to such a profiler library?
This is a profiler program that, at least on Intel Itanium 2,
does count single processor ticks:

http://www.ncsa.uiuc.edu/UserInfo/Re...e/Tools/pfmon/
As far as i found out, telling the cpu to automatically trigger a software
interrupt is possible.
Sure, the single-step mode. But I suppose you'd need to be
in kernel mode to do be able to turn it on (I guess).
I think it is possible to catch this interrupt but
the only question is how to tell the cpu to do so.
If you are concerned with Intel x86, I vaguely remember that
there's a flag in the flags register that does just that.
I even more vaguely recall that it is a little tricky to use,
because you don't want your "debugger" code to be single-stepped
and switching between the two modes is tricky.
Perhaps, i should check a
debuggers source code :-/

The instruction pointer would only help me if the software made a break
after each command.......
What happens if an interrupt or a thread switch occurs while
your loop is being executed? Suddenly there are someone else's
instructions executed... You want them single-stepped or no?
I would be thankful for further help...
Unfortunately I don't have enough knowledge on this.
Also, this is not the right newsgroup to ask, because we
only deal with standard C++ here. You have a system-specific
problem and your coding it in C++ is only secondary.
I don't know a proper newsgroup, however.

HTH,
- J.
Sep 30 '06 #5
Hi,

thanks for help.

I've found another solution: Using Java and the JVM Tool Interface which
allows single step execution of java (byte) code. It's been a hard work to
get it running but now, my Java Code calls a C++-Callback-Function which was
linked into a shared object. It is nearly exactly what I wanted. The only
difference is that i wanted to count ASM commands instead of Java Byte Code
commands.

I got off a C++ solution because as if you said, there is no platform and
hardware independend solution.
int 3 does not help me because I don't know the offset where to post this
interrupt command...

Best regards,
Jo
Sep 30 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ranju. V | last post by:
Hi, I use a lot asynchronous XMLHTTP from JavaScript. Are the callbacks that we register with XMLHTTP guaranteed to execute single-threaded? For instance, consider the following code snippet. ...
10
by: Sorawit Sharp | last post by:
My app executes C# user scripts via dynamic code execution. Is it possible to execute the scripts single step wise like a debugger ?
3
by: R Millman | last post by:
under ASP.NET, single stepping in debug mode appears not to stop within event procedures. i.e. 1) Create web page with submit button and event procedure for the click event in the code behind...
3
by: Solution Seeker | last post by:
I want to Store the String value with Single Quotes in the Field of Database where if i try to Store the String value with Single Quotes (as it is) then it is throwing the error as SQL String...
4
by: Lunchtimemama | last post by:
I have a UI with a gallery of thumbnail image previews. The PictureBoxes are created and their Images are generated by a method which quickly retrieves the icon for the filetype. Worker threads...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
1
by: Jon Todd | last post by:
Happy holidays all! I'm developing an application and, as a relative newbie to Python, have come across a stumbling block with Tkinter. I'd like to have a button that when pressed executes a...
3
by: Matthew Wells | last post by:
Hello, I am using a client callback routine that seems to mostly work, except that program flow doesn't seem to continue from the point the function is called after the Receive function...
7
by: gregory.lielens | last post by:
Hi, I am using a small python file as an input file (defining constants, parameters, input data, ...) for a python application. The input file is simply read by an exec statement in a specific...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.