Commit 2b7f3289 authored by Med Ismail Bennani's avatar Med Ismail Bennani
Browse files

[lldb/Target] Add Assert StackFrame Recognizer

When a thread stops, this checks depending on the platform if the top frame is
an abort stack frame. If so, it looks for an assert stack frame in the upper
frames and set it as the most relavant frame when found.

To do so, the StackFrameRecognizer class holds a "Most Relevant Frame" and a
"cooked" stop reason description. When the thread is about to stop, it checks
if the current frame is recognized, and if so, it fetches the recognized frame's
attributes and applies them.

rdar://58528686

Differential Revision: https://reviews.llvm.org/D73303



Signed-off-by: default avatarMed Ismail Bennani <medismail.bennani@gmail.com>
parent 3627c91e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -134,7 +134,9 @@ A complete list of currently supported format string variables is listed below:
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``thread.queue``                                  | The queue name of the thread if the target OS supports dispatch queues                                                                                                                                                                                                                      |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``thread.stop-reason``                            | A textual reason each thread stopped                                                                                                                                                                                                                                                        |
| ``thread.stop-reason``                            | A textual reason why the thread stopped. If the thread have a recognized frame, this displays its recognized stop reason. Otherwise, gets the stop info description.                                                                                                                        |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``thread.stop-reason-raw``                        | A textual reason why the thread stopped. Always returns stop info description.                                                                                                                                                                                                              |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``thread.return-value``                           | The return value of the latest step operation (currently only for step-out.)                                                                                                                                                                                                                |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ public:
      ThreadName,
      ThreadQueue,
      ThreadStopReason,
      ThreadStopReasonRaw,
      ThreadReturnValue,
      ThreadCompletedExpression,
      ScriptThread,
+54 −0
Original line number Diff line number Diff line
//===-- AssertFrameRecognizer.cpp -------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_AssertFrameRecognizer_h_
#define liblldb_AssertFrameRecognizer_h_

#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrameRecognizer.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/FileSpec.h"

#include <tuple>

namespace lldb_private {

/// Registers the assert stack frame recognizer.
///
/// \param[in] process
///    The process that is currently asserting. This will give us information on
///    the target and the platform.
void RegisterAssertFrameRecognizer(Process *process);

/// \class AssertRecognizedStackFrame
///
/// Holds the stack frame where the assert is called from.
class AssertRecognizedStackFrame : public RecognizedStackFrame {
public:
  AssertRecognizedStackFrame(lldb::StackFrameSP most_relevant_frame_sp);
  lldb::StackFrameSP GetMostRelevantFrame() override;

private:
  lldb::StackFrameSP m_most_relevant_frame;
};

/// \class AssertFrameRecognizer
///
/// When a thread stops, it checks depending on the platform if the top frame is
/// an abort stack frame. If so, it looks for an assert stack frame in the upper
/// frames and set it as the most relavant frame when found.
class AssertFrameRecognizer : public StackFrameRecognizer {
public:
  std::string GetName() override { return "Assert StackFrame Recognizer"; }
  lldb::RecognizedStackFrameSP
  RecognizeFrame(lldb::StackFrameSP frame_sp) override;
};

} // namespace lldb_private

#endif // liblldb_AssertFrameRecognizer_h_
+5 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
#include "lldb/Core/ValueObject.h"
#include "lldb/Core/ValueObjectList.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Utility/StructuredData.h"
#include "lldb/lldb-private-forward.h"
#include "lldb/lldb-public.h"
@@ -33,10 +34,14 @@ public:
  virtual lldb::ValueObjectSP GetExceptionObject() {
    return lldb::ValueObjectSP();
  }
  virtual lldb::StackFrameSP GetMostRelevantFrame() { return nullptr; };
  virtual ~RecognizedStackFrame(){};

  std::string GetStopDescription() { return m_stop_desc; }

protected:
  lldb::ValueObjectListSP m_arguments;
  std::string m_stop_desc;
};

/// \class StackFrameRecognizer
+6 −0
Original line number Diff line number Diff line
@@ -216,6 +216,12 @@ public:

  virtual void RefreshStateAfterStop() = 0;

  void SelectMostRelevantFrame();

  std::string GetStopDescription();

  std::string GetStopDescriptionRaw();

  void WillStop();

  bool ShouldStop(Event *event_ptr);
Loading