I need to make a debug shell inside each c exe(linux enviroment), and my solution is as follows:
- Read elf symbols from exe file, build a symbol->address table in memory;
- Run a thread calling readline to accept user input, some thing like a c function call;
- use Lex & yacc to parse the function name and arg list;
- Find address of the function in the symbol table;
- Call the function with args list;
- Every function written can be input as shell command instantly开发者_运维技巧.
I don't think this is a fresh idea, and my question is: Are there any mature codes implemented already? Thanks for your help!
Sure. If you had working with VxWorks, you'll find WindShell is what you're looking for. I had port a similar shell to Linux. You can download the source from: https://sourceforge.net/projects/zprj/
Note: don't use the source in commercial products, since they are ported from WindShell. If you do want a shell in commercial fields, then you shall develop one with LEX/YACC.
精彩评论