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

Changing the execution path of methods at runtime

P: n/a
Hi All,

Can i change the execution path of methods in my process at runtime?

e.g

a()->b()->c()->d()->e()

Now, i want execution to be altered at runtime as -

a()->b()->myfun1()->myfun2()->myfun3()... ->e()

Can this be done without changing the actual source file, may be by
adding a new module at runtime?

Thanks

--pradeep

May 29 '07 #1
Share this Question
Share on Google+
17 Replies


P: n/a
In article <11*********************@q19g2000prn.googlegroups. com>,
blufox <25**********@gmail.comwrote:
>Can i change the execution path of methods in my process at runtime?
Not in C, because C does not have methods.

>e.g
>a()->b()->c()->d()->e()
>Now, i want execution to be altered at runtime as -
>a()->b()->myfun1()->myfun2()->myfun3()... ->e()
>Can this be done without changing the actual source file, may be by
adding a new module at runtime?
C does not have modules either. Furthermore, C does not offer any
method of activating new code at runtime.

Some operating systems provide mechanisms for dynamically loadable
objects. In the Windows world, these are usually called 'dll';
in the Unix world, these are usually called 'dso' but the
Unix operating system calls usually begin with dlopen() .
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson
May 29 '07 #2

P: n/a
On May 29, 7:43 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
In article <1180449520.473891.53...@q19g2000prn.googlegroups. com>,

blufox <2500.prad...@gmail.comwrote:
Can i change the execution path of methods in my process at runtime?

Not in C, because C does not have methods.
Right. Apologies i meant kernel functions in linux which are usually
called methods.
>
e.g
a()->b()->c()->d()->e()
Now, i want execution to be altered at runtime as -
a()->b()->myfun1()->myfun2()->myfun3()... ->e()
Can this be done without changing the actual source file, may be by
adding a new module at runtime?

C does not have modules either. Furthermore, C does not offer any
method of activating new code at runtime.

Some operating systems provide mechanisms for dynamically loadable
objects. In the Windows world, these are usually called 'dll';
in the Unix world, these are usually called 'dso' but the
Unix operating system calls usually begin with dlopen() .
Right, and i mean a Linux kernel module here.
Essentially it is C(with loads of GCCism) i guess.

So, is it possible using modules in unix/linux then. i must ask?

Thanks for the reply
--pradeep
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson

May 29 '07 #3

P: n/a
blufox wrote:
Hi All,

Can i change the execution path of methods in my process at runtime?

e.g

a()->b()->c()->d()->e()

Now, i want execution to be altered at runtime as -

a()->b()->myfun1()->myfun2()->myfun3()... ->e()

Can this be done without changing the actual source file, may be by
adding a new module at runtime?

Thanks

--pradeep
Hi

a()->b()->c()->d()->e()

means (in C):

call function a(), that returns some pointer to a
structure that has a field called "b". This field is a function
pointer. Call that, and that will return some structure with
a field "c". That field is a function pointer...

etc

Note that the type of the return of a() is known at compile
time. The compiler has then calculated at which offset the "b"
pointer is, and generates code to access that pointer at that
offset. You can't change that. You can only change the value
in the field "b", in the structure returned by a().

If a returns the same structure but with a function pointer to
"myfun", the generated code will work the same, but you will
end calling another function, not the one that you were calling

This requires a modification at compile time to a() or to b(), etc.

Somehow those functions will need to figure out when they should put
a certain function pointer in field "b" or not.

But all this looks far too complicated.

WHAT are you trying to do?

Explain that first.

jacob
May 29 '07 #4

P: n/a
On May 29, 8:01 pm, jacob navia <j...@jacob.remcomp.frwrote:
blufox wrote:
Hi All,
Can i change the execution path of methods in my process at runtime?
e.g
a()->b()->c()->d()->e()
Now, i want execution to be altered at runtime as -
a()->b()->myfun1()->myfun2()->myfun3()... ->e()
Can this be done without changing the actual source file, may be by
adding a new module at runtime?
Thanks
--pradeep

Hi

a()->b()->c()->d()->e()

means (in C):

call function a(), that returns some pointer to a
structure that has a field called "b". This field is a function
pointer. Call that, and that will return some structure with
a field "c". That field is a function pointer...

etc

Note that the type of the return of a() is known at compile
time. The compiler has then calculated at which offset the "b"
pointer is, and generates code to access that pointer at that
offset. You can't change that. You can only change the value
in the field "b", in the structure returned by a().

If a returns the same structure but with a function pointer to
"myfun", the generated code will work the same, but you will
end calling another function, not the one that you were calling

This requires a modification at compile time to a() or to b(), etc.

Somehow those functions will need to figure out when they should put
a certain function pointer in field "b" or not.

But all this looks far too complicated.

WHAT are you trying to do?

Explain that first.
Oops i messed it up i must admit. :-(
No it is not pointer dereferencing literally here.
Just to illustrate the flow of program here, i used arrows "->" .

What I intend to do?

I want to invoke my function without changing the actual source code
at runtime.

Is this somehow possible on a Linux system?

Thanks

--pradeep
>
jacob

May 29 '07 #5

P: n/a
On May 29, 4:07 pm, blufox <2500.prad...@gmail.comwrote:
On May 29, 8:01 pm, jacob navia <j...@jacob.remcomp.frwrote:
blufox wrote:
Hi All,
Can i change the execution path of methods in my process at runtime?
e.g
a()->b()->c()->d()->e()
Now, i want execution to be altered at runtime as -
a()->b()->myfun1()->myfun2()->myfun3()... ->e()
Can this be done without changing the actual source file, may be by
adding a new module at runtime?
Thanks
--pradeep
Hi
a()->b()->c()->d()->e()
means (in C):
call function a(), that returns some pointer to a
structure that has a field called "b". This field is a function
pointer. Call that, and that will return some structure with
a field "c". That field is a function pointer...
etc
Note that the type of the return of a() is known at compile
time. The compiler has then calculated at which offset the "b"
pointer is, and generates code to access that pointer at that
offset. You can't change that. You can only change the value
in the field "b", in the structure returned by a().
If a returns the same structure but with a function pointer to
"myfun", the generated code will work the same, but you will
end calling another function, not the one that you were calling
This requires a modification at compile time to a() or to b(), etc.
Somehow those functions will need to figure out when they should put
a certain function pointer in field "b" or not.
But all this looks far too complicated.
WHAT are you trying to do?
Explain that first.

Oops i messed it up i must admit. :-(
No it is not pointer dereferencing literally here.
Just to illustrate the flow of program here, i used arrows "->" .

What I intend to do?

I want to invoke my function without changing the actual source code
at runtime.

Is this somehow possible on a Linux system?

Thanks

--pradeep
jacob
It's just about possible using portable C, but only if you design the
source file to make it possible. For instance:

/* whichfunc.c */
extern void c(void);
extern void myfun1(void);
void (*func)()=c; /* =myfun1; */

/* prog.c */
extern void (*func)();

void a(void)
{
b();
}

void b(void)
{
(*func)(); /* the key line */
}

/* ... whatever ... */

Then you can link both files together using whatever implementation-
specific method your implementation provides (if you're on Linux,
you're quite possibly using gcc, in which case you specify both files
on the command line or probably use a makefile if it's a complex
project). Changing func will change the path of execution b takes.

Of course, modifying the source code is nearly always going to be
easier (the only advantage of doing it like this is that you can
change the flow pattern at runtime if you want to, by assigning to
func).

In the general case, in which you haven't deliberately written the
source code in this unusual form, you can't substitute a call to one
function with another using what's available in standard C89/C99.
--
ais523

May 29 '07 #6

P: n/a
blufox <25**********@gmail.comwrites:
On May 29, 7:43 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
>In article <1180449520.473891.53...@q19g2000prn.googlegroups. com>,

blufox <2500.prad...@gmail.comwrote:
>Can i change the execution path of methods in my process at runtime?

Not in C, because C does not have methods.
Right. Apologies i meant kernel functions in linux which are usually
called methods.
They are? That's news to me.

In any case, you should ask on a Linux-specific newsgroup.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 29 '07 #7

P: n/a
On May 30, 3:00 am, Keith Thompson <k...@mib.orgwrote:
blufox <2500.prad...@gmail.comwrites:
On May 29, 7:43 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
In article <1180449520.473891.53...@q19g2000prn.googlegroups. com>,
blufox <2500.prad...@gmail.comwrote:
Can i change the execution path of methods in my process at runtime?
Not in C, because C does not have methods.
Right. Apologies i meant kernel functions in linux which are usually
called methods.

They are? That's news to me.
Yes they are called methods in the kernel AFAIK.
May be i am misunderstanding it.
>
In any case, you should ask on a Linux-specific newsgroup.
Tried that, didn't get satisfying answers so resorted to clc.
I 'll give another try though.

Thank you
--psr
>
--
Keith Thompson (The_Other_Keith) k...@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

May 30 '07 #8

P: n/a
On May 29, 8:30 pm, ais523 <ais...@bham.ac.ukwrote:
On May 29, 4:07 pm, blufox <2500.prad...@gmail.comwrote:
On May 29, 8:01 pm, jacob navia <j...@jacob.remcomp.frwrote:
blufox wrote:
Hi All,
Can i change the execution path of methods in my process at runtime?
e.g
a()->b()->c()->d()->e()
Now, i want execution to be altered at runtime as -
a()->b()->myfun1()->myfun2()->myfun3()... ->e()
Can this be done without changing the actual source file, may be by
adding a new module at runtime?
Thanks
--pradeep
Hi
a()->b()->c()->d()->e()
means (in C):
call function a(), that returns some pointer to a
structure that has a field called "b". This field is a function
pointer. Call that, and that will return some structure with
a field "c". That field is a function pointer...
etc
Note that the type of the return of a() is known at compile
time. The compiler has then calculated at which offset the "b"
pointer is, and generates code to access that pointer at that
offset. You can't change that. You can only change the value
in the field "b", in the structure returned by a().
If a returns the same structure but with a function pointer to
"myfun", the generated code will work the same, but you will
end calling another function, not the one that you were calling
This requires a modification at compile time to a() or to b(), etc.
Somehow those functions will need to figure out when they should put
a certain function pointer in field "b" or not.
But all this looks far too complicated.
WHAT are you trying to do?
Explain that first.
Oops i messed it up i must admit. :-(
No it is not pointer dereferencing literally here.
Just to illustrate the flow of program here, i used arrows "->" .
What I intend to do?
I want to invoke my function without changing the actual source code
at runtime.
Is this somehow possible on a Linux system?
Thanks
--pradeep
jacob

It's just about possible using portable C, but only if you design the
source file to make it possible. For instance:

/* whichfunc.c */
extern void c(void);
extern void myfun1(void);
void (*func)()=c; /* =myfun1; */

/* prog.c */
extern void (*func)();

void a(void)
{
b();

}

void b(void)
{
(*func)(); /* the key line */

}

/* ... whatever ... */

Then you can link both files together using whatever implementation-
specific method your implementation provides (if you're on Linux,
you're quite possibly using gcc, in which case you specify both files
on the command line or probably use a makefile if it's a complex
project). Changing func will change the path of execution b takes.

Of course, modifying the source code is nearly always going to be
easier (the only advantage of doing it like this is that you can
change the flow pattern at runtime if you want to, by assigning to
func).

In the general case, in which you haven't deliberately written the
source code in this unusual form, you can't substitute a call to one
function with another using what's available in standard C89/C99.
This is fruitful.
I ll look into this and see if i can get something concrete from this
hint.

Thanks a ton for the help.

--psr
--
ais523

May 30 '07 #9

P: n/a
blufox wrote:
ais523 <ais...@bham.ac.ukwrote:
.... snip about 100 lines ...
>>
Of course, modifying the source code is nearly always going to be
easier (the only advantage of doing it like this is that you can
change the flow pattern at runtime if you want to, by assigning to
func).

In the general case, in which you haven't deliberately written the
source code in this unusual form, you can't substitute a call to one
function with another using what's available in standard C89/C99.

This is fruitful. I ll look into this and see if i can get something
concrete from this hint.
Please snip irrelevant data from the quoted portion of your
replies. The links below (in my sig) may be helpful.

--
Some useful links on quoting:
<http://www.xs4all.nl/%7ewijnands/nnq/nquote.html>
<http://www.complang.tuwien.ac.at/anton/mail-news-errors.html>
<http://www.netmeister.org/news/learn2quote2.html>
<http://www.star-one.org.uk/computer/format.htm>

--
Posted via a free Usenet account from http://www.teranews.com

May 30 '07 #10

P: n/a
On 29 May 2007 20:42:00 -0700, in comp.lang.c , blufox
<25**********@gmail.comwrote:
>On May 30, 3:00 am, Keith Thompson <k...@mib.orgwrote:
>blufox <2500.prad...@gmail.comwrites:
Right. Apologies i meant kernel functions in linux which are usually
called methods.
>They are? That's news to me.
>Yes they are called methods in the kernel AFAIK.
I've never heard anything called a method in C or C++. Some other
languages such as VB and the ilk have methods.
>May be i am misunderstanding it.
Its possible...

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
May 30 '07 #11

P: n/a
In article <5m********************************@4ax.com>,
Mark McIntyre <ma**********@spamcop.netwrote:
>On 29 May 2007 20:42:00 -0700, in comp.lang.c , blufox
<25**********@gmail.comwrote:
>>On May 30, 3:00 am, Keith Thompson <k...@mib.orgwrote:
>>blufox <2500.prad...@gmail.comwrites:
>Right. Apologies i meant kernel functions in linux which are usually
called methods.
>>They are? That's news to me.
>>Yes they are called methods in the kernel AFAIK.

I've never heard anything called a method in C or C++. Some other
languages such as VB and the ilk have methods.
Of course you have (heard someone refer to C++ as having methods).
That part of your statement (that "I've never heard...") is plain and
simply a lie.

The more substantive question is whether or not C++ has methods. Pretty
clearly, it does (although of course this is all OT here), but I would
imagine that you or one of your buddies will come up with some bit of
sophistry to explain why it doesn't.

Jun 9 '07 #12

P: n/a
Mark McIntyre <ma**********@spamcop.netwrites:
On 29 May 2007 20:42:00 -0700, in comp.lang.c , blufox
<25**********@gmail.comwrote:
>>On May 30, 3:00 am, Keith Thompson <k...@mib.orgwrote:
>>blufox <2500.prad...@gmail.comwrites:
>Right. Apologies i meant kernel functions in linux which are usually
called methods.
>>They are? That's news to me.
>>Yes they are called methods in the kernel AFAIK.

I've never heard anything called a method in C or C++. Some other
languages such as VB and the ilk have methods.
Then you are purposely complicating things for some reason or have not,
in any shape or form, had any worthwhile experience in C++.

The term "method" is widely used to C++. Not necessarily in the Linux
kernel of course since that is C and Assembler.
>
>>May be i am misunderstanding it.

Its possible...
http://www.google.de/search?q=c%2B%2...ient=firefox-a

Or not.
Jun 10 '07 #13

P: n/a
Richard wrote:
Mark McIntyre <ma**********@spamcop.netwrites:
.... snip ...
>>
I've never heard anything called a method in C or C++. Some other
languages such as VB and the ilk have methods.

Then you are purposely complicating things for some reason or have
not, in any shape or form, had any worthwhile experience in C++.

The term "method" is widely used to C++. Not necessarily in the
Linux kernel of course since that is C and Assembler.
You have obviously failed to read the name of this newsgroup. It
is "comp.lang.c". Note the absence of ++. C++ is another
language, and has its own newsgroup, where you may discuss it.
Meanwhile C++ is off-topic here.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 10 '07 #14

P: n/a
CBFalconer wrote:
Richard wrote:
>Mark McIntyre <ma**********@spamcop.netwrites:
... snip ...
>>>
I've never heard anything called a method in C or C++. Some other
languages such as VB and the ilk have methods.

Then you are purposely complicating things for some reason or have
not, in any shape or form, had any worthwhile experience in C++.

The term "method" is widely used to C++. Not necessarily in the
Linux kernel of course since that is C and Assembler.

You have obviously failed to read the name of this newsgroup. It
is "comp.lang.c". Note the absence of ++. C++ is another
language, and has its own newsgroup, where you may discuss it.
Meanwhile C++ is off-topic here.
Then complain to Mark, not to Richard.
Jun 10 '07 #15

P: n/a
On Sun, 10 Jun 2007 17:19:45 +0200, in comp.lang.c , Harald van D?k
<tr*****@gmail.comwrote:
>CBFalconer wrote:
>Richard wrote:
>>Mark McIntyre <ma**********@spamcop.netwrites:
... snip ...
>>>>
I've never heard anything called a method in C or C++. Some other
languages such as VB and the ilk have methods.

Then you are purposely complicating things for some reason or have
not, in any shape or form, had any worthwhile experience in C++.

The term "method" is widely used to C++. Not necessarily in the
Linux kernel of course since that is C and Assembler.

You have obviously failed to read the name of this newsgroup. It
is "comp.lang.c". Note the absence of ++. C++ is another
language, and has its own newsgroup, where you may discuss it.
Meanwhile C++ is off-topic here.

Then complain to Mark, not to Richard.
Why? I didn't post the original question.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 11 '07 #16

P: n/a
Mark McIntyre wrote:
On Sun, 10 Jun 2007 17:19:45 +0200, in comp.lang.c , Harald van D?k
<tr*****@gmail.comwrote:
>>CBFalconer wrote:
>>Richard wrote:
Mark McIntyre <ma**********@spamcop.netwrites:

... snip ...
>
I've never heard anything called a method in C or C++. Some other
languages such as VB and the ilk have methods.

Then you are purposely complicating things for some reason or have
not, in any shape or form, had any worthwhile experience in C++.

The term "method" is widely used to C++. Not necessarily in the
Linux kernel of course since that is C and Assembler.

You have obviously failed to read the name of this newsgroup. It
is "comp.lang.c". Note the absence of ++. C++ is another
language, and has its own newsgroup, where you may discuss it.
Meanwhile C++ is off-topic here.

Then complain to Mark, not to Richard.

Why? I didn't post the original question.
blufox:
>>Yes they are called methods in the kernel AFAIK.
You:
>I've never heard anything called a method in C or C++.
You were the one who gave the first mention of C++.

As far as I'm concerned your comment is fine. But as far as I'm concerned,
Richard's message is fine too.
Jun 12 '07 #17

P: n/a
On Tue, 12 Jun 2007 07:37:31 +0200, in comp.lang.c , Harald van D?k
<tr*****@gmail.comwrote:
>Mark McIntyre wrote:
>On Sun, 10 Jun 2007 17:19:45 +0200, in comp.lang.c , Harald van D?k
<tr*****@gmail.comwrote:
>>>CBFalconer wrote:
Richard wrote:
Mark McIntyre <ma**********@spamcop.netwrites:
>
... snip ...
>>
>I've never heard anything called a method in C or C++. Some other
>languages such as VB and the ilk have methods.
>
Then you are purposely complicating things for some reason or have
not, in any shape or form, had any worthwhile experience in C++.
>
The term "method" is widely used to C++. Not necessarily in the
Linux kernel of course since that is C and Assembler.

You have obviously failed to read the name of this newsgroup. It
is "comp.lang.c". Note the absence of ++. C++ is another
language, and has its own newsgroup, where you may discuss it.
Meanwhile C++ is off-topic here.

Then complain to Mark, not to Richard.

Why? I didn't post the original question.

blufox:
>>>Yes they are called methods in the kernel AFAIK.

You:
>>I've never heard anything called a method in C or C++.

You were the one who gave the first mention of C++.
To forestall the next response which was going to be exactly what we
got.
>As far as I'm concerned your comment is fine.
Good. Then why tell people to complain to me? And I didn't go off and
start lecturing people about whether or not C++ actually had methods.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 12 '07 #18

This discussion thread is closed

Replies have been disabled for this discussion.