Print string with newlines with lldb

拈花ヽ惹草 提交于 2019-12-10 16:43:02

问题


I'd like to print a string, either const char* or std::string, using lldb so that it is human readable. Most importantly, \n's would be printed as a newline. Does anyone know how to do this? I tried the advice given for gdb in this post, however it doesn't seem to work with lldb.

Edit: I'm aware that you can issue the print myString command to print the string, however it doesn't format newline characters (at least not by default):


回答1:


Most of the time you want to see the literal contents of your strings, so the default lldb behavior for print is correct. However, it would be useful to have a format option to "render" the output in the same way the standard libraries would do a string. That's basically what the gdb "printf" command is. Please file a bug with the lldb.llvm.org bug reporter asking for this.

Just like with gdb, you can get the standard library to render the text for you:

(lldb)  expr (void) printf("Some text\nMore text\nEven more text\n")
Some text
More text
Even more text
(lldb)

I cast it to void in this case because I didn't care about the return value, and it makes it harder to see the text.

As was pointed out in the post you referred to, if your output is not going to a terminal somewhere, that isn't helpful, so some explicit "render the output" option would be a good idea as well. But that should only happen if you attach to, rather than run, your program in the debugger.



来源:https://stackoverflow.com/questions/34278238/print-string-with-newlines-with-lldb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!