-1

Is it possible to read own symbol name by it's address using some API, when we assume that the whole program (and all related .so-files) has been deleted ?

I found some pieces how to get this information using objdump, readelf, nm etc., but are not an option.

What I'd like to have is a function string get_symbol_at(uint64_t addr).

Ivan Baidakou
  • 713
  • 9
  • 14
  • It's not clear what you are trying to do, or in what circumstance. You might not be aware, but a program is not truly deleted while it is still in use - the directory entry may be gone, but /proc/self/exe still points to the actual file contents, which will not be deleted until the program exits. Regardless of that, have you determined that dladdr() will not meet your need? If not, you will likely need to provide more details of your goal. – Chris Stratton Dec 25 '19 at 17:51
  • `dladdr()` resolves *dynamic* symbols. It is mentioned, that I still need to resolve *static* symbols, i.e. those, which are missing in the .so; for example C++ inlined function (compiled with -O2 -g). Another example is `static void my_fn()` inside `.cpp` which is not dynamic symbol. What I need to to is to lazily print full available stack trace, like `bt` command in `gdb`. OK, the `/proc/self/exe` is not deleted, but how about loaded `.so` files? How can I get them on the running program, if they where deleted? – Ivan Baidakou Dec 25 '19 at 18:24

1 Answers1

0

The static/debug symbols in ELF-files are encoded in DWARF-format. They can be discovered via analyzing debug information. However, all .debug_* sections seems are simply not loaded by Operating system (see), because they are quite big and useless for the program execution (they become useful only when program is debugged).

So, the answer is: when debug symbols are needed the executable have to be read from disk via own forces.

Ivan Baidakou
  • 713
  • 9
  • 14