5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync/** @file
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * IPRT - Core Dumper.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync */
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync/*
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * Copyright (C) 2010 Oracle Corporation
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync *
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * available from http://www.virtualbox.org. This file is free software;
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * General Public License (GPL) as published by the Free Software
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync *
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * The contents of this file may alternatively be used under the terms
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * of the Common Development and Distribution License Version 1.0
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * VirtualBox OSE distribution, in which case the provisions of the
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * CDDL are applicable instead of those of the GPL.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync *
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * You may elect to license modified versions of this file under the
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * terms and conditions of either the GPL or the CDDL or both.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync */
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync#ifndef ___iprt_coredumper_h
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync#define ___iprt_coredumper_h
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync#include <iprt/cdefs.h>
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync#include <iprt/types.h>
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsyncRT_C_DECLS_BEGIN
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync/** @defgroup grp_rt_coredumper RTCoreDumper - Core Dumper.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * @ingroup grp_rt
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * @{
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync */
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
807512a9a87993f7c56ea2e58e81fb866f578164vboxsync/** @name RTCoreDumperSetup flags
807512a9a87993f7c56ea2e58e81fb866f578164vboxsync * @{ */
d91fefe476dcb42704e1c426ddac37d8cf5d22bdvboxsync/** Override system core dumper. Registers handlers for
d91fefe476dcb42704e1c426ddac37d8cf5d22bdvboxsync * SIGSEGV/SIGTRAP/SIGBUS. */
470deca4c684fee094576ae4feae40f9b4c9f1c1vboxsync#define RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP RT_BIT(0)
d91fefe476dcb42704e1c426ddac37d8cf5d22bdvboxsync/** Allow taking live process dumps (without killing process). Registers handler
d91fefe476dcb42704e1c426ddac37d8cf5d22bdvboxsync * for SIGUSR2. */
470deca4c684fee094576ae4feae40f9b4c9f1c1vboxsync#define RTCOREDUMPER_FLAGS_LIVE_CORE RT_BIT(1)
807512a9a87993f7c56ea2e58e81fb866f578164vboxsync/** @} */
807512a9a87993f7c56ea2e58e81fb866f578164vboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync/**
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * Take a core dump of the current process without terminating it.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync *
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * @returns IPRT status code.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * @param pszOutputFile Name of the core file. If NULL use the
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * default naming scheme.
807512a9a87993f7c56ea2e58e81fb866f578164vboxsync * @param fLiveCore When true, the process is not killed after
807512a9a87993f7c56ea2e58e81fb866f578164vboxsync * taking a core. Otherwise it will be killed. This
807512a9a87993f7c56ea2e58e81fb866f578164vboxsync * works in conjuction with the flags set during
807512a9a87993f7c56ea2e58e81fb866f578164vboxsync * RTCoreDumperSetup().
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync */
807512a9a87993f7c56ea2e58e81fb866f578164vboxsyncRTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile, bool fLiveCore);
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync/**
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * Sets up and enables the core dumper.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync *
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * Installs signal / unhandled exception handlers for catching fatal errors
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * that should result in a core dump. If you wish to install your own handlers
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * you should do that after calling this function and make sure you pass on
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * events you don't handle.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync *
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * This can be called multiple times to change the settings without needing to
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * call RTCoreDumperDisable in between.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync *
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * @param pszOutputDir The directory to store the cores in. If NULL
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * the current directory will be used.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * @param pszBaseName Base file name, no directory. If NULL the
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * dumper will generate an appropriate name.
d91fefe476dcb42704e1c426ddac37d8cf5d22bdvboxsync * @param fFlags Setup flags, 0 in NOT a valid flag, it must be
d91fefe476dcb42704e1c426ddac37d8cf5d22bdvboxsync * one or more of RTCOREDUMPER_FLAGS_*.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync */
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsyncRTDECL(int) RTCoreDumperSetup(const char *pszOutputDir, uint32_t fFlags);
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync/**
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * Disables the core dumper, i.e. undoes what RTCoreDumperSetup did.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync *
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * @returns IPRT status code.
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync */
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsyncRTDECL(int) RTCoreDumperDisable(void);
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync/** @} */
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsyncRT_C_DECLS_END
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync#endif
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync