在运行时更改方法的执行路径 [英] Changing the execution path of methods at runtime

查看:57
本文介绍了在运行时更改方法的执行路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我可以在运行时更改流程中方法的执行路径吗?


例如


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


现在,我想要执行在运行时被改变为 -


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


这可以在不更改实际源文件的情况下完成,可以通过

在运行时添加新模块吗?


谢谢


--pradeep

解决方案

文章< 11 ********************* @ q19g2000prn.googlegroups。 com>,

blufox< 25 ********** @ gmail.comwrote:


>我可以在运行时更改进程中方法的执行路径?



不在C中,因为C没有方法。


> eg


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


>现在,我希望执行在运行时被更改为 -


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

< blockquote class =post_quotes>
>这可以在不更改实际源文件的情况下完成,可以通过在运行时添加新模块吗?



C也没有模块。此外,C不提供在运行时激活新代码的任何

方法。


某些操作系统提供可动态加载的机制

个对象。在Windows世界中,这些通常在Unix世界中被称为''dll'';

,这些通常被称为''dso''但是

Unix操作系统电话通常以dlopen()开头。

-

好​​吧,只有流行语。两个音节,上衣。 - Laurie Anderson


5月29日晚上7:43,rober ... @ ibd.nrc-cnrc.gc.ca(Walter Roberson)

写道:


文章< 1180449520.473891.53 ... @ q19g2000prn.googlegroups。 com>,


blufox< 2500.prad ... @ gmail.comwrote:


我可以更改执行运行时我的进程中的方法路径?



不在C中,因为C没有方法。



对。道歉我的意思是Linux中的内核函数,通常称为b
方法。


>


eg

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

现在,我希望执行在运行时被更改为 -

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

这可以在不更改实际源文件的情况下完成,可以通过

在运行时添加新模块?



C也没有模块。此外,C不提供在运行时激活新代码的任何

方法。


某些操作系统提供可动态加载的机制

个对象。在Windows世界中,这些通常在Unix世界中被称为''dll'';

,这些通常被称为''dso''但是

Unix操作系统调用通常以dlopen()开头。



对,我的意思是Linux内核模块。

基本上它是C(带有GCC主义的负载)我想。 />

那么,是否可以在unix / linux中使用模块。我必须问一下吗?


感谢您的回复

--pradeep


-

好​​吧,只有流行语。两个音节,上衣。 - Laurie Anderson



blufox写道:


大家好,


我可以在运行时更改进程中方法的执行路径吗?


例如


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

现在,我希望在运行时更改执行 -


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


这可以在不更改实际源文件的情况下完成,可以通过

在运行时添加新模块吗?


谢谢


--pradeep






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


表示(在C中):


调用函数a(),它返回一个指向

结构的指针,该结构有一个名为b的字段。这个字段是一个函数

指针。打电话给那个,这将返回一些结构与

字段c。该字段是一个函数指针...





注意a()的返回类型在编译时已知

时间。然后编译器计算出b指示的指示符是什么偏移量,并生成代码以在该指示符处访问该指针。

偏移量。你不能改变它。您只能在()返回的结构中更改字段b中的值




如果a返回相同的结构但使用指向

" myfun"的函数指针,生成的代码将工作相同,但你将结束调用另一个函数,而不是你正在调用的函数。 br />

这需要在编译时修改为()或b()等等。


不知何故,这些函数需要弄清楚什么时候他们应该在字段b中放置某些函数指针。是不是。


但这一切看起来都太复杂了。


你想做什么?


首先解释一下。


jacob


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

解决方案

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


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



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


这篇关于在运行时更改方法的执行路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆