By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

Single step execution using a callback between two asm commands

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.