{prompt_preamble}

You will be given a list of currently open definitions (e.g. function/struct/union/macro/global constant definitions). You can choose to open more definitions by giving the file path and symbol name, or just by giving the symbol name if you are unsure about the file. You can also close the definitions that you're sure are not relevant for fixing the bug. You will also have the ability to search for arbitrary regex patterns throughout the repository code and throught the past commit messages and patches in the {repoName} repository git history.

You should reason from first principles about the possible root causes of the crash and how it can be fixed. For example, you can take a bottom-up approach, starting with the variable and function involved in the crash directly. Then you should track the dataflow of the variable and the control flow through conditional statements and function calls. You should analyse this flow and open more functions if needed, to narrow down on the root cause of the bug. You should use the `search_code` action to search for useful patterns of code throughout the repository. You should also use the `search_commits` actions to search through previous commit messages and patches for past commits that can be helpful. You can use the `search_definition` action (with just the symbol name or the file path and symbol name) to search for the definition of a relevant symbol, including functions, structs, unions, global constants and macros.

Once you have explored the repository and gathered enough context using the `search_definition`, `search_code` and `search_commits` actions, you should write a justification for why you have gathered all the context necessary to completely understand and repair this bug. If you are satisfied with your justification, you should take the `done` action to end exploration. If not, you should explore the repository code and commit history more. You must not stop until you have enough context to describe, in a specific and detailed manner, all possible root causes of the crash and how to fix it.

You should always review any responses you give, and ensure that you never make inferences or conclusions that don't directly follow from reading the {repoName} repository code and the crash report. You should always place any insights you gain from your analysis into your memory so that they are readily available. Focus on gathering all the relevant context and understanding the bug step-by-step, through careful reasoning steps.

For each step of your analysis, you must provide your response in the following format:

<thoughts>
Write your current analysis of the situation and reasoning about next steps. Be specific about what you've learned and what you need to investigate next. If you believe you have enough information to completely understand all possible root causes of the bug and how to fix it, you should write a justification here. Then you should analyse the justification and see if it holds up. If yes, you should take the `done` action to end exploration. If not, you should continue exploring.
</thoughts>

<actions>
Available actions (write one action per line with no additional formatting):

close_definition(filePath, symbolName, startLine)      Close the defintion of a specificed symbol that is not relevant to the bug (e.g. debug functions like dump_stack)
search_definition(filePath, symbolName)    Search for the definition of a specified symbol, which can be a function name, a struct name, a global constant, a union name or a macro name
search_definition(symbolName)              Search for the definition of a specified symbol (a function name, a struct name, a global constant, a union name or a macro name) when you don't know its file path. Use this to search for the definiton of symbols whose file you don't know.

search_code("regex pattern")               Search through all tracked files in the repository using git grep with regex pattern. Shows 2 context lines before and after each match, limited to 5 matches total.
                                           Examples: "function_name\\(" matches exact function calls
                                                     "struct \\w+_info" matches struct names ending in _info
search_commits("regex pattern")            Search historical commit messages and code changes in the repository using git log --grep and -G with regex pattern. Shows full commit message and complete patch for each matching commit. Limited to 5 matches total.
                                           Example: "handle->size|crypto_fun\\(|ptr->" matches commits that access handle->size, or call crypto_fun, or dereference ptr.

done                                       End exploration because you have gathered enough context to understand the bug and propose a fix. You must only take this action if you are satisfied with the justification you provided in the thoughts section. If unsure, continue exploring. You should also write your justification after this action inside <justification></justification> tags.

For done, write the action name alone on one line, then from the next line, write a specific and detailed justification inside <justification></justification> tags for why you have gathered all relevant context to understand and fix the bug. It should be formatted as follows:

done
<justification>
Specific and detailed reasoning about why the information you have gathered is enough to understand the bug and fix it. Talk about the possible root causes of the bug, how you can fix it, and how you the information is sufficient to reach these conclusions. Write at least 3-4 sentences.
</justification>

</actions>

<memory>
Record any important insights gained during this step that you want to remember for future steps. Each insight should be on a new line starting with a dash (-). These insights will be available in all future steps.
</memory>

You can, and should, combine multiple actions in a single response. Taking multiple independent actions in a single step saves time and money. The done action must be followed by the justification in <justification> tags.

Here are examples of responses in different scenarios:

{prompt_analysis_examples}
