[Lldb-commits] [lldb] Add a StackFrameRecognizer for the Darwin specific abort_with_payload… (PR #101365)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 31 10:12:55 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 80c0e8d572d3b1c34d66faffc42bcfc9432583ec 5b2cf0ab7e382e41ff3dfe88e4d7e35ddc99afd5 --extensions cpp,h,c -- lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.h lldb/test/API/macosx/abort_with_payload/main.c lldb/include/lldb/Target/Process.h lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp lldb/source/Target/Process.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index ffff84bbd8..e1be76d494 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2569,14 +2569,14 @@ void PruneThreadPlans();
/// A StructuredDataSP object which, if non-empty, will contain the
/// information related to the process.
virtual StructuredData::DictionarySP GetMetadata() { return nullptr; }
-
+
/// Fetch extended crash information held by the process. This will never be
/// an empty shared pointer, it will always have a dict, though it may be
/// empty.
StructuredData::DictionarySP GetExtendedCrashInfoDict() {
- return m_crash_info_dict_sp;
+ return m_crash_info_dict_sp;
}
-
+
void ResetExtendedCrashInfoDict() {
// StructuredData::Dictionary is add only, so we have to make a new one:
m_crash_info_dict_sp.reset(new StructuredData::Dictionary());
@@ -3197,8 +3197,8 @@ protected:
/// Per process source file cache.
SourceManager::SourceFileCache m_source_file_cache;
-
- /// A repository for extra crash information, consulted in
+
+ /// A repository for extra crash information, consulted in
/// GetExtendedCrashInformation.
StructuredData::DictionarySP m_crash_info_dict_sp;
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 398b44c293..3d22e7122d 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -856,15 +856,15 @@ PlatformDarwin::ParseVersionBuildDir(llvm::StringRef dir) {
}
llvm::Expected<StructuredData::DictionarySP>
-PlatformDarwin::
-FetchExtendedCrashInformation(Process &process) {
+PlatformDarwin::FetchExtendedCrashInformation(Process &process) {
static constexpr llvm::StringLiteral crash_info_key("Crash-Info Annotations");
- static constexpr llvm::StringLiteral asi_info_key("Application Specific Information");
+ static constexpr llvm::StringLiteral asi_info_key(
+ "Application Specific Information");
// We cache the information we find in the process extended info dict:
- StructuredData::DictionarySP process_dict_sp
- = process.GetExtendedCrashInfoDict();
- StructuredData::Array *annotations = nullptr;
+ StructuredData::DictionarySP process_dict_sp =
+ process.GetExtendedCrashInfoDict();
+ StructuredData::Array *annotations = nullptr;
StructuredData::ArraySP new_annotations_sp;
if (!process_dict_sp->GetValueForKeyAsArray(crash_info_key, annotations)) {
new_annotations_sp = ExtractCrashInfoAnnotations(process);
@@ -876,15 +876,15 @@ FetchExtendedCrashInformation(Process &process) {
StructuredData::Dictionary *app_specific_info;
StructuredData::DictionarySP new_app_specific_info_sp;
- if (!process_dict_sp->GetValueForKeyAsDictionary(asi_info_key, app_specific_info))
- {
+ if (!process_dict_sp->GetValueForKeyAsDictionary(asi_info_key,
+ app_specific_info)) {
new_app_specific_info_sp = ExtractAppSpecificInfo(process);
if (new_app_specific_info_sp && new_app_specific_info_sp->GetSize()) {
process_dict_sp->AddItem(asi_info_key, new_app_specific_info_sp);
app_specific_info = new_app_specific_info_sp.get();
}
}
-
+
// Now get anything else that was in the process info dict, and add it to the
// return here:
return process_dict_sp->GetSize() ? process_dict_sp : nullptr;
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp
index 7f2aecd148..5434601f54 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.cpp
@@ -1,4 +1,4 @@
- //===-- AbortWithPayloadFrameRecognizer.cpp -------------------------------===//
+//===-- AbortWithPayloadFrameRecognizer.cpp -------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -26,26 +26,25 @@ using namespace lldb_private;
namespace lldb_private {
void RegisterAbortWithPayloadFrameRecognizer(Process *process) {
- // There are two user-level API's that this recognizer captures,
+ // There are two user-level API's that this recognizer captures,
// abort_with_reason and abort_with_payload. But they both call the private
// __abort_with_payload, the abort_with_reason call fills in a null payload.
static ConstString module_name("libsystem_kernel.dylib");
static ConstString sym_name("__abort_with_payload");
-
+
if (!process)
return;
- ConstString sym_arr[1]= {sym_name};
-
+ ConstString sym_arr[1] = {sym_name};
+
process->GetTarget().GetFrameRecognizerManager().AddRecognizer(
- std::make_shared<AbortWithPayloadFrameRecognizer>(),
- module_name, sym_arr,
- /*first_instruction_only*/ false);
+ std::make_shared<AbortWithPayloadFrameRecognizer>(), module_name, sym_arr,
+ /*first_instruction_only*/ false);
}
RecognizedStackFrameSP
AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
// We have two jobs:
- // 1) to add the data passed to abort_with_payload to the
+ // 1) to add the data passed to abort_with_payload to the
// ExtraCrashInformation dictionary.
// 2) To make up faux arguments for this frame.
static constexpr llvm::StringLiteral namespace_key("namespace");
@@ -55,7 +54,7 @@ AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
static constexpr llvm::StringLiteral reason_key("reason");
static constexpr llvm::StringLiteral flags_key("flags");
static constexpr llvm::StringLiteral info_key("abort_with_payload");
-
+
// We are fetching the data from registers.
Thread *thread = frame_sp->GetThread().get();
Process *process = thread->GetProcess().get();
@@ -69,10 +68,10 @@ AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
if (!scratch_ts_sp)
return {};
- // The abort_with_payload signature is:
- // abort_with_payload(uint32_t reason_namespace, uint64_t reason_code,
- // void* payload, uint32_t payload_size,
- // const char* reason_string, uint64_t reason_flags);
+ // The abort_with_payload signature is:
+ // abort_with_payload(uint32_t reason_namespace, uint64_t reason_code,
+ // void* payload, uint32_t payload_size,
+ // const char* reason_string, uint64_t reason_flags);
ValueList arg_values;
Value input_value_32;
@@ -93,7 +92,7 @@ AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
CompilerType clang_char_star_type =
scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint,
64);
-
+
input_value_32.SetValueType(Value::ValueType::Scalar);
input_value_32.SetCompilerType(clang_uint32_type);
input_value_64.SetValueType(Value::ValueType::Scalar);
@@ -102,7 +101,7 @@ AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
input_value_void_ptr.SetCompilerType(clang_void_ptr_type);
input_value_char_ptr.SetValueType(Value::ValueType::Scalar);
input_value_char_ptr.SetCompilerType(clang_char_ptr_type);
-
+
arg_values.PushValue(input_value_32);
arg_values.PushValue(input_value_64);
arg_values.PushValue(input_value_void_ptr);
@@ -119,10 +118,10 @@ AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
StackFrame *frame = frame_sp.get();
ValueObjectListSP arguments_sp = ValueObjectListSP(new ValueObjectList());
- auto add_to_arguments = [&](llvm::StringRef name, Value *value, bool dynamic)
- {
- ValueObjectSP cur_valobj_sp = ValueObjectConstResult::Create(frame, *value,
- ConstString(name));
+ auto add_to_arguments = [&](llvm::StringRef name, Value *value,
+ bool dynamic) {
+ ValueObjectSP cur_valobj_sp =
+ ValueObjectConstResult::Create(frame, *value, ConstString(name));
cur_valobj_sp = ValueObjectRecognizerSynthesizedValue::Create(
*cur_valobj_sp, eValueTypeVariableArgument);
ValueObjectSP dyn_valobj_sp;
@@ -133,19 +132,19 @@ AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
}
arguments_sp->Append(cur_valobj_sp);
};
-
+
// Decode the arg_values:
-
+
uint32_t namespace_val = 0;
cur_value = arg_values.GetValueAtIndex(0);
add_to_arguments(namespace_key, cur_value, false);
namespace_val = cur_value->GetScalar().UInt(namespace_val);
-
+
uint32_t code_val = 0;
cur_value = arg_values.GetValueAtIndex(1);
add_to_arguments(code_key, cur_value, false);
code_val = cur_value->GetScalar().UInt(code_val);
-
+
lldb::addr_t payload_addr = LLDB_INVALID_ADDRESS;
cur_value = arg_values.GetValueAtIndex(2);
add_to_arguments(payload_addr_key, cur_value, true);
@@ -155,16 +154,17 @@ AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
cur_value = arg_values.GetValueAtIndex(3);
add_to_arguments(payload_size_key, cur_value, false);
payload_size = cur_value->GetScalar().UInt(payload_size);
-
+
lldb::addr_t reason_addr = LLDB_INVALID_ADDRESS;
cur_value = arg_values.GetValueAtIndex(4);
add_to_arguments(reason_key, cur_value, false);
reason_addr = cur_value->GetScalar().ULongLong(payload_addr);
-
+
// For the reason string, we want the string not the address, so fetch that.
std::string reason_string;
Status error;
- size_t str_len = process->ReadCStringFromMemory(reason_addr, reason_string, error);
+ size_t str_len =
+ process->ReadCStringFromMemory(reason_addr, reason_string, error);
if (error.Fail())
return {};
@@ -183,19 +183,19 @@ AbortWithPayloadFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame_sp) {
abort_dict_sp->AddStringItem(reason_key, reason_string);
abort_dict_sp->AddIntegerItem(flags_key, flags_val);
- // This will overwrite any information in the dictionary already.
+ // This will overwrite any information in the dictionary already.
// But we can only crash on abort_with_payload once, so that shouldn't matter.
process->GetExtendedCrashInfoDict()->AddItem(info_key, abort_dict_sp);
-
- return RecognizedStackFrameSP(new AbortWithPayloadRecognizedStackFrame(frame_sp, arguments_sp));
+
+ return RecognizedStackFrameSP(
+ new AbortWithPayloadRecognizedStackFrame(frame_sp, arguments_sp));
}
AbortWithPayloadRecognizedStackFrame::AbortWithPayloadRecognizedStackFrame(
- lldb::StackFrameSP &frame_sp, ValueObjectListSP &args_sp) :
- RecognizedStackFrame() {
- m_arguments = args_sp;
- m_stop_desc = "abort with payload or reason";
+ lldb::StackFrameSP &frame_sp, ValueObjectListSP &args_sp)
+ : RecognizedStackFrame() {
+ m_arguments = args_sp;
+ m_stop_desc = "abort with payload or reason";
}
} // namespace lldb_private
-
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.h b/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.h
index 25053a4322..6f3538647a 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.h
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/AbortWithPayloadFrameRecognizer.h
@@ -21,17 +21,17 @@ void RegisterAbortWithPayloadFrameRecognizer(Process *process);
class AbortWithPayloadRecognizedStackFrame : public RecognizedStackFrame {
public:
- AbortWithPayloadRecognizedStackFrame(lldb::StackFrameSP &frame_sp,
+ AbortWithPayloadRecognizedStackFrame(lldb::StackFrameSP &frame_sp,
lldb::ValueObjectListSP &args_sp);
};
-class AbortWithPayloadFrameRecognizer: public StackFrameRecognizer {
- public:
- std::string GetName() override {
- return "abort_with_payload StackFrame Recognizer"; }
+class AbortWithPayloadFrameRecognizer : public StackFrameRecognizer {
+public:
+ std::string GetName() override {
+ return "abort_with_payload StackFrame Recognizer";
+ }
lldb::RecognizedStackFrameSP
- RecognizeFrame(lldb::StackFrameSP frame_sp) override;
-
+ RecognizeFrame(lldb::StackFrameSP frame_sp) override;
};
} // namespace lldb_private
diff --git a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
index 999b81b49e..0556b87777 100644
--- a/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
+++ b/lldb/source/Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.cpp
@@ -28,8 +28,8 @@
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
-#include "SystemRuntimeMacOSX.h"
#include "AbortWithPayloadFrameRecognizer.h"
+#include "SystemRuntimeMacOSX.h"
#include <memory>
@@ -92,7 +92,7 @@ SystemRuntimeMacOSX::SystemRuntimeMacOSX(Process *process)
m_libdispatch_tsd_indexes(),
m_dispatch_voucher_offsets_addr(LLDB_INVALID_ADDRESS),
m_libdispatch_voucher_offsets() {
-
+
RegisterAbortWithPayloadFrameRecognizer(process);
}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index c72852d2af..728f9aadef 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -477,7 +477,7 @@ Process::Process(lldb::TargetSP target_sp, ListenerSP listener_sp,
m_clear_thread_plans_on_stop(false), m_force_next_event_delivery(false),
m_last_broadcast_state(eStateInvalid), m_destroy_in_process(false),
m_can_interpret_function_calls(false), m_run_thread_plan_lock(),
- m_can_jit(eCanJITDontKnow),
+ m_can_jit(eCanJITDontKnow),
m_crash_info_dict_sp(new StructuredData::Dictionary()) {
CheckInWithManager();
diff --git a/lldb/test/API/macosx/abort_with_payload/main.c b/lldb/test/API/macosx/abort_with_payload/main.c
index aabe21b9cb..a10a6cf65f 100644
--- a/lldb/test/API/macosx/abort_with_payload/main.c
+++ b/lldb/test/API/macosx/abort_with_payload/main.c
@@ -2,29 +2,32 @@
#include <stdint.h>
#include <string.h>
-extern void abort_with_payload(uint32_t reason_namespace, uint64_t reason_code, void* payload, uint32_t payload_size, const char* reason_string, uint64_t reason_flags);
+extern void abort_with_payload(uint32_t reason_namespace, uint64_t reason_code,
+ void *payload, uint32_t payload_size,
+ const char *reason_string,
+ uint64_t reason_flags);
-extern void abort_with_reason(uint32_t reason_namespace, uint64_t reason_code, const char* reason_string, uint64_t reason_flags);
+extern void abort_with_reason(uint32_t reason_namespace, uint64_t reason_code,
+ const char *reason_string, uint64_t reason_flags);
-#define OS_REASON_FLAG_FROM_USERSPACE 0x4
-#define OS_REASON_FLAG_NO_CRASH_REPORT 0x1
-#define OS_REASON_FLAG_ONE_TIME_FAILURE 0x80
+#define OS_REASON_FLAG_FROM_USERSPACE 0x4
+#define OS_REASON_FLAG_NO_CRASH_REPORT 0x1
+#define OS_REASON_FLAG_ONE_TIME_FAILURE 0x80
-#define MY_REASON_FLAGS OS_REASON_FLAG_FROM_USERSPACE|OS_REASON_FLAG_NO_CRASH_REPORT|OS_REASON_FLAG_ONE_TIME_FAILURE
-#define OS_REASON_TEST 5
+#define MY_REASON_FLAGS \
+ OS_REASON_FLAG_FROM_USERSPACE | OS_REASON_FLAG_NO_CRASH_REPORT | \
+ OS_REASON_FLAG_ONE_TIME_FAILURE
+#define OS_REASON_TEST 5
-int
-main(int argc, char **argv)
-{
+int main(int argc, char **argv) {
const char *reason_string = "This is the reason string";
- const char *payload_string = "This is a payload that happens to be a string";
+ const char *payload_string = "This is a payload that happens to be a string";
size_t payload_string_len = strlen(payload_string) + 1;
if (argc == 1) // Stop here before abort
- abort_with_payload(OS_REASON_TEST, 100, (void *) payload_string , payload_string_len,
- reason_string, MY_REASON_FLAGS);
- else
+ abort_with_payload(OS_REASON_TEST, 100, (void *)payload_string,
+ payload_string_len, reason_string, MY_REASON_FLAGS);
+ else
abort_with_reason(OS_REASON_TEST, 100, reason_string, MY_REASON_FLAGS);
return 0;
-
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/101365
More information about the lldb-commits
mailing list