LLDB mainline
Classes | Functions
TraceDumper.cpp File Reference
#include "lldb/Target/TraceDumper.h"
#include "lldb/Core/Module.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/SectionLoadList.h"
#include <optional>

Go to the source code of this file.

Classes

class  OutputWriterCLI
 
class  OutputWriterJSON
 

Functions

static std::optional< const char * > ToOptionalString (const char *s)
 
static const char * GetModuleName (const SymbolContext &sc)
 
static const char * GetModuleName (const TraceDumper::TraceItem &item)
 
static bool IsLineEntryValid (const LineEntry &line_entry)
 
static bool FileLineAndColumnMatches (const LineEntry &a, const LineEntry &b)
 
static bool IsSameInstructionSymbolContext (const TraceDumper::SymbolInfo &prev_insn, const TraceDumper::SymbolInfo &insn, bool check_source_line_info=true)
 Compare the symbol contexts of the provided SymbolInfo objects.
 
static std::unique_ptr< TraceDumper::OutputWriterCreateWriter (Stream &s, const TraceDumperOptions &options, Thread &thread)
 
static SymbolContext CalculateSymbolContext (const Address &address, const SymbolContext &prev_symbol_context)
 Find the symbol context for the given address reusing the previous instruction's symbol context when possible.
 
static std::tuple< DisassemblerSP, InstructionSPCalculateDisass (const TraceDumper::SymbolInfo &symbol_info, const TraceDumper::SymbolInfo &prev_symbol_info, const ExecutionContext &exe_ctx)
 Find the disassembler for the given address reusing the previous instruction's disassembler when possible.
 
static TraceDumper::SymbolInfo CalculateSymbolInfo (const ExecutionContext &exe_ctx, lldb::addr_t load_address, const TraceDumper::SymbolInfo &prev_symbol_info)
 
static TraceDumper::FunctionCallAppendReturnedInstructionToFunctionCallForest (TraceDumper::FunctionCall &last_function_call, const TraceDumper::SymbolInfo &symbol_info, const TraceCursorSP &cursor_sp, std::vector< TraceDumper::FunctionCallUP > &roots)
 Given an instruction that happens after a return, find the ancestor function call that owns it.
 
static TraceDumper::FunctionCallAppendInstructionToFunctionCallForest (const ExecutionContext &exe_ctx, TraceDumper::FunctionCall *last_function_call, const TraceDumper::SymbolInfo &prev_symbol_info, const TraceDumper::SymbolInfo &symbol_info, const TraceCursorSP &cursor_sp, std::vector< TraceDumper::FunctionCallUP > &roots)
 Append an instruction to a function call forest.
 
TraceDumper::FunctionCallAppendErrorToFunctionCallForest (TraceDumper::FunctionCall *last_function_call, TraceCursorSP &cursor_sp, std::vector< TraceDumper::FunctionCallUP > &roots)
 Append an error to a function call forest.
 
static std::vector< TraceDumper::FunctionCallUPCreateFunctionCallForest (TraceCursorSP &cursor_sp, const ExecutionContext &exe_ctx)
 

Function Documentation

◆ AppendErrorToFunctionCallForest()

TraceDumper::FunctionCall & AppendErrorToFunctionCallForest ( TraceDumper::FunctionCall last_function_call,
TraceCursorSP cursor_sp,
std::vector< TraceDumper::FunctionCallUP > &  roots 
)

Append an error to a function call forest.

The new error might be appended to the current segment if it contains errors or will create a new root.

Parameters
[in]last_function_callThe chronologically most recent function call before the new error.
[in]cursor_spThe cursor pointing to the new error.
[in,out]rootsThe object owning the roots. It might be modified if a new root needs to be created.
Returns
A reference to the function call that owns the new error.

Definition at line 859 of file TraceDumper.cpp.

References lldb_private::TraceDumper::FunctionCall::TracedSegment::AppendInsn(), lldb_private::TraceDumper::FunctionCall::GetLastTracedSegment(), and lldb_private::TraceDumper::FunctionCall::IsError().

Referenced by CreateFunctionCallForest().

◆ AppendInstructionToFunctionCallForest()

static TraceDumper::FunctionCall & AppendInstructionToFunctionCallForest ( const ExecutionContext exe_ctx,
TraceDumper::FunctionCall last_function_call,
const TraceDumper::SymbolInfo prev_symbol_info,
const TraceDumper::SymbolInfo symbol_info,
const TraceCursorSP cursor_sp,
std::vector< TraceDumper::FunctionCallUP > &  roots 
)
static

Append an instruction to a function call forest.

The new instruction might be appended to the current segment, to a new nest call, or return to an ancestor call.

Parameters
[in]exe_ctxThe exeuction context of the traced thread.
[in]last_function_callThe chronologically most recent function call before the new instruction.
[in]prev_symbol_infoThe symbol information of the previous instruction in the trace.
[in]symbol_infoThe symbol information of the new instruction.
[in]cursor_spThe cursor pointing to the new instruction.
[in,out]rootsThe object owning the roots. It might be modified if a new root needs to be created.
Returns
A reference to the function call that owns the new instruction.

Definition at line 769 of file TraceDumper.cpp.

References lldb_private::TraceDumper::SymbolInfo::address, lldb_private::TraceDumper::FunctionCall::TracedSegment::AppendInsn(), AppendReturnedInstructionToFunctionCallForest(), lldb_private::SymbolContext::block, lldb_private::TraceDumper::FunctionCall::TracedSegment::CreateNestedCall(), lldb::eInstructionControlFlowKindCall, lldb::eInstructionControlFlowKindFarCall, lldb::eInstructionControlFlowKindFarReturn, lldb::eInstructionControlFlowKindOther, lldb::eInstructionControlFlowKindReturn, lldb_private::SymbolContext::GetAddressRange(), lldb_private::AddressRange::GetBaseAddress(), lldb_private::Block::GetContainingInlinedBlock(), lldb_private::TraceDumper::FunctionCall::TracedSegment::GetLastInstructionSymbolInfo(), lldb_private::TraceDumper::FunctionCall::GetLastTracedSegment(), lldb_private::TraceDumper::SymbolInfo::instruction, lldb_private::TraceDumper::FunctionCall::IsError(), IsSameInstructionSymbolContext(), and lldb_private::TraceDumper::SymbolInfo::sc.

Referenced by CreateFunctionCallForest().

◆ AppendReturnedInstructionToFunctionCallForest()

static TraceDumper::FunctionCall & AppendReturnedInstructionToFunctionCallForest ( TraceDumper::FunctionCall last_function_call,
const TraceDumper::SymbolInfo symbol_info,
const TraceCursorSP cursor_sp,
std::vector< TraceDumper::FunctionCallUP > &  roots 
)
static

Given an instruction that happens after a return, find the ancestor function call that owns it.

If this ancestor doesn't exist, create a new ancestor and make it the root of the tree.

Parameters
[in]last_function_callThe function call that performs the return.
[in]symbol_infoThe symbol information of the instruction after the return.
[in]cursor_spThe cursor pointing to the instruction after the return.
[in,out]rootsThe object owning the roots. It might be modified if a new root needs to be created.
Returns
A reference to the function call that owns the new instruction

Definition at line 711 of file TraceDumper.cpp.

References lldb_private::TraceDumper::FunctionCall::AppendSegment(), lldb_private::TraceDumper::FunctionCall::GetParentCall(), lldb_private::TraceDumper::FunctionCall::GetSymbolInfo(), and IsSameInstructionSymbolContext().

Referenced by AppendInstructionToFunctionCallForest().

◆ CalculateDisass()

static std::tuple< DisassemblerSP, InstructionSP > CalculateDisass ( const TraceDumper::SymbolInfo symbol_info,
const TraceDumper::SymbolInfo prev_symbol_info,
const ExecutionContext exe_ctx 
)
static

◆ CalculateSymbolContext()

static SymbolContext CalculateSymbolContext ( const Address address,
const SymbolContext prev_symbol_context 
)
static

Find the symbol context for the given address reusing the previous instruction's symbol context when possible.

Definition at line 473 of file TraceDumper.cpp.

References lldb_private::Address::CalculateSymbolContext(), lldb_private::AddressRange::Contains(), and lldb_private::SymbolContext::GetAddressRange().

Referenced by CalculateSymbolInfo().

◆ CalculateSymbolInfo()

static TraceDumper::SymbolInfo CalculateSymbolInfo ( const ExecutionContext exe_ctx,
lldb::addr_t  load_address,
const TraceDumper::SymbolInfo prev_symbol_info 
)
static

◆ CreateFunctionCallForest()

static std::vector< TraceDumper::FunctionCallUP > CreateFunctionCallForest ( TraceCursorSP cursor_sp,
const ExecutionContext exe_ctx 
)
static

◆ CreateWriter()

static std::unique_ptr< TraceDumper::OutputWriter > CreateWriter ( Stream s,
const TraceDumperOptions options,
Thread thread 
)
static

Definition at line 432 of file TraceDumper.cpp.

References lldb_private::TraceDumperOptions::json.

◆ FileLineAndColumnMatches()

static bool FileLineAndColumnMatches ( const LineEntry a,
const LineEntry b 
)
static
Returns
true if the provided line entries match line, column and source file. This function assumes that the line entries are valid.

Definition at line 55 of file TraceDumper.cpp.

References lldb_private::LineEntry::column, lldb_private::LineEntry::GetFile(), and lldb_private::LineEntry::line.

Referenced by IsSameInstructionSymbolContext().

◆ GetModuleName() [1/2]

static const char * GetModuleName ( const SymbolContext sc)
static

◆ GetModuleName() [2/2]

static const char * GetModuleName ( const TraceDumper::TraceItem item)
static
Returns
The module name (basename if the module is a file, or the actual name if it's a virtual module), or nullptr if no name nor module was found.

Definition at line 39 of file TraceDumper.cpp.

References GetModuleName(), and lldb_private::TraceDumper::TraceItem::symbol_info.

◆ IsLineEntryValid()

static bool IsLineEntryValid ( const LineEntry line_entry)
static

◆ IsSameInstructionSymbolContext()

static bool IsSameInstructionSymbolContext ( const TraceDumper::SymbolInfo prev_insn,
const TraceDumper::SymbolInfo insn,
bool  check_source_line_info = true 
)
static

Compare the symbol contexts of the provided SymbolInfo objects.

Returns
true if both instructions belong to the same scope level analized in the following order:
  • module
  • symbol
  • function
  • inlined function
  • source line info

Definition at line 75 of file TraceDumper.cpp.

References lldb_private::SymbolContext::block, FileLineAndColumnMatches(), lldb_private::SymbolContext::function, lldb_private::Block::GetContainingInlinedBlock(), IsLineEntryValid(), lldb_private::SymbolContext::line_entry, lldb_private::SymbolContext::module_sp, lldb_private::TraceDumper::SymbolInfo::sc, and lldb_private::SymbolContext::symbol.

Referenced by AppendInstructionToFunctionCallForest(), AppendReturnedInstructionToFunctionCallForest(), and OutputWriterCLI::TraceItem().

◆ ToOptionalString()

static std::optional< const char * > ToOptionalString ( const char *  s)
static
Returns
The given string or std::nullopt if it's empty.

Definition at line 24 of file TraceDumper.cpp.

Referenced by OutputWriterJSON::DumpInstruction().