66#include < cinttypes>
77#include < execinfo.h>
88#include < fcntl.h>
9+ #include < ucontext.h>
910#include < unistd.h>
11+ #include < memory>
1012
1113#include " common/algorithms/find.h"
1214#include " common/fast-backtrace.h"
15+ #include " common/server/crash-dump.h"
1316#include " common/wrappers/likely.h"
1417#include " common/ucontext/ucontext-portable.h"
1518#include " runtime/kphp-backtrace.h"
@@ -259,7 +262,7 @@ void JsonLogger::write_log_with_demangled_backtrace(vk::string_view message,int
259262}
260263
261264void JsonLogger::write_log (vk::string_view message, int type, int64_t created_at,
262- void *const *trace, int64_t trace_size, bool uncaught) noexcept {
265+ void *const *trace, int64_t trace_size, bool uncaught, void * ucontext ) noexcept {
263266 if (json_log_fd_ <= 0 ) {
264267 return ;
265268 }
@@ -269,7 +272,7 @@ void JsonLogger::write_log(vk::string_view message, int type, int64_t created_at
269272 }
270273 assert (json_out_it != buffers_.end ());
271274
272- write_general_info (json_out_it, type, created_at, uncaught);
275+ write_general_info (json_out_it, type, created_at, uncaught, ucontext );
273276
274277 json_out_it->append_key (" trace" ).start <' [' >();
275278 for (int64_t i = 0 ; i < trace_size; i++) {
@@ -324,7 +327,7 @@ void JsonLogger::reset_buffers() noexcept {
324327 }
325328}
326329
327- void JsonLogger::write_general_info (JsonBuffer *json_out_it, int type, int64_t created_at, bool uncaught) {
330+ void JsonLogger::write_general_info (JsonBuffer *json_out_it, int type, int64_t created_at, bool uncaught, void * ucontext ) {
328331 json_out_it->append_key (" version" ).append_integer (release_version_);
329332 json_out_it->append_key (" hostname" ).append_string (hostname_);
330333 json_out_it->append_key (" type" ).append_integer (type);
@@ -348,12 +351,25 @@ void JsonLogger::write_general_info(JsonBuffer *json_out_it, int type, int64_t c
348351 json_out_it->append_key (" logname_id" ).append_integer (logname_id);
349352 }
350353 json_out_it->append_key (" pid" ).append_integer (pid);
354+ json_out_it->append_key (" ppid" ).append_integer (ppid);
351355 json_out_it->append_key (" cluster" ).append_string (vk::singleton<ServerConfig>::get ().get_cluster_name ());
352356 json_out_it->append_raw (uncaught ? R"json( "uncaught":true)json" : R"json( "uncaught":false)json" );
353357 json_out_it->finish <' }' >();
354358
355359 if (extra_info_available_) {
356- json_out_it->append_key (" extra_info" ).start <' {' >().append_raw (extra_info_).finish <' }' >();
360+ json_out_it->append_key (" extra_info" ).start <' {' >().append_raw (extra_info_);
361+ if (ucontext != nullptr ) {
362+ const auto * ucp = static_cast <ucontext_t *>(ucontext);
363+
364+ #if defined(__x86_64__) && !defined(__APPLE__)
365+ json_out_it->append_key (" CR2 register" ).append_hex_as_string (ucp->uc_mcontext .gregs [REG_CR2]);
366+ #endif
367+
368+ crash_dump_buffer_t buffer{};
369+ crash_dump_prepare_registers (std::addressof (buffer), ucp);
370+ json_out_it->append_key (" registers" ).append_string (buffer.get_content ());
371+ }
372+ json_out_it->finish <' }' >();
357373 }
358374}
359375
0 commit comments