[llvm] [z/OS] Add backtrace support for z/OS. (PR #121826)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 07:11:03 PST 2025


================
@@ -708,13 +712,89 @@ static int unwindBacktrace(void **StackTrace, int MaxEntries) {
 }
 #endif
 
+#if ENABLE_BACKTRACES && defined(__MVS__)
+void zosbacktrace(raw_ostream &OS) {
+  // A function name in the PPA1 can have length 16k.
+  constexpr size_t MAX_ENTRY_NAME = UINT16_MAX;
+  // Limit all other strings to 8 byte.
+  constexpr size_t MAX_OTHER = 8;
+  int32_t dsa_format = -1; // Input/Output
+  void *caaptr = _gtca();  // Input
+  int32_t member_id;
+  char compile_unit_name[MAX_OTHER];
+  int32_t compile_unit_name_length = sizeof(compile_unit_name); // Input/Output
+  void *compile_unit_address;                                   // Output
+  void *call_instruction_address = nullptr;                     // Input/Output
+  char entry_name[MAX_ENTRY_NAME];                              // Output
+  int32_t entry_name_length = sizeof(entry_name);               // Input/Output
+  void *entry_address;                                          // Output
+  void *callers_instruction_address;                            // Output
+  void *callers_dsaptr;                                         // Output
+  int32_t callers_dsa_format;                                   // Output
+  char statement_id[MAX_OTHER];                                 // Output
+  int32_t statement_id_length = sizeof(statement_id);           // Input/Output
+  void *cibptr;                                                 // Output
+  int32_t main_program;                                         // Output
+  _FEEDBACK fc;                                                 // Output
+
+  // The DSA pointer is the value of the stack pointer r4.
+  // __builtin_frame_address() returns a pointer to the stack frame, so the
+  // stack bias has to be considered to get the expected DSA value.
+  void *dsaptr = static_cast<char *>(__builtin_frame_address(0)) - 2048;
+  int count = 0;
+  OS << " DSA  Adr                EP                 +EP         DSA           "
+        "     Entry\n";
+  while (1) {
+    compile_unit_name_length = sizeof(compile_unit_name);
+    entry_name_length = sizeof(entry_name);
+    statement_id_length = sizeof(statement_id);
----------------
arsenm wrote:

These can just be declared here too 

https://github.com/llvm/llvm-project/pull/121826


More information about the llvm-commits mailing list