Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lldb/include/lldb/Target/StackFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,28 @@ class StackFrame : public ExecutionContextScope,
/// system implementation details this way.
bool IsHidden();

/// Query whether this frame is a Swift Thunk.
bool IsSwiftThunk();

/// Get this frame language specific data.
///
/// \return
/// The StructuredDataImpl object containing the language specific data. Can
/// be null.
StructuredDataImpl *GetLanguageSpecificData();

/// Get the frame's demangled name.
///
/// /// \return
/// A C-String containing the function demangled name. Can be null.
const char *GetFunctionName();

/// Get the frame's demangled display name.
///
/// /// \return
/// A C-String containing the function demangled display name. Can be null.
const char *GetDisplayFunctionName();

/// Query this frame to find what frame it is in this Thread's
/// StackFrameList.
///
Expand Down
83 changes: 10 additions & 73 deletions lldb/source/API/SBFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@

#include "llvm/Support/PrettyStackTrace.h"

// BEGIN SWIFT
#include "lldb/Target/LanguageRuntime.h"
#ifdef LLDB_ENABLE_SWIFT
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
#endif
// END SWIFT

using namespace lldb;
using namespace lldb_private;

Expand Down Expand Up @@ -1182,12 +1175,8 @@ bool SBFrame::IsInlined() const {
Process::StopLocker stop_locker;
if (stop_locker.TryLock(&process->GetRunLock())) {
frame = exe_ctx.GetFramePtr();
if (frame) {

Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
if (block)
return block->GetContainingInlinedBlock() != nullptr;
}
if (frame)
return frame->IsInlined();
}
}
return false;
Expand Down Expand Up @@ -1253,13 +1242,10 @@ lldb::LanguageType SBFrame::GuessLanguage() const {
lldb::SBStructuredData SBFrame::GetLanguageSpecificData() const {
std::unique_lock<std::recursive_mutex> lock;
ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
auto *process = exe_ctx.GetProcessPtr();
auto *frame = exe_ctx.GetFramePtr();
if (process && frame)
if (auto *runtime = process->GetLanguageRuntime(
frame->GuessLanguage().AsLanguageType()))
if (auto *data = runtime->GetLanguageSpecificData(*frame))
return SBStructuredData(*data);
if (frame)
if (StructuredDataImpl *data = frame->GetLanguageSpecificData())
return SBStructuredData(*data);

return {};
}
Expand All @@ -1280,14 +1266,7 @@ bool SBFrame::IsSwiftThunk() const {
frame = exe_ctx.GetFramePtr();
if (!frame)
return false;
SymbolContext sc;
sc = frame->GetSymbolContext(eSymbolContextSymbol);
if (!sc.symbol)
return false;
auto *runtime = process->GetLanguageRuntime(eLanguageTypeSwift);
if (!runtime)
return false;
return runtime->IsSymbolARuntimeThunk(*sc.symbol);
return frame->IsSwiftThunk();
}
// END SWIFT

Expand All @@ -1305,29 +1284,8 @@ const char *SBFrame::GetFunctionName() const {
Process::StopLocker stop_locker;
if (stop_locker.TryLock(&process->GetRunLock())) {
frame = exe_ctx.GetFramePtr();
if (frame) {
SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
eSymbolContextBlock |
eSymbolContextSymbol));
if (sc.block) {
Block *inlined_block = sc.block->GetContainingInlinedBlock();
if (inlined_block) {
const InlineFunctionInfo *inlined_info =
inlined_block->GetInlinedFunctionInfo();
name = inlined_info->GetName().AsCString();
}
}

if (name == nullptr) {
if (sc.function)
name = sc.function->GetName().GetCString();
}

if (name == nullptr) {
if (sc.symbol)
name = sc.symbol->GetName().GetCString();
}
}
if (frame)
return frame->GetFunctionName();
}
}
return name;
Expand All @@ -1348,29 +1306,8 @@ const char *SBFrame::GetDisplayFunctionName() {
Process::StopLocker stop_locker;
if (stop_locker.TryLock(&process->GetRunLock())) {
frame = exe_ctx.GetFramePtr();
if (frame) {
SymbolContext sc(frame->GetSymbolContext(eSymbolContextFunction |
eSymbolContextBlock |
eSymbolContextSymbol));
if (sc.block) {
Block *inlined_block = sc.block->GetContainingInlinedBlock();
if (inlined_block) {
const InlineFunctionInfo *inlined_info =
inlined_block->GetInlinedFunctionInfo();
name = inlined_info->GetDisplayName().AsCString();
}
}

if (name == nullptr) {
if (sc.function)
name = sc.function->GetDisplayName().GetCString();
}

if (name == nullptr) {
if (sc.symbol)
name = sc.symbol->GetDisplayName().GetCString();
}
}
if (frame)
return frame->GetDisplayFunctionName();
}
}
return name;
Expand Down
90 changes: 90 additions & 0 deletions lldb/source/Target/StackFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "lldb/ValueObject/ValueObjectMemory.h"
#include "lldb/ValueObject/ValueObjectVariable.h"

#include "lldb/Target/LanguageRuntime.h"
#ifdef LLDB_ENABLE_SWIFT
#include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
#endif

#include "lldb/lldb-enumerations.h"

#include <memory>
Expand Down Expand Up @@ -1215,6 +1220,91 @@ bool StackFrame::IsHidden() {
return false;
}

bool StackFrame::IsSwiftThunk() {
ThreadSP thread_sp = GetThread();
if (!thread_sp)
return false;
ProcessSP process_sp = thread_sp->GetProcess();
if (!process_sp)
return false;

SymbolContext sc = GetSymbolContext(eSymbolContextSymbol);
if (!sc.symbol)
return false;
auto *runtime = process_sp->GetLanguageRuntime(eLanguageTypeSwift);
if (!runtime)
return false;
return runtime->IsSymbolARuntimeThunk(*sc.symbol);
}

StructuredDataImpl *StackFrame::GetLanguageSpecificData() {
ThreadSP thread_sp = GetThread();
if (!thread_sp)
return {};
ProcessSP process_sp = thread_sp->GetProcess();
if (!process_sp)
return {};

if (auto *runtime =
process_sp->GetLanguageRuntime(GuessLanguage().AsLanguageType()))
if (auto *data = runtime->GetLanguageSpecificData(*this))
return data;
return {};
}

const char *StackFrame::GetFunctionName() {
const char *name = nullptr;
SymbolContext sc = GetSymbolContext(
eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
if (sc.block) {
Block *inlined_block = sc.block->GetContainingInlinedBlock();
if (inlined_block) {
const InlineFunctionInfo *inlined_info =
inlined_block->GetInlinedFunctionInfo();
if (inlined_info)
name = inlined_info->GetName().AsCString();
}
}

if (name == nullptr) {
if (sc.function)
name = sc.function->GetName().GetCString();
}

if (name == nullptr) {
if (sc.symbol)
name = sc.symbol->GetName().GetCString();
}

return name;
}

const char *StackFrame::GetDisplayFunctionName() {
const char *name = nullptr;
SymbolContext sc = GetSymbolContext(
eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
if (sc.block) {
Block *inlined_block = sc.block->GetContainingInlinedBlock();
if (inlined_block) {
const InlineFunctionInfo *inlined_info =
inlined_block->GetInlinedFunctionInfo();
if (inlined_info)
name = inlined_info->GetDisplayName().AsCString();
}
}

if (name == nullptr) {
if (sc.function)
name = sc.function->GetDisplayName().GetCString();
}

if (name == nullptr) {
if (sc.symbol)
name = sc.symbol->GetDisplayName().GetCString();
}
return name;
}

SourceLanguage StackFrame::GetLanguage() {
CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
if (cu)
Expand Down