1

I'm currently debugging some software using lldb, and its been a weeks long project. I've been adding aliases for commonly used commands, and even tweaked an example python script to help with speeding up my work.

The issue I am having - sometimes I type a command, and then later on I need to reference that (a memory address I need is there, for example). In bash I'd simply do:

history | grep <command>
!<history number>

That obviously does not work in lldb. I'd like to add a script where I add a python command 'history' but nowhere that I look can I find a way to access the lldb command history. Is that possible?

1 Answer 1

2

Are you talking about python commands or lldb commands? lldb does support command history (the command is command history) and !<HISTORY_NUMBER> also works. ^R will start an incremental search back through the history buffer. The lldb command line doesn't have command pipelines (or a grep) so you can't search that way, but you can still get around pretty well this way.

Sign up to request clarification or add additional context in comments.

7 Comments

Wow. I'm not sure how I missed that. Worst case I can use python to run command history, then search it for the command I want. Thanks a ton. I'll mark this an the answer. It's not exactly what I'm going for, but close enough.
Yes, the SBCommandInterpreter::HandleCommand API will return the text of the command in the result object so you can easily get your hands on the output in Python. The result of "command history" should be pretty easy to parse, and for extra credit it would be straightforward to make a Python based lldb command that wrapped this up. It wouldn't be a bad idea to have an SB API to return you the command history of the current interpreter as some kind of list. Feel free to file a request with the lldb.llvm.org bugzilla.
I just finished doing just that. Issued a command hsitory, stored it in a SBCommandReturnObject, split it by line, and looped through doing a .find on it, printing out matching lines. Exactly what I wanted to do. My only disappointment is that command history only shows history of the current session. If I start a new session, I can up-arrow into past commands. Better than before tho, thanks again.
Yes, this is a known issue. Saving command history is currently done by editline (which we use for the front end of the command entry/editing) because it gives you that for free. But it doesn't have a way to query what it has ingested, so lldb doesn't know about this part of the history. We need to figure out how to get this out of editline willy-nilly or switch to having lldb write out the history, then read the file & prime editline with the results. That's a bit tricky and nobody has had time to address this yet since it mostly works.
BTW, it would be useful to have "command history" take a --filter flag to do what you were asking. Please file a bug about that with the lldb.llvm.org bugzilla. You could even hack this up in lldb yourself if you have some free time and are bold!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.