Alberto Barbaro via llvm-dev
2019-Jan-26 07:44 UTC
[llvm-dev] How to pass arbitrary arguments to runFunctionAsMain?
Hi, I'm trying to call the function main passing arbitrary parameters. My code is something like: Please note that MyInterpreter extends Interpreter StringRef filename = argv[1]; std::unique_ptr<Module> m(parseIRFile(filename, error, context)); MyInterpreter * v = new MyInterpreter(std::move(m)); v->finalizeObject(); errs() << "Done\n"; Function *main = v->FindFunctionNamed("main"); errs() << " Function " << main->getName().str() << "\n"; std::vector<std::string> parameters; parameters.insert(parameters.begin(), "argv"); const char* const* envp; for (int i=1; i<argc;i++) parameters.push_back(argv[i]); v->runFunctionAsMain(main, parameters, envp); Is it correct or should I construct parameters in another way? Thanks a lot Alberto -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190126/045eaff0/attachment.html>
Tim Northover via llvm-dev
2019-Jan-26 08:21 UTC
[llvm-dev] How to pass arbitrary arguments to runFunctionAsMain?
On Sat, 26 Jan 2019 at 07:44, Alberto Barbaro via llvm-dev <llvm-dev at lists.llvm.org> wrote:> const char* const* envp; > [...] > v->runFunctionAsMain(main, parameters, envp);envp remains uninitialized here, and runFunctionAsMain appears to iterate through it until it reaches a nullptr, so that'll probably crash. I think you want const char* const* envp = {nullptr}; Other than that, it looked sensible to me. Cheers. Tim.
Alberto Barbaro via llvm-dev
2019-Jan-26 08:33 UTC
[llvm-dev] How to pass arbitrary arguments to runFunctionAsMain?
Hi Tim, Thanks for your answer. I'll fix the problem with envp now. I don't know if you have seen my other question but i was doubting of that code because I cannot get the proper value of argv at runtime using my Interpreter. I hope this is the problem. Do you think the same? Thanks again On Sat, Jan 26, 2019, 08:22 Tim Northover <t.p.northover at gmail.com wrote:> On Sat, 26 Jan 2019 at 07:44, Alberto Barbaro via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > const char* const* envp; > > [...] > > v->runFunctionAsMain(main, parameters, envp); > > envp remains uninitialized here, and runFunctionAsMain appears to > iterate through it until it reaches a nullptr, so that'll probably > crash. I think you want > > const char* const* envp = {nullptr}; > > Other than that, it looked sensible to me. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190126/23e4e9de/attachment.html>