title: Is it possible to do hot code swapping in C?
body: <p>this</p>
  
  <p>en.wikipedia.org/wiki/Hot_swapping#cite_note-1</p>
  
  <p>says that VS can do it with the help of its debugger. Does gdb provide a similar functionality ?</p>
  
  <p>this is the closest i could find, but doesn't seem to be ready to be used:</p>
  
  <p><a href="http://www.aitdspace.gr/xmlui/handle/123456789/219" rel="nofollow">http://www.aitdspace.gr/xmlui/handle/123456789/219</a></p>
  
  <p>dlopen/dlsym/dlclose are also close, but will not work for -lmylib referenced libraries (reference count never gets to 0).</p>
  
  <p>alternatives i've considered:</p>
  
  <p>1) using -Wl,-wrap,foo and on __wrap_foo() { func = dlopen(); func(); }</p>
  
  <p>2) making libfoo.so a shared library and when we need to hotswap we dlopen(RTLD_GLOBAL) to load the new code and provide updated symbols to the next call to foo();</p>
  
  <p>1) doesn't work very well because it requires me to enumerate all the functions i want to hotswap, which are all of them.</p>
  
  <p>2) doesn't work very well because when foo() is called, the new code is loaded, but foo has forever the reference to that symbol. calling dlopen multiple times make foo to be re evaluated.</p>