This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

source: ps/trunk/source/lib/sysdep/os/unix/udbg.cpp

Last change on this file was 23271, checked in by Vladislav Belov, 5 years ago

Use raise() instead of kill() for debug_break()

Patch By: linkmauve
Differential Revision: https://code.wildfiregames.com/D2480

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1/* Copyright (C) 2019 Wildfire Games.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining
4 * a copy of this software and associated documentation files (the
5 * "Software"), to deal in the Software without restriction, including
6 * without limitation the rights to use, copy, modify, merge, publish,
7 * distribute, sublicense, and/or sell copies of the Software, and to
8 * permit persons to whom the Software is furnished to do so, subject to
9 * the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23/* udbg.cpp
24
25This file contains debug helpers that are common for all unix systems. See
26linux/ldbg.cpp for the linux-specific stuff (Using BFD and backtrace() for
27symbol lookups and backtraces)
28*/
29
30#include "precompiled.h"
31
32#include <cstdio>
33#include <sys/types.h>
34#include <signal.h>
35
36#include "lib/timer.h"
37#include "lib/sysdep/sysdep.h"
38#include "lib/debug.h"
39#include "lib/utf8.h"
40
41
42Status debug_CaptureContext(void* UNUSED(context))
43{
44 // (not needed unless/until we support stack traces)
45 return INFO::SKIPPED;
46}
47
48void debug_break()
49{
50#ifndef NDEBUG
51 raise(SIGTRAP);
52#endif
53}
54
55#define DEBUGGER_WAIT 3
56#define DEBUGGER_CMD "gdb"
57#define DEBUGGER_ARG_FORMAT "--pid=%d"
58#define DEBUGGER_BREAK_AFTER_WAIT 0
59
60/*
61Start the debugger and tell it to attach to the current process/thread
62(called by display_error)
63*/
64void udbg_launch_debugger()
65{
66 pid_t orgpid=getpid();
67 pid_t ret=fork();
68 if (ret == 0)
69 {
70 // Child Process: exec() gdb (Debugger), set to attach to old fork
71 char buf[16];
72 snprintf(buf, 16, DEBUGGER_ARG_FORMAT, orgpid);
73
74 int ret=execlp(DEBUGGER_CMD, DEBUGGER_CMD, buf, NULL);
75 // In case of success, we should never get here anyway, though...
76 if (ret != 0)
77 {
78 perror("Debugger launch failed");
79 }
80 }
81 else if (ret > 0)
82 {
83 // Parent (original) fork:
84 debug_printf("Sleeping until debugger attaches.\nPlease wait.\n");
85 sleep(DEBUGGER_WAIT);
86 }
87 else // fork error, ret == -1
88 {
89 perror("Debugger launch: fork failed");
90 }
91}
92
93#if OS_ANDROID
94
95#include <android/log.h>
96
97void debug_puts(const char* text)
98{
99 __android_log_print(ANDROID_LOG_WARN, "pyrogenesis", "%s", text);
100}
101
102#else
103
104void debug_puts(const char* text)
105{
106 printf("%s", text);
107 fflush(stdout);
108}
109
110#endif
111
112int debug_IsPointerBogus(const void* UNUSED(p))
113{
114 // TODO: maybe this should do some checks
115 return false;
116}
Note: See TracBrowser for help on using the repository browser.