reloading a linked in driver

Vance Shipley vances@REDACTED
Fri Feb 2 22:38:20 CET 2001


While writing a dynamically linked driver it occurred 
to me that it might be possible to reload a new version
of the driver without first stopping it.  This was a 
natural thing to want to do as I had an Erlang shell in
one window and in another window I was making changes 
to the driver code.  To be able to do live code change 
on a driver would be very advantageous in real life.

I found that it worked.  Sort of.  If I make changes
that keep the size consistent it works but if I make a
change which would alter the offsets it crashes.  I 
wonder if someone with a better knowledge of how this
works could comment on the possibilities.

An example:

$ erl
Erlang (BEAM) emulator version 5.0.1.1 [source]

Eshell V5.0.1.1  (abort with ^G)
1> erl_ddll:load_driver("./", foo_drv).
ok
2> Port = open_port({spawn, foo_drv}, []).
#Port<0.8>
3> port_control(Port, 2, <<0>>).
"foo"

Now I make a simple change to the driver code so that
it will return "bar" instead of "foo".  Things work as 
hoped:

4> erl_ddll:load_driver("./", foo_drv).
ok
5> port_control(Port, 2, <<0>>).
"bar"

Now I change the driver so that it returns "foobar"
instead.  This adds three bytes to the code.

6> erl_ddll:load_driver("./", foo_drv).
ok
7> port_control(Port, 2, <<0>>).
Segmentation Fault(coredump)
$ 

It would really be very cool if there was a way to
make this work.  I have been very happy with the ability 
to make frequent code changes on live systems with Erlang.
To be able to extend this benefit to the C language drivers 
would be a boon to us.

	-Vance





More information about the erlang-questions mailing list