LCOV - code coverage report
Current view: top level - atrace/utrace/stacktrace - stacktrace_common.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 3 3
Test Date: 2026-07-28 10:53:44 Functions: 100.0 % 1 1

            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              : #ifndef STACKTRACE_COMMON_H
      12              : #define STACKTRACE_COMMON_H
      13              : 
      14              : #include <signal.h>
      15              : #include <stdbool.h>
      16              : #include <stddef.h>
      17              : #include <stdint.h>
      18              : 
      19              : #define SIG_ATRACE              35
      20              : #define STACKTRACE_DUMP_BIN_MODE 0xAABB0003U
      21              : #define THREAD_NAME_LEN         16U
      22              : #define MAX_BIN_PATH_LEN        1024U
      23              : #define MAX_THREAD_NUM          1024U
      24              : 
      25              : #define SCD_MAX_NAME_HEAD_LEN       64U
      26              : #define SCD_MAX_FILENAME_LEN        128U
      27              : #define SCD_MAX_FILEDIR_LEN         255U
      28              : #define SCD_MAX_FILEPATH_LEN        (SCD_MAX_FILEDIR_LEN + SCD_MAX_NAME_HEAD_LEN)
      29              : #define SCD_MAX_FULLPATH_LEN        (SCD_MAX_FILEPATH_LEN + SCD_MAX_FILENAME_LEN)
      30              : 
      31              : /*
      32              :  * [parent process] ---fork---> [child process] ---execv---> [new process]
      33              :  * [parent process] application process which receive signal
      34              :  * [child process]  copy form "parent process", prepare to execute new program
      35              :  * [new process]    created by "child process" via execv, dumper stacktrace in this process
      36              :  */
      37              : 
      38              : typedef enum ScdDumpType {
      39              :     SCD_DUMP_THREADS_TXT,
      40              :     SCD_DUMP_THREADS_BIN,
      41              :     SCD_DUMP_THREAD_TXT,
      42              :     SCD_DUMP_THREAD_BIN,
      43              : } ScdDumpType;
      44              : 
      45          176 : static inline bool ScdSignalIsBinDump(int32_t signo, const siginfo_t *siginfo)
      46              : {
      47          209 :     return (signo == SIG_ATRACE) && (siginfo != NULL) &&
      48           33 :         ((uint32_t)siginfo->si_value.sival_int == STACKTRACE_DUMP_BIN_MODE);
      49              : }
      50              : 
      51              : // [child process] ---execv---> [new process]
      52              : typedef struct ScdProcessArgs {
      53              :     int32_t     pid;      // the crashing process
      54              :     int32_t     crashTid; // the crashing thread
      55              :     int32_t     signo;
      56              :     uint64_t    crashTime;
      57              :     uintptr_t   stackBaseAddr;
      58              :     siginfo_t   si;
      59              :     ucontext_t  uc;
      60              :     char        filePath[SCD_MAX_FILEPATH_LEN + 1U];
      61              :     char        fileName[SCD_MAX_FILENAME_LEN + 1U];
      62              :     ScdDumpType handleType;
      63              : } ScdProcessArgs;
      64              : 
      65              : // [parent process] ---fork---> [child process]
      66              : typedef struct {
      67              :     int32_t     pid;  // the crashing process
      68              :     int32_t     tid;  // the crashing thread
      69              :     int32_t     signo;
      70              :     uint64_t    crashTime;
      71              :     uintptr_t   stackBaseAddr;
      72              :     siginfo_t   siginfo;
      73              :     ucontext_t  ucontext;
      74              :     char        filePath[SCD_MAX_FILEPATH_LEN + 1U];
      75              :     char        fileName[SCD_MAX_FILENAME_LEN + 1U];
      76              :     char        exePath[MAX_BIN_PATH_LEN];
      77              : } ThreadArgument;
      78              : 
      79              : #endif
        

Generated by: LCOV version 2.0-1