0

I am new to the LLDB debugger. I would like to ask if we have some ways to analyze the source code and set breakpoints at a function's returns automatically with its Python API?

Thank you.

2
  • Try lldb.debugger.HandleCommand? Commented Dec 22, 2017 at 20:42
  • Hi Galen, Thank you for your reply. But debugger.HandleCommand is used to execute a command and get its result only. I wonder if we can use LLDB to analyze the source code or other intermediate presentation of the program to determine where are a function's returns and set breakpoints at these locations. Commented Dec 22, 2017 at 23:46

1 Answer 1

1

One way to do this is to use a source expression breakpoint on "return":

(lldb) break set -p return -X <FunctionName>

Depending on whether you use "return" elsewhere in the function you may have to disable some of the individual locations.

If you are on an architecture that uses a link register (e.g. arm or arm64) and you are stopped in the function, you can break on the link register value.

Otherwise, you can get the disassembly for the function (SBFrame::GetFunction() will give you the SBFunction, and SBFunction::GetInstructions will return the instruction list, and you can scan that setting breakpoints on the return instructions (e.g. retq, etc. on x86_64).

lldb doesn't have much semantic understanding of source code, but it would be useful to have a "return from function" breakpoint implemented either by instruction scanning or architecture knowledge (like the lr...) If you feel motivated, file an enhancement request at bugs.llvm.org, and maybe somebody will implement it.

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

Comments

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.