Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ set(COREDUMPER_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

add_subdirectory(src)

add_subdirectory(tool)

include(CTest)
if(BUILD_TESTING)
enable_testing()
Expand Down
14 changes: 14 additions & 0 deletions include/coredumper/coredumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define _COREDUMP_H

#include <stddef.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -105,6 +106,11 @@ struct CoreDumpParameters {
*/
#define COREDUMPER_FLAG_LIMITED_BY_PRIORITY 2

/* The core file is requested for an external process, By default we try to
* collect the core from self.
*/
#define COREDUMPER_FLAG_EXTERNAL_PROCESS 4

/* Try compressing with either bzip2, gzip, or compress. If all of those fail,
* fall back on generating an uncompressed file.
*/
Expand Down Expand Up @@ -166,6 +172,14 @@ int GetCompressedCoreDump(const struct CoredumperCompressor compressors[],
*/
int WriteCoreDump(const char *file_name);

/* Writes the core file of a process with pid to disk. This is a convenience
* method wrapping GetCoreDump(). If a core file could not be generated
* for any reason, -1 is returned and errno is set appropriately.
* On success, zero is returned.
*/
int WriteCoreDumpOfPID(struct CoreDumpParameters *params,
const char *file_name, pid_t pid);

/* Writes a core dump to the given file with the given parameters. */
int WriteCoreDumpWith(const struct CoreDumpParameters *params, const char *file_name);

Expand Down
19 changes: 19 additions & 0 deletions src/coredumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,25 @@ int WriteCoreDump(const char *file_name) {
return WriteCoreDumpFunction(&frame, &params, file_name);
}

/*
* This variant collects the core from a process with pid.
* Useful to collect core from un-related process, this assumes that
* the caller has the permission or privilege to trace 'pid' process.
*/
int WriteCoreDumpOfPID(struct CoreDumpParameters *params,
const char *file_name, pid_t pid) {
Frame f;

/*
* Frame cannot be used to retrieve register value for an external process
* we are just using it to pass the pid below.
*/
f.tid = pid;

SetCoreDumpParameter(params, flags, COREDUMPER_FLAG_EXTERNAL_PROCESS);
return ListAllThreadsOfPid(&f, pid, InternalGetCoreDump, params, file_name, getenv("PATH"));
}

int WriteCoreDumpWith(const struct CoreDumpParameters *params, const char *file_name) {
FRAME(frame);
return WriteCoreDumpFunction(&frame, params, file_name);
Expand Down
Loading