Can a running C program access its own symbol table?

前端 未结 3 1486
伪装坚强ぢ
伪装坚强ぢ 2021-02-19 19:06

I have a linux C program that handles request sent to a TCP socket (bound to a particular port). I want to be able to query the internal state of the C program via a request to

3条回答
  •  花落未央
    2021-02-19 19:56

    The general term for this sort of feature is "reflection", and it is not part of C.

    If this is for debugging purposes, and you want to be able to inspect the entire state of a C program remotely, examine any variable, start and stop its execution, and so on, you might consider GDB remote debugging:

    GDB offers a 'remote' mode often used when debugging embedded systems. Remote operation is when GDB runs on one machine and the program being debugged runs on another. GDB can communicate to the remote 'stub' which understands GDB protocol via Serial or TCP/IP. A stub program can be created by linking to the appropriate stub files provided with GDB, which implement the target side of the communication protocol. Alternatively, gdbserver can be used to remotely debug the program without needing to change it in any way.

提交回复
热议问题