LCOV - code coverage report
Current view: top level - atrace/utrace/stacktrace/stacktrace_dumper - scd_regs_x86_64.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 18 18
Test Date: 2026-08-31 10:07:06 Functions: 100.0 % 8 8

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "scd_regs.h"
      12              : #include "securec.h"
      13              : 
      14              : #ifdef __x86_64__
      15              : 
      16              : #define SCD_REGS_SP SCD_REGS_RSP
      17              : #define SCD_REGS_PC SCD_REGS_RIP
      18              : 
      19          294 : void ScdRegsLoadFromUcontext(ScdRegs* regs, ucontext_t* uc) { GET_REGISTER_FROM_CONTEXT(regs->r, &uc->uc_mcontext); }
      20              : 
      21           25 : uintptr_t ScdRegsGetPc(ScdRegs* regs) { return regs->r[SCD_REGS_PC]; }
      22              : 
      23           21 : void ScdRegsSetPc(ScdRegs* regs, uintptr_t pc) { regs->r[SCD_REGS_PC] = pc; }
      24              : 
      25           55 : uintptr_t ScdRegsGetSp(ScdRegs* regs) { return regs->r[SCD_REGS_SP]; }
      26              : 
      27           17 : void ScdRegsSetSp(ScdRegs* regs, uintptr_t sp) { regs->r[SCD_REGS_SP] = sp; }
      28              : 
      29           43 : uintptr_t ScdRegsGetFp(ScdRegs* regs) { return regs->r[SCD_REGS_RBP]; }
      30              : 
      31           17 : void ScdRegsSetFp(ScdRegs* regs, uintptr_t fp) { regs->r[SCD_REGS_RBP] = fp; }
      32              : 
      33          374 : TraStatus ScdRegsGetString(const ScdRegs* regs, char* buf, size_t bufSize)
      34              : {
      35          374 :     if (regs == NULL || buf == NULL || bufSize == 0) {
      36           51 :         return TRACE_INVALID_PARAM;
      37              :     }
      38          323 :     int32_t ret = snprintf_s(
      39              :         buf, bufSize, bufSize - 1U,
      40              :         "crash registers:\n"
      41              :         "    rax 0x%016lx  rbx 0x%016lx  rcx 0x%016lx  rdx 0x%016lx\n"
      42              :         "    r8  0x%016lx  r9  0x%016lx  r10 0x%016lx  r11 0x%016lx\n"
      43              :         "    r12 0x%016lx  r13 0x%016lx  r14 0x%016lx  r15 0x%016lx\n"
      44              :         "    rdi 0x%016lx  rsi 0x%016lx\n"
      45              :         "    rbp 0x%016lx  rsp 0x%016lx  rip 0x%016lx\n\n",
      46          323 :         regs->r[SCD_REGS_RAX], regs->r[SCD_REGS_RBX], regs->r[SCD_REGS_RCX], regs->r[SCD_REGS_RDX],
      47          323 :         regs->r[SCD_REGS_R8], regs->r[SCD_REGS_R9], regs->r[SCD_REGS_R10], regs->r[SCD_REGS_R11], regs->r[SCD_REGS_R12],
      48          323 :         regs->r[SCD_REGS_R13], regs->r[SCD_REGS_R14], regs->r[SCD_REGS_R15], regs->r[SCD_REGS_RDI],
      49          323 :         regs->r[SCD_REGS_RSI], regs->r[SCD_REGS_RBP], regs->r[SCD_REGS_RSP], regs->r[SCD_REGS_RIP]);
      50          323 :     if (ret == -1) {
      51          119 :         return TRACE_FAILURE;
      52              :     }
      53          204 :     return TRACE_SUCCESS;
      54              : }
      55              : 
      56              : #endif
        

Generated by: LCOV version 2.0-1