Coverage Report

Created: 2023-09-25 06:56

/src/FreeRDP/winpr/libwinpr/utils/execinfo/debug.c
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * WinPR: Windows Portable Runtime
3
 * Debugging Utils
4
 *
5
 * Copyright 2014 Armin Novak <armin.novak@thincast.com>
6
 * Copyright 2014 Thincast Technologies GmbH
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
#include <stdlib.h>
22
#include <fcntl.h>
23
24
#include <execinfo.h>
25
26
#include "debug.h"
27
28
typedef struct
29
{
30
  void** buffer;
31
  size_t max;
32
  size_t used;
33
} t_execinfo;
34
35
void winpr_execinfo_backtrace_free(void* buffer)
36
0
{
37
0
  t_execinfo* data = (t_execinfo*)buffer;
38
0
  if (!data)
39
0
    return;
40
41
0
  free(data->buffer);
42
0
  free(data);
43
0
}
44
45
void* winpr_execinfo_backtrace(DWORD size)
46
0
{
47
0
  t_execinfo* data = calloc(1, sizeof(t_execinfo));
48
49
0
  if (!data)
50
0
    return NULL;
51
52
0
  data->buffer = calloc(size, sizeof(void*));
53
54
0
  if (!data->buffer)
55
0
  {
56
0
    free(data);
57
0
    return NULL;
58
0
  }
59
60
0
  const int rc = backtrace(data->buffer, size);
61
0
  if (rc < 0)
62
0
  {
63
0
    free(data);
64
0
    return NULL;
65
0
  }
66
0
  data->max = size;
67
0
  data->used = (size_t)rc;
68
0
  return data;
69
0
}
70
71
char** winpr_execinfo_backtrace_symbols(void* buffer, size_t* used)
72
0
{
73
0
  t_execinfo* data = (t_execinfo*)buffer;
74
0
  if (used)
75
0
    *used = 0;
76
77
0
  if (!data)
78
0
    return NULL;
79
80
0
  if (used)
81
0
    *used = data->used;
82
83
0
  return backtrace_symbols(data->buffer, data->used);
84
0
}
85
86
void winpr_execinfo_backtrace_symbols_fd(void* buffer, int fd)
87
0
{
88
0
  t_execinfo* data = (t_execinfo*)buffer;
89
90
0
  if (!data)
91
0
    return;
92
93
0
  backtrace_symbols_fd(data->buffer, data->used, fd);
94
0
}