Path: blob/main/contrib/llvm-project/lldb/source/Target/StackID.cpp
39587 views
//===-- StackID.cpp -------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Target/StackID.h"9#include "lldb/Symbol/Block.h"10#include "lldb/Symbol/Symbol.h"11#include "lldb/Symbol/SymbolContext.h"12#include "lldb/Utility/Stream.h"1314using namespace lldb_private;1516void StackID::Dump(Stream *s) {17s->Printf("StackID (pc = 0x%16.16" PRIx64 ", cfa = 0x%16.16" PRIx6418", symbol_scope = %p",19m_pc, m_cfa, static_cast<void *>(m_symbol_scope));20if (m_symbol_scope) {21SymbolContext sc;2223m_symbol_scope->CalculateSymbolContext(&sc);24if (sc.block)25s->Printf(" (Block {0x%8.8" PRIx64 "})", sc.block->GetID());26else if (sc.symbol)27s->Printf(" (Symbol{0x%8.8x})", sc.symbol->GetID());28}29s->PutCString(") ");30}3132bool lldb_private::operator==(const StackID &lhs, const StackID &rhs) {33if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress())34return false;3536SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();37SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();3839// Only compare the PC values if both symbol context scopes are nullptr40if (lhs_scope == nullptr && rhs_scope == nullptr)41return lhs.GetPC() == rhs.GetPC();4243return lhs_scope == rhs_scope;44}4546bool lldb_private::operator!=(const StackID &lhs, const StackID &rhs) {47if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress())48return true;4950SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();51SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();5253if (lhs_scope == nullptr && rhs_scope == nullptr)54return lhs.GetPC() != rhs.GetPC();5556return lhs_scope != rhs_scope;57}5859bool lldb_private::operator<(const StackID &lhs, const StackID &rhs) {60const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddress();61const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddress();6263// FIXME: We are assuming that the stacks grow downward in memory. That's not64// necessary, but true on65// all the machines we care about at present. If this changes, we'll have to66// deal with that. The ABI is the agent who knows this ordering, but the67// StackID has no access to the ABI. The most straightforward way to handle68// this is to add a "m_grows_downward" bool to the StackID, and set it in the69// constructor. But I'm not going to waste a bool per StackID on this till we70// need it.7172if (lhs_cfa != rhs_cfa)73return lhs_cfa < rhs_cfa;7475SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();76SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();7778if (lhs_scope != nullptr && rhs_scope != nullptr) {79// Same exact scope, lhs is not less than (younger than rhs)80if (lhs_scope == rhs_scope)81return false;8283SymbolContext lhs_sc;84SymbolContext rhs_sc;85lhs_scope->CalculateSymbolContext(&lhs_sc);86rhs_scope->CalculateSymbolContext(&rhs_sc);8788// Items with the same function can only be compared89if (lhs_sc.function == rhs_sc.function && lhs_sc.function != nullptr &&90lhs_sc.block != nullptr && rhs_sc.function != nullptr &&91rhs_sc.block != nullptr) {92return rhs_sc.block->Contains(lhs_sc.block);93}94}95return false;96}979899